当前位置:   article > 正文

【three.js】scene场景的常用属性和方法

【three.js】scene场景的常用属性和方法

children

返回场景中的对象列表

const children = scene.children
  • 1

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)
  • 1
  • 2
  • 3
  • 4

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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

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)
  • 1
  • 2
  • 3
  • 4
  • 5

traverse

遍历调用者和调用者的所有后代,接受一个函数作为参数,被调用者和它的所有后代,都会调用该函数

 scene.traverse(child => {
 	console.log(child.name)
 })
  • 1
  • 2
  • 3

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/96029
推荐阅读
相关标签
  

闽ICP备14008679号