Spark AR 脚本中的距离和宽度

Distance and width in Spark AR scripting

我很难浏览 Spark AR 文档,我找不到这个问题的答案:我在一个场景中有三个平面。其中两个在移动,一个在静止。

谢谢!

你很幸运,因为 Reactive Module 正好有一个内置的距离函数!

//import the Reactive module
const Reactive = require('Reactive');

//find your planes
let plane1 = Scene.root.find('plane1');
let plane2 = Scene.root.find('plane2');
let plane3 = Scene.root.find('plane3');

//create point signals
let point1 = Reactive.pack3(plane1.transform.x, plane1.transform.y, plane1.transform.z);
let point2 = Reactive.pack3(plane2.transform.x, plane2.transform.y, plane2.transform.z);

//get the distance between the two points
let distance = Reactive.distance(point1, point2);

//apply scale
plane3.transform.scaleX = distance;

祝你好运!