Improve roof node editing
This commit is contained in:
@@ -101,6 +101,7 @@ export {
|
||||
getActiveRoofHeight,
|
||||
getEffectiveSegmentSurfaceMaterial,
|
||||
getPitchFromActiveRoofHeight,
|
||||
getRoofSegmentSurfaceY,
|
||||
getSegmentSlopeFrame,
|
||||
hasSegmentMaterialOverride,
|
||||
ROOF_SHAPE_DEFAULTS,
|
||||
|
||||
@@ -181,7 +181,6 @@ function getPrimarySlopeRun(input: PitchInputs & ShapeRatios): number {
|
||||
return min * input.mansardSteepWidthRatio
|
||||
case 'dutch':
|
||||
return min * input.dutchHipWidthRatio
|
||||
case 'hip':
|
||||
default:
|
||||
return min / 2
|
||||
}
|
||||
@@ -253,6 +252,42 @@ export function getActiveRoofHeight(node: Parameters<typeof getSegmentSlopeFrame
|
||||
return getSegmentSlopeFrame(node).activeRh
|
||||
}
|
||||
|
||||
/** Segment-local surface height used by roof accessory placement and hit disambiguation. */
|
||||
export function getRoofSegmentSurfaceY(
|
||||
node: Pick<RoofSegmentNode, 'roofType' | 'width' | 'depth' | 'wallHeight'> &
|
||||
Parameters<typeof getSegmentSlopeFrame>[0],
|
||||
localX: number,
|
||||
localZ: number,
|
||||
): number {
|
||||
const activeRh = getActiveRoofHeight(node)
|
||||
const peakY = node.wallHeight + activeRh
|
||||
if (activeRh === 0) return node.wallHeight
|
||||
|
||||
if (
|
||||
node.roofType === 'gable' ||
|
||||
node.roofType === 'gambrel' ||
|
||||
node.roofType === 'mansard' ||
|
||||
node.roofType === 'dutch'
|
||||
) {
|
||||
const t = node.depth > 0 ? Math.abs(localZ) / (node.depth / 2) : 0
|
||||
return peakY - t * activeRh
|
||||
}
|
||||
|
||||
if (node.roofType === 'shed') {
|
||||
const t = (localZ + node.depth / 2) / (node.depth || 1)
|
||||
return peakY - t * activeRh
|
||||
}
|
||||
|
||||
if (node.roofType === 'hip') {
|
||||
const fx = node.width > 0 ? Math.abs(localX) / (node.width / 2) : 0
|
||||
const fz = node.depth > 0 ? Math.abs(localZ) / (node.depth / 2) : 0
|
||||
return peakY - Math.max(fx, fz) * activeRh
|
||||
}
|
||||
|
||||
const t = node.depth > 0 ? Math.abs(localZ) / (node.depth / 2) : 0
|
||||
return peakY - t * activeRh
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverse of `getActiveRoofHeight` — recover the pitch a legacy
|
||||
* `roofHeight` value would correspond to. Used by the scene migration.
|
||||
|
||||
Reference in New Issue
Block a user