完善 xyzbc-trt 刀具偏置闭环
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
linearValueToMeters,
|
||||
resolveStateLinearUnits,
|
||||
} from "../runtime/linear-units.js";
|
||||
import { buildVismachModelState } from "../runtime/vismach-model-state.js";
|
||||
|
||||
const scenes = new WeakMap();
|
||||
const CAMERA_PRESETS = {
|
||||
@@ -62,6 +63,7 @@ export function renderFiveAxisScene(canvas, state) {
|
||||
preview.executedPath.geometry,
|
||||
preview.currentSegmentPath.geometry,
|
||||
]),
|
||||
vismachModel: preview.currentVismachModelState,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -123,6 +125,7 @@ function createScene(canvas) {
|
||||
toolMarker,
|
||||
toolAxis,
|
||||
currentToolhead: new THREE.Vector3(),
|
||||
currentVismachModelState: null,
|
||||
lastSelectedView: null,
|
||||
lastCameraRevision: null,
|
||||
lastFitKey: null,
|
||||
@@ -177,6 +180,7 @@ function renderFallbackPreview(preview, state) {
|
||||
currentSegmentPointCount: currentSegmentPoints.length,
|
||||
pathFitBounds: computePointBounds(previewPoints.concat(executedPoints, currentSegmentPoints)) !== null,
|
||||
pathBounds: summarizeBounds(computePointBounds(previewPoints.concat(executedPoints, currentSegmentPoints))),
|
||||
vismachModel: buildVismachModelState(state),
|
||||
});
|
||||
canvas.dataset.threeFallbackReason = preview.errorMessage;
|
||||
|
||||
@@ -268,6 +272,9 @@ function exposePreviewDataset(canvas, state, preview) {
|
||||
canvas.dataset.threeArcPathPoints = String(preview.arcPointCount || 0);
|
||||
canvas.dataset.threeCurrentSegmentPoints = String(preview.currentSegmentPointCount || 0);
|
||||
canvas.dataset.threeCurrentSegmentType = currentSegmentType(state);
|
||||
canvas.dataset.threeVismachPins = JSON.stringify(preview.vismachModel?.pins || {});
|
||||
canvas.dataset.threeVismachTransforms = JSON.stringify(preview.vismachModel?.transforms || {});
|
||||
canvas.dataset.threeVismachPinDrivenModel = preview.vismachModel?.semanticBoundary || "none";
|
||||
}
|
||||
|
||||
function createLine(color, opacity) {
|
||||
@@ -291,6 +298,19 @@ function createMachineReferenceModel() {
|
||||
);
|
||||
base.position.z = -0.016;
|
||||
|
||||
const tableAxis = new THREE.Group();
|
||||
tableAxis.name = "vismach-table-x";
|
||||
const saddleAxis = new THREE.Group();
|
||||
saddleAxis.name = "vismach-saddle-y";
|
||||
const spindleAxis = new THREE.Group();
|
||||
spindleAxis.name = "vismach-spindle-z";
|
||||
const tiltAxis = new THREE.Group();
|
||||
tiltAxis.name = "vismach-tilt-b";
|
||||
const rotaryAxis = new THREE.Group();
|
||||
rotaryAxis.name = "vismach-rotate-c";
|
||||
const toolOffsetAxis = new THREE.Group();
|
||||
toolOffsetAxis.name = "vismach-tool-offset";
|
||||
|
||||
const table = new THREE.Mesh(
|
||||
new THREE.BoxGeometry(0.37, 0.235, 0.005),
|
||||
new THREE.MeshBasicMaterial({ color: 0x3a444d, transparent: true, opacity: 0.78 }),
|
||||
@@ -329,9 +349,21 @@ function createMachineReferenceModel() {
|
||||
cutter.position.z = 0.008;
|
||||
toolHolder.add(holderBody, cutter);
|
||||
|
||||
root.add(base, table, xAxis, yAxis, zAxis, rotaryA, rotaryC, toolHolder);
|
||||
toolOffsetAxis.add(toolHolder);
|
||||
spindleAxis.add(toolOffsetAxis);
|
||||
rotaryAxis.add(table, rotaryC);
|
||||
tiltAxis.add(rotaryA, rotaryAxis);
|
||||
saddleAxis.add(tiltAxis);
|
||||
tableAxis.add(saddleAxis);
|
||||
root.add(base, xAxis, yAxis, zAxis, tableAxis, spindleAxis);
|
||||
return {
|
||||
root,
|
||||
tableAxis,
|
||||
saddleAxis,
|
||||
spindleAxis,
|
||||
tiltAxis,
|
||||
rotaryAxis,
|
||||
toolOffsetAxis,
|
||||
rotaryA,
|
||||
rotaryC,
|
||||
toolHolder,
|
||||
@@ -410,15 +442,23 @@ function updateToolExecutionMarker(preview, state, toolPosition) {
|
||||
function updateMachineReferenceModel(preview, state, toolPosition) {
|
||||
const model = preview.machineModel;
|
||||
if (!model) return;
|
||||
const a = degreesToRadians(state.axisPose?.a);
|
||||
const b = degreesToRadians(state.axisPose?.b);
|
||||
const c = degreesToRadians(state.axisPose?.c);
|
||||
model.rotaryA.rotation.x = a;
|
||||
model.rotaryA.rotation.y = Math.PI / 2 + b;
|
||||
model.rotaryC.rotation.z = c;
|
||||
const vismach = buildVismachModelState(state);
|
||||
preview.currentVismachModelState = summarizeVismachModelStateForDataset(vismach);
|
||||
const toMeters = (value) => linearValueToMeters(value, vismach.linearUnits);
|
||||
model.tableAxis.position.x = toMeters(vismach.transforms.table.translate.x);
|
||||
model.saddleAxis.position.y = toMeters(vismach.transforms.saddle.translate.y);
|
||||
model.spindleAxis.position.z = toMeters(vismach.transforms.spindle.translate.z);
|
||||
model.tiltAxis.rotation.y = degreesToRadians(vismach.transforms.tilt.rotateDeg.y);
|
||||
model.rotaryAxis.rotation.z = degreesToRadians(vismach.transforms.rotary.rotateDeg.z);
|
||||
model.toolOffsetAxis.position.set(
|
||||
toMeters(vismach.transforms.tool.translate.x),
|
||||
0,
|
||||
toMeters(vismach.transforms.tool.translate.z),
|
||||
);
|
||||
model.rotaryA.rotation.y = Math.PI / 2;
|
||||
model.rotaryC.rotation.x = Math.PI / 2;
|
||||
|
||||
const tcpPosition = toolPosition || toPreviewVector(state.tcpPose || state.axisPose, state);
|
||||
model.toolHolder.position.copy(tcpPosition);
|
||||
const toolVector = toToolVector(state.toolAxisVector);
|
||||
model.toolHolder.lookAt(tcpPosition.clone().add(toolVector));
|
||||
}
|
||||
@@ -652,6 +692,26 @@ function summarizeBounds(bounds) {
|
||||
};
|
||||
}
|
||||
|
||||
function summarizeVismachModelStateForDataset(vismach) {
|
||||
const summarizeVector = (vector = {}) => ({
|
||||
x: round(vector.x),
|
||||
y: round(vector.y),
|
||||
z: round(vector.z),
|
||||
});
|
||||
return {
|
||||
...vismach,
|
||||
pins: Object.fromEntries(Object.entries(vismach.pins).map(([key, value]) => [key, round(value)])),
|
||||
transforms: {
|
||||
table: { ...vismach.transforms.table, translate: summarizeVector(vismach.transforms.table.translate) },
|
||||
saddle: { ...vismach.transforms.saddle, translate: summarizeVector(vismach.transforms.saddle.translate) },
|
||||
spindle: { ...vismach.transforms.spindle, translate: summarizeVector(vismach.transforms.spindle.translate) },
|
||||
tilt: { ...vismach.transforms.tilt },
|
||||
rotary: { ...vismach.transforms.rotary },
|
||||
tool: { ...vismach.transforms.tool, translate: summarizeVector(vismach.transforms.tool.translate) },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function drawFallbackPolyline(ctx, points, cx, cy, scale) {
|
||||
for (let index = 0; index < points.length; index += 1) {
|
||||
const point = points[index];
|
||||
|
||||
Reference in New Issue
Block a user