Selaa lähdekoodia

Change the visibility of the origin node

customisations
alemart 11 kuukautta sitten
vanhempi
commit
02eb07b8fb
2 muutettua tiedostoa jossa 22 lisäystä ja 23 poistoa
  1. 5
    5
      plugins/aframe-with-encantar.js
  2. 17
    18
      plugins/three-with-encantar.js

+ 5
- 5
plugins/aframe-with-encantar.js Näytä tiedosto

495
 
495
 
496
     play()
496
     play()
497
     {
497
     {
498
-        const root = this.el.object3D;
499
-        root.visible = true;
498
+        const origin = this._origin;
499
+        origin.visible = true;
500
 
500
 
501
         if(this._firstRun) {
501
         if(this._firstRun) {
502
             this._firstRun = false;
502
             this._firstRun = false;
503
-            root.visible = false;
503
+            origin.visible = false;
504
             this.el.pause();
504
             this.el.pause();
505
         }
505
         }
506
     },
506
     },
507
 
507
 
508
     pause()
508
     pause()
509
     {
509
     {
510
-        const root = this.el.object3D;
511
-        root.visible = false;
510
+        const origin = this._origin;
511
+        origin.visible = false;
512
     },
512
     },
513
 
513
 
514
     teek()
514
     teek()

+ 17
- 18
plugins/three-with-encantar.js Näytä tiedosto

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
      * @returns {THREE.Group}
88
      * @returns {THREE.Group}
90
      */
89
      */
91
     get root()
90
     get root()
136
 }
135
 }
137
 
136
 
138
 /**
137
 /**
139
- * Do magic to connect encantar.js to three.js
138
+ * Enchant three.js with encantar.js!
140
  * @param {ARScene} scene
139
  * @param {ARScene} scene
141
  * @returns {Promise<ARSystem>}
140
  * @returns {Promise<ARSystem>}
142
  */
141
  */
144
 {
143
 {
145
     const ar = new ARSystem();
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
     function mix(frame)
157
     function mix(frame)
148
     {
158
     {
149
-        ar._root.visible = false;
159
+        ar._origin.visible = false;
150
 
160
 
151
         for(const result of frame.results) {
161
         for(const result of frame.results) {
152
             if(result.tracker.type == 'image-tracker') {
162
             if(result.tracker.type == 'image-tracker') {
157
                     const modelMatrix = trackable.pose.transform.matrix;
167
                     const modelMatrix = trackable.pose.transform.matrix;
158
 
168
 
159
                     align(projectionMatrix, viewMatrixInverse, modelMatrix);
169
                     align(projectionMatrix, viewMatrixInverse, modelMatrix);
160
-                    ar._root.visible = true;
170
+                    ar._origin.visible = true;
161
 
171
 
162
                     return;
172
                     return;
163
                 }
173
                 }
175
         ar._origin.updateMatrixWorld(true);
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
     return Promise.resolve()
188
     return Promise.resolve()
190
     .then(() => {
189
     .then(() => {
191
         return scene.startSession(); // Promise or SpeedyPromise
190
         return scene.startSession(); // Promise or SpeedyPromise
212
         });
211
         });
213
 
212
 
214
         session.addEventListener('end', event => {
213
         session.addEventListener('end', event => {
215
-            ar._root.visible = false;
214
+            ar._origin.visible = false;
216
             ar._frame = null;
215
             ar._frame = null;
217
         });
216
         });
218
 
217
 

Loading…
Peruuta
Tallenna