|
|
|
|
@@ -27,12 +27,12 @@ export function XyzacToolPreview({ visual, view = "p", zoom = 1, rotateMode = fa
|
|
|
|
|
const scene = new THREE.Scene();
|
|
|
|
|
scene.background = new THREE.Color(0x050a0e);
|
|
|
|
|
scene.add(new THREE.HemisphereLight(0xdcecff, 0x121820, 1.4));
|
|
|
|
|
const camera = new THREE.PerspectiveCamera(40, 1, 0.01, 100);
|
|
|
|
|
let camera: THREE.PerspectiveCamera | THREE.OrthographicCamera = new THREE.PerspectiveCamera(40, 1, 0.001, 100);
|
|
|
|
|
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false, preserveDrawingBuffer: true });
|
|
|
|
|
renderer.setPixelRatio(Math.min(globalThis.devicePixelRatio || 1, 2));
|
|
|
|
|
renderer.domElement.dataset.engine = "three.js r185 / xyzac-tool-preview";
|
|
|
|
|
element.appendChild(renderer.domElement);
|
|
|
|
|
const controls = new OrbitControls(camera, renderer.domElement);
|
|
|
|
|
let controls: OrbitControls<THREE.PerspectiveCamera | THREE.OrthographicCamera> = new OrbitControls(camera, renderer.domElement);
|
|
|
|
|
controls.enableDamping = true;
|
|
|
|
|
controls.dampingFactor = .12;
|
|
|
|
|
controls.enableZoom = true;
|
|
|
|
|
@@ -60,12 +60,18 @@ export function XyzacToolPreview({ visual, view = "p", zoom = 1, rotateMode = fa
|
|
|
|
|
const toolGroup = new THREE.Group(); toolGroup.name = "xyzac-preview-tool"; scene.add(toolGroup);
|
|
|
|
|
const overlayGroup = new THREE.Group(); overlayGroup.name = "xyzac-preview-overlays"; scene.add(overlayGroup);
|
|
|
|
|
const offsetAxes = new THREE.AxesHelper(1.5); offsetAxes.name = "xyzac-preview-offset-axes"; overlayGroup.add(offsetAxes);
|
|
|
|
|
const limitGrid = new THREE.GridHelper(2.5, 10, 0x8b4d47, 0x4f2d2d); limitGrid.name = "xyzac-preview-limits"; overlayGroup.add(limitGrid);
|
|
|
|
|
const limitGrid = new THREE.Box3Helper(new THREE.Box3(), 0xd8756d); limitGrid.name = "xyzac-preview-limits"; overlayGroup.add(limitGrid);
|
|
|
|
|
const extents = new THREE.Box3Helper(new THREE.Box3(), 0xf2cf65); extents.name = "xyzac-preview-extents"; overlayGroup.add(extents);
|
|
|
|
|
const toolMaterial = new THREE.MeshStandardMaterial({ color: 0xb8bec4, roughness: .45, metalness: .35 });
|
|
|
|
|
const tool = new THREE.Mesh(new THREE.CylinderGeometry(.04, .04, .58, 20), toolMaterial); tool.name = "xyzac-preview-tool-shaft"; toolGroup.add(tool);
|
|
|
|
|
const tipGeometry = new THREE.ConeGeometry(.09, .28, 24); tipGeometry.rotateZ(Math.PI); tipGeometry.translate(0, .14, 0);
|
|
|
|
|
const tip = new THREE.Mesh(tipGeometry, new THREE.MeshBasicMaterial({ color: 0xf2f2f2 })); tip.name = "xyzac-preview-tool-tip"; toolGroup.add(tip);
|
|
|
|
|
const resize = () => { const width = Math.max(element.clientWidth, 280); const height = Math.max(element.clientHeight, 260); camera.aspect = width / height; camera.updateProjectionMatrix(); renderer.setSize(width, height, false); };
|
|
|
|
|
const resize = () => {
|
|
|
|
|
const width = Math.max(element.clientWidth, 280), height = Math.max(element.clientHeight, 260);
|
|
|
|
|
if (camera instanceof THREE.PerspectiveCamera) camera.aspect = width / height;
|
|
|
|
|
else { camera.left = -camera.top * width / height; camera.right = -camera.left; }
|
|
|
|
|
camera.updateProjectionMatrix(); renderer.setSize(width, height, false);
|
|
|
|
|
};
|
|
|
|
|
const observer = new ResizeObserver(resize); observer.observe(element); resize();
|
|
|
|
|
const fit = (segments: Segment[]) => {
|
|
|
|
|
const points = segments.flatMap((segment) => (Array.isArray(segment.samples) && segment.samples.length > 1 ? segment.samples : [segment.start ?? {}, segment.end ?? {}]).map(sourcePoint));
|
|
|
|
|
@@ -90,6 +96,7 @@ export function XyzacToolPreview({ visual, view = "p", zoom = 1, rotateMode = fa
|
|
|
|
|
let liveTick = -1;
|
|
|
|
|
let liveTrace: THREE.Vector3[] = [];
|
|
|
|
|
let pathSegments: Segment[] | null = null;
|
|
|
|
|
let extentsSegments: Segment[] | null = null;
|
|
|
|
|
// Native TP active_id is the source line/motion id and may repeat (for
|
|
|
|
|
// example, each call of the same helix subroutine). Preserve every
|
|
|
|
|
// occurrence instead of letting a Map overwrite all but one geometry.
|
|
|
|
|
@@ -109,6 +116,7 @@ export function XyzacToolPreview({ visual, view = "p", zoom = 1, rotateMode = fa
|
|
|
|
|
let paintedActiveSegment = 0;
|
|
|
|
|
let paintedProgress = 0;
|
|
|
|
|
let liveHistoryLine: THREE.Line | null = null;
|
|
|
|
|
let historyVertexCount = 0;
|
|
|
|
|
let activeLiveLine: THREE.Line | null = null;
|
|
|
|
|
let livePathEpoch = -1;
|
|
|
|
|
let lastHistoryTick = -1;
|
|
|
|
|
@@ -116,14 +124,25 @@ export function XyzacToolPreview({ visual, view = "p", zoom = 1, rotateMode = fa
|
|
|
|
|
let lastPreset = "";
|
|
|
|
|
const presetCamera = (selected: Props["view"], selectedZoom: number) => {
|
|
|
|
|
const distance = bounds.radius * 2.9 / Math.max(.5, selectedZoom);
|
|
|
|
|
controls.dispose();
|
|
|
|
|
const aspect = Math.max(element.clientWidth, 280) / Math.max(element.clientHeight, 260);
|
|
|
|
|
const span = bounds.radius * 1.3 / Math.max(.5, selectedZoom);
|
|
|
|
|
camera = selected === "p" ? new THREE.PerspectiveCamera(40, aspect, .001, 100)
|
|
|
|
|
: new THREE.OrthographicCamera(-span * aspect, span * aspect, span, -span, .001, 100);
|
|
|
|
|
camera.up.set(0, 1, 0);
|
|
|
|
|
if (selected === "z") camera.up.set(0, 0, 1);
|
|
|
|
|
if (selected === "z2") camera.up.set(-1, 0, 0);
|
|
|
|
|
if (selected === "y2") camera.up.set(1, 0, 0);
|
|
|
|
|
controls = new OrbitControls(camera, renderer.domElement);
|
|
|
|
|
controls.enableDamping = true; controls.dampingFactor = .12; controls.screenSpacePanning = true;
|
|
|
|
|
controls.target.copy(bounds.center);
|
|
|
|
|
if (selected === "z") camera.position.copy(bounds.center).add(new THREE.Vector3(0, distance, .01));
|
|
|
|
|
else if (selected === "z2") camera.position.copy(bounds.center).add(new THREE.Vector3(distance * .3, distance * .9, distance * .3));
|
|
|
|
|
else if (selected === "x") camera.position.copy(bounds.center).add(new THREE.Vector3(distance, .02, .01));
|
|
|
|
|
else if (selected === "y") camera.position.copy(bounds.center).add(new THREE.Vector3(.01, .02, distance));
|
|
|
|
|
else if (selected === "y2") camera.position.copy(bounds.center).add(new THREE.Vector3(.01, .02, -distance));
|
|
|
|
|
if (selected === "z" || selected === "z2") camera.position.copy(bounds.center).add(new THREE.Vector3(0, -distance, 0));
|
|
|
|
|
else if (selected === "x") camera.position.copy(bounds.center).add(new THREE.Vector3(-distance, 0, 0));
|
|
|
|
|
else if (selected === "y") camera.position.copy(bounds.center).add(new THREE.Vector3(0, 0, distance));
|
|
|
|
|
else if (selected === "y2") camera.position.copy(bounds.center).add(new THREE.Vector3(0, 0, -distance));
|
|
|
|
|
else camera.position.copy(bounds.center).add(new THREE.Vector3(distance * .85, distance * .7, distance));
|
|
|
|
|
camera.lookAt(bounds.center);
|
|
|
|
|
element.dataset.xyzacProjection = selected === "p" ? "perspective" : "orthographic";
|
|
|
|
|
controls.update();
|
|
|
|
|
};
|
|
|
|
|
const pan = (horizontal: number, vertical: number) => {
|
|
|
|
|
@@ -246,22 +265,14 @@ export function XyzacToolPreview({ visual, view = "p", zoom = 1, rotateMode = fa
|
|
|
|
|
// vertices so preview loading does not block the UI on one WebGL
|
|
|
|
|
// object and geometry allocation per G-code line.
|
|
|
|
|
const batched = { rapid: [] as THREE.Vector3[], completed: [] as THREE.Vector3[] };
|
|
|
|
|
const sampledLines: Array<{ points: THREE.Vector3[]; rapid: boolean }> = [];
|
|
|
|
|
for (const segment of segments) {
|
|
|
|
|
const start = segment.start ?? {}; const end = segment.end ?? {};
|
|
|
|
|
const sampled = Array.isArray(segment.samples) && segment.samples.length > 1;
|
|
|
|
|
const points = sampled ? segment.samples!.map(sourcePoint) : [sourcePoint(start), sourcePoint(end)];
|
|
|
|
|
const rapidPath = segment.kind === "rapid";
|
|
|
|
|
if (sampled) sampledLines.push({ points, rapid: rapidPath });
|
|
|
|
|
else (rapidPath ? batched.rapid : batched.completed).push(...points);
|
|
|
|
|
const target = rapidPath ? batched.rapid : batched.completed;
|
|
|
|
|
for (let index = 1; index < points.length; index++) target.push(points[index - 1], points[index]);
|
|
|
|
|
}
|
|
|
|
|
const addLine = (points: THREE.Vector3[], material: THREE.LineBasicMaterial | THREE.LineDashedMaterial, dashed = false) => {
|
|
|
|
|
if (points.length < 2) return;
|
|
|
|
|
const line = new THREE.Line(new THREE.BufferGeometry().setFromPoints(points), material);
|
|
|
|
|
if (dashed) line.computeLineDistances();
|
|
|
|
|
line.renderOrder = 10;
|
|
|
|
|
pathGroup.add(line);
|
|
|
|
|
};
|
|
|
|
|
const addSegments = (points: THREE.Vector3[], material: THREE.LineBasicMaterial | THREE.LineDashedMaterial, dashed = false) => {
|
|
|
|
|
if (points.length < 2) return;
|
|
|
|
|
const line = new THREE.LineSegments(new THREE.BufferGeometry().setFromPoints(points), material);
|
|
|
|
|
@@ -271,7 +282,8 @@ export function XyzacToolPreview({ visual, view = "p", zoom = 1, rotateMode = fa
|
|
|
|
|
};
|
|
|
|
|
addSegments(batched.rapid, rapid, true);
|
|
|
|
|
addSegments(batched.completed, completed);
|
|
|
|
|
for (const sampled of sampledLines) addLine(sampled.points, sampled.rapid ? rapid : completed, sampled.rapid);
|
|
|
|
|
element.dataset.xyzacPreviewDrawCalls = String(pathGroup.children.length);
|
|
|
|
|
element.dataset.xyzacPreviewVertices = String(batched.rapid.length + batched.completed.length);
|
|
|
|
|
}
|
|
|
|
|
const presetKey = `${viewRef.current}:${zoomRef.current}:${bounds.radius}:${bounds.center.x}:${bounds.center.y}:${bounds.center.z}`;
|
|
|
|
|
if (presetKey !== lastPreset) { presetCamera(viewRef.current, zoomRef.current); lastPreset = presetKey; }
|
|
|
|
|
@@ -291,10 +303,30 @@ export function XyzacToolPreview({ visual, view = "p", zoom = 1, rotateMode = fa
|
|
|
|
|
element.dataset.xyzacRenderedTick = String(renderedTick);
|
|
|
|
|
const historyDue = liveTrace.length > 1 && (lastHistoryTick < 0 || renderedTick - lastHistoryTick >= 4);
|
|
|
|
|
if (historyDue) {
|
|
|
|
|
if (liveHistoryLine) { liveHistoryLine.geometry.dispose(); liveGroup.remove(liveHistoryLine); }
|
|
|
|
|
liveHistoryLine = new THREE.Line(new THREE.BufferGeometry().setFromPoints(liveTrace), liveHistory);
|
|
|
|
|
liveHistoryLine.renderOrder = 19;
|
|
|
|
|
liveGroup.add(liveHistoryLine);
|
|
|
|
|
if (!liveHistoryLine) {
|
|
|
|
|
liveHistoryLine = new THREE.Line(new THREE.BufferGeometry(), liveHistory);
|
|
|
|
|
liveHistoryLine.renderOrder = 19;
|
|
|
|
|
liveHistoryLine.frustumCulled = false;
|
|
|
|
|
liveGroup.add(liveHistoryLine);
|
|
|
|
|
historyVertexCount = 0;
|
|
|
|
|
}
|
|
|
|
|
let attribute = liveHistoryLine.geometry.getAttribute("position") as THREE.BufferAttribute | undefined;
|
|
|
|
|
if (!attribute || attribute.count < liveTrace.length) {
|
|
|
|
|
const capacity = Math.max(1024, 2 ** Math.ceil(Math.log2(liveTrace.length)));
|
|
|
|
|
attribute = new THREE.BufferAttribute(new Float32Array(capacity * 3), 3).setUsage(THREE.DynamicDrawUsage);
|
|
|
|
|
liveHistoryLine.geometry.dispose();
|
|
|
|
|
liveHistoryLine.geometry = new THREE.BufferGeometry();
|
|
|
|
|
liveHistoryLine.geometry.setAttribute("position", attribute);
|
|
|
|
|
historyVertexCount = 0;
|
|
|
|
|
}
|
|
|
|
|
for (let index = historyVertexCount; index < liveTrace.length; index++) {
|
|
|
|
|
const point = liveTrace[index];
|
|
|
|
|
attribute.setXYZ(index, point.x, point.y, point.z);
|
|
|
|
|
}
|
|
|
|
|
attribute.addUpdateRange(historyVertexCount * 3, (liveTrace.length - historyVertexCount) * 3);
|
|
|
|
|
attribute.needsUpdate = true;
|
|
|
|
|
historyVertexCount = liveTrace.length;
|
|
|
|
|
liveHistoryLine.geometry.setDrawRange(0, historyVertexCount);
|
|
|
|
|
lastHistoryTick = renderedTick;
|
|
|
|
|
}
|
|
|
|
|
const nextActiveKey = `${renderedTick}:${renderedActiveSegment}:${renderedProgress}`;
|
|
|
|
|
@@ -326,17 +358,32 @@ export function XyzacToolPreview({ visual, view = "p", zoom = 1, rotateMode = fa
|
|
|
|
|
}
|
|
|
|
|
pathGroup.visible = layer.showPath; liveGroup.visible = layer.showLive;
|
|
|
|
|
grid.scale.setScalar(Math.max(.2, bounds.radius * 2.4));
|
|
|
|
|
originGroup.scale.setScalar(Math.max(.35, bounds.radius * .55));
|
|
|
|
|
originGroup.scale.setScalar(Math.max(.015, bounds.radius * .35));
|
|
|
|
|
const pose = sourcePoint(renderedPose);
|
|
|
|
|
toolGroup.position.copy(pose);
|
|
|
|
|
toolGroup.rotation.set(-Number(renderedPose.a ?? 0) * DEG, -Number(renderedPose.c ?? 0) * DEG, 0);
|
|
|
|
|
const toolScale = Math.min(1, Math.max(0.15, bounds.radius * 0.55));
|
|
|
|
|
const toolScale = Math.min(1, Math.max(0.015, bounds.radius * 0.35));
|
|
|
|
|
toolGroup.scale.setScalar(toolScale);
|
|
|
|
|
tool.position.set(0, .57, 0); tip.position.set(0, 0, 0);
|
|
|
|
|
grid.visible = true; limitGrid.visible = layer.showLimits; offsetAxes.visible = layer.showOffsets;
|
|
|
|
|
offsetAxes.position.copy(sourcePoint({ x: state.offsets.x_rot_point, y: state.offsets.y_offset, z: state.offsets.z_offset }));
|
|
|
|
|
if (hudRef.current) hudRef.current.textContent = `TOOL PREVIEW\nX ${Number(renderedPose.x).toFixed(3)} Y ${Number(renderedPose.y).toFixed(3)} Z ${Number(renderedPose.z).toFixed(3)}\nA ${Number(renderedPose.a).toFixed(3)} C ${Number(renderedPose.c).toFixed(3)}\nJ0 ${Number(renderedJoints[0] ?? 0).toFixed(3)} J1 ${Number(renderedJoints[1] ?? 0).toFixed(3)} J2 ${Number(renderedJoints[2] ?? 0).toFixed(3)}\nJ3 ${Number(renderedJoints[3] ?? 0).toFixed(3)} J4 ${Number(renderedJoints[4] ?? 0).toFixed(3)}\nHelix ${segments.filter((segment) => segment.kind === "helix").length} / Samples ${segments.reduce((count, segment) => count + (Array.isArray(segment.samples) ? segment.samples.length : 0), 0)}\nLive ${renderedActiveSegment || "-"} / ${renderedProgress.toFixed(3)}\nTick ${renderedTick}\nHash ${state.stateHash.slice(0, 18)}`;
|
|
|
|
|
controls.update(); scene.rotation.y = rotateRef.current ? (performance.now() / 5000) % (Math.PI * 2) : 0; renderer.render(scene, camera); frame = requestAnimationFrame(render);
|
|
|
|
|
grid.visible = true;
|
|
|
|
|
const limits = state.machineLimits;
|
|
|
|
|
limitGrid.visible = layer.showLimits && Boolean(limits);
|
|
|
|
|
if (limits?.length === 3) limitGrid.box.setFromPoints([sourcePoint({ x: limits[0][0], y: limits[1][0], z: limits[2][0] }), sourcePoint({ x: limits[0][1], y: limits[1][1], z: limits[2][1] })]);
|
|
|
|
|
offsetAxes.visible = layer.showOffsets && Boolean(state.coordinateOffset);
|
|
|
|
|
const offset = state.coordinateOffset ?? [0, 0, 0];
|
|
|
|
|
offsetAxes.position.copy(sourcePoint({ x: offset[0], y: offset[1], z: offset[2] }));
|
|
|
|
|
extents.visible = layer.showExtents && segments.length > 0;
|
|
|
|
|
if (extents.visible && extentsSegments !== segments) {
|
|
|
|
|
extentsSegments = segments;
|
|
|
|
|
extents.box.setFromPoints(segments.flatMap((segment) => (segment.samples?.length ? segment.samples : [segment.start, segment.end]).filter(Boolean).map((point) => sourcePoint(point ?? {}))));
|
|
|
|
|
}
|
|
|
|
|
element.dataset.xyzacLimitsVisible = String(limitGrid.visible);
|
|
|
|
|
element.dataset.xyzacExtentsVisible = String(extents.visible);
|
|
|
|
|
element.dataset.xyzacOffset = JSON.stringify(offset);
|
|
|
|
|
if (hudRef.current) hudRef.current.textContent = `TOOL PREVIEW\nX ${Number(renderedPose.x).toFixed(3)} Y ${Number(renderedPose.y).toFixed(3)} Z ${Number(renderedPose.z).toFixed(3)}\nA ${Number(renderedPose.a).toFixed(3)} C ${Number(renderedPose.c).toFixed(3)}\nJ0 ${Number(renderedJoints[0] ?? 0).toFixed(3)} J1 ${Number(renderedJoints[1] ?? 0).toFixed(3)} J2 ${Number(renderedJoints[2] ?? 0).toFixed(3)}\nJ3 ${Number(renderedJoints[3] ?? 0).toFixed(3)} J4 ${Number(renderedJoints[4] ?? 0).toFixed(3)}`;
|
|
|
|
|
if (layer.showVelocity && hudRef.current) hudRef.current.textContent += `\nV ${Number(state.velocityMmMin ?? 0).toFixed(1)} mm/min`;
|
|
|
|
|
controls.mouseButtons.LEFT = rotateRef.current ? THREE.MOUSE.ROTATE : THREE.MOUSE.PAN;
|
|
|
|
|
controls.update(); renderer.render(scene, camera); frame = requestAnimationFrame(render);
|
|
|
|
|
};
|
|
|
|
|
render();
|
|
|
|
|
return () => { cancelAnimationFrame(frame); observer.disconnect(); clearLines(pathGroup); clearLines(liveGroup); completed.dispose(); rapid.dispose(); live.dispose(); liveHistory.dispose(); originGroup.traverse((child) => { const mesh = child as THREE.Mesh; mesh.geometry?.dispose?.(); const material = mesh.material as (THREE.Material & { map?: THREE.Texture }) | undefined; material?.map?.dispose?.(); material?.dispose?.(); }); controls.dispose(); delete (element as typeof element & { xyzacController?: unknown }).xyzacController; renderer.dispose(); element.replaceChildren(); };
|
|
|
|
|
@@ -346,7 +393,7 @@ export function XyzacToolPreview({ visual, view = "p", zoom = 1, rotateMode = fa
|
|
|
|
|
const helixCount = visual.toolpath.filter((segment) => (segment as { kind?: string }).kind === "helix").length;
|
|
|
|
|
const sampleCount = visual.toolpath.reduce((count, segment) => count + (Array.isArray((segment as { samples?: unknown[] }).samples) ? (segment as { samples: unknown[] }).samples.length : 0), 0);
|
|
|
|
|
const controllerButton = (action: string, label: string, glyph: string) => ["zoomIn", "zoomOut"].includes(action) ? null : <button type="button" data-axis-control={`preview-${action}`} data-xyzac-controller={action} title={label} aria-label={label} onClick={() => { const controller = (host.current as (HTMLDivElement & { xyzacController?: Record<string, () => void> }) | null)?.xyzacController; controller?.[action]?.(); }}>{glyph}</button>;
|
|
|
|
|
return <div className="three-viewer xyzac-tool-preview" ref={host} data-xyzac-authoritative={String(visual.authoritative)} data-xyzac-preview="toolpath" data-xyzac-controller="orbit" data-xyzac-origin="0,0,0" data-xyzac-origin-axes="X,Y,Z" data-xyzac-toolpath-count={visual.toolpath.length} data-xyzac-helix-count={helixCount} data-xyzac-sample-count={sampleCount} data-xyzac-samples-source="linuxcnc-wasm-sim_posemath_segment_point" data-xyzac-live-source="linuxcnc-source-tp" data-xyzac-live-progress={visual.activeProgress} data-xyzac-live-pose={JSON.stringify(visual.livePose)} data-xyzac-tick={visual.tick} data-xyzac-state-hash={visual.stateHash} data-xyzac-active-segment={visual.activeSegmentId ?? ""} aria-label="XYZAC authoritative tool preview"><div className="xyzac-view-controller" role="toolbar" aria-label="3D preview controller">{controllerButton("zoomIn", "Zoom in", "+")}{controllerButton("zoomOut", "Zoom out", "-")}<span className="xyzac-controller-divider" aria-hidden="true" />{controllerButton("panLeft", "Pan left", "L")}{controllerButton("panRight", "Pan right", "R")}{controllerButton("panUp", "Pan up", "U")}{controllerButton("panDown", "Pan down", "D")}<span className="xyzac-controller-divider" aria-hidden="true" />{controllerButton("reset", "Reset 3D view", "0")}</div><pre ref={hudRef} className="axis-preview-hud" aria-label="XYZAC tool preview state">{visual.authoritative ? `TOOL PREVIEW\nX ${Number(pose.x).toFixed(3)} Y ${Number(pose.y).toFixed(3)} Z ${Number(pose.z).toFixed(3)}\nA ${Number(pose.a).toFixed(3)} C ${Number(pose.c).toFixed(3)}\nJ0 ${Number(visual.joints[0]).toFixed(3)} J1 ${Number(visual.joints[1]).toFixed(3)} J2 ${Number(visual.joints[2]).toFixed(3)}\nJ3 ${Number(visual.joints[3]).toFixed(3)} J4 ${Number(visual.joints[4]).toFixed(3)}\nHelix ${helixCount} / Samples ${sampleCount}\nLive ${visual.activeSegmentId ?? "-"} / ${visual.activeProgress.toFixed(3)}\nTick ${visual.tick}\nHash ${visual.stateHash.slice(0, 18)}` : "TOOL PREVIEW\nWASM state pending"}</pre></div>;
|
|
|
|
|
return <div className="three-viewer xyzac-tool-preview" ref={host} data-xyzac-authoritative={String(visual.authoritative)} data-xyzac-preview="toolpath" data-xyzac-controller="orbit" data-xyzac-origin="0,0,0" data-xyzac-origin-axes="X,Y,Z" data-xyzac-toolpath-count={visual.toolpath.length} data-xyzac-helix-count={helixCount} data-xyzac-sample-count={sampleCount} data-xyzac-samples-source="linuxcnc-wasm-sim_posemath_segment_point" data-xyzac-live-source="linuxcnc-source-tp" data-xyzac-live-progress={visual.activeProgress} data-xyzac-live-pose={JSON.stringify(visual.livePose)} data-xyzac-tick={visual.tick} data-xyzac-state-hash={visual.stateHash} data-xyzac-active-segment={visual.activeSegmentId ?? ""} aria-label="XYZAC authoritative tool preview"><div className="xyzac-view-controller" role="toolbar" aria-label="3D preview controller">{controllerButton("zoomIn", "Zoom in", "+")}{controllerButton("zoomOut", "Zoom out", "-")}<span className="xyzac-controller-divider" aria-hidden="true" />{controllerButton("panLeft", "Pan left", "L")}{controllerButton("panRight", "Pan right", "R")}{controllerButton("panUp", "Pan up", "U")}{controllerButton("panDown", "Pan down", "D")}<span className="xyzac-controller-divider" aria-hidden="true" />{controllerButton("reset", "Reset 3D view", "0")}</div><pre ref={hudRef} className="axis-preview-hud" aria-label="XYZAC tool preview state">{visual.authoritative ? `TOOL PREVIEW\nX ${Number(pose.x).toFixed(3)} Y ${Number(pose.y).toFixed(3)} Z ${Number(pose.z).toFixed(3)}\nA ${Number(pose.a).toFixed(3)} C ${Number(pose.c).toFixed(3)}\nJ0 ${Number(visual.joints[0]).toFixed(3)} J1 ${Number(visual.joints[1]).toFixed(3)} J2 ${Number(visual.joints[2]).toFixed(3)}\nJ3 ${Number(visual.joints[3]).toFixed(3)} J4 ${Number(visual.joints[4]).toFixed(3)}` : "TOOL PREVIEW\nWASM state pending"}</pre></div>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function XyzacToolPreviewFromSnapshot({ snapshot, ...props }: Omit<Props, "visual"> & { snapshot: XyzacVisualSource | null | undefined }) {
|
|
|
|
|
|