• Content count

  • Joined

  • Last visited

  1. 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; };
  2. 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
  3. 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
  4. 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 );
  5. 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?
  6. 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.
  7. 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.
  8. @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
  9. 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
  10. 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(); }
  11. 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
  12. 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?
  13. 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!
  14. 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.
  15. 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.