spark-ar-studio - 将鼻子的 3D 位置值转换为 2D 值?
问题描述
只是想知道这是否曾经尝试过。
我正在制作一个游戏,其中 2D 物体从顶部落下,我用鼻子“抓住”这些物体。
目前我的设置方式是,如果鼻子和 2D 对象的 X 和 Y 值相同,它会增加计数器。
但是我注意到 3D 和 2D 对象的位置都反映了非常不同的值。
我尝试使用空对象来包含 2D 画布,但它也不起作用。
乱用公差值并没有达到预期的效果。
第一个数字取自空对象,第二个数字取自鼻子的位置。
从空对象:-0.09079 从鼻子:0.00108
这是与限制有关还是我在这里做错了什么?感谢您抽出宝贵时间阅读本文 :(
解决方案
这是一个将 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);
});
});
推荐阅读
- javascript - 类型错误:标记__WEBPACK_IMPORTED_MODULE_3___default(...) 不是函数
- mongodb - 为什么 Oplog 会减少 Mongodb
- excel - Excel - 查找简单的四分位数练习时结果错误
- algorithm - 用于排序的重新洗牌次数
- regex - 正则表达式匹配模式并在 之后提取字段:
- yolov5 - 自定义数据标签和训练-YoloV5检测问题
- javascript - JavaScript中的“函数(错误,结果)”是什么意思
- ruby-on-rails - 如何从 Heroku 中托管的 Rails API 应用程序在浏览器中设置 cookie,该应用程序在 Netlify 中托管的 React 应用程序中运行前端?
- c# - 使用 multipart/form-data 将照片发布到 Facebook 粉丝专页
- flutter - 是否有可能使颤振:扩展面板小部件反向扩展?