Facebook ARStudio:如何设置对象位置?

时间:2018-01-04 02:05:50

标签: javascript facebook augmented-reality spark-ar-studio

我开始从Facebook尝试ARStudio,但我无法弄清楚如何从脚本中设置对象的位置。 我尝试了类似下面的内容,但似乎object.transform.x(or y, z)采用“ScalarSignal”而不是数值。如何在ARStudio中设置对象的位置?

class Vector3{
    constructor(xPos = 0, yPos = 0, zPos = 0){
        var x = xPos;
        var y = yPos;
        var z = zPos;
    }
}

const FaceTracking = require("FaceTracking");
const Diagnostics = require("Diagnostics");
const Scene = require("Scene");

var sphere = Scene.root.child("sphere");
var spherePosition = new Vector3()

var mouthCenter = FaceTracking.face(0).mouth.center;
var mouthCenterPosition = new Vector3();

mouthCenter.x.monitor().subscribe(function(e){
    if(e.newValue){
        mouthCenterPosition.x = mouthCenter.x.lastValue;
    }
});

mouthCenter.y.monitor().subscribe(function(e){
    if(e.newValue){
        mouthCenterPosition.y = mouthCenter.y.lastValue;
    }
});

mouthCenter.z.monitor().subscribe(function(e){
    if(e.newValue){
        mouthCenterPosition.z = mouthCenter.z.lastValue;
    }
    // Diagnostics.log(mouthCenterPosition);
    SetSpherePosition(mouthCenterPosition);
});

function SetSpherePosition(pos){
    //This part is causing error...
    sphere.transform.x = pos.x;
    sphere.transform.y = pos.y;
    sphere.transform.z = pos.z;
}

1 个答案:

答案 0 :(得分:1)

这可能会有所帮助:https://developers.facebook.com/docs/ar-studio/reference/reactive_module/transformsignal_class

另外,尝试类似

sphere.transform.position = mouthCenterPosition; 

我认为球体对象可能包含此转换模块,然后该模块具有可以修改的position属性。我相信像这样设置一个相等值是如何在React中“绑定”。我是React的新手,我也将不胜感激关于此答案的任何其他帮助!