@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.
Files changed (176) hide show
  1. package/capabilities.json +1505 -79
  2. package/dist/{audio-7i3Xl0l3.d.ts → audio-DIJE5HTr.d.ts} +43 -3
  3. package/dist/{canvas-layer-DDmC_VVF.d.ts → canvas-layer-C1-5CviZ.d.ts} +5 -1
  4. package/dist/{game-CljaDv4D.d.ts → game-Jz4Fdoeb.d.ts} +114 -11
  5. package/dist/hot.d.ts +4 -4
  6. package/dist/index.d.ts +712 -118
  7. package/dist/index.js +12437 -4955
  8. package/dist/{gpu-readback-CqJEfWNQ.d.ts → model-lod-BDAUYgsS.d.ts} +80 -5
  9. package/dist/playtest.d.ts +6 -10
  10. package/dist/playtest.js +57 -24
  11. package/dist/react-css.d.ts +62 -0
  12. package/dist/react-css.js +591 -0
  13. package/dist/react.d.ts +2 -2
  14. package/dist/{renderer-CfsS2hxi.d.ts → renderer-9yEo9hPa.d.ts} +489 -22
  15. package/dist/terrain-jobs-worker.d.ts +2 -0
  16. package/dist/terrain-jobs-worker.js +130 -0
  17. package/dist/ui-layer.js +59 -8
  18. package/dist/world.d.ts +766 -73
  19. package/dist/world.js +9307 -3543
  20. package/gpl/recipes/export_world.py +18 -1
  21. package/mcp/blender-server.mjs +7 -4
  22. package/mcp/blender.mjs +3 -4
  23. package/mcp/engine-server.mjs +2 -2
  24. package/mcp/servers.mjs +4 -4
  25. package/package.json +15 -9
  26. package/patches/three@0.185.1-prd269-upgrade.patch +22418 -0
  27. package/patches/three@0.185.1.patch +6594 -700
  28. package/scripts/apply-three-patch.mjs +62 -4
  29. package/src/animation-blend.ts +264 -0
  30. package/src/animation-composition.ts +362 -0
  31. package/src/animation-layers.ts +260 -0
  32. package/src/animation-root-motion.ts +283 -0
  33. package/src/animation.ts +896 -0
  34. package/src/assets.ts +1303 -0
  35. package/src/atmosphere/index.ts +335 -0
  36. package/src/atmosphere/luts.ts +298 -0
  37. package/src/atmosphere/params.ts +323 -0
  38. package/src/audio.ts +912 -0
  39. package/src/billboard.ts +124 -0
  40. package/src/bone-lengths.ts +157 -0
  41. package/src/camera-shake.ts +116 -0
  42. package/src/canvas-layer.ts +47 -0
  43. package/src/clip-audit.ts +401 -0
  44. package/src/clustered-batch.ts +492 -0
  45. package/src/clustered-mesh.ts +638 -0
  46. package/src/compute-driven.ts +176 -0
  47. package/src/compute-timing.ts +318 -0
  48. package/src/config.ts +593 -0
  49. package/src/debug.ts +82 -0
  50. package/src/engine-render-hook.ts +25 -0
  51. package/src/entities.ts +79 -0
  52. package/src/entity-snapshot.ts +53 -0
  53. package/src/flight.ts +683 -0
  54. package/src/fluid-field.ts +748 -0
  55. package/src/fluid-particles.ts +1253 -0
  56. package/src/frame-budget.ts +1368 -0
  57. package/src/game.ts +2408 -0
  58. package/src/geometry-capture.ts +1098 -0
  59. package/src/gpu-class.ts +160 -0
  60. package/src/gpu-frame-observation.ts +424 -0
  61. package/src/gpu-readback.ts +143 -0
  62. package/src/gpu-scene-bvh.ts +464 -0
  63. package/src/grounding.ts +100 -0
  64. package/src/hot.ts +161 -0
  65. package/src/import-meta.d.ts +13 -0
  66. package/src/index.ts +1536 -0
  67. package/src/input.ts +690 -0
  68. package/src/instanced-batch-lod.ts +283 -0
  69. package/src/instanced-batch.ts +274 -0
  70. package/src/interpolation.ts +129 -0
  71. package/src/launch-diagnostics.ts +161 -0
  72. package/src/loop.ts +574 -0
  73. package/src/matrix-world.ts +245 -0
  74. package/src/merge-parts.ts +812 -0
  75. package/src/model-lod.ts +1315 -0
  76. package/src/net-protocol.ts +333 -0
  77. package/src/net-session.ts +477 -0
  78. package/src/net.ts +80 -0
  79. package/src/ocean/fft.ts +72 -0
  80. package/src/ocean/spectral.ts +728 -0
  81. package/src/particle-significance.ts +102 -0
  82. package/src/particles.ts +648 -0
  83. package/src/path-follow.ts +175 -0
  84. package/src/picking.ts +250 -0
  85. package/src/pipeline-census.ts +1566 -0
  86. package/src/platform.ts +210 -0
  87. package/src/playtest.ts +850 -0
  88. package/src/pointer-events.ts +411 -0
  89. package/src/pose-measure.ts +435 -0
  90. package/src/profiling/FrameCounters.ts +231 -0
  91. package/src/profiling/Spans.ts +548 -0
  92. package/src/profiling/opacity-convention.ts +21 -0
  93. package/src/profiling/render-list-validate.ts +175 -0
  94. package/src/profiling/render-trap-audit.ts +84 -0
  95. package/src/profiling/scene-warning.ts +190 -0
  96. package/src/profiling/span-probes.ts +191 -0
  97. package/src/profiling/unlit-foliage-warning.ts +149 -0
  98. package/src/projection-apply.ts +1529 -0
  99. package/src/projection-marker.ts +142 -0
  100. package/src/projection-plan.ts +1258 -0
  101. package/src/projection-skinned.ts +419 -0
  102. package/src/projection-stability.ts +409 -0
  103. package/src/projection-uniform.ts +328 -0
  104. package/src/random.ts +41 -0
  105. package/src/react-css.ts +604 -0
  106. package/src/react-glyphs.ts +114 -0
  107. package/src/react-host.ts +576 -0
  108. package/src/react-layout.ts +265 -0
  109. package/src/react.ts +60 -0
  110. package/src/render/alpha-antialiasing.ts +159 -0
  111. package/src/render/batched-velocity.ts +126 -0
  112. package/src/render/chain.ts +1021 -0
  113. package/src/render/daylight.ts +189 -0
  114. package/src/render/depth-pyramid.ts +596 -0
  115. package/src/render/foliage-alpha.ts +166 -0
  116. package/src/render/material-key.ts +60 -0
  117. package/src/render/mesh-pool.ts +144 -0
  118. package/src/render/probe-volume.ts +1668 -0
  119. package/src/render/resolution-subrect.ts +253 -0
  120. package/src/render/velocity.ts +442 -0
  121. package/src/render/virtual-shadow-pages.ts +827 -0
  122. package/src/render/virtual-shadow-partial.ts +174 -0
  123. package/src/render/virtual-shadow.ts +3330 -0
  124. package/src/render/world-impostor-surface.ts +722 -0
  125. package/src/render/world-impostor.ts +558 -0
  126. package/src/render-camera-cull.ts +441 -0
  127. package/src/render-pass-budget.ts +501 -0
  128. package/src/renderProjection.ts +758 -0
  129. package/src/renderer-config.ts +127 -0
  130. package/src/renderer.ts +1847 -0
  131. package/src/replay-protocol.ts +85 -0
  132. package/src/replay.ts +205 -0
  133. package/src/resolution-scaler.ts +819 -0
  134. package/src/rig-preparation.ts +271 -0
  135. package/src/ripple-field.ts +432 -0
  136. package/src/scale.ts +109 -0
  137. package/src/scene.ts +239 -0
  138. package/src/schedule.ts +155 -0
  139. package/src/skeletal-mesh.ts +61 -0
  140. package/src/skeleton.ts +100 -0
  141. package/src/snow-field.ts +744 -0
  142. package/src/softbody-topology.ts +269 -0
  143. package/src/softbody.ts +516 -0
  144. package/src/sprite-animator.ts +222 -0
  145. package/src/startup-readiness.ts +386 -0
  146. package/src/state.ts +66 -0
  147. package/src/static-transform.ts +274 -0
  148. package/src/storage-buffer.ts +253 -0
  149. package/src/streaming.ts +308 -0
  150. package/src/target-fps.ts +92 -0
  151. package/src/terrain-jobs-worker.ts +17 -0
  152. package/src/terrain-jobs.ts +353 -0
  153. package/src/textures.ts +39 -0
  154. package/src/tracers.ts +237 -0
  155. package/src/ui-bridge.ts +368 -0
  156. package/src/ui-hit-regions.ts +380 -0
  157. package/src/ui-layer.ts +83 -0
  158. package/src/ui-state.ts +220 -0
  159. package/src/version.ts +2 -0
  160. package/src/viewport.ts +253 -0
  161. package/src/warmup.ts +1357 -0
  162. package/src/water-surface.ts +384 -0
  163. package/src/wave-field.ts +524 -0
  164. package/src/world-capabilities.ts +131 -0
  165. package/src/world-cell-proxy.ts +392 -0
  166. package/src/world-cells.ts +10564 -0
  167. package/src/world-gpu-scene.ts +3354 -0
  168. package/src/world-heightmap.ts +82 -0
  169. package/src/world-package.ts +469 -0
  170. package/src/world-passes.ts +582 -0
  171. package/src/world-region.ts +17 -0
  172. package/src/world-terrain-splat.ts +564 -0
  173. package/src/world-tiles.ts +3826 -0
  174. package/src/world-topology.ts +370 -0
  175. package/src/world-validate.ts +48 -0
  176. package/src/world.ts +805 -0
