@vived/app 4.35.3 → 4.36.0

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.
@@ -16,6 +16,7 @@ function setupZSpace(appObjectRepo) {
16
16
  UC_1.makeStylusFromGamepadHook(zSpaceAO);
17
17
  PM_1.makeZSpaceIsEnabledPM(zSpaceAO);
18
18
  PM_1.makeZSpaceViewerScalePM(zSpaceAO);
19
+ UC_1.makeCheckZSpaceDisplaySizeUC(zSpaceAO);
19
20
  const displayAO = zSpaceEntity.display.appObject;
20
21
  Transform3D_1.makeTransform3DPM(displayAO);
21
22
  PM_1.makeZSpaceDisplayPM(displayAO);
@@ -1,5 +1,5 @@
1
1
  /// <reference types="webxr" />
2
- import { AppObjectUC } from "../../../AppObject";
2
+ import { AppObject, AppObjectUC } from "../../../AppObject";
3
3
  export interface DisplaySize {
4
4
  width: number;
5
5
  height: number;
@@ -9,3 +9,11 @@ export declare abstract class CheckZSpaceDisplaySizeUC extends AppObjectUC {
9
9
  abstract checkDisplayFromXRSession(xrSession: XRSession): void;
10
10
  abstract checkDisplayFromSize(displaySize: DisplaySize): void;
11
11
  }
12
+ export declare function makeCheckZSpaceDisplaySizeUC(appObject: AppObject): CheckZSpaceDisplaySizeUC;
13
+ export declare class CheckZSpaceDisplaySizeImp extends CheckZSpaceDisplaySizeUC {
14
+ private zSpaceEntity?;
15
+ checkDisplayFromXRSession: (xrSession: XRSession) => void;
16
+ getDisplaySize: (xrSession: XRSession) => Promise<void>;
17
+ checkDisplayFromSize: (displaySize: DisplaySize) => void;
18
+ constructor(appObject: AppObject);
19
+ }
@@ -1,8 +1,56 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CheckZSpaceDisplaySizeUC = void 0;
12
+ exports.CheckZSpaceDisplaySizeImp = exports.makeCheckZSpaceDisplaySizeUC = exports.CheckZSpaceDisplaySizeUC = void 0;
4
13
  const AppObject_1 = require("../../../AppObject");
14
+ const ValueObjects_1 = require("../../../ValueObjects");
15
+ const Transform3D_1 = require("../../Transform3D");
16
+ const Entities_1 = require("../Entities");
17
+ const DisplaySizeExtractor_1 = require("./DisplaySizeExtractor");
5
18
  class CheckZSpaceDisplaySizeUC extends AppObject_1.AppObjectUC {
6
19
  }
7
20
  exports.CheckZSpaceDisplaySizeUC = CheckZSpaceDisplaySizeUC;
8
21
  CheckZSpaceDisplaySizeUC.type = "CheckZSpaceDisplaySizeUC";
22
+ function makeCheckZSpaceDisplaySizeUC(appObject) {
23
+ return new CheckZSpaceDisplaySizeImp(appObject);
24
+ }
25
+ exports.makeCheckZSpaceDisplaySizeUC = makeCheckZSpaceDisplaySizeUC;
26
+ class CheckZSpaceDisplaySizeImp extends CheckZSpaceDisplaySizeUC {
27
+ constructor(appObject) {
28
+ super(appObject, CheckZSpaceDisplaySizeUC.type);
29
+ this.checkDisplayFromXRSession = (xrSession) => {
30
+ this.getDisplaySize(xrSession);
31
+ };
32
+ this.getDisplaySize = (xrSession) => __awaiter(this, void 0, void 0, function* () {
33
+ const dse = new DisplaySizeExtractor_1.DisplaySizeExtractor(xrSession);
34
+ const displaySize = yield dse.QueryDisplaySize();
35
+ this.checkDisplayFromSize(displaySize);
36
+ });
37
+ this.checkDisplayFromSize = (displaySize) => {
38
+ const displayWidth = Math.round(displaySize.width * 1000) / 1000;
39
+ if (displayWidth !== Entities_1.INSPIRE_WIDTH && this.zSpaceEntity) {
40
+ const viewerScale = Entities_1.INSPIRE_WIDTH / displaySize.width;
41
+ this.zSpaceEntity.viewerScale = viewerScale;
42
+ this.zSpaceEntity.display.setForSize(displaySize.width, displaySize.height);
43
+ const zSpaceTransform = Transform3D_1.Transform3D.get(this.zSpaceEntity.appObject);
44
+ if (zSpaceTransform) {
45
+ zSpaceTransform.localScale = new ValueObjects_1.Vector3(viewerScale, viewerScale, viewerScale);
46
+ }
47
+ }
48
+ };
49
+ this.zSpaceEntity = Entities_1.ZSpaceEntity.get(appObject.appObjectRepo);
50
+ if (!this.zSpaceEntity) {
51
+ console.warn("[EmulateDisplaySizeHook] Unable to find the zSpace Entity");
52
+ return;
53
+ }
54
+ }
55
+ }
56
+ exports.CheckZSpaceDisplaySizeImp = CheckZSpaceDisplaySizeImp;
@@ -0,0 +1,34 @@
1
+ /// <reference types="webxr" />
2
+ interface DisplaySize {
3
+ width: number;
4
+ height: number;
5
+ }
6
+ declare class DisplaySizeExtractor {
7
+ private _planes;
8
+ private _displaySize;
9
+ private _session;
10
+ private _referenceSpace;
11
+ private _headPos;
12
+ private _raycastLeft;
13
+ private _raycastRight;
14
+ private _raycastTop;
15
+ private _raycastBottom;
16
+ private resolve;
17
+ private reject;
18
+ constructor(xrSession: XRSession);
19
+ QueryDisplaySize(): Promise<DisplaySize>;
20
+ private _onXrFrame;
21
+ private _intersectRayPlaneDistance;
22
+ private _vec3subtract;
23
+ private _vec3multiply;
24
+ private _vec3dot;
25
+ private _mat4Transpose;
26
+ private _extractPlanes;
27
+ private _normalizePlane;
28
+ private _normalizeFrustumPlanes;
29
+ private _vec4tovec3;
30
+ private _vec4TransformMat4;
31
+ private _vec3TransformMat4;
32
+ private _mat4multiply;
33
+ }
34
+ export { DisplaySizeExtractor };
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+ //////////////////////////////////////////////////////////////////////////
3
+ //
4
+ // Copyright (C) 2007-2023 zSpace, Inc. All Rights Reserved.
5
+ //
6
+ //////////////////////////////////////////////////////////////////////////
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.DisplaySizeExtractor = void 0;
9
+ class DisplaySizeExtractor {
10
+ constructor(xrSession) {
11
+ this._planes = [];
12
+ this._displaySize = { width: 0, height: 0 };
13
+ this._session = xrSession;
14
+ this._referenceSpace = null;
15
+ this._headPos = [0, 0, 0, 1];
16
+ this._raycastLeft = null;
17
+ this._raycastRight = null;
18
+ this._raycastTop = null;
19
+ this._raycastBottom = null;
20
+ this.resolve = null;
21
+ this.reject = null;
22
+ }
23
+ QueryDisplaySize() {
24
+ return new Promise((resolve, reject) => {
25
+ this.resolve = resolve;
26
+ this.reject = reject;
27
+ if (this._referenceSpace === null) {
28
+ this._session
29
+ .requestReferenceSpace("local")
30
+ .then((refSpace) => {
31
+ this._referenceSpace = refSpace;
32
+ this._session.requestAnimationFrame(this._onXrFrame.bind(this));
33
+ })
34
+ .catch((err) => {
35
+ if (this.reject)
36
+ this.reject(err);
37
+ });
38
+ }
39
+ else {
40
+ this._session.requestAnimationFrame(this._onXrFrame.bind(this));
41
+ }
42
+ });
43
+ }
44
+ _onXrFrame(time, frame) {
45
+ var _a;
46
+ if (!this._referenceSpace || !this.resolve)
47
+ return;
48
+ const view = (_a = frame.getViewerPose(this._referenceSpace)) === null || _a === void 0 ? void 0 : _a.views[0];
49
+ if (!view)
50
+ return;
51
+ const projection = this._mat4Transpose(view.projectionMatrix);
52
+ const viewInverse = this._mat4Transpose(view.transform.inverse.matrix);
53
+ const combo = this._mat4multiply(projection, viewInverse);
54
+ this._planes = this._extractPlanes(combo);
55
+ this._planes = this._normalizeFrustumPlanes(this._planes);
56
+ this._headPos = [
57
+ view.transform.inverse.position.x,
58
+ view.transform.inverse.position.y,
59
+ view.transform.inverse.position.z,
60
+ view.transform.inverse.position.w,
61
+ ];
62
+ this._raycastLeft = this._intersectRayPlaneDistance(this._headPos, this._planes[0], [0, 0, 0], [1, 0, 0]);
63
+ this._raycastRight = this._intersectRayPlaneDistance(this._headPos, this._planes[1], [0, 0, 0], [-1, 0, 0]);
64
+ this._raycastTop = this._intersectRayPlaneDistance(this._headPos, this._planes[2], [0, 0, 0], [0, 1, 0]);
65
+ this._raycastBottom = this._intersectRayPlaneDistance(this._headPos, this._planes[3], [0, 0, 0], [0, -1, 0]);
66
+ this._displaySize = {
67
+ width: this._raycastLeft + this._raycastRight,
68
+ height: this._raycastTop + this._raycastBottom,
69
+ };
70
+ this.resolve(this._displaySize);
71
+ }
72
+ _intersectRayPlaneDistance(plane_pos, plane_norm, ray_pos, ray_norm) {
73
+ if (plane_pos.length === 4) {
74
+ plane_pos = this._vec4tovec3(plane_pos);
75
+ }
76
+ if (plane_norm.length === 4) {
77
+ plane_norm = this._vec4tovec3(plane_norm);
78
+ }
79
+ return (this._vec3dot(plane_norm, this._vec3subtract(ray_pos, plane_pos)) /
80
+ this._vec3dot(plane_norm, this._vec3subtract([0, 0, 0], ray_norm)));
81
+ }
82
+ _vec3subtract(a, b) {
83
+ const out = [];
84
+ out[0] = a[0] - b[0];
85
+ out[1] = a[1] - b[1];
86
+ out[2] = a[2] - b[2];
87
+ out.length = 3;
88
+ return out;
89
+ }
90
+ _vec3multiply(a, b) {
91
+ const out = [];
92
+ out[0] = a[0] * b[0];
93
+ out[1] = a[1] * b[1];
94
+ out[2] = a[2] * b[2];
95
+ out.length = 3;
96
+ return out;
97
+ }
98
+ _vec3dot(a, b) {
99
+ const x = a[0] * b[0];
100
+ const y = a[1] * b[1];
101
+ const z = a[2] * b[2];
102
+ return x + y + z;
103
+ }
104
+ _mat4Transpose(a) {
105
+ const out = [];
106
+ out[0] = a[0];
107
+ out[1] = a[4];
108
+ out[2] = a[8];
109
+ out[3] = a[12];
110
+ out[4] = a[1];
111
+ out[5] = a[5];
112
+ out[6] = a[9];
113
+ out[7] = a[13];
114
+ out[8] = a[2];
115
+ out[9] = a[6];
116
+ out[10] = a[10];
117
+ out[11] = a[14];
118
+ out[12] = a[3];
119
+ out[13] = a[7];
120
+ out[14] = a[11];
121
+ out[15] = a[15];
122
+ return out;
123
+ }
124
+ _extractPlanes(M, zNear, zFar) {
125
+ return [
126
+ // Left
127
+ [M[12] + M[0], M[13] + M[1], M[14] + M[2], M[15] + M[3]],
128
+ // Right
129
+ [M[12] - M[0], M[13] - M[1], M[14] - M[2], M[15] - M[3]],
130
+ // Top
131
+ [M[12] + M[4], M[13] + M[5], M[14] + M[6], M[15] + M[7]],
132
+ // Bottom
133
+ [M[12] - M[4], M[13] - M[5], M[14] - M[6], M[15] - M[7]],
134
+ ];
135
+ }
136
+ _normalizePlane(plane) {
137
+ const mag = Math.sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
138
+ const normalizedPlane = [];
139
+ normalizedPlane[0] = plane[0] / mag;
140
+ normalizedPlane[1] = plane[1] / mag;
141
+ normalizedPlane[2] = plane[2] / mag;
142
+ normalizedPlane[3] = 1 / mag;
143
+ normalizedPlane.length = 4;
144
+ return normalizedPlane;
145
+ }
146
+ _normalizeFrustumPlanes(planes) {
147
+ return planes.map((plane) => this._normalizePlane(plane));
148
+ }
149
+ _vec4tovec3(v) {
150
+ const out = [];
151
+ out[0] = v[0] * (1 / v[3]);
152
+ out[1] = v[1] * (1 / v[3]);
153
+ out[2] = v[2] * (1 / v[3]);
154
+ out.length = 3;
155
+ return out;
156
+ }
157
+ _vec4TransformMat4(a, m) {
158
+ const out = [0, 0, 0, 1];
159
+ const x = a[0];
160
+ const y = a[1];
161
+ const z = a[2];
162
+ const w = a[3];
163
+ out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
164
+ out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
165
+ out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
166
+ out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
167
+ out.length = 4;
168
+ return out;
169
+ }
170
+ _vec3TransformMat4(a, m) {
171
+ const out = [0, 0, 0];
172
+ const x = a[0];
173
+ const y = a[1];
174
+ const z = a[2];
175
+ const w = m[3] * x + m[7] * y + m[11] * z + m[15] || 1.0;
176
+ out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
177
+ out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
178
+ out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
179
+ out.length = 3;
180
+ return out;
181
+ }
182
+ _mat4multiply(a, b) {
183
+ const out = [];
184
+ const a00 = a[0];
185
+ const a01 = a[1];
186
+ const a02 = a[2];
187
+ const a03 = a[3];
188
+ const a10 = a[4];
189
+ const a11 = a[5];
190
+ const a12 = a[6];
191
+ const a13 = a[7];
192
+ const a20 = a[8];
193
+ const a21 = a[9];
194
+ const a22 = a[10];
195
+ const a23 = a[11];
196
+ const a30 = a[12];
197
+ const a31 = a[13];
198
+ const a32 = a[14];
199
+ const a33 = a[15];
200
+ let b0 = b[0];
201
+ let b1 = b[1];
202
+ let b2 = b[2];
203
+ let b3 = b[3];
204
+ out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
205
+ out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
206
+ out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
207
+ out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
208
+ b0 = b[4];
209
+ b1 = b[5];
210
+ b2 = b[6];
211
+ b3 = b[7];
212
+ out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
213
+ out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
214
+ out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
215
+ out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
216
+ b0 = b[8];
217
+ b1 = b[9];
218
+ b2 = b[10];
219
+ b3 = b[11];
220
+ out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
221
+ out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
222
+ out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
223
+ out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
224
+ b0 = b[12];
225
+ b1 = b[13];
226
+ b2 = b[14];
227
+ b3 = b[15];
228
+ out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
229
+ out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
230
+ out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
231
+ out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
232
+ return out;
233
+ }
234
+ }
235
+ exports.DisplaySizeExtractor = DisplaySizeExtractor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vived/app",
3
- "version": "4.35.3",
3
+ "version": "4.36.0",
4
4
  "description": "Public package for the VIVED Learning App system",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",