• Content count

  • Joined

  • Last visited

  1. Have you tried using octrees? I also had 800+ meshes in my scene and octrees helped my CPU performance by a lot.
  2. In your app is your canvas focused? I added `document.getElementById("renderCanvas").focus();` and it works for me in the playground you have. http://www.babylonjs-playground.com/#3H5RJW#1
  3. Great, thanks! Should the importedMeshesFiles array be cleared on scene.dispose() as it could potentially leak memory?
  4. Hi, I was optimizing memory usage for my babylon app and I stumbled across this property scene.importedMeshesFiles // Imported meshes public importedMeshesFiles = new Array<String>(); https://github.com/BabylonJS/Babylon.js/blob/master/src/babylon.scene.ts#L603 In my application it was using over 25 mb of memory storing all the loaded .babylon mesh files and from what I can see it's not used anywhere except in the playground code. https://github.com/BabylonJS/Babylon.js/blob/8ff548e2fdb9a203ac5b29e6a662a7d48220f2af/Playground/js/index.js#L477 Can I assume it's safe to clear the importedMeshesFiles every time I load a mesh to reduce memory footprint or would it cause any issues?
  5. Edit: NEVERMIND, I checked noscript and that was blocking urls! I havn't had troubles saving before so didnt think of that!. Here's the url if you want to see it in action! http://babylonjs-playground.azurewebsites.net/#NJ8S1D Hi, I'm guessing this probably isn't a bug and is a security feature but I was creating a playground where I was projecting a world position to screenspace and then using css to position a div to make sure it was correct. I couldn't find any information about unable to save a playground mentioning DOM manipulation. Heres the code that is unable to save with the error Unable to save your code. It may be too long. var createScene = function () { // This creates a basic Babylon Scene object (non-mesh) var scene = new BABYLON.Scene(engine); // This creates and positions a free camera (non-mesh) var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene); // This targets the camera to scene origin camera.setTarget(BABYLON.Vector3.Zero()); // This attaches the camera to the canvas camera.attachControl(canvas, true); // This creates a light, aiming 0,1,0 - to the sky (non-mesh) var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene); // Default intensity is 1. Let's dim the light a small amount light.intensity = 0.7; // Our built-in 'sphere' shape. Params: name, subdivs, size, scene var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene); // Move the sphere upward 1/2 its height sphere.position.y = 1; // Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene var ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene); var time = 0; var blob = document.getElementById("blobby"); var canvasZone = document.getElementById("canvasZone"); canvasZone.style.position = "relative"; if ( !blob ) { blob = document.createElement("div"); blob.style.position = "absolute"; blob.style.backgroundColor = "red"; blob.style.left = "0"; blob.style.top = "0"; blob.style.width = "5px"; blob.style.height = "5px"; blob.id = "blobby"; blob.style.zIndex = 10000000; canvasZone.appendChild(blob); } scene.afterRender = function() { time += 1 / 120; sphere.position.x = 0 + 20 * Math.sin( time ); var scene = sphere.getScene(); var cameraViewport = camera.viewport; let projectedVector = BABYLON.Vector3.Project( sphere.position, BABYLON.Matrix.Identity(), //sphere.getWorldMatrix(), scene.getTransformMatrix(), cameraViewport ); const width = canvasZone.offsetWidth; const height = canvasZone.offsetHeight; blob.style.left = (width * projectedVector.x) + "px"; blob.style.top = (height * projectedVector.y) + "px"; } return scene; };
  6. Hi, I was debugging using temporary meshes and noticed that if you just dispose the mesh after adding it to the octree.dynamicContent it stays there even after dispose. Here's a playground where I create 500 meshes and then add them to octree.dynamicContent and then dispose of all of them and the dynamicContent keeps all 500. http://babylonjs-playground.azurewebsites.net/#1YPN4G#2
  7. Hi I was using uniqueId to uniquely represent a mesh and I noticed if I use a cloned mesh ( mesh.clone() ) their uniqueId would be the same. After debugging the code the cloned mesh has a uniqueId after this line: super(name, scene); But after the line: Tools.DeepCopy(source, this, ["name", "material", "skeleton", "instances", "parent"], ["_poseMatrix"]); They now have the same uniqueId Which can be seen here: http://babylonjs-playground.azurewebsites.net/#27FBML#0
  8. Interesting, I think in my case it's better to use the current triangle getting logic because I only need the positions and nothing else. Here's a link to the C or C++ implementation if you're interested: http://fileadmin.cs.lth.se/cs/personal/tomas_akenine-moller/code/opttritri.txt Edit: Ended up going with the original solution and not using facetdata. As for going from local B -> local A: // Declared outside function as reusable matrix: var _tmpMatrix = BABYLON.Matrix.Identity(); // To convert from localSpace B -> localSpace B let finalMatrix = _tmpMatrix; const aWorldMatrix = a.getWorldMatrix(); const bWorldMatrix = b.getWorldMatrix(); let tmpAInverseWorldMatrix = BABYLON.Tmp.Matrix[ 0 ]; aWorldMatrix.invertToRef( tmpAInverseWorldMatrix ); bWorldMatrix.multiplyToRef( tmpAInverseWorldMatrix, finalMatrix ); // Later on when iterating each vertex for mesh b BABYLON.Vector3.TransformCoordinatesToRef( vertex, finalMatrix, resultVertex );
  9. Hi, so I've converted Tomas Möller's Triangle-Triangle Overlap Test code for babylonjs to do precise intersection for 2 meshes. Currently the code I have looks like this which uses the triangles in world space. However I figured it'd be faster to convert mesh B into mesh As localspace instead. const Av = getTriangles( a ); const Bv = getTriangles( b ); function getTriangles ( mesh ) { const vertices = mesh.getVerticesData( BABYLON.VertexBuffer.PositionKind ); const indices = mesh.getIndices(); const worldMatrix = mesh.getWorldMatrix(); let result = []; // Get all triangles for ( let i = 0; i < indices.length; ++i ) { let index = indices[ i ] * 3; let vertex = new BABYLON.Vector3( vertices[ index ], vertices[ index + 1 ], vertices[ index + 2 ] ); BABYLON.Vector3.TransformCoordinatesToRef( vertex, worldMatrix, vertex ); result.push( vertex ); } return result; } Which for A would skip the transformCoordinates step and for B I would calculate a matrix that looks like this to move B to A's local space: matrix = bWorldMatrix * aInvertedWorldMatrix Is that the way to convert B to A's local space or is it some other way to do it? Or some other better way to get all the triangles for the tri to tri overlap test?
  10. In the predicate function you write your own logic of what meshes should be valid or not for picking. In your case that is if the mesh has voxelData so what you should do there is return true. As long as mesh has voxelData it will be checked against the ray. Just because the predicate function returns true doesn't mean the ray will hit. So as RaananW said if your debugger statement is executed the ray most likely doesn't hit your mesh.
  11. You can also try and decrease the decimal precision. When I used the fbx exporter the exported babylon file had something like 16 decimals per vertex, normal e.t.c. which I reduced to 5 which reduced the filesize by a lot.
  12. @adam If you set the scale to 0.5 in your playground the ray no longer for me at least intersects with the boxTarget mesh. http://www.babylonjs-playground.com/#ZHDBJ#37
  13. Hi, I've been using ray.intersectsMesh when it came with 2.5 and I started noticing in some cases that it doesn't hit the mesh it should intersect with. Here's a playground illustrating the issue: http://babylonjs-playground.azurewebsites.net/#1IOFE4#9 In that playground I also wrote overwrote the intersectsMesh function that will hit the 2 cases I had where it doesn't hit the scaled mesh if you uncomment the line: //overwriteIntersectsMesh(); I could be using the ray.intersectsMesh wrong but the way I've been using it is: direction = mesh.position - point origin = point length = direction.length() before normalizing
  14. Hi, I was debugging some code and stumbled upon Ray.TransformToRef and I noticed probably a bug? The result ray's direction is never normalized unless I'm mistaken. public static TransformToRef(ray: Ray, matrix: Matrix, result:Ray): void { Vector3.TransformCoordinatesToRef(ray.origin, matrix, result.origin); Vector3.TransformNormalToRef(ray.direction, matrix, result.direction); // This should be result.direction.normalize(); ? ray.direction.normalize(); }
  15. Hi, thanks Adam that did help. The important part was this: BABYLON.Vector3.TransformCoordinates(raypos, mesh.getWorldMatrix()) The direction I could use what I have already calculated. The updated playground: http://babylonjs-playground.azurewebsites.net/#1QXOXX#6