feat(web): armature bone parenting, pose evaluation and ABB IRB120 headed suite
- engine: PARBONE parenting, BKE_pose_where_is pose refresh, pose channel readback - viewport: three.js bone wireframes for the main-thread and offscreen paths - properties: draft numeric transform inputs (decimals survive typing), armature pose readback in degrees with step=any fields so validation cannot block Apply Pose - tests: headed armature/robot suite (9 cases), receipts bound to candidate hashes Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
41
web/app/src/three-adapter/armature.ts
Normal file
41
web/app/src/three-adapter/armature.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import {BufferGeometry,Float32BufferAttribute,Group,LineBasicMaterial,LineSegments,Matrix4} from '../vendor/three/three.module.js';
|
||||
import type {ArmatureIR} from '../../../protocol/scene-ir';
|
||||
|
||||
/* Bone wireframes for the viewport. Segments live in armature object space:
|
||||
* head is the pose matrix translation and the tail follows the bone Y axis by
|
||||
* the rest length, the same construction BKE_pose_where_is uses for pose_tail.
|
||||
* The caller sets each group matrix from the armature object's display matrix. */
|
||||
export function createArmatureWireframes(
|
||||
armatures: ArmatureIR[],
|
||||
objectMatrix: (objectId: string) => Matrix4 | null,
|
||||
): { group: Group; boneCount: number } {
|
||||
const group = new Group();
|
||||
group.name = 'ARMATURE_BONES';
|
||||
let boneCount = 0;
|
||||
for (const armature of armatures) {
|
||||
const points: number[] = [];
|
||||
for (const bone of armature.bones) {
|
||||
const matrix = bone.poseMatrix ?? bone.restMatrix;
|
||||
if (!matrix || matrix.length !== 16) continue;
|
||||
const length = Math.hypot(bone.tail[0] - bone.head[0], bone.tail[1] - bone.head[1], bone.tail[2] - bone.head[2]);
|
||||
const head = [matrix[12], matrix[13], matrix[14]];
|
||||
const tail = [head[0] + matrix[4] * length, head[1] + matrix[5] * length, head[2] + matrix[6] * length];
|
||||
points.push(head[0], head[1], head[2], tail[0], tail[1], tail[2]);
|
||||
boneCount++;
|
||||
}
|
||||
if (!points.length) continue;
|
||||
const geometry = new BufferGeometry();
|
||||
geometry.setAttribute('position', new Float32BufferAttribute(points, 3));
|
||||
const lines = new LineSegments(geometry, new LineBasicMaterial({ color: 0x9fd7ff, transparent: true, opacity: 0.9, depthTest: false }));
|
||||
lines.renderOrder = 8;
|
||||
lines.frustumCulled = false;
|
||||
lines.userData.renderHelper = 'ARMATURE_BONES';
|
||||
lines.userData.armatureId = armature.id;
|
||||
if (armature.objectId) {
|
||||
const matrix = objectMatrix(armature.objectId);
|
||||
if (matrix) { lines.matrixAutoUpdate = false; lines.matrix.copy(matrix); }
|
||||
}
|
||||
group.add(lines);
|
||||
}
|
||||
return { group, boneCount };
|
||||
}
|
||||
@@ -83,7 +83,7 @@ export type OffscreenViewportResponse =
|
||||
| { type: "ready" }
|
||||
| { type: "deviceStatus"; status: "ready" | "lost" | "restoring" }
|
||||
| { type: "frame"; visiblePixels: number; camera?: ViewportCameraState }
|
||||
| { type: "snapshotStatus"; snapshotRevision: number; nonMeshCount: number; nonMeshBlockedCount: number; greasePencilCount: number; greasePencilBlockedCount: number; greasePencilOnionStrokeCount: number; renderBudget: PBRLightingBudgetReport }
|
||||
| { type: "snapshotStatus"; snapshotRevision: number; nonMeshCount: number; nonMeshBlockedCount: number; greasePencilCount: number; greasePencilBlockedCount: number; greasePencilOnionStrokeCount: number; armatureBoneCount: number; renderBudget: PBRLightingBudgetReport }
|
||||
| ({ type: "textureStatus" } & OffscreenTextureStatus)
|
||||
| { type: "viewPresetStatus"; preset: "SCENE_CAMERA" | "COMPARISON"; position: [number, number, number]; target: [number, number, number] }
|
||||
| { type: "displacementStatus"; mappedMaterials: number; boundMaterials: number; heightTextures: number; heightTextureKeys: number; heightBindingImageIds: string[]; heightTextureKeyList: string[] }
|
||||
|
||||
@@ -834,6 +834,7 @@ export class OffscreenViewportRenderer implements ViewportBackend {
|
||||
this.canvas.dataset.greasePencilCount = String(message.greasePencilCount);
|
||||
this.canvas.dataset.greasePencilBlockedCount = String(message.greasePencilBlockedCount);
|
||||
this.canvas.dataset.greasePencilOnionStrokeCount = String(message.greasePencilOnionStrokeCount);
|
||||
this.canvas.dataset.armatureBoneCount = String(message.armatureBoneCount);
|
||||
this.canvas.dataset.renderBudgetBackend = message.renderBudget.backend;
|
||||
this.canvas.dataset.renderBudgetStatus = message.renderBudget.status.toLowerCase();
|
||||
this.canvas.dataset.renderBudgetCode = message.renderBudget.issues[0]?.code ?? "";
|
||||
|
||||
@@ -40,6 +40,7 @@ import { TransformGizmo, buildGizmoSegments, pickGizmoHandle, type GizmoState, t
|
||||
import { pickSurface, projectBrushRing, type BrushCursorRing, type SurfacePick } from "./viewport-surface-math";
|
||||
import {ViewportNavigation} from './viewport-navigation';
|
||||
import {nodeDisplayMatrix} from './node-display-matrix';
|
||||
import {createArmatureWireframes} from './armature';
|
||||
import type { MaterialIR, SceneNodeIR, SceneSnapshotIR, SceneTransformIR } from "../../../protocol/scene-ir";
|
||||
import { composeLocalMatrix } from "./viewport-transform";
|
||||
import { applySceneDelta, sceneDeltaRequiresRendererRebuild, type SceneDelta } from "../../../protocol/scene-delta";
|
||||
@@ -316,6 +317,13 @@ export class ViewportRenderer {
|
||||
this.populateLights(snapshot, lightingBudget);
|
||||
this.populateNonMesh(snapshot, nonMeshGeometryBuffers);
|
||||
this.populateGreasePencils(snapshot);
|
||||
const armatureWireframes = createArmatureWireframes(snapshot.armatures ?? [], (objectId) => {
|
||||
const node = snapshot.nodes.find((candidate) => candidate.id === objectId);
|
||||
return node ? nodeDisplayMatrix(node, node.visible) : null;
|
||||
});
|
||||
if (armatureWireframes.boneCount > 0) this.importedRoot.add(armatureWireframes.group);
|
||||
this.canvas.dataset.armatureBoneCount = String(armatureWireframes.boneCount);
|
||||
this.canvas.dataset.snapshotRevision = String(snapshot.revision);
|
||||
const meshes = new Map(snapshot.meshes.map((mesh) => [mesh.id, mesh]));
|
||||
const binaryGeometry = new Map(geometryBuffers.map((payload) => [payload.meshId, payload]));
|
||||
for (const node of snapshot.nodes) {
|
||||
|
||||
Reference in New Issue
Block a user