将鼻子的3D位置值转换为2D值?

问题描述

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

我正在做一个游戏,其中2D对象从顶部掉落,然后用鼻子“抓住”这些对象。

目前,我将其设置为如果鼻子和2D对象的X和Y值相同,则会增加计数器。

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

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

在公差值附近乱搞并没有达到预期的效果

Equals Patch

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

来自nullobject:-0.09079 从鼻子:0.00108

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

解决方法

这是一个将3D鼻子位置转换为2D屏幕空间的项目。我制作了一个有关如何执行此操作的视频:video,这里是free download的链接。

需要几行脚本和场景模块才能将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);

    });
});