threedog 0.2.0 → 0.5.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/CHANGELOG.md +290 -0
- package/README.md +9 -8
- package/core/Animator.js +15 -12
- package/core/Assets.js +83 -16
- package/core/Audio.js +45 -38
- package/core/Baked.js +32 -8
- package/core/Batching.js +102 -15
- package/core/Budget.js +39 -18
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +45 -10
- package/core/Describe.js +104 -43
- package/core/Engine.js +190 -57
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +168 -79
- package/core/Inspect.js +2 -2
- package/core/InspectMaterials.js +85 -0
- package/core/InspectPerf.js +61 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +5 -5
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +14 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +25 -9
- package/core/Views.js +9 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +22 -5
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +38 -11
- package/core/assetManifest.js +48 -9
- package/core/assetReport.js +1 -1
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +5 -2
- package/core/cells.js +62 -0
- package/core/checks.js +10 -8
- package/core/chunkStream.js +87 -0
- package/core/control.js +149 -0
- package/core/copies.js +32 -0
- package/core/dayTime.js +12 -6
- package/core/debugView.js +82 -15
- package/core/describeRender.js +43 -17
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +438 -19
- package/core/errorHints.js +37 -141
- package/core/errors.js +31 -8
- package/core/events.generated.js +12 -7
- package/core/gameLights.js +62 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +128 -0
- package/core/gridLoad.js +20 -0
- package/core/ground.js +6 -4
- package/core/headlessLoad.js +55 -0
- package/core/holds.js +78 -50
- package/core/inputContext.js +11 -7
- package/core/inputDefaults.js +24 -21
- package/core/inputPad.js +1 -1
- package/core/inputPointer.js +1 -1
- package/core/inputTouch.js +2 -2
- package/core/lifecycle.js +48 -12
- package/core/lightWatch.js +6 -4
- package/core/look/coreParts.js +137 -30
- package/core/look/part.js +175 -95
- package/core/look/points.js +255 -0
- package/core/look/report.js +34 -17
- package/core/look/shadowPart.js +63 -0
- package/core/look/state.js +45 -0
- package/core/look/write.js +12 -28
- package/core/loop.js +101 -37
- package/core/math.js +11 -3
- package/core/moduleSlots.js +75 -0
- package/core/moduleTypes.js +73 -0
- package/core/modules.js +145 -27
- package/core/movement.js +2 -2
- package/core/namedModel.js +70 -0
- package/core/opsCheck.js +3 -3
- package/core/opsFail.js +15 -6
- package/core/opsGuard.js +4 -4
- package/core/opsRun.js +4 -3
- package/core/owned.js +168 -0
- package/core/page.js +2 -1
- package/core/params.js +30 -8
- package/core/plugins.js +277 -0
- package/core/saveApply.js +99 -17
- package/core/saveFiles.js +8 -6
- package/core/saveValues.js +46 -0
- package/core/saveVersions.js +20 -3
- package/core/scatter.js +48 -19
- package/core/sceneDelta.js +203 -0
- package/core/sceneMethods.js +35 -30
- package/core/screenToGround.js +1 -1
- package/core/services.js +27 -11
- package/core/session.js +28 -25
- package/core/shaderCost.js +78 -0
- package/core/shadowTypes.js +2 -1
- package/core/sharedPoint.js +317 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +34 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -11
- package/core/streamSources.js +0 -11
- package/core/styleParts.js +65 -47
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +2 -2
- package/core/thingOps.js +29 -6
- package/core/things.js +21 -11
- package/core/threadPure.js +7 -3
- package/core/threePatches.js +47 -0
- package/core/tier.js +21 -10
- package/core/time.js +236 -0
- package/core/uiClock.js +25 -0
- package/core/util.js +7 -1
- package/core/validate.js +65 -86
- package/core/wrap.js +106 -0
- package/docs/AI.md +89 -97
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +224 -149
- package/docs/COMMANDS.md +57 -34
- package/docs/CONVENTIONS.md +92 -30
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +228 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +79 -27
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +12 -9
- package/docs/api/audio.md +10 -14
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -25
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +9 -6
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +65 -62
- package/docs/api/events.md +19 -14
- package/docs/api/grids.md +3 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +11 -6
- package/docs/api/interactions.md +7 -5
- package/docs/api/inventory.md +17 -16
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +15 -0
- package/docs/api/post.md +5 -4
- package/docs/api/quests.md +2 -3
- package/docs/api/rigid.md +16 -14
- package/docs/api/saves.md +6 -4
- package/docs/api/settings.md +2 -3
- package/docs/api/sky.md +11 -44
- package/docs/api/stream.md +1 -1
- package/docs/api/style.md +31 -29
- package/docs/api/terrain.md +9 -6
- package/docs/api/terrainLook.md +10 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +30 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +12 -8
- package/docs/api/vegetationLook.md +10 -0
- package/docs/api/water.md +4 -20
- package/docs/api/weather.md +5 -15
- package/docs/api/weatherLook.md +10 -0
- package/docs/api/world.md +2 -1
- package/docs/recipes/01-new-game.md +71 -59
- package/docs/recipes/02-npc.md +46 -29
- package/docs/recipes/03-items-pickups.md +38 -24
- package/docs/recipes/04-quests.md +34 -27
- package/docs/recipes/05-props-bake.md +154 -18
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +41 -10
- package/docs/recipes/08-weather-sky.md +146 -37
- package/docs/recipes/09-style.md +218 -0
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +34 -10
- package/docs/recipes/14-custom-module.md +65 -34
- package/docs/recipes/15-perf.md +35 -6
- package/docs/recipes/16-dev-bridge.md +65 -41
- package/docs/recipes/18-world.md +21 -8
- package/docs/recipes/19-shooting-picking.md +12 -11
- package/docs/recipes/20-content-actions-save.md +63 -25
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +18 -18
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +12 -6
- package/docs/recipes/28-terrain.md +35 -2
- package/docs/recipes/29-grid.md +71 -33
- package/docs/recipes/30-templates.md +64 -12
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +35 -2
- package/docs/recipes/34-environment-lighting.md +27 -4
- package/docs/recipes/35-style-from-reference.md +115 -51
- package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
- package/docs/recipes/37-terrain-look-hooks.md +37 -15
- package/docs/recipes/38-environment-look-hooks.md +64 -48
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +3 -3
- package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
- package/docs/recipes/44-water-weather-look-hooks.md +30 -21
- package/docs/recipes/45-cascaded-shadows.md +17 -8
- package/docs/recipes/46-blender-art-route.md +4 -4
- package/docs/recipes/47-island-snow-backdrop.md +11 -10
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +46 -33
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +4 -4
- package/docs/recipes/52-look.md +228 -54
- package/docs/recipes/53-ground-up-close.md +58 -0
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +112 -0
- package/docs/recipes/56-webgpu-tsl.md +260 -0
- package/docs/recipes/57-control.md +65 -0
- package/docs/recipes/58-input.md +57 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +55 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +17 -13
- package/examples/action/assets.js +8 -0
- package/examples/action/content/actions.js +1 -1
- package/examples/action/content/audio.js +5 -5
- package/examples/action/look.js +1 -1
- package/examples/action/main.js +10 -13
- package/examples/action/models.js +24 -23
- package/examples/pullable.json +111 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +83 -0
- package/examples/rc2d/README.md +52 -0
- package/examples/rc2d/main.js +63 -0
- package/examples/rc2d/rc2d.js +197 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +13 -11
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/main.js +17 -12
- package/examples/sheepisland/style/index.js +6 -6
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +15 -16
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/npcs.js +1 -1
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +18 -17
- package/examples/styletest/models.js +1 -1
- package/examples/styletest/params.js +3 -3
- package/examples/techniques/contact-shadows/README.md +92 -0
- package/examples/techniques/contact-shadows/contactShadows.js +51 -0
- package/examples/techniques/contact-shadows/main.js +53 -0
- package/examples/techniques/day-night-grade/README.md +86 -0
- package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
- package/examples/techniques/day-night-grade/main.js +51 -0
- package/examples/techniques/interior-light/README.md +103 -0
- package/examples/techniques/interior-light/interiorLight.js +45 -0
- package/examples/techniques/interior-light/main.js +124 -0
- package/examples/techniques/modular-building/README.md +125 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +47 -0
- package/examples/techniques/night-lights/README.md +94 -0
- package/examples/techniques/night-lights/main.js +70 -0
- package/examples/techniques/night-lights/nightLights.js +91 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +84 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/procedural-animation/README.md +77 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +45 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +67 -0
- package/examples/techniques/procedural-surface/main.js +103 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +75 -0
- package/examples/techniques/stylized-shading/main.js +93 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +135 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
- package/examples/techniques/sun-and-key-light/main.js +95 -0
- package/examples/techniques/wet-road/README.md +99 -0
- package/examples/techniques/wet-road/main.js +68 -0
- package/examples/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +84 -0
- package/examples/webgpu-tsl/README.md +42 -0
- package/examples/webgpu-tsl/main.js +21 -0
- package/examples/webgpu-tsl/tslScene.js +75 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +22 -15
- package/examples/world/art/humanoid.js +42 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +58 -0
- package/examples/world/art/shapes.js +9 -0
- package/examples/world/assets.js +6 -0
- package/examples/world/content/audio.js +5 -5
- package/examples/world/content/npcs.js +2 -2
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/rules.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +17 -13
- package/examples/world/style/index.js +61 -0
- package/examples/world/style/plugins/10-bloom.js +5 -0
- package/index.d.ts +50 -45
- package/index.js +27 -22
- package/llms.txt +20 -12
- package/modules/ambience/Ambience.js +34 -23
- package/modules/calendar/Calendar.js +163 -0
- package/modules/calendar/contract.js +21 -0
- package/modules/calendar/index.js +81 -0
- package/modules/{sky → calendar}/schedule.js +17 -16
- package/modules/calendar/seasons.js +55 -0
- package/modules/camera/FirstPersonCamera.js +6 -15
- package/modules/camera/FixedCamera.js +33 -15
- package/modules/camera/FollowCamera.js +90 -16
- package/modules/camera/RtsCamera.js +18 -17
- package/modules/camera/common.js +70 -19
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +196 -59
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +27 -8
- package/modules/characters/behaviors.js +2 -1
- package/modules/characters/contract.js +13 -0
- package/modules/characters/footsteps.js +1 -1
- package/modules/characters/index.js +87 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +97 -19
- package/modules/characters/movers/manual.js +20 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +172 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +12 -8
- package/modules/characters/npcView.js +44 -16
- package/modules/characters/pathAsync.js +7 -3
- package/modules/characters/playerStrings.js +4 -3
- package/modules/characters/proceduralRig.js +46 -10
- package/modules/characters/useModel.js +1 -1
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +65 -25
- package/modules/collision/grid.js +8 -6
- package/modules/content/explain.js +2 -2
- package/modules/content/fields.js +102 -0
- package/modules/content/ids.js +8 -6
- package/modules/content/index.js +97 -28
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +11 -40
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +16 -9
- package/modules/content/rules.js +58 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +121 -30
- package/modules/debug/DebugPanel.js +24 -17
- package/modules/flow/contract.js +16 -0
- package/modules/flow/index.js +21 -15
- package/modules/gameplay/Container.js +41 -32
- package/modules/gameplay/Containers.js +30 -15
- package/modules/gameplay/Dialogue.js +113 -55
- package/modules/gameplay/Interactions.js +193 -67
- package/modules/gameplay/Inventory.js +69 -73
- package/modules/gameplay/Quests.js +75 -39
- package/modules/gameplay/boxOps.js +3 -3
- package/modules/gameplay/dialogue.contract.js +21 -0
- package/modules/gameplay/dialogueBox.js +4 -2
- package/modules/gameplay/dialogueBubbles.js +116 -0
- package/modules/gameplay/interactionPrompt.js +4 -1
- package/modules/gameplay/interactions.contract.js +16 -0
- package/modules/gameplay/inventory.contract.js +23 -0
- package/modules/gameplay/inventoryOps.js +18 -16
- package/modules/gameplay/pickups.js +268 -85
- package/modules/gameplay/questLog.js +4 -4
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +14 -13
- package/modules/grid/index.js +60 -36
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +15 -16
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +6 -5
- package/modules/hlod/index.js +51 -19
- package/modules/hud/index.js +35 -20
- package/modules/hud/parts.js +20 -7
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +45 -20
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +42 -18
- package/modules/music/Music.js +38 -21
- package/modules/music/rules.js +1 -1
- package/modules/nav/index.js +48 -42
- package/modules/net/Client.js +13 -6
- package/modules/net/Host.js +19 -5
- package/modules/net/Net.js +2 -1
- package/modules/net/index.js +13 -8
- package/modules/net/sync.js +9 -8
- package/modules/net/transports.js +77 -27
- package/modules/particles/Particles.js +23 -14
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +39 -11
- package/modules/photo/Photo.js +53 -36
- package/modules/rigid/RigidBodies.js +194 -32
- package/modules/rigid/Vehicles.js +18 -15
- package/modules/rigid/sync.js +62 -17
- package/modules/settings/Settings.js +57 -52
- package/modules/settings/apply.js +38 -3
- package/modules/settings/sections.js +5 -3
- package/modules/settings/strings.js +3 -2
- package/modules/settings/view.js +5 -3
- package/modules/sky/Sky.js +88 -176
- package/modules/sky/cascades.js +86 -25
- package/modules/sky/cascades.tsl.js +82 -0
- package/modules/sky/clouds.js +34 -19
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +83 -13
- package/modules/sky/fog.js +140 -95
- package/modules/sky/frame.js +112 -44
- package/modules/sky/look.js +22 -19
- package/modules/sky/lookFog.js +48 -52
- package/modules/sky/lookShadow.js +53 -41
- package/modules/sky/lookSky.js +82 -21
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +41 -19
- package/modules/sky/shadow.js +44 -20
- package/modules/sky/skyModule.js +45 -33
- package/modules/sky/tint.js +61 -0
- package/modules/terrain/ChunkManager.js +175 -108
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/index.js +105 -50
- package/modules/terrain/look.js +83 -0
- package/modules/terrain/lookGround.js +21 -16
- package/modules/terrain/terrainDefaults.js +1 -1
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +5 -3
- package/modules/terrain/terrainIsland.js +5 -4
- package/modules/terrain/terrainShape.js +12 -12
- package/modules/terrain/terrainShapeMain.js +8 -7
- package/modules/terrain/terrainTexture.js +21 -19
- package/modules/timeline/Timeline.js +95 -43
- package/modules/timeline/Tween.js +18 -10
- package/modules/timeline/letterbox.js +2 -2
- package/modules/timeline/shots.js +5 -1
- package/modules/triggers/index.js +107 -76
- package/modules/vegetation/Vegetation.js +190 -102
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +31 -10
- package/modules/vegetation/look.js +119 -0
- package/modules/vegetation/lookWind.js +71 -10
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +45 -0
- package/modules/water/Water.js +65 -27
- package/modules/water/look.js +29 -18
- package/modules/water/surface.js +64 -25
- package/modules/water/surfaceDefaults.js +3 -0
- package/modules/weather/Weather.js +62 -104
- package/modules/weather/look.js +1 -2
- package/modules/weather/particles.js +24 -9
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherLook.js +135 -0
- package/modules/world/World.js +24 -7
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -4
- package/modules/world/persist.js +62 -2
- package/modules/world/pos.js +3 -2
- package/modules/world/records.js +8 -6
- package/modules/world/sim.js +60 -20
- package/modules/world/simFar.js +4 -3
- package/modules/world/state.js +3 -2
- package/modules/world/thingSource.js +1 -1
- package/modules/world/views.js +7 -5
- package/package.json +8 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +150 -45
- package/render/effects.js +130 -38
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +26 -0
- package/render/fx/lighting.tsl.js +28 -0
- package/render/fx/nodeErrors.tsl.js +68 -0
- package/render/fx/noise.tsl.js +12 -0
- package/render/fx/objectOrigin.tsl.js +42 -0
- package/render/fx/particles.tsl.js +139 -0
- package/render/fx/patchNodes.tsl.js +403 -0
- package/render/fx/postWebGPU.tsl.js +158 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +260 -0
- package/render/fx/uniforms.tsl.js +67 -0
- package/render/fx/water.tsl.js +53 -0
- package/render/fx/wind.tsl.js +22 -0
- package/render/fxNumbers.js +36 -0
- package/render/hotGlsl.js +24 -0
- package/render/lighting.js +66 -14
- package/render/lights.js +223 -4
- package/render/lookGlow.js +139 -0
- package/render/lookSurface.js +99 -36
- package/render/materials.js +71 -52
- package/render/modeling.js +73 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +311 -34
- package/render/postLook.js +124 -46
- package/render/postWebGL.js +197 -0
- package/render/probes.js +231 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/surface.js +53 -17
- package/render/terms.js +211 -0
- package/render/uniformDecl.js +3 -2
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +620 -244
- package/types/gameplay.d.ts +494 -318
- package/types/generated/core/Audio.d.ts +26 -42
- package/types/generated/core/Batching.d.ts +6 -2
- package/types/generated/core/Budget.d.ts +2 -8
- package/types/generated/core/DebugOverrides.d.ts +44 -3
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +102 -31
- package/types/generated/core/Ops.d.ts +31 -0
- package/types/generated/core/Random.d.ts +2 -2
- package/types/generated/core/Saves.d.ts +10 -2
- package/types/generated/core/Stream.d.ts +1 -1
- package/types/generated/core/Threads.d.ts +4 -1
- package/types/generated/core/Views.d.ts +0 -1
- package/types/generated/core/audioVoice.d.ts +17 -9
- package/types/generated/core/control.d.ts +55 -0
- package/types/generated/core/session.d.ts +2 -1
- package/types/generated/modules/ambience/Ambience.d.ts +0 -9
- package/types/generated/modules/calendar/Calendar.d.ts +84 -0
- package/types/generated/modules/calendar/index.d.ts +10 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Grid.d.ts +61 -25
- package/types/generated/modules/grid/Layer.d.ts +5 -5
- package/types/generated/modules/grid/index.d.ts +29 -17
- package/types/generated/modules/music/Music.d.ts +5 -3
- package/types/generated/modules/net/index.d.ts +3 -3
- package/types/generated/modules/net/transports.d.ts +12 -3
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +12 -104
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/weather/Weather.d.ts +17 -18
- package/types/generated/modules/weather/weatherLook.d.ts +12 -0
- package/types/generated/modules/world/World.d.ts +18 -3
- package/types/generated/render/PostFX.d.ts +67 -30
- package/types/generated/render/materials.d.ts +26 -20
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/patches.d.ts +16 -2
- package/types/generated/ui/UI.d.ts +6 -3
- package/types/nav.d.ts +6 -0
- package/types/physics.d.ts +137 -44
- package/types/style.d.ts +125 -92
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +164 -110
- package/ui/Focus.js +25 -14
- package/ui/LoadingScreen.js +1 -1
- package/ui/Parts.js +27 -11
- package/ui/UI.js +20 -10
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +9 -6
- package/ui/touchPart.js +1 -1
- package/core/claims.js +0 -51
- package/core/look/layers.js +0 -136
- package/core/renamed.js +0 -21
- package/docs/api/entities.md +0 -61
- package/docs/recipes/09-style-pack.md +0 -234
- package/examples/styletest/overrides.js +0 -33
- package/examples/styletest/panel.js +0 -135
- package/modules/entities/Entities.js +0 -243
- package/modules/entities/build.js +0 -25
- package/modules/entities/index.js +0 -4
- package/modules/sky/calendar.js +0 -80
- package/modules/sky/layers.js +0 -69
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/world/cells.js +0 -42
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Modular building kit (optional technique example, see README.md). Shapes only: every module is built from parameters and drawn with the
|
|
3
|
+
// game's own materials, one per slot (wall, trim, roof, frame, glass, accent, awning, sign). Imports only three and three/addons, so a game can
|
|
4
|
+
// copy the folder and change anything.
|
|
5
|
+
// The pieces are deliberately plain: they teach the method (grid, modules, variation, shared geometry), not a look.
|
|
6
|
+
import * as THREE from 'three';
|
|
7
|
+
import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js';
|
|
8
|
+
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
|
|
9
|
+
|
|
10
|
+
export const SLOTS = ['wall', 'trim', 'roof', 'frame', 'glass', 'accent', 'awning', 'sign'];
|
|
11
|
+
// a slot the game leaves out borrows from the next one, so one material is enough to start (a gray block-out)
|
|
12
|
+
const FALLBACK = { trim: 'wall', roof: 'trim', frame: 'trim', glass: 'frame', accent: 'frame', awning: 'accent', sign: 'trim' };
|
|
13
|
+
|
|
14
|
+
/** Trim profiles: [out, up] points of a cross-section, outward from the wall face. Swap or add profiles to change a style's trim */
|
|
15
|
+
export const PROFILES = {
|
|
16
|
+
flat: [[0, 0], [1, 0], [1, 1], [0, 1]],
|
|
17
|
+
step: [[0, 0], [0.55, 0], [0.55, 0.45], [1, 0.45], [1, 1], [0, 1]],
|
|
18
|
+
cove: [[0, 0], [0.35, 0], [0.5, 0.25], [0.75, 0.45], [1, 0.75], [1, 1], [0, 1]],
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Window variants a street picks from: a few shared variants (not a random size per window) keep the look designed and the geometry shared */
|
|
22
|
+
export const WINDOWS = [
|
|
23
|
+
{ width: 0.9, height: 1.4, sill: 0.9, mullions: 1, planter: false },
|
|
24
|
+
{ width: 1.1, height: 1.5, sill: 0.8, mullions: 2, planter: true },
|
|
25
|
+
{ width: 0.7, height: 1.6, sill: 0.8, mullions: 0, planter: false },
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
/** Seeded random 0..1 (mulberry32): the same seed gives the same street on every machine */
|
|
29
|
+
export function rng(seed) {
|
|
30
|
+
let a = seed >>> 0;
|
|
31
|
+
return () => {
|
|
32
|
+
a = (a + 0x6D2B79F5) >>> 0;
|
|
33
|
+
let t = a;
|
|
34
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
35
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
36
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A kit: module builders + an assembler for buildings and streets, all sharing one geometry cache and one slot set.
|
|
42
|
+
* @param {{ prefix?: string, cell?: number, storey?: number, wall?: number, slots: Record<string, THREE.Material>,
|
|
43
|
+
* profiles?: Record<string, number[][]>, windows?: typeof WINDOWS,
|
|
44
|
+
* ao?: { bake: (g: THREE.BufferGeometry, o: any) => any, samples?: number, strength?: number } | null }} opts
|
|
45
|
+
* cell: grid cell in metres (one wall module wide); storey: floor height; wall: wall thickness. slots: the game's materials.
|
|
46
|
+
* ao: optional vertex AO (pass threedog's bakeVertexAO as `bake`); the slot materials then need vertexColors: true.
|
|
47
|
+
*/
|
|
48
|
+
export function createModularKit(opts) {
|
|
49
|
+
const known = ['prefix', 'cell', 'storey', 'wall', 'slots', 'profiles', 'windows', 'ao'];
|
|
50
|
+
for (const k of Object.keys(opts ?? {})) if (!known.includes(k)) throw new Error(`createModularKit: unknown option "${k}" (use ${known.join(', ')})`);
|
|
51
|
+
const { prefix = 'mb', cell = 2, storey = 3, wall: T = 0.2, profiles = PROFILES, windows = WINDOWS, ao = null } = opts;
|
|
52
|
+
if (!opts.slots?.wall) throw new Error('createModularKit: slots.wall is required (other slots fall back to it)');
|
|
53
|
+
for (const k of Object.keys(opts.slots)) if (!SLOTS.includes(k)) throw new Error(`createModularKit: unknown slot "${k}" (slots: ${SLOTS.join(', ')})`);
|
|
54
|
+
const slots = /** @type {Record<string, THREE.Material>} */ ({});
|
|
55
|
+
for (const s of SLOTS) { let k = s; while (!opts.slots[k]) k = FALLBACK[k]; slots[s] = opts.slots[k]; }
|
|
56
|
+
|
|
57
|
+
// ---- shared geometry and materials ---------------------------------------------------------------------------------------------------
|
|
58
|
+
// One geometry per module + params, one material per slot (+ texture): every copy of a module shares them, which is what lets
|
|
59
|
+
// engine.batching draw a whole street with a few dozen instanced draws instead of one draw per piece.
|
|
60
|
+
const geoCache = new Map(), texCache = new Map(), matCache = new Map();
|
|
61
|
+
const memo = (key, make) => geoCache.get(key) ?? geoCache.set(key, make()).get(key);
|
|
62
|
+
const textured = (slot, tex) => {
|
|
63
|
+
const k = slot + '|' + tex.uuid;
|
|
64
|
+
if (!matCache.has(k)) { const m = slots[slot].clone(); /** @type {any} */ (m).map = tex; m.polygonOffset = true; m.polygonOffsetFactor = -1; matCache.set(k, m); }
|
|
65
|
+
return matCache.get(k);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** pieces [geometry, slot][] in module space -> { slot: one merged geometry } (non-indexed, so boxes and extrusions merge together) */
|
|
69
|
+
function bySlot(pieces) {
|
|
70
|
+
const out = {};
|
|
71
|
+
for (const [g, s] of pieces) (out[s] ||= []).push(g.index ? g.toNonIndexed() : g);
|
|
72
|
+
for (const s in out) {
|
|
73
|
+
const merged = mergeGeometries(out[s]);
|
|
74
|
+
if (!merged) throw new Error(`modular kit: pieces of slot "${s}" do not share attributes`);
|
|
75
|
+
out[s] = merged;
|
|
76
|
+
}
|
|
77
|
+
if (ao) for (const s in out) {
|
|
78
|
+
// each slot's geometry is darkened by the module's other parts too (a sill under a frame, the reveal of a window hole)
|
|
79
|
+
const others = Object.keys(out).filter(o => o !== s).map(o => out[o]);
|
|
80
|
+
ao.bake(out[s], { samples: ao.samples ?? 24, strength: ao.strength ?? 0.6, occluders: others, radius: 0.6 });
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
/** A module's group: one mesh per slot, identity transforms (the group is what the assembler moves) */
|
|
85
|
+
function group(type, geos, maps = {}) {
|
|
86
|
+
const g = new THREE.Group();
|
|
87
|
+
g.name = type;
|
|
88
|
+
for (const [slot, geo] of Object.entries(geos)) {
|
|
89
|
+
const m = new THREE.Mesh(geo, maps[slot] ? textured(slot.split(':')[0], maps[slot]) : slots[slot.split(':')[0]]);
|
|
90
|
+
m.name = slot; m.castShadow = m.receiveShadow = true;
|
|
91
|
+
g.add(m);
|
|
92
|
+
}
|
|
93
|
+
return g;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ---- geometry helpers --------------------------------------------------------------------------------------------------------------
|
|
97
|
+
const box = (w, h, d, x = 0, y = 0, z = 0) => new THREE.BoxGeometry(w, h, d).translate(x, y, z);
|
|
98
|
+
// rounded edges: a raw box reads as a placeholder; a small radius catches a highlight along every edge. One segment (108 triangles, a
|
|
99
|
+
// chamfer with smooth normals) instead of two (300) because sills, pilasters and copings repeat hundreds of times on a street
|
|
100
|
+
const rbox = (w, h, d, r, x = 0, y = 0, z = 0) => new RoundedBoxGeometry(w, h, d, 1, Math.min(r, w / 2.01, h / 2.01, d / 2.01)).translate(x, y, z);
|
|
101
|
+
const shape = pts => new THREE.Shape(pts.map(([x, y]) => new THREE.Vector2(x, y)));
|
|
102
|
+
const rect = (x0, y0, x1, y1) => [[x0, y0], [x1, y0], [x1, y1], [x0, y1]];
|
|
103
|
+
const extrude = (s, depth) => new THREE.ExtrudeGeometry(s, { depth, bevelEnabled: false });
|
|
104
|
+
/** A cross-section in (out, up) extruded along x over [-len/2, len/2]: trims, roofs, gable ends */
|
|
105
|
+
const sweepX = (pts, len) => extrude(shape(pts), len).rotateY(-Math.PI / 2).translate(len / 2, 0, 0);
|
|
106
|
+
/** A wall slab of one cell, outer face at z = 0, with holes ([x0, y0, x1, y1] rectangles) */
|
|
107
|
+
function slab(holes = [], h = storey) {
|
|
108
|
+
if (!holes.length) return box(cell, h, T, 0, h / 2, -T / 2);
|
|
109
|
+
const s = shape(rect(-cell / 2, 0, cell / 2, h));
|
|
110
|
+
for (const r of holes) s.holes.push(new THREE.Path(rect(...r).map(([x, y]) => new THREE.Vector2(x, y)).reverse()));
|
|
111
|
+
return extrude(s, T).translate(0, 0, -T);
|
|
112
|
+
}
|
|
113
|
+
/** A wall slab with an opening cut up from the floor (a door): one U-shaped outline, since a hole may not touch the border */
|
|
114
|
+
function slabOpen(w, h) {
|
|
115
|
+
const c = cell / 2, pts = [[-c, 0], [-w / 2, 0], [-w / 2, h], [w / 2, h], [w / 2, 0], [c, 0], [c, storey], [-c, storey]];
|
|
116
|
+
return extrude(shape(pts), T).translate(0, 0, -T);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ---- modules (each: params -> Group). Params are plain data, so the manifest can cache, tune and gallery them ---------------------------
|
|
120
|
+
const mod = {
|
|
121
|
+
wall() { return group('wall', memo('wall', () => bySlot([[slab(), 'wall']]))); },
|
|
122
|
+
|
|
123
|
+
/** A window: slab with a hole, a proud surround, an inset frame with mullions, recessed glass, a sill and optionally a planter */
|
|
124
|
+
window(p) {
|
|
125
|
+
const { width: w, height: h, sill: y0, mullions = 1, planter = false, inset = 0.08, frame: f = 0.08 } = p;
|
|
126
|
+
return group('window', memo('window' + JSON.stringify(p), () => {
|
|
127
|
+
const z = -inset, bars = [];
|
|
128
|
+
for (let i = 1; i <= mullions; i++) bars.push([box(0.04, h, 0.05, -w / 2 + (w * i) / (mullions + 1), y0 + h / 2, z), 'frame']);
|
|
129
|
+
const surround = shape(rect(-w / 2 - f, y0 - f, w / 2 + f, y0 + h + f));
|
|
130
|
+
surround.holes.push(new THREE.Path(rect(-w / 2, y0, w / 2, y0 + h).map(([x, y]) => new THREE.Vector2(x, y)).reverse()));
|
|
131
|
+
const pieces = [
|
|
132
|
+
[slab([[-w / 2, y0, w / 2, y0 + h]]), 'wall'],
|
|
133
|
+
[extrude(surround, 0.04), 'trim'], // proud of the face: catches light, hides the cut edge
|
|
134
|
+
[rbox(w + 2 * f + 0.12, 0.08, 0.22, 0.02, 0, y0 - 0.035, 0.07), 'trim'], // the sill sticks out further than the surround; its top 5 mm above the reveal floor so the two never share a plane
|
|
135
|
+
[box(w, 0.05, 0.05, 0, y0 + h / 2, z), 'frame'], // transom
|
|
136
|
+
...bars,
|
|
137
|
+
[box(w, h, 0.01, 0, y0 + h / 2, z - 0.03), 'glass'], // recessed: the reveal reads as wall thickness
|
|
138
|
+
];
|
|
139
|
+
if (planter) pieces.push([rbox(w * 0.9, 0.22, 0.2, 0.03, 0, y0 + 0.115, 0.1), 'accent']);
|
|
140
|
+
return bySlot(pieces);
|
|
141
|
+
}));
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
/** A door: U-cut slab, surround on three sides, recessed leaf, a step */
|
|
145
|
+
door(p) {
|
|
146
|
+
const { width: w = 1, height: h = 2.2, inset = 0.1, frame: f = 0.1 } = p;
|
|
147
|
+
return group('door', memo('door' + JSON.stringify(p), () => bySlot([
|
|
148
|
+
[slabOpen(w, h), 'wall'],
|
|
149
|
+
[box(f, h + f, 0.05, -w / 2 - f / 2, (h + f) / 2, 0.025), 'trim'],
|
|
150
|
+
[box(f, h + f, 0.05, w / 2 + f / 2, (h + f) / 2, 0.025), 'trim'],
|
|
151
|
+
[box(w, f, 0.05, 0, h + f / 2, 0.025), 'trim'],
|
|
152
|
+
[box(w, h, 0.05, 0, h / 2, -inset), 'accent'],
|
|
153
|
+
[rbox(w + 0.3, 0.12, 0.35, 0.03, 0, 0.06, 0.17), 'trim'],
|
|
154
|
+
])));
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
/** A corner pilaster, one storey: centered on the corner, a little wider than the wall, so it covers the seam where two walls meet */
|
|
158
|
+
corner(p) {
|
|
159
|
+
const { size = T * 1.6 } = p;
|
|
160
|
+
return group('corner', memo('corner' + size, () => bySlot([[rbox(size, storey, size, 0.03, 0, storey / 2, 0), 'trim']])));
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
/** A trim strip of any length along x: cornice, floor band, plinth. profile = a name in profiles */
|
|
164
|
+
trim(p) {
|
|
165
|
+
const { length, profile = 'step', height = 0.25, depth = 0.15 } = p;
|
|
166
|
+
const pts = profiles[profile];
|
|
167
|
+
if (!pts) throw new Error(`modular kit: unknown trim profile "${profile}" (profiles: ${Object.keys(profiles).join(', ')})`);
|
|
168
|
+
return group('trim', memo('trim' + JSON.stringify(p), () => bySlot([[sweepX(pts.map(([o, u]) => [o * depth, u * height]), length), 'trim']])));
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
/** A gable roof over width x depth metres (ridge along x), bottom resting on the wall top at the eaves line; gable end walls included */
|
|
172
|
+
gable(p) {
|
|
173
|
+
const { width: W, depth: D, pitch = 0.6, overhang = 0.3, thickness = 0.15 } = p;
|
|
174
|
+
return group('gable', memo('gable' + JSON.stringify(p), () => {
|
|
175
|
+
const a = D / 2 + overhang, r = a * pitch, k = thickness * Math.hypot(1, pitch), drop = r * (1 - D / 2 / a);
|
|
176
|
+
const chevron = [[-a, 0], [0, r], [a, 0], [a, k], [0, r + k], [-a, k]].map(([z, y]) => [z, y - drop]);
|
|
177
|
+
const apex = r * (D / 2) / a; // the gable triangle under the roof, height above the wall top at the ridge
|
|
178
|
+
const tri = [[-D / 2, 0], [D / 2, 0], [0, apex]];
|
|
179
|
+
return bySlot([
|
|
180
|
+
[sweepX(chevron, W + 2 * overhang), 'roof'],
|
|
181
|
+
[extrude(shape(tri), T).rotateY(-Math.PI / 2).translate(W / 2, 0, 0), 'wall'],
|
|
182
|
+
[extrude(shape(tri), T).rotateY(Math.PI / 2).translate(-W / 2, 0, 0), 'wall'],
|
|
183
|
+
]);
|
|
184
|
+
}));
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
/** A flat roof with a parapet and a coping on top */
|
|
188
|
+
flatRoof(p) {
|
|
189
|
+
const { width: W, depth: D, parapet = 0.6, coping = 0.06 } = p;
|
|
190
|
+
return group('flatRoof', memo('flat' + JSON.stringify(p), () => {
|
|
191
|
+
const t = T, c = coping, y = parapet / 2, top = parapet + 0.04;
|
|
192
|
+
return bySlot([
|
|
193
|
+
[box(W - 2 * t, 0.12, D - 2 * t, 0, 0.06, 0), 'roof'],
|
|
194
|
+
[box(W, parapet, t, 0, y, D / 2 - t / 2), 'wall'], [box(W, parapet, t, 0, y, -D / 2 + t / 2), 'wall'],
|
|
195
|
+
[box(t, parapet, D - 2 * t, W / 2 - t / 2, y, 0), 'wall'], [box(t, parapet, D - 2 * t, -W / 2 + t / 2, y, 0), 'wall'],
|
|
196
|
+
[rbox(W + 2 * c, 0.08, t + 2 * c, 0.02, 0, top, D / 2 - t / 2), 'trim'], [rbox(W + 2 * c, 0.08, t + 2 * c, 0.02, 0, top, -D / 2 + t / 2), 'trim'],
|
|
197
|
+
[rbox(t + 2 * c, 0.08, D - 2 * t - 2 * c, 0.02, W / 2 - t / 2, top, 0), 'trim'], [rbox(t + 2 * c, 0.08, D - 2 * t - 2 * c, 0.02, -W / 2 + t / 2, top, 0), 'trim'],
|
|
198
|
+
]);
|
|
199
|
+
}));
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
/** A striped awning: sloped canvas + valance. The stripes are a gray mask made lazily here; the awning slot's color tints it */
|
|
203
|
+
awning(p) {
|
|
204
|
+
const { width: w = 1.6, depth = 0.9, drop = 0.4, stripes = 7, y = 2.6 } = p;
|
|
205
|
+
const key = 'stripes' + stripes;
|
|
206
|
+
const tex = texCache.get(key) ?? texCache.set(key, stripeTexture(stripes)).get(key);
|
|
207
|
+
const geos = memo('awning' + JSON.stringify(p), () => {
|
|
208
|
+
const len = Math.hypot(depth, drop), ang = Math.atan2(drop, depth);
|
|
209
|
+
const canvas = new THREE.BoxGeometry(w, 0.03, len).translate(0, 0, len / 2).rotateX(ang).translate(0, y, 0);
|
|
210
|
+
const valance = box(w, 0.22, 0.03, 0, y - drop - 0.11, depth);
|
|
211
|
+
return bySlot([[canvas, 'awning'], [valance, 'awning'], [box(0.04, 0.04, depth, -w / 2, y - drop, depth / 2), 'frame'],
|
|
212
|
+
[box(0.04, 0.04, depth, w / 2, y - drop, depth / 2), 'frame']]);
|
|
213
|
+
});
|
|
214
|
+
return group('awning', geos, { awning: tex });
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
/** A sign board with text painted on a canvas (white ground, dark letters: a mask the sign slot's color tints) */
|
|
218
|
+
sign(p) {
|
|
219
|
+
const { text = 'SIGN', width: w = 1.6, height: h = 0.45, y = 3.25 } = p;
|
|
220
|
+
const key = 'sign' + text + w + h;
|
|
221
|
+
const tex = texCache.get(key) ?? texCache.set(key, textTexture(text, w / h)).get(key);
|
|
222
|
+
const geos = memo('sign' + JSON.stringify(p), () => bySlot([
|
|
223
|
+
[rbox(w, h, 0.08, 0.03, 0, y, 0.04), 'sign'],
|
|
224
|
+
[new THREE.PlaneGeometry(w - 0.08, h - 0.08).translate(0, y, 0.081), 'sign:face'],
|
|
225
|
+
]));
|
|
226
|
+
return group('sign', geos, { 'sign:face': tex });
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
/** A chimney: a rounded column and a wider cap */
|
|
230
|
+
chimney(p) {
|
|
231
|
+
const { width: w = 0.5, height: h = 2 } = p;
|
|
232
|
+
return group('chimney', memo('chimney' + JSON.stringify(p), () => bySlot([
|
|
233
|
+
[rbox(w, h, w, 0.04, 0, h / 2, 0), 'wall'], [rbox(w + 0.12, 0.12, w + 0.12, 0.03, 0, h + 0.06, 0), 'trim']])));
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// ---- assembler -----------------------------------------------------------------------------------------------------------------------
|
|
238
|
+
const SIDES = ['front', 'right', 'back', 'left'];
|
|
239
|
+
/**
|
|
240
|
+
* A building: footprint W x D cells, floors, a facade pattern per side ('/' separates floors, ground floor first, the last row repeats:
|
|
241
|
+
* 'WDW/WWW'), a roof. Letters: W window, S shop window (window + awning), D door, . blank wall.
|
|
242
|
+
* Each module group carries userData.module = { type, side, floor, i } so tools and tests can find it; the wall slab mesh is named 'wall'.
|
|
243
|
+
*/
|
|
244
|
+
function building(p) {
|
|
245
|
+
const { width = 3, depth = 2, floors = 2, roof = 'gable', pitch = 0.6, parapet = 0.6, trim = 'step', window: wv = 0,
|
|
246
|
+
sign = '', chimney = false } = p;
|
|
247
|
+
const W = width * cell, D = depth * cell, H = floors * storey, root = new THREE.Group(), win = windows[wv % windows.length];
|
|
248
|
+
root.name = 'building';
|
|
249
|
+
const facade = { front: p.front ?? 'W'.repeat(width), back: p.back ?? 'W'.repeat(width), left: p.left ?? '.'.repeat(depth), right: p.right ?? '.'.repeat(depth) };
|
|
250
|
+
const place = (g, x, y, z, ry, info) => { g.position.set(x, y, z); g.rotation.y = ry; g.userData.module = info; root.add(g); return g; };
|
|
251
|
+
// where cell i of a side sits, and which way it faces (module space: x along the facade, +z out)
|
|
252
|
+
const frame = (side, i) => {
|
|
253
|
+
const n = side === 'front' || side === 'back' ? width : depth, u = -(n * cell) / 2 + (i + 0.5) * cell;
|
|
254
|
+
return side === 'front' ? [u, D / 2, 0] : side === 'back' ? [-u, -D / 2, Math.PI] : side === 'right' ? [W / 2, -u, Math.PI / 2] : [-W / 2, u, -Math.PI / 2];
|
|
255
|
+
};
|
|
256
|
+
for (const side of SIDES) {
|
|
257
|
+
const rows = facade[side].split('/'), n = side === 'front' || side === 'back' ? width : depth;
|
|
258
|
+
for (const r of rows) if (r.length !== n) throw new Error(`modular kit: facade ${side} row "${r}" has ${r.length} letters, the footprint side has ${n} cells`);
|
|
259
|
+
let signed = false;
|
|
260
|
+
for (let f = 0; f < floors; f++) {
|
|
261
|
+
const row = rows[Math.min(f, rows.length - 1)];
|
|
262
|
+
for (let i = 0; i < n; i++) {
|
|
263
|
+
const ch = row[i], [x, z, ry] = frame(side, i), info = { type: ch, side, floor: f, i };
|
|
264
|
+
if (ch === 'D' && f > 0) throw new Error(`modular kit: a door (D) on floor ${f} of side ${side}; doors go on the ground floor`);
|
|
265
|
+
const g = ch === 'W' ? mod.window(win) : ch === 'S' ? mod.window({ ...win, width: cell * 0.75, height: storey * 0.62, sill: 0.45, planter: false })
|
|
266
|
+
: ch === 'D' ? mod.door({}) : ch === '.' ? mod.wall() : null;
|
|
267
|
+
if (!g) throw new Error(`modular kit: unknown facade letter "${ch}" (W window, S shop window, D door, . wall)`);
|
|
268
|
+
place(g, x, f * storey, z, ry, info);
|
|
269
|
+
if (ch === 'S') place(mod.awning({ width: cell * 0.85, y: storey * 0.88 }), x, f * storey, z, ry, { type: 'awning', side, floor: f, i });
|
|
270
|
+
if (ch === 'D' && sign && !signed && side === 'front') {
|
|
271
|
+
signed = true;
|
|
272
|
+
place(mod.sign({ text: sign, width: cell * 0.8, y: storey * 0.85 }), x, 0, z, ry, { type: 'sign', side, floor: 0, i });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
// pilasters on the four corners of every floor, then trim bands: front/back strips run past the corners by their depth, side strips
|
|
278
|
+
// stop at the wall faces, so the strips touch without overlapping (overlapping coplanar faces would flicker)
|
|
279
|
+
for (let f = 0; f < floors; f++) for (const [x, z] of [[W / 2, D / 2], [-W / 2, D / 2], [W / 2, -D / 2], [-W / 2, -D / 2]]) {
|
|
280
|
+
place(mod.corner({}), x, f * storey, z, 0, { type: 'corner', floor: f });
|
|
281
|
+
}
|
|
282
|
+
if (trim !== 'none') for (let f = 1; f <= floors; f++) {
|
|
283
|
+
const top = f === floors, h = top ? 0.3 : 0.18, d = top ? 0.22 : 0.12, y = f * storey - h;
|
|
284
|
+
for (const side of SIDES) {
|
|
285
|
+
const along = side === 'front' || side === 'back', len = along ? W + 2 * d : D, [, , ry] = frame(side, 0);
|
|
286
|
+
const [x, z] = side === 'front' ? [0, D / 2] : side === 'back' ? [0, -D / 2] : side === 'right' ? [W / 2, 0] : [-W / 2, 0];
|
|
287
|
+
place(mod.trim({ length: len, profile: trim, height: h, depth: d }), x, y, z, ry, { type: 'trim', side, floor: f });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (roof === 'gable') {
|
|
291
|
+
place(mod.gable({ width: W, depth: D, pitch }), 0, H, 0, 0, { type: 'roof' });
|
|
292
|
+
if (chimney) place(mod.chimney({ height: D / 2 * pitch + 1.2 }), W / 2 - cell / 2, H, -D / 4, 0, { type: 'chimney' });
|
|
293
|
+
} else if (roof === 'flat') place(mod.flatRoof({ width: W, depth: D, parapet }), 0, H, 0, 0, { type: 'roof' });
|
|
294
|
+
else throw new Error(`modular kit: unknown roof "${roof}" (gable, flat)`);
|
|
295
|
+
root.userData.building = { cells: [width, depth], floors, size: [W, H, D] };
|
|
296
|
+
return root;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* A street: count buildings in a row along +x, front faces on z = 0, each snapped to whole cells with gap cells between them.
|
|
301
|
+
* Variation is seeded and chosen from a few options per trait (floors, width, roof, window variant, trim profile, door spot, shop
|
|
302
|
+
* fronts, sign), so no two neighbours repeat yet geometry stays shared.
|
|
303
|
+
*/
|
|
304
|
+
function street(p) {
|
|
305
|
+
const { seed = 1, count = 10, gap = 1, signs = 'BAKERY,BOOKS,CAFE,TOOLS,TEA,HOTEL' } = p;
|
|
306
|
+
const rand = rng(seed), pick = a => a[Math.floor(rand() * a.length)], root = new THREE.Group(), names = signs.split(',').filter(Boolean);
|
|
307
|
+
const trims = Object.keys(profiles);
|
|
308
|
+
root.name = 'street';
|
|
309
|
+
let x = 0;
|
|
310
|
+
for (let b = 0; b < count; b++) {
|
|
311
|
+
const width = pick([2, 3, 3, 4]), depth = pick([2, 3]), floors = pick([1, 2, 2, 3]), roof = rand() < 0.6 ? 'gable' : 'flat';
|
|
312
|
+
const door = Math.floor(rand() * width), shop = rand() < 0.5;
|
|
313
|
+
// upper floors mirror around the middle: a symmetric facade reads as designed, a fully random one as noise
|
|
314
|
+
const half = Array.from({ length: Math.ceil(width / 2) }, () => (rand() < 0.8 ? 'W' : '.'));
|
|
315
|
+
const upper = [...half, ...half.slice(0, Math.floor(width / 2)).reverse()].join('');
|
|
316
|
+
const ground = Array.from({ length: width }, (_, i) => (i === door ? 'D' : shop ? 'S' : 'W')).join('');
|
|
317
|
+
const params = {
|
|
318
|
+
width, depth, floors, roof, pitch: pick([0.5, 0.7]), parapet: pick([0.4, 0.8]), trim: pick(trims), window: Math.floor(rand() * windows.length),
|
|
319
|
+
front: floors > 1 ? `${ground}/${upper}` : ground, back: upper, left: Array.from({ length: depth }, () => (rand() < 0.3 ? 'W' : '.')).join(''),
|
|
320
|
+
right: '.'.repeat(depth), sign: shop && names.length ? pick(names) : '', chimney: roof === 'gable' && rand() < 0.5,
|
|
321
|
+
};
|
|
322
|
+
const g = building(params);
|
|
323
|
+
g.position.set((x + width / 2) * cell, 0, -(depth * cell) / 2); // whole cells: every module edge lands on the grid
|
|
324
|
+
g.userData.params = params;
|
|
325
|
+
root.add(g);
|
|
326
|
+
x += width + gap;
|
|
327
|
+
}
|
|
328
|
+
root.userData.street = { seed, count, length: (x - gap) * cell };
|
|
329
|
+
return root;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// ---- manifest entries: { build, params } so threedog gallery, hot swap and the panel's tune work on every piece -----------------------
|
|
333
|
+
// cache: false because the slot materials are live objects of the game, not params (the dev cache would keep a stale material)
|
|
334
|
+
const n = (d, min, max) => ({ type: 'number', default: d, min, max });
|
|
335
|
+
const entry = (build, params) => ({ build, params, cache: false });
|
|
336
|
+
const w0 = windows[0];
|
|
337
|
+
const models = {
|
|
338
|
+
[`${prefix}-wall`]: entry(() => mod.wall(), {}),
|
|
339
|
+
[`${prefix}-window`]: entry(p => mod.window(p), { width: n(w0.width, 0.3, cell - 0.3), height: n(w0.height, 0.4, storey - 0.6), sill: n(w0.sill, 0.2, storey - 1),
|
|
340
|
+
mullions: { type: 'int', default: w0.mullions, min: 0, max: 4 }, planter: { type: 'bool', default: !!w0.planter }, inset: n(0.08, 0, T - 0.04) }),
|
|
341
|
+
[`${prefix}-door`]: entry(p => mod.door(p), { width: n(1, 0.6, cell - 0.4), height: n(2.2, 1.6, storey - 0.4) }),
|
|
342
|
+
[`${prefix}-corner`]: entry(p => mod.corner(p), { size: n(T * 1.6, T, 1) }),
|
|
343
|
+
[`${prefix}-trim`]: entry(p => mod.trim(p), { length: n(cell, 0.5, 20), profile: { type: 'string', default: 'step', values: Object.keys(profiles) },
|
|
344
|
+
height: n(0.25, 0.05, 1), depth: n(0.15, 0.02, 0.6) }),
|
|
345
|
+
[`${prefix}-gable`]: entry(p => mod.gable(p), { width: n(cell * 3, cell, 20), depth: n(cell * 2, cell, 12), pitch: n(0.6, 0.2, 1.5), overhang: n(0.3, 0, 1) }),
|
|
346
|
+
[`${prefix}-flatRoof`]: entry(p => mod.flatRoof(p), { width: n(cell * 3, cell, 20), depth: n(cell * 2, cell, 12), parapet: n(0.6, 0.1, 1.5) }),
|
|
347
|
+
[`${prefix}-awning`]: entry(p => mod.awning(p), { width: n(1.6, 0.5, 6), depth: n(0.9, 0.3, 2), drop: n(0.4, 0, 1), stripes: { type: 'int', default: 7, min: 1, max: 20 } }),
|
|
348
|
+
[`${prefix}-sign`]: entry(p => mod.sign(p), { text: { type: 'string', default: 'SIGN' }, width: n(1.6, 0.4, 6), height: n(0.45, 0.2, 2) }),
|
|
349
|
+
[`${prefix}-chimney`]: entry(p => mod.chimney(p), { width: n(0.5, 0.2, 1.5), height: n(2, 0.5, 5) }),
|
|
350
|
+
[`${prefix}-building`]: entry(p => building(p), {
|
|
351
|
+
width: { type: 'int', default: 3, min: 1, max: 8 }, depth: { type: 'int', default: 2, min: 1, max: 6 }, floors: { type: 'int', default: 2, min: 1, max: 8 },
|
|
352
|
+
roof: { type: 'string', default: 'gable', values: ['gable', 'flat'] }, pitch: n(0.6, 0.2, 1.5), parapet: n(0.6, 0.1, 1.5),
|
|
353
|
+
trim: { type: 'string', default: 'step', values: [...Object.keys(profiles), 'none'] }, window: { type: 'int', default: 0, min: 0, max: windows.length - 1 },
|
|
354
|
+
front: { type: 'string', default: 'SDS/WWW' }, back: { type: 'string', default: 'W.W' }, left: { type: 'string', default: '.W' }, right: { type: 'string', default: '..' },
|
|
355
|
+
sign: { type: 'string', default: 'SHOP' }, chimney: { type: 'bool', default: true },
|
|
356
|
+
}),
|
|
357
|
+
[`${prefix}-street`]: entry(p => street(p), { seed: { type: 'int', default: 1, min: 0, max: 99999 }, count: { type: 'int', default: 10, min: 1, max: 40 },
|
|
358
|
+
gap: { type: 'int', default: 1, min: 0, max: 4 }, signs: { type: 'string', default: 'BAKERY,BOOKS,CAFE,TOOLS,TEA,HOTEL' } }),
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Merge a finished, static group into one mesh per material (world transforms baked in): the fewest draw calls (one per slot), at the price
|
|
363
|
+
* of culling (the whole merged mesh is drawn when any part is on screen) and of editing single pieces later. The input is left as it was.
|
|
364
|
+
* @param {THREE.Object3D} root
|
|
365
|
+
*/
|
|
366
|
+
function merge(root) {
|
|
367
|
+
root.updateWorldMatrix(true, true);
|
|
368
|
+
const byMat = new Map(), out = new THREE.Group();
|
|
369
|
+
root.traverse(o => {
|
|
370
|
+
const m = /** @type {THREE.Mesh} */ (o);
|
|
371
|
+
if (!m.isMesh) return;
|
|
372
|
+
const g = (m.geometry.index ? m.geometry.toNonIndexed() : m.geometry.clone()).applyMatrix4(m.matrixWorld);
|
|
373
|
+
for (const k of Object.keys(g.attributes)) if (!['position', 'normal', 'uv', 'color'].includes(k)) g.deleteAttribute(k);
|
|
374
|
+
g.clearGroups();
|
|
375
|
+
(byMat.get(m.material) ?? byMat.set(m.material, []).get(m.material)).push(g);
|
|
376
|
+
});
|
|
377
|
+
for (const [mat, list] of byMat) {
|
|
378
|
+
const mesh = new THREE.Mesh(mergeGeometries(list), mat);
|
|
379
|
+
mesh.castShadow = mesh.receiveShadow = true;
|
|
380
|
+
out.add(mesh);
|
|
381
|
+
for (const g of list) g.dispose();
|
|
382
|
+
}
|
|
383
|
+
out.name = root.name + '-merged';
|
|
384
|
+
return out;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return {
|
|
388
|
+
/** asset pack: engine.assets.manifest(kit.pack) */
|
|
389
|
+
pack: { name: `${prefix}-kit`, models },
|
|
390
|
+
modules: mod, building, street, merge, cell, storey, wall: T, slots,
|
|
391
|
+
/** shared geometries made so far (each module + params once) */
|
|
392
|
+
get geometries() { return geoCache.size; },
|
|
393
|
+
/** Free every geometry, texture and textured material the kit made (the slot materials are the game's and stay) */
|
|
394
|
+
dispose() {
|
|
395
|
+
for (const g of geoCache.values()) for (const x of Object.values(g)) x.dispose();
|
|
396
|
+
for (const t of texCache.values()) t.dispose();
|
|
397
|
+
for (const m of matCache.values()) m.dispose();
|
|
398
|
+
geoCache.clear(); texCache.clear(); matCache.clear();
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** Vertical stripes, white and light gray: a luminance mask (the material's color supplies the hue) */
|
|
404
|
+
function stripeTexture(stripes) {
|
|
405
|
+
const c = document.createElement('canvas'); c.width = stripes * 2 * 8; c.height = 8;
|
|
406
|
+
const x = /** @type {CanvasRenderingContext2D} */ (c.getContext('2d'));
|
|
407
|
+
for (let i = 0; i < stripes * 2; i++) { x.fillStyle = i % 2 ? '#bdbdbd' : '#ffffff'; x.fillRect(i * 8, 0, 8, 8); }
|
|
408
|
+
const t = new THREE.CanvasTexture(c);
|
|
409
|
+
t.colorSpace = THREE.SRGBColorSpace; t.magFilter = THREE.NearestFilter; // crisp stripe edges up close
|
|
410
|
+
return t;
|
|
411
|
+
}
|
|
412
|
+
/** Text centered on white, sized to fill the board */
|
|
413
|
+
function textTexture(text, aspect) {
|
|
414
|
+
const h = 64, c = document.createElement('canvas'); c.width = Math.round(h * aspect); c.height = h;
|
|
415
|
+
const x = /** @type {CanvasRenderingContext2D} */ (c.getContext('2d'));
|
|
416
|
+
x.fillStyle = '#ffffff'; x.fillRect(0, 0, c.width, h);
|
|
417
|
+
x.fillStyle = '#262626'; x.textAlign = 'center'; x.textBaseline = 'middle';
|
|
418
|
+
let size = h * 0.62;
|
|
419
|
+
x.font = `bold ${size}px sans-serif`;
|
|
420
|
+
const fit = x.measureText(text).width;
|
|
421
|
+
if (fit > c.width * 0.9) { size *= (c.width * 0.9) / fit; x.font = `bold ${size}px sans-serif`; }
|
|
422
|
+
x.fillText(text, c.width / 2, h / 2);
|
|
423
|
+
const t = new THREE.CanvasTexture(c);
|
|
424
|
+
t.colorSpace = THREE.SRGBColorSpace; t.anisotropy = 4;
|
|
425
|
+
return t;
|
|
426
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Modular building demo (page /modular-building.html): one seeded street from kit.js, drawn with one of three material sets.
|
|
3
|
+
// URL: ?set=gray|warm|cool (gray = the block-out, the default) &seed=1 &count=10 &view=street|close &batch=0 (draw every piece on its own) | merge (kit.merge: one mesh per material).
|
|
4
|
+
// The two coloured sets exist to show the kit is style-free: same seed, same shapes, other slots and trim profiles. They are demo values,
|
|
5
|
+
// not a recommended look. Test page for tests/specs/modular-building.mjs: window.mbTest = { kit, street, createModularKit, makeSlots, bakeVertexAO, THREE }.
|
|
6
|
+
import { createEngine, fixedCamera, makeMaterial, bakeVertexAO, THREE } from '../../../index.js';
|
|
7
|
+
import { createModularKit, PROFILES } from './kit.js';
|
|
8
|
+
|
|
9
|
+
const url = new URLSearchParams(location.search);
|
|
10
|
+
const set = url.get('set') ?? 'gray', seed = Number(url.get('seed') ?? 1), count = Number(url.get('count') ?? 10);
|
|
11
|
+
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), ui: { loading: false }, saveKey: 'threedog-modular-building',
|
|
12
|
+
batching: url.get('batch') === '0' || url.get('batch') === 'merge' ? false : undefined });
|
|
13
|
+
|
|
14
|
+
/** Slot materials for one set. A game makes these from its own style (makeMaterial roles, or plain three.js materials) */
|
|
15
|
+
function makeSlots(name = 'gray') {
|
|
16
|
+
const m = (/** @type {number} */ color, extra = {}) => makeMaterial('prop', { color, ...extra });
|
|
17
|
+
if (name === 'gray') return { wall: m(0x9c9c9c), trim: m(0xbdbdbd), roof: m(0x6c6c6c), frame: m(0x5c5c5c), glass: m(0x3c4046, { roughness: 0.3 }),
|
|
18
|
+
accent: m(0x7c7c7c), awning: m(0xc4c4c4), sign: m(0xd2d2d2) };
|
|
19
|
+
if (name === 'warm') return { wall: m(0xd9c7a3), trim: m(0xf0e9da), roof: m(0xa4553a), frame: m(0x3f5b45), glass: m(0x2e3d4f, { roughness: 0.2 }),
|
|
20
|
+
accent: m(0x7a4e33), awning: m(0xb8433a), sign: m(0xe0b54a) };
|
|
21
|
+
if (name === 'cool') return { wall: m(0x4a5260), trim: m(0x9aa3ad), roof: m(0x2c3038), frame: m(0x30c0d0, { emissive: 0x1a6a74, emissiveIntensity: 0.6 }),
|
|
22
|
+
glass: m(0x1b2a33, { roughness: 0.15, emissive: 0x0e2a33, emissiveIntensity: 0.5 }), accent: m(0xd07a30), awning: m(0x2f8f9a), sign: m(0xe6edf2) };
|
|
23
|
+
throw new Error(`modular-building: unknown set "${name}" (gray, warm, cool)`);
|
|
24
|
+
}
|
|
25
|
+
// a style swaps trim profiles too: same names (so a seed picks the same trim slot), other cross-sections. Hard-edged for the cool set
|
|
26
|
+
const cutProfiles = { flat: PROFILES.flat, step: [[0, 0], [1, 0], [1, 0.35], [0.4, 0.35], [0.4, 1], [0, 1]], cove: [[0, 0], [0.6, 0], [1, 0.4], [1, 1], [0, 1]] };
|
|
27
|
+
const kit = createModularKit({ slots: makeSlots(set), profiles: set === 'cool' ? cutProfiles : PROFILES });
|
|
28
|
+
engine.assets.manifest(kit.pack); // every module, a building and the street, by name: threedog gallery, hot swap, ?panel=1 tuning
|
|
29
|
+
|
|
30
|
+
const ground = new THREE.Mesh(new THREE.PlaneGeometry(400, 400), makeMaterial('terrain', { color: 0x8c8c86 }));
|
|
31
|
+
ground.rotation.x = -Math.PI / 2; ground.receiveShadow = true;
|
|
32
|
+
engine.scene.add(ground);
|
|
33
|
+
|
|
34
|
+
const shots = /** @type {any} */ ({
|
|
35
|
+
street: { position: [-9, 10, 22], lookAt: [22, 3, -4], fov: 50 },
|
|
36
|
+
close: { position: [3, 4.5, 11], lookAt: [6, 3.2, -2], fov: 45 },
|
|
37
|
+
});
|
|
38
|
+
engine.use(fixedCamera({ shots, start: url.get('view') ?? 'street' }));
|
|
39
|
+
|
|
40
|
+
// built directly here so the URL can pick the seed; a game names it in content instead: { model: ['mb-street', { seed: 7 }], x: 0, z: 0 }
|
|
41
|
+
const built = kit.street({ seed, count });
|
|
42
|
+
built.userData.batch = true; // opt in to engine.batching before adding: identical module meshes become one InstancedMesh per cell
|
|
43
|
+
const street = url.get('batch') === 'merge' ? kit.merge(built) : built;
|
|
44
|
+
engine.scene.add(street);
|
|
45
|
+
|
|
46
|
+
Object.assign(window, { engine, mbTest: { kit, street, createModularKit, makeSlots, bakeVertexAO, THREE } });
|
|
47
|
+
engine.start();
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Night lights: street lamps, lit windows and signs that read as light at night without glaring, and fade in at dusk.
|
|
2
|
+
|
|
3
|
+
# Night lights (technique example)
|
|
4
|
+
|
|
5
|
+
A neutral gray street at night with lamps, lit windows and signs. Run `npm run dev` and open `/night-lights.html` (`?time=22:00`, `halo=0`,
|
|
6
|
+
`bloom=0`, `glare=1` shows the classic mistakes all at once). The engine never imports this folder.
|
|
7
|
+
|
|
8
|
+
## The principle
|
|
9
|
+
A light at night is read from what it lights, not from how bright its bulb is: a pool on the ground that fades smoothly, a small hot core,
|
|
10
|
+
colored windows, and a night that is darker than all of them.
|
|
11
|
+
|
|
12
|
+
**Light pools come from distance and decay, not from big intensities.** Physical lights fall off as the square of the distance: with
|
|
13
|
+
`decay: 2` the ground under a lamp gets `intensity / height²`. A downward spot with a wide, soft cone puts the light on the ground and leaves
|
|
14
|
+
the facades above dark, like a real cut-off fixture. `distance` only cuts the tail; keep it a few times the lamp height so the edge comes
|
|
15
|
+
from decay.
|
|
16
|
+
|
|
17
|
+
**Which pixels bloom is the threshold's choice.** The tone curve (AgX by default) compresses everything above ~1 toward white. Bloom adds light
|
|
18
|
+
around pixels above its `threshold` (linear, before the curve). Usually it sits between the windows and the lamp heads, so only the small heads
|
|
19
|
+
glow and windows and signs read as colored light; if your game wants a hazy, everything-glows night, set it lower on purpose.
|
|
20
|
+
|
|
21
|
+
**Emissive is a color, not a brightness knob.** Saturated emissive colors survive the tone curve; near-white ones have no headroom and clip
|
|
22
|
+
to flat white rectangles (why: recipe 52-look "Night glow", headroom). Get the warmth from the color and let bloom carry the halo; the
|
|
23
|
+
intensities in this example are its values, not targets.
|
|
24
|
+
|
|
25
|
+
**Lights read when the night is darker than they are.** If the ambient at night is close to the pool brightness, the lamps look painted on.
|
|
26
|
+
Usually the night is darkened until the pools carry the scene, with enough left that the dark parts hold some shape; if your game wants a
|
|
27
|
+
bright, readable night, keep the ambient up and let the lamps be accents instead.
|
|
28
|
+
|
|
29
|
+
**A halo is cheap glow.** An additive sprite with a soft falloff around each head gives the "light in damp air" look without any post pass.
|
|
30
|
+
|
|
31
|
+
**Lights fade in.** A hard switch at 18:00 pops; fade by daylight.
|
|
32
|
+
|
|
33
|
+
How to judge it in a shot at the game's camera: the ground under a lamp is clearly brighter than half way to the next one, and the pool fades
|
|
34
|
+
without a ring; around a lamp only its core is white (the look check of `threedog shot` / `threedog snap` names each light or glowing material that blows pixels out, and the detail lost under it); the "near black" share stays low enough
|
|
35
|
+
that shapes hold.
|
|
36
|
+
|
|
37
|
+
| Symptom | Cause | Fix |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| Lamp heads and windows are flat white blocks | emissive far above the tone curve's shoulder: everything clips to the same white | lower emissiveIntensity, use a saturated color; usually only the small lamp core clips (more if your game wants blinding light) |
|
|
40
|
+
| A wall next to a lamp is a bright blown-out sheet | `decay: 0` (or 1) and the light close to the wall: no falloff, the whole wall gets the full intensity | `decay: 2`, aim a spot down, move the light off the wall |
|
|
41
|
+
| The whole night scene glows and looks foggy | bloom threshold below 1: every lit surface blooms | threshold between window and lamp-head brightness |
|
|
42
|
+
| Everything is too bright or too gray at night | exposure or ambient set for the day | lower the night ambient (sky keyframes or `engine.mod('look.lights.hemi.intensity')`) rather than the lights |
|
|
43
|
+
| Halo plus bloom look like a smear | both at full strength | pick one as the main glow, keep the other faint |
|
|
44
|
+
| Lights pop on at nightfall | a hard switch at 18:00 | fade by daylight (`dusk`) |
|
|
45
|
+
|
|
46
|
+
`?glare=1` on the demo page shows the first three at once.
|
|
47
|
+
|
|
48
|
+
## Plain three.js
|
|
49
|
+
- Lamps: [SpotLight](https://threejs.org/docs/#api/en/lights/SpotLight) aimed down with `decay: 2`, a wide `angle` and soft `penumbra`;
|
|
50
|
+
intensity in candela ([webgl_lights_spotlight](https://threejs.org/examples/#webgl_lights_spotlight)). Many lamps: keep a fixed number of
|
|
51
|
+
lights and move them to the nearest lamps, so the light count never changes.
|
|
52
|
+
- Windows and lamp heads: `MeshStandardMaterial.emissive` and `emissiveIntensity`, faded by a daylight value.
|
|
53
|
+
- Bloom: `UnrealBloomPass` with `threshold`, `strength`, `radius` ([webgl_postprocessing_unreal_bloom](https://threejs.org/examples/#webgl_postprocessing_unreal_bloom)).
|
|
54
|
+
- Halo: a [Sprite](https://threejs.org/docs/#api/en/objects/Sprite) with a radial-gradient texture, `blending: THREE.AdditiveBlending`,
|
|
55
|
+
`depthWrite: false`.
|
|
56
|
+
|
|
57
|
+
## Style routes
|
|
58
|
+
- **Naturalistic**: pooled spot lights with decay 2, saturated warm windows, bloom only on lamp cores. One bloom pass.
|
|
59
|
+
- **Bloom-free / mobile**: halo sprites as the only glow, emissive windows. One sprite draw per lamp batch, no post pass.
|
|
60
|
+
- **Stylized / toon**: a projected decal or a baked light texture instead of the spot pool, a hand-drawn halo sprite, the window emissive as
|
|
61
|
+
a palette color; decay 2 still gives pools an edge. No real lights at all if decals carry it.
|
|
62
|
+
- **Painterly**: soft wide pools, a colored fog around lamps, halos larger and fainter. Fog and sprites only.
|
|
63
|
+
- **Pixel art**: hard-edged pools in two or three palette steps, no bloom. A texture lookup.
|
|
64
|
+
|
|
65
|
+
## The engine helper (optional convenience)
|
|
66
|
+
`threedog examples pull night-lights` copies it. Only `nightLights.js` is the technique (defaults in `NIGHT_LIGHTS_DEFAULTS`); `main.js` is the
|
|
67
|
+
demo scene, in a game change its import to `from 'threedog'`, then:
|
|
68
|
+
```js
|
|
69
|
+
engine.use(lightPool({ point: 4, spot: 8 })); // real lights for the nearest lamps; the rest wait their turn
|
|
70
|
+
const lights = createNightLights(engine);
|
|
71
|
+
lights.addLamp(headPosition, { head: headMaterial }); // pooled spot aimed down + emissive head + halo
|
|
72
|
+
lights.addGlow(windowMaterial); // look.materials.glow: emissive fades in at dusk
|
|
73
|
+
```
|
|
74
|
+
This example's current values: 80 cd at 5.5 m, so the pool center is a little under the brightness a sunlit mid-gray gets (recipe 52 "How
|
|
75
|
+
bright a lit color comes out"); raise it for brighter streets, lower it for moody ones. Lamp heads at 2.5, windows at 0.6, bloom threshold 1.4.
|
|
76
|
+
The demo lowers the sky ambient by the same night factor (a game's own sky keyframes normally do this). With bloom on, keep the halo's
|
|
77
|
+
opacity low; they stack.
|
|
78
|
+
|
|
79
|
+
Cost (the demo street): 8 pooled spot lights (no shadows) for any number of lamps; one emissive material per kind of glow; one sprite per lamp
|
|
80
|
+
sharing one material and a 64 px texture; bloom is one `UnrealBloomPass` (several half-resolution blur passes; costly on integrated GPUs, the
|
|
81
|
+
engine starts it off on low-tier devices). Spot shadows add one shadow map each (another pass over the casters): this example gives none; a game that wants lamp shadows picks its hero lamps and measures the frame time as it adds them.
|
|
82
|
+
|
|
83
|
+
Rules (correctness):
|
|
84
|
+
- Lamps take their real lights from `engine.lightPool` (`lightPool({ spot })`): a fixed number of three.js lights, so many lamps never
|
|
85
|
+
recompile shaders or add per-light cost. Without the pool it throws.
|
|
86
|
+
- The night factor comes from the time of day (`engine.calendar.daylight`, the sky's when there is no calendar). Nothing here is saved: it
|
|
87
|
+
is recomputed from the time each frame, so loads and time skips are right by construction.
|
|
88
|
+
- A glow rule drives every mesh using that material: give dark windows their own material (the demo uses two lit ones and plain wall gray).
|
|
89
|
+
- Windows, signs and lamp heads use the engine's night glow (`engine.look.materials.glow(material, { night })`, recipe 52 "Night glow"):
|
|
90
|
+
the engine fades their `emissiveIntensity` with daylight. The lamps' real lights need a number, so the technique computes the same fade
|
|
91
|
+
from `daylight` (`dusk` is set to the glow's range) and sets the pooled lights; `lights.force(v)` holds it.
|
|
92
|
+
|
|
93
|
+
Sources: written for this example; no code copied. Light units and falloff as documented for three.js physically based lights; the bloom pass
|
|
94
|
+
is three's `UnrealBloomPass` through `@threedog/post-effects`.
|