@pascal-app/editor 1.0.0-beta.4 → 1.0.0
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/LICENSE +21 -0
- package/bunfig.toml +4 -0
- package/package.json +15 -8
- package/scripts/generate-print-golden-house.ts +89 -0
- package/src/components/editor/alignment-3d-guide-layer.tsx +12 -3
- package/src/components/editor/bake-exporter.tsx +1 -0
- package/src/components/editor/camera-dragging-lifecycle.test.ts +41 -0
- package/src/components/editor/camera-dragging-lifecycle.ts +10 -2
- package/src/components/editor/capture-camera-rig.tsx +59 -0
- package/src/components/editor/custom-camera-controls.tsx +20 -11
- package/src/components/editor/editor-layout-mobile.tsx +6 -6
- package/src/components/editor/editor-layout-v2.tsx +17 -5
- package/src/components/editor/elevation-3d-guide-layer.tsx +3 -2
- package/src/components/editor/export-manager.tsx +175 -33
- package/src/components/editor/first-person/build-collider-world.test.ts +30 -0
- package/src/components/editor/first-person-controls.tsx +182 -57
- package/src/components/editor/floating-action-menu.tsx +55 -55
- package/src/components/editor/floorplan-background-selection.test.ts +31 -4
- package/src/components/editor/floorplan-background-selection.ts +27 -7
- package/src/components/editor/floorplan-panel.tsx +81 -57
- package/src/components/editor/grid.tsx +12 -7
- package/src/components/editor/group-actions.ts +34 -50
- package/src/components/editor/group-floating-action-menu.tsx +30 -15
- package/src/components/editor/group-move-3d.ts +51 -21
- package/src/components/editor/group-transform-shared.test.ts +78 -0
- package/src/components/editor/group-transform-shared.ts +74 -7
- package/src/components/editor/handles/handle-arrow-raycast.test.ts +86 -0
- package/src/components/editor/handles/handle-arrow.tsx +109 -48
- package/src/components/editor/handles/linear-resize-drag.ts +67 -0
- package/src/components/editor/handles/resize-snap.test.ts +46 -0
- package/src/components/editor/handles/resize-snap.ts +10 -1
- package/src/components/editor/handles/use-handle-drag.ts +18 -1
- package/src/components/editor/index.tsx +252 -46
- package/src/components/editor/measurement-pill.tsx +12 -12
- package/src/components/editor/node-action-menu.tsx +42 -1
- package/src/components/editor/node-arrow-handles.tsx +47 -58
- package/src/components/editor/opening-guides-3d-layer.tsx +13 -4
- package/src/components/editor/selection-manager.tsx +132 -47
- package/src/components/editor/site-edge-labels.tsx +2 -1
- package/src/components/editor/snapshot-capture-overlay.tsx +309 -41
- package/src/components/editor/snapshot-capture.test.ts +422 -0
- package/src/components/editor/snapshot-capture.ts +145 -0
- package/src/components/editor/thumbnail-generator.tsx +295 -232
- package/src/components/editor/use-floorplan-background-placement.ts +53 -5
- package/src/components/editor/wall-measurement-label.tsx +3 -2
- package/src/components/editor/wall-move-side-handles.tsx +299 -7
- package/src/components/editor-2d/floorplan-group-action-menu.tsx +23 -16
- package/src/components/editor-2d/floorplan-group-move.tsx +67 -33
- package/src/components/editor-2d/floorplan-registered-tool-layer.tsx +3 -1
- package/src/components/editor-2d/floorplan-registry-move-overlay.tsx +129 -38
- package/src/components/editor-2d/renderers/floorplan-dimension-renderer.tsx +14 -1
- package/src/components/editor-2d/renderers/floorplan-geometry-renderer.test.tsx +16 -0
- package/src/components/editor-2d/renderers/floorplan-geometry-renderer.tsx +2 -0
- package/src/components/editor-2d/renderers/floorplan-placement-preview-layer.tsx +52 -3
- package/src/components/editor-2d/renderers/floorplan-registry-layer.test.ts +196 -1
- package/src/components/editor-2d/renderers/floorplan-registry-layer.tsx +204 -114
- package/src/components/systems/ceiling/ceiling-bracket-batch.test.ts +402 -0
- package/src/components/systems/ceiling/ceiling-bracket-batch.ts +371 -0
- package/src/components/systems/ceiling/ceiling-selection-affordance-system.test.ts +347 -0
- package/src/components/systems/ceiling/ceiling-selection-affordance-system.tsx +281 -305
- package/src/components/systems/roof/roof-edit-system.test.tsx +120 -0
- package/src/components/systems/roof/roof-edit-system.tsx +10 -19
- package/src/components/systems/selection-affordance-manager.tsx +59 -9
- package/src/components/systems/selection-affordance-services.ts +19 -0
- package/src/components/systems/stair/stair-edit-system.tsx +5 -2
- package/src/components/tools/fence/fence-drafting.test.ts +100 -0
- package/src/components/tools/fence/fence-drafting.ts +6 -25
- package/src/components/tools/item/draft-creation.test.ts +12 -0
- package/src/components/tools/item/draft-creation.ts +10 -0
- package/src/components/tools/item/face-host-commit.test.ts +65 -0
- package/src/components/tools/item/face-host-commit.ts +56 -0
- package/src/components/tools/item/face-host-preview.test.ts +77 -0
- package/src/components/tools/item/face-host-preview.ts +82 -0
- package/src/components/tools/item/move-tool.tsx +4 -3
- package/src/components/tools/item/placement-math.test.ts +11 -1
- package/src/components/tools/item/placement-math.ts +0 -20
- package/src/components/tools/item/placement-strategies.test.ts +494 -0
- package/src/components/tools/item/placement-strategies.ts +192 -24
- package/src/components/tools/item/placement-surface.test.ts +61 -0
- package/src/components/tools/item/placement-surface.ts +24 -0
- package/src/components/tools/item/placement-types.ts +6 -0
- package/src/components/tools/item/test-face-host.ts +121 -0
- package/src/components/tools/item/use-draft-node.test.tsx +336 -0
- package/src/components/tools/item/use-draft-node.ts +26 -4
- package/src/components/tools/item/use-placement-coordinator.tsx +447 -180
- package/src/components/tools/registered-tool-install-lifecycle.test.tsx +256 -0
- package/src/components/tools/registry/move-registry-node-tool.test.ts +10 -0
- package/src/components/tools/registry/move-registry-node-tool.tsx +306 -110
- package/src/components/tools/registry-tool-context.tsx +30 -0
- package/src/components/tools/select/box-select-tool.tsx +3 -1
- package/src/components/tools/select/marquee-footprint.test.ts +53 -0
- package/src/components/tools/select/marquee-footprint.ts +29 -0
- package/src/components/tools/shared/placement-box.tsx +63 -8
- package/src/components/tools/shared/placement-dimension-guides.tsx +121 -0
- package/src/components/tools/shared/pointer-support-cap.test.ts +319 -17
- package/src/components/tools/shared/pointer-support-cap.ts +45 -8
- package/src/components/tools/site/terrain-brush-cursor.tsx +2 -1
- package/src/components/tools/site/terrain-sculpt-grid.tsx +9 -5
- package/src/components/tools/site/terrain-sculpt-tool.tsx +1 -1
- package/src/components/tools/stair/stair-tool.tsx +127 -74
- package/src/components/tools/tool-manager.tsx +25 -8
- package/src/components/tools/wall/wall-drafting.test.ts +527 -4
- package/src/components/tools/wall/wall-drafting.ts +55 -462
- package/src/components/ui/action-menu/control-modes.tsx +9 -6
- package/src/components/ui/action-menu/index.tsx +11 -1
- package/src/components/ui/command-palette/editor-commands.tsx +12 -13
- package/src/components/ui/command-palette/index.tsx +7 -2
- package/src/components/ui/controls/material-paint-panel.tsx +6 -4
- package/src/components/ui/controls/material-picker.tsx +4 -4
- package/src/components/ui/controls/scene-material-list.tsx +6 -5
- package/src/components/ui/controls/segmented-control.tsx +8 -1
- package/src/components/ui/controls/slider-control.tsx +19 -3
- package/src/components/ui/controls/toggle-control.tsx +18 -5
- package/src/components/ui/controls/tool-options-panel.tsx +126 -0
- package/src/components/ui/floating-level-selector.tsx +23 -6
- package/src/components/ui/helpers/contextual-helper-panel.tsx +9 -0
- package/src/components/ui/helpers/helper-manager.tsx +47 -11
- package/src/components/ui/helpers/item-helper.tsx +1 -1
- package/src/components/ui/helpers/registered-tool-helper.tsx +21 -0
- package/src/components/ui/panels/homogeneous-selection.test.ts +80 -0
- package/src/components/ui/panels/homogeneous-selection.ts +47 -0
- package/src/components/ui/panels/mobile-selection-bar.tsx +11 -5
- package/src/components/ui/panels/multi-field-value.test.ts +209 -0
- package/src/components/ui/panels/multi-field-value.ts +163 -0
- package/src/components/ui/panels/multi-height-mode.tsx +185 -0
- package/src/components/ui/panels/multi-parametric-inspector.tsx +263 -0
- package/src/components/ui/panels/multi-selection-panel.tsx +78 -26
- package/src/components/ui/panels/node-display.ts +4 -0
- package/src/components/ui/panels/panel-manager.tsx +77 -3
- package/src/components/ui/panels/panel-wrapper.tsx +228 -12
- package/src/components/ui/panels/parametric-field-control.tsx +173 -0
- package/src/components/ui/panels/parametric-field-utils.ts +18 -0
- package/src/components/ui/panels/parametric-inspector.tsx +29 -162
- package/src/components/ui/panels/reference-panel.tsx +31 -1
- package/src/components/ui/primitives/shortcut-token.tsx +23 -1
- package/src/components/ui/scene-loader.tsx +35 -0
- package/src/components/ui/sidebar/panels/items-panel/function-tree-panel.tsx +7 -2
- package/src/components/ui/sidebar/panels/settings-panel/index.tsx +390 -36
- package/src/components/ui/sidebar/panels/settings-panel/keyboard-shortcuts-dialog.tsx +31 -23
- package/src/components/ui/sidebar/panels/settings-panel/print-export-button.test.ts +140 -0
- package/src/components/ui/sidebar/panels/settings-panel/print-export-button.tsx +109 -0
- package/src/components/ui/sidebar/panels/site-panel/dormer-tree-node.tsx +19 -5
- package/src/components/ui/sidebar/panels/site-panel/index.tsx +128 -46
- package/src/components/ui/sidebar/panels/site-panel/level-tree-node.tsx +5 -2
- package/src/components/ui/sidebar/panels/site-panel/registry-tree-node.tsx +28 -11
- package/src/components/ui/sidebar/panels/site-panel/tree-node.test.ts +8 -0
- package/src/components/ui/sidebar/panels/site-panel/tree-node.tsx +22 -7
- package/src/components/ui/sidebar/tab-bar.tsx +9 -1
- package/src/components/ui/sidebar/use-plugin-panels.tsx +17 -2
- package/src/components/viewer/floorplan-compass-button.tsx +50 -0
- package/src/components/viewer/floorplan-preview-geometry.test.ts +107 -0
- package/src/components/viewer/floorplan-preview-geometry.ts +281 -0
- package/src/components/viewer/floorplan-preview-navigation.test.ts +43 -0
- package/src/components/viewer/floorplan-preview-navigation.ts +62 -0
- package/src/components/viewer/floorplan-preview.tsx +1069 -0
- package/src/components/viewer/use-viewer-camera-navigation-sync.ts +140 -0
- package/src/components/viewer/viewer-scene-header.tsx +2 -1
- package/src/components/viewer/viewer-stage-modes.test.ts +38 -0
- package/src/components/viewer/viewer-stage-modes.ts +49 -0
- package/src/components/viewer/viewer-stage-switcher.tsx +95 -0
- package/src/components/viewer/viewer-stage.test.tsx +47 -0
- package/src/components/viewer/viewer-stage.tsx +221 -0
- package/src/components/viewer-overlay.tsx +13 -30
- package/src/components/viewer-zone-system.tsx +6 -2
- package/src/components/walkthrough-hud.tsx +19 -10
- package/src/hooks/use-auto-save.test.ts +122 -1
- package/src/hooks/use-auto-save.ts +119 -13
- package/src/hooks/use-ceiling-events.test.ts +122 -0
- package/src/hooks/use-drag-action.ts +17 -3
- package/src/hooks/use-grid-events.test.ts +240 -0
- package/src/hooks/use-grid-events.ts +190 -11
- package/src/hooks/use-keyboard.test.ts +244 -0
- package/src/hooks/use-keyboard.ts +164 -63
- package/src/hooks/use-registered-tool-enabled.ts +20 -0
- package/src/hooks/use-save-shortcut.ts +33 -0
- package/src/index.tsx +109 -4
- package/src/lib/active-placement-surface.test.ts +16 -0
- package/src/lib/active-placement-surface.ts +14 -0
- package/src/lib/ceiling-surface-raycast.test.ts +64 -0
- package/src/lib/ceiling-surface-raycast.ts +12 -0
- package/src/lib/contextual-help-extension.ts +17 -0
- package/src/lib/contextual-help.test.ts +8 -0
- package/src/lib/contextual-help.ts +8 -0
- package/src/lib/continuation.test.ts +11 -0
- package/src/lib/continuation.ts +8 -1
- package/src/lib/direct-manipulation.test.ts +132 -0
- package/src/lib/direct-manipulation.ts +38 -1
- package/src/lib/editor-api.ts +6 -3
- package/src/lib/elevation-guides.test.ts +28 -1
- package/src/lib/elevation-guides.ts +22 -7
- package/src/lib/floating-menu-scale.test.ts +29 -0
- package/src/lib/floating-menu-scale.ts +14 -0
- package/src/lib/floorplan/apply-alignment.test.ts +47 -2
- package/src/lib/floorplan/apply-alignment.ts +10 -1
- package/src/lib/floorplan/floorplan-export.test.ts +397 -1
- package/src/lib/floorplan/floorplan-export.tsx +111 -16
- package/src/lib/floorplan/floorplan-pdfkit-renderer.test.ts +26 -0
- package/src/lib/floorplan/floorplan-pdfkit-renderer.ts +32 -24
- package/src/lib/floorplan/floorplan-readonly.test.ts +47 -0
- package/src/lib/floorplan/floorplan-readonly.ts +85 -0
- package/src/lib/floorplan-grid-event-point.test.ts +29 -0
- package/src/lib/floorplan-grid-event-point.ts +13 -0
- package/src/lib/glb-export.test.ts +1169 -21
- package/src/lib/glb-export.ts +629 -101
- package/src/lib/grid-event-presentation.ts +16 -0
- package/src/lib/history.test.ts +523 -77
- package/src/lib/history.ts +133 -14
- package/src/lib/host-tree-children.test.ts +27 -0
- package/src/lib/host-tree-children.ts +79 -0
- package/src/lib/inspector-card-mode.test.ts +92 -0
- package/src/lib/inspector-card-mode.ts +60 -0
- package/src/lib/interaction/hot-set.test.ts +10 -1
- package/src/lib/interaction/hot-set.ts +3 -1
- package/src/lib/interaction/overlay-policy.test.ts +33 -1
- package/src/lib/interaction/overlay-policy.ts +16 -0
- package/src/lib/interaction/registered-drafting.ts +36 -0
- package/src/lib/interaction/scope.ts +31 -0
- package/src/lib/level-print-export.test.ts +484 -0
- package/src/lib/level-print-export.ts +526 -0
- package/src/lib/local-project-presentation-persistence.test.ts +302 -0
- package/src/lib/local-project-presentation-persistence.ts +335 -0
- package/src/lib/material-paint.ts +2 -0
- package/src/lib/measurement-parser.ts +3 -0
- package/src/lib/measurements.test.ts +4 -0
- package/src/lib/model-export.ts +29 -0
- package/src/lib/paint-preview-owner.ts +71 -0
- package/src/lib/paint-scope.test.ts +58 -2
- package/src/lib/paint-scope.ts +8 -2
- package/src/lib/planar-cursor-placement.test.ts +178 -1
- package/src/lib/planar-cursor-placement.ts +61 -5
- package/src/lib/plugin-panels.test.ts +92 -1
- package/src/lib/plugin-panels.ts +48 -0
- package/src/lib/portable-export.test.ts +366 -0
- package/src/lib/portable-export.ts +969 -0
- package/src/lib/print-3mf.test.ts +86 -0
- package/src/lib/print-3mf.ts +161 -0
- package/src/lib/print-content-scope.test.ts +107 -0
- package/src/lib/print-content-scope.ts +90 -0
- package/src/lib/print-export.test.ts +294 -0
- package/src/lib/print-export.ts +735 -0
- package/src/lib/print-feature-thickness.test.ts +147 -0
- package/src/lib/print-feature-thickness.ts +180 -0
- package/src/lib/print-golden-house.test-fixture.ts +352 -0
- package/src/lib/print-golden-house.test.ts +249 -0
- package/src/lib/print-roof-solids.test.ts +133 -0
- package/src/lib/print-roof-solids.ts +630 -0
- package/src/lib/print-shell-compiler-baseline.test.ts +419 -0
- package/src/lib/print-shell-compiler-baseline.ts +225 -0
- package/src/lib/print-shell-compiler-manifold-core.ts +330 -0
- package/src/lib/print-shell-compiler-manifold-worker.ts +187 -0
- package/src/lib/print-shell-compiler-manifold.worker.ts +20 -0
- package/src/lib/print-shell-compiler-mesh-data.ts +32 -0
- package/src/lib/print-shell-compiler-protocol.ts +30 -0
- package/src/lib/print-shell-compiler.ts +273 -0
- package/src/lib/print-wall-solids.test.ts +194 -0
- package/src/lib/print-wall-solids.ts +328 -0
- package/src/lib/rigid-plan-svg-transform.test.ts +35 -0
- package/src/lib/rigid-plan-svg-transform.ts +24 -0
- package/src/lib/scene.ts +22 -8
- package/src/lib/selection-routing.test.ts +125 -6
- package/src/lib/selection-routing.ts +34 -1
- package/src/lib/session-groups.test.ts +88 -0
- package/src/lib/session-groups.ts +201 -0
- package/src/lib/sfx-bus.ts +4 -0
- package/src/lib/sfx-player.ts +8 -0
- package/src/lib/snapping-mode.test.ts +32 -4
- package/src/lib/snapping-mode.ts +11 -7
- package/src/lib/structured-clone-fallback.test.ts +45 -0
- package/src/lib/structured-clone-fallback.ts +24 -0
- package/src/lib/usdz-export.ts +38 -0
- package/src/lib/walkthrough-pointer-lock.ts +47 -0
- package/src/store/live-draft-preview-stores.test.ts +3 -0
- package/src/store/terrain-sculpt-mode.test.ts +3 -6
- package/src/store/tool-mode.test.ts +87 -0
- package/src/store/use-camera-hint-focus.ts +48 -0
- package/src/store/use-editor.tsx +299 -188
- package/src/store/use-floorplan-draft-preview.ts +9 -0
- package/src/store/use-interaction-scope.test.ts +23 -1
- package/src/store/use-interaction-scope.ts +63 -2
- package/src/store/use-placement-preview.ts +56 -3
- package/src/store/use-session-groups.ts +103 -0
- package/src/components/tools/roof/roof-tool.tsx +0 -656
- package/src/components/ui/helpers/roof-helper.tsx +0 -14
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AnyNode,
|
|
3
|
+
getWallEffectiveHeightForNodes,
|
|
4
|
+
type RoofSegmentNode,
|
|
5
|
+
resolveLevelId,
|
|
6
|
+
spatialGridManager,
|
|
7
|
+
type WallNode,
|
|
8
|
+
} from '@pascal-app/core'
|
|
9
|
+
import { disposeObject3DResources } from '@pascal-app/viewer'
|
|
10
|
+
import * as THREE from 'three'
|
|
11
|
+
import { buildPrintableRoofSegmentSolids } from './print-roof-solids'
|
|
12
|
+
import {
|
|
13
|
+
compilePrintShellBaseline,
|
|
14
|
+
type PrintShellCompileDiagnostic,
|
|
15
|
+
type PrintShellCompileResult,
|
|
16
|
+
} from './print-shell-compiler-baseline'
|
|
17
|
+
import { buildPrintableWallSolids } from './print-wall-solids'
|
|
18
|
+
|
|
19
|
+
export type SemanticPrintCompileOptions = {
|
|
20
|
+
wallSolids?: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type SemanticPrintSourceResult =
|
|
24
|
+
| {
|
|
25
|
+
status: 'ready'
|
|
26
|
+
scene: THREE.Object3D
|
|
27
|
+
diagnostics: []
|
|
28
|
+
dispose: () => void
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
status: 'blocked'
|
|
32
|
+
scene: null
|
|
33
|
+
inputMeshCount: number
|
|
34
|
+
sourceNodeIds: string[]
|
|
35
|
+
diagnostics: PrintShellCompileDiagnostic[]
|
|
36
|
+
dispose: () => void
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function meshCount(root: THREE.Object3D): number {
|
|
40
|
+
let count = 0
|
|
41
|
+
root.traverse((object) => {
|
|
42
|
+
const mesh = object as THREE.Mesh
|
|
43
|
+
const position = mesh.isMesh ? mesh.geometry?.getAttribute('position') : null
|
|
44
|
+
if (position && position.count > 0) count += 1
|
|
45
|
+
})
|
|
46
|
+
return count
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function replaceChild(parent: THREE.Object3D, target: THREE.Object3D, replacement: THREE.Object3D) {
|
|
50
|
+
const targetIndex = parent.children.indexOf(target)
|
|
51
|
+
parent.remove(target)
|
|
52
|
+
parent.add(replacement)
|
|
53
|
+
const appendedIndex = parent.children.indexOf(replacement)
|
|
54
|
+
parent.children.splice(appendedIndex, 1)
|
|
55
|
+
parent.children.splice(targetIndex, 0, replacement)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function copyPreparedTransform(
|
|
59
|
+
source: THREE.Object3D,
|
|
60
|
+
target: THREE.Object3D,
|
|
61
|
+
printSource: 'canonical-roof' | 'canonical-wall',
|
|
62
|
+
) {
|
|
63
|
+
target.name = source.name
|
|
64
|
+
target.position.copy(source.position)
|
|
65
|
+
target.quaternion.copy(source.quaternion)
|
|
66
|
+
target.scale.copy(source.scale)
|
|
67
|
+
target.matrix.copy(source.matrix)
|
|
68
|
+
target.matrixAutoUpdate = source.matrixAutoUpdate
|
|
69
|
+
target.visible = source.visible
|
|
70
|
+
target.layers.mask = source.layers.mask
|
|
71
|
+
target.userData = { ...source.userData, printSource }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function disposeGenerated(root: THREE.Object3D) {
|
|
75
|
+
disposeObject3DResources(root)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function exportedIdentityIds(root: THREE.Object3D): Set<string> {
|
|
79
|
+
const ids = new Set<string>()
|
|
80
|
+
root.traverse((object) => {
|
|
81
|
+
if (typeof object.userData.pascalId === 'string') ids.add(object.userData.pascalId)
|
|
82
|
+
})
|
|
83
|
+
return ids
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function ownedLocalYBounds(root: THREE.Object3D): { min: number; max: number } | null {
|
|
87
|
+
root.updateMatrixWorld(true)
|
|
88
|
+
const inverseRoot = root.matrixWorld.clone().invert()
|
|
89
|
+
const point = new THREE.Vector3()
|
|
90
|
+
let min = Number.POSITIVE_INFINITY
|
|
91
|
+
let max = Number.NEGATIVE_INFINITY
|
|
92
|
+
|
|
93
|
+
const visit = (object: THREE.Object3D) => {
|
|
94
|
+
if (
|
|
95
|
+
object !== root &&
|
|
96
|
+
typeof object.userData.pascalId === 'string' &&
|
|
97
|
+
object.userData.pascalId !== root.userData.pascalId
|
|
98
|
+
) {
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
const mesh = object as THREE.Mesh
|
|
102
|
+
const position = mesh.isMesh ? mesh.geometry.getAttribute('position') : null
|
|
103
|
+
if (position) {
|
|
104
|
+
const toRoot = inverseRoot.clone().multiply(object.matrixWorld)
|
|
105
|
+
for (let index = 0; index < position.count; index += 1) {
|
|
106
|
+
point.fromBufferAttribute(position, index).applyMatrix4(toRoot)
|
|
107
|
+
min = Math.min(min, point.y)
|
|
108
|
+
max = Math.max(max, point.y)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (const child of object.children) visit(child)
|
|
112
|
+
}
|
|
113
|
+
visit(root)
|
|
114
|
+
return Number.isFinite(min) && Number.isFinite(max) ? { min, max } : null
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function preparedWallHeight(
|
|
118
|
+
node: WallNode,
|
|
119
|
+
object: THREE.Object3D,
|
|
120
|
+
nodes: Record<string, AnyNode>,
|
|
121
|
+
):
|
|
122
|
+
| { height: number; diagnostic: null }
|
|
123
|
+
| { height: null; diagnostic: PrintShellCompileDiagnostic } {
|
|
124
|
+
const levelId = resolveLevelId(node, nodes)
|
|
125
|
+
const support = spatialGridManager.getSlabSupportForWall(
|
|
126
|
+
levelId,
|
|
127
|
+
node.start,
|
|
128
|
+
node.end,
|
|
129
|
+
node.curveOffset ?? 0,
|
|
130
|
+
node.thickness,
|
|
131
|
+
node.supportSlabId ?? null,
|
|
132
|
+
undefined,
|
|
133
|
+
node.supportOffset,
|
|
134
|
+
)
|
|
135
|
+
const hasDisplacedBase =
|
|
136
|
+
Math.abs(support.baseElevation - support.elevation) > 1e-5 ||
|
|
137
|
+
support.baseSegments.some((segment) => Math.abs(segment.elevation - support.elevation) > 1e-5)
|
|
138
|
+
const bounds = ownedLocalYBounds(object)
|
|
139
|
+
if (hasDisplacedBase || (bounds && bounds.max > 1e-7 && Math.abs(bounds.min) > 1e-5)) {
|
|
140
|
+
return {
|
|
141
|
+
height: null,
|
|
142
|
+
diagnostic: {
|
|
143
|
+
severity: 'error',
|
|
144
|
+
code: 'unsupported_wall_print_base',
|
|
145
|
+
message: `Wall ${node.id} has a stepped or displaced local base that does not yet have a canonical printable solid.`,
|
|
146
|
+
nodeIds: [node.id],
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const height = getWallEffectiveHeightForNodes(node, nodes)
|
|
152
|
+
if (!Number.isFinite(height) || height <= 1e-7) {
|
|
153
|
+
return {
|
|
154
|
+
height: null,
|
|
155
|
+
diagnostic: {
|
|
156
|
+
severity: 'error',
|
|
157
|
+
code: 'invalid_wall_print_dimensions',
|
|
158
|
+
message: `Wall ${node.id} has no finite semantic height for print compilation.`,
|
|
159
|
+
nodeIds: [node.id],
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return { height, diagnostic: null }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function prepareSemanticPrintShellSource(
|
|
167
|
+
source: THREE.Object3D,
|
|
168
|
+
nodes: Record<string, AnyNode>,
|
|
169
|
+
options: SemanticPrintCompileOptions = {},
|
|
170
|
+
): SemanticPrintSourceResult {
|
|
171
|
+
const scene = new THREE.Group()
|
|
172
|
+
scene.name = 'semantic-print-source'
|
|
173
|
+
scene.add(source.clone(true))
|
|
174
|
+
|
|
175
|
+
const includedNodeIds = exportedIdentityIds(scene)
|
|
176
|
+
const roofTargets: { node: RoofSegmentNode; object: THREE.Object3D }[] = []
|
|
177
|
+
const wallTargets: { node: WallNode; object: THREE.Object3D }[] = []
|
|
178
|
+
scene.traverse((object) => {
|
|
179
|
+
const id = object.userData.pascalId
|
|
180
|
+
const node = typeof id === 'string' ? nodes[id] : undefined
|
|
181
|
+
if (node?.type === 'roof-segment') roofTargets.push({ node, object })
|
|
182
|
+
if (options.wallSolids && node?.type === 'wall') wallTargets.push({ node, object })
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
const diagnostics: PrintShellCompileDiagnostic[] = []
|
|
186
|
+
const replacements: { target: THREE.Object3D; replacement: THREE.Group }[] = []
|
|
187
|
+
for (const { node, object } of roofTargets) {
|
|
188
|
+
const result = buildPrintableRoofSegmentSolids(node, nodes)
|
|
189
|
+
if (result.status === 'blocked') {
|
|
190
|
+
diagnostics.push(...result.diagnostics)
|
|
191
|
+
continue
|
|
192
|
+
}
|
|
193
|
+
copyPreparedTransform(object, result.object, 'canonical-roof')
|
|
194
|
+
replacements.push({ target: object, replacement: result.object })
|
|
195
|
+
}
|
|
196
|
+
for (const { node, object } of wallTargets) {
|
|
197
|
+
const prepared = preparedWallHeight(node, object, nodes)
|
|
198
|
+
if (prepared.diagnostic) {
|
|
199
|
+
diagnostics.push(prepared.diagnostic)
|
|
200
|
+
continue
|
|
201
|
+
}
|
|
202
|
+
const result = buildPrintableWallSolids(
|
|
203
|
+
node,
|
|
204
|
+
{ effectiveHeight: prepared.height, includedNodeIds },
|
|
205
|
+
nodes,
|
|
206
|
+
)
|
|
207
|
+
if (result.status === 'blocked') {
|
|
208
|
+
diagnostics.push(...result.diagnostics)
|
|
209
|
+
continue
|
|
210
|
+
}
|
|
211
|
+
copyPreparedTransform(object, result.object, 'canonical-wall')
|
|
212
|
+
replacements.push({ target: object, replacement: result.object })
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (diagnostics.length > 0) {
|
|
216
|
+
for (const { replacement } of replacements) disposeGenerated(replacement)
|
|
217
|
+
return {
|
|
218
|
+
status: 'blocked',
|
|
219
|
+
scene: null,
|
|
220
|
+
inputMeshCount: meshCount(scene),
|
|
221
|
+
sourceNodeIds: Array.from(
|
|
222
|
+
new Set(diagnostics.flatMap((diagnostic) => diagnostic.nodeIds)),
|
|
223
|
+
).sort(),
|
|
224
|
+
diagnostics,
|
|
225
|
+
dispose: () => {},
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
for (const { target, replacement } of replacements) {
|
|
230
|
+
if (target.parent) replaceChild(target.parent, target, replacement)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
let disposed = false
|
|
234
|
+
return {
|
|
235
|
+
status: 'ready',
|
|
236
|
+
scene,
|
|
237
|
+
diagnostics: [],
|
|
238
|
+
dispose: () => {
|
|
239
|
+
if (disposed) return
|
|
240
|
+
disposed = true
|
|
241
|
+
for (const { replacement } of replacements) disposeGenerated(replacement)
|
|
242
|
+
},
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Compiles a semantic structural source instead of trusting display aggregates.
|
|
248
|
+
* Roof segments are replaced as complete identity subtrees so their hosted
|
|
249
|
+
* display CSG and accessory meshes cannot leak into the manufacturing shell.
|
|
250
|
+
*/
|
|
251
|
+
export function compileSemanticPrintShell(
|
|
252
|
+
source: THREE.Object3D,
|
|
253
|
+
nodes: Record<string, AnyNode>,
|
|
254
|
+
options: SemanticPrintCompileOptions = {},
|
|
255
|
+
): PrintShellCompileResult {
|
|
256
|
+
const prepared = prepareSemanticPrintShellSource(source, nodes, options)
|
|
257
|
+
if (prepared.status === 'blocked') {
|
|
258
|
+
return {
|
|
259
|
+
backend: 'pascal-three-bvh-csg',
|
|
260
|
+
status: 'blocked',
|
|
261
|
+
scene: null,
|
|
262
|
+
inputMeshCount: prepared.inputMeshCount,
|
|
263
|
+
sourceNodeIds: prepared.sourceNodeIds,
|
|
264
|
+
diagnostics: prepared.diagnostics,
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
return compilePrintShellBaseline(prepared.scene)
|
|
270
|
+
} finally {
|
|
271
|
+
prepared.dispose()
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { DoorNode, WallNode, WindowNode } from '@pascal-app/core'
|
|
3
|
+
import * as THREE from 'three'
|
|
4
|
+
import { buildPrintableWallSolids } from './print-wall-solids'
|
|
5
|
+
|
|
6
|
+
function rayIntersectionCount(root: THREE.Object3D, x: number, y: number): number {
|
|
7
|
+
root.updateMatrixWorld(true)
|
|
8
|
+
const raycaster = new THREE.Raycaster(new THREE.Vector3(x, y, -1), new THREE.Vector3(0, 0, 1))
|
|
9
|
+
const material = new THREE.MeshBasicMaterial({ side: THREE.DoubleSide })
|
|
10
|
+
let count = 0
|
|
11
|
+
root.traverse((object) => {
|
|
12
|
+
const mesh = object as THREE.Mesh
|
|
13
|
+
if (!mesh.isMesh) return
|
|
14
|
+
const originalMaterial = mesh.material
|
|
15
|
+
mesh.material = material
|
|
16
|
+
count += raycaster.intersectObject(mesh, false).length
|
|
17
|
+
mesh.material = originalMaterial
|
|
18
|
+
})
|
|
19
|
+
material.dispose()
|
|
20
|
+
return count
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function expectClosedBoxMeshes(root: THREE.Group) {
|
|
24
|
+
for (const object of root.children) {
|
|
25
|
+
const mesh = object as THREE.Mesh
|
|
26
|
+
expect(mesh.isMesh).toBe(true)
|
|
27
|
+
const index = mesh.geometry.getIndex()
|
|
28
|
+
expect(index).not.toBeNull()
|
|
29
|
+
const edges = new Map<string, number>()
|
|
30
|
+
const add = (a: number, b: number) => {
|
|
31
|
+
const key = a < b ? `${a}|${b}` : `${b}|${a}`
|
|
32
|
+
edges.set(key, (edges.get(key) ?? 0) + 1)
|
|
33
|
+
}
|
|
34
|
+
for (let offset = 0; offset + 2 < index!.count; offset += 3) {
|
|
35
|
+
const a = index!.getX(offset)
|
|
36
|
+
const b = index!.getX(offset + 1)
|
|
37
|
+
const c = index!.getX(offset + 2)
|
|
38
|
+
add(a, b)
|
|
39
|
+
add(b, c)
|
|
40
|
+
add(c, a)
|
|
41
|
+
}
|
|
42
|
+
expect(Array.from(edges.values()).every((uses) => uses === 2)).toBe(true)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function dispose(root: THREE.Group) {
|
|
47
|
+
root.traverse((object) => {
|
|
48
|
+
const mesh = object as THREE.Mesh
|
|
49
|
+
if (mesh.isMesh) mesh.geometry.dispose()
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe('buildPrintableWallSolids', () => {
|
|
54
|
+
test('builds deterministic closed solids around rectangular door and window voids', () => {
|
|
55
|
+
const door = DoorNode.parse({
|
|
56
|
+
id: 'door_print-wall',
|
|
57
|
+
wallId: 'wall_print-openings',
|
|
58
|
+
position: [1.5, 1.05, 0],
|
|
59
|
+
width: 0.9,
|
|
60
|
+
height: 2.1,
|
|
61
|
+
})
|
|
62
|
+
const window = WindowNode.parse({
|
|
63
|
+
id: 'window_print-wall',
|
|
64
|
+
wallId: 'wall_print-openings',
|
|
65
|
+
position: [4.5, 1.4, 0],
|
|
66
|
+
width: 1.2,
|
|
67
|
+
height: 1.0,
|
|
68
|
+
})
|
|
69
|
+
const wall = WallNode.parse({
|
|
70
|
+
id: 'wall_print-openings',
|
|
71
|
+
start: [0, 0],
|
|
72
|
+
end: [6, 0],
|
|
73
|
+
height: 2.5,
|
|
74
|
+
thickness: 0.2,
|
|
75
|
+
children: [door.id, window.id],
|
|
76
|
+
})
|
|
77
|
+
const nodes = { [door.id]: door, [window.id]: window }
|
|
78
|
+
const first = buildPrintableWallSolids(wall, { effectiveHeight: 2.5 }, nodes)
|
|
79
|
+
const second = buildPrintableWallSolids(wall, { effectiveHeight: 2.5 }, nodes)
|
|
80
|
+
|
|
81
|
+
expect(first.status).toBe('ready')
|
|
82
|
+
expect(second.status).toBe('ready')
|
|
83
|
+
expect(first.object).not.toBeNull()
|
|
84
|
+
expect(second.object).not.toBeNull()
|
|
85
|
+
expect(first.object!.userData.pascalId).toBe(wall.id)
|
|
86
|
+
expectClosedBoxMeshes(first.object!)
|
|
87
|
+
|
|
88
|
+
const bounds = new THREE.Box3().setFromObject(first.object!)
|
|
89
|
+
expect(bounds.min.x).toBeCloseTo(0, 6)
|
|
90
|
+
expect(bounds.min.y).toBeCloseTo(0, 6)
|
|
91
|
+
expect(bounds.min.z).toBeCloseTo(-0.1, 6)
|
|
92
|
+
expect(bounds.max.x).toBeCloseTo(6, 6)
|
|
93
|
+
expect(bounds.max.y).toBeCloseTo(2.5, 6)
|
|
94
|
+
expect(bounds.max.z).toBeCloseTo(0.1, 6)
|
|
95
|
+
expect(rayIntersectionCount(first.object!, 1.5, 1)).toBe(0)
|
|
96
|
+
expect(rayIntersectionCount(first.object!, 4.5, 1.4)).toBe(0)
|
|
97
|
+
expect(rayIntersectionCount(first.object!, 3, 1)).toBeGreaterThanOrEqual(2)
|
|
98
|
+
|
|
99
|
+
expect(first.object!.children.map((child) => child.position.toArray())).toEqual(
|
|
100
|
+
second.object!.children.map((child) => child.position.toArray()),
|
|
101
|
+
)
|
|
102
|
+
expect(
|
|
103
|
+
first.object!.children.map((child) =>
|
|
104
|
+
Array.from((child as THREE.Mesh).geometry.getAttribute('position').array),
|
|
105
|
+
),
|
|
106
|
+
).toEqual(
|
|
107
|
+
second.object!.children.map((child) =>
|
|
108
|
+
Array.from((child as THREE.Mesh).geometry.getAttribute('position').array),
|
|
109
|
+
),
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
const hiddenOpenings = buildPrintableWallSolids(
|
|
113
|
+
wall,
|
|
114
|
+
{ effectiveHeight: 2.5, includedNodeIds: new Set() },
|
|
115
|
+
nodes,
|
|
116
|
+
)
|
|
117
|
+
expect(hiddenOpenings.status).toBe('ready')
|
|
118
|
+
expect(rayIntersectionCount(hiddenOpenings.object!, 1.5, 1)).toBeGreaterThanOrEqual(2)
|
|
119
|
+
|
|
120
|
+
dispose(first.object!)
|
|
121
|
+
dispose(second.object!)
|
|
122
|
+
dispose(hiddenOpenings.object!)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
test('preserves the authored wall-local transform', () => {
|
|
126
|
+
const wall = WallNode.parse({
|
|
127
|
+
id: 'wall_print-transform',
|
|
128
|
+
start: [1, 2],
|
|
129
|
+
end: [1, 6],
|
|
130
|
+
thickness: 0.2,
|
|
131
|
+
})
|
|
132
|
+
const result = buildPrintableWallSolids(wall, { effectiveHeight: 3 })
|
|
133
|
+
|
|
134
|
+
expect(result.status).toBe('ready')
|
|
135
|
+
expect(result.object?.position.toArray()).toEqual([1, 0, 2])
|
|
136
|
+
expect(result.object?.rotation.y).toBeCloseTo(-Math.PI / 2)
|
|
137
|
+
dispose(result.object!)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
test('blocks unsupported wall forms and invalid opening contracts', () => {
|
|
141
|
+
const shaped = DoorNode.parse({
|
|
142
|
+
id: 'door_print-wall-arch',
|
|
143
|
+
wallId: 'wall_print-blocked',
|
|
144
|
+
position: [2, 1.05, 0],
|
|
145
|
+
openingShape: 'arch',
|
|
146
|
+
})
|
|
147
|
+
const wall = WallNode.parse({
|
|
148
|
+
id: 'wall_print-blocked',
|
|
149
|
+
start: [0, 0],
|
|
150
|
+
end: [4, 0],
|
|
151
|
+
children: [shaped.id],
|
|
152
|
+
})
|
|
153
|
+
const curved = buildPrintableWallSolids(
|
|
154
|
+
{ ...wall, curveOffset: 0.5 },
|
|
155
|
+
{ effectiveHeight: 2.5 },
|
|
156
|
+
{ [shaped.id]: shaped },
|
|
157
|
+
)
|
|
158
|
+
const terrain = buildPrintableWallSolids(
|
|
159
|
+
{ ...wall, children: [], fillToTerrain: true },
|
|
160
|
+
{ effectiveHeight: 2.5 },
|
|
161
|
+
)
|
|
162
|
+
const shapedResult = buildPrintableWallSolids(
|
|
163
|
+
wall,
|
|
164
|
+
{ effectiveHeight: 2.5 },
|
|
165
|
+
{ [shaped.id]: shaped },
|
|
166
|
+
)
|
|
167
|
+
const unresolved = buildPrintableWallSolids(wall, { effectiveHeight: 2.5 }, {})
|
|
168
|
+
|
|
169
|
+
expect(curved).toEqual(
|
|
170
|
+
expect.objectContaining({
|
|
171
|
+
status: 'blocked',
|
|
172
|
+
diagnostics: [expect.objectContaining({ code: 'unsupported_wall_print_curve' })],
|
|
173
|
+
}),
|
|
174
|
+
)
|
|
175
|
+
expect(terrain).toEqual(
|
|
176
|
+
expect.objectContaining({
|
|
177
|
+
status: 'blocked',
|
|
178
|
+
diagnostics: [expect.objectContaining({ code: 'unsupported_wall_print_terrain' })],
|
|
179
|
+
}),
|
|
180
|
+
)
|
|
181
|
+
expect(shapedResult).toEqual(
|
|
182
|
+
expect.objectContaining({
|
|
183
|
+
status: 'blocked',
|
|
184
|
+
diagnostics: [expect.objectContaining({ code: 'unsupported_wall_print_opening_shape' })],
|
|
185
|
+
}),
|
|
186
|
+
)
|
|
187
|
+
expect(unresolved).toEqual(
|
|
188
|
+
expect.objectContaining({
|
|
189
|
+
status: 'blocked',
|
|
190
|
+
diagnostics: [expect.objectContaining({ code: 'unresolved_wall_print_child' })],
|
|
191
|
+
}),
|
|
192
|
+
)
|
|
193
|
+
})
|
|
194
|
+
})
|