haestflod

Members
  • Content count

    19
  • Joined

  • Last visited

  1. 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
  2. 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 );
  3. 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?
  4. 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.
  5. 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.
  6. @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
  7. 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
  8. 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(); }
  9. 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
  10. Hi, I have a scene where I am calculating the direction of a ray and then tries to intersect a specific mesh to get the pickingInfo so I can get the surfaceNormal of the closest surface. I have replicated it here. http://babylonjs-playground.azurewebsites.net/#1QXOXX#5 If I create a new mesh with the scaled values of the mesh it hits the mesh and everything works. Since the ray doesn't hit the mesh that is scaled I'm wondering what I'm doing wrong?
  11. Because it made it simple to move & rotate them after adding as child mesh. All that is needed is to move & rotate the parent and children automatically does the same. Also the child & parent relations can be edited on the fly by either adding a mesh or remove a mesh and the children of that mesh by selecting with mouse. Edit: So in the end I solved it using adam's approach by adding an empty mesh. Here's a static version with 3 meshes: http://www.babylonjs-playground.com/#1CWAMX#15 Here's the same but with some rotation & scale being altered each frame: http://www.babylonjs-playground.com/#1CWAMX#18 I did try using some kind of matrix decomposition at first but it never worked so alas adam's approach it was!
  12. That's an interesting solution JohnK but is that applicable to a .babylon loaded mesh somehow? Like clone the geometry and alter all the vertice points? And no the parent will not change scale as long as it has a child attached. And thanks Adam for that piece of code if I can't find a way solve it without creating a helper mesh to act as parent.
  13. Hey, I tried inverting some values with no luck. Could you clarify a bit of what I'd have to do? Sorry I don't have much experience with pivotMatrices.
  14. Hi, in our app we have parent & child relations tree that could be for example have this structure: rootmesh mesh mesh mesh mesh Each mesh should have their own scale so if a parent is scaled it will remove that scale by dividing the parents scale. We recently added scaling and eventually found unintended behavior where rootmesh has a non-uniform scaling and if a mesh under has a rotation it skews that mesh. As reproduced in this playground: http://www.babylonjs-playground.com/#1CWAMX#2 So I was wondering if it was possible to solve somehow by math somehow.
  15. Thanks that worked. For those wondering what I did: // Main camera has default layerMask (0x0FFFFFFF) // Outline camera has layermask 0x20000000; // When adding mesh to outline mesh.layerMask = 0x2FFFFFFF; // When clearing the outline renderTarget (disabling outline) for (let i = 0; i < renderList.length; ++i){ renderList[i].layerMask = 0x0FFFFFFF; }