Feldspar Posted April 3, 2014 Share Posted April 3, 2014 Hi guys, I'm having trouble positioning objects on my scene. Here is the context :I'm having 3 objects "table" on which the position is effectively non zero These 3 objects have a non-visible "floor" parent mesh, for the purpose of local positionning : Unfortunately, all these table meshes appears at the center of the scene. The girl is in (0,0,0) for reference : The solution I have found for the meshes to appear in the right spot, is to add this hella dirty code, just after i finish adding the objects :setTimeout(function() {floor.markAsDirty()}, 100);Here is the result : If i don't use a setTimeout, and mark the floor as dirty right away, the tables are still in (0, 0, 0)Any thoughts on what to update in the hierarchy, so I can get my objects in their right position ? Thanks Quote Link to comment Share on other sites More sharing options...
gwenael Posted April 3, 2014 Share Posted April 3, 2014 Does it work without the setTimeout and if the non-visible "floor" parent mesh is visible? Quote Link to comment Share on other sites More sharing options...
Feldspar Posted April 3, 2014 Author Share Posted April 3, 2014 I can't set the floor parent mesh to visible, it has no vertices Edit : I tried to set the floor mesh to a simple cube, so I can set it to visible, but the problem is still there. Quote Link to comment Share on other sites More sharing options...
Artem Posted April 3, 2014 Share Posted April 3, 2014 Do you use '.setPhysicsState' properties? Quote Link to comment Share on other sites More sharing options...
Feldspar Posted April 3, 2014 Author Share Posted April 3, 2014 No I don't Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 3, 2014 Share Posted April 3, 2014 Could you call: mesh.computeWorldMatrix(true) ? If this works I'm really interested by getting your sample because you should definitely not have to do that Quote Link to comment Share on other sites More sharing options...
Feldspar Posted April 3, 2014 Author Share Posted April 3, 2014 @Deltakosh, already done, and it already failed i'm really stuck with this. I'll try to reproduce it on a simpler test case. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 3, 2014 Share Posted April 3, 2014 Yes please I'll figure out what is going wrong;) Quote Link to comment Share on other sites More sharing options...
Feldspar Posted April 4, 2014 Author Share Posted April 4, 2014 Okay i found it, it turns out when I import the tables, I have a function that recursively computes bounding boxes of the table and its children.This custom function uses computeWorldMatrix on the mesh, and by some way I don't really understand, it prevented the table from being updated on the scene. Any idea why Deltakosh ? Oh, and here is the custom function. It computes an overall boundingbox of the object and its children in the object's local frame :BABYLON.Mesh.prototype.getBoundingBox = function(force) { if(!force && this.boundingBox) { return this.boundingBox; } var minX = Infinity, minY = Infinity, minZ = Infinity, maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity; // Put back the bounding box in the local frame this.computeWorldMatrix(); var worldToObject = this.getWorldMatrix().clone(); worldToObject.invert(); var customTraverse = function(mesh) { mesh.computeWorldMatrix(); var subObjectToWorld = mesh.getWorldMatrix().clone(); // Top level Object local frame var subObjectToObject = subObjectToWorld.multiply(worldToObject); if(mesh instanceof BABYLON.Mesh && mesh.isVisible) { var minMax = BABYLON.Tools.ExtractMinAndMaxWithTransform(mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind), 0, mesh._totalVertices, subObjectToObject); var Minimum = minMax.minimum; var Maximum = minMax.maximum; // compute overall bbox minX = Math.min(minX, Minimum.x); minY = Math.min(minY, Minimum.y); minZ = Math.min(minZ, Minimum.z); maxX = Math.max(maxX, Maximum.x); maxY = Math.max(maxY, Maximum.y); maxZ = Math.max(maxZ, Maximum.z); } var children = mesh.getChildren(); for(var i = 0, l = children.length; i < l; i++) { customTraverse(children[i]); } }; customTraverse(this); var bBox_min = new BABYLON.Vector3(minX, minY, minZ); var bBox_max = new BABYLON.Vector3(maxX, maxY, maxZ); this._boundingInfo = new BABYLON.BoundingInfo(bBox_min, bBox_max); return this._boundingInfo.boundingBox;}; Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 5, 2014 Share Posted April 5, 2014 Umf...I suspect the problem is coming from the fact that you are using this._boundingInfo which is already used by babylon To be sure to not override babylon.js objects, I suggest that you use __ instead of _ Quote Link to comment Share on other sites More sharing options...
Feldspar Posted April 7, 2014 Author Share Posted April 7, 2014 That's very likely the problem is here..Thanks for your help ! 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.