jerome Posted January 28, 2016 Share Posted January 28, 2016 I retrieve this old post because I wasn't satisfied by my result : Actually, I'm trying to set some fixed values to a mesh bounding box, different from the computed ones. I would like these fixed values to keep stored then forever, so not recomputed. http://www.babylonjs-playground.com/#1OOAYL what I did ? I created a mesh, then scaled its BB, then froze its World Matrix so it isn't computed any longer. I expected to keep and display the BB scaled values... this is not what I get. Where's my error ? and is this possible to set forever a fixed BB for a given (frozen) mesh ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 28, 2016 Share Posted January 28, 2016 Wrong use of Scaling:) and you should freeze THEN update (else freeze will force a computation of the worldmatrix which in turn will update the BB) http://www.babylonjs-playground.com/#1OOAYL#1 Quote Link to comment Share on other sites More sharing options...
jerome Posted January 28, 2016 Author Share Posted January 28, 2016 crystal clear ! thanks a lot Quote Link to comment Share on other sites More sharing options...
jerome Posted January 28, 2016 Author Share Posted January 28, 2016 but... is there a way to set BB fixed values (at least scaling ones) whatever the mesh world matrix would be recomputed or not ? [EDIT] I'm reading the BBox code and I understand that its 8 vertices are recomputed on the call to _update(matrix) : https://github.com/BabylonJS/Babylon.js/blob/master/src/Culling/babylon.boundingBox.ts#L56 AFAIUndersand, these 8 vertices are compared in turn with the transformed (by the passed matrix) 8 world vertices. Ok, this means we apply the same transformation to the BBox than the one applied to its embedded mesh. What I don't find in the code is where the BBox is recomputed if the mesh has its World matric frozen and don't even move, rotate or scale, but is updated, so when the mesh vertices change their positions. http://www.babylonjs-playground.com/#1JFDFW#2 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 28, 2016 Share Posted January 28, 2016 it is because of that guy: https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.geometry.ts#L90 jerome 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted January 29, 2016 Author Share Posted January 29, 2016 Damn ! I read this part of code twice yet but didn't understand what the variable meshes was about. I thought it was about subMeshes or something like this. Not about iterating over each mesh vertex here. Quote Link to comment Share on other sites More sharing options...
jerome Posted January 29, 2016 Author Share Posted January 29, 2016 There is still something I don't get about the BBox and Pickability (or visibility). Please have a look at this : http://www.babylonjs-playground.com/#1JFDFW#6 Everything is done from the line 216 : sps.setParticles(); // set them s.freezeWorldMatrix(); // freeze the mesh world matrix sps.refreshVisibleSize(); // force BB recomputation once s.getBoundingInfo().update(BABYLON.Matrix.Scaling(5, 5, 100)); // set BB fixed values s.showBoundingBox = true; // show the BB As you can see, the mesh World Matrix is frozen, the BBox is computed once from the current vertex positions and then scaled once. If you try the PG, you can blow the wall particle mesh. Then once the particles are on the ground AND still within the BBox they aren't pickable any longer. Now, if I uncomment the line 210 what forces the BBox recomputation each frame, I get this : http://www.babylonjs-playground.com/#1JFDFW#7 If you try to pick the particles on the ground they are still pickable. I thought that the pickability was related to the current BBox size. Did I miss something anywhere ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 29, 2016 Share Posted January 29, 2016 So you did it right BUT the picking use ray casting in local object coordinates. So you also have so setup the local world bounding info values like here: http://www.babylonjs-playground.com/#1JFDFW#12 Quote Link to comment Share on other sites More sharing options...
jerome Posted January 30, 2016 Author Share Posted January 30, 2016 This works perfectly. Huge thanks !!! GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.