minerender 2.1.0-alpha.117 → 2.1.0-alpha.119
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/dist/browser/index.d.mts +24 -3
- package/dist/browser/index.d.ts +24 -3
- package/dist/browser/index.js +208 -74
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +208 -74
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +661 -524
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +19 -3
- package/dist/node/index.d.ts +19 -3
- package/dist/node/index.js +122 -6
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +119 -6
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.mjs
CHANGED
|
@@ -13276,6 +13276,8 @@ import { Controls, Euler as Euler11, MathUtils as MathUtils2, Quaternion as Quat
|
|
|
13276
13276
|
var VANILLA_FLY_SPEED = 10.89;
|
|
13277
13277
|
var PITCH_LIMIT = Math.PI / 2;
|
|
13278
13278
|
var MOVE_EPSILON = 1e-6;
|
|
13279
|
+
var MAX_STEP_SECONDS = 0.1;
|
|
13280
|
+
var CLICK_SLOP_PIXELS = 4;
|
|
13279
13281
|
var _euler = new Euler11(0, 0, 0, "YXZ");
|
|
13280
13282
|
var _forward = new Vector313();
|
|
13281
13283
|
var _right = new Vector313();
|
|
@@ -13310,7 +13312,8 @@ var FlyControls = class extends Controls {
|
|
|
13310
13312
|
right: ["KeyD", "ArrowRight"],
|
|
13311
13313
|
up: ["Space"],
|
|
13312
13314
|
down: ["ShiftLeft", "ShiftRight"],
|
|
13313
|
-
|
|
13315
|
+
// Not Control: Ctrl+W closes the browser tab on Windows and Linux, and a page cannot block it.
|
|
13316
|
+
sprint: ["KeyR"]
|
|
13314
13317
|
};
|
|
13315
13318
|
this._pressed = /* @__PURE__ */ new Set();
|
|
13316
13319
|
this._velocity = new Vector313();
|
|
@@ -13318,8 +13321,12 @@ var FlyControls = class extends Controls {
|
|
|
13318
13321
|
this._lastQuaternion = new Quaternion6();
|
|
13319
13322
|
this._position0 = new Vector313();
|
|
13320
13323
|
this._quaternion0 = new Quaternion6();
|
|
13324
|
+
this._dragX = 0;
|
|
13325
|
+
this._dragY = 0;
|
|
13321
13326
|
this._dragMoved = false;
|
|
13327
|
+
this._dragTravel = 0;
|
|
13322
13328
|
this._locked = false;
|
|
13329
|
+
this._madeFocusable = false;
|
|
13323
13330
|
this._onKeyDown = (event) => this.handleKey(event, true);
|
|
13324
13331
|
this._onKeyUp = (event) => this.handleKey(event, false);
|
|
13325
13332
|
this._onPointerDown = (event) => this.handlePointerDown(event);
|
|
@@ -13349,7 +13356,10 @@ var FlyControls = class extends Controls {
|
|
|
13349
13356
|
element.addEventListener("wheel", this._onWheel, { passive: false });
|
|
13350
13357
|
element.addEventListener("blur", this._onBlur);
|
|
13351
13358
|
element.style.touchAction = "none";
|
|
13352
|
-
if (element.tabIndex < 0)
|
|
13359
|
+
if (element.tabIndex < 0) {
|
|
13360
|
+
element.tabIndex = 0;
|
|
13361
|
+
this._madeFocusable = true;
|
|
13362
|
+
}
|
|
13353
13363
|
}
|
|
13354
13364
|
disconnect() {
|
|
13355
13365
|
const element = this.domElement;
|
|
@@ -13367,6 +13377,10 @@ var FlyControls = class extends Controls {
|
|
|
13367
13377
|
element.removeEventListener("wheel", this._onWheel);
|
|
13368
13378
|
element.removeEventListener("blur", this._onBlur);
|
|
13369
13379
|
element.style.touchAction = "auto";
|
|
13380
|
+
if (this._madeFocusable) {
|
|
13381
|
+
element.removeAttribute("tabindex");
|
|
13382
|
+
this._madeFocusable = false;
|
|
13383
|
+
}
|
|
13370
13384
|
this.unlock();
|
|
13371
13385
|
this._locked = false;
|
|
13372
13386
|
this.releaseKeys();
|
|
@@ -13437,6 +13451,7 @@ var FlyControls = class extends Controls {
|
|
|
13437
13451
|
/**
|
|
13438
13452
|
* Advances movement by `delta` seconds (measured since the previous call when omitted)
|
|
13439
13453
|
* and dispatches `change` when the camera moved.
|
|
13454
|
+
* A step longer than 0.1 s is applied as 0.1 s.
|
|
13440
13455
|
*/
|
|
13441
13456
|
update(delta) {
|
|
13442
13457
|
if (delta === void 0) {
|
|
@@ -13448,7 +13463,7 @@ var FlyControls = class extends Controls {
|
|
|
13448
13463
|
this._velocity.set(0, 0, 0);
|
|
13449
13464
|
return;
|
|
13450
13465
|
}
|
|
13451
|
-
if (delta > 0) this.move(delta);
|
|
13466
|
+
if (delta > 0) this.move(Math.min(delta, MAX_STEP_SECONDS));
|
|
13452
13467
|
this.notifyChange();
|
|
13453
13468
|
}
|
|
13454
13469
|
move(delta) {
|
|
@@ -13495,15 +13510,21 @@ var FlyControls = class extends Controls {
|
|
|
13495
13510
|
this._pressed.clear();
|
|
13496
13511
|
}
|
|
13497
13512
|
handleKey(event, down) {
|
|
13513
|
+
if (event.code === "MetaLeft" || event.code === "MetaRight") this.releaseKeys();
|
|
13498
13514
|
const action = this.actionFor(event.code);
|
|
13499
13515
|
if (!action) return;
|
|
13500
13516
|
const ownsInput = this.enabled && (this._locked || event.target === this.domElement);
|
|
13501
|
-
if (down && !ownsInput) return;
|
|
13517
|
+
if (down && (!ownsInput || this.isBrowserShortcut(event))) return;
|
|
13502
13518
|
const pressed = this._pressed.has(action);
|
|
13503
13519
|
if (down) this._pressed.add(action);
|
|
13504
13520
|
else this._pressed.delete(action);
|
|
13505
13521
|
if (ownsInput || this.enabled && pressed) event.preventDefault();
|
|
13506
13522
|
}
|
|
13523
|
+
/** A key pressed with Control, Alt, or Command stays a browser shortcut unless that modifier is bound to an action. */
|
|
13524
|
+
isBrowserShortcut(event) {
|
|
13525
|
+
const bound = (modifier) => Object.values(this.keys).some((codes) => codes.some((code) => code.startsWith(modifier)));
|
|
13526
|
+
return event.ctrlKey && !bound("Control") || event.altKey && !bound("Alt") || event.metaKey && !bound("Meta");
|
|
13527
|
+
}
|
|
13507
13528
|
actionFor(code) {
|
|
13508
13529
|
for (const action in this.keys) {
|
|
13509
13530
|
if (this.keys[action].includes(code)) return action;
|
|
@@ -13523,7 +13544,10 @@ var FlyControls = class extends Controls {
|
|
|
13523
13544
|
if (this._dragPointer !== void 0) return;
|
|
13524
13545
|
if (event.pointerType === "mouse" && event.button !== 0 && event.button !== 2) return;
|
|
13525
13546
|
this._dragPointer = event.pointerId;
|
|
13547
|
+
this._dragX = event.clientX;
|
|
13548
|
+
this._dragY = event.clientY;
|
|
13526
13549
|
this._dragMoved = false;
|
|
13550
|
+
this._dragTravel = 0;
|
|
13527
13551
|
element.setPointerCapture?.(event.pointerId);
|
|
13528
13552
|
}
|
|
13529
13553
|
onJoystickSide(event) {
|
|
@@ -13539,8 +13563,20 @@ var FlyControls = class extends Controls {
|
|
|
13539
13563
|
return;
|
|
13540
13564
|
}
|
|
13541
13565
|
if (!this._locked && event.pointerId !== this._dragPointer) return;
|
|
13542
|
-
|
|
13543
|
-
|
|
13566
|
+
let dx, dy;
|
|
13567
|
+
if (this._locked) {
|
|
13568
|
+
dx = event.movementX ?? 0;
|
|
13569
|
+
dy = event.movementY ?? 0;
|
|
13570
|
+
} else {
|
|
13571
|
+
dx = event.clientX - this._dragX;
|
|
13572
|
+
dy = event.clientY - this._dragY;
|
|
13573
|
+
this._dragX = event.clientX;
|
|
13574
|
+
this._dragY = event.clientY;
|
|
13575
|
+
if (!this._dragMoved) {
|
|
13576
|
+
this._dragTravel += Math.hypot(dx, dy);
|
|
13577
|
+
if (this._dragTravel <= CLICK_SLOP_PIXELS) return;
|
|
13578
|
+
}
|
|
13579
|
+
}
|
|
13544
13580
|
if (!dx && !dy) return;
|
|
13545
13581
|
this._dragMoved = true;
|
|
13546
13582
|
this.turn(dx, dy);
|
|
@@ -15500,6 +15536,7 @@ var Renderer = class _Renderer {
|
|
|
15500
15536
|
/**
|
|
15501
15537
|
* Replaces renderer-owned controls with the selected mode, keeping the camera where it is.
|
|
15502
15538
|
* Switching to orbit controls targets the point the camera looks at, at the previous orbit distance.
|
|
15539
|
+
* The previous controls object is disposed, so its listeners and settings do not carry over.
|
|
15503
15540
|
* Returns the new controls, or undefined when controls were disabled at construction or after disposal.
|
|
15504
15541
|
*/
|
|
15505
15542
|
setControlsMode(mode) {
|
|
@@ -16125,6 +16162,79 @@ function parseSceneDocument(value) {
|
|
|
16125
16162
|
return JSON.parse(JSON.stringify(input));
|
|
16126
16163
|
}
|
|
16127
16164
|
|
|
16165
|
+
// src/scene/SceneDocumentCodec.ts
|
|
16166
|
+
var SCENE_DOCUMENT_MAX_BYTES = 1024 * 1024;
|
|
16167
|
+
async function readBounded(stream, label) {
|
|
16168
|
+
const reader = stream.getReader();
|
|
16169
|
+
const chunks = [];
|
|
16170
|
+
let size = 0;
|
|
16171
|
+
try {
|
|
16172
|
+
while (true) {
|
|
16173
|
+
const { value, done } = await reader.read();
|
|
16174
|
+
if (done) break;
|
|
16175
|
+
size += value.byteLength;
|
|
16176
|
+
if (size > SCENE_DOCUMENT_MAX_BYTES) throw new RangeError(`${label} exceeds ${SCENE_DOCUMENT_MAX_BYTES} bytes`);
|
|
16177
|
+
chunks.push(value);
|
|
16178
|
+
}
|
|
16179
|
+
} catch (error) {
|
|
16180
|
+
await reader.cancel().catch(() => {
|
|
16181
|
+
});
|
|
16182
|
+
throw error;
|
|
16183
|
+
} finally {
|
|
16184
|
+
reader.releaseLock();
|
|
16185
|
+
}
|
|
16186
|
+
const bytes = new Uint8Array(size);
|
|
16187
|
+
let offset = 0;
|
|
16188
|
+
for (const chunk of chunks) {
|
|
16189
|
+
bytes.set(chunk, offset);
|
|
16190
|
+
offset += chunk.byteLength;
|
|
16191
|
+
}
|
|
16192
|
+
return bytes;
|
|
16193
|
+
}
|
|
16194
|
+
function encodeBase64(bytes) {
|
|
16195
|
+
let binary = "";
|
|
16196
|
+
for (let offset = 0; offset < bytes.length; offset += 32768) {
|
|
16197
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + 32768));
|
|
16198
|
+
}
|
|
16199
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
16200
|
+
}
|
|
16201
|
+
async function encodeSceneDocument(value) {
|
|
16202
|
+
const scene = parseSceneDocument(value);
|
|
16203
|
+
const bytes = new TextEncoder().encode(JSON.stringify(scene));
|
|
16204
|
+
if (bytes.byteLength > SCENE_DOCUMENT_MAX_BYTES) {
|
|
16205
|
+
throw new RangeError(`Scene document exceeds ${SCENE_DOCUMENT_MAX_BYTES} bytes`);
|
|
16206
|
+
}
|
|
16207
|
+
const compressed = await readBounded(new Blob([bytes]).stream().pipeThrough(new CompressionStream("deflate")), "Encoded scene");
|
|
16208
|
+
return `v1.${encodeBase64(compressed)}`;
|
|
16209
|
+
}
|
|
16210
|
+
async function decodeSceneDocument(value) {
|
|
16211
|
+
if (!value.startsWith("v1.")) throw new Error("Unsupported scene encoding version; expected v1");
|
|
16212
|
+
const encoded = value.slice(3);
|
|
16213
|
+
if (encoded.length > Math.ceil(SCENE_DOCUMENT_MAX_BYTES * 4 / 3)) {
|
|
16214
|
+
throw new RangeError(`Encoded scene exceeds ${SCENE_DOCUMENT_MAX_BYTES} bytes`);
|
|
16215
|
+
}
|
|
16216
|
+
if (!/^[A-Za-z0-9_-]+$/.test(encoded) || encoded.length % 4 === 1) {
|
|
16217
|
+
throw new Error("Invalid scene base64url encoding");
|
|
16218
|
+
}
|
|
16219
|
+
const binary = atob(encoded.replace(/-/g, "+").replace(/_/g, "/"));
|
|
16220
|
+
const compressed = Uint8Array.from(binary, (character) => character.charCodeAt(0));
|
|
16221
|
+
if (encodeBase64(compressed) !== encoded) throw new Error("Invalid scene base64url encoding");
|
|
16222
|
+
let bytes;
|
|
16223
|
+
try {
|
|
16224
|
+
bytes = await readBounded(new Blob([compressed]).stream().pipeThrough(new DecompressionStream("deflate")), "Scene document");
|
|
16225
|
+
} catch (error) {
|
|
16226
|
+
if (error instanceof RangeError) throw error;
|
|
16227
|
+
throw new Error("Invalid compressed scene document");
|
|
16228
|
+
}
|
|
16229
|
+
let json;
|
|
16230
|
+
try {
|
|
16231
|
+
json = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
16232
|
+
} catch {
|
|
16233
|
+
throw new Error("Invalid UTF-8 scene document");
|
|
16234
|
+
}
|
|
16235
|
+
return parseSceneDocument(json);
|
|
16236
|
+
}
|
|
16237
|
+
|
|
16128
16238
|
// src/scene/SceneDocumentLoader.ts
|
|
16129
16239
|
init_AssetKey();
|
|
16130
16240
|
init_AssetLoader();
|
|
@@ -19212,6 +19322,7 @@ export {
|
|
|
19212
19322
|
Renderer,
|
|
19213
19323
|
RequestError,
|
|
19214
19324
|
Requests,
|
|
19325
|
+
SCENE_DOCUMENT_MAX_BYTES,
|
|
19215
19326
|
SKIN_PARTS,
|
|
19216
19327
|
SceneDocumentLoader,
|
|
19217
19328
|
SceneExporter,
|
|
@@ -19263,6 +19374,8 @@ export {
|
|
|
19263
19374
|
createGuiTextGeometry,
|
|
19264
19375
|
createGuiTextureGeometry,
|
|
19265
19376
|
createImage,
|
|
19377
|
+
decodeSceneDocument,
|
|
19378
|
+
encodeSceneDocument,
|
|
19266
19379
|
entityAnimationTime,
|
|
19267
19380
|
estimateBytesUsed,
|
|
19268
19381
|
fluidKindOf,
|