BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

Object3D.attach()

Object3D.attach() 方法用于将一个对象附加到另一个对象上,作为其子对象。附加后,子对象将随着父对象的各种变换而更新自己的位置。

parent.attach(child);

参数说明:

  • parent:父对象,Object3D 类型。
  • child:子对象,Object3D 类型。

示例代码:

// 创建父对象
const parent = new THREE.Object3D();

// 创建子对象
const child = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), new THREE.MeshBasicMaterial({ color: 0xff0000 }));

// 将子对象附加到父对象上
parent.attach(child);

注意事项:

  • 一个子对象只能拥有一个父对象,如果要改变子对象的父对象,需要先将其从原来的父对象上移除,再将其附加到新的父对象上。
  • 当子对象被附加到父对象上时,其相对位置将被重置为原点,如果需要指定子对象在父对象中的初始位置,可以手动设置其坐标属性。
  • 当编辑子对象的位置时,不要直接修改其 position 属性,而应该通过修改父对象的变换属性(如 rotation, position, scale)来实现。