@threenative/core 0.3.4 → 0.3.6
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/capabilities.json +1505 -79
- package/dist/{audio-7i3Xl0l3.d.ts → audio-DIJE5HTr.d.ts} +43 -3
- package/dist/{canvas-layer-DDmC_VVF.d.ts → canvas-layer-C1-5CviZ.d.ts} +5 -1
- package/dist/{game-CljaDv4D.d.ts → game-Jz4Fdoeb.d.ts} +114 -11
- package/dist/hot.d.ts +4 -4
- package/dist/index.d.ts +712 -118
- package/dist/index.js +12437 -4955
- package/dist/{gpu-readback-CqJEfWNQ.d.ts → model-lod-BDAUYgsS.d.ts} +80 -5
- package/dist/playtest.d.ts +6 -10
- package/dist/playtest.js +57 -24
- package/dist/react-css.d.ts +62 -0
- package/dist/react-css.js +591 -0
- package/dist/react.d.ts +2 -2
- package/dist/{renderer-CfsS2hxi.d.ts → renderer-9yEo9hPa.d.ts} +489 -22
- package/dist/terrain-jobs-worker.d.ts +2 -0
- package/dist/terrain-jobs-worker.js +130 -0
- package/dist/ui-layer.js +59 -8
- package/dist/world.d.ts +766 -73
- package/dist/world.js +9307 -3543
- package/gpl/recipes/export_world.py +18 -1
- package/mcp/blender-server.mjs +7 -4
- package/mcp/blender.mjs +3 -4
- package/mcp/engine-server.mjs +2 -2
- package/mcp/servers.mjs +4 -4
- package/package.json +15 -9
- package/patches/three@0.185.1-prd269-upgrade.patch +22418 -0
- package/patches/three@0.185.1.patch +6594 -700
- package/scripts/apply-three-patch.mjs +62 -4
- package/src/animation-blend.ts +264 -0
- package/src/animation-composition.ts +362 -0
- package/src/animation-layers.ts +260 -0
- package/src/animation-root-motion.ts +283 -0
- package/src/animation.ts +896 -0
- package/src/assets.ts +1303 -0
- package/src/atmosphere/index.ts +335 -0
- package/src/atmosphere/luts.ts +298 -0
- package/src/atmosphere/params.ts +323 -0
- package/src/audio.ts +912 -0
- package/src/billboard.ts +124 -0
- package/src/bone-lengths.ts +157 -0
- package/src/camera-shake.ts +116 -0
- package/src/canvas-layer.ts +47 -0
- package/src/clip-audit.ts +401 -0
- package/src/clustered-batch.ts +492 -0
- package/src/clustered-mesh.ts +638 -0
- package/src/compute-driven.ts +176 -0
- package/src/compute-timing.ts +318 -0
- package/src/config.ts +593 -0
- package/src/debug.ts +82 -0
- package/src/engine-render-hook.ts +25 -0
- package/src/entities.ts +79 -0
- package/src/entity-snapshot.ts +53 -0
- package/src/flight.ts +683 -0
- package/src/fluid-field.ts +748 -0
- package/src/fluid-particles.ts +1253 -0
- package/src/frame-budget.ts +1368 -0
- package/src/game.ts +2408 -0
- package/src/geometry-capture.ts +1098 -0
- package/src/gpu-class.ts +160 -0
- package/src/gpu-frame-observation.ts +424 -0
- package/src/gpu-readback.ts +143 -0
- package/src/gpu-scene-bvh.ts +464 -0
- package/src/grounding.ts +100 -0
- package/src/hot.ts +161 -0
- package/src/import-meta.d.ts +13 -0
- package/src/index.ts +1536 -0
- package/src/input.ts +690 -0
- package/src/instanced-batch-lod.ts +283 -0
- package/src/instanced-batch.ts +274 -0
- package/src/interpolation.ts +129 -0
- package/src/launch-diagnostics.ts +161 -0
- package/src/loop.ts +574 -0
- package/src/matrix-world.ts +245 -0
- package/src/merge-parts.ts +812 -0
- package/src/model-lod.ts +1315 -0
- package/src/net-protocol.ts +333 -0
- package/src/net-session.ts +477 -0
- package/src/net.ts +80 -0
- package/src/ocean/fft.ts +72 -0
- package/src/ocean/spectral.ts +728 -0
- package/src/particle-significance.ts +102 -0
- package/src/particles.ts +648 -0
- package/src/path-follow.ts +175 -0
- package/src/picking.ts +250 -0
- package/src/pipeline-census.ts +1566 -0
- package/src/platform.ts +210 -0
- package/src/playtest.ts +850 -0
- package/src/pointer-events.ts +411 -0
- package/src/pose-measure.ts +435 -0
- package/src/profiling/FrameCounters.ts +231 -0
- package/src/profiling/Spans.ts +548 -0
- package/src/profiling/opacity-convention.ts +21 -0
- package/src/profiling/render-list-validate.ts +175 -0
- package/src/profiling/render-trap-audit.ts +84 -0
- package/src/profiling/scene-warning.ts +190 -0
- package/src/profiling/span-probes.ts +191 -0
- package/src/profiling/unlit-foliage-warning.ts +149 -0
- package/src/projection-apply.ts +1529 -0
- package/src/projection-marker.ts +142 -0
- package/src/projection-plan.ts +1258 -0
- package/src/projection-skinned.ts +419 -0
- package/src/projection-stability.ts +409 -0
- package/src/projection-uniform.ts +328 -0
- package/src/random.ts +41 -0
- package/src/react-css.ts +604 -0
- package/src/react-glyphs.ts +114 -0
- package/src/react-host.ts +576 -0
- package/src/react-layout.ts +265 -0
- package/src/react.ts +60 -0
- package/src/render/alpha-antialiasing.ts +159 -0
- package/src/render/batched-velocity.ts +126 -0
- package/src/render/chain.ts +1021 -0
- package/src/render/daylight.ts +189 -0
- package/src/render/depth-pyramid.ts +596 -0
- package/src/render/foliage-alpha.ts +166 -0
- package/src/render/material-key.ts +60 -0
- package/src/render/mesh-pool.ts +144 -0
- package/src/render/probe-volume.ts +1668 -0
- package/src/render/resolution-subrect.ts +253 -0
- package/src/render/velocity.ts +442 -0
- package/src/render/virtual-shadow-pages.ts +827 -0
- package/src/render/virtual-shadow-partial.ts +174 -0
- package/src/render/virtual-shadow.ts +3330 -0
- package/src/render/world-impostor-surface.ts +722 -0
- package/src/render/world-impostor.ts +558 -0
- package/src/render-camera-cull.ts +441 -0
- package/src/render-pass-budget.ts +501 -0
- package/src/renderProjection.ts +758 -0
- package/src/renderer-config.ts +127 -0
- package/src/renderer.ts +1847 -0
- package/src/replay-protocol.ts +85 -0
- package/src/replay.ts +205 -0
- package/src/resolution-scaler.ts +819 -0
- package/src/rig-preparation.ts +271 -0
- package/src/ripple-field.ts +432 -0
- package/src/scale.ts +109 -0
- package/src/scene.ts +239 -0
- package/src/schedule.ts +155 -0
- package/src/skeletal-mesh.ts +61 -0
- package/src/skeleton.ts +100 -0
- package/src/snow-field.ts +744 -0
- package/src/softbody-topology.ts +269 -0
- package/src/softbody.ts +516 -0
- package/src/sprite-animator.ts +222 -0
- package/src/startup-readiness.ts +386 -0
- package/src/state.ts +66 -0
- package/src/static-transform.ts +274 -0
- package/src/storage-buffer.ts +253 -0
- package/src/streaming.ts +308 -0
- package/src/target-fps.ts +92 -0
- package/src/terrain-jobs-worker.ts +17 -0
- package/src/terrain-jobs.ts +353 -0
- package/src/textures.ts +39 -0
- package/src/tracers.ts +237 -0
- package/src/ui-bridge.ts +368 -0
- package/src/ui-hit-regions.ts +380 -0
- package/src/ui-layer.ts +83 -0
- package/src/ui-state.ts +220 -0
- package/src/version.ts +2 -0
- package/src/viewport.ts +253 -0
- package/src/warmup.ts +1357 -0
- package/src/water-surface.ts +384 -0
- package/src/wave-field.ts +524 -0
- package/src/world-capabilities.ts +131 -0
- package/src/world-cell-proxy.ts +392 -0
- package/src/world-cells.ts +10564 -0
- package/src/world-gpu-scene.ts +3354 -0
- package/src/world-heightmap.ts +82 -0
- package/src/world-package.ts +469 -0
- package/src/world-passes.ts +582 -0
- package/src/world-region.ts +17 -0
- package/src/world-terrain-splat.ts +564 -0
- package/src/world-tiles.ts +3826 -0
- package/src/world-topology.ts +370 -0
- package/src/world-validate.ts +48 -0
- package/src/world.ts +805 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// src/terrain-jobs.ts
|
|
2
|
+
function mergeBlockAttributes(job) {
|
|
3
|
+
let vertexCount = 0;
|
|
4
|
+
let indexCount = 0;
|
|
5
|
+
for (const part of job.parts) {
|
|
6
|
+
vertexCount += part.positions.length / 3;
|
|
7
|
+
indexCount += part.indices.length;
|
|
8
|
+
}
|
|
9
|
+
const positions = new Float32Array(vertexCount * 3);
|
|
10
|
+
const normals = new Float32Array(vertexCount * 3);
|
|
11
|
+
const indices = new Uint32Array(indexCount);
|
|
12
|
+
let vertexOffset = 0;
|
|
13
|
+
let indexOffset = 0;
|
|
14
|
+
for (const part of job.parts) {
|
|
15
|
+
const dx = part.origin.x - job.blockOrigin.x;
|
|
16
|
+
const dz = part.origin.z - job.blockOrigin.z;
|
|
17
|
+
const count = part.positions.length / 3;
|
|
18
|
+
for (let vertex = 0; vertex < count; vertex += 1) {
|
|
19
|
+
const at = (vertexOffset + vertex) * 3;
|
|
20
|
+
const from = vertex * 3;
|
|
21
|
+
positions[at] = part.positions[from] + dx;
|
|
22
|
+
positions[at + 1] = part.positions[from + 1];
|
|
23
|
+
positions[at + 2] = part.positions[from + 2] + dz;
|
|
24
|
+
normals[at] = part.normals[from];
|
|
25
|
+
normals[at + 1] = part.normals[from + 1];
|
|
26
|
+
normals[at + 2] = part.normals[from + 2];
|
|
27
|
+
}
|
|
28
|
+
for (let element = 0; element < part.indices.length; element += 1)
|
|
29
|
+
indices[indexOffset + element] = part.indices[element] + vertexOffset;
|
|
30
|
+
vertexOffset += count;
|
|
31
|
+
indexOffset += part.indices.length;
|
|
32
|
+
}
|
|
33
|
+
return { indices, kind: "merge", normals, positions };
|
|
34
|
+
}
|
|
35
|
+
function interpolatedEdgeSample(samples, normalized, name) {
|
|
36
|
+
const position = Math.max(0, Math.min(1, normalized)) * (samples.length - 1);
|
|
37
|
+
const lower = Math.floor(position);
|
|
38
|
+
const upper = Math.min(samples.length - 1, lower + 1);
|
|
39
|
+
const mix = position - lower;
|
|
40
|
+
const lowerValue = samples[lower];
|
|
41
|
+
const upperValue = samples[upper];
|
|
42
|
+
if (!Number.isFinite(lowerValue) || !Number.isFinite(upperValue))
|
|
43
|
+
throw new Error(`TerrainTiles retained ${name} edge sample must be finite.`);
|
|
44
|
+
return lowerValue * (1 - mix) + upperValue * mix;
|
|
45
|
+
}
|
|
46
|
+
function edgeWorldPoint(edge, normalized, height) {
|
|
47
|
+
const minimumX = edge.origin.x - edge.width / 2;
|
|
48
|
+
const minimumZ = edge.origin.z - edge.depth / 2;
|
|
49
|
+
const x = edge.side === "west" ? minimumX : edge.side === "east" ? minimumX + edge.width : minimumX + normalized * edge.width;
|
|
50
|
+
const z = edge.side === "north" ? minimumZ : edge.side === "south" ? minimumZ + edge.depth : minimumZ + normalized * edge.depth;
|
|
51
|
+
return [x, height, z];
|
|
52
|
+
}
|
|
53
|
+
function stitchBridgeAttributes(fine, coarse) {
|
|
54
|
+
const positions = new Float32Array(fine.resolution * 6);
|
|
55
|
+
const normals = new Float32Array(fine.resolution * 6);
|
|
56
|
+
const indices = new Uint32Array((fine.resolution - 1) * 12);
|
|
57
|
+
let coverageDepth = 0;
|
|
58
|
+
for (let index = 0; index < fine.resolution; index += 1) {
|
|
59
|
+
const normalized = index / (fine.resolution - 1);
|
|
60
|
+
const fineHeight = interpolatedEdgeSample(
|
|
61
|
+
fine.samples,
|
|
62
|
+
normalized,
|
|
63
|
+
`${fine.side} of finer LOD`
|
|
64
|
+
);
|
|
65
|
+
const coarseHeight = interpolatedEdgeSample(
|
|
66
|
+
coarse.samples,
|
|
67
|
+
normalized,
|
|
68
|
+
`${coarse.side} of coarser LOD`
|
|
69
|
+
);
|
|
70
|
+
coverageDepth = Math.max(coverageDepth, Math.abs(fineHeight - coarseHeight));
|
|
71
|
+
const at = index * 6;
|
|
72
|
+
const finePoint = edgeWorldPoint(fine, normalized, fineHeight);
|
|
73
|
+
const coarsePoint = edgeWorldPoint(coarse, normalized, coarseHeight);
|
|
74
|
+
positions[at] = finePoint[0];
|
|
75
|
+
positions[at + 1] = finePoint[1];
|
|
76
|
+
positions[at + 2] = finePoint[2];
|
|
77
|
+
positions[at + 3] = coarsePoint[0];
|
|
78
|
+
positions[at + 4] = coarsePoint[1];
|
|
79
|
+
positions[at + 5] = coarsePoint[2];
|
|
80
|
+
normals[at] = 0;
|
|
81
|
+
normals[at + 1] = 1;
|
|
82
|
+
normals[at + 2] = 0;
|
|
83
|
+
normals[at + 3] = 0;
|
|
84
|
+
normals[at + 4] = 1;
|
|
85
|
+
normals[at + 5] = 0;
|
|
86
|
+
}
|
|
87
|
+
for (let index = 0; index < fine.resolution - 1; index += 1) {
|
|
88
|
+
const fine2 = index * 2;
|
|
89
|
+
const coarse2 = fine2 + 1;
|
|
90
|
+
const nextFine = fine2 + 2;
|
|
91
|
+
const nextCoarse = coarse2 + 2;
|
|
92
|
+
const at = index * 12;
|
|
93
|
+
indices[at] = fine2;
|
|
94
|
+
indices[at + 1] = coarse2;
|
|
95
|
+
indices[at + 2] = nextFine;
|
|
96
|
+
indices[at + 3] = nextFine;
|
|
97
|
+
indices[at + 4] = coarse2;
|
|
98
|
+
indices[at + 5] = nextCoarse;
|
|
99
|
+
indices[at + 6] = nextFine;
|
|
100
|
+
indices[at + 7] = coarse2;
|
|
101
|
+
indices[at + 8] = fine2;
|
|
102
|
+
indices[at + 9] = nextCoarse;
|
|
103
|
+
indices[at + 10] = coarse2;
|
|
104
|
+
indices[at + 11] = nextFine;
|
|
105
|
+
}
|
|
106
|
+
return { coverageDepth, indices, normals, positions };
|
|
107
|
+
}
|
|
108
|
+
function runTerrainJob(job) {
|
|
109
|
+
if (job.kind === "merge") return mergeBlockAttributes(job);
|
|
110
|
+
return {
|
|
111
|
+
bridges: job.pairs.map(({ coarse, fine }) => stitchBridgeAttributes(fine, coarse)),
|
|
112
|
+
kind: "seam"
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function terrainJobTransfers(result) {
|
|
116
|
+
if (result.kind === "merge")
|
|
117
|
+
return [result.positions.buffer, result.normals.buffer, result.indices.buffer];
|
|
118
|
+
return result.bridges.flatMap((bridge) => [
|
|
119
|
+
bridge.positions.buffer,
|
|
120
|
+
bridge.normals.buffer,
|
|
121
|
+
bridge.indices.buffer
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/terrain-jobs-worker.ts
|
|
126
|
+
self.onmessage = (event) => {
|
|
127
|
+
const request = event.data;
|
|
128
|
+
const result = runTerrainJob(request.job);
|
|
129
|
+
self.postMessage({ id: request.id, result }, terrainJobTransfers(result));
|
|
130
|
+
};
|
package/dist/ui-layer.js
CHANGED
|
@@ -14,6 +14,19 @@ var UI_BRIDGE_GLOBALS = {
|
|
|
14
14
|
/** Game end, outbound: the runtime installs this and forwards to the web view. */
|
|
15
15
|
gamePost: "__tnUiPost"
|
|
16
16
|
};
|
|
17
|
+
var stateFrames = /* @__PURE__ */ new WeakMap();
|
|
18
|
+
function serializeUiState(state) {
|
|
19
|
+
return assertSendable({ type: GAME_STATE_MESSAGE, state });
|
|
20
|
+
}
|
|
21
|
+
function postUiState(bridge, state, frame) {
|
|
22
|
+
const message = { type: GAME_STATE_MESSAGE, state };
|
|
23
|
+
stateFrames.set(message, frame);
|
|
24
|
+
try {
|
|
25
|
+
bridge.post(message);
|
|
26
|
+
} finally {
|
|
27
|
+
stateFrames.delete(message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
17
30
|
function assertSendable(message) {
|
|
18
31
|
if (typeof message !== "object" || message === null || Array.isArray(message)) {
|
|
19
32
|
throw new Error("TN_UI_BRIDGE_MESSAGE_INVALID: a bridge message must be a JSON object.");
|
|
@@ -23,7 +36,7 @@ function assertSendable(message) {
|
|
|
23
36
|
}
|
|
24
37
|
let frame;
|
|
25
38
|
try {
|
|
26
|
-
frame = JSON.stringify(message);
|
|
39
|
+
frame = stateFrames.get(message) ?? JSON.stringify(message);
|
|
27
40
|
} catch (error) {
|
|
28
41
|
throw new Error(
|
|
29
42
|
`TN_UI_BRIDGE_MESSAGE_INVALID: '${message.type}' is not JSON-serialisable: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -79,10 +92,43 @@ var BROKER_KEY = "__tnUiBridgeBroker";
|
|
|
79
92
|
function broker(scope) {
|
|
80
93
|
const existing = scope[BROKER_KEY];
|
|
81
94
|
if (existing !== void 0) return existing;
|
|
82
|
-
const created = { game: /* @__PURE__ */ new Set(), ui: /* @__PURE__ */ new Set() };
|
|
95
|
+
const created = { game: /* @__PURE__ */ new Set(), ui: /* @__PURE__ */ new Set(), inbound: /* @__PURE__ */ new Map() };
|
|
83
96
|
scope[BROKER_KEY] = created;
|
|
84
97
|
return created;
|
|
85
98
|
}
|
|
99
|
+
function installInbound(scope, key, deliver) {
|
|
100
|
+
const bus = broker(scope);
|
|
101
|
+
let slot = bus.inbound.get(key);
|
|
102
|
+
if (slot === void 0) {
|
|
103
|
+
const receivers = /* @__PURE__ */ new Set();
|
|
104
|
+
slot = {
|
|
105
|
+
receivers,
|
|
106
|
+
dispatch: (frame) => {
|
|
107
|
+
let firstError;
|
|
108
|
+
let failed = false;
|
|
109
|
+
for (const receiver of [...receivers]) {
|
|
110
|
+
try {
|
|
111
|
+
receiver(frame);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (!failed) {
|
|
114
|
+
failed = true;
|
|
115
|
+
firstError = error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (failed) throw firstError;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
bus.inbound.set(key, slot);
|
|
123
|
+
}
|
|
124
|
+
slot.receivers.add(deliver);
|
|
125
|
+
scope[key] = slot.dispatch;
|
|
126
|
+
const installed = slot;
|
|
127
|
+
return () => {
|
|
128
|
+
installed.receivers.delete(deliver);
|
|
129
|
+
if (installed.receivers.size === 0 && scope[key] === installed.dispatch) scope[key] = void 0;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
86
132
|
function connectUiBridge(options) {
|
|
87
133
|
const { end } = options;
|
|
88
134
|
if (end !== "game" && end !== "ui") {
|
|
@@ -125,7 +171,7 @@ function connectUiBridge(options) {
|
|
|
125
171
|
}
|
|
126
172
|
};
|
|
127
173
|
}
|
|
128
|
-
scope
|
|
174
|
+
const uninstall = installInbound(scope, inboundKey, deliver);
|
|
129
175
|
const injected = scope[UI_BRIDGE_GLOBALS.uiHost];
|
|
130
176
|
if (end === "ui" && injected !== void 0 && typeof injected === "object") {
|
|
131
177
|
injected.onmessage = (event) => deliver(event);
|
|
@@ -150,7 +196,7 @@ function connectUiBridge(options) {
|
|
|
150
196
|
close() {
|
|
151
197
|
closed = true;
|
|
152
198
|
listeners.clear();
|
|
153
|
-
|
|
199
|
+
uninstall();
|
|
154
200
|
if (end === "ui" && injected !== void 0 && typeof injected === "object") {
|
|
155
201
|
injected.onmessage = void 0;
|
|
156
202
|
}
|
|
@@ -173,18 +219,23 @@ function publishUiState(bridge, store, options = {}) {
|
|
|
173
219
|
let stopped = false;
|
|
174
220
|
let queued = false;
|
|
175
221
|
let lastFrame = "";
|
|
222
|
+
const send = (state, frame) => {
|
|
223
|
+
lastFrame = frame;
|
|
224
|
+
postUiState(bridge, state, frame);
|
|
225
|
+
};
|
|
176
226
|
const publish = () => {
|
|
177
227
|
if (stopped) return;
|
|
178
228
|
const state = read();
|
|
179
|
-
|
|
180
|
-
bridge.post({ type: GAME_STATE_MESSAGE, state });
|
|
229
|
+
send(state, serializeUiState(state));
|
|
181
230
|
};
|
|
182
231
|
const flush = () => {
|
|
183
232
|
queued = false;
|
|
184
233
|
if (stopped) return;
|
|
185
234
|
if (!bridge.hasPeer()) return;
|
|
186
|
-
|
|
187
|
-
|
|
235
|
+
const state = read();
|
|
236
|
+
const frame = serializeUiState(state);
|
|
237
|
+
if (frame === lastFrame) return;
|
|
238
|
+
send(state, frame);
|
|
188
239
|
};
|
|
189
240
|
const unsubscribe = store.subscribe(() => {
|
|
190
241
|
if (stopped || queued) return;
|