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
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
// Sheep island: a small floating island built only from the engine's public entry points (the acceptance scene of docs/plans/acceptance-sheepisland.md).
|
|
2
|
+
// Sheep island: a small floating island built only from the engine's public entry points (the acceptance scene of docs/plans/done/acceptance-sheepisland.md).
|
|
3
3
|
// A meadow with a river, round trees, a wheat field and a flock of sheep on an island with a ragged rim, over a pale backdrop with no horizon.
|
|
4
4
|
// Parameters (params.js): time day | dusk | night, weather clear | snow, view overview | flock | field | river | rim.
|
|
5
5
|
// main.js holds wiring only: modules, the island's terrain functions, view switching and the snow-to-winter link. Objects are content (rule R33),
|
|
6
|
-
// the look is the style
|
|
6
|
+
// the look is the style in style/.
|
|
7
7
|
import { params, VIEW_NAMES } from './params.js'; // first: rewrites ?time=dusk style words before the engine reads the URL
|
|
8
8
|
import { createEngine, openWorld, presets, content, fixedCamera } from '../../index.js';
|
|
9
|
-
import style
|
|
9
|
+
import style from './style/index.js';
|
|
10
|
+
import packs from './assets.js';
|
|
10
11
|
import data from './content/index.js';
|
|
11
12
|
import { VIEWS } from './views.js';
|
|
12
13
|
|
|
@@ -14,12 +15,16 @@ import { VIEWS } from './views.js';
|
|
|
14
15
|
// Every function runs in terrain workers: pure, only its parameters and Math (recipe 28 §1).
|
|
15
16
|
const island = {
|
|
16
17
|
resolution: 48, // 64 m chunk / 48 = 1.33 m cells: the rim is cut along cells, so finer cells give a finer brushed edge (recipe 42 §4)
|
|
18
|
+
// the river's centre line z = amp * sin(x * freq) + shift: one set of numbers both functions read (n.params), so the dip and the river
|
|
19
|
+
// ground type cannot drift apart
|
|
20
|
+
params: { river: { amp: 6, freq: 0.09, shift: 2, dip: 3.2, wet: 2.4 } },
|
|
17
21
|
height: (x, z, n) => {
|
|
18
|
-
const d = Math.abs(z - (
|
|
19
|
-
return 3 + 1.2 * n.fbm(x * 0.03, z * 0.03) - (d <
|
|
22
|
+
const r = n.params.river, d = Math.abs(z - (r.amp * Math.sin(x * r.freq) + r.shift)); // distance to the river's centre line
|
|
23
|
+
return 3 + 1.2 * n.fbm(x * 0.03, z * 0.03) - (d < r.dip ? (1 - d / r.dip) * 0.6 : 0); // a gentle meadow, a shallow dip for the river
|
|
20
24
|
},
|
|
21
|
-
groundType: (x, z) => {
|
|
22
|
-
|
|
25
|
+
groundType: (x, z, h, slope, n) => {
|
|
26
|
+
const r = n.params.river;
|
|
27
|
+
if (Math.abs(z - (r.amp * Math.sin(x * r.freq) + r.shift)) < r.wet) return 'river';
|
|
23
28
|
const fx = (x - 14) / 9.5, fz = (z + 13) / 6.5; // the wheat field: an ellipse north-east of the river
|
|
24
29
|
return fx * fx + fz * fz < 1 ? 'wheat' : 'grass';
|
|
25
30
|
},
|
|
@@ -35,19 +40,19 @@ const island = {
|
|
|
35
40
|
|
|
36
41
|
// ---------- 2. Engine: own style, open-world preset with a fixed sky; a two-season calendar so snow can turn the island white ----------
|
|
37
42
|
const WINTER_DAY = 1001; // seasons last 1000 days each, so the season never blends towards the next one (it does over the last 20%)
|
|
38
|
-
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), style, saveKey: 'threedog-sheepisland',
|
|
43
|
+
const engine = createEngine({ bindings: { ...presets.bindings.debug }, canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), style, saveKey: 'threedog-sheepisland',
|
|
39
44
|
ui: { loading: { title: 'sheep island' } } });
|
|
40
45
|
engine.use(openWorld({ camera: fixedCamera(), terrain: island, water: false, rigid: false, ambience: false,
|
|
41
|
-
|
|
46
|
+
calendar: { ...presets.calendar.fixedTime, time: 0.5, seasons: ['summer', 'winter'], daysPerSeason: 1000 },
|
|
42
47
|
weather: { ...presets.weather.temperate, start: 'clear' }, autoWeather: false }), content());
|
|
43
|
-
engine.assets.manifest(
|
|
48
|
+
engine.assets.manifest(packs);
|
|
44
49
|
engine.content.load(data);
|
|
45
50
|
|
|
46
51
|
// ---------- 3. Snow means winter: the engine's season tint (style.seasons.winter) whitens foliage and ground ----------
|
|
47
52
|
// The weather module sends no change event and a weather has no ground cover of its own, so the calendar day follows the weather each frame.
|
|
48
53
|
engine.onFrame(() => {
|
|
49
54
|
const day = engine.weather?.name === 'snow' ? WINTER_DAY : 1;
|
|
50
|
-
if (engine.
|
|
55
|
+
if (engine.calendar.day !== day) engine.calendar.day = day;
|
|
51
56
|
});
|
|
52
57
|
|
|
53
58
|
// ---------- 4. Views: an op, so the URL, the dev bridge and tests switch the same way ----------
|
|
@@ -63,7 +68,7 @@ engine.ops.define('sheepisland.view', {
|
|
|
63
68
|
},
|
|
64
69
|
reasons: { unknownView: 'View names: overview, flock, field, river, rim' },
|
|
65
70
|
});
|
|
66
|
-
engine.describe.add('sheepisland', () => ({ view: state.view, season: engine.
|
|
71
|
+
engine.describe.add('sheepisland', () => ({ view: state.view, season: engine.calendar.season, weather: engine.weather?.name }));
|
|
67
72
|
engine.events.on('engine:ready', () => engine.ops.run('sheepisland.view', { name: params.view }));
|
|
68
73
|
if (params.badView) console.warn(`sheepisland: unknown view '${params.badView}', showing overview. Views: ${VIEW_NAMES.join(', ')}`);
|
|
69
74
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// sheepisland:
|
|
2
|
-
//
|
|
1
|
+
// sheepisland: this game's style, LOOKS ONLY (recipes/09-style.md, 35-style-from-reference.md), filled in from the empty style/index.js
|
|
2
|
+
// a new game starts with. A soft painted diorama: few flat colors, round shapes, soft shadows, a pale warm background with no horizon.
|
|
3
3
|
// The world (island outline, river, wheat field) is the game's terrain() in ../main.js, never here.
|
|
4
4
|
import { makeMaterial, applyEffects } from '../../../index.js';
|
|
5
5
|
import { models, PALETTE } from './models.js';
|
|
@@ -11,15 +11,15 @@ export const assets = { name: 'sheepisland', models };
|
|
|
11
11
|
// Background: zenith = horizon = fog color at every time, so the dome is one flat tone and no horizon line shows.
|
|
12
12
|
// [time 0-1, zenith, horizon (= fog), sun color, sun intensity, ambient intensity]
|
|
13
13
|
// Ground material with snow that survives shading: 'texture'. The engine's season tint runs at color_fragment, before the per-chunk color map is
|
|
14
|
-
// multiplied in, so in 'mix' mode the map paints the green back over the white. This patch repeats the season mix later (emissivemap_fragment,
|
|
14
|
+
// multiplied in, so in 'mix' mode the map paints the green back over the white. This patch repeats the season mix later (slot emissive, emissivemap_fragment,
|
|
15
15
|
// after every color patch, before lighting), reading the engine's own season uniforms under new names (the season patch declares the old ones).
|
|
16
16
|
/** @param {any} engine */
|
|
17
17
|
function snowyGround(engine) {
|
|
18
18
|
const u = engine.uniforms;
|
|
19
19
|
return applyEffects(makeMaterial('terrain', { vertexColors: true }, engine), { clouds: false, patches: [{
|
|
20
20
|
name: 'snowCover', cacheKey: 1, uniforms: { uSnowTint: u.uGroundTint, uSnowMix: u.uGroundMix },
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
pars: 'uniform vec3 uSnowTint; uniform float uSnowMix;',
|
|
22
|
+
slot: 'emissive', glsl: 'diffuseColor.rgb = mix(diffuseColor.rgb, uSnowTint, uSnowMix);' }] });
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const DAY = 0xefebe4, DUSK = 0xf0d9c4, NIGHT = 0x2c3346;
|
|
@@ -28,7 +28,7 @@ export default {
|
|
|
28
28
|
exposure: 1,
|
|
29
29
|
toneMapping: 'neutral', // neutral keeps the painted colors close to what is written here (aces darkens and shifts them)
|
|
30
30
|
|
|
31
|
-
post:
|
|
31
|
+
// no post plugins: restraint, the reference shows no outline, bloom or grain
|
|
32
32
|
|
|
33
33
|
materials: {
|
|
34
34
|
default: { type: 'lambert' },
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":1,"files":{"content/items.js":{"kind":"items","mtime":1793494482512.194,"from":0,"count":3,"indexIds":0,"positional":[]},"content/npcs.js":{"kind":"npcs","mtime":1793540086876.2478,"from":0,"count":1,"indexIds":0,"positional":[]},"content/places.js":{"kind":"places","mtime":1793494482518.1973,"from":0,"count":2,"indexIds":0,"positional":[]},"content/props.js":{"kind":"props","mtime":1793494482521.1953,"from":0,"count":12,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1793699847094.7925,"from":0,"count":6,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1793699847095.7913,"from":0,"count":5,"indexIds":0,"positional":[]}},"ids":{"apple":[{"file":"content/items.js","kind":"items","line":3,"placed":false}],"key":[{"file":"content/items.js","kind":"items","line":4,"placed":false}],"wood":[{"file":"content/items.js","kind":"items","line":5,"placed":false},{"file":"content/props.js","kind":"props","line":10,"placed":true}],"guide":[{"file":"content/npcs.js","kind":"npcs","line":3,"placed":false}],"stage":[{"file":"content/places.js","kind":"places","line":3,"placed":false}],"water":[{"file":"content/places.js","kind":"places","line":4,"placed":false}],"pine":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"round-tree":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"rock":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"flower-a":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"flower-b":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"flower-c":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"stone":[{"file":"content/props.js","kind":"props","line":11,"placed":true}],"metal":[{"file":"content/props.js","kind":"props","line":12,"placed":true}],"glass":[{"file":"content/props.js","kind":"props","line":13,"placed":true}],"shadow-stage":[{"file":"content/props.js","kind":"props","line":14,"placed":true}],"room":[{"file":"content/props.js","kind":"props","line":15,"placed":true},{"file":"content/templates.js","kind":"templates","line":8,"placed":false}],"woodBlock":[{"file":"content/templates.js","kind":"templates","line":3,"placed":false}],"stoneBlock":[{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"metalBall":[{"file":"content/templates.js","kind":"templates","line":5,"placed":false}],"glassPanes":[{"file":"content/templates.js","kind":"templates","line":6,"placed":false}],"shadowStage":[{"file":"content/templates.js","kind":"templates","line":7,"placed":false}],"松树":[{"file":"content/vegetation.js","kind":"vegetation","line":4,"placed":false}],"圆树":[{"file":"content/vegetation.js","kind":"vegetation","line":10,"placed":false}],"石头":[{"file":"content/vegetation.js","kind":"vegetation","line":16,"placed":false}],"草":[{"file":"content/vegetation.js","kind":"vegetation","line":20,"placed":false}],"野花":[{"file":"content/vegetation.js","kind":"vegetation","line":25,"placed":false}]}}
|
|
@@ -11,11 +11,11 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
|
|
|
11
11
|
|
|
12
12
|
## Engine modules (engine.use)
|
|
13
13
|
|
|
14
|
-
- createEngine: {
|
|
15
|
-
- openWorld preset ({ camera: fixedCamera(), seed: SEED, terrain: terrainPreset(), flatten: [{ x: stage.x, z: stage.z, …) → world, terrain, vegetation, sky, weather, water, collision, rigid, characters, ambience, settings, debug
|
|
14
|
+
- createEngine: { bindings: { ...presets.bindings.walk, ...presets.bindings.interact, ...presets.bindings.inventory, ...prese…
|
|
15
|
+
- openWorld preset ({ camera: fixedCamera(), seed: SEED, terrain: terrainPreset(), flatten: [{ x: stage.x, z: stage.z, …) → world, terrain, vegetation, calendar, sky, weather, water, collision, rigid, characters, ambience, settings, debug
|
|
16
16
|
- interactions ({ ...presets.interactions.nearest })
|
|
17
17
|
- dialogue ({ holdSeconds: 1e6 })
|
|
18
|
-
- inventory
|
|
18
|
+
- inventory
|
|
19
19
|
- hud
|
|
20
20
|
- lightPool ({ point: 2 })
|
|
21
21
|
- content
|
|
@@ -25,19 +25,19 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
|
|
|
25
25
|
- world: `node_modules/threedog/docs/recipes/18-world.md` · `node_modules/threedog/docs/api/world.md`
|
|
26
26
|
- terrain: `node_modules/threedog/docs/recipes/28-terrain.md` · `node_modules/threedog/docs/api/terrain.md`
|
|
27
27
|
- vegetation: `node_modules/threedog/docs/recipes/10-blender-level.md` · `node_modules/threedog/docs/api/vegetation.md`
|
|
28
|
+
- calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
|
|
28
29
|
- sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
|
|
29
30
|
- weather: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/weather.md`
|
|
30
31
|
- water: `node_modules/threedog/docs/recipes/44-water-weather-look-hooks.md` · `node_modules/threedog/docs/api/water.md`
|
|
31
32
|
- collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
|
|
32
33
|
- rigid: `node_modules/threedog/docs/recipes/11-vehicles.md` · `node_modules/threedog/docs/api/rigid.md`
|
|
33
34
|
- characters: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/characters.md`
|
|
34
|
-
-
|
|
35
|
-
- …7 more modules: their pages are in `node_modules/threedog/docs/api/`
|
|
35
|
+
- …8 more modules: their pages are in `node_modules/threedog/docs/api/`
|
|
36
36
|
|
|
37
37
|
Not used yet (check these before writing the system yourself):
|
|
38
38
|
|
|
39
39
|
- saves: save your own state: `engine.saves.register(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
|
|
40
|
-
- quests: goals with steps, conditions and rewards: `quests(
|
|
40
|
+
- quests: goals with steps, conditions and rewards: `quests()` + key map presets.bindings.quests, content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
|
|
41
41
|
- grids: cell placement for farming and building: `grids()` (node_modules/threedog/docs/recipes/29-grid.md)
|
|
42
42
|
|
|
43
43
|
## Files
|
|
@@ -46,6 +46,7 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
46
46
|
|
|
47
47
|
| File | Lines | Description |
|
|
48
48
|
|---|---|---|
|
|
49
|
+
| assets.js | 7 | The asset packs this game registers (main.js: engine.assets.manifest(packs)). Kept in their own fil… |
|
|
49
50
|
| content/index.js | 10 | |
|
|
50
51
|
| content/items.js | 9 | |
|
|
51
52
|
| content/npcs.js | 9 | |
|
|
@@ -53,17 +54,15 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
53
54
|
| content/props.js | 17 | |
|
|
54
55
|
| content/templates.js | 10 | |
|
|
55
56
|
| content/vegetation.js | 32 | |
|
|
56
|
-
| look.js | 12 | This example's look, a style part merged over the
|
|
57
|
-
| main.js |
|
|
58
|
-
| models.js | 88 | The exhibits that are not in the
|
|
59
|
-
| overrides.js | 34 | What the style workbench exports: the values the user changed, as a plain object literal to paste i… |
|
|
60
|
-
| panel.js | 136 | Style workbench (?panel=1): sliders and color pickers over the running style test, plus an export o… |
|
|
57
|
+
| look.js | 12 | This example's look, a style part merged over the style under test (createEngine({ style: [worldSty… |
|
|
58
|
+
| main.js | 97 | @ts-check Style test: one fixed scene to judge a style by (and the check an AI runs after turning a… |
|
|
59
|
+
| models.js | 88 | The exhibits that are not in the world example's art (../world/art), built in code and registered b… |
|
|
61
60
|
| params.js | 33 | URL parameters of the style test page. Import this file first in main.js: it rewrites word values i… |
|
|
62
61
|
| views.js | 32 | Named camera positions of the style test. Same name = same framing every time, so two screenshots d… |
|
|
63
62
|
|
|
64
63
|
## NPCs (content/npcs.js)
|
|
65
64
|
|
|
66
|
-
| id | Name | Schedule |
|
|
65
|
+
| id | Name | Schedule | Interact |
|
|
67
66
|
|---|---|---|---|
|
|
68
67
|
| guide | Guide | wander | — |
|
|
69
68
|
|
|
@@ -90,7 +89,7 @@ Starting inventory: apple×5, key×1, wood×12. Pickups: 0.
|
|
|
90
89
|
- Place stage: a flat spot near water (found at startup); all exhibits are placed relative to it
|
|
91
90
|
- Place water: the nearest water to the stage (found at startup)
|
|
92
91
|
|
|
93
|
-
## Object templates (content/templates.js; placed with props { template }, spawned with engine.spawn)
|
|
92
|
+
## Object templates (content/templates.js; placed with props { template }, spawned with engine.content.spawn)
|
|
94
93
|
|
|
95
94
|
| Template | Model | Collide | Interact (op / label) | Container | State (defaults) | Instances |
|
|
96
95
|
|---|---|---|---|---|---|---|
|
|
@@ -126,10 +125,10 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
126
125
|
## Saves
|
|
127
126
|
|
|
128
127
|
- Save prefix saveKey: threedog-styletest
|
|
129
|
-
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `
|
|
128
|
+
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `threedog catalog` (saves per module)
|
|
130
129
|
|
|
131
|
-
## Style
|
|
130
|
+
## Style keys
|
|
132
131
|
|
|
133
|
-
- Style
|
|
132
|
+
- Style: parts
|
|
134
133
|
- Models (asset names): pine, pineLow, roundTree, roundTreeLow, rock, grass, flower, woodBlock, stoneBlock, metalBall, glassPanes, shadowStage, room
|
|
135
134
|
- Vegetation (content/vegetation.js): 松树, 圆树, 石头, 草, 野花
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The asset packs this game registers (main.js: engine.assets.manifest(packs)). Kept in their own file so `npm run check` imports the same
|
|
2
|
+
// objects and checks the model / sound names content uses against them (one source, no scanning of main.js).
|
|
3
|
+
import { assets as worldArt } from '../world/art/index.js'; // the world example's procedural trees / rocks / humanoid
|
|
4
|
+
import { woodBlock, stoneBlock, metalBall, glassPanes, shadowStage, room } from './models.js';
|
|
5
|
+
|
|
6
|
+
export default [worldArt, { name: 'styletest', models: { woodBlock, stoneBlock, metalBall, glassPanes, shadowStage, room } }]; // the names content/templates.js uses
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export default {
|
|
3
3
|
guide: {
|
|
4
4
|
name: 'Guide',
|
|
5
|
-
colors: { body: 0x4f6d8f, legs: 0x5b4a3a, hair: 0xd8d4cc },
|
|
5
|
+
model: 'humanoid', colors: { body: 0x4f6d8f, legs: 0x5b4a3a, hair: 0xd8d4cc },
|
|
6
6
|
start: { place: 'stage', x: 2.5, z: 4 }, behavior: 'wander', mind: { radius: 0 },
|
|
7
7
|
},
|
|
8
8
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Templates: the exhibits. Model names are registered in main.js (models.js); trees, rocks and flowers come from the
|
|
1
|
+
// Templates: the exhibits. Model names are registered in main.js (models.js); trees, rocks and flowers come from the world example's art (../world/art).
|
|
2
2
|
export default {
|
|
3
3
|
woodBlock: { model: 'woodBlock' },
|
|
4
4
|
stoneBlock: { model: 'stoneBlock' },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Vegetation: name -> model (an asset name from the
|
|
1
|
+
// Vegetation: name -> model (an asset name from the world example's asset pack, ../../world/art/; use an array for parameters) and growth rule.
|
|
2
2
|
// rule.biomes lists the biomes it grows in, values are spawn probabilities; rule cannot hold functions (it is sent to a worker thread).
|
|
3
3
|
export default {
|
|
4
4
|
松树: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// This example's look, a style part merged over the
|
|
1
|
+
// This example's look, a style part merged over the style under test (createEngine({ style: [worldStyle, look] }), worldStyle = ../world/style): how the test surfaces feel.
|
|
2
2
|
// The exhibits ask for roles wood / stone / metal / glass; a style that does not define them falls back to materials.default.
|
|
3
3
|
export default {
|
|
4
4
|
name: 'styletest',
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
// Style test: one fixed scene to judge a style
|
|
2
|
+
// Style test: one fixed scene to judge a style by (and the check an AI runs after turning a reference picture into a style).
|
|
3
3
|
// Exhibits (content/): character, trees, rock, grass, flowers, water, terrain, glass, a shadow receiver, wood / stone / metal, a lit room (outside and inside),
|
|
4
4
|
// and the UI parts (HUD, dialogue, bag) on the `ui` view. Parameters (params.js): time, weather, style, env, view, panel. Camera views: views.js.
|
|
5
5
|
// main.js holds wiring only: modules, finding the stage, view switching, the lamp. The exhibits are content (rule R33).
|
|
6
6
|
import { params } from './params.js'; // first: rewrites ?time=dusk style words before the engine reads the URL
|
|
7
7
|
import { createEngine, openWorld, presets, content, interactions, dialogue, inventory, fixedCamera, hud, lightPool, createTerrain } from '../../index.js';
|
|
8
|
-
|
|
8
|
+
// The style under test: the world example's style folder (its look, named 'world'); the world example's procedural trees / rocks / humanoid are registered from assets.js.
|
|
9
|
+
// To judge your own look, point this import and the one in assets.js at your game's style/index.js.
|
|
10
|
+
import worldStyle from '../world/style/index.js';
|
|
9
11
|
import { terrainPreset, riverAt, terrainStrings } from '@threedog/terrain-noise';
|
|
10
12
|
import look from './look.js';
|
|
11
13
|
import data from './content/index.js';
|
|
12
|
-
import
|
|
14
|
+
import packs from './assets.js';
|
|
13
15
|
import { makeViews, pathAt } from './views.js';
|
|
14
16
|
|
|
15
17
|
// ---------- 0. The stage: a flat spot with water close by (same seed = same place every run) ----------
|
|
@@ -32,25 +34,24 @@ for (let r = 0, found = false; r < 3000 && !found; r += 10) {
|
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
// ---------- 1. Engine: style under test + open-world preset with a fixed sky (no clock drift between screenshots) ----------
|
|
35
|
-
const parts = params.style === 'none' ? [] : [
|
|
37
|
+
const parts = params.style === 'none' ? [] : [worldStyle, look];
|
|
36
38
|
if (params.overrides) parts.push(params.overrides); // the workbench's "rebuild preview" values
|
|
37
|
-
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), style: parts.length ? parts : undefined, strings: terrainStrings, saveKey: 'threedog-styletest',
|
|
39
|
+
const engine = createEngine({ bindings: { ...presets.bindings.walk, ...presets.bindings.interact, ...presets.bindings.inventory, ...presets.bindings.debug, ...presets.bindings.dialogNumbers }, canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), style: parts.length ? parts : undefined, strings: terrainStrings, saveKey: 'threedog-styletest',
|
|
38
40
|
ui: { loading: { title: 'style test' } } });
|
|
39
|
-
engine.use(openWorld({ camera: fixedCamera(), seed: SEED, terrain: terrainPreset(), flatten: [{ x: stage.x, z: stage.z, radius: 30 }],
|
|
41
|
+
engine.use(openWorld({ camera: fixedCamera(), seed: SEED, terrain: terrainPreset(), flatten: [{ x: stage.x, z: stage.z, radius: 30 }], calendar: { ...presets.calendar.fixedTime, time: 0.5 },
|
|
40
42
|
weather: presets.weather.temperate, autoWeather: false }),
|
|
41
|
-
interactions({ ...presets.interactions.nearest }), dialogue({ holdSeconds: 1e6 }), inventory(
|
|
43
|
+
interactions({ ...presets.interactions.nearest }), dialogue({ holdSeconds: 1e6 }), inventory(), hud(), lightPool({ point: 2 }), content());
|
|
42
44
|
|
|
43
|
-
engine.assets.manifest(
|
|
44
|
-
engine.
|
|
45
|
-
engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: { x: stage.x + 0.5, z: stage.z + 6 } });
|
|
45
|
+
engine.assets.manifest(packs); // assets.js: the world example's trees / rocks and the test models content/templates.js uses
|
|
46
|
+
engine.characters.createPlayer({ ...presets.player.thirdPerson, model: params.style === 'none' ? null : 'humanoid', spawn: { x: stage.x + 0.5, z: stage.z + 6 } }); // style=none: the gray capsule
|
|
46
47
|
engine.content.load(data, { places: { stage, water } });
|
|
47
|
-
if (params.env) { engine.look.env.replace('sky'); engine.look.env.set({ intensity: 0.8 }); engine.
|
|
48
|
+
if (params.env) { engine.look.env.replace('sky'); engine.look.env.set({ intensity: 0.8 }); engine.mod('look.lights.hemi.intensity', { owner: 'env', mul: 0.6 }); } // soft ambient from the sky: lower the hemisphere ambient so shadows stay
|
|
48
49
|
|
|
49
50
|
// ---------- 2. The room's lamp: emissive plus one pooled light, on from 18:00 to 06:00 ----------
|
|
50
51
|
const lampPos = [stage.x + 14, engine.surface(stage.x + 14, stage.z - 2) + 2.7, stage.z - 2];
|
|
51
52
|
const lampLight = engine.lightPool.add({ x: lampPos[0], y: lampPos[1], z: lampPos[2] }, { color: 0xffc070, intensity: 0, distance: 9 });
|
|
52
53
|
let lampOn = false;
|
|
53
|
-
engine.
|
|
54
|
+
engine.calendar.between('18:00', '06:00', { on: () => { lampOn = true; }, off: () => { lampOn = false; } });
|
|
54
55
|
engine.onFrame(() => {
|
|
55
56
|
const lamp = /** @type {import('three').Mesh<any, import('three').MeshLambertMaterial> | undefined} */ (engine.world.view('room')?.getObjectByName('lamp'));
|
|
56
57
|
if (lamp) lamp.material.emissiveIntensity = lampOn ? 1.6 : 0;
|
|
@@ -63,7 +64,7 @@ const state = { view: params.view, since: 0, views: /** @type {any} */ (null) };
|
|
|
63
64
|
/** Show the UI exhibits only on the ui view; close them when leaving it */
|
|
64
65
|
function showUi(on) {
|
|
65
66
|
if (on) {
|
|
66
|
-
engine.dialogue.say('The light is best just before dusk. Mind the step.', { speaker: 'Guide',
|
|
67
|
+
engine.dialogue.say('The light is best just before dusk. Mind the step.', { speaker: 'Guide' }); // the main box, shown for its look
|
|
67
68
|
engine.ui.open('inventory');
|
|
68
69
|
} else { engine.dialogue.end(); engine.ui.close('inventory'); }
|
|
69
70
|
}
|
|
@@ -71,12 +72,12 @@ function showUi(on) {
|
|
|
71
72
|
function setView(name) {
|
|
72
73
|
const cam = /** @type {any} */ (engine.cameraRig), views = makeViews(engine, stage, water);
|
|
73
74
|
for (const [n, v] of Object.entries(views)) cam.add(n, { position: v.pos, lookAt: v.look });
|
|
74
|
-
state.view = name; state.since = engine.
|
|
75
|
+
state.view = name; state.since = engine.time.now('real'); state.views = views;
|
|
75
76
|
showUi(name === 'ui');
|
|
76
77
|
cam.cut(name);
|
|
77
78
|
}
|
|
78
79
|
engine.onFrame(() => {
|
|
79
|
-
if (state.view === 'path' && state.views) /** @type {any} */ (engine.cameraRig).shots.path.position.fromArray(pathAt(state.views.path, engine.
|
|
80
|
+
if (state.view === 'path' && state.views) /** @type {any} */ (engine.cameraRig).shots.path.position.fromArray(pathAt(state.views.path, engine.time.now('real') - state.since));
|
|
80
81
|
});
|
|
81
82
|
engine.ops.define('styletest.view', {
|
|
82
83
|
desc: 'Move the camera to a named view: overview, character, water, room, path, ui', args: { name: 'string' },
|
|
@@ -88,8 +89,8 @@ engine.describe.add('styletest', () => ({ view: state.view, style: params.style,
|
|
|
88
89
|
engine.events.on('engine:ready', () => engine.ops.run('styletest.view', { name: params.view }));
|
|
89
90
|
if (params.badView) console.warn(`styletest: unknown view '${params.badView}', showing overview. Views: overview, character, water, room, path, ui`);
|
|
90
91
|
|
|
91
|
-
// The
|
|
92
|
-
if (params.panel) import('
|
|
92
|
+
// The dev panel (@threedog/tools/panel) on ?panel=1; a production build gets a stub (tweakpane may be missing: the panel then says so in the page)
|
|
93
|
+
if (params.panel) import('@threedog/tools/panel').then(m => m.openPanel(engine, { overrides: params.overrides }));
|
|
93
94
|
|
|
94
95
|
engine.start();
|
|
95
96
|
window.engine = engine; // handy for debugging in the browser console
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The exhibits that are not in the
|
|
1
|
+
// The exhibits that are not in the world example's art (../world/art), built in code and registered by name in main.js (content/templates.js places them).
|
|
2
2
|
// Every surface goes through makeMaterial(role), so the style decides the feel: roles wood, stone, metal, glass, building.
|
|
3
3
|
// Shadow flags are set here, on the model (the engine does not guess them).
|
|
4
4
|
import { THREE, mergeColored, makeMaterial } from '../../index.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// URL parameters of the style test page. Import this file first in main.js: it rewrites word values into the forms the engine's own
|
|
2
2
|
// URL state understands (time=dusk -> 18:30, weather=雨 -> rain) before createEngine reads the URL.
|
|
3
3
|
// time day | dusk | night, or HH:MM weather clear | rain | snow (晴 雨 雪), or any engine weather name
|
|
4
|
-
// style
|
|
4
|
+
// style world | none env 1 = environment lighting from the sky (default 0)
|
|
5
5
|
// view overview | character | water | room | path | ui (总览 角色特写 水面 室内 移动镜头路径 界面)
|
|
6
|
-
// panel 1 = the
|
|
6
|
+
// panel 1 = the dev panel, @threedog/tools/panel (needs the tweakpane dev package)
|
|
7
7
|
// ov style overrides the workbench exports for "rebuild preview" (JSON, URL-encoded)
|
|
8
8
|
/** @type {Record<string, string>} */
|
|
9
9
|
const TIME = { day: '12:00', 白天: '12:00', dusk: '18:30', 黄昏: '18:30', night: '23:00', 夜晚: '23:00' };
|
|
@@ -24,7 +24,7 @@ if (changed) history.replaceState(null, '', url);
|
|
|
24
24
|
const view = VIEWS[q.get('view')] ?? q.get('view') ?? 'overview';
|
|
25
25
|
export const params = Object.freeze({
|
|
26
26
|
view: VIEW_NAMES.includes(view) ? view : 'overview',
|
|
27
|
-
style: q.get('style') === 'none' ? 'none' : '
|
|
27
|
+
style: q.get('style') === 'none' ? 'none' : 'world',
|
|
28
28
|
env: q.get('env') === '1',
|
|
29
29
|
panel: q.get('panel') === '1',
|
|
30
30
|
overrides: q.get('ov') ? JSON.parse(q.get('ov')) : null,
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Contact shadows: make objects sit on the ground instead of floating (shadow box size, bias, fill balance, baked and screen-space AO, probes).
|
|
2
|
+
|
|
3
|
+
# Contact shadows (technique example)
|
|
4
|
+
|
|
5
|
+
A neutral gray scene with small objects on the ground and on a table. Demo: `npm run dev` in the engine package, open `/contact-shadows.html`
|
|
6
|
+
(`?mode=float` shows the failure, `&ao=1` the AO pass, `&probes=1` probes). The engine never imports this folder.
|
|
7
|
+
|
|
8
|
+
## The principle
|
|
9
|
+
A cup on a table, a box on the floor, a character's feet: if nothing darkens the ground right where the object touches it, the eye reads a
|
|
10
|
+
gap, and the object hovers. What grounds it is a small, dark, sharp-ish shadow at the foot plus darkening in the creases between parts. Three
|
|
11
|
+
things usually remove that darkening together (`?mode=float` is the engine's defaults, built for a 140 m open world):
|
|
12
|
+
1. **The shadow map is too coarse for small things.** Shadow detail is texels per meter, nothing else. One sun map covers a box of
|
|
13
|
+
`2 * extent` meters: `extent: 70` on a 2048 map is 140 m / 2048 = **6.8 cm per texel**. A 10 cm cup's shadow is one or two texels,
|
|
14
|
+
blurred away by the soft filter.
|
|
15
|
+
2. **The bias pushes the shadow off the foot.** Acne is a sampling error of about one texel, so the bias that cures it scales with the texel.
|
|
16
|
+
`normalBias` moves the lookup along the surface normal so flat ground does not shadow itself; 4 cm is right for 6.8 cm texels and far
|
|
17
|
+
too much under a 10 cm cup: the shadow starts a few centimeters away from its base. Too low: stripes on the ground. Too high: shadows
|
|
18
|
+
detach (peter-panning).
|
|
19
|
+
3. **The fill washes out what shadow is left.** A shadow is only the absence of the sun; what you see in it is the fill (hemisphere and
|
|
20
|
+
environment light). When the fill is close to the sun, a shadow darkens the ground by 10-20% and reads as dirt, not contact.
|
|
21
|
+
A fourth cause is plain placement: an object 1 cm above its support also floats. Put it at `y = support + half height`.
|
|
22
|
+
|
|
23
|
+
Occlusion is geometry, not light: a crease or a foot is dark because the surroundings block the sky, which is why ambient occlusion (baked
|
|
24
|
+
or screen-space) grounds things even where the sun shadow is soft. Light probes are different: indirect light sampled at points; they do not
|
|
25
|
+
ground small objects by themselves, they make the fill vary so shadowed corners and the space under a roof are darker than open ground.
|
|
26
|
+
|
|
27
|
+
How to judge it: take a shot at the game's real camera and look at whether small things sit or hover. `threedog shot` prints "shadow area
|
|
28
|
+
... darkened by N%"; on the demo the defaults give "shadow area 8.0% (darkened by 11.0%)", the technique "8.9% (darkened by 26.0%)".
|
|
29
|
+
How strongly shadows should read is a decision for DESIGN.md, not a fixed value.
|
|
30
|
+
|
|
31
|
+
## Plain three.js
|
|
32
|
+
- Shadow box: a `DirectionalLight`'s `shadow.camera` is an `OrthographicCamera`; its `left/right/top/bottom` set the box, `shadow.mapSize`
|
|
33
|
+
the texels ([DirectionalLightShadow](https://threejs.org/docs/#api/en/lights/shadows/DirectionalLightShadow),
|
|
34
|
+
[LightShadow](https://threejs.org/docs/#api/en/lights/shadows/LightShadow) for `bias`, `normalBias`, `radius`). Long views use cascades
|
|
35
|
+
([webgl_shadowmap_csm](https://threejs.org/examples/#webgl_shadowmap_csm)).
|
|
36
|
+
- Fill: [HemisphereLight](https://threejs.org/docs/#api/en/lights/HemisphereLight) intensity and `scene.environment` /
|
|
37
|
+
`material.envMapIntensity`.
|
|
38
|
+
- Screen-space AO: `GTAOPass` in `three/addons/postprocessing` ([webgl_postprocessing_gtao](https://threejs.org/examples/#webgl_postprocessing_gtao)).
|
|
39
|
+
- Baked AO: write occlusion into a vertex `color` attribute with `material.vertexColors = true`, or into an `aoMap` from a DCC tool.
|
|
40
|
+
- Probes: [LightProbe](https://threejs.org/docs/#api/en/lights/LightProbe) with `LightProbeGenerator` from a cube render.
|
|
41
|
+
- A blob shadow: a transparent quad with a radial gradient texture under the object, `depthWrite: false`.
|
|
42
|
+
|
|
43
|
+
## Style routes
|
|
44
|
+
- **Realistic**: a tight shadow box, small texel-sized bias, a fill low enough that shadows read, plus AO in the creases. Costs shadow-map
|
|
45
|
+
tuning and possibly a screen AO pass.
|
|
46
|
+
- **Pastel / flat-shaded**: the same box and bias, a gentler fill (soft shadows read as color, not black). No extra cost.
|
|
47
|
+
- **High-contrast / noir**: a lower fill, perhaps a tinted hemisphere ground color. No extra cost.
|
|
48
|
+
- **Toon whose material ignores light**: contact only from vertex AO or a blob decal under the object. One quad per object, no shadow map.
|
|
49
|
+
- **Big open world**: keep the default box for the far view and use cascades; bias, fill and vertex AO still apply.
|
|
50
|
+
- **Interiors with strong bounce** (a sunlit room): probes, baked once and shipped.
|
|
51
|
+
|
|
52
|
+
## The engine helper (optional convenience)
|
|
53
|
+
`contactShadows.js` combines what the engine already has. `applyContactShadows(engine, opts)` does steps 1-3 below (and 5 with `ao: true`);
|
|
54
|
+
it returns `{ remove(), describe() }` and writes as owner `contact-shadows`, so `engine.describe().look.shadow` says who set the box.
|
|
55
|
+
`groundStatic(geometry)` bakes vertex AO with the ground as occluder (wraps `bakeVertexAO`). `shadowTexelCm()` gives one texel in
|
|
56
|
+
centimeters. The starting values sit in `PARAMS` (tied to this example's 16 m scene; your game picks its own); `threedog examples pull
|
|
57
|
+
contact-shadows` copies the file, then tune `PARAMS` against your DESIGN.md look.
|
|
58
|
+
|
|
59
|
+
| Step | What | Cost (1280x720, laptop GPU, this demo) |
|
|
60
|
+
|---|---|---|
|
|
61
|
+
| 1. Size the shadow box to what the player sees up close | `look.shadow.set({ extent: 8 })`: 16 m / 2048 = **0.8 cm per texel** | none: same map, same draws (4.1 -> 4.3 ms a frame) |
|
|
62
|
+
| 2. Bias in texels, not by habit | `normalBias` about 1.5 texels (1.2 cm here), `bias` near 0; re-check after changing `extent` | none |
|
|
63
|
+
| 3. Fill balance | `engine.mod('look.lights.hemi.intensity', { mul: 0.4 })`: shadows go from 11% to 26% darker on average (shot look numbers) | none |
|
|
64
|
+
| 4. Baked vertex AO on static code-built models | `groundStatic(geometry)`: dark foot, dark creases between parts | load time only: ~95 ms for 880 vertices x 32 rays; 0 per frame |
|
|
65
|
+
| 5. Screen-space AO (optional) | `applyContactShadows(engine, { ao: true })` (GTAO from `@threedog/post-effects`) | **+6.3 ms a frame** (4.3 -> 10.6 ms): only where contact must hold for moving things too |
|
|
66
|
+
| 6. Light probes (optional) | `await engine.bakeProbes({ bounds, spacing })`: bounce light, darker under roofs, lighter beside a sunlit wall | load: 3.6 s for 75 probes (ship the JSON, `engine.loadProbes`); +0.8 ms a frame |
|
|
67
|
+
| Bigger map instead | `mapSize: 4096` | +0.6 ms a frame and 4x the shadow memory; try a smaller `extent` first |
|
|
68
|
+
|
|
69
|
+
Measured with `engine.step` + a 1 px `readPixels` per frame, median of 120 frames. Notes on the engine side:
|
|
70
|
+
- The box follows `engine.focus`, so a compact box is fine for a third-person or fixed camera; the far ground loses its sun shadow, which is
|
|
71
|
+
what cascades are for (`look.shadow.set({ cascades: 3 })`, recipe 45) when the view is long.
|
|
72
|
+
- The sky's ambient column feeds the hemisphere light AND the environment map (recipe 34), so a strong env plus a strong hemi doubles the
|
|
73
|
+
fill. A multiplier (`engine.mod('look.lights.hemi.intensity')`) keeps the day-night cycle.
|
|
74
|
+
- Which steps where: small props on tables, a tidy room, a yard: 1-3, plus 4 for every static code-built model (free at run time).
|
|
75
|
+
Characters and moving props that must look planted close up: add 5 on desktop, keep it off on low-tier devices (`look.post` lists
|
|
76
|
+
`ao.enabled` as costly).
|
|
77
|
+
|
|
78
|
+
Rules (correctness):
|
|
79
|
+
- Vertex AO needs `vertexColors: true` on the material and vertices where the darkening should be; it is baked once, so only static geometry.
|
|
80
|
+
- Under a day-night cycle change the fill with a multiplier (`engine.mod('look.lights.hemi.intensity')`), not `look.lights.set({ hemi })`: a set value replaces the keyframes.
|
|
81
|
+
- `look.shadow` is a sky-module part: `applyContactShadows` needs `sky()` installed. Change cascades / map type on a settings screen (they recompile).
|
|
82
|
+
- `ao()` comes from `@threedog/post-effects`; install it in the game.
|
|
83
|
+
|
|
84
|
+
Common mistakes:
|
|
85
|
+
- Raising `mapSize` to 8192 before shrinking `extent` (16x memory for what `extent` gives free).
|
|
86
|
+
- Copying a `normalBias` from another game: it belongs to that game's texel size.
|
|
87
|
+
- Brightening the whole scene with hemisphere light "so shadows are not black": that is what makes everything float; lift exposure instead.
|
|
88
|
+
- Baking vertex AO on a 12-triangle box: the corners get it, the faces cannot (no vertices there; tessellate big faces).
|
|
89
|
+
- Turning on screen AO and leaving the fill at full: AO darkens creases inside a washed-out picture and looks like dirt.
|
|
90
|
+
|
|
91
|
+
Sources: written for this engine from the three.js docs (`LightShadow.bias / normalBias`, `GTAOPass`, `LightProbeGenerator`) and the common
|
|
92
|
+
shadow-mapping literature (Microsoft "Common Techniques to Improve Shadow Depth Maps"); no code copied.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Contact shadows: make objects sit ON the ground instead of hovering above it. Technique example (README.md next to this file); copy and adapt.
|
|
3
|
+
// It only combines what the engine already has: a sun shadow box sized to the scene, small biases, a fill light that leaves shadows dark,
|
|
4
|
+
// optional screen-space AO, and baked vertex AO for static code-built models. Every number is a starting point for a compact scene (a room,
|
|
5
|
+
// a yard, a table top); change PARAMS, not the code.
|
|
6
|
+
import { bakeVertexAO, THREE } from 'threedog';
|
|
7
|
+
import { ao } from '@threedog/post-effects';
|
|
8
|
+
|
|
9
|
+
export const PARAMS = {
|
|
10
|
+
extent: 8, // m, half size of the sun's shadow box around engine.focus: the area the player sees up close, not the whole level
|
|
11
|
+
mapSize: 2048, // px per side; texel = 2 * extent / mapSize (8 m / 2048 -> 0.8 cm). The engine default 70 m box gives 6.8 cm
|
|
12
|
+
normalBias: 0.012, // m, about 1.5 texels: enough against acne, small enough that a 5 cm cup keeps its shadow under its foot
|
|
13
|
+
bias: -0.00002, // shadow-camera depth; normalBias does most of the work, keep this near 0
|
|
14
|
+
fill: 0.4, // x the sky's ambient (hemisphere + environment): lower = darker shadows. 1 = the sky's own value
|
|
15
|
+
ao: false, // screen-space AO post pass (GTAO, @threedog/post-effects): creases and contact corners, +~6 ms on a laptop GPU
|
|
16
|
+
aoRadius: 0.35, // m, how far from a contact AO reaches; about the size of the smallest object you want grounded
|
|
17
|
+
aoIntensity: 0.8, // 0..1
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** One shadow-map texel in centimeters for a box of half size `extent` m drawn into `mapSize` px */
|
|
21
|
+
export const shadowTexelCm = (extent = PARAMS.extent, mapSize = PARAMS.mapSize) => 200 * extent / mapSize;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Apply the grounding settings to a running engine with a sky (look.shadow is a sky part). Returns { remove(), describe() }: remove() gives
|
|
25
|
+
* every value back to the style / engine. Owner 'contact-shadows' shows in engine.describe().look as the writer.
|
|
26
|
+
* @param {import('threedog').Engine} engine
|
|
27
|
+
* @param {Partial<typeof PARAMS>} [opts]
|
|
28
|
+
*/
|
|
29
|
+
export function applyContactShadows(engine, opts = {}) {
|
|
30
|
+
const p = { ...PARAMS, ...opts }, owner = 'contact-shadows', handles = [];
|
|
31
|
+
handles.push(engine.look.shadow.set({ extent: p.extent, mapSize: p.mapSize, normalBias: p.normalBias, bias: p.bias }, { owner }));
|
|
32
|
+
// a multiplier on the sky's ambient, not a fixed hemi intensity: the day-night cycle keeps working (look.lights.set would freeze it)
|
|
33
|
+
if (p.fill !== 1) handles.push(engine.mod('look.lights.hemi.intensity', { owner, mul: p.fill }));
|
|
34
|
+
if (p.ao) handles.push(engine.look.post.add(ao({ enabled: true, radius: p.aoRadius, intensity: p.aoIntensity }), { owner }));
|
|
35
|
+
return {
|
|
36
|
+
remove() { for (const h of handles.splice(0)) h.remove(); },
|
|
37
|
+
describe: () => ({ ...p, texelCm: +shadowTexelCm(p.extent, p.mapSize).toFixed(2) }),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Bake ambient occlusion into a static code-built geometry standing on flat ground at height `ground` (in the geometry's own space):
|
|
43
|
+
* the ground is an occluder, so the foot of the model darkens where it meets the floor. Draw it with `vertexColors: true`.
|
|
44
|
+
* Cost: once at load (tens of ms for a few thousand vertices), nothing per frame. Detail is per vertex: tessellate big faces first.
|
|
45
|
+
* @param {THREE.BufferGeometry} geometry
|
|
46
|
+
* @param {{ ground?: number, samples?: number, strength?: number, radius?: number }} [o]
|
|
47
|
+
*/
|
|
48
|
+
export function groundStatic(geometry, { ground = 0, samples = 32, strength = 0.75, radius } = {}) {
|
|
49
|
+
const floor = new THREE.PlaneGeometry(40, 40).rotateX(-Math.PI / 2).translate(0, ground, 0);
|
|
50
|
+
return bakeVertexAO(geometry, { samples, strength, radius, occluders: [floor] });
|
|
51
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Demo page for the contact-shadows technique (page /contact-shadows.html). A neutral gray yard at 14:30: a table with a small cup and a ball on
|
|
3
|
+
// it, a crate stack (static, code-built, vertex AO baked), a figure-sized capsule and a wall corner.
|
|
4
|
+
// URL: ?mode=float the engine defaults (70 m shadow box, 4 cm normal bias, full fill): the "small object floats" failure
|
|
5
|
+
// &ao=1 add the screen-space AO pass &probes=1 bake light probes over the yard (bounce light from the wall)
|
|
6
|
+
// Test page for tests/specs/contact-shadows.mjs: window.contactTest = { THREE, points, cs } (points: world spots the spec reads brightness at).
|
|
7
|
+
import { createEngine, sky, fixedCamera, makeMaterial, THREE } from 'threedog';
|
|
8
|
+
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
|
|
9
|
+
import { applyContactShadows, groundStatic } from './contactShadows.js';
|
|
10
|
+
|
|
11
|
+
const url = new URLSearchParams(location.search), float = url.get('mode') === 'float';
|
|
12
|
+
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), ui: { loading: false }, saveKey: 'threedog-contact' });
|
|
13
|
+
engine.use(sky({ time: '14:30' }));
|
|
14
|
+
engine.use(fixedCamera({ position: [1.9, 1.6, 2.3], lookAt: [0, 0.55, -0.1] }));
|
|
15
|
+
|
|
16
|
+
const gray = (/** @type {number} */ c, vertexColors = false) => makeMaterial('prop', { color: c, vertexColors });
|
|
17
|
+
const ground = new THREE.Mesh(new THREE.PlaneGeometry(40, 40), makeMaterial('terrain', { color: 0x9a9a9a }));
|
|
18
|
+
ground.rotation.x = -Math.PI / 2;
|
|
19
|
+
ground.receiveShadow = true;
|
|
20
|
+
engine.scene.add(ground);
|
|
21
|
+
|
|
22
|
+
const add = (/** @type {THREE.BufferGeometry} */ g, /** @type {THREE.Material} */ m, x = 0, y = 0, z = 0) => {
|
|
23
|
+
const mesh = new THREE.Mesh(g, m);
|
|
24
|
+
mesh.position.set(x, y, z);
|
|
25
|
+
mesh.castShadow = mesh.receiveShadow = true;
|
|
26
|
+
engine.scene.add(mesh);
|
|
27
|
+
return mesh;
|
|
28
|
+
};
|
|
29
|
+
// the table: top 1.2 x 0.8 at 0.75 m, four legs. Objects sit exactly on their support (y = half height): a 1 cm gap also reads as floating
|
|
30
|
+
add(new THREE.BoxGeometry(1.2, 0.05, 0.8), gray(0xb0b0b0), 0, 0.725, 0);
|
|
31
|
+
for (const [x, z] of [[-0.55, -0.35], [0.55, -0.35], [-0.55, 0.35], [0.55, 0.35]]) add(new THREE.BoxGeometry(0.05, 0.7, 0.05), gray(0x8c8c8c), x, 0.35, z);
|
|
32
|
+
const cup = add(new THREE.CylinderGeometry(0.04, 0.035, 0.1, 24), gray(0xd0d0d0), 0.2, 0.75 + 0.05, 0.1);
|
|
33
|
+
add(new THREE.SphereGeometry(0.07, 24, 16), gray(0xc4c4c4), -0.25, 0.75 + 0.07, -0.1);
|
|
34
|
+
// a small object on the ground, where floating is easiest to see
|
|
35
|
+
const block = add(new THREE.BoxGeometry(0.12, 0.12, 0.12), gray(0xc8c8c8), 1.1, 0.06, 0.6);
|
|
36
|
+
// the crate stack: one static merged geometry with baked vertex AO (darker at the floor and between crates). Tessellated boxes: AO is per vertex
|
|
37
|
+
const crate = (/** @type {number} */ s, /** @type {number} */ x, /** @type {number} */ y, /** @type {number} */ z) => new THREE.BoxGeometry(s, s, s, 6, 6, 6).translate(x, y + s / 2, z);
|
|
38
|
+
const stack = mergeGeometries([crate(0.6, 0, 0, 0), crate(0.6, 0.62, 0, 0.05), crate(0.45, 0.3, 0.6, 0)]);
|
|
39
|
+
if (!float) groundStatic(stack, { ground: 0 });
|
|
40
|
+
add(stack, gray(0xb4b4b4, !float), -1.6, 0, -0.6);
|
|
41
|
+
// a figure-sized capsule and a wall corner (the probes' bounce light shows next to the wall)
|
|
42
|
+
add(new THREE.CapsuleGeometry(0.25, 1.2, 8, 16), gray(0xa8a8a8), 1.4, 0.85, -1.2);
|
|
43
|
+
add(new THREE.BoxGeometry(5, 2.5, 0.2), gray(0xbcbcbc), 0, 1.25, -2.4);
|
|
44
|
+
add(new THREE.BoxGeometry(0.2, 2.5, 4), gray(0xbcbcbc), -2.6, 1.25, -0.5);
|
|
45
|
+
|
|
46
|
+
// the shadow box centers on engine.focus, which the fixed camera puts at its lookAt (the table): the middle of the compact scene
|
|
47
|
+
const cs = float ? null : applyContactShadows(engine, { ao: url.get('ao') === '1' });
|
|
48
|
+
if (url.get('probes') === '1') await engine.bakeProbes({ bounds: { min: [-3, 0.2, -2.2], max: [3, 2, 3] }, spacing: 1.5 });
|
|
49
|
+
|
|
50
|
+
// small objects (base center and half width, m) and open spots on the same surfaces; the spec reads just beside each base on the side away from the sun
|
|
51
|
+
const points = { cup: { at: [0.2, 0.751, 0.1], r: 0.04 }, block: { at: [1.1, 0.001, 0.6], r: 0.06 }, tableOpen: [-0.4, 0.751, 0.3], groundOpen: [-1.0, 0.001, 0.9] };
|
|
52
|
+
Object.assign(window, { engine, contactTest: { THREE, points, cs, cup } });
|
|
53
|
+
engine.start();
|