多个THREE.LOD对象都同时改变状态

时间:2016-05-19 21:03:01

标签: three.js

我正在设计一个城市模型,并希望基于此示例实现LOD:http://threejs.org/examples/#webgl_lod

出于测试目的,我已经加载了我的建筑物的一个子集,并为每个建筑物创建了一个LOD实例。 问题是,当我试图放大其中一个时,它们似乎都在同时改变状态。我期待着我正在缩小的混凝土建筑会改变状态,但不会改变那些遥远的地方。

在这里,我创建了LOD并将它们添加到场景

var geometries = [
    [ new THREE.ExtrudeGeometry(rectShape, {steps: 2, amount: height, bevelEnabled: true, bevelSegments: 1, bevelSize: 0.1, bevelThickness: 0.1 }), 50 ],
    [ new THREE.ExtrudeGeometry(rectShape, {steps: 1, amount: height, bevelEnabled: true, bevelSegments: 1, bevelSize: 0.1, bevelThickness: 0.1 }), 300 ],
    [ new THREE.ExtrudeGeometry(rectShape, {steps: 0, amount: height, bevelEnabled: true, bevelSegments: 1, bevelSize: 0.1, bevelThickness: 0.1 }), 1000 ]
];

var materials = [
    new THREE.MeshLambertMaterial( {color: "rgb(255,0,0)" }),
    new THREE.MeshLambertMaterial( {color: "rgb(0,255,0)" }),
    new THREE.MeshLambertMaterial( {color: "rgb(0,0,255)" })
];


var lod = new THREE.LOD();
for (var i = 0; i < geometries.length; i ++ ) {
    //update
    geometries[i][0].computeBoundingBox();
    if(geometries[i][0].boundingBox.min.z<0){
            zDiff = geometries[i][0].boundingBox.min.z;
    }

    matrix.makeTranslation(-fCenterX,-fCenterY,-zDiff);
    geometries[i][0].applyMatrix(matrix);
    geometries[i][0].rotateX(-3.1415*0.5);
    //end update
    var mesh = new THREE.Mesh( geometries[ i ][ 0 ], materials[i] );
    mesh.updateMatrix();

    lod.addLevel( mesh, geometries[ i ][ 1 ] );

}

scene.add( lod );

根据示例,在我的render()中:

scene.updateMatrixWorld();
scene.traverse(function(obj){
if(obj instanceof THREE.LOD){
        obj.update(camera);
    }
});

renderer.render(scene, camera);
rendererStats.update(renderer);

我对明显的事情一无所知吗?

0 个答案:

没有答案