'cannot set property 'rotationX' of undefined
Im doing a Christmas based filter where i want my body to stay static and does not rotate according to the face movement. I have a code for that but for some reason, this error shows up "cannot set property 'rotationX' of undefined". Can someone help on how to fix this? Running on Spark AR v104
Here is the code:
var Scene = require('Scene');
var Textures = require('Textures');
var Materials = require('Materials');
var FaceTracking = require('FaceTracking');
var Animation = require('Animation');
var Reactive = require('Reactive');
var TouchGestures = require('TouchGestures');
const Instruction = require('Instruction');
var face = FaceTracking.face(0);
var neck = Scene.root.findFirst('Bone.004');
var neckmovement = 80;
neck.transform.rotationX = face.cameraTransform.rotationX.mul(-1.0).sum(0).expSmooth(neckmovement);
neck.transform.rotationY = face.cameraTransform.rotationZ.mul(1.0).sum(0).expSmooth(neckmovement);
neck.transform.rotationZ = face.cameraTransform.rotationY.mul(-1.0).sum(0).expSmooth(neckmovement);
Solution 1:[1]
findFirst
returns a promise (https://sparkar.facebook.com/ar-studio/learn/reference/classes/scenemodule.scene/#methods). So you need to do something like this:
var Scene = require('Scene');
var Textures = require('Textures');
var Materials = require('Materials');
var FaceTracking = require('FaceTracking');
var Animation = require('Animation');
var Reactive = require('Reactive');
var TouchGestures = require('TouchGestures');
const Instruction = require('Instruction');
(async function() {
var face = FaceTracking.face(0);
var neck = await Scene.root.findFirst('Bone.004');
var neckmovement = 80;
neck.transform.rotationX = face.cameraTransform.rotationX.mul(-1.0).sum(0).expSmooth(neckmovement);
neck.transform.rotationY = face.cameraTransform.rotationZ.mul(1.0).sum(0).expSmooth(neckmovement);
neck.transform.rotationZ = face.cameraTransform.rotationY.mul(-1.0).sum(0).expSmooth(neckmovement);
})();
Or you could decide to use .then(...)
on the promise if you don't want to wrap everything in an async function. But I would recommend the async function approach as it'll make things a little easier in your code most likely.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mattjgalloway |