@inweb/client 25.3.18 → 25.3.19

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.
@@ -240,11 +240,11 @@ export declare class Assembly {
240
240
  * ="_blank">AbortSignal</a> object instance. Allows to communicate with a fetch request
241
241
  * and abort it if desired.
242
242
  */
243
- downloadResourceRange(dataId: string, ranges: Array<{
243
+ downloadResourceRange(dataId: string, requestId: number, ranges: Array<{
244
244
  begin: number;
245
245
  end: number;
246
246
  requestId: number;
247
- }>, requestId: number, onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
247
+ }>, onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
248
248
  /**
249
249
  * Deprecated since `25.3`. Use {@link Assembly.downloadResource()} instead.
250
250
  */
package/lib/Api/File.d.ts CHANGED
@@ -363,11 +363,11 @@ export declare class File {
363
363
  * ="_blank">AbortSignal</a> object instance. Allows to communicate with a fetch request
364
364
  * and abort it if desired.
365
365
  */
366
- downloadResourceRange(dataId: string, ranges: Array<{
366
+ downloadResourceRange(dataId: string, requestId: number, ranges: Array<{
367
367
  begin: number;
368
368
  end: number;
369
369
  requestId: number;
370
- }>, requestId: number, onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
370
+ }>, onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
371
371
  /**
372
372
  * Deprecated since `25.3`. Use {@link File.downloadResource()} instead.
373
373
  */
@@ -10,7 +10,7 @@ export declare class HttpClient implements IHttpClient {
10
10
  delete(relativePath: string): Promise<Response>;
11
11
  uploadFile(relativePath: string, file: File, onProgress?: (progress: number) => void): Promise<XMLHttpRequest>;
12
12
  downloadFile(relativePath: string, onProgress?: (progress: number, chunk: Uint8Array) => void, signal?: AbortSignal): Promise<Response>;
13
- downloadFileRange(relativePath: string, ranges: Array<{
13
+ downloadFileRange(relativePath: string, requestId: number, ranges: Array<{
14
14
  begin: number;
15
15
  end: number;
16
16
  requestId: number;
@@ -8,7 +8,7 @@ export interface IHttpClient {
8
8
  delete(relativePath: string): Promise<Response>;
9
9
  uploadFile(relativePath: string, file: globalThis.File, onProgress?: (progress: number) => void): Promise<XMLHttpRequest>;
10
10
  downloadFile(relativePath: string, onProgress?: (progress: number, chunk: Uint8Array) => void, signal?: AbortSignal): Promise<Response>;
11
- downloadFileRange(relativePath: string, ranges: Array<{
11
+ downloadFileRange(relativePath: string, requestId: number, ranges: Array<{
12
12
  begin: number;
13
13
  end: number;
14
14
  requestId: number;
@@ -169,11 +169,11 @@ export declare class Model {
169
169
  * ="_blank">AbortSignal</a> object instance. Allows to communicate with a fetch request
170
170
  * and abort it if desired.
171
171
  */
172
- downloadResourceRange(dataId: string, ranges: Array<{
172
+ downloadResourceRange(dataId: string, requestId: number, ranges: Array<{
173
173
  begin: number;
174
174
  end: number;
175
175
  requestId: number;
176
- }>, requestId: number, onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
176
+ }>, onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
177
177
  /**
178
178
  * Deprecated since `25.3`. Use {@link Model.downloadResource()} instead.
179
179
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/client",
3
- "version": "25.3.18",
3
+ "version": "25.3.19",
4
4
  "description": "JavaScript REST API client for the Open Cloud Server",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -27,6 +27,6 @@
27
27
  "ts-docs": "typedoc"
28
28
  },
29
29
  "dependencies": {
30
- "@inweb/eventemitter2": "^25.3.13"
30
+ "@inweb/eventemitter2": "^25.3.18"
31
31
  }
32
32
  }
@@ -441,14 +441,14 @@ export class Assembly {
441
441
  */
442
442
  downloadResourceRange(
443
443
  dataId: string,
444
- ranges: Array<{ begin: number; end: number; requestId: number }>,
445
444
  requestId: number,
445
+ ranges: Array<{ begin: number; end: number; requestId: number }>,
446
446
  onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void,
447
447
  signal?: AbortSignal
448
448
  ): Promise<ArrayBuffer> {
449
449
  const relativePath = this.appendVersionParam(`/downloads/${dataId}?requestId=${requestId}`);
450
450
  return this.httpClient
451
- .downloadFileRange(`${this.path}${relativePath}`, ranges, onProgress, signal)
451
+ .downloadFileRange(`${this.path}${relativePath}`, requestId, ranges, onProgress, signal)
452
452
  .then((response) => response.arrayBuffer());
453
453
  }
454
454
 
@@ -476,7 +476,7 @@ export class Assembly {
476
476
  onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void,
477
477
  signal?: AbortSignal
478
478
  ): Promise<void> {
479
- await this.downloadResourceRange(dataId, records, requestId, onProgress, signal);
479
+ await this.downloadResourceRange(dataId, requestId, records, onProgress, signal);
480
480
  }
481
481
 
482
482
  // Reserved for future use
package/src/Api/File.ts CHANGED
@@ -587,14 +587,14 @@ export class File {
587
587
  */
588
588
  downloadResourceRange(
589
589
  dataId: string,
590
- ranges: Array<{ begin: number; end: number; requestId: number }>,
591
590
  requestId: number,
591
+ ranges: Array<{ begin: number; end: number; requestId: number }>,
592
592
  onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void,
593
593
  signal?: AbortSignal
594
594
  ): Promise<ArrayBuffer> {
595
595
  const relativePath = this.appendVersionParam(`/downloads/${dataId}?requestId=${requestId}`);
596
596
  return this.httpClient
597
- .downloadFileRange(`${this.path}${relativePath}`, ranges, onProgress, signal)
597
+ .downloadFileRange(`${this.path}${relativePath}`, requestId, ranges, onProgress, signal)
598
598
  .then((response) => response.arrayBuffer());
599
599
  }
600
600
 
@@ -622,7 +622,7 @@ export class File {
622
622
  onProgress?: (progress: number, downloaded: Uint8Array, requestId: number) => void,
623
623
  signal?: AbortSignal
624
624
  ): Promise<void> {
625
- await this.downloadResourceRange(dataId, records, requestId, onProgress, signal);
625
+ await this.downloadResourceRange(dataId, requestId, records, onProgress, signal);
626
626
  }
627
627
 
628
628
  /**
@@ -111,6 +111,7 @@ export class HttpClient implements IHttpClient {
111
111
 
112
112
  async downloadFileRange(
113
113
  relativePath: string,
114
+ requestId: number,
114
115
  ranges: Array<{ begin: number; end: number; requestId: number }>,
115
116
  onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void,
116
117
  signal?: AbortSignal
@@ -48,6 +48,7 @@ export interface IHttpClient {
48
48
 
49
49
  downloadFileRange(
50
50
  relativePath: string,
51
+ requestId: number,
51
52
  ranges: Array<{ begin: number; end: number; requestId: number }>,
52
53
  onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void,
53
54
  signal?: AbortSignal
package/src/Api/Model.ts CHANGED
@@ -279,12 +279,12 @@ export class Model {
279
279
  */
280
280
  downloadResourceRange(
281
281
  dataId: string,
282
- ranges: Array<{ begin: number; end: number; requestId: number }>,
283
282
  requestId: number,
283
+ ranges: Array<{ begin: number; end: number; requestId: number }>,
284
284
  onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void,
285
285
  signal?: AbortSignal
286
286
  ): Promise<ArrayBuffer> {
287
- return this._file.downloadResourceRange(dataId, ranges, requestId, onProgress, signal);
287
+ return this._file.downloadResourceRange(dataId, requestId, ranges, onProgress, signal);
288
288
  }
289
289
 
290
290
  /**
@@ -328,7 +328,7 @@ export class Model {
328
328
  }
329
329
  }
330
330
 
331
- await this.downloadResourceRange(dataId, ranges, requestId, onProgress, signal);
331
+ await this.downloadResourceRange(dataId, requestId, ranges, onProgress, signal);
332
332
  }
333
333
 
334
334
  /**
@@ -1,28 +0,0 @@
1
- /**
2
- * Convert world coordinates to screen normalized (-1, 1)
3
- *
4
- * @param viewMatrix Camera world matrix
5
- * @param projectionMatrix Camera projection matrix
6
- * @param worldPoint World point
7
- */
8
- export declare function worldToScreenNormalized(viewMatrix: Array<number>, projectionMatrix: Array<number>, worldPoint: [x: number, y: number, z: number]): [x: number, y: number, z: number];
9
- export declare function multiplyMatrices(a: Array<number>, b: Array<number>): Array<number>;
10
- /**
11
- * @param matrix
12
- * @returns Matrix
13
- */
14
- export declare function invertMatrix(matrix: Array<number>): Array<number>;
15
- /**
16
- * Convert world coordinates to screen (screenWidth, screenHeight)
17
- *
18
- * @param viewMatrix Camera world matrix
19
- * @param projectionMatrix Camera projection matrix
20
- * @param worldPoint World point
21
- * @param screenWidth Screen width
22
- * @param screenHeight Screen height
23
- */
24
- export declare function worldToScreen(viewMatrix: Array<number>, projectionMatrix: Array<number>, worldPoint: [x: number, y: number, z: number], screenWidth: number, screenHeight: number): number[];
25
- export declare function createOrthoProjectionMatrix(camera: any, width: any, height: any): number[];
26
- export declare function createViewMatrix(camera: any): any[];
27
- export declare function bcfWorldToScreenFromCamera(camera: any, canvas: HTMLCanvasElement, point: [x: number, y: number, z: number]): number[];
28
- export declare function matrixLookAt(matrix: any, eye: any, target: any, up: any): any;
package/src/ConvetMath.ts DELETED
@@ -1,372 +0,0 @@
1
- /**
2
- * Convert world coordinates to screen normalized (-1, 1)
3
- *
4
- * @param viewMatrix Camera world matrix
5
- * @param projectionMatrix Camera projection matrix
6
- * @param worldPoint World point
7
- */
8
- export function worldToScreenNormalized(
9
- viewMatrix: Array<number>,
10
- projectionMatrix: Array<number>,
11
- worldPoint: [x: number, y: number, z: number]
12
- ): [x: number, y: number, z: number] {
13
- function applyMatrixToPoint3(matrix, point: [x: number, y: number, z: number]): [x: number, y: number, z: number] {
14
- const [x, y, z] = point;
15
- const e = matrix;
16
- const w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
17
-
18
- return [
19
- (e[0] * x + e[4] * y + e[8] * z + e[12]) * w,
20
- (e[1] * x + e[5] * y + e[9] * z + e[13]) * w,
21
- (e[2] * x + e[6] * y + e[10] * z + e[14]) * w,
22
- ];
23
- }
24
-
25
- const [x, y, z] = applyMatrixToPoint3(projectionMatrix, applyMatrixToPoint3(invertMatrix(viewMatrix), worldPoint));
26
-
27
- return [x, y, z];
28
- }
29
-
30
- export function multiplyMatrices(a: Array<number>, b: Array<number>): Array<number> {
31
- const ae = a;
32
- const be = b;
33
- const te = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
34
-
35
- const a11 = ae[0],
36
- a12 = ae[4],
37
- a13 = ae[8],
38
- a14 = ae[12];
39
- const a21 = ae[1],
40
- a22 = ae[5],
41
- a23 = ae[9],
42
- a24 = ae[13];
43
- const a31 = ae[2],
44
- a32 = ae[6],
45
- a33 = ae[10],
46
- a34 = ae[14];
47
- const a41 = ae[3],
48
- a42 = ae[7],
49
- a43 = ae[11],
50
- a44 = ae[15];
51
-
52
- const b11 = be[0],
53
- b12 = be[4],
54
- b13 = be[8],
55
- b14 = be[12];
56
- const b21 = be[1],
57
- b22 = be[5],
58
- b23 = be[9],
59
- b24 = be[13];
60
- const b31 = be[2],
61
- b32 = be[6],
62
- b33 = be[10],
63
- b34 = be[14];
64
- const b41 = be[3],
65
- b42 = be[7],
66
- b43 = be[11],
67
- b44 = be[15];
68
-
69
- te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
70
- te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
71
- te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
72
- te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
73
-
74
- te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
75
- te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
76
- te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
77
- te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
78
-
79
- te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
80
- te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
81
- te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
82
- te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
83
-
84
- te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
85
- te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
86
- te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
87
- te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
88
-
89
- return te;
90
- }
91
-
92
- /**
93
- * @param matrix
94
- * @returns Matrix
95
- */
96
- export function invertMatrix(matrix: Array<number>): Array<number> {
97
- const te = matrix,
98
- n11 = te[0],
99
- n21 = te[1],
100
- n31 = te[2],
101
- n41 = te[3],
102
- n12 = te[4],
103
- n22 = te[5],
104
- n32 = te[6],
105
- n42 = te[7],
106
- n13 = te[8],
107
- n23 = te[9],
108
- n33 = te[10],
109
- n43 = te[11],
110
- n14 = te[12],
111
- n24 = te[13],
112
- n34 = te[14],
113
- n44 = te[15],
114
- t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
115
- t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
116
- t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
117
- t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
118
-
119
- const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
120
-
121
- if (det === 0) return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
122
-
123
- const detInv = 1 / det;
124
-
125
- return [
126
- t11 * detInv,
127
- (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) *
128
- detInv,
129
- (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) *
130
- detInv,
131
- (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) *
132
- detInv,
133
-
134
- t12 * detInv,
135
- (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) *
136
- detInv,
137
- (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) *
138
- detInv,
139
- (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) *
140
- detInv,
141
-
142
- t13 * detInv,
143
- (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) *
144
- detInv,
145
- (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) *
146
- detInv,
147
- (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) *
148
- detInv,
149
-
150
- t14 * detInv,
151
- (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) *
152
- detInv,
153
- (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) *
154
- detInv,
155
- (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) *
156
- detInv,
157
- ];
158
- }
159
-
160
- /**
161
- * Convert world coordinates to screen (screenWidth, screenHeight)
162
- *
163
- * @param viewMatrix Camera world matrix
164
- * @param projectionMatrix Camera projection matrix
165
- * @param worldPoint World point
166
- * @param screenWidth Screen width
167
- * @param screenHeight Screen height
168
- */
169
- export function worldToScreen(
170
- viewMatrix: Array<number>,
171
- projectionMatrix: Array<number>,
172
- worldPoint: [x: number, y: number, z: number],
173
- screenWidth: number,
174
- screenHeight: number
175
- ) {
176
- const widthHalf = screenWidth / 2;
177
- const heightHalf = screenHeight / 2;
178
-
179
- const [x, y] = worldToScreenNormalized(viewMatrix, projectionMatrix, worldPoint);
180
- const p = [x * widthHalf + widthHalf, -(y * heightHalf) + heightHalf];
181
- return p;
182
- }
183
-
184
- /**
185
- * @param a
186
- * @returns
187
- */
188
- function lengthVector(a: { x: number; y: number; z: number }): number {
189
- return Math.sqrt(a.x * a.x + a.y * a.y + a.z * a.z);
190
- }
191
- function normalizeVector(a: { x: number; y: number; z: number }): { x: number; y: number; z: number } {
192
- const len = lengthVector(a);
193
- if (len === 0) return a;
194
- return {
195
- x: a.x / len,
196
- y: a.y / len,
197
- z: a.z / len,
198
- };
199
- }
200
-
201
- function crossVectors(a, b) {
202
- const ax = a.x,
203
- ay = a.y,
204
- az = a.z;
205
- const bx = b.x,
206
- by = b.y,
207
- bz = b.z;
208
-
209
- return {
210
- x: ay * bz - az * by,
211
- y: az * bx - ax * bz,
212
- z: ax * by - ay * bx,
213
- };
214
- }
215
-
216
- function normalizedProjection(
217
- width,
218
- height,
219
- nearClipPlaneDist,
220
- farClipPlaneDist,
221
- normalizedCenter,
222
- normalizedWidth,
223
- normalizedHeight,
224
- normalizedDepth
225
- ) {
226
- const mtx = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
227
-
228
- mtx[0] = -normalizedWidth / width;
229
- mtx[1] = 0;
230
- mtx[2] = 0.0;
231
- mtx[3] = normalizedCenter.x;
232
-
233
- mtx[4] = 0.0;
234
- mtx[5] = -normalizedHeight / height;
235
- mtx[6] = 0.0;
236
- mtx[7] = normalizedCenter.y;
237
-
238
- mtx[8] = 0;
239
- mtx[9] = 0.0;
240
- mtx[10] = normalizedDepth / (farClipPlaneDist - nearClipPlaneDist);
241
- mtx[11] = -mtx[10] * nearClipPlaneDist;
242
-
243
- mtx[12] = mtx[13] = mtx[14] = 0.0;
244
- mtx[15] = 1.0;
245
-
246
- return mtx;
247
- }
248
-
249
- export function createOrthoProjectionMatrix(camera, width, height) {
250
- const nearClipPlaneDist = 0.1;
251
- const farClipPlaneDist = 1000;
252
- const fieldWidth = camera.field_width;
253
- const fieldHeight = camera.field_height;
254
- let viewportNormalizedWidth = 2;
255
- let viewportNormalizedHeight = 2;
256
-
257
- if (width > height) {
258
- const aspect = height / width;
259
- const aspectFiled = fieldHeight / fieldWidth;
260
- viewportNormalizedWidth = (2 / aspectFiled) * aspect;
261
- viewportNormalizedHeight = 2;
262
- } else {
263
- const aspect = width / height;
264
- const aspectFiled = fieldWidth / fieldHeight;
265
- viewportNormalizedWidth = 2;
266
- viewportNormalizedHeight = (2 / aspectFiled) * aspect;
267
- }
268
-
269
- const viewportNormalizedCenter = {
270
- x: 0,
271
- y: 0,
272
- };
273
-
274
- const projectionMatrix = normalizedProjection(
275
- fieldWidth,
276
- fieldHeight,
277
- nearClipPlaneDist,
278
- farClipPlaneDist,
279
- viewportNormalizedCenter,
280
- viewportNormalizedWidth,
281
- viewportNormalizedHeight,
282
- 1.0
283
- );
284
-
285
- return projectionMatrix;
286
- }
287
-
288
- export function createViewMatrix(camera) {
289
- const position = camera.view_point;
290
-
291
- const viewMatrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, position.x, position.y, position.z, 1];
292
-
293
- const target = addVectors(camera.direction, position);
294
-
295
- matrixLookAt(viewMatrix, position, target, camera.up_vector);
296
-
297
- return viewMatrix;
298
- }
299
-
300
- export function bcfWorldToScreenFromCamera(
301
- camera,
302
- canvas: HTMLCanvasElement,
303
- point: [x: number, y: number, z: number]
304
- ) {
305
- const { width, height } = canvas;
306
-
307
- if (lengthVector(camera.direction) >= 1.0001) {
308
- camera = {
309
- ...camera,
310
- direction: normalizeVector(subVectors(camera.direction, camera.view_point)),
311
- };
312
- }
313
-
314
- const projectionMatrix = createOrthoProjectionMatrix(camera, width, height);
315
- const viewMatrix = createViewMatrix(camera);
316
-
317
- return worldToScreen(viewMatrix, projectionMatrix, point, width, height);
318
- }
319
-
320
- function subVectors(
321
- a: { x: number; y: number; z: number },
322
- b: { x: number; y: number; z: number }
323
- ): { x: number; y: number; z: number } {
324
- return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
325
- }
326
-
327
- function addVectors(
328
- a: { x: number; y: number; z: number },
329
- b: { x: number; y: number; z: number }
330
- ): { x: number; y: number; z: number } {
331
- return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
332
- }
333
-
334
- export function matrixLookAt(matrix, eye, target, up) {
335
- let z = subVectors(eye, target);
336
-
337
- if (lengthVector(z) === 0) {
338
- z.z = 1;
339
- }
340
- z = normalizeVector(z);
341
-
342
- let x = crossVectors(z, up);
343
- if (lengthVector(x) === 0) {
344
- if (Math.abs(up.z) === 1) {
345
- z.x += 0.0001;
346
- } else {
347
- z.z += 0.0001;
348
- }
349
-
350
- z = normalizeVector(z);
351
-
352
- x = crossVectors(up, z);
353
- }
354
-
355
- x = normalizeVector(x);
356
-
357
- const y = crossVectors(z, x);
358
-
359
- const m = matrix;
360
-
361
- m[0] = x.x;
362
- m[4] = y.x;
363
- m[8] = z.x;
364
- m[1] = x.y;
365
- m[5] = y.y;
366
- m[9] = z.y;
367
- m[2] = x.z;
368
- m[6] = y.z;
369
- m[10] = z.z;
370
-
371
- return m;
372
- }