• Content Count

  • Joined

  • Last visited

About georage

  • Rank
    Advanced Member

Recent Profile Visitors

776 profile views
  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); = 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. Tutorial on shapes:
  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!
  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 ....
  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 =; //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. (cool colored spotlights) and this one ... (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.
  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.