@@ -0,0 +1,269 @@
1
+ import type { BufferGeometry } from "three";
2
+
3
+ export interface IClothTopologyOptions {
4
+ /** Original geometry vertex indices that never move. Duplicate positions pin together. */
5
+ readonly pinned: readonly number[];
6
+ }
7
+
8
+ export interface IClothTopology {
9
+ /** Unique local-space xyz values after exact exporter-duplicate welding. */
10
+ readonly positions: Float32Array;
11
+ /** Original geometry vertex index to unique simulation vertex index. */
12
+ readonly originalToUnique: Uint32Array;
13
+ /** Undirected endpoint pairs, one pair per triangle edge. */
14
+ readonly springs: Uint32Array;
15
+ readonly restLengths: Float32Array;
16
+ readonly pinned: Uint32Array;
17
+ readonly neighborCounts: Uint32Array;
18
+ readonly neighbors: Uint32Array;
19
+ readonly neighborRestLengths: Float32Array;
20
+ readonly maxNeighbors: number;
21
+ }
22
+
23
+ export interface IClothReferenceOptions {
24
+ readonly topology: IClothTopology;
25
+ readonly duration: number;
26
+ readonly frameStep: number;
27
+ readonly gravity: readonly [number, number, number];
28
+ readonly wind: readonly [number, number, number];
29
+ readonly stiffness: number;
30
+ readonly damping: number;
31
+ }
32
+
33
+ const REFERENCE_STEP = 1 / 120;
34
+
35
+ function finite(name: string, value: number): number {
36
+ if (!Number.isFinite(value)) throw new Error(`SoftBody3D ${name} must be finite.`);
37
+ return value;
38
+ }
39
+
40
+ function positive(name: string, value: number): number {
41
+ finite(name, value);
42
+ if (value <= 0) throw new Error(`SoftBody3D ${name} must be greater than zero.`);
43
+ return value;
44
+ }
45
+
46
+ function nonNegative(name: string, value: number): number {
47
+ finite(name, value);
48
+ if (value < 0) throw new Error(`SoftBody3D ${name} must be non-negative.`);
49
+ return value;
50
+ }
51
+
52
+ function valueAt(values: ArrayLike<number>, index: number, label: string): number {
53
+ const value = values[index];
54
+ if (value === undefined) throw new Error(`SoftBody3D ${label} ${index} is missing.`);
55
+ return value;
56
+ }
57
+
58
+ function vertexKey(x: number, y: number, z: number): string {
59
+ return `${x}|${y}|${z}`;
60
+ }
61
+
62
+ function triangleIndices(geometry: BufferGeometry, originalCount: number): Uint32Array {
63
+ const source = geometry.getIndex();
64
+ const count = source?.count ?? originalCount;
65
+ if (count === 0 || count % 3 !== 0)
66
+ throw new Error("SoftBody3D geometry must contain complete triangles.");
67
+ const result = new Uint32Array(count);
68
+ for (let index = 0; index < count; index += 1) {
69
+ const vertex = source === null ? index : source.getX(index);
70
+ if (!Number.isInteger(vertex) || vertex < 0 || vertex >= originalCount)
71
+ throw new Error(`SoftBody3D triangle index ${vertex} is outside the geometry.`);
72
+ result[index] = vertex;
73
+ }
74
+ return result;
75
+ }
76
+
77
+ function restLength(positions: Float32Array, a: number, b: number): number {
78
+ const offsetA = a * 3;
79
+ const offsetB = b * 3;
80
+ const x = valueAt(positions, offsetB, "position") - valueAt(positions, offsetA, "position");
81
+ const y =
82
+ valueAt(positions, offsetB + 1, "position") - valueAt(positions, offsetA + 1, "position");
83
+ const z =
84
+ valueAt(positions, offsetB + 2, "position") - valueAt(positions, offsetA + 2, "position");
85
+ return Math.hypot(x, y, z);
86
+ }
87
+
88
+ function adjacency(
89
+ positions: Float32Array,
90
+ springs: Uint32Array,
91
+ ): Pick<IClothTopology, "maxNeighbors" | "neighborCounts" | "neighborRestLengths" | "neighbors"> {
92
+ const vertexCount = positions.length / 3;
93
+ const lists = Array.from({ length: vertexCount }, () => [] as { index: number; rest: number }[]);
94
+ for (let spring = 0; spring < springs.length; spring += 2) {
95
+ const a = valueAt(springs, spring, "spring");
96
+ const b = valueAt(springs, spring + 1, "spring");
97
+ const rest = restLength(positions, a, b);
98
+ lists[a]?.push({ index: b, rest });
99
+ lists[b]?.push({ index: a, rest });
100
+ }
101
+ const maxNeighbors = Math.max(1, ...lists.map((list) => list.length));
102
+ const neighborCounts = new Uint32Array(vertexCount);
103
+ const neighbors = new Uint32Array(vertexCount * maxNeighbors);
104
+ const neighborRestLengths = new Float32Array(vertexCount * maxNeighbors);
105
+ for (let vertex = 0; vertex < lists.length; vertex += 1) {
106
+ const list = lists[vertex] as { index: number; rest: number }[];
107
+ neighborCounts[vertex] = list.length;
108
+ for (let neighbor = 0; neighbor < list.length; neighbor += 1) {
109
+ const entry = list[neighbor] as { index: number; rest: number };
110
+ const slot = vertex * maxNeighbors + neighbor;
111
+ neighbors[slot] = entry.index;
112
+ neighborRestLengths[slot] = entry.rest;
113
+ }
114
+ }
115
+ return { maxNeighbors, neighborCounts, neighborRestLengths, neighbors };
116
+ }
117
+
118
+ /** Derive one spring graph from ordinary indexed or non-indexed triangle geometry. */
119
+ export function buildClothTopology(
120
+ geometry: BufferGeometry,
121
+ options: IClothTopologyOptions,
122
+ ): IClothTopology {
123
+ const attribute = geometry.getAttribute("position");
124
+ if (attribute === undefined || attribute.itemSize !== 3 || attribute.count === 0)
125
+ throw new Error("SoftBody3D geometry needs a non-empty vec3 position attribute.");
126
+ if (!Array.isArray(options.pinned) || options.pinned.length === 0)
127
+ throw new Error("SoftBody3D pinned must name at least one original vertex.");
128
+
129
+ const originalToUnique = new Uint32Array(attribute.count);
130
+ const uniqueValues: number[] = [];
131
+ const uniqueByPosition = new Map<string, number>();
132
+ for (let original = 0; original < attribute.count; original += 1) {
133
+ const x = finite(`position[${original}].x`, attribute.getX(original));
134
+ const y = finite(`position[${original}].y`, attribute.getY(original));
135
+ const z = finite(`position[${original}].z`, attribute.getZ(original));
136
+ const key = vertexKey(x, y, z);
137
+ let unique = uniqueByPosition.get(key);
138
+ if (unique === undefined) {
139
+ unique = uniqueValues.length / 3;
140
+ uniqueByPosition.set(key, unique);
141
+ uniqueValues.push(x, y, z);
142
+ }
143
+ originalToUnique[original] = unique;
144
+ }
145
+ const positions = new Float32Array(uniqueValues);
146
+ const triangle = triangleIndices(geometry, attribute.count);
147
+ const springKeys = new Set<string>();
148
+ const springValues: number[] = [];
149
+ for (let offset = 0; offset < triangle.length; offset += 3) {
150
+ const vertices = [
151
+ originalToUnique[valueAt(triangle, offset, "triangle")],
152
+ originalToUnique[valueAt(triangle, offset + 1, "triangle")],
153
+ originalToUnique[valueAt(triangle, offset + 2, "triangle")],
154
+ ] as const;
155
+ for (const [left, right] of [
156
+ [vertices[0], vertices[1]],
157
+ [vertices[1], vertices[2]],
158
+ [vertices[2], vertices[0]],
159
+ ] as const) {
160
+ if (left === undefined || right === undefined || left === right) continue;
161
+ const a = Math.min(left, right);
162
+ const b = Math.max(left, right);
163
+ const key = `${a}:${b}`;
164
+ if (springKeys.has(key)) continue;
165
+ springKeys.add(key);
166
+ springValues.push(a, b);
167
+ }
168
+ }
169
+ if (springValues.length === 0) throw new Error("SoftBody3D geometry produced no springs.");
170
+ const springs = new Uint32Array(springValues);
171
+ const restLengths = new Float32Array(springs.length / 2);
172
+ for (let spring = 0; spring < springs.length; spring += 2)
173
+ restLengths[spring / 2] = restLength(
174
+ positions,
175
+ valueAt(springs, spring, "spring"),
176
+ valueAt(springs, spring + 1, "spring"),
177
+ );
178
+
179
+ const pinned = new Uint32Array(positions.length / 3);
180
+ for (const original of options.pinned) {
181
+ if (!Number.isInteger(original) || original < 0 || original >= attribute.count)
182
+ throw new Error(`SoftBody3D pinned vertex ${original} is outside the geometry.`);
183
+ const unique = originalToUnique[original];
184
+ if (unique === undefined) throw new Error(`SoftBody3D pinned vertex ${original} is missing.`);
185
+ pinned[unique] = 1;
186
+ }
187
+
188
+ return {
189
+ ...adjacency(positions, springs),
190
+ originalToUnique,
191
+ pinned,
192
+ positions,
193
+ restLengths,
194
+ springs,
195
+ };
196
+ }
197
+
198
+ function referenceStep(
199
+ positions: Float64Array,
200
+ velocities: Float64Array,
201
+ options: IClothReferenceOptions,
202
+ ): void {
203
+ const { topology } = options;
204
+ const forces = new Float64Array(positions.length);
205
+ for (let spring = 0; spring < topology.springs.length; spring += 2) {
206
+ const a = valueAt(topology.springs, spring, "spring");
207
+ const b = valueAt(topology.springs, spring + 1, "spring");
208
+ const ax = a * 3;
209
+ const bx = b * 3;
210
+ const dx = valueAt(positions, bx, "position") - valueAt(positions, ax, "position");
211
+ const dy = valueAt(positions, bx + 1, "position") - valueAt(positions, ax + 1, "position");
212
+ const dz = valueAt(positions, bx + 2, "position") - valueAt(positions, ax + 2, "position");
213
+ const length = Math.hypot(dx, dy, dz);
214
+ if (length <= 1e-9) continue;
215
+ const scale =
216
+ ((length - valueAt(topology.restLengths, spring / 2, "rest length")) * options.stiffness) /
217
+ length;
218
+ for (const [offset, value] of [
219
+ [0, dx * scale],
220
+ [1, dy * scale],
221
+ [2, dz * scale],
222
+ ] as const) {
223
+ forces[ax + offset] = valueAt(forces, ax + offset, "force") + value;
224
+ forces[bx + offset] = valueAt(forces, bx + offset, "force") - value;
225
+ }
226
+ }
227
+ const decay = Math.exp(-options.damping * REFERENCE_STEP);
228
+ for (let vertex = 0; vertex < topology.pinned.length; vertex += 1) {
229
+ if (topology.pinned[vertex] === 1) continue;
230
+ for (let axis = 0; axis < 3; axis += 1) {
231
+ const index = vertex * 3 + axis;
232
+ const acceleration =
233
+ valueAt(forces, index, "force") +
234
+ valueAt(options.gravity, axis, "gravity") +
235
+ valueAt(options.wind, axis, "wind");
236
+ velocities[index] =
237
+ (valueAt(velocities, index, "velocity") + acceleration * REFERENCE_STEP) * decay;
238
+ positions[index] =
239
+ valueAt(positions, index, "position") +
240
+ valueAt(velocities, index, "velocity") * REFERENCE_STEP;
241
+ }
242
+ }
243
+ }
244
+
245
+ /** Scalar oracle for determinism and fixed-substep tests; the runtime solver remains on the GPU. */
246
+ export function simulateClothReference(options: IClothReferenceOptions): Float64Array {
247
+ positive("duration", options.duration);
248
+ positive("frameStep", options.frameStep);
249
+ positive("stiffness", options.stiffness);
250
+ nonNegative("damping", options.damping);
251
+ for (const [name, values] of [
252
+ ["gravity", options.gravity],
253
+ ["wind", options.wind],
254
+ ] as const)
255
+ for (const value of values) finite(name, value);
256
+ const frames = Math.round(options.duration / options.frameStep);
257
+ const substeps = Math.round(options.frameStep / REFERENCE_STEP);
258
+ if (
259
+ Math.abs(frames * options.frameStep - options.duration) > 1e-9 ||
260
+ Math.abs(substeps * REFERENCE_STEP - options.frameStep) > 1e-9
261
+ )
262
+ throw new Error("SoftBody3D reference duration and frameStep must align to 1/120 s.");
263
+ const positions = new Float64Array(options.topology.positions);
264
+ const velocities = new Float64Array(positions.length);
265
+ for (let frame = 0; frame < frames; frame += 1)
266
+ for (let substep = 0; substep < substeps; substep += 1)
267
+ referenceStep(positions, velocities, options);
268
+ return positions;
269
+ }