获取3D对象在Facebook AR中的位置,并通过脚本进行更改

时间:2018-10-18 03:37:14

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

我有一个3d对象,我想通过脚本从A“移动”到B。我不太确定如何去做。我不了解Facebook文件。只是一个简短的例子就可以了。

我假设一些事情:

var object = Scene.root.find("object");
var lastPosX = object.transform.positionX.lastValue;
object.transform.positionX = //NOT SURE HOW TO PUT THE NEW POSITION

1 个答案:

答案 0 :(得分:1)

您需要做的是使用AnimationModule-这是一个简单的示例:

const Animation = require('Animation');
var obj = Scene.root.find("object");

//set up the length of the animations, 1000 = 1 second
var driver = Animation.timeDriver({durationMilliseconds: 1000});

//define the starting and ending values (start at 0, go to 100)
var sampler = Animation.samplers.linear(0, 100);

//create an animation signal to control the object x position
obj.transform.x = Animation.animate(driver, sampler);

//start the animation
driver.start();

与许多其他内容一样,ARS中的动画基于“反应性编程”的概念并与“信号”一起使用,“信号”是随时间变化的值。掌握信号是什么以及如何在ARS中编写有用的代码非常重要。请通读以下内容以获得简介性概述:https://developers.facebook.com/docs/ar-studio/scripting/basics

以上是一个非常基本的示例,但是使用AnimationModule可以实现更多有趣,高级和复杂的效果,请查看此处的文档以获取更多信息:https://developers.facebook.com/docs/ar-studio/reference/classes/animationmodule/

希望这会有所帮助!