|
@@ -160,11 +160,27 @@ class EnchantedDemo extends ARDemo
|
160
|
160
|
}
|
161
|
161
|
|
162
|
162
|
/**
|
|
163
|
+ * Preload resources before starting the AR session
|
|
164
|
+ * @returns {Promise<void>}
|
|
165
|
+ */
|
|
166
|
+ async preload()
|
|
167
|
+ {
|
|
168
|
+ // preload meshes
|
|
169
|
+ const [ mage, cat ] = await Promise.all([
|
|
170
|
+ Utils.loadGLTF('../assets/mage.glb'),
|
|
171
|
+ Utils.loadGLTF('../assets/cat.glb')
|
|
172
|
+ ]);
|
|
173
|
+
|
|
174
|
+ // save references
|
|
175
|
+ this._objects.gltf = { mage, cat };
|
|
176
|
+ }
|
|
177
|
+
|
|
178
|
+ /**
|
163
|
179
|
* Initialization
|
164
|
180
|
* @param {ARSystem} ar
|
165
|
|
- * @returns {Promise<void>}
|
|
181
|
+ * @returns {void}
|
166
|
182
|
*/
|
167
|
|
- async init(ar)
|
|
183
|
+ init(ar)
|
168
|
184
|
{
|
169
|
185
|
// Change the point of view. All virtual objects are descendants of
|
170
|
186
|
// ar.root, a node that is automatically aligned to the physical scene.
|
|
@@ -176,11 +192,8 @@ class EnchantedDemo extends ARDemo
|
176
|
192
|
this._initLight(ar);
|
177
|
193
|
this._initText(ar);
|
178
|
194
|
this._initMagicCircle(ar);
|
179
|
|
-
|
180
|
|
- await Promise.all([
|
181
|
|
- this._initMage(ar),
|
182
|
|
- this._initCat(ar),
|
183
|
|
- ]);
|
|
195
|
+ this._initMage(ar);
|
|
196
|
+ this._initCat(ar);
|
184
|
197
|
|
185
|
198
|
// done!
|
186
|
199
|
this._initialized = true;
|
|
@@ -242,10 +255,10 @@ class EnchantedDemo extends ARDemo
|
242
|
255
|
this._objects.text = text;
|
243
|
256
|
}
|
244
|
257
|
|
245
|
|
- async _initMage(ar)
|
|
258
|
+ _initMage(ar)
|
246
|
259
|
{
|
247
|
260
|
// load the mage
|
248
|
|
- const gltf = await Utils.loadGLTF('../assets/mage.glb');
|
|
261
|
+ const gltf = this._objects.gltf.mage;
|
249
|
262
|
const mage = gltf.scene;
|
250
|
263
|
mage.scale.set(0.7, 0.7, 0.7);
|
251
|
264
|
|
|
@@ -261,9 +274,9 @@ class EnchantedDemo extends ARDemo
|
261
|
274
|
this._objects.mageAction = mageAction;
|
262
|
275
|
}
|
263
|
276
|
|
264
|
|
- async _initCat(ar)
|
|
277
|
+ _initCat(ar)
|
265
|
278
|
{
|
266
|
|
- const gltf = await Utils.loadGLTF('../assets/cat.glb');
|
|
279
|
+ const gltf = this._objects.gltf.cat;
|
267
|
280
|
const cat = gltf.scene;
|
268
|
281
|
cat.scale.set(0.7, 0.7, 0.7);
|
269
|
282
|
|