wallhammer-web 0.0.0-stage → 0.4.1
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 +92 -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,966 @@
|
|
|
1
|
+
// Interior of a damaged structure: the destructible parts of the interior plan (slabs, partitions, stairs) and their
|
|
2
|
+
// geometry. Only a damaged structure draws it; an intact one stays exactly the plain mesh.
|
|
3
|
+
//
|
|
4
|
+
// Surfaces are written as `KIND.interior` with the room in the vertex data, so the shader paints them:
|
|
5
|
+
// s0, s1 pattern coordinates (box frame s, t on floors and ceilings; along the wall and height above the floor
|
|
6
|
+
// on walls), s2 clear height of the storey, s3 room hash;
|
|
7
|
+
// a_fac night light of the room: lowest lit-window threshold of its windows (2 = no window), own threshold, mode;
|
|
8
|
+
// a_bits finish, room type, storey;
|
|
9
|
+
// a_win daylight of the room: glazed share (0–255) and the direction it comes from (x, z bytes, 128 = none).
|
|
10
|
+
// The lowest threshold uses the same hash as the window light, so a room glows exactly when one of its windows does.
|
|
11
|
+
//
|
|
12
|
+
// The inner face of an outer wall is `KIND.wallInside`: it keeps the wall's façade data (u along the wall, wall length,
|
|
13
|
+
// height above the floor base, window and door attributes), so the shader puts the openings exactly where the outside
|
|
14
|
+
// has them. The room goes into slots the inside does not read: s3 packs room paint, lit threshold and own threshold
|
|
15
|
+
// (one byte each), a_mat.x finish | type << 2 | mode << 4, a_mat.y daylight, a_mat.w and a_win.w its direction.
|
|
16
|
+
import { PART_FLAG, PART_ROLE } from '../../base/index.js';
|
|
17
|
+
import { hashInts, unit } from '../../gen-core/index.js';
|
|
18
|
+
import { INTERIOR_DIM } from '../structure/dims.js';
|
|
19
|
+
import { DOOR_KIND, GROUND_FLOOR } from '../structure/facade.js';
|
|
20
|
+
import { ROOM_TYPE, cellAt, clipToRect, frameS, frameT, frameX, frameZ, segmentInside } from './interior-plan.js';
|
|
21
|
+
import { PART_RULE, bayKey, partitionKey, slabKey, stairKey } from '../structure/parts.js';
|
|
22
|
+
import { DAMAGE_STEP, KIND, WIN_UNIT } from '../structure/writer.js';
|
|
23
|
+
/** Finish codes the shader reads (a_bits.x). */
|
|
24
|
+
export const FINISH = { paint: 0, ceiling: 1, floor: 2, concrete: 3, stair: 4, atticWall: 5, atticFloor: 6 };
|
|
25
|
+
/** Material slots of the interior parts, appended after the structure materials. */
|
|
26
|
+
export const INTERIOR_MATERIAL = { floor: 5, partition: 6 };
|
|
27
|
+
const MAX_STOREY = 255;
|
|
28
|
+
// --- Night light ----------------------------------------------------------------------------------------------------
|
|
29
|
+
/** The GLSL `hashU` (render/glsl.ts) on 32-bit unsigned integers. */
|
|
30
|
+
function hashU(x) {
|
|
31
|
+
x >>>= 0;
|
|
32
|
+
x = (x ^ (x >>> 16)) >>> 0;
|
|
33
|
+
x = Math.imul(x, 0x7feb352d) >>> 0;
|
|
34
|
+
x = (x ^ (x >>> 15)) >>> 0;
|
|
35
|
+
x = Math.imul(x, 0x846ca68b) >>> 0;
|
|
36
|
+
return (x ^ (x >>> 16)) >>> 0;
|
|
37
|
+
}
|
|
38
|
+
/** The GLSL `hash2(ivec2(px, py), seed)`, including the float conversion of the shader. */
|
|
39
|
+
function hash2(px, py, seed) {
|
|
40
|
+
const v = hashU((Math.imul(px >>> 0, 0x9e3779b1) ^ hashU((py + Math.imul(seed >>> 0, 0x85ebca6b)) >>> 0)) >>> 0);
|
|
41
|
+
return Math.fround(v) / 4294967296;
|
|
42
|
+
}
|
|
43
|
+
/** `uint(a * b)` as the shader computes it in 32-bit floats. */
|
|
44
|
+
const f32uint = (a, b) => Math.floor(Math.fround(Math.fround(a) * b)) >>> 0;
|
|
45
|
+
/** Room behind column centre u of an edge, looking a little past the wall's inner face (-1: none). */
|
|
46
|
+
function roomBehind(ip, e, u, wallT) {
|
|
47
|
+
for (const d of [wallT + 0.35, wallT + 1]) {
|
|
48
|
+
const r = cellAt(ip, e.ax + e.dx * u - e.nx * d, e.az + e.dz * u - e.nz * d);
|
|
49
|
+
if (r >= 0 && ip.cells[r].room >= 0)
|
|
50
|
+
return ip.cells[r].room;
|
|
51
|
+
}
|
|
52
|
+
return -1;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Window light of the rooms, from the same rules the façade shader uses: the lowest lit-window threshold (the room is
|
|
56
|
+
* lit at night when the share of lit windows passes it) and the glazed area with its direction (daylight).
|
|
57
|
+
*/
|
|
58
|
+
function roomLights(p, ip, wallT) {
|
|
59
|
+
const n = ip.rooms.length * p.floors;
|
|
60
|
+
const out = { lit: new Float32Array(n).fill(2), glass: new Float32Array(n), dirX: new Float32Array(n), dirZ: new Float32Array(n) };
|
|
61
|
+
const seed = f32uint(p.mat.seed, 16777215);
|
|
62
|
+
const rec = p.rec;
|
|
63
|
+
for (const e of p.edges) {
|
|
64
|
+
const wallSeed = (seed + 77 + f32uint(e.len, 31)) >>> 0;
|
|
65
|
+
if (rec ? e.blind : p.b.windowStyle === 0 || e.len <= p.b.bayWidth * 0.7)
|
|
66
|
+
continue;
|
|
67
|
+
const doorCol = e.doors.length > 0 ? Math.floor(e.doors[0].u / e.colW) : -1;
|
|
68
|
+
const doorKind = e.doors.length > 0 ? e.doors[0].kind : 0;
|
|
69
|
+
for (let c = 0; c < e.cols; c++) {
|
|
70
|
+
const u = (c + 0.5) * e.colW;
|
|
71
|
+
const room = roomBehind(ip, e, u, wallT);
|
|
72
|
+
if (room < 0)
|
|
73
|
+
continue;
|
|
74
|
+
const doorColumn = e.doors.some((d) => Math.floor(d.u / e.colW) === c);
|
|
75
|
+
for (let f = 0; f < p.floors; f++) {
|
|
76
|
+
let row = f;
|
|
77
|
+
let factor = 1;
|
|
78
|
+
let area;
|
|
79
|
+
if (rec) {
|
|
80
|
+
if (doorColumn && rec.stairStrip && doorKind !== DOOR_KIND.garage && c === doorCol)
|
|
81
|
+
continue;
|
|
82
|
+
if (f === 0 && (rec.groundFloor === GROUND_FLOOR.blind || doorColumn))
|
|
83
|
+
continue;
|
|
84
|
+
if (f === 0 && rec.groundFloor !== GROUND_FLOOR.windows)
|
|
85
|
+
factor = 0.5;
|
|
86
|
+
const narrow = ((rec.window.narrowMask >> (c % 4)) & 1) !== 0;
|
|
87
|
+
let ww = Math.min(rec.window.width * (narrow ? 0.55 : 1), 0.86 * e.colW);
|
|
88
|
+
let wh = rec.window.height;
|
|
89
|
+
if (f === 0 && rec.groundFloor === GROUND_FLOOR.glazed) {
|
|
90
|
+
ww = Math.min(0.82 * e.colW, e.colW - 0.5);
|
|
91
|
+
wh = p.groundFloorH - 0.85;
|
|
92
|
+
}
|
|
93
|
+
else if (f === 0 && rec.groundFloor === GROUND_FLOOR.high) {
|
|
94
|
+
ww *= 0.85;
|
|
95
|
+
wh = 0.7;
|
|
96
|
+
}
|
|
97
|
+
area = Math.max(0, ww) * Math.max(0, wh);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const mid = (ip.floorY[f] + ip.floorY[f + 1]) / 2 - p.floorBase;
|
|
101
|
+
row = Math.floor(mid / p.floorHeight);
|
|
102
|
+
if (row >= p.floors)
|
|
103
|
+
continue;
|
|
104
|
+
factor = p.b.windowStyle === 1 ? 1 : 0.55;
|
|
105
|
+
const st = p.b.windowStyle;
|
|
106
|
+
const ww = st === 2 ? 0.8 : st === 3 ? 0.36 : Math.min(0.66, Math.max(0.38, 1.5 / e.colW));
|
|
107
|
+
const wh = st === 2 ? 0.48 : st === 3 ? 0.3 : Math.min(0.62, Math.max(0.3, 1.65 / p.floorHeight));
|
|
108
|
+
area = ww * e.colW * wh * p.floorHeight;
|
|
109
|
+
}
|
|
110
|
+
const h = hash2(c, row, wallSeed) / factor;
|
|
111
|
+
const k = room * p.floors + f;
|
|
112
|
+
out.lit[k] = Math.min(out.lit[k], h);
|
|
113
|
+
out.glass[k] = out.glass[k] + area;
|
|
114
|
+
out.dirX[k] = out.dirX[k] + area * e.nx;
|
|
115
|
+
out.dirZ[k] = out.dirZ[k] + area * e.nz;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
// --- Vertex data ----------------------------------------------------------------------------------------------------
|
|
122
|
+
/** Vertex data of interior surfaces per room, storey and finish. */
|
|
123
|
+
export class InteriorPaint {
|
|
124
|
+
cache = new Map();
|
|
125
|
+
lights;
|
|
126
|
+
area;
|
|
127
|
+
p;
|
|
128
|
+
ip;
|
|
129
|
+
wallT;
|
|
130
|
+
constructor(p, ip, wallT) {
|
|
131
|
+
this.p = p;
|
|
132
|
+
this.ip = ip;
|
|
133
|
+
this.wallT = wallT;
|
|
134
|
+
this.lights = roomLights(p, ip, wallT);
|
|
135
|
+
this.area = new Float32Array(ip.rooms.length);
|
|
136
|
+
ip.rooms.forEach((r, k) => {
|
|
137
|
+
for (const c of r.cells)
|
|
138
|
+
this.area[k] = this.area[k] + ip.cells[c].area;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* An opening (a breached bay) of `area` m² in the outer wall at column centre u of edge e, storey f: it lets in
|
|
143
|
+
* daylight like a window. Must be called before the first `attr`.
|
|
144
|
+
*/
|
|
145
|
+
addOpening(e, u, f, area) {
|
|
146
|
+
const room = roomBehind(this.ip, e, u, this.wallT);
|
|
147
|
+
if (room < 0 || f < 0 || f >= this.p.floors)
|
|
148
|
+
return;
|
|
149
|
+
const k = room * this.p.floors + f;
|
|
150
|
+
const L = this.lights;
|
|
151
|
+
L.glass[k] = L.glass[k] + area;
|
|
152
|
+
L.dirX[k] = L.dirX[k] + area * e.nx;
|
|
153
|
+
L.dirZ[k] = L.dirZ[k] + area * e.nz;
|
|
154
|
+
}
|
|
155
|
+
/** Room hash of a room index (-1: a neutral one). */
|
|
156
|
+
hash(room) {
|
|
157
|
+
return room >= 0 ? this.ip.rooms[room].hash : 0.5;
|
|
158
|
+
}
|
|
159
|
+
/** Daylight of a room on storey f as bytes: amount (glazed share of the floor area) and the direction it comes from (x, z, 128 = none). */
|
|
160
|
+
daylight(room, f) {
|
|
161
|
+
if (room < 0 || f >= this.p.floors)
|
|
162
|
+
return [0, 128, 128];
|
|
163
|
+
const k = room * this.p.floors + f;
|
|
164
|
+
const g = this.lights.glass[k];
|
|
165
|
+
const day = Math.min(1, g / Math.max(this.area[room], 1) / DAYLIGHT_FULL_SHARE);
|
|
166
|
+
const dx = g > 0 ? this.lights.dirX[k] / g : 0;
|
|
167
|
+
const dz = g > 0 ? this.lights.dirZ[k] / g : 0;
|
|
168
|
+
return [Math.round(day * 255), Math.round(128 + 127 * dx), Math.round(128 + 127 * dz)];
|
|
169
|
+
}
|
|
170
|
+
attr(room, f, finish) {
|
|
171
|
+
const key = ((room + 1) * 300 + Math.min(f, 299)) * 8 + finish;
|
|
172
|
+
let a = this.cache.get(key);
|
|
173
|
+
if (!a) {
|
|
174
|
+
const r = room >= 0 ? this.ip.rooms[room] : null;
|
|
175
|
+
const type = f >= this.p.floors ? ROOM_TYPE.attic : r ? r.type : ROOM_TYPE.room;
|
|
176
|
+
const lit = r && f < this.p.floors ? this.lights.lit[room * this.p.floors + f] : 2;
|
|
177
|
+
const own = unit(hashInts(this.p.b.hash, 0x6c74, room, f));
|
|
178
|
+
// Mode: 0 a room (own threshold only without windows), 1 shared space on timers, 2 never lit (roof space).
|
|
179
|
+
const mode = type === ROOM_TYPE.attic || !r ? 2 : type === ROOM_TYPE.room ? 0 : 1;
|
|
180
|
+
const [day, dx, dz] = this.daylight(room, f);
|
|
181
|
+
a = { doorU: lit, doorW: 0, doorY: own, groundFloorH: mode, win: [day * WIN_UNIT, dx * WIN_UNIT, dz * WIN_UNIT, 0], bits: [finish, type, Math.min(f, MAX_STOREY), 0], cols: [0, 0, 0, 0] };
|
|
182
|
+
this.cache.set(key, a);
|
|
183
|
+
}
|
|
184
|
+
return a;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Vertex data of the inner face of an outer wall (`KIND.wallInside`): the wall's own façade data, so the shader
|
|
188
|
+
* finds its windows and doors exactly where the outside has them, with the room packed into the slots the inside
|
|
189
|
+
* does not read (see the module comment).
|
|
190
|
+
*/
|
|
191
|
+
wallInside(room, f, finish, wall) {
|
|
192
|
+
const a = this.attr(room, f, finish);
|
|
193
|
+
const rs = f32uint(this.hash(room), 16777215) >>> 16;
|
|
194
|
+
const lit = a.doorU >= 1 ? 255 : Math.round(a.doorU * 254);
|
|
195
|
+
const own = Math.round(a.doorY * 255);
|
|
196
|
+
const [day, dx, dz] = this.daylight(room, f);
|
|
197
|
+
return {
|
|
198
|
+
mat: { ...this.p.mat, wallColor: finish | (a.bits[1] << 2) | (a.groundFloorH << 4), roofColor: day, trimColor: dx },
|
|
199
|
+
fa: { ...wall, groundFloorH: wall.groundFloorH > 0 ? wall.groundFloorH : this.p.groundFloorH, win: [wall.win[0], wall.win[1], wall.win[2], dz * WIN_UNIT] },
|
|
200
|
+
s3: rs + 256 * lit + 65536 * own,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/** Glazed share of the floor area at which a room counts as fully daylit. */
|
|
205
|
+
const DAYLIGHT_FULL_SHARE = 0.22;
|
|
206
|
+
/** Writes a convex polygon (3D points) facing along n, with per-vertex pattern coordinates. */
|
|
207
|
+
function polyOut(w, p, pts, uv, n, damage, s2, s3, fa) {
|
|
208
|
+
if (pts.length < 3)
|
|
209
|
+
return;
|
|
210
|
+
// Orientation from Newell's normal of the whole polygon.
|
|
211
|
+
let nx = 0;
|
|
212
|
+
let ny = 0;
|
|
213
|
+
let nz = 0;
|
|
214
|
+
for (let k = 0; k < pts.length; k++) {
|
|
215
|
+
const q = pts[k];
|
|
216
|
+
const r = pts[(k + 1) % pts.length];
|
|
217
|
+
nx += (q[1] - r[1]) * (q[2] + r[2]);
|
|
218
|
+
ny += (q[2] - r[2]) * (q[0] + r[0]);
|
|
219
|
+
nz += (q[0] - r[0]) * (q[1] + r[1]);
|
|
220
|
+
}
|
|
221
|
+
const flip = nx * n[0] + ny * n[1] + nz * n[2] < 0;
|
|
222
|
+
const kind = KIND.interior + DAMAGE_STEP * damage;
|
|
223
|
+
const put = (k) => {
|
|
224
|
+
const q = pts[k];
|
|
225
|
+
const t = uv[k];
|
|
226
|
+
w.push(q[0], q[1], q[2], n[0], n[1], n[2], kind, t[0], t[1], s2, s3, p.mat, p.floors, p.floorHeight, fa);
|
|
227
|
+
};
|
|
228
|
+
for (let k = 1; k + 1 < pts.length; k++) {
|
|
229
|
+
put(0);
|
|
230
|
+
if (flip) {
|
|
231
|
+
put(k + 1);
|
|
232
|
+
put(k);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
put(k);
|
|
236
|
+
put(k + 1);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/** A vertical quad from (x0, z0) to (x1, z1) between y0 and y1, facing along n; pattern u from u0. */
|
|
241
|
+
function wallQuad(w, p, x0, z0, x1, z1, y0, y1, n, u0, floorY, damage, s2, s3, fa) {
|
|
242
|
+
if (y1 - y0 < 1e-4)
|
|
243
|
+
return;
|
|
244
|
+
const len = Math.hypot(x1 - x0, z1 - z0);
|
|
245
|
+
if (len < 1e-4)
|
|
246
|
+
return;
|
|
247
|
+
polyOut(w, p, [
|
|
248
|
+
[x0, y0, z0],
|
|
249
|
+
[x1, y0, z1],
|
|
250
|
+
[x1, y1, z1],
|
|
251
|
+
[x0, y1, z0],
|
|
252
|
+
], [
|
|
253
|
+
[u0, y0 - floorY],
|
|
254
|
+
[u0 + len, y0 - floorY],
|
|
255
|
+
[u0 + len, y1 - floorY],
|
|
256
|
+
[u0, y1 - floorY],
|
|
257
|
+
], n, damage, s2, s3, fa);
|
|
258
|
+
}
|
|
259
|
+
/** A box in the box frame: [a0, a1] along `along` (s when true), [b0, b1] across, y from y0 to y1; all six faces. */
|
|
260
|
+
function frameBox(w, p, ip, alongS, a0, a1, b0, b1, y0, y1, floorY, damage, s2, s3, fa, bottom) {
|
|
261
|
+
const fr = ip.frame;
|
|
262
|
+
const P = (a, b, y) => {
|
|
263
|
+
const s = alongS ? a : b;
|
|
264
|
+
const t = alongS ? b : a;
|
|
265
|
+
return [frameX(fr, s, t), y, frameZ(fr, s, t)];
|
|
266
|
+
};
|
|
267
|
+
const dirA = alongS ? [fr.ux, 0, fr.uz] : [-fr.uz, 0, fr.ux];
|
|
268
|
+
const dirB = alongS ? [-fr.uz, 0, fr.ux] : [fr.ux, 0, fr.uz];
|
|
269
|
+
const neg = (v) => [-v[0], -v[1], -v[2]];
|
|
270
|
+
const top = [P(a0, b0, y1), P(a1, b0, y1), P(a1, b1, y1), P(a0, b1, y1)];
|
|
271
|
+
const uv = [
|
|
272
|
+
[a0, b0],
|
|
273
|
+
[a1, b0],
|
|
274
|
+
[a1, b1],
|
|
275
|
+
[a0, b1],
|
|
276
|
+
];
|
|
277
|
+
polyOut(w, p, top, uv, [0, 1, 0], damage, s2, s3, fa);
|
|
278
|
+
if (bottom)
|
|
279
|
+
polyOut(w, p, [P(a0, b0, y0), P(a1, b0, y0), P(a1, b1, y0), P(a0, b1, y0)], uv, [0, -1, 0], damage, s2, s3, fa);
|
|
280
|
+
const side = (q0, q1, n) => wallQuad(w, p, q0[0], q0[2], q1[0], q1[2], y0, y1, n, 0, floorY, damage, s2, s3, fa);
|
|
281
|
+
side(P(a0, b0, 0), P(a1, b0, 0), neg(dirB));
|
|
282
|
+
side(P(a0, b1, 0), P(a1, b1, 0), dirB);
|
|
283
|
+
side(P(a0, b0, 0), P(a0, b1, 0), neg(dirA));
|
|
284
|
+
side(P(a1, b0, 0), P(a1, b1, 0), dirA);
|
|
285
|
+
}
|
|
286
|
+
const linkCache = new WeakMap();
|
|
287
|
+
export function cellLinks(ip) {
|
|
288
|
+
let out = linkCache.get(ip);
|
|
289
|
+
if (out)
|
|
290
|
+
return out;
|
|
291
|
+
out = [];
|
|
292
|
+
const nS = ip.sCuts.length - 1;
|
|
293
|
+
const nT = ip.tCuts.length - 1;
|
|
294
|
+
const fr = ip.frame;
|
|
295
|
+
for (let i = 0; i < nS; i++) {
|
|
296
|
+
for (let j = 0; j < nT; j++) {
|
|
297
|
+
const c = i * nT + j;
|
|
298
|
+
if (ip.cells[c].area <= 0)
|
|
299
|
+
continue;
|
|
300
|
+
for (const dir of [0, 1]) {
|
|
301
|
+
const ni = dir === 0 ? i + 1 : i;
|
|
302
|
+
const nj = dir === 0 ? j : j + 1;
|
|
303
|
+
if (ni >= nS || nj >= nT)
|
|
304
|
+
continue;
|
|
305
|
+
const d = ni * nT + nj;
|
|
306
|
+
if (ip.cells[d].area <= 0)
|
|
307
|
+
continue;
|
|
308
|
+
const s0 = dir === 0 ? ip.sCuts[ni] : ip.sCuts[i];
|
|
309
|
+
const s1 = dir === 0 ? ip.sCuts[ni] : ip.sCuts[i + 1];
|
|
310
|
+
const t0 = dir === 0 ? ip.tCuts[j] : ip.tCuts[nj];
|
|
311
|
+
const t1 = dir === 0 ? ip.tCuts[j + 1] : ip.tCuts[nj];
|
|
312
|
+
const ax = frameX(fr, s0, t0);
|
|
313
|
+
const az = frameZ(fr, s0, t0);
|
|
314
|
+
const bx = frameX(fr, s1, t1);
|
|
315
|
+
const bz = frameZ(fr, s1, t1);
|
|
316
|
+
const segs = [];
|
|
317
|
+
for (const [p0, p1] of segmentInside(ip.insets, ax, az, bx, bz)) {
|
|
318
|
+
if (p1 - p0 < 1e-4)
|
|
319
|
+
continue;
|
|
320
|
+
segs.push([ax + (bx - ax) * p0, az + (bz - az) * p0, ax + (bx - ax) * p1, az + (bz - az) * p1]);
|
|
321
|
+
}
|
|
322
|
+
if (segs.length > 0)
|
|
323
|
+
out.push({ a: c, b: d, dir, segs });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
linkCache.set(ip, out);
|
|
328
|
+
return out;
|
|
329
|
+
}
|
|
330
|
+
const pieceCache = new WeakMap();
|
|
331
|
+
/** Inner wall faces split by cell (computed once per plan). */
|
|
332
|
+
function wallPieces(p, ip) {
|
|
333
|
+
let out = pieceCache.get(ip);
|
|
334
|
+
if (out)
|
|
335
|
+
return out;
|
|
336
|
+
out = [];
|
|
337
|
+
const fr = ip.frame;
|
|
338
|
+
const nT = ip.tCuts.length - 1;
|
|
339
|
+
const edgeOf = new Map(p.edges.map((e) => [e.ring * 100000 + e.i, e]));
|
|
340
|
+
ip.insets.forEach((ring, rk) => {
|
|
341
|
+
const n = ring.length / 2;
|
|
342
|
+
for (let k = 0; k < n; k++) {
|
|
343
|
+
const e = edgeOf.get(rk * 100000 + k);
|
|
344
|
+
if (!e)
|
|
345
|
+
continue;
|
|
346
|
+
const q = (k + 1) % n;
|
|
347
|
+
const a = [frameS(fr, ring[k * 2], ring[k * 2 + 1]), frameT(fr, ring[k * 2], ring[k * 2 + 1])];
|
|
348
|
+
const b = [frameS(fr, ring[q * 2], ring[q * 2 + 1]), frameT(fr, ring[q * 2], ring[q * 2 + 1])];
|
|
349
|
+
const sLo = Math.min(a[0], b[0]);
|
|
350
|
+
const sHi = Math.max(a[0], b[0]);
|
|
351
|
+
const tLo = Math.min(a[1], b[1]);
|
|
352
|
+
const tHi = Math.max(a[1], b[1]);
|
|
353
|
+
ip.cells.forEach((cell, c) => {
|
|
354
|
+
if (cell.area <= 0)
|
|
355
|
+
return;
|
|
356
|
+
const i = Math.floor(c / nT);
|
|
357
|
+
const j = c % nT;
|
|
358
|
+
const rect = { s0: ip.sCuts[i], s1: ip.sCuts[i + 1], t0: ip.tCuts[j], t1: ip.tCuts[j + 1] };
|
|
359
|
+
if (rect.s1 < sLo - 1e-6 || rect.s0 > sHi + 1e-6 || rect.t1 < tLo - 1e-6 || rect.t0 > tHi + 1e-6)
|
|
360
|
+
return;
|
|
361
|
+
const seg = clipSeg(a, b, rect);
|
|
362
|
+
if (!seg)
|
|
363
|
+
return;
|
|
364
|
+
const x0 = frameX(fr, seg[0], seg[1]);
|
|
365
|
+
const z0 = frameZ(fr, seg[0], seg[1]);
|
|
366
|
+
const x1 = frameX(fr, seg[2], seg[3]);
|
|
367
|
+
const z1 = frameZ(fr, seg[2], seg[3]);
|
|
368
|
+
out.push({ cell: c, e, x0, z0, x1, z1, u0: (x0 - e.ax) * e.dx + (z0 - e.az) * e.dz, u1: (x1 - e.ax) * e.dx + (z1 - e.az) * e.dz });
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
pieceCache.set(ip, out);
|
|
373
|
+
return out;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Which rooms can be seen into, per storey: `open[f * rooms + room]` is 1. Index `floors` is the space under a
|
|
377
|
+
* pitched roof. A room opens behind a breached or gone outer bay, above and below a gone slab, under a gone roof
|
|
378
|
+
* section; it passes the view on through gone partitions, and one step further through a door. The stair core is
|
|
379
|
+
* open on every storey or on none. Rooms that stay closed draw nothing: only exposed rooms cost triangles.
|
|
380
|
+
*/
|
|
381
|
+
export function interiorExposure(p, ip, ctx) {
|
|
382
|
+
const nR = ip.rooms.length;
|
|
383
|
+
const F = p.floors;
|
|
384
|
+
const open = new Uint8Array((F + 1) * nR);
|
|
385
|
+
if (!ip.ok || nR === 0)
|
|
386
|
+
return open;
|
|
387
|
+
const fits = interiorFits(p, ip);
|
|
388
|
+
const lv = (key) => (fits ? ctx.level(key) : 0);
|
|
389
|
+
const roomOf = (c) => (c >= 0 ? ip.cells[c].room : -1);
|
|
390
|
+
const mark = (f, r) => {
|
|
391
|
+
if (r >= 0 && f >= 0 && f <= F)
|
|
392
|
+
open[f * nR + r] = 1;
|
|
393
|
+
};
|
|
394
|
+
const nT = ip.tCuts.length - 1;
|
|
395
|
+
// Behind open bays of the outer walls.
|
|
396
|
+
for (const pc of wallPieces(p, ip)) {
|
|
397
|
+
const r = roomOf(pc.cell);
|
|
398
|
+
if (r < 0)
|
|
399
|
+
continue;
|
|
400
|
+
const ua = Math.min(pc.u0, pc.u1);
|
|
401
|
+
const ub = Math.max(pc.u0, pc.u1);
|
|
402
|
+
const e = pc.e;
|
|
403
|
+
for (let f = 0; f < F; f++) {
|
|
404
|
+
if (open[f * nR + r])
|
|
405
|
+
continue;
|
|
406
|
+
for (let col = Math.max(0, Math.floor(ua / e.colW)); col < e.cols && col * e.colW < ub; col++) {
|
|
407
|
+
if (ctx.bayOpen(e, col, f)) {
|
|
408
|
+
mark(f, r);
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
// Under gone roof sections: the top storey of a flat roof, the roof space of a pitched one.
|
|
415
|
+
for (const g of ctx.roofGone) {
|
|
416
|
+
if (!p.flat) {
|
|
417
|
+
for (let r = 0; r < nR; r++)
|
|
418
|
+
mark(F, r);
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
ip.cells.forEach((cell, c) => {
|
|
422
|
+
if (cell.area <= 0)
|
|
423
|
+
return;
|
|
424
|
+
const i = Math.floor(c / nT);
|
|
425
|
+
const j = c % nT;
|
|
426
|
+
if (ip.sCuts[i + 1] <= g.s0 || ip.sCuts[i] >= g.s1 || ip.tCuts[j + 1] <= g.t0 || ip.tCuts[j] >= g.t1)
|
|
427
|
+
return;
|
|
428
|
+
mark(F - 1, cell.room);
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
// Above and below gone slabs.
|
|
432
|
+
const top = topSlab(p);
|
|
433
|
+
for (let f = 1; f <= top; f++) {
|
|
434
|
+
ip.cells.forEach((cell, c) => {
|
|
435
|
+
if (cell.area <= 0 || cell.room < 0)
|
|
436
|
+
return;
|
|
437
|
+
if (lv(slabKey(f, Math.floor(c / nT), c % nT)) >= 0)
|
|
438
|
+
return;
|
|
439
|
+
mark(f - 1, cell.room);
|
|
440
|
+
mark(f, cell.room);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
const isOpen = (f, r) => r >= 0 && open[f * nR + r] === 1;
|
|
444
|
+
const core = ip.core ? roomOf(ip.core.cell) : -1;
|
|
445
|
+
const coreRule = () => {
|
|
446
|
+
if (core < 0)
|
|
447
|
+
return;
|
|
448
|
+
let any = false;
|
|
449
|
+
for (let f = 0; f < F; f++)
|
|
450
|
+
any ||= isOpen(f, core);
|
|
451
|
+
if (any)
|
|
452
|
+
for (let f = 0; f < F; f++)
|
|
453
|
+
mark(f, core);
|
|
454
|
+
};
|
|
455
|
+
// Through gone partitions, until nothing changes.
|
|
456
|
+
for (let changed = true; changed;) {
|
|
457
|
+
changed = false;
|
|
458
|
+
coreRule();
|
|
459
|
+
for (let f = 0; f < F; f++) {
|
|
460
|
+
for (const q of ip.partitions) {
|
|
461
|
+
const a = roomOf(q.cellA);
|
|
462
|
+
const b = roomOf(q.cellB);
|
|
463
|
+
if (a < 0 || b < 0 || isOpen(f, a) === isOpen(f, b))
|
|
464
|
+
continue;
|
|
465
|
+
if (lv(partitionKey(f, q.dir, q.i, q.j)) >= 0)
|
|
466
|
+
continue;
|
|
467
|
+
mark(f, a);
|
|
468
|
+
mark(f, b);
|
|
469
|
+
changed = true;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
// One step through doors.
|
|
474
|
+
const before = open.slice();
|
|
475
|
+
for (let f = 0; f < F; f++) {
|
|
476
|
+
for (const q of ip.partitions) {
|
|
477
|
+
if (!q.door)
|
|
478
|
+
continue;
|
|
479
|
+
const a = roomOf(q.cellA);
|
|
480
|
+
const b = roomOf(q.cellB);
|
|
481
|
+
if (a < 0 || b < 0)
|
|
482
|
+
continue;
|
|
483
|
+
if (before[f * nR + a])
|
|
484
|
+
mark(f, b);
|
|
485
|
+
if (before[f * nR + b])
|
|
486
|
+
mark(f, a);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
coreRule();
|
|
490
|
+
return open;
|
|
491
|
+
}
|
|
492
|
+
/** Top slab level: the slab under the roof space of a pitched roof, else the last floor slab. */
|
|
493
|
+
export const topSlab = (p) => (p.flat ? p.floors - 1 : p.floors);
|
|
494
|
+
/** The stair hole of slab `f` in the core cell (box frame), or null. */
|
|
495
|
+
function stairHole(p, ip, f) {
|
|
496
|
+
const core = ip.core;
|
|
497
|
+
if (!core || f < 1 || f > p.floors - 1)
|
|
498
|
+
return null;
|
|
499
|
+
const g = stairGeometry(p, ip);
|
|
500
|
+
if (!g)
|
|
501
|
+
return null;
|
|
502
|
+
const r = core.rect;
|
|
503
|
+
if (core.alongS)
|
|
504
|
+
return core.startLow ? { s0: r.s0 + g.ls, s1: r.s1, t0: r.t0, t1: r.t1 } : { s0: r.s0, s1: r.s1 - g.ls, t0: r.t0, t1: r.t1 };
|
|
505
|
+
return core.startLow ? { s0: r.s0, s1: r.s1, t0: r.t0 + g.ls, t1: r.t1 } : { s0: r.s0, s1: r.s1, t0: r.t0, t1: r.t1 - g.ls };
|
|
506
|
+
}
|
|
507
|
+
/** Shared stair dimensions of all storeys: tread, start landing length, flight A side. */
|
|
508
|
+
function stairGeometry(p, ip) {
|
|
509
|
+
const core = ip.core;
|
|
510
|
+
if (!core)
|
|
511
|
+
return null;
|
|
512
|
+
const D = INTERIOR_DIM;
|
|
513
|
+
const r = core.rect;
|
|
514
|
+
const L = core.alongS ? r.s1 - r.s0 : r.t1 - r.t0;
|
|
515
|
+
let nAmax = 1;
|
|
516
|
+
for (let f = 0; f + 1 < p.floors; f++) {
|
|
517
|
+
const n = Math.max(2, Math.ceil((ip.floorY[f + 1] - ip.floorY[f]) / D.stairRise - 1e-6));
|
|
518
|
+
nAmax = Math.max(nAmax, Math.ceil(n / 2));
|
|
519
|
+
}
|
|
520
|
+
const tread = Math.max(0.12, Math.min(D.treadMax, (L - 2 * D.landingMin) / nAmax));
|
|
521
|
+
const ls = Math.max(0.5, (L - nAmax * tread) / 2);
|
|
522
|
+
return { tread, ls, aLow: unit(hashInts(p.b.hash, 0x5374)) < 0.5 };
|
|
523
|
+
}
|
|
524
|
+
/** Convex hull (x, z pairs) of points. */
|
|
525
|
+
function hull(pts) {
|
|
526
|
+
const ps = [];
|
|
527
|
+
for (let k = 0; k < pts.length; k += 2)
|
|
528
|
+
ps.push([pts[k], pts[k + 1]]);
|
|
529
|
+
ps.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
530
|
+
if (ps.length < 3)
|
|
531
|
+
return pts;
|
|
532
|
+
const cross = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
|
|
533
|
+
const lower = [];
|
|
534
|
+
for (const q of ps) {
|
|
535
|
+
while (lower.length >= 2 && cross(lower[lower.length - 2], lower[lower.length - 1], q) <= 0)
|
|
536
|
+
lower.pop();
|
|
537
|
+
lower.push(q);
|
|
538
|
+
}
|
|
539
|
+
const upper = [];
|
|
540
|
+
for (let k = ps.length - 1; k >= 0; k--) {
|
|
541
|
+
const q = ps[k];
|
|
542
|
+
while (upper.length >= 2 && cross(upper[upper.length - 2], upper[upper.length - 1], q) <= 0)
|
|
543
|
+
upper.pop();
|
|
544
|
+
upper.push(q);
|
|
545
|
+
}
|
|
546
|
+
return [...lower.slice(0, -1), ...upper.slice(0, -1)].flat();
|
|
547
|
+
}
|
|
548
|
+
/** Seg endpoints in world x, z. */
|
|
549
|
+
function segXZ(ip, sg) {
|
|
550
|
+
const fr = ip.frame;
|
|
551
|
+
return [frameX(fr, sg.s0, sg.t0), frameZ(fr, sg.s0, sg.t0), frameX(fr, sg.s1, sg.t1), frameZ(fr, sg.s1, sg.t1)];
|
|
552
|
+
}
|
|
553
|
+
/** Does the key layout hold every interior part of the plan? */
|
|
554
|
+
export function interiorFits(p, ip) {
|
|
555
|
+
return slabKey(topSlab(p), ip.sCuts.length, ip.tCuts.length) >= 0 && partitionKey(p.floors, 1, ip.sCuts.length, ip.tCuts.length) >= 0;
|
|
556
|
+
}
|
|
557
|
+
/** Slabs, partitions and stairs as parts with bonds: slabs rest on the walls and partitions under them. */
|
|
558
|
+
export function describeInterior(p, ip, ctx) {
|
|
559
|
+
if (!ip.ok || !interiorFits(p, ip))
|
|
560
|
+
return;
|
|
561
|
+
const D = INTERIOR_DIM;
|
|
562
|
+
const nT = ip.tCuts.length - 1;
|
|
563
|
+
const ij = (c) => [Math.floor(c / nT), c % nT];
|
|
564
|
+
const slab = (f, c) => {
|
|
565
|
+
const [i, j] = ij(c);
|
|
566
|
+
return slabKey(f, i, j);
|
|
567
|
+
};
|
|
568
|
+
const live = (c) => ip.cells[c].area > 0;
|
|
569
|
+
const top = topSlab(p);
|
|
570
|
+
const links = cellLinks(ip);
|
|
571
|
+
// Slabs.
|
|
572
|
+
for (let f = 1; f <= top; f++) {
|
|
573
|
+
const y1 = ip.floorY[f];
|
|
574
|
+
ip.cells.forEach((cell, c) => {
|
|
575
|
+
if (!live(c))
|
|
576
|
+
return;
|
|
577
|
+
const pts = hull(cell.polys.flat());
|
|
578
|
+
ctx.add(slab(f, c), PART_ROLE.span, INTERIOR_MATERIAL.floor, cell.area * D.slab * 2400, ctx.piece(pts, y1 - D.slab, y1), PART_FLAG.inner, 1);
|
|
579
|
+
});
|
|
580
|
+
for (const l of links) {
|
|
581
|
+
const [x0, z0, x1, z1] = l.segs[0];
|
|
582
|
+
ctx.bond(slab(f, l.a), slab(f, l.b), false, (x0 + x1) / 2, y1 - D.slab / 2, (z0 + z1) / 2, Math.hypot(x1 - x0, z1 - z0) * D.slab);
|
|
583
|
+
}
|
|
584
|
+
// On the outer walls of the storey below: three points per bay just inside the wall.
|
|
585
|
+
for (const e of p.edges) {
|
|
586
|
+
for (let c = 0; c < e.cols; c++) {
|
|
587
|
+
const bay = bayKey(PART_RULE.wall, e.ring, e.i, c, f - 1);
|
|
588
|
+
for (const sm of [0.2, 0.5, 0.8]) {
|
|
589
|
+
const u = (c + sm) * e.colW;
|
|
590
|
+
const x = e.ax + e.dx * u - e.nx * (ctx.wallT + 0.4);
|
|
591
|
+
const z = e.az + e.dz * u - e.nz * (ctx.wallT + 0.4);
|
|
592
|
+
const cc = cellAt(ip, x, z);
|
|
593
|
+
if (cc >= 0 && live(cc))
|
|
594
|
+
ctx.bond(bay, slab(f, cc), true, x, y1 - D.slab, z, e.colW * ctx.wallT);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
// Partitions: rest on the slab cells on both sides (or the ground) and carry nothing: they are not load-bearing,
|
|
600
|
+
// so a slab whose outer walls are gone falls even with partitions under it, and takes the partitions on it along.
|
|
601
|
+
for (let f = 0; f < p.floors; f++) {
|
|
602
|
+
for (const q of ip.partitions) {
|
|
603
|
+
const key = partitionKey(f, q.dir, q.i, q.j);
|
|
604
|
+
const pts = [];
|
|
605
|
+
let len = 0;
|
|
606
|
+
for (const sg of q.segs) {
|
|
607
|
+
const [x0, z0, x1, z1] = segXZ(ip, sg);
|
|
608
|
+
const l = Math.hypot(x1 - x0, z1 - z0) || 1;
|
|
609
|
+
len += l;
|
|
610
|
+
const ox = (-(z1 - z0) / l) * (D.partition / 2);
|
|
611
|
+
const oz = ((x1 - x0) / l) * (D.partition / 2);
|
|
612
|
+
pts.push(x0 + ox, z0 + oz, x0 - ox, z0 - oz, x1 + ox, z1 + oz, x1 - ox, z1 - oz);
|
|
613
|
+
}
|
|
614
|
+
const y0 = ip.floorY[f];
|
|
615
|
+
const y1 = ip.ceilY[f];
|
|
616
|
+
ctx.add(key, PART_ROLE.bearing, INTERIOR_MATERIAL.partition, len * (y1 - y0) * D.partition * 1500, ctx.piece(hull(pts), y0, y1), PART_FLAG.inner, 0);
|
|
617
|
+
const [mx0, mz0, mx1, mz1] = segXZ(ip, q.segs[0]);
|
|
618
|
+
const mx = (mx0 + mx1) / 2;
|
|
619
|
+
const mz = (mz0 + mz1) / 2;
|
|
620
|
+
const area = len * D.partition;
|
|
621
|
+
if (f === 0)
|
|
622
|
+
ctx.bond(ctx.foundation, key, true, mx, y0, mz, area);
|
|
623
|
+
else
|
|
624
|
+
for (const c of [q.cellA, q.cellB])
|
|
625
|
+
ctx.bond(slab(f, c), key, true, mx, y0, mz, area / 2);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
// Stairs: one flight pair per storey, resting on the core cell's floor.
|
|
629
|
+
const core = ip.core;
|
|
630
|
+
if (core) {
|
|
631
|
+
const r = core.rect;
|
|
632
|
+
const corners = [frameX(ip.frame, r.s0, r.t0), frameZ(ip.frame, r.s0, r.t0), frameX(ip.frame, r.s1, r.t0), frameZ(ip.frame, r.s1, r.t0), frameX(ip.frame, r.s1, r.t1), frameZ(ip.frame, r.s1, r.t1), frameX(ip.frame, r.s0, r.t1), frameZ(ip.frame, r.s0, r.t1)];
|
|
633
|
+
const cx = frameX(ip.frame, (r.s0 + r.s1) / 2, (r.t0 + r.t1) / 2);
|
|
634
|
+
const cz = frameZ(ip.frame, (r.s0 + r.s1) / 2, (r.t0 + r.t1) / 2);
|
|
635
|
+
const area = (r.s1 - r.s0) * (r.t1 - r.t0);
|
|
636
|
+
for (let f = 0; f + 1 < p.floors; f++) {
|
|
637
|
+
const key = stairKey(f);
|
|
638
|
+
const y0 = ip.floorY[f];
|
|
639
|
+
const y1 = ip.floorY[f + 1];
|
|
640
|
+
ctx.add(key, PART_ROLE.fixture, INTERIOR_MATERIAL.floor, area * 0.25 * 2400, ctx.piece(corners, y0, y1), PART_FLAG.inner, 0);
|
|
641
|
+
ctx.bond(f === 0 ? ctx.foundation : slab(f, core.cell), key, true, cx, y0, cz, area);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
/** Writes slabs, partitions and stairs of a damaged structure. */
|
|
646
|
+
export function emitInterior(w, p, ip, paint, ctx) {
|
|
647
|
+
if (!ip.ok)
|
|
648
|
+
return;
|
|
649
|
+
const D = INTERIOR_DIM;
|
|
650
|
+
const fits = interiorFits(p, ip);
|
|
651
|
+
const lv = (key) => (fits ? ctx.level(key) : 0);
|
|
652
|
+
const fr = ip.frame;
|
|
653
|
+
const nT = ip.tCuts.length - 1;
|
|
654
|
+
const ij = (c) => [Math.floor(c / nT), c % nT];
|
|
655
|
+
const top = topSlab(p);
|
|
656
|
+
const live = (c) => ip.cells[c].area > 0;
|
|
657
|
+
const slabLevel = (f, c) => {
|
|
658
|
+
if (f === 0)
|
|
659
|
+
return 0;
|
|
660
|
+
const [i, j] = ij(c);
|
|
661
|
+
return lv(slabKey(f, i, j));
|
|
662
|
+
};
|
|
663
|
+
const links = cellLinks(ip);
|
|
664
|
+
const nR = ip.rooms.length;
|
|
665
|
+
const isOpen = (f, r) => r >= 0 && f >= 0 && ctx.open[f * nR + r] === 1;
|
|
666
|
+
const piecesOf = new Map();
|
|
667
|
+
for (const pc of wallPieces(p, ip)) {
|
|
668
|
+
const list = piecesOf.get(pc.cell);
|
|
669
|
+
if (list)
|
|
670
|
+
list.push(pc);
|
|
671
|
+
else
|
|
672
|
+
piecesOf.set(pc.cell, [pc]);
|
|
673
|
+
}
|
|
674
|
+
const down = [0, -1, 0];
|
|
675
|
+
const up = [0, 1, 0];
|
|
676
|
+
// --- Slabs: floor on top, ceiling of the storey below underneath, cut edges where a neighbour is gone.
|
|
677
|
+
for (let f = 0; f <= top; f++) {
|
|
678
|
+
const yTop = ip.floorY[f];
|
|
679
|
+
const yBot = yTop - D.slab;
|
|
680
|
+
const hole = stairHole(p, ip, f);
|
|
681
|
+
const atticLevel = f >= p.floors;
|
|
682
|
+
ip.cells.forEach((cell, c) => {
|
|
683
|
+
if (!live(c))
|
|
684
|
+
return;
|
|
685
|
+
const level = slabLevel(f, c);
|
|
686
|
+
if (level < 0)
|
|
687
|
+
return;
|
|
688
|
+
const room = cell.room;
|
|
689
|
+
const showTop = isOpen(f, room);
|
|
690
|
+
const showBottom = f > 0 && isOpen(f - 1, room);
|
|
691
|
+
if (!showTop && !showBottom)
|
|
692
|
+
return;
|
|
693
|
+
const floorFa = paint.attr(room, f, atticLevel ? FINISH.atticFloor : FINISH.floor);
|
|
694
|
+
const ceilFa = f > 0 ? paint.attr(room, f - 1, FINISH.ceiling) : null;
|
|
695
|
+
const hTop = atticLevel ? 3 : ip.ceilY[f] - yTop;
|
|
696
|
+
const hBelow = f > 0 ? ip.ceilY[f - 1] - ip.floorY[f - 1] : 0;
|
|
697
|
+
for (const poly of cell.polys) {
|
|
698
|
+
let pieces = [];
|
|
699
|
+
const st = [];
|
|
700
|
+
for (let k = 0; k < poly.length; k += 2)
|
|
701
|
+
st.push([frameS(fr, poly[k], poly[k + 1]), frameT(fr, poly[k], poly[k + 1])]);
|
|
702
|
+
if (hole && c === ip.core.cell) {
|
|
703
|
+
const big = 1e5;
|
|
704
|
+
for (const r of [
|
|
705
|
+
{ s0: -big, s1: hole.s0, t0: -big, t1: big },
|
|
706
|
+
{ s0: hole.s1, s1: big, t0: -big, t1: big },
|
|
707
|
+
{ s0: hole.s0, s1: hole.s1, t0: -big, t1: hole.t0 },
|
|
708
|
+
{ s0: hole.s0, s1: hole.s1, t0: hole.t1, t1: big },
|
|
709
|
+
]) {
|
|
710
|
+
const q = clipToRect(st, r);
|
|
711
|
+
if (q.length >= 3)
|
|
712
|
+
pieces.push(q);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
else
|
|
716
|
+
pieces = [st];
|
|
717
|
+
for (const q of pieces) {
|
|
718
|
+
const pts = (y) => q.map((v) => [frameX(fr, v[0], v[1]), y, frameZ(fr, v[0], v[1])]);
|
|
719
|
+
const uv = q.map((v) => [v[0], v[1]]);
|
|
720
|
+
if (showTop)
|
|
721
|
+
polyOut(w, p, pts(yTop), uv, up, level, hTop, paint.hash(room), floorFa);
|
|
722
|
+
if (ceilFa && showBottom)
|
|
723
|
+
polyOut(w, p, pts(yBot), uv, down, level, hBelow, paint.hash(room), ceilFa);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
if (f === 0)
|
|
727
|
+
return;
|
|
728
|
+
const edgeFa = paint.attr(room, f, FINISH.concrete);
|
|
729
|
+
const edge = (x0, z0, x1, z1, n) => wallQuad(w, p, x0, z0, x1, z1, yBot, yTop, n, 0, yBot, level, 1, paint.hash(room), edgeFa);
|
|
730
|
+
// Hole edges, facing into the hole.
|
|
731
|
+
if (hole && c === ip.core.cell) {
|
|
732
|
+
const P = (s, t) => [frameX(fr, s, t), frameZ(fr, s, t)];
|
|
733
|
+
const sx = [fr.ux, 0, fr.uz];
|
|
734
|
+
const tx = [-fr.uz, 0, fr.ux];
|
|
735
|
+
const neg = (v) => [-v[0], -v[1], -v[2]];
|
|
736
|
+
const e4 = [
|
|
737
|
+
[P(hole.s0, hole.t0), P(hole.s0, hole.t1), sx],
|
|
738
|
+
[P(hole.s1, hole.t0), P(hole.s1, hole.t1), neg(sx)],
|
|
739
|
+
[P(hole.s0, hole.t0), P(hole.s1, hole.t0), tx],
|
|
740
|
+
[P(hole.s0, hole.t1), P(hole.s1, hole.t1), neg(tx)],
|
|
741
|
+
];
|
|
742
|
+
for (const [a, b, n] of e4)
|
|
743
|
+
edge(a[0], a[1], b[0], b[1], n);
|
|
744
|
+
}
|
|
745
|
+
// Cut edges towards gone neighbours.
|
|
746
|
+
for (const l of links) {
|
|
747
|
+
if (l.a !== c && l.b !== c)
|
|
748
|
+
continue;
|
|
749
|
+
const other = l.a === c ? l.b : l.a;
|
|
750
|
+
if (slabLevel(f, other) >= 0)
|
|
751
|
+
continue;
|
|
752
|
+
const sign = l.a === c ? 1 : -1;
|
|
753
|
+
const n = l.dir === 0 ? [fr.ux * sign, 0, fr.uz * sign] : [-fr.uz * sign, 0, fr.ux * sign];
|
|
754
|
+
for (const [x0, z0, x1, z1] of l.segs)
|
|
755
|
+
edge(x0, z0, x1, z1, n);
|
|
756
|
+
}
|
|
757
|
+
// Edge along the outer wall where the bay in front of the slab is gone.
|
|
758
|
+
for (const pc of piecesOf.get(c) ?? []) {
|
|
759
|
+
const e = pc.e;
|
|
760
|
+
const ua = Math.min(pc.u0, pc.u1);
|
|
761
|
+
const ub = Math.max(pc.u0, pc.u1);
|
|
762
|
+
for (let col = Math.max(0, Math.floor(ua / e.colW)); col < e.cols && col * e.colW < ub; col++) {
|
|
763
|
+
if (!ctx.bayGone(e, col, f - 1) && !(f < p.floors && ctx.bayGone(e, col, f)))
|
|
764
|
+
continue;
|
|
765
|
+
const c0 = Math.max(ua, col * e.colW);
|
|
766
|
+
const c1 = Math.min(ub, (col + 1) * e.colW);
|
|
767
|
+
if (c1 - c0 < 1e-3)
|
|
768
|
+
continue;
|
|
769
|
+
const ta = (c0 - pc.u0) / (pc.u1 - pc.u0 || 1);
|
|
770
|
+
const tb = (c1 - pc.u0) / (pc.u1 - pc.u0 || 1);
|
|
771
|
+
edge(pc.x0 + (pc.x1 - pc.x0) * ta, pc.z0 + (pc.z1 - pc.z0) * ta, pc.x0 + (pc.x1 - pc.x0) * tb, pc.z0 + (pc.z1 - pc.z0) * tb, [e.nx, 0, e.nz]);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
// --- Partitions.
|
|
777
|
+
for (let f = 0; f < p.floors; f++) {
|
|
778
|
+
const y0 = ip.floorY[f];
|
|
779
|
+
const y1 = ip.ceilY[f];
|
|
780
|
+
const h = y1 - y0;
|
|
781
|
+
for (const q of ip.partitions) {
|
|
782
|
+
const sideA = isOpen(f, ip.cells[q.cellA].room);
|
|
783
|
+
const sideB = isOpen(f, ip.cells[q.cellB].room);
|
|
784
|
+
if (!sideA && !sideB)
|
|
785
|
+
continue;
|
|
786
|
+
const level = lv(partitionKey(f, q.dir, q.i, q.j));
|
|
787
|
+
if (level < 0)
|
|
788
|
+
continue;
|
|
789
|
+
partition(w, p, ip, paint, q, f, y0, y1, h, level, sideA, sideB);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
// --- Stairs.
|
|
793
|
+
const core = ip.core;
|
|
794
|
+
const g = stairGeometry(p, ip);
|
|
795
|
+
if (core && g) {
|
|
796
|
+
const r = core.rect;
|
|
797
|
+
const a0 = core.alongS ? r.s0 : r.t0;
|
|
798
|
+
const a1 = core.alongS ? r.s1 : r.t1;
|
|
799
|
+
const b0 = core.alongS ? r.t0 : r.s0;
|
|
800
|
+
const b1 = core.alongS ? r.t1 : r.s1;
|
|
801
|
+
const L = a1 - a0;
|
|
802
|
+
const bm = (b0 + b1) / 2;
|
|
803
|
+
const gap = D.flightGap / 2;
|
|
804
|
+
// Along-axis position from the start end.
|
|
805
|
+
const A = (d) => (core.startLow ? a0 + d : a1 - d);
|
|
806
|
+
const room = ip.cells[core.cell].room;
|
|
807
|
+
const fa = (f) => paint.attr(room, f, FINISH.stair);
|
|
808
|
+
const [bA0, bA1, bB0, bB1] = g.aLow ? [b0, bm - gap, bm + gap, b1] : [bm + gap, b1, b0, bm - gap];
|
|
809
|
+
for (let f = 0; f + 1 < p.floors; f++) {
|
|
810
|
+
if (!isOpen(f, room))
|
|
811
|
+
continue;
|
|
812
|
+
const level = lv(stairKey(f));
|
|
813
|
+
if (level < 0)
|
|
814
|
+
continue;
|
|
815
|
+
const yf = ip.floorY[f];
|
|
816
|
+
const H = ip.floorY[f + 1] - yf;
|
|
817
|
+
const n = Math.max(2, Math.ceil(H / D.stairRise - 1e-6));
|
|
818
|
+
const rise = H / n;
|
|
819
|
+
const nA = Math.ceil(n / 2);
|
|
820
|
+
const nB = n - nA;
|
|
821
|
+
const s2 = ip.ceilY[f] - yf;
|
|
822
|
+
const s3 = paint.hash(room);
|
|
823
|
+
const box = (d0, d1, ba, bb, ya, yb) => {
|
|
824
|
+
const x0 = Math.min(A(d0), A(d1));
|
|
825
|
+
const x1 = Math.max(A(d0), A(d1));
|
|
826
|
+
frameBox(w, p, ip, core.alongS, x0, x1, ba, bb, ya, yb, yf, level, s2, s3, fa(f), true);
|
|
827
|
+
};
|
|
828
|
+
// Flight A up to the landing at the far end.
|
|
829
|
+
for (let k = 0; k + 1 < nA; k++) {
|
|
830
|
+
const t = yf + (k + 1) * rise;
|
|
831
|
+
box(g.ls + k * g.tread, g.ls + (k + 1) * g.tread, bA0, bA1, Math.max(yf, t - rise - 0.16), t);
|
|
832
|
+
}
|
|
833
|
+
const yl = yf + nA * rise;
|
|
834
|
+
box(g.ls + (nA - 1) * g.tread, L, b0, b1, yl - 0.2, yl);
|
|
835
|
+
// Flight B back to the start end, arriving on the slab above.
|
|
836
|
+
const lb = g.ls + (nA - 1) * g.tread;
|
|
837
|
+
for (let k = 0; k < nB - 1; k++) {
|
|
838
|
+
const t = yl + (k + 1) * rise;
|
|
839
|
+
const dEnd = k === nB - 2 ? g.ls : lb - (k + 1) * g.tread;
|
|
840
|
+
box(Math.min(dEnd, lb - (k + 1) * g.tread), lb - k * g.tread, bB0, bB1, t - rise - 0.16, t);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
/** Clips the segment a–b (frame s, t) to a rectangle; null when nothing is left. */
|
|
846
|
+
function clipSeg(a, b, r) {
|
|
847
|
+
let t0 = 0;
|
|
848
|
+
let t1 = 1;
|
|
849
|
+
const d = [b[0] - a[0], b[1] - a[1]];
|
|
850
|
+
const lims = [
|
|
851
|
+
[0, r.s0, 1],
|
|
852
|
+
[0, r.s1, -1],
|
|
853
|
+
[1, r.t0, 1],
|
|
854
|
+
[1, r.t1, -1],
|
|
855
|
+
];
|
|
856
|
+
for (const [ax, lim, sign] of lims) {
|
|
857
|
+
const p0 = sign * (a[ax] - lim);
|
|
858
|
+
const dp = sign * d[ax];
|
|
859
|
+
if (Math.abs(dp) < 1e-12) {
|
|
860
|
+
if (p0 < -1e-6)
|
|
861
|
+
return null;
|
|
862
|
+
continue;
|
|
863
|
+
}
|
|
864
|
+
const t = -p0 / dp;
|
|
865
|
+
if (dp > 0)
|
|
866
|
+
t0 = Math.max(t0, t);
|
|
867
|
+
else
|
|
868
|
+
t1 = Math.min(t1, t);
|
|
869
|
+
}
|
|
870
|
+
if (t1 - t0 < 1e-6)
|
|
871
|
+
return null;
|
|
872
|
+
return [a[0] + d[0] * t0, a[1] + d[1] * t0, a[0] + d[0] * t1, a[1] + d[1] * t1];
|
|
873
|
+
}
|
|
874
|
+
/** One partition in storey f: the painted sides facing open rooms, a door opening with jambs and a soffit, ends and top. */
|
|
875
|
+
function partition(w, p, ip, paint, q, f, y0, y1, h, level, sideA, sideB) {
|
|
876
|
+
const D = INTERIOR_DIM;
|
|
877
|
+
const half = D.partition / 2;
|
|
878
|
+
const roomA = ip.cells[q.cellA].room;
|
|
879
|
+
const roomB = ip.cells[q.cellB].room;
|
|
880
|
+
const faA = paint.attr(roomA, f, FINISH.paint);
|
|
881
|
+
const faB = paint.attr(roomB, f, FINISH.paint);
|
|
882
|
+
q.segs.forEach((sg, k) => {
|
|
883
|
+
const [x0, z0, x1, z1] = segXZ(ip, sg);
|
|
884
|
+
const len = Math.hypot(x1 - x0, z1 - z0);
|
|
885
|
+
if (len < 1e-3)
|
|
886
|
+
return;
|
|
887
|
+
const dx = (x1 - x0) / len;
|
|
888
|
+
const dz = (z1 - z0) / len;
|
|
889
|
+
// Side normal towards cell B: +s for a cut across, +t for a run along.
|
|
890
|
+
const nB = q.dir === 0 ? [ip.frame.ux, 0, ip.frame.uz] : [-ip.frame.uz, 0, ip.frame.ux];
|
|
891
|
+
const nA = [-nB[0], 0, -nB[2]];
|
|
892
|
+
const at = (d, side) => [x0 + dx * d + nB[0] * half * side, z0 + dz * d + nB[2] * half * side];
|
|
893
|
+
// A door to a room that stays closed is drawn shut: nothing is drawn behind it.
|
|
894
|
+
const door = q.door && q.door.seg === k && sideA && sideB ? q.door : null;
|
|
895
|
+
const spans = door
|
|
896
|
+
? [
|
|
897
|
+
[0, door.at - door.width / 2, y0],
|
|
898
|
+
[door.at - door.width / 2, door.at + door.width / 2, Math.min(y1, y0 + D.doorHeight)],
|
|
899
|
+
[door.at + door.width / 2, len, y0],
|
|
900
|
+
]
|
|
901
|
+
: [[0, len, y0]];
|
|
902
|
+
for (const [d0, d1, yb] of spans) {
|
|
903
|
+
if (d1 - d0 < 1e-3 || y1 - yb < 1e-3)
|
|
904
|
+
continue;
|
|
905
|
+
for (const [side, n, fa, room, shown] of [
|
|
906
|
+
[-1, nA, faA, roomA, sideA],
|
|
907
|
+
[1, nB, faB, roomB, sideB],
|
|
908
|
+
]) {
|
|
909
|
+
if (!shown)
|
|
910
|
+
continue;
|
|
911
|
+
const [ax, az] = at(d0, side);
|
|
912
|
+
const [bx, bz] = at(d1, side);
|
|
913
|
+
wallQuad(w, p, ax, az, bx, bz, yb, y1, n, d0, y0, level, h, paint.hash(room), fa);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
const capFa = paint.attr(roomA, f, FINISH.paint);
|
|
917
|
+
const cap = (d, yb, ya, n) => {
|
|
918
|
+
const [ax, az] = at(d, -1);
|
|
919
|
+
const [bx, bz] = at(d, 1);
|
|
920
|
+
wallQuad(w, p, ax, az, bx, bz, ya, yb, n, 0, y0, level, h, paint.hash(roomA), capFa);
|
|
921
|
+
};
|
|
922
|
+
const dir = [dx, 0, dz];
|
|
923
|
+
const back = [-dx, 0, -dz];
|
|
924
|
+
if (!sg.wall0)
|
|
925
|
+
cap(0, y1, y0, back);
|
|
926
|
+
if (!sg.wall1)
|
|
927
|
+
cap(len, y1, y0, dir);
|
|
928
|
+
if (door) {
|
|
929
|
+
const yd = Math.min(y1, y0 + D.doorHeight);
|
|
930
|
+
cap(door.at - door.width / 2, yd, y0, dir);
|
|
931
|
+
cap(door.at + door.width / 2, yd, y0, back);
|
|
932
|
+
// Soffit of the opening.
|
|
933
|
+
const [a0x, a0z] = at(door.at - door.width / 2, -1);
|
|
934
|
+
const [a1x, a1z] = at(door.at + door.width / 2, -1);
|
|
935
|
+
const [b1x, b1z] = at(door.at + door.width / 2, 1);
|
|
936
|
+
const [b0x, b0z] = at(door.at - door.width / 2, 1);
|
|
937
|
+
polyOut(w, p, [
|
|
938
|
+
[a0x, yd, a0z],
|
|
939
|
+
[a1x, yd, a1z],
|
|
940
|
+
[b1x, yd, b1z],
|
|
941
|
+
[b0x, yd, b0z],
|
|
942
|
+
], [
|
|
943
|
+
[0, 0],
|
|
944
|
+
[door.width, 0],
|
|
945
|
+
[door.width, D.partition],
|
|
946
|
+
[0, D.partition],
|
|
947
|
+
], [0, -1, 0], level, h, paint.hash(roomA), capFa);
|
|
948
|
+
}
|
|
949
|
+
// Top, seen where the slab above is gone.
|
|
950
|
+
const [t0x, t0z] = at(0, -1);
|
|
951
|
+
const [t1x, t1z] = at(len, -1);
|
|
952
|
+
const [t2x, t2z] = at(len, 1);
|
|
953
|
+
const [t3x, t3z] = at(0, 1);
|
|
954
|
+
polyOut(w, p, [
|
|
955
|
+
[t0x, y1, t0z],
|
|
956
|
+
[t1x, y1, t1z],
|
|
957
|
+
[t2x, y1, t2z],
|
|
958
|
+
[t3x, y1, t3z],
|
|
959
|
+
], [
|
|
960
|
+
[0, 0],
|
|
961
|
+
[len, 0],
|
|
962
|
+
[len, D.partition],
|
|
963
|
+
[0, D.partition],
|
|
964
|
+
], [0, 1, 0], level, h, paint.hash(roomA), paint.attr(roomA, f, FINISH.concrete));
|
|
965
|
+
});
|
|
966
|
+
}
|