wallhammer-web 0.0.0-stage → 0.4.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/README.md +88 -2
- package/dist/base/data.d.ts +67 -0
- package/dist/base/data.js +10 -0
- package/dist/base/destructible.d.ts +167 -0
- package/dist/base/destructible.js +47 -0
- package/dist/base/env-slot.d.ts +101 -0
- package/dist/base/env-slot.js +8 -0
- package/dist/base/frames.d.ts +138 -0
- package/dist/base/frames.js +459 -0
- package/dist/base/index.d.ts +21 -0
- package/dist/base/index.js +11 -0
- package/dist/base/mat34.d.ts +46 -0
- package/dist/base/mat34.js +173 -0
- package/dist/base/material.d.ts +87 -0
- package/dist/base/material.js +6 -0
- package/dist/base/math.d.ts +27 -0
- package/dist/base/math.js +60 -0
- package/dist/base/progress.d.ts +38 -0
- package/dist/base/progress.js +81 -0
- package/dist/base/rig.d.ts +177 -0
- package/dist/base/rig.js +97 -0
- package/dist/base/trig.d.ts +29 -0
- package/dist/base/trig.js +169 -0
- package/dist/base/up.d.ts +26 -0
- package/dist/base/up.js +40 -0
- package/dist/base/view.d.ts +128 -0
- package/dist/base/view.js +136 -0
- package/dist/camera/camera.d.ts +99 -0
- package/dist/camera/camera.js +228 -0
- package/dist/camera/follow.d.ts +120 -0
- package/dist/camera/follow.js +320 -0
- package/dist/camera/free.d.ts +153 -0
- package/dist/camera/free.js +359 -0
- package/dist/camera/index.d.ts +10 -0
- package/dist/camera/index.js +6 -0
- package/dist/camera/orbit.d.ts +93 -0
- package/dist/camera/orbit.js +261 -0
- package/dist/camera/path.d.ts +48 -0
- package/dist/camera/path.js +179 -0
- package/dist/core/ballistic.d.ts +66 -0
- package/dist/core/ballistic.js +104 -0
- package/dist/core/bodies.d.ts +77 -0
- package/dist/core/bodies.js +125 -0
- package/dist/core/clock.d.ts +37 -0
- package/dist/core/clock.js +87 -0
- package/dist/core/cover-fade.d.ts +14 -0
- package/dist/core/cover-fade.js +38 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +8 -0
- package/dist/core/kepler.d.ts +74 -0
- package/dist/core/kepler.js +108 -0
- package/dist/core/level-fade.d.ts +66 -0
- package/dist/core/level-fade.js +123 -0
- package/dist/core/palette.d.ts +15 -0
- package/dist/core/palette.js +47 -0
- package/dist/env/atmosphere.d.ts +129 -0
- package/dist/env/atmosphere.js +707 -0
- package/dist/env/cloud-field.d.ts +44 -0
- package/dist/env/cloud-field.js +111 -0
- package/dist/env/environment.d.ts +217 -0
- package/dist/env/environment.js +441 -0
- package/dist/env/frame-block.d.ts +29 -0
- package/dist/env/frame-block.js +152 -0
- package/dist/env/glsl.d.ts +35 -0
- package/dist/env/glsl.js +246 -0
- package/dist/env/index.d.ts +13 -0
- package/dist/env/index.js +9 -0
- package/dist/env/sky.d.ts +48 -0
- package/dist/env/sky.js +227 -0
- package/dist/env/sun.d.ts +31 -0
- package/dist/env/sun.js +42 -0
- package/dist/gen-arch/build.d.ts +17 -0
- package/dist/gen-arch/build.js +414 -0
- package/dist/gen-arch/damage/damaged.d.ts +44 -0
- package/dist/gen-arch/damage/damaged.js +1119 -0
- package/dist/gen-arch/damage/fall-material.d.ts +10 -0
- package/dist/gen-arch/damage/fall-material.js +47 -0
- package/dist/gen-arch/damage/fall.d.ts +78 -0
- package/dist/gen-arch/damage/fall.js +797 -0
- package/dist/gen-arch/damage/rubble.d.ts +22 -0
- package/dist/gen-arch/damage/rubble.js +188 -0
- package/dist/gen-arch/index.d.ts +25 -0
- package/dist/gen-arch/index.js +16 -0
- package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
- package/dist/gen-arch/interior/interior-plan.js +615 -0
- package/dist/gen-arch/interior/interior.d.ts +97 -0
- package/dist/gen-arch/interior/interior.js +966 -0
- package/dist/gen-arch/structure/building-shader.d.ts +25 -0
- package/dist/gen-arch/structure/building-shader.js +946 -0
- package/dist/gen-arch/structure/buildings.d.ts +248 -0
- package/dist/gen-arch/structure/buildings.js +294 -0
- package/dist/gen-arch/structure/dims.d.ts +77 -0
- package/dist/gen-arch/structure/dims.js +39 -0
- package/dist/gen-arch/structure/distant.d.ts +62 -0
- package/dist/gen-arch/structure/distant.js +316 -0
- package/dist/gen-arch/structure/env-slots.d.ts +18 -0
- package/dist/gen-arch/structure/env-slots.js +47 -0
- package/dist/gen-arch/structure/facade.d.ts +193 -0
- package/dist/gen-arch/structure/facade.js +159 -0
- package/dist/gen-arch/structure/parts.d.ts +31 -0
- package/dist/gen-arch/structure/parts.js +69 -0
- package/dist/gen-arch/structure/roof.d.ts +76 -0
- package/dist/gen-arch/structure/roof.js +568 -0
- package/dist/gen-arch/structure/structure-material.d.ts +23 -0
- package/dist/gen-arch/structure/structure-material.js +55 -0
- package/dist/gen-arch/structure/writer.d.ts +94 -0
- package/dist/gen-arch/structure/writer.js +195 -0
- package/dist/gen-core/cell.d.ts +138 -0
- package/dist/gen-core/cell.js +150 -0
- package/dist/gen-core/cube-sphere.d.ts +57 -0
- package/dist/gen-core/cube-sphere.js +159 -0
- package/dist/gen-core/field.d.ts +55 -0
- package/dist/gen-core/field.js +154 -0
- package/dist/gen-core/geometry.d.ts +31 -0
- package/dist/gen-core/geometry.js +231 -0
- package/dist/gen-core/hash.d.ts +18 -0
- package/dist/gen-core/hash.js +58 -0
- package/dist/gen-core/height-field.d.ts +33 -0
- package/dist/gen-core/height-field.js +137 -0
- package/dist/gen-core/index.d.ts +22 -0
- package/dist/gen-core/index.js +17 -0
- package/dist/gen-core/instance-cells.d.ts +37 -0
- package/dist/gen-core/instance-cells.js +72 -0
- package/dist/gen-core/near-scatter.d.ts +56 -0
- package/dist/gen-core/near-scatter.js +120 -0
- package/dist/gen-core/noise.d.ts +23 -0
- package/dist/gen-core/noise.js +72 -0
- package/dist/gen-core/occupancy.d.ts +21 -0
- package/dist/gen-core/occupancy.js +104 -0
- package/dist/gen-core/sphere-patch.d.ts +138 -0
- package/dist/gen-core/sphere-patch.js +544 -0
- package/dist/gen-core/strip-surface.d.ts +34 -0
- package/dist/gen-core/strip-surface.js +246 -0
- package/dist/gen-core/strip.d.ts +102 -0
- package/dist/gen-core/strip.js +817 -0
- package/dist/gen-ground/env-slots.d.ts +48 -0
- package/dist/gen-ground/env-slots.js +78 -0
- package/dist/gen-ground/ground.d.ts +78 -0
- package/dist/gen-ground/ground.js +208 -0
- package/dist/gen-ground/index.d.ts +9 -0
- package/dist/gen-ground/index.js +7 -0
- package/dist/gen-ground/markings.d.ts +46 -0
- package/dist/gen-ground/markings.js +124 -0
- package/dist/gen-ground/materials.d.ts +18 -0
- package/dist/gen-ground/materials.js +22 -0
- package/dist/gen-ground/terrain-shader.d.ts +5 -0
- package/dist/gen-ground/terrain-shader.js +151 -0
- package/dist/gen-mesh/bare-shapes.d.ts +194 -0
- package/dist/gen-mesh/bare-shapes.js +596 -0
- package/dist/gen-mesh/bisect-surface.d.ts +47 -0
- package/dist/gen-mesh/bisect-surface.js +261 -0
- package/dist/gen-mesh/box.d.ts +18 -0
- package/dist/gen-mesh/box.js +2 -0
- package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
- package/dist/gen-mesh/cell-morph-mesh.js +258 -0
- package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
- package/dist/gen-mesh/cell-surface-mesh.js +140 -0
- package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
- package/dist/gen-mesh/chunk-mesh.js +112 -0
- package/dist/gen-mesh/drape-mesh.d.ts +36 -0
- package/dist/gen-mesh/drape-mesh.js +98 -0
- package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
- package/dist/gen-mesh/height-field-mesh.js +98 -0
- package/dist/gen-mesh/index.d.ts +26 -0
- package/dist/gen-mesh/index.js +15 -0
- package/dist/gen-mesh/line-mesh.d.ts +25 -0
- package/dist/gen-mesh/line-mesh.js +62 -0
- package/dist/gen-mesh/mesh-builder.d.ts +115 -0
- package/dist/gen-mesh/mesh-builder.js +315 -0
- package/dist/gen-mesh/packed-mesh.d.ts +53 -0
- package/dist/gen-mesh/packed-mesh.js +205 -0
- package/dist/gen-mesh/prism-mesh.d.ts +33 -0
- package/dist/gen-mesh/prism-mesh.js +176 -0
- package/dist/gen-mesh/rig-mesh.d.ts +9 -0
- package/dist/gen-mesh/rig-mesh.js +135 -0
- package/dist/gen-mesh/strip-mesh.d.ts +45 -0
- package/dist/gen-mesh/strip-mesh.js +258 -0
- package/dist/gen-plan/drain.d.ts +58 -0
- package/dist/gen-plan/drain.js +270 -0
- package/dist/gen-plan/grid.d.ts +37 -0
- package/dist/gen-plan/grid.js +182 -0
- package/dist/gen-plan/horizon.d.ts +50 -0
- package/dist/gen-plan/horizon.js +185 -0
- package/dist/gen-plan/index.d.ts +15 -0
- package/dist/gen-plan/index.js +13 -0
- package/dist/gen-plan/line-tiles.d.ts +35 -0
- package/dist/gen-plan/line-tiles.js +190 -0
- package/dist/gen-plan/lines.d.ts +31 -0
- package/dist/gen-plan/lines.js +183 -0
- package/dist/gen-plan/plots.d.ts +40 -0
- package/dist/gen-plan/plots.js +282 -0
- package/dist/gen-plan/route.d.ts +55 -0
- package/dist/gen-plan/route.js +297 -0
- package/dist/gen-plan/sites.d.ts +32 -0
- package/dist/gen-plan/sites.js +209 -0
- package/dist/gen-tex/code-stamp.d.ts +31 -0
- package/dist/gen-tex/code-stamp.js +137 -0
- package/dist/gen-tex/index.d.ts +7 -0
- package/dist/gen-tex/index.js +5 -0
- package/dist/gen-tex/light-horizon.d.ts +47 -0
- package/dist/gen-tex/light-horizon.js +180 -0
- package/dist/gen-tex/textures.d.ts +8 -0
- package/dist/gen-tex/textures.js +49 -0
- package/dist/gen-tex/value-textures.d.ts +46 -0
- package/dist/gen-tex/value-textures.js +102 -0
- package/dist/gen-vegetation/env-slots.d.ts +20 -0
- package/dist/gen-vegetation/env-slots.js +29 -0
- package/dist/gen-vegetation/index.d.ts +8 -0
- package/dist/gen-vegetation/index.js +7 -0
- package/dist/gen-vegetation/materials.d.ts +7 -0
- package/dist/gen-vegetation/materials.js +17 -0
- package/dist/gen-vegetation/planting.d.ts +170 -0
- package/dist/gen-vegetation/planting.js +363 -0
- package/dist/gen-vegetation/tree-shader.d.ts +23 -0
- package/dist/gen-vegetation/tree-shader.js +229 -0
- package/dist/gen-vegetation/trees.d.ts +59 -0
- package/dist/gen-vegetation/trees.js +329 -0
- package/dist/gpu/device.d.ts +286 -0
- package/dist/gpu/device.js +1157 -0
- package/dist/gpu/gl.d.ts +134 -0
- package/dist/gpu/gl.js +276 -0
- package/dist/gpu/index.d.ts +4 -0
- package/dist/gpu/index.js +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/dist/motion/graph.d.ts +244 -0
- package/dist/motion/graph.js +739 -0
- package/dist/motion/index.d.ts +8 -0
- package/dist/motion/index.js +8 -0
- package/dist/motion/pose-ops.d.ts +30 -0
- package/dist/motion/pose-ops.js +232 -0
- package/dist/motion/reach.d.ts +45 -0
- package/dist/motion/reach.js +264 -0
- package/dist/motion/skeleton.d.ts +49 -0
- package/dist/motion/skeleton.js +99 -0
- package/dist/platform/byte-store.d.ts +21 -0
- package/dist/platform/byte-store.js +137 -0
- package/dist/platform/canvas.d.ts +29 -0
- package/dist/platform/canvas.js +76 -0
- package/dist/platform/context-loss.d.ts +8 -0
- package/dist/platform/context-loss.js +17 -0
- package/dist/platform/free-input.d.ts +51 -0
- package/dist/platform/free-input.js +100 -0
- package/dist/platform/index.d.ts +18 -0
- package/dist/platform/index.js +10 -0
- package/dist/platform/input.d.ts +48 -0
- package/dist/platform/input.js +117 -0
- package/dist/platform/keys.d.ts +12 -0
- package/dist/platform/keys.js +29 -0
- package/dist/platform/loop.d.ts +41 -0
- package/dist/platform/loop.js +84 -0
- package/dist/platform/walk-input.d.ts +74 -0
- package/dist/platform/walk-input.js +226 -0
- package/dist/platform/worker.d.ts +51 -0
- package/dist/platform/worker.js +170 -0
- package/dist/render/bone-instances.d.ts +24 -0
- package/dist/render/bone-instances.js +74 -0
- package/dist/render/cells.d.ts +70 -0
- package/dist/render/cells.js +144 -0
- package/dist/render/glsl.d.ts +66 -0
- package/dist/render/glsl.js +173 -0
- package/dist/render/index.d.ts +26 -0
- package/dist/render/index.js +16 -0
- package/dist/render/instance-sets.d.ts +97 -0
- package/dist/render/instance-sets.js +241 -0
- package/dist/render/near-instances.d.ts +75 -0
- package/dist/render/near-instances.js +219 -0
- package/dist/render/particles.d.ts +63 -0
- package/dist/render/particles.js +215 -0
- package/dist/render/pieces.d.ts +57 -0
- package/dist/render/pieces.js +151 -0
- package/dist/render/point-lights.d.ts +97 -0
- package/dist/render/point-lights.js +243 -0
- package/dist/render/renderer.d.ts +447 -0
- package/dist/render/renderer.js +1100 -0
- package/dist/render/rig.d.ts +74 -0
- package/dist/render/rig.js +576 -0
- package/dist/render/shadow-areas.d.ts +49 -0
- package/dist/render/shadow-areas.js +125 -0
- package/dist/render/shadow-glsl.d.ts +12 -0
- package/dist/render/shadow-glsl.js +146 -0
- package/dist/render/transient.d.ts +61 -0
- package/dist/render/transient.js +213 -0
- package/dist/render/value-glsl.d.ts +17 -0
- package/dist/render/value-glsl.js +208 -0
- package/dist/render/value-layers.d.ts +180 -0
- package/dist/render/value-layers.js +333 -0
- package/dist/runtime/atmosphere.d.ts +37 -0
- package/dist/runtime/atmosphere.js +304 -0
- package/dist/runtime/cloud-shell.d.ts +29 -0
- package/dist/runtime/cloud-shell.js +158 -0
- package/dist/runtime/engine.d.ts +155 -0
- package/dist/runtime/engine.js +305 -0
- package/dist/runtime/environment-link.d.ts +22 -0
- package/dist/runtime/environment-link.js +49 -0
- package/dist/runtime/index.d.ts +13 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/precipitation-glsl.d.ts +2 -0
- package/dist/runtime/precipitation-glsl.js +70 -0
- package/dist/runtime/precipitation.d.ts +11 -0
- package/dist/runtime/precipitation.js +78 -0
- package/dist/runtime/sky.d.ts +30 -0
- package/dist/runtime/sky.js +114 -0
- package/dist/runtime/streaming.d.ts +245 -0
- package/dist/runtime/streaming.js +602 -0
- package/dist/sim/agenda.d.ts +167 -0
- package/dist/sim/agenda.js +425 -0
- package/dist/sim/bytes.d.ts +34 -0
- package/dist/sim/bytes.js +125 -0
- package/dist/sim/destruction/apply.d.ts +59 -0
- package/dist/sim/destruction/apply.js +243 -0
- package/dist/sim/destruction/cell-states.d.ts +54 -0
- package/dist/sim/destruction/cell-states.js +198 -0
- package/dist/sim/destruction/index.d.ts +11 -0
- package/dist/sim/destruction/index.js +10 -0
- package/dist/sim/destruction/int-geometry.d.ts +17 -0
- package/dist/sim/destruction/int-geometry.js +131 -0
- package/dist/sim/destruction/pick.d.ts +13 -0
- package/dist/sim/destruction/pick.js +59 -0
- package/dist/sim/destruction/rubble.d.ts +8 -0
- package/dist/sim/destruction/rubble.js +159 -0
- package/dist/sim/destruction/state.d.ts +15 -0
- package/dist/sim/destruction/state.js +83 -0
- package/dist/sim/destruction/structure.d.ts +30 -0
- package/dist/sim/destruction/structure.js +139 -0
- package/dist/sim/events.d.ts +37 -0
- package/dist/sim/events.js +106 -0
- package/dist/sim/fixed.d.ts +21 -0
- package/dist/sim/fixed.js +64 -0
- package/dist/sim/flow-probe.d.ts +58 -0
- package/dist/sim/flow-probe.js +158 -0
- package/dist/sim/flow.d.ts +257 -0
- package/dist/sim/flow.js +967 -0
- package/dist/sim/index.d.ts +28 -0
- package/dist/sim/index.js +20 -0
- package/dist/sim/interlock.d.ts +47 -0
- package/dist/sim/interlock.js +252 -0
- package/dist/sim/movers.d.ts +228 -0
- package/dist/sim/movers.js +1083 -0
- package/dist/sim/nav.d.ts +72 -0
- package/dist/sim/nav.js +292 -0
- package/dist/sim/paths.d.ts +80 -0
- package/dist/sim/paths.js +197 -0
- package/dist/sim/regions.d.ts +87 -0
- package/dist/sim/regions.js +517 -0
- package/dist/sim/simulation.d.ts +114 -0
- package/dist/sim/simulation.js +291 -0
- package/dist/sim/states.d.ts +23 -0
- package/dist/sim/states.js +54 -0
- package/dist/sim/table.d.ts +49 -0
- package/dist/sim/table.js +126 -0
- package/dist/sim/zones.d.ts +11 -0
- package/dist/sim/zones.js +196 -0
- package/dist/tools/collision-lines.d.ts +12 -0
- package/dist/tools/collision-lines.js +50 -0
- package/dist/tools/data-view-glsl.d.ts +3 -0
- package/dist/tools/data-view-glsl.js +63 -0
- package/dist/tools/data-view-layers.d.ts +20 -0
- package/dist/tools/data-view-layers.js +60 -0
- package/dist/tools/debug-view.d.ts +30 -0
- package/dist/tools/debug-view.js +4 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.js +7 -0
- package/dist/tools/mesh-checks.d.ts +67 -0
- package/dist/tools/mesh-checks.js +188 -0
- package/dist/tools/profile.d.ts +85 -0
- package/dist/tools/profile.js +173 -0
- package/dist/world/cell-cache.d.ts +32 -0
- package/dist/world/cell-cache.js +60 -0
- package/dist/world/cell-format.d.ts +25 -0
- package/dist/world/cell-format.js +232 -0
- package/dist/world/collide.d.ts +192 -0
- package/dist/world/collide.js +822 -0
- package/dist/world/index.d.ts +16 -0
- package/dist/world/index.js +12 -0
- package/dist/world/mesh-solids.d.ts +48 -0
- package/dist/world/mesh-solids.js +169 -0
- package/dist/world/pick.d.ts +34 -0
- package/dist/world/pick.js +177 -0
- package/dist/world/providers.d.ts +66 -0
- package/dist/world/providers.js +83 -0
- package/dist/world/sphere.d.ts +69 -0
- package/dist/world/sphere.js +271 -0
- package/dist/world/streaming.d.ts +288 -0
- package/dist/world/streaming.js +801 -0
- package/dist/world/walker.d.ts +145 -0
- package/dist/world/walker.js +502 -0
- package/docs/architecture.md +111 -0
- package/docs/cameras.md +302 -0
- package/docs/concepts.md +123 -0
- package/docs/destruction.md +127 -0
- package/docs/frames.md +199 -0
- package/docs/generators.md +575 -0
- package/docs/getting-started.md +123 -0
- package/docs/headless.md +50 -0
- package/docs/motion.md +160 -0
- package/docs/planet.md +152 -0
- package/docs/recipes.md +521 -0
- package/docs/reference.md +364 -0
- package/docs/rendering.md +823 -0
- package/docs/rigs.md +203 -0
- package/docs/simulation.md +235 -0
- package/docs/streaming.md +590 -0
- package/docs/system.md +166 -0
- package/docs/tools.md +175 -0
- package/docs/walking.md +262 -0
- package/package.json +131 -3
|
@@ -0,0 +1,1119 @@
|
|
|
1
|
+
// The destructible structure model of the structure generator. The generator knows its structure, so it emits it as
|
|
2
|
+
// parts next to the mesh (`describeStructure`) and draws a damaged structure from the same parts (`emitDamaged`).
|
|
3
|
+
//
|
|
4
|
+
// Parts and their stable keys (rule id in the top four bits, the part's path in the recipe below; never the order in
|
|
5
|
+
// which geometry is written):
|
|
6
|
+
// foundation one per structure, the ground anchor, indestructible
|
|
7
|
+
// wall (ring, edge, column, storey) a bay of a footprint edge in one storey; columns are the window columns
|
|
8
|
+
// roof (cell s, cell t) a section of the roof on a grid in the structure's oriented box
|
|
9
|
+
// balcony (ring, edge, column, storey), canopy (entrance), chimney (index), roof top (index of the superstructure)
|
|
10
|
+
//
|
|
11
|
+
// Damage ladder per part: intact → cracked (vertex damage channel, no geometry change) → breached (walls only: the
|
|
12
|
+
// opening the window rule would cut, enlarged and torn, cut as geometry with reveals) → gone (dropped; the rubble is a
|
|
13
|
+
// separate generator, rubble.ts). Inner faces and cut faces appear only in a damaged structure.
|
|
14
|
+
import { hashInts, unit } from '../../gen-core/index.js';
|
|
15
|
+
import { DAMAGE, PART_FLAG, PART_ROLE, entryRung, entryVariant } from '../../base/index.js';
|
|
16
|
+
import { PART_RULE, bayKey, canopyKey, chimneyKey, foundationKey, roofKey, roofTopKey } from '../structure/parts.js';
|
|
17
|
+
import { DOOR_KIND, FACADE_DIM } from '../structure/facade.js';
|
|
18
|
+
import { DAMAGE_STEP, KIND, NO_WALL_ATTR, pushBox, wallBox } from '../structure/writer.js';
|
|
19
|
+
import { FINISH, InteriorPaint, describeInterior, emitInterior, interiorExposure } from '../interior/interior.js';
|
|
20
|
+
import { cellAt, clipToRect, frameS, frameT, frameX, frameZ, planInterior } from '../interior/interior-plan.js';
|
|
21
|
+
export { PART_RULE, bayKey, canopyKey, chimneyKey, describeKey, foundationKey, partGone, partitionKey, roofKey, roofTopKey, slabKey, stairKey } from '../structure/parts.js';
|
|
22
|
+
// --- Dimensions and materials ---------------------------------------------------------------------------------------
|
|
23
|
+
/** Sizes of the destructible model in metres. */
|
|
24
|
+
export const DESTRUCT_DIM = {
|
|
25
|
+
/** Wall thickness: depth of reveals, cut faces and inner faces. */
|
|
26
|
+
wall: 0.3,
|
|
27
|
+
/** Target size of a roof section and the most sections along one axis. */
|
|
28
|
+
roofCell: 4.5,
|
|
29
|
+
roofCellsMax: 12,
|
|
30
|
+
/** Thickness of a roof section (for mass and the hit test). */
|
|
31
|
+
roofSlab: 0.25,
|
|
32
|
+
/** Ruin: height range of the wall stubs left standing. */
|
|
33
|
+
stubMin: 0.5,
|
|
34
|
+
stubMax: 2.2,
|
|
35
|
+
};
|
|
36
|
+
/** Material slots of the description. Energy thresholds in the units of `DestructionEvent.energy`. */
|
|
37
|
+
export const STRUCTURE_MATERIAL = { masonry: 0, slab: 1, attached: 2, fixture: 3, foundation: 4, floor: 5, partition: 6 };
|
|
38
|
+
export const STRUCTURE_MATERIALS = [
|
|
39
|
+
{ crack: 140, breach: 320, gone: 560, density: 1800 },
|
|
40
|
+
{ crack: 110, breach: 0, gone: 430, density: 2200 },
|
|
41
|
+
{ crack: 70, breach: 0, gone: 250, density: 2400 },
|
|
42
|
+
{ crack: 60, breach: 0, gone: 210, density: 1700 },
|
|
43
|
+
{ crack: 1 << 30, breach: 0, gone: 1 << 30, density: 2400 },
|
|
44
|
+
// Interior: floor slabs and stairs, partition walls.
|
|
45
|
+
{ crack: 220, breach: 0, gone: 950, density: 2400 },
|
|
46
|
+
{ crack: 150, breach: 0, gone: 600, density: 1500 },
|
|
47
|
+
];
|
|
48
|
+
/**
|
|
49
|
+
* Lateral hang allowed per rule (see `StructurePart.maxSpan`). A roof section rests on the walls and partitions under
|
|
50
|
+
* it and hangs no further than it does when intact, so it falls with the walls that carry it.
|
|
51
|
+
*/
|
|
52
|
+
const SPAN = { wall: 1, roof: 0, attached: 1, fixture: 0 };
|
|
53
|
+
const interiorCache = new WeakMap();
|
|
54
|
+
/**
|
|
55
|
+
* The interior plan of a structure. It is kept per spec object while the plan inputs stay the same, so repeated
|
|
56
|
+
* rebuilds of one structure (every hit) plan it once.
|
|
57
|
+
*/
|
|
58
|
+
export function interiorPlan(p) {
|
|
59
|
+
const sig = [p.flat, p.baseY, p.eaveY, p.floors, p.floorHeight, p.groundFloorH, p.floorBase, ...p.edges.flatMap((e) => [e.ring, e.i, e.ax, e.az, e.len, e.cols])].join(',');
|
|
60
|
+
const hit = interiorCache.get(p.b);
|
|
61
|
+
if (hit && hit.sig === sig)
|
|
62
|
+
return hit.ip;
|
|
63
|
+
const ip = planInterior(p, DESTRUCT_DIM.wall, DESTRUCT_DIM.roofSlab);
|
|
64
|
+
interiorCache.set(p.b, { sig, ip });
|
|
65
|
+
return ip;
|
|
66
|
+
}
|
|
67
|
+
// --- Shared geometry --------------------------------------------------------------------------------------------------
|
|
68
|
+
/** Bottom of storey row `f` (row 0 starts at the floor base; the top row reaches up to the roof line). */
|
|
69
|
+
function rowBottom(p, f) {
|
|
70
|
+
return f === 0 ? p.floorBase : p.floorBase + p.groundFloorH + (f - 1) * p.floorHeight;
|
|
71
|
+
}
|
|
72
|
+
function rowTop(p, f) {
|
|
73
|
+
return f < p.floors - 1 ? rowBottom(p, f + 1) : Infinity;
|
|
74
|
+
}
|
|
75
|
+
function wallLine(p, ei) {
|
|
76
|
+
const e = p.edges[ei];
|
|
77
|
+
const ts = p.splits[ei];
|
|
78
|
+
const us = [];
|
|
79
|
+
const tops = [];
|
|
80
|
+
const grounds = [];
|
|
81
|
+
for (const t of ts) {
|
|
82
|
+
const x = e.ax + (e.bx - e.ax) * t;
|
|
83
|
+
const z = e.az + (e.bz - e.az) * t;
|
|
84
|
+
us.push(e.len * t);
|
|
85
|
+
tops.push(p.roof.topAt(x, z) + p.wallTopExtra);
|
|
86
|
+
grounds.push(p.groundAt(x, z));
|
|
87
|
+
}
|
|
88
|
+
const base = p.attrs[ei] ?? null;
|
|
89
|
+
const fas = [];
|
|
90
|
+
for (let k = 0; k + 1 < us.length; k++) {
|
|
91
|
+
let fa = base ?? NO_WALL_ATTR;
|
|
92
|
+
if (base) {
|
|
93
|
+
const door = e.doors.find((d) => d.u >= us[k] - 1e-4 && d.u <= us[k + 1] + 1e-4);
|
|
94
|
+
if (door)
|
|
95
|
+
fa = { ...base, doorU: door.u, doorW: door.width, doorY: door.y, bits: [base.bits[0], base.bits[1] | (door.kind << 4), base.bits[2], base.bits[3]] };
|
|
96
|
+
}
|
|
97
|
+
fas.push(fa);
|
|
98
|
+
}
|
|
99
|
+
return { e, us, tops, grounds, fas };
|
|
100
|
+
}
|
|
101
|
+
/** Index of the piece of the line that holds u. */
|
|
102
|
+
function pieceAt(l, u) {
|
|
103
|
+
for (let k = 0; k + 2 < l.us.length; k++)
|
|
104
|
+
if (u < l.us[k + 1])
|
|
105
|
+
return k;
|
|
106
|
+
return Math.max(0, l.us.length - 2);
|
|
107
|
+
}
|
|
108
|
+
function lerpAt(l, vals, u) {
|
|
109
|
+
const k = pieceAt(l, u);
|
|
110
|
+
const u0 = l.us[k];
|
|
111
|
+
const u1 = l.us[k + 1];
|
|
112
|
+
const t = u1 - u0 > 1e-9 ? (u - u0) / (u1 - u0) : 0;
|
|
113
|
+
return vals[k] + (vals[k + 1] - vals[k]) * t;
|
|
114
|
+
}
|
|
115
|
+
/** Lowest top of the wall between u0 and u1. */
|
|
116
|
+
function minTop(l, u0, u1) {
|
|
117
|
+
let m = Math.min(lerpAt(l, l.tops, u0), lerpAt(l, l.tops, u1));
|
|
118
|
+
l.us.forEach((u, k) => {
|
|
119
|
+
if (u > u0 && u < u1)
|
|
120
|
+
m = Math.min(m, l.tops[k]);
|
|
121
|
+
});
|
|
122
|
+
return m;
|
|
123
|
+
}
|
|
124
|
+
function maxTop(l, u0, u1) {
|
|
125
|
+
let m = Math.max(lerpAt(l, l.tops, u0), lerpAt(l, l.tops, u1));
|
|
126
|
+
l.us.forEach((u, k) => {
|
|
127
|
+
if (u > u0 && u < u1)
|
|
128
|
+
m = Math.max(m, l.tops[k]);
|
|
129
|
+
});
|
|
130
|
+
return m;
|
|
131
|
+
}
|
|
132
|
+
/** Clips a convex polygon to the half plane a·u + b·y + c ≥ 0 (Sutherland–Hodgman). */
|
|
133
|
+
function clip2(poly, a, b, c) {
|
|
134
|
+
const out = [];
|
|
135
|
+
for (let i = 0; i < poly.length; i++) {
|
|
136
|
+
const p = poly[i];
|
|
137
|
+
const q = poly[(i + 1) % poly.length];
|
|
138
|
+
const fp = a * p[0] + b * p[1] + c;
|
|
139
|
+
const fq = a * q[0] + b * q[1] + c;
|
|
140
|
+
if (fp >= 0)
|
|
141
|
+
out.push(p);
|
|
142
|
+
if ((fp >= 0) !== (fq >= 0)) {
|
|
143
|
+
const t = fp / (fp - fq);
|
|
144
|
+
out.push([p[0] + (q[0] - p[0]) * t, p[1] + (q[1] - p[1]) * t]);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
/** Pieces of the wall region [u0, u1] × [ya, yb] under the roof line, one convex polygon per line piece (u, y). */
|
|
150
|
+
function wallRegion(l, u0, u1, ya, yb) {
|
|
151
|
+
const out = [];
|
|
152
|
+
for (let k = 0; k + 1 < l.us.length; k++) {
|
|
153
|
+
const s0 = Math.max(u0, l.us[k]);
|
|
154
|
+
const s1 = Math.min(u1, l.us[k + 1]);
|
|
155
|
+
if (s1 - s0 < 1e-5)
|
|
156
|
+
continue;
|
|
157
|
+
const t0 = lerpAt(l, l.tops, s0);
|
|
158
|
+
const t1 = lerpAt(l, l.tops, s1);
|
|
159
|
+
const hi = Math.min(yb, Math.max(t0, t1) + 1);
|
|
160
|
+
if (hi <= ya)
|
|
161
|
+
continue;
|
|
162
|
+
let poly = [
|
|
163
|
+
[s0, ya],
|
|
164
|
+
[s1, ya],
|
|
165
|
+
[s1, hi],
|
|
166
|
+
[s0, hi],
|
|
167
|
+
];
|
|
168
|
+
// Under the top line y ≤ t0 + (t1 − t0)(u − s0)/(s1 − s0).
|
|
169
|
+
const slope = (t1 - t0) / (s1 - s0);
|
|
170
|
+
poly = clip2(poly, slope, -1, t0 - slope * s0);
|
|
171
|
+
if (poly.length >= 3)
|
|
172
|
+
out.push({ poly, piece: k });
|
|
173
|
+
}
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
/** Writes one triangle, turned so its winding faces along n. */
|
|
177
|
+
function tri(w, a, b, c, n, put) {
|
|
178
|
+
const ex = b[0] - a[0];
|
|
179
|
+
const ey = b[1] - a[1];
|
|
180
|
+
const ez = b[2] - a[2];
|
|
181
|
+
const fx = c[0] - a[0];
|
|
182
|
+
const fy = c[1] - a[1];
|
|
183
|
+
const fz = c[2] - a[2];
|
|
184
|
+
const cx = ey * fz - ez * fy;
|
|
185
|
+
const cy = ez * fx - ex * fz;
|
|
186
|
+
const cz = ex * fy - ey * fx;
|
|
187
|
+
if (cx * n[0] + cy * n[1] + cz * n[2] < 0) {
|
|
188
|
+
put(a);
|
|
189
|
+
put(c);
|
|
190
|
+
put(b);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
put(a);
|
|
194
|
+
put(b);
|
|
195
|
+
put(c);
|
|
196
|
+
}
|
|
197
|
+
void w;
|
|
198
|
+
}
|
|
199
|
+
// --- Description -------------------------------------------------------------------------------------------------------
|
|
200
|
+
const cm = (m) => Math.round(m * 100);
|
|
201
|
+
/** Convex prism piece from x, z corners in metres; fixes the winding to counter-clockwise (positive area). */
|
|
202
|
+
function piece(xz, y0, y1) {
|
|
203
|
+
let area = 0;
|
|
204
|
+
const n = xz.length / 2;
|
|
205
|
+
for (let i = 0; i < n; i++) {
|
|
206
|
+
const j = (i + 1) % n;
|
|
207
|
+
area += xz[i * 2] * xz[j * 2 + 1] - xz[j * 2] * xz[i * 2 + 1];
|
|
208
|
+
}
|
|
209
|
+
const out = new Int32Array(n * 2);
|
|
210
|
+
for (let i = 0; i < n; i++) {
|
|
211
|
+
const s = area >= 0 ? i : n - 1 - i;
|
|
212
|
+
out[i * 2] = cm(xz[s * 2]);
|
|
213
|
+
out[i * 2 + 1] = cm(xz[s * 2 + 1]);
|
|
214
|
+
}
|
|
215
|
+
return { xz: out, y0: cm(y0), y1: cm(Math.max(y1, y0 + 0.01)) };
|
|
216
|
+
}
|
|
217
|
+
function boxCorners(p) {
|
|
218
|
+
const out = [];
|
|
219
|
+
for (const [su, sv] of [
|
|
220
|
+
[-1, -1],
|
|
221
|
+
[1, -1],
|
|
222
|
+
[1, 1],
|
|
223
|
+
[-1, 1],
|
|
224
|
+
]) {
|
|
225
|
+
out.push(p.cx + p.ux * p.halfL * su - p.uz * p.halfW * sv, p.cz + p.uz * p.halfL * su + p.ux * p.halfW * sv);
|
|
226
|
+
}
|
|
227
|
+
return out;
|
|
228
|
+
}
|
|
229
|
+
function roofGrid(b) {
|
|
230
|
+
const nS = Math.max(1, Math.min(DESTRUCT_DIM.roofCellsMax, Math.round((2 * b.box.halfL) / DESTRUCT_DIM.roofCell)));
|
|
231
|
+
const nT = Math.max(1, Math.min(DESTRUCT_DIM.roofCellsMax, Math.round((2 * b.box.halfW) / DESTRUCT_DIM.roofCell)));
|
|
232
|
+
return { nS, nT, cs: (2 * b.box.halfL) / nS, ct: (2 * b.box.halfW) / nT };
|
|
233
|
+
}
|
|
234
|
+
function cellOf(b, g, x, z) {
|
|
235
|
+
const { box } = b;
|
|
236
|
+
const s = (x - box.cx) * box.ux + (z - box.cz) * box.uz;
|
|
237
|
+
const t = -(x - box.cx) * box.uz + (z - box.cz) * box.ux;
|
|
238
|
+
const is = Math.max(0, Math.min(g.nS - 1, Math.floor((s + box.halfL) / g.cs)));
|
|
239
|
+
const it = Math.max(0, Math.min(g.nT - 1, Math.floor((t + box.halfW) / g.ct)));
|
|
240
|
+
return [is, it];
|
|
241
|
+
}
|
|
242
|
+
const roofCellCache = new WeakMap();
|
|
243
|
+
/**
|
|
244
|
+
* Roof cells of a structure. Kept per spec object while its box, the grid and the roof triangles are exactly the same,
|
|
245
|
+
* so describing and redrawing one structure (every hit) cut the roof once. Callers only read the result.
|
|
246
|
+
*/
|
|
247
|
+
function roofCells(p, g) {
|
|
248
|
+
const hit = roofCellCache.get(p.b);
|
|
249
|
+
const tr = p.roof.tris;
|
|
250
|
+
const bx = p.b.box;
|
|
251
|
+
const box = [bx.cx, bx.cz, bx.ux, bx.uz, bx.halfL, bx.halfW];
|
|
252
|
+
if (hit && hit.box.every((v, i) => v === box[i]) && hit.g.nS === g.nS && hit.g.nT === g.nT && hit.g.cs === g.cs && hit.g.ct === g.ct && hit.tris.length === tr.length && hit.tris.every((v, i) => v === tr[i]))
|
|
253
|
+
return hit.cells;
|
|
254
|
+
const cells = cutRoofCells(p, g);
|
|
255
|
+
roofCellCache.set(p.b, { box, g: { ...g }, tris: tr.slice(), cells });
|
|
256
|
+
return cells;
|
|
257
|
+
}
|
|
258
|
+
function cutRoofCells(p, g) {
|
|
259
|
+
const { box } = p.b;
|
|
260
|
+
const cells = new Map();
|
|
261
|
+
const tr = p.roof.tris;
|
|
262
|
+
const clip = (poly, axis, lo, keepAbove) => {
|
|
263
|
+
const out = [];
|
|
264
|
+
for (let i = 0; i < poly.length; i++) {
|
|
265
|
+
const a = poly[i];
|
|
266
|
+
const b = poly[(i + 1) % poly.length];
|
|
267
|
+
const fa = keepAbove ? a[axis] - lo : lo - a[axis];
|
|
268
|
+
const fb = keepAbove ? b[axis] - lo : lo - b[axis];
|
|
269
|
+
if (fa >= 0)
|
|
270
|
+
out.push(a);
|
|
271
|
+
if ((fa >= 0) !== (fb >= 0)) {
|
|
272
|
+
const t = fa / (fa - fb);
|
|
273
|
+
out.push(a.map((v, k) => v + (b[k] - v) * t));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return out;
|
|
277
|
+
};
|
|
278
|
+
for (let t = 0; t < tr.length; t += 9) {
|
|
279
|
+
const ex = tr[t + 3] - tr[t];
|
|
280
|
+
const ey = tr[t + 4] - tr[t + 1];
|
|
281
|
+
const ez = tr[t + 5] - tr[t + 2];
|
|
282
|
+
const fx = tr[t + 6] - tr[t];
|
|
283
|
+
const fy = tr[t + 7] - tr[t + 1];
|
|
284
|
+
const fz = tr[t + 8] - tr[t + 2];
|
|
285
|
+
let nx = ey * fz - ez * fy;
|
|
286
|
+
let ny = ez * fx - ex * fz;
|
|
287
|
+
let nz = ex * fy - ey * fx;
|
|
288
|
+
const l = Math.hypot(nx, ny, nz) || 1;
|
|
289
|
+
nx /= l;
|
|
290
|
+
ny /= l;
|
|
291
|
+
nz /= l;
|
|
292
|
+
const q = [];
|
|
293
|
+
for (let k = 0; k < 9; k += 3) {
|
|
294
|
+
const x = tr[t + k];
|
|
295
|
+
const y = tr[t + k + 1];
|
|
296
|
+
const z = tr[t + k + 2];
|
|
297
|
+
q.push([x, y, z, (x - box.cx) * box.ux + (z - box.cz) * box.uz + box.halfL, -(x - box.cx) * box.uz + (z - box.cz) * box.ux + box.halfW]);
|
|
298
|
+
}
|
|
299
|
+
const sMin = Math.min(q[0][3], q[1][3], q[2][3]);
|
|
300
|
+
const sMax = Math.max(q[0][3], q[1][3], q[2][3]);
|
|
301
|
+
const tMin = Math.min(q[0][4], q[1][4], q[2][4]);
|
|
302
|
+
const tMax = Math.max(q[0][4], q[1][4], q[2][4]);
|
|
303
|
+
const is0 = Math.max(0, Math.min(g.nS - 1, Math.floor(sMin / g.cs)));
|
|
304
|
+
const is1 = Math.max(0, Math.min(g.nS - 1, Math.floor(sMax / g.cs)));
|
|
305
|
+
const it0 = Math.max(0, Math.min(g.nT - 1, Math.floor(tMin / g.ct)));
|
|
306
|
+
const it1 = Math.max(0, Math.min(g.nT - 1, Math.floor(tMax / g.ct)));
|
|
307
|
+
for (let is = is0; is <= is1; is++) {
|
|
308
|
+
for (let it = it0; it <= it1; it++) {
|
|
309
|
+
let poly = q;
|
|
310
|
+
if (is > 0)
|
|
311
|
+
poly = clip(poly, 3, is * g.cs, true);
|
|
312
|
+
if (is < g.nS - 1)
|
|
313
|
+
poly = clip(poly, 3, (is + 1) * g.cs, false);
|
|
314
|
+
if (it > 0)
|
|
315
|
+
poly = clip(poly, 4, it * g.ct, true);
|
|
316
|
+
if (it < g.nT - 1)
|
|
317
|
+
poly = clip(poly, 4, (it + 1) * g.ct, false);
|
|
318
|
+
if (poly.length < 3)
|
|
319
|
+
continue;
|
|
320
|
+
// Area in the s, t plane.
|
|
321
|
+
let area = 0;
|
|
322
|
+
for (let i = 0; i < poly.length; i++) {
|
|
323
|
+
const a = poly[i];
|
|
324
|
+
const b = poly[(i + 1) % poly.length];
|
|
325
|
+
area += a[3] * b[4] - b[3] * a[4];
|
|
326
|
+
}
|
|
327
|
+
area = Math.abs(area) / 2;
|
|
328
|
+
if (area < 1e-4)
|
|
329
|
+
continue;
|
|
330
|
+
const key = roofKey(is, it);
|
|
331
|
+
let cell = cells.get(key);
|
|
332
|
+
if (!cell) {
|
|
333
|
+
cell = { is, it, polys: [], area: 0, y0: Infinity, y1: -Infinity };
|
|
334
|
+
cells.set(key, cell);
|
|
335
|
+
}
|
|
336
|
+
cell.area += area;
|
|
337
|
+
const pts = [];
|
|
338
|
+
for (const v of poly) {
|
|
339
|
+
pts.push(v[0], v[1], v[2]);
|
|
340
|
+
cell.y0 = Math.min(cell.y0, v[1]);
|
|
341
|
+
cell.y1 = Math.max(cell.y1, v[1]);
|
|
342
|
+
}
|
|
343
|
+
cell.polys.push({ pts, n: [nx, ny, nz] });
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return cells;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* The destructible description of one structure. Deterministic for the same plan; keys from the recipe paths.
|
|
351
|
+
* A structure whose paths do not fit the key layout is described as keep-out with only its foundation.
|
|
352
|
+
*/
|
|
353
|
+
export function describeStructure(p, keepOut) {
|
|
354
|
+
const { b } = p;
|
|
355
|
+
const parts = [];
|
|
356
|
+
const bonds = new Map();
|
|
357
|
+
const T = DESTRUCT_DIM.wall;
|
|
358
|
+
const add = (key, role, material, massKg, pc, flags, maxSpan) => {
|
|
359
|
+
parts.push({ key, role, material, mass: Math.max(1, Math.round(massKg)), piece: pc, flags, maxSpan });
|
|
360
|
+
};
|
|
361
|
+
const bond = (a, c, bearing, x, y, z, area) => {
|
|
362
|
+
// A tie is stored with the smaller key first; a bearing bond keeps its direction.
|
|
363
|
+
const [ka, kb] = bearing || a < c ? [a, c] : [c, a];
|
|
364
|
+
const id = `${ka}:${kb}`;
|
|
365
|
+
if (!bonds.has(id))
|
|
366
|
+
bonds.set(id, { a: ka, b: kb, bearing, x: cm(x), y: cm(y), z: cm(z), area: Math.max(1, Math.round(area * 10000)) });
|
|
367
|
+
};
|
|
368
|
+
const box = b.box;
|
|
369
|
+
const outline = piece(boxCorners(box), p.baseY, p.floorBase);
|
|
370
|
+
const fKey = foundationKey();
|
|
371
|
+
add(fKey, PART_ROLE.foundation, STRUCTURE_MATERIAL.foundation, (4 * box.halfL * box.halfW * Math.max(0.1, p.floorBase - p.baseY)) * 2400, outline, PART_FLAG.anchor | PART_FLAG.indestructible, 0);
|
|
372
|
+
const fits = p.edges.every((e) => bayKey(PART_RULE.wall, e.ring, e.i, e.cols - 1, p.floors - 1) >= 0);
|
|
373
|
+
const finish = (keep) => {
|
|
374
|
+
parts.sort((x, y) => x.key - y.key);
|
|
375
|
+
const list = [...bonds.values()].sort((x, y) => x.a - y.a || x.b - y.b);
|
|
376
|
+
return { id: b.id, keepOut: keep, groundY: cm(p.floorBase), cx: cm(box.cx), cz: cm(box.cz), outline: outline.xz, materials: [...STRUCTURE_MATERIALS], parts, bonds: list };
|
|
377
|
+
};
|
|
378
|
+
if (!fits)
|
|
379
|
+
return finish(true);
|
|
380
|
+
// Walls: bays per edge, column and storey.
|
|
381
|
+
const lines = p.edges.map((_, ei) => wallLine(p, ei));
|
|
382
|
+
p.edges.forEach((e, ei) => {
|
|
383
|
+
const l = lines[ei];
|
|
384
|
+
for (let c = 0; c < e.cols; c++) {
|
|
385
|
+
const u0 = c * e.colW;
|
|
386
|
+
const u1 = (c + 1) * e.colW;
|
|
387
|
+
for (let f = 0; f < p.floors; f++) {
|
|
388
|
+
const key = bayKey(PART_RULE.wall, e.ring, e.i, c, f);
|
|
389
|
+
const ya = rowBottom(p, f);
|
|
390
|
+
const yb = f < p.floors - 1 ? rowTop(p, f) : maxTop(l, u0, u1);
|
|
391
|
+
const xz = [e.ax + e.dx * u0, e.az + e.dz * u0, e.ax + e.dx * u1, e.az + e.dz * u1, e.ax + e.dx * u1 - e.nx * T, e.az + e.dz * u1 - e.nz * T, e.ax + e.dx * u0 - e.nx * T, e.az + e.dz * u0 - e.nz * T];
|
|
392
|
+
const h = f < p.floors - 1 ? yb - ya : (minTop(l, u0, u1) + yb) / 2 - ya;
|
|
393
|
+
add(key, PART_ROLE.bearing, STRUCTURE_MATERIAL.masonry, e.colW * Math.max(0.3, h) * T * STRUCTURE_MATERIALS[0].density, piece(xz, ya, yb), 0, SPAN.wall);
|
|
394
|
+
const um = (u0 + u1) / 2;
|
|
395
|
+
const mx = e.ax + e.dx * um - e.nx * T * 0.5;
|
|
396
|
+
const mz = e.az + e.dz * um - e.nz * T * 0.5;
|
|
397
|
+
if (f === 0)
|
|
398
|
+
bond(fKey, key, true, mx, ya, mz, e.colW * T);
|
|
399
|
+
else
|
|
400
|
+
bond(bayKey(PART_RULE.wall, e.ring, e.i, c, f - 1), key, true, mx, ya, mz, e.colW * T);
|
|
401
|
+
if (c + 1 < e.cols) {
|
|
402
|
+
const yc = (ya + Math.min(yb, ya + 3)) / 2;
|
|
403
|
+
bond(key, bayKey(PART_RULE.wall, e.ring, e.i, c + 1, f), false, e.ax + e.dx * u1, yc, e.az + e.dz * u1, Math.max(0.3, Math.min(yb, ya + 3) - ya) * T);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
// Corners: the last bay of an edge ties to the first bay of the next edge of the same ring.
|
|
409
|
+
const byRing = new Map();
|
|
410
|
+
for (const e of p.edges)
|
|
411
|
+
byRing.set(e.ring, [...(byRing.get(e.ring) ?? []), e]);
|
|
412
|
+
for (const ring of byRing.values()) {
|
|
413
|
+
if (ring.length < 2)
|
|
414
|
+
continue;
|
|
415
|
+
ring.forEach((e, k) => {
|
|
416
|
+
const next = ring[(k + 1) % ring.length];
|
|
417
|
+
for (let f = 0; f < p.floors; f++) {
|
|
418
|
+
const ya = rowBottom(p, f);
|
|
419
|
+
bond(bayKey(PART_RULE.wall, e.ring, e.i, e.cols - 1, f), bayKey(PART_RULE.wall, next.ring, next.i, 0, f), false, e.bx, ya + 1, e.bz, 3 * T);
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
// Roof sections, resting on the top bays under their edges, tied to each other.
|
|
424
|
+
const grid = roofGrid(b);
|
|
425
|
+
const cells = roofCells(p, grid);
|
|
426
|
+
for (const [key, cell] of cells) {
|
|
427
|
+
const s0 = -box.halfL + cell.is * grid.cs;
|
|
428
|
+
const t0 = -box.halfW + cell.it * grid.ct;
|
|
429
|
+
const sc = { cx: box.cx + box.ux * (s0 + grid.cs / 2) - box.uz * (t0 + grid.ct / 2), cz: box.cz + box.uz * (s0 + grid.cs / 2) + box.ux * (t0 + grid.ct / 2), ux: box.ux, uz: box.uz, halfL: grid.cs / 2, halfW: grid.ct / 2 };
|
|
430
|
+
add(key, PART_ROLE.span, STRUCTURE_MATERIAL.slab, cell.area * DESTRUCT_DIM.roofSlab * STRUCTURE_MATERIALS[1].density, piece(boxCorners(sc), cell.y0 - DESTRUCT_DIM.roofSlab, cell.y1), 0, SPAN.roof);
|
|
431
|
+
for (const [ds, dt] of [
|
|
432
|
+
[1, 0],
|
|
433
|
+
[0, 1],
|
|
434
|
+
]) {
|
|
435
|
+
const nKey = roofKey(cell.is + ds, cell.it + dt);
|
|
436
|
+
if (!cells.has(nKey))
|
|
437
|
+
continue;
|
|
438
|
+
const x = sc.cx + box.ux * (ds * grid.cs / 2) - box.uz * (dt * grid.ct / 2);
|
|
439
|
+
const z = sc.cz + box.uz * (ds * grid.cs / 2) + box.ux * (dt * grid.ct / 2);
|
|
440
|
+
bond(key, nKey, false, x, (cell.y0 + cell.y1) / 2, z, (ds ? grid.ct : grid.cs) * DESTRUCT_DIM.roofSlab);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
const restOnRoof = (key, x, z, y, area) => {
|
|
444
|
+
let [is, it] = cellOf(b, grid, x, z);
|
|
445
|
+
if (!cells.has(roofKey(is, it))) {
|
|
446
|
+
// Nearest section that exists (by grid distance, then key order).
|
|
447
|
+
let best = Infinity;
|
|
448
|
+
for (const c of cells.values()) {
|
|
449
|
+
const d = Math.abs(c.is - is) + Math.abs(c.it - it);
|
|
450
|
+
if (d < best) {
|
|
451
|
+
best = d;
|
|
452
|
+
[is, it] = [c.is, c.it];
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (cells.has(roofKey(is, it)))
|
|
457
|
+
bond(roofKey(is, it), key, true, x, y, z, area);
|
|
458
|
+
};
|
|
459
|
+
p.edges.forEach((e) => {
|
|
460
|
+
const f = p.floors - 1;
|
|
461
|
+
for (let c = 0; c < e.cols; c++) {
|
|
462
|
+
const key = bayKey(PART_RULE.wall, e.ring, e.i, c, f);
|
|
463
|
+
for (const s of [0.2, 0.5, 0.8]) {
|
|
464
|
+
const u = (c + s) * e.colW;
|
|
465
|
+
const x = e.ax + e.dx * u - e.nx * 0.8;
|
|
466
|
+
const z = e.az + e.dz * u - e.nz * 0.8;
|
|
467
|
+
const [is, it] = cellOf(b, grid, x, z);
|
|
468
|
+
const rk = roofKey(is, it);
|
|
469
|
+
if (cells.has(rk))
|
|
470
|
+
bond(key, rk, true, x, p.eaveY, z, e.colW * T);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
// Interior: slabs on the outer walls, partitions and stairs on the slabs.
|
|
475
|
+
describeInterior(p, interiorPlan(p), {
|
|
476
|
+
add,
|
|
477
|
+
bond,
|
|
478
|
+
piece,
|
|
479
|
+
foundation: fKey,
|
|
480
|
+
wallT: T,
|
|
481
|
+
});
|
|
482
|
+
// Attached parts and fixtures.
|
|
483
|
+
for (const pb of p.balconies) {
|
|
484
|
+
const e = p.edges[pb.edge];
|
|
485
|
+
const key = bayKey(PART_RULE.balcony, e.ring, e.i, pb.c, pb.f);
|
|
486
|
+
const bx = pb.box;
|
|
487
|
+
add(key, PART_ROLE.attached, STRUCTURE_MATERIAL.attached, 4 * bx.halfL * bx.halfW * bx.height * 0.5 * 2400, piece(boxCorners(bx), bx.baseY, bx.baseY + bx.height), 0, SPAN.attached);
|
|
488
|
+
for (const f of [pb.f, pb.f - 1])
|
|
489
|
+
bond(key, bayKey(PART_RULE.wall, e.ring, e.i, pb.c, f), false, bx.cx, bx.baseY, bx.cz, bx.halfL * 2 * 0.3);
|
|
490
|
+
}
|
|
491
|
+
for (const cp of p.canopies) {
|
|
492
|
+
const e = p.edges[cp.edge];
|
|
493
|
+
const key = canopyKey(cp.k);
|
|
494
|
+
const bx = cp.box;
|
|
495
|
+
add(key, PART_ROLE.attached, STRUCTURE_MATERIAL.attached, 4 * bx.halfL * bx.halfW * bx.height * 0.8 * 2400, piece(boxCorners(bx), bx.baseY, bx.baseY + bx.height), 0, SPAN.attached);
|
|
496
|
+
const c = Math.max(0, Math.min(e.cols - 1, Math.floor(cp.u / e.colW)));
|
|
497
|
+
bond(key, bayKey(PART_RULE.wall, e.ring, e.i, c, 0), false, bx.cx, bx.baseY, bx.cz, bx.halfL * 2 * bx.height);
|
|
498
|
+
}
|
|
499
|
+
for (const [list, keyOf, fill] of [
|
|
500
|
+
[p.chimneys, chimneyKey, 0.6],
|
|
501
|
+
[p.tops, roofTopKey, 0.12],
|
|
502
|
+
]) {
|
|
503
|
+
for (const pb of list) {
|
|
504
|
+
const key = keyOf(pb.k);
|
|
505
|
+
const bx = pb.box;
|
|
506
|
+
add(key, PART_ROLE.fixture, STRUCTURE_MATERIAL.fixture, 4 * bx.halfL * bx.halfW * bx.height * fill * 1700, piece(boxCorners(bx), bx.baseY, bx.baseY + bx.height), 0, SPAN.fixture);
|
|
507
|
+
restOnRoof(key, bx.cx, bx.cz, bx.baseY, 4 * bx.halfL * bx.halfW);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return finish(keepOut);
|
|
511
|
+
}
|
|
512
|
+
// --- Damaged emission ------------------------------------------------------------------------------------------------
|
|
513
|
+
/** Directions of the outline of a breach: cos and sin of 0°, 30°, …, 330° (constants, no trigonometry at run time). */
|
|
514
|
+
const DIRS12 = [
|
|
515
|
+
[1, 0],
|
|
516
|
+
[0.8660254037844387, 0.5],
|
|
517
|
+
[0.5, 0.8660254037844387],
|
|
518
|
+
[0, 1],
|
|
519
|
+
[-0.5, 0.8660254037844387],
|
|
520
|
+
[-0.8660254037844387, 0.5],
|
|
521
|
+
[-1, 0],
|
|
522
|
+
[-0.8660254037844387, -0.5],
|
|
523
|
+
[-0.5, -0.8660254037844387],
|
|
524
|
+
[0, -1],
|
|
525
|
+
[0.5, -0.8660254037844387],
|
|
526
|
+
[0.8660254037844387, -0.5],
|
|
527
|
+
];
|
|
528
|
+
/** Damage level written into the vertices for a rung. */
|
|
529
|
+
const levelOf = (r) => (r === DAMAGE.cracked ? 1 : r === DAMAGE.breached ? 2 : 0);
|
|
530
|
+
/**
|
|
531
|
+
* Writes a damaged structure: the same plan as the intact path, drawn part by part. Gone parts are left out, cracked
|
|
532
|
+
* ones carry the damage channel, breached bays get a torn opening with reveals, and the inside shows inner faces.
|
|
533
|
+
*/
|
|
534
|
+
export function emitDamaged(w, p, state) {
|
|
535
|
+
const T = DESTRUCT_DIM.wall;
|
|
536
|
+
const { b, mat, floors, floorHeight, floorBase, eaveY } = p;
|
|
537
|
+
const entry = (key) => state.parts.get(key) ?? 0;
|
|
538
|
+
const rungOf = (key) => (state.ruin ? DAMAGE.gone : entryRung(entry(key)));
|
|
539
|
+
const inner = { ...mat, trimColor: mat.wallColor };
|
|
540
|
+
const lines = p.edges.map((_, ei) => wallLine(p, ei));
|
|
541
|
+
const ip = state.ruin ? null : interiorPlan(p);
|
|
542
|
+
const paint = ip && ip.ok ? new InteriorPaint(p, ip, T) : null;
|
|
543
|
+
const grid = roofGrid(b);
|
|
544
|
+
const cells = roofCells(p, grid);
|
|
545
|
+
// Rooms that can be seen into; closed rooms draw nothing.
|
|
546
|
+
const open = ip && paint
|
|
547
|
+
? interiorExposure(p, ip, {
|
|
548
|
+
level: (key) => {
|
|
549
|
+
const r = rungOf(key);
|
|
550
|
+
return r === DAMAGE.gone ? -1 : levelOf(r);
|
|
551
|
+
},
|
|
552
|
+
bayOpen: (e, c, f) => rungOf(bayKey(PART_RULE.wall, e.ring, e.i, c, f)) >= DAMAGE.breached,
|
|
553
|
+
roofGone: [...cells.entries()]
|
|
554
|
+
.filter(([key]) => rungOf(key) === DAMAGE.gone)
|
|
555
|
+
.map(([, c]) => ({ s0: c.is * grid.cs - b.box.halfL, s1: (c.is + 1) * grid.cs - b.box.halfL, t0: c.it * grid.ct - b.box.halfW, t1: (c.it + 1) * grid.ct - b.box.halfW })),
|
|
556
|
+
})
|
|
557
|
+
: null;
|
|
558
|
+
// Torn and missing bays let daylight in like large windows.
|
|
559
|
+
if (paint) {
|
|
560
|
+
for (const e of p.edges) {
|
|
561
|
+
for (let c = 0; c < e.cols; c++) {
|
|
562
|
+
for (let f = 0; f < floors; f++) {
|
|
563
|
+
const r = rungOf(bayKey(PART_RULE.wall, e.ring, e.i, c, f));
|
|
564
|
+
if (r < DAMAGE.breached)
|
|
565
|
+
continue;
|
|
566
|
+
const flH = f === 0 ? p.groundFloorH : floorHeight;
|
|
567
|
+
paint.addOpening(e, (c + 0.5) * e.colW, f, e.colW * flH * (r === DAMAGE.gone ? 0.9 : 0.45));
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
const nRooms = ip ? ip.rooms.length : 0;
|
|
573
|
+
const roomOpen = (f, r) => open !== null && open[f * nRooms + r] === 1;
|
|
574
|
+
let atticOpen = false;
|
|
575
|
+
for (let r = 0; r < nRooms; r++)
|
|
576
|
+
atticOpen ||= roomOpen(floors, r);
|
|
577
|
+
const edgeIndex = new Map(p.edges.map((e, k) => [e, k]));
|
|
578
|
+
// Writers for a wall line: the outer face (façade data) and the inner face (damage level 3) at depth T.
|
|
579
|
+
const outer = (l, piece, damage) => (v) => {
|
|
580
|
+
const e = l.e;
|
|
581
|
+
const u = v[0];
|
|
582
|
+
const y = v[1];
|
|
583
|
+
w.push(e.ax + e.dx * u, y, e.az + e.dz * u, e.nx, 0, e.nz, KIND.wall + DAMAGE_STEP * damage, u, e.len, y - floorBase, y - lerpAt(l, l.grounds, u), mat, floors, floorHeight, l.fas[piece] ?? NO_WALL_ATTR);
|
|
584
|
+
};
|
|
585
|
+
const innerPut = (l, nx, ny, nz) => (v) => {
|
|
586
|
+
const e = l.e;
|
|
587
|
+
const u = v[0];
|
|
588
|
+
const y = v[1];
|
|
589
|
+
const d = v[3];
|
|
590
|
+
w.push(e.ax + e.dx * u - e.nx * d, y, e.az + e.dz * u - e.nz * d, nx, ny, nz, KIND.trim + DAMAGE_STEP * 3, 0, 0, y - floorBase, 100, inner, floors, floorHeight);
|
|
591
|
+
};
|
|
592
|
+
// In wall coordinates (u, y, ·, depth) a face along +n in 3D is a triangle that is clockwise in (u, y).
|
|
593
|
+
const wallTri = (l, a, bb, c, front, put) => {
|
|
594
|
+
const e = l.e;
|
|
595
|
+
const to3 = (v) => [e.ax + e.dx * v[0], v[1], e.az + e.dz * v[0], 0];
|
|
596
|
+
const n = front ? [e.nx, 0, e.nz] : [-e.nx, 0, -e.nz];
|
|
597
|
+
const A = to3(a);
|
|
598
|
+
const B = to3(bb);
|
|
599
|
+
const C = to3(c);
|
|
600
|
+
// Orient in 3D, then write the original (u, y) vertices in that order.
|
|
601
|
+
const ex = B[0] - A[0];
|
|
602
|
+
const ey = B[1] - A[1];
|
|
603
|
+
const ez = B[2] - A[2];
|
|
604
|
+
const fx = C[0] - A[0];
|
|
605
|
+
const fy = C[1] - A[1];
|
|
606
|
+
const fz = C[2] - A[2];
|
|
607
|
+
const cx = ey * fz - ez * fy;
|
|
608
|
+
const cy = ez * fx - ex * fz;
|
|
609
|
+
const cz = ex * fy - ey * fx;
|
|
610
|
+
if (cx * n[0] + cy * n[1] + cz * n[2] < 0) {
|
|
611
|
+
put(a);
|
|
612
|
+
put(c);
|
|
613
|
+
put(bb);
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
put(a);
|
|
617
|
+
put(bb);
|
|
618
|
+
put(c);
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
const fan = (l, poly, depth, front, put) => {
|
|
622
|
+
for (let k = 1; k + 1 < poly.length; k++) {
|
|
623
|
+
const a = poly[0];
|
|
624
|
+
const q = poly[k];
|
|
625
|
+
const r = poly[k + 1];
|
|
626
|
+
wallTri(l, [a[0], a[1], 0, depth], [q[0], q[1], 0, depth], [r[0], r[1], 0, depth], front, put);
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
/** A quad across the wall thickness along the segment p0–p1 (u, y), facing along nIn (3D). */
|
|
630
|
+
const cut = (l, p0, p1, n3) => {
|
|
631
|
+
const e = l.e;
|
|
632
|
+
const put = (v) => {
|
|
633
|
+
w.push(e.ax + e.dx * v[0] - e.nx * v[3], v[1], e.az + e.dz * v[0] - e.nz * v[3], n3[0], n3[1], n3[2], KIND.trim + DAMAGE_STEP * 3, 0, 0, v[1] - floorBase, 100, inner, floors, floorHeight);
|
|
634
|
+
};
|
|
635
|
+
const pos = (v) => [e.ax + e.dx * v[0] - e.nx * v[3], v[1], e.az + e.dz * v[0] - e.nz * v[3], 0];
|
|
636
|
+
const a = [p0[0], p0[1], 0, 0];
|
|
637
|
+
const bq = [p1[0], p1[1], 0, 0];
|
|
638
|
+
const c = [p1[0], p1[1], 0, T];
|
|
639
|
+
const d = [p0[0], p0[1], 0, T];
|
|
640
|
+
for (const [x, y, z] of [
|
|
641
|
+
[a, bq, c],
|
|
642
|
+
[a, c, d],
|
|
643
|
+
]) {
|
|
644
|
+
const A = pos(x);
|
|
645
|
+
const B = pos(y);
|
|
646
|
+
const C = pos(z);
|
|
647
|
+
tri(w, A, B, C, n3, () => undefined);
|
|
648
|
+
const ex = B[0] - A[0];
|
|
649
|
+
const ey = B[1] - A[1];
|
|
650
|
+
const ez = B[2] - A[2];
|
|
651
|
+
const fx = C[0] - A[0];
|
|
652
|
+
const fy = C[1] - A[1];
|
|
653
|
+
const fz = C[2] - A[2];
|
|
654
|
+
const flip = (ey * fz - ez * fy) * n3[0] + (ez * fx - ex * fz) * n3[1] + (ex * fy - ey * fx) * n3[2] < 0;
|
|
655
|
+
put(x);
|
|
656
|
+
if (flip) {
|
|
657
|
+
put(z);
|
|
658
|
+
put(y);
|
|
659
|
+
}
|
|
660
|
+
else {
|
|
661
|
+
put(y);
|
|
662
|
+
put(z);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
/**
|
|
667
|
+
* Inner face of storey `f` of a wall: painted per room between partitions, the slab edge in concrete, the roof space
|
|
668
|
+
* above the eave; without an interior (or for f < 0) the bare core as before.
|
|
669
|
+
*/
|
|
670
|
+
const innerFan = (l, poly, f, damage, outerPiece) => {
|
|
671
|
+
if (!paint || !ip || f < 0) {
|
|
672
|
+
fan(l, poly, T, false, innerPut(l, -l.e.nx, 0, -l.e.nz));
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
const e = l.e;
|
|
676
|
+
const ei = edgeIndex.get(e);
|
|
677
|
+
const top = f === floors - 1;
|
|
678
|
+
const cy = ip.ceilY[f];
|
|
679
|
+
const bands = [
|
|
680
|
+
[-Infinity, cy, FINISH.paint],
|
|
681
|
+
[cy, top ? eaveY : ip.floorY[f + 1], FINISH.concrete],
|
|
682
|
+
];
|
|
683
|
+
if (top)
|
|
684
|
+
bands.push([eaveY, Infinity, p.flat ? -1 : FINISH.atticWall]);
|
|
685
|
+
const cuts = [-Infinity, ...ip.wallSplits[ei].filter((u) => u > 1e-3 && u < e.len - 1e-3), Infinity];
|
|
686
|
+
let us = Infinity;
|
|
687
|
+
let ue = -Infinity;
|
|
688
|
+
for (const v of poly) {
|
|
689
|
+
us = Math.min(us, v[0]);
|
|
690
|
+
ue = Math.max(ue, v[0]);
|
|
691
|
+
}
|
|
692
|
+
for (const [ya, yb, finish] of bands) {
|
|
693
|
+
let band = clip2(poly, 0, 1, -ya);
|
|
694
|
+
band = clip2(band, 0, -1, yb);
|
|
695
|
+
if (band.length < 3)
|
|
696
|
+
continue;
|
|
697
|
+
if (finish < 0) {
|
|
698
|
+
fan(l, band, T, false, innerPut(l, -e.nx, 0, -e.nz));
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
for (let k = 0; k + 1 < cuts.length; k++) {
|
|
702
|
+
const ua = cuts[k];
|
|
703
|
+
const ub = cuts[k + 1];
|
|
704
|
+
if (ub <= us || ua >= ue)
|
|
705
|
+
continue;
|
|
706
|
+
let piece = clip2(band, 1, 0, -ua);
|
|
707
|
+
piece = clip2(piece, -1, 0, ub);
|
|
708
|
+
if (piece.length < 3)
|
|
709
|
+
continue;
|
|
710
|
+
const um = (Math.max(ua, us) + Math.min(ub, ue)) / 2;
|
|
711
|
+
const c = cellAt(ip, e.ax + e.dx * um - e.nx * (T + 0.2), e.az + e.dz * um - e.nz * (T + 0.2));
|
|
712
|
+
const room = finish === FINISH.atticWall ? -1 : c >= 0 ? ip.cells[c].room : -1;
|
|
713
|
+
// Closed rooms draw no inner face (a face whose room is unknown is kept).
|
|
714
|
+
if (finish === FINISH.atticWall ? !atticOpen : room >= 0 && !roomOpen(f, room))
|
|
715
|
+
continue;
|
|
716
|
+
if (finish === FINISH.atticWall) {
|
|
717
|
+
const fa = paint.attr(room, floors, finish);
|
|
718
|
+
const s3 = paint.hash(room);
|
|
719
|
+
fan(l, piece, T, false, (v) => {
|
|
720
|
+
w.push(e.ax + e.dx * v[0] - e.nx * T, v[1], e.az + e.dz * v[0] - e.nz * T, -e.nx, 0, -e.nz, KIND.interior + DAMAGE_STEP * damage, v[0], v[1] - eaveY, 3, s3, mat, floors, floorHeight, fa);
|
|
721
|
+
});
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
// Storey walls keep the façade data of the outside piece, so the shader draws the same openings from inside.
|
|
725
|
+
const inside = paint.wallInside(room, f, finish, l.fas[outerPiece] ?? NO_WALL_ATTR);
|
|
726
|
+
fan(l, piece, T, false, (v) => {
|
|
727
|
+
w.push(e.ax + e.dx * v[0] - e.nx * T, v[1], e.az + e.dz * v[0] - e.nz * T, -e.nx, 0, -e.nz, KIND.wallInside + DAMAGE_STEP * damage, v[0], e.len, v[1] - floorBase, inside.s3, inside.mat, floors, floorHeight, inside.fa);
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
/** Region [u0, u1] × [ya, yb] of a wall line: outer face with the damage level and the inner face of storey f. */
|
|
733
|
+
const panel = (l, u0, u1, ya, yb, damage, withInner, f = -1) => {
|
|
734
|
+
for (const { poly, piece } of wallRegion(l, u0, u1, ya, yb)) {
|
|
735
|
+
fan(l, poly, 0, true, outer(l, piece, damage));
|
|
736
|
+
if (withInner)
|
|
737
|
+
innerFan(l, poly, f, damage, piece);
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
// Foundation band: always there.
|
|
741
|
+
for (const l of lines)
|
|
742
|
+
panel(l, -1, l.e.len + 1, p.baseY, floorBase, 0, false);
|
|
743
|
+
if (state.ruin) {
|
|
744
|
+
emitRuinStubs(p, lines, panel, cut);
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
p.edges.forEach((e, ei) => {
|
|
748
|
+
const l = lines[ei];
|
|
749
|
+
const rungAt = (c, f) => (c < 0 || c >= e.cols || f < 0 || f >= floors ? DAMAGE.intact : rungOf(bayKey(2, e.ring, e.i, c, f)));
|
|
750
|
+
for (let c = 0; c < e.cols; c++) {
|
|
751
|
+
const u0 = c * e.colW;
|
|
752
|
+
const u1 = (c + 1) * e.colW;
|
|
753
|
+
for (let f = 0; f < floors; f++) {
|
|
754
|
+
const key = bayKey(2, e.ring, e.i, c, f);
|
|
755
|
+
const r = rungOf(key);
|
|
756
|
+
const ya = rowBottom(p, f);
|
|
757
|
+
const yb = rowTop(p, f);
|
|
758
|
+
const top = f === floors - 1;
|
|
759
|
+
if (r === DAMAGE.gone) {
|
|
760
|
+
// Cut faces where a standing neighbour borders the gap.
|
|
761
|
+
const hiL = Math.min(yb, lerpAt(l, l.tops, u0));
|
|
762
|
+
const hiR = Math.min(yb, lerpAt(l, l.tops, u1));
|
|
763
|
+
if (c > 0 && rungAt(c - 1, f) !== DAMAGE.gone)
|
|
764
|
+
cut(l, [u0, ya], [u0, hiL], [e.dx, 0, e.dz]);
|
|
765
|
+
if (c + 1 < e.cols && rungAt(c + 1, f) !== DAMAGE.gone)
|
|
766
|
+
cut(l, [u1, ya], [u1, hiR], [-e.dx, 0, -e.dz]);
|
|
767
|
+
if (f > 0 && rungAt(c, f - 1) !== DAMAGE.gone)
|
|
768
|
+
cut(l, [u0, ya], [u1, ya], [0, 1, 0]);
|
|
769
|
+
if (!top && rungAt(c, f + 1) !== DAMAGE.gone)
|
|
770
|
+
cut(l, [u0, yb], [u1, yb], [0, -1, 0]);
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
const level = levelOf(r);
|
|
774
|
+
if (r === DAMAGE.breached) {
|
|
775
|
+
const yr = Math.min(top ? Infinity : yb, minTop(l, u0, u1));
|
|
776
|
+
breach(l, u0, u1, ya, yr, f, c, entry(key));
|
|
777
|
+
if (yr < yb)
|
|
778
|
+
panel(l, u0, u1, yr, yb, level, true, f);
|
|
779
|
+
}
|
|
780
|
+
else {
|
|
781
|
+
panel(l, u0, u1, ya, yb, level, true, f);
|
|
782
|
+
}
|
|
783
|
+
if (top)
|
|
784
|
+
topRow(l, ei, c, u0, u1, level);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
/** Breach: the window opening of the bay (or its door), enlarged and torn, cut out of the band [ya, yr]. */
|
|
789
|
+
function breach(l, u0, u1, ya, yr, f, c, en) {
|
|
790
|
+
const e = l.e;
|
|
791
|
+
const v = entryVariant(en);
|
|
792
|
+
const r = (k) => unit(hashInts(b.hash, 0x6272, e.ring, e.i, c, f, v, k));
|
|
793
|
+
const rec = p.rec;
|
|
794
|
+
const flH = f === 0 ? p.groundFloorH : floorHeight;
|
|
795
|
+
const win = p.attrs[p.edges.indexOf(e)]?.win;
|
|
796
|
+
const winW = win && win[0] > 0 ? win[0] : 1.4;
|
|
797
|
+
const winH = win && win[1] > 0 ? win[1] : Math.min(1.6, flH - 0.8);
|
|
798
|
+
const sill = win && win[2] > 0 ? win[2] : 0.9;
|
|
799
|
+
const door = f === 0 ? e.doors.find((d) => d.u >= u0 && d.u < u1) : undefined;
|
|
800
|
+
let uc = (u0 + u1) / 2;
|
|
801
|
+
let yc = ya + sill + winH / 2;
|
|
802
|
+
let hw = winW / 2 + 0.3 + 0.35 * r(1);
|
|
803
|
+
let hh = winH / 2 + 0.25 + 0.35 * r(2);
|
|
804
|
+
if (door) {
|
|
805
|
+
const dh = door.kind === DOOR_KIND.arch
|
|
806
|
+
? door.width * FACADE_DIM.archHeightPerWidth
|
|
807
|
+
: door.kind === DOOR_KIND.garage
|
|
808
|
+
? FACADE_DIM.garageDoorHeight
|
|
809
|
+
: door.kind === DOOR_KIND.portal
|
|
810
|
+
? FACADE_DIM.portalHeight
|
|
811
|
+
: FACADE_DIM.doorHeight;
|
|
812
|
+
uc = door.u;
|
|
813
|
+
yc = door.y + dh / 2 + 0.2;
|
|
814
|
+
hw = door.width / 2 + 0.3 + 0.3 * r(1);
|
|
815
|
+
hh = dh / 2 + 0.2 + 0.3 * r(2);
|
|
816
|
+
}
|
|
817
|
+
void rec;
|
|
818
|
+
const margin = 0.18;
|
|
819
|
+
hw = Math.min(hw, (u1 - u0) / 2 - margin);
|
|
820
|
+
hh = Math.min(hh, (yr - ya) / 2 - margin);
|
|
821
|
+
if (hw < 0.3 || hh < 0.3) {
|
|
822
|
+
panel(l, u0, u1, ya, yr, 2, true, f);
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
uc = Math.max(u0 + margin + hw, Math.min(u1 - margin - hw, uc));
|
|
826
|
+
yc = Math.max(ya + margin + hh, Math.min(yr - margin - hh, yc));
|
|
827
|
+
// Torn outline: a ray every 30°, cut short by a seeded amount; the outer ring is the band rectangle.
|
|
828
|
+
const holeP = [];
|
|
829
|
+
const ringP = [];
|
|
830
|
+
DIRS12.forEach(([dx, dy], k) => {
|
|
831
|
+
const th = Math.min(dx !== 0 ? hw / Math.abs(dx) : Infinity, dy !== 0 ? hh / Math.abs(dy) : Infinity);
|
|
832
|
+
const s = 0.72 + 0.28 * r(10 + k);
|
|
833
|
+
holeP.push([uc + dx * th * s, yc + dy * th * s]);
|
|
834
|
+
const tb = Math.min(dx > 0 ? (u1 - uc) / dx : dx < 0 ? (u0 - uc) / dx : Infinity, dy > 0 ? (yr - yc) / dy : dy < 0 ? (ya - yc) / dy : Infinity);
|
|
835
|
+
ringP.push([uc + dx * tb, yc + dy * tb]);
|
|
836
|
+
});
|
|
837
|
+
const corners = [
|
|
838
|
+
[u1, yr],
|
|
839
|
+
[u0, yr],
|
|
840
|
+
[u0, ya],
|
|
841
|
+
[u1, ya],
|
|
842
|
+
];
|
|
843
|
+
const cross = (a, q) => a[0] * q[1] - a[1] * q[0];
|
|
844
|
+
const piece = pieceAt(l, uc);
|
|
845
|
+
for (let k = 0; k < 12; k++) {
|
|
846
|
+
const k1 = (k + 1) % 12;
|
|
847
|
+
const d0 = [DIRS12[k][0], DIRS12[k][1]];
|
|
848
|
+
const d1 = [DIRS12[k1][0], DIRS12[k1][1]];
|
|
849
|
+
const poly = [holeP[k], ringP[k]];
|
|
850
|
+
for (const q of corners) {
|
|
851
|
+
const rel = [q[0] - uc, q[1] - yc];
|
|
852
|
+
if (cross(d0, rel) > 1e-9 && cross(rel, d1) > 1e-9)
|
|
853
|
+
poly.push(q);
|
|
854
|
+
}
|
|
855
|
+
poly.push(ringP[k1], holeP[k1]);
|
|
856
|
+
// Sector polygon: fan from the hole point.
|
|
857
|
+
fan(l, poly, 0, true, outer(l, piece, 2));
|
|
858
|
+
innerFan(l, poly, f, 2, piece);
|
|
859
|
+
// Reveal along the torn edge, facing into the opening.
|
|
860
|
+
const a = holeP[k];
|
|
861
|
+
const q = holeP[k1];
|
|
862
|
+
const mu = (a[0] + q[0]) / 2 - uc;
|
|
863
|
+
const my = (a[1] + q[1]) / 2 - yc;
|
|
864
|
+
const len = Math.hypot(mu, my) || 1;
|
|
865
|
+
cut(l, a, q, [(-e.dx * mu) / len, -my / len, (-e.dz * mu) / len]);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
/** Parapet and cornice on top of a standing top-row bay. */
|
|
869
|
+
function topRow(l, ei, c, u0, u1, level) {
|
|
870
|
+
const e = l.e;
|
|
871
|
+
const innerRing = p.parapet > 0 ? p.insets[e.ring] : null;
|
|
872
|
+
if (innerRing) {
|
|
873
|
+
const ringLen = innerRing.length / 2;
|
|
874
|
+
const j = (e.i + 1) % ringLen;
|
|
875
|
+
const top = eaveY + p.parapet;
|
|
876
|
+
const t0 = u0 / e.len;
|
|
877
|
+
const t1 = u1 / e.len;
|
|
878
|
+
const ix = (t) => innerRing[e.i * 2] + (innerRing[j * 2] - innerRing[e.i * 2]) * t;
|
|
879
|
+
const iz = (t) => innerRing[e.i * 2 + 1] + (innerRing[j * 2 + 1] - innerRing[e.i * 2 + 1]) * t;
|
|
880
|
+
const kind = KIND.trim + DAMAGE_STEP * level;
|
|
881
|
+
const t = (x, y, z, px, py, pz) => w.push(x, y, z, px, py, pz, kind, 0, 0, y - eaveY, 100, mat, floors, floorHeight);
|
|
882
|
+
const ax = e.ax + e.dx * u0;
|
|
883
|
+
const az = e.az + e.dz * u0;
|
|
884
|
+
const bx = e.ax + e.dx * u1;
|
|
885
|
+
const bz = e.az + e.dz * u1;
|
|
886
|
+
t(ax, top, az, 0, 1, 0);
|
|
887
|
+
t(ix(t0), top, iz(t0), 0, 1, 0);
|
|
888
|
+
t(bx, top, bz, 0, 1, 0);
|
|
889
|
+
t(bx, top, bz, 0, 1, 0);
|
|
890
|
+
t(ix(t0), top, iz(t0), 0, 1, 0);
|
|
891
|
+
t(ix(t1), top, iz(t1), 0, 1, 0);
|
|
892
|
+
t(ix(t0), top, iz(t0), -e.nx, 0, -e.nz);
|
|
893
|
+
t(ix(t0), eaveY, iz(t0), -e.nx, 0, -e.nz);
|
|
894
|
+
t(ix(t1), top, iz(t1), -e.nx, 0, -e.nz);
|
|
895
|
+
t(ix(t1), top, iz(t1), -e.nx, 0, -e.nz);
|
|
896
|
+
t(ix(t0), eaveY, iz(t0), -e.nx, 0, -e.nz);
|
|
897
|
+
t(ix(t1), eaveY, iz(t1), -e.nx, 0, -e.nz);
|
|
898
|
+
}
|
|
899
|
+
const cor = p.cornice;
|
|
900
|
+
if (cor && !e.party && e.levelTop && e.len >= 1.5) {
|
|
901
|
+
const proj = cor.projection + 0.004 * (ei % 3);
|
|
902
|
+
const topY = eaveY + p.wallTopExtra - FACADE_DIM.corniceTopGap - 0.003 * (ei % 2);
|
|
903
|
+
const a0 = c === 0 && e.convexA ? -proj : u0;
|
|
904
|
+
const a1 = c === e.cols - 1 && e.convexB ? e.len + proj : u1;
|
|
905
|
+
pushBox(w, wallBox(e.ax, e.az, e.dx, e.dz, a0, a1, -0.05, proj, topY - cor.height, cor.height, b.trimColor, hashInts(b.hash, 950, ei, c)), level, cor.underside === true);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
// Attachments that still stand.
|
|
909
|
+
for (const pb of p.balconies) {
|
|
910
|
+
const e = p.edges[pb.edge];
|
|
911
|
+
const r = rungOf(bayKey(PART_RULE.balcony, e.ring, e.i, pb.c, pb.f));
|
|
912
|
+
if (r !== DAMAGE.gone)
|
|
913
|
+
pushBox(w, pb.box, levelOf(r));
|
|
914
|
+
}
|
|
915
|
+
for (const pb of p.tops) {
|
|
916
|
+
const r = rungOf(roofTopKey(pb.k));
|
|
917
|
+
if (r !== DAMAGE.gone)
|
|
918
|
+
pushBox(w, pb.box, levelOf(r));
|
|
919
|
+
}
|
|
920
|
+
for (const pb of p.chimneys) {
|
|
921
|
+
const r = rungOf(chimneyKey(pb.k));
|
|
922
|
+
if (r !== DAMAGE.gone)
|
|
923
|
+
pushBox(w, pb.box, levelOf(r));
|
|
924
|
+
}
|
|
925
|
+
// Interior: slabs, partitions and stairs.
|
|
926
|
+
if (ip && paint) {
|
|
927
|
+
emitInterior(w, p, ip, paint, {
|
|
928
|
+
level: (key) => {
|
|
929
|
+
const r = rungOf(key);
|
|
930
|
+
return r === DAMAGE.gone ? -1 : levelOf(r);
|
|
931
|
+
},
|
|
932
|
+
bayGone: (e, c, f) => f >= 0 && f < floors && rungOf(bayKey(PART_RULE.wall, e.ring, e.i, c, f)) === DAMAGE.gone,
|
|
933
|
+
open: open,
|
|
934
|
+
wallT: T,
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
// Roof sections.
|
|
938
|
+
const kind = p.flat ? KIND.roofFlat : KIND.roofPitched;
|
|
939
|
+
for (const [key, cell] of cells) {
|
|
940
|
+
const r = rungOf(key);
|
|
941
|
+
if (r === DAMAGE.gone)
|
|
942
|
+
continue;
|
|
943
|
+
const k2 = kind + DAMAGE_STEP * levelOf(r);
|
|
944
|
+
for (const { pts, n } of cell.polys) {
|
|
945
|
+
const m = pts.length / 3;
|
|
946
|
+
for (let i = 1; i + 1 < m; i++) {
|
|
947
|
+
for (const v of [0, i, i + 1]) {
|
|
948
|
+
const y = pts[v * 3 + 1];
|
|
949
|
+
w.push(pts[v * 3], y, pts[v * 3 + 2], n[0], n[1], n[2], k2, 0, 0, y - eaveY, 100, mat, floors, floorHeight);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
if (ip && paint)
|
|
954
|
+
roofUnderside(cell, levelOf(r), (s0, t0) => {
|
|
955
|
+
const nk = roofKey(s0, t0);
|
|
956
|
+
return cells.has(nk) && rungOf(nk) === DAMAGE.gone;
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Underside of a roof section inside the footprint: the ceiling of the rooms of the top storey under a flat roof
|
|
961
|
+
* (split by room), the roof space under a pitched one. Cut edges where a neighbouring section is gone.
|
|
962
|
+
*/
|
|
963
|
+
function roofUnderside(cell, level, goneAt) {
|
|
964
|
+
const plan = ip;
|
|
965
|
+
const fr = plan.frame;
|
|
966
|
+
const slab = DESTRUCT_DIM.roofSlab;
|
|
967
|
+
const topF = floors - 1;
|
|
968
|
+
const yMin = p.flat ? -Infinity : eaveY + 0.02;
|
|
969
|
+
const kindI = KIND.interior + DAMAGE_STEP * level;
|
|
970
|
+
const nTc = plan.tCuts.length - 1;
|
|
971
|
+
const attic = !p.flat && atticOpen;
|
|
972
|
+
if (p.flat) {
|
|
973
|
+
// Flat roof: the ceilings of the open rooms under this section, straight from the plan cells (the section
|
|
974
|
+
// covers the whole footprint inside its rectangle).
|
|
975
|
+
const flatY = cell.polys.find((q) => q.n[1] > 0.05)?.pts[1];
|
|
976
|
+
if (flatY !== undefined) {
|
|
977
|
+
const rect = { s0: cell.is * grid.cs - b.box.halfL, s1: (cell.is + 1) * grid.cs - b.box.halfL, t0: cell.it * grid.ct - b.box.halfW, t1: (cell.it + 1) * grid.ct - b.box.halfW };
|
|
978
|
+
const y = flatY - slab;
|
|
979
|
+
const h = plan.ceilY[topF] - plan.floorY[topF];
|
|
980
|
+
plan.cells.forEach((pc, ci) => {
|
|
981
|
+
if (pc.area <= 0 || !roomOpen(topF, pc.room))
|
|
982
|
+
return;
|
|
983
|
+
const i = Math.floor(ci / nTc);
|
|
984
|
+
const j = ci % nTc;
|
|
985
|
+
if (plan.sCuts[i + 1] <= rect.s0 || plan.sCuts[i] >= rect.s1 || plan.tCuts[j + 1] <= rect.t0 || plan.tCuts[j] >= rect.t1)
|
|
986
|
+
return;
|
|
987
|
+
const fa = paint.attr(pc.room, topF, FINISH.ceiling);
|
|
988
|
+
const hash = paint.hash(pc.room);
|
|
989
|
+
for (const cp of pc.polys) {
|
|
990
|
+
const st = [];
|
|
991
|
+
for (let k = 0; k < cp.length; k += 2)
|
|
992
|
+
st.push([frameS(fr, cp[k], cp[k + 1]), frameT(fr, cp[k], cp[k + 1]), cp[k], cp[k + 1]]);
|
|
993
|
+
const piece = clipToRect(st, rect);
|
|
994
|
+
if (piece.length < 3)
|
|
995
|
+
continue;
|
|
996
|
+
const put = (v) => {
|
|
997
|
+
w.push(frameX(fr, v[0], v[1]), y, frameZ(fr, v[0], v[1]), 0, -1, 0, kindI, v[0], v[1], h, hash, mat, floors, floorHeight, fa);
|
|
998
|
+
};
|
|
999
|
+
// Written so that every triangle faces down.
|
|
1000
|
+
const A = piece[0];
|
|
1001
|
+
for (let k = 1; k + 1 < piece.length; k++) {
|
|
1002
|
+
const B = piece[k];
|
|
1003
|
+
const C = piece[k + 1];
|
|
1004
|
+
const ny = (frameZ(fr, B[0], B[1]) - frameZ(fr, A[0], A[1])) * (frameX(fr, C[0], C[1]) - frameX(fr, A[0], A[1])) - (frameX(fr, B[0], B[1]) - frameX(fr, A[0], A[1])) * (frameZ(fr, C[0], C[1]) - frameZ(fr, A[0], A[1]));
|
|
1005
|
+
put(A);
|
|
1006
|
+
if (ny < 0) {
|
|
1007
|
+
put(B);
|
|
1008
|
+
put(C);
|
|
1009
|
+
}
|
|
1010
|
+
else {
|
|
1011
|
+
put(C);
|
|
1012
|
+
put(B);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
for (const { pts, n } of cell.polys) {
|
|
1020
|
+
const m = pts.length / 3;
|
|
1021
|
+
if (n[1] <= 0.05)
|
|
1022
|
+
continue;
|
|
1023
|
+
// Polygon in the box frame with its world position: s, t, x, y, z.
|
|
1024
|
+
const poly = [];
|
|
1025
|
+
for (let k = 0; k < m; k++) {
|
|
1026
|
+
const x = pts[k * 3];
|
|
1027
|
+
const z = pts[k * 3 + 2];
|
|
1028
|
+
poly.push([frameS(fr, x, z), frameT(fr, x, z), x, pts[k * 3 + 1], z]);
|
|
1029
|
+
}
|
|
1030
|
+
// Pitched roof: the underside of the section over the roof space, when that space is open.
|
|
1031
|
+
if (attic) {
|
|
1032
|
+
const fa = paint.attr(-1, floors, FINISH.atticWall);
|
|
1033
|
+
const hash = paint.hash(-1);
|
|
1034
|
+
const put = (v) => {
|
|
1035
|
+
const y = Math.max(yMin, v[3] - slab);
|
|
1036
|
+
w.push(v[2], y, v[4], -n[0], -n[1], -n[2], kindI, v[0], v[1], 3, hash, mat, floors, floorHeight, fa);
|
|
1037
|
+
};
|
|
1038
|
+
// The roof polygon winds upwards; written backwards it faces down.
|
|
1039
|
+
for (let k = 1; k + 1 < poly.length; k++) {
|
|
1040
|
+
put(poly[0]);
|
|
1041
|
+
put(poly[k + 1]);
|
|
1042
|
+
put(poly[k]);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
// Cut edges on the section borders towards gone neighbours (only inside the footprint).
|
|
1046
|
+
for (let k = 0; k < m; k++) {
|
|
1047
|
+
const a = poly[k];
|
|
1048
|
+
const q = poly[(k + 1) % m];
|
|
1049
|
+
const sa = a[0] + b.box.halfL;
|
|
1050
|
+
const sb = q[0] + b.box.halfL;
|
|
1051
|
+
const ta = a[1] + b.box.halfW;
|
|
1052
|
+
const tb = q[1] + b.box.halfW;
|
|
1053
|
+
let nis = cell.is;
|
|
1054
|
+
let nit = cell.it;
|
|
1055
|
+
let nrm = null;
|
|
1056
|
+
const on = (va, vb, line) => Math.abs(va - line) < 1e-4 && Math.abs(vb - line) < 1e-4;
|
|
1057
|
+
if (on(sa, sb, cell.is * grid.cs)) {
|
|
1058
|
+
nis--;
|
|
1059
|
+
nrm = [-b.box.ux, 0, -b.box.uz];
|
|
1060
|
+
}
|
|
1061
|
+
else if (on(sa, sb, (cell.is + 1) * grid.cs)) {
|
|
1062
|
+
nis++;
|
|
1063
|
+
nrm = [b.box.ux, 0, b.box.uz];
|
|
1064
|
+
}
|
|
1065
|
+
else if (on(ta, tb, cell.it * grid.ct)) {
|
|
1066
|
+
nit--;
|
|
1067
|
+
nrm = [b.box.uz, 0, -b.box.ux];
|
|
1068
|
+
}
|
|
1069
|
+
else if (on(ta, tb, (cell.it + 1) * grid.ct)) {
|
|
1070
|
+
nit++;
|
|
1071
|
+
nrm = [-b.box.uz, 0, b.box.ux];
|
|
1072
|
+
}
|
|
1073
|
+
if (!nrm || nis < 0 || nit < 0 || !goneAt(nis, nit))
|
|
1074
|
+
continue;
|
|
1075
|
+
const mx = (a[2] + q[2]) / 2;
|
|
1076
|
+
const mz = (a[4] + q[4]) / 2;
|
|
1077
|
+
if (cellAt(plan, mx, mz) < 0 || !pointInside(plan, mx, mz))
|
|
1078
|
+
continue;
|
|
1079
|
+
const fa = paint.attr(-1, floors, FINISH.concrete);
|
|
1080
|
+
const A = [a[2], a[3], a[4], 0];
|
|
1081
|
+
const B = [q[2], q[3], q[4], 0];
|
|
1082
|
+
const C = [q[2], Math.max(yMin, q[3] - slab), q[4], 0];
|
|
1083
|
+
const Dd = [a[2], Math.max(yMin, a[3] - slab), a[4], 0];
|
|
1084
|
+
const put = (v) => w.push(v[0], v[1], v[2], nrm[0], 0, nrm[2], kindI, 0, v[1] - eaveY, 1, 0.5, mat, floors, floorHeight, fa);
|
|
1085
|
+
tri(w, A, B, C, nrm, put);
|
|
1086
|
+
tri(w, A, C, Dd, nrm, put);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
/** Is a point inside the interior footprint (the inner face of the outer walls)? */
|
|
1092
|
+
function pointInside(ip, x, z) {
|
|
1093
|
+
for (let k = 0; k < ip.tris.length; k += 6) {
|
|
1094
|
+
const t = ip.tris;
|
|
1095
|
+
const d1 = (x - t[k + 2]) * (t[k + 1] - t[k + 3]) - (t[k] - t[k + 2]) * (z - t[k + 3]);
|
|
1096
|
+
const d2 = (x - t[k + 4]) * (t[k + 3] - t[k + 5]) - (t[k + 2] - t[k + 4]) * (z - t[k + 5]);
|
|
1097
|
+
const d3 = (x - t[k]) * (t[k + 5] - t[k + 1]) - (t[k + 4] - t[k]) * (z - t[k + 1]);
|
|
1098
|
+
const neg = d1 < 0 || d2 < 0 || d3 < 0;
|
|
1099
|
+
const pos = d1 > 0 || d2 > 0 || d3 > 0;
|
|
1100
|
+
if (!(neg && pos))
|
|
1101
|
+
return true;
|
|
1102
|
+
}
|
|
1103
|
+
return false;
|
|
1104
|
+
}
|
|
1105
|
+
/** A ruin: only stubs of the ground-storey walls stand, torn at seeded heights. */
|
|
1106
|
+
function emitRuinStubs(p, lines, panel, cut) {
|
|
1107
|
+
const yb0 = rowTop(p, 0);
|
|
1108
|
+
for (const l of lines) {
|
|
1109
|
+
const e = l.e;
|
|
1110
|
+
for (let c = 0; c < e.cols; c++) {
|
|
1111
|
+
const u0 = c * e.colW;
|
|
1112
|
+
const u1 = (c + 1) * e.colW;
|
|
1113
|
+
const h = DESTRUCT_DIM.stubMin + (DESTRUCT_DIM.stubMax - DESTRUCT_DIM.stubMin) * unit(hashInts(p.b.hash, 0x7275, e.ring, e.i, c));
|
|
1114
|
+
const top = Math.min(p.floorBase + h, yb0, minTop(l, u0, u1));
|
|
1115
|
+
panel(l, u0, u1, p.floorBase, top, 2, true);
|
|
1116
|
+
cut(l, [u0, top], [u1, top], [0, 1, 0]);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}
|