加载后从object3D获取材质

时间:2017-06-28 15:15:50

标签: javascript three.js

我想在加载后从对象获取一个材质,但我无法访问我的对象的子项

function loadObject () {
    var loader = new THREE.OBJLoader();
    var container = new THREE.Object3D();
    var mesh  = null;
    loader.load( this.link , function ( object ) {
        object.traverse(function (child) {
            if(child instanceof THREE.Mesh){
                var geometry  =  new THREE.Geometry().fromBufferGeometry(child.geometry);
                mesh = new THREE.Mesh(geometry, child.material);
                mesh.name = 'tibia';
                container.add( mesh );
                console.log(container.children.length);
            }
        });
    });
    return container;
};

var myObject = loadObject();

0 个答案:

没有答案