roland zhang Posted July 30, 2018 Share Posted July 30, 2018 following is the example: https://www.babylonjs-playground.com/#UCDS98#3 the computed boundingInfo is very bigger than the real objects. var group = new BABYLON.Mesh('g',scene); group.refreshBoundingInfo = function () { var children = this.getChildren(); //children[0].refreshBoundingInfo(); var boundingInfo = children[0].getBoundingInfo(); var min = boundingInfo.minimum.add(children[0].position); var max = boundingInfo.maximum.add(children[0].position); for (var i = 1; i < children.length; i++) { //children[i].refreshBoundingInfo(); boundingInfo = children[i].getBoundingInfo(); min = BABYLON.Vector3.Minimize(min, boundingInfo.minimum.add(children[i].position)); max = BABYLON.Vector3.Maximize(max, boundingInfo.maximum.add(children[i].position)); } this.setBoundingInfo(new BABYLON.BoundingInfo(min, max)); }; BABYLON.SceneLoader.ImportMesh('','https://raw.githubusercontent.com/rolandzhang/jqextension/master/','door.babylon',scene,function(meshes){ meshes.forEach(function(el){ if (el.getTotalVertices()>0){ el.parent = group; //el.showBoundingBox = true; } }); group.refreshBoundingInfo(); group.showBoundingBox = true; }); Quote Link to comment Share on other sites More sharing options...
Guest Posted July 30, 2018 Share Posted July 30, 2018 Hello, I think I already answered this topic :0 You forgot to take scaling in account in your refreshBoundingInfo function Quote Link to comment Share on other sites More sharing options...
roland zhang Posted July 31, 2018 Author Share Posted July 31, 2018 @Deltakosh Thanks but I still don't know how to handle the boudingInfo's scaling, because boundingInfo's scale method accept only one parameter, and meshes's scaling property is a Vector3, and x, y, z are different values. Quote Link to comment Share on other sites More sharing options...
roland zhang Posted July 31, 2018 Author Share Posted July 31, 2018 I tried this way, but the result still wrong. https://www.babylonjs-playground.com/#UCDS98#4 var getMinMax = function(mesh){ var info = mesh.getBoundingInfo(); var min = info.minimum.multiply(mesh.scaling).add(mesh.position); var max = info.maximum.multiply(mesh.scaling).add(mesh.position); return {min:min, max:max}; }; group.refreshBoundingInfo = function () { var children = this.getChildren(); //children[0].refreshBoundingInfo(); var mm = getMinMax(children[0]); var min = mm.min; var max = mm.max; for (var i = 1; i < children.length; i++) { //children[i].refreshBoundingInfo(); mm = getMinMax(children[i]); min = BABYLON.Vector3.Minimize(min, mm.min); max = BABYLON.Vector3.Maximize(max, mm.max); } this.setBoundingInfo(new BABYLON.BoundingInfo(min, max)); }; Quote Link to comment Share on other sites More sharing options...
roland zhang Posted July 31, 2018 Author Share Posted July 31, 2018 This happened only in babylon file, the obj file's boudingInfo is correct, same 3dmax model export to obj file. https://www.babylonjs-playground.com/#UCDS98#5 Quote Link to comment Share on other sites More sharing options...
Guest Posted July 31, 2018 Share Posted July 31, 2018 But you don't need all of that You can just use the minimumWorld and maximumWorld properties of the BoundingBox: https://www.babylonjs-playground.com/#UCDS98#8 Quote Link to comment Share on other sites More sharing options...
roland zhang Posted August 1, 2018 Author Share Posted August 1, 2018 @Deltakosh Thanks 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.