Snap roof segment resize handles to grid
This commit is contained in:
@@ -56,6 +56,7 @@ function roofSegmentWidthHandle(side: 'left' | 'right'): HandleDescriptor<RoofSe
|
||||
// 'max' = +X edge anchored (left arrow grows the -X edge outward).
|
||||
anchor: side === 'right' ? 'min' : 'max',
|
||||
min: MIN_ROOF_DIM,
|
||||
gridSnap: true,
|
||||
currentValue: (n) => n.width,
|
||||
apply: (initial, newWidth) => {
|
||||
const rotY = initial.rotation ?? 0
|
||||
@@ -100,6 +101,7 @@ function roofSegmentDepthHandle(side: 'front' | 'back'): HandleDescriptor<RoofSe
|
||||
axis: 'z',
|
||||
anchor: side === 'front' ? 'min' : 'max',
|
||||
min: MIN_ROOF_DIM,
|
||||
gridSnap: true,
|
||||
currentValue: (n) => n.depth,
|
||||
apply: (initial, newDepth) => {
|
||||
// Recenter so the anchored Z edge stays at the same world point.
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
type FloorplanMoveTarget,
|
||||
type RoofNode,
|
||||
type RoofSegmentNode,
|
||||
snapScalar,
|
||||
useScene,
|
||||
} from '@pascal-app/core'
|
||||
|
||||
@@ -56,7 +57,7 @@ function resolveSegmentFrame(
|
||||
* the math survives any parent-roof rotation.
|
||||
*/
|
||||
export const roofSegmentResizeAffordance: FloorplanAffordance<RoofSegmentNode> = {
|
||||
start({ node, payload, nodes, initialPlanPoint }) {
|
||||
start({ node, payload, nodes, initialPlanPoint, gridSnapStep }) {
|
||||
const { axis, side } = payload as RoofSegmentResizePayload
|
||||
const segmentId = node.id as AnyNodeId
|
||||
const initialValue = axis === 'x' ? node.width : node.depth
|
||||
@@ -79,7 +80,9 @@ export const roofSegmentResizeAffordance: FloorplanAffordance<RoofSegmentNode> =
|
||||
apply({ planPoint }) {
|
||||
const currentLocal = projectLocalAxis(planPoint[0], planPoint[1])
|
||||
const delta = (currentLocal - initialLocal) * side
|
||||
const newValue = Math.max(MIN_ROOF_DIM, initialValue + 2 * delta)
|
||||
const rawValue = initialValue + 2 * delta
|
||||
const snappedValue = gridSnapStep > 0 ? snapScalar(rawValue, gridSnapStep) : rawValue
|
||||
const newValue = Math.max(MIN_ROOF_DIM, snappedValue)
|
||||
lastValue = newValue
|
||||
useScene
|
||||
.getState()
|
||||
|
||||
Reference in New Issue
Block a user