我开始从 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;
}