首页 > 解决方案 > 将鼻子的 3D 位置值转换为 2D 值?

问题描述

只是想知道这是否曾经尝试过。

我正在制作一个游戏,其中 2D 物体从顶部落下,我用鼻子“抓住”这些物体。

目前我的设置方式是,如果鼻子和 2D 对象的 X 和 Y 值相同,它会增加计数器。

但是我注意到 3D 和 2D 对象的位置都反映了非常不同的值。

我尝试使用空对象来包含 2D 画布,但它也不起作用。

乱用公差值并没有达到预期的效果。

等于补丁

第一个数字取自空对象,第二个数字取自鼻子的位置。

从空对象:-0.09079 从鼻子:0.00108

这是与限制有关还是我在这里做错了什么?感谢您抽出宝贵时间阅读本文 :(

标签: spark-ar-studio

解决方案


这是一个将 3D 鼻子位置转换为 2D 屏幕空间的项目。我制作了一个关于如何做到这一点的视频:视频,这里是免费下载的链接。

它需要几行脚本和场景模块将 3D 位置投影到 2D 屏幕空间。

const Scene = require('Scene');
const Patches = require('Patches');

Promise.all([

    // The 3D Object or 3D Point we want to track
    Scene.root.findFirst('Nose3D'),

]).then(function (results) {

    // Define variable names for items we found
    const nose3D = results[0];

    // This transforms the world coordinate of the 3D Object to a screen coordinate.
    var nose2D = Scene.projectToScreen(nose3D.worldTransform.position)

    // Get the Nose3D Position, then set the projectToScreen point Nose2D
    Patches.outputs.getPoint("Nose3D").then(pointSignal => {

        Patches.inputs.setPoint2D('Nose2D', nose2D);

    });
});

推荐阅读