@volter/blender-engine 0.1.133 → 0.1.134

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.
@@ -8,6 +8,7 @@ import { z } from 'zod';
8
8
  import { onPresenterChange, presenterChanged } from './blender-presenter-change';
9
9
  import { bytesFromBase64 } from './blender-base64';
10
10
  import { ArmatureOverlay, armatureSchema } from './blender-runtime-armature';
11
+ import { type FrameSkin, RuntimeSkeletons, skinGeometry } from './blender-runtime-skeleton';
11
12
  import { UNKNOWN_GEOMETRY, UNKNOWN_IMAGE } from './blender-runtime-frame';
12
13
  import {
13
14
  drawArraysFromColumns,
@@ -129,6 +130,38 @@ const attributeSchema = z.discriminatedUnion('type', [
129
130
  z.object({ ...attributeFields, type: z.literal('BOOLEAN'), data: z.array(z.boolean()) }).strict(),
130
131
  z.object({ ...attributeFields, type: z.literal('STRING'), data: z.array(z.string()) }).strict(),
131
132
  ]);
133
+ /** The door's skin block (`bpy_web_export.cc` `write_skin`): per EXPORTED vertex, four deform
134
+ * groups and their weights, for the armature that deforms the mesh. */
135
+ const frameSkinSchema = z
136
+ .object({
137
+ armature: z.string(),
138
+ groups: z.array(z.string()),
139
+ columns: z.object({ joints: z.instanceof(Uint16Array), weights: z.instanceof(Float32Array) }).strict(),
140
+ })
141
+ .strict();
142
+ /** The same skin per DRAWN vertex, as a copy of a presented frame carries it (`fullFrame`). */
143
+ const drawnSkinSchema = z
144
+ .object({
145
+ armature: z.string(),
146
+ groups: z.array(z.string()),
147
+ index: z.instanceof(Uint16Array),
148
+ weight: z.instanceof(Float32Array),
149
+ })
150
+ .strict();
151
+ /** An exported mesh's geometry with its skin laid over its drawn vertices (`skinGeometry`). */
152
+ function withFrameSkin(geometry: THREE.BufferGeometry, skin: FrameSkin | undefined): THREE.BufferGeometry {
153
+ if (skin) skinGeometry(geometry, skin);
154
+ return geometry;
155
+ }
156
+ /** A drawn mesh's geometry with the per-drawn-vertex skin a copy carried (`fullFrame`). */
157
+ function withDrawnSkin(geometry: THREE.BufferGeometry,
158
+ skin: { armature: string; groups: string[]; index: Uint16Array; weight: Float32Array } | undefined): THREE.BufferGeometry {
159
+ if (!skin) return geometry;
160
+ geometry.setAttribute('skinIndex', new THREE.Uint16BufferAttribute(skin.index, 4));
161
+ geometry.setAttribute('skinWeight', new THREE.Float32BufferAttribute(skin.weight, 4));
162
+ geometry.userData['blenderSkin'] = { armature: skin.armature, groups: [...skin.groups] };
163
+ return geometry;
164
+ }
132
165
  const drawArraysSchema = z
133
166
  .object({
134
167
  positions: z.instanceof(Float32Array),
@@ -149,6 +182,7 @@ const drawArraysSchema = z
149
182
  ),
150
183
  /** The draw's vertex map (`DrawArrays.sourceVertex`), kept by a copy that plays (skins bind over it). */
151
184
  sourceVertex: z.instanceof(Uint32Array).optional(),
185
+ skin: drawnSkinSchema.optional(),
152
186
  hash: z.string(),
153
187
  })
154
188
  .strict();
@@ -224,6 +258,7 @@ const columnAttributeSchema = z
224
258
  .strict();
225
259
  const exportedMeshSchema = z
