three.js 在另一个对象的本地坐标系中设置对象
three.js set objects in local coordinate system of another object
我想知道是否可以将 3d 对象放置在 three.js 中另一个对象的局部坐标系中。所以放置的对象应该是相对于 "origin" 对象。
例如:我使用设备相机(使用 expo AR)扫描图像,并希望放置与图像有固定距离的物体。我认为这些位置是相对于相机的,不是吗?
this.scene.add(chair)
chair.position.set( 1, 0, -5);
this.scene.add(chair2)
chair2.position.set( 1, 0 , -3);
我认为您要查找的是 THREE.Group
对象。它允许您将元素嵌套在一个组中,因此如果您更改组的坐标,它的子项也会随之移动。例如:
// Create parent, set its pos to 0, 5, 0
var parent = new THREE.Group();
scene.add(parent);
parent.position.set(0, 5, 0);
// create child, and add to parent
var chair1 = new THREE.Mesh(geom, mat);
parent.add(chair1);
chair1.position.set(1, 0, 0);
// create child, and add to parent
var chair2 = new THREE.Mesh(geom, mat);
parent.add(chair2);
chair2.position.set(0, 1, 0);
- 椅子 1 在全局坐标中位于
[1, 5, 0]
,但在局部坐标中 [1, 0, 0]
space。
- 椅子 2 在全局坐标中位于
[0, 6, 0]
,但在局部坐标中 [0, 1, 0]
space。
我想知道是否可以将 3d 对象放置在 three.js 中另一个对象的局部坐标系中。所以放置的对象应该是相对于 "origin" 对象。
例如:我使用设备相机(使用 expo AR)扫描图像,并希望放置与图像有固定距离的物体。我认为这些位置是相对于相机的,不是吗?
this.scene.add(chair)
chair.position.set( 1, 0, -5);
this.scene.add(chair2)
chair2.position.set( 1, 0 , -3);
我认为您要查找的是 THREE.Group
对象。它允许您将元素嵌套在一个组中,因此如果您更改组的坐标,它的子项也会随之移动。例如:
// Create parent, set its pos to 0, 5, 0
var parent = new THREE.Group();
scene.add(parent);
parent.position.set(0, 5, 0);
// create child, and add to parent
var chair1 = new THREE.Mesh(geom, mat);
parent.add(chair1);
chair1.position.set(1, 0, 0);
// create child, and add to parent
var chair2 = new THREE.Mesh(geom, mat);
parent.add(chair2);
chair2.position.set(0, 1, 0);
- 椅子 1 在全局坐标中位于
[1, 5, 0]
,但在局部坐标中[1, 0, 0]
space。 - 椅子 2 在全局坐标中位于
[0, 6, 0]
,但在局部坐标中[0, 1, 0]
space。