hj-gis-sdk 1.0.0 → 1.0.2

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.
Files changed (194) hide show
  1. package/README.md +50 -59
  2. package/dev-dist/animation.esm.js +152 -0
  3. package/dev-dist/animation.esm.js.map +1 -0
  4. package/dev-dist/animation.js +154 -0
  5. package/dev-dist/animation.js.map +1 -0
  6. package/dev-dist/building.esm.js +85 -0
  7. package/dev-dist/building.esm.js.map +1 -0
  8. package/dev-dist/building.js +87 -0
  9. package/dev-dist/building.js.map +1 -0
  10. package/dev-dist/common.esm.js +16159 -0
  11. package/dev-dist/common.esm.js.map +1 -0
  12. package/dev-dist/common.js +16163 -0
  13. package/dev-dist/common.js.map +1 -0
  14. package/dev-dist/fence.esm.js +100 -0
  15. package/dev-dist/fence.esm.js.map +1 -0
  16. package/dev-dist/fence.js +102 -0
  17. package/dev-dist/fence.js.map +1 -0
  18. package/dev-dist/ghost.esm.js +53 -0
  19. package/dev-dist/ghost.esm.js.map +1 -0
  20. package/dev-dist/ghost.js +55 -0
  21. package/dev-dist/ghost.js.map +1 -0
  22. package/dev-dist/heatmap.esm.js +103 -0
  23. package/dev-dist/heatmap.esm.js.map +1 -0
  24. package/dev-dist/heatmap.js +105 -0
  25. package/dev-dist/heatmap.js.map +1 -0
  26. package/dev-dist/index.esm.js +21 -0
  27. package/dev-dist/index.esm.js.map +1 -0
  28. package/dev-dist/index.esm2.js +4272 -0
  29. package/dev-dist/index.esm2.js.map +1 -0
  30. package/dev-dist/index.js +26 -0
  31. package/dev-dist/index.js.map +1 -0
  32. package/dev-dist/index2.js +4280 -0
  33. package/dev-dist/index2.js.map +1 -0
  34. package/dev-dist/keyframe.esm.js +95 -0
  35. package/dev-dist/keyframe.esm.js.map +1 -0
  36. package/dev-dist/keyframe.js +97 -0
  37. package/dev-dist/keyframe.js.map +1 -0
  38. package/dev-dist/measurement.esm.js +57 -0
  39. package/dev-dist/measurement.esm.js.map +1 -0
  40. package/dev-dist/measurement.js +59 -0
  41. package/dev-dist/measurement.js.map +1 -0
  42. package/dev-dist/scatter.esm.js +85 -0
  43. package/dev-dist/scatter.esm.js.map +1 -0
  44. package/dev-dist/scatter.js +87 -0
  45. package/dev-dist/scatter.js.map +1 -0
  46. package/dev-dist/src.esm.js +289 -0
  47. package/dev-dist/src.esm.js.map +1 -0
  48. package/dev-dist/src.js +291 -0
  49. package/dev-dist/src.js.map +1 -0
  50. package/dev-dist/types/hj-gis-sdk/addons/animation/animate-clip.d.ts +39 -0
  51. package/dev-dist/types/hj-gis-sdk/addons/animation/animate-clip.d.ts.map +1 -0
  52. package/dev-dist/types/hj-gis-sdk/addons/animation/animation-action.d.ts +31 -0
  53. package/dev-dist/types/hj-gis-sdk/addons/animation/animation-action.d.ts.map +1 -0
  54. package/dev-dist/types/hj-gis-sdk/addons/animation/animation-mixer.d.ts +18 -0
  55. package/dev-dist/types/hj-gis-sdk/addons/animation/animation-mixer.d.ts.map +1 -0
  56. package/dev-dist/types/hj-gis-sdk/addons/animation/index.d.ts +5 -0
  57. package/dev-dist/types/hj-gis-sdk/addons/animation/index.d.ts.map +1 -0
  58. package/dev-dist/types/hj-gis-sdk/addons/camera.d.ts +59 -0
  59. package/dev-dist/types/hj-gis-sdk/addons/camera.d.ts.map +1 -0
  60. package/dev-dist/types/hj-gis-sdk/addons/clock.d.ts +40 -0
  61. package/dev-dist/types/hj-gis-sdk/addons/clock.d.ts.map +1 -0
  62. package/dev-dist/types/hj-gis-sdk/addons/commander/context.d.ts +24 -0
  63. package/dev-dist/types/hj-gis-sdk/addons/commander/context.d.ts.map +1 -0
  64. package/dev-dist/types/hj-gis-sdk/addons/commander/dispatcher.d.ts +43 -0
  65. package/dev-dist/types/hj-gis-sdk/addons/commander/dispatcher.d.ts.map +1 -0
  66. package/dev-dist/types/hj-gis-sdk/addons/commander/excutor/base.d.ts +22 -0
  67. package/dev-dist/types/hj-gis-sdk/addons/commander/excutor/base.d.ts.map +1 -0
  68. package/dev-dist/types/hj-gis-sdk/addons/loader/index.d.ts +6 -0
  69. package/dev-dist/types/hj-gis-sdk/addons/loader/index.d.ts.map +1 -0
  70. package/dev-dist/types/hj-gis-sdk/addons/loader/loader.d.ts +4 -0
  71. package/dev-dist/types/hj-gis-sdk/addons/loader/loader.d.ts.map +1 -0
  72. package/dev-dist/types/hj-gis-sdk/addons/node/base.d.ts +63 -0
  73. package/dev-dist/types/hj-gis-sdk/addons/node/base.d.ts.map +1 -0
  74. package/dev-dist/types/hj-gis-sdk/addons/node/ue-node.d.ts +82 -0
  75. package/dev-dist/types/hj-gis-sdk/addons/node/ue-node.d.ts.map +1 -0
  76. package/dev-dist/types/hj-gis-sdk/addons/proxy.d.ts +83 -0
  77. package/dev-dist/types/hj-gis-sdk/addons/proxy.d.ts.map +1 -0
  78. package/dev-dist/types/hj-gis-sdk/addons/tools/base.d.ts +7 -0
  79. package/dev-dist/types/hj-gis-sdk/addons/tools/base.d.ts.map +1 -0
  80. package/dev-dist/types/hj-gis-sdk/addons/tools/building.d.ts +36 -0
  81. package/dev-dist/types/hj-gis-sdk/addons/tools/building.d.ts.map +1 -0
  82. package/dev-dist/types/hj-gis-sdk/addons/tools/daytime.d.ts +7 -0
  83. package/dev-dist/types/hj-gis-sdk/addons/tools/daytime.d.ts.map +1 -0
  84. package/dev-dist/types/hj-gis-sdk/addons/tools/fence.d.ts +61 -0
  85. package/dev-dist/types/hj-gis-sdk/addons/tools/fence.d.ts.map +1 -0
  86. package/dev-dist/types/hj-gis-sdk/addons/tools/ghost.d.ts +14 -0
  87. package/dev-dist/types/hj-gis-sdk/addons/tools/ghost.d.ts.map +1 -0
  88. package/dev-dist/types/hj-gis-sdk/addons/tools/heat-map.d.ts +65 -0
  89. package/dev-dist/types/hj-gis-sdk/addons/tools/heat-map.d.ts.map +1 -0
  90. package/dev-dist/types/hj-gis-sdk/addons/tools/index.d.ts +26 -0
  91. package/dev-dist/types/hj-gis-sdk/addons/tools/index.d.ts.map +1 -0
  92. package/dev-dist/types/hj-gis-sdk/addons/tools/match-view.d.ts +7 -0
  93. package/dev-dist/types/hj-gis-sdk/addons/tools/match-view.d.ts.map +1 -0
  94. package/dev-dist/types/hj-gis-sdk/addons/tools/measurement.d.ts +13 -0
  95. package/dev-dist/types/hj-gis-sdk/addons/tools/measurement.d.ts.map +1 -0
  96. package/dev-dist/types/hj-gis-sdk/addons/tools/pick-cast.d.ts +26 -0
  97. package/dev-dist/types/hj-gis-sdk/addons/tools/pick-cast.d.ts.map +1 -0
  98. package/dev-dist/types/hj-gis-sdk/addons/tools/scatter.d.ts +57 -0
  99. package/dev-dist/types/hj-gis-sdk/addons/tools/scatter.d.ts.map +1 -0
  100. package/dev-dist/types/hj-gis-sdk/addons/tools/weather.d.ts +31 -0
  101. package/dev-dist/types/hj-gis-sdk/addons/tools/weather.d.ts.map +1 -0
  102. package/dev-dist/types/hj-gis-sdk/addons/transform.d.ts +91 -0
  103. package/dev-dist/types/hj-gis-sdk/addons/transform.d.ts.map +1 -0
  104. package/dev-dist/types/hj-gis-sdk/addons/world.d.ts +76 -0
  105. package/dev-dist/types/hj-gis-sdk/addons/world.d.ts.map +1 -0
  106. package/dev-dist/types/hj-gis-sdk/core/ue-rpc.d.ts +54 -0
  107. package/dev-dist/types/hj-gis-sdk/core/ue-rpc.d.ts.map +1 -0
  108. package/dev-dist/types/hj-gis-sdk/index.d.ts +27 -0
  109. package/dev-dist/types/hj-gis-sdk/index.d.ts.map +1 -0
  110. package/dev-dist/types/hj-gis-sdk/utils.d.ts +16 -0
  111. package/dev-dist/types/hj-gis-sdk/utils.d.ts.map +1 -0
  112. package/dev-dist/types/src/animation.d.ts +2 -0
  113. package/dev-dist/types/src/animation.d.ts.map +1 -0
  114. package/dev-dist/types/src/building.d.ts +2 -0
  115. package/dev-dist/types/src/building.d.ts.map +1 -0
  116. package/dev-dist/types/src/common.d.ts +5 -0
  117. package/dev-dist/types/src/common.d.ts.map +1 -0
  118. package/dev-dist/types/src/fence.d.ts +2 -0
  119. package/dev-dist/types/src/fence.d.ts.map +1 -0
  120. package/dev-dist/types/src/ghost.d.ts +2 -0
  121. package/dev-dist/types/src/ghost.d.ts.map +1 -0
  122. package/dev-dist/types/src/heatmap.d.ts +2 -0
  123. package/dev-dist/types/src/heatmap.d.ts.map +1 -0
  124. package/dev-dist/types/src/index.d.ts +2 -0
  125. package/dev-dist/types/src/index.d.ts.map +1 -0
  126. package/dev-dist/types/src/keyframe.d.ts +2 -0
  127. package/dev-dist/types/src/keyframe.d.ts.map +1 -0
  128. package/dev-dist/types/src/measurement.d.ts +2 -0
  129. package/dev-dist/types/src/measurement.d.ts.map +1 -0
  130. package/dev-dist/types/src/scatter.d.ts +2 -0
  131. package/dev-dist/types/src/scatter.d.ts.map +1 -0
  132. package/dev-dist/types/src/weather.d.ts +2 -0
  133. package/dev-dist/types/src/weather.d.ts.map +1 -0
  134. package/dev-dist/weather.esm.js +68 -0
  135. package/dev-dist/weather.esm.js.map +1 -0
  136. package/dev-dist/weather.js +70 -0
  137. package/dev-dist/weather.js.map +1 -0
  138. package/dist/sdk.esm.js +19 -6
  139. package/dist/sdk.esm.js.map +1 -1
  140. package/dist/sdk.js +19 -6
  141. package/dist/sdk.js.map +1 -1
  142. package/dist/sdk.umd.js +1 -1
  143. package/dist/sdk.umd.js.map +1 -1
  144. package/dist/types/hj-gis-sdk/addons/tools/scatter.d.ts.map +1 -1
  145. package/dist/types/src/common.d.ts.map +1 -1
  146. package/hj-gis-sdk/addons/animation/animate-clip.ts +93 -0
  147. package/hj-gis-sdk/addons/animation/animation-action.ts +93 -0
  148. package/hj-gis-sdk/addons/animation/animation-mixer.ts +51 -0
  149. package/hj-gis-sdk/addons/animation/index.ts +17 -0
  150. package/hj-gis-sdk/addons/camera.ts +173 -0
  151. package/hj-gis-sdk/addons/clock.ts +85 -0
  152. package/hj-gis-sdk/addons/commander/context.ts +70 -0
  153. package/hj-gis-sdk/addons/commander/dispatcher.ts +68 -0
  154. package/hj-gis-sdk/addons/commander/excutor/base.ts +26 -0
  155. package/hj-gis-sdk/addons/loader/index.ts +7 -0
  156. package/hj-gis-sdk/addons/loader/loader.ts +3 -0
  157. package/hj-gis-sdk/addons/node/base.ts +131 -0
  158. package/hj-gis-sdk/addons/node/ue-node.ts +147 -0
  159. package/hj-gis-sdk/addons/proxy.ts +200 -0
  160. package/hj-gis-sdk/addons/tools/base.ts +11 -0
  161. package/hj-gis-sdk/addons/tools/building.ts +84 -0
  162. package/hj-gis-sdk/addons/tools/daytime.ts +14 -0
  163. package/hj-gis-sdk/addons/tools/fence.ts +105 -0
  164. package/hj-gis-sdk/addons/tools/ghost.ts +31 -0
  165. package/hj-gis-sdk/addons/tools/heat-map.ts +95 -0
  166. package/hj-gis-sdk/addons/tools/index.ts +25 -0
  167. package/hj-gis-sdk/addons/tools/match-view.ts +35 -0
  168. package/hj-gis-sdk/addons/tools/measurement.ts +25 -0
  169. package/hj-gis-sdk/addons/tools/pick-cast.ts +67 -0
  170. package/hj-gis-sdk/addons/tools/scatter.ts +230 -0
  171. package/hj-gis-sdk/addons/tools/weather.ts +40 -0
  172. package/hj-gis-sdk/addons/transform.ts +126 -0
  173. package/hj-gis-sdk/addons/world.ts +173 -0
  174. package/hj-gis-sdk/core/ue-rpc.ts +234 -0
  175. package/hj-gis-sdk/index.ts +26 -0
  176. package/hj-gis-sdk/utils.ts +52 -0
  177. package/index.html +48 -0
  178. package/package-lock.json +7368 -0
  179. package/package.json +17 -4
  180. package/rollup.config.dev.js +107 -0
  181. package/rollup.config.js +52 -0
  182. package/src/animation.ts +175 -0
  183. package/src/building.ts +114 -0
  184. package/src/common.ts +47 -0
  185. package/src/fence.ts +131 -0
  186. package/src/ghost.ts +70 -0
  187. package/src/heatmap.ts +125 -0
  188. package/src/index.ts +350 -0
  189. package/src/keyframe.ts +113 -0
  190. package/src/measurement.ts +80 -0
  191. package/src/scatter.ts +105 -0
  192. package/src/weather.ts +86 -0
  193. package/tsconfig.json +30 -0
  194. package/yarn.lock +3108 -0
