|
| 1 | +/* |
| 2 | +Toolbox Aid |
| 3 | +David Quesenberry |
| 4 | +04/16/2026 |
| 5 | +panel3dTransformInspector.js |
| 6 | +*/ |
| 7 | + |
| 8 | +import { |
| 9 | + createPanelDescriptor, |
| 10 | + toLinePair |
| 11 | +} from "../shared/threeDDebugUtils.js"; |
| 12 | + |
| 13 | +export const PANEL_3D_TRANSFORM_INSPECTOR = "3d.transform"; |
| 14 | + |
| 15 | +function formatVector3(vector = {}, digits = 2) { |
| 16 | + const x = Number.isFinite(vector.x) ? Number(vector.x).toFixed(digits) : Number(0).toFixed(digits); |
| 17 | + const y = Number.isFinite(vector.y) ? Number(vector.y).toFixed(digits) : Number(0).toFixed(digits); |
| 18 | + const z = Number.isFinite(vector.z) ? Number(vector.z).toFixed(digits) : Number(0).toFixed(digits); |
| 19 | + return `${x},${y},${z}`; |
| 20 | +} |
| 21 | + |
| 22 | +function toNodeLine(node, index) { |
| 23 | + return toLinePair( |
| 24 | + `node.${index + 1}`, |
| 25 | + `${node.nodeId}|pos=${formatVector3(node.position)}|rot=${formatVector3(node.rotation)}|scale=${formatVector3(node.scale)}|dirty=${node.dirty === true}|frozen=${node.frozen === true}` |
| 26 | + ); |
| 27 | +} |
| 28 | + |
| 29 | +export function create3dTransformInspectorPanel(provider, options = {}) { |
| 30 | + return createPanelDescriptor({ |
| 31 | + id: PANEL_3D_TRANSFORM_INSPECTOR, |
| 32 | + title: "3D Transform Inspector", |
| 33 | + provider, |
| 34 | + priority: options.priority ?? 1100, |
| 35 | + enabled: options.enabled === true, |
| 36 | + linesBuilder(snapshot = {}) { |
| 37 | + const nodeRows = Array.isArray(snapshot.nodeRows) ? snapshot.nodeRows : []; |
| 38 | + const selectedIds = Array.isArray(snapshot.selectedIds) ? snapshot.selectedIds : []; |
| 39 | + const baseLines = [ |
| 40 | + toLinePair("nodeCount", snapshot.nodeCount), |
| 41 | + toLinePair("selectedCount", snapshot.selectedCount), |
| 42 | + toLinePair("dirtyCount", snapshot.dirtyCount), |
| 43 | + toLinePair("frozenCount", snapshot.frozenCount), |
| 44 | + toLinePair("activeNodeId", snapshot.activeNodeId) |
| 45 | + ]; |
| 46 | + |
| 47 | + if (nodeRows.length === 0) { |
| 48 | + return [ |
| 49 | + ...baseLines, |
| 50 | + toLinePair("selectedIds", selectedIds.length > 0 ? selectedIds.join(",") : "none"), |
| 51 | + toLinePair("nodes", "none") |
| 52 | + ]; |
| 53 | + } |
| 54 | + |
| 55 | + return [ |
| 56 | + ...baseLines, |
| 57 | + toLinePair("selectedIds", selectedIds.length > 0 ? selectedIds.join(",") : "none"), |
| 58 | + ...nodeRows.map((node, index) => toNodeLine(node, index)) |
| 59 | + ]; |
| 60 | + } |
| 61 | + }); |
| 62 | +} |
0 commit comments