Переглянути джерело

Change the visibility of the origin node

customisations
alemart 11 місяці тому
джерело
коміт
02eb07b8fb
2 змінених файлів з 22 додано та 23 видалено
  1. 5
    5
      plugins/aframe-with-encantar.js
  2. 17
    18
      plugins/three-with-encantar.js

+ 5
- 5
plugins/aframe-with-encantar.js Переглянути файл

@@ -495,20 +495,20 @@ AFRAME.registerComponent('ar-root', ARComponent({
495 495
 
496 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 501
         if(this._firstRun) {
502 502
             this._firstRun = false;
503
-            root.visible = false;
503
+            origin.visible = false;
504 504
             this.el.pause();
505 505
         }
506 506
     },
507 507
 
508 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 514
     teek()

+ 17
- 18
plugins/three-with-encantar.js Переглянути файл

@@ -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
 

Завантаження…
Відмінити
Зберегти