forked from Spark-AR-Community/SparkAR-Snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamicInstanceOnTap.js
51 lines (38 loc) · 1.14 KB
/
dynamicInstanceOnTap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
Prerequisites
* Make sure you added Script Dynamic Instancing on your capability
* Make sure you seleted Tap under TouchGestures on your capability
*/
//Create plane Dynamically in code On Tap
// load in modules
const Scene = require('Scene');
const tap = require("TouchGestures");
(async function () {
// Accessing the Focal Distance
const [fd] = await Promise.all([
Scene.root.findFirst("Focal Distance"),
]);
// Array to store the created elements
var totalPlane = [];
var x = 0;
// Tap function
tap.onTap().subscribe(async () => {
//Promise that creates plane on tap
let [planeClone] = await Promise.all([
Scene.create("Plane", {
"name": "Plane",
"width": 0.1,
"height": 0.1,
"x": x,
"y": 0,
"z": 0,
"hidden": false,
}),
]);
//Storing the created plane
totalPlane.push(planeClone);
//Adding the created plane to the parent and the scene
fd.addChild(totalPlane[totalPlane.length - 1]);
x += .1;
});
})();