소스 검색

Add ar.viewer to the plugins

customisations
alemart 10 달 전
부모
커밋
a1d78f6fc6
3개의 변경된 파일48개의 추가작업 그리고 2개의 파일을 삭제
  1. 20
    2
      plugins/aframe-with-encantar.js
  2. 14
    0
      plugins/babylon-with-encantar.js
  3. 14
    0
      plugins/three-with-encantar.js

+ 20
- 2
plugins/aframe-with-encantar.js 파일 보기

@@ -39,7 +39,22 @@ const ARUtils = () => ({
39 39
         return null;
40 40
     },
41 41
 
42
-    getTrackablePointers(frame)
42
+    findViewer(frame)
43
+    {
44
+        if(frame === null)
45
+            return null;
46
+
47
+        for(const result of frame.results) {
48
+            if(result.tracker.type == 'image-tracker') {
49
+                if(result.trackables.length > 0)
50
+                    return result.viewer;
51
+            }
52
+        }
53
+
54
+        return null;
55
+    },
56
+
57
+    findTrackablePointers(frame)
43 58
     {
44 59
         if(frame === null)
45 60
             return [];
@@ -67,6 +82,7 @@ AFRAME.registerSystem('ar', {
67 82
 
68 83
     session: /** @type {Session | null} */ (null),
69 84
     frame: /** @type {Frame | null} */ (null),
85
+    viewer: /** @type {Viewer | null} */ (null),
70 86
     pointers: /** @type {TrackablePointer[]} */ ([]),
71 87
 
72 88
     _utils: ARUtils(),
@@ -207,6 +223,7 @@ AFRAME.registerSystem('ar', {
207 223
         }
208 224
 
209 225
         session.addEventListener('end', () => {
226
+            this.viewer = null;
210 227
             this.frame = null;
211 228
             this.pointers.length = 0;
212 229
         });
@@ -230,6 +247,7 @@ AFRAME.registerSystem('ar', {
230 247
         // animation loop
231 248
         const animate = (time, frame) => {
232 249
             this.frame = frame;
250
+            this.viewer = this._utils.findViewer(frame);
233 251
             this._updateTrackablePointers();
234 252
 
235 253
             scene.render();
@@ -312,7 +330,7 @@ AFRAME.registerSystem('ar', {
312 330
     {
313 331
         this.pointers.length = 0;
314 332
 
315
-        const newPointers = this._utils.getTrackablePointers(this.frame);
333
+        const newPointers = this._utils.findTrackablePointers(this.frame);
316 334
         if(newPointers.length > 0)
317 335
             this.pointers.push.apply(this.pointers, newPointers);
318 336
     },

+ 14
- 0
plugins/babylon-with-encantar.js 파일 보기

@@ -83,6 +83,15 @@ class ARSystem
83 83
     }
84 84
 
85 85
     /**
86
+     * AR Viewer
87
+     * @returns {Viewer | null}
88
+     */
89
+    get viewer()
90
+    {
91
+        return this._viewer;
92
+    }
93
+
94
+    /**
86 95
      * Pointer-based input in the current frame (touch, mouse, pen...)
87 96
      * You need a PointerTracker in your session in order to use these
88 97
      * @returns {TrackablePointer[]}
@@ -136,6 +145,7 @@ class ARSystem
136 145
     {
137 146
         this._session = null;
138 147
         this._frame = null;
148
+        this._viewer = null;
139 149
         this._pointers = [];
140 150
         this._origin = null;
141 151
         this._root = null;
@@ -174,6 +184,7 @@ function encantar(demo)
174 184
     function mix(frame)
175 185
     {
176 186
         let found = false;
187
+        ar._viewer = null;
177 188
         ar._pointers.length = 0;
178 189
 
179 190
         for(const result of frame.results) {
@@ -186,6 +197,7 @@ function encantar(demo)
186 197
 
187 198
                     align(projectionMatrix, viewMatrix, modelMatrix);
188 199
                     ar._origin.setEnabled(true);
200
+                    ar._viewer = result.viewer;
189 201
 
190 202
                     found = true;
191 203
                 }
@@ -260,7 +272,9 @@ function encantar(demo)
260 272
 
261 273
         session.addEventListener('end', event => {
262 274
             ar._origin.setEnabled(false);
275
+            ar._viewer = null;
263 276
             ar._frame = null;
277
+            ar._pointers.length = 0;
264 278
         });
265 279
 
266 280
         session.viewport.addEventListener('resize', event => {

+ 14
- 0
plugins/three-with-encantar.js 파일 보기

@@ -83,6 +83,15 @@ class ARSystem
83 83
     }
84 84
 
85 85
     /**
86
+     * AR Viewer
87
+     * @returns {Viewer | null}
88
+     */
89
+    get viewer()
90
+    {
91
+        return this._viewer;
92
+    }
93
+
94
+    /**
86 95
      * Pointer-based input in the current frame (touch, mouse, pen...)
87 96
      * You need a PointerTracker in your session in order to use these
88 97
      * @returns {TrackablePointer[]}
@@ -136,6 +145,7 @@ class ARSystem
136 145
     {
137 146
         this._session = null;
138 147
         this._frame = null;
148
+        this._viewer = null;
139 149
         this._pointers = [];
140 150
         this._origin = null;
141 151
         this._root = null;
@@ -168,6 +178,7 @@ function encantar(demo)
168 178
     function mix(frame)
169 179
     {
170 180
         let found = false;
181
+        ar._viewer = null;
171 182
         ar._pointers.length = 0;
172 183
 
173 184
         for(const result of frame.results) {
@@ -180,6 +191,7 @@ function encantar(demo)
180 191
 
181 192
                     align(projectionMatrix, viewMatrixInverse, modelMatrix);
182 193
                     ar._origin.visible = true;
194
+                    ar._viewer = result.viewer;
183 195
 
184 196
                     found = true;
185 197
                 }
@@ -232,7 +244,9 @@ function encantar(demo)
232 244
 
233 245
         session.addEventListener('end', event => {
234 246
             ar._origin.visible = false;
247
+            ar._viewer = null;
235 248
             ar._frame = null;
249
+            ar._pointers.length = 0;
236 250
         });
237 251
 
238 252
         session.viewport.addEventListener('resize', event => {

Loading…
취소
저장