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
)来实现。