@@ -0,0 +1,4272 @@
1
+
2
+ (function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
3
+ // Copyright Epic Games, Inc. All Rights Reserved.
4
+ var LogLevel;
5
+ (function (LogLevel) {
6
+ LogLevel[LogLevel["Disabled"] = 0] = "Disabled";
7
+ LogLevel[LogLevel["Error"] = 1] = "Error";
8
+ LogLevel[LogLevel["Warning"] = 2] = "Warning";
9
+ LogLevel[LogLevel["Info"] = 3] = "Info";
10
+ LogLevel[LogLevel["Debug"] = 4] = "Debug";
11
+ })(LogLevel || (LogLevel = {}));
12
+ /**
13
+ * The global context for the logger configuration.
14
+ * This cannot be stored statically in the Logger class because we sometimes have multiple execution
15
+ * contexts, such as stats reporting. Instead we store the logger config context on the window object
16
+ * to be shared with any Logger instances.
17
+ */
18
+ class LoggerContext {
19
+ constructor() {
20
+ this.logLevel = LogLevel.Debug;
21
+ this.includeStack = true;
22
+ }
23
+ }
24
+ /**
25
+ * A basic console logger utilized by the Pixel Streaming frontend to allow
26
+ * logging to the browser console.
27
+ */
28
+ class LoggerType {
29
+ /**
30
+ * Set the log verbosity level
31
+ */
32
+ InitLogging(logLevel, includeStack) {
33
+ this.ValidateContext();
34
+ this.context.logLevel = logLevel;
35
+ this.context.includeStack = includeStack;
36
+ }
37
+ /**
38
+ * Logging output for debugging
39
+ * @param message - the message to be logged
40
+ */
41
+ Debug(message) {
42
+ this.ValidateContext();
43
+ if (this.context.logLevel >= LogLevel.Debug) {
44
+ this.CommonLog('Debug', message);
45
+ }
46
+ }
47
+ /**
48
+ * Basic logging output for standard messages
49
+ * @param message - the message to be logged
50
+ */
51
+ Info(message) {
52
+ this.ValidateContext();
53
+ if (this.context.logLevel >= LogLevel.Info) {
54
+ this.CommonLog('Info', message);
55
+ }
56
+ }
57
+ /**
58
+ * Logging for warnings
59
+ * @param message - the message to be logged
60
+ */
61
+ Warning(message) {
62
+ this.ValidateContext();
63
+ if (this.context.logLevel >= LogLevel.Warning) {
64
+ this.CommonLog('Warning', message);
65
+ }
66
+ }
67
+ /**
68
+ * Error logging
69
+ * @param message - the message to be logged
70
+ */
71
+ Error(message) {
72
+ this.ValidateContext();
73
+ if (this.context.logLevel >= LogLevel.Error) {
74
+ this.CommonLog('Error', message);
75
+ }
76
+ }
77
+ /**
78
+ * The common log function that all other log functions call to.
79
+ * @param level - the level of this log message.
80
+ * @param stack - an optional stack trace string from where the log message was called.
81
+ * @param message - the message to be logged.
82
+ */
83
+ CommonLog(level, message) {
84
+ let logMessage = `[${level}] - ${message}`;
85
+ if (this.context.includeStack) {
86
+ logMessage += `\nStack: ${this.GetStackTrace()}`;
87
+ }
88
+ if (level === 'Error') {
89
+ console.error(logMessage);
90
+ }
91
+ else if (level === 'Warning') {
92
+ console.warn(logMessage);
93
+ }
94
+ else {
95
+ console.log(logMessage);
96
+ }
97
+ }
98
+ /**
99
+ * Captures the stack and returns it
100
+ * @returns the current stack
101
+ */
102
+ GetStackTrace() {
103
+ const error = new Error();
104
+ let formattedStack = 'No Stack Available for this browser';
105
+ // format the error
106
+ if (error.stack) {
107
+ formattedStack = error.stack.toString().replace(/Error/g, '');
108
+ }
109
+ return formattedStack;
110
+ }
111
+ /**
112
+ * Since there can be multiple execution contexts, (stats reporting and some webxr logging comes from
113
+ * different execution contexts we can end up with multiple static Logger instances. Here we try to
114
+ * work around it by storing the context on the window object.
115
+ */
116
+ ValidateContext() {
117
+ if (!this.context) {
118
+ if (typeof window == 'undefined' || !window) {
119
+ // no window object so we can only store a local context.
120
+ this.context = new LoggerContext();
121
+ }
122
+ else if (!window.loggerContext) {
123
+ this.context = new LoggerContext();
124
+ window.loggerContext = this.context;
125
+ }
126
+ else {
127
+ this.context = window.loggerContext;
128
+ }
129
+ }
130
+ }
131
+ }
132
+ let Logger = new LoggerType();
133
+
134
+ /**
135
+ * UERPC wraps RPC-style interactions over Pixel Streaming's DataChannel.
136
+ * It mirrors the Web/script.js behavior: sends {Type:'RPC_CALL', Command, ReqId, ...payload}
137
+ * and expects UE to reply with {Type:'RPC_RESPONSE', ReqId, Status, Data|Message} via EmitJSEvent.
138
+ */
139
+ class UERPC {
140
+ constructor(stream, responseEventName = 'handle_responses') {
141
+ this.stream = stream;
142
+ this.responseEventName = responseEventName;
143
+ this.pendingRequests = new Map();
144
+ this.timeoutMs = 30000;
145
+ try {
146
+ this.stream.addResponseEventListener(this.responseEventName, this.handleResponse.bind(this));
147
+ }
148
+ catch (e) {
149
+ // If the stream is not ready yet, user can call bind later.
150
+ }
151
+ }
152
+ getStream() {
153
+ return this.stream;
154
+ }
155
+ /**
156
+ * Bind the response listener explicitly if constructor binding failed or the stream changed.
157
+ */
158
+ bind(stream, responseEventName = this.responseEventName) {
159
+ this.stream = stream;
160
+ this.responseEventName = responseEventName;
161
+ this.stream.addResponseEventListener(this.responseEventName, this.handleResponse.bind(this));
162
+ }
163
+ emitCommand(playload) {
164
+ this.stream.emitCommand(playload);
165
+ }
166
+ /**
167
+ * Generic RPC call. Resolves when UE replies with matching ReqId.
168
+ */
169
+ call(command, payload = {}, timeoutMs) {
170
+ const reqId = this.generateUUID();
171
+ const message = {
172
+ Type: 'RPC_CALL',
173
+ Command: command,
174
+ ReqId: reqId,
175
+ ...payload
176
+ };
177
+ return new Promise((resolve, reject) => {
178
+ const timer = window.setTimeout(() => {
179
+ if (this.pendingRequests.has(reqId)) {
180
+ this.pendingRequests.delete(reqId);
181
+ reject(new Error(`UE RPC Timeout: ${command}`));
182
+ }
183
+ }, timeoutMs || this.timeoutMs);
184
+ this.pendingRequests.set(reqId, { resolve, reject, timer });
185
+ try {
186
+ this.stream.emitUIInteraction(message);
187
+ }
188
+ catch (e) {
189
+ window.clearTimeout(timer);
190
+ this.pendingRequests.delete(reqId);
191
+ reject(e);
192
+ }
193
+ });
194
+ }
195
+ /**
196
+ * Handle UE responses. Accepts stringified or object payloads.
197
+ */
198
+ handleResponse(raw) {
199
+ let json = raw;
200
+ try {
201
+ if (typeof raw === 'string') {
202
+ json = JSON.parse(raw);
203
+ }
204
+ }
205
+ catch {
206
+ return;
207
+ }
208
+ if (!json || json.Type !== 'RPC_RESPONSE')
209
+ return;
210
+ const reqId = json.ReqId;
211
+ if (!reqId)
212
+ return;
213
+ const pending = this.pendingRequests.get(reqId);
214
+ if (!pending)
215
+ return;
216
+ window.clearTimeout(pending.timer);
217
+ this.pendingRequests.delete(reqId);
218
+ const status = json.Status;
219
+ if (status === 'success') {
220
+ pending.resolve(json.Data);
221
+ }
222
+ else {
223
+ const msg = json.Message || 'Unknown UE Error';
224
+ pending.reject(new Error(msg));
225
+ }
226
+ }
227
+ callModule(moduleName, actionName, params = {}, timeoutMs = 30000) {
228
+ const reqId = this.generateUUID();
229
+ const message = {
230
+ Type: 'RPC_CALL',
231
+ ReqId: reqId,
232
+ ModuleName: moduleName,
233
+ ActionName: actionName,
234
+ Params: params
235
+ };
236
+ Logger.Info(JSON.stringify(message));
237
+ return new Promise((resolve, reject) => {
238
+ const timer = window.setTimeout(() => {
239
+ if (this.pendingRequests.has(reqId)) {
240
+ this.pendingRequests.delete(reqId);
241
+ reject(new Error(`UE Call Timeout: ${moduleName}/${actionName}`));
242
+ }
243
+ }, timeoutMs || this.timeoutMs);
244
+ this.pendingRequests.set(reqId, { resolve, reject, timer });
245
+ try {
246
+ this.stream.emitUIInteraction(message);
247
+ }
248
+ catch (e) {
249
+ window.clearTimeout(timer);
250
+ this.pendingRequests.delete(reqId);
251
+ reject(e);
252
+ }
253
+ });
254
+ }
255
+ // ---- Convenience helpers for Web-supported commands ----
256
+ // Level management
257
+ loadLevelByName(levelName) {
258
+ return this.call('LoadLevelByName', { LevelName: levelName });
259
+ }
260
+ unLoadMap(levelName) {
261
+ return this.call('UnLoadMap', { LevelName: levelName });
262
+ }
263
+ // Actor management
264
+ spawnStaticMeshActor(params) {
265
+ return this.call('SpawnStaticMeshActor', params);
266
+ }
267
+ // Blueprint management
268
+ spawnLocalBlueprintActor(params) {
269
+ return this.call('SpawnLocalBlueprintActor', params);
270
+ }
271
+ setActorTransformByHandle(handle, transform) {
272
+ return this.call('SetActorTransformByHandle', {
273
+ Handle: handle,
274
+ Transform: transform
275
+ });
276
+ }
277
+ destroyActorByHandle(handle) {
278
+ return this.call('DestroyActorByHandle', { Handle: handle });
279
+ }
280
+ // Picking
281
+ pickPointByScreen(x, y, maxDistance = 10000000, highlight = false) {
282
+ return this.call('PickPointByScreen', {
283
+ Screen: {
284
+ X: x,
285
+ Y: y
286
+ },
287
+ MaxDistance: maxDistance,
288
+ Highlight: highlight
289
+ });
290
+ }
291
+ // Camera lens and transform
292
+ getCameraTransform() {
293
+ return this.call('GetCameraTransform', {});
294
+ }
295
+ setCameraTransform(transform) {
296
+ return this.call('SetCameraTransform', { Transform: transform });
297
+ }
298
+ setCameraResetTransform(transform) {
299
+ return this.call('SetCameraResetTransform', { Transform: transform });
300
+ }
301
+ resetCameraToSavedTransform() {
302
+ return this.call('ResetCameraToSavedTransform', {});
303
+ }
304
+ generateUUID() {
305
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
306
+ const r = (Math.random() * 16) | 0;
307
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
308
+ return v.toString(16);
309
+ });
310
+ }
311
+ }
312
+
313
+ // math.gl
314
+ const DEFAULT_CONFIG = {
315
+ EPSILON: 1e-12,
316
+ debug: false,
317
+ precision: 4,
318
+ printTypes: false,
319
+ printDegrees: false,
320
+ printRowMajor: true,
321
+ _cartographicRadians: false
322
+ };
323
+ // Configuration is truly global as of v3.6 to ensure single config even if multiple copies of math.gl
324
+ // Multiple copies of config can be quite tricky to debug...
325
+ globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
326
+ const config = globalThis.mathgl.config;
327
+ /**
328
+ * Formats a value into a string
329
+ * @param value
330
+ * @param param1
331
+ * @returns
332
+ */
333
+ function formatValue(value, { precision = config.precision } = {}) {
334
+ value = round(value);
335
+ // get rid of trailing zeros
336
+ return `${parseFloat(value.toPrecision(precision))}`;
337
+ }
338
+ /**
339
+ * Check if value is an "array"
340
+ * Returns `true` if value is either an array or a typed array
341
+ * Note: returns `false` for `ArrayBuffer` and `DataView` instances
342
+ * @note isTypedArray and isNumericArray are often more useful in TypeScript
343
+ */
344
+ function isArray(value) {
345
+ return Array.isArray(value) || (ArrayBuffer.isView(value) && !(value instanceof DataView));
346
+ }
347
+ function clamp(value, min, max) {
348
+ return map(value, (value) => Math.max(min, Math.min(max, value)));
349
+ }
350
+ /* eslint-disable */
351
+ /**
352
+ * Compares any two math objects, using `equals` method if available.
353
+ * @param a
354
+ * @param b
355
+ * @param epsilon
356
+ * @returns
357
+ */
358
+ function equals(a, b, epsilon) {
359
+ const oldEpsilon = config.EPSILON;
360
+ if (epsilon) {
361
+ config.EPSILON = epsilon;
362
+ }
363
+ try {
364
+ if (a === b) {
365
+ return true;
366
+ }
367
+ if (isArray(a) && isArray(b)) {
368
+ if (a.length !== b.length) {
369
+ return false;
370
+ }
371
+ for (let i = 0; i < a.length; ++i) {
372
+ // eslint-disable-next-line max-depth
373
+ if (!equals(a[i], b[i])) {
374
+ return false;
375
+ }
376
+ }
377
+ return true;
378
+ }
379
+ if (a && a.equals) {
380
+ return a.equals(b);
381
+ }
382
+ if (b && b.equals) {
383
+ return b.equals(a);
384
+ }
385
+ if (typeof a === 'number' && typeof b === 'number') {
386
+ return Math.abs(a - b) <= config.EPSILON * Math.max(1, Math.abs(a), Math.abs(b));
387
+ }
388
+ return false;
389
+ }
390
+ finally {
391
+ config.EPSILON = oldEpsilon;
392
+ }
393
+ }
394
+ // HELPERS
395
+ function round(value) {
396
+ return Math.round(value / config.EPSILON) * config.EPSILON;
397
+ }
398
+ // If the array has a clone function, calls it, otherwise returns a copy
399
+ function duplicateArray(array) {
400
+ // @ts-expect-error We check for math.gl class methods
401
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
402
+ return array.clone ? array.clone() : new Array(array.length);
403
+ }
404
+ // If the argument value is an array, applies the func element wise,
405
+ // otherwise applies func to the argument value
406
+ function map(value, func, result) {
407
+ if (isArray(value)) {
408
+ const array = value;
409
+ result = result || duplicateArray(array);
410
+ for (let i = 0; i < result.length && i < array.length; ++i) {
411
+ const val = typeof value === 'number' ? value : value[i];
412
+ result[i] = func(val, i, result);
413
+ }
414
+ return result;
415
+ }
416
+ return func(value);
417
+ }
418
+
419
+ // math.gl
420
+ /** Base class for vectors and matrices */
421
+ class MathArray extends Array {
422
+ // Common methods
423
+ /**
424
+ * Clone the current object
425
+ * @returns a new copy of this object
426
+ */
427
+ clone() {
428
+ // @ts-expect-error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
429
+ return new this.constructor().copy(this); // eslint-disable-line
430
+ }
431
+ fromArray(array, offset = 0) {
432
+ for (let i = 0; i < this.ELEMENTS; ++i) {
433
+ this[i] = array[i + offset];
434
+ }
435
+ return this.check();
436
+ }
437
+ toArray(targetArray = [], offset = 0) {
438
+ for (let i = 0; i < this.ELEMENTS; ++i) {
439
+ targetArray[offset + i] = this[i];
440
+ }
441
+ return targetArray;
442
+ }
443
+ toObject(targetObject) {
444
+ return targetObject;
445
+ }
446
+ from(arrayOrObject) {
447
+ return Array.isArray(arrayOrObject)
448
+ ? this.copy(arrayOrObject)
449
+ : // @ts-ignore
450
+ this.fromObject(arrayOrObject);
451
+ }
452
+ to(arrayOrObject) {
453
+ // @ts-ignore
454
+ if (arrayOrObject === this) {
455
+ return this;
456
+ }
457
+ // @ts-expect-error TS2339: Property 'toObject' does not exist on type 'MathArray'.
458
+ return isArray(arrayOrObject) ? this.toArray(arrayOrObject) : this.toObject(arrayOrObject);
459
+ }
460
+ toTarget(target) {
461
+ return target ? this.to(target) : this;
462
+ }
463
+ /** @deprecated */
464
+ toFloat32Array() {
465
+ return new Float32Array(this);
466
+ }
467
+ toString() {
468
+ return this.formatString(config);
469
+ }
470
+ /** Formats string according to options */
471
+ formatString(opts) {
472
+ let string = '';
473
+ for (let i = 0; i < this.ELEMENTS; ++i) {
474
+ string += (i > 0 ? ', ' : '') + formatValue(this[i], opts);
475
+ }
476
+ return `${opts.printTypes ? this.constructor.name : ''}[${string}]`;
477
+ }
478
+ equals(array) {
479
+ if (!array || this.length !== array.length) {
480
+ return false;
481
+ }
482
+ for (let i = 0; i < this.ELEMENTS; ++i) {
483
+ if (!equals(this[i], array[i])) {
484
+ return false;
485
+ }
486
+ }
487
+ return true;
488
+ }
489
+ exactEquals(array) {
490
+ if (!array || this.length !== array.length) {
491
+ return false;
492
+ }
493
+ for (let i = 0; i < this.ELEMENTS; ++i) {
494
+ if (this[i] !== array[i]) {
495
+ return false;
496
+ }
497
+ }
498
+ return true;
499
+ }
500
+ // Modifiers
501
+ /** Negates all values in this object */
502
+ negate() {
503
+ for (let i = 0; i < this.ELEMENTS; ++i) {
504
+ this[i] = -this[i];
505
+ }
506
+ return this.check();
507
+ }
508
+ lerp(a, b, t) {
509
+ if (t === undefined) {
510
+ return this.lerp(this, a, b);
511
+ }
512
+ for (let i = 0; i < this.ELEMENTS; ++i) {
513
+ const ai = a[i];
514
+ const endValue = typeof b === 'number' ? b : b[i];
515
+ this[i] = ai + t * (endValue - ai);
516
+ }
517
+ return this.check();
518
+ }
519
+ /** Minimal */
520
+ min(vector) {
521
+ for (let i = 0; i < this.ELEMENTS; ++i) {
522
+ this[i] = Math.min(vector[i], this[i]);
523
+ }
524
+ return this.check();
525
+ }
526
+ /** Maximal */
527
+ max(vector) {
528
+ for (let i = 0; i < this.ELEMENTS; ++i) {
529
+ this[i] = Math.max(vector[i], this[i]);
530
+ }
531
+ return this.check();
532
+ }
533
+ clamp(minVector, maxVector) {
534
+ for (let i = 0; i < this.ELEMENTS; ++i) {
535
+ this[i] = Math.min(Math.max(this[i], minVector[i]), maxVector[i]);
536
+ }
537
+ return this.check();
538
+ }
539
+ add(...vectors) {
540
+ for (const vector of vectors) {
541
+ for (let i = 0; i < this.ELEMENTS; ++i) {
542
+ this[i] += vector[i];
543
+ }
544
+ }
545
+ return this.check();
546
+ }
547
+ subtract(...vectors) {
548
+ for (const vector of vectors) {
549
+ for (let i = 0; i < this.ELEMENTS; ++i) {
550
+ this[i] -= vector[i];
551
+ }
552
+ }
553
+ return this.check();
554
+ }
555
+ scale(scale) {
556
+ if (typeof scale === 'number') {
557
+ for (let i = 0; i < this.ELEMENTS; ++i) {
558
+ this[i] *= scale;
559
+ }
560
+ }
561
+ else {
562
+ for (let i = 0; i < this.ELEMENTS && i < scale.length; ++i) {
563
+ this[i] *= scale[i];
564
+ }
565
+ }
566
+ return this.check();
567
+ }
568
+ /**
569
+ * Multiplies all elements by `scale`
570
+ * Note: `Matrix4.multiplyByScalar` only scales its 3x3 "minor"
571
+ */
572
+ multiplyByScalar(scalar) {
573
+ for (let i = 0; i < this.ELEMENTS; ++i) {
574
+ this[i] *= scalar;
575
+ }
576
+ return this.check();
577
+ }
578
+ // Debug checks
579
+ /** Throws an error if array length is incorrect or contains illegal values */
580
+ check() {
581
+ if (config.debug && !this.validate()) {
582
+ throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);
583
+ }
584
+ return this;
585
+ }
586
+ /** Returns false if the array length is incorrect or contains illegal values */
587
+ validate() {
588
+ let valid = this.length === this.ELEMENTS;
589
+ for (let i = 0; i < this.ELEMENTS; ++i) {
590
+ valid = valid && Number.isFinite(this[i]);
591
+ }
592
+ return valid;
593
+ }
594
+ // three.js compatibility
595
+ /** @deprecated */
596
+ sub(a) {
597
+ return this.subtract(a);
598
+ }
599
+ /** @deprecated */
600
+ setScalar(a) {
601
+ for (let i = 0; i < this.ELEMENTS; ++i) {
602
+ this[i] = a;
603
+ }
604
+ return this.check();
605
+ }
606
+ /** @deprecated */
607
+ addScalar(a) {
608
+ for (let i = 0; i < this.ELEMENTS; ++i) {
609
+ this[i] += a;
610
+ }
611
+ return this.check();
612
+ }
613
+ /** @deprecated */
614
+ subScalar(a) {
615
+ return this.addScalar(-a);
616
+ }
617
+ /** @deprecated */
618
+ multiplyScalar(scalar) {
619
+ // Multiplies all elements
620
+ // `Matrix4.scale` only scales its 3x3 "minor"
621
+ for (let i = 0; i < this.ELEMENTS; ++i) {
622
+ this[i] *= scalar;
623
+ }
624
+ return this.check();
625
+ }
626
+ /** @deprecated */
627
+ divideScalar(a) {
628
+ return this.multiplyByScalar(1 / a);
629
+ }
630
+ /** @deprecated */
631
+ clampScalar(min, max) {
632
+ for (let i = 0; i < this.ELEMENTS; ++i) {
633
+ this[i] = Math.min(Math.max(this[i], min), max);
634
+ }
635
+ return this.check();
636
+ }
637
+ /** @deprecated */
638
+ get elements() {
639
+ return this;
640
+ }
641
+ }
642
+
643
+ // math.gl
644
+ function validateVector(v, length) {
645
+ if (v.length !== length) {
646
+ return false;
647
+ }
648
+ // Could be arguments "array" (v.every not availasble)
649
+ for (let i = 0; i < v.length; ++i) {
650
+ if (!Number.isFinite(v[i])) {
651
+ return false;
652
+ }
653
+ }
654
+ return true;
655
+ }
656
+ function checkNumber(value) {
657
+ if (!Number.isFinite(value)) {
658
+ throw new Error(`Invalid number ${JSON.stringify(value)}`);
659
+ }
660
+ return value;
661
+ }
662
+ function checkVector(v, length, callerName = '') {
663
+ if (config.debug && !validateVector(v, length)) {
664
+ throw new Error(`math.gl: ${callerName} some fields set to invalid numbers'`);
665
+ }
666
+ return v;
667
+ }
668
+
669
+ // math.gl
670
+ // SPDX-License-Identifier: MIT
671
+ // Copyright (c) vis.gl contributors
672
+ function assert(condition, message) {
673
+ if (!condition) {
674
+ throw new Error(`math.gl assertion ${message}`);
675
+ }
676
+ }
677
+
678
+ // math.gl
679
+ /** Base class for vectors with at least 2 elements */
680
+ class Vector extends MathArray {
681
+ // ACCESSORS
682
+ get x() {
683
+ return this[0];
684
+ }
685
+ set x(value) {
686
+ this[0] = checkNumber(value);
687
+ }
688
+ get y() {
689
+ return this[1];
690
+ }
691
+ set y(value) {
692
+ this[1] = checkNumber(value);
693
+ }
694
+ /**
695
+ * Returns the length of the vector from the origin to the point described by this vector
696
+ *
697
+ * @note `length` is a reserved word for Arrays, so `v.length()` will return number of elements
698
+ * Instead we provide `len` and `magnitude`
699
+ */
700
+ len() {
701
+ return Math.sqrt(this.lengthSquared());
702
+ }
703
+ /**
704
+ * Returns the length of the vector from the origin to the point described by this vector
705
+ */
706
+ magnitude() {
707
+ return this.len();
708
+ }
709
+ /**
710
+ * Returns the squared length of the vector from the origin to the point described by this vector
711
+ */
712
+ lengthSquared() {
713
+ let length = 0;
714
+ for (let i = 0; i < this.ELEMENTS; ++i) {
715
+ length += this[i] * this[i];
716
+ }
717
+ return length;
718
+ }
719
+ /**
720
+ * Returns the squared length of the vector from the origin to the point described by this vector
721
+ */
722
+ magnitudeSquared() {
723
+ return this.lengthSquared();
724
+ }
725
+ distance(mathArray) {
726
+ return Math.sqrt(this.distanceSquared(mathArray));
727
+ }
728
+ distanceSquared(mathArray) {
729
+ let length = 0;
730
+ for (let i = 0; i < this.ELEMENTS; ++i) {
731
+ const dist = this[i] - mathArray[i];
732
+ length += dist * dist;
733
+ }
734
+ return checkNumber(length);
735
+ }
736
+ dot(mathArray) {
737
+ let product = 0;
738
+ for (let i = 0; i < this.ELEMENTS; ++i) {
739
+ product += this[i] * mathArray[i];
740
+ }
741
+ return checkNumber(product);
742
+ }
743
+ // MODIFIERS
744
+ normalize() {
745
+ const length = this.magnitude();
746
+ if (length !== 0) {
747
+ for (let i = 0; i < this.ELEMENTS; ++i) {
748
+ this[i] /= length;
749
+ }
750
+ }
751
+ return this.check();
752
+ }
753
+ multiply(...vectors) {
754
+ for (const vector of vectors) {
755
+ for (let i = 0; i < this.ELEMENTS; ++i) {
756
+ this[i] *= vector[i];
757
+ }
758
+ }
759
+ return this.check();
760
+ }
761
+ divide(...vectors) {
762
+ for (const vector of vectors) {
763
+ for (let i = 0; i < this.ELEMENTS; ++i) {
764
+ this[i] /= vector[i];
765
+ }
766
+ }
767
+ return this.check();
768
+ }
769
+ // THREE.js compatibility
770
+ lengthSq() {
771
+ return this.lengthSquared();
772
+ }
773
+ distanceTo(vector) {
774
+ return this.distance(vector);
775
+ }
776
+ distanceToSquared(vector) {
777
+ return this.distanceSquared(vector);
778
+ }
779
+ getComponent(i) {
780
+ assert(i >= 0 && i < this.ELEMENTS, 'index is out of range');
781
+ return checkNumber(this[i]);
782
+ }
783
+ setComponent(i, value) {
784
+ assert(i >= 0 && i < this.ELEMENTS, 'index is out of range');
785
+ this[i] = value;
786
+ return this.check();
787
+ }
788
+ addVectors(a, b) {
789
+ return this.copy(a).add(b);
790
+ }
791
+ subVectors(a, b) {
792
+ return this.copy(a).subtract(b);
793
+ }
794
+ multiplyVectors(a, b) {
795
+ return this.copy(a).multiply(b);
796
+ }
797
+ addScaledVector(a, b) {
798
+ // @ts-expect-error error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
799
+ return this.add(new this.constructor(a).multiplyScalar(b));
800
+ }
801
+ }
802
+
803
+ // @eslint-disable
804
+ // @ts-nocheck
805
+ /**
806
+ * Common utilities
807
+ * @module glMatrix
808
+ */
809
+ // Configuration Constants
810
+ const EPSILON = 0.000001;
811
+ let ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
812
+
813
+ // math.gl
814
+ // vec3 additions
815
+ // Transform as vector, only uses 3x3 minor matrix
816
+ function vec3_transformMat4AsVector(out, a, m) {
817
+ const x = a[0];
818
+ const y = a[1];
819
+ const z = a[2];
820
+ const w = m[3] * x + m[7] * y + m[11] * z || 1.0;
821
+ out[0] = (m[0] * x + m[4] * y + m[8] * z) / w;
822
+ out[1] = (m[1] * x + m[5] * y + m[9] * z) / w;
823
+ out[2] = (m[2] * x + m[6] * y + m[10] * z) / w;
824
+ return out;
825
+ }
826
+ function vec3_transformMat2(out, a, m) {
827
+ const x = a[0];
828
+ const y = a[1];
829
+ out[0] = m[0] * x + m[2] * y;
830
+ out[1] = m[1] * x + m[3] * y;
831
+ out[2] = a[2];
832
+ return out;
833
+ }
834
+ // vec4 additions
835
+ function vec4_transformMat2(out, a, m) {
836
+ const x = a[0];
837
+ const y = a[1];
838
+ out[0] = m[0] * x + m[2] * y;
839
+ out[1] = m[1] * x + m[3] * y;
840
+ out[2] = a[2];
841
+ out[3] = a[3];
842
+ return out;
843
+ }
844
+ function vec4_transformMat3(out, a, m) {
845
+ const x = a[0];
846
+ const y = a[1];
847
+ const z = a[2];
848
+ out[0] = m[0] * x + m[3] * y + m[6] * z;
849
+ out[1] = m[1] * x + m[4] * y + m[7] * z;
850
+ out[2] = m[2] * x + m[5] * y + m[8] * z;
851
+ out[3] = a[3];
852
+ return out;
853
+ }
854
+
855
+ // @eslint-disable
856
+ /**
857
+ * 3 Dimensional Vector
858
+ * @module vec3
859
+ */
860
+ /**
861
+ * Creates a new, empty vec3
862
+ *
863
+ * @returns {vec3} a new 3D vector
864
+ */
865
+ function create$3() {
866
+ const out = new ARRAY_TYPE(3);
867
+ if (ARRAY_TYPE != Float32Array) {
868
+ out[0] = 0;
869
+ out[1] = 0;
870
+ out[2] = 0;
871
+ }
872
+ return out;
873
+ }
874
+ /**
875
+ * Calculates the length of a vec3
876
+ *
877
+ * @param {ReadonlyVec3} a vector to calculate length of
878
+ * @returns {Number} length of a
879
+ */
880
+ function length$2(a) {
881
+ const x = a[0];
882
+ const y = a[1];
883
+ const z = a[2];
884
+ return Math.sqrt(x * x + y * y + z * z);
885
+ }
886
+ /**
887
+ * Creates a new vec3 initialized with the given values
888
+ *
889
+ * @param {Number} x X component
890
+ * @param {Number} y Y component
891
+ * @param {Number} z Z component
892
+ * @returns {vec3} a new 3D vector
893
+ */
894
+ function fromValues(x, y, z) {
895
+ const out = new ARRAY_TYPE(3);
896
+ out[0] = x;
897
+ out[1] = y;
898
+ out[2] = z;
899
+ return out;
900
+ }
901
+ /**
902
+ * Normalize a vec3
903
+ *
904
+ * @param {vec3} out the receiving vector
905
+ * @param {ReadonlyVec3} a vector to normalize
906
+ * @returns {vec3} out
907
+ */
908
+ function normalize$2(out, a) {
909
+ const x = a[0];
910
+ const y = a[1];
911
+ const z = a[2];
912
+ let len = x * x + y * y + z * z;
913
+ if (len > 0) {
914
+ // TODO: evaluate use of glm_invsqrt here?
915
+ len = 1 / Math.sqrt(len);
916
+ }
917
+ out[0] = a[0] * len;
918
+ out[1] = a[1] * len;
919
+ out[2] = a[2] * len;
920
+ return out;
921
+ }
922
+ /**
923
+ * Calculates the dot product of two vec3's
924
+ *
925
+ * @param {ReadonlyVec3} a the first operand
926
+ * @param {ReadonlyVec3} b the second operand
927
+ * @returns {Number} dot product of a and b
928
+ */
929
+ function dot$2(a, b) {
930
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
931
+ }
932
+ /**
933
+ * Computes the cross product of two vec3's
934
+ *
935
+ * @param {vec3} out the receiving vector
936
+ * @param {ReadonlyVec3} a the first operand
937
+ * @param {ReadonlyVec3} b the second operand
938
+ * @returns {vec3} out
939
+ */
940
+ function cross(out, a, b) {
941
+ const ax = a[0];
942
+ const ay = a[1];
943
+ const az = a[2];
944
+ const bx = b[0];
945
+ const by = b[1];
946
+ const bz = b[2];
947
+ out[0] = ay * bz - az * by;
948
+ out[1] = az * bx - ax * bz;
949
+ out[2] = ax * by - ay * bx;
950
+ return out;
951
+ }
952
+ /**
953
+ * Transforms the vec3 with a mat4.
954
+ * 4th vector component is implicitly '1'
955
+ *
956
+ * @param {vec3} out the receiving vector
957
+ * @param {ReadonlyVec3} a the vector to transform
958
+ * @param {ReadonlyMat4} m matrix to transform with
959
+ * @returns {vec3} out
960
+ */
961
+ function transformMat4(out, a, m) {
962
+ const x = a[0];
963
+ const y = a[1];
964
+ const z = a[2];
965
+ let w = m[3] * x + m[7] * y + m[11] * z + m[15];
966
+ w = w || 1.0;
967
+ out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
968
+ out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
969
+ out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
970
+ return out;
971
+ }
972
+ /**
973
+ * Transforms the vec3 with a mat3.
974
+ *
975
+ * @param {vec3} out the receiving vector
976
+ * @param {ReadonlyVec3} a the vector to transform
977
+ * @param {ReadonlyMat3} m the 3x3 matrix to transform with
978
+ * @returns {vec3} out
979
+ */
980
+ function transformMat3(out, a, m) {
981
+ const x = a[0];
982
+ const y = a[1];
983
+ const z = a[2];
984
+ out[0] = x * m[0] + y * m[3] + z * m[6];
985
+ out[1] = x * m[1] + y * m[4] + z * m[7];
986
+ out[2] = x * m[2] + y * m[5] + z * m[8];
987
+ return out;
988
+ }
989
+ /**
990
+ * Transforms the vec3 with a quat
991
+ * Can also be used for dual quaternions. (Multiply it with the real part)
992
+ *
993
+ * @param {vec3} out the receiving vector
994
+ * @param {ReadonlyVec3} a the vector to transform
995
+ * @param {ReadonlyQuat} q quaternion to transform with
996
+ * @returns {vec3} out
997
+ */
998
+ function transformQuat$1(out, a, q) {
999
+ // benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed
1000
+ const qx = q[0];
1001
+ const qy = q[1];
1002
+ const qz = q[2];
1003
+ const qw = q[3];
1004
+ const x = a[0];
1005
+ const y = a[1];
1006
+ const z = a[2];
1007
+ // var qvec = [qx, qy, qz];
1008
+ // var uv = vec3.cross([], qvec, a);
1009
+ let uvx = qy * z - qz * y;
1010
+ let uvy = qz * x - qx * z;
1011
+ let uvz = qx * y - qy * x;
1012
+ // var uuv = vec3.cross([], qvec, uv);
1013
+ let uuvx = qy * uvz - qz * uvy;
1014
+ let uuvy = qz * uvx - qx * uvz;
1015
+ let uuvz = qx * uvy - qy * uvx;
1016
+ // vec3.scale(uv, uv, 2 * w);
1017
+ const w2 = qw * 2;
1018
+ uvx *= w2;
1019
+ uvy *= w2;
1020
+ uvz *= w2;
1021
+ // vec3.scale(uuv, uuv, 2);
1022
+ uuvx *= 2;
1023
+ uuvy *= 2;
1024
+ uuvz *= 2;
1025
+ // return vec3.add(out, a, vec3.add(out, uv, uuv));
1026
+ out[0] = x + uvx + uuvx;
1027
+ out[1] = y + uvy + uuvy;
1028
+ out[2] = z + uvz + uuvz;
1029
+ return out;
1030
+ }
1031
+ /**
1032
+ * Rotate a 3D vector around the x-axis
1033
+ * @param {vec3} out The receiving vec3
1034
+ * @param {ReadonlyVec3} a The vec3 point to rotate
1035
+ * @param {ReadonlyVec3} b The origin of the rotation
1036
+ * @param {Number} rad The angle of rotation in radians
1037
+ * @returns {vec3} out
1038
+ */
1039
+ function rotateX$1(out, a, b, rad) {
1040
+ const p = [];
1041
+ const r = [];
1042
+ // Translate point to the origin
1043
+ p[0] = a[0] - b[0];
1044
+ p[1] = a[1] - b[1];
1045
+ p[2] = a[2] - b[2];
1046
+ // perform rotation
1047
+ r[0] = p[0];
1048
+ r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad);
1049
+ r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad);
1050
+ // translate to correct position
1051
+ out[0] = r[0] + b[0];
1052
+ out[1] = r[1] + b[1];
1053
+ out[2] = r[2] + b[2];
1054
+ return out;
1055
+ }
1056
+ /**
1057
+ * Rotate a 3D vector around the y-axis
1058
+ * @param {vec3} out The receiving vec3
1059
+ * @param {ReadonlyVec3} a The vec3 point to rotate
1060
+ * @param {ReadonlyVec3} b The origin of the rotation
1061
+ * @param {Number} rad The angle of rotation in radians
1062
+ * @returns {vec3} out
1063
+ */
1064
+ function rotateY$1(out, a, b, rad) {
1065
+ const p = [];
1066
+ const r = [];
1067
+ // Translate point to the origin
1068
+ p[0] = a[0] - b[0];
1069
+ p[1] = a[1] - b[1];
1070
+ p[2] = a[2] - b[2];
1071
+ // perform rotation
1072
+ r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad);
1073
+ r[1] = p[1];
1074
+ r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad);
1075
+ // translate to correct position
1076
+ out[0] = r[0] + b[0];
1077
+ out[1] = r[1] + b[1];
1078
+ out[2] = r[2] + b[2];
1079
+ return out;
1080
+ }
1081
+ /**
1082
+ * Rotate a 3D vector around the z-axis
1083
+ * @param {vec3} out The receiving vec3
1084
+ * @param {ReadonlyVec3} a The vec3 point to rotate
1085
+ * @param {ReadonlyVec3} b The origin of the rotation
1086
+ * @param {Number} rad The angle of rotation in radians
1087
+ * @returns {vec3} out
1088
+ */
1089
+ function rotateZ$1(out, a, b, rad) {
1090
+ const p = [];
1091
+ const r = [];
1092
+ // Translate point to the origin
1093
+ p[0] = a[0] - b[0];
1094
+ p[1] = a[1] - b[1];
1095
+ p[2] = a[2] - b[2];
1096
+ // perform rotation
1097
+ r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad);
1098
+ r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad);
1099
+ r[2] = p[2];
1100
+ // translate to correct position
1101
+ out[0] = r[0] + b[0];
1102
+ out[1] = r[1] + b[1];
1103
+ out[2] = r[2] + b[2];
1104
+ return out;
1105
+ }
1106
+ /**
1107
+ * Get the angle between two 3D vectors
1108
+ * @param {ReadonlyVec3} a The first operand
1109
+ * @param {ReadonlyVec3} b The second operand
1110
+ * @returns {Number} The angle in radians
1111
+ */
1112
+ function angle(a, b) {
1113
+ const ax = a[0];
1114
+ const ay = a[1];
1115
+ const az = a[2];
1116
+ const bx = b[0];
1117
+ const by = b[1];
1118
+ const bz = b[2];
1119
+ const mag = Math.sqrt((ax * ax + ay * ay + az * az) * (bx * bx + by * by + bz * bz));
1120
+ const cosine = mag && dot$2(a, b) / mag;
1121
+ return Math.acos(Math.min(Math.max(cosine, -1), 1));
1122
+ }
1123
+ /**
1124
+ * Alias for {@link vec3.length}
1125
+ * @function
1126
+ */
1127
+ const len = length$2;
1128
+ /**
1129
+ * Perform some operation over an array of vec3s.
1130
+ *
1131
+ * @param {Array} a the array of vectors to iterate over
1132
+ * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
1133
+ * @param {Number} offset Number of elements to skip at the beginning of the array
1134
+ * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
1135
+ * @param {Function} fn Function to call for each vector in the array
1136
+ * @param {Object} [arg] additional argument to pass to fn
1137
+ * @returns {Array} a
1138
+ * @function
1139
+ */
1140
+ ((function () {
1141
+ const vec = create$3();
1142
+ return function (a, stride, offset, count, fn, arg) {
1143
+ let i;
1144
+ let l;
1145
+ if (!stride) {
1146
+ stride = 3;
1147
+ }
1148
+ if (!offset) {
1149
+ offset = 0;
1150
+ }
1151
+ if (count) {
1152
+ l = Math.min(count * stride + offset, a.length);
1153
+ }
1154
+ else {
1155
+ l = a.length;
1156
+ }
1157
+ for (i = offset; i < l; i += stride) {
1158
+ vec[0] = a[i];
1159
+ vec[1] = a[i + 1];
1160
+ vec[2] = a[i + 2];
1161
+ fn(vec, vec, arg);
1162
+ a[i] = vec[0];
1163
+ a[i + 1] = vec[1];
1164
+ a[i + 2] = vec[2];
1165
+ }
1166
+ return a;
1167
+ };
1168
+ }))();
1169
+
1170
+ // math.gl
1171
+ const ORIGIN = [0, 0, 0];
1172
+ let ZERO$1;
1173
+ /**
1174
+ * Three-element vector class with common linear algebra operations.
1175
+ * Subclass of Array<number> meaning that it is highly compatible with other libraries
1176
+ */
1177
+ class Vector3 extends Vector {
1178
+ static get ZERO() {
1179
+ if (!ZERO$1) {
1180
+ ZERO$1 = new Vector3(0, 0, 0);
1181
+ Object.freeze(ZERO$1);
1182
+ }
1183
+ return ZERO$1;
1184
+ }
1185
+ /**
1186
+ * @class
1187
+ * @param x
1188
+ * @param y
1189
+ * @param z
1190
+ */
1191
+ constructor(x = 0, y = 0, z = 0) {
1192
+ // PERF NOTE: initialize elements as double precision numbers
1193
+ super(-0, -0, -0);
1194
+ if (arguments.length === 1 && isArray(x)) {
1195
+ this.copy(x);
1196
+ }
1197
+ else {
1198
+ // this.set(x, y, z);
1199
+ if (config.debug) {
1200
+ checkNumber(x);
1201
+ checkNumber(y);
1202
+ checkNumber(z);
1203
+ }
1204
+ // @ts-expect-error TS2412: Property '0' of type 'number | [number, number, number]' is not assignable to numeric index type 'number'
1205
+ this[0] = x;
1206
+ this[1] = y;
1207
+ this[2] = z;
1208
+ }
1209
+ }
1210
+ set(x, y, z) {
1211
+ this[0] = x;
1212
+ this[1] = y;
1213
+ this[2] = z;
1214
+ return this.check();
1215
+ }
1216
+ copy(array) {
1217
+ this[0] = array[0];
1218
+ this[1] = array[1];
1219
+ this[2] = array[2];
1220
+ return this.check();
1221
+ }
1222
+ fromObject(object) {
1223
+ if (config.debug) {
1224
+ checkNumber(object.x);
1225
+ checkNumber(object.y);
1226
+ checkNumber(object.z);
1227
+ }
1228
+ this[0] = object.x;
1229
+ this[1] = object.y;
1230
+ this[2] = object.z;
1231
+ return this.check();
1232
+ }
1233
+ toObject(object) {
1234
+ object.x = this[0];
1235
+ object.y = this[1];
1236
+ object.z = this[2];
1237
+ return object;
1238
+ }
1239
+ // Getters/setters
1240
+ get ELEMENTS() {
1241
+ return 3;
1242
+ }
1243
+ get z() {
1244
+ return this[2];
1245
+ }
1246
+ set z(value) {
1247
+ this[2] = checkNumber(value);
1248
+ }
1249
+ // ACCESSORS
1250
+ angle(vector) {
1251
+ return angle(this, vector);
1252
+ }
1253
+ // MODIFIERS
1254
+ cross(vector) {
1255
+ cross(this, this, vector);
1256
+ return this.check();
1257
+ }
1258
+ rotateX({ radians, origin = ORIGIN }) {
1259
+ rotateX$1(this, this, origin, radians);
1260
+ return this.check();
1261
+ }
1262
+ rotateY({ radians, origin = ORIGIN }) {
1263
+ rotateY$1(this, this, origin, radians);
1264
+ return this.check();
1265
+ }
1266
+ rotateZ({ radians, origin = ORIGIN }) {
1267
+ rotateZ$1(this, this, origin, radians);
1268
+ return this.check();
1269
+ }
1270
+ // Transforms
1271
+ // transforms as point (4th component is implicitly 1)
1272
+ transform(matrix4) {
1273
+ return this.transformAsPoint(matrix4);
1274
+ }
1275
+ // transforms as point (4th component is implicitly 1)
1276
+ transformAsPoint(matrix4) {
1277
+ transformMat4(this, this, matrix4);
1278
+ return this.check();
1279
+ }
1280
+ // transforms as vector (4th component is implicitly 0, ignores translation. slightly faster)
1281
+ transformAsVector(matrix4) {
1282
+ vec3_transformMat4AsVector(this, this, matrix4);
1283
+ return this.check();
1284
+ }
1285
+ transformByMatrix3(matrix3) {
1286
+ transformMat3(this, this, matrix3);
1287
+ return this.check();
1288
+ }
1289
+ transformByMatrix2(matrix2) {
1290
+ vec3_transformMat2(this, this, matrix2);
1291
+ return this.check();
1292
+ }
1293
+ transformByQuaternion(quaternion) {
1294
+ transformQuat$1(this, this, quaternion);
1295
+ return this.check();
1296
+ }
1297
+ }
1298
+
1299
+ // math.gl
1300
+ let ZERO;
1301
+ /**
1302
+ * Four-element vector class with common linear algebra operations.
1303
+ * Subclass of Array<number> meaning that it is highly compatible with other libraries
1304
+ */
1305
+ class Vector4 extends Vector {
1306
+ static get ZERO() {
1307
+ if (!ZERO) {
1308
+ ZERO = new Vector4(0, 0, 0, 0);
1309
+ Object.freeze(ZERO);
1310
+ }
1311
+ return ZERO;
1312
+ }
1313
+ constructor(x = 0, y = 0, z = 0, w = 0) {
1314
+ // PERF NOTE: initialize elements as double precision numbers
1315
+ super(-0, -0, -0, -0);
1316
+ if (isArray(x) && arguments.length === 1) {
1317
+ this.copy(x);
1318
+ }
1319
+ else {
1320
+ // this.set(x, y, z, w);
1321
+ if (config.debug) {
1322
+ checkNumber(x);
1323
+ checkNumber(y);
1324
+ checkNumber(z);
1325
+ checkNumber(w);
1326
+ }
1327
+ this[0] = x;
1328
+ this[1] = y;
1329
+ this[2] = z;
1330
+ this[3] = w;
1331
+ }
1332
+ }
1333
+ set(x, y, z, w) {
1334
+ this[0] = x;
1335
+ this[1] = y;
1336
+ this[2] = z;
1337
+ this[3] = w;
1338
+ return this.check();
1339
+ }
1340
+ copy(array) {
1341
+ this[0] = array[0];
1342
+ this[1] = array[1];
1343
+ this[2] = array[2];
1344
+ this[3] = array[3];
1345
+ return this.check();
1346
+ }
1347
+ fromObject(object) {
1348
+ if (config.debug) {
1349
+ checkNumber(object.x);
1350
+ checkNumber(object.y);
1351
+ checkNumber(object.z);
1352
+ checkNumber(object.w);
1353
+ }
1354
+ this[0] = object.x;
1355
+ this[1] = object.y;
1356
+ this[2] = object.z;
1357
+ this[3] = object.w;
1358
+ return this;
1359
+ }
1360
+ toObject(object) {
1361
+ object.x = this[0];
1362
+ object.y = this[1];
1363
+ object.z = this[2];
1364
+ object.w = this[3];
1365
+ return object;
1366
+ }
1367
+ // Getters/setters
1368
+ /* eslint-disable no-multi-spaces, brace-style, no-return-assign */
1369
+ get ELEMENTS() {
1370
+ return 4;
1371
+ }
1372
+ get z() {
1373
+ return this[2];
1374
+ }
1375
+ set z(value) {
1376
+ this[2] = checkNumber(value);
1377
+ }
1378
+ get w() {
1379
+ return this[3];
1380
+ }
1381
+ set w(value) {
1382
+ this[3] = checkNumber(value);
1383
+ }
1384
+ transform(matrix4) {
1385
+ transformMat4(this, this, matrix4);
1386
+ return this.check();
1387
+ }
1388
+ transformByMatrix3(matrix3) {
1389
+ vec4_transformMat3(this, this, matrix3);
1390
+ return this.check();
1391
+ }
1392
+ transformByMatrix2(matrix2) {
1393
+ vec4_transformMat2(this, this, matrix2);
1394
+ return this.check();
1395
+ }
1396
+ transformByQuaternion(quaternion) {
1397
+ transformQuat$1(this, this, quaternion);
1398
+ return this.check();
1399
+ }
1400
+ // three.js compatibility
1401
+ applyMatrix4(m) {
1402
+ m.transform(this, this);
1403
+ return this;
1404
+ }
1405
+ }
1406
+
1407
+ /**
1408
+ * 3x3 Matrix
1409
+ * @module mat3
1410
+ */
1411
+ /**
1412
+ * Creates a new identity mat3
1413
+ *
1414
+ * @returns {mat3} a new 3x3 matrix
1415
+ */
1416
+ function create$2() {
1417
+ const out = new ARRAY_TYPE(9);
1418
+ if (ARRAY_TYPE != Float32Array) {
1419
+ out[1] = 0;
1420
+ out[2] = 0;
1421
+ out[3] = 0;
1422
+ out[5] = 0;
1423
+ out[6] = 0;
1424
+ out[7] = 0;
1425
+ }
1426
+ out[0] = 1;
1427
+ out[4] = 1;
1428
+ out[8] = 1;
1429
+ return out;
1430
+ }
1431
+
1432
+ // @eslint-disable
1433
+ /**
1434
+ * 4 Dimensional Vector
1435
+ * @module vec4
1436
+ */
1437
+ /**
1438
+ * Creates a new, empty vec4
1439
+ *
1440
+ * @returns {vec4} a new 4D vector
1441
+ */
1442
+ function create$1() {
1443
+ const out = new ARRAY_TYPE(4);
1444
+ if (ARRAY_TYPE != Float32Array) {
1445
+ out[0] = 0;
1446
+ out[1] = 0;
1447
+ out[2] = 0;
1448
+ out[3] = 0;
1449
+ }
1450
+ return out;
1451
+ }
1452
+ /**
1453
+ * Adds two vec4's
1454
+ *
1455
+ * @param {vec4} out the receiving vector
1456
+ * @param {ReadonlyVec4} a the first operand
1457
+ * @param {ReadonlyVec4} b the second operand
1458
+ * @returns {vec4} out
1459
+ */
1460
+ function add$1(out, a, b) {
1461
+ out[0] = a[0] + b[0];
1462
+ out[1] = a[1] + b[1];
1463
+ out[2] = a[2] + b[2];
1464
+ out[3] = a[3] + b[3];
1465
+ return out;
1466
+ }
1467
+ /**
1468
+ * Scales a vec4 by a scalar number
1469
+ *
1470
+ * @param {vec4} out the receiving vector
1471
+ * @param {ReadonlyVec4} a the vector to scale
1472
+ * @param {Number} b amount to scale the vector by
1473
+ * @returns {vec4} out
1474
+ */
1475
+ function scale$1(out, a, b) {
1476
+ out[0] = a[0] * b;
1477
+ out[1] = a[1] * b;
1478
+ out[2] = a[2] * b;
1479
+ out[3] = a[3] * b;
1480
+ return out;
1481
+ }
1482
+ /**
1483
+ * Calculates the length of a vec4
1484
+ *
1485
+ * @param {ReadonlyVec4} a vector to calculate length of
1486
+ * @returns {Number} length of a
1487
+ */
1488
+ function length$1(a) {
1489
+ const x = a[0];
1490
+ const y = a[1];
1491
+ const z = a[2];
1492
+ const w = a[3];
1493
+ return Math.sqrt(x * x + y * y + z * z + w * w);
1494
+ }
1495
+ /**
1496
+ * Calculates the squared length of a vec4
1497
+ *
1498
+ * @param {ReadonlyVec4} a vector to calculate squared length of
1499
+ * @returns {Number} squared length of a
1500
+ */
1501
+ function squaredLength$1(a) {
1502
+ const x = a[0];
1503
+ const y = a[1];
1504
+ const z = a[2];
1505
+ const w = a[3];
1506
+ return x * x + y * y + z * z + w * w;
1507
+ }
1508
+ /**
1509
+ * Normalize a vec4
1510
+ *
1511
+ * @param {vec4} out the receiving vector
1512
+ * @param {ReadonlyVec4} a vector to normalize
1513
+ * @returns {vec4} out
1514
+ */
1515
+ function normalize$1(out, a) {
1516
+ const x = a[0];
1517
+ const y = a[1];
1518
+ const z = a[2];
1519
+ const w = a[3];
1520
+ let len = x * x + y * y + z * z + w * w;
1521
+ if (len > 0) {
1522
+ len = 1 / Math.sqrt(len);
1523
+ }
1524
+ out[0] = x * len;
1525
+ out[1] = y * len;
1526
+ out[2] = z * len;
1527
+ out[3] = w * len;
1528
+ return out;
1529
+ }
1530
+ /**
1531
+ * Calculates the dot product of two vec4's
1532
+ *
1533
+ * @param {ReadonlyVec4} a the first operand
1534
+ * @param {ReadonlyVec4} b the second operand
1535
+ * @returns {Number} dot product of a and b
1536
+ */
1537
+ function dot$1(a, b) {
1538
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
1539
+ }
1540
+ /**
1541
+ * Performs a linear interpolation between two vec4's
1542
+ *
1543
+ * @param {vec4} out the receiving vector
1544
+ * @param {ReadonlyVec4} a the first operand
1545
+ * @param {ReadonlyVec4} b the second operand
1546
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
1547
+ * @returns {vec4} out
1548
+ */
1549
+ function lerp$1(out, a, b, t) {
1550
+ const ax = a[0];
1551
+ const ay = a[1];
1552
+ const az = a[2];
1553
+ const aw = a[3];
1554
+ out[0] = ax + t * (b[0] - ax);
1555
+ out[1] = ay + t * (b[1] - ay);
1556
+ out[2] = az + t * (b[2] - az);
1557
+ out[3] = aw + t * (b[3] - aw);
1558
+ return out;
1559
+ }
1560
+ /**
1561
+ * Transforms the vec4 with a quat
1562
+ *
1563
+ * @param {vec4} out the receiving vector
1564
+ * @param {ReadonlyVec4} a the vector to transform
1565
+ * @param {ReadonlyQuat} q quaternion to transform with
1566
+ * @returns {vec4} out
1567
+ */
1568
+ function transformQuat(out, a, q) {
1569
+ const x = a[0];
1570
+ const y = a[1];
1571
+ const z = a[2];
1572
+ const qx = q[0];
1573
+ const qy = q[1];
1574
+ const qz = q[2];
1575
+ const qw = q[3];
1576
+ // calculate quat * vec
1577
+ const ix = qw * x + qy * z - qz * y;
1578
+ const iy = qw * y + qz * x - qx * z;
1579
+ const iz = qw * z + qx * y - qy * x;
1580
+ const iw = -qx * x - qy * y - qz * z;
1581
+ // calculate result * inverse quat
1582
+ out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
1583
+ out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
1584
+ out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
1585
+ out[3] = a[3];
1586
+ return out;
1587
+ }
1588
+ /**
1589
+ * Perform some operation over an array of vec4s.
1590
+ *
1591
+ * @param {Array} a the array of vectors to iterate over
1592
+ * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed
1593
+ * @param {Number} offset Number of elements to skip at the beginning of the array
1594
+ * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array
1595
+ * @param {Function} fn Function to call for each vector in the array
1596
+ * @param {Object} [arg] additional argument to pass to fn
1597
+ * @returns {Array} a
1598
+ * @function
1599
+ */
1600
+ ((function () {
1601
+ const vec = create$1();
1602
+ return function (a, stride, offset, count, fn, arg) {
1603
+ let i;
1604
+ let l;
1605
+ if (!stride) {
1606
+ stride = 4;
1607
+ }
1608
+ if (!offset) {
1609
+ offset = 0;
1610
+ }
1611
+ if (count) {
1612
+ l = Math.min(count * stride + offset, a.length);
1613
+ }
1614
+ else {
1615
+ l = a.length;
1616
+ }
1617
+ for (i = offset; i < l; i += stride) {
1618
+ vec[0] = a[i];
1619
+ vec[1] = a[i + 1];
1620
+ vec[2] = a[i + 2];
1621
+ vec[3] = a[i + 3];
1622
+ fn(vec, vec, arg);
1623
+ a[i] = vec[0];
1624
+ a[i + 1] = vec[1];
1625
+ a[i + 2] = vec[2];
1626
+ a[i + 3] = vec[3];
1627
+ }
1628
+ return a;
1629
+ };
1630
+ }))();
1631
+
1632
+ // @eslint-disable
1633
+ // const glMatrix: {EPSILON = 0.000001};
1634
+ /**
1635
+ * Quaternion in the format XYZW
1636
+ * @module quat
1637
+ */
1638
+ /**
1639
+ * Creates a new identity quat
1640
+ *
1641
+ * @returns {quat} a new quaternion
1642
+ */
1643
+ function create() {
1644
+ const out = new ARRAY_TYPE(4);
1645
+ if (ARRAY_TYPE != Float32Array) {
1646
+ out[0] = 0;
1647
+ out[1] = 0;
1648
+ out[2] = 0;
1649
+ }
1650
+ out[3] = 1;
1651
+ return out;
1652
+ }
1653
+ /**
1654
+ * Set a quat to the identity quaternion
1655
+ *
1656
+ * @param {quat} out the receiving quaternion
1657
+ * @returns {quat} out
1658
+ */
1659
+ function identity(out) {
1660
+ out[0] = 0;
1661
+ out[1] = 0;
1662
+ out[2] = 0;
1663
+ out[3] = 1;
1664
+ return out;
1665
+ }
1666
+ /**
1667
+ * Sets a quat from the given angle and rotation axis,
1668
+ * then returns it.
1669
+ *
1670
+ * @param {quat} out the receiving quaternion
1671
+ * @param {ReadonlyVec3} axis the axis around which to rotate
1672
+ * @param {Number} rad the angle in radians
1673
+ * @returns {quat} out
1674
+ **/
1675
+ function setAxisAngle(out, axis, rad) {
1676
+ rad = rad * 0.5;
1677
+ const s = Math.sin(rad);
1678
+ out[0] = s * axis[0];
1679
+ out[1] = s * axis[1];
1680
+ out[2] = s * axis[2];
1681
+ out[3] = Math.cos(rad);
1682
+ return out;
1683
+ }
1684
+ /**
1685
+ * Multiplies two quat's
1686
+ *
1687
+ * @param {quat} out the receiving quaternion
1688
+ * @param {ReadonlyQuat} a the first operand
1689
+ * @param {ReadonlyQuat} b the second operand
1690
+ * @returns {quat} out
1691
+ */
1692
+ function multiply(out, a, b) {
1693
+ const ax = a[0];
1694
+ const ay = a[1];
1695
+ const az = a[2];
1696
+ const aw = a[3];
1697
+ const bx = b[0];
1698
+ const by = b[1];
1699
+ const bz = b[2];
1700
+ const bw = b[3];
1701
+ out[0] = ax * bw + aw * bx + ay * bz - az * by;
1702
+ out[1] = ay * bw + aw * by + az * bx - ax * bz;
1703
+ out[2] = az * bw + aw * bz + ax * by - ay * bx;
1704
+ out[3] = aw * bw - ax * bx - ay * by - az * bz;
1705
+ return out;
1706
+ }
1707
+ /**
1708
+ * Rotates a quaternion by the given angle about the X axis
1709
+ *
1710
+ * @param {quat} out quat receiving operation result
1711
+ * @param {ReadonlyQuat} a quat to rotate
1712
+ * @param {number} rad angle (in radians) to rotate
1713
+ * @returns {quat} out
1714
+ */
1715
+ function rotateX(out, a, rad) {
1716
+ rad *= 0.5;
1717
+ const ax = a[0];
1718
+ const ay = a[1];
1719
+ const az = a[2];
1720
+ const aw = a[3];
1721
+ const bx = Math.sin(rad);
1722
+ const bw = Math.cos(rad);
1723
+ out[0] = ax * bw + aw * bx;
1724
+ out[1] = ay * bw + az * bx;
1725
+ out[2] = az * bw - ay * bx;
1726
+ out[3] = aw * bw - ax * bx;
1727
+ return out;
1728
+ }
1729
+ /**
1730
+ * Rotates a quaternion by the given angle about the Y axis
1731
+ *
1732
+ * @param {quat} out quat receiving operation result
1733
+ * @param {ReadonlyQuat} a quat to rotate
1734
+ * @param {number} rad angle (in radians) to rotate
1735
+ * @returns {quat} out
1736
+ */
1737
+ function rotateY(out, a, rad) {
1738
+ rad *= 0.5;
1739
+ const ax = a[0];
1740
+ const ay = a[1];
1741
+ const az = a[2];
1742
+ const aw = a[3];
1743
+ const by = Math.sin(rad);
1744
+ const bw = Math.cos(rad);
1745
+ out[0] = ax * bw - az * by;
1746
+ out[1] = ay * bw + aw * by;
1747
+ out[2] = az * bw + ax * by;
1748
+ out[3] = aw * bw - ay * by;
1749
+ return out;
1750
+ }
1751
+ /**
1752
+ * Rotates a quaternion by the given angle about the Z axis
1753
+ *
1754
+ * @param {quat} out quat receiving operation result
1755
+ * @param {ReadonlyQuat} a quat to rotate
1756
+ * @param {number} rad angle (in radians) to rotate
1757
+ * @returns {quat} out
1758
+ */
1759
+ function rotateZ(out, a, rad) {
1760
+ rad *= 0.5;
1761
+ const ax = a[0];
1762
+ const ay = a[1];
1763
+ const az = a[2];
1764
+ const aw = a[3];
1765
+ const bz = Math.sin(rad);
1766
+ const bw = Math.cos(rad);
1767
+ out[0] = ax * bw + ay * bz;
1768
+ out[1] = ay * bw - ax * bz;
1769
+ out[2] = az * bw + aw * bz;
1770
+ out[3] = aw * bw - az * bz;
1771
+ return out;
1772
+ }
1773
+ /**
1774
+ * Calculates the W component of a quat from the X, Y, and Z components.
1775
+ * Assumes that quaternion is 1 unit in length.
1776
+ * Any existing W component will be ignored.
1777
+ *
1778
+ * @param {quat} out the receiving quaternion
1779
+ * @param {ReadonlyQuat} a quat to calculate W component of
1780
+ * @returns {quat} out
1781
+ */
1782
+ function calculateW(out, a) {
1783
+ const x = a[0];
1784
+ const y = a[1];
1785
+ const z = a[2];
1786
+ out[0] = x;
1787
+ out[1] = y;
1788
+ out[2] = z;
1789
+ out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));
1790
+ return out;
1791
+ }
1792
+ /**
1793
+ * Performs a spherical linear interpolation between two quat
1794
+ *
1795
+ * @param {quat} out the receiving quaternion
1796
+ * @param {ReadonlyQuat} a the first operand
1797
+ * @param {ReadonlyQuat} b the second operand
1798
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
1799
+ * @returns {quat} out
1800
+ */
1801
+ function slerp(out, a, b, t) {
1802
+ // benchmarks:
1803
+ // http://jsperf.com/quaternion-slerp-implementations
1804
+ const ax = a[0];
1805
+ const ay = a[1];
1806
+ const az = a[2];
1807
+ const aw = a[3];
1808
+ let bx = b[0];
1809
+ let by = b[1];
1810
+ let bz = b[2];
1811
+ let bw = b[3];
1812
+ let cosom;
1813
+ let omega;
1814
+ let scale0;
1815
+ let scale1;
1816
+ let sinom;
1817
+ // calc cosine
1818
+ cosom = ax * bx + ay * by + az * bz + aw * bw;
1819
+ // adjust signs (if necessary)
1820
+ if (cosom < 0.0) {
1821
+ cosom = -cosom;
1822
+ bx = -bx;
1823
+ by = -by;
1824
+ bz = -bz;
1825
+ bw = -bw;
1826
+ }
1827
+ // calculate coefficients
1828
+ if (1.0 - cosom > EPSILON) {
1829
+ // standard case (slerp)
1830
+ omega = Math.acos(cosom);
1831
+ sinom = Math.sin(omega);
1832
+ scale0 = Math.sin((1.0 - t) * omega) / sinom;
1833
+ scale1 = Math.sin(t * omega) / sinom;
1834
+ }
1835
+ else {
1836
+ // "from" and "to" quaternions are very close
1837
+ // ... so we can do a linear interpolation
1838
+ scale0 = 1.0 - t;
1839
+ scale1 = t;
1840
+ }
1841
+ // calculate final values
1842
+ out[0] = scale0 * ax + scale1 * bx;
1843
+ out[1] = scale0 * ay + scale1 * by;
1844
+ out[2] = scale0 * az + scale1 * bz;
1845
+ out[3] = scale0 * aw + scale1 * bw;
1846
+ return out;
1847
+ }
1848
+ /**
1849
+ * Generates a random unit quaternion
1850
+ *
1851
+ * @param {quat} out the receiving quaternion
1852
+ * @returns {quat} out
1853
+ */
1854
+ // export function random(out) {
1855
+ // // Implementation of http://planning.cs.uiuc.edu/node198.html
1856
+ // // TODO: Calling random 3 times is probably not the fastest solution
1857
+ // let u1 = glMatrix.RANDOM();
1858
+ // let u2 = glMatrix.RANDOM();
1859
+ // let u3 = glMatrix.RANDOM();
1860
+ // let sqrt1MinusU1 = Math.sqrt(1 - u1);
1861
+ // let sqrtU1 = Math.sqrt(u1);
1862
+ // out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2);
1863
+ // out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2);
1864
+ // out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3);
1865
+ // out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3);
1866
+ // return out;
1867
+ // }
1868
+ /**
1869
+ * Calculates the inverse of a quat
1870
+ *
1871
+ * @param {quat} out the receiving quaternion
1872
+ * @param {ReadonlyQuat} a quat to calculate inverse of
1873
+ * @returns {quat} out
1874
+ */
1875
+ function invert(out, a) {
1876
+ const a0 = a[0];
1877
+ const a1 = a[1];
1878
+ const a2 = a[2];
1879
+ const a3 = a[3];
1880
+ const dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
1881
+ const invDot = dot ? 1.0 / dot : 0;
1882
+ // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0
1883
+ out[0] = -a0 * invDot;
1884
+ out[1] = -a1 * invDot;
1885
+ out[2] = -a2 * invDot;
1886
+ out[3] = a3 * invDot;
1887
+ return out;
1888
+ }
1889
+ /**
1890
+ * Calculates the conjugate of a quat
1891
+ * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
1892
+ *
1893
+ * @param {quat} out the receiving quaternion
1894
+ * @param {ReadonlyQuat} a quat to calculate conjugate of
1895
+ * @returns {quat} out
1896
+ */
1897
+ function conjugate(out, a) {
1898
+ out[0] = -a[0];
1899
+ out[1] = -a[1];
1900
+ out[2] = -a[2];
1901
+ out[3] = a[3];
1902
+ return out;
1903
+ }
1904
+ /**
1905
+ * Creates a quaternion from the given 3x3 rotation matrix.
1906
+ *
1907
+ * NOTE: The resultant quaternion is not normalized, so you should be sure
1908
+ * to renormalize the quaternion yourself where necessary.
1909
+ *
1910
+ * @param {quat} out the receiving quaternion
1911
+ * @param {ReadonlyMat3} m rotation matrix
1912
+ * @returns {quat} out
1913
+ * @function
1914
+ */
1915
+ function fromMat3(out, m) {
1916
+ // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
1917
+ // article "Quaternion Calculus and Fast Animation".
1918
+ const fTrace = m[0] + m[4] + m[8];
1919
+ let fRoot;
1920
+ if (fTrace > 0.0) {
1921
+ // |w| > 1/2, may as well choose w > 1/2
1922
+ fRoot = Math.sqrt(fTrace + 1.0); // 2w
1923
+ out[3] = 0.5 * fRoot;
1924
+ fRoot = 0.5 / fRoot; // 1/(4w)
1925
+ out[0] = (m[5] - m[7]) * fRoot;
1926
+ out[1] = (m[6] - m[2]) * fRoot;
1927
+ out[2] = (m[1] - m[3]) * fRoot;
1928
+ }
1929
+ else {
1930
+ // |w| <= 1/2
1931
+ let i = 0;
1932
+ if (m[4] > m[0])
1933
+ i = 1;
1934
+ if (m[8] > m[i * 3 + i])
1935
+ i = 2;
1936
+ const j = (i + 1) % 3;
1937
+ const k = (i + 2) % 3;
1938
+ fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
1939
+ out[i] = 0.5 * fRoot;
1940
+ fRoot = 0.5 / fRoot;
1941
+ out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
1942
+ out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
1943
+ out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
1944
+ }
1945
+ return out;
1946
+ }
1947
+ /**
1948
+ * Adds two quat's
1949
+ *
1950
+ * @param {quat} out the receiving quaternion
1951
+ * @param {ReadonlyQuat} a the first operand
1952
+ * @param {ReadonlyQuat} b the second operand
1953
+ * @returns {quat} out
1954
+ * @function
1955
+ */
1956
+ const add = add$1;
1957
+ /**
1958
+ * Scales a quat by a scalar number
1959
+ *
1960
+ * @param {quat} out the receiving vector
1961
+ * @param {ReadonlyQuat} a the vector to scale
1962
+ * @param {Number} b amount to scale the vector by
1963
+ * @returns {quat} out
1964
+ * @function
1965
+ */
1966
+ const scale = scale$1;
1967
+ /**
1968
+ * Calculates the dot product of two quat's
1969
+ *
1970
+ * @param {ReadonlyQuat} a the first operand
1971
+ * @param {ReadonlyQuat} b the second operand
1972
+ * @returns {Number} dot product of a and b
1973
+ * @function
1974
+ */
1975
+ const dot = dot$1;
1976
+ /**
1977
+ * Performs a linear interpolation between two quat's
1978
+ *
1979
+ * @param {quat} out the receiving quaternion
1980
+ * @param {ReadonlyQuat} a the first operand
1981
+ * @param {ReadonlyQuat} b the second operand
1982
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
1983
+ * @returns {quat} out
1984
+ * @function
1985
+ */
1986
+ const lerp = lerp$1;
1987
+ /**
1988
+ * Calculates the length of a quat
1989
+ *
1990
+ * @param {ReadonlyQuat} a vector to calculate length of
1991
+ * @returns {Number} length of a
1992
+ */
1993
+ const length = length$1;
1994
+ /**
1995
+ * Calculates the squared length of a quat
1996
+ *
1997
+ * @param {ReadonlyQuat} a vector to calculate squared length of
1998
+ * @returns {Number} squared length of a
1999
+ * @function
2000
+ */
2001
+ const squaredLength = squaredLength$1;
2002
+ /**
2003
+ * Normalize a quat
2004
+ *
2005
+ * @param {quat} out the receiving quaternion
2006
+ * @param {ReadonlyQuat} a quaternion to normalize
2007
+ * @returns {quat} out
2008
+ * @function
2009
+ */
2010
+ const normalize = normalize$1;
2011
+ /**
2012
+ * Sets a quaternion to represent the shortest rotation from one
2013
+ * vector to another.
2014
+ *
2015
+ * Both vectors are assumed to be unit length.
2016
+ *
2017
+ * @param {quat} out the receiving quaternion.
2018
+ * @param {ReadonlyVec3} a the initial vector
2019
+ * @param {ReadonlyVec3} b the destination vector
2020
+ * @returns {quat} out
2021
+ */
2022
+ const rotationTo = (function () {
2023
+ const tmpvec3 = create$3();
2024
+ const xUnitVec3 = fromValues(1, 0, 0);
2025
+ const yUnitVec3 = fromValues(0, 1, 0);
2026
+ return function (out, a, b) {
2027
+ const dot = dot$2(a, b);
2028
+ if (dot < -0.999999) {
2029
+ cross(tmpvec3, xUnitVec3, a);
2030
+ if (len(tmpvec3) < 0.000001)
2031
+ cross(tmpvec3, yUnitVec3, a);
2032
+ normalize$2(tmpvec3, tmpvec3);
2033
+ setAxisAngle(out, tmpvec3, Math.PI);
2034
+ return out;
2035
+ }
2036
+ else if (dot > 0.999999) {
2037
+ out[0] = 0;
2038
+ out[1] = 0;
2039
+ out[2] = 0;
2040
+ out[3] = 1;
2041
+ return out;
2042
+ }
2043
+ cross(tmpvec3, a, b);
2044
+ out[0] = tmpvec3[0];
2045
+ out[1] = tmpvec3[1];
2046
+ out[2] = tmpvec3[2];
2047
+ out[3] = 1 + dot;
2048
+ return normalize(out, out);
2049
+ };
2050
+ })();
2051
+ /**
2052
+ * Performs a spherical linear interpolation with two control points
2053
+ *
2054
+ * @param {quat} out the receiving quaternion
2055
+ * @param {ReadonlyQuat} a the first operand
2056
+ * @param {ReadonlyQuat} b the second operand
2057
+ * @param {ReadonlyQuat} c the third operand
2058
+ * @param {ReadonlyQuat} d the fourth operand
2059
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
2060
+ * @returns {quat} out
2061
+ */
2062
+ ((function () {
2063
+ const temp1 = create();
2064
+ const temp2 = create();
2065
+ return function (out, a, b, c, d, t) {
2066
+ slerp(temp1, a, d, t);
2067
+ slerp(temp2, b, c, t);
2068
+ slerp(out, temp1, temp2, 2 * t * (1 - t));
2069
+ return out;
2070
+ };
2071
+ }))();
2072
+ /**
2073
+ * Sets the specified quaternion with values corresponding to the given
2074
+ * axes. Each axis is a vec3 and is expected to be unit length and
2075
+ * perpendicular to all other specified axes.
2076
+ *
2077
+ * @param {ReadonlyVec3} view the vector representing the viewing direction
2078
+ * @param {ReadonlyVec3} right the vector representing the local "right" direction
2079
+ * @param {ReadonlyVec3} up the vector representing the local "up" direction
2080
+ * @returns {quat} out
2081
+ */
2082
+ ((function () {
2083
+ const matr = create$2();
2084
+ return function (out, view, right, up) {
2085
+ matr[0] = right[0];
2086
+ matr[3] = right[1];
2087
+ matr[6] = right[2];
2088
+ matr[1] = up[0];
2089
+ matr[4] = up[1];
2090
+ matr[7] = up[2];
2091
+ matr[2] = -view[0];
2092
+ matr[5] = -view[1];
2093
+ matr[8] = -view[2];
2094
+ return normalize(out, fromMat3(out, matr));
2095
+ };
2096
+ }))();
2097
+
2098
+ // math.gl
2099
+ const IDENTITY_QUATERNION = [0, 0, 0, 1];
2100
+ class Quaternion extends MathArray {
2101
+ constructor(x = 0, y = 0, z = 0, w = 1) {
2102
+ // PERF NOTE: initialize elements as double precision numbers
2103
+ super(-0, -0, -0, -0);
2104
+ // eslint-disable-next-line prefer-rest-params
2105
+ if (Array.isArray(x) && arguments.length === 1) {
2106
+ this.copy(x);
2107
+ }
2108
+ else {
2109
+ this.set(x, y, z, w);
2110
+ }
2111
+ }
2112
+ copy(array) {
2113
+ this[0] = array[0];
2114
+ this[1] = array[1];
2115
+ this[2] = array[2];
2116
+ this[3] = array[3];
2117
+ return this.check();
2118
+ }
2119
+ set(x, y, z, w) {
2120
+ this[0] = x;
2121
+ this[1] = y;
2122
+ this[2] = z;
2123
+ this[3] = w;
2124
+ return this.check();
2125
+ }
2126
+ fromObject(object) {
2127
+ this[0] = object.x;
2128
+ this[1] = object.y;
2129
+ this[2] = object.z;
2130
+ this[3] = object.w;
2131
+ return this.check();
2132
+ }
2133
+ /**
2134
+ * Creates a quaternion from the given 3x3 rotation matrix.
2135
+ * NOTE: The resultant quaternion is not normalized, so you should
2136
+ * be sure to renormalize the quaternion yourself where necessary.
2137
+ * @param m
2138
+ * @returns
2139
+ */
2140
+ fromMatrix3(m) {
2141
+ fromMat3(this, m);
2142
+ return this.check();
2143
+ }
2144
+ fromAxisRotation(axis, rad) {
2145
+ setAxisAngle(this, axis, rad);
2146
+ return this.check();
2147
+ }
2148
+ /** Set a quat to the identity quaternion */
2149
+ identity() {
2150
+ identity(this);
2151
+ return this.check();
2152
+ }
2153
+ // Set the components of a quat to the given values
2154
+ // set(i, j, k, l) {
2155
+ // quat_set(this, i, j, k, l);
2156
+ // return this.check();
2157
+ // }
2158
+ // Sets a quat from the given angle and rotation axis, then returns it.
2159
+ setAxisAngle(axis, rad) {
2160
+ return this.fromAxisRotation(axis, rad);
2161
+ }
2162
+ // Getters/setters
2163
+ get ELEMENTS() {
2164
+ return 4;
2165
+ }
2166
+ get x() {
2167
+ return this[0];
2168
+ }
2169
+ set x(value) {
2170
+ this[0] = checkNumber(value);
2171
+ }
2172
+ get y() {
2173
+ return this[1];
2174
+ }
2175
+ set y(value) {
2176
+ this[1] = checkNumber(value);
2177
+ }
2178
+ get z() {
2179
+ return this[2];
2180
+ }
2181
+ set z(value) {
2182
+ this[2] = checkNumber(value);
2183
+ }
2184
+ get w() {
2185
+ return this[3];
2186
+ }
2187
+ set w(value) {
2188
+ this[3] = checkNumber(value);
2189
+ }
2190
+ // Calculates the length of a quat
2191
+ len() {
2192
+ return length(this);
2193
+ }
2194
+ // Calculates the squared length of a quat
2195
+ lengthSquared() {
2196
+ return squaredLength(this);
2197
+ }
2198
+ // Calculates the dot product of two quat's
2199
+ // @return {Number}
2200
+ dot(a) {
2201
+ return dot(this, a);
2202
+ }
2203
+ // Gets the rotation axis and angle for a given quaternion.
2204
+ // If a quaternion is created with setAxisAngle, this method will
2205
+ // return the same values as providied in the original parameter
2206
+ // list OR functionally equivalent values.
2207
+ // Example: The quaternion formed by axis [0, 0, 1] and angle -90
2208
+ // is the same as the quaternion formed by [0, 0, 1] and 270.
2209
+ // This method favors the latter.
2210
+ // @return {{[x,y,z], Number}}
2211
+ // getAxisAngle() {
2212
+ // const axis = [];
2213
+ // // const angle = quat_getAxisAngle(axis, this);
2214
+ // return {axis, angle};
2215
+ // }
2216
+ // MODIFIERS
2217
+ // Sets a quaternion to represent the shortest rotation from one vector
2218
+ // to another. Both vectors are assumed to be unit length.
2219
+ rotationTo(vectorA, vectorB) {
2220
+ rotationTo(this, vectorA, vectorB);
2221
+ return this.check();
2222
+ }
2223
+ // Sets the specified quaternion with values corresponding to the given axes.
2224
+ // Each axis is a vec3 and is expected to be unit length and perpendicular
2225
+ // to all other specified axes.
2226
+ // setAxes() {
2227
+ // Number
2228
+ // }
2229
+ // Performs a spherical linear interpolation with two control points
2230
+ // sqlerp() {
2231
+ // Number;
2232
+ // }
2233
+ // Adds two quat's
2234
+ add(a) {
2235
+ add(this, this, a);
2236
+ return this.check();
2237
+ }
2238
+ // Calculates the W component of a quat from the X, Y, and Z components.
2239
+ // Any existing W component will be ignored.
2240
+ calculateW() {
2241
+ calculateW(this, this);
2242
+ return this.check();
2243
+ }
2244
+ // Calculates the conjugate of a quat If the quaternion is normalized,
2245
+ // this function is faster than quat_invert and produces the same result.
2246
+ conjugate() {
2247
+ conjugate(this, this);
2248
+ return this.check();
2249
+ }
2250
+ // Calculates the inverse of a quat
2251
+ invert() {
2252
+ invert(this, this);
2253
+ return this.check();
2254
+ }
2255
+ // Performs a linear interpolation between two quat's
2256
+ lerp(a, b, t) {
2257
+ if (t === undefined) {
2258
+ return this.lerp(this, a, b);
2259
+ }
2260
+ lerp(this, a, b, t);
2261
+ return this.check();
2262
+ }
2263
+ // Multiplies two quat's
2264
+ multiplyRight(a) {
2265
+ multiply(this, this, a);
2266
+ return this.check();
2267
+ }
2268
+ multiplyLeft(a) {
2269
+ multiply(this, a, this);
2270
+ return this.check();
2271
+ }
2272
+ // Normalize a quat
2273
+ normalize() {
2274
+ // Handle 0 case
2275
+ const length = this.len();
2276
+ const l = length > 0 ? 1 / length : 0;
2277
+ this[0] = this[0] * l;
2278
+ this[1] = this[1] * l;
2279
+ this[2] = this[2] * l;
2280
+ this[3] = this[3] * l;
2281
+ // Set to [0, 0, 0, 1] if length is 0
2282
+ if (length === 0) {
2283
+ this[3] = 1;
2284
+ }
2285
+ return this.check();
2286
+ }
2287
+ // Rotates a quaternion by the given angle about the X axis
2288
+ rotateX(rad) {
2289
+ rotateX(this, this, rad);
2290
+ return this.check();
2291
+ }
2292
+ // Rotates a quaternion by the given angle about the Y axis
2293
+ rotateY(rad) {
2294
+ rotateY(this, this, rad);
2295
+ return this.check();
2296
+ }
2297
+ // Rotates a quaternion by the given angle about the Z axis
2298
+ rotateZ(rad) {
2299
+ rotateZ(this, this, rad);
2300
+ return this.check();
2301
+ }
2302
+ // Scales a quat by a scalar number
2303
+ scale(b) {
2304
+ scale(this, this, b);
2305
+ return this.check();
2306
+ }
2307
+ // Performs a spherical linear interpolation between two quat
2308
+ slerp(arg0, arg1, arg2) {
2309
+ let start;
2310
+ let target;
2311
+ let ratio;
2312
+ // eslint-disable-next-line prefer-rest-params
2313
+ switch (arguments.length) {
2314
+ case 1: // Deprecated signature ({start, target, ratio})
2315
+ // eslint-disable-next-line prefer-rest-params
2316
+ ({
2317
+ start = IDENTITY_QUATERNION,
2318
+ target,
2319
+ ratio
2320
+ } = arg0);
2321
+ break;
2322
+ case 2: // THREE.js compatibility signature (target, ration)
2323
+ start = this; // eslint-disable-line
2324
+ target = arg0;
2325
+ ratio = arg1;
2326
+ break;
2327
+ default:
2328
+ // Default signature: (start, target, ratio)
2329
+ start = arg0;
2330
+ target = arg1;
2331
+ ratio = arg2;
2332
+ }
2333
+ slerp(this, start, target, ratio);
2334
+ return this.check();
2335
+ }
2336
+ transformVector4(vector, result = new Vector4()) {
2337
+ transformQuat(result, vector, this);
2338
+ return checkVector(result, 4);
2339
+ }
2340
+ // THREE.js Math API compatibility
2341
+ lengthSq() {
2342
+ return this.lengthSquared();
2343
+ }
2344
+ setFromAxisAngle(axis, rad) {
2345
+ return this.setAxisAngle(axis, rad);
2346
+ }
2347
+ premultiply(a) {
2348
+ return this.multiplyLeft(a);
2349
+ }
2350
+ multiply(a) {
2351
+ return this.multiplyRight(a);
2352
+ }
2353
+ }
2354
+
2355
+ // math.gl
2356
+ // Internal constants
2357
+ const ERR_UNKNOWN_ORDER = 'Unknown Euler angle order';
2358
+ const ALMOST_ONE = 0.99999;
2359
+ // eslint-disable-next-line no-shadow
2360
+ var RotationOrder;
2361
+ (function (RotationOrder) {
2362
+ RotationOrder[RotationOrder["ZYX"] = 0] = "ZYX";
2363
+ RotationOrder[RotationOrder["YXZ"] = 1] = "YXZ";
2364
+ RotationOrder[RotationOrder["XZY"] = 2] = "XZY";
2365
+ RotationOrder[RotationOrder["ZXY"] = 3] = "ZXY";
2366
+ RotationOrder[RotationOrder["YZX"] = 4] = "YZX";
2367
+ RotationOrder[RotationOrder["XYZ"] = 5] = "XYZ";
2368
+ })(RotationOrder || (RotationOrder = {}));
2369
+ class Euler extends MathArray {
2370
+ // Constants
2371
+ static get ZYX() {
2372
+ return RotationOrder.ZYX;
2373
+ }
2374
+ static get YXZ() {
2375
+ return RotationOrder.YXZ;
2376
+ }
2377
+ static get XZY() {
2378
+ return RotationOrder.XZY;
2379
+ }
2380
+ static get ZXY() {
2381
+ return RotationOrder.ZXY;
2382
+ }
2383
+ static get YZX() {
2384
+ return RotationOrder.YZX;
2385
+ }
2386
+ static get XYZ() {
2387
+ return RotationOrder.XYZ;
2388
+ }
2389
+ static get RollPitchYaw() {
2390
+ return RotationOrder.ZYX;
2391
+ }
2392
+ static get DefaultOrder() {
2393
+ return RotationOrder.ZYX;
2394
+ }
2395
+ static get RotationOrders() {
2396
+ return RotationOrder;
2397
+ }
2398
+ static rotationOrder(order) {
2399
+ return RotationOrder[order];
2400
+ }
2401
+ get ELEMENTS() {
2402
+ return 4;
2403
+ }
2404
+ /**
2405
+ * @class
2406
+ * @param {Number | Number[]} x
2407
+ * @param {Number=} [y]
2408
+ * @param {Number=} [z]
2409
+ * @param {Number=} [order]
2410
+ */
2411
+ constructor(x = 0, y = 0, z = 0, order = Euler.DefaultOrder) {
2412
+ // PERF NOTE: initialize elements as double precision numbers
2413
+ super(-0, -0, -0, -0);
2414
+ // eslint-disable-next-line prefer-rest-params
2415
+ if (arguments.length > 0 && Array.isArray(arguments[0])) {
2416
+ // @ts-expect-error
2417
+ // eslint-disable-next-line prefer-rest-params
2418
+ this.fromVector3(...arguments);
2419
+ }
2420
+ else {
2421
+ this.set(x, y, z, order);
2422
+ }
2423
+ }
2424
+ fromQuaternion(quaternion) {
2425
+ const [x, y, z, w] = quaternion;
2426
+ const ysqr = y * y;
2427
+ const t0 = -2 * (ysqr + z * z) + 1;
2428
+ const t1 = +2 * (x * y + w * z);
2429
+ let t2 = -2 * (x * z - w * y);
2430
+ const t3 = +2 * (y * z + w * x);
2431
+ const t4 = -2 * (x * x + ysqr) + 1;
2432
+ t2 = t2 > 1 ? 1 : t2;
2433
+ t2 = t2 < -1 ? -1 : t2;
2434
+ const roll = Math.atan2(t3, t4);
2435
+ const pitch = Math.asin(t2);
2436
+ const yaw = Math.atan2(t1, t0);
2437
+ return this.set(roll, pitch, yaw, Euler.RollPitchYaw);
2438
+ }
2439
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2440
+ fromObject(object) {
2441
+ throw new Error('not implemented');
2442
+ // return this.set(object.x, object.y, object.z, object.order);
2443
+ }
2444
+ // fromQuaternion(q, order) {
2445
+ // this._fromRotationMat[-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
2446
+ // return this.check();
2447
+ // }
2448
+ // If copied array does contain fourth element, preserves currently set order
2449
+ copy(array) {
2450
+ this[0] = array[0];
2451
+ this[1] = array[1];
2452
+ this[2] = array[2];
2453
+ // @ts-expect-error
2454
+ this[3] = Number.isFinite(array[3]) || this.order;
2455
+ return this.check();
2456
+ }
2457
+ // Sets the three angles, and optionally sets the rotation order
2458
+ // If order is not specified, preserves currently set order
2459
+ set(x = 0, y = 0, z = 0, order) {
2460
+ this[0] = x;
2461
+ this[1] = y;
2462
+ this[2] = z;
2463
+ this[3] = Number.isFinite(order) ? order : this[3];
2464
+ return this.check();
2465
+ }
2466
+ validate() {
2467
+ return (validateOrder(this[3]) &&
2468
+ Number.isFinite(this[0]) &&
2469
+ Number.isFinite(this[1]) &&
2470
+ Number.isFinite(this[2]));
2471
+ }
2472
+ // Does not copy the orientation element
2473
+ toArray(array = [], offset = 0) {
2474
+ array[offset] = this[0];
2475
+ array[offset + 1] = this[1];
2476
+ array[offset + 2] = this[2];
2477
+ return array;
2478
+ }
2479
+ // Copies the orientation element
2480
+ toArray4(array = [], offset = 0) {
2481
+ array[offset] = this[0];
2482
+ array[offset + 1] = this[1];
2483
+ array[offset + 2] = this[2];
2484
+ array[offset + 3] = this[3];
2485
+ return array;
2486
+ }
2487
+ toVector3(result = [-0, -0, -0]) {
2488
+ result[0] = this[0];
2489
+ result[1] = this[1];
2490
+ result[2] = this[2];
2491
+ return result;
2492
+ }
2493
+ /* eslint-disable no-multi-spaces, brace-style, no-return-assign */
2494
+ // x, y, z angle notation (note: only corresponds to axis in XYZ orientation)
2495
+ get x() {
2496
+ return this[0];
2497
+ }
2498
+ set x(value) {
2499
+ this[0] = checkNumber(value);
2500
+ }
2501
+ get y() {
2502
+ return this[1];
2503
+ }
2504
+ set y(value) {
2505
+ this[1] = checkNumber(value);
2506
+ }
2507
+ get z() {
2508
+ return this[2];
2509
+ }
2510
+ set z(value) {
2511
+ this[2] = checkNumber(value);
2512
+ }
2513
+ // alpha, beta, gamma angle notation
2514
+ get alpha() {
2515
+ return this[0];
2516
+ }
2517
+ set alpha(value) {
2518
+ this[0] = checkNumber(value);
2519
+ }
2520
+ get beta() {
2521
+ return this[1];
2522
+ }
2523
+ set beta(value) {
2524
+ this[1] = checkNumber(value);
2525
+ }
2526
+ get gamma() {
2527
+ return this[2];
2528
+ }
2529
+ set gamma(value) {
2530
+ this[2] = checkNumber(value);
2531
+ }
2532
+ // phi, theta, psi angle notation
2533
+ get phi() {
2534
+ return this[0];
2535
+ }
2536
+ set phi(value) {
2537
+ this[0] = checkNumber(value);
2538
+ }
2539
+ get theta() {
2540
+ return this[1];
2541
+ }
2542
+ set theta(value) {
2543
+ this[1] = checkNumber(value);
2544
+ }
2545
+ get psi() {
2546
+ return this[2];
2547
+ }
2548
+ set psi(value) {
2549
+ this[2] = checkNumber(value);
2550
+ }
2551
+ // roll, pitch, yaw angle notation
2552
+ get roll() {
2553
+ return this[0];
2554
+ }
2555
+ set roll(value) {
2556
+ this[0] = checkNumber(value);
2557
+ }
2558
+ get pitch() {
2559
+ return this[1];
2560
+ }
2561
+ set pitch(value) {
2562
+ this[1] = checkNumber(value);
2563
+ }
2564
+ get yaw() {
2565
+ return this[2];
2566
+ }
2567
+ set yaw(value) {
2568
+ this[2] = checkNumber(value);
2569
+ }
2570
+ // rotation order, in all three angle notations
2571
+ get order() {
2572
+ return this[3];
2573
+ }
2574
+ set order(value) {
2575
+ this[3] = checkOrder(value);
2576
+ }
2577
+ // Constructors
2578
+ fromVector3(v, order) {
2579
+ return this.set(v[0], v[1], v[2], Number.isFinite(order) ? order : this[3]);
2580
+ }
2581
+ // TODO - with and without 4th element
2582
+ fromArray(array, offset = 0) {
2583
+ this[0] = array[0 + offset];
2584
+ this[1] = array[1 + offset];
2585
+ this[2] = array[2 + offset];
2586
+ if (array[3] !== undefined) {
2587
+ this[3] = array[3];
2588
+ }
2589
+ return this.check();
2590
+ }
2591
+ // Common ZYX rotation order
2592
+ fromRollPitchYaw(roll, pitch, yaw) {
2593
+ return this.set(roll, pitch, yaw, RotationOrder.ZYX);
2594
+ }
2595
+ fromRotationMatrix(m, order = Euler.DefaultOrder) {
2596
+ this._fromRotationMatrix(m, order);
2597
+ return this.check();
2598
+ }
2599
+ // ACCESSORS
2600
+ getRotationMatrix(m) {
2601
+ return this._getRotationMatrix(m);
2602
+ }
2603
+ // TODO - move to Quaternion
2604
+ getQuaternion() {
2605
+ const q = new Quaternion();
2606
+ switch (this[3]) {
2607
+ case RotationOrder.XYZ:
2608
+ return q.rotateX(this[0]).rotateY(this[1]).rotateZ(this[2]);
2609
+ case RotationOrder.YXZ:
2610
+ return q.rotateY(this[0]).rotateX(this[1]).rotateZ(this[2]);
2611
+ case RotationOrder.ZXY:
2612
+ return q.rotateZ(this[0]).rotateX(this[1]).rotateY(this[2]);
2613
+ case RotationOrder.ZYX:
2614
+ return q.rotateZ(this[0]).rotateY(this[1]).rotateX(this[2]);
2615
+ case RotationOrder.YZX:
2616
+ return q.rotateY(this[0]).rotateZ(this[1]).rotateX(this[2]);
2617
+ case RotationOrder.XZY:
2618
+ return q.rotateX(this[0]).rotateZ(this[1]).rotateY(this[2]);
2619
+ default:
2620
+ throw new Error(ERR_UNKNOWN_ORDER);
2621
+ }
2622
+ }
2623
+ // INTERNAL METHODS
2624
+ // Conversion from Euler to rotation matrix and from matrix to Euler
2625
+ // Adapted from three.js under MIT license
2626
+ // // WARNING: this discards revolution information -bhouston
2627
+ // reorder(newOrder) {
2628
+ // const q = new Quaternion().setFromEuler(this);
2629
+ // return this.setFromQuaternion(q, newOrder);
2630
+ /* eslint-disable complexity, max-statements, one-var */
2631
+ _fromRotationMatrix(m, order = Euler.DefaultOrder) {
2632
+ // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
2633
+ const m11 = m[0], m12 = m[4], m13 = m[8];
2634
+ const m21 = m[1], m22 = m[5], m23 = m[9];
2635
+ const m31 = m[2], m32 = m[6], m33 = m[10];
2636
+ order = order || this[3];
2637
+ switch (order) {
2638
+ case Euler.XYZ:
2639
+ this[1] = Math.asin(clamp(m13, -1, 1));
2640
+ if (Math.abs(m13) < ALMOST_ONE) {
2641
+ this[0] = Math.atan2(-m23, m33);
2642
+ this[2] = Math.atan2(-m12, m11);
2643
+ }
2644
+ else {
2645
+ this[0] = Math.atan2(m32, m22);
2646
+ this[2] = 0;
2647
+ }
2648
+ break;
2649
+ case Euler.YXZ:
2650
+ this[0] = Math.asin(-clamp(m23, -1, 1));
2651
+ if (Math.abs(m23) < ALMOST_ONE) {
2652
+ this[1] = Math.atan2(m13, m33);
2653
+ this[2] = Math.atan2(m21, m22);
2654
+ }
2655
+ else {
2656
+ this[1] = Math.atan2(-m31, m11);
2657
+ this[2] = 0;
2658
+ }
2659
+ break;
2660
+ case Euler.ZXY:
2661
+ this[0] = Math.asin(clamp(m32, -1, 1));
2662
+ if (Math.abs(m32) < ALMOST_ONE) {
2663
+ this[1] = Math.atan2(-m31, m33);
2664
+ this[2] = Math.atan2(-m12, m22);
2665
+ }
2666
+ else {
2667
+ this[1] = 0;
2668
+ this[2] = Math.atan2(m21, m11);
2669
+ }
2670
+ break;
2671
+ case Euler.ZYX:
2672
+ this[1] = Math.asin(-clamp(m31, -1, 1));
2673
+ if (Math.abs(m31) < ALMOST_ONE) {
2674
+ this[0] = Math.atan2(m32, m33);
2675
+ this[2] = Math.atan2(m21, m11);
2676
+ }
2677
+ else {
2678
+ this[0] = 0;
2679
+ this[2] = Math.atan2(-m12, m22);
2680
+ }
2681
+ break;
2682
+ case Euler.YZX:
2683
+ this[2] = Math.asin(clamp(m21, -1, 1));
2684
+ if (Math.abs(m21) < ALMOST_ONE) {
2685
+ this[0] = Math.atan2(-m23, m22);
2686
+ this[1] = Math.atan2(-m31, m11);
2687
+ }
2688
+ else {
2689
+ this[0] = 0;
2690
+ this[1] = Math.atan2(m13, m33);
2691
+ }
2692
+ break;
2693
+ case Euler.XZY:
2694
+ this[2] = Math.asin(-clamp(m12, -1, 1));
2695
+ if (Math.abs(m12) < ALMOST_ONE) {
2696
+ this[0] = Math.atan2(m32, m22);
2697
+ this[1] = Math.atan2(m13, m11);
2698
+ }
2699
+ else {
2700
+ this[0] = Math.atan2(-m23, m33);
2701
+ this[1] = 0;
2702
+ }
2703
+ break;
2704
+ default:
2705
+ throw new Error(ERR_UNKNOWN_ORDER);
2706
+ }
2707
+ this[3] = order;
2708
+ return this;
2709
+ }
2710
+ _getRotationMatrix(result) {
2711
+ const te = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
2712
+ const x = this.x, y = this.y, z = this.z;
2713
+ const a = Math.cos(x);
2714
+ const c = Math.cos(y);
2715
+ const e = Math.cos(z);
2716
+ const b = Math.sin(x);
2717
+ const d = Math.sin(y);
2718
+ const f = Math.sin(z);
2719
+ switch (this[3]) {
2720
+ case Euler.XYZ: {
2721
+ const ae = a * e, af = a * f, be = b * e, bf = b * f;
2722
+ te[0] = c * e;
2723
+ te[4] = -c * f;
2724
+ te[8] = d;
2725
+ te[1] = af + be * d;
2726
+ te[5] = ae - bf * d;
2727
+ te[9] = -b * c;
2728
+ te[2] = bf - ae * d;
2729
+ te[6] = be + af * d;
2730
+ te[10] = a * c;
2731
+ break;
2732
+ }
2733
+ case Euler.YXZ: {
2734
+ const ce = c * e, cf = c * f, de = d * e, df = d * f;
2735
+ te[0] = ce + df * b;
2736
+ te[4] = de * b - cf;
2737
+ te[8] = a * d;
2738
+ te[1] = a * f;
2739
+ te[5] = a * e;
2740
+ te[9] = -b;
2741
+ te[2] = cf * b - de;
2742
+ te[6] = df + ce * b;
2743
+ te[10] = a * c;
2744
+ break;
2745
+ }
2746
+ case Euler.ZXY: {
2747
+ const ce = c * e, cf = c * f, de = d * e, df = d * f;
2748
+ te[0] = ce - df * b;
2749
+ te[4] = -a * f;
2750
+ te[8] = de + cf * b;
2751
+ te[1] = cf + de * b;
2752
+ te[5] = a * e;
2753
+ te[9] = df - ce * b;
2754
+ te[2] = -a * d;
2755
+ te[6] = b;
2756
+ te[10] = a * c;
2757
+ break;
2758
+ }
2759
+ case Euler.ZYX: {
2760
+ const ae = a * e, af = a * f, be = b * e, bf = b * f;
2761
+ te[0] = c * e;
2762
+ te[4] = be * d - af;
2763
+ te[8] = ae * d + bf;
2764
+ te[1] = c * f;
2765
+ te[5] = bf * d + ae;
2766
+ te[9] = af * d - be;
2767
+ te[2] = -d;
2768
+ te[6] = b * c;
2769
+ te[10] = a * c;
2770
+ break;
2771
+ }
2772
+ case Euler.YZX: {
2773
+ const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
2774
+ te[0] = c * e;
2775
+ te[4] = bd - ac * f;
2776
+ te[8] = bc * f + ad;
2777
+ te[1] = f;
2778
+ te[5] = a * e;
2779
+ te[9] = -b * e;
2780
+ te[2] = -d * e;
2781
+ te[6] = ad * f + bc;
2782
+ te[10] = ac - bd * f;
2783
+ break;
2784
+ }
2785
+ case Euler.XZY: {
2786
+ const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
2787
+ te[0] = c * e;
2788
+ te[4] = -f;
2789
+ te[8] = d * e;
2790
+ te[1] = ac * f + bd;
2791
+ te[5] = a * e;
2792
+ te[9] = ad * f - bc;
2793
+ te[2] = bc * f - ad;
2794
+ te[6] = b * e;
2795
+ te[10] = bd * f + ac;
2796
+ break;
2797
+ }
2798
+ default:
2799
+ throw new Error(ERR_UNKNOWN_ORDER);
2800
+ }
2801
+ // last column
2802
+ te[3] = 0;
2803
+ te[7] = 0;
2804
+ te[11] = 0;
2805
+ // bottom row
2806
+ te[12] = 0;
2807
+ te[13] = 0;
2808
+ te[14] = 0;
2809
+ te[15] = 1;
2810
+ return te;
2811
+ }
2812
+ toQuaternion() {
2813
+ // Abbreviations for the various angular functions
2814
+ const cy = Math.cos(this.yaw * 0.5);
2815
+ const sy = Math.sin(this.yaw * 0.5);
2816
+ const cr = Math.cos(this.roll * 0.5);
2817
+ const sr = Math.sin(this.roll * 0.5);
2818
+ const cp = Math.cos(this.pitch * 0.5);
2819
+ const sp = Math.sin(this.pitch * 0.5);
2820
+ const w = cy * cr * cp + sy * sr * sp;
2821
+ const x = cy * sr * cp - sy * cr * sp;
2822
+ const y = cy * cr * sp + sy * sr * cp;
2823
+ const z = sy * cr * cp - cy * sr * sp;
2824
+ return new Quaternion(x, y, z, w);
2825
+ }
2826
+ }
2827
+ // HELPER FUNCTIONS
2828
+ function validateOrder(value) {
2829
+ return value >= 0 && value < 6;
2830
+ }
2831
+ function checkOrder(value) {
2832
+ if (value < 0 && value >= 6) {
2833
+ throw new Error(ERR_UNKNOWN_ORDER);
2834
+ }
2835
+ return value;
2836
+ }
2837
+
2838
+ /**
2839
+ * 变换模块,提供变换相关的类和功能
2840
+ * 用于表示对象的位置、旋转和缩放信息
2841
+ */
2842
+ /**
2843
+ * 变换基类,用于表示对象的位置、旋转和缩放
2844
+ */
2845
+ class OTransform {
2846
+ /**
2847
+ * 构造函数
2848
+ * @param position 位置向量
2849
+ * @param rotation 旋转欧拉角
2850
+ * @param scale 缩放向量
2851
+ */
2852
+ constructor(position, rotation, scale) {
2853
+ this.position = position;
2854
+ this.rotation = rotation;
2855
+ this.scale = scale;
2856
+ }
2857
+ /**
2858
+ * 创建默认的变换对象
2859
+ * @param params 可选参数对象
2860
+ * @param params.position 位置向量,默认值为新的Vector3实例
2861
+ * @param params.rotation 旋转欧拉角,默认值为新的Euler实例
2862
+ * @param params.scale 缩放向量,默认值为Vector3(1, 1, 1)
2863
+ * @returns 默认的变换对象
2864
+ */
2865
+ static default(params) {
2866
+ return new OTransform(params?.position || new Vector3(), params?.rotation || new Euler(), params?.scale || new Vector3(1, 1, 1));
2867
+ }
2868
+ }
2869
+ /**
2870
+ * 变换类,继承自OTransform,用于表示带有标识符的变换对象
2871
+ */
2872
+ class Transform extends OTransform {
2873
+ /**
2874
+ * 构造函数
2875
+
2876
+ * @param position 位置向量
2877
+ * @param rotation 旋转欧拉角
2878
+ * @param scale 缩放向量
2879
+ */
2880
+ constructor(position, rotation, scale) {
2881
+ super(position, rotation, scale);
2882
+ }
2883
+ toRPCJSON() {
2884
+ return {
2885
+ Location: {
2886
+ X: this.position.x,
2887
+ Y: this.position.y,
2888
+ Z: this.position.z
2889
+ },
2890
+ Rotation: {
2891
+ Pitch: this.rotation.pitch,
2892
+ Yaw: this.rotation.yaw,
2893
+ Roll: this.rotation.roll
2894
+ },
2895
+ Scale: {
2896
+ X: this.scale.x,
2897
+ Y: this.scale.y,
2898
+ Z: this.scale.z
2899
+ }
2900
+ };
2901
+ }
2902
+ /**
2903
+ * 创建默认的变换对象
2904
+ * @param handle 变换对象的唯一标识符
2905
+ * @returns 默认的变换对象
2906
+ */
2907
+ static default() {
2908
+ return new Transform(new Vector3(), new Euler(), new Vector3(1, 1, 1));
2909
+ }
2910
+ static fromRPCObject(obj) {
2911
+ return new Transform(obj.Location
2912
+ ? new Vector3(obj.Location.X, obj.Location.Y, obj.Location.Z)
2913
+ : new Vector3(), obj.Rotation
2914
+ ? new Euler(obj.Rotation.Pitch, obj.Rotation.Yaw, obj.Rotation.Roll)
2915
+ : new Euler(), obj.Scale
2916
+ ? new Vector3(obj.Scale.X, obj.Scale.Y, obj.Scale.Z)
2917
+ : new Vector3(1, 1, 1));
2918
+ }
2919
+ }
2920
+
2921
+ /**
2922
+ * 节点基类模块,提供节点树的基础实现
2923
+ * 用于表示场景中的对象,支持父子关系、变换和数据存储
2924
+ */
2925
+ /**
2926
+ * 节点基类,用于表示场景中的对象
2927
+ * 支持父子关系、变换、数据存储和节点查找
2928
+ * @template T 节点数据类型
2929
+ */
2930
+ class Node {
2931
+ /**
2932
+ * 构造函数
2933
+ * @param key 节点唯一标识符
2934
+ * @param data 节点附加数据
2935
+ * @param transform 节点变换信息
2936
+ */
2937
+ constructor(key, data, transform) {
2938
+ this._children = [];
2939
+ this._key = key;
2940
+ this.isRoot = true;
2941
+ this.data = data;
2942
+ if (transform) {
2943
+ this._transform = new OTransform(new Vector3(), new Euler(), new Vector3(1, 1, 1));
2944
+ }
2945
+ else {
2946
+ this._transform = OTransform.default();
2947
+ }
2948
+ }
2949
+ /**
2950
+ * 获取节点唯一标识符
2951
+ */
2952
+ get key() {
2953
+ return this._key;
2954
+ }
2955
+ /**
2956
+ * 获取节点变换信息
2957
+ */
2958
+ get transform() {
2959
+ return this._transform;
2960
+ }
2961
+ /**
2962
+ * 获取子节点列表
2963
+ */
2964
+ get children() {
2965
+ return this._children;
2966
+ }
2967
+ /**
2968
+ * 添加子节点
2969
+ * @param child 要添加的子节点
2970
+ */
2971
+ add(child) {
2972
+ // this.children.push(child)
2973
+ child.parent = this;
2974
+ this._children.push(child);
2975
+ child.isRoot = false;
2976
+ }
2977
+ /**
2978
+ * 脱离父节点
2979
+ */
2980
+ detach() {
2981
+ if (this.parent) {
2982
+ this.parent.removeChild(this);
2983
+ }
2984
+ this.isRoot = true;
2985
+ }
2986
+ remove() {
2987
+ if (this.parent) {
2988
+ this.detach();
2989
+ }
2990
+ }
2991
+ /**
2992
+ * 移除子节点
2993
+ * @param child 要移除的子节点
2994
+ */
2995
+ removeChild(child) {
2996
+ child.parent = undefined;
2997
+ let index = this._children.findIndex((c) => c !== child);
2998
+ if (index > -1) {
2999
+ this._children.splice(index, 1);
3000
+ }
3001
+ }
3002
+ /**
3003
+ * 根据key查找子节点
3004
+ * @param key 要查找的节点key
3005
+ * @returns 找到的节点或undefined
3006
+ */
3007
+ findChild(key) {
3008
+ if (this.key === key) {
3009
+ return this;
3010
+ }
3011
+ for (let i = 0; i < this._children.length; i++) {
3012
+ let child = this._children[i];
3013
+ let found = child.findChild(key);
3014
+ if (found) {
3015
+ return found;
3016
+ }
3017
+ }
3018
+ }
3019
+ }
3020
+
3021
+ /**
3022
+ * 代理模块,提供深度代理和变动收集功能
3023
+ * 用于跟踪对象的属性变化并在事件循环结束后统一处理
3024
+ */
3025
+ /**
3026
+ * 收集器类,用于收集对象变动并在事件循环结束后触发回调
3027
+ */
3028
+ class Collector {
3029
+ /**
3030
+ * 创建收集器实例
3031
+ * @param callback 变动回调函数,在事件循环结束后调用
3032
+ */
3033
+ constructor(callback) {
3034
+ /**
3035
+ * 收集到的变动列表
3036
+ */
3037
+ this.changes = [];
3038
+ /**
3039
+ * 标志位,用于确保只有一个 setTimeout 在运行
3040
+ */
3041
+ this.isTimeoutSet = false;
3042
+ this.callback = callback;
3043
+ }
3044
+ /**
3045
+ * 添加变动
3046
+ * @param change 变动对象
3047
+ */
3048
+ addChange(change) {
3049
+ this.changes.push(change);
3050
+ this.scheduleCallback();
3051
+ }
3052
+ /**
3053
+ * 调度回调函数,确保在事件循环结束后执行
3054
+ */
3055
+ scheduleCallback() {
3056
+ if (!this.isTimeoutSet) {
3057
+ this.isTimeoutSet = true;
3058
+ // setTimeout(() => {
3059
+ Promise.resolve().then(() => this.triggerCallback());
3060
+ // }, 0);
3061
+ }
3062
+ }
3063
+ /**
3064
+ * 触发回调函数
3065
+ */
3066
+ triggerCallback() {
3067
+ if (this.changes.length > 0) {
3068
+ this.callback([...this.changes]); // 传递变动的副本
3069
+ this.changes = []; // 清空变动列表
3070
+ }
3071
+ this.isTimeoutSet = false;
3072
+ }
3073
+ }
3074
+ /**
3075
+ * 创建深度代理,递归地为对象及其所有子对象创建 Proxy
3076
+ * @param target 要代理的目标对象
3077
+ * @param handler 自定义处理器
3078
+ * @param collector 变动收集器,用于收集对象变动
3079
+ * @returns 代理后的对象
3080
+ */
3081
+ function createDeepProxy(target, handler = {}, collector) {
3082
+ // 递归创建 Proxy 的核心函数
3083
+ const proxyHandler = {
3084
+ // 拦截属性读取
3085
+ get(target, prop, receiver) {
3086
+ // 先调用自定义 handler 的 get(如果有)
3087
+ if (handler.get) {
3088
+ handler.get(target, prop, receiver);
3089
+ }
3090
+ // 获取属性值
3091
+ const result = Reflect.get(target, prop, receiver);
3092
+ // 如果读取的属性是对象/数组且不是 null,递归创建 Proxy
3093
+ if (result !== null &&
3094
+ (typeof result === 'object' || Array.isArray(result))) {
3095
+ return createDeepProxy(result, handler, collector);
3096
+ }
3097
+ return result;
3098
+ },
3099
+ // 拦截属性赋值
3100
+ set(target, prop, value, receiver) {
3101
+ // 先调用自定义 handler 的 set(如果有)
3102
+ if (handler.set) {
3103
+ handler.set(target, prop, value, receiver);
3104
+ }
3105
+ // 赋值时,如果新值是对象/数组,也需要代理
3106
+ const newValue = value !== null && (typeof value === 'object' || Array.isArray(value))
3107
+ ? createDeepProxy(value, handler, collector)
3108
+ : value;
3109
+ // 如果有收集器,收集变动
3110
+ if (collector) {
3111
+ collector.addChange({
3112
+ target,
3113
+ prop,
3114
+ value: newValue,
3115
+ type: 'set'
3116
+ });
3117
+ }
3118
+ return Reflect.set(target, prop, newValue, receiver);
3119
+ },
3120
+ // 拦截属性删除
3121
+ deleteProperty(target, prop) {
3122
+ // 先调用自定义 handler 的 deleteProperty(如果有)
3123
+ if (handler.deleteProperty) {
3124
+ handler.deleteProperty(target, prop);
3125
+ }
3126
+ // 如果有收集器,收集变动
3127
+ if (collector) {
3128
+ collector.addChange({
3129
+ target,
3130
+ prop,
3131
+ value: undefined,
3132
+ type: 'delete'
3133
+ });
3134
+ }
3135
+ return Reflect.deleteProperty(target, prop);
3136
+ },
3137
+ // 可选:拦截其他操作(如 has 等)
3138
+ ...handler // 合并自定义 handler 的其他拦截器
3139
+ };
3140
+ // 为目标对象创建 Proxy
3141
+ return new Proxy(target, proxyHandler);
3142
+ }
3143
+
3144
+ /**
3145
+ * 资源类型枚举,用于标识不同类型的资源
3146
+ */
3147
+ var AssetType;
3148
+ (function (AssetType) {
3149
+ /** 其他类型资源 */
3150
+ AssetType["Other"] = "other";
3151
+ /** 地图资源 */
3152
+ AssetType["Map"] = "map";
3153
+ /** 蓝图资源 */
3154
+ AssetType["Blueprint"] = "blueprint";
3155
+ /** 静态网格资源 */
3156
+ AssetType["StaticMesh"] = "static_mesh";
3157
+ /** 骨骼网格资源 */
3158
+ AssetType["SkeletalMesh"] = "skeletal_mesh";
3159
+ })(AssetType || (AssetType = {}));
3160
+ /**
3161
+ * UE RPC 节点类,继承自 Node,用于与 Unreal Engine 通信
3162
+ * 支持变换同步、远程更新和子节点管理
3163
+ */
3164
+ class UERPCNode extends Node {
3165
+ /**
3166
+ * 构造函数
3167
+ * @param rpc RPC 通信实例
3168
+ * @param key 节点唯一标识符
3169
+ * @param data 节点数据
3170
+ * @param transform 节点变换信息
3171
+ */
3172
+ constructor(rpc, key, data, transform, tag) {
3173
+ super(key, data);
3174
+ this._rpc = rpc;
3175
+ if (transform) {
3176
+ this._transform = transform;
3177
+ }
3178
+ else {
3179
+ this._transform = Transform.default();
3180
+ }
3181
+ this._remoteUpdateFlag = false;
3182
+ this._collector = new Collector(this._triggerRemoteUpdate.bind(this));
3183
+ this.tag = tag;
3184
+ }
3185
+ /**
3186
+ * 获取变换信息的深度代理,用于跟踪属性变化
3187
+ */
3188
+ get transform() {
3189
+ return createDeepProxy(this._transform, {}, this._collector);
3190
+ }
3191
+ set transform(transform) {
3192
+ this._transform = transform;
3193
+ this._triggerRemoteUpdate();
3194
+ }
3195
+ /**
3196
+ * 添加子节点
3197
+ * @param child 要添加的子节点
3198
+ * @throws 非根节点添加子节点时抛出错误
3199
+ */
3200
+ add(child) {
3201
+ // throw new Error("UERPCNode can't add child")
3202
+ if (this.isRoot) {
3203
+ super.add(child);
3204
+ child.world = this.world;
3205
+ }
3206
+ else {
3207
+ throw new Error("UERPCNode can't add child , except root node");
3208
+ }
3209
+ }
3210
+ __dangerousRawAdd(child) {
3211
+ super.add(child);
3212
+ }
3213
+ /**
3214
+ * 脱离父节点
3215
+ */
3216
+ async detach() {
3217
+ super.detach();
3218
+ }
3219
+ async remove() {
3220
+ super.remove();
3221
+ await this._rpc.destroyActorByHandle(this.key);
3222
+ }
3223
+ /**
3224
+ * 移除子节点
3225
+ * @param child 要移除的子节点
3226
+ */
3227
+ async removeChild(child) {
3228
+ super.removeChild(child);
3229
+ await this._rpc.destroyActorByHandle(this.key);
3230
+ }
3231
+ _triggerRemoteUpdate() {
3232
+ if (!this._remoteUpdateFlag) {
3233
+ this._remoteUpdateFlag = true;
3234
+ Promise.resolve().then(() => this._remoteUpdate());
3235
+ }
3236
+ }
3237
+ /**
3238
+ * 远程更新节点变换到 UE
3239
+ * 向 UE 发送变换数据,更新 Actor 的位置、旋转和缩放
3240
+ */
3241
+ _remoteUpdate() {
3242
+ this._rpc.setActorTransformByHandle(this.key, this.transform.toRPCJSON());
3243
+ this._remoteUpdateFlag = false;
3244
+ }
3245
+ }
3246
+
3247
+ class Tool {
3248
+ constructor(rpc) {
3249
+ this._rpc = rpc;
3250
+ }
3251
+ excute(params) {
3252
+ throw new Error('Method not implemented.');
3253
+ }
3254
+ }
3255
+
3256
+ const maxView4K = (width, height) => {
3257
+ const maxWidth = 3840;
3258
+ const maxHeight = 2160;
3259
+ // 如果宽或高任一超过4K限制
3260
+ if (width > maxWidth || height > maxHeight) {
3261
+ const ratio = Math.min(maxWidth / width, maxHeight / height);
3262
+ return {
3263
+ width: Math.ceil(width * ratio),
3264
+ height: Math.ceil(height * ratio)
3265
+ };
3266
+ }
3267
+ // 未超过限制,返回原尺寸
3268
+ return { width, height };
3269
+ };
3270
+ class MatchView extends Tool {
3271
+ constructor(rpc) {
3272
+ super(rpc);
3273
+ }
3274
+ excute() {
3275
+ this._rpc.emitCommand({
3276
+ Command: 'MatchView',
3277
+ 'Resolution.Width': maxView4K(window.innerWidth, window.innerHeight)
3278
+ .width,
3279
+ 'Resolution.Height': maxView4K(window.innerWidth, window.innerHeight)
3280
+ .height
3281
+ });
3282
+ }
3283
+ }
3284
+
3285
+ /**
3286
+ * 天气类型枚举,定义了不同的天气状态
3287
+ */
3288
+ var WeatherType;
3289
+ (function (WeatherType) {
3290
+ /** 晴天 */
3291
+ WeatherType["SUNNY"] = "Sunny";
3292
+ /** 雾天 */
3293
+ WeatherType["Foggy"] = "Foggy";
3294
+ /** 雨天 */
3295
+ WeatherType["RAIN"] = "Rain";
3296
+ /** 雪天 */
3297
+ WeatherType["SNOW"] = "Snow";
3298
+ })(WeatherType || (WeatherType = {}));
3299
+ /**
3300
+ * 天气类,用于管理和控制场景中的天气
3301
+ */
3302
+ class Weather {
3303
+ /**
3304
+ * 构造函数
3305
+ */
3306
+ constructor(rpc) {
3307
+ this._rpc = rpc;
3308
+ }
3309
+ /**
3310
+ * 设置天气类型
3311
+ * @param type 天气类型
3312
+ */
3313
+ async setWeather(type) {
3314
+ return this._rpc.callModule('Enviorment', 'SetWeather', {
3315
+ Preset: type
3316
+ });
3317
+ }
3318
+ }
3319
+
3320
+ /**
3321
+ * 防抖函数 - 延迟执行函数,直到停止调用一段时间后才执行
3322
+ * @param func 要执行的函数
3323
+ * @param wait 等待时间(毫秒)
3324
+ * @param immediate 是否立即执行
3325
+ * @returns 防抖处理后的函数
3326
+ */
3327
+ /**
3328
+ * 节流函数 - 限制函数在一定时间内只能执行一次
3329
+ * @param func 要执行的函数
3330
+ * @param limit 时间限制(毫秒)
3331
+ * @returns 节流处理后的函数
3332
+ */
3333
+ function throttle(func, limit) {
3334
+ let inThrottle = false;
3335
+ return function (...args) {
3336
+ const context = this;
3337
+ if (!inThrottle) {
3338
+ func.apply(context, args);
3339
+ inThrottle = true;
3340
+ setTimeout(() => (inThrottle = false), limit);
3341
+ }
3342
+ };
3343
+ }
3344
+
3345
+ class PickCast extends Tool {
3346
+ constructor(rpc) {
3347
+ super(rpc);
3348
+ }
3349
+ hover(callback, maxDistance = 1000000, highlight = false) {
3350
+ let stream = this._rpc.getStream();
3351
+ let videoElementParent = stream.videoElementParent;
3352
+ const onMousemove = throttle(async (event) => {
3353
+ // console.log(event)
3354
+ const offsetX = event.offsetX;
3355
+ const offsetY = event.offsetY;
3356
+ let response = await this._rpc.pickPointByScreen(offsetX, offsetY, maxDistance, highlight);
3357
+ callback && callback(response);
3358
+ }, 50);
3359
+ videoElementParent.addEventListener('mousemove', onMousemove);
3360
+ return function finish() {
3361
+ videoElementParent.removeEventListener('mousemove', onMousemove);
3362
+ };
3363
+ }
3364
+ pick(callback, maxDistance = 1000000, highlight = true) {
3365
+ let videoElementParent = this._rpc.getStream().videoElementParent;
3366
+ let rpc = this._rpc;
3367
+ async function onPick(event) {
3368
+ const offsetX = event.offsetX;
3369
+ const offsetY = event.offsetY;
3370
+ let response = await rpc.pickPointByScreen(offsetX, offsetY, maxDistance, highlight);
3371
+ callback && callback(response);
3372
+ }
3373
+ videoElementParent.addEventListener('click', onPick);
3374
+ return function finish() {
3375
+ videoElementParent.removeEventListener('click', onPick);
3376
+ };
3377
+ }
3378
+ }
3379
+
3380
+ /**
3381
+ * 热力图工具类,用于创建热力图
3382
+ */
3383
+ class HeatMap extends Tool {
3384
+ constructor(rpc, world) {
3385
+ super(rpc);
3386
+ this._world = world;
3387
+ }
3388
+ async create(params) {
3389
+ let _transform = params.transform || Transform.default();
3390
+ let response = await this._rpc.callModule('HeatMap', 'Create', {
3391
+ url: params.url,
3392
+ X: _transform.position.x,
3393
+ Y: _transform.position.y,
3394
+ Z: _transform.position.z,
3395
+ ScaleX: _transform.scale.x,
3396
+ ScaleY: _transform.scale.y,
3397
+ ScaleZ: _transform.scale.z,
3398
+ Pitch: _transform.rotation.pitch,
3399
+ Yaw: _transform.rotation.yaw,
3400
+ Roll: _transform.rotation.roll,
3401
+ Tag: params.tag,
3402
+ MeshSize: params.meshSize,
3403
+ MeshSegment: params.meshSegment,
3404
+ LerpScale: params.lerpScale,
3405
+ Opacity: params.opacity,
3406
+ HeightScale: params.heightScale,
3407
+ ZeroValueOpacity: params.zeroValueOpacity,
3408
+ InfluenceSize: params.influenceSize,
3409
+ EmissiveStrength: params.emissiveStrength,
3410
+ HeatMapPoints: params.heatMapPoints
3411
+ });
3412
+ let _node = new UERPCNode(this._rpc, response.Handle, {
3413
+ assetType: AssetType.Other
3414
+ }, _transform, params.tag);
3415
+ this._world.root.__dangerousRawAdd(_node);
3416
+ return _node;
3417
+ }
3418
+ }
3419
+
3420
+ class Scatter extends Tool {
3421
+ constructor(rpc) {
3422
+ super(rpc);
3423
+ }
3424
+ async create(params) {
3425
+ let response = await this._rpc.callModule('Point', 'Create', {
3426
+ WidgetSpace: params.widgetSpace,
3427
+ PointParams: params.pointParams.map((item) => {
3428
+ return {
3429
+ Id: item.id,
3430
+ Location: item.location,
3431
+ Rotation: item.rotation,
3432
+ Scale: item.scale,
3433
+ Tag: item.tag,
3434
+ TextContent: item.textContent
3435
+ };
3436
+ })
3437
+ });
3438
+ let _params = [];
3439
+ for (let i = 0; i < response.CreatedIDs.length; i++) {
3440
+ let id = response.CreatedIDs[i];
3441
+ let param = params.pointParams[i];
3442
+ _params.push({
3443
+ ...param,
3444
+ id
3445
+ });
3446
+ }
3447
+ return createScatterGroupHandler(this._rpc, _params);
3448
+ }
3449
+ }
3450
+ class ScatterGroupHandler {
3451
+ get pointsMap() {
3452
+ return this.children.reduce((acc, cur) => {
3453
+ acc[cur.id] = cur;
3454
+ return acc;
3455
+ }, {});
3456
+ }
3457
+ get tagMap() {
3458
+ return this.children.reduce((acc, cur) => {
3459
+ if (!acc[cur.tag]) {
3460
+ acc[cur.tag] = [];
3461
+ }
3462
+ acc[cur.tag].push(cur);
3463
+ return acc;
3464
+ }, {});
3465
+ }
3466
+ constructor(rpc) {
3467
+ this.children = [];
3468
+ this._rpc = rpc;
3469
+ }
3470
+ getById(id) {
3471
+ return this.pointsMap[id];
3472
+ }
3473
+ async removeById(id) {
3474
+ let handle = this.getById(id);
3475
+ if (handle) {
3476
+ this.children = this.children.filter((child) => child.id !== id);
3477
+ handle.group = undefined;
3478
+ await handle.remove();
3479
+ }
3480
+ }
3481
+ async removeAll() {
3482
+ let childrenIds = this.children.map((child) => child.id);
3483
+ this.children = [];
3484
+ await this._rpc.callModule('Point', 'DeleteByIds', {
3485
+ PointParams: childrenIds.map((item) => {
3486
+ return {
3487
+ Id: item
3488
+ };
3489
+ })
3490
+ });
3491
+ }
3492
+ async removeByTag(tag) {
3493
+ let childrenIds = this.tagMap[tag].map((child) => child.id);
3494
+ this.children = this.children.filter((child) => child.tag !== tag);
3495
+ await this._rpc.callModule('Point', 'DeleteByIds', {
3496
+ PointParams: childrenIds.map((item) => {
3497
+ return {
3498
+ Id: item
3499
+ };
3500
+ })
3501
+ });
3502
+ }
3503
+ }
3504
+ class PointHandler {
3505
+ constructor(id, params) {
3506
+ this._id = id;
3507
+ this._rpc = params.rpc;
3508
+ this._transform = params.transform || Transform.default();
3509
+ this._textContent = params.textContent;
3510
+ this._tag = params.tag || '';
3511
+ this._remoteUpdateFlag = false;
3512
+ this._collector = new Collector(this._triggerRemoteUpdate.bind(this));
3513
+ this.group = params.group;
3514
+ }
3515
+ get tag() {
3516
+ return this._tag;
3517
+ }
3518
+ get id() {
3519
+ return this._id;
3520
+ }
3521
+ get transform() {
3522
+ return createDeepProxy(this._transform, {}, this._collector);
3523
+ }
3524
+ get textContent() {
3525
+ return this._textContent;
3526
+ }
3527
+ set textContent(value) {
3528
+ this._textContent = value;
3529
+ this._triggerRemoteUpdate();
3530
+ }
3531
+ _triggerRemoteUpdate() {
3532
+ if (!this._remoteUpdateFlag) {
3533
+ this._remoteUpdateFlag = true;
3534
+ this.remoteUpdate();
3535
+ }
3536
+ }
3537
+ remoteUpdate() {
3538
+ let transformObj = this.transform.toRPCJSON();
3539
+ this._rpc.callModule('Point', 'Update', {
3540
+ PointParams: [
3541
+ {
3542
+ Id: this.id,
3543
+ textContent: this.textContent,
3544
+ Location: transformObj.Location,
3545
+ Rotation: transformObj.Rotation,
3546
+ Scale: transformObj.Scale
3547
+ }
3548
+ ]
3549
+ });
3550
+ this._remoteUpdateFlag = false;
3551
+ }
3552
+ async remove() {
3553
+ if (this.group) {
3554
+ // this.group = undefined
3555
+ return this.group.removeById(this.id);
3556
+ }
3557
+ await this._rpc.callModule('Point', 'DeleteByIds', {
3558
+ IDs: [this.id]
3559
+ });
3560
+ }
3561
+ }
3562
+ function createScatterGroupHandler(rpc, params) {
3563
+ let scatterhandler = new ScatterGroupHandler(rpc);
3564
+ let phandler = params.map((param) => createPointHandler(rpc, {
3565
+ ...param
3566
+ }, scatterhandler));
3567
+ scatterhandler.children = phandler;
3568
+ return scatterhandler;
3569
+ }
3570
+ function createPointHandler(rpc, param, group) {
3571
+ // return new PointHandlerQuery()
3572
+ let handler = new PointHandler(param.id, {
3573
+ rpc,
3574
+ transform: Transform.fromRPCObject({}),
3575
+ textContent: param.textContent,
3576
+ tag: param.tag,
3577
+ group: group
3578
+ });
3579
+ return handler;
3580
+ }
3581
+
3582
+ /**
3583
+ * 围栏工具类,用于创建和删除电子围栏
3584
+ */
3585
+ class Fence extends Tool {
3586
+ constructor(rpc) {
3587
+ super(rpc);
3588
+ }
3589
+ async create(params) {
3590
+ let response = this._rpc.callModule('Box', 'Create', {
3591
+ VectorArray: params.vectorArray,
3592
+ Height: params.height,
3593
+ MaterialEnum: params.materialEnum,
3594
+ Color: params.color
3595
+ });
3596
+ const { FenceID } = await response;
3597
+ let handler = new FenceHandler(this._rpc, FenceID, FenceStatus.Created);
3598
+ return handler;
3599
+ }
3600
+ }
3601
+ var FenceStatus;
3602
+ (function (FenceStatus) {
3603
+ FenceStatus["UnCreated"] = "UnCreated";
3604
+ /** 围栏已创建 */
3605
+ FenceStatus["Created"] = "Created";
3606
+ /** 围栏已删除 */
3607
+ FenceStatus["Removed"] = "Removed";
3608
+ })(FenceStatus || (FenceStatus = {}));
3609
+ class FenceHandler {
3610
+ get id() {
3611
+ return this._id;
3612
+ }
3613
+ constructor(rpc, id, status) {
3614
+ this._id = id;
3615
+ this._rpc = rpc;
3616
+ this._status = status || FenceStatus.UnCreated;
3617
+ }
3618
+ get status() {
3619
+ return this._status;
3620
+ }
3621
+ async remove() {
3622
+ return this._rpc.callModule('Box', 'Delete', {
3623
+ FenceID: this.id
3624
+ });
3625
+ }
3626
+ }
3627
+
3628
+ class Building extends Tool {
3629
+ constructor(rpc) {
3630
+ super(rpc);
3631
+ }
3632
+ async expand(id, params) {
3633
+ await this._rpc.callModule('Building', 'Expand', {
3634
+ BuildingId: id,
3635
+ Spacing: params.spacing,
3636
+ Duration: params.duration || 2000
3637
+ });
3638
+ let handler = new BuildingHandler(id, this._rpc);
3639
+ return handler;
3640
+ }
3641
+ }
3642
+ var Status$1;
3643
+ (function (Status) {
3644
+ Status["Expanded"] = "Expanded";
3645
+ Status["ExpandFloor"] = "ExpandFloor";
3646
+ Status["Collapsed"] = "Collapsed";
3647
+ })(Status$1 || (Status$1 = {}));
3648
+ class BuildingHandler {
3649
+ constructor(id, rpc, status) {
3650
+ this._id = id;
3651
+ this._rpc = rpc;
3652
+ this._status = status || Status$1.Collapsed;
3653
+ }
3654
+ get status() {
3655
+ return this._status;
3656
+ }
3657
+ get id() {
3658
+ return this._id;
3659
+ }
3660
+ async expand(params) {
3661
+ await this._rpc.callModule('Building', 'ExpandFloor', {
3662
+ BuildingId: this._id,
3663
+ Spacing: params.spacing,
3664
+ Duration: params.duration || 2
3665
+ });
3666
+ }
3667
+ async expandFloor(params) {
3668
+ let _params = {
3669
+ BuildingId: this._id,
3670
+ Distance: params.distance,
3671
+ ExpandHeight: params.expandHeight,
3672
+ Duration: params.duration || 2
3673
+ };
3674
+ if (params.direction) {
3675
+ _params.Direction = {
3676
+ X: params.direction.X,
3677
+ Y: params.direction.Y,
3678
+ Z: params.direction.Z
3679
+ };
3680
+ }
3681
+ return this._rpc.callModule('Building', 'ExpandFloor', _params);
3682
+ }
3683
+ async collapse(duration = 2) {
3684
+ return this._rpc.callModule('Building', 'Collapse', {
3685
+ BuildingId: this._id,
3686
+ duration: duration || 2
3687
+ });
3688
+ }
3689
+ }
3690
+
3691
+ var MeasurementType;
3692
+ (function (MeasurementType) {
3693
+ MeasurementType["Path"] = "Path";
3694
+ MeasurementType["Height"] = "Height";
3695
+ MeasurementType["Area"] = "Area";
3696
+ })(MeasurementType || (MeasurementType = {}));
3697
+ class Measurement extends Tool {
3698
+ constructor(rpc) {
3699
+ super(rpc);
3700
+ }
3701
+ draw(type) {
3702
+ return this._rpc.callModule('Measurement', 'SetDrawType', {
3703
+ Type: type
3704
+ });
3705
+ }
3706
+ clean() {
3707
+ return this._rpc.callModule('Measurement', 'SetDrawType', {
3708
+ Type: 'Null'
3709
+ });
3710
+ }
3711
+ }
3712
+
3713
+ class Daytime extends Tool {
3714
+ constructor(rpc) {
3715
+ super(rpc);
3716
+ }
3717
+ setDaytime(hh, mm) {
3718
+ return this._rpc.callModule('Environment', 'SetDaytime', {
3719
+ value: `${hh}${mm}`
3720
+ });
3721
+ }
3722
+ }
3723
+
3724
+ // 虚化
3725
+ class Ghost extends Tool {
3726
+ constructor(rpc) {
3727
+ super(rpc);
3728
+ }
3729
+ async ghost(node) {
3730
+ await this._rpc.callModule('Visual', 'Ghost', {
3731
+ Ghost: true,
3732
+ handle: node.key
3733
+ });
3734
+ return new GhostHandle(node, this._rpc);
3735
+ }
3736
+ }
3737
+ class GhostHandle {
3738
+ constructor(node, rpc) {
3739
+ this._node = node;
3740
+ this._rpc = rpc;
3741
+ }
3742
+ async restore() {
3743
+ await this._rpc.callModule('Visual', 'Ghost', {
3744
+ handle: this._node.key,
3745
+ Ghost: false
3746
+ });
3747
+ }
3748
+ }
3749
+
3750
+ var Tools = {
3751
+ Tool,
3752
+ MatchViewTool: MatchView,
3753
+ WeatherTool: Weather,
3754
+ PickCastTool: PickCast,
3755
+ HeatMapTool: HeatMap,
3756
+ ScatterTool: Scatter,
3757
+ FenceTool: Fence,
3758
+ BuildingTool: Building,
3759
+ MeasurementTool: Measurement,
3760
+ DaytimeTool: Daytime,
3761
+ GhostTool: Ghost
3762
+ };
3763
+
3764
+ /**
3765
+ * 世界模块,提供世界场景的核心类
3766
+ * 用于管理场景中的所有对象、天气和RPC通信
3767
+ */
3768
+ /**
3769
+ * 世界类,整个场景的根容器
3770
+ * 管理场景中的所有对象、天气系统和RPC通信
3771
+ */
3772
+ class World {
3773
+ /**
3774
+ * 构造函数
3775
+ * @param pixelStream PixelStream实例,用于与远程渲染引擎通信
3776
+ */
3777
+ constructor(pixelStream) {
3778
+ this._rpc = new UERPC(pixelStream);
3779
+ this.root = new UERPCNode(this._rpc);
3780
+ this.root.world = this;
3781
+ this.tools = {
3782
+ ghost: new Tools.GhostTool(this._rpc),
3783
+ weather: new Tools.WeatherTool(this._rpc),
3784
+ matchView: new Tools.MatchViewTool(this._rpc),
3785
+ pickCast: new Tools.PickCastTool(this._rpc),
3786
+ scatter: new Tools.ScatterTool(this._rpc),
3787
+ heatMap: new Tools.HeatMapTool(this._rpc, this),
3788
+ fence: new Tools.FenceTool(this._rpc),
3789
+ building: new Tools.BuildingTool(this._rpc),
3790
+ measurement: new Tools.MeasurementTool(this._rpc),
3791
+ daytime: new Tools.DaytimeTool(this._rpc)
3792
+ };
3793
+ }
3794
+ /**
3795
+ * 获取RPC通信实例
3796
+ */
3797
+ get rpc() {
3798
+ return this._rpc;
3799
+ }
3800
+ /**
3801
+ * 加载关卡
3802
+ * @param params 加载关卡的参数
3803
+ * @returns 加载成功后返回关卡节点
3804
+ */
3805
+ async loadLevelByName(assetPath) {
3806
+ let response = await this._rpc.loadLevelByName(assetPath);
3807
+ // let response = await this._rpc.callModule('Mesh', 'Spawn', {
3808
+ // AssetPath: assetPath,
3809
+ // Transform: Transform.default().toRPCJSON()
3810
+ // })
3811
+ let handle = response.Handle || 'map';
3812
+ let node = new UERPCNode(this._rpc, handle, { assetType: AssetType.Map });
3813
+ node.data = { assetType: AssetType.Map };
3814
+ this.root.add(node);
3815
+ return node;
3816
+ }
3817
+ /**
3818
+ * 生成含有骨骼动画的Mesh
3819
+ */
3820
+ async spawnSkeletalMesh(params) {
3821
+ let _transform = params.transform || Transform.default();
3822
+ let response = await this._rpc.callModule('Mesh', 'Spawn', {
3823
+ Type: 'SkeletalMesh',
3824
+ AssetPath: params.assetPath,
3825
+ Transform: _transform.toRPCJSON(),
3826
+ Tag: params.tag
3827
+ });
3828
+ let handle = response.Handle;
3829
+ let node = new UERPCNode(this._rpc, handle, {
3830
+ assetType: AssetType.SkeletalMesh
3831
+ }, _transform);
3832
+ this.root.add(node);
3833
+ return node;
3834
+ }
3835
+ /**
3836
+ * 生成静态网格体演员
3837
+ * @param params 生成静态网格体的参数
3838
+ * @returns 生成成功后返回演员节点
3839
+ */
3840
+ async spawnStaticMeshActor(params) {
3841
+ let _transform = params.transform || Transform.default();
3842
+ let response = await this._rpc.callModule('Mesh', 'Spawn', {
3843
+ Type: 'StaticMesh',
3844
+ AssetPath: params.assetPath,
3845
+ Transform: _transform.toRPCJSON(),
3846
+ Tag: params.tag
3847
+ });
3848
+ let handle = response.Handle;
3849
+ let node = new UERPCNode(this._rpc, handle, {
3850
+ assetType: AssetType.StaticMesh
3851
+ }, _transform);
3852
+ this.root.add(node);
3853
+ return node;
3854
+ }
3855
+ /**
3856
+ * 生成本地蓝图演员
3857
+ * @param params 生成本地蓝图的参数
3858
+ * @returns 生成成功后返回演员节点
3859
+ */
3860
+ async spawnLocalBlueprintActor(params) {
3861
+ let _transform = params.transform || Transform.default();
3862
+ let response = await this._rpc.callModule('Mesh', 'Spawn', {
3863
+ Type: 'Blueprint',
3864
+ AssetPath: params.assetPath,
3865
+ Transform: _transform.toRPCJSON(),
3866
+ Tag: params.tag
3867
+ });
3868
+ // let response = await this._rpc.spawnLocalBlueprintActor({
3869
+ // AssetPath: params.assetPath,
3870
+ // Transform: _transform.toRPCJSON(),
3871
+ // Tag: params.tag
3872
+ // })
3873
+ let handle = response.Handle;
3874
+ let node = new UERPCNode(this._rpc, handle, {
3875
+ assetType: AssetType.Blueprint
3876
+ }, _transform);
3877
+ this.root.add(node);
3878
+ return node;
3879
+ }
3880
+ }
3881
+
3882
+ /**
3883
+ * 相机基类,继承自UERPCNode
3884
+ * 定义了相机的基本结构,所有具体相机类型的父类
3885
+ */
3886
+ class Camera extends UERPCNode {
3887
+ /**
3888
+ * 相机基类构造函数
3889
+ * @param rpc UERPC实例,用于与远程服务通信
3890
+ * @param type 相机类型
3891
+ */
3892
+ constructor(rpc, type) {
3893
+ super(rpc, type);
3894
+ }
3895
+ }
3896
+ /**
3897
+ * 透视相机类,用于表示3D场景中的透视相机
3898
+ * 实现了透视相机的属性和变换管理
3899
+ */
3900
+ class PerspectiveCamera extends Camera {
3901
+ /**
3902
+ * 构造函数
3903
+ * @param rpc UERPC实例,用于与远程服务通信
3904
+ */
3905
+ constructor(rpc) {
3906
+ super(rpc, 'camera');
3907
+ // // 初始化相机默认属性
3908
+ // this._fov = 75
3909
+ // this._focalLength = 50
3910
+ // this._aperture = 35
3911
+ // this._focusDistance = 100
3912
+ // 创建默认变换
3913
+ this._transform = Transform.default();
3914
+ // 初始化变换收集器
3915
+ this._collector = new Collector(this._triggerRemoteUpdate.bind(this));
3916
+ // 初始化远程更新标志
3917
+ this._remoteUpdateFlag = false;
3918
+ }
3919
+ // /**
3920
+ // * 获取焦距值
3921
+ // * @returns {number} 焦距值,单位为毫米
3922
+ // */
3923
+ // get focalLength() {
3924
+ // return this._focalLength
3925
+ // }
3926
+ // /**
3927
+ // * 设置焦距值
3928
+ // * @param focalLength 新的焦距值,单位为毫米
3929
+ // */
3930
+ // set focalLength(focalLength: number) {
3931
+ // this._focalLength = focalLength
3932
+ // this._triggerRemoteUpdate()
3933
+ // }
3934
+ // /**
3935
+ // * 获取光圈值
3936
+ // * @returns {number} 光圈值
3937
+ // */
3938
+ // get aperture() {
3939
+ // return this._aperture
3940
+ // }
3941
+ // /**
3942
+ // * 设置光圈值
3943
+ // * @param aperture 新的光圈值
3944
+ // */
3945
+ // set aperture(aperture: number) {
3946
+ // this._aperture = aperture
3947
+ // this._triggerRemoteUpdate()
3948
+ // }
3949
+ // /**
3950
+ // * 获取视场角
3951
+ // * @returns {number} 视场角,单位为度
3952
+ // */
3953
+ // get fov() {
3954
+ // return this._fov
3955
+ // }
3956
+ // /**
3957
+ // * 设置视场角
3958
+ // * @param fov 新的视场角,单位为度
3959
+ // */
3960
+ // set fov(fov: number) {
3961
+ // this._fov = fov
3962
+ // this._triggerRemoteUpdate()
3963
+ // }
3964
+ // /**
3965
+ // * 获取焦距离
3966
+ // * @returns {number} 焦距离,单位为世界单位
3967
+ // */
3968
+ // get focusDistance() {
3969
+ // return this._focusDistance
3970
+ // }
3971
+ // 同步远程相机参数到本地
3972
+ async forceSyncRemoteToLocal() {
3973
+ let response = await this._rpc.getCameraTransform();
3974
+ console.log(response);
3975
+ if (response.Transform) {
3976
+ let transform = Transform.fromRPCObject(response.Transform);
3977
+ this._transform = transform;
3978
+ }
3979
+ }
3980
+ // /**
3981
+ // * 设置焦距离
3982
+ // * @param focusDistance 新的焦距离,单位为世界单位
3983
+ // */
3984
+ // set focusDistance(focusDistance: number) {
3985
+ // this._focusDistance = focusDistance
3986
+ // this._triggerRemoteUpdate()
3987
+ // }
3988
+ /**
3989
+ * 获取相机变换的代理对象
3990
+ * 通过深度代理实现对变换属性的监听,当变换属性变化时自动触发远程更新
3991
+ * @returns {Transform} 相机变换的代理对象
3992
+ */
3993
+ get transform() {
3994
+ return createDeepProxy(this._transform, {}, this._collector);
3995
+ }
3996
+ /**
3997
+ * 触发远程更新
3998
+ * 该方法在相机属性或变换变化时被调用,用于标记相机需要同步到远程
3999
+ */
4000
+ _triggerRemoteUpdate() {
4001
+ this._remoteUpdateFlag = true;
4002
+ this._remoteUpdate();
4003
+ }
4004
+ /**
4005
+ * 远程更新处理方法
4006
+ * 用于将相机的属性和变换同步到远程服务器
4007
+ * TODO: 实现具体的远程同步逻辑
4008
+ */
4009
+ _remoteUpdate() {
4010
+ // TODO: 实现相机属性和变换的远程同步逻辑
4011
+ this._rpc.setCameraTransform(this._transform.toRPCJSON());
4012
+ this._remoteUpdateFlag = true;
4013
+ }
4014
+ }
4015
+
4016
+ class PresetAnimateClip {
4017
+ constructor(animateName) {
4018
+ this.animateName = animateName;
4019
+ }
4020
+ _clipCall() {
4021
+ return new PresetAnimateClipCall(this);
4022
+ }
4023
+ }
4024
+ class PresetAnimateClipCall {
4025
+ constructor(clip) {
4026
+ this.clip = clip;
4027
+ }
4028
+ _play(action, params) {
4029
+ action.mixer?.rpc.callModule('Animation', 'Play', {
4030
+ ...params,
4031
+ Animation: this.clip.animateName
4032
+ });
4033
+ }
4034
+ _pause(action, params) {
4035
+ action.mixer?.rpc.callModule('Animation', 'Pause', {
4036
+ handle: params.Handle
4037
+ });
4038
+ }
4039
+ _resume(action, params) {
4040
+ action.mixer?.rpc.callModule('Animation', 'Resume', {
4041
+ handle: params.Handle
4042
+ });
4043
+ }
4044
+ }
4045
+ class KeyFrameAnimateClip {
4046
+ constructor(params) {
4047
+ this.startTransform = params.startTransform;
4048
+ this.endTransform = params.endTransform;
4049
+ }
4050
+ _clipCall() {
4051
+ return new KeyFrameAnimateClipCall(this);
4052
+ }
4053
+ }
4054
+ class KeyFrameAnimateClipCall {
4055
+ constructor(clip) {
4056
+ this.clip = clip;
4057
+ }
4058
+ _play(action, params) {
4059
+ action.mixer?.rpc.callModule('Animation', 'MoveBetweenTransforms', {
4060
+ Handle: action.handle,
4061
+ StartTransform: this.clip.startTransform?.toRPCJSON(),
4062
+ EndTransform: this.clip.endTransform?.toRPCJSON(),
4063
+ Duration: action.duration
4064
+ });
4065
+ }
4066
+ _pause(action, params) {
4067
+ action.mixer?.rpc.callModule('Animation', 'PauseMoveBetweenTransforms', {
4068
+ Handle: action.handle
4069
+ });
4070
+ }
4071
+ _resume(action, params) {
4072
+ action.mixer?.rpc.callModule('Animation', 'ResumeMoveBetweenTransforms', {
4073
+ Handle: action.handle
4074
+ });
4075
+ }
4076
+ }
4077
+
4078
+ var Status;
4079
+ (function (Status) {
4080
+ Status["Playing"] = "playing";
4081
+ Status["Paused"] = "paused";
4082
+ Status["Stopped"] = "stopped";
4083
+ })(Status || (Status = {}));
4084
+ var PlaybackType;
4085
+ (function (PlaybackType) {
4086
+ PlaybackType["Loop"] = "loop";
4087
+ PlaybackType["Once"] = "once";
4088
+ })(PlaybackType || (PlaybackType = {}));
4089
+ class AnimationAction {
4090
+ constructor(handle, clip, mixer) {
4091
+ this._status = Status.Stopped;
4092
+ this._handle = handle;
4093
+ this.type = PlaybackType.Once;
4094
+ this.rate = 1;
4095
+ this.clip = clip;
4096
+ this.playDuration = 0;
4097
+ this.mixer = mixer;
4098
+ }
4099
+ get duration() {
4100
+ return this._duration;
4101
+ }
4102
+ set duration(duration) {
4103
+ this._duration = duration;
4104
+ }
4105
+ get handle() {
4106
+ return this._handle;
4107
+ }
4108
+ get status() {
4109
+ return this._status;
4110
+ }
4111
+ async play() {
4112
+ if (this._status == Status.Paused) {
4113
+ let clipCall = this.clip._clipCall();
4114
+ return clipCall._resume(this, {
4115
+ Handle: this._handle
4116
+ });
4117
+ }
4118
+ let obj = {
4119
+ Handle: this._handle,
4120
+ Rate: this.rate,
4121
+ Loop: this.type == PlaybackType.Loop
4122
+ };
4123
+ let clipCall = this.clip._clipCall();
4124
+ this.playDuration = 0;
4125
+ this._status = Status.Playing;
4126
+ clipCall._play(this, obj);
4127
+ return;
4128
+ }
4129
+ pause() {
4130
+ let obj = {
4131
+ Handle: this._handle,
4132
+ Rate: this.rate,
4133
+ Loop: this.type == PlaybackType.Loop
4134
+ };
4135
+ let clipCall = this.clip._clipCall();
4136
+ this._status = Status.Paused;
4137
+ return clipCall._pause(this, obj);
4138
+ }
4139
+ update(delta) {
4140
+ if (this.status != Status.Playing) {
4141
+ return;
4142
+ }
4143
+ this.playDuration += delta;
4144
+ if (this.type === PlaybackType.Once &&
4145
+ this.duration &&
4146
+ this.playDuration >= this.duration) {
4147
+ this._status = Status.Stopped;
4148
+ }
4149
+ }
4150
+ }
4151
+
4152
+ // 创建一个 Clock , 计算每次的时间差 , 同时保存开始的时间
4153
+ class Clock {
4154
+ constructor() {
4155
+ this.startTime = 0;
4156
+ this.previousTime = 0;
4157
+ this.elapsedTime = 0;
4158
+ this.isRunning = false;
4159
+ }
4160
+ /**
4161
+ * 开始计时
4162
+ */
4163
+ start() {
4164
+ this.startTime = performance.now();
4165
+ this.previousTime = this.startTime;
4166
+ this.elapsedTime = 0;
4167
+ this.isRunning = true;
4168
+ }
4169
+ /**
4170
+ * 停止计时
4171
+ */
4172
+ stop() {
4173
+ this.getDelta(); // 更新 elapsedTime
4174
+ this.isRunning = false;
4175
+ }
4176
+ /**
4177
+ * 获取自上次调用 getDelta() 以来经过的时间(时间差)
4178
+ * @returns 时间差(毫秒)
4179
+ */
4180
+ getDelta() {
4181
+ let currentTime = performance.now();
4182
+ let delta = 0;
4183
+ if (this.isRunning) {
4184
+ delta = currentTime - this.previousTime;
4185
+ this.elapsedTime += delta;
4186
+ this.previousTime = currentTime;
4187
+ }
4188
+ return delta;
4189
+ }
4190
+ /**
4191
+ * 获取自开始计时以来经过的总时间
4192
+ * @returns 经过的总时间(毫秒)
4193
+ */
4194
+ getElapsedTime() {
4195
+ if (this.isRunning) {
4196
+ this.getDelta(); // 更新 elapsedTime
4197
+ }
4198
+ return this.elapsedTime;
4199
+ }
4200
+ /**
4201
+ * 获取开始时间
4202
+ * @returns 开始时间(毫秒)
4203
+ */
4204
+ getStartTime() {
4205
+ return this.startTime;
4206
+ }
4207
+ /**
4208
+ * 检查是否正在运行
4209
+ * @returns 是否正在运行
4210
+ */
4211
+ isRunningState() {
4212
+ return this.isRunning;
4213
+ }
4214
+ /**
4215
+ * 重置计时器
4216
+ */
4217
+ reset() {
4218
+ this.startTime = performance.now();
4219
+ this.previousTime = this.startTime;
4220
+ this.elapsedTime = 0;
4221
+ }
4222
+ }
4223
+
4224
+ class AnimationMixer {
4225
+ constructor(rpc) {
4226
+ this._actions = [];
4227
+ this._rpc = rpc;
4228
+ this._duration = 0;
4229
+ this._actions = [];
4230
+ this.init();
4231
+ }
4232
+ get rpc() {
4233
+ return this._rpc;
4234
+ }
4235
+ init() {
4236
+ this._clock = new Clock();
4237
+ this._clock.start();
4238
+ setTimeout(() => {
4239
+ this._duration += this._clock.getDelta();
4240
+ this.updateAction();
4241
+ }, 1000 / 60);
4242
+ }
4243
+ get duration() {
4244
+ return this._duration;
4245
+ }
4246
+ updateAction() {
4247
+ this._actions.forEach((action) => {
4248
+ action.update(this._duration);
4249
+ });
4250
+ }
4251
+ clipAction(clip, node) {
4252
+ return new AnimationAction(node.key, clip, this);
4253
+ }
4254
+ removeAction(action) {
4255
+ // this._actions = this._actions.filter((item) => item !== action)
4256
+ let index = this._actions.findIndex((item) => item === action);
4257
+ if (index > -1) {
4258
+ this._actions.splice(index, 1);
4259
+ }
4260
+ }
4261
+ }
4262
+
4263
+ var Animation = /*#__PURE__*/Object.freeze({
4264
+ __proto__: null,
4265
+ AnimationMixer: AnimationMixer,
4266
+ AnimationAction: AnimationAction,
4267
+ PresetAnimateClip: PresetAnimateClip,
4268
+ KeyFrameAnimateClip: KeyFrameAnimateClip
4269
+ });
4270
+
4271
+ export { Animation as A, Logger as L, MeasurementType as M, PerspectiveCamera as P, Transform as T, UERPCNode as U, World as W, WeatherType as a, UERPC as b, LogLevel as c };
4272
+ //# sourceMappingURL=index.esm2.js.map