【问题标题】:Is there a way to know the "real" position of an a-frame element?有没有办法知道 a-frame 元素的“真实”位置?
【发布时间】:2016-11-16 18:23:39
【问题描述】:

我想找到一个框架元素的“真实”位置。不是position 属性中显示的那个。但是那个是所有父母和相对于世界/场景位置的总和?

【问题讨论】:

    标签: aframe


    【解决方案1】:

    可以在three.js中搜索查找世界坐标:https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=threejs+get+world+position

    它看起来像:

    var worldPos = new THREE.Vector3();
    worldPos.setFromMatrixPosition(el.object3D.matrixWorld);
    

    【讨论】:

    • 链接打不开。什么是矩阵世界?
    【解决方案2】:

    为了从 2021 年/从 A-Frame 1.1.0 的角度给出更完整/更新的答案,

    here所述,

    var parent = new THREE.Object3D();
    parent.position.set(100, 100, 100);
    
    var child = new THREE.Object3D();
    child.position.set(100, 100, 100);
    parent.add(child);
    
    scene.add(parent);
    
    var target = new THREE.Vector3(); // create once an reuse it
    
    child.getWorldPosition( target );
    

    target 将包含结果。

    用A-Frame来说,应该是,

    AFRAME.registerComponent('some-component', {
      init() {
        const realWorldPosition = this.el.object3D.getWorldPosition(new THREE.Vector3())
      },
    };
    

    【讨论】:

      猜你喜欢
      • 2021-12-20
      • 1970-01-01
      • 2012-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-20
      相关资源
      最近更新 更多