Facebook AR-Javascript

时间:2018-10-01 20:48:00

标签: javascript facebook augmented-reality

我正在使用Facebook AR Studio,并且大致遵循本教程来满足我的需求:https://blog.tallan.com/2018/04/24/facebook-ar-studio-how-to-use-tap-gestures-to-change-effect-materials/

但是,当我尝试播放项目时,它给了我一个错误-

JavaScript错误:调用功能时,本机代码中的异常:未找到孩子:ScreenCanvas 回溯

这是我使用的代码。

//includes for base libraries
var Scene = require('Scene');
var Tap = require('TouchGestures');
var Mat = require('Materials');

// base dir
var base = 
Scene.root.child('Device').child('Camera').child('Focal 
Distance');
var sCanvas = base.child('ScreenCanvas');
var NoEffectButton  = sCanvas.child('NoEffectButton');
var StageOneButton  = sCanvas.child('StageOneButton');
var effectVisibility = false;

// facemesh

var faceMesh = 
base.child('facetracker0').child('StageOneFaceMesh');


Tap.onTap(NoEffectButton).subscribe(function(event){
                                setEffectVisibility(false);
                                });

Tap.onTap(StageOneButton).subscribe(function(event){
                                faceMesh.material = 
Mat.get('coldsore');
                                setEffectVisibility(true);
                                });

function setEffectVisibility(option){
    if(effectVisibility !== option){
    effectVisibility = option;
    faceMesh.cameraVisibility.forFrontCamera = effectVisibility;
    faceMesh.cameraVisibility.forRearCamera = effectVisibility;
    faceMesh.cameraVisibility.forUnspecifiedCamera = 
effectVisibility;
   }
}

1 个答案:

答案 0 :(得分:0)

这很可能只是意味着您的场景中没有名称为“ ScreenCanvas”的对象,它是“ base”的子代。您可能只是针对某些错误或拼写错误。

尝试使用Diagnostics.log(base)以确保您定位的是正确的元素。祝你好运!