【问题标题】:three.js set objects in local coordinate system of another object三.js在另一个对象的局部坐标系中设置对象
【发布时间】:2019-01-08 02:16:06
【问题描述】:

我想知道是否可以将 3d 对象放置在 three.js 中另一个对象的局部坐标系中。所以放置的对象应该是相对于“原点”对象的。

例如:我使用设备相机(使用 expo AR)扫描图像,并希望放置与图像具有固定距离的物体。我认为这些位置是相对于相机的,不是吗?

             this.scene.add(chair)
            chair.position.set(  1, 0,  -5);

            this.scene.add(chair2)
            chair2.position.set( 1, 0 ,  -3);

【问题讨论】:

    标签: three.js augmented-reality expo


    【解决方案1】:

    我认为您正在寻找的是 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);
    
    • chair1 在全球坐标中位于[1, 5, 0],但在本地空间中位于[1, 0, 0]
    • chair2 在全球坐标中位于[0, 6, 0],但在本地空间中位于[0, 1, 0]

    【讨论】:

    • 感谢一百万。子对象现在完全相对于主对象:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-07
    • 1970-01-01
    相关资源
    最近更新 更多