Add dual canvas XYZBC and refined machine visualization

This commit is contained in:
2026-09-10 05:47:14 +08:00
parent d90933b980
commit 17887c199a
15 changed files with 935 additions and 92 deletions

View File

@@ -168,6 +168,7 @@ export class SimSession {
this.previewState = null;
this.livePathEpoch = 0;
this.workspaceFiles = {};
this.visualModelSourceHash = null;
call(core, "sim_protocol_reset");
if (typeof core.ccall === "function") core.ccall("sim_event_reset", null, [], []);
}
@@ -460,6 +461,23 @@ export class SimSession {
? (Array.isArray(wasmMotion.state.joint_commanded) && wasmMotion.state.joint_commanded.length === 5 ? [...wasmMotion.state.joint_commanded] : inverseJoints?.length === 5 ? [...inverseJoints] : [position.x, position.y, position.z, position.a ?? 0, position.c ?? 0])
: authoritative.kinematics.joints;
const preview = this.previewState?.status === "verified" ? this.previewState : null;
// Keep the Vismach model identity in the same authoritative visual
// envelope as the canonical toolpath and live motion trace. The source
// hash comes from the exact resource resolved during WASM startup, so a
// renderer can audit that its geometry matches the loaded LinuxCNC case.
const modelResource = this.configurationState?.exact_resources?.find?.((row) => row.role === "vismach_source");
const modelSourcePath = "linuxcnc/src/hal/user_comps/vismach/xyzac-trt-gui.py";
const modelSourceText = this.workspaceFiles?.[modelSourcePath];
const machineModel = this.xyzacProgram ? {
schema: "linuxcnc-vismach-model.v1",
id: "xyzac-trt",
source: "linuxcnc-wasm-worker",
source_path: modelResource?.path ?? modelSourcePath,
source_hash: modelResource?.data_hash ?? this.visualModelSourceHash ?? (typeof modelSourceText === "string" ? fnv1a64(modelSourceText) : null),
coordinate_system: "XYZAC",
joints: ["table-x", "saddle-y", "spindle-z", "tilt-a", "rotate-c"],
components: ["base", "column", "head", "spindle", "tool", "table", "saddle", "zslide"],
} : null;
const visual = {
schema: "axis-visual.v1",
pose: { ...position },
@@ -477,6 +495,7 @@ export class SimSession {
velocity_mm_min: motion.velocity_mm_min ?? 0,
machine_limits: this.wasmMotion.axisLimits?.() ?? null,
coordinate_offset: program?.coordinate_context?.offsets?.[(program?.coordinate_context?.system ?? 1) - 1]?.slice(0, 3) ?? null,
...(machineModel ? { machine_model: machineModel } : {}),
};
const axisCoordinates = [position.x, position.y, position.z, position.a ?? 0, position.c ?? 0];
const coordinateContext = program?.coordinate_context;
@@ -1567,6 +1586,8 @@ export class SimSession {
const configuration = input.payload?.configuration ?? null;
if (configuration) {
this.workspaceFiles = { ...(configuration.files ?? configuration.workspace ?? configuration.workspace_files ?? {}) };
const visualSourcePath = "linuxcnc/src/hal/user_comps/vismach/xyzac-trt-gui.py";
this.visualModelSourceHash = typeof this.workspaceFiles[visualSourcePath] === "string" ? fnv1a64(this.workspaceFiles[visualSourcePath]) : null;
const startupWorkspace = configuration.workspace ?? configuration.files ?? configuration.workspace_files;
if (startupWorkspace) {
const startup = new ConfigurationStartupStateMachine({

View File

@@ -0,0 +1,58 @@
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import createModule from "../../build-wasm/linuxcnc-sim-core.js";
import { loadSimulationCase, toWorkerConfiguration } from "../workspace/sim-case-loader.mjs";
import { CONTEXT_ID, SimSession } from "./sim-session.mjs";
import { fnv1a64 } from "./replay.mjs";
const CASE = "linuxcnc/configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzac-trt.ini";
const fetchImpl = async (url) => {
try {
const body = await readFile(new URL(`../../${String(url).replace(/^\//, "")}`, import.meta.url));
return { ok: true, text: async () => body.toString("utf8") };
} catch {
return { ok: false, text: async () => "" };
}
};
const bundle = await loadSimulationCase({ path: CASE, fetchImpl });
assert.equal(bundle.status, "ready");
const sourcePath = "linuxcnc/src/hal/user_comps/vismach/xyzac-trt-gui.py";
const sourceHash = fnv1a64(bundle.files[sourcePath]);
const core = await createModule({ wasmBinary: await readFile(new URL("../../build-wasm/linuxcnc-sim-core.wasm", import.meta.url)) });
const session = new SimSession(core, { sessionId: "xyzac-visual-data-bridge" });
const base = { schema_version: 1, context_id: CONTEXT_ID, session_id: session.sessionId };
let seq = 0;
const send = (kind, payload = {}) => session.accept({ ...base, kind, seq: ++seq, operation_id: `${kind.toLowerCase()}-${seq}`, payload });
send("HELLO");
send("SESSION_ATTACH");
const loaded = send("LOAD_WORKSPACE", { root_path: "/workspace", configuration: toWorkerConfiguration(bundle) });
assert.equal(loaded.payload.status, "verified");
const panel = loaded.payload.panel_snapshot;
assert.equal(panel.visual.source, "wasm_canonical_motion");
assert.equal(panel.visual.machine_model.schema, "linuxcnc-vismach-model.v1");
assert.equal(panel.visual.machine_model.source, "linuxcnc-wasm-worker");
assert.equal(panel.visual.machine_model.source_path, sourcePath);
assert.equal(panel.visual.machine_model.source_hash, sourceHash);
assert.deepEqual(panel.visual.machine_model.joints, ["table-x", "saddle-y", "spindle-z", "tilt-a", "rotate-c"]);
assert.equal(panel.visual.machine_model.coordinate_system, "XYZAC");
assert.ok(panel.visual.toolpath === undefined || Array.isArray(panel.visual.toolpath), "toolpath is optional on compact startup snapshots");
const loadedProgram = send("PROGRAM_LOAD", {
source: "G21\nG90\nG1 X1 Y2 Z3 A4 C5 F100\nM2\n",
path: "bridge.ngc",
});
const visual = loadedProgram.payload.panel_snapshot.visual;
assert.equal(visual.machine_model.source_hash, sourceHash);
assert.ok(Array.isArray(visual.toolpath) && visual.toolpath.length > 0);
assert.equal(visual.source, "wasm_canonical_motion");
assert.match(loadedProgram.payload.panel_snapshot.state_hash, /^fnv1a64:/);
console.log(JSON.stringify({
schema: "xyzac-visual-data-bridge.v1",
status: "verified",
source: sourcePath,
source_hash: sourceHash,
toolpath_segments: visual.toolpath.length,
shared_snapshot_fields: ["visual.machine_model", "visual.toolpath", "visual.motion_trace", "visual.pose", "visual.joints"],
}));