|
@@ -83,9 +83,8 @@ class ARSystem
|
83
|
83
|
}
|
84
|
84
|
|
85
|
85
|
/**
|
86
|
|
- * The root is a 3D object that is automatically aligned to the physical
|
87
|
|
- * scene. Objects of your virtual scene should be descendants of this node.
|
88
|
|
- * The root is only visible if something is being tracked.
|
|
86
|
+ * The root is a node that is automatically aligned to the physical scene.
|
|
87
|
+ * Objects of your virtual scene should be descendants of this node.
|
89
|
88
|
* @returns {THREE.Group}
|
90
|
89
|
*/
|
91
|
90
|
get root()
|
|
@@ -136,7 +135,7 @@ class ARSystem
|
136
|
135
|
}
|
137
|
136
|
|
138
|
137
|
/**
|
139
|
|
- * Do magic to connect encantar.js to three.js
|
|
138
|
+ * Enchant three.js with encantar.js!
|
140
|
139
|
* @param {ARScene} scene
|
141
|
140
|
* @returns {Promise<ARSystem>}
|
142
|
141
|
*/
|
|
@@ -144,9 +143,20 @@ function encantar(scene)
|
144
|
143
|
{
|
145
|
144
|
const ar = new ARSystem();
|
146
|
145
|
|
|
146
|
+ function animate(time, frame)
|
|
147
|
+ {
|
|
148
|
+ ar._frame = frame;
|
|
149
|
+ mix(frame);
|
|
150
|
+
|
|
151
|
+ scene.update(ar);
|
|
152
|
+
|
|
153
|
+ ar._renderer.render(ar._scene, ar._camera);
|
|
154
|
+ ar._session.requestAnimationFrame(animate);
|
|
155
|
+ }
|
|
156
|
+
|
147
|
157
|
function mix(frame)
|
148
|
158
|
{
|
149
|
|
- ar._root.visible = false;
|
|
159
|
+ ar._origin.visible = false;
|
150
|
160
|
|
151
|
161
|
for(const result of frame.results) {
|
152
|
162
|
if(result.tracker.type == 'image-tracker') {
|
|
@@ -157,7 +167,7 @@ function encantar(scene)
|
157
|
167
|
const modelMatrix = trackable.pose.transform.matrix;
|
158
|
168
|
|
159
|
169
|
align(projectionMatrix, viewMatrixInverse, modelMatrix);
|
160
|
|
- ar._root.visible = true;
|
|
170
|
+ ar._origin.visible = true;
|
161
|
171
|
|
162
|
172
|
return;
|
163
|
173
|
}
|
|
@@ -175,17 +185,6 @@ function encantar(scene)
|
175
|
185
|
ar._origin.updateMatrixWorld(true);
|
176
|
186
|
}
|
177
|
187
|
|
178
|
|
- function animate(time, frame)
|
179
|
|
- {
|
180
|
|
- ar._frame = frame;
|
181
|
|
- mix(frame);
|
182
|
|
-
|
183
|
|
- scene.update(ar);
|
184
|
|
-
|
185
|
|
- ar._renderer.render(ar._scene, ar._camera);
|
186
|
|
- ar._session.requestAnimationFrame(animate);
|
187
|
|
- }
|
188
|
|
-
|
189
|
188
|
return Promise.resolve()
|
190
|
189
|
.then(() => {
|
191
|
190
|
return scene.startSession(); // Promise or SpeedyPromise
|
|
@@ -212,7 +211,7 @@ function encantar(scene)
|
212
|
211
|
});
|
213
|
212
|
|
214
|
213
|
session.addEventListener('end', event => {
|
215
|
|
- ar._root.visible = false;
|
|
214
|
+ ar._origin.visible = false;
|
216
|
215
|
ar._frame = null;
|
217
|
216
|
});
|
218
|
217
|
|