Jump to content

how to compute boundingInfo of imported meshes


roland zhang
 Share

Recommended Posts

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;
    });

 

Link to comment
Share on other sites

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));
    };

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...