Przeglądaj źródła

Preload meshes before starting the AR session

customisations
alemart 9 miesięcy temu
rodzic
commit
b6c30b1e8e
1 zmienionych plików z 24 dodań i 11 usunięć
  1. 24
    11
      demos/hello-three/demo.js

+ 24
- 11
demos/hello-three/demo.js Wyświetl plik

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
      * Initialization
179
      * Initialization
164
      * @param {ARSystem} ar
180
      * @param {ARSystem} ar
165
-     * @returns {Promise<void>}
181
+     * @returns {void}
166
      */
182
      */
167
-    async init(ar)
183
+    init(ar)
168
     {
184
     {
169
         // Change the point of view. All virtual objects are descendants of
185
         // Change the point of view. All virtual objects are descendants of
170
         // ar.root, a node that is automatically aligned to the physical scene.
186
         // ar.root, a node that is automatically aligned to the physical scene.
176
         this._initLight(ar);
192
         this._initLight(ar);
177
         this._initText(ar);
193
         this._initText(ar);
178
         this._initMagicCircle(ar);
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
         // done!
198
         // done!
186
         this._initialized = true;
199
         this._initialized = true;
242
         this._objects.text = text;
255
         this._objects.text = text;
243
     }
256
     }
244
 
257
 
245
-    async _initMage(ar)
258
+    _initMage(ar)
246
     {
259
     {
247
         // load the mage
260
         // load the mage
248
-        const gltf = await Utils.loadGLTF('../assets/mage.glb');
261
+        const gltf = this._objects.gltf.mage;
249
         const mage = gltf.scene;
262
         const mage = gltf.scene;
250
         mage.scale.set(0.7, 0.7, 0.7);
263
         mage.scale.set(0.7, 0.7, 0.7);
251
 
264
 
261
         this._objects.mageAction = mageAction;
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
         const cat = gltf.scene;
280
         const cat = gltf.scene;
268
         cat.scale.set(0.7, 0.7, 0.7);
281
         cat.scale.set(0.7, 0.7, 0.7);
269
 
282
 

Ładowanie…
Anuluj
Zapisz