architwin 1.0.29 → 1.0.30
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 +112 -11
- package/lib/architwin.d.ts +27 -4
- package/lib/architwin.min.js +1 -1
- package/lib/common/architwin.min.js +2 -0
- package/lib/common/architwin.min.js.LICENSE.txt +34 -0
- package/lib/types.d.ts +40 -1
- package/package.json +6 -5
- package/static/marker3d.png +0 -0
- package/{webpack.config.js → webpack.config.cjs} +5 -3
package/README.md
CHANGED
|
@@ -21,6 +21,9 @@ ArchiTwin Library
|
|
|
21
21
|
- [Rotate, Pan and Tilt Camera](#rotate-pan-and-tilt-camera)
|
|
22
22
|
- [Space Overview](#space-overview)
|
|
23
23
|
- [Points of Interest](#points-of-interest)
|
|
24
|
+
- [Loading and Interacting with 3D/2D Objects](#loading-and-interacting-with-3d2d-objects)
|
|
25
|
+
- [What is an Object?](#what-is-an-object)
|
|
26
|
+
- [Loading Objects](#loading-objects)
|
|
24
27
|
- [Function Reference](#function-reference)
|
|
25
28
|
- [Tags](#tags)
|
|
26
29
|
- [Sweeps](#sweeps)
|
|
@@ -549,29 +552,118 @@ moveToSweep(sweepId) - // to move to a specific Sweep
|
|
|
549
552
|
</script>
|
|
550
553
|
````
|
|
551
554
|
|
|
555
|
+
## Loading and Interacting with 3D/2D Objects
|
|
556
|
+
|
|
557
|
+
Architwin allows you to load and interact with 3D or 2D objects into a 3D showcase. Architwin has internal functions that performs GET requests from an API enpoint, parses it, and then renders it to your 3D showcase. The result fetched data implement the `IShowcaseObject` type interface which matches the schema of the response of the API. Please take note that this guide assumes that you have implemented the recommended database schema for storing your showcase objects.
|
|
558
|
+
|
|
559
|
+
### What is an Object?
|
|
560
|
+
|
|
561
|
+
We define objects as 3D or 2D assets that have or will be loaded into a space. This could be a 3D model of a statue or a 2D video or image. An object can be static or interactive. Static objects are objects that the user cannot interact with (e.g. clickable or playable). An example of a static object would be 3D statue with no animations. Interactive objects are objects that the user can interact with by either clicking the object directly or just by being near it (e.g. videos). Architwin currently supports the following file types:
|
|
562
|
+
|
|
563
|
+
**3D Models**
|
|
564
|
+
|
|
565
|
+
- GTLF/GLB
|
|
566
|
+
- FBX
|
|
567
|
+
|
|
568
|
+
**2D Objects**
|
|
569
|
+
|
|
570
|
+
- MP4 (Videos)
|
|
571
|
+
- ZIP (Image/Image slideshows)
|
|
572
|
+
|
|
573
|
+
We add support for more file types in future updates
|
|
574
|
+
|
|
575
|
+
### Loading Objects
|
|
576
|
+
|
|
577
|
+
Objects come in many shapes and sizes. Loading objects may sometimes take a lot of resources especially if you intend to load a lot of objects in your space. Architwin is optimized to load your 3D spaces and its associated objects as fast and efficiently as possible to reduce the TTI.
|
|
578
|
+
|
|
579
|
+
To achieve this, instead of loading all of your objects at the same time at the start which causes long initial load times, Architwin eagerly renders objects in the space when the user is at a certain distance from the objects intended position. We call this feature **Render On Demand**.
|
|
580
|
+
|
|
581
|
+
By default, objects are rendered in the space when objects are within a **2 meters** diameter from the Camera (User view). You can increase or decrease this distance by setting the render distance using the `setRenderDistance` method.
|
|
582
|
+
|
|
583
|
+
Example:
|
|
584
|
+
|
|
585
|
+
```typescript
|
|
586
|
+
import * as atwin from 'architwin'
|
|
587
|
+
|
|
588
|
+
atwin.setRenderDistance(10) //Render all objects within 10 meters from the User
|
|
589
|
+
atwin.connectSpace(url, auth, config)
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
You only need to set the render distance once. Make sure to invoke the function before running `connectSpace`
|
|
593
|
+
|
|
594
|
+
Architwin also allows you to get **rendered** objects near the user by calling the `getNearbyObjects` method which will return an array of nodes of the rendered objects within the target range.
|
|
595
|
+
|
|
596
|
+
Example:
|
|
597
|
+
|
|
598
|
+
```typescript
|
|
599
|
+
import * as atwin from 'architwin'
|
|
600
|
+
|
|
601
|
+
atwin.getNearbyObjects('ALL',10) // Will get ALL object types within a 10 meter range
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
You can learn more about the different paramaters of this function under the [function reference](#function-reference) section. If you need to get all the nearby objects everytime the user moves, then you can simple add the following key-value pair in your config.
|
|
605
|
+
|
|
606
|
+
```typescript
|
|
607
|
+
import * as atwin from 'architwin'
|
|
608
|
+
|
|
609
|
+
const config: IMPConfig = {
|
|
610
|
+
//other configs...
|
|
611
|
+
autoDetectNearbyObjs: true,
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
atwin.connectSpace(url, auth, config)
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
You can the get the data by importing the `nearbyObjects` variable
|
|
618
|
+
|
|
619
|
+
```typescript
|
|
620
|
+
import * as atwin from 'architwin'
|
|
621
|
+
|
|
622
|
+
atwin.nearbyObjects //Gets updated everytime the User camera moves
|
|
623
|
+
```
|
|
624
|
+
|
|
552
625
|
## Function Reference
|
|
626
|
+
|
|
627
|
+
Some Functions are **async**; when invoking them, Use keyword **await** or **.then** syntax
|
|
628
|
+
|
|
553
629
|
--------------------------
|
|
554
630
|
```typescript
|
|
555
631
|
disconnectSpace() // disconnects and clear currently displayed Space
|
|
632
|
+
// this is an async function that returns a Promise
|
|
556
633
|
```
|
|
557
634
|
|
|
558
635
|
#### Tags
|
|
559
636
|
````typescript
|
|
560
|
-
|
|
637
|
+
gotoTag(space: ISpace) - //returns an array of an array of ITag containing information of all tags in the space. Please take note that this function is executed internally when the space is loaded and you can access the tag data via calling atwin.tags
|
|
638
|
+
// this is an async function that requires a Tag ID param and returns a Promise
|
|
639
|
+
|
|
640
|
+
atwin.tags //Variable containing an array of ITag
|
|
561
641
|
|
|
562
642
|
gotoTag(tagId: number) - //transport navigate directly to the tag with given ID
|
|
643
|
+
// this is an async function that requires a Tag ID param and returns a Promise
|
|
563
644
|
````
|
|
564
645
|
### Sweeps
|
|
565
646
|
````typescript
|
|
566
|
-
getSweeps() - //
|
|
647
|
+
getSweeps() - //Returns an array of ISweep, please note that this function is executed internally upon starting the space and you can just get the sweep data by calling the atwin.sweeps
|
|
648
|
+
// this is an async function that requires a Sweep ID then returns a Promise
|
|
649
|
+
|
|
650
|
+
atwin.sweeps //Variable containg an array of ISweep data
|
|
651
|
+
|
|
652
|
+
moveToSweep(sweepId: string) - // transport navigate directly to the Sweep with given ID.
|
|
653
|
+
// this is an async function that requires a Sweep ID then returns a Promise
|
|
654
|
+
|
|
567
655
|
|
|
568
656
|
moveToSweep(sweepId: string) - // transport navigate directly to the Sweep with given ID.
|
|
657
|
+
// this is an async function that requires a Sweep ID then returns a Promise
|
|
569
658
|
|
|
570
659
|
getNearbySweeps(sweepId: string) - // returns the nearby or neighbors of a given sweep.
|
|
660
|
+
// this is an async function that requires a Sweep ID then returns a Promise
|
|
571
661
|
|
|
572
662
|
getCurrentSweep() - // returns the current sweep detail
|
|
663
|
+
// this is a function
|
|
573
664
|
|
|
574
665
|
getSweepPosition(): {x: number, y: number, z: number} - // returns the position of the current sweep:
|
|
666
|
+
// this is a function
|
|
575
667
|
````
|
|
576
668
|
|
|
577
669
|
**Example:**
|
|
@@ -580,16 +672,13 @@ getSweepPosition(): {x: number, y: number, z: number} - // returns the position
|
|
|
580
672
|
import * as atwin from 'architwin';
|
|
581
673
|
|
|
582
674
|
...
|
|
583
|
-
|
|
584
|
-
await atwin.getSweeps()
|
|
585
|
-
|
|
586
|
-
|
|
675
|
+
|
|
587
676
|
// get current sweep data
|
|
588
|
-
|
|
677
|
+
atwin.getCurrentSweep()
|
|
589
678
|
|
|
590
679
|
|
|
591
680
|
// get current sweep position
|
|
592
|
-
|
|
681
|
+
atwin.getSweepPosition()
|
|
593
682
|
|
|
594
683
|
|
|
595
684
|
// moving to a Sweep
|
|
@@ -607,8 +696,10 @@ getSweepPosition(): {x: number, y: number, z: number} - // returns the position
|
|
|
607
696
|
### Video
|
|
608
697
|
````typescript
|
|
609
698
|
playVideo(videoId: number) - // play a video screen
|
|
699
|
+
// this is a function
|
|
610
700
|
|
|
611
701
|
pauseVideo(videoId: number) - // pause a video screen
|
|
702
|
+
// this is a function
|
|
612
703
|
````
|
|
613
704
|
|
|
614
705
|
**Example:**
|
|
@@ -630,29 +721,38 @@ pauseVideo(videoId: number) - // pause a video screen
|
|
|
630
721
|
````typescript
|
|
631
722
|
cameraLookAt(x: number,y: number) - // set camera view at coordinate in SCREEN.
|
|
632
723
|
// x and y is in pixel valuews from top left corner of the space canvas
|
|
724
|
+
// this is an async function and returns a Promise
|
|
725
|
+
|
|
633
726
|
moveInDirection(direction: string) - // move in DIRECTION, can be LEFT, RIGTH, UP, DOWN, FORWARD, BACKWARD
|
|
727
|
+
// this is an async function and returns a Promise
|
|
634
728
|
|
|
635
729
|
getViewMode() - // returns the current View Mode of the space.
|
|
636
730
|
// there are three modes:
|
|
637
731
|
// "mode.inside" - shows the interior view of the space
|
|
638
732
|
// "mode.floorplan" - shows the floor plan of the space
|
|
639
733
|
// "mode.dollhouse" - shows the doll house view
|
|
734
|
+
// this is a function
|
|
640
735
|
|
|
641
736
|
setViewMode(mode: string) - // to set the viewing mode to "INSIDE", "FLOORPLAN" or "DOLLHOUSE"
|
|
737
|
+
// this is an async function and returns a Promise
|
|
642
738
|
````
|
|
643
739
|
|
|
644
740
|
|
|
645
741
|
### Camera
|
|
646
742
|
````typescript
|
|
647
743
|
getCurrentCameraPose() - // returns the current camera Pose object
|
|
744
|
+
// this is a function
|
|
648
745
|
|
|
649
746
|
getCameraPosition() - // returns the current camera Position {x,y,z}
|
|
747
|
+
// this is a function
|
|
650
748
|
|
|
651
749
|
cameraPan(x: number, z: number) - // pan (z-axis) makes the camera look left and right. tilt (x-axis) the camera look up and down.
|
|
652
750
|
// x and z are angles in degrees
|
|
751
|
+
// this is an async function and returns a Promise
|
|
653
752
|
|
|
654
753
|
cameraRotate(x: number, y: number, speed: number) - // rotates the camera view, x and y is rotation in horizontal
|
|
655
754
|
// and vertical rotation in degrees
|
|
755
|
+
// this is an async function and returns a Promise
|
|
656
756
|
|
|
657
757
|
````
|
|
658
758
|
|
|
@@ -663,11 +763,11 @@ cameraRotate(x: number, y: number, speed: number) - // rotates the camera view,
|
|
|
663
763
|
...
|
|
664
764
|
|
|
665
765
|
// get current Camera Pose
|
|
666
|
-
|
|
766
|
+
atwin.getCurrentCameraPose()
|
|
667
767
|
|
|
668
768
|
|
|
669
769
|
// get current camera position
|
|
670
|
-
|
|
770
|
+
atwin.getCameraPosition()
|
|
671
771
|
|
|
672
772
|
|
|
673
773
|
// set Camera View
|
|
@@ -696,7 +796,7 @@ cameraRotate(x: number, y: number, speed: number) - // rotates the camera view,
|
|
|
696
796
|
|
|
697
797
|
|
|
698
798
|
// get current View
|
|
699
|
-
|
|
799
|
+
atwin.getViewMode()
|
|
700
800
|
|
|
701
801
|
// set View Mode
|
|
702
802
|
await atwin.setViewMode("INSIDE")
|
|
@@ -715,6 +815,7 @@ getNearbyObjects(type?: '3DX' | 'SLIDESHOW' | 'VIDEO', distance?: number = 2)
|
|
|
715
815
|
// returns a list of nearby objects
|
|
716
816
|
// type - can be 3Dx, Slideshow or Video; parameter is optional. if no parameter is passed, it returns all objects
|
|
717
817
|
// distance - is optional but with a default of 2 meters
|
|
818
|
+
// this is a function
|
|
718
819
|
|
|
719
820
|
````
|
|
720
821
|
|
package/lib/architwin.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { MpSdk } from "../bundle/sdk";
|
|
2
|
-
import { type IUser, type IMPConfig, type ISweep, type ITagPublic, type NearbyPayload, type NearbyObjects, type IObjectData } from "./types";
|
|
2
|
+
import { type ITag, type IUser, type ISpace, type IMPConfig, type ISweep, type ITagPublic, type NearbyPayload, type NearbyObjects, type IObjectData, TRANSFORM_TYPE, Object3DPosition, State, ObjectUpload } from "./types";
|
|
3
|
+
declare let _space: ISpace;
|
|
3
4
|
declare let tags: ITagPublic[];
|
|
4
5
|
declare let sweeps: any;
|
|
5
6
|
declare let selectedObject: IObjectData;
|
|
7
|
+
declare let previousObjTransform: Object3DPosition;
|
|
8
|
+
declare let currentObjTransform: Object3DPosition;
|
|
9
|
+
declare let actionHistory: Array<string>;
|
|
10
|
+
declare let state: State;
|
|
6
11
|
/**
|
|
7
12
|
* initialization: loginUser, iframe, space, tags, objects
|
|
8
13
|
* @constructor
|
|
@@ -24,13 +29,28 @@ declare function connectSpace(url: string, auth: {
|
|
|
24
29
|
* @returns {NearbyObjects}
|
|
25
30
|
*/
|
|
26
31
|
declare function getNearbyObjects(payload: NearbyPayload): NearbyObjects;
|
|
32
|
+
declare function setRenderDistance(distance: number): void;
|
|
33
|
+
declare function getTags(space: ISpace): Promise<ITag[] | null>;
|
|
27
34
|
declare function gotoTag(tag_id: string): Promise<void>;
|
|
28
35
|
declare function getCurrentSweep(): ISweep;
|
|
29
36
|
declare function getCurrentCameraPose(): any;
|
|
30
37
|
declare function getCameraPosition(): any;
|
|
31
38
|
declare function getCurrentSweepPosition(): MpSdk.Vector3;
|
|
39
|
+
declare function getSweeps(): Promise<ISweep | null>;
|
|
32
40
|
declare function moveToSweep(sweepId: string): Promise<void>;
|
|
33
41
|
declare function getNearbySweeps(sweepId: string): Promise<any>;
|
|
42
|
+
declare function setTransformMode(mode: TRANSFORM_TYPE | string): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* This function either reverts or restores an transformation action done on an object
|
|
45
|
+
* @param action Accepts either undo or redo. undo is the default value if none is set
|
|
46
|
+
* @returns {boolean} Returns false if you can still undo/redo and true if not.
|
|
47
|
+
*/
|
|
48
|
+
declare function revertTransform(action?: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Clears the action history of all objects
|
|
51
|
+
* @returns {void}
|
|
52
|
+
*/
|
|
53
|
+
declare function clearActionHistory(): void;
|
|
34
54
|
declare function playVideo(videoId: number): void;
|
|
35
55
|
declare function pauseVideo(videoId: number): void;
|
|
36
56
|
declare function cameraRotate(x: number, y: number, speed: number): Promise<void>;
|
|
@@ -46,9 +66,8 @@ declare function moveInDirection(direction: string): Promise<void>;
|
|
|
46
66
|
declare function getViewMode(): MpSdk.Mode.Mode;
|
|
47
67
|
declare function setViewMode(mode: string): Promise<void>;
|
|
48
68
|
declare function disconnectSpace(): Promise<void>;
|
|
69
|
+
declare function addObject(payload: ObjectUpload): Promise<State>;
|
|
49
70
|
declare const atwin: {
|
|
50
|
-
tags: ITagPublic[];
|
|
51
|
-
sweeps: any;
|
|
52
71
|
connectSpace: typeof connectSpace;
|
|
53
72
|
disconnectSpace: typeof disconnectSpace;
|
|
54
73
|
gotoTag: typeof gotoTag;
|
|
@@ -67,5 +86,9 @@ declare const atwin: {
|
|
|
67
86
|
getViewMode: typeof getViewMode;
|
|
68
87
|
setViewMode: typeof setViewMode;
|
|
69
88
|
getNearbyObjects: typeof getNearbyObjects;
|
|
89
|
+
setTransformMode: typeof setTransformMode;
|
|
90
|
+
setRenderDistance: typeof setRenderDistance;
|
|
91
|
+
clearActionHistory: typeof clearActionHistory;
|
|
92
|
+
addObject: typeof addObject;
|
|
70
93
|
};
|
|
71
|
-
export { atwin as default, tags, sweeps, selectedObject, connectSpace, disconnectSpace, gotoTag, getCurrentSweep, getCurrentSweepPosition, moveToSweep, getNearbySweeps, pauseVideo, playVideo, getCurrentCameraPose, getCameraPosition, moveInDirection, cameraLookAt, cameraPan, cameraRotate, getViewMode, setViewMode, getNearbyObjects, };
|
|
94
|
+
export { atwin as default, tags, sweeps, selectedObject, previousObjTransform, currentObjTransform, actionHistory, state, _space, connectSpace, disconnectSpace, getTags, gotoTag, getSweeps, getCurrentSweep, getCurrentSweepPosition, moveToSweep, getNearbySweeps, pauseVideo, playVideo, getCurrentCameraPose, getCameraPosition, moveInDirection, cameraLookAt, cameraPan, cameraRotate, getViewMode, setViewMode, getNearbyObjects, setTransformMode, revertTransform, setRenderDistance, clearActionHistory, addObject };
|
package/lib/architwin.min.js
CHANGED
|
@@ -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:{appKey:"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 _appKey=_config.mp.appKey;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 _viewMode="public";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){console.log("'apiURL' in auth");lastString=auth.apiURL.slice(-1);if(lastString!=="/"){auth.apiURL+="/"}_apiURL=auth.apiURL}if("appKey"in config){console.log("'appKey' in config");_appKey=config.appKey}console.log("_apiURL",_apiURL);api=axios.create({baseURL:_apiURL,headers:{"Access-Control-Allow-Origin":"*","Content-Type":"application/json",Authorization:auth.apiKey}});_api=api;if(config.viewMode==="interactive"){_viewMode="interactive"}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();if(_viewMode==="interactive"){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(_appKey,"&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(_appKey,"&newtags=1")}else{src+="architwin/bundle/showcase.html?m=".concat(modelId,"&applicationKey=").concat(_appKey,"&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 DragSpy=function(){function DragSpy(data,node,component){this.eventType="INTERACTION.DRAG_END";this.object_data=data;this.node=node;this.component=component}DragSpy.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.DRAG_END",payload);selectedObj={object:this.object_data,node:this.node,component:this.component};return[4,setTransformControls(selectedObj)];case 1:_a.sent();return[2]}}))}))};return DragSpy}();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,selectedObject,connectSpace,disconnectSpace,gotoTag,getCurrentSweep,getCurrentSweepPosition,moveToSweep,getNearbySweeps,pauseVideo,playVideo,getCurrentCameraPose,getCameraPosition,moveInDirection,cameraLookAt,cameraPan,cameraRotate,getViewMode,setViewMode,getNearbyObjects};
|
|
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:{appKey:"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 _appKey=_config.mp.appKey;var urlParams=_config.mp.urlParams;var _iframe={};var _api={};var _spaceId="";var _space=null;var _atwin={};var _tags=[];var _objects=[];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=3;var _autoDetectNearbyObj=false;var _viewMode="public";var _transformMode="translate";var _transformComponent;var previousObjTransform={object_position:{x:0,y:0,z:0},object_rotation:{_x:0,_y:0,_z:0},object_scale:{x:0,y:0,z:0}};var currentObjTransform={object_position:{x:0,y:0,z:0},object_rotation:{_x:0,_y:0,_z:0},object_scale:{x:0,y:0,z:0}};var _previousAction;var actionHistory=[];var _currentSweep={};var _currentCameraPose={};var _sweeps=[];var _isInitialLoad=true;var _hasRegisteredLoaders=false;var _sceneObject;var state={isLoading:false,loaded:false,error:"",data:null};var supportedFileTypes=["GLB","GLTF","FBX","MP4","ZIP"];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){console.log("'apiURL' in auth");lastString=auth.apiURL.slice(-1);if(lastString!=="/"){auth.apiURL+="/"}_apiURL=auth.apiURL}if("appKey"in config){console.log("'appKey' in config");_appKey=config.appKey}console.log("_apiURL",_apiURL);api=axios.create({baseURL:_apiURL,headers:{"Access-Control-Allow-Origin":"*","Content-Type":"application/json",Authorization:auth.apiKey}});_api=api;if(config.viewMode==="interactive"){_viewMode="interactive"}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,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);_spaceId=spaceId;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);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,2];console.log("App is loading...");return[4,get3DObjects(_spaceId)];case 1:_a.sent();return[3,9];case 2:if(!(appState.phase===_atwin.App.Phase.STARTING))return[3,4];console.log("App is starting...");return[4,hideTags()];case 3:_a.sent();return[3,9];case 4:if(!(appState.phase===_atwin.App.Phase.PLAYING))return[3,9];console.log("App is playing...");return[4,showTags(_tags)];case 5:_a.sent();return[4,getSweeps()];case 6:_a.sent();return[4,createSceneObject()];case 7:_sceneObject=_a.sent();return[4,setLighting()];case 8:_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=9;case 9: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 setRenderDistance(distance){if(!Number.isInteger(distance)){console.error("Render distance argument is not a valid number");return}_renderDistance=distance}function createSceneObject(){return __awaiter(this,void 0,void 0,(function(){var sceneObject;return __generator(this,(function(_a){switch(_a.label){case 0:return[4,_atwin.Scene.createObjects(1)];case 1:sceneObject=_a.sent()[0];return[2,sceneObject]}}))}))}function show3DObjects(object){var _a;return __awaiter(this,void 0,void 0,(function(){var sceneObject,modelNode,component,objTransformation;return __generator(this,(function(_b){switch(_b.label){case 0:return[4,_atwin.Scene.createObjects(1)];case 1:sceneObject=_b.sent()[0];modelNode=sceneObject.addNode();component=modelNode.addComponent(getComponentLoader(object.object_data),{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]}objTransformation={object_position:object.object_position,object_rotation:object.object_rotation,object_scale:object.object_scale};setObjectTranformation(modelNode,objTransformation);_3DXObject.push(modelNode);console.log("_3DXObject "+_3DXObject.length);modelNode.start();if(_viewMode==="interactive"){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()");registerCustomLoaders();objects=getNearbyUnrenderedObjects({type:"",distance:_renderDistance});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(_appKey,"&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(_appKey,"&newtags=1")}else{src+="architwin/bundle/showcase.html?m=".concat(modelId,"&applicationKey=").concat(_appKey,"&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,object_ids_1,response_1,object_data,objectDataMap_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));object_ids_1=showcase_objects.map((function(obj){return obj.object_id}));_a.label=3;case 3:_a.trys.push([3,5,,6]);return[4,_api.get("/v1/objects")];case 4:response_1=_a.sent();console.log("Finished getting objects");object_data=response_1.data.data.filter((function(obj){return object_ids_1.includes(obj.id)}));console.log("object_data length "+object_data.length);objectDataMap_1=object_data.reduce((function(map,obj){map[obj.id]=obj;return map}),{});console.log("object_data"+JSON.stringify(object_data));threed_objects=showcase_objects.map((function(showcase){var target=objectDataMap_1[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,sweeps]}))}))}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){var index=object.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,type){selectedObject={object:data,component:component,node:node,type:type};var previousCoords={object_position:selectedObject.node.obj3D.position,object_rotation:selectedObject.node.obj3D.rotation,object_scale:selectedObject.node.obj3D.scale};_previousAction=JSON.stringify(previousCoords);actionHistory.push(_previousAction);console.log("Previous transform "+JSON.stringify(previousObjTransform));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}_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});_transformComponent=transformComponent;_inputControlComponent=inputComponent.spyOnEvent(new DragSpy(selectedObject.object,selectedObject.node,selectedObject.component));transformNode.start();transformComponent.inputs.selection=selectedObject.node;transformComponent.inputs.mode=mode;return[2]}}))}))}function setTransformMode(mode){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(_a){if(mode=="translate"){_transformMode="translate"}else if(mode=="rotate"){_transformMode="rotate"}else if(mode=="scale"){_transformMode="scale"}else{console.error("Transform mode not supported or incorrect")}_transformComponent.inputs.mode=_transformMode;return[2]}))}))}function revertTransform(action){if(action===void 0){action="undo"}if(!selectedObject){console.error("selectedObject is undefined.");return}if(!currentObjTransform){console.error("currentObjTransform is undefined");return}if(actionHistory.length<=0){console.error("actionHistory is empty");return}var targetIndex;var nextIndex;var index=actionHistory.indexOf(JSON.stringify(currentObjTransform));console.log("Action is ".concat(action," and index is ").concat(index));if(action==="undo"){if(index-1>=0){targetIndex=index-1;nextIndex=targetIndex-1}else{return false}}else if(action==="redo"){if(index+1<=actionHistory.length){targetIndex=index+1;nextIndex=targetIndex+1}else{return false}}else{console.error("Incorrect function argument for revertTransform");return false}previousObjTransform=JSON.parse(_previousAction);if(!actionHistory[targetIndex]){console.error("actionHistory is either empty or undefined");return}var objectTransform=JSON.parse(actionHistory[targetIndex]);var euler=convertToEuler(objectTransform.object_rotation);objectTransform.object_rotation={_x:euler.x,_y:euler.y,_z:euler.z};setObjectTranformation(selectedObject.node,objectTransform,true);console.log("Action history length "+actionHistory.length);console.log("Current history position "+index);console.log("Target history position "+targetIndex);currentObjTransform=JSON.parse(actionHistory[targetIndex]);if(action=="undo"&&nextIndex>=0){return false}else if(action=="redo"&&nextIndex<=actionHistory.length){return false}else{return true}}function clearActionHistory(){console.info("clearActionHistory()");actionHistory=[]}function convertToEuler(coords){var eulerX=Math.atan2(coords._x,coords._x);var eulerY=Math.atan2(-coords._x,Math.sqrt(coords._y*coords._y+coords._z*coords._z));var eulerZ=Math.atan2(coords._x,coords._x);var degreesX=eulerX*(180/Math.PI);var degreesY=eulerY*(180/Math.PI);var degreesZ=eulerZ*(180/Math.PI);var eulerCoords={x:degreesX,y:degreesY,z:degreesZ};console.log("Euler coords "+JSON.stringify(eulerCoords));return eulerCoords}function setObjectTranformation(node,transform,reverting){if(reverting===void 0){reverting=false}node.scale.set={x:transform.object_scale.x,y:transform.object_scale.y,z:transform.object_scale.z};node.obj3D.position.set(transform.object_position.x,transform.object_position.y,transform.object_position.z);if(reverting){node.obj3D.rotation.set(transform.object_rotation._x,transform.object_rotation._y,transform.object_rotation._z)}else{node.obj3D.rotation.set(transform.object_rotation.x,transform.object_rotation.y,transform.object_rotation.z)}}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,_atwin.Scene.createObjects(1)];case 1:sceneObject=_c.sent()[0];liveStreamNode=sceneObject.addNode();liveStreamComponent=liveStreamNode.addComponent(getComponentLoader(object.object_data),{url:(_a=object.object_data)===null||_a===void 0?void 0:_a.amazon_uri});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,collider:liveStreamComponent.outputs,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.events={"INTERACTION.CLICK":true};this.onEvent=function(eventType,eventData){return __awaiter(this,void 0,void 0,(function(){var video,selectedObj;return __generator(this,(function(_a){switch(_a.label){case 0:if(!(eventType=="INTERACTION.CLICK"&&_viewMode==="interactive"))return[3,2];video=_videos.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("Video object "+JSON.stringify(video.data));selectedObj={object:video.data,node:video.node,component:video.component};clearActionHistory();setSelectedObject(video.data,video.node,video.component,"VIDEO");return[4,setTransformControls(selectedObj)];case 1:_a.sent();_a.label=2;case 2:return[2]}}))}))};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,selectedObj,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,4];if(!(_allSlideShow.length>0))return[3,4];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 object "+JSON.stringify(slideshow_1.object));if(!(_viewMode==="interactive"))return[3,2];selectedObj={object:slideshow_1.object,node:slideshow_1.node,component:slideshow_1.component,type:"ZIP"};clearActionHistory();setSelectedObject(slideshow_1.object,slideshow_1.node,slideshow_1.component,"ZIP");return[4,setTransformControls(selectedObj)];case 1:_a.sent();_a.label=2;case 2:console.log("slideShow eventData",slideshow_1);if(!(slideshow_1!=null))return[3,4];console.log("slideShow eventData",slideshow_1);return[4,getMousePosition()];case 3:mousePosition=_a.sent();planePosition=slideshow_1.node.obj3D.position;console.log("MOUSE POSITION",mousePosition);console.log("PLANE POSITION",planePosition);if(slideshow_1.object.object_data.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=4;case 4: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){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 createDracoGltfComponent(){function DracoGltfRenderer(){this.inputs={visible:true,url:null,model:null,userNavigationEnabled:true,eventsEnabled:true,colliderEnabled:true,rotation:{x:0,y:0,z:0},scale:{x:100,y:100,z:100}};this.events={"INTERACTION.CLICK":true};this.onInit=function(){var objectContext=this;var THREE=this.context.three;var loader=new THREE.GLTFLoader;var dracoLoader=new THREE.DRACOLoader;dracoLoader.setDecoderPath("https://www.gstatic.com/draco/v1/decoders/");loader.setDRACOLoader(dracoLoader);loader.load(objectContext.inputs.url,(function(gltf){gltf.scene.traverse((function(node){if(node instanceof THREE.Mesh){node.castShadow=false;node.material.side=THREE.FrontSide}}));gltf.scene.animations=gltf.animations;objectContext.inputs.model=gltf.scene.clone();var model=gltf.scene;objectContext.outputs.objectRoot=model;objectContext.outputs.collider=model}),(function(xhr){if(xhr.loaded/xhr.total==1)console.log(xhr.loaded/xhr.total*100+"% loaded")}),(function(error){console.log("Error loading DRACO Gltf model",error)}))};this.onEvent=function(type,data){};this.onInputsUpdated=function(previous){var objectContext=this;var THREE=objectContext.context.three;if(objectContext.inputs.model){var model=objectContext.inputs.model;console.log("Updating:",model);console.log("Scale:",objectContext.inputs.scale);console.log("Rotation:",objectContext.inputs.rotation);model.scale.set(objectContext.inputs.scale.x/100,objectContext.inputs.scale.y/100,objectContext.inputs.scale.z/100);model.rotation.set(objectContext.inputs.rotation.x*(Math.PI/180),objectContext.inputs.rotation.y*(Math.PI/180),objectContext.inputs.rotation.z*(Math.PI/180))}};this.onDestroy=function(){this.material.dispose()}}function makeDracoGltfLoader(){return new DracoGltfRenderer}_atwin.Scene.register("atwin.gltfLoader",makeDracoGltfLoader)}function registerCustomLoaders(){if(_hasRegisteredLoaders===false){console.log("registerCustomLoaders()");createVideoComponent();createSlideScreenModel();_hasRegisteredLoaders=true}}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: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,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){_atwin.Pointer.intersection.subscribe((function(intersection){planePosition=intersection.position}));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={};_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]}}))}))}function setState(_a){var isLoading=_a.isLoading,loaded=_a.loaded,error=_a.error,data=_a.data;state.isLoading=isLoading;state.loaded=loaded;state.error=error!==undefined?error:"";state.data=data!==undefined?data:null}function checkValidFileType(payload){if(payload){var fileName=payload.name;var fileExtension=fileName.substring(fileName.lastIndexOf(".")+1);console.log("File extension "+fileExtension);if(supportedFileTypes.includes(fileExtension)){return{valid:true,type:fileExtension}}return{valid:false}}console.error("No file provided");return{valid:false}}function addObject(payload){return __awaiter(this,void 0,void 0,(function(){var fileCheck,response,id,error_6;return __generator(this,(function(_a){switch(_a.label){case 0:setState({isLoading:true,loaded:false});fileCheck=checkValidFileType(payload.file);if(!fileCheck.valid)return[3,4];_a.label=1;case 1:_a.trys.push([1,3,,4]);return[4,_api.post("/s3/file.json",payload)];case 2:response=_a.sent();if(response.data.status=="success"){id=response.data.data.id;setState({isLoading:false,loaded:true,data:id});return[2,state]}setState({isLoading:false,loaded:false});return[2,state];case 3:error_6=_a.sent();setState({isLoading:false,loaded:false,error:error_6});console.error("Object upload failed"+error_6);return[2,state];case 4:setState({isLoading:false,loaded:false,error:"Unsupported file type"});return[2,state]}}))}))}function getObject(id){return __awaiter(this,void 0,void 0,(function(){var response,object_data,error_7;return __generator(this,(function(_a){switch(_a.label){case 0:console.log("getObject()");if(!id)return[3,4];_a.label=1;case 1:_a.trys.push([1,3,,4]);return[4,_api.get("/v1/objects/".concat(id))];case 2:response=_a.sent();if(response.data.status=="success"){object_data=response.data.data;return[2,object_data]}console.error("Failed to get requested object");return[3,4];case 3:error_7=_a.sent();console.error("Error getting object "+error_7);return[3,4];case 4:return[2,null]}}))}))}function positionObject(object){return __awaiter(this,void 0,void 0,(function(){var modelNode,component;return __generator(this,(function(_a){console.log("positionObject()");console.log("Object Data "+JSON.stringify(object));if(object!==null||object!==undefined){modelNode=_sceneObject.addNode();component=modelNode.addComponent(getComponentLoader(object),{url:object.amazon_uri});if(!component.inputs){console.error("component.inputs is undefined");return[2]}}console.error("Object is either null or undefined");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};clearActionHistory();setSelectedObject(this.object_data,this.node,this.component,"3DX");return[4,setTransformControls(selectedObj)];case 1:_a.sent();return[2]}}))}))};return ClickSpy}();var DragSpy=function(){function DragSpy(data,node,component){this.eventType="INTERACTION.DRAG_END";this.object_data=data;this.node=node;this.component=component}DragSpy.prototype.onEvent=function(payload){return __awaiter(this,void 0,void 0,(function(){var selectedObj,objectCoords,currentTranform;return __generator(this,(function(_a){console.log("INTERACTION.DRAG_END",payload);selectedObj={object:this.object_data,node:this.node,component:this.component};console.log("New Drag Position"+JSON.stringify(selectedObj.node.position));console.log("New Drag Rotation"+JSON.stringify(selectedObj.node.obj3D.rotation));console.log("New Drag Scale"+JSON.stringify(selectedObj.node.scale));objectCoords={object_position:selectedObj.node.position,object_rotation:selectedObj.node.obj3D.rotation,object_scale:selectedObj.node.scale};currentObjTransform=objectCoords;currentTranform=JSON.stringify(currentObjTransform);actionHistory.push(currentTranform);console.log("Actions count "+actionHistory.length);console.log("Actions list "+actionHistory);return[2]}))}))};return DragSpy}();var atwin={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,setTransformMode:setTransformMode,setRenderDistance:setRenderDistance,clearActionHistory:clearActionHistory,addObject:addObject};export{atwin as default,tags,sweeps,selectedObject,previousObjTransform,currentObjTransform,actionHistory,state,_space,connectSpace,disconnectSpace,getTags,gotoTag,getSweeps,getCurrentSweep,getCurrentSweepPosition,moveToSweep,getNearbySweeps,pauseVideo,playVideo,getCurrentCameraPose,getCameraPosition,moveInDirection,cameraLookAt,cameraPan,cameraRotate,getViewMode,setViewMode,getNearbyObjects,setTransformMode,revertTransform,setRenderDistance,clearActionHistory,addObject};
|