226
260
  .object({
261
+ skin: frameSkinSchema.optional(),
227
262
  columns: columnsSchema,
228
263
  attributes: z.array(columnAttributeSchema),
229
264
  activeUv: z.string().nullable(),
@@ -567,6 +602,11 @@ export const frameSchema = z
567
602
  * `show_in_front`. `blender-runtime-armature.ts` is the drawing.
568
603
  */
569
604
  armatures: z.record(z.string(), armatureSchema).default({}),
605
+ /** Every action and its revision (`bpy_web_export.cc`): a clip is baked again exactly when its
606
+ * action's revision moves. */
607
+ actions: z.record(z.string(), z.number().int().nonnegative()).default({}),
608
+ /** The scene's frame range and rate (`session.py`), beside `frame`. */
609
+ clock: z.object({ start: z.number().int(), end: z.number().int(), fps: z.number().finite().positive() }).strict().optional(),
570
610
  /** The active object's active vertex group, per vertex
571
611
  * (`blender-runtime-weights.ts`); null when nothing is painted. */
572
612
  weights: weightsSchema.nullable().default(null),
@@ -663,8 +703,24 @@ export interface PhotographRecord {
663
703
  render: { width: number; height: number; fov: number; orthographic: boolean };
664
704
  }
665
705
 
706
+ /** A skinned mesh as the plain mesh it is again (its geometry kept), when its skin went away. */
707
+ function plainMesh(skinned: THREE.Mesh): THREE.Mesh {
708
+ const plain = new THREE.Mesh(skinned.geometry, skinned.material);
709
+ plain.name = skinned.name;
710
+ plain.matrixAutoUpdate = skinned.matrixAutoUpdate;
711
+ plain.matrix.copy(skinned.matrix);
712
+ plain.matrix.decompose(plain.position, plain.quaternion, plain.scale);
713
+ plain.userData = skinned.userData;
714
+ return plain;
715
+ }
716
+
666
717
  export class BlenderRuntimeView {
667
718
  readonly root = new THREE.Group();
719
+ /** Every armature's bones as the frame poses them, and the skins bound to them
720
+ * (`blender-runtime-skeleton.ts`). A reader plays clips on `skeletons.rig(name).bones`. */
721
+ readonly skeletons = new RuntimeSkeletons();
722
+ /** The geometry and rig each skinned mesh was bound with, so it is bound again only when either changes. */
723
+ private skinBinds = new WeakMap<THREE.Object3D, { geometry: THREE.BufferGeometry; rig: object }>();
668
724
  private readonly instances = new BlenderRuntimeInstances(this.root);
669
725
  private readonly materialRanges = new BlenderMaterialRanges();
670
726
  private readonly transparentInstances = new BlenderTransparentInstances(this.root);
@@ -1061,6 +1117,35 @@ export class BlenderRuntimeView {
1061
1117
  * needs it — its rows come from the engine by name, and every one that our
1062
1118
  * viewport can select has to find its way back to a three object through
1063
1119
  * the frame's own table, never through `object.name`. */
1120
+ /**
1121
+ * WHAT THE LAST FRAME SAYS ABOUT ANIMATION, for a reader that plays clips on `skeletons`: the
1122
+ * scene's current frame and clock, every action's revision, each armature's assigned action, the
1123
+ * active object, and which armature a mesh object's skin is bound to. Read off the frame the view
1124
+ * holds, never the engine.
1125
+ */
1126
+ animationFacts(): {
1127
+ frame: number;
1128
+ clock: { start: number; end: number; fps: number } | null;
1129
+ active: string | null;
1130
+ actions: Readonly<Record<string, number>>;
1131
+ armatures: Readonly<Record<string, { action: string | null }>>;
1132
+ skinArmature(object: string): string | null;
1133
+ } {
1134
+ const frame = this.frame;
1135
+ return {
1136
+ frame: frame?.frame ?? 0,
1137
+ clock: frame?.clock ?? null,
1138
+ active: frame?.active ?? null,
1139
+ actions: frame?.actions ?? {},
1140
+ armatures: Object.fromEntries(Object.entries(frame?.armatures ?? {}).map(([name, armature]) => [name, { action: armature.action ?? null }])),
1141
+ skinArmature: (name) => {
1142
+ const object = this.objectForBlenderName(name) as THREE.Mesh | null;
1143
+ const skin = object?.geometry?.userData['blenderSkin'] as { armature: string } | undefined;
1144
+ return skin?.armature ?? null;
1145
+ },
1146
+ };
1147
+ }
1148
+
1064
1149
  objectForBlenderName(name: string): THREE.Object3D | null {
1065
1150
  const entry = this.frame?.objects.find((o) => o.name === name);
1066
1151
  return entry === undefined ? null : (this.objects.get(entry.id) ?? null);
@@ -1671,9 +1756,11 @@ export class BlenderRuntimeView {
1671
1756
  const data = exportedMeshSchema.parse(part.piece);
1672
1757
  if (staged.meshes.has(part.mesh)) throw new Error('Duplicate Blender mesh piece');
1673
1758
  const signature = `revision:${data.revision}`;
1674
- staged.meshes.set(part.mesh, { signature, geometry: geometryFromDrawArrays(drawArraysFromColumns({
1759
+ const geometry = geometryFromDrawArrays(drawArraysFromColumns({
1675
1760
  ...data.columns, attributes: data.attributes as never, activeUv: data.activeUv, renderUv: data.renderUv,
1676
- }, signature)) });
1761
+ }, signature));
1762
+ if (data.skin) skinGeometry(geometry, data.skin);
1763
+ staged.meshes.set(part.mesh, { signature, geometry });
1677
1764
  } else if (part.image !== undefined) {
1678
1765
  if (staged.images.has(part.image)) throw new Error('Duplicate Blender image piece');
1679
1766
  staged.images.set(part.image, frameImageSchema.parse(part.piece));
@@ -1791,7 +1878,7 @@ export class BlenderRuntimeView {
1791
1878
  prepared.set(id, {
1792
1879
  signature,
1793
1880
  geometry: exported
1794
- ? geometryFromDrawArrays(
1881
+ ? withFrameSkin(geometryFromDrawArrays(
1795
1882
  drawArraysFromColumns(
1796
1883
  {
1797
1884
  ...data.columns,
@@ -1801,9 +1888,9 @@ export class BlenderRuntimeView {
1801
1888
  },
1802
1889
  signature,
1803
1890
  ),
1804
- )
1891
+ ), data.skin)
1805
1892
  : drawn
1806
- ? geometryFromDrawArrays(data)
1893
+ ? withDrawnSkin(geometryFromDrawArrays(data), data.skin)
1807
1894
  : drawRuntimeGeometry(data),
1808
1895
  });
1809
1896
  }
@@ -2180,6 +2267,26 @@ export class BlenderRuntimeView {
2180
2267
  this.lights.delete(id);
2181
2268
  }
2182
2269
  this.root.updateMatrixWorld(true);
2270
+ // THE SKINS, once the graph stands (a bind reads world matrices): every armature's bones as
2271
+ // Blender posed them, and every mesh whose exported geometry carries a skin bound to them. A
2272
+ // mesh is bound again only when its geometry or its rig was rebuilt; one whose geometry lost
2273
+ // its skin draws as the plain mesh it is.
2274
+ const named = new Map(next.objects.map((obj) => [obj.name, this.objects.get(obj.id) ?? null]));
2275
+ this.skeletons.apply(next.armatures, (name) => named.get(name) ?? null);
2276
+ for (const obj of next.objects) {
2277
+ if (obj.mesh === null || obj.volume) continue;
2278
+ const object = this.objects.get(obj.id) as THREE.Mesh | undefined;
2279
+ if (!object?.isMesh) continue;
2280
+ const skin = object.geometry.userData['blenderSkin'] as { armature: string } | undefined;
2281
+ const rig = skin ? this.skeletons.rig(skin.armature) : null;
2282
+ const held = this.skinBinds.get(object);
2283
+ if (rig && held?.geometry === object.geometry && held.rig === rig) continue;
2284
+ const bound = rig ? this.skeletons.bind(object) : null;
2285
+ const replacement = bound ?? ((object as THREE.SkinnedMesh).isSkinnedMesh ? plainMesh(object) : null);
2286
+ if (replacement && replacement !== object) this.replacePresentedObject(object, replacement);
2287
+ if (bound && rig) this.skinBinds.set(bound, { geometry: bound.geometry, rig });
2288
+ }
2289
+ this.root.updateMatrixWorld(true);
2183
2290
  // Keep the frame's identity and object table, not its geometry payloads:
2184
2291
  // a presented mesh is already resident as its BufferGeometry, and the
2185
2292
  // nested number arrays it arrived as cost ~15x their JSON (the blower's
@@ -2256,7 +2363,8 @@ export class BlenderRuntimeView {
2256
2363
  // Inspection overlays are not render content. In particular weight-paint
2257
2364
  // overlays reference source vertices, which the evaluated draw no longer
2258
2365
  // needs and a render snapshot deliberately does not copy.
2259
- const frame: Frame = structuredClone({ ...source, images: {}, armatures: {}, weights: null });
2366
+ // A copy that plays keeps the armatures its skins bind to; a render snapshot draws no bones.
2367
+ const frame: Frame = structuredClone({ ...source, images: {}, armatures: options.sourceVertices ? source.armatures : {}, weights: null });
2260
2368
  for (const [id, { signature, geometry }] of this.meshes) {
2261
2369
  const attribute = (name: string): Float32Array<ArrayBuffer> | null => {
2262
2370
  const value = geometry.getAttribute(name);
@@ -2298,6 +2406,14 @@ export class BlenderRuntimeView {
2298
2406
  ...(options.sourceVertices && geometry.getAttribute('blenderVertex')
2299
2407
  ? { sourceVertex: new Uint32Array((geometry.getAttribute('blenderVertex') as THREE.BufferAttribute).array) }
2300
2408
  : {}),
2409
+ // A COPY THAT PLAYS keeps its skin too, per drawn vertex, so its own skeletons bind it.
2410
+ ...(options.sourceVertices && geometry.userData['blenderSkin'] && geometry.getAttribute('skinIndex')
2411
+ ? { skin: {
2412
+ ...(geometry.userData['blenderSkin'] as { armature: string; groups: string[] }),
2413
+ index: new Uint16Array((geometry.getAttribute('skinIndex') as THREE.BufferAttribute).array),
2414
+ weight: new Float32Array((geometry.getAttribute('skinWeight') as THREE.BufferAttribute).array),
2415
+ } }
2416
+ : {}),
2301
2417
  };
2302
2418
  }
2303
2419
  for (const [id, { signature }] of this.volumes)
@@ -2507,6 +2623,8 @@ export class BlenderRuntimeView {
2507
2623
  }
2508
2624
 
2509
2625
  private clear() {
2626
+ this.skeletons.dispose();
2627
+ this.skinBinds = new WeakMap();
2510
2628
  this.worldVisibility.dispose();
2511
2629
  this.objectInfoMaterials.clear();
2512
2630
  this.materialRanges.clear();
package/browser/worker.ts CHANGED
@@ -796,11 +796,6 @@ async function handle(request: WorkerRequest): Promise<unknown> {
796
796
  // reason is a measured defect: I4's Collection tab simply did not stand
797
797
  // because `collection` crossed `runtime.ts` and `session.py` and never
798
798
  // this switch, with no error anywhere.
799
- case 'rig':
800
- return pullWork('rig', () => ask({
801
- op: 'rig',
802
- ...(request.object === undefined ? {} : { object: request.object }),
803
- }));
804
799
  case 'action-clip':
805
800
  return ask({
806
801
  op: 'action-clip',
@@ -808,8 +803,6 @@ async function handle(request: WorkerRequest): Promise<unknown> {
808
803
  ...(request.bake === undefined ? {} : { bake: request.bake }),
809
804
  ...(request.action === undefined ? {} : { action: request.action }),
810
805
  });
811
- case 'armature-actions':
812
- return ask({ op: 'armature-actions' });
813
806
  case 'outliner-set':
814
807
  return ask({
815
808
  op: 'outliner-set',
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@volter/blender-engine",
3
3
  "author": "Volter AI, Inc.",
4
4
  "license": "GPL-3.0-or-later",
5
- "version": "0.1.133",
5
+ "version": "0.1.134",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
package/wasm/BUNDLE.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "blender": "5.2.0 LTS",
3
- "source": "5a3cb1250fc1fd7df59e3ff823949c06e52d9422",
3
+ "source": "49cb2710c66715ba61fbf65cc1cc818b1f49d73a",
4
4
  "upstream": "fbe6228777e7d9afefcd61a413844e790ae75db7",
5
5
  "sourceRepository": "https://github.com/volter-ai/blender",
6
- "sourceRecipe": "https://github.com/volter-ai/blender/blob/5a3cb1250fc1fd7df59e3ff823949c06e52d9422/build_files/emscripten/RELEASE.md",
6
+ "sourceRecipe": "https://github.com/volter-ai/blender/blob/49cb2710c66715ba61fbf65cc1cc818b1f49d73a/build_files/emscripten/RELEASE.md",
7
7
  "factoryEngine": "BLENDER_EEVEE",
8
8
  "files": {
9
9
  "blender_browser.js": "raw",
@@ -12,12 +12,12 @@
12
12
  },
13
13
  "rawFiles": {
14
14
  "blender_browser.js": {
15
- "bytes": 408423,
16
- "sha256": "d818e8d746bc62ebf810206ac564d2dc75dc645b3121f4a3919d13ecef11e419"
15
+ "bytes": 408218,
16
+ "sha256": "bcdbcb3ff18110c095b5170d70a0d0f0b33687f86c14c8bc10c979d613ed11c7"
17
17
  },
18
18
  "blender_browser.wasm": {
19
- "bytes": 86351436,
20
- "sha256": "d4c3a8002cb1686f3c5299e28bcbb356934bbe910f2485b2572032b115cf67bd"
19
+ "bytes": 86366810,
20
+ "sha256": "56752d31e837d314eb489ffb031915e003ec9fade944657690ae097ed7c1e947"
21
21
  },
22
22
  "blender_browser.data": {
23
23
  "bytes": 52699590,
@@ -26,12 +26,12 @@
26
26
  },
27
27
  "shippedFiles": {
28
28
  "blender_browser.js": {
29
- "bytes": 408423,
30
- "sha256": "d818e8d746bc62ebf810206ac564d2dc75dc645b3121f4a3919d13ecef11e419"
29
+ "bytes": 408218,
30
+ "sha256": "bcdbcb3ff18110c095b5170d70a0d0f0b33687f86c14c8bc10c979d613ed11c7"
31
31
  },
32
32
  "blender_browser.wasm.br": {
33
- "bytes": 18605311,
34
- "sha256": "97e3bc2c772e9fd6da5a3e28086c1ee1dfd62b35ebdeb127a413b4bd5904031f"
33
+ "bytes": 18248590,
34
+ "sha256": "54cb053de1d77030ba19345eaca38d16d1971bbb50f3de6624709f8b2f97f4e9"
35
35
  },
36
36
  "blender_browser.data.br": {
37
37
  "bytes": 8056485,
@@ -45,6 +45,6 @@
45
45
  "note": "Emscripten 6.0.5, Release -O3 objects and -O2 link, retained public build recipe and dependency licenses. Scoped render-evaluated export preserves render-only geometry and render-specific modifier results without replacing the viewport export state. Prior geometry identity and memory fixes remain. Full-scene Three versus Cycles rendering parity remains incomplete.",
46
46
  "callTrampoline": "CPython 3.13.13 is compiled with PY_CALL_TRAMPOLINE for Blender CPython slot arity casts. This applies to CPython dispatch, not arbitrary indirect calls.",
47
47
  "engineIds": "The session preserves the compiled native CYCLES engine. VOLTER_THREE selects the explicit raster presenter; BLENDER_EEVEE and BLENDER_WORKBENCH remain presentation engines.",
48
- "exportDoor": "The source-owned bpy_web_export.cc exports Principled physical inputs, normal images, eight named UV layers and evaluated corner normals, and takes graph_materials/graph_images/graph_generated (a graph-drawn shader mix reduced to the one Principled BSDF it reaches, graph images at the door revisions with every UDIM tile, orco for deformed meshes whose graph reads Generated coordinates). A frame can defer its changed meshes and pictures (defer) for the caller to pull one at a time (export_mesh, export_image), each call freeing the previous one's columns and a picture it decoded; an undo step keeps the revisions when Blender kept the depsgraph (session_undo); Blender's CPU subdivision descriptor is released once a mesh is read; the memory door reports malloc in-use and free. Datablock revisions are keyed by session_uid. writefile.cc writes one copy of the document per save in the browser build. CPU evaluators adopt stencil tables without cloning; browser subdivision descriptors are released immediately after CPU tessellation/deformation. Native evaluated corner triangles accompany corner normals. Consumed local conversion stencils are released before later UV channels are constructed. Caller-thread file-read, evaluated-object and subdivision checkpoints provide backpressure for resumable startup. Shared geometry revisions advance once per frame. Existing synchronous export remains available. Optional instance_sources exports stable evaluated collection and particle source meshes, including excluded library meshes and converted curves. Frame-local instance_geometry tokens verify Python placement metadata against the exported geometry and are consumed before presentation. Geometry resource identity preserves implicit input storage only for unmodified geometry and separates evaluated modifier/deformation outputs. Object and mesh resource keys have independent namespaces. Scoped begin_render_export/end_render_export reads the render engine depsgraph and isolates viewport revision, undo, deferred resource and image watcher state. Geometry resource identity preserves implicit input storage only for unmodified geometry and separates evaluated modifier/deformation outputs. Object and mesh resource keys have independent namespaces.",
48
+ "exportDoor": "The source-owned bpy_web_export.cc exports Principled physical inputs, normal images, eight named UV layers and evaluated corner normals, and takes graph_materials/graph_images/graph_generated (a graph-drawn shader mix reduced to the one Principled BSDF it reaches, graph images at the door revisions with every UDIM tile, orco for deformed meshes whose graph reads Generated coordinates). A frame can defer its changed meshes and pictures (defer) for the caller to pull one at a time (export_mesh, export_image), each call freeing the previous one's columns and a picture it decoded; an undo step keeps the revisions when Blender kept the depsgraph (session_undo); Blender's CPU subdivision descriptor is released once a mesh is read; the memory door reports malloc in-use and free. Datablock revisions are keyed by session_uid. writefile.cc writes one copy of the document per save in the browser build. CPU evaluators adopt stencil tables without cloning; browser subdivision descriptors are released immediately after CPU tessellation/deformation. Native evaluated corner triangles accompany corner normals. Consumed local conversion stencils are released before later UV channels are constructed. Caller-thread file-read, evaluated-object and subdivision checkpoints provide backpressure for resumable startup. Shared geometry revisions advance once per frame. Existing synchronous export remains available. Optional instance_sources exports stable evaluated collection and particle source meshes, including excluded library meshes and converted curves. Frame-local instance_geometry tokens verify Python placement metadata against the exported geometry and are consumed before presentation. Geometry resource identity preserves implicit input storage only for unmodified geometry and separates evaluated modifier/deformation outputs. Object and mesh resource keys have independent namespaces. Scoped begin_render_export/end_render_export reads the render engine depsgraph and isolates viewport revision, undo, deferred resource and image watcher state. Geometry resource identity preserves implicit input storage only for unmodified geometry and separates evaluated modifier/deformation outputs. Object and mesh resource keys have independent namespaces. A frame ships each armature-deformed mesh's skin with its geometry (write_skin: four joints and weights per drawn vertex by the armature's deform bones, keyed by skin_digest so it is re-sent only when the binding changes) and each armature's assigned action (actions).",
49
49
  "preloadedPayload": "releasePreloadedFileData releases the JS preload buffer after session ready. The measured working payload exclusions are retained."
50
50
  }