children
返回场景中的对象列表
const children = scene.children
add
向场景中添加模型、灯光等,还可以添加对象组
const geometry = new THREE.BoxGeometry(10, 10, 10)
const material = new THREE.MeshBasicMaterial({color: 0x00ff00})
const cube = new THREE.Mesh(geometry, material)
scene.add(cube)
getObjectByName
查找场景中特定名字的对象
const geometry = new THREE.BoxGeometry(10, 10, 10)
const material = new THREE.MeshBasicMaterial({color: 0x00ff00})
const cube = new THREE.Mesh(geometry, material)
cube.name = 'cube'
scene.add(cube)
scene.getObjectByName('cube', true)
remove
将指定对象从场景中的移除
const geometry = new THREE.BoxGeometry(10, 10, 10)
const material = new THREE.MeshBasicMaterial({color: 0x00ff00})
const cube = new THREE.Mesh(geometry, material)
scene.add(cube)
scene.remove(cube)
traverse
遍历调用者和调用者的所有后代,接受一个函数作为参数,被调用者和它的所有后代,都会调用该函数
scene.traverse(child => {
console.log(child.name)
})