Three.js - Wrong Bounding Box importing Blender JSON model

半城伤御伤魂 提交于 2019-12-12 12:27:13

问题


I am having some problems manipulating the objects I load from Blender. I think the pivot point is always set to 0,0,0 instead of the current object's position. I correctly position and import the objects in the Blender scene, but then I have problems rotating them.

I have used BoundingBoxHelper to see what is happening, but the bounding box is not appearing surrounding the object but centered in the world and with a 1-unit size (I guess that is the default)

This is the code I use to load the alien:

texture6 = THREE.ImageUtils.loadTexture('images/alien1.png', {}, function() {
        renderer.render(scene, camera);
    });

    loader = new THREE.JSONLoader();
    loader.load( "models/alien1.js", function( geometry ) {
        geometry.computeFaceNormals();
        geometry.computeCentroids();
        geometry.computeBoundingBox();

        var mat = new THREE.MeshBasicMaterial({map: texture6,transparent: true, color:0x00FF00} );
        var mesh = new THREE.Mesh( geometry, mat );
        scene.add(mesh);

        bbHelper = new THREE.BoundingBoxHelper( mesh, 0xff0000 );
        scene.add( bbHelper );
    });

And this is the result: (The red bounding box should be surrounding the green alien but is in the center of the scene)

Any suggestions?


回答1:


You need to call bbHelper.update().

Make the call in the render loop if the object is moving.

three.js r.59



来源:https://stackoverflow.com/questions/17775687/three-js-wrong-bounding-box-importing-blender-json-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!