@things-factory/figure-ui 10.1.74 → 10.1.76
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.
- package/client/figure-assistant.ts +3 -3
- package/client/graphql/{v3-store.ts → store.ts} +6 -6
- package/client/modeller/{v3-ai-proposal.ts → ai-proposal.ts} +8 -8
- package/client/modeller/{v3-align.ts → align.ts} +14 -14
- package/client/modeller/{v3-canvas.ts → canvas.ts} +13 -13
- package/client/modeller/{v3-clips.ts → clips.ts} +5 -5
- package/client/modeller/{v3-controls.ts → controls.ts} +2 -2
- package/client/modeller/{v3-editor.ts → editor.ts} +137 -126
- package/client/modeller/{figure-v3-capability.ts → figure-capability-panel.ts} +7 -7
- package/client/modeller/{figure-v3-clips.ts → figure-clips.ts} +10 -10
- package/client/modeller/{figure-v3-controls.ts → figure-controls.ts} +9 -9
- package/client/modeller/{v3-figure-facts.ts → figure-facts.ts} +11 -11
- package/client/modeller/{figure-v3-first-save.ts → figure-first-save.ts} +3 -3
- package/client/modeller/figure-history-panel.ts +1 -1
- package/client/modeller/{figure-v3-links.ts → figure-links.ts} +35 -35
- package/client/modeller/{figure-v3-material.ts → figure-material-panel.ts} +20 -20
- package/client/modeller/{figure-v3-parts.ts → figure-parts.ts} +15 -15
- package/client/modeller/{figure-v3-preview.ts → figure-preview.ts} +14 -14
- package/client/modeller/{figure-v3-properties.ts → figure-properties.ts} +25 -25
- package/client/modeller/{figure-v3-recipe-catalog.ts → figure-recipe-catalog.ts} +10 -10
- package/client/modeller/{figure-v3-verdict.ts → figure-verdict.ts} +24 -24
- package/client/modeller/gate-findings.ts +2 -2
- package/client/modeller/{v3-gizmo.ts → gizmo.ts} +11 -11
- package/client/modeller/{v3-joint-drag.ts → joint-drag.ts} +11 -11
- package/client/modeller/{v3-joint-fan.ts → joint-fan.ts} +13 -13
- package/client/modeller/{v3-links.ts → links.ts} +59 -59
- package/client/modeller/{v3-live.ts → live.ts} +9 -9
- package/client/modeller/{v3-maturity.ts → maturity.ts} +65 -65
- package/client/modeller/modeller-route.ts +1 -1
- package/client/modeller/{v3-occupancy.ts → occupancy.ts} +6 -6
- package/client/modeller/{v3-palette.ts → palette.ts} +3 -3
- package/client/modeller/{v3-preview-model.ts → preview-model.ts} +8 -8
- package/client/modeller/{v3-product-session.ts → product-session.ts} +25 -25
- package/client/modeller/{v3-recipe-source.ts → recipe-source.ts} +2 -2
- package/client/modeller/{v3-recipes.ts → recipes.ts} +9 -9
- package/client/modeller/{v3-refusals.ts → refusals.ts} +62 -13
- package/client/modeller/{v3-renderer.ts → renderer.ts} +16 -16
- package/client/modeller/{v3-stage-model.ts → stage-model.ts} +15 -15
- package/client/modeller/{v3-thumbnail.ts → thumbnail.ts} +8 -8
- package/client/pages/figure-list-page.ts +4 -4
- package/client/pages/{figure-v3-modeller-page.ts → figure-modeller-page.ts} +37 -37
- package/client/route.ts +1 -5
- package/dist-client/figure-assistant.js +3 -3
- package/dist-client/figure-assistant.js.map +1 -1
- package/dist-client/graphql/store.d.ts +3 -0
- package/dist-client/graphql/store.js +39 -0
- package/dist-client/graphql/store.js.map +1 -0
- package/dist-client/modeller/ai-proposal.d.ts +51 -0
- package/dist-client/modeller/ai-proposal.js +64 -0
- package/dist-client/modeller/ai-proposal.js.map +1 -0
- package/dist-client/modeller/align.d.ts +30 -0
- package/dist-client/modeller/align.js +75 -0
- package/dist-client/modeller/align.js.map +1 -0
- package/dist-client/modeller/canvas.d.ts +72 -0
- package/dist-client/modeller/canvas.js +379 -0
- package/dist-client/modeller/canvas.js.map +1 -0
- package/dist-client/modeller/clips.d.ts +39 -0
- package/dist-client/modeller/clips.js +58 -0
- package/dist-client/modeller/clips.js.map +1 -0
- package/dist-client/modeller/controls.d.ts +28 -0
- package/dist-client/modeller/controls.js +28 -0
- package/dist-client/modeller/controls.js.map +1 -0
- package/dist-client/modeller/editor.d.ts +203 -0
- package/dist-client/modeller/editor.js +1526 -0
- package/dist-client/modeller/editor.js.map +1 -0
- package/dist-client/modeller/fields.d.ts +45 -0
- package/dist-client/modeller/fields.js +83 -0
- package/dist-client/modeller/fields.js.map +1 -0
- package/dist-client/modeller/figure-capability-panel.d.ts +22 -0
- package/dist-client/modeller/figure-capability-panel.js +141 -0
- package/dist-client/modeller/figure-capability-panel.js.map +1 -0
- package/dist-client/modeller/figure-clips.d.ts +31 -0
- package/dist-client/modeller/figure-clips.js +268 -0
- package/dist-client/modeller/figure-clips.js.map +1 -0
- package/dist-client/modeller/figure-controls.d.ts +36 -0
- package/dist-client/modeller/figure-controls.js +226 -0
- package/dist-client/modeller/figure-controls.js.map +1 -0
- package/dist-client/modeller/figure-facts.d.ts +35 -0
- package/dist-client/modeller/figure-facts.js +55 -0
- package/dist-client/modeller/figure-facts.js.map +1 -0
- package/dist-client/modeller/figure-first-save.d.ts +20 -0
- package/dist-client/modeller/figure-first-save.js +118 -0
- package/dist-client/modeller/figure-first-save.js.map +1 -0
- package/dist-client/modeller/figure-history-panel.d.ts +1 -1
- package/dist-client/modeller/figure-history-panel.js.map +1 -1
- package/dist-client/modeller/figure-links.d.ts +77 -0
- package/dist-client/modeller/figure-links.js +649 -0
- package/dist-client/modeller/figure-links.js.map +1 -0
- package/dist-client/modeller/figure-material-panel.d.ts +39 -0
- package/dist-client/modeller/figure-material-panel.js +323 -0
- package/dist-client/modeller/figure-material-panel.js.map +1 -0
- package/dist-client/modeller/figure-parts.d.ts +69 -0
- package/dist-client/modeller/figure-parts.js +559 -0
- package/dist-client/modeller/figure-parts.js.map +1 -0
- package/dist-client/modeller/figure-preview.d.ts +34 -0
- package/dist-client/modeller/figure-preview.js +346 -0
- package/dist-client/modeller/figure-preview.js.map +1 -0
- package/dist-client/modeller/figure-properties.d.ts +45 -0
- package/dist-client/modeller/figure-properties.js +239 -0
- package/dist-client/modeller/figure-properties.js.map +1 -0
- package/dist-client/modeller/figure-recipe-catalog.d.ts +38 -0
- package/dist-client/modeller/figure-recipe-catalog.js +399 -0
- package/dist-client/modeller/figure-recipe-catalog.js.map +1 -0
- package/dist-client/modeller/figure-verdict.d.ts +64 -0
- package/dist-client/modeller/figure-verdict.js +787 -0
- package/dist-client/modeller/figure-verdict.js.map +1 -0
- package/dist-client/modeller/first-save.d.ts +17 -0
- package/dist-client/modeller/first-save.js +26 -0
- package/dist-client/modeller/first-save.js.map +1 -0
- package/dist-client/modeller/gate-findings.d.ts +2 -2
- package/dist-client/modeller/gate-findings.js +2 -2
- package/dist-client/modeller/gate-findings.js.map +1 -1
- package/dist-client/modeller/gizmo.d.ts +72 -0
- package/dist-client/modeller/gizmo.js +111 -0
- package/dist-client/modeller/gizmo.js.map +1 -0
- package/dist-client/modeller/help.d.ts +18 -0
- package/dist-client/modeller/help.js +37 -0
- package/dist-client/modeller/help.js.map +1 -0
- package/dist-client/modeller/joint-drag.d.ts +19 -0
- package/dist-client/modeller/joint-drag.js +97 -0
- package/dist-client/modeller/joint-drag.js.map +1 -0
- package/dist-client/modeller/joint-fan.d.ts +9 -0
- package/dist-client/modeller/joint-fan.js +276 -0
- package/dist-client/modeller/joint-fan.js.map +1 -0
- package/dist-client/modeller/keys.d.ts +22 -0
- package/dist-client/modeller/keys.js +26 -0
- package/dist-client/modeller/keys.js.map +1 -0
- package/dist-client/modeller/links.d.ts +267 -0
- package/dist-client/modeller/links.js +480 -0
- package/dist-client/modeller/links.js.map +1 -0
- package/dist-client/modeller/live.d.ts +37 -0
- package/dist-client/modeller/live.js +68 -0
- package/dist-client/modeller/live.js.map +1 -0
- package/dist-client/modeller/maturity.d.ts +120 -0
- package/dist-client/modeller/maturity.js +313 -0
- package/dist-client/modeller/maturity.js.map +1 -0
- package/dist-client/modeller/modeller-route.d.ts +1 -1
- package/dist-client/modeller/modeller-route.js +1 -1
- package/dist-client/modeller/modeller-route.js.map +1 -1
- package/dist-client/modeller/occupancy.d.ts +18 -0
- package/dist-client/modeller/occupancy.js +24 -0
- package/dist-client/modeller/occupancy.js.map +1 -0
- package/dist-client/modeller/palette.d.ts +7 -0
- package/dist-client/modeller/palette.js +46 -0
- package/dist-client/modeller/palette.js.map +1 -0
- package/dist-client/modeller/preview-model.d.ts +47 -0
- package/dist-client/modeller/preview-model.js +68 -0
- package/dist-client/modeller/preview-model.js.map +1 -0
- package/dist-client/modeller/product-session.d.ts +510 -0
- package/dist-client/modeller/product-session.js +157 -0
- package/dist-client/modeller/product-session.js.map +1 -0
- package/dist-client/modeller/recipe-source.d.ts +8 -0
- package/dist-client/modeller/recipe-source.js +14 -0
- package/dist-client/modeller/recipe-source.js.map +1 -0
- package/dist-client/modeller/recipes.d.ts +37 -0
- package/dist-client/modeller/recipes.js +103 -0
- package/dist-client/modeller/recipes.js.map +1 -0
- package/dist-client/modeller/refusals.d.ts +68 -0
- package/dist-client/modeller/refusals.js +142 -0
- package/dist-client/modeller/refusals.js.map +1 -0
- package/dist-client/modeller/renderer.d.ts +40 -0
- package/dist-client/modeller/renderer.js +73 -0
- package/dist-client/modeller/renderer.js.map +1 -0
- package/dist-client/modeller/stage-model.d.ts +39 -0
- package/dist-client/modeller/stage-model.js +147 -0
- package/dist-client/modeller/stage-model.js.map +1 -0
- package/dist-client/modeller/thumbnail.d.ts +3 -0
- package/dist-client/modeller/thumbnail.js +75 -0
- package/dist-client/modeller/thumbnail.js.map +1 -0
- package/dist-client/modeller/v3-clips.d.ts +1 -1
- package/dist-client/modeller/v3-editor.d.ts +5 -0
- package/dist-client/modeller/v3-editor.js +21 -10
- package/dist-client/modeller/v3-editor.js.map +1 -1
- package/dist-client/modeller/v3-product-session.d.ts +31 -0
- package/dist-client/modeller/v3-refusals.d.ts +37 -5
- package/dist-client/modeller/v3-refusals.js +59 -16
- package/dist-client/modeller/v3-refusals.js.map +1 -1
- package/dist-client/pages/figure-list-page.d.ts +1 -1
- package/dist-client/pages/figure-list-page.js +4 -4
- package/dist-client/pages/figure-list-page.js.map +1 -1
- package/dist-client/pages/figure-modeller-page.d.ts +102 -0
- package/dist-client/pages/figure-modeller-page.js +548 -0
- package/dist-client/pages/figure-modeller-page.js.map +1 -0
- package/dist-client/route.d.ts +1 -1
- package/dist-client/route.js +1 -5
- package/dist-client/route.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/docs/product-cutover.md +25 -0
- package/package.json +5 -5
- package/test/{v3-ai-proposal.test.ts → ai-proposal.test.ts} +6 -6
- package/test/{v3-align.test.ts → align.test.ts} +8 -8
- package/test/browser/modeller-page.js +30 -30
- package/test/browser/modeller.check.mjs +17 -16
- package/test/browser/serve.mjs +1 -1
- package/test/browser/thumbnail-page.js +6 -6
- package/test/{v3-clips.test.ts → clips.test.ts} +18 -18
- package/test/{v3-controls.test.ts → controls.test.ts} +15 -15
- package/test/{v3-fields.test.ts → fields.test.ts} +13 -13
- package/test/figure-assistant-surface.test.ts +3 -3
- package/test/{v3-first-save.test.ts → first-save.test.ts} +10 -10
- package/test/fixtures/joint-column.json +2 -2
- package/test/fixtures/joint-roller.json +2 -2
- package/test/fixtures/robot-arm-6dof.json +2 -2
- package/test/{v3-gizmo.test.ts → gizmo.test.ts} +33 -33
- package/test/{v3-joint-drag.test.ts → joint-drag.test.ts} +17 -17
- package/test/{v3-joint-fan.test.ts → joint-fan.test.ts} +18 -18
- package/test/joints.ts +6 -6
- package/test/{v3-keys.test.ts → keys.test.ts} +2 -2
- package/test/{v3-layout.test.ts → layout.test.ts} +8 -8
- package/test/{v3-links.test.ts → links.test.ts} +201 -201
- package/test/{v3-live.test.ts → live.test.ts} +18 -18
- package/test/{v3-material.test.ts → material.test.ts} +12 -12
- package/test/{v3-maturity.test.ts → maturity.test.ts} +74 -74
- package/test/modeller-route.test.ts +5 -6
- package/test/{v3-palette-icons.test.ts → palette-icons.test.ts} +1 -1
- package/test/{v3-parts-wiring.test.ts → parts-wiring.test.ts} +11 -7
- package/test/{v3-preview.test.ts → preview.test.ts} +12 -12
- package/test/{v3-product-session.test.ts → product-session.test.ts} +17 -17
- package/test/{v3-product-write.test.ts → product-write.test.ts} +20 -20
- package/test/{v3-properties.test.ts → properties.test.ts} +24 -24
- package/test/{v3-recipes.test.ts → recipes.test.ts} +10 -10
- package/test/refusals.test.ts +166 -0
- package/test/{v3-release-panel.test.ts → release-panel.test.ts} +21 -21
- package/test/renderer.test.ts +24 -0
- package/test/resolve-ts-siblings.mjs +1 -1
- package/test/{v3-scene-canvas.test.ts → scene-canvas.test.ts} +6 -6
- package/test/{v3-stage-model.test.ts → stage-model.test.ts} +5 -5
- package/test/{v3-theme.test.ts → theme.test.ts} +4 -4
- package/test/{v3-thumbnail.test.ts → thumbnail.test.ts} +4 -4
- package/test/{v3-verdict.test.ts → verdict.test.ts} +17 -17
- package/test/{v3-view.test.ts → view.test.ts} +2 -2
- package/things-factory.config.js +2 -3
- package/translations/en.json +15 -7
- package/translations/ja.json +15 -7
- package/translations/ko.json +15 -7
- package/translations/ms.json +15 -7
- package/translations/zh.json +15 -7
- package/docs/v3-product-cutover.md +0 -25
- package/test/v3-refusals.test.ts +0 -136
- package/test/v3-renderer.test.ts +0 -24
- /package/client/modeller/{v3-fields.ts → fields.ts} +0 -0
- /package/client/modeller/{v3-first-save.ts → first-save.ts} +0 -0
- /package/client/modeller/{v3-help.ts → help.ts} +0 -0
- /package/client/modeller/{v3-keys.ts → keys.ts} +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { compileFigureAsset } from '@hatiolab/figure-model';
|
|
3
|
+
const AXES = ['x', 'y', 'z'];
|
|
4
|
+
/** The axis each face faces along, and which way (as figure-model's `FIGURE_FACES`). */
|
|
5
|
+
const FACE_AXIS = { left: 'x', right: 'x', bottom: 'y', top: 'y', back: 'z', front: 'z' };
|
|
6
|
+
const FACE_SIGN = { left: -1, right: 1, bottom: -1, top: 1, back: -1, front: 1 };
|
|
7
|
+
const matrixOf = (r) => new THREE.Matrix4().set(r[0][0], r[0][1], r[0][2], 0, r[1][0], r[1][1], r[1][2], 0, r[2][0], r[2][1], r[2][2], 0, 0, 0, 0, 1);
|
|
8
|
+
const eulerMatrix = (deg) => new THREE.Matrix4().makeRotationFromEuler(new THREE.Euler(...deg.map(THREE.MathUtils.degToRad), 'XYZ'));
|
|
9
|
+
const unit = (axis) => new THREE.Vector3(/x/i.test(axis) ? 1 : 0, /y/i.test(axis) ? 1 : 0, /z/i.test(axis) ? 1 : 0);
|
|
10
|
+
const round = (v, step) => Number((Math.round(v / step) * step).toFixed(Math.max(0, -Math.floor(Math.log10(step)))));
|
|
11
|
+
/** The part's own quarter turn in the joint frame, as the record says it. */
|
|
12
|
+
const turnMatrix = (j) => eulerMatrix(AXES.map(a => j.origin?.turn?.[a] ?? 0));
|
|
13
|
+
/** The joint frame's rotation in the figure: the part's rotation now, less its own turn and less the joint's. */
|
|
14
|
+
function jointFrameRotation(j, part, angle) {
|
|
15
|
+
const now = matrixOf(part.pose.r);
|
|
16
|
+
const own = turnMatrix(j);
|
|
17
|
+
const turn = j.type === 'revolute' ? new THREE.Matrix4().makeRotationAxis(unit(j.axis), THREE.MathUtils.degToRad(angle)) : new THREE.Matrix4();
|
|
18
|
+
return now.multiply(own.invert()).multiply(turn.invert());
|
|
19
|
+
}
|
|
20
|
+
export function jointDragOf(asset, id, part, result, values) {
|
|
21
|
+
const j = asset.joints?.find(joint => joint.body1.part === id);
|
|
22
|
+
/* A size is the part's own, not the joint's: a scale drag goes to the part's measures (the editor drops the shift). */
|
|
23
|
+
if (!j || result.scale || (!result.rotation && !result.position))
|
|
24
|
+
return null;
|
|
25
|
+
const stateId = j.state?.id ?? j.id;
|
|
26
|
+
const now = values[stateId] ?? asset.stateDefaults[stateId] ?? 0;
|
|
27
|
+
const turns = j.type === 'revolute';
|
|
28
|
+
/* A revolute joint without limits turns without end (USD). */
|
|
29
|
+
const endless = turns && j.lowerLimit === undefined && j.upperLimit === undefined;
|
|
30
|
+
if (result.rotation) {
|
|
31
|
+
if (!turns)
|
|
32
|
+
return { kind: 'refused', reason: j.type === 'prismatic' ? 'turned-slide' : 'fixed-turn', joint: j.id };
|
|
33
|
+
if (j.mimic)
|
|
34
|
+
return { kind: 'refused', reason: 'mimic', joint: j.id, leader: j.mimic.joint };
|
|
35
|
+
/* The turn about the joint's axis (the twist of the change): the only turn the joint can make. */
|
|
36
|
+
const before = new THREE.Quaternion().setFromRotationMatrix(matrixOf(part.pose.r));
|
|
37
|
+
const after = new THREE.Quaternion().setFromRotationMatrix(eulerMatrix(result.rotation));
|
|
38
|
+
const change = after.multiply(before.invert());
|
|
39
|
+
const axis = unit(j.axis).applyMatrix4(jointFrameRotation(j, part, now)).normalize();
|
|
40
|
+
const twist = 2 * Math.atan2(change.x * axis.x + change.y * axis.y + change.z * axis.z, change.w);
|
|
41
|
+
/* Turned about another axis: the joint cannot make that turn, and nothing is written for it. */
|
|
42
|
+
const whole = 2 * Math.acos(Math.min(1, Math.abs(change.w)));
|
|
43
|
+
if (Math.abs(twist) < whole * 0.5)
|
|
44
|
+
return { kind: 'refused', reason: 'off-axis', joint: j.id, axis: j.axis };
|
|
45
|
+
let value = now + THREE.MathUtils.radToDeg(twist);
|
|
46
|
+
if (endless)
|
|
47
|
+
value = ((((value + 180) % 360) + 360) % 360) - 180;
|
|
48
|
+
else
|
|
49
|
+
value = Math.min(Math.max(value, j.lowerLimit), j.upperLimit);
|
|
50
|
+
return { kind: 'value', input: stateId, unit: 'deg', value: round(value, 0.1) };
|
|
51
|
+
}
|
|
52
|
+
const moved = new THREE.Vector3(...result.position).sub(new THREE.Vector3(...part.pose.t));
|
|
53
|
+
if (moved.length() < 0.5)
|
|
54
|
+
return null;
|
|
55
|
+
const frame = jointFrameRotation(j, part, turns ? now : 0);
|
|
56
|
+
if (j.type === 'prismatic') {
|
|
57
|
+
if (j.mimic)
|
|
58
|
+
return { kind: 'refused', reason: 'mimic', joint: j.id, leader: j.mimic.joint };
|
|
59
|
+
/* How far one unit of the value moves the part along its axis, measured on the figure itself (a ratio travels a length). */
|
|
60
|
+
const along = unit(j.axis).applyMatrix4(frame).normalize();
|
|
61
|
+
const at = (v) => {
|
|
62
|
+
const g = compileFigureAsset(asset).evaluate({ ...values, [stateId]: v }).geometry.find(g => g.id === id && 'pose' in g);
|
|
63
|
+
return g ? new THREE.Vector3(...g.pose.t).dot(along) : 0;
|
|
64
|
+
};
|
|
65
|
+
const step = j.travel ? 0.01 : 1;
|
|
66
|
+
const rate = (at(now + step) - at(now)) / step;
|
|
67
|
+
if (Math.abs(rate) > 1e-9 && Math.abs(moved.dot(along)) >= moved.length() * 0.7) {
|
|
68
|
+
const value = Math.min(Math.max(now + moved.dot(along) / rate, j.lowerLimit), j.upperLimit);
|
|
69
|
+
return { kind: 'value', input: stateId, unit: j.travel ? 'ratio' : 'mm', value: round(value, j.travel ? 0.001 : 1) };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/* Moving the joint's origin: the change in the frame the joint sits in. */
|
|
73
|
+
const local = moved.clone().applyMatrix4(frame.clone().invert());
|
|
74
|
+
const normal = 'plane' in j.body0 ? 'y' : FACE_AXIS[j.body0.face];
|
|
75
|
+
/* Which way a larger gap moves the part: out of the face it meets (on the plane: up when it stands, down when it hangs). */
|
|
76
|
+
const outward = 'plane' in j.body0 ? (j.body1.face === 'bottom' ? 1 : -1) : ((j.origin?.facing ?? 'meet') === 'meet' ? 1 : -1) * FACE_SIGN[j.body0.face];
|
|
77
|
+
const origin = { ...(j.origin ?? {}) };
|
|
78
|
+
const along = local[normal];
|
|
79
|
+
if (Math.abs(along) >= 0.5) {
|
|
80
|
+
const gap = origin.gap ?? 0;
|
|
81
|
+
if (typeof gap !== 'number')
|
|
82
|
+
return { kind: 'refused', reason: 'origin-follows', joint: j.id };
|
|
83
|
+
origin.gap = round(gap + outward * along, 1);
|
|
84
|
+
}
|
|
85
|
+
for (const axis of AXES.filter(a => a !== normal)) {
|
|
86
|
+
const d = local[axis];
|
|
87
|
+
if (Math.abs(d) < 0.5)
|
|
88
|
+
continue;
|
|
89
|
+
const how = origin.align?.[axis] ?? 'centre';
|
|
90
|
+
const was = how === 'centre' ? 0 : typeof how === 'object' && typeof how.mm === 'number' ? how.mm : null;
|
|
91
|
+
if (was === null)
|
|
92
|
+
return { kind: 'refused', reason: 'origin-follows', joint: j.id };
|
|
93
|
+
origin.align = { ...(origin.align ?? {}), [axis]: { mm: round(was + d, 1) } };
|
|
94
|
+
}
|
|
95
|
+
return { kind: 'joint', joint: { ...j, origin } };
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=joint-drag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"joint-drag.js","sourceRoot":"","sources":["../../client/modeller/joint-drag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAwB3D,MAAM,IAAI,GAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AACpC,wFAAwF;AACxF,MAAM,SAAS,GAAyB,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,CAAA;AAC/G,MAAM,SAAS,GAA2B,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAA;AAExG,MAAM,QAAQ,GAAG,CAAC,CAAa,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,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GAAG,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAA;QAC5C,MAAM,GAAG,GAAG,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;QACxG,IAAI,GAAG,KAAK,IAAI;YAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAA;QACnF,MAAM,CAAC,KAAK,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAA;IAC/E,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,CAAA;AACnD,CAAC","sourcesContent":["import * as THREE from 'three'\nimport { compileFigureAsset } from '@hatiolab/figure-model'\nimport type { FigureAsset, FigureJoint } from '@hatiolab/figure-model'\n\nimport type { GizmoResult } from './gizmo.js'\nimport type { FigureRenderPart } from './renderer.js'\n\n/*\n * A gizmo drag on a part that hangs from a joint edits the joint, not the part (ADR-0093; r3 §3: the modeller changes\n * the inputs of the relation, and never breaks it because a computed place was moved):\n *\n * - turning a part on a revolute or continuous joint sets the joint's value -- the turn about the joint's axis;\n * - sliding a part on a prismatic joint along its axis sets its value;\n * - moving a part any other way moves the joint's origin: the gap along the face it sits on, the offset across it.\n *\n * What would break a relation is refused and said: an origin that follows another part's size, a joint that mimics\n * another, a turn on a joint that does not turn.\n */\n\nexport type JointDrag =\n | { kind: 'value'; input: string; unit: 'deg' | 'mm' | 'ratio'; value: number }\n | { kind: 'joint'; joint: FigureJoint }\n | { kind: 'refused'; reason: 'mimic' | 'fixed-turn' | 'origin-follows' | 'turned-slide' | 'off-axis'; joint: string; leader?: string; axis?: string }\n\ntype Axis = 'x' | 'y' | 'z'\nconst AXES: Axis[] = ['x', 'y', 'z']\n/** The axis each face faces along, and which way (as figure-model's `FIGURE_FACES`). */\nconst FACE_AXIS: Record<string, Axis> = { left: 'x', right: 'x', bottom: 'y', top: 'y', back: 'z', front: 'z' }\nconst FACE_SIGN: Record<string, number> = { left: -1, right: 1, bottom: -1, top: 1, back: -1, front: 1 }\n\nconst matrixOf = (r: number[][]) => new THREE.Matrix4().set(r[0]![0]!, r[0]![1]!, r[0]![2]!, 0, r[1]![0]!, r[1]![1]!, r[1]![2]!, 0, r[2]![0]!, r[2]![1]!, r[2]![2]!, 0, 0, 0, 0, 1)\nconst eulerMatrix = (deg: number[]) => new THREE.Matrix4().makeRotationFromEuler(new THREE.Euler(...(deg.map(THREE.MathUtils.degToRad) as [number, number, number]), 'XYZ'))\nconst unit = (axis: string) => new THREE.Vector3(/x/i.test(axis) ? 1 : 0, /y/i.test(axis) ? 1 : 0, /z/i.test(axis) ? 1 : 0)\nconst round = (v: number, step: number) => Number((Math.round(v / step) * step).toFixed(Math.max(0, -Math.floor(Math.log10(step)))))\n\n/** The part's own quarter turn in the joint frame, as the record says it. */\nconst turnMatrix = (j: FigureJoint) => eulerMatrix(AXES.map(a => j.origin?.turn?.[a] ?? 0))\n\n/** The joint frame's rotation in the figure: the part's rotation now, less its own turn and less the joint's. */\nfunction jointFrameRotation(j: FigureJoint, part: FigureRenderPart, angle: number): THREE.Matrix4 {\n const now = matrixOf(part.pose.r as number[][])\n const own = turnMatrix(j)\n const turn = j.type === 'revolute' ? new THREE.Matrix4().makeRotationAxis(unit(j.axis!), THREE.MathUtils.degToRad(angle)) : new THREE.Matrix4()\n return now.multiply(own.invert()).multiply(turn.invert())\n}\n\nexport function jointDragOf(asset: FigureAsset, id: string, part: FigureRenderPart, result: GizmoResult, values: Record<string, number>): JointDrag | null {\n const j = asset.joints?.find(joint => joint.body1.part === id)\n /* A size is the part's own, not the joint's: a scale drag goes to the part's measures (the editor drops the shift). */\n if (!j || result.scale || (!result.rotation && !result.position)) return null\n const stateId = j.state?.id ?? j.id\n const now = values[stateId] ?? asset.stateDefaults[stateId] ?? 0\n const turns = j.type === 'revolute'\n /* A revolute joint without limits turns without end (USD). */\n const endless = turns && j.lowerLimit === undefined && j.upperLimit === undefined\n\n if (result.rotation) {\n if (!turns) return { kind: 'refused', reason: j.type === 'prismatic' ? 'turned-slide' : 'fixed-turn', joint: j.id }\n if (j.mimic) return { kind: 'refused', reason: 'mimic', joint: j.id, leader: j.mimic.joint }\n /* The turn about the joint's axis (the twist of the change): the only turn the joint can make. */\n const before = new THREE.Quaternion().setFromRotationMatrix(matrixOf(part.pose.r as number[][]))\n const after = new THREE.Quaternion().setFromRotationMatrix(eulerMatrix(result.rotation))\n const change = after.multiply(before.invert())\n const axis = unit(j.axis!).applyMatrix4(jointFrameRotation(j, part, now)).normalize()\n const twist = 2 * Math.atan2(change.x * axis.x + change.y * axis.y + change.z * axis.z, change.w)\n /* Turned about another axis: the joint cannot make that turn, and nothing is written for it. */\n const whole = 2 * Math.acos(Math.min(1, Math.abs(change.w)))\n if (Math.abs(twist) < whole * 0.5) return { kind: 'refused', reason: 'off-axis', joint: j.id, axis: j.axis! }\n let value = now + THREE.MathUtils.radToDeg(twist)\n if (endless) value = ((((value + 180) % 360) + 360) % 360) - 180\n else value = Math.min(Math.max(value, j.lowerLimit!), j.upperLimit!)\n return { kind: 'value', input: stateId, unit: 'deg', value: round(value, 0.1) }\n }\n\n const moved = new THREE.Vector3(...result.position!).sub(new THREE.Vector3(...(part.pose.t as [number, number, number])))\n if (moved.length() < 0.5) return null\n const frame = jointFrameRotation(j, part, turns ? now : 0)\n\n if (j.type === 'prismatic') {\n if (j.mimic) return { kind: 'refused', reason: 'mimic', joint: j.id, leader: j.mimic.joint }\n /* How far one unit of the value moves the part along its axis, measured on the figure itself (a ratio travels a length). */\n const along = unit(j.axis!).applyMatrix4(frame).normalize()\n const at = (v: number) => {\n const g = compileFigureAsset(asset).evaluate({ ...values, [stateId]: v }).geometry.find(g => g.id === id && 'pose' in g) as { pose: { t: number[] } } | undefined\n return g ? new THREE.Vector3(...(g.pose.t as [number, number, number])).dot(along) : 0\n }\n const step = j.travel ? 0.01 : 1\n const rate = (at(now + step) - at(now)) / step\n if (Math.abs(rate) > 1e-9 && Math.abs(moved.dot(along)) >= moved.length() * 0.7) {\n const value = Math.min(Math.max(now + moved.dot(along) / rate, j.lowerLimit!), j.upperLimit!)\n return { kind: 'value', input: stateId, unit: j.travel ? 'ratio' : 'mm', value: round(value, j.travel ? 0.001 : 1) }\n }\n }\n\n /* Moving the joint's origin: the change in the frame the joint sits in. */\n const local = moved.clone().applyMatrix4(frame.clone().invert())\n const normal: Axis = 'plane' in j.body0 ? 'y' : FACE_AXIS[j.body0.face]!\n /* Which way a larger gap moves the part: out of the face it meets (on the plane: up when it stands, down when it hangs). */\n const outward = 'plane' in j.body0 ? (j.body1.face === 'bottom' ? 1 : -1) : ((j.origin?.facing ?? 'meet') === 'meet' ? 1 : -1) * FACE_SIGN[j.body0.face]!\n const origin: NonNullable<FigureJoint['origin']> = { ...(j.origin ?? {}) }\n const along = local[normal]\n if (Math.abs(along) >= 0.5) {\n const gap = origin.gap ?? 0\n if (typeof gap !== 'number') return { kind: 'refused', reason: 'origin-follows', joint: j.id }\n origin.gap = round(gap + outward * along, 1)\n }\n for (const axis of AXES.filter(a => a !== normal)) {\n const d = local[axis]\n if (Math.abs(d) < 0.5) continue\n const how = origin.align?.[axis] ?? 'centre'\n const was = how === 'centre' ? 0 : typeof how === 'object' && typeof how.mm === 'number' ? how.mm : null\n if (was === null) return { kind: 'refused', reason: 'origin-follows', joint: j.id }\n origin.align = { ...(origin.align ?? {}), [axis]: { mm: round(was + d, 1) } }\n }\n return { kind: 'joint', joint: { ...j, origin } }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FigureAsset } from '@hatiolab/figure-model';
|
|
2
|
+
import type { FigureRenderPart } from './renderer.js';
|
|
3
|
+
/** The fan's name on the board. It is not a part: not in the list, not saved, not picked. */
|
|
4
|
+
export declare const JOINT_FAN = "__joint-fan";
|
|
5
|
+
/**
|
|
6
|
+
* The fan for the part, as a body to stand on the board, or null when the part does not turn. `values` are the
|
|
7
|
+
* inputs the figure is drawn with now (a pose in hand included), so the fan follows the arm as it is posed.
|
|
8
|
+
*/
|
|
9
|
+
export declare function jointFanOf(asset: FigureAsset, part: string, values?: Record<string, number>): FigureRenderPart | null;
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { compileFigureAsset, compileFigureGraph, figureWorldBoxesOf, figureWritersOf } from '@hatiolab/figure-model';
|
|
2
|
+
/*
|
|
3
|
+
* Where the selected part turns, and how far -- a translucent fan on the editing board. An axis name says nothing about which way a part swings; on a six-axis arm the author went to the preview and
|
|
4
|
+
* pushed each slider to its end to find out. The fan lies in the plane the part turns in, at the pivot, open from the
|
|
5
|
+
* control's lowest value to its highest; the edge at the value the figure holds now is where the part is.
|
|
6
|
+
*
|
|
7
|
+
* It is found by evaluating, not by reading the graph's shape: the frame that carries the part is sampled across the
|
|
8
|
+
* control's range, and a point at a fixed distance from the pivot traces the fan. So the direction is right whatever
|
|
9
|
+
* the slope of the control, and a joint inside other joints is drawn where its parents put it.
|
|
10
|
+
*
|
|
11
|
+
* Two ways a part turns are read:
|
|
12
|
+
* - a joint record (ADR-0093): at the joint's origin, about its axis;
|
|
13
|
+
* - a joint written as values (`<joint>.motion` · `<joint>.chain`): the part is composed on the joint's
|
|
14
|
+
* chain, the pivot is the joint's origin (`<joint>.frameOnParent`).
|
|
15
|
+
* A slide has no fan. Nothing is drawn when the turn cannot be found -- a fan in some guessed plane would point the
|
|
16
|
+
* wrong way.
|
|
17
|
+
*/
|
|
18
|
+
/** The fan's name on the board. It is not a part: not in the list, not saved, not picked. */
|
|
19
|
+
export const JOINT_FAN = '__joint-fan';
|
|
20
|
+
/** How thick the fan is: thin enough not to hide the part, thick enough to be seen edge-on. */
|
|
21
|
+
const THICKNESS = 6;
|
|
22
|
+
/** About one segment every six degrees, so a full turn reads as a circle. */
|
|
23
|
+
const STEP_DEG = 6;
|
|
24
|
+
const apply = (p, v) => [0, 1, 2].map(i => p.r[i][0] * v[0] + p.r[i][1] * v[1] + p.r[i][2] * v[2] + p.t[i]);
|
|
25
|
+
const sub = (a, b) => a.map((v, i) => v - b[i]);
|
|
26
|
+
const dot = (a, b) => a.reduce((s, v, i) => s + v * b[i], 0);
|
|
27
|
+
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
28
|
+
const norm = (a) => {
|
|
29
|
+
const l = Math.hypot(...a);
|
|
30
|
+
return l > 1e-9 ? a.map(v => v / l) : null;
|
|
31
|
+
};
|
|
32
|
+
/** How far outside a part's box a pivot may lie and still be on the part: the kernel's contact skin. */
|
|
33
|
+
const SEAM = 1;
|
|
34
|
+
/** An origin this deep in a part's box (a share of its half-measure, on every axis) is housed by the part. */
|
|
35
|
+
const HOUSED = 0.5;
|
|
36
|
+
const AXIS_NAMES = ['x', 'y', 'z'];
|
|
37
|
+
function turnOf(asset, part, values, box) {
|
|
38
|
+
const m = asset.document.model;
|
|
39
|
+
const node = (id) => m.nodes.find(n => n.id === id);
|
|
40
|
+
const constant = (ref) => m.constants.find(c => c.id === ref)?.value;
|
|
41
|
+
const valueOf = (n) => (n ? values[Object.values(n.outputs)[0]] : undefined);
|
|
42
|
+
const controlOf = (ref, seen = new Set()) => {
|
|
43
|
+
if (!ref || seen.has(ref))
|
|
44
|
+
return null;
|
|
45
|
+
seen.add(ref);
|
|
46
|
+
const input = m.inputs.find(i => i.id === ref && i.role === 'state');
|
|
47
|
+
if (input)
|
|
48
|
+
return { id: input.id, min: input.min ?? 0, max: input.max ?? 0 };
|
|
49
|
+
const writer = m.nodes.find(n => Object.values(n.outputs).includes(ref));
|
|
50
|
+
for (const arg of writer?.args ?? []) {
|
|
51
|
+
const found = controlOf(arg, seen);
|
|
52
|
+
if (found)
|
|
53
|
+
return found;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
};
|
|
57
|
+
const axisOf = (motion) => {
|
|
58
|
+
const axis = motion.args.slice(0, 3).map(constant);
|
|
59
|
+
return axis.every(v => typeof v === 'number') ? norm(axis) : null;
|
|
60
|
+
};
|
|
61
|
+
/*
|
|
62
|
+
A joint record (ADR-0093): the fan stands at the joint -- the point on the parent's face the child is fastened at --
|
|
63
|
+
about the joint's axis. A part that does not turn itself shows the joint that sits on it, when there is one: the
|
|
64
|
+
elbow block shows the elbow (user, 2026-09-24: 「elbow-housing itself is a axis」).
|
|
65
|
+
*/
|
|
66
|
+
const turning = (asset.joints ?? []).filter(j => j.type === 'revolute');
|
|
67
|
+
const record = turning.find(j => j.body1.part === part) ?? (() => {
|
|
68
|
+
const on = turning.filter(j => 'part' in j.body0 && j.body0.part === part);
|
|
69
|
+
return on.length === 1 && !(asset.joints ?? []).some(j => j.body1.part === part && j.type !== 'fixed') ? on[0] : undefined;
|
|
70
|
+
})();
|
|
71
|
+
if (record) {
|
|
72
|
+
const child = record.body1.part;
|
|
73
|
+
const carrier = node(`${child}.world`) ? `${child}.world` : `${child}.chain`;
|
|
74
|
+
const pose = valueOf(node(`${child}.pose`));
|
|
75
|
+
const motion = node(`${child}.motion`);
|
|
76
|
+
const control = controlOf(motion?.args[3]);
|
|
77
|
+
if (!node(carrier) || !pose || !control)
|
|
78
|
+
return null;
|
|
79
|
+
/* In the child's own frame: the joint is where its pose puts the seat's origin, the axis turned back by its pose. */
|
|
80
|
+
const back = (v) => [0, 1, 2].map(i => pose.r[0][i] * v[0] + pose.r[1][i] * v[1] + pose.r[2][i] * v[2]);
|
|
81
|
+
const pivot = back(pose.t.map(v => -v));
|
|
82
|
+
const axis = norm(back(AXIS_NAMES.map(a => (a.toUpperCase() === record.axis ? 1 : 0))));
|
|
83
|
+
if (!axis)
|
|
84
|
+
return null;
|
|
85
|
+
return { carrier, pivot, axis, toward: [0, 0, 0], control, turnedPart: child };
|
|
86
|
+
}
|
|
87
|
+
/*
|
|
88
|
+
A joint written as values (`<joint>.motion`, its origin `<joint>.frameOnParent`) carries its own part and
|
|
89
|
+
everything fastened below it, through its chain (the first joint of a chain has only its attachment). A part shows
|
|
90
|
+
the joint it is to that part of the mechanism (user, 2026-09-24: 「elbow-housing itself is a axis」 · 「please check
|
|
91
|
+
all that logic and concept」), tested in this order on the joints as they stand now:
|
|
92
|
+
1. housing -- a joint's origin lies deep inside the part, which is centred on it: the shoulder housing shows the
|
|
93
|
+
shoulder and the elbow housing the elbow, though another joint carries them;
|
|
94
|
+
2. turned -- the joint that carries the part, when its axis passes through the part: through its middle for a
|
|
95
|
+
body that rolls on it (the wrist roll, the tool flange, the gripper body), through its root for a link (the
|
|
96
|
+
upper arm, the forearm);
|
|
97
|
+
3. otherwise none: the pedestal (the base's axis runs through it but turns it not), the fingers.
|
|
98
|
+
An axis passing through a part is not enough by itself: the wrist roll's axis runs the forearm's length and the
|
|
99
|
+
tool roll's through the wrist pitch, and neither turns them (an earlier rule said so, and was wrong).
|
|
100
|
+
*/
|
|
101
|
+
if (!box)
|
|
102
|
+
return null;
|
|
103
|
+
const carrierOf = (joint) => (node(`${joint}.chain`) ? `${joint}.chain` : `${joint}.attach`);
|
|
104
|
+
const mine = node(`${part}.moved`)?.args.find(arg => /\.(chain|attach)\.value$/.test(arg))?.replace(/\.value$/, '');
|
|
105
|
+
const centre = AXIS_NAMES.map(a => box.centre[a]);
|
|
106
|
+
const half = AXIS_NAMES.map(a => box.extent[a] / 2);
|
|
107
|
+
const joints = m.nodes
|
|
108
|
+
.filter(n => n.op === 'axis-turn@1' && n.id.endsWith('.motion') && node(n.id.replace(/\.motion$/, '.frameOnParent')))
|
|
109
|
+
.map(motion => {
|
|
110
|
+
const joint = motion.id.replace(/\.motion$/, '');
|
|
111
|
+
const carrier = carrierOf(joint);
|
|
112
|
+
const frame = valueOf(node(carrier));
|
|
113
|
+
const origin = valueOf(node(`${joint}.frameOnParent`));
|
|
114
|
+
const local = axisOf(motion);
|
|
115
|
+
if (!frame || !origin || !local)
|
|
116
|
+
return null;
|
|
117
|
+
const at = apply(frame, origin.t);
|
|
118
|
+
const along = norm([0, 1, 2].map(i => dot(frame.r[i], local)));
|
|
119
|
+
if (!along)
|
|
120
|
+
return null;
|
|
121
|
+
const off = sub(centre, at);
|
|
122
|
+
return {
|
|
123
|
+
joint,
|
|
124
|
+
motion,
|
|
125
|
+
carrier,
|
|
126
|
+
origin,
|
|
127
|
+
/* How deep the origin lies: 0 at the centre, 1 on the box's face, on the axis where it is shallowest. */
|
|
128
|
+
depth: Math.max(...[0, 1, 2].map(i => Math.abs(off[i]) / (half[i] + SEAM))),
|
|
129
|
+
fromCentre: Math.hypot(...off),
|
|
130
|
+
through: lineMeetsBox(at, along, centre, half)
|
|
131
|
+
};
|
|
132
|
+
})
|
|
133
|
+
.filter((c) => !!c);
|
|
134
|
+
const housing = joints.filter(c => c.depth <= HOUSED).sort((a, b) => a.fromCentre - b.fromCentre)[0];
|
|
135
|
+
const carrying = joints.find(c => c.carrier === mine);
|
|
136
|
+
const chosen = housing ?? (carrying && carrying.through ? carrying : undefined);
|
|
137
|
+
if (!chosen)
|
|
138
|
+
return null;
|
|
139
|
+
const axis = axisOf(chosen.motion);
|
|
140
|
+
const control = controlOf(chosen.motion.args[3]);
|
|
141
|
+
if (!axis || !control)
|
|
142
|
+
return null;
|
|
143
|
+
/* The reference edge points at what the joint turns: of the parts it carries, the one farthest off its axis. */
|
|
144
|
+
const flatOff = (t) => {
|
|
145
|
+
const rel = sub(t, chosen.origin.t);
|
|
146
|
+
return Math.hypot(...sub(rel, axis.map(v => v * dot(rel, axis))));
|
|
147
|
+
};
|
|
148
|
+
const turned = m.nodes
|
|
149
|
+
.filter(n => n.id.endsWith('.moved') && n.args.includes(`${chosen.carrier}.value`))
|
|
150
|
+
.map(n => ({ id: n.id.replace(/\.moved$/, ''), t: valueOf(node(n.id.replace(/\.moved$/, '.pose')))?.t }))
|
|
151
|
+
.filter((one) => !!one.t)
|
|
152
|
+
.sort((a, b) => flatOff(b.t) - flatOff(a.t))[0];
|
|
153
|
+
return { carrier: chosen.carrier, pivot: chosen.origin.t, axis, toward: turned?.t ?? chosen.origin.t, control, turnedPart: turned?.id ?? part };
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The fan for the part, as a body to stand on the board, or null when the part does not turn. `values` are the
|
|
157
|
+
* inputs the figure is drawn with now (a pose in hand included), so the fan follows the arm as it is posed.
|
|
158
|
+
*/
|
|
159
|
+
export function jointFanOf(asset, part, values = {}) {
|
|
160
|
+
if (!part)
|
|
161
|
+
return null;
|
|
162
|
+
let graph;
|
|
163
|
+
try {
|
|
164
|
+
graph = compileFigureGraph(asset.document.model);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
const inputs = { ...asset.designInputs, ...asset.stateDefaults, ...values };
|
|
170
|
+
const at = (over) => graph.evaluate({ ...inputs, ...over }).values;
|
|
171
|
+
let now;
|
|
172
|
+
try {
|
|
173
|
+
now = at({});
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
let box;
|
|
179
|
+
try {
|
|
180
|
+
box = figureWorldBoxesOf(compileFigureAsset({ ...asset, designInputs: { ...asset.designInputs, ...pick(values, asset.designInputs) }, stateDefaults: { ...asset.stateDefaults, ...pick(values, asset.stateDefaults) } })
|
|
181
|
+
.evaluate()
|
|
182
|
+
.geometry.filter(g => g.id === part), figureWritersOf(asset))[0];
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
box = undefined;
|
|
186
|
+
}
|
|
187
|
+
const turn = turnOf(asset, part, now, box);
|
|
188
|
+
if (!turn)
|
|
189
|
+
return null;
|
|
190
|
+
const carrierRef = Object.values(asset.document.model.nodes.find(n => n.id === turn.carrier).outputs)[0];
|
|
191
|
+
const carrierNow = now[carrierRef];
|
|
192
|
+
if (!carrierNow)
|
|
193
|
+
return null;
|
|
194
|
+
/* The reference edge points from the pivot toward the part, in the plane it turns in; any perpendicular if it sits on the axis. */
|
|
195
|
+
const rel = sub(turn.toward, turn.pivot);
|
|
196
|
+
const inPlane = sub(rel, turn.axis.map(v => v * dot(rel, turn.axis)));
|
|
197
|
+
const d = norm(inPlane) ?? norm(cross(turn.axis, Math.abs(turn.axis[0]) < 0.9 ? [1, 0, 0] : [0, 1, 0]));
|
|
198
|
+
/*
|
|
199
|
+
Sized from what the joint turns, not from the selected part: selecting the elbow housing or the forearm
|
|
200
|
+
shows the elbow's one fan, not a smaller one for the smaller part (user, 2026-09-24).
|
|
201
|
+
*/
|
|
202
|
+
const radius = Math.max(60, Math.round(Math.max(largestMeasureOf(asset, turn.turnedPart, inputs), Math.hypot(...inPlane)) * 0.6));
|
|
203
|
+
const edge = turn.pivot.map((v, i) => v + d[i] * radius);
|
|
204
|
+
const { min, max } = turn.control;
|
|
205
|
+
if (!(max > min))
|
|
206
|
+
return null;
|
|
207
|
+
const steps = Math.max(2, Math.ceil((max - min) / STEP_DEG));
|
|
208
|
+
const pivot = apply(carrierNow, turn.pivot);
|
|
209
|
+
const traced = [];
|
|
210
|
+
try {
|
|
211
|
+
for (let i = 0; i <= steps; i++) {
|
|
212
|
+
const s = min + ((max - min) * i) / steps;
|
|
213
|
+
traced.push(apply(at({ [turn.control.id]: s })[carrierRef], edge));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
/* The fan's own frame: x toward the first traced point, y along the axis as it stands now, z completing them. */
|
|
220
|
+
const axisNow = norm([0, 1, 2].map(i => dot(carrierNow.r[i], turn.axis)));
|
|
221
|
+
const first = norm(sub(traced[0], pivot));
|
|
222
|
+
if (!axisNow || !first)
|
|
223
|
+
return null;
|
|
224
|
+
const zAxis = cross(first, axisNow);
|
|
225
|
+
const r = [0, 1, 2].map(i => [first[i], axisNow[i], zAxis[i]]);
|
|
226
|
+
const local = (p) => {
|
|
227
|
+
const v = sub(p, pivot);
|
|
228
|
+
return { x: dot(v, first), y: dot(v, zAxis) };
|
|
229
|
+
};
|
|
230
|
+
const full = max - min >= 359.999;
|
|
231
|
+
const profile = [...(full ? [] : [{ x: 0, y: 0 }]), ...traced.map(local)].map(p => ({ x: Math.round(p.x * 1000) / 1000, y: Math.round(p.y * 1000) / 1000 }));
|
|
232
|
+
return {
|
|
233
|
+
id: JOINT_FAN,
|
|
234
|
+
shape: { provider: 'polygon', dimensions: { height: THICKNESS }, profile },
|
|
235
|
+
pose: { t: pivot, r },
|
|
236
|
+
material: { token: '__joint-fan', transparent: true },
|
|
237
|
+
/** Which control turns it: the joint the fan shows. */
|
|
238
|
+
turns: turn.control.id
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/** The values in hand that belong to a record's keys (design inputs, or state defaults). */
|
|
242
|
+
function pick(values, of) {
|
|
243
|
+
return Object.fromEntries(Object.entries(values).filter(([id]) => id in of));
|
|
244
|
+
}
|
|
245
|
+
/** A part's largest own measure (a box side, a diameter, a length) at the inputs given; 0 when it cannot be read. */
|
|
246
|
+
function largestMeasureOf(asset, part, inputs) {
|
|
247
|
+
try {
|
|
248
|
+
const body = compileFigureAsset({ ...asset, designInputs: pick(inputs, asset.designInputs), stateDefaults: pick(inputs, asset.stateDefaults) })
|
|
249
|
+
.evaluate()
|
|
250
|
+
.geometry.find(g => g.id === part);
|
|
251
|
+
const dims = Object.entries(body?.shape?.dimensions ?? {}).map(([k, v]) => (k.startsWith('radius') ? v * 2 : v));
|
|
252
|
+
return dims.length ? Math.max(...dims) : 0;
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
return 0;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/** Whether the line through `at` along `along` passes through the box (centre, half-measures), within the skin. */
|
|
259
|
+
function lineMeetsBox(at, along, centre, half) {
|
|
260
|
+
let lo = -Infinity, hi = Infinity;
|
|
261
|
+
for (let i = 0; i < 3; i++) {
|
|
262
|
+
const min = centre[i] - half[i] - SEAM, max = centre[i] + half[i] + SEAM;
|
|
263
|
+
if (Math.abs(along[i]) < 1e-12) {
|
|
264
|
+
if (at[i] < min || at[i] > max)
|
|
265
|
+
return false;
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const t1 = (min - at[i]) / along[i], t2 = (max - at[i]) / along[i];
|
|
269
|
+
lo = Math.max(lo, Math.min(t1, t2));
|
|
270
|
+
hi = Math.min(hi, Math.max(t1, t2));
|
|
271
|
+
if (lo > hi)
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=joint-fan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"joint-fan.js","sourceRoot":"","sources":["../../client/modeller/joint-fan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAKpH;;;;;;;;;;;;;;;GAeG;AAEH,6FAA6F;AAC7F,MAAM,CAAC,MAAM,SAAS,GAAG,aAAa,CAAA;AAEtC,+FAA+F;AAC/F,MAAM,SAAS,GAAG,CAAC,CAAA;AACnB,6EAA6E;AAC7E,MAAM,QAAQ,GAAG,CAAC,CAAA;AAWlB,MAAM,KAAK,GAAG,CAAC,CAAO,EAAE,CAAW,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,C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sset } from '@hatiolab/figure-model'\n\nimport type { FigureRenderPart } from './renderer.js'\n\n/*\n * Where the selected part turns, and how far -- a translucent fan on the editing board. An axis name says nothing about which way a part swings; on a six-axis arm the author went to the preview and\n * pushed each slider to its end to find out. The fan lies in the plane the part turns in, at the pivot, open from the\n * control's lowest value to its highest; the edge at the value the figure holds now is where the part is.\n *\n * It is found by evaluating, not by reading the graph's shape: the frame that carries the part is sampled across the\n * control's range, and a point at a fixed distance from the pivot traces the fan. So the direction is right whatever\n * the slope of the control, and a joint inside other joints is drawn where its parents put it.\n *\n * Two ways a part turns are read:\n * - a joint record (ADR-0093): at the joint's origin, about its axis;\n * - a joint written as values (`<joint>.motion` · `<joint>.chain`): the part is composed on the joint's\n * chain, the pivot is the joint's origin (`<joint>.frameOnParent`).\n * A slide has no fan. Nothing is drawn when the turn cannot be found -- a fan in some guessed plane would point the\n * wrong way.\n */\n\n/** The fan's name on the board. It is not a part: not in the list, not saved, not picked. */\nexport const JOINT_FAN = '__joint-fan'\n\n/** How thick the fan is: thin enough not to hide the part, thick enough to be seen edge-on. */\nconst THICKNESS = 6\n/** About one segment every six degrees, so a full turn reads as a circle. */\nconst STEP_DEG = 6\n\ntype Pose = { r: number[][]; t: number[] }\ninterface Node {\n id: string\n op: string\n args: string[]\n outputs: Record<string, string>\n params?: Record<string, string>\n}\n\nconst apply = (p: Pose, v: number[]) => [0, 1, 2].map(i => p.r[i]![0]! * v[0]! + p.r[i]![1]! * v[1]! + p.r[i]![2]! * v[2]! + p.t[i]!)\nconst sub = (a: number[], b: number[]) => a.map((v, i) => v - b[i]!)\nconst dot = (a: number[], b: number[]) => a.reduce((s, v, i) => s + v * b[i]!, 0)\nconst cross = (a: number[], b: number[]) => [a[1]! * b[2]! - a[2]! * b[1]!, a[2]! * b[0]! - a[0]! * b[2]!, a[0]! * b[1]! - a[1]! * b[0]!]\nconst norm = (a: number[]) => {\n const l = Math.hypot(...a)\n return l > 1e-9 ? a.map(v => v / l) : null\n}\n\n/** How far outside a part's box a pivot may lie and still be on the part: the kernel's contact skin. */\nconst SEAM = 1\n/** An origin this deep in a part's box (a share of its half-measure, on every axis) is housed by the part. */\nconst HOUSED = 0.5\nconst AXIS_NAMES = ['x', 'y', 'z'] as const\ntype WorldBox = { centre: Record<'x' | 'y' | 'z', number>; extent: Record<'x' | 'y' | 'z', number> }\n\ninterface Turn {\n /** The node whose value carries the moving frame into the figure's frame. */\n carrier: string\n /** The pivot, in the moving frame. */\n pivot: number[]\n /** The axis, in the moving frame. */\n axis: number[]\n /** Where the part sits, in the moving frame -- which way the fan's reference edge points. */\n toward: number[]\n /** The part the joint turns -- the fan is sized from it, so a joint shows one fan whichever part is selected. */\n turnedPart: string\n /** The state input that turns it. */\n control: { id: string; min: number; max: number }\n}\n\nfunction turnOf(asset: FigureAsset, part: string, values: Record<string, unknown>, box: WorldBox | undefined): Turn | null {\n const m = asset.document.model as unknown as { nodes: Node[]; constants: { id: string; value: number }[]; inputs: { id: string; role?: string; min?: number; max?: number }[] }\n const node = (id: string) => m.nodes.find(n => n.id === id)\n const constant = (ref: string) => m.constants.find(c => c.id === ref)?.value\n const valueOf = (n: Node | undefined) => (n ? values[Object.values(n.outputs)[0]!] : undefined) as Pose | undefined\n const controlOf = (ref: string | undefined, seen = new Set<string>()): Turn['control'] | null => {\n if (!ref || seen.has(ref)) return null\n seen.add(ref)\n const input = m.inputs.find(i => i.id === ref && i.role === 'state')\n if (input) return { id: input.id, min: input.min ?? 0, max: input.max ?? 0 }\n const writer = m.nodes.find(n => Object.values(n.outputs).includes(ref))\n for (const arg of writer?.args ?? []) {\n const found = controlOf(arg, seen)\n if (found) return found\n }\n return null\n }\n const axisOf = (motion: Node) => {\n const axis = motion.args.slice(0, 3).map(constant)\n return axis.every(v => typeof v === 'number') ? norm(axis as number[]) : null\n }\n\n /*\n A joint record (ADR-0093): the fan stands at the joint -- the point on the parent's face the child is fastened at --\n about the joint's axis. A part that does not turn itself shows the joint that sits on it, when there is one: the\n elbow block shows the elbow (user, 2026-09-24: 「elbow-housing itself is a axis」).\n */\n const turning = (asset.joints ?? []).filter(j => j.type === 'revolute')\n const record = turning.find(j => j.body1.part === part) ?? (() => {\n const on = turning.filter(j => 'part' in j.body0 && j.body0.part === part)\n return on.length === 1 && !(asset.joints ?? []).some(j => j.body1.part === part && j.type !== 'fixed') ? on[0] : undefined\n })()\n if (record) {\n const child = record.body1.part\n const carrier = node(`${child}.world`) ? `${child}.world` : `${child}.chain`\n const pose = valueOf(node(`${child}.pose`))\n const motion = node(`${child}.motion`)\n const control = controlOf(motion?.args[3])\n if (!node(carrier) || !pose || !control) return null\n /* In the child's own frame: the joint is where its pose puts the seat's origin, the axis turned back by its pose. */\n const back = (v: number[]) => [0, 1, 2].map(i => pose.r[0]![i]! * v[0]! + pose.r[1]![i]! * v[1]! + pose.r[2]![i]! * v[2]!)\n const pivot = back(pose.t.map(v => -v))\n const axis = norm(back(AXIS_NAMES.map(a => (a.toUpperCase() === record.axis ? 1 : 0))))\n if (!axis) return null\n return { carrier, pivot, axis, toward: [0, 0, 0], control, turnedPart: child }\n }\n\n /*\n A joint written as values (`<joint>.motion`, its origin `<joint>.frameOnParent`) carries its own part and\n everything fastened below it, through its chain (the first joint of a chain has only its attachment). A part shows\n the joint it is to that part of the mechanism (user, 2026-09-24: 「elbow-housing itself is a axis」 · 「please check\n all that logic and concept」), tested in this order on the joints as they stand now:\n 1. housing -- a joint's origin lies deep inside the part, which is centred on it: the shoulder housing shows the\n shoulder and the elbow housing the elbow, though another joint carries them;\n 2. turned -- the joint that carries the part, when its axis passes through the part: through its middle for a\n body that rolls on it (the wrist roll, the tool flange, the gripper body), through its root for a link (the\n upper arm, the forearm);\n 3. otherwise none: the pedestal (the base's axis runs through it but turns it not), the fingers.\n An axis passing through a part is not enough by itself: the wrist roll's axis runs the forearm's length and the\n tool roll's through the wrist pitch, and neither turns them (an earlier rule said so, and was wrong).\n */\n if (!box) return null\n const carrierOf = (joint: string) => (node(`${joint}.chain`) ? `${joint}.chain` : `${joint}.attach`)\n const mine = node(`${part}.moved`)?.args.find(arg => /\\.(chain|attach)\\.value$/.test(arg))?.replace(/\\.value$/, '')\n const centre = AXIS_NAMES.map(a => box.centre[a])\n const half = AXIS_NAMES.map(a => box.extent[a] / 2)\n const joints = m.nodes\n .filter(n => n.op === 'axis-turn@1' && n.id.endsWith('.motion') && node(n.id.replace(/\\.motion$/, '.frameOnParent')))\n .map(motion => {\n const joint = motion.id.replace(/\\.motion$/, '')\n const carrier = carrierOf(joint)\n const frame = valueOf(node(carrier))\n const origin = valueOf(node(`${joint}.frameOnParent`))\n const local = axisOf(motion)\n if (!frame || !origin || !local) return null\n const at = apply(frame, origin.t)\n const along = norm([0, 1, 2].map(i => dot(frame.r[i]!, local)))\n if (!along) return null\n const off = sub(centre, at)\n return {\n joint,\n motion,\n carrier,\n origin,\n /* How deep the origin lies: 0 at the centre, 1 on the box's face, on the axis where it is shallowest. */\n depth: Math.max(...[0, 1, 2].map(i => Math.abs(off[i]!) / (half[i]! + SEAM))),\n fromCentre: Math.hypot(...off),\n through: lineMeetsBox(at, along, centre, half)\n }\n })\n .filter((c): c is NonNullable<typeof c> => !!c)\n const housing = joints.filter(c => c.depth <= HOUSED).sort((a, b) => a.fromCentre - b.fromCentre)[0]\n const carrying = joints.find(c => c.carrier === mine)\n const chosen = housing ?? (carrying && carrying.through ? carrying : undefined)\n if (!chosen) return null\n const axis = axisOf(chosen.motion)\n const control = controlOf(chosen.motion.args[3])\n if (!axis || !control) return null\n /* The reference edge points at what the joint turns: of the parts it carries, the one farthest off its axis. */\n const flatOff = (t: number[]) => {\n const rel = sub(t, chosen.origin.t)\n return Math.hypot(...sub(rel, axis.map(v => v * dot(rel, axis))))\n }\n const turned = m.nodes\n .filter(n => n.id.endsWith('.moved') && n.args.includes(`${chosen.carrier}.value`))\n .map(n => ({ id: n.id.replace(/\\.moved$/, ''), t: valueOf(node(n.id.replace(/\\.moved$/, '.pose')))?.t }))\n .filter((one): one is { id: string; t: number[] } => !!one.t)\n .sort((a, b) => flatOff(b.t) - flatOff(a.t))[0]\n return { carrier: chosen.carrier, pivot: chosen.origin.t, axis, toward: turned?.t ?? chosen.origin.t, control, turnedPart: turned?.id ?? part }\n}\n\n/**\n * The fan for the part, as a body to stand on the board, or null when the part does not turn. `values` are the\n * inputs the figure is drawn with now (a pose in hand included), so the fan follows the arm as it is posed.\n */\nexport function jointFanOf(asset: FigureAsset, part: string, values: Record<string, number> = {}): FigureRenderPart | null {\n if (!part) return null\n let graph: ReturnType<typeof compileFigureGraph>\n try {\n graph = compileFigureGraph(asset.document.model as never)\n } catch {\n return null\n }\n const inputs = { ...asset.designInputs, ...asset.stateDefaults, ...values }\n const at = (over: Record<string, number>) => graph.evaluate({ ...inputs, ...over }).values as Record<string, unknown>\n let now: Record<string, unknown>\n try {\n now = at({})\n } catch {\n return null\n }\n let box: WorldBox | undefined\n try {\n box = figureWorldBoxesOf(\n compileFigureAsset({ ...asset, designInputs: { ...asset.designInputs, ...pick(values, asset.designInputs) }, stateDefaults: { ...asset.stateDefaults, ...pick(values, asset.stateDefaults) } })\n .evaluate()\n .geometry.filter(g => g.id === part),\n figureWritersOf(asset)\n )[0]\n } catch {\n box = undefined\n }\n const turn = turnOf(asset, part, now, box)\n if (!turn) return null\n const carrierRef = Object.values(asset.document.model.nodes.find(n => n.id === turn.carrier)!.outputs)[0]!\n const carrierNow = now[carrierRef] as Pose | undefined\n if (!carrierNow) return null\n\n /* The reference edge points from the pivot toward the part, in the plane it turns in; any perpendicular if it sits on the axis. */\n const rel = sub(turn.toward, turn.pivot)\n const inPlane = sub(rel, turn.axis.map(v => v * dot(rel, turn.axis)))\n const d = norm(inPlane) ?? norm(cross(turn.axis, Math.abs(turn.axis[0]!) < 0.9 ? [1, 0, 0] : [0, 1, 0]))!\n /*\n Sized from what the joint turns, not from the selected part: selecting the elbow housing or the forearm\n shows the elbow's one fan, not a smaller one for the smaller part (user, 2026-09-24).\n */\n const radius = Math.max(60, Math.round(Math.max(largestMeasureOf(asset, turn.turnedPart, inputs), Math.hypot(...inPlane)) * 0.6))\n const edge = turn.pivot.map((v, i) => v + d[i]! * radius)\n\n const { min, max } = turn.control\n if (!(max > min)) return null\n const steps = Math.max(2, Math.ceil((max - min) / STEP_DEG))\n const pivot = apply(carrierNow, turn.pivot)\n const traced: number[][] = []\n try {\n for (let i = 0; i <= steps; i++) {\n const s = min + ((max - min) * i) / steps\n traced.push(apply(at({ [turn.control.id]: s })[carrierRef] as Pose, edge))\n }\n } catch {\n return null\n }\n\n /* The fan's own frame: x toward the first traced point, y along the axis as it stands now, z completing them. */\n const axisNow = norm([0, 1, 2].map(i => dot(carrierNow.r[i]!, turn.axis)))\n const first = norm(sub(traced[0]!, pivot))\n if (!axisNow || !first) return null\n const zAxis = cross(first, axisNow)\n const r = [0, 1, 2].map(i => [first[i]!, axisNow[i]!, zAxis[i]!])\n const local = (p: number[]) => {\n const v = sub(p, pivot)\n return { x: dot(v, first), y: dot(v, zAxis) }\n }\n const full = max - min >= 359.999\n const profile = [...(full ? [] : [{ x: 0, y: 0 }]), ...traced.map(local)].map(p => ({ x: Math.round(p.x * 1000) / 1000, y: Math.round(p.y * 1000) / 1000 }))\n\n return {\n id: JOINT_FAN,\n shape: { provider: 'polygon', dimensions: { height: THICKNESS }, profile },\n pose: { t: pivot, r },\n material: { token: '__joint-fan', transparent: true },\n /** Which control turns it: the joint the fan shows. */\n turns: turn.control.id\n } as unknown as FigureRenderPart\n}\n\n/** The values in hand that belong to a record's keys (design inputs, or state defaults). */\nfunction pick(values: Record<string, number>, of: Record<string, number>): Record<string, number> {\n return Object.fromEntries(Object.entries(values).filter(([id]) => id in of))\n}\n\n/** A part's largest own measure (a box side, a diameter, a length) at the inputs given; 0 when it cannot be read. */\nfunction largestMeasureOf(asset: FigureAsset, part: string, inputs: Record<string, number>): number {\n try {\n const body = compileFigureAsset({ ...asset, designInputs: pick(inputs, asset.designInputs), stateDefaults: pick(inputs, asset.stateDefaults) })\n .evaluate()\n .geometry.find(g => g.id === part) as { shape?: { dimensions?: Record<string, number> } } | undefined\n const dims = Object.entries(body?.shape?.dimensions ?? {}).map(([k, v]) => (k.startsWith('radius') ? v * 2 : v))\n return dims.length ? Math.max(...dims) : 0\n } catch {\n return 0\n }\n}\n\n/** Whether the line through `at` along `along` passes through the box (centre, half-measures), within the skin. */\nfunction lineMeetsBox(at: number[], along: number[], centre: number[], half: number[]): boolean {\n let lo = -Infinity,\n hi = Infinity\n for (let i = 0; i < 3; i++) {\n const min = centre[i]! - half[i]! - SEAM,\n max = centre[i]! + half[i]! + SEAM\n if (Math.abs(along[i]!) < 1e-12) {\n if (at[i]! < min || at[i]! > max) return false\n continue\n }\n const t1 = (min - at[i]!) / along[i]!,\n t2 = (max - at[i]!) / along[i]!\n lo = Math.max(lo, Math.min(t1, t2))\n hi = Math.min(hi, Math.max(t1, t2))\n if (lo > hi) return false\n }\n return true\n}\n\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type KeyAction = 'undo' | 'redo' | 'duplicate' | 'remove' | 'deselect' | GizmoKey;
|
|
2
|
+
/** The gizmo's modes on W, E and R, as the scene has them. */
|
|
3
|
+
export type GizmoKey = 'translate' | 'rotate' | 'scale';
|
|
4
|
+
export interface KeyLike {
|
|
5
|
+
key: string;
|
|
6
|
+
ctrlKey?: boolean;
|
|
7
|
+
metaKey?: boolean;
|
|
8
|
+
shiftKey?: boolean;
|
|
9
|
+
altKey?: boolean;
|
|
10
|
+
/** The element the key was pressed in -- the first of the event's composed path. */
|
|
11
|
+
target?: {
|
|
12
|
+
tagName?: string;
|
|
13
|
+
isContentEditable?: boolean;
|
|
14
|
+
} | null;
|
|
15
|
+
/**
|
|
16
|
+
* Pressed with the canvas focused. The scene takes W, E and R there itself; they are passed on only from elsewhere
|
|
17
|
+
* -- a part picked in the parts list left the focus there, and the gizmo could not be had at all (2026-09-25).
|
|
18
|
+
* Passing a key the scene already took would toggle the gizmo off again.
|
|
19
|
+
*/
|
|
20
|
+
inScene?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function keyActionOf(e: KeyLike, selected: string): KeyAction | null;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const GIZMO_KEYS = { w: 'translate', e: 'rotate', r: 'scale' };
|
|
2
|
+
const TYPING = new Set(['INPUT', 'SELECT', 'TEXTAREA']);
|
|
3
|
+
export function keyActionOf(e, selected) {
|
|
4
|
+
if (e.target && (TYPING.has(String(e.target.tagName).toUpperCase()) || e.target.isContentEditable))
|
|
5
|
+
return null;
|
|
6
|
+
if (e.altKey)
|
|
7
|
+
return null;
|
|
8
|
+
const mod = !!(e.ctrlKey || e.metaKey);
|
|
9
|
+
const key = e.key.toLowerCase();
|
|
10
|
+
if (mod && key === 'z')
|
|
11
|
+
return e.shiftKey ? 'redo' : 'undo';
|
|
12
|
+
if (mod && key === 'y')
|
|
13
|
+
return 'redo';
|
|
14
|
+
if (!selected)
|
|
15
|
+
return null;
|
|
16
|
+
if (mod && key === 'd')
|
|
17
|
+
return 'duplicate';
|
|
18
|
+
if (!mod && (key === 'delete' || key === 'backspace'))
|
|
19
|
+
return 'remove';
|
|
20
|
+
if (!mod && key === 'escape')
|
|
21
|
+
return 'deselect';
|
|
22
|
+
if (!mod && !e.shiftKey && !e.inScene && GIZMO_KEYS[key])
|
|
23
|
+
return GIZMO_KEYS[key];
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../client/modeller/keys.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,GAA6B,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,CAAA;AAkBxF,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAA;AAEvD,MAAM,U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the rule is tested without a browser.\n *\n * Typing is never taken: a key pressed in a field belongs to the field -- Backspace in a name box deletes a letter,\n * not the part.\n */\nexport type KeyAction = 'undo' | 'redo' | 'duplicate' | 'remove' | 'deselect' | GizmoKey\n\n/** The gizmo's modes on W, E and R, as the scene has them. */\nexport type GizmoKey = 'translate' | 'rotate' | 'scale'\nconst GIZMO_KEYS: Record<string, GizmoKey> = { w: 'translate', e: 'rotate', r: 'scale' }\n\nexport interface KeyLike {\n key: string\n ctrlKey?: boolean\n metaKey?: boolean\n shiftKey?: boolean\n altKey?: boolean\n /** The element the key was pressed in -- the first of the event's composed path. */\n target?: { tagName?: string; isContentEditable?: boolean } | null\n /**\n * Pressed with the canvas focused. The scene takes W, E and R there itself; they are passed on only from elsewhere\n * -- a part picked in the parts list left the focus there, and the gizmo could not be had at all (2026-09-25).\n * Passing a key the scene already took would toggle the gizmo off again.\n */\n inScene?: boolean\n}\n\nconst TYPING = new Set(['INPUT', 'SELECT', 'TEXTAREA'])\n\nexport function keyActionOf(e: KeyLike, selected: string): KeyAction | null {\n if (e.target && (TYPING.has(String(e.target.tagName).toUpperCase()) || e.target.isContentEditable)) return null\n if (e.altKey) return null\n const mod = !!(e.ctrlKey || e.metaKey)\n const key = e.key.toLowerCase()\n if (mod && key === 'z') return e.shiftKey ? 'redo' : 'undo'\n if (mod && key === 'y') return 'redo'\n if (!selected) return null\n if (mod && key === 'd') return 'duplicate'\n if (!mod && (key === 'delete' || key === 'backspace')) return 'remove'\n if (!mod && key === 'escape') return 'deselect'\n if (!mod && !e.shiftKey && !e.inScene && GIZMO_KEYS[key]) return GIZMO_KEYS[key]\n return null\n}\n"]}
|