architwin 1.0.25 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,6 +12,7 @@ ArchiTwin Library
12
12
  - [Import the library](#import-the-library)
13
13
  - [Setup your proxy](#setup-your-proxy)
14
14
  - [Connect to a Space](#connect-to-a-space)
15
+ - [Setup for other frameworks](#setup-for-other-frameworks)
15
16
  - [Connection Parameters](#connection-parameters)
16
17
  - [Config Options](#config-options)
17
18
  - [Space Navigation and Camera Control](#space-navigation-and-camera-control)
@@ -41,6 +42,7 @@ This example uses Vue's ref attribute to reference the target iFrame. Please con
41
42
 
42
43
  ````html
43
44
  <template>
45
+ <!-- ref is an attribute used in Vue-->
44
46
  <div>
45
47
  <iframe
46
48
  id="mp-showcase"
@@ -58,7 +60,8 @@ This example uses Vue's ref attribute to reference the target iFrame. Please con
58
60
 
59
61
  ````typescript
60
62
  <script lang="ts">
61
- import atwin from 'architwin';
63
+ import * as atwin from 'architwin';
64
+ //We also support default imports using import * as atwin from 'architwin';
62
65
  import type { IMPConfig, IUser } from 'architwin/lib/types'; //for typescript projects
63
66
  import { onMounted, ref } from 'vue';
64
67
 
@@ -87,7 +90,9 @@ During production deployment you may need to setup proxy settings using your web
87
90
  import { fileURLToPath, URL } from "node:url";
88
91
 
89
92
  import { defineConfig, loadEnv } from "vite";
90
- import vue from "@vitejs/plugin-vue";
93
+ import vue from "@vitejs/plugin-vue"; //for Vue projects
94
+ import { svelte } from '@sveltejs/vite-plugin-svelte' //for Svelte projects
95
+ import react from '@vitejs/plugin-react' //for React projects
91
96
  import dotenv from "dotenv";
92
97
 
93
98
  // https://vitejs.dev/config/
@@ -99,7 +104,11 @@ export default defineConfig(({ command, mode }) => {
99
104
 
100
105
  return {
101
106
  env: env,
102
- plugins: [vue()],
107
+ plugins: [
108
+ vue(), //for vue projects,
109
+ svelte(), //for svelte projects,
110
+ react(), //for react projects
111
+ ],
103
112
  server: {
104
113
  host: true,
105
114
  port: 5173,
@@ -161,7 +170,7 @@ export default defineConfig(({ command, mode }) => {
161
170
 
162
171
  const config: IMPConfig = {
163
172
  iframeId: 'mp-showcase',
164
- bundlePath: "path/to/bundle", // optional. Iframe src should be something like this: <bundlePath>/bundle/showcase.html?
173
+ bundlePath: "path/to/bundle/", // optional. Iframe src should be something like this: <bundlePath>/bundle/showcase.html?
165
174
  play: 1,
166
175
  }
167
176
 
@@ -183,39 +192,136 @@ You should be able to move around the Space using keyboard and mouse.
183
192
 
184
193
  Or programmatically using methods defined in this library.
185
194
 
186
- ## Connection Parameters
187
- connectSpace has three important parameters:
195
+ #### Setup for other frameworks
196
+
197
+ Vue is the framework we use in the code snippets provided above. If your team intends to use other frameworks like Svelte or React.
198
+
199
+ **Svelete**: Setup your svelte project with Architwin
200
+
188
201
  ````javascript
189
- connectSpace(spaceUrl, auth, config)
202
+ <script>
203
+ import { onMount } from 'svelte'
204
+ import * as atwin from 'architwin'
205
+ import type {IMPConfig,IUser} from 'architwin/lib/types' //for typescript projects
206
+
207
+ let mpIframe:HTMLIFrameElement
208
+ const apiKey = "YOUR-API-KEY"
209
+ const authUser = {
210
+ email: "su@email.com",
211
+ password: "su123"
212
+ } as IUser
213
+
214
+ onMount(async () => {
215
+ const spaceUrl = "https://basic-dev.rev-kitten.com/showcase/model3d_public/1?token=e707880f-0fc5-48a6-b3f6-643a19f81464";
216
+
217
+ const auth = {
218
+ apiKey: apiKey,
219
+ user: authUser
220
+ }
221
+
222
+ const config = {
223
+ iframeId: 'mp-showcase',
224
+ play: 1,
225
+ } as IMPConfig
226
+
227
+ // more config options as explain later
228
+ await atwin.connectSpace(spaceUrl, auth, config)
229
+ })
230
+ </script>
231
+
232
+ <style>
233
+ main {
234
+ font-family: sans-serif;
235
+ text-align: center;
236
+ }
237
+ </style>
238
+
239
+ <main>
240
+ <iframe
241
+ id="mp-showcase"
242
+ title="mpIframe"
243
+ frameborder=”0”
244
+ allow="xr-spatial-tracking"
245
+ allowfullscreen
246
+ bind:this={mpIframe}
247
+ >
248
+ </iframe>
249
+ </main>
190
250
  ````
251
+ - [Svelte Architwin Project](https://playcode.io/1500211)
191
252
 
192
- **spaceUrl** - the URL of the space you wanted to connect.
193
- **auth** - an authentication object with apiKey and user credentials. This will be provided by ArchiTwin.
194
- **config** - a config object to set some default space behavior
253
+ **React**: Setup your react project with Architwin
195
254
 
255
+ ````jsx
256
+ import React, { useEffect, useRef } from 'react';
257
+ import * as atwin from 'architwin';
258
+ //import { IMPConfig, IUser } from 'architwin/lib/types'; //for typescript script projects
196
259
 
197
- **Example:**
198
- ```javascript
199
- import atwin from 'architwin'
260
+ export function App(props) {
261
+ const mpIframeRef = useRef(null);
262
+ const apiKey = "YOUR-API-KEY";
263
+ const authUser = {
264
+ email: "su@email.com",
265
+ password: "su123"
266
+ };
200
267
 
201
- // public URL for the space, you will be provided an API Endpoint for the list of public spaces
202
- const spaceUrl = "https://basic-dev.rev-kitten.com/showcase/model3d_public/1?token=e707880f-0fc5-48a6-b3f6-643a19f81464"
268
+ useEffect(() => {
269
+ const spaceUrl = "https://basic-dev.rev-kitten.com/showcase/model3d_public/1?token=e707880f-0fc5-48a6-b3f6-643a19f81464";
203
270
 
204
- const auth = {
205
- apiKey: "585876be-339f-4e52-a6a0-0bc816ccb95a", //xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
206
- user: {
207
- email: 'su@email.com',
208
- password: 'su123'
209
- }
210
- }
271
+ const auth = {
272
+ apiKey: apiKey,
273
+ user: authUser
274
+ };
211
275
 
212
- const config = {
213
- iframeId: "mp-showcase", // this is required
214
- // ... other config options.
276
+ const config = {
277
+ iframeId: 'mp-showcase',
278
+ play: 1
279
+ };
280
+
281
+ // more config options as explained later
282
+ const connectSpace = async () => {
283
+ await atwin.connectSpace(spaceUrl, auth, config);
284
+ };
285
+
286
+ connectSpace();
287
+ }, []);
288
+ return (
289
+ <main>
290
+ <iframe
291
+ id="mp-showcase"
292
+ title="mpIframe"
293
+ frameBorder="0"
294
+ allow="xr-spatial-tracking"
295
+ allowFullScreen
296
+ ref={mpIframeRef}
297
+ ></iframe>
298
+ </main>
299
+ );
215
300
  }
216
301
 
217
- await atwin.connectSpace(url, auth, config)
218
- ```
302
+ // Log to console
303
+ console.log('Hello console')
304
+ ````
305
+
306
+ - [React Architwin Project](https://playcode.io/1500222)
307
+
308
+ Please take note that you **must** setup the appropriate proxy configuration as stated in [this section](#setup-your-proxy) otherwise it will not work.
309
+
310
+ ## Connection Parameters
311
+ connectSpace has three important parameters:
312
+ ````javascript
313
+ connectSpace(spaceUrl, auth, config)
314
+ ````
315
+
316
+ **spaceUrl** - the URL of the space you wish to connect to.
317
+
318
+ **auth** - an authentication object with the apiKey and user credentials. Default user credentials will be provided by ArchiTwin for testing which you can change anytime to your own user credentials. The auth object passed to the `connectSpace` method may consist of the following keys:
319
+
320
+ - apiURL: (string) an optional key which if set, will point all internal API calls to the api endpoint or base URL you assign. If this is not set, all api calls will be directed to the proxy address set in the `vite.config.ts` file during **local development**. Example: `apiURL: "apps.awesomesite.com/api"` will resolve internally to `apps.awesomesite.com/api/cas/tickets?someparams` or `apps.awesomesite.com/api/v1/showcase/id/1`. It is important to add `/api` to the base url of your custom apiURL to ensure the api requests are properly sent. There is no need to add a forward slash at the end of our custom apiURL. Please take note that you *may* have to setup a proxy server to bypass CORS issues when you deploy your application on your production servers
321
+ - apiKey: (string) sets the required apiKey that is inserted into the authorization headers of each API request
322
+ - user: (IUser | Object) an object that contains the `email` and `password` of the user.
323
+
324
+ **config** - a config object to set some default space behavior. You can learn more about the config object and its keys by going to the [config options](#config-options) section
219
325
 
220
326
  ## Config Options
221
327
 
@@ -230,15 +336,15 @@ export interface IMPConfig{
230
336
  }
231
337
  ```
232
338
 
233
- **iframeId:** string,
339
+ **iframeId:** string: The `id` of the target iframe where the 3D space will be loaded into.
234
340
 
235
- **bundlePath?:** string, bundlePath is an optional key that can be set for projects whose project structure require a custom path to the bundle SDK provided by matterport. If not set, the package will by default set the bundle path to the bundle SDK find inside the architwin package in node_modules. The path should end with a /
341
+ **bundlePath?:** string: bundlePath is an optional key that can be set for projects whose project structure requires a custom path to the bundle SDK provided by matterport. If not set, the package will by default set the bundle path to the bundle SDK found inside the architwin package in node_modules.
236
342
 
237
343
  *Example:*
238
344
 
239
- `bundlePath: "assets/"`
345
+ `bundlePath: "assets/customBundleName"`
240
346
 
241
- This will resolve internally to `"assets/bundle/showcase.html?someparams"`
347
+ This will resolve internally to `"assets/customBundleName/showcase.html?someparams"`
242
348
 
243
349
 
244
350
  **play?:** 0 | 1, default = 0
@@ -261,6 +367,30 @@ This will resolve internally to `"assets/bundle/showcase.html?someparams"`
261
367
  - 0 Hide the VR button.
262
368
  - 1 Default Show the VR button.
263
369
 
370
+ **Example:**
371
+ ```javascript
372
+ import * as atwin from 'architwin'
373
+
374
+ // public URL for the space, you will be provided an API Endpoint for the list of public spaces
375
+ const spaceUrl = "https://basic-dev.rev-kitten.com/showcase/model3d_public/1?token=e707880f-0fc5-48a6-b3f6-643a19f81464"
376
+
377
+ const auth = {
378
+ apiURL: "YOUR-API-URL", //Set the url to make api requests to
379
+ apiKey: "YOUR-API-KEY", //xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
380
+ user: {
381
+ email: 'su@email.com',
382
+ password: 'su123'
383
+ }
384
+ }
385
+
386
+ const config = {
387
+ iframeId: "mp-showcase", // this is required
388
+ // ... other config options.
389
+ }
390
+
391
+ await atwin.connectSpace(url, auth, config)
392
+ ```
393
+
264
394
  ## Space Navigation and Camera Control
265
395
  -----------------------------
266
396
  #### Moving Around
@@ -276,18 +406,18 @@ This will move the user to the nearest Sweep marker in the indicated direction.
276
406
 
277
407
  ````typescript
278
408
  <script lang="ts">
279
- import atwin from 'architwin';
409
+ import * as atwin from 'architwin';
280
410
  import type { IMPConfig, IUser } from 'architwin/lib/types';
281
411
  import { onMounted, ref } from 'vue';
282
412
 
283
413
  ...
284
- atwin.moveInDirection("FORWARD")
285
- atwin.moveInDirection("FORWARD")
414
+ await atwin.moveInDirection("FORWARD")
415
+ await atwin.moveInDirection("FORWARD")
286
416
 
287
- atwin.moveInDirection("RIGHT")
288
- atwin.moveInDirection("RIGHT")
289
- atwin.moveInDirection("FORWARD")
290
- atwin.moveInDirection("LEFT")
417
+ await atwin.moveInDirection("RIGHT")
418
+ await atwin.moveInDirection("RIGHT")
419
+ await atwin.moveInDirection("FORWARD")
420
+ await atwin.moveInDirection("LEFT")
291
421
  ...
292
422
 
293
423
  </script>
@@ -307,25 +437,25 @@ Note, cameraPan will work only in *Dollhouse* mode.
307
437
 
308
438
  ````typescript
309
439
  <script lang="ts">
310
- import atwin from 'architwin';
440
+ import * as atwin from 'architwin';
311
441
  import type { IMPConfig, IUser } from 'architwin/lib/types';
312
442
  import { onMounted, ref } from 'vue';
313
443
 
314
444
  ...
315
445
  // rotate around X axis, last parameter is the Speed of rotation in seconds
316
- atwin.cameraRotate(20,0,2)
446
+ await atwin.cameraRotate(20,0,2)
317
447
 
318
448
 
319
449
  // rotate around Y axis
320
- atwin.cameraRotate(0,45,5)
450
+ await atwin.cameraRotate(0,45,5)
321
451
 
322
452
 
323
453
 
324
454
  // pan around z axis (pan and tilt only works in Dollhouse mode)
325
- atwin.cameraPan(0,20)
455
+ await atwin.cameraPan(0,20)
326
456
 
327
457
  // tilt abpout x axis
328
- atwin.cameraPan(30,0)
458
+ await atwin.cameraPan(30,0)
329
459
 
330
460
  ...
331
461
 
@@ -383,24 +513,24 @@ moveToSweep(sweepId) - // to move to a specific Sweep
383
513
  **Example:**
384
514
  ````typescript
385
515
  <script lang="ts">
386
- import atwin from 'architwin';
516
+ import * as atwin from 'architwin';
387
517
  import type { IMPConfig, IUser } from 'architwin/lib/types';
388
518
  import { onMounted, ref } from 'vue';
389
519
 
390
520
  ...
391
521
  // get current sweep data
392
- atwin.getCurrentSweep()
522
+ await atwin.getCurrentSweep()
393
523
 
394
524
 
395
525
  // get current sweep position
396
- atwin.getSweepPosition()
526
+ await atwin.getSweepPosition()
397
527
 
398
528
 
399
529
  // moving to a Sweep
400
- atwin.moveToSweep('msdfkj353h')
530
+ await atwin.moveToSweep('msdfkj353h')
401
531
 
402
532
  // move to a Tag
403
- atwin.gotoTag(5)
533
+ await atwin.gotoTag(5)
404
534
 
405
535
  ...
406
536
 
@@ -435,29 +565,29 @@ getSweepPosition(): {x: number, y: number, z: number} - // returns the position
435
565
  **Example:**
436
566
  ````typescript
437
567
  <script lang="ts">
438
- import atwin from 'architwin';
568
+ import * as atwin from 'architwin';
439
569
  import type { IMPConfig, IUser } from 'architwin/lib/types';
440
570
  import { onMounted, ref } from 'vue';
441
571
 
442
572
  ...
443
573
  // get all Sweeps in loaded Space
444
- atwin.getSweeps()
574
+ await atwin.getSweeps()
445
575
 
446
576
 
447
577
  // get current sweep data
448
- atwin.getCurrentSweep()
578
+ await atwin.getCurrentSweep()
449
579
 
450
580
 
451
581
  // get current sweep position
452
- atwin.getSweepPosition()
582
+ await atwin.getSweepPosition()
453
583
 
454
584
 
455
585
  // moving to a Sweep
456
- atwin.moveToSweep('mfj45ligf')
586
+ await atwin.moveToSweep('mfj45ligf')
457
587
 
458
588
 
459
589
  // get nearby sweeps from current Sweep
460
- atwin.getNearbySweeps('mfj45ligf')
590
+ await atwin.getNearbySweeps('mfj45ligf')
461
591
 
462
592
  ...
463
593
 
@@ -474,7 +604,7 @@ pauseVideo(videoId: number) - // pause a video screen
474
604
  **Example:**
475
605
  ````typescript
476
606
  <script lang="ts">
477
- import atwin from 'architwin';
607
+ import * as atwin from 'architwin';
478
608
  import type { IMPConfig, IUser } from 'architwin/lib/types';
479
609
  import { onMounted, ref } from 'vue';
480
610
 
@@ -521,52 +651,52 @@ cameraRotate(x: number, y: number, speed: number) - // rotates the camera view,
521
651
  **Example:**
522
652
  ````typescript
523
653
  <script lang="ts">
524
- import atwin from 'architwin';
654
+ import * as atwin from 'architwin';
525
655
  import type { IMPConfig, IUser } from 'architwin/lib/types';
526
656
  import { onMounted, ref } from 'vue';
527
657
 
528
658
  ...
529
659
 
530
660
  // get current Camera Pose
531
- atwin.getCurrentCameraPose()
661
+ await atwin.getCurrentCameraPose()
532
662
 
533
663
 
534
664
  // get current camera position
535
- atwin.getCameraPosition()
665
+ await atwin.getCameraPosition()
536
666
 
537
667
 
538
668
  // set Camera View
539
- atwin.cameraLookAt(0, 10)
669
+ await atwin.cameraLookAt(0, 10)
540
670
 
541
671
 
542
672
  // move in different Directions
543
- atwin.moveInDirection("FORWARD")
544
- atwin.moveInDirection("FORWARD")
673
+ await atwin.moveInDirection("FORWARD")
674
+ await atwin.moveInDirection("FORWARD")
545
675
 
546
676
 
547
677
  // pan around z axis (pan and tilt only works in Dollhouse mode)
548
- atwin.cameraPan(0,20)
678
+ await atwin.cameraPan(0,20)
549
679
 
550
680
 
551
681
  // tilt abpout x axis
552
- atwin.cameraPan(30,0)
682
+ await atwin.cameraPan(30,0)
553
683
 
554
684
 
555
685
  // rotate around X axis, last parameter is the Speed of rotation in seconds
556
- atwin.cameraRotate(20,0,2)
686
+ await atwin.cameraRotate(20,0,2)
557
687
 
558
688
 
559
689
  // rotate around Y axis
560
- atwin.cameraRotate(20,5,2)
690
+ await atwin.cameraRotate(20,5,2)
561
691
 
562
692
 
563
693
  // get current View
564
- atwin.getViewMode()
694
+ await atwin.getViewMode()
565
695
 
566
696
  // set View Mode
567
- atwin.setViewMode("INSIDE")
568
- atwin.setViewMode("FLOORPLAN")
569
- atwin.setViewMode("DOLLHOUSE")
697
+ await atwin.setViewMode("INSIDE")
698
+ await atwin.setViewMode("FLOORPLAN")
699
+ await atwin.setViewMode("DOLLHOUSE")
570
700
  ...
571
701
 
572
702
  </script>
@@ -586,7 +716,7 @@ getNearbyObjects(type?: '3DX' | 'SLIDESHOW' | 'VIDEO', distance?: number = 2)
586
716
  **Example**
587
717
  ````typescript
588
718
  <script lang="ts">
589
- import atwin from 'architwin';
719
+ import * as atwin from 'architwin';
590
720
  import type { IMPConfig, IUser } from 'architwin/lib/types';
591
721
  import { onMounted, ref } from 'vue';
592
722
 
@@ -1,11 +1,21 @@
1
1
  import type { MpSdk } from "../bundle/sdk";
2
- import type { IUser, IMPConfig, ISweep, ITagPublic } from "./types";
2
+ import type { IUser, IMPConfig, ISweep, ITagPublic, NearbyPayload, NearbyObjects } from "./types";
3
3
  declare let tags: ITagPublic[];
4
4
  declare let sweeps: any;
5
5
  declare function connectSpace(url: string, auth: {
6
+ apiURL?: string;
6
7
  apiKey: string;
7
8
  user: IUser;
8
9
  }, config: IMPConfig): Promise<void>;
10
+ /**
11
+ * This function returns an object that returns an array of 3D, video, and slideshow objects
12
+ * You can pass a object type as a object parameter to set what the contents of the returned objects will be
13
+ * @constructor
14
+ * @param payload
15
+ * @type {NearbyPayload}
16
+ * @returns {NearbyObjects}
17
+ */
18
+ declare function getNearbyObjects(payload: NearbyPayload): NearbyObjects;
9
19
  declare function gotoTag(tag_id: string): Promise<void>;
10
20
  declare function getCurrentSweep(): ISweep;
11
21
  declare function getCurrentCameraPose(): any;
@@ -27,7 +37,7 @@ declare function cameraLookAt(x: number, y: number): Promise<void>;
27
37
  declare function moveInDirection(direction: string): Promise<void>;
28
38
  declare function getViewMode(): MpSdk.Mode.Mode;
29
39
  declare function setViewMode(mode: string): Promise<void>;
30
- declare function disconnectSpace(): void;
40
+ declare function disconnectSpace(): Promise<void>;
31
41
  declare const atwin: {
32
42
  tags: ITagPublic[];
33
43
  sweeps: any;
@@ -48,5 +58,6 @@ declare const atwin: {
48
58
  cameraRotate: typeof cameraRotate;
49
59
  getViewMode: typeof getViewMode;
50
60
  setViewMode: typeof setViewMode;
61
+ getNearbyObjects: typeof getNearbyObjects;
51
62
  };
52
- export { atwin as default, tags, sweeps, connectSpace, disconnectSpace, gotoTag, getCurrentSweep, getCurrentSweepPosition, moveToSweep, getNearbySweeps, pauseVideo, playVideo, getCurrentCameraPose, getCameraPosition, moveInDirection, cameraLookAt, cameraPan, cameraRotate, getViewMode, setViewMode, };
63
+ export { atwin as default, tags, sweeps, connectSpace, disconnectSpace, gotoTag, getCurrentSweep, getCurrentSweepPosition, moveToSweep, getNearbySweeps, pauseVideo, playVideo, getCurrentCameraPose, getCameraPosition, moveInDirection, cameraLookAt, cameraPan, cameraRotate, getViewMode, setViewMode, getNearbyObjects, };
@@ -1 +1 @@
1
- var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P((function(resolve){resolve(value)}))}return new(P||(P=Promise))((function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator["throw"](value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):adopt(result.value).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())}))};var __generator=this&&this.__generator||function(thisArg,body){var _={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},f,y,t,g;return g={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(g[Symbol.iterator]=function(){return this}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break}if(t[2])_.ops.pop();_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e];y=0}finally{f=t=0}if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true}}};import axios from"axios";import{distance}from"mathjs";import JSZip from"jszip";import JSZipUtils from"jszip-utils";var _config={aws:{region:"ap-northeast-1",accessKeyId:"AKIAVVUXZ66KW7GBSW7A",secretAccessKey:"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'"},mp:{sdkKey:"a3ae8341bd8f44899eba16df86307d7d",urlParams:["help","play","nt","qs","brand","dh","tour","gt","hr","mls","mt","tagNav","pin","portal","f","fp","lang","kb","lp","st","title","tourcta","wts","ts","hl","vr","nozoom","search","wh"]}};var apiURL="http://localhost:5173/api/v1/";var sdkKey=_config.mp.sdkKey;var urlParams=_config.mp.urlParams;console.log("apiURL...",apiURL);var _iframe={};var _api={};var _space={};var _atwin={};var _tags=[];var tags=[];var sweeps=[];var _allSlideShow=[];var _slideShowImage=[];var _currentSlideShowID=0;var _currentSlideIndex=0;var _currentSlideShow=null;var _timer=null;var _videos=[];var _currentViewMode="";var _3DXObject=[];var _unrenderedObjects=[];var _transformControlNode;var _inputControlComponent=null;var _selectedObject={};var previousTimestamp=0;var _currentSweep={};var _currentCameraPose={};var _sweeps=[];var _isInitialLoad=true;function connectSpace(url,auth,config){return __awaiter(this,void 0,void 0,(function(){var api,showcase;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("connectSpace()");console.log("__config",config);api=axios.create({baseURL:apiURL,headers:{"Access-Control-Allow-Origin":"*","Content-Type":"application/json",Authorization:auth.apiKey}});_api=api;showcase=document.getElementById(config.iframeId);_iframe=showcase;if(!url.includes("https://my.matterport.com/show/"))return[3,2];console.log("URL IS MATTERPORT");return[4,loadDefaultMpSpace(url,config,showcase)];case 1:_a.sent();return[3,4];case 2:console.log("URL IS REV-KITTEN");return[4,loadAtwinSpace(url,auth,config,showcase)];case 3:_a.sent();_a.label=4;case 4:return[2]}}))}))}function loadDefaultMpSpace(url,config,showcase){return __awaiter(this,void 0,void 0,(function(){var iframeSrc,showcaseWindow,_setTags;var _this=this;return __generator(this,(function(_a){console.log("loadDefaultMpSpace(url: string, showcase: HTMLIFrameElement)",url,showcase);iframeSrc=getIframeSrc(config,url);console.log("__iframeSrc",iframeSrc);showcase.src=iframeSrc;showcaseWindow=showcase.contentWindow;showcase.addEventListener("load",(function(){return __awaiter(_this,void 0,void 0,(function(){var e_1;var _this=this;return __generator(this,(function(_a){switch(_a.label){case 0:console.log('iframe.addEventListener("load")');console.log("showcaseWindow",showcaseWindow);_a.label=1;case 1:_a.trys.push([1,3,,4]);return[4,showcaseWindow.MP_SDK.connect(showcaseWindow)];case 2:_atwin=_a.sent();console.log("Hello Bundle SDK",_atwin);_atwin.App.state.subscribe((function(appState){return __awaiter(_this,void 0,void 0,(function(){return __generator(this,(function(_a){switch(_a.label){case 0:console.log("appState",appState);if(!(appState.phase===_atwin.App.Phase.LOADING))return[3,2];console.log("App is loading...");return[4,_setTags()];case 1:_a.sent();return[3,3];case 2:if(appState.phase===_atwin.App.Phase.STARTING){console.log("App is starting...")}else if(appState.phase===_atwin.App.Phase.PLAYING){console.log("App is playing...")}_a.label=3;case 3:return[2]}}))}))}));return[3,4];case 3:e_1=_a.sent();console.error(e_1);return[3,4];case 4:return[2]}}))}))}));_setTags=function(){return __awaiter(_this,void 0,void 0,(function(){var mpTags,filteredMpTags;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("_setTags()");return[4,_atwin.Mattertag.getData()];case 1:mpTags=_a.sent();if(mpTags){filteredMpTags=mpTags.map((function(i){var x={};x.id=i.sid;x.name=i.label;return x}));tags=filteredMpTags;console.log("tags",tags)}return[2]}}))}))};return[2]}))}))}function loadAtwinSpace(url,auth,config,showcase){var _a;return __awaiter(this,void 0,void 0,(function(){var spaceId,space,iframeSrc,tags,objects,showcaseWindow;var _this=this;return __generator(this,(function(_b){switch(_b.label){case 0:console.log("loadAtwinSpace(url: string, auth: { apiKey: string; user: IUser },config: IMPConfig, showcase: HTMLIFrameElement)");spaceId=getSpaceId(url);if(!spaceId){console.error("spaceId is undefined");return[2]}if(!_isInitialLoad)return[3,2];return[4,loginUser(auth.user)];case 1:_b.sent();_b.label=2;case 2:return[4,getSpace(spaceId)];case 3:space=_b.sent();if(!space){console.error("space is undefined");return[2]}setSpace(space);iframeSrc=getIframeSrc(config,space.space_url);console.log("__iframeSrc",iframeSrc);showcase.src=iframeSrc;return[4,getTags(space)];case 4:tags=_b.sent();if(!tags){console.log("tags is undefined");return[2]}setTags(tags);return[4,get3DObjects(spaceId)];case 5:objects=_b.sent();if(!objects){console.log("objects is undefined");return[2]}if(_isInitialLoad){(_a=showcase.contentWindow)===null||_a===void 0?void 0:_a.location.reload()}_isInitialLoad=false;showcaseWindow=showcase.contentWindow;showcase.addEventListener("load",(function(){return __awaiter(_this,void 0,void 0,(function(){var e_2;return __generator(this,(function(_a){switch(_a.label){case 0:console.log('iframe.addEventListener("load")');console.log("showcaseWindow",showcaseWindow);_a.label=1;case 1:_a.trys.push([1,3,,4]);return[4,showcaseWindow.MP_SDK.connect(showcaseWindow)];case 2:_atwin=_a.sent();console.log("Hello Bundle SDK",_atwin);onShowcaseConnect();return[3,4];case 3:e_2=_a.sent();console.error(e_2);return[3,4];case 4:return[2]}}))}))}));return[2]}}))}))}function onShowcaseConnect(){return __awaiter(this,void 0,void 0,(function(){var modelData,e_3;var _this=this;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("onShowcaseConnect()");_a.label=1;case 1:_a.trys.push([1,3,,4]);return[4,_atwin.Model.getData()];case 2:modelData=_a.sent();console.log("Model sid:"+modelData.sid);_atwin.App.state.subscribe((function(appState){return __awaiter(_this,void 0,void 0,(function(){return __generator(this,(function(_a){switch(_a.label){case 0:console.log("appState",appState);if(!(appState.phase===_atwin.App.Phase.LOADING))return[3,1];console.log("App is loading...");return[3,7];case 1:if(!(appState.phase===_atwin.App.Phase.STARTING))return[3,3];console.log("App is starting...");return[4,hideTags()];case 2:_a.sent();return[3,7];case 3:if(!(appState.phase===_atwin.App.Phase.PLAYING))return[3,7];console.log("App is playing...");return[4,showTags(_tags)];case 4:_a.sent();return[4,getSweeps()];case 5:_a.sent();return[4,setLighting()];case 6:_a.sent();_atwin.Sweep.current.subscribe((function(currentSweep){if(currentSweep.sid===""){console.log("Not currently stationed at a sweep position")}else{_currentSweep=currentSweep;console.log("Currently at sweep",_currentSweep.id);videoAutoPlay()}}));_atwin.Camera.pose.subscribe((function(pose){return __awaiter(this,void 0,void 0,(function(){var hasElapsed;return __generator(this,(function(_a){switch(_a.label){case 0:_currentCameraPose=pose;console.log("Current Camera Pose",_currentCameraPose);hasElapsed=hasTimeElapsed(300);if(!hasElapsed)return[3,2];console.log("_unrenderedObjects "+_unrenderedObjects.length);return[4,renderOnDemand()];case 1:_a.sent();_a.label=2;case 2:if(hasTimeElapsed(1e3)){getNearbyObjects({type:"ALL",distance:2})}return[2]}}))}))}));_atwin.Mode.current.subscribe((function(mode){_currentViewMode=mode}));_a.label=7;case 7:return[2]}}))}))}));return[3,4];case 3:e_3=_a.sent();console.error(e_3);return[3,4];case 4:return[2]}}))}))}function hasTimeElapsed(maxTime){var currentTimestamp=Date.now();var differenceInMilliseconds=(currentTimestamp-previousTimestamp)%1e3;previousTimestamp=currentTimestamp;if(differenceInMilliseconds>=maxTime){console.log("Elapsed more than ".concat(maxTime));return true}else{console.log("Elapsed less than ".concat(maxTime));return false}}function getNearbyUnrenderedObjects(payload){var toBeRendered=[];var currentPose={x:_currentCameraPose.position.x,y:_currentCameraPose.position.y};toBeRendered=_unrenderedObjects.filter((function(obj){var obj_pos={x:obj.object_position.x,y:obj.object_position.y};var distance=calculateDistance(currentPose,obj_pos);return distance<payload.distance}));var filtered=_unrenderedObjects.filter((function(obj){return toBeRendered.indexOf(obj)===-1}));_unrenderedObjects=filtered;console.log("render toBeRendered "+toBeRendered.length);return toBeRendered}function getNearbyObjects(payload){if(payload.type===undefined||payload.type===""){payload.type="ALL"}if(payload.distance===undefined){payload.distance=2}var pos1={x:_currentCameraPose.position.x,y:_currentCameraPose.position.y};var three_d=[];var videos=[];var slideshows=[];if(payload.type==="ALL"||"3DX"){three_d=_3DXObject.filter((function(obj){var pos2={x:obj.position.x,y:obj.position.y};var distance=calculateDistance(pos1,pos2);console.log("3DX Distance: "+distance);return distance<payload.distance}))}if(payload.type==="ALL"||"VIDEO"){videos=_videos.filter((function(vid){var pos2={x:vid.node.position.x,y:vid.node.position.y};var distance=calculateDistance(pos1,pos2);console.log("Video Distance: "+distance);return distance<payload.distance}))}if(payload.type==="ALL"||"SLIDESHOW"){slideshows=_allSlideShow.filter((function(slide){var pos2={x:slide.node.position.x,y:slide.node.position.y};var distance=calculateDistance(pos1,pos2);console.log("Slideshow Distance: "+distance);return distance<payload.distance}))}console.log("nearby3DXObjects "+three_d.length);console.log("nearbyVideos "+videos.length);console.log("nearbySlideshows "+slideshows.length);return{x3d:three_d,videos:videos,slideshows:slideshows}}function show3DObjects(object){var _a;return __awaiter(this,void 0,void 0,(function(){var sceneObject,id,modelNode,component;return __generator(this,(function(_b){switch(_b.label){case 0:return[4,_atwin.Scene.createObjects(1)];case 1:sceneObject=_b.sent()[0];id=Math.floor(Math.random()*20);modelNode=sceneObject.addNode(id.toString());component=modelNode.addComponent(getComponentLoader(object),{url:(_a=object.object_data)===null||_a===void 0?void 0:_a.amazon_uri});if(!component.inputs){console.error("component.inputs is undefined");return[2]}component.inputs.localScale={x:object.object_scale.x,y:object.object_scale.y,z:object.object_scale.z};modelNode.obj3D.position.set(object.object_position.x,object.object_position.y,object.object_position.z);modelNode.obj3D.rotation.set(object.object_rotation.x,object.object_rotation.y,object.object_rotation.z);_3DXObject.push(modelNode);console.log("_3DXObject "+_3DXObject.length);modelNode.start();component.spyOnEvent(new ClickSpy(object,modelNode,component));return[2]}}))}))}function renderOnDemand(){return __awaiter(this,void 0,void 0,(function(){var objects;var _this=this;return __generator(this,(function(_a){if(_unrenderedObjects.length!==0){console.log("renderOnDemand()");objects=getNearbyUnrenderedObjects({type:"",distance:2});objects.forEach((function(obj){return __awaiter(_this,void 0,void 0,(function(){var _a,_b,_c,_d;return __generator(this,(function(_e){switch(_e.label){case 0:if(!(((_a=obj.object_data)===null||_a===void 0?void 0:_a.object_type)==="FBX"||((_b=obj.object_data)===null||_b===void 0?void 0:_b.object_type)==="GLB"))return[3,2];return[4,show3DObjects(obj)];case 1:_e.sent();return[3,6];case 2:if(!(((_c=obj.object_data)===null||_c===void 0?void 0:_c.object_type)==="MP4"))return[3,4];return[4,showVideoObjects(obj)];case 3:_e.sent();return[3,6];case 4:if(!(((_d=obj.object_data)===null||_d===void 0?void 0:_d.object_type)==="ZIP"))return[3,6];return[4,showSlideScreenModel(obj)];case 5:_e.sent();_e.label=6;case 6:return[2]}}))}))}))}return[2]}))}))}function getIframeSrc(config,url){console.log("getIframeSrc()",config,url);var modelId=url.split("?m=")[1];if(!modelId){console.error("modelId is undefined");return""}var src="";if("bundlePath"in config){src+="".concat(config.bundlePath,"bundle/showcase.html?m=").concat(modelId,"&applicationKey=").concat(sdkKey,"&newtags=1")}else{if(config.prod===undefined||config.prod===null){config.prod=true}if(config.prod){src+="node_modules/architwin/bundle/showcase.html?m=".concat(modelId,"&applicationKey=").concat(sdkKey,"&newtags=1")}else{src+="architwin/bundle/showcase.html?m=".concat(modelId,"&applicationKey=").concat(sdkKey,"&newtags=1")}}console.log("__src",src);for(var _i=0,urlParams_1=urlParams;_i<urlParams_1.length;_i++){var param=urlParams_1[_i];if(param in config){src+="&".concat(param,"=").concat(config[param])}}return src}function loginUser(user){return __awaiter(this,void 0,void 0,(function(){var response;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("loginUser(user)",user);return[4,_api.post("/cas/tickets?email="+user.email+"&password="+user.password)];case 1:response=_a.sent();console.log("loginUser, response",response.status,response.data);if(response.status==200){return[2,response.data]}else{return[2,response]}return[2]}}))}))}function getSpace(spaceId){return __awaiter(this,void 0,void 0,(function(){var response;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("getShowcase(spaceId: string)",spaceId);return[4,_api.get("showcases/id/".concat(spaceId))];case 1:response=_a.sent();console.log("response",response);if(response.status===200){if(response.data.data.length===0){console.error("No data")}return[2,response.data.data[0]]}else{console.error("Error in fetchShowcase()"+response)}return[2,null]}}))}))}function getSpaceId(url){var urlArray=url.split(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/);var path=urlArray[5];var spaceId=path.split("/")[3];console.log("urlArray",urlArray);console.log("path",path);if(!spaceId){console.error("spaceId is undefined");return}return spaceId}function setSpace(space){console.log("setSpace(space: ISpace)",space);_space=space}function getTags(space){return __awaiter(this,void 0,void 0,(function(){var response,tags_1,error_1;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("getTags()");_a.label=1;case 1:_a.trys.push([1,3,,4]);return[4,_api.get("tags/showcase-id/".concat(space.id))];case 2:response=_a.sent();console.log("response",response);if(response.status===200){tags_1=response.data.data;if(!tags_1){console.error("tags is undefined")}return[2,tags_1]}else{console.error("Custom Error: Unable to fetch tags")}return[3,4];case 3:error_1=_a.sent();console.error(error_1);return[3,4];case 4:return[2,null]}}))}))}function setTags(tags){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(_a){console.log("setTags()",tags);_tags=tags.map((function(tag){tag.json_data=JSON.parse(tag.json_data);tag.json_data.id=tag.json_data.sid;return tag}));mapTags(_tags);return[2]}))}))}function get3DObjects(showcase_id){return __awaiter(this,void 0,void 0,(function(){var id,response,showcase_objects,getRequests,response_1,object_data_1,threed_objects,error_2,error_3;return __generator(this,(function(_a){switch(_a.label){case 0:if(!showcase_id)return[3,8];_a.label=1;case 1:_a.trys.push([1,7,,8]);id=parseInt(showcase_id);console.log("showcase_id "+id);return[4,_api.get("showcase-objects/showcase-id/".concat(id))];case 2:response=_a.sent();showcase_objects=response.data.data;console.log("showcase_objects "+JSON.stringify(showcase_objects));getRequests=showcase_objects.map((function(obj){return _api.get("objects/id/".concat(obj.object_id))}));_a.label=3;case 3:_a.trys.push([3,5,,6]);return[4,axios.all(getRequests)];case 4:response_1=_a.sent();object_data_1=response_1.map((function(res){return res.data.data[0]}));console.log("object_data"+JSON.stringify(object_data_1));threed_objects=showcase_objects.map((function(showcase){var target=object_data_1.find((function(obj){return obj.id===showcase.object_id}));if(target){showcase.object_data=target}if(showcase.object_position){showcase.object_position=typeof showcase.object_position==="string"?JSON.parse(showcase.object_position):showcase.object_position}if(showcase.object_rotation){showcase.object_rotation=typeof showcase.object_rotation==="string"?JSON.parse(showcase.object_rotation):showcase.object_rotation}if(showcase.object_scale){showcase.object_scale=typeof showcase.object_scale==="string"?JSON.parse(showcase.object_scale):showcase.object_scale}return showcase}));console.log("get3DObjectsByShowcaseId "+JSON.stringify(threed_objects));_unrenderedObjects=threed_objects;return[2,threed_objects];case 5:error_2=_a.sent();console.error("threed_objects "+error_2);return[3,6];case 6:return[3,8];case 7:error_3=_a.sent();console.error("get3DObjectsByShowcaseId "+error_3);return[3,8];case 8:return[2,[]]}}))}))}function gotoTag(tag_id){return __awaiter(this,void 0,void 0,(function(){var error_4;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("gotoTag(tag: tag_id)",tag_id);if(!tag_id){console.error("tag is undefined");return[2]}_a.label=1;case 1:_a.trys.push([1,3,,4]);return[4,_atwin.Mattertag.navigateToTag(tag_id,_atwin.Mattertag.Transition.FLY)];case 2:_a.sent();return[3,4];case 3:error_4=_a.sent();console.error(error_4);return[3,4];case 4:return[2]}}))}))}function showTags(tags){return __awaiter(this,void 0,void 0,(function(){var _this=this;return __generator(this,(function(_a){tags.forEach((function(tag,indx){return __awaiter(_this,void 0,void 0,(function(){var mpData,tagIds,attachmentId1,error_5;return __generator(this,(function(_a){switch(_a.label){case 0:mpData=tag.json_data;if(!mpData){console.error("tag.json_data/mpData is undefined");return[2]}return[4,_atwin.Tag.add({anchorPosition:mpData.anchorPosition,color:mpData.color,description:mpData.description,id:mpData.sid,label:mpData.label,stemVector:mpData.stemVector,stemVisible:mpData.stemVisible})];case 1:tagIds=_a.sent();if(!tagIds)return[3,6];tag.json_data.id=tagIds[0];if(!(tag.json_data.media&&tag.json_data.media.src.trim()!==""))return[3,6];_a.label=2;case 2:_a.trys.push([2,5,,6]);console.log("Attaching media...");return[4,_atwin.Tag.registerAttachment(tag.json_data.media.src)];case 3:attachmentId1=_a.sent()[0];tag.json_data["attachments"]=[attachmentId1];return[4,_atwin.Tag.attach(tag.json_data.sid,attachmentId1)];case 4:_a.sent();console.log("Media successfully attached");return[3,6];case 5:error_5=_a.sent();console.warn("Custom warn: Media not attached: Invalid media src link: "+error_5);console.warn("mediaSrc: ".concat(tag.json_data.media.src," | tag index: ").concat(indx));return[3,6];case 6:return[2]}}))}))}));console.log("tags",_tags);return[2]}))}))}function hideTags(){return __awaiter(this,void 0,void 0,(function(){var tags,tagIds;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("hideTags()");return[4,_atwin.Mattertag.getData()];case 1:tags=_a.sent();if(!tags)return[3,3];tagIds=tags.map((function(i){return i.sid}));return[4,_atwin.Mattertag.remove(tagIds)];case 2:_a.sent();console.log("Tags removed in space: ",tagIds);_a.label=3;case 3:return[2]}}))}))}function mapTags($tags){console.log("mapTags()",$tags);tags=$tags.map((function(i){var x={};x.id=i.json_data.id;x.name=i.json_data.label;return x}));console.log("tags",tags)}function getCurrentSweep(){return _currentSweep}function getCurrentCameraPose(){return _currentCameraPose}function getCameraPosition(){return _currentCameraPose.position}function getCurrentSweepPosition(){return _currentSweep.position}function getSweeps(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(_a){console.log("Getting Sweeps in Space");_atwin.Sweep.data.subscribe({onCollectionUpdated:function(collection){console.log("Sweeps In Space",collection);if(!collection){console.log("No Sweeps in loaded Space")}_sweeps=collection;var sw=Object.values(_sweeps);sweeps=sw.map((function(item){return{id:item.uuid,position:item.position,neighbors:item.neighbors}}))}});return[2,null]}))}))}function moveToSweep(sweepId){return __awaiter(this,void 0,void 0,(function(){var transition,transitionTime;return __generator(this,(function(_a){transition=_atwin.Sweep.Transition.FLY;transitionTime=2e3;console.log("Sweep Move",sweepId);_atwin.Sweep.moveTo(sweepId,{transition:transition,transitionTime:transitionTime}).then((function(){console.log("Sweep Arrived at sweep "+sweepId)})).catch((function(error){console.log("Sweep Error on Arriving",error)}));return[2]}))}))}function getNearbySweeps(sweepId){return __awaiter(this,void 0,void 0,(function(){var nearby;return __generator(this,(function(_a){switch(_a.label){case 0:if(!sweepId)return[3,2];return[4,sweeps.find((function(item){return item.id==sweepId})).neighbors];case 1:nearby=_a.sent();console.log("Nearby Sweeps",nearby);return[2,nearby];case 2:console.log("No Nearby Sweeps");_a.label=3;case 3:return[2]}}))}))}function getComponentLoader(object){if(object&&object.object_data){var index=object.object_data.object_type;var component={FBX:_atwin.Scene.Component.FBX_LOADER,GLB:_atwin.Scene.Component.GLTF_LOADER,MP4:"liveVideo",ZIP:"slideScreenModel"};return component[index]||""}return""}function setSelectedObject(data,node,component){_selectedObject={object:data,component:component,node:node};console.log("setSelectedObject()")}function setLighting(){return __awaiter(this,void 0,void 0,(function(){var sceneObject,lights;return __generator(this,(function(_a){switch(_a.label){case 0:return[4,_atwin.Scene.createObjects(1)];case 1:sceneObject=_a.sent()[0];lights=sceneObject.addNode();lights.addComponent("mp.directionalLight",{intensity:.6,color:{r:1,g:1,b:1}});lights.addComponent("mp.ambientLight",{intensity:.6,color:{r:1,g:1,b:1}});lights.start();return[2]}}))}))}function clearTransformControls(){if(!_transformControlNode){console.error("_transformControlNode is undefined");return}if(_inputControlComponent==null||!_inputControlComponent){console.error("_inputControlComponent is undefined");return}_transformControlNode.stop();console.log("clearTransformControls()")}function setTransformControls(selectedObject,mode){if(mode===void 0){mode="translate"}return __awaiter(this,void 0,void 0,(function(){var sceneObject,transformNode,transformComponent,inputComponent;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("Object to be transformed "+selectedObject.object.object_data.name);clearTransformControls();return[4,_atwin.Scene.createObjects(1)];case 1:sceneObject=_a.sent()[0];transformNode=sceneObject.addNode();transformComponent=transformNode.addComponent("mp.transformControls");_transformControlNode=transformNode;inputComponent=transformNode.addComponent("mp.input",{eventsEnabled:true,userNavigationEnabled:true});_inputControlComponent=inputComponent.spyOnEvent(new ClickSpy(selectedObject.object,selectedObject.node,selectedObject.component));transformNode.start();transformComponent.inputs.selection=selectedObject.node;transformComponent.inputs.mode=mode;return[2]}}))}))}function calculateDistance(pos1,pos2){var dx=pos2.x-pos1.x;var dy=pos2.y-pos1.y;return Math.sqrt(dx*dx+dy*dy)}function showVideoObjects(object){var _a,_b;return __awaiter(this,void 0,void 0,(function(){var sceneObject,liveStreamNode,liveStreamComponent;return __generator(this,(function(_c){switch(_c.label){case 0:return[4,createVideoComponent()];case 1:_c.sent();return[4,_atwin.Scene.createObjects(1)];case 2:sceneObject=_c.sent()[0];liveStreamNode=sceneObject.addNode();return[4,liveStreamNode.addComponent(getComponentLoader(object),{url:(_a=object.object_data)===null||_a===void 0?void 0:_a.amazon_uri})];case 3:liveStreamComponent=_c.sent();liveStreamNode.position.set(object.object_position.x,object.object_position.y,object.object_position.z);liveStreamNode.obj3D.rotation.set(object.object_rotation.x,object.object_rotation.y,object.object_rotation.z);liveStreamNode.scale.set(object.object_scale.x,object.object_scale.y,object.object_scale.z);if(liveStreamComponent.outputs.loadingState!="Error"){liveStreamNode.start()}liveStreamComponent.inputs.src=(_b=object.object_data)===null||_b===void 0?void 0:_b.amazon_uri;_videos.push({data:object,component:liveStreamComponent,node:liveStreamNode,type:"VIDEO"});return[2]}}))}))}function playVideo(videoId){var videoObject=_videos.find((function(object){return object.data.id==videoId}));if(videoObject){videoObject.component.video.play()}else{console.error("Unable to find video object using that id")}}function pauseVideo(videoId){var videoObject=_videos.find((function(object){return object.data.id==videoId}));if(videoObject){videoObject.component.video.pause()}else{console.error("Unable to find video object using that id")}}function videoAutoPlay(){function nearestVideo(videoObject){return __awaiter(this,void 0,void 0,(function(){var videoPosition,cameraPosition,computedDistance;return __generator(this,(function(_a){videoPosition=videoObject.data.object_position;cameraPosition=getCurrentSweepPosition();computedDistance=distance([cameraPosition.x,cameraPosition.y,cameraPosition.z],[videoPosition.x,videoPosition.y,videoPosition.z]);try{if(videoObject.data.autoplay&&videoObject.data.autoplay_distance&&computedDistance<videoObject.data.autoplay_distance){videoObject.component.video.play()}else{videoObject.component.video.pause()}}catch(e){console.error("Unable to play or stop video")}return[2]}))}))}_videos.forEach((function(videoObject){return nearestVideo(videoObject)}))}function createVideoComponent(){function videoRenderer(){this.inputs={visible:true,userNavigationEnabled:true,eventsEnabled:true,colliderEnabled:true,src:null};this.outputs={texture:null,video:null,aspect:720/480};this.onInit=function(){this.video;this.texture};this.onEvent=function(eventType,eventData){};this.onInputsUpdated=function(previous){this.releaseTexture();var THREE=this.context.three;if(!this.inputs.src){this.video.src="";return}if(this.inputs.src instanceof HTMLVideoElement){this.video=this.inputs.src}else{this.video=this.createVideoElement();if(typeof this.inputs.src==="string"){this.video.src=this.inputs.src}else{this.video.srcObject=this.inputs.src}this.video.load()}this.texture=new THREE.VideoTexture(this.video);this.texture.minFilter=THREE.LinearFilter;this.texture.magFilter=THREE.LinearFilter;this.texture.format=THREE.RGBFormat;var geometry=new THREE.PlaneGeometry(1,1);geometry.scale(1,480/720,1);geometry.translate(0,.33,0);this.material=new THREE.MeshBasicMaterial({map:this.texture,side:THREE.DoubleSide});var mesh=new THREE.Mesh(geometry,this.material);this.outputs.objectRoot=mesh;this.outputs.collider=mesh;mesh.visible=this.inputs.visible;this.outputs.texture=this.texture;this.outputs.video=this.video};this.releaseTexture=function(){if(this.texture){this.outputs.texture=null;this.texture.dispose()}};this.createVideoElement=function(){var video=document.createElement("video");video.setAttribute("id","htmlLivestreamVideo");video.crossOrigin="anonymous";video.setAttribute("height","480");video.setAttribute("width","720");video.setAttribute("webkit-playsinline","webkit-playsinline");video.setAttribute("controls","controls");video.muted=false;video.loop=true;video.volume=1;return video};this.onTick=function(tickDelta){};this.onDestroy=function(){this.material.dispose()};this.spyOnEvent=function(payload){console.log("payload",payload)}}function makeVideoRender(){return new videoRenderer}_atwin.Scene.register("liveVideo",makeVideoRender)}function createSlideScreenModel(){function SlideScreenModelRenderer(){this.inputs={src:null,userNavigationEnabled:true,eventsEnabled:true,colliderEnabled:true,visible:true};this.outputs={texture:null,t_image:null};this.onInit=function(){this.texture;this.t_image;this.material;this.mesh};this.events={"INTERACTION.CLICK":true};this.onEvent=function(eventType,eventData){return __awaiter(this,void 0,void 0,(function(){var slideshow_1,mousePosition,planePosition;var _this=this;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("onEventSlideShow",eventType,eventData);if(!(eventType=="INTERACTION.CLICK"))return[3,2];if(!(_allSlideShow.length>0))return[3,2];slideshow_1=_allSlideShow.filter((function(l){var _a,_b,_c,_d;return(_d=((_b=(_a=l.collider)===null||_a===void 0?void 0:_a.collider)===null||_b===void 0?void 0:_b.uuid)==((_c=eventData.collider)===null||_c===void 0?void 0:_c.uuid))!==null&&_d!==void 0?_d:false}))[0];console.log("slideShow eventData",slideshow_1);if(!(slideshow_1!=null))return[3,2];console.log("slideShow eventData",slideshow_1);return[4,getMousePosition()];case 1:mousePosition=_a.sent();planePosition=slideshow_1.node.obj3D.position;console.log("MOUSE POSITION",mousePosition);console.log("PLANE POSITION",planePosition);if(slideshow_1.object.object_type=="ZIP"){if(slideshow_1.id!=_currentSlideShowID){_currentSlideIndex=_slideShowImage.find((function(elem){return elem.id===slideshow_1.id})).idx;console.log("CURRENT INDEX",_currentSlideIndex);_currentSlideShow=_slideShowImage.find((function(elem){return elem.id===slideshow_1.id})).images;console.log("CURRENT SLIDE",_currentSlideShow)}if(slideshow_1.id==_currentSlideShowID){console.log("ChangeImage",slideshow_1,_currentSlideShowID);if(planePosition.x<mousePosition.x){console.log("LEFT SIDE");clearInterval(_timer);this.inputs.src=imageStream("prev")}else if(planePosition.y<mousePosition.y){console.log("RIGHT SIDE");clearInterval(_timer);this.inputs.src=imageStream("next")}else if(planePosition.y>mousePosition.y){console.log("AUTOPLAY");_timer=setInterval((function(){_currentSlideIndex=(_currentSlideIndex+1)%_currentSlideShow.length;console.log("CURRENT INDEX",_currentSlideIndex);_this.inputs.src=imageStream("next")}),2e3)}}else{_currentSlideShowID=slideshow_1.id}}_a.label=2;case 2:return[2]}}))}))};this.onInputsUpdated=function(previous){var _this=this;this.releaseTexture();var three=this.context.three;this.t_image=document.createElement("IMG");this.t_image.src=this.inputs.src;this.t_image.setAttribute("width","auto");this.t_image.setAttribute("height","auto");this.t_image.crossOrigin="anonymous";var planeGeo=new three.PlaneGeometry(1.5,1.5);planeGeo.translate(0,.33,0);if(previous.src!=this.inputs.src){console.log("this.inputs.src",this.inputs.src);this.texture=(new three.TextureLoader).load(this.t_image.src,(function(tex){if(tex===void 0){tex=_this.texture}tex.minFilter=three.LinearFilter;tex.magFilter=three.LinearFilter;tex.format=three.RGBAFormat;tex.needsUpdate=true;tex.onUpdate=_this.textureUpdated;_this.material=new three.MeshBasicMaterial({map:_this.texture,side:three.DoubleSide,transparent:true,alphaTest:.5});_this.mesh=new three.Mesh(planeGeo,_this.material);_this.mesh.scale.set(1,_this.texture.image.height/_this.texture.image.width,1);_this.outputs.objectRoot=_this.mesh;_this.outputs.collider=_this.mesh;_this.outputs.texture=_this.texture;_this.outputs.t_image=_this.t_image}))}if(this.mesh!=null){this.mesh.visible=this.inputs.visible}};this.textureUpdated=function(params){console.log("Update Callback",params)};this.releaseTexture=function(){if(this.texture){this.outputs.texture=null}};this.onTick=function(tickDelta){};this.onDestroy=function(){this.material.dispose();this.texture.dispose()}}function makeSlideScreenModelRenderer(){return new SlideScreenModelRenderer}_atwin.Scene.register("slideScreenModel",makeSlideScreenModelRenderer)}function showSlideScreenModel(object){return __awaiter(this,void 0,void 0,(function(){var sceneObject,modelNode,component,slideShow;return __generator(this,(function(_a){switch(_a.label){case 0:createSlideScreenModel();return[4,_atwin.Scene.createObjects(1)];case 1:sceneObject=_a.sent()[0];modelNode=sceneObject.addNode();component=modelNode.addComponent("slideScreenModel");console.log("COMPONENT",component);modelNode.scale.set={x:object.object_scale.x,y:object.object_scale.y,z:object.object_scale.z};modelNode.obj3D.position.set(object.object_position.x,object.object_position.y,object.object_position.z);modelNode.obj3D.rotation.set(object.object_rotation.x,object.object_rotation.y,object.object_rotation.z);modelNode.start();return[4,addImageToSlideShow(object.object_data,component,object.id)];case 2:_a.sent();console.log("SLIDE OUTPUT",component.outputs);slideShow={id:object.id,collider:component.outputs,object:object.object_data,node:modelNode,component:component,type:"ZIP"};_allSlideShow.push(slideShow);console.log("ALL SLIDESHOW",_allSlideShow);return[2]}}))}))}function addImageToSlideShow(data,component,objectID){return __awaiter(this,void 0,void 0,(function(){var dataList;return __generator(this,(function(_a){switch(_a.label){case 0:dataList=[];return[4,new JSZip.external.Promise((function(resolve,reject){JSZipUtils.getBinaryContent(data.amazon_uri,(function(err,data){if(err){console.log("getBI error",err);reject(err)}else{console.log("getBI success",data);resolve(data)}}))})).then((function(data){console.log("data from getBI",data);return JSZip.loadAsync(data)})).then((function(data){console.log("data from loadAsync",data);var _loop_1=function(key){if(key.includes("__MACOSX"))return"continue";if(key.includes(".DS_Store"))return"continue";if(data.files[key].dir)return"continue";var base=data.file(data.files[key].name).async("base64");base.then((function(res){dataList.push({name:data.files[key].name,path:"data:image/png;base64,".concat(res)});if(dataList.length==1){component.inputs.src="data:image/png;base64,".concat(res)}}))};for(var key in data.files){_loop_1(key)}_slideShowImage.push({id:objectID,images:dataList,idx:0,playID:null,play:false,comp:component})}))];case 1:_a.sent();return[2]}}))}))}function getMousePosition(){return __awaiter(this,void 0,void 0,(function(){var planePosition;return __generator(this,(function(_a){switch(_a.label){case 0:return[4,_atwin.Pointer.intersection.subscribe((function(intersection){planePosition=intersection.position}))];case 1:_a.sent();return[2,planePosition]}}))}))}function imageStream(direction){var diff=direction==="prev"?-1:1;var length=_currentSlideShow.length;var index=_currentSlideIndex+diff;if(index===-1){index=length-1}if(index===length){index=0}_currentSlideIndex=index;_slideShowImage.find((function(elem){return elem.id===_currentSlideShowID})).idx=index;return _currentSlideShow[_currentSlideIndex].path}function cameraRotate(x,y,speed){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(_a){switch(_a.label){case 0:return[4,_atwin.Camera.rotate(x,y,{speed:speed}).then((function(){console.log("camera rotate success.",x,y)})).catch((function(error){console.log("camera rotate error.",error)}))];case 1:_a.sent();return[2]}}))}))}function cameraPan(x,z){return __awaiter(this,void 0,void 0,(function(){var mode;return __generator(this,(function(_a){switch(_a.label){case 0:mode=getViewMode();if(!(mode==_atwin.Mode.Mode.FLOORPLAN||mode==_atwin.Mode.Mode.DOLLHOUSE))return[3,2];return[4,_atwin.Camera.pan({x:x,z:z}).then((function(){console.log("camera pan success.")})).catch((function(error){console.log("camera rotate error:",error)}))];case 1:_a.sent();return[3,3];case 2:console.error("Incorrect view mode.");_a.label=3;case 3:return[2]}}))}))}function cameraLookAt(x,y){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(_a){switch(_a.label){case 0:return[4,_atwin.Camera.lookAtScreenCoords(x,y).then((function(){console.log("camera looking at...",x,y)})).catch((function(error){console.log("camera looking at error:",error)}))];case 1:_a.sent();return[2]}}))}))}function moveInDirection(direction){return __awaiter(this,void 0,void 0,(function(){var nextDirection;return __generator(this,(function(_a){switch(_a.label){case 0:nextDirection=_atwin.Camera.Direction.LEFT;switch(direction.toUpperCase()){case"LEFT":nextDirection=_atwin.Camera.Direction.LEFT;break;case"RIGHT":nextDirection=_atwin.Camera.Direction.RIGHT;break;case"UP":nextDirection=_atwin.Camera.Direction.UP;break;case"DOWN":nextDirection=_atwin.Camera.Direction.DOWN;break;case"BACK":nextDirection=_atwin.Camera.Direction.BACK;break;case"FORWARD":nextDirection=_atwin.Camera.Direction.FORWARD;break;default:nextDirection=_atwin.Camera.Direction.LEFT;break}return[4,_atwin.Camera.moveInDirection(nextDirection).then((function(){console.log("Move to...",nextDirection)})).catch((function(){console.warn("An error occured while moving in that direction.",nextDirection)}))];case 1:_a.sent();return[2]}}))}))}function getViewMode(){return _currentViewMode}function setViewMode(mode){return __awaiter(this,void 0,void 0,(function(){var modeType;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("=== get Mode Type ===",_getModeType(mode));modeType=_getModeType(mode);return[4,_atwin.Mode.moveTo(modeType).then((function(nextMode){console.log("Arrived at new view mode "+nextMode)})).catch((function(error){console.error("Error occur on:",error)}))];case 1:_a.sent();return[2]}}))}))}function _getModeType(mode){var modes={DOLLHOUSE:"mode.dollhouse",FLOORPLAN:"mode.floorplan",INSIDE:"mode.inside",OUTSIDE:"mode.outside",TRANSITIONING:"mode.transitioning"};return modes[mode.toUpperCase()]||""}function disconnectSpace(){console.log("disconnectSpace()");_atwin.disconnect();_iframe.src="";_api={};_space={};_atwin={};_tags=[];tags=[];sweeps=[];_allSlideShow=[];_slideShowImage=[];_currentSlideShowID=0;_currentSlideIndex=0;_currentSlideShow=null;_timer=null;_videos=[];_currentViewMode="";_3DXObject=[];_unrenderedObjects=[];previousTimestamp=0;_currentSweep={};_currentCameraPose={};_sweeps=[]}var ClickSpy=function(){function ClickSpy(data,node,component){this.eventType="INTERACTION.CLICK";this.object_data=data;this.node=node;this.component=component}ClickSpy.prototype.onEvent=function(payload){return __awaiter(this,void 0,void 0,(function(){var selectedObj;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("INTERACTION.CLICK",payload);selectedObj={object:this.object_data,node:this.node,component:this.component};setSelectedObject(this.object_data,this.node,this.component);return[4,setTransformControls(selectedObj)];case 1:_a.sent();return[2]}}))}))};return ClickSpy}();var atwin={tags:tags,sweeps:sweeps,connectSpace:connectSpace,disconnectSpace:disconnectSpace,gotoTag:gotoTag,getCurrentSweep:getCurrentSweep,getCurrentSweepPosition:getCurrentSweepPosition,moveToSweep:moveToSweep,getNearbySweeps:getNearbySweeps,pauseVideo:pauseVideo,playVideo:playVideo,getCurrentCameraPose:getCurrentCameraPose,getCameraPosition:getCameraPosition,moveInDirection:moveInDirection,cameraLookAt:cameraLookAt,cameraPan:cameraPan,cameraRotate:cameraRotate,getViewMode:getViewMode,setViewMode:setViewMode};export{atwin as default,tags,sweeps,connectSpace,disconnectSpace,gotoTag,getCurrentSweep,getCurrentSweepPosition,moveToSweep,getNearbySweeps,pauseVideo,playVideo,getCurrentCameraPose,getCameraPosition,moveInDirection,cameraLookAt,cameraPan,cameraRotate,getViewMode,setViewMode};
1
+ var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P((function(resolve){resolve(value)}))}return new(P||(P=Promise))((function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator["throw"](value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):adopt(result.value).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())}))};var __generator=this&&this.__generator||function(thisArg,body){var _={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},f,y,t,g;return g={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(g[Symbol.iterator]=function(){return this}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break}if(t[2])_.ops.pop();_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e];y=0}finally{f=t=0}if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true}}};import axios from"axios";import{distance}from"mathjs";import JSZip from"jszip";import JSZipUtils from"jszip-utils";var _config={aws:{region:"ap-northeast-1",accessKeyId:"AKIAVVUXZ66KW7GBSW7A",secretAccessKey:"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'"},mp:{sdkKey:"a3ae8341bd8f44899eba16df86307d7d",urlParams:["help","play","nt","qs","brand","dh","tour","gt","hr","mls","mt","tagNav","pin","portal","f","fp","lang","kb","lp","st","title","tourcta","wts","ts","hl","vr","nozoom","search","wh"]}};var _apiURL="http://localhost:5173/api";var sdkKey=_config.mp.sdkKey;var urlParams=_config.mp.urlParams;var _iframe={};var _api={};var _space={};var _atwin={};var _tags=[];var tags=[];var sweeps=[];var _allSlideShow=[];var _slideShowImage=[];var _currentSlideShowID=0;var _currentSlideIndex=0;var _currentSlideShow=null;var _timer=null;var _videos=[];var _currentViewMode="";var _3DXObject=[];var _unrenderedObjects=[];var _transformControlNode;var _inputControlComponent=null;var _selectedObject={};var _previousTimeStamp=0;var _renderDistance=null;var _autoDetectNearbyObj=false;var _currentSweep={};var _currentCameraPose={};var _sweeps=[];var _isInitialLoad=true;function connectSpace(url,auth,config){return __awaiter(this,void 0,void 0,(function(){var lastString,api,showcase;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("connectSpace()");console.log("__config",config);if("apiURL"in auth){lastString=auth.apiURL.slice(-1);if(lastString!=="/"){auth.apiURL+="/"}_apiURL=auth.apiURL}console.log("_apiURL",_apiURL);api=axios.create({baseURL:_apiURL,headers:{"Access-Control-Allow-Origin":"*","Content-Type":"application/json",Authorization:auth.apiKey}});_api=api;showcase=document.getElementById(config.iframeId);_iframe=showcase;if(!url.includes("https://my.matterport.com/show/"))return[3,2];console.log("URL IS MATTERPORT");return[4,loadDefaultMpSpace(url,config,showcase)];case 1:_a.sent();return[3,4];case 2:console.log("URL IS REV-KITTEN");return[4,loadAtwinSpace(url,auth,config,showcase)];case 3:_a.sent();_a.label=4;case 4:return[2]}}))}))}function loadDefaultMpSpace(url,config,showcase){return __awaiter(this,void 0,void 0,(function(){var iframeSrc,showcaseWindow,_setTags;var _this=this;return __generator(this,(function(_a){console.log("loadDefaultMpSpace(url: string, showcase: HTMLIFrameElement)",url,showcase);iframeSrc=getIframeSrc(config,url);console.log("__iframeSrc",iframeSrc);showcase.src=iframeSrc;showcaseWindow=showcase.contentWindow;showcase.addEventListener("load",(function(){return __awaiter(_this,void 0,void 0,(function(){var e_1;var _this=this;return __generator(this,(function(_a){switch(_a.label){case 0:console.log('iframe.addEventListener("load")');console.log("showcaseWindow",showcaseWindow);_a.label=1;case 1:_a.trys.push([1,3,,4]);return[4,showcaseWindow.MP_SDK.connect(showcaseWindow)];case 2:_atwin=_a.sent();console.log("Hello Bundle SDK",_atwin);_atwin.App.state.subscribe((function(appState){return __awaiter(_this,void 0,void 0,(function(){return __generator(this,(function(_a){switch(_a.label){case 0:console.log("appState",appState);if(!(appState.phase===_atwin.App.Phase.LOADING))return[3,2];console.log("App is loading...");return[4,_setTags()];case 1:_a.sent();return[3,3];case 2:if(appState.phase===_atwin.App.Phase.STARTING){console.log("App is starting...")}else if(appState.phase===_atwin.App.Phase.PLAYING){console.log("App is playing...")}_a.label=3;case 3:return[2]}}))}))}));return[3,4];case 3:e_1=_a.sent();console.error(e_1);return[3,4];case 4:return[2]}}))}))}));_setTags=function(){return __awaiter(_this,void 0,void 0,(function(){var mpTags,filteredMpTags;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("_setTags()");return[4,_atwin.Mattertag.getData()];case 1:mpTags=_a.sent();if(mpTags){filteredMpTags=mpTags.map((function(i){var x={};x.id=i.sid;x.name=i.label;return x}));tags=filteredMpTags;console.log("tags",tags)}return[2]}}))}))};return[2]}))}))}function loadAtwinSpace(url,auth,config,showcase){var _a;return __awaiter(this,void 0,void 0,(function(){var spaceId,space,iframeSrc,tags,objects,showcaseWindow;var _this=this;return __generator(this,(function(_b){switch(_b.label){case 0:console.log("loadAtwinSpace(url: string, auth: { apiKey: string; user: IUser },config: IMPConfig, showcase: HTMLIFrameElement)");spaceId=getSpaceId(url);if(!spaceId){console.error("spaceId is undefined");return[2]}if(!_isInitialLoad)return[3,2];return[4,loginUser(auth.user)];case 1:_b.sent();_b.label=2;case 2:return[4,getSpace(spaceId)];case 3:space=_b.sent();if(!space){console.error("space is undefined");return[2]}setSpace(space);iframeSrc=getIframeSrc(config,space.space_url);console.log("__iframeSrc",iframeSrc);showcase.src=iframeSrc;return[4,getTags(space)];case 4:tags=_b.sent();if(!tags){console.log("tags is undefined");return[2]}setTags(tags);return[4,get3DObjects(spaceId)];case 5:objects=_b.sent();if(!objects){console.log("objects is undefined");return[2]}if(_isInitialLoad){(_a=showcase.contentWindow)===null||_a===void 0?void 0:_a.location.reload()}_isInitialLoad=false;showcaseWindow=showcase.contentWindow;showcase.addEventListener("load",(function(){return __awaiter(_this,void 0,void 0,(function(){var e_2;return __generator(this,(function(_a){switch(_a.label){case 0:console.log('iframe.addEventListener("load")');console.log("showcaseWindow",showcaseWindow);if(!showcaseWindow.MP_SDK)return[3,5];_a.label=1;case 1:_a.trys.push([1,3,,4]);return[4,showcaseWindow.MP_SDK.connect(showcaseWindow)];case 2:_atwin=_a.sent();console.log("Hello Bundle SDK",_atwin);onShowcaseConnect();return[3,4];case 3:e_2=_a.sent();console.error(e_2);return[3,4];case 4:return[3,6];case 5:console.log("No showcaseWindow.MP_SDK found");_a.label=6;case 6:return[2]}}))}))}));return[2]}}))}))}function onShowcaseConnect(){return __awaiter(this,void 0,void 0,(function(){var modelData,e_3;var _this=this;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("onShowcaseConnect()");_a.label=1;case 1:_a.trys.push([1,3,,4]);return[4,_atwin.Model.getData()];case 2:modelData=_a.sent();console.log("Model sid:"+modelData.sid);_atwin.App.state.subscribe((function(appState){return __awaiter(_this,void 0,void 0,(function(){return __generator(this,(function(_a){switch(_a.label){case 0:console.log("appState",appState);if(!(appState.phase===_atwin.App.Phase.LOADING))return[3,1];console.log("App is loading...");return[3,7];case 1:if(!(appState.phase===_atwin.App.Phase.STARTING))return[3,3];console.log("App is starting...");return[4,hideTags()];case 2:_a.sent();return[3,7];case 3:if(!(appState.phase===_atwin.App.Phase.PLAYING))return[3,7];console.log("App is playing...");return[4,showTags(_tags)];case 4:_a.sent();return[4,getSweeps()];case 5:_a.sent();return[4,setLighting()];case 6:_a.sent();_atwin.Sweep.current.subscribe((function(currentSweep){if(currentSweep.sid===""){console.log("Not currently stationed at a sweep position")}else{_currentSweep=currentSweep;console.log("Currently at sweep",_currentSweep.id);videoAutoPlay()}}));_atwin.Camera.pose.subscribe((function(pose){return __awaiter(this,void 0,void 0,(function(){var hasElapsed;return __generator(this,(function(_a){switch(_a.label){case 0:_currentCameraPose=pose;console.log("Current Camera Pose",_currentCameraPose);hasElapsed=hasTimeElapsed(300);if(!hasElapsed)return[3,2];console.log("_unrenderedObjects "+_unrenderedObjects.length);return[4,renderOnDemand()];case 1:_a.sent();_a.label=2;case 2:if(hasTimeElapsed(1e3)&&_autoDetectNearbyObj){getNearbyObjects({type:"ALL",distance:2})}return[2]}}))}))}));_atwin.Mode.current.subscribe((function(mode){_currentViewMode=mode}));_a.label=7;case 7:return[2]}}))}))}));return[3,4];case 3:e_3=_a.sent();console.error(e_3);return[3,4];case 4:return[2]}}))}))}function hasTimeElapsed(maxTime){var currentTimestamp=Date.now();var differenceInMilliseconds=(currentTimestamp-_previousTimeStamp)%1e3;_previousTimeStamp=currentTimestamp;if(differenceInMilliseconds>=maxTime){console.log("Elapsed more than ".concat(maxTime));return true}else{console.log("Elapsed less than ".concat(maxTime));return false}}function getNearbyUnrenderedObjects(payload){var toBeRendered=[];var currentPose={x:_currentCameraPose.position.x,y:_currentCameraPose.position.y};toBeRendered=_unrenderedObjects.filter((function(obj){var obj_pos={x:obj.object_position.x,y:obj.object_position.y};var distance=calculateDistance(currentPose,obj_pos);return distance<payload.distance}));var filtered=_unrenderedObjects.filter((function(obj){return toBeRendered.indexOf(obj)===-1}));_unrenderedObjects=filtered;console.log("render toBeRendered "+toBeRendered.length);return toBeRendered}function getNearbyObjects(payload){if(payload.type===undefined||payload.type===""){payload.type="ALL"}if(payload.distance===undefined){payload.distance=2}var pos1={x:_currentCameraPose.position.x,y:_currentCameraPose.position.y};var three_d=[];var videos=[];var slideshows=[];if(payload.type==="ALL"||"3DX"){three_d=_3DXObject.filter((function(obj){var pos2={x:obj.position.x,y:obj.position.y};var distance=calculateDistance(pos1,pos2);console.log("3DX Distance: "+distance);return distance<payload.distance}))}if(payload.type==="ALL"||"VIDEO"){videos=_videos.filter((function(vid){var pos2={x:vid.node.position.x,y:vid.node.position.y};var distance=calculateDistance(pos1,pos2);console.log("Video Distance: "+distance);return distance<payload.distance}))}if(payload.type==="ALL"||"SLIDESHOW"){slideshows=_allSlideShow.filter((function(slide){var pos2={x:slide.node.position.x,y:slide.node.position.y};var distance=calculateDistance(pos1,pos2);console.log("Slideshow Distance: "+distance);return distance<payload.distance}))}console.log("nearby3DXObjects "+three_d.length);console.log("nearbyVideos "+videos.length);console.log("nearbySlideshows "+slideshows.length);return{x3d:three_d,videos:videos,slideshows:slideshows}}function show3DObjects(object){var _a;return __awaiter(this,void 0,void 0,(function(){var sceneObject,id,modelNode,component;return __generator(this,(function(_b){switch(_b.label){case 0:return[4,_atwin.Scene.createObjects(1)];case 1:sceneObject=_b.sent()[0];id=Math.floor(Math.random()*20);modelNode=sceneObject.addNode(id.toString());component=modelNode.addComponent(getComponentLoader(object),{url:(_a=object.object_data)===null||_a===void 0?void 0:_a.amazon_uri});if(!component.inputs){console.error("component.inputs is undefined");return[2]}component.inputs.localScale={x:object.object_scale.x,y:object.object_scale.y,z:object.object_scale.z};modelNode.obj3D.position.set(object.object_position.x,object.object_position.y,object.object_position.z);modelNode.obj3D.rotation.set(object.object_rotation.x,object.object_rotation.y,object.object_rotation.z);_3DXObject.push(modelNode);console.log("_3DXObject "+_3DXObject.length);modelNode.start();component.spyOnEvent(new ClickSpy(object,modelNode,component));return[2]}}))}))}function renderOnDemand(){return __awaiter(this,void 0,void 0,(function(){var objects;var _this=this;return __generator(this,(function(_a){if(_unrenderedObjects.length!==0){console.log("renderOnDemand()");objects=getNearbyUnrenderedObjects({type:"",distance:2});objects.forEach((function(obj){return __awaiter(_this,void 0,void 0,(function(){var _a,_b,_c,_d;return __generator(this,(function(_e){switch(_e.label){case 0:if(!(((_a=obj.object_data)===null||_a===void 0?void 0:_a.object_type)==="FBX"||((_b=obj.object_data)===null||_b===void 0?void 0:_b.object_type)==="GLB"))return[3,2];return[4,show3DObjects(obj)];case 1:_e.sent();return[3,6];case 2:if(!(((_c=obj.object_data)===null||_c===void 0?void 0:_c.object_type)==="MP4"))return[3,4];return[4,showVideoObjects(obj)];case 3:_e.sent();return[3,6];case 4:if(!(((_d=obj.object_data)===null||_d===void 0?void 0:_d.object_type)==="ZIP"))return[3,6];return[4,showSlideScreenModel(obj)];case 5:_e.sent();_e.label=6;case 6:return[2]}}))}))}))}return[2]}))}))}function getIframeSrc(config,url){console.log("getIframeSrc()",config,url);var modelId=url.split("?m=")[1];if(!modelId){console.error("modelId is undefined");return""}var src="";if("bundlePath"in config){var lastString=config.bundlePath.slice(-1);if(lastString!=="/"){config.bundlePath+="/"}src+="".concat(config.bundlePath,"showcase.html?m=").concat(modelId,"&applicationKey=").concat(sdkKey,"&newtags=1")}else{if(config.prod===undefined||config.prod===null){config.prod=true}if(config.prod){src+="node_modules/architwin/bundle/showcase.html?m=".concat(modelId,"&applicationKey=").concat(sdkKey,"&newtags=1")}else{src+="architwin/bundle/showcase.html?m=".concat(modelId,"&applicationKey=").concat(sdkKey,"&newtags=1")}}console.log("__src",src);for(var _i=0,urlParams_1=urlParams;_i<urlParams_1.length;_i++){var param=urlParams_1[_i];if(param in config){src+="&".concat(param,"=").concat(config[param])}}return src}function loginUser(user){return __awaiter(this,void 0,void 0,(function(){var response;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("loginUser(user)",user);return[4,_api.post("/cas/tickets?email="+user.email+"&password="+user.password)];case 1:response=_a.sent();console.log("loginUser, response",response.status,response.data);if(response.status==200){return[2,response.data]}else{return[2,response]}return[2]}}))}))}function getSpace(spaceId){return __awaiter(this,void 0,void 0,(function(){var response;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("getShowcase(spaceId: string)",spaceId);return[4,_api.get("/v1/showcases/id/".concat(spaceId))];case 1:response=_a.sent();console.log("response",response);if(response.status===200){if(response.data.data.length===0){console.error("No data")}return[2,response.data.data[0]]}else{console.error("Error in fetchShowcase()"+response)}return[2,null]}}))}))}function getSpaceId(url){var urlArray=url.split(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/);var path=urlArray[5];var spaceId=path.split("/")[3];console.log("urlArray",urlArray);console.log("path",path);if(!spaceId){console.error("spaceId is undefined");return}return spaceId}function setSpace(space){console.log("setSpace(space: ISpace)",space);_space=space}function getTags(space){return __awaiter(this,void 0,void 0,(function(){var response,tags_1,error_1;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("getTags()");_a.label=1;case 1:_a.trys.push([1,3,,4]);return[4,_api.get("/v1/tags/showcase-id/".concat(space.id))];case 2:response=_a.sent();console.log("response",response);if(response.status===200){tags_1=response.data.data;if(!tags_1){console.error("tags is undefined")}return[2,tags_1]}else{console.error("Custom Error: Unable to fetch tags")}return[3,4];case 3:error_1=_a.sent();console.error(error_1);return[3,4];case 4:return[2,null]}}))}))}function setTags(tags){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(_a){console.log("setTags()",tags);_tags=tags.map((function(tag){tag.json_data=JSON.parse(tag.json_data);tag.json_data.id=tag.json_data.sid;return tag}));mapTags(_tags);return[2]}))}))}function get3DObjects(showcase_id){return __awaiter(this,void 0,void 0,(function(){var id,response,showcase_objects,getRequests,response_1,object_data_1,threed_objects,error_2,error_3;return __generator(this,(function(_a){switch(_a.label){case 0:if(!showcase_id)return[3,8];_a.label=1;case 1:_a.trys.push([1,7,,8]);id=parseInt(showcase_id);console.log("showcase_id "+id);return[4,_api.get("/v1/showcase-objects/showcase-id/".concat(id))];case 2:response=_a.sent();showcase_objects=response.data.data;console.log("showcase_objects "+JSON.stringify(showcase_objects));getRequests=showcase_objects.map((function(obj){return _api.get("/v1/objects/id/".concat(obj.object_id))}));_a.label=3;case 3:_a.trys.push([3,5,,6]);return[4,axios.all(getRequests)];case 4:response_1=_a.sent();object_data_1=response_1.map((function(res){return res.data.data[0]}));console.log("object_data"+JSON.stringify(object_data_1));threed_objects=showcase_objects.map((function(showcase){var target=object_data_1.find((function(obj){return obj.id===showcase.object_id}));if(target){showcase.object_data=target}if(showcase.object_position){showcase.object_position=typeof showcase.object_position==="string"?JSON.parse(showcase.object_position):showcase.object_position}if(showcase.object_rotation){showcase.object_rotation=typeof showcase.object_rotation==="string"?JSON.parse(showcase.object_rotation):showcase.object_rotation}if(showcase.object_scale){showcase.object_scale=typeof showcase.object_scale==="string"?JSON.parse(showcase.object_scale):showcase.object_scale}return showcase}));console.log("get3DObjectsByShowcaseId "+JSON.stringify(threed_objects));_unrenderedObjects=threed_objects;return[2,threed_objects];case 5:error_2=_a.sent();console.error("threed_objects "+error_2);return[3,6];case 6:return[3,8];case 7:error_3=_a.sent();console.error("get3DObjectsByShowcaseId "+error_3);return[3,8];case 8:return[2,[]]}}))}))}function gotoTag(tag_id){return __awaiter(this,void 0,void 0,(function(){var error_4;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("gotoTag(tag: tag_id)",tag_id);if(!tag_id){console.error("tag is undefined");return[2]}_a.label=1;case 1:_a.trys.push([1,3,,4]);return[4,_atwin.Mattertag.navigateToTag(tag_id,_atwin.Mattertag.Transition.FLY)];case 2:_a.sent();return[3,4];case 3:error_4=_a.sent();console.error(error_4);return[3,4];case 4:return[2]}}))}))}function showTags(tags){return __awaiter(this,void 0,void 0,(function(){var _this=this;return __generator(this,(function(_a){tags.forEach((function(tag,indx){return __awaiter(_this,void 0,void 0,(function(){var mpData,tagIds,attachmentId1,error_5;return __generator(this,(function(_a){switch(_a.label){case 0:mpData=tag.json_data;if(!mpData){console.error("tag.json_data/mpData is undefined");return[2]}return[4,_atwin.Tag.add({anchorPosition:mpData.anchorPosition,color:mpData.color,description:mpData.description,id:mpData.sid,label:mpData.label,stemVector:mpData.stemVector,stemVisible:mpData.stemVisible})];case 1:tagIds=_a.sent();if(!tagIds)return[3,6];tag.json_data.id=tagIds[0];if(!(tag.json_data.media&&tag.json_data.media.src.trim()!==""))return[3,6];_a.label=2;case 2:_a.trys.push([2,5,,6]);console.log("Attaching media...");return[4,_atwin.Tag.registerAttachment(tag.json_data.media.src)];case 3:attachmentId1=_a.sent()[0];tag.json_data["attachments"]=[attachmentId1];return[4,_atwin.Tag.attach(tag.json_data.sid,attachmentId1)];case 4:_a.sent();console.log("Media successfully attached");return[3,6];case 5:error_5=_a.sent();console.warn("Custom warn: Media not attached: Invalid media src link: "+error_5);console.warn("mediaSrc: ".concat(tag.json_data.media.src," | tag index: ").concat(indx));return[3,6];case 6:return[2]}}))}))}));console.log("tags",_tags);return[2]}))}))}function hideTags(){return __awaiter(this,void 0,void 0,(function(){var tags,tagIds;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("hideTags()");return[4,_atwin.Mattertag.getData()];case 1:tags=_a.sent();if(!tags)return[3,3];tagIds=tags.map((function(i){return i.sid}));return[4,_atwin.Mattertag.remove(tagIds)];case 2:_a.sent();console.log("Tags removed in space: ",tagIds);_a.label=3;case 3:return[2]}}))}))}function mapTags($tags){console.log("mapTags()",$tags);tags=$tags.map((function(i){var x={};x.id=i.json_data.id;x.name=i.json_data.label;return x}));console.log("tags",tags)}function getCurrentSweep(){return _currentSweep}function getCurrentCameraPose(){return _currentCameraPose}function getCameraPosition(){return _currentCameraPose.position}function getCurrentSweepPosition(){return _currentSweep.position}function getSweeps(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(_a){console.log("Getting Sweeps in Space");_atwin.Sweep.data.subscribe({onCollectionUpdated:function(collection){console.log("Sweeps In Space",collection);if(!collection){console.log("No Sweeps in loaded Space")}_sweeps=collection;var sw=Object.values(_sweeps);sweeps=sw.map((function(item){return{id:item.uuid,position:item.position,neighbors:item.neighbors}}))}});return[2,null]}))}))}function moveToSweep(sweepId){return __awaiter(this,void 0,void 0,(function(){var transition,transitionTime;return __generator(this,(function(_a){transition=_atwin.Sweep.Transition.FLY;transitionTime=2e3;console.log("Sweep Move",sweepId);_atwin.Sweep.moveTo(sweepId,{transition:transition,transitionTime:transitionTime}).then((function(){console.log("Sweep Arrived at sweep "+sweepId)})).catch((function(error){console.log("Sweep Error on Arriving",error)}));return[2]}))}))}function getNearbySweeps(sweepId){return __awaiter(this,void 0,void 0,(function(){var nearby;return __generator(this,(function(_a){switch(_a.label){case 0:if(!sweepId)return[3,2];return[4,sweeps.find((function(item){return item.id==sweepId})).neighbors];case 1:nearby=_a.sent();console.log("Nearby Sweeps",nearby);return[2,nearby];case 2:console.log("No Nearby Sweeps");_a.label=3;case 3:return[2]}}))}))}function getComponentLoader(object){if(object&&object.object_data){var index=object.object_data.object_type;var component={FBX:_atwin.Scene.Component.FBX_LOADER,GLB:_atwin.Scene.Component.GLTF_LOADER,MP4:"liveVideo",ZIP:"slideScreenModel"};return component[index]||""}return""}function setSelectedObject(data,node,component){_selectedObject={object:data,component:component,node:node};console.log("setSelectedObject()")}function setLighting(){return __awaiter(this,void 0,void 0,(function(){var sceneObject,lights;return __generator(this,(function(_a){switch(_a.label){case 0:return[4,_atwin.Scene.createObjects(1)];case 1:sceneObject=_a.sent()[0];lights=sceneObject.addNode();lights.addComponent("mp.directionalLight",{intensity:.6,color:{r:1,g:1,b:1}});lights.addComponent("mp.ambientLight",{intensity:.6,color:{r:1,g:1,b:1}});lights.start();return[2]}}))}))}function clearTransformControls(){if(!_transformControlNode){console.error("_transformControlNode is undefined");return}if(_inputControlComponent==null||!_inputControlComponent){console.error("_inputControlComponent is undefined");return}_transformControlNode.stop();console.log("clearTransformControls()")}function setTransformControls(selectedObject,mode){if(mode===void 0){mode="translate"}return __awaiter(this,void 0,void 0,(function(){var sceneObject,transformNode,transformComponent,inputComponent;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("Object to be transformed "+selectedObject.object.object_data.name);clearTransformControls();return[4,_atwin.Scene.createObjects(1)];case 1:sceneObject=_a.sent()[0];transformNode=sceneObject.addNode();transformComponent=transformNode.addComponent("mp.transformControls");_transformControlNode=transformNode;inputComponent=transformNode.addComponent("mp.input",{eventsEnabled:true,userNavigationEnabled:true});_inputControlComponent=inputComponent.spyOnEvent(new ClickSpy(selectedObject.object,selectedObject.node,selectedObject.component));transformNode.start();transformComponent.inputs.selection=selectedObject.node;transformComponent.inputs.mode=mode;return[2]}}))}))}function calculateDistance(pos1,pos2){var dx=pos2.x-pos1.x;var dy=pos2.y-pos1.y;return Math.sqrt(dx*dx+dy*dy)}function showVideoObjects(object){var _a,_b;return __awaiter(this,void 0,void 0,(function(){var sceneObject,liveStreamNode,liveStreamComponent;return __generator(this,(function(_c){switch(_c.label){case 0:return[4,createVideoComponent()];case 1:_c.sent();return[4,_atwin.Scene.createObjects(1)];case 2:sceneObject=_c.sent()[0];liveStreamNode=sceneObject.addNode();return[4,liveStreamNode.addComponent(getComponentLoader(object),{url:(_a=object.object_data)===null||_a===void 0?void 0:_a.amazon_uri})];case 3:liveStreamComponent=_c.sent();liveStreamNode.position.set(object.object_position.x,object.object_position.y,object.object_position.z);liveStreamNode.obj3D.rotation.set(object.object_rotation.x,object.object_rotation.y,object.object_rotation.z);liveStreamNode.scale.set(object.object_scale.x,object.object_scale.y,object.object_scale.z);if(liveStreamComponent.outputs.loadingState!="Error"){liveStreamNode.start()}liveStreamComponent.inputs.src=(_b=object.object_data)===null||_b===void 0?void 0:_b.amazon_uri;_videos.push({data:object,component:liveStreamComponent,node:liveStreamNode,type:"VIDEO"});return[2]}}))}))}function playVideo(videoId){var videoObject=_videos.find((function(object){return object.data.id==videoId}));if(videoObject){videoObject.component.video.play()}else{console.error("Unable to find video object using that id")}}function pauseVideo(videoId){var videoObject=_videos.find((function(object){return object.data.id==videoId}));if(videoObject){videoObject.component.video.pause()}else{console.error("Unable to find video object using that id")}}function videoAutoPlay(){function nearestVideo(videoObject){return __awaiter(this,void 0,void 0,(function(){var videoPosition,cameraPosition,computedDistance;return __generator(this,(function(_a){videoPosition=videoObject.data.object_position;cameraPosition=getCurrentSweepPosition();computedDistance=distance([cameraPosition.x,cameraPosition.y,cameraPosition.z],[videoPosition.x,videoPosition.y,videoPosition.z]);try{if(videoObject.data.autoplay&&videoObject.data.autoplay_distance&&computedDistance<videoObject.data.autoplay_distance){videoObject.component.video.play()}else{videoObject.component.video.pause()}}catch(e){console.error("Unable to play or stop video")}return[2]}))}))}_videos.forEach((function(videoObject){return nearestVideo(videoObject)}))}function createVideoComponent(){function videoRenderer(){this.inputs={visible:true,userNavigationEnabled:true,eventsEnabled:true,colliderEnabled:true,src:null};this.outputs={texture:null,video:null,aspect:720/480};this.onInit=function(){this.video;this.texture};this.onEvent=function(eventType,eventData){};this.onInputsUpdated=function(previous){this.releaseTexture();var THREE=this.context.three;if(!this.inputs.src){this.video.src="";return}if(this.inputs.src instanceof HTMLVideoElement){this.video=this.inputs.src}else{this.video=this.createVideoElement();if(typeof this.inputs.src==="string"){this.video.src=this.inputs.src}else{this.video.srcObject=this.inputs.src}this.video.load()}this.texture=new THREE.VideoTexture(this.video);this.texture.minFilter=THREE.LinearFilter;this.texture.magFilter=THREE.LinearFilter;this.texture.format=THREE.RGBFormat;var geometry=new THREE.PlaneGeometry(1,1);geometry.scale(1,480/720,1);geometry.translate(0,.33,0);this.material=new THREE.MeshBasicMaterial({map:this.texture,side:THREE.DoubleSide});var mesh=new THREE.Mesh(geometry,this.material);this.outputs.objectRoot=mesh;this.outputs.collider=mesh;mesh.visible=this.inputs.visible;this.outputs.texture=this.texture;this.outputs.video=this.video};this.releaseTexture=function(){if(this.texture){this.outputs.texture=null;this.texture.dispose()}};this.createVideoElement=function(){var video=document.createElement("video");video.setAttribute("id","htmlLivestreamVideo");video.crossOrigin="anonymous";video.setAttribute("height","480");video.setAttribute("width","720");video.setAttribute("webkit-playsinline","webkit-playsinline");video.setAttribute("controls","controls");video.muted=false;video.loop=true;video.volume=1;return video};this.onTick=function(tickDelta){};this.onDestroy=function(){this.material.dispose()};this.spyOnEvent=function(payload){console.log("payload",payload)}}function makeVideoRender(){return new videoRenderer}_atwin.Scene.register("liveVideo",makeVideoRender)}function createSlideScreenModel(){function SlideScreenModelRenderer(){this.inputs={src:null,userNavigationEnabled:true,eventsEnabled:true,colliderEnabled:true,visible:true};this.outputs={texture:null,t_image:null};this.onInit=function(){this.texture;this.t_image;this.material;this.mesh};this.events={"INTERACTION.CLICK":true};this.onEvent=function(eventType,eventData){return __awaiter(this,void 0,void 0,(function(){var slideshow_1,mousePosition,planePosition;var _this=this;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("onEventSlideShow",eventType,eventData);if(!(eventType=="INTERACTION.CLICK"))return[3,2];if(!(_allSlideShow.length>0))return[3,2];slideshow_1=_allSlideShow.filter((function(l){var _a,_b,_c,_d;return(_d=((_b=(_a=l.collider)===null||_a===void 0?void 0:_a.collider)===null||_b===void 0?void 0:_b.uuid)==((_c=eventData.collider)===null||_c===void 0?void 0:_c.uuid))!==null&&_d!==void 0?_d:false}))[0];console.log("slideShow eventData",slideshow_1);if(!(slideshow_1!=null))return[3,2];console.log("slideShow eventData",slideshow_1);return[4,getMousePosition()];case 1:mousePosition=_a.sent();planePosition=slideshow_1.node.obj3D.position;console.log("MOUSE POSITION",mousePosition);console.log("PLANE POSITION",planePosition);if(slideshow_1.object.object_type=="ZIP"){if(slideshow_1.id!=_currentSlideShowID){_currentSlideIndex=_slideShowImage.find((function(elem){return elem.id===slideshow_1.id})).idx;console.log("CURRENT INDEX",_currentSlideIndex);_currentSlideShow=_slideShowImage.find((function(elem){return elem.id===slideshow_1.id})).images;console.log("CURRENT SLIDE",_currentSlideShow)}if(slideshow_1.id==_currentSlideShowID){console.log("ChangeImage",slideshow_1,_currentSlideShowID);if(planePosition.x<mousePosition.x){console.log("LEFT SIDE");clearInterval(_timer);this.inputs.src=imageStream("prev")}else if(planePosition.y<mousePosition.y){console.log("RIGHT SIDE");clearInterval(_timer);this.inputs.src=imageStream("next")}else if(planePosition.y>mousePosition.y){console.log("AUTOPLAY");_timer=setInterval((function(){_currentSlideIndex=(_currentSlideIndex+1)%_currentSlideShow.length;console.log("CURRENT INDEX",_currentSlideIndex);_this.inputs.src=imageStream("next")}),2e3)}}else{_currentSlideShowID=slideshow_1.id}}_a.label=2;case 2:return[2]}}))}))};this.onInputsUpdated=function(previous){var _this=this;this.releaseTexture();var three=this.context.three;this.t_image=document.createElement("IMG");this.t_image.src=this.inputs.src;this.t_image.setAttribute("width","auto");this.t_image.setAttribute("height","auto");this.t_image.crossOrigin="anonymous";var planeGeo=new three.PlaneGeometry(1.5,1.5);planeGeo.translate(0,.33,0);if(previous.src!=this.inputs.src){console.log("this.inputs.src",this.inputs.src);this.texture=(new three.TextureLoader).load(this.t_image.src,(function(tex){if(tex===void 0){tex=_this.texture}tex.minFilter=three.LinearFilter;tex.magFilter=three.LinearFilter;tex.format=three.RGBAFormat;tex.needsUpdate=true;tex.onUpdate=_this.textureUpdated;_this.material=new three.MeshBasicMaterial({map:_this.texture,side:three.DoubleSide,transparent:true,alphaTest:.5});_this.mesh=new three.Mesh(planeGeo,_this.material);_this.mesh.scale.set(1,_this.texture.image.height/_this.texture.image.width,1);_this.outputs.objectRoot=_this.mesh;_this.outputs.collider=_this.mesh;_this.outputs.texture=_this.texture;_this.outputs.t_image=_this.t_image}))}if(this.mesh!=null){this.mesh.visible=this.inputs.visible}};this.textureUpdated=function(params){console.log("Update Callback",params)};this.releaseTexture=function(){if(this.texture){this.outputs.texture=null}};this.onTick=function(tickDelta){};this.onDestroy=function(){this.material.dispose();this.texture.dispose()}}function makeSlideScreenModelRenderer(){return new SlideScreenModelRenderer}_atwin.Scene.register("slideScreenModel",makeSlideScreenModelRenderer)}function showSlideScreenModel(object){return __awaiter(this,void 0,void 0,(function(){var sceneObject,modelNode,component,slideShow;return __generator(this,(function(_a){switch(_a.label){case 0:createSlideScreenModel();return[4,_atwin.Scene.createObjects(1)];case 1:sceneObject=_a.sent()[0];modelNode=sceneObject.addNode();component=modelNode.addComponent("slideScreenModel");console.log("COMPONENT",component);modelNode.scale.set={x:object.object_scale.x,y:object.object_scale.y,z:object.object_scale.z};modelNode.obj3D.position.set(object.object_position.x,object.object_position.y,object.object_position.z);modelNode.obj3D.rotation.set(object.object_rotation.x,object.object_rotation.y,object.object_rotation.z);modelNode.start();return[4,addImageToSlideShow(object.object_data,component,object.id)];case 2:_a.sent();console.log("SLIDE OUTPUT",component.outputs);slideShow={id:object.id,collider:component.outputs,object:object.object_data,node:modelNode,component:component,type:"ZIP"};_allSlideShow.push(slideShow);console.log("ALL SLIDESHOW",_allSlideShow);return[2]}}))}))}function addImageToSlideShow(data,component,objectID){return __awaiter(this,void 0,void 0,(function(){var dataList;return __generator(this,(function(_a){switch(_a.label){case 0:dataList=[];return[4,new JSZip.external.Promise((function(resolve,reject){JSZipUtils.getBinaryContent(data.amazon_uri,(function(err,data){if(err){console.log("getBI error",err);reject(err)}else{console.log("getBI success",data);resolve(data)}}))})).then((function(data){console.log("data from getBI",data);return JSZip.loadAsync(data)})).then((function(data){console.log("data from loadAsync",data);var _loop_1=function(key){if(key.includes("__MACOSX"))return"continue";if(key.includes(".DS_Store"))return"continue";if(data.files[key].dir)return"continue";var base=data.file(data.files[key].name).async("base64");base.then((function(res){dataList.push({name:data.files[key].name,path:"data:image/png;base64,".concat(res)});if(dataList.length==1){component.inputs.src="data:image/png;base64,".concat(res)}}))};for(var key in data.files){_loop_1(key)}_slideShowImage.push({id:objectID,images:dataList,idx:0,playID:null,play:false,comp:component})}))];case 1:_a.sent();return[2]}}))}))}function getMousePosition(){return __awaiter(this,void 0,void 0,(function(){var planePosition;return __generator(this,(function(_a){switch(_a.label){case 0:return[4,_atwin.Pointer.intersection.subscribe((function(intersection){planePosition=intersection.position}))];case 1:_a.sent();return[2,planePosition]}}))}))}function imageStream(direction){var diff=direction==="prev"?-1:1;var length=_currentSlideShow.length;var index=_currentSlideIndex+diff;if(index===-1){index=length-1}if(index===length){index=0}_currentSlideIndex=index;_slideShowImage.find((function(elem){return elem.id===_currentSlideShowID})).idx=index;return _currentSlideShow[_currentSlideIndex].path}function cameraRotate(x,y,speed){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(_a){switch(_a.label){case 0:return[4,_atwin.Camera.rotate(x,y,{speed:speed}).then((function(){console.log("camera rotate success.",x,y)})).catch((function(error){console.log("camera rotate error.",error)}))];case 1:_a.sent();return[2]}}))}))}function cameraPan(x,z){return __awaiter(this,void 0,void 0,(function(){var mode;return __generator(this,(function(_a){switch(_a.label){case 0:mode=getViewMode();if(!(mode==_atwin.Mode.Mode.FLOORPLAN||mode==_atwin.Mode.Mode.DOLLHOUSE))return[3,2];return[4,_atwin.Camera.pan({x:x,z:z}).then((function(){console.log("camera pan success.")})).catch((function(error){console.log("camera rotate error:",error)}))];case 1:_a.sent();return[3,3];case 2:console.error("Incorrect view mode.");_a.label=3;case 3:return[2]}}))}))}function cameraLookAt(x,y){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(_a){switch(_a.label){case 0:return[4,_atwin.Camera.lookAtScreenCoords(x,y).then((function(){console.log("camera looking at...",x,y)})).catch((function(error){console.log("camera looking at error:",error)}))];case 1:_a.sent();return[2]}}))}))}function moveInDirection(direction){return __awaiter(this,void 0,void 0,(function(){var nextDirection;return __generator(this,(function(_a){switch(_a.label){case 0:nextDirection=_atwin.Camera.Direction.LEFT;switch(direction.toUpperCase()){case"LEFT":nextDirection=_atwin.Camera.Direction.LEFT;break;case"RIGHT":nextDirection=_atwin.Camera.Direction.RIGHT;break;case"UP":nextDirection=_atwin.Camera.Direction.UP;break;case"DOWN":nextDirection=_atwin.Camera.Direction.DOWN;break;case"BACK":nextDirection=_atwin.Camera.Direction.BACK;break;case"FORWARD":nextDirection=_atwin.Camera.Direction.FORWARD;break;default:nextDirection=_atwin.Camera.Direction.LEFT;break}return[4,_atwin.Camera.moveInDirection(nextDirection).then((function(){console.log("Move to...",nextDirection)})).catch((function(){console.warn("An error occured while moving in that direction.",nextDirection)}))];case 1:_a.sent();return[2]}}))}))}function dispose3dObjects(){console.log("dispose3dObjects");_3DXObject.forEach((function(obj){console.log("_3DXObject stop",obj);obj.stop()}));_videos.forEach((function(vid){console.log("_videos pause and node stop",vid);vid.component.video.pause();vid.node.stop()}));_allSlideShow.forEach((function(slide){console.log("_allSlideShow stop",slide);slide.node.stop()}))}function getViewMode(){return _currentViewMode}function setViewMode(mode){return __awaiter(this,void 0,void 0,(function(){var modeType;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("=== get Mode Type ===",_getModeType(mode));modeType=_getModeType(mode);return[4,_atwin.Mode.moveTo(modeType).then((function(nextMode){console.log("Arrived at new view mode "+nextMode)})).catch((function(error){console.error("Error occur on:",error)}))];case 1:_a.sent();return[2]}}))}))}function _getModeType(mode){var modes={DOLLHOUSE:"mode.dollhouse",FLOORPLAN:"mode.floorplan",INSIDE:"mode.inside",OUTSIDE:"mode.outside",TRANSITIONING:"mode.transitioning"};return modes[mode.toUpperCase()]||""}function disconnectSpace(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(_a){switch(_a.label){case 0:console.log("disconnectSpace()");return[4,hideTags()];case 1:_a.sent();dispose3dObjects();_atwin.disconnect();_iframe.src="";_api={};_space={};_atwin={};_tags=[];tags=[];sweeps=[];_allSlideShow=[];_slideShowImage=[];_currentSlideShowID=0;_currentSlideIndex=0;_currentSlideShow=null;_timer=null;_videos=[];_currentViewMode="";_3DXObject=[];_unrenderedObjects=[];_previousTimeStamp=0;_currentSweep={};_currentCameraPose={};_sweeps=[];return[2]}}))}))}var ClickSpy=function(){function ClickSpy(data,node,component){this.eventType="INTERACTION.CLICK";this.object_data=data;this.node=node;this.component=component}ClickSpy.prototype.onEvent=function(payload){return __awaiter(this,void 0,void 0,(function(){var selectedObj;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("INTERACTION.CLICK",payload);selectedObj={object:this.object_data,node:this.node,component:this.component};setSelectedObject(this.object_data,this.node,this.component);return[4,setTransformControls(selectedObj)];case 1:_a.sent();return[2]}}))}))};return ClickSpy}();var atwin={tags:tags,sweeps:sweeps,connectSpace:connectSpace,disconnectSpace:disconnectSpace,gotoTag:gotoTag,getCurrentSweep:getCurrentSweep,getCurrentSweepPosition:getCurrentSweepPosition,moveToSweep:moveToSweep,getNearbySweeps:getNearbySweeps,pauseVideo:pauseVideo,playVideo:playVideo,getCurrentCameraPose:getCurrentCameraPose,getCameraPosition:getCameraPosition,moveInDirection:moveInDirection,cameraLookAt:cameraLookAt,cameraPan:cameraPan,cameraRotate:cameraRotate,getViewMode:getViewMode,setViewMode:setViewMode,getNearbyObjects:getNearbyObjects};export{atwin as default,tags,sweeps,connectSpace,disconnectSpace,gotoTag,getCurrentSweep,getCurrentSweepPosition,moveToSweep,getNearbySweeps,pauseVideo,playVideo,getCurrentCameraPose,getCameraPosition,moveInDirection,cameraLookAt,cameraPan,cameraRotate,getViewMode,setViewMode,getNearbyObjects};
package/lib/types.d.ts CHANGED
@@ -50,7 +50,6 @@ export interface IMPConfig {
50
50
  search?: 0 | 1;
51
51
  wh?: 0 | 1;
52
52
  prod?: boolean;
53
- domain: string;
54
53
  }
55
54
  export interface ISweep {
56
55
  alignmentType: MpSdk.Sweep.Alignment;
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "architwin",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "ArchiTwin Library for Matterport",
5
5
  "main": "./lib/architwin.min.js",
6
6
  "types": "./lib/architwin.d.ts",
7
+ "type":"module",
7
8
  "exports": {
8
9
  ".": {
9
10
  "types": {
@@ -30,7 +31,6 @@
30
31
  "jszip": "^3.10.1",
31
32
  "jszip-utils": "^0.1.0",
32
33
  "mathjs": "^11.8.0",
33
- "terser": "^5.17.7",
34
34
  "three": "^0.152.2",
35
35
  "ts-loader": "^9.4.3"
36
36
  },