我有一个 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
最佳答案
您需要做的是使用 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/
希望这对您有所帮助!
关于javascript - 获取 Facebook AR 中 3d 对象的位置并通过脚本更改它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52866646/