@n3rdw1z4rd/core 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -8
- package/dist/index.css +0 -9
- package/dist/index.d.mts +288 -287
- package/dist/index.d.ts +288 -287
- package/dist/index.js +979 -1098
- package/dist/index.mjs +970 -1091
- package/package.json +19 -2
package/dist/index.mjs
CHANGED
|
@@ -20,10 +20,6 @@ var AStar = class {
|
|
|
20
20
|
_key(x, y) {
|
|
21
21
|
return `${x},${y}`;
|
|
22
22
|
}
|
|
23
|
-
// NOTE: ported as-is from rogue-craft. useAdjacent is currently hard-coded
|
|
24
|
-
// to true below - the original had a known unresolved bug where setting it
|
|
25
|
-
// to false via params caused an infinite loop, so that path is disabled
|
|
26
|
-
// rather than exposed broken.
|
|
27
23
|
findPath(a, b, params = {}) {
|
|
28
24
|
const useAdjacent = true;
|
|
29
25
|
const walkable = params.walkableValues ?? [0];
|
|
@@ -94,198 +90,130 @@ var AStar = class {
|
|
|
94
90
|
}
|
|
95
91
|
};
|
|
96
92
|
|
|
97
|
-
// src/
|
|
98
|
-
var
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
valueColor = "lightgray";
|
|
102
|
-
constructor(align = "bottom", justify = "right") {
|
|
103
|
-
this.divElement = document.createElement("div");
|
|
104
|
-
this.divElement.setAttribute("id", "clock-stats");
|
|
105
|
-
this.divElement.style.setProperty("position", "absolute");
|
|
106
|
-
this.divElement.style.setProperty(align, "4px");
|
|
107
|
-
this.divElement.style.setProperty(justify, "4px");
|
|
93
|
+
// src/emitter.ts
|
|
94
|
+
var Emitter = class {
|
|
95
|
+
listeners = /* @__PURE__ */ new Map();
|
|
96
|
+
constructor() {
|
|
108
97
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
98
|
+
on(...eventName) {
|
|
99
|
+
const listener = eventName.pop();
|
|
100
|
+
const events = eventName.filter((ev) => typeof ev === "string");
|
|
101
|
+
events.forEach((event) => {
|
|
102
|
+
if (!this.listeners.has(event)) {
|
|
103
|
+
this.listeners.set(event, new Array());
|
|
104
|
+
}
|
|
105
|
+
this.listeners.get(event)?.push(listener);
|
|
106
|
+
});
|
|
107
|
+
return this;
|
|
114
108
|
}
|
|
115
|
-
|
|
116
|
-
this.
|
|
117
|
-
|
|
118
|
-
|
|
109
|
+
emit(eventName, ...args) {
|
|
110
|
+
this.listeners.get(eventName)?.forEach((listener) => listener(...args, eventName));
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
clear(eventName) {
|
|
114
|
+
if (eventName) {
|
|
115
|
+
this.listeners.delete(eventName);
|
|
116
|
+
} else {
|
|
117
|
+
this.listeners.clear();
|
|
118
|
+
}
|
|
119
|
+
return this;
|
|
119
120
|
}
|
|
120
121
|
};
|
|
121
122
|
|
|
122
123
|
// src/clock.ts
|
|
123
|
-
var Clock = class {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
_avgDeltaTime = 0;
|
|
128
|
-
_frameCount = 0;
|
|
129
|
-
_frameCountTotal = 0;
|
|
124
|
+
var Clock = class extends Emitter {
|
|
125
|
+
_startTime = 0;
|
|
126
|
+
_time = 0;
|
|
127
|
+
_deltaTime = 0;
|
|
130
128
|
_frameTime = 0;
|
|
129
|
+
_frameCount = 0;
|
|
131
130
|
_fps = 0;
|
|
132
131
|
_isRunning = false;
|
|
133
|
-
_updateCallback = () => {
|
|
134
|
-
};
|
|
135
|
-
_statsParent;
|
|
136
|
-
_stats;
|
|
137
|
-
_startTime = 0;
|
|
138
|
-
get fps() {
|
|
139
|
-
return this._fps;
|
|
140
|
-
}
|
|
141
|
-
get frames() {
|
|
142
|
-
return this._frameCountTotal;
|
|
143
|
-
}
|
|
144
|
-
get deltaTimeSeconds() {
|
|
145
|
-
return this._deltaTimeSeconds;
|
|
146
|
-
}
|
|
147
|
-
get deltaTimeMilliseconds() {
|
|
148
|
-
return this._daltaTimeMilliseconds;
|
|
149
|
-
}
|
|
150
|
-
get avgDeltaTime() {
|
|
151
|
-
return this._avgDeltaTime;
|
|
152
|
-
}
|
|
153
132
|
get time() {
|
|
154
|
-
return this.
|
|
133
|
+
return this._time;
|
|
155
134
|
}
|
|
156
|
-
get
|
|
157
|
-
return this.
|
|
135
|
+
get deltaTime() {
|
|
136
|
+
return this._deltaTime;
|
|
158
137
|
}
|
|
159
|
-
get
|
|
138
|
+
get elapsedTime() {
|
|
160
139
|
return performance.now() - this._startTime;
|
|
161
140
|
}
|
|
162
|
-
|
|
163
|
-
this.
|
|
164
|
-
}
|
|
165
|
-
_update(time) {
|
|
166
|
-
this.update(time);
|
|
167
|
-
this._updateCallback(this._deltaTimeSeconds);
|
|
168
|
-
if (this._isRunning) {
|
|
169
|
-
requestAnimationFrame(this._update.bind(this));
|
|
170
|
-
}
|
|
141
|
+
get fps() {
|
|
142
|
+
return this._fps;
|
|
171
143
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
this._deltaTimeSeconds = this._daltaTimeMilliseconds / 1e3;
|
|
175
|
-
this._lastFrameTime = time;
|
|
176
|
-
if (this._frameTime + 1e3 >= time) {
|
|
177
|
-
this._frameCount += 1;
|
|
178
|
-
} else {
|
|
179
|
-
this._frameTime = time;
|
|
180
|
-
this._fps = this._frameCount;
|
|
181
|
-
this._frameCount = 0;
|
|
182
|
-
}
|
|
183
|
-
this._frameCountTotal++;
|
|
184
|
-
this._avgDeltaTime = (this._avgDeltaTime * this._frameCount + this._daltaTimeMilliseconds) / (this._frameCount + 1);
|
|
144
|
+
get isRunning() {
|
|
145
|
+
return this._isRunning;
|
|
185
146
|
}
|
|
186
|
-
|
|
147
|
+
start() {
|
|
187
148
|
if (!this._isRunning) {
|
|
188
|
-
this._frameCountTotal = 0;
|
|
189
149
|
this._startTime = performance.now();
|
|
190
150
|
this._isRunning = true;
|
|
191
|
-
|
|
192
|
-
|
|
151
|
+
const update = (time) => {
|
|
152
|
+
this._deltaTime = (time - this._time) / 1e3;
|
|
153
|
+
this._time = time;
|
|
154
|
+
if (this._frameTime + 1e3 >= time) {
|
|
155
|
+
this._frameCount += 1;
|
|
156
|
+
} else {
|
|
157
|
+
this._frameTime = time;
|
|
158
|
+
this._fps = this._frameCount;
|
|
159
|
+
this._frameCount = 0;
|
|
160
|
+
}
|
|
161
|
+
this.emit("frame", this._deltaTime);
|
|
162
|
+
if (this._isRunning) {
|
|
163
|
+
requestAnimationFrame(update);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
requestAnimationFrame(update);
|
|
193
167
|
}
|
|
194
168
|
}
|
|
195
|
-
runOnce(callback) {
|
|
196
|
-
this._isRunning = false;
|
|
197
|
-
this._updateCallback = callback;
|
|
198
|
-
this._update(0);
|
|
199
|
-
}
|
|
200
169
|
stop() {
|
|
201
170
|
this._isRunning = false;
|
|
202
171
|
}
|
|
203
|
-
getExecuteTime(func) {
|
|
204
|
-
const now = performance.now();
|
|
205
|
-
func();
|
|
206
|
-
return performance.now() - now;
|
|
207
|
-
}
|
|
208
|
-
showStats(data = {}, parent) {
|
|
209
|
-
parent = parent ?? this._statsParent ?? document.body;
|
|
210
|
-
if (!this._stats) {
|
|
211
|
-
this._stats = new ClockStats();
|
|
212
|
-
this._stats.appendTo(parent);
|
|
213
|
-
}
|
|
214
|
-
this._stats.update({
|
|
215
|
-
fps: this._fps,
|
|
216
|
-
"deltaTime(s)": `${this._deltaTimeSeconds.toFixed(3)}`,
|
|
217
|
-
"avgDeltaTime(ms)": `${this._avgDeltaTime.toFixed(3)}`,
|
|
218
|
-
...data
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
172
|
};
|
|
222
173
|
|
|
223
|
-
// src/
|
|
224
|
-
var logdev = console.debug.bind(console, "%c[dbg]", "font-weight: bold; color: #888;");
|
|
225
|
-
var log = logdev;
|
|
226
|
-
var loginf = console.log.bind(console, "%c[inf]", "font-weight: bold;");
|
|
227
|
-
var logwrn = console.log.bind(console, "%c[wrn]", "font-weight: bold; color: orange;");
|
|
228
|
-
var logerr = console.log.bind(console, "%c[err]", "font-weight: bold; color: red;");
|
|
229
|
-
|
|
230
|
-
// src/math.ts
|
|
231
|
-
var DEG2RAD = 0.01745329;
|
|
174
|
+
// src/math/math.ts
|
|
232
175
|
var PI = 3.141592653589793;
|
|
233
|
-
var
|
|
176
|
+
var DOUBLE_PI = PI * 2;
|
|
234
177
|
var HALF_PI = PI / 2;
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
function max(a, b) {
|
|
242
|
-
return a > b ? a : b;
|
|
243
|
-
}
|
|
244
|
-
function floor(n) {
|
|
178
|
+
var RADIAN_FACTOR = PI / 180;
|
|
179
|
+
var abs = (n) => n < 0 ? -n : n;
|
|
180
|
+
var min = (a, b) => a < b ? a : b;
|
|
181
|
+
var max = (a, b) => a > b ? a : b;
|
|
182
|
+
var floor = (n) => {
|
|
245
183
|
const t = n | 0;
|
|
246
184
|
return n < 0 && t !== n ? t - 1 : t;
|
|
247
|
-
}
|
|
248
|
-
|
|
185
|
+
};
|
|
186
|
+
var ceil = (n) => {
|
|
249
187
|
const t = n | 0;
|
|
250
188
|
return n > 0 && t !== n ? t + 1 : t;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
function pow(base, exp) {
|
|
259
|
-
return base ** exp;
|
|
260
|
-
}
|
|
261
|
-
function hypot2(x, y) {
|
|
262
|
-
return (x * x + y * y) ** 0.5;
|
|
263
|
-
}
|
|
264
|
-
function hypot3(x, y, z) {
|
|
265
|
-
return (x * x + y * y + z * z) ** 0.5;
|
|
266
|
-
}
|
|
267
|
-
function imul(a, b) {
|
|
189
|
+
};
|
|
190
|
+
var round = (n) => floor(n + 0.5);
|
|
191
|
+
var sqrt = (n) => n ** 0.5;
|
|
192
|
+
var pow = (base, exp) => base ** exp;
|
|
193
|
+
var hypot2 = (x, y) => (x * x + y * y) ** 0.5;
|
|
194
|
+
var hypot3 = (x, y, z) => (x * x + y * y + z * z) ** 0.5;
|
|
195
|
+
var imul = (a, b) => {
|
|
268
196
|
b |= 0;
|
|
269
197
|
let result = (a & 4194303) * b;
|
|
270
198
|
if (a & 4290772992) result += (a & 4290772992) * b | 0;
|
|
271
199
|
return result | 0;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
n = n %
|
|
275
|
-
if (n > PI) n -=
|
|
276
|
-
else if (n < -PI) n +=
|
|
200
|
+
};
|
|
201
|
+
var _wrapAngle = (n) => {
|
|
202
|
+
n = n % DOUBLE_PI;
|
|
203
|
+
if (n > PI) n -= DOUBLE_PI;
|
|
204
|
+
else if (n < -PI) n += DOUBLE_PI;
|
|
277
205
|
return n;
|
|
278
|
-
}
|
|
279
|
-
|
|
206
|
+
};
|
|
207
|
+
var _sinSeries = (n) => {
|
|
280
208
|
const n2 = n * n;
|
|
281
209
|
return n * (1 + n2 * (-1 / 6 + n2 * (1 / 120 + n2 * (-1 / 5040 + n2 * (1 / 362880 + n2 * (-1 / 39916800))))));
|
|
282
|
-
}
|
|
283
|
-
|
|
210
|
+
};
|
|
211
|
+
var _cosSeries = (n) => {
|
|
284
212
|
const n2 = n * n;
|
|
285
213
|
return 1 + n2 * (-1 / 2 + n2 * (1 / 24 + n2 * (-1 / 720 + n2 * (1 / 40320 + n2 * (-1 / 3628800)))));
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
let x =
|
|
214
|
+
};
|
|
215
|
+
var _reduceAngle = (n) => {
|
|
216
|
+
let x = _wrapAngle(n);
|
|
289
217
|
let sinSign = 1;
|
|
290
218
|
if (x < 0) {
|
|
291
219
|
x = -x;
|
|
@@ -297,207 +225,173 @@ function reduceAngle(n) {
|
|
|
297
225
|
cosSign = -1;
|
|
298
226
|
}
|
|
299
227
|
return [x, sinSign, cosSign];
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const [x, sinSign] =
|
|
303
|
-
return sinSign *
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const [x, , cosSign] =
|
|
307
|
-
return cosSign *
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
function lerp(start, end, scale) {
|
|
316
|
-
return start * (1 - scale) + end * scale;
|
|
317
|
-
}
|
|
318
|
-
function distance(x1, y1, x2, y2) {
|
|
319
|
-
return hypot2(x2 - x1, y2 - y1);
|
|
320
|
-
}
|
|
321
|
-
function squaredDistance(x1, y1, x2, y2) {
|
|
228
|
+
};
|
|
229
|
+
var sin = (n) => {
|
|
230
|
+
const [x, sinSign] = _reduceAngle(n);
|
|
231
|
+
return sinSign * _sinSeries(x);
|
|
232
|
+
};
|
|
233
|
+
var cos = (n) => {
|
|
234
|
+
const [x, , cosSign] = _reduceAngle(n);
|
|
235
|
+
return cosSign * _cosSeries(x);
|
|
236
|
+
};
|
|
237
|
+
var clamp = (value, lo, hi) => max(lo, min(hi, value));
|
|
238
|
+
var deg2rad = (degree) => degree * RADIAN_FACTOR;
|
|
239
|
+
var lerp = (start, end, scale) => start * (1 - scale) + end * scale;
|
|
240
|
+
var distance2d = (x1, y1, x2, y2) => hypot2(x2 - x1, y2 - y1);
|
|
241
|
+
var distance3d = (x1, y1, z1, x2, y2, z2) => hypot3(x2 - x1, y2 - y1, z2 - z1);
|
|
242
|
+
var squaredDistance = (x1, y1, x2, y2) => {
|
|
322
243
|
const dx = x1 - x2;
|
|
323
244
|
const dy = y1 - y2;
|
|
324
245
|
return dx * dx + dy * dy;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
function roundTo(value, digits, base = 10) {
|
|
246
|
+
};
|
|
247
|
+
var manhattanDistance = (x1, y1, x2, y2) => abs(x1 - x2) + abs(y1 - y2);
|
|
248
|
+
var roundTo = (value, digits, base = 10) => {
|
|
330
249
|
const p = pow(base, digits);
|
|
331
250
|
return round(value * p) / p;
|
|
332
|
-
}
|
|
251
|
+
};
|
|
333
252
|
|
|
334
|
-
// src/
|
|
335
|
-
var
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
253
|
+
// src/math/rectangle.ts
|
|
254
|
+
var Rectangle = class _Rectangle {
|
|
255
|
+
x;
|
|
256
|
+
y;
|
|
257
|
+
width;
|
|
258
|
+
height;
|
|
259
|
+
constructor(x = 0, y = 0, width = 1, height = 1) {
|
|
260
|
+
this.x = x;
|
|
261
|
+
this.y = y;
|
|
262
|
+
this.width = width;
|
|
263
|
+
this.height = height;
|
|
343
264
|
}
|
|
344
|
-
|
|
345
|
-
this.
|
|
346
|
-
this._hex = this._to_hex();
|
|
265
|
+
area() {
|
|
266
|
+
return this.width * this.height;
|
|
347
267
|
}
|
|
348
|
-
|
|
349
|
-
return this.
|
|
268
|
+
contains(target, padding = 0) {
|
|
269
|
+
return target instanceof Vector ? target.x >= this.x - padding && target.x <= this.x + this.width + padding && target.y >= this.y - padding && target.y <= this.y + this.height + padding : target.x >= this.x + padding && target.y >= this.y + padding && target.x + target.width <= this.x + this.width - padding && target.y + target.height <= this.y + this.height - padding;
|
|
350
270
|
}
|
|
351
|
-
|
|
352
|
-
this.
|
|
353
|
-
this._hex = this._to_hex();
|
|
271
|
+
intersects(other, padding = 0) {
|
|
272
|
+
return !(other.x - padding > this.x + this.width + padding || other.x + other.width + padding < this.x - padding || other.y - padding > this.y + this.height + padding || other.y + other.height + padding < this.y - padding);
|
|
354
273
|
}
|
|
355
|
-
|
|
356
|
-
return
|
|
274
|
+
center() {
|
|
275
|
+
return new Vector(
|
|
276
|
+
this.x + this.width / 2,
|
|
277
|
+
this.y + this.height / 2
|
|
278
|
+
);
|
|
357
279
|
}
|
|
358
|
-
|
|
359
|
-
this.
|
|
360
|
-
this._hex = this._to_hex();
|
|
280
|
+
distanceTo(other) {
|
|
281
|
+
return this.center().distanceTo(other.center());
|
|
361
282
|
}
|
|
362
|
-
|
|
363
|
-
return this.
|
|
283
|
+
clone() {
|
|
284
|
+
return new _Rectangle(this.x, this.y, this.width, this.height);
|
|
364
285
|
}
|
|
365
|
-
|
|
366
|
-
this.
|
|
367
|
-
this._hex = this._to_hex();
|
|
286
|
+
equals(other) {
|
|
287
|
+
return this.x === other.x && this.y === other.y && this.width === other.width && this.height === other.height;
|
|
368
288
|
}
|
|
369
|
-
|
|
370
|
-
return
|
|
289
|
+
grow(padding) {
|
|
290
|
+
return new _Rectangle(
|
|
291
|
+
this.x - padding,
|
|
292
|
+
this.y - padding,
|
|
293
|
+
this.width + padding * 2,
|
|
294
|
+
this.height + padding * 2
|
|
295
|
+
);
|
|
371
296
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
297
|
+
vectorInside(vec, padding = 0) {
|
|
298
|
+
return vec.x >= this.x - padding && vec.x <= this.x + this.width + padding && vec.y >= this.y - padding && vec.y <= this.y + this.height + padding;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// src/math/vector.ts
|
|
303
|
+
var Vector = class _Vector {
|
|
304
|
+
x;
|
|
305
|
+
y;
|
|
306
|
+
constructor(x = 0, y = 0) {
|
|
307
|
+
this.x = x;
|
|
308
|
+
this.y = y;
|
|
309
|
+
}
|
|
310
|
+
clone() {
|
|
311
|
+
return new _Vector(this.x, this.y);
|
|
312
|
+
}
|
|
313
|
+
distanceTo(that) {
|
|
314
|
+
return distance2d(
|
|
315
|
+
this.x,
|
|
316
|
+
this.y,
|
|
317
|
+
that.x,
|
|
318
|
+
that.y
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
floored() {
|
|
322
|
+
return new _Vector(
|
|
323
|
+
Math.floor(this.x),
|
|
324
|
+
Math.floor(this.y)
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
plus(x, y) {
|
|
328
|
+
if (x instanceof _Vector) {
|
|
329
|
+
y = x.y;
|
|
330
|
+
x = x.x;
|
|
331
|
+
} else if (y === void 0) {
|
|
332
|
+
y = x;
|
|
378
333
|
}
|
|
334
|
+
this.x += x;
|
|
335
|
+
this.y += y;
|
|
336
|
+
return this;
|
|
379
337
|
}
|
|
380
|
-
|
|
381
|
-
|
|
338
|
+
minus(x, y) {
|
|
339
|
+
if (x instanceof _Vector) {
|
|
340
|
+
y = x.y;
|
|
341
|
+
x = x.x;
|
|
342
|
+
} else if (y === void 0) {
|
|
343
|
+
y = x;
|
|
344
|
+
}
|
|
345
|
+
this.x -= x;
|
|
346
|
+
this.y -= y;
|
|
347
|
+
return this;
|
|
382
348
|
}
|
|
383
|
-
|
|
384
|
-
if (
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
r = g = b = a = 255;
|
|
390
|
-
}
|
|
391
|
-
} else {
|
|
392
|
-
[r, g, b, a] = [r, g, b, a].map((n) => _Color._normalize(n));
|
|
349
|
+
times(x, y) {
|
|
350
|
+
if (x instanceof _Vector) {
|
|
351
|
+
y = x.y;
|
|
352
|
+
x = x.x;
|
|
353
|
+
} else if (y === void 0) {
|
|
354
|
+
y = x;
|
|
393
355
|
}
|
|
394
|
-
this.
|
|
395
|
-
this.
|
|
396
|
-
this
|
|
397
|
-
this.a = a;
|
|
356
|
+
this.x *= x;
|
|
357
|
+
this.y *= y;
|
|
358
|
+
return this;
|
|
398
359
|
}
|
|
399
|
-
|
|
400
|
-
|
|
360
|
+
dividedBy(x, y) {
|
|
361
|
+
if (x instanceof _Vector) {
|
|
362
|
+
y = x.y;
|
|
363
|
+
x = x.x;
|
|
364
|
+
} else if (y === void 0) {
|
|
365
|
+
y = x;
|
|
366
|
+
}
|
|
367
|
+
this.x /= x || 1;
|
|
368
|
+
this.y /= y || 1;
|
|
369
|
+
return this;
|
|
401
370
|
}
|
|
402
|
-
|
|
403
|
-
return
|
|
371
|
+
static get NORTH() {
|
|
372
|
+
return new _Vector(0, -1);
|
|
404
373
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
return result ? [
|
|
408
|
-
parseInt(result[1], 16),
|
|
409
|
-
parseInt(result[2], 16),
|
|
410
|
-
parseInt(result[3], 16),
|
|
411
|
-
result[4] ? parseInt(result[4], 16) : 255
|
|
412
|
-
] : [255, 255, 255, 255];
|
|
413
|
-
}
|
|
414
|
-
static fromHsv(h, s, v, a = 255) {
|
|
415
|
-
let r = 0;
|
|
416
|
-
let g = 0;
|
|
417
|
-
let b = 0;
|
|
418
|
-
let i = Math.floor(h * 6);
|
|
419
|
-
let f = h * 6 - i;
|
|
420
|
-
let p = v * (1 - s);
|
|
421
|
-
let q = v * (1 - f * s);
|
|
422
|
-
let t = v * (1 - (1 - f) * s);
|
|
423
|
-
switch (i % 6) {
|
|
424
|
-
case 0:
|
|
425
|
-
r = v, g = t, b = p;
|
|
426
|
-
break;
|
|
427
|
-
case 1:
|
|
428
|
-
r = q, g = v, b = p;
|
|
429
|
-
break;
|
|
430
|
-
case 2:
|
|
431
|
-
r = p, g = v, b = t;
|
|
432
|
-
break;
|
|
433
|
-
case 3:
|
|
434
|
-
r = p, g = q, b = v;
|
|
435
|
-
break;
|
|
436
|
-
case 4:
|
|
437
|
-
r = t, g = p, b = v;
|
|
438
|
-
break;
|
|
439
|
-
case 5:
|
|
440
|
-
r = v, g = p, b = q;
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
return new _Color(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a);
|
|
444
|
-
}
|
|
445
|
-
static get BLACK() {
|
|
446
|
-
return new _Color(0, 0, 0, 255);
|
|
447
|
-
}
|
|
448
|
-
static get GRAY() {
|
|
449
|
-
return new _Color(128, 128, 128, 255);
|
|
450
|
-
}
|
|
451
|
-
static get WHITE() {
|
|
452
|
-
return new _Color(255, 255, 255, 255);
|
|
453
|
-
}
|
|
454
|
-
static get RED() {
|
|
455
|
-
return new _Color(255, 0, 0, 255);
|
|
456
|
-
}
|
|
457
|
-
static get GREEN() {
|
|
458
|
-
return new _Color(0, 255, 0, 255);
|
|
459
|
-
}
|
|
460
|
-
static get BLUE() {
|
|
461
|
-
return new _Color(0, 0, 255, 255);
|
|
462
|
-
}
|
|
463
|
-
static get YELLOW() {
|
|
464
|
-
return new _Color(255, 255, 0, 255);
|
|
465
|
-
}
|
|
466
|
-
static get ORANGE() {
|
|
467
|
-
return new _Color(255, 128, 0, 255);
|
|
468
|
-
}
|
|
469
|
-
static get PURPLE() {
|
|
470
|
-
return new _Color(128, 0, 128, 255);
|
|
471
|
-
}
|
|
472
|
-
static get CYAN() {
|
|
473
|
-
return new _Color(0, 255, 255, 255);
|
|
474
|
-
}
|
|
475
|
-
static get MAGENTA() {
|
|
476
|
-
return new _Color(255, 0, 255, 255);
|
|
374
|
+
static get SOUTH() {
|
|
375
|
+
return new _Vector(0, 1);
|
|
477
376
|
}
|
|
478
|
-
static
|
|
479
|
-
|
|
480
|
-
element.style.color = name;
|
|
481
|
-
document.body.appendChild(element);
|
|
482
|
-
const computedColor = getComputedStyle(element).color;
|
|
483
|
-
document.body.removeChild(element);
|
|
484
|
-
const rgba = computedColor.match(/\d+/g);
|
|
485
|
-
if (rgba && rgba.length === 4) {
|
|
486
|
-
const [r, g, b, a] = rgba.map(Number);
|
|
487
|
-
return new _Color(r, g, b, a);
|
|
488
|
-
} else {
|
|
489
|
-
logwrn(`Color: invalid CSS color name: ${name}. Defaulting to transparent.`);
|
|
490
|
-
return _Color.TRANSPARENT;
|
|
491
|
-
}
|
|
377
|
+
static get EAST() {
|
|
378
|
+
return new _Vector(1, 0);
|
|
492
379
|
}
|
|
493
|
-
static get
|
|
494
|
-
return new
|
|
380
|
+
static get WEST() {
|
|
381
|
+
return new _Vector(-1, 0);
|
|
495
382
|
}
|
|
496
383
|
};
|
|
497
384
|
|
|
498
385
|
// src/dungeon-generator.ts
|
|
499
386
|
import { Heap } from "heap-js";
|
|
500
387
|
|
|
388
|
+
// src/logger.ts
|
|
389
|
+
var logdev = console.debug.bind(console, "%c[dbg]", "font-weight: bold; color: #888;");
|
|
390
|
+
var log = logdev;
|
|
391
|
+
var loginf = console.log.bind(console, "%c[inf]", "font-weight: bold;");
|
|
392
|
+
var logwrn = console.log.bind(console, "%c[wrn]", "font-weight: bold; color: orange;");
|
|
393
|
+
var logerr = console.log.bind(console, "%c[err]", "font-weight: bold; color: red;");
|
|
394
|
+
|
|
501
395
|
// src/map2d.ts
|
|
502
396
|
var DEFAULT_VALUE = -1;
|
|
503
397
|
var Map2D = class {
|
|
@@ -543,140 +437,8 @@ var Map2D = class {
|
|
|
543
437
|
}
|
|
544
438
|
};
|
|
545
439
|
|
|
546
|
-
// src/vector.ts
|
|
547
|
-
var Vector = class _Vector {
|
|
548
|
-
x;
|
|
549
|
-
y;
|
|
550
|
-
constructor(x = 0, y = 0) {
|
|
551
|
-
this.x = x;
|
|
552
|
-
this.y = y;
|
|
553
|
-
}
|
|
554
|
-
clone() {
|
|
555
|
-
return new _Vector(this.x, this.y);
|
|
556
|
-
}
|
|
557
|
-
distanceTo(that) {
|
|
558
|
-
return distance(
|
|
559
|
-
this.x,
|
|
560
|
-
this.y,
|
|
561
|
-
that.x,
|
|
562
|
-
that.y
|
|
563
|
-
);
|
|
564
|
-
}
|
|
565
|
-
floored() {
|
|
566
|
-
return new _Vector(
|
|
567
|
-
Math.floor(this.x),
|
|
568
|
-
Math.floor(this.y)
|
|
569
|
-
);
|
|
570
|
-
}
|
|
571
|
-
plus(x, y) {
|
|
572
|
-
if (x instanceof _Vector) {
|
|
573
|
-
y = x.y;
|
|
574
|
-
x = x.x;
|
|
575
|
-
} else if (y === void 0) {
|
|
576
|
-
y = x;
|
|
577
|
-
}
|
|
578
|
-
this.x += x;
|
|
579
|
-
this.y += y;
|
|
580
|
-
return this;
|
|
581
|
-
}
|
|
582
|
-
minus(x, y) {
|
|
583
|
-
if (x instanceof _Vector) {
|
|
584
|
-
y = x.y;
|
|
585
|
-
x = x.x;
|
|
586
|
-
} else if (y === void 0) {
|
|
587
|
-
y = x;
|
|
588
|
-
}
|
|
589
|
-
this.x -= x;
|
|
590
|
-
this.y -= y;
|
|
591
|
-
return this;
|
|
592
|
-
}
|
|
593
|
-
times(x, y) {
|
|
594
|
-
if (x instanceof _Vector) {
|
|
595
|
-
y = x.y;
|
|
596
|
-
x = x.x;
|
|
597
|
-
} else if (y === void 0) {
|
|
598
|
-
y = x;
|
|
599
|
-
}
|
|
600
|
-
this.x *= x;
|
|
601
|
-
this.y *= y;
|
|
602
|
-
return this;
|
|
603
|
-
}
|
|
604
|
-
dividedBy(x, y) {
|
|
605
|
-
if (x instanceof _Vector) {
|
|
606
|
-
y = x.y;
|
|
607
|
-
x = x.x;
|
|
608
|
-
} else if (y === void 0) {
|
|
609
|
-
y = x;
|
|
610
|
-
}
|
|
611
|
-
this.x /= x || 1;
|
|
612
|
-
this.y /= y || 1;
|
|
613
|
-
return this;
|
|
614
|
-
}
|
|
615
|
-
static get NORTH() {
|
|
616
|
-
return new _Vector(0, -1);
|
|
617
|
-
}
|
|
618
|
-
static get SOUTH() {
|
|
619
|
-
return new _Vector(0, 1);
|
|
620
|
-
}
|
|
621
|
-
static get EAST() {
|
|
622
|
-
return new _Vector(1, 0);
|
|
623
|
-
}
|
|
624
|
-
static get WEST() {
|
|
625
|
-
return new _Vector(-1, 0);
|
|
626
|
-
}
|
|
627
|
-
};
|
|
628
|
-
|
|
629
|
-
// src/rectangle.ts
|
|
630
|
-
var Rectangle = class _Rectangle {
|
|
631
|
-
x;
|
|
632
|
-
y;
|
|
633
|
-
width;
|
|
634
|
-
height;
|
|
635
|
-
constructor(x = 0, y = 0, width = 1, height = 1) {
|
|
636
|
-
this.x = x;
|
|
637
|
-
this.y = y;
|
|
638
|
-
this.width = width;
|
|
639
|
-
this.height = height;
|
|
640
|
-
}
|
|
641
|
-
area() {
|
|
642
|
-
return this.width * this.height;
|
|
643
|
-
}
|
|
644
|
-
contains(target, padding = 0) {
|
|
645
|
-
return target instanceof Vector ? target.x >= this.x - padding && target.x <= this.x + this.width + padding && target.y >= this.y - padding && target.y <= this.y + this.height + padding : target.x >= this.x + padding && target.y >= this.y + padding && target.x + target.width <= this.x + this.width - padding && target.y + target.height <= this.y + this.height - padding;
|
|
646
|
-
}
|
|
647
|
-
intersects(other, padding = 0) {
|
|
648
|
-
return !(other.x - padding > this.x + this.width + padding || other.x + other.width + padding < this.x - padding || other.y - padding > this.y + this.height + padding || other.y + other.height + padding < this.y - padding);
|
|
649
|
-
}
|
|
650
|
-
center() {
|
|
651
|
-
return new Vector(
|
|
652
|
-
this.x + this.width / 2,
|
|
653
|
-
this.y + this.height / 2
|
|
654
|
-
);
|
|
655
|
-
}
|
|
656
|
-
distanceTo(other) {
|
|
657
|
-
return this.center().distanceTo(other.center());
|
|
658
|
-
}
|
|
659
|
-
clone() {
|
|
660
|
-
return new _Rectangle(this.x, this.y, this.width, this.height);
|
|
661
|
-
}
|
|
662
|
-
equals(other) {
|
|
663
|
-
return this.x === other.x && this.y === other.y && this.width === other.width && this.height === other.height;
|
|
664
|
-
}
|
|
665
|
-
grow(padding) {
|
|
666
|
-
return new _Rectangle(
|
|
667
|
-
this.x - padding,
|
|
668
|
-
this.y - padding,
|
|
669
|
-
this.width + padding * 2,
|
|
670
|
-
this.height + padding * 2
|
|
671
|
-
);
|
|
672
|
-
}
|
|
673
|
-
vectorInside(vec, padding = 0) {
|
|
674
|
-
return vec.x >= this.x - padding && vec.x <= this.x + this.width + padding && vec.y >= this.y - padding && vec.y <= this.y + this.height + padding;
|
|
675
|
-
}
|
|
676
|
-
};
|
|
677
|
-
|
|
678
440
|
// src/rng.ts
|
|
679
|
-
var
|
|
441
|
+
var RandomNumberGenerator = class {
|
|
680
442
|
__seed;
|
|
681
443
|
_seed;
|
|
682
444
|
_uid_characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
@@ -708,10 +470,6 @@ var Rng = class {
|
|
|
708
470
|
get nexti() {
|
|
709
471
|
return this.nextf * Number.MAX_SAFE_INTEGER | 0;
|
|
710
472
|
}
|
|
711
|
-
// NOTE: as of the core/apparatus consolidation, range(min, max) treats
|
|
712
|
-
// max as EXCLUSIVE (previous published versions of this package treated
|
|
713
|
-
// it as inclusive - if you're upgrading from an older @n3rdw1z4rd/core,
|
|
714
|
-
// range(0, 10) now returns [0, 10) instead of [0, 10]).
|
|
715
473
|
range(min2, max2) {
|
|
716
474
|
if (max2 === void 0) {
|
|
717
475
|
max2 = min2;
|
|
@@ -723,9 +481,6 @@ var Rng = class {
|
|
|
723
481
|
const theta = this.nextf * 2 * PI;
|
|
724
482
|
return [cos(theta), sin(theta)];
|
|
725
483
|
}
|
|
726
|
-
// Box-Muller-ish gaussian sample, mean 0.5 stddev 1/6 (so ~99.7% of
|
|
727
|
-
// samples land in [0, 1]). Uses native Math.log since a pure natural-log
|
|
728
|
-
// implementation isn't part of math.ts yet.
|
|
729
484
|
parkMillerNormal() {
|
|
730
485
|
const mean = 1 / 2;
|
|
731
486
|
const stddev = 1 / 6;
|
|
@@ -773,7 +528,7 @@ var Rng = class {
|
|
|
773
528
|
return rows;
|
|
774
529
|
}
|
|
775
530
|
};
|
|
776
|
-
var rng = new
|
|
531
|
+
var rng = new RandomNumberGenerator();
|
|
777
532
|
|
|
778
533
|
// src/dungeon-generator.ts
|
|
779
534
|
var TILE_EMPTY = 0;
|
|
@@ -930,7 +685,7 @@ function _getShortestPathBetweenRects(rectA, rectB) {
|
|
|
930
685
|
let paths = { a: edgeA[0], b: edgeB[0], distance: Infinity };
|
|
931
686
|
for (const a of edgeA) {
|
|
932
687
|
for (const b of edgeB) {
|
|
933
|
-
const d =
|
|
688
|
+
const d = distance2d(a.x, a.y, b.x, b.y);
|
|
934
689
|
if (d < paths.distance) {
|
|
935
690
|
paths = { a, b, distance: d };
|
|
936
691
|
}
|
|
@@ -1208,58 +963,19 @@ var ECS = class _ECS {
|
|
|
1208
963
|
}
|
|
1209
964
|
};
|
|
1210
965
|
|
|
1211
|
-
// src/
|
|
1212
|
-
var
|
|
1213
|
-
|
|
1214
|
-
|
|
966
|
+
// src/input/index.ts
|
|
967
|
+
var Input = class extends Emitter {
|
|
968
|
+
inputThreshold = 200;
|
|
969
|
+
_keyStates = {};
|
|
970
|
+
_mouseButtonStates = {};
|
|
971
|
+
_mousePosition = [0, 0];
|
|
972
|
+
_mousePosition2 = [0, 0];
|
|
973
|
+
_contextMenuTarget;
|
|
974
|
+
get mousePosition() {
|
|
975
|
+
return this._mousePosition;
|
|
1215
976
|
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
const events = eventName.filter((ev) => typeof ev === "string");
|
|
1219
|
-
events.forEach((event) => {
|
|
1220
|
-
if (!this.listeners.has(event)) {
|
|
1221
|
-
this.listeners.set(event, new Array());
|
|
1222
|
-
}
|
|
1223
|
-
this.listeners.get(event)?.push(listener);
|
|
1224
|
-
});
|
|
1225
|
-
return this;
|
|
1226
|
-
}
|
|
1227
|
-
emit(eventName, ...args) {
|
|
1228
|
-
this.listeners.get(eventName)?.forEach((listener) => listener(...args, eventName));
|
|
1229
|
-
return this;
|
|
1230
|
-
}
|
|
1231
|
-
clear(eventName) {
|
|
1232
|
-
if (eventName) {
|
|
1233
|
-
this.listeners.delete(eventName);
|
|
1234
|
-
} else {
|
|
1235
|
-
this.listeners.clear();
|
|
1236
|
-
}
|
|
1237
|
-
return this;
|
|
1238
|
-
}
|
|
1239
|
-
};
|
|
1240
|
-
var GlobalEmitter = new Emitter();
|
|
1241
|
-
var EventBus = class extends EventTarget {
|
|
1242
|
-
emit(type, detail) {
|
|
1243
|
-
this.dispatchEvent(new CustomEvent(type, { detail }));
|
|
1244
|
-
}
|
|
1245
|
-
on(type, cb) {
|
|
1246
|
-
this.addEventListener(type, cb);
|
|
1247
|
-
}
|
|
1248
|
-
};
|
|
1249
|
-
var eventBus = new EventBus();
|
|
1250
|
-
|
|
1251
|
-
// src/input.ts
|
|
1252
|
-
var Input = class extends Emitter {
|
|
1253
|
-
inputThreshold = 200;
|
|
1254
|
-
_keyStates = {};
|
|
1255
|
-
_mouseButtonStates = {};
|
|
1256
|
-
_mousePosition = [0, 0];
|
|
1257
|
-
_mousePosition2 = [0, 0];
|
|
1258
|
-
get mousePosition() {
|
|
1259
|
-
return this._mousePosition;
|
|
1260
|
-
}
|
|
1261
|
-
get mousePosition2() {
|
|
1262
|
-
return this._mousePosition2;
|
|
977
|
+
get mousePosition2() {
|
|
978
|
+
return this._mousePosition2;
|
|
1263
979
|
}
|
|
1264
980
|
constructor() {
|
|
1265
981
|
super();
|
|
@@ -1270,6 +986,19 @@ var Input = class extends Emitter {
|
|
|
1270
986
|
window.addEventListener("mousemove", this._onMouseMove.bind(this));
|
|
1271
987
|
window.addEventListener("wheel", this._onWheel.bind(this));
|
|
1272
988
|
}
|
|
989
|
+
blockContextMenu(target) {
|
|
990
|
+
this.stopBlockingContextMenu();
|
|
991
|
+
this._contextMenuTarget = target;
|
|
992
|
+
target.addEventListener("contextmenu", this._onContextMenu);
|
|
993
|
+
}
|
|
994
|
+
stopBlockingContextMenu() {
|
|
995
|
+
this._contextMenuTarget?.removeEventListener("contextmenu", this._onContextMenu);
|
|
996
|
+
this._contextMenuTarget = void 0;
|
|
997
|
+
}
|
|
998
|
+
_onContextMenu = (ev) => {
|
|
999
|
+
ev.preventDefault();
|
|
1000
|
+
this.emit("contextmenu");
|
|
1001
|
+
};
|
|
1273
1002
|
_getCommonEventProps(ev) {
|
|
1274
1003
|
const props = {
|
|
1275
1004
|
timeStamp: ev.timeStamp,
|
|
@@ -1280,11 +1009,6 @@ var Input = class extends Emitter {
|
|
|
1280
1009
|
};
|
|
1281
1010
|
return props;
|
|
1282
1011
|
}
|
|
1283
|
-
// private _onContextMenu(ev: MouseEvent) {
|
|
1284
|
-
// ev.preventDefault();
|
|
1285
|
-
// this.emit('contextmenu');
|
|
1286
|
-
// return false;
|
|
1287
|
-
// }
|
|
1288
1012
|
_onKeyDown(ev) {
|
|
1289
1013
|
const props = this._getCommonEventProps(ev);
|
|
1290
1014
|
const { code, key } = ev;
|
|
@@ -1419,6 +1143,9 @@ var Map3D = class {
|
|
|
1419
1143
|
function isNullOrUndefined(target) {
|
|
1420
1144
|
return target === null || target === void 0;
|
|
1421
1145
|
}
|
|
1146
|
+
function isPositiveString(target) {
|
|
1147
|
+
return target.length > 0;
|
|
1148
|
+
}
|
|
1422
1149
|
var getRedYellowGreenGradientHex = (min2, max2) => {
|
|
1423
1150
|
if (max2 === void 0) {
|
|
1424
1151
|
max2 = min2;
|
|
@@ -1443,6 +1170,14 @@ var getRedYellowGreenGradientHex = (min2, max2) => {
|
|
|
1443
1170
|
"#00ff00"
|
|
1444
1171
|
][index];
|
|
1445
1172
|
};
|
|
1173
|
+
function GetUrlParams() {
|
|
1174
|
+
const params = {};
|
|
1175
|
+
const url = new URLSearchParams(location.search);
|
|
1176
|
+
for (const [key, value] of url.entries()) {
|
|
1177
|
+
params[key] = value;
|
|
1178
|
+
}
|
|
1179
|
+
return params;
|
|
1180
|
+
}
|
|
1446
1181
|
|
|
1447
1182
|
// src/noise.ts
|
|
1448
1183
|
import { createNoise2D, createNoise3D, createNoise4D } from "simplex-noise";
|
|
@@ -1505,57 +1240,167 @@ var Noise = class _Noise {
|
|
|
1505
1240
|
}
|
|
1506
1241
|
};
|
|
1507
1242
|
|
|
1508
|
-
// src/
|
|
1509
|
-
var
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1243
|
+
// src/rendering/color.ts
|
|
1244
|
+
var Color = class _Color {
|
|
1245
|
+
_hex = "#ffffffff";
|
|
1246
|
+
_r = 255;
|
|
1247
|
+
_g = 255;
|
|
1248
|
+
_b = 255;
|
|
1249
|
+
_a = 255;
|
|
1250
|
+
get r() {
|
|
1251
|
+
return this._r;
|
|
1516
1252
|
}
|
|
1517
|
-
|
|
1518
|
-
|
|
1253
|
+
set r(value) {
|
|
1254
|
+
this._r = clamp(value, 0, 255);
|
|
1255
|
+
this._hex = this._to_hex();
|
|
1519
1256
|
}
|
|
1520
|
-
|
|
1521
|
-
this.
|
|
1522
|
-
this._bufferCanvas = new OffscreenCanvas(this._screenCanvas.width, this._screenCanvas.height);
|
|
1523
|
-
this.screenContext = this._screenCanvas.getContext("2d");
|
|
1524
|
-
this.bufferContext = this._bufferCanvas.getContext("2d");
|
|
1525
|
-
if (!this.screenContext || !this.bufferContext) {
|
|
1526
|
-
throw "Failed to create CanvasRenderingContext2D";
|
|
1527
|
-
}
|
|
1257
|
+
get g() {
|
|
1258
|
+
return this._g;
|
|
1528
1259
|
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1260
|
+
set g(value) {
|
|
1261
|
+
this._g = clamp(value, 0, 255);
|
|
1262
|
+
this._hex = this._to_hex();
|
|
1263
|
+
}
|
|
1264
|
+
get b() {
|
|
1265
|
+
return this._b;
|
|
1266
|
+
}
|
|
1267
|
+
set b(value) {
|
|
1268
|
+
this._b = clamp(value, 0, 255);
|
|
1269
|
+
this._hex = this._to_hex();
|
|
1270
|
+
}
|
|
1271
|
+
get a() {
|
|
1272
|
+
return this._a;
|
|
1273
|
+
}
|
|
1274
|
+
set a(value) {
|
|
1275
|
+
this._a = clamp(value, 0, 255);
|
|
1276
|
+
this._hex = this._to_hex();
|
|
1277
|
+
}
|
|
1278
|
+
get hexStr() {
|
|
1279
|
+
return this._hex;
|
|
1280
|
+
}
|
|
1281
|
+
set hexStr(value) {
|
|
1282
|
+
if (value.startsWith("#")) {
|
|
1283
|
+
[this._r, this._g, this._b, this._a] = this._parse_hex_color_string(value);
|
|
1284
|
+
this._hex = value;
|
|
1285
|
+
} else {
|
|
1286
|
+
logwrn(`Color: invalid color string: ${value}. Should be a hexadecimal color string (i.e.: '#ffffff' or '#ffffffff'). Keeping the current color.`);
|
|
1532
1287
|
}
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1288
|
+
}
|
|
1289
|
+
get rgba() {
|
|
1290
|
+
return [this._r, this._g, this._b, this._a];
|
|
1291
|
+
}
|
|
1292
|
+
constructor(r = 255, g = 255, b = 255, a = 255) {
|
|
1293
|
+
if (typeof r === "string") {
|
|
1294
|
+
if (r.startsWith("#")) {
|
|
1295
|
+
[r, g, b, a] = this._parse_hex_color_string(r);
|
|
1296
|
+
} else {
|
|
1297
|
+
logwrn(`Color: invalid color string: ${r}. Should be a hexadecimal color string (i.e.: '#ffffff' or '#ffffffff'). Defaulting to opaque white.`);
|
|
1298
|
+
r = g = b = a = 255;
|
|
1299
|
+
}
|
|
1300
|
+
} else {
|
|
1301
|
+
[r, g, b, a] = [r, g, b, a].map((n) => _Color._normalize(n));
|
|
1536
1302
|
}
|
|
1303
|
+
this.r = r;
|
|
1304
|
+
this.g = g;
|
|
1305
|
+
this.b = b;
|
|
1306
|
+
this.a = a;
|
|
1537
1307
|
}
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1308
|
+
static _normalize(value) {
|
|
1309
|
+
return clamp(0 | (value > 0 && value < 1 ? value * 255 : value), 0, 255);
|
|
1310
|
+
}
|
|
1311
|
+
_to_hex() {
|
|
1312
|
+
return `#${this.r.toString(16).padStart(2, "0")}${this.g.toString(16).padStart(2, "0")}${this.b.toString(16).padStart(2, "0")}${this.a.toString(16).padStart(2, "0")}`;
|
|
1313
|
+
}
|
|
1314
|
+
_parse_hex_color_string(hex) {
|
|
1315
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(hex);
|
|
1316
|
+
return result ? [
|
|
1317
|
+
parseInt(result[1], 16),
|
|
1318
|
+
parseInt(result[2], 16),
|
|
1319
|
+
parseInt(result[3], 16),
|
|
1320
|
+
result[4] ? parseInt(result[4], 16) : 255
|
|
1321
|
+
] : [255, 255, 255, 255];
|
|
1322
|
+
}
|
|
1323
|
+
static fromHsv(h, s, v, a = 255) {
|
|
1324
|
+
let r = 0;
|
|
1325
|
+
let g = 0;
|
|
1326
|
+
let b = 0;
|
|
1327
|
+
let i = Math.floor(h * 6);
|
|
1328
|
+
let f = h * 6 - i;
|
|
1329
|
+
let p = v * (1 - s);
|
|
1330
|
+
let q = v * (1 - f * s);
|
|
1331
|
+
let t = v * (1 - (1 - f) * s);
|
|
1332
|
+
switch (i % 6) {
|
|
1333
|
+
case 0:
|
|
1334
|
+
r = v, g = t, b = p;
|
|
1335
|
+
break;
|
|
1336
|
+
case 1:
|
|
1337
|
+
r = q, g = v, b = p;
|
|
1338
|
+
break;
|
|
1339
|
+
case 2:
|
|
1340
|
+
r = p, g = v, b = t;
|
|
1341
|
+
break;
|
|
1342
|
+
case 3:
|
|
1343
|
+
r = p, g = q, b = v;
|
|
1344
|
+
break;
|
|
1345
|
+
case 4:
|
|
1346
|
+
r = t, g = p, b = v;
|
|
1347
|
+
break;
|
|
1348
|
+
case 5:
|
|
1349
|
+
r = v, g = p, b = q;
|
|
1350
|
+
break;
|
|
1548
1351
|
}
|
|
1549
|
-
return
|
|
1352
|
+
return new _Color(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a);
|
|
1550
1353
|
}
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
this.bufferContext.fillRect(x - size / 2, y - size / 2, size, size);
|
|
1354
|
+
static get BLACK() {
|
|
1355
|
+
return new _Color(0, 0, 0, 255);
|
|
1554
1356
|
}
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1357
|
+
static get GRAY() {
|
|
1358
|
+
return new _Color(128, 128, 128, 255);
|
|
1359
|
+
}
|
|
1360
|
+
static get WHITE() {
|
|
1361
|
+
return new _Color(255, 255, 255, 255);
|
|
1362
|
+
}
|
|
1363
|
+
static get RED() {
|
|
1364
|
+
return new _Color(255, 0, 0, 255);
|
|
1365
|
+
}
|
|
1366
|
+
static get GREEN() {
|
|
1367
|
+
return new _Color(0, 255, 0, 255);
|
|
1368
|
+
}
|
|
1369
|
+
static get BLUE() {
|
|
1370
|
+
return new _Color(0, 0, 255, 255);
|
|
1371
|
+
}
|
|
1372
|
+
static get YELLOW() {
|
|
1373
|
+
return new _Color(255, 255, 0, 255);
|
|
1374
|
+
}
|
|
1375
|
+
static get ORANGE() {
|
|
1376
|
+
return new _Color(255, 128, 0, 255);
|
|
1377
|
+
}
|
|
1378
|
+
static get PURPLE() {
|
|
1379
|
+
return new _Color(128, 0, 128, 255);
|
|
1380
|
+
}
|
|
1381
|
+
static get CYAN() {
|
|
1382
|
+
return new _Color(0, 255, 255, 255);
|
|
1383
|
+
}
|
|
1384
|
+
static get MAGENTA() {
|
|
1385
|
+
return new _Color(255, 0, 255, 255);
|
|
1386
|
+
}
|
|
1387
|
+
static fromName(name) {
|
|
1388
|
+
const element = document.createElement("div");
|
|
1389
|
+
element.style.color = name;
|
|
1390
|
+
document.body.appendChild(element);
|
|
1391
|
+
const computedColor = getComputedStyle(element).color;
|
|
1392
|
+
document.body.removeChild(element);
|
|
1393
|
+
const rgba = computedColor.match(/\d+/g);
|
|
1394
|
+
if (rgba && rgba.length === 4) {
|
|
1395
|
+
const [r, g, b, a] = rgba.map(Number);
|
|
1396
|
+
return new _Color(r, g, b, a);
|
|
1397
|
+
} else {
|
|
1398
|
+
logwrn(`Color: invalid CSS color name: ${name}. Defaulting to transparent.`);
|
|
1399
|
+
return _Color.TRANSPARENT;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
static get TRANSPARENT() {
|
|
1403
|
+
return new _Color(0, 0, 0, 0);
|
|
1559
1404
|
}
|
|
1560
1405
|
};
|
|
1561
1406
|
|
|
@@ -1782,547 +1627,212 @@ function PoissonDiskSampler(width, height, minDist, maxPoints = 30) {
|
|
|
1782
1627
|
return samples;
|
|
1783
1628
|
}
|
|
1784
1629
|
|
|
1785
|
-
// src/
|
|
1630
|
+
// src/rendering/canvas-renderer.ts
|
|
1786
1631
|
var CanvasRenderer = class {
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
fontSize = 32;
|
|
1791
|
-
textAlign = "center";
|
|
1792
|
-
textBaseline = "middle";
|
|
1632
|
+
canvas;
|
|
1633
|
+
context;
|
|
1634
|
+
drawCentered = true;
|
|
1793
1635
|
get width() {
|
|
1794
|
-
return this.
|
|
1636
|
+
return this.context.canvas.width;
|
|
1795
1637
|
}
|
|
1796
1638
|
get height() {
|
|
1797
|
-
return this.
|
|
1798
|
-
}
|
|
1799
|
-
get center() {
|
|
1800
|
-
return [this.width / 2, this.height / 2];
|
|
1639
|
+
return this.context.canvas.height;
|
|
1801
1640
|
}
|
|
1802
1641
|
constructor(canvas) {
|
|
1803
|
-
this.
|
|
1804
|
-
this.
|
|
1805
|
-
this.ctx.canvas.style.display = "block";
|
|
1806
|
-
this.ctx.font = `${this.fontSize}px ${this.fontName}`;
|
|
1807
|
-
this.ctx.textAlign = this.textAlign;
|
|
1808
|
-
this.ctx.textBaseline = this.textBaseline;
|
|
1809
|
-
this.resize();
|
|
1810
|
-
this.clear();
|
|
1642
|
+
this.canvas = canvas ?? document.createElement("canvas");
|
|
1643
|
+
this.context = this.canvas.getContext("2d");
|
|
1811
1644
|
}
|
|
1812
|
-
appendTo(target
|
|
1813
|
-
if (this.
|
|
1814
|
-
this.
|
|
1815
|
-
}
|
|
1816
|
-
if (target) {
|
|
1817
|
-
target.appendChild(this.ctx.canvas);
|
|
1818
|
-
if (autoResize) {
|
|
1819
|
-
this.resize();
|
|
1820
|
-
}
|
|
1645
|
+
appendTo(target) {
|
|
1646
|
+
if (this.canvas.parentNode) {
|
|
1647
|
+
this.canvas.parentNode.removeChild(this.canvas);
|
|
1821
1648
|
}
|
|
1649
|
+
target.appendChild(this.canvas);
|
|
1822
1650
|
}
|
|
1823
1651
|
resize(displayWidth, displayHeight) {
|
|
1824
|
-
|
|
1825
|
-
const { width, height } = this.ctx.canvas.parentElement?.getBoundingClientRect() ?? this.ctx.canvas.getBoundingClientRect();
|
|
1652
|
+
const { width, height } = this.canvas.parentElement?.getBoundingClientRect() ?? this.canvas.getBoundingClientRect();
|
|
1826
1653
|
displayWidth = 0 | (displayWidth ?? width);
|
|
1827
1654
|
displayHeight = 0 | (displayHeight ?? height);
|
|
1828
|
-
if (this.width !== displayWidth || this.height !== displayHeight) {
|
|
1829
|
-
this.
|
|
1830
|
-
this.
|
|
1831
|
-
|
|
1655
|
+
if (this.canvas.width !== displayWidth || this.canvas.height !== displayHeight) {
|
|
1656
|
+
this.canvas.width = displayWidth;
|
|
1657
|
+
this.canvas.height = displayHeight;
|
|
1658
|
+
return true;
|
|
1832
1659
|
}
|
|
1833
|
-
return
|
|
1660
|
+
return false;
|
|
1834
1661
|
}
|
|
1835
1662
|
clear() {
|
|
1836
|
-
this.
|
|
1837
|
-
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
this.
|
|
1844
|
-
this.
|
|
1845
|
-
this.
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
this.
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
this.
|
|
1869
|
-
this.
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
this.
|
|
1875
|
-
this.
|
|
1876
|
-
this.
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1663
|
+
this.context.clearRect(0, 0, this.width, this.height);
|
|
1664
|
+
}
|
|
1665
|
+
drawRect(x, y, width, height, params = {}) {
|
|
1666
|
+
if (this.drawCentered) {
|
|
1667
|
+
x -= width / 2;
|
|
1668
|
+
y -= height / 2;
|
|
1669
|
+
}
|
|
1670
|
+
this.context.strokeStyle = params.strokeColor ?? params.color ?? "white";
|
|
1671
|
+
this.context.fillStyle = params.fillColor ?? params.color ?? "white";
|
|
1672
|
+
this.context.lineWidth = params.size ?? 1;
|
|
1673
|
+
if (params.lineDash) {
|
|
1674
|
+
this.context.setLineDash(params.lineDash);
|
|
1675
|
+
}
|
|
1676
|
+
this.context.beginPath();
|
|
1677
|
+
if (params.filled === true) {
|
|
1678
|
+
this.context.fillRect(x, y, width, height);
|
|
1679
|
+
if (params.strokeColor !== void 0) this.context.strokeRect(x, y, width, height);
|
|
1680
|
+
} else {
|
|
1681
|
+
this.context.strokeRect(x, y, width, height);
|
|
1682
|
+
}
|
|
1683
|
+
if (params.lineDash) {
|
|
1684
|
+
this.context.setLineDash([]);
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
drawPixel(x, y, params = {}) {
|
|
1688
|
+
const size = abs(params.size || 1);
|
|
1689
|
+
this.drawRect(x, y, size, size, {
|
|
1690
|
+
...params,
|
|
1691
|
+
filled: true
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1694
|
+
drawLine(x1, y1, x2, y2, params = {}) {
|
|
1695
|
+
this.context.strokeStyle = params.color ?? "white";
|
|
1696
|
+
this.context.lineWidth = params.size ?? 1;
|
|
1697
|
+
if (params.lineDash) {
|
|
1698
|
+
this.context.setLineDash(params.lineDash);
|
|
1699
|
+
}
|
|
1700
|
+
this.context.beginPath();
|
|
1701
|
+
this.context.moveTo(x1, y1);
|
|
1702
|
+
this.context.lineTo(x2, y2);
|
|
1703
|
+
this.context.stroke();
|
|
1704
|
+
if (params.lineDash) {
|
|
1705
|
+
this.context.setLineDash([]);
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
drawCircle(x, y, radius, params = {}) {
|
|
1709
|
+
this.context.strokeStyle = params.strokeColor ?? params.color ?? "white";
|
|
1710
|
+
this.context.fillStyle = params.fillColor ?? params.color ?? "white";
|
|
1711
|
+
this.context.lineWidth = params.size ?? 1;
|
|
1712
|
+
if (params.lineDash) {
|
|
1713
|
+
this.context.setLineDash(params.lineDash);
|
|
1714
|
+
}
|
|
1715
|
+
this.context.beginPath();
|
|
1716
|
+
this.context.arc(x, y, radius, 0, 2 * PI);
|
|
1717
|
+
if (params.filled === true) this.context.fill();
|
|
1718
|
+
this.context.stroke();
|
|
1719
|
+
if (params.lineDash) {
|
|
1720
|
+
this.context.setLineDash([]);
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
drawText(x, y, text, params = {}) {
|
|
1724
|
+
this.context.font = `${params.size ?? 14}px ${params.fontName ?? "monospace"}`;
|
|
1725
|
+
this.context.textAlign = params.textAlign ?? "left";
|
|
1726
|
+
this.context.textBaseline = params.textBaseline ?? "alphabetic";
|
|
1727
|
+
this.context.fillStyle = params.color ?? "white";
|
|
1728
|
+
this.context.fillText(text, x, y);
|
|
1729
|
+
}
|
|
1898
1730
|
};
|
|
1899
1731
|
|
|
1900
|
-
// src/renderer
|
|
1901
|
-
var
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
function CreateWebGlContext(canvas) {
|
|
1907
|
-
return (canvas ?? document.createElement("canvas")).getContext("webgl2");
|
|
1908
|
-
}
|
|
1909
|
-
function ResizeWebGlContext(gl, displayWidth, displayHeight) {
|
|
1910
|
-
const canvas = gl.canvas;
|
|
1911
|
-
const { width, height } = canvas.parentElement?.getBoundingClientRect() ?? canvas.getBoundingClientRect();
|
|
1912
|
-
displayWidth = 0 | (displayWidth ?? width);
|
|
1913
|
-
displayHeight = 0 | (displayHeight ?? height);
|
|
1914
|
-
if (canvas.width !== displayWidth || canvas.height !== displayHeight) {
|
|
1915
|
-
gl.canvas.width = displayWidth;
|
|
1916
|
-
gl.canvas.height = displayHeight;
|
|
1917
|
-
gl.viewport(0, 0, displayWidth, displayHeight);
|
|
1918
|
-
return true;
|
|
1919
|
-
}
|
|
1920
|
-
return false;
|
|
1921
|
-
}
|
|
1922
|
-
function CompileShader(gl, type, source) {
|
|
1923
|
-
const shader = gl.createShader(type);
|
|
1924
|
-
gl.shaderSource(shader, source);
|
|
1925
|
-
gl.compileShader(shader);
|
|
1926
|
-
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
1927
|
-
throw `CompileShader: failed to compile shader: ${gl.getShaderInfoLog(shader)}`;
|
|
1928
|
-
}
|
|
1929
|
-
return shader;
|
|
1930
|
-
}
|
|
1931
|
-
function CreateProgram(gl, vertexShader2, fragmentShader2) {
|
|
1932
|
-
if (typeof vertexShader2 === "string") {
|
|
1933
|
-
vertexShader2 = CompileShader(gl, ShaderType.VERTEX, vertexShader2);
|
|
1934
|
-
}
|
|
1935
|
-
if (typeof fragmentShader2 === "string") {
|
|
1936
|
-
fragmentShader2 = CompileShader(gl, ShaderType.FRAGMENT, fragmentShader2);
|
|
1937
|
-
}
|
|
1938
|
-
const program = gl.createProgram();
|
|
1939
|
-
gl.attachShader(program, vertexShader2);
|
|
1940
|
-
gl.attachShader(program, fragmentShader2);
|
|
1941
|
-
gl.linkProgram(program);
|
|
1942
|
-
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
1943
|
-
throw `CreateProgram: failed to link program: ${gl.getProgramInfoLog(program)}`;
|
|
1944
|
-
}
|
|
1945
|
-
return program;
|
|
1946
|
-
}
|
|
1947
|
-
function GetProgramLocations(gl, program) {
|
|
1948
|
-
const attributes = {};
|
|
1949
|
-
const attributeCount = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
|
|
1950
|
-
for (let i = 0; i < attributeCount; i++) {
|
|
1951
|
-
const info = gl.getActiveAttrib(program, i);
|
|
1952
|
-
attributes[info.name] = gl.getAttribLocation(program, info.name);
|
|
1953
|
-
}
|
|
1954
|
-
const uniforms = {};
|
|
1955
|
-
const uniformCount = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
|
|
1956
|
-
for (let i = 0; i < uniformCount; i++) {
|
|
1957
|
-
const info = gl.getActiveUniform(program, i);
|
|
1958
|
-
uniforms[info.name] = gl.getUniformLocation(program, info.name);
|
|
1959
|
-
}
|
|
1960
|
-
return { attributes, uniforms };
|
|
1961
|
-
}
|
|
1962
|
-
function CreateProgramInfo(gl, vertexShaderSource, fragmentShaderSource) {
|
|
1963
|
-
const program = CreateProgram(
|
|
1964
|
-
gl,
|
|
1965
|
-
vertexShaderSource,
|
|
1966
|
-
fragmentShaderSource
|
|
1967
|
-
);
|
|
1968
|
-
const locations = GetProgramLocations(gl, program);
|
|
1969
|
-
return { program, ...locations };
|
|
1970
|
-
}
|
|
1971
|
-
|
|
1972
|
-
// src/renderer/webgl-renderer.ts
|
|
1973
|
-
var WebGlRenderer = class {
|
|
1974
|
-
gl;
|
|
1975
|
-
programInfo;
|
|
1976
|
-
get canvas() {
|
|
1977
|
-
return this.gl.canvas;
|
|
1978
|
-
}
|
|
1732
|
+
// src/rendering/particle-renderer.ts
|
|
1733
|
+
var ParticleRenderer = class {
|
|
1734
|
+
_screenCanvas;
|
|
1735
|
+
_bufferCanvas;
|
|
1736
|
+
screenContext;
|
|
1737
|
+
bufferContext;
|
|
1979
1738
|
get width() {
|
|
1980
|
-
return this.
|
|
1739
|
+
return this._screenCanvas.width;
|
|
1981
1740
|
}
|
|
1982
1741
|
get height() {
|
|
1983
|
-
return this.
|
|
1742
|
+
return this._screenCanvas.height;
|
|
1984
1743
|
}
|
|
1985
|
-
constructor() {
|
|
1986
|
-
this.
|
|
1987
|
-
this.
|
|
1744
|
+
constructor(canvas) {
|
|
1745
|
+
this._screenCanvas = canvas ?? document.createElement("canvas");
|
|
1746
|
+
this._bufferCanvas = new OffscreenCanvas(this._screenCanvas.width, this._screenCanvas.height);
|
|
1747
|
+
this.screenContext = this._screenCanvas.getContext("2d");
|
|
1748
|
+
this.bufferContext = this._bufferCanvas.getContext("2d");
|
|
1749
|
+
if (!this.screenContext || !this.bufferContext) {
|
|
1750
|
+
throw "Failed to create CanvasRenderingContext2D";
|
|
1751
|
+
}
|
|
1988
1752
|
}
|
|
1989
|
-
appendTo(
|
|
1990
|
-
if (this.
|
|
1991
|
-
this.
|
|
1753
|
+
appendTo(target, autoResize = true) {
|
|
1754
|
+
if (this._screenCanvas.parentNode) {
|
|
1755
|
+
this._screenCanvas.parentNode.removeChild(this._screenCanvas);
|
|
1992
1756
|
}
|
|
1993
|
-
|
|
1994
|
-
|
|
1757
|
+
target.appendChild(this._screenCanvas);
|
|
1758
|
+
if (autoResize) {
|
|
1995
1759
|
this.resize();
|
|
1996
1760
|
}
|
|
1997
1761
|
}
|
|
1998
1762
|
resize(displayWidth, displayHeight) {
|
|
1999
|
-
const { width, height } = this.
|
|
1763
|
+
const { width, height } = this._screenCanvas.parentElement?.getBoundingClientRect() ?? this._screenCanvas.getBoundingClientRect();
|
|
2000
1764
|
displayWidth = 0 | (displayWidth ?? width);
|
|
2001
1765
|
displayHeight = 0 | (displayHeight ?? height);
|
|
2002
|
-
if (this.width !== displayWidth || this.height !== displayHeight) {
|
|
2003
|
-
this.
|
|
2004
|
-
this.
|
|
2005
|
-
this.
|
|
1766
|
+
if (this._screenCanvas.width !== displayWidth || this._screenCanvas.height !== displayHeight) {
|
|
1767
|
+
this._screenCanvas.width = displayWidth;
|
|
1768
|
+
this._screenCanvas.height = displayHeight;
|
|
1769
|
+
this._bufferCanvas.width = displayWidth;
|
|
1770
|
+
this._bufferCanvas.height = displayHeight;
|
|
2006
1771
|
return true;
|
|
2007
1772
|
}
|
|
2008
1773
|
return false;
|
|
2009
1774
|
}
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
1775
|
+
setPixel(x, y, color, size = 2) {
|
|
1776
|
+
this.bufferContext.fillStyle = color.hexStr;
|
|
1777
|
+
this.bufferContext.fillRect(x - size / 2, y - size / 2, size, size);
|
|
1778
|
+
}
|
|
1779
|
+
render() {
|
|
1780
|
+
this.screenContext.clearRect(0, 0, this._screenCanvas.width, this._screenCanvas.height);
|
|
1781
|
+
this.screenContext.drawImage(this._bufferCanvas, 0, 0);
|
|
1782
|
+
this.bufferContext.clearRect(0, 0, this._screenCanvas.width, this._screenCanvas.height);
|
|
2013
1783
|
}
|
|
2014
1784
|
};
|
|
2015
1785
|
|
|
2016
|
-
// src/
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
[0, -1, 1],
|
|
2033
|
-
[0, 1, -1],
|
|
2034
|
-
[0, -1, -1]
|
|
2035
|
-
];
|
|
2036
|
-
this.p = [];
|
|
2037
|
-
for (let i = 0; i < 256; i++) {
|
|
2038
|
-
this.p.push(Math.floor(rng.nextf * 256));
|
|
2039
|
-
}
|
|
2040
|
-
this.perm = [];
|
|
2041
|
-
for (let i = 0; i < 512; i++) {
|
|
2042
|
-
this.perm.push(this.p[i & 255]);
|
|
1786
|
+
// src/rendering/three/cube-sphere-geometry.ts
|
|
1787
|
+
import { BoxGeometry, Vector3 } from "three";
|
|
1788
|
+
var CubeSphereGeometry = class extends BoxGeometry {
|
|
1789
|
+
constructor(size, segments) {
|
|
1790
|
+
size = Math.floor(size);
|
|
1791
|
+
segments = Math.floor(segments);
|
|
1792
|
+
super(size, size, size, segments, segments, segments);
|
|
1793
|
+
this.size = size;
|
|
1794
|
+
this.segments = segments;
|
|
1795
|
+
this._halfSize = this.size / 2;
|
|
1796
|
+
const attrPositions = this.attributes.position;
|
|
1797
|
+
const position = new Vector3();
|
|
1798
|
+
for (let i = 0; i < attrPositions.count; i++) {
|
|
1799
|
+
position.fromBufferAttribute(attrPositions, i);
|
|
1800
|
+
position.normalize().multiplyScalar(this._halfSize);
|
|
1801
|
+
attrPositions.setXYZ(i, position.x, position.y, position.z);
|
|
2043
1802
|
}
|
|
1803
|
+
attrPositions.needsUpdate = true;
|
|
2044
1804
|
}
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
const
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
const Y0 = j - t;
|
|
2058
|
-
const x0 = xin - X0;
|
|
2059
|
-
const y0 = yin - Y0;
|
|
2060
|
-
let i1, j1;
|
|
2061
|
-
if (x0 > y0) {
|
|
2062
|
-
i1 = 1;
|
|
2063
|
-
j1 = 0;
|
|
2064
|
-
} else {
|
|
2065
|
-
i1 = 0;
|
|
2066
|
-
j1 = 1;
|
|
2067
|
-
}
|
|
2068
|
-
const x1 = x0 - i1 + G2;
|
|
2069
|
-
const y1 = y0 - j1 + G2;
|
|
2070
|
-
const x2 = x0 - 1 + 2 * G2;
|
|
2071
|
-
const y2 = y0 - 1 + 2 * G2;
|
|
2072
|
-
const ii = i & 255;
|
|
2073
|
-
const jj = j & 255;
|
|
2074
|
-
const gi0 = this.perm[ii + this.perm[jj]] % 12;
|
|
2075
|
-
const gi1 = this.perm[ii + i1 + this.perm[jj + j1]] % 12;
|
|
2076
|
-
const gi2 = this.perm[ii + 1 + this.perm[jj + 1]] % 12;
|
|
2077
|
-
let t0 = 0.5 - x0 * x0 - y0 * y0;
|
|
2078
|
-
if (t0 < 0) {
|
|
2079
|
-
n0 = 0;
|
|
2080
|
-
} else {
|
|
2081
|
-
t0 *= t0;
|
|
2082
|
-
n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0);
|
|
2083
|
-
}
|
|
2084
|
-
let t1 = 0.5 - x1 * x1 - y1 * y1;
|
|
2085
|
-
if (t1 < 0) {
|
|
2086
|
-
n1 = 0;
|
|
2087
|
-
} else {
|
|
2088
|
-
t1 *= t1;
|
|
2089
|
-
n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1);
|
|
1805
|
+
size;
|
|
1806
|
+
segments;
|
|
1807
|
+
_halfSize;
|
|
1808
|
+
applyFractalBrownianMotion(octaves, persistence, scale, amplitude) {
|
|
1809
|
+
const attrPositions = this.attributes.position;
|
|
1810
|
+
const position = new Vector3();
|
|
1811
|
+
for (let i = 0; i < attrPositions.count; i++) {
|
|
1812
|
+
position.fromBufferAttribute(attrPositions, i);
|
|
1813
|
+
position.normalize().multiplyScalar(this._halfSize);
|
|
1814
|
+
const noiseValue = this.fBm(position.x * scale, position.y * scale, position.z * scale, octaves, persistence);
|
|
1815
|
+
position.addScaledVector(position.clone().normalize(), noiseValue * amplitude);
|
|
1816
|
+
attrPositions.setXYZ(i, position.x, position.y, position.z);
|
|
2090
1817
|
}
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
1818
|
+
attrPositions.needsUpdate = true;
|
|
1819
|
+
}
|
|
1820
|
+
fBm(x, y, z, octaves, persistence) {
|
|
1821
|
+
let total = 0;
|
|
1822
|
+
let frequency = 1;
|
|
1823
|
+
let amplitude = 1;
|
|
1824
|
+
let maxValue = 0;
|
|
1825
|
+
for (let i = 0; i < octaves; i++) {
|
|
1826
|
+
total += Noise.noise3d(x * frequency, y * frequency, z * frequency) * amplitude;
|
|
1827
|
+
maxValue += amplitude;
|
|
1828
|
+
amplitude *= persistence;
|
|
1829
|
+
frequency *= 2;
|
|
2097
1830
|
}
|
|
2098
|
-
return
|
|
2099
|
-
}
|
|
2100
|
-
// 3D simplex noise
|
|
2101
|
-
noise3d(xin, yin, zin) {
|
|
2102
|
-
let n0, n1, n2, n3;
|
|
2103
|
-
const F3 = 1 / 3;
|
|
2104
|
-
const s = (xin + yin + zin) * F3;
|
|
2105
|
-
const i = Math.floor(xin + s);
|
|
2106
|
-
const j = Math.floor(yin + s);
|
|
2107
|
-
const k = Math.floor(zin + s);
|
|
2108
|
-
const G3 = 1 / 6;
|
|
2109
|
-
const t = (i + j + k) * G3;
|
|
2110
|
-
const X0 = i - t;
|
|
2111
|
-
const Y0 = j - t;
|
|
2112
|
-
const Z0 = k - t;
|
|
2113
|
-
const x0 = xin - X0;
|
|
2114
|
-
const y0 = yin - Y0;
|
|
2115
|
-
const z0 = zin - Z0;
|
|
2116
|
-
let i1, j1, k1;
|
|
2117
|
-
let i2, j2, k2;
|
|
2118
|
-
if (x0 >= y0) {
|
|
2119
|
-
if (y0 >= z0) {
|
|
2120
|
-
i1 = 1;
|
|
2121
|
-
j1 = 0;
|
|
2122
|
-
k1 = 0;
|
|
2123
|
-
i2 = 1;
|
|
2124
|
-
j2 = 1;
|
|
2125
|
-
k2 = 0;
|
|
2126
|
-
} else if (x0 >= z0) {
|
|
2127
|
-
i1 = 1;
|
|
2128
|
-
j1 = 0;
|
|
2129
|
-
k1 = 0;
|
|
2130
|
-
i2 = 1;
|
|
2131
|
-
j2 = 0;
|
|
2132
|
-
k2 = 1;
|
|
2133
|
-
} else {
|
|
2134
|
-
i1 = 0;
|
|
2135
|
-
j1 = 0;
|
|
2136
|
-
k1 = 1;
|
|
2137
|
-
i2 = 1;
|
|
2138
|
-
j2 = 0;
|
|
2139
|
-
k2 = 1;
|
|
2140
|
-
}
|
|
2141
|
-
} else {
|
|
2142
|
-
if (y0 < z0) {
|
|
2143
|
-
i1 = 0;
|
|
2144
|
-
j1 = 0;
|
|
2145
|
-
k1 = 1;
|
|
2146
|
-
i2 = 0;
|
|
2147
|
-
j2 = 1;
|
|
2148
|
-
k2 = 1;
|
|
2149
|
-
} else if (x0 < z0) {
|
|
2150
|
-
i1 = 0;
|
|
2151
|
-
j1 = 1;
|
|
2152
|
-
k1 = 0;
|
|
2153
|
-
i2 = 0;
|
|
2154
|
-
j2 = 1;
|
|
2155
|
-
k2 = 1;
|
|
2156
|
-
} else {
|
|
2157
|
-
i1 = 0;
|
|
2158
|
-
j1 = 1;
|
|
2159
|
-
k1 = 0;
|
|
2160
|
-
i2 = 1;
|
|
2161
|
-
j2 = 1;
|
|
2162
|
-
k2 = 0;
|
|
2163
|
-
}
|
|
2164
|
-
}
|
|
2165
|
-
const x1 = x0 - i1 + G3;
|
|
2166
|
-
const y1 = y0 - j1 + G3;
|
|
2167
|
-
const z1 = z0 - k1 + G3;
|
|
2168
|
-
const x2 = x0 - i2 + 2 * G3;
|
|
2169
|
-
const y2 = y0 - j2 + 2 * G3;
|
|
2170
|
-
const z2 = z0 - k2 + 2 * G3;
|
|
2171
|
-
const x3 = x0 - 1 + 3 * G3;
|
|
2172
|
-
const y3 = y0 - 1 + 3 * G3;
|
|
2173
|
-
const z3 = z0 - 1 + 3 * G3;
|
|
2174
|
-
const ii = i & 255;
|
|
2175
|
-
const jj = j & 255;
|
|
2176
|
-
const kk = k & 255;
|
|
2177
|
-
const gi0 = this.perm[ii + this.perm[jj + this.perm[kk]]] % 12;
|
|
2178
|
-
const gi1 = this.perm[ii + i1 + this.perm[jj + j1 + this.perm[kk + k1]]] % 12;
|
|
2179
|
-
const gi2 = this.perm[ii + i2 + this.perm[jj + j2 + this.perm[kk + k2]]] % 12;
|
|
2180
|
-
const gi3 = this.perm[ii + 1 + this.perm[jj + 1 + this.perm[kk + 1]]] % 12;
|
|
2181
|
-
let t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
|
|
2182
|
-
if (t0 < 0) {
|
|
2183
|
-
n0 = 0;
|
|
2184
|
-
} else {
|
|
2185
|
-
t0 *= t0;
|
|
2186
|
-
n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0, z0);
|
|
2187
|
-
}
|
|
2188
|
-
let t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1;
|
|
2189
|
-
if (t1 < 0) {
|
|
2190
|
-
n1 = 0;
|
|
2191
|
-
} else {
|
|
2192
|
-
t1 *= t1;
|
|
2193
|
-
n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1, z1);
|
|
2194
|
-
}
|
|
2195
|
-
let t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2;
|
|
2196
|
-
if (t2 < 0) {
|
|
2197
|
-
n2 = 0;
|
|
2198
|
-
} else {
|
|
2199
|
-
t2 *= t2;
|
|
2200
|
-
n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2, z2);
|
|
2201
|
-
}
|
|
2202
|
-
let t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3;
|
|
2203
|
-
if (t3 < 0) {
|
|
2204
|
-
n3 = 0;
|
|
2205
|
-
} else {
|
|
2206
|
-
t3 *= t3;
|
|
2207
|
-
n3 = t3 * t3 * this.dot(this.grad3[gi3], x3, y3, z3);
|
|
2208
|
-
}
|
|
2209
|
-
return 32 * (n0 + n1 + n2 + n3);
|
|
2210
|
-
}
|
|
2211
|
-
};
|
|
2212
|
-
|
|
2213
|
-
// src/spatial-partition-3d.ts
|
|
2214
|
-
var SpatialPartition3d = class {
|
|
2215
|
-
cells;
|
|
2216
|
-
cellSize;
|
|
2217
|
-
entities;
|
|
2218
|
-
constructor(cellSize, entities) {
|
|
2219
|
-
this.cellSize = cellSize;
|
|
2220
|
-
this.entities = entities;
|
|
2221
|
-
const gridSize = Math.ceil(1 / cellSize);
|
|
2222
|
-
this.cells = Array.from(
|
|
2223
|
-
{ length: gridSize },
|
|
2224
|
-
() => Array.from(
|
|
2225
|
-
{ length: gridSize },
|
|
2226
|
-
() => Array.from({ length: gridSize }, () => [])
|
|
2227
|
-
)
|
|
2228
|
-
);
|
|
2229
|
-
for (const entity of this.entities) {
|
|
2230
|
-
this.addEntity(entity);
|
|
2231
|
-
}
|
|
2232
|
-
}
|
|
2233
|
-
getCell(x, y, z) {
|
|
2234
|
-
const cx = Math.floor(x / this.cellSize);
|
|
2235
|
-
const cy = Math.floor(y / this.cellSize);
|
|
2236
|
-
const cz = Math.floor(z / this.cellSize);
|
|
2237
|
-
return this.cells[cz][cy][cx];
|
|
2238
|
-
}
|
|
2239
|
-
getCellNeighbors(cx, cy, cz) {
|
|
2240
|
-
const neighbors = [];
|
|
2241
|
-
const gridSize = this.cells.length;
|
|
2242
|
-
for (let dz = -1; dz <= 1; dz++) {
|
|
2243
|
-
for (let dy = -1; dy <= 1; dy++) {
|
|
2244
|
-
for (let dx = -1; dx <= 1; dx++) {
|
|
2245
|
-
let nx = (cx + dx + gridSize) % gridSize;
|
|
2246
|
-
let ny = (cy + dy + gridSize) % gridSize;
|
|
2247
|
-
let nz = (cz + dz + gridSize) % gridSize;
|
|
2248
|
-
neighbors.push(this.cells[nz][ny][nx]);
|
|
2249
|
-
}
|
|
2250
|
-
}
|
|
2251
|
-
}
|
|
2252
|
-
return neighbors;
|
|
2253
|
-
}
|
|
2254
|
-
addEntity(entity) {
|
|
2255
|
-
const cell = this.getCell(entity.x, entity.y, entity.z);
|
|
2256
|
-
cell.push(entity);
|
|
2257
|
-
}
|
|
2258
|
-
};
|
|
2259
|
-
|
|
2260
|
-
// src/tilemap.ts
|
|
2261
|
-
var Tilemap = class {
|
|
2262
|
-
map = /* @__PURE__ */ new Map();
|
|
2263
|
-
_key(x, y) {
|
|
2264
|
-
x = floor(x);
|
|
2265
|
-
y = floor(y);
|
|
2266
|
-
return `${x}x${y}`;
|
|
2267
|
-
}
|
|
2268
|
-
get(x, y) {
|
|
2269
|
-
return this.map.get(this._key(x, y));
|
|
2270
|
-
}
|
|
2271
|
-
set(x, y, v) {
|
|
2272
|
-
this.map.set(this._key(x, y), v);
|
|
2273
|
-
}
|
|
2274
|
-
};
|
|
2275
|
-
|
|
2276
|
-
// src/three/cube-sphere-geometry.ts
|
|
2277
|
-
import { BoxGeometry, Vector3 } from "three";
|
|
2278
|
-
var CubeSphereGeometry = class extends BoxGeometry {
|
|
2279
|
-
constructor(size, segments) {
|
|
2280
|
-
size = Math.floor(size);
|
|
2281
|
-
segments = Math.floor(segments);
|
|
2282
|
-
super(size, size, size, segments, segments, segments);
|
|
2283
|
-
this.size = size;
|
|
2284
|
-
this.segments = segments;
|
|
2285
|
-
this._halfSize = this.size / 2;
|
|
2286
|
-
const attrPositions = this.attributes.position;
|
|
2287
|
-
const position = new Vector3();
|
|
2288
|
-
for (let i = 0; i < attrPositions.count; i++) {
|
|
2289
|
-
position.fromBufferAttribute(attrPositions, i);
|
|
2290
|
-
position.normalize().multiplyScalar(this._halfSize);
|
|
2291
|
-
attrPositions.setXYZ(i, position.x, position.y, position.z);
|
|
2292
|
-
}
|
|
2293
|
-
attrPositions.needsUpdate = true;
|
|
2294
|
-
}
|
|
2295
|
-
size;
|
|
2296
|
-
segments;
|
|
2297
|
-
_halfSize;
|
|
2298
|
-
applyFractalBrownianMotion(octaves, persistence, scale, amplitude) {
|
|
2299
|
-
const attrPositions = this.attributes.position;
|
|
2300
|
-
const position = new Vector3();
|
|
2301
|
-
for (let i = 0; i < attrPositions.count; i++) {
|
|
2302
|
-
position.fromBufferAttribute(attrPositions, i);
|
|
2303
|
-
position.normalize().multiplyScalar(this._halfSize);
|
|
2304
|
-
const noiseValue = this.fBm(position.x * scale, position.y * scale, position.z * scale, octaves, persistence);
|
|
2305
|
-
position.addScaledVector(position.clone().normalize(), noiseValue * amplitude);
|
|
2306
|
-
attrPositions.setXYZ(i, position.x, position.y, position.z);
|
|
2307
|
-
}
|
|
2308
|
-
attrPositions.needsUpdate = true;
|
|
2309
|
-
}
|
|
2310
|
-
fBm(x, y, z, octaves, persistence) {
|
|
2311
|
-
let total = 0;
|
|
2312
|
-
let frequency = 1;
|
|
2313
|
-
let amplitude = 1;
|
|
2314
|
-
let maxValue = 0;
|
|
2315
|
-
for (let i = 0; i < octaves; i++) {
|
|
2316
|
-
total += Noise.noise3d(x * frequency, y * frequency, z * frequency) * amplitude;
|
|
2317
|
-
maxValue += amplitude;
|
|
2318
|
-
amplitude *= persistence;
|
|
2319
|
-
frequency *= 2;
|
|
2320
|
-
}
|
|
2321
|
-
return total / maxValue;
|
|
1831
|
+
return total / maxValue;
|
|
2322
1832
|
}
|
|
2323
1833
|
};
|
|
2324
1834
|
|
|
2325
|
-
// src/three/texture-atlas.ts
|
|
1835
|
+
// src/rendering/three/texture-atlas.ts
|
|
2326
1836
|
import { TextureLoader, MeshLambertMaterial, NearestFilter, RepeatWrapping } from "three";
|
|
2327
1837
|
function LoadTexture(url) {
|
|
2328
1838
|
return new Promise((res, rej) => {
|
|
@@ -2447,10 +1957,10 @@ var AtlasTextureMaterial = class _AtlasTextureMaterial extends MeshLambertMateri
|
|
|
2447
1957
|
}
|
|
2448
1958
|
};
|
|
2449
1959
|
|
|
2450
|
-
// src/three/threejs-boiler-plate.ts
|
|
1960
|
+
// src/rendering/three/threejs-boiler-plate.ts
|
|
2451
1961
|
import { AmbientLight, BoxGeometry as BoxGeometry2, DirectionalLight, GridHelper, Mesh, MeshLambertMaterial as MeshLambertMaterial2, PlaneGeometry, Raycaster, Scene, Vector2, WebGLRenderer } from "three";
|
|
2452
1962
|
|
|
2453
|
-
// src/three/threejs-camera-rig.ts
|
|
1963
|
+
// src/rendering/three/threejs-camera-rig.ts
|
|
2454
1964
|
import { PerspectiveCamera, Group } from "three";
|
|
2455
1965
|
var ThreeJsCameraRig = class extends Group {
|
|
2456
1966
|
gimbal;
|
|
@@ -2492,7 +2002,7 @@ var ThreeJsCameraRig = class extends Group {
|
|
|
2492
2002
|
}
|
|
2493
2003
|
};
|
|
2494
2004
|
|
|
2495
|
-
// src/three/threejs-boiler-plate.ts
|
|
2005
|
+
// src/rendering/three/threejs-boiler-plate.ts
|
|
2496
2006
|
var ThreeJsBoilerPlate = class {
|
|
2497
2007
|
clock = new Clock();
|
|
2498
2008
|
scene = new Scene();
|
|
@@ -2517,9 +2027,6 @@ var ThreeJsBoilerPlate = class {
|
|
|
2517
2027
|
this.appendTo(params.parentElement);
|
|
2518
2028
|
}
|
|
2519
2029
|
}
|
|
2520
|
-
// Mutually exclusive with enableOrbitControls() - pick one. Gives you
|
|
2521
|
-
// manual orbit()/dolly() with tilt clamping and target-following, driven
|
|
2522
|
-
// by this.input's mouse events.
|
|
2523
2030
|
enableCameraRigControls() {
|
|
2524
2031
|
this.orbitControls?.dispose();
|
|
2525
2032
|
this.orbitControls = void 0;
|
|
@@ -2529,12 +2036,6 @@ var ThreeJsBoilerPlate = class {
|
|
|
2529
2036
|
}
|
|
2530
2037
|
}).on("mouse_wheel", ({ deltaY }) => this.cameraRig.dolly(deltaY));
|
|
2531
2038
|
}
|
|
2532
|
-
// Mutually exclusive with enableCameraRigControls() - pick one. Uses
|
|
2533
|
-
// Three's own OrbitControls instead of the hand-rolled rig math; call
|
|
2534
|
-
// update() once per frame in your render loop while this is active.
|
|
2535
|
-
// Async because OrbitControls only ships as an ESM-only addon module -
|
|
2536
|
-
// a dynamic import avoids forcing this whole package (built as both
|
|
2537
|
-
// CJS and ESM) to statically import an ESM-only file.
|
|
2538
2039
|
async enableOrbitControls() {
|
|
2539
2040
|
const { OrbitControls } = await import("three/examples/jsm/Addons.js");
|
|
2540
2041
|
this.orbitControls = new OrbitControls(this.camera, this.canvas);
|
|
@@ -2542,7 +2043,6 @@ var ThreeJsBoilerPlate = class {
|
|
|
2542
2043
|
this.orbitControls.maxDistance = 100;
|
|
2543
2044
|
this.orbitControls.update();
|
|
2544
2045
|
}
|
|
2545
|
-
// Call once per frame if enableOrbitControls() is active - no-op otherwise.
|
|
2546
2046
|
update() {
|
|
2547
2047
|
this.orbitControls?.update();
|
|
2548
2048
|
}
|
|
@@ -2600,7 +2100,7 @@ var ThreeJsBoilerPlate = class {
|
|
|
2600
2100
|
}
|
|
2601
2101
|
};
|
|
2602
2102
|
|
|
2603
|
-
// src/three/threejs-player-controller.ts
|
|
2103
|
+
// src/rendering/three/threejs-player-controller.ts
|
|
2604
2104
|
import { Group as Group2, Vector3 as Vector32 } from "three";
|
|
2605
2105
|
var ThreeJsPlayerController = class extends Group2 {
|
|
2606
2106
|
moveSpeed = 1;
|
|
@@ -2619,7 +2119,7 @@ var ThreeJsPlayerController = class extends Group2 {
|
|
|
2619
2119
|
}
|
|
2620
2120
|
};
|
|
2621
2121
|
|
|
2622
|
-
// src/three/voxel-mesh.ts
|
|
2122
|
+
// src/rendering/three/voxel-mesh.ts
|
|
2623
2123
|
import { BufferAttribute, BufferGeometry, Color as Color2, Mesh as Mesh2 } from "three";
|
|
2624
2124
|
var VoxelMesh = class extends Mesh2 {
|
|
2625
2125
|
type = "VoxelMesh";
|
|
@@ -2969,8 +2469,57 @@ var Colors = {
|
|
|
2969
2469
|
]
|
|
2970
2470
|
};
|
|
2971
2471
|
|
|
2972
|
-
// src/three/particle-system-3d.ts
|
|
2472
|
+
// src/rendering/three/particle-system-3d.ts
|
|
2973
2473
|
import { BufferGeometry as BufferGeometry2, Float32BufferAttribute, Group as Group3, Points, ShaderMaterial, Vector3 as Vector33 } from "three";
|
|
2474
|
+
|
|
2475
|
+
// src/spatial-partition-3d.ts
|
|
2476
|
+
var SpatialPartition3d = class {
|
|
2477
|
+
cells;
|
|
2478
|
+
cellSize;
|
|
2479
|
+
entities;
|
|
2480
|
+
constructor(cellSize, entities) {
|
|
2481
|
+
this.cellSize = cellSize;
|
|
2482
|
+
this.entities = entities;
|
|
2483
|
+
const gridSize = Math.ceil(1 / cellSize);
|
|
2484
|
+
this.cells = Array.from(
|
|
2485
|
+
{ length: gridSize },
|
|
2486
|
+
() => Array.from(
|
|
2487
|
+
{ length: gridSize },
|
|
2488
|
+
() => Array.from({ length: gridSize }, () => [])
|
|
2489
|
+
)
|
|
2490
|
+
);
|
|
2491
|
+
for (const entity of this.entities) {
|
|
2492
|
+
this.addEntity(entity);
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
getCell(x, y, z) {
|
|
2496
|
+
const cx = Math.floor(x / this.cellSize);
|
|
2497
|
+
const cy = Math.floor(y / this.cellSize);
|
|
2498
|
+
const cz = Math.floor(z / this.cellSize);
|
|
2499
|
+
return this.cells[cz][cy][cx];
|
|
2500
|
+
}
|
|
2501
|
+
getCellNeighbors(cx, cy, cz) {
|
|
2502
|
+
const neighbors = [];
|
|
2503
|
+
const gridSize = this.cells.length;
|
|
2504
|
+
for (let dz = -1; dz <= 1; dz++) {
|
|
2505
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
2506
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
2507
|
+
let nx = (cx + dx + gridSize) % gridSize;
|
|
2508
|
+
let ny = (cy + dy + gridSize) % gridSize;
|
|
2509
|
+
let nz = (cz + dz + gridSize) % gridSize;
|
|
2510
|
+
neighbors.push(this.cells[nz][ny][nx]);
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
return neighbors;
|
|
2515
|
+
}
|
|
2516
|
+
addEntity(entity) {
|
|
2517
|
+
const cell = this.getCell(entity.x, entity.y, entity.z);
|
|
2518
|
+
cell.push(entity);
|
|
2519
|
+
}
|
|
2520
|
+
};
|
|
2521
|
+
|
|
2522
|
+
// src/rendering/three/particle-system-3d.ts
|
|
2974
2523
|
var vertexShader = `
|
|
2975
2524
|
uniform float pointSize;
|
|
2976
2525
|
|
|
@@ -3159,7 +2708,7 @@ var ParticleSystem3d = class extends Group3 {
|
|
|
3159
2708
|
}
|
|
3160
2709
|
};
|
|
3161
2710
|
|
|
3162
|
-
// src/three/asteroid-mesh.ts
|
|
2711
|
+
// src/rendering/three/asteroid-mesh.ts
|
|
3163
2712
|
import { IcosahedronGeometry, Mesh as Mesh3, MeshStandardMaterial as MeshStandardMaterial2 } from "three";
|
|
3164
2713
|
import { createNoise3D as createNoise3D2 } from "simplex-noise";
|
|
3165
2714
|
var AsteroidMesh = class extends Mesh3 {
|
|
@@ -3194,7 +2743,7 @@ var AsteroidMesh = class extends Mesh3 {
|
|
|
3194
2743
|
}
|
|
3195
2744
|
};
|
|
3196
2745
|
|
|
3197
|
-
// src/three/starfield.ts
|
|
2746
|
+
// src/rendering/three/starfield.ts
|
|
3198
2747
|
import { BufferAttribute as BufferAttribute2, BufferGeometry as BufferGeometry3, Group as Group4, Mesh as Mesh4, MeshBasicMaterial as MeshBasicMaterial2, PointLight, Points as Points2, PointsMaterial, SphereGeometry, Vector3 as Vector34 } from "three";
|
|
3199
2748
|
function CreateStarfield(radius = 1e3, count = 5e3, color = 16777215) {
|
|
3200
2749
|
const geometry = new BufferGeometry3();
|
|
@@ -3233,7 +2782,7 @@ function CreateSystemStar(position) {
|
|
|
3233
2782
|
return star;
|
|
3234
2783
|
}
|
|
3235
2784
|
|
|
3236
|
-
// src/three/palette-controller.ts
|
|
2785
|
+
// src/rendering/three/palette-controller.ts
|
|
3237
2786
|
import { Color as Color3, Vector3 as Vector35 } from "three";
|
|
3238
2787
|
async function CreatePaletteController(parentGui, colorPalette, onChange, folderName = "palette") {
|
|
3239
2788
|
const { Controller } = await import("three/examples/jsm/libs/lil-gui.module.min.js");
|
|
@@ -3338,7 +2887,7 @@ async function CreatePaletteController(parentGui, colorPalette, onChange, folder
|
|
|
3338
2887
|
return new PaletteControllerImpl();
|
|
3339
2888
|
}
|
|
3340
2889
|
|
|
3341
|
-
// src/three/ecs.ts
|
|
2890
|
+
// src/rendering/three/ecs.ts
|
|
3342
2891
|
import { Group as Group5 } from "three";
|
|
3343
2892
|
var entityCounter = 0;
|
|
3344
2893
|
function GenerateEntityId() {
|
|
@@ -3363,6 +2912,334 @@ function IsThreeEntity(obj) {
|
|
|
3363
2912
|
return obj.userData.entityId !== void 0;
|
|
3364
2913
|
}
|
|
3365
2914
|
|
|
2915
|
+
// src/rendering/webgl.ts
|
|
2916
|
+
var ShaderType = ((ShaderType2) => {
|
|
2917
|
+
ShaderType2[ShaderType2["VERTEX"] = WebGL2RenderingContext.VERTEX_SHADER] = "VERTEX";
|
|
2918
|
+
ShaderType2[ShaderType2["FRAGMENT"] = WebGL2RenderingContext.FRAGMENT_SHADER] = "FRAGMENT";
|
|
2919
|
+
return ShaderType2;
|
|
2920
|
+
})(ShaderType || {});
|
|
2921
|
+
function CreateWebGlContext(canvas) {
|
|
2922
|
+
return (canvas ?? document.createElement("canvas")).getContext("webgl2");
|
|
2923
|
+
}
|
|
2924
|
+
function ResizeWebGlContext(gl, displayWidth, displayHeight) {
|
|
2925
|
+
const canvas = gl.canvas;
|
|
2926
|
+
const { width, height } = canvas.parentElement?.getBoundingClientRect() ?? canvas.getBoundingClientRect();
|
|
2927
|
+
displayWidth = 0 | (displayWidth ?? width);
|
|
2928
|
+
displayHeight = 0 | (displayHeight ?? height);
|
|
2929
|
+
if (canvas.width !== displayWidth || canvas.height !== displayHeight) {
|
|
2930
|
+
gl.canvas.width = displayWidth;
|
|
2931
|
+
gl.canvas.height = displayHeight;
|
|
2932
|
+
gl.viewport(0, 0, displayWidth, displayHeight);
|
|
2933
|
+
return true;
|
|
2934
|
+
}
|
|
2935
|
+
return false;
|
|
2936
|
+
}
|
|
2937
|
+
function CompileShader(gl, type, source) {
|
|
2938
|
+
const shader = gl.createShader(type);
|
|
2939
|
+
gl.shaderSource(shader, source);
|
|
2940
|
+
gl.compileShader(shader);
|
|
2941
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
2942
|
+
throw `CompileShader: failed to compile shader: ${gl.getShaderInfoLog(shader)}`;
|
|
2943
|
+
}
|
|
2944
|
+
return shader;
|
|
2945
|
+
}
|
|
2946
|
+
function CreateProgram(gl, vertexShader2, fragmentShader2) {
|
|
2947
|
+
if (typeof vertexShader2 === "string") {
|
|
2948
|
+
vertexShader2 = CompileShader(gl, ShaderType.VERTEX, vertexShader2);
|
|
2949
|
+
}
|
|
2950
|
+
if (typeof fragmentShader2 === "string") {
|
|
2951
|
+
fragmentShader2 = CompileShader(gl, ShaderType.FRAGMENT, fragmentShader2);
|
|
2952
|
+
}
|
|
2953
|
+
const program = gl.createProgram();
|
|
2954
|
+
gl.attachShader(program, vertexShader2);
|
|
2955
|
+
gl.attachShader(program, fragmentShader2);
|
|
2956
|
+
gl.linkProgram(program);
|
|
2957
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
2958
|
+
throw `CreateProgram: failed to link program: ${gl.getProgramInfoLog(program)}`;
|
|
2959
|
+
}
|
|
2960
|
+
return program;
|
|
2961
|
+
}
|
|
2962
|
+
function GetProgramLocations(gl, program) {
|
|
2963
|
+
const attributes = {};
|
|
2964
|
+
const attributeCount = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
|
|
2965
|
+
for (let i = 0; i < attributeCount; i++) {
|
|
2966
|
+
const info = gl.getActiveAttrib(program, i);
|
|
2967
|
+
attributes[info.name] = gl.getAttribLocation(program, info.name);
|
|
2968
|
+
}
|
|
2969
|
+
const uniforms = {};
|
|
2970
|
+
const uniformCount = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
|
|
2971
|
+
for (let i = 0; i < uniformCount; i++) {
|
|
2972
|
+
const info = gl.getActiveUniform(program, i);
|
|
2973
|
+
uniforms[info.name] = gl.getUniformLocation(program, info.name);
|
|
2974
|
+
}
|
|
2975
|
+
return { attributes, uniforms };
|
|
2976
|
+
}
|
|
2977
|
+
function CreateProgramInfo(gl, vertexShaderSource, fragmentShaderSource) {
|
|
2978
|
+
const program = CreateProgram(
|
|
2979
|
+
gl,
|
|
2980
|
+
vertexShaderSource,
|
|
2981
|
+
fragmentShaderSource
|
|
2982
|
+
);
|
|
2983
|
+
const locations = GetProgramLocations(gl, program);
|
|
2984
|
+
return { program, ...locations };
|
|
2985
|
+
}
|
|
2986
|
+
|
|
2987
|
+
// src/rendering/webgl-renderer.ts
|
|
2988
|
+
var WebGlRenderer = class {
|
|
2989
|
+
gl;
|
|
2990
|
+
programInfo;
|
|
2991
|
+
get canvas() {
|
|
2992
|
+
return this.gl.canvas;
|
|
2993
|
+
}
|
|
2994
|
+
get width() {
|
|
2995
|
+
return this.gl.canvas.width;
|
|
2996
|
+
}
|
|
2997
|
+
get height() {
|
|
2998
|
+
return this.gl.canvas.height;
|
|
2999
|
+
}
|
|
3000
|
+
constructor() {
|
|
3001
|
+
this.gl = CreateWebGlContext();
|
|
3002
|
+
this.gl.enable(this.gl.DEPTH_TEST);
|
|
3003
|
+
}
|
|
3004
|
+
appendTo(htmlElement) {
|
|
3005
|
+
if (this.canvas.parentElement) {
|
|
3006
|
+
this.canvas.parentElement.removeChild(this.canvas);
|
|
3007
|
+
}
|
|
3008
|
+
if (htmlElement) {
|
|
3009
|
+
htmlElement.appendChild(this.canvas);
|
|
3010
|
+
this.resize();
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
resize(displayWidth, displayHeight) {
|
|
3014
|
+
const { width, height } = this.canvas.parentElement?.getBoundingClientRect() ?? this.canvas.getBoundingClientRect();
|
|
3015
|
+
displayWidth = 0 | (displayWidth ?? width);
|
|
3016
|
+
displayHeight = 0 | (displayHeight ?? height);
|
|
3017
|
+
if (this.width !== displayWidth || this.height !== displayHeight) {
|
|
3018
|
+
this.gl.canvas.width = displayWidth;
|
|
3019
|
+
this.gl.canvas.height = displayHeight;
|
|
3020
|
+
this.gl.viewport(0, 0, displayWidth, displayHeight);
|
|
3021
|
+
return true;
|
|
3022
|
+
}
|
|
3023
|
+
return false;
|
|
3024
|
+
}
|
|
3025
|
+
render(_deltaTime) {
|
|
3026
|
+
if (this.programInfo) {
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
};
|
|
3030
|
+
|
|
3031
|
+
// src/simplex-noise.ts
|
|
3032
|
+
var SimplexNoise = class {
|
|
3033
|
+
grad3;
|
|
3034
|
+
p;
|
|
3035
|
+
perm;
|
|
3036
|
+
constructor() {
|
|
3037
|
+
this.grad3 = [
|
|
3038
|
+
[1, 1, 0],
|
|
3039
|
+
[-1, 1, 0],
|
|
3040
|
+
[1, -1, 0],
|
|
3041
|
+
[-1, -1, 0],
|
|
3042
|
+
[1, 0, 1],
|
|
3043
|
+
[-1, 0, 1],
|
|
3044
|
+
[1, 0, -1],
|
|
3045
|
+
[-1, 0, -1],
|
|
3046
|
+
[0, 1, 1],
|
|
3047
|
+
[0, -1, 1],
|
|
3048
|
+
[0, 1, -1],
|
|
3049
|
+
[0, -1, -1]
|
|
3050
|
+
];
|
|
3051
|
+
this.p = [];
|
|
3052
|
+
for (let i = 0; i < 256; i++) {
|
|
3053
|
+
this.p.push(Math.floor(rng.nextf * 256));
|
|
3054
|
+
}
|
|
3055
|
+
this.perm = [];
|
|
3056
|
+
for (let i = 0; i < 512; i++) {
|
|
3057
|
+
this.perm.push(this.p[i & 255]);
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
dot(g, x, y, z) {
|
|
3061
|
+
return g[0] * x + g[1] * y + (typeof z === "number" ? g[2] * z : 0);
|
|
3062
|
+
}
|
|
3063
|
+
noise2d(xin, yin) {
|
|
3064
|
+
let n0, n1, n2;
|
|
3065
|
+
const F2 = 0.5 * (Math.sqrt(3) - 1);
|
|
3066
|
+
const s = (xin + yin) * F2;
|
|
3067
|
+
let i = Math.floor(xin + s);
|
|
3068
|
+
let j = Math.floor(yin + s);
|
|
3069
|
+
const G2 = (3 - Math.sqrt(3)) / 6;
|
|
3070
|
+
const t = (i + j) * G2;
|
|
3071
|
+
const X0 = i - t;
|
|
3072
|
+
const Y0 = j - t;
|
|
3073
|
+
const x0 = xin - X0;
|
|
3074
|
+
const y0 = yin - Y0;
|
|
3075
|
+
let i1, j1;
|
|
3076
|
+
if (x0 > y0) {
|
|
3077
|
+
i1 = 1;
|
|
3078
|
+
j1 = 0;
|
|
3079
|
+
} else {
|
|
3080
|
+
i1 = 0;
|
|
3081
|
+
j1 = 1;
|
|
3082
|
+
}
|
|
3083
|
+
const x1 = x0 - i1 + G2;
|
|
3084
|
+
const y1 = y0 - j1 + G2;
|
|
3085
|
+
const x2 = x0 - 1 + 2 * G2;
|
|
3086
|
+
const y2 = y0 - 1 + 2 * G2;
|
|
3087
|
+
const ii = i & 255;
|
|
3088
|
+
const jj = j & 255;
|
|
3089
|
+
const gi0 = this.perm[ii + this.perm[jj]] % 12;
|
|
3090
|
+
const gi1 = this.perm[ii + i1 + this.perm[jj + j1]] % 12;
|
|
3091
|
+
const gi2 = this.perm[ii + 1 + this.perm[jj + 1]] % 12;
|
|
3092
|
+
let t0 = 0.5 - x0 * x0 - y0 * y0;
|
|
3093
|
+
if (t0 < 0) {
|
|
3094
|
+
n0 = 0;
|
|
3095
|
+
} else {
|
|
3096
|
+
t0 *= t0;
|
|
3097
|
+
n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0);
|
|
3098
|
+
}
|
|
3099
|
+
let t1 = 0.5 - x1 * x1 - y1 * y1;
|
|
3100
|
+
if (t1 < 0) {
|
|
3101
|
+
n1 = 0;
|
|
3102
|
+
} else {
|
|
3103
|
+
t1 *= t1;
|
|
3104
|
+
n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1);
|
|
3105
|
+
}
|
|
3106
|
+
let t2 = 0.5 - x2 * x2 - y2 * y2;
|
|
3107
|
+
if (t2 < 0) {
|
|
3108
|
+
n2 = 0;
|
|
3109
|
+
} else {
|
|
3110
|
+
t2 *= t2;
|
|
3111
|
+
n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2);
|
|
3112
|
+
}
|
|
3113
|
+
return 70 * (n0 + n1 + n2);
|
|
3114
|
+
}
|
|
3115
|
+
noise3d(xin, yin, zin) {
|
|
3116
|
+
let n0, n1, n2, n3;
|
|
3117
|
+
const F3 = 1 / 3;
|
|
3118
|
+
const s = (xin + yin + zin) * F3;
|
|
3119
|
+
const i = Math.floor(xin + s);
|
|
3120
|
+
const j = Math.floor(yin + s);
|
|
3121
|
+
const k = Math.floor(zin + s);
|
|
3122
|
+
const G3 = 1 / 6;
|
|
3123
|
+
const t = (i + j + k) * G3;
|
|
3124
|
+
const X0 = i - t;
|
|
3125
|
+
const Y0 = j - t;
|
|
3126
|
+
const Z0 = k - t;
|
|
3127
|
+
const x0 = xin - X0;
|
|
3128
|
+
const y0 = yin - Y0;
|
|
3129
|
+
const z0 = zin - Z0;
|
|
3130
|
+
let i1, j1, k1;
|
|
3131
|
+
let i2, j2, k2;
|
|
3132
|
+
if (x0 >= y0) {
|
|
3133
|
+
if (y0 >= z0) {
|
|
3134
|
+
i1 = 1;
|
|
3135
|
+
j1 = 0;
|
|
3136
|
+
k1 = 0;
|
|
3137
|
+
i2 = 1;
|
|
3138
|
+
j2 = 1;
|
|
3139
|
+
k2 = 0;
|
|
3140
|
+
} else if (x0 >= z0) {
|
|
3141
|
+
i1 = 1;
|
|
3142
|
+
j1 = 0;
|
|
3143
|
+
k1 = 0;
|
|
3144
|
+
i2 = 1;
|
|
3145
|
+
j2 = 0;
|
|
3146
|
+
k2 = 1;
|
|
3147
|
+
} else {
|
|
3148
|
+
i1 = 0;
|
|
3149
|
+
j1 = 0;
|
|
3150
|
+
k1 = 1;
|
|
3151
|
+
i2 = 1;
|
|
3152
|
+
j2 = 0;
|
|
3153
|
+
k2 = 1;
|
|
3154
|
+
}
|
|
3155
|
+
} else {
|
|
3156
|
+
if (y0 < z0) {
|
|
3157
|
+
i1 = 0;
|
|
3158
|
+
j1 = 0;
|
|
3159
|
+
k1 = 1;
|
|
3160
|
+
i2 = 0;
|
|
3161
|
+
j2 = 1;
|
|
3162
|
+
k2 = 1;
|
|
3163
|
+
} else if (x0 < z0) {
|
|
3164
|
+
i1 = 0;
|
|
3165
|
+
j1 = 1;
|
|
3166
|
+
k1 = 0;
|
|
3167
|
+
i2 = 0;
|
|
3168
|
+
j2 = 1;
|
|
3169
|
+
k2 = 1;
|
|
3170
|
+
} else {
|
|
3171
|
+
i1 = 0;
|
|
3172
|
+
j1 = 1;
|
|
3173
|
+
k1 = 0;
|
|
3174
|
+
i2 = 1;
|
|
3175
|
+
j2 = 1;
|
|
3176
|
+
k2 = 0;
|
|
3177
|
+
}
|
|
3178
|
+
}
|
|
3179
|
+
const x1 = x0 - i1 + G3;
|
|
3180
|
+
const y1 = y0 - j1 + G3;
|
|
3181
|
+
const z1 = z0 - k1 + G3;
|
|
3182
|
+
const x2 = x0 - i2 + 2 * G3;
|
|
3183
|
+
const y2 = y0 - j2 + 2 * G3;
|
|
3184
|
+
const z2 = z0 - k2 + 2 * G3;
|
|
3185
|
+
const x3 = x0 - 1 + 3 * G3;
|
|
3186
|
+
const y3 = y0 - 1 + 3 * G3;
|
|
3187
|
+
const z3 = z0 - 1 + 3 * G3;
|
|
3188
|
+
const ii = i & 255;
|
|
3189
|
+
const jj = j & 255;
|
|
3190
|
+
const kk = k & 255;
|
|
3191
|
+
const gi0 = this.perm[ii + this.perm[jj + this.perm[kk]]] % 12;
|
|
3192
|
+
const gi1 = this.perm[ii + i1 + this.perm[jj + j1 + this.perm[kk + k1]]] % 12;
|
|
3193
|
+
const gi2 = this.perm[ii + i2 + this.perm[jj + j2 + this.perm[kk + k2]]] % 12;
|
|
3194
|
+
const gi3 = this.perm[ii + 1 + this.perm[jj + 1 + this.perm[kk + 1]]] % 12;
|
|
3195
|
+
let t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
|
|
3196
|
+
if (t0 < 0) {
|
|
3197
|
+
n0 = 0;
|
|
3198
|
+
} else {
|
|
3199
|
+
t0 *= t0;
|
|
3200
|
+
n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0, z0);
|
|
3201
|
+
}
|
|
3202
|
+
let t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1;
|
|
3203
|
+
if (t1 < 0) {
|
|
3204
|
+
n1 = 0;
|
|
3205
|
+
} else {
|
|
3206
|
+
t1 *= t1;
|
|
3207
|
+
n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1, z1);
|
|
3208
|
+
}
|
|
3209
|
+
let t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2;
|
|
3210
|
+
if (t2 < 0) {
|
|
3211
|
+
n2 = 0;
|
|
3212
|
+
} else {
|
|
3213
|
+
t2 *= t2;
|
|
3214
|
+
n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2, z2);
|
|
3215
|
+
}
|
|
3216
|
+
let t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3;
|
|
3217
|
+
if (t3 < 0) {
|
|
3218
|
+
n3 = 0;
|
|
3219
|
+
} else {
|
|
3220
|
+
t3 *= t3;
|
|
3221
|
+
n3 = t3 * t3 * this.dot(this.grad3[gi3], x3, y3, z3);
|
|
3222
|
+
}
|
|
3223
|
+
return 32 * (n0 + n1 + n2 + n3);
|
|
3224
|
+
}
|
|
3225
|
+
};
|
|
3226
|
+
|
|
3227
|
+
// src/tilemap.ts
|
|
3228
|
+
var Tilemap = class {
|
|
3229
|
+
map = /* @__PURE__ */ new Map();
|
|
3230
|
+
_key(x, y) {
|
|
3231
|
+
x = floor(x);
|
|
3232
|
+
y = floor(y);
|
|
3233
|
+
return `${x}x${y}`;
|
|
3234
|
+
}
|
|
3235
|
+
get(x, y) {
|
|
3236
|
+
return this.map.get(this._key(x, y));
|
|
3237
|
+
}
|
|
3238
|
+
set(x, y, v) {
|
|
3239
|
+
this.map.set(this._key(x, y), v);
|
|
3240
|
+
}
|
|
3241
|
+
};
|
|
3242
|
+
|
|
3366
3243
|
// src/worker-interface.ts
|
|
3367
3244
|
var WorkerInterface = class extends Emitter {
|
|
3368
3245
|
_worker;
|
|
@@ -3387,7 +3264,6 @@ export {
|
|
|
3387
3264
|
BuildDefaultPalette,
|
|
3388
3265
|
CanvasRenderer,
|
|
3389
3266
|
Clock,
|
|
3390
|
-
ClockStats,
|
|
3391
3267
|
Color,
|
|
3392
3268
|
Colors,
|
|
3393
3269
|
CompileShader,
|
|
@@ -3400,16 +3276,17 @@ export {
|
|
|
3400
3276
|
CreateThreeEntity,
|
|
3401
3277
|
CreateWebGlContext,
|
|
3402
3278
|
CubeSphereGeometry,
|
|
3279
|
+
DOUBLE_PI,
|
|
3403
3280
|
ECS,
|
|
3404
3281
|
Emitter,
|
|
3405
|
-
EventBus,
|
|
3406
3282
|
GenerateDoors,
|
|
3407
3283
|
GenerateEntityId,
|
|
3408
3284
|
GenerateRooms,
|
|
3409
3285
|
GenerateWalls,
|
|
3410
3286
|
GetProgramLocations,
|
|
3411
3287
|
GetThreeComponent,
|
|
3412
|
-
|
|
3288
|
+
GetUrlParams,
|
|
3289
|
+
HALF_PI,
|
|
3413
3290
|
Input,
|
|
3414
3291
|
IsThreeEntity,
|
|
3415
3292
|
LoadTexture,
|
|
@@ -3417,14 +3294,15 @@ export {
|
|
|
3417
3294
|
Map3D,
|
|
3418
3295
|
Noise,
|
|
3419
3296
|
PI,
|
|
3297
|
+
ParticleRenderer,
|
|
3420
3298
|
ParticleSystem2d,
|
|
3421
3299
|
ParticleSystem3d,
|
|
3422
3300
|
PoissonDiskSampler,
|
|
3301
|
+
RADIAN_FACTOR,
|
|
3302
|
+
RandomNumberGenerator,
|
|
3423
3303
|
Rectangle,
|
|
3424
3304
|
RemoveThreeComponent,
|
|
3425
|
-
Renderer,
|
|
3426
3305
|
ResizeWebGlContext,
|
|
3427
|
-
Rng,
|
|
3428
3306
|
ShaderType,
|
|
3429
3307
|
SimplexNoise,
|
|
3430
3308
|
SpatialPartition2d,
|
|
@@ -3447,14 +3325,15 @@ export {
|
|
|
3447
3325
|
clamp,
|
|
3448
3326
|
cos,
|
|
3449
3327
|
deg2rad,
|
|
3450
|
-
|
|
3451
|
-
|
|
3328
|
+
distance2d,
|
|
3329
|
+
distance3d,
|
|
3452
3330
|
floor,
|
|
3453
3331
|
getRedYellowGreenGradientHex,
|
|
3454
3332
|
hypot2,
|
|
3455
3333
|
hypot3,
|
|
3456
3334
|
imul,
|
|
3457
3335
|
isNullOrUndefined,
|
|
3336
|
+
isPositiveString,
|
|
3458
3337
|
lerp,
|
|
3459
3338
|
log,
|
|
3460
3339
|
logdev,
|