Javascript 在三个JS中从场景中移除组类型GLTF对象
我正在尝试从场景中删除一组对象,Javascript 在三个JS中从场景中移除组类型GLTF对象,javascript,three.js,Javascript,Three.js,我正在尝试从场景中删除一组对象,scene.remove(group)无效 这是我的加载器: GLTFloader.load( src+'.gltf', function ( gltf ) { gltf.scene.traverse( function ( child ) { if(child.type === "Group") { ne
scene.remove(group)
无效
这是我的加载器:
GLTFloader.load( src+'.gltf', function ( gltf ) {
gltf.scene.traverse( function ( child ) {
if(child.type === "Group")
{
newObject = true;
GLTFobjects.push(child);
}
if ( child.isMesh ) {
child.receiveShadow = true;
child.castShadow = true;
child.material.transparent = true;
child.material.opacity = 0.7;
}
} );
scene.add( gltf.scene );
},function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
// called when loading has errors
function ( error ) {
console.log( 'An error happened' );
console.log(error);
}
);
GLTFobjects是包含所有“我的对象”的全局数组
GLTFobjects的每个成员都是组类型,假设应该删除此数组的第一个元素
我尝试了以下方法:
scene.remove(GLTFobjects[0])
以及:
甚至:
GLTFobjects[0].traverse(function (e) {
scene.remove(e);
});
什么都没起作用
如何从场景中删除组对象
注:
GLTFobjects[0]
如下所示(如果有帮助):
{…}卡斯特:错子数组:数组(7)[{…},{…},{…},{…},]沮丧的:是的身份证号码:24层:对象{掩码:1}矩阵:对象{元素:(16)[…]}Matrix自动更新:truematrixWorld:对象{元素:(16)[…]}matrixWorldNeedsUpdate:falsemodelViewMatrix:对象{元素:(16)[…]}姓名:“House3”normalMatrix:对象{元素:(9)[…]}父对象:对象{uuid:“E6BE42B7-C7D3-4617-83E5-83EACD0948B6”,名称:“场景”,类型:“场景”,…}位置:对象{x:0,y:1.1222255299949951,z:-16.519949752598595}四元数:对象{{ux:0,{uy:0,{uz:0,…}接收阴影:错误渲染器:0旋转:对象{{ux:0,{uy:0,{uz:0,…}比例:对象{x:1,y:1,z:1}类型:“组”向上:对象{x:0,y:1,z:0}用户数据:对象{}uuid:“9F7508DD-E1C2-481D-AF49-57EE3973C27F”可见:正确: 对象{构造函数:Group(),isGroup:true}
gltf。场景
已添加到场景
中,而不是添加到GLTFobjects
组中
如果添加了GLTFobjects
,则只需执行以下操作:
移除(GLTFobjects.getObjectByName(“多维数据集”)
或
GLTFobjects.remove(GLTFobjects.children[0])
GLTFobjects[0].traverse(function (e) {
scene.remove(e);
});
{…}castShadow: falsechildren: Array(7) [ {…}, {…}, {…}, … ]frustumCulled: trueid: 24layers: Object { mask: 1 }matrix: Object { elements: (16) […] }matrixAutoUpdate: truematrixWorld: Object { elements: (16) […] }matrixWorldNeedsUpdate: falsemodelViewMatrix: Object { elements: (16) […] }name: "House3"normalMatrix: Object { elements: (9) […] }parent: Object { uuid: "E6BE42B7-C7D3-4617-83E5-83EACD0948B6", name: "Scene", type: "Scene", … }position: Object { x: 0, y: 1.1222255229949951, z: -16.519949752598595 }quaternion: Object { _x: 0, _y: 0, _z: 0, … }receiveShadow: falserenderOrder: 0rotation: Object { _x: 0, _y: 0, _z: 0, … }scale: Object { x: 1, y: 1, z: 1 }type: "Group"up: Object { x: 0, y: 1, z: 0 }userData: Object { }uuid: "9F7508DD-E1C2-481D-AF49-57EE3973C27F"visible: true<prototype>: Object { constructor: Group(), isGroup: true }