georage

Members
  • Content Count

    54
  • Joined

  • Last visited

Everything posted by georage

  1. Is there any way to create a dynamic texture from a noise function? I thought this was possible and created a function to generate a 2D array of color values but it seems from my searched that dynamic textures require an image. I guess I could make an image from the array, but that seems like a step that could avoided.
  2. Hey, maybe try this? save your vertex data as a file and load it with this function. function loadMesh(directory, fileName, scene){ var rootURL = "json/" + directory + "/"; BABYLON.SceneLoader.ImportMesh("", rootURL, fileName, scene, function (newMeshes) { console.log(newMeshes); camera.target = newMeshes[0]; }); } here is an example of a loadable mesh file. It will take some time to load so wait for it. skull.babylon
  3. you can import vertex data to create or modify a mesh/shape. I can give you some working code in a bit, but check this thread
  4. You are trying to create a 3D shape that looks like a diamond? This may help. http://www.babylonjs-playground.com/#21QRSK#1 Tutorial on shapes: https://doc.babylonjs.com/tutorials/mesh_createxxx_methods_with_options_parameter
  5. Hey, I am not great with Babylonjs, but have managed to put together a few timesaving functions. I am sure you have too. If you have any that you thought were clever, please share them. None of mine are clever, but they are useful. Here is the humblest of all to get the ball rolling. All it does it output to the console for development. But once you go into production you can turn off all the console messages by commenting out one line instead of hundreds or thousands. function log(msg) { console.log( msg ); } I set and get global values with the following. There may be a better way but this is how I store player login information instead of using PHP sessions. function setGlobal(varName, varValue){ var global = $( "body" ).data( varName, varValue ); return global; } function getGlobal(varName){ var global = $( "body" ).data( varName ); return global; } function removeGlobal(varName){ $( "body" ).removeData( varName ); } Three more utility functions you may find helpful //converts from degrees to radians function degreesToRadians(degrees) { return degrees * Math.PI / 180; } //converts from radians to degrees function radiansToDegrees(radians) { return radians * 180 / Math.PI; } function deleteAllMeshes(scene){ console.log(scene.meshes.length + " meshes detected"); var countMesh = 0; for (var i = 0; i < scene.meshes.length; i++) { scene.meshes[i].dispose(); countMesh++; i--; } console.log(countMesh + " meshes deleted"); } Here's a way to format a date so it has leading zeroes with numbers under 10. Otherwise the width of the output will jump around. Remember to use a monospaced font. function formatDate(d){ function pad(n){return n<10 ? '0'+n : n;} function pad2(n){ if (n < 10) return '00'+n; else if (n < 100) return '0'+n; else return n; } return d.getFullYear()+'-'+ pad(d.getMonth()+1)+'-'+ pad(d.getDate())+' '+ pad(d.getHours())+':'+ pad(d.getMinutes())+':'+ pad(d.getSeconds())+'.'+ pad2(d.getMilliseconds()); } Calculate distance between meshes? function getDistanceBetweenMeshes( mesh1, mesh2 ) { //log("mesh1="+mesh1); //log("mesh2="+mesh2); var v1 = mesh1.position; var v2 = mesh2.position; var dx = v1.x - v2.x; var dy = v1.y - v2.y; var dz = v1.z - v2.z; var result = Math.sqrt( dx * dx + dy * dy + dz * dz ); return result.toFixed(5); } and the final entry for now ... it could be refactored to find the orbit distance of a planet based on the planet speed. function calculateOrbitalSpeed(starSize, planetSize, planetOrbit) { //the formula for obital speed is ... planet velocity = SQRT (gravity constant • mass of star / radius of orbit) //but since the planet mass is negligible we are just using the mass of the star var planetOrbitRadius = planetOrbit/2; //var gravityConstant = (starSize*planetSize)/Math.pow(planetOrbitRadius, 2); var gravityConstant = (starSize)/Math.pow(planetOrbitRadius, 2); planetSpeed = Math.sqrt(gravityConstant*starSize)/planetOrbitRadius; return planetSpeed; }
  6. Thanks, this seems to work quickly ... not sure about memory issues but can tweak later. I won't have more than 250 simple meshes in memory at a time either way, I don't think. function disableAllMeshesExcept(star, scene){ log(scene.meshes.length + " meshes detected"); var countMesh = 0; for (var i = 0; i < scene.meshes.length; i++) { if(scene.meshes[i] != star){ //log(scene.meshes[i].sName); scene.meshes[i].setEnabled(false); countMesh++; } } log(countMesh + " meshes disabled"); }
  7. Does anyone have any evidence (anecdotal even) on which method would be quickest? Scenario A: Dispose of 200 static meshes and create 12 new ones. Scenario B: Dispose of the whole scene and create a new scene with 13 static meshes. Scenario C: Not sure this is possible, but can you make babylon.js not render meshes? I could "turn off" the 200 static meshes so they do not interact with lights and player input. This would be the preferred method, I think, since it would minimize object creation, which in C is an expensive process. I can test it, of course, but was wondering if anyone had any best practices on how to make that as seamless as possible. Thanks for any input. EDIT: Looks like setEnabled() may make Scenario C possible! I will test it! https://doc.babylonjs.com/classes/2.4/node
  8. No, a great PC will always outperform a great phone. My crummy 4-year-old laptop is better than my new S7, and my desktop PC blows them both out of the water. There is only so much magic a phone can pull off. A PC can have much better graphic cards, memory, cpus and the motherboard has much greater I/O bandwidth. BUT ... you can do some amazing stuff on phones ... just keep the mesh/vertices count down and be judicious and much is possible. As a benchmark my PC has no prob with animating 3,000 cloned shapes at 60 FPS but my phone has 10 FPS and my "business" laptop about 40. Wife's iPad is 20. Not sure you would ever need more than 3,000 animated meshes in a game. They make pretty demos though. Here is an instructive read .... https://blog.raananweber.com/2015/09/03/scene-optimization-in-babylon-js/
  9. here is how i pick a mesh. maybe try that instead? feel free to change the "change position" bit of course. scene.onPointerDown = function (evt, pickResult) { if (pickResult.hit) { console.log(pickResult.pickedPoint.x); console.log(pickResult.pickedPoint.y); console.log(pickResult.pickedPoint.z); var pickInfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) { return mesh; }); var star = pickInfo.pickedMesh; //change position star.position.x = pickResult.pickedPoint.x +1; } };
  10. are you throwing an error? your console.log line does not end in a semi-colon. Not sure that will help but give it a shot.
  11. Well I'm as dense as a neutron star but I finally got it to work! Thanks wingy! for those who may find such things useful, this onclick function targets an arcRotate camera and toggles godrays on selected/previously selected objects. My star meshes are overloaded with custom names (sName for star name) which I check to make sure the mesh exists before trying to remove the godrays effect, so if you use this function be aware of this line ... if (prevTarget.sName). It will work without the check but throw an error the first time you select a mesh since no prior mesh/camera target exists. Also useful is the star != prevTarget check because it seems you can add godrays on top of godrays and the effect starts to look terrible if you do that too much. function focusCamera(camera, star){ //define previous star var prevTarget = camera.target; //retarget camera to selected star camera.setTarget(star); //set distance var camRad = star.sSize*12; camera.radius = camRad; console.log("set camera radius to "+camRad); //don't apply godrays to star that already has godrays if(star != prevTarget){ //apply godrays effect to selected star var godrays = new BABYLON.VolumetricLightScatteringPostProcess('godrays', 1.0, camera, star, 90, BABYLON.Texture.BILINEAR_SAMPLINGMODE, engine, true); star.godrays = godrays; //if previous star is a mesh, delete godrays from it if(prevTarget.sName){ console.log(prevTarget.sName); prevTarget.godrays.excludedMeshes.push(prevTarget); } else{ console.log("no previous camera target"); } } }
  12. do they pay you wingy? i hope so. and well! thanks again. I searched for hours and never hit the right links. but i did see you helping many people. i particularly liked this one. http://playground.babylonjs.com/#MX8Q6 (cool colored spotlights) and this one ... http://playground.babylonjs.com/#5R8A1 (layered fog) I feel like WE owe you many beers.
  13. Is it possible to remove the effect? Is it possible to check if the effect has been applied to a mesh (other than an independent variable)? I have an onClick event that adds the effect to the clicked mesh, but it seems to multiply the effect every time the mesh is clicked and it starts to look crazy. I'd like to remove the effect from non-targeted meshes to save gpu cycles, and be able to check if the effect even needs to be applied. Thanks for any tips. Here is an old playground I made if someone wants to play with it. http://babylonjs-playground.com/#AX6IZ#3
  14. On a semi-related topic, how would one go about delaying javascript functions. I can't find anything like sleep and all the stuff I googled doesn't seem to delay the function at all. I was trying "async await" and even timeout wrappers but it doesn't seem to block anything. Or perhaps this is too off-topic. I have a JS script populating a DB and was wanting to throttle it a bit.
  15. Thanks Wingy. I am just making 1 or 2 stars at a time for the godrays thing. Separately I am using instances to create a thousand or so stars at a time and storing the x, y, z coords in a database. In truth I don't even need to use meshes to generate random positions ... but it is fun to look at the results. I like your examples. That #4 is really neat. I can maybe use that for something! I also like one I saw you did with CORONAS ... almost like a godrays thing. You have skills son!
  16. I think I have answered my own question, but it seems you can't dispose of a root mesh that is used to build instances without deleting all the instances from the scene as well. Is that right? I created a "galaxy" (OK, a small one!) of various star types. I created one root star for each star type then made several thousand instances of each star type with different xyx positions and scaling. It works great. But when I dispose of the root meshes everything disappears. I guess this is how it is supposed to work. Reminds me of a game I worked on where we had to keep all the magic items in a hidden treasure chest somewhere in the game world and whenever a player got a magic sword we just copied one from the hidden chest. -- George
  17. cool. thanks for the help. ALL IS WELL. http://babylonjs-playground.com/#AX6IZ#1
  18. Hello friends. Long time no see. I have returned and updated to 2.5 (from 2.4) and it seems something has changed with godrays (aka VolumetricLightScatteringPostProcess). I get this error. "VolumetricLightScatteringPostProcess.useDiffuseColor is no longer used, use the mesh material directly instead" Any clues about that? I had some rather dandy looking stars in 2.4! I can't make a playground either ... gives me an error Compilation error Line 4:16942 - Cannot read property 'precision' of null I blame myself for not playing with this for a while but any help is appreciated. -- George
  19. Seems a little like marketing at times. Might want to tone it down.
  20. Wingnut, I hope you are well paid. Thanks for that cool example.
  21. I suggest doing a hit test (see tutorial playgrounds) when you drop the box and see which square it should snap to. You will have to use math! But you could easily make it snap to a random side or corner. I am working on something similar using 3D cubes. Not code to share yet!
  22. Thanks for all the help fellows, I got it working. That skull is really cool.
  23. I can't seem to load a babylon mesh into my scene from my server. I am familiar with the playground, but my version appends appends manifest?unixtimestamp to the resource url I provide and I get a showstopping GET error. My console reports I have a version of skull.babylon on the server but the url appended with .manifest?unixtimestamp returns a 404. I find the SceneLoader documentation a little confusing, with lots of repeated text. https://doc.babylonjs.com/classes/2.3/SceneLoader My questions: How do I get rid of the GET error? How would you code this up if you have your .babylon files in a separate folder from your root folder? I have my root folder with index.html, then a js folder and a json folder for saved .babylon mesh files. BABYLON.SceneLoader.ImportMesh("", "_json/", "skull.babylon", scene, function (newMeshes) { }); Thanks for any help! I think I am learning a lot but am often bewildered for hours.
  24. thanks! i appreciate your showing me the light. I guess I will have to change my functions to use your method, but in every case except disposing of meshes it seems to work with "scene.meshes.forEach" Is there a reason why your method is more reliable?