如何删除或隐藏three.js中加载的stl

时间:2018-04-19 09:53:04

标签: three.js

如何根据条件删除hide loaded.load three.js例如id为door condition = 0,如果将加载flame.stl并反转

function checkDoorStatus(isDoorOpen,prevIsDoorOpen){

                if ( isDoorOpen == 1)
                {

                    var loader = new THREE.STLLoader();
                    loader.load( 'model/panic.stl', function ( geometry ) {

                    var material = new THREE.MeshPhongMaterial( { color: 0xa80306, specular: 0x111111, shininess: 200 } );
                    var mesh = new THREE.Mesh( geometry, material );    
                    mesh.position.set( 0.145, -0.3, -0.29);
                    mesh.rotation.set( 0 , 0, Math.PI / 2 );
                    mesh.scale.set( 0.05, 0.05, 0.05);
                    mesh.castShadow = true;
                    mesh.receiveShadow = true;
                    scene.add( mesh );
                    } );

                    //console.log("Panic 1");

                }
                else if (isDoorOpen == 0)
                {

                    var loader = new THREE.STLLoader();
                    loader.load( 'model/flame.stl', function ( geometry ) {

                    var material = new THREE.MeshPhongMaterial( { color: 0xa80306, specular: 0x111111, shininess: 200 } );
                    var mesh = new THREE.Mesh( geometry, material );    
                    mesh.position.set( 0.145, -0.3, -0.29);
                    mesh.rotation.set( 0 , 0, Math.PI / 2 );
                    mesh.scale.set( 0.05, 0.05, 0.05);
                    mesh.castShadow = true;
                    mesh.receiveShadow = true;
                    scene.add( mesh );
                    } );

                    //console.log("Panic 0");
                }       


        }

1 个答案:

答案 0 :(得分:0)

根据我的理解,您希望根据某些条件一次只显示一个网格。如果是这种情况,一种可能的解决方案是在添加到场景之前为网格命名,并在添加新门之前根据其名称移除旧门。例如

mesh.name = "openDoor"; scene.remove(scene.getObjectByName("closedDoor")); scene.add( mesh )

希望它有所帮助。