0

I started experimenting the ARStudio from Facebook but I couldn't figure out how can I set the position of the object from a script. I tried something like down below but seems like object.transform.x(or y, z) takes "ScalarSignal" instead of numeric value. How do I set the positions of objects in 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;
}
peterept
  • 4,407
  • 23
  • 32
Tats
  • 69
  • 1
  • 2
  • 10

2 Answers2

1

This may help: https://developers.facebook.com/docs/ar-studio/reference/reactive_module/transformsignal_class

Additionally, try something like

sphere.transform.position = mouthCenterPosition; 

The sphere object I think is likely to contain this transform module, which then has a position property you can modify. I believe setting an equal like this is how to "bind" in React. I'm new to React, any other help on this answer would be appreciated by me as well!

0

If you need just apply the sphere to the mouth center you can use

sphere.transform.x = face.cameraTransform.applyToPoint(mouth.center).x; sphere.transform.y = face.cameraTransform.applyToPoint(mouth.center).y;

Daria
  • 1