threedog 0.2.1 → 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 +71 -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 +183 -59
- 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 +37 -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 +14 -13
- package/core/gridLoad.js +2 -1
- 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 +100 -41
- 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 +63 -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 +87 -100
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +220 -147
- package/docs/COMMANDS.md +56 -35
- package/docs/CONVENTIONS.md +90 -28
- 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 +11 -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 +38 -23
- 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 +63 -60
- 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 +28 -26
- 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 +29 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +11 -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 +48 -34
- package/docs/recipes/02-npc.md +24 -7
- package/docs/recipes/03-items-pickups.md +35 -21
- package/docs/recipes/04-quests.md +12 -5
- package/docs/recipes/05-props-bake.md +151 -15
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +40 -9
- package/docs/recipes/08-weather-sky.md +145 -36
- package/docs/recipes/{09-style-pack.md → 09-style.md} +101 -52
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +14 -6
- package/docs/recipes/14-custom-module.md +61 -29
- package/docs/recipes/15-perf.md +30 -9
- package/docs/recipes/16-dev-bridge.md +61 -37
- package/docs/recipes/18-world.md +16 -6
- package/docs/recipes/19-shooting-picking.md +6 -6
- package/docs/recipes/20-content-actions-save.md +55 -17
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +3 -3
- package/docs/recipes/23-ops.md +16 -10
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +11 -5
- package/docs/recipes/28-terrain.md +34 -1
- package/docs/recipes/29-grid.md +34 -16
- 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 +26 -3
- package/docs/recipes/35-style-from-reference.md +88 -19
- package/docs/recipes/36-sky-ground-plant-looks.md +18 -18
- package/docs/recipes/37-terrain-look-hooks.md +3 -2
- package/docs/recipes/38-environment-look-hooks.md +37 -26
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +2 -2
- package/docs/recipes/43-shader-patches-surface-looks.md +158 -76
- package/docs/recipes/44-water-weather-look-hooks.md +26 -17
- package/docs/recipes/45-cascaded-shadows.md +16 -7
- package/docs/recipes/47-island-snow-backdrop.md +7 -7
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +30 -17
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +3 -3
- package/docs/recipes/52-look.md +197 -61
- package/docs/recipes/53-ground-up-close.md +1 -1
- 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 -14
- 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/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +17 -16
- 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 +1 -1
- 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 +44 -45
- package/index.js +26 -22
- package/llms.txt +11 -4
- 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 +177 -42
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +4 -13
- 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 +2 -1
- 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 +96 -27
- 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 +186 -110
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +32 -11
- 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 +8 -2
- 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 +7 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +120 -39
- 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 +614 -240
- package/types/gameplay.d.ts +482 -312
- 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 +109 -81
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +158 -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 -22
- package/docs/api/entities.md +0 -61
- 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,209 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Technique: a road that gets wet in rain and dries after it (README.md next to this file). Copy this file into a game; in a game the import
|
|
3
|
+
// below becomes `from 'threedog'`. Three parts, each switchable:
|
|
4
|
+
// 1. wetness 0-1 from engine.weather.current.rain, with a dry-out delay (game time, so engine.skip and frozen time behave);
|
|
5
|
+
// 2. a material patch (slots color / roughness / normal, no global ShaderChunk edits): darker albedo, lower roughness, soft-edged puddles;
|
|
6
|
+
// 3. reflection streaks: one instanced draw of stretched additive quads on the road under each lamp / window / sign (the cheap fake that
|
|
7
|
+
// works at night; real lights also get a sharp GGX highlight for free from the lower roughness).
|
|
8
|
+
import { THREE, applyEffects } from 'threedog';
|
|
9
|
+
|
|
10
|
+
/** Every knob of the technique; createWetRoad(engine, { ...overrides }) */
|
|
11
|
+
export const WET_ROAD_DEFAULTS = {
|
|
12
|
+
wetSeconds: 25, // seconds of full rain from dry to fully wet (light rain wets slower: the rate scales with rain)
|
|
13
|
+
dryDelay: 40, // seconds after the rain stops before the road starts to dry (puddles stand a while)
|
|
14
|
+
drySeconds: 120, // seconds from fully wet to dry once drying started
|
|
15
|
+
rainThreshold: 0.05, // rain below this counts as stopped
|
|
16
|
+
darken: 0.6, // albedo multiplier when fully wet (porous asphalt / stone darkens; 1 = metal or glazed tile, no change)
|
|
17
|
+
wetRoughness: 0.32, // roughness cap when wet (the film of water); the dry roughness comes from the material
|
|
18
|
+
puddles: true, // false: wet film only, one less noise in the shader
|
|
19
|
+
puddleScale: 0.45, // noise cells per meter (bigger = more, smaller puddles)
|
|
20
|
+
puddleCover: 0.32, // share of the surface under water when fully wet (puddles grow in from 0 as wetness passes 0.35)
|
|
21
|
+
puddleSoftness: 0.09, // edge width in noise units: the soft rim where water thins out (0.02 = hard disc edge, avoid)
|
|
22
|
+
puddleDarken: 0.55, // extra albedo multiplier under a puddle (you see the dark wet ground through the water)
|
|
23
|
+
puddleRoughness: 0.03, // still water is almost a mirror
|
|
24
|
+
streaks: true, // reflection streaks under emitters (addStreak)
|
|
25
|
+
streakSpread: 0.12, // radians the reflection smears up and down around the mirror image (the water film's roughness; 0.02 = puddle mirror)
|
|
26
|
+
streakBlur: 0.006, // radians it smears sideways, on top of the source's own size
|
|
27
|
+
streakFilm: 0.35, // streak strength on wet film relative to a puddle (1 = puddles do not matter)
|
|
28
|
+
streakFade: 70, // meters from the camera where streaks have faded out
|
|
29
|
+
bounds: /** @type {number[] | null} */ (null), // [minX, minZ, maxX, maxZ]: streaks are cut to this world rectangle (the road); null = anywhere
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// The puddle noise, shared by the surface patch and the streak shader so a streak is bright exactly over the puddles the surface shows.
|
|
33
|
+
// Value noise, 3 octaves, world xz in, 0-1 out. Written for this example (the usual hash-and-smoothstep value noise).
|
|
34
|
+
const NOISE_GLSL = /* glsl */`
|
|
35
|
+
float tdWetHash(vec2 p) { p = fract(p * vec2(123.34, 456.21)); p += dot(p, p + 45.32); return fract(p.x * p.y); }
|
|
36
|
+
float tdWetValue(vec2 p) {
|
|
37
|
+
vec2 i = floor(p), f = fract(p); vec2 u = f * f * (3.0 - 2.0 * f);
|
|
38
|
+
return mix(mix(tdWetHash(i), tdWetHash(i + vec2(1, 0)), u.x), mix(tdWetHash(i + vec2(0, 1)), tdWetHash(i + vec2(1, 1)), u.x), u.y);
|
|
39
|
+
}
|
|
40
|
+
float tdWetNoise(vec2 p) { return 0.57 * tdWetValue(p) + 0.29 * tdWetValue(p * 2.03 + 17.1) + 0.14 * tdWetValue(p * 4.11 - 9.7); }
|
|
41
|
+
// cover 0-1 -> threshold on the noise (fbm piles up near 0.5, so the share under water is not linear in the threshold; fitted by eye)
|
|
42
|
+
float tdWetPuddle(vec2 xz, float scale, float cover, float soft) {
|
|
43
|
+
if (cover <= 0.0) return 0.0;
|
|
44
|
+
float t = 0.72 - 0.5 * cover;
|
|
45
|
+
return smoothstep(t - soft, t + soft, tdWetNoise(xz * scale));
|
|
46
|
+
}`;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Wet road: wetness follows rain; patched materials darken, gloss up and grow puddles; optional reflection streaks.
|
|
50
|
+
* @param {any} engine
|
|
51
|
+
* @param {Partial<typeof WET_ROAD_DEFAULTS> & { materials: THREE.Material[] }} options materials: MeshStandard / MeshPhysical materials of the road
|
|
52
|
+
*/
|
|
53
|
+
export function createWetRoad(engine, { materials, ...over }) {
|
|
54
|
+
const o = { ...WET_ROAD_DEFAULTS, ...over };
|
|
55
|
+
for (const k of Object.keys(over)) if (!(k in WET_ROAD_DEFAULTS)) throw new Error(`createWetRoad: unknown option '${k}' (known: ${Object.keys(WET_ROAD_DEFAULTS).join(', ')})`);
|
|
56
|
+
for (const m of materials) if (!(/** @type {any} */ (m).isMeshStandardMaterial)) throw new Error('createWetRoad: road materials must be MeshStandardMaterial / MeshPhysicalMaterial (roughness is what makes it read as wet)');
|
|
57
|
+
|
|
58
|
+
// One uniform object for all patched materials and the streaks: changing a number never recompiles.
|
|
59
|
+
const u = {
|
|
60
|
+
uWet: { value: 0 }, uWetDarken: { value: o.darken }, uWetRough: { value: o.wetRoughness },
|
|
61
|
+
uPuddleScale: { value: o.puddleScale }, uPuddleCover: { value: 0 }, uPuddleSoft: { value: o.puddleSoftness },
|
|
62
|
+
uPuddleDarken: { value: o.puddleDarken }, uPuddleRough: { value: o.puddleRoughness }, uWetMaskView: { value: 0 },
|
|
63
|
+
};
|
|
64
|
+
const puddle = o.puddles ? 'tdWetPuddle(vThreedogWorld.xz, uPuddleScale, uPuddleCover, uPuddleSoft)' : '0.0';
|
|
65
|
+
const patch = {
|
|
66
|
+
name: 'wetRoad', cacheKey: o.puddles ? 'p1' : 'f1', needs: { patches: ['world'] }, uniforms: u,
|
|
67
|
+
pars: { fragment: `uniform float uWet, uWetDarken, uWetRough, uPuddleScale, uPuddleCover, uPuddleSoft, uPuddleDarken, uPuddleRough, uWetMaskView;\n${NOISE_GLSL}` },
|
|
68
|
+
glsl: {
|
|
69
|
+
// the color slot runs first in main(), so the two values declared here are in scope for the later slots
|
|
70
|
+
color: `float tdWet = uWet; float tdPuddle = ${puddle};
|
|
71
|
+
diffuseColor.rgb *= mix(1.0, uWetDarken, tdWet) * mix(1.0, uPuddleDarken, tdPuddle);`,
|
|
72
|
+
// min(): a surface already glossier than the water film stays as it is
|
|
73
|
+
roughness: 'roughnessFactor = mix(roughnessFactor, min(roughnessFactor, uWetRough), tdWet); roughnessFactor = mix(roughnessFactor, uPuddleRough, tdPuddle);',
|
|
74
|
+
// standing water is flat: it hides the bumps of a normal map under it
|
|
75
|
+
normal: 'normal = normalize(mix(normal, normalize((viewMatrix * vec4(0.0, 1.0, 0.0, 0.0)).xyz), tdPuddle));',
|
|
76
|
+
// debug view of the puddle mask (wet.maskView = true): white = water
|
|
77
|
+
output: 'if (uWetMaskView > 0.5) outgoingLight = vec3(tdPuddle);',
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
for (const m of materials) applyEffects(/** @type {any} */ (m), { patches: [patch] });
|
|
81
|
+
|
|
82
|
+
// ---- streaks: one InstancedMesh, matrices placed on the CPU each frame (a few dozen at most) ----
|
|
83
|
+
/** @type {{ at: THREE.Vector3, color: THREE.Color, intensity: number }[]} */
|
|
84
|
+
const sources = [];
|
|
85
|
+
const MAX = 128;
|
|
86
|
+
const geo = new THREE.PlaneGeometry(1, 1).rotateX(-Math.PI / 2).translate(0, 0, 0.5); // flat on the ground; x across, z 0 (near) -> 1 (far)
|
|
87
|
+
const aColor = new THREE.InstancedBufferAttribute(new Float32Array(MAX * 3), 3);
|
|
88
|
+
geo.setAttribute('aColor', aColor);
|
|
89
|
+
const aPeak = new THREE.InstancedBufferAttribute(new Float32Array(MAX), 1); // where along the quad the mirror image sits, 0-1
|
|
90
|
+
geo.setAttribute('aPeak', aPeak);
|
|
91
|
+
const streakMat = new THREE.ShaderMaterial({
|
|
92
|
+
uniforms: { ...u, uStreakFilm: { value: o.streakFilm }, uStreakFade: { value: o.streakFade }, uBounds: { value: new THREE.Vector4(...(o.bounds ?? [-1e9, -1e9, 1e9, 1e9])) } },
|
|
93
|
+
vertexShader: /* glsl */`
|
|
94
|
+
attribute vec3 aColor; attribute float aPeak; varying vec3 vColor; varying vec2 vUv; varying vec3 vWorld; varying float vDist, vPeak;
|
|
95
|
+
void main() {
|
|
96
|
+
vColor = aColor; vPeak = aPeak; vUv = vec2(uv.x * 2.0 - 1.0, 1.0 - uv.y);
|
|
97
|
+
vec4 w = modelMatrix * instanceMatrix * vec4(position, 1.0); vWorld = w.xyz;
|
|
98
|
+
vec4 mv = viewMatrix * w; vDist = -mv.z; gl_Position = projectionMatrix * mv;
|
|
99
|
+
}`,
|
|
100
|
+
fragmentShader: /* glsl */`
|
|
101
|
+
uniform float uWet, uPuddleScale, uPuddleCover, uPuddleSoft, uStreakFilm, uStreakFade; uniform vec4 uBounds;
|
|
102
|
+
varying vec3 vColor; varying vec2 vUv; varying vec3 vWorld; varying float vDist, vPeak;
|
|
103
|
+
${NOISE_GLSL}
|
|
104
|
+
void main() {
|
|
105
|
+
// across: a gaussian. along (vUv.y 0 near -> 1 far): a gaussian around the mirror image, each side stretched to its end of the quad,
|
|
106
|
+
// so the smear is symmetric in view angle although the ground distances on the two sides differ a lot
|
|
107
|
+
float across = exp(-vUv.x * vUv.x * 4.0);
|
|
108
|
+
float a = (vUv.y - vPeak) / (vUv.y < vPeak ? max(vPeak, 1e-3) : max(1.0 - vPeak, 1e-3));
|
|
109
|
+
float along = exp(-a * a * 3.5);
|
|
110
|
+
float edge = 1.0 - smoothstep(0.8, 1.0, abs(vUv.x));
|
|
111
|
+
float water = mix(uStreakFilm, 1.0, ${o.puddles ? 'tdWetPuddle(vWorld.xz, uPuddleScale, uPuddleCover, uPuddleSoft)' : '0.0'});
|
|
112
|
+
float fade = 1.0 - smoothstep(uStreakFade * 0.6, uStreakFade, vDist);
|
|
113
|
+
// shortcut: a rectangle keeps streaks off the curbs; several surfaces or curved roads want a stencil bit written by the road material
|
|
114
|
+
if (any(lessThan(vWorld.xz, uBounds.xy)) || any(greaterThan(vWorld.xz, uBounds.zw))) discard;
|
|
115
|
+
gl_FragColor = vec4(vColor * across * along * edge * water * fade * uWet, 1.0);
|
|
116
|
+
#include <tonemapping_fragment>
|
|
117
|
+
#include <colorspace_fragment>
|
|
118
|
+
}`,
|
|
119
|
+
blending: THREE.AdditiveBlending, depthWrite: false, transparent: true, toneMapped: true,
|
|
120
|
+
polygonOffset: true, polygonOffsetFactor: -2, polygonOffsetUnits: -2,
|
|
121
|
+
});
|
|
122
|
+
const streakMesh = new THREE.InstancedMesh(geo, streakMat, MAX);
|
|
123
|
+
streakMesh.count = 0; streakMesh.frustumCulled = false; streakMesh.renderOrder = 2; streakMesh.name = 'wetRoadStreaks';
|
|
124
|
+
if (o.streaks) engine.scene.add(streakMesh);
|
|
125
|
+
|
|
126
|
+
const C = new THREE.Vector3(), P = new THREE.Vector3(), d = new THREE.Vector3(), q = new THREE.Quaternion(), s = new THREE.Vector3();
|
|
127
|
+
const Y = new THREE.Vector3(0, 1, 0), m4 = new THREE.Matrix4();
|
|
128
|
+
let groundY = 0;
|
|
129
|
+
function placeStreaks() {
|
|
130
|
+
if (!o.streaks) return;
|
|
131
|
+
streakMesh.visible = state.wetness > 0.001;
|
|
132
|
+
if (!streakMesh.visible) return;
|
|
133
|
+
engine.camera.getWorldPosition(C);
|
|
134
|
+
let n = 0;
|
|
135
|
+
for (const src of sources) {
|
|
136
|
+
const h = src.at.y - groundY, ch = C.y - groundY;
|
|
137
|
+
if (h <= 0 || ch <= 0 || src.intensity <= 0) continue;
|
|
138
|
+
// Mirror image of the source: h below the ground. Seen from the camera at angle th below the horizon; a wet film smears it by
|
|
139
|
+
// +-streakSpread in angle, which on the ground runs from `near` to `far` (far stops at the source's foot: nothing reflects beyond it).
|
|
140
|
+
d.set(src.at.x - C.x, 0, src.at.z - C.z);
|
|
141
|
+
const D = d.length();
|
|
142
|
+
if (D < 0.5) continue;
|
|
143
|
+
d.divideScalar(D);
|
|
144
|
+
const th = Math.atan2(ch + h, D), toGround = (/** @type {number} */ a) => ch / Math.tan(a);
|
|
145
|
+
const peak = toGround(th), near = toGround(Math.min(th + o.streakSpread, 1.5)), far = th - o.streakSpread > 0.001 ? Math.min(toGround(th - o.streakSpread), D) : D;
|
|
146
|
+
if (far <= near) continue;
|
|
147
|
+
const width = (0.6 / Math.hypot(D, ch + h) + o.streakBlur) * Math.hypot(peak, ch) * 2; // 0.6 m: the apparent size of a lamp head / window
|
|
148
|
+
q.setFromAxisAngle(Y, Math.atan2(d.x, d.z));
|
|
149
|
+
s.set(width, 1, far - near);
|
|
150
|
+
m4.compose(P.set(C.x + d.x * near, groundY + 0.01, C.z + d.z * near), q, s);
|
|
151
|
+
streakMesh.setMatrixAt(n, m4);
|
|
152
|
+
aPeak.setX(n, (peak - near) / (far - near));
|
|
153
|
+
aColor.setXYZ(n, src.color.r * src.intensity, src.color.g * src.intensity, src.color.b * src.intensity);
|
|
154
|
+
if (++n >= MAX) break;
|
|
155
|
+
}
|
|
156
|
+
streakMesh.count = n;
|
|
157
|
+
streakMesh.instanceMatrix.needsUpdate = true;
|
|
158
|
+
aColor.needsUpdate = true; aPeak.needsUpdate = true;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ---- wetness from the weather, game time ----
|
|
162
|
+
const rainNow = () => engine.weather?.current?.rain ?? 0;
|
|
163
|
+
const state = { wetness: rainNow() > o.rainThreshold ? 1 : 0, sinceRain: rainNow() > o.rainThreshold ? 0 : Infinity, held: /** @type {number | null} */ (null) };
|
|
164
|
+
function apply() {
|
|
165
|
+
u.uWet.value = state.wetness;
|
|
166
|
+
// puddles start once the film is there (wetness 0.35) and grow to their full cover; they also shrink first when drying
|
|
167
|
+
u.uPuddleCover.value = o.puddleCover * THREE.MathUtils.smoothstep(state.wetness, 0.35, 1);
|
|
168
|
+
}
|
|
169
|
+
apply();
|
|
170
|
+
const hFixed = engine.onFixed((/** @type {number} */ dt) => {
|
|
171
|
+
if (state.held !== null) { state.wetness = state.held; apply(); return; }
|
|
172
|
+
const rain = rainNow();
|
|
173
|
+
if (rain > o.rainThreshold) { state.sinceRain = 0; state.wetness = Math.min(1, state.wetness + dt * rain / o.wetSeconds); }
|
|
174
|
+
else {
|
|
175
|
+
state.sinceRain += dt;
|
|
176
|
+
if (state.sinceRain > o.dryDelay) state.wetness = Math.max(0, state.wetness - dt / o.drySeconds);
|
|
177
|
+
}
|
|
178
|
+
apply();
|
|
179
|
+
});
|
|
180
|
+
const hFrame = engine.onFrame(placeStreaks);
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
/** current wetness 0-1 */
|
|
184
|
+
get wetness() { return state.wetness; },
|
|
185
|
+
/** hold wetness at a value (a cutscene, a test, a puddle-filled level); null gives it back to the weather */
|
|
186
|
+
hold(/** @type {number | null} */ v) { state.held = v === null ? null : THREE.MathUtils.clamp(v, 0, 1); if (v !== null) { state.wetness = state.held ?? 0; apply(); } },
|
|
187
|
+
/** debug: draw the puddle mask on the patched materials (white = water) */
|
|
188
|
+
get maskView() { return u.uWetMaskView.value > 0.5; },
|
|
189
|
+
set maskView(on) { u.uWetMaskView.value = on ? 1 : 0; },
|
|
190
|
+
/** height of the ground the streaks lie on (default 0) */
|
|
191
|
+
set groundY(y) { groundY = y; },
|
|
192
|
+
/**
|
|
193
|
+
* A reflection streak under an emitter: lamp head, window, sign. at = its world position (an Object3D is read once; call again if it moves)
|
|
194
|
+
* @param {THREE.Vector3 | { x: number, y: number, z: number }} at
|
|
195
|
+
* @param {{ color?: THREE.ColorRepresentation, intensity?: number }} [opts] intensity: linear brightness of the streak's core (about the emitter's emissiveIntensity / 2)
|
|
196
|
+
*/
|
|
197
|
+
addStreak(at, { color = 0xffffff, intensity = 1 } = {}) {
|
|
198
|
+
const src = { at: new THREE.Vector3(at.x, at.y, at.z), color: new THREE.Color(color), intensity };
|
|
199
|
+
sources.push(src);
|
|
200
|
+
return {
|
|
201
|
+
/** change the streak (a lamp switching on / off follows its light) */
|
|
202
|
+
set(/** @type {{ color?: THREE.ColorRepresentation, intensity?: number }} */ v) { if (v.color !== undefined) src.color.set(v.color); if (v.intensity !== undefined) src.intensity = v.intensity; },
|
|
203
|
+
remove() { const i = sources.indexOf(src); if (i >= 0) sources.splice(i, 1); },
|
|
204
|
+
};
|
|
205
|
+
},
|
|
206
|
+
describe() { return { wetness: +state.wetness.toFixed(3), sinceRain: state.sinceRain, rain: rainNow(), puddleCover: +u.uPuddleCover.value.toFixed(3), streaks: streakMesh.count, held: state.held }; },
|
|
207
|
+
dispose() { hFixed?.remove?.(); hFrame?.remove?.(); streakMesh.removeFromParent(); geo.dispose(); streakMat.dispose(); },
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":1,"files":{},"ids":{}}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Game map: webgpu-tsl (generated, do not edit by hand)
|
|
2
|
+
|
|
3
|
+
> Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /webgpu-tsl.html, entry `main.js`.
|
|
4
|
+
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`; for the engine API read `node_modules/threedog/docs/API.md` (index) first, then only the module pages listed below.
|
|
5
|
+
|
|
6
|
+
Content: none (no content/ folder)
|
|
7
|
+
|
|
8
|
+
## Design decisions (hand-written, from DESIGN.md)
|
|
9
|
+
|
|
10
|
+
None yet, write them in `DESIGN.md` (why it is designed this way, what not to change).
|
|
11
|
+
|
|
12
|
+
## Engine modules (engine.use)
|
|
13
|
+
|
|
14
|
+
- createEngine: { canvas, renderer, ui: { loading: false }, saveKey: 'threedog-webgpu-tsl' }
|
|
15
|
+
- sky ({ time: Number(url.get('time') ?? 0.72) })
|
|
16
|
+
- fixedCamera ({ shots: { field: { position: [6, 2.2, 9], lookAt: [0, 0.8, 0] } }, start: 'field' })
|
|
17
|
+
|
|
18
|
+
## Read for this game (per installed module: recipe · api page; core API: `node_modules/threedog/docs/api/engine.md`)
|
|
19
|
+
|
|
20
|
+
- sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
|
|
21
|
+
- cameraRig: `node_modules/threedog/docs/recipes/21-camera.md` · `node_modules/threedog/docs/api/cameraRig.md`
|
|
22
|
+
|
|
23
|
+
Not used yet (check these before writing the system yourself):
|
|
24
|
+
|
|
25
|
+
- inventory: items, stacks, containers and pickups: `inventory()` + key map presets.bindings.inventory, content/items.js (node_modules/threedog/docs/recipes/03-items-pickups.md)
|
|
26
|
+
- collision: walls and blocking for characters: `collision()` (in openWorld), template `collide` (node_modules/threedog/docs/recipes/18-world.md)
|
|
27
|
+
- characters: player and NPC movement, spawn, schedules: `characters()` (in openWorld), content/npcs.js (node_modules/threedog/docs/recipes/02-npc.md)
|
|
28
|
+
- saves: save your own state: `engine.saves.register(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
|
|
29
|
+
- interactions: press a key near a thing: `interactions({ ...presets.interactions.nearest })` (E, nearest; the game picks the pick mode and keys), template `interact: { label, op }` (node_modules/threedog/docs/recipes/30-templates.md)
|
|
30
|
+
- quests: goals with steps, conditions and rewards: `quests()` + key map presets.bindings.quests, content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
|
|
31
|
+
- grids: cell placement for farming and building: `grids()` (node_modules/threedog/docs/recipes/29-grid.md)
|
|
32
|
+
- templates: reusable objects placed from content: content/templates.js + props { template } (node_modules/threedog/docs/recipes/30-templates.md)
|
|
33
|
+
|
|
34
|
+
## Files
|
|
35
|
+
|
|
36
|
+
content/*.js is content data: how to write it in `node_modules/threedog/docs/recipes/` (02-npc, 03-items-pickups, 04-quests, 20-content-actions-save…).
|
|
37
|
+
|
|
38
|
+
| File | Lines | Description |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| main.js | 22 | @ts-check WebGPU + TSL demo (page /webgpu-tsl.html): the scene of tslScene.js with the engine's sky… |
|
|
41
|
+
| tslScene.js | 76 | @ts-check A whole small scene on the WebGPU route, every material a three.js NodeMaterial written i… |
|
|
42
|
+
|
|
43
|
+
## NPCs (content/npcs.js)
|
|
44
|
+
|
|
45
|
+
(none)
|
|
46
|
+
|
|
47
|
+
## Dialogues (content/dialogues.js, node → destination)
|
|
48
|
+
|
|
49
|
+
(none)
|
|
50
|
+
|
|
51
|
+
## Items (content/items.js)
|
|
52
|
+
|
|
53
|
+
(none)
|
|
54
|
+
|
|
55
|
+
## Quests (content/quests.js)
|
|
56
|
+
|
|
57
|
+
(none)
|
|
58
|
+
|
|
59
|
+
## Trigger zones, level markers, places
|
|
60
|
+
|
|
61
|
+
(none)
|
|
62
|
+
|
|
63
|
+
## Placements (the level is content; counts per content file)
|
|
64
|
+
|
|
65
|
+
- none in content yet: place things with a template (content/templates.js) and a placement (content/props.js)
|
|
66
|
+
|
|
67
|
+
Code that breaks saves or manages world models: none (rule R33).
|
|
68
|
+
|
|
69
|
+
## Key actions defined by the game (the engine's own are in node_modules/threedog/docs/CODEMAP.md)
|
|
70
|
+
|
|
71
|
+
(none)
|
|
72
|
+
|
|
73
|
+
## Events the game emits / listens to
|
|
74
|
+
|
|
75
|
+
(none)
|
|
76
|
+
|
|
77
|
+
## Saves
|
|
78
|
+
|
|
79
|
+
- Save prefix saveKey: threedog-webgpu-tsl
|
|
80
|
+
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `threedog catalog` (saves per module)
|
|
81
|
+
|
|
82
|
+
## Style keys
|
|
83
|
+
|
|
84
|
+
- Style: none (all neutral fallback look)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
WebGPU and TSL: a small scene where every material is a TSL node material (ground, wind-blown grass, a lantern of your own, a post effect).
|
|
2
|
+
|
|
3
|
+
# WebGPU and TSL (example)
|
|
4
|
+
|
|
5
|
+
One field under the engine's sky: ground mixed from two tones by noise, grass swaying in the engine's wind, a lantern that glows as the day
|
|
6
|
+
ends, soft scanlines after tone mapping. Demo: `npm run dev` in the engine package, open `/webgpu-tsl.html` (`?time=0.85` dusk, `&webgl2`
|
|
7
|
+
the WebGL2 backend, `&scanlines=0` no post). The engine never imports this folder. Read recipe 56 (`docs/recipes/56-webgpu-tsl.md`) first;
|
|
8
|
+
this is the same material written out as a scene.
|
|
9
|
+
|
|
10
|
+
## Use it
|
|
11
|
+
```js
|
|
12
|
+
import 'threedog/tsl'; // first line of main.js on the WebGPU route
|
|
13
|
+
import { createEngine, sky } from 'threedog';
|
|
14
|
+
import { createTslScene } from './techniques/webgpu-tsl/tslScene.js';
|
|
15
|
+
|
|
16
|
+
const engine = createEngine({ canvas: document.getElementById('view'), renderer: 'webgpu' });
|
|
17
|
+
engine.use(sky());
|
|
18
|
+
createTslScene(engine, { grass: 3000 });
|
|
19
|
+
await engine.start();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## How it works
|
|
23
|
+
- **Your node, the engine's function.** `wind()`, `cloudShadow()`, `season()`, `detailNoise()` come from `threedog/tsl` and are ordinary
|
|
24
|
+
TSL functions: they take nodes and return nodes, so they go anywhere a node goes (`colorNode`, `positionNode`, inside your own `Fn`).
|
|
25
|
+
- **The engine's values as nodes.** `uniforms(engine)` gives `uTime`, `uWind`, `uDaylight`, `uSunDir`... as nodes over `engine.uniforms`.
|
|
26
|
+
The lantern's glow is a function of `uDaylight`; the sky moves that value, the node follows, and there is no per-frame code.
|
|
27
|
+
- **Grass shadows sway by themselves.** three's shadow pass draws with the material's `positionNode`, so moving vertices there moves
|
|
28
|
+
their shadow too. (On WebGL the same needs a depth material; that is the engine patch's job there.)
|
|
29
|
+
- **Post is a node too.** The effect's `node(input, ctx)` returns the new color. `slot: 'ldr'` puts it after tone mapping, where colors are
|
|
30
|
+
what the screen shows; an effect that should glow or bleed belongs in `hdr` instead.
|
|
31
|
+
|
|
32
|
+
## Knobs (`PARAMS`)
|
|
33
|
+
`size`, `grass` (one InstancedMesh, one draw call), `sway` (meters per meter of blade height, times the weather's wind), `scanlines`.
|
|
34
|
+
The colors are neutral placeholders: take them from the game's DESIGN.md, not from here.
|
|
35
|
+
|
|
36
|
+
## Adapting it
|
|
37
|
+
- Rotated or scaled grass instances: the offset must turn with each instance. Use the patch form, `applyEffects(mat, { wind: 0.25 })`, which
|
|
38
|
+
does that (recipe 56, section 5), instead of `positionNode` by hand.
|
|
39
|
+
- A different look for the ground (stripes, rock by slope, a texture): replace the `colorNode` expression; keep `.mul(cloudShadow(positionWorld))`
|
|
40
|
+
if the game has cloud shadows.
|
|
41
|
+
- Cost: TSL compiles when a material is first drawn. Many distinct materials mean a longer first frame on WebGPU (recipe 56 says when
|
|
42
|
+
WebGL is the better choice).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// WebGPU + TSL demo (page /webgpu-tsl.html): the scene of tslScene.js with the engine's sky, written the way a game's main.js would be
|
|
3
|
+
// (imports from 'threedog', not engine-internal paths), so what runs here is what runs after `threedog examples pull webgpu-tsl`.
|
|
4
|
+
// URL: ?time=0..1 (fixed time of day, default 0.72: late afternoon, the lantern starting to glow) &webgl2 (the game's own WebGPURenderer on
|
|
5
|
+
// its WebGL2 backend: how the test runs it, the same on every machine) &scanlines=0 (no post effect).
|
|
6
|
+
// Test page for tests/specs/webgpu-tsl.mjs: window.webgpuTslTest = { parts, THREE }.
|
|
7
|
+
import 'threedog/tsl'; // first: the WebGPU route's node versions of the engine's sky, post chain and patches register here
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import { WebGPURenderer } from 'three/webgpu';
|
|
10
|
+
import { createEngine, sky, fixedCamera } from 'threedog';
|
|
11
|
+
import { createTslScene } from './tslScene.js';
|
|
12
|
+
|
|
13
|
+
const url = new URLSearchParams(location.search), canvas = /** @type {HTMLCanvasElement} */ (document.getElementById('view'));
|
|
14
|
+
// 'webgpu': the engine builds the WebGPURenderer and falls back to its WebGL2 backend when the browser has no WebGPU (said once in the console)
|
|
15
|
+
const renderer = url.has('webgl2') ? new WebGPURenderer({ canvas, antialias: true, forceWebGL: true }) : 'webgpu';
|
|
16
|
+
const engine = createEngine({ canvas, renderer, ui: { loading: false }, saveKey: 'threedog-webgpu-tsl' });
|
|
17
|
+
engine.use(sky({ time: Number(url.get('time') ?? 0.72) }),
|
|
18
|
+
fixedCamera({ shots: { field: { position: [6, 2.2, 9], lookAt: [0, 0.8, 0] } }, start: 'field' }));
|
|
19
|
+
const parts = createTslScene(engine, url.get('scanlines') === '0' ? { scanlines: 0 } : {});
|
|
20
|
+
Object.assign(window, { engine, webgpuTslTest: { parts, THREE } }); // the dev bridge and the test find the engine here
|
|
21
|
+
await engine.start();
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// A whole small scene on the WebGPU route, every material a three.js NodeMaterial written in TSL: ground, wind-blown grass, one material of
|
|
3
|
+
// the game's own (a lantern that lights up as the day ends) and one post effect (soft scanlines). README.md next to this file; copy and adapt.
|
|
4
|
+
// What it shows: the engine's shader functions (threedog/tsl) are plain TSL functions called inside your own nodes, and the engine's values
|
|
5
|
+
// (time, wind, daylight, season) reach your nodes through uniforms(engine). Nothing here is a style: colors are neutral starting points.
|
|
6
|
+
// Needs: import 'threedog/tsl' at the top of the game's main.js and createEngine({ renderer: 'webgpu' }) (or your own WebGPURenderer).
|
|
7
|
+
import * as THREE from 'three';
|
|
8
|
+
import { MeshLambertNodeMaterial, MeshStandardNodeMaterial } from 'three/webgpu';
|
|
9
|
+
import { color, float, mix, positionGeometry, positionLocal, positionWorld, sin, smoothstep, uv } from 'three/tsl';
|
|
10
|
+
import { wind, objectOrigin, cloudShadow, season, detailNoise, uniforms } from 'threedog/tsl';
|
|
11
|
+
|
|
12
|
+
export const PARAMS = {
|
|
13
|
+
size: 40, // m, side of the square ground
|
|
14
|
+
grass: 1500, // blades (one InstancedMesh: one draw call however many)
|
|
15
|
+
sway: 0.25, // wind amplitude, meters per meter of blade height (times engine.uniforms.uWind, which weather changes)
|
|
16
|
+
scanlines: 0.08, // post effect strength 0..1; 0 = the effect stays in the chain but does nothing
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Build the scene into engine.scene. Call before engine.start().
|
|
21
|
+
* @param {import('threedog').Engine} engine
|
|
22
|
+
* @param {Partial<typeof PARAMS>} [o]
|
|
23
|
+
* @returns {{ ground: THREE.Mesh, grass: THREE.InstancedMesh, lantern: THREE.Mesh, post: { remove(): void } }}
|
|
24
|
+
*/
|
|
25
|
+
export function createTslScene(engine, o = {}) {
|
|
26
|
+
const P = { ...PARAMS, ...o }, u = uniforms(engine);
|
|
27
|
+
|
|
28
|
+
// Ground: two earth tones mixed by the engine's detail noise (a world-space pattern, so tiles never repeat), tinted by the season and
|
|
29
|
+
// darkened under the drifting cloud shadows. All three are functions of the position; none of them needs a texture.
|
|
30
|
+
const patches = detailNoise(positionWorld.xz.mul(0.15), 0, 3).a;
|
|
31
|
+
const groundMat = new MeshStandardNodeMaterial({ roughness: 1 });
|
|
32
|
+
groundMat.colorNode = season(mix(color(0x5f7a3c), color(0x857452), smoothstep(0.35, 0.65, patches)), 1).mul(cloudShadow(positionWorld));
|
|
33
|
+
const ground = new THREE.Mesh(new THREE.PlaneGeometry(P.size, P.size).rotateX(-Math.PI / 2), groundMat);
|
|
34
|
+
ground.receiveShadow = true;
|
|
35
|
+
ground.name = 'ground';
|
|
36
|
+
|
|
37
|
+
// Grass: one blade shape drawn many times. wind() returns an object-space offset; positionGeometry is the blade before the instance
|
|
38
|
+
// transform, objectOrigin() each instance's own world origin (so neighbours sway out of phase). positionNode is also what three's shadow
|
|
39
|
+
// pass reads, so the shadows sway with the blades without a second material.
|
|
40
|
+
// Instances are only moved, never rotated or scaled: then the object-space offset is already right after the instance transform. Rotated
|
|
41
|
+
// instances: use the patch form applyEffects(mat, { wind }) (recipe 56, section 5), which turns the offset with each instance.
|
|
42
|
+
const blade = new THREE.PlaneGeometry(0.07, 0.5, 1, 3).translate(0, 0.25, 0);
|
|
43
|
+
const grassMat = new MeshLambertNodeMaterial({ side: THREE.DoubleSide });
|
|
44
|
+
grassMat.colorNode = season(mix(color(0x2f4a1c), color(0x8fb052), uv().y), 0);
|
|
45
|
+
grassMat.positionNode = positionLocal.add(wind(positionGeometry, objectOrigin(), float(P.sway)));
|
|
46
|
+
const grass = new THREE.InstancedMesh(blade, grassMat, P.grass);
|
|
47
|
+
const m = new THREE.Matrix4(), r = engine.random, half = P.size * 0.45;
|
|
48
|
+
for (let i = 0; i < P.grass; i++) grass.setMatrixAt(i, m.makeTranslation(r.range(-half, half), 0, r.range(-half, half)));
|
|
49
|
+
grass.castShadow = true;
|
|
50
|
+
grass.name = 'grass';
|
|
51
|
+
|
|
52
|
+
// The game's own material: a lantern whose glow follows the engine's daylight (1 at noon, 0 at night) and flickers with engine time.
|
|
53
|
+
// uniforms(engine) are nodes over engine.uniforms: when the sky moves uDaylight, this node moves with it; nothing to update per frame.
|
|
54
|
+
const night = float(1).sub(u.uDaylight);
|
|
55
|
+
const flicker = sin(u.uTime.mul(7)).mul(0.08).add(0.92);
|
|
56
|
+
const lanternMat = new MeshStandardNodeMaterial({ color: 0x3a2a18, roughness: 0.6 });
|
|
57
|
+
lanternMat.emissiveNode = color(0xffa040).mul(smoothstep(0.3, 0.9, night).mul(3).mul(flicker));
|
|
58
|
+
const lantern = new THREE.Mesh(new THREE.OctahedronGeometry(0.35, 1), lanternMat);
|
|
59
|
+
lantern.position.set(0, 1.2, 0);
|
|
60
|
+
lantern.castShadow = true;
|
|
61
|
+
lantern.name = 'lantern';
|
|
62
|
+
|
|
63
|
+
engine.scene.add(ground, grass, lantern);
|
|
64
|
+
|
|
65
|
+
// Post on the WebGPU route: an effect gives node(input, ctx) => color node. input is the picture so far; slot 'ldr' runs after tone
|
|
66
|
+
// mapping, so the values are display colors 0..1. ctx.p holds a live uniform per number param: look.post.set({ 'scanlines.amount': 0.2 })
|
|
67
|
+
// changes it without rebuilding the chain. A three.js Pass (create) does not run on WebGPURenderer.
|
|
68
|
+
const post = engine.look.post.add({ name: 'scanlines', slot: 'ldr', params: { amount: P.scanlines },
|
|
69
|
+
node: (input, { tsl: T, p }) => {
|
|
70
|
+
const line = T.sin(T.screenCoordinate.y.mul(Math.PI)).mul(0.5).add(0.5); // 0..1 every other device pixel row
|
|
71
|
+
return T.vec4(input.rgb.mul(T.float(1).sub(p.amount.mul(line))), input.a);
|
|
72
|
+
} });
|
|
73
|
+
|
|
74
|
+
return { ground, grass, lantern, post };
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":1,"files":{"content/actions.js":{"kind":"actions","mtime":1793474271288.9531,"from":0,"count":4,"indexIds":0,"positional":[]},"content/audio.js":{"kind":"audio","mtime":1793627600000,"from":0,"count":3,"indexIds":0,"positional":[]},"content/bodies.js":{"kind":"bodies","mtime":1793474271284.9543,"from":0,"count":8,"indexIds":0,"positional":[]},"content/containers.js":{"kind":"containers","mtime":1793474271310.478,"from":0,"count":1,"indexIds":0,"positional":[]},"content/dialogues.js":{"kind":"dialogues","mtime":1793474271305.4783,"from":0,"count":1,"indexIds":0,"positional":[]},"content/items.js":{"kind":"items","mtime":1793474271323.4858,"from":0,"count":4,"indexIds":0,"positional":[]},"content/npcs.js":{"kind":"npcs","mtime":1793627600000,"from":0,"count":1,"indexIds":0,"positional":[]},"content/pickups.js":{"kind":"pickups","mtime":1793474271319.4905,"from":0,"count":8,"indexIds":8,"positional":[0,1,2,3,4,5,6,7]},"content/places.js":{"kind":"places","mtime":1793474271301.9636,"from":0,"count":3,"indexIds":0,"positional":[]},"content/props.js":{"kind":"props","mtime":1793627600000,"from":0,"count":8,"indexIds":0,"positional":[]},"content/quests.js":{"kind":"quests","mtime":1793474271339.5947,"from":0,"count":1,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1793627600000,"from":0,"count":1,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1793627600000,"from":0,"count":5,"indexIds":0,"positional":[]}},"ids":{"save":[{"file":"content/actions.js","kind":"actions","line":4,"placed":false}],"load":[{"file":"content/actions.js","kind":"actions","line":5,"placed":false}],"kick":[{"file":"content/actions.js","kind":"actions","line":6,"placed":false}],"chop":[{"file":"content/actions.js","kind":"actions","line":7,"placed":false}],"sounds":[{"file":"content/audio.js","kind":"audio","line":7,"placed":false}],"ambience":[{"file":"content/audio.js","kind":"audio","line":14,"placed":false}],"footsteps":[{"file":"content/audio.js","kind":"audio","line":23,"placed":false}],"crate-0":[{"file":"content/bodies.js","kind":"bodies","line":4,"placed":false}],"crate-1":[{"file":"content/bodies.js","kind":"bodies","line":5,"placed":false}],"crate-2":[{"file":"content/bodies.js","kind":"bodies","line":6,"placed":false}],"crate-3":[{"file":"content/bodies.js","kind":"bodies","line":7,"placed":false}],"crate-4":[{"file":"content/bodies.js","kind":"bodies","line":8,"placed":false}],"crate-5":[{"file":"content/bodies.js","kind":"bodies","line":9,"placed":false}],"ball":[{"file":"content/bodies.js","kind":"bodies","line":10,"placed":false}],"barrel":[{"file":"content/bodies.js","kind":"bodies","line":11,"placed":false}],"fisher-basket":[{"file":"content/containers.js","kind":"containers","line":3,"placed":false}],"fisher":[{"file":"content/dialogues.js","kind":"dialogues","line":4,"placed":false},{"file":"content/npcs.js","kind":"npcs","line":3,"placed":false}],"film":[{"file":"content/items.js","kind":"items","line":3,"placed":false}],"berry":[{"file":"content/items.js","kind":"items","line":4,"placed":false}],"feather":[{"file":"content/items.js","kind":"items","line":5,"placed":false}],"wood":[{"file":"content/items.js","kind":"items","line":6,"placed":false}],"pickup:feather:0":[{"file":"content/pickups.js","kind":"pickups","line":3,"placed":true}],"pickup:berry:1":[{"file":"content/pickups.js","kind":"pickups","line":4,"placed":true}],"pickup:berry:2":[{"file":"content/pickups.js","kind":"pickups","line":5,"placed":true}],"pickup:feather:3":[{"file":"content/pickups.js","kind":"pickups","line":6,"placed":true}],"pickup:berry:4":[{"file":"content/pickups.js","kind":"pickups","line":7,"placed":true}],"pickup:berry:5":[{"file":"content/pickups.js","kind":"pickups","line":8,"placed":true}],"pickup:feather:6":[{"file":"content/pickups.js","kind":"pickups","line":9,"placed":true}],"pickup:berry:7":[{"file":"content/pickups.js","kind":"pickups","line":10,"placed":true}],"home":[{"file":"content/places.js","kind":"places","line":3,"placed":false}],"river":[{"file":"content/places.js","kind":"places","line":4,"placed":false}],"water":[{"file":"content/places.js","kind":"places","line":5,"placed":false}],"prop:pine:0":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"prop:pine:1":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"prop:roundTree:2":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"prop:rock:3":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"prop:rock:4":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"prop:flower:5":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"prop:flower:6":[{"file":"content/props.js","kind":"props","line":10,"placed":true}],"cabin":[{"file":"content/props.js","kind":"props","line":11,"placed":true},{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"first-light":[{"file":"content/quests.js","kind":"quests","line":4,"placed":false}],"松树":[{"file":"content/vegetation.js","kind":"vegetation","line":5,"placed":false}],"圆树":[{"file":"content/vegetation.js","kind":"vegetation","line":11,"placed":false}],"石头":[{"file":"content/vegetation.js","kind":"vegetation","line":17,"placed":false}],"草":[{"file":"content/vegetation.js","kind":"vegetation","line":21,"placed":false}],"野花":[{"file":"content/vegetation.js","kind":"vegetation","line":26,"placed":false}]}}
|
|
@@ -13,16 +13,16 @@ Content: actions 4 · audio 3 · containers 1 · dialogues 1 · items 4 · npcs
|
|
|
13
13
|
|
|
14
14
|
## Engine modules (engine.use)
|
|
15
15
|
|
|
16
|
-
- createEngine: {
|
|
17
|
-
- openWorld preset ({ camera: 'follow', seed: SEED, terrain: terrainPreset(), flatten: [{ x: home.x, z: home.z, radius:…) → world, terrain, vegetation, sky, weather, water, collision, rigid, characters, ambience, settings, debug
|
|
16
|
+
- createEngine: { ...(gpuRoute && { renderer: 'webgpu' }), bindings: { ...presets.bindings.walk, ...presets.bindings.interact…
|
|
17
|
+
- openWorld preset ({ camera: 'follow', seed: SEED, terrain: terrainPreset(), flatten: [{ x: home.x, z: home.z, radius:…) → world, terrain, vegetation, calendar, sky, weather, water, collision, rigid, characters, ambience, settings, debug
|
|
18
18
|
- interactions ({ ...presets.interactions.nearest })
|
|
19
19
|
- dialogue
|
|
20
|
-
- inventory
|
|
21
|
-
-
|
|
22
|
-
-
|
|
20
|
+
- inventory
|
|
21
|
+
- pickups
|
|
22
|
+
- quests
|
|
23
|
+
- photo
|
|
23
24
|
- timeline
|
|
24
25
|
- triggers
|
|
25
|
-
- entities
|
|
26
26
|
- particles
|
|
27
27
|
- music ({ duckDialogue: 0.35 })
|
|
28
28
|
- hud
|
|
@@ -32,14 +32,14 @@ Content: actions 4 · audio 3 · containers 1 · dialogues 1 · items 4 · npcs
|
|
|
32
32
|
- world: `node_modules/threedog/docs/recipes/18-world.md` · `node_modules/threedog/docs/api/world.md`
|
|
33
33
|
- terrain: `node_modules/threedog/docs/recipes/28-terrain.md` · `node_modules/threedog/docs/api/terrain.md`
|
|
34
34
|
- vegetation: `node_modules/threedog/docs/recipes/10-blender-level.md` · `node_modules/threedog/docs/api/vegetation.md`
|
|
35
|
+
- calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
|
|
35
36
|
- sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
|
|
36
37
|
- weather: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/weather.md`
|
|
37
38
|
- water: `node_modules/threedog/docs/recipes/44-water-weather-look-hooks.md` · `node_modules/threedog/docs/api/water.md`
|
|
38
39
|
- collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
|
|
39
40
|
- rigid: `node_modules/threedog/docs/recipes/11-vehicles.md` · `node_modules/threedog/docs/api/rigid.md`
|
|
40
41
|
- characters: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/characters.md`
|
|
41
|
-
-
|
|
42
|
-
- …12 more modules: their pages are in `node_modules/threedog/docs/api/`
|
|
42
|
+
- …13 more modules: their pages are in `node_modules/threedog/docs/api/`
|
|
43
43
|
|
|
44
44
|
Not used yet (check these before writing the system yourself):
|
|
45
45
|
|
|
@@ -51,6 +51,11 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
51
51
|
|
|
52
52
|
| File | Lines | Description |
|
|
53
53
|
|---|---|---|
|
|
54
|
+
| art/humanoid.js | 43 | The 'humanoid' body: the procedural character body, exported in the world example's asset pack (art… |
|
|
55
|
+
| art/index.js | 12 | The world example's own art: procedural models built in code (trees, rocks, grass, flowers, the 'hu… |
|
|
56
|
+
| art/models.js | 59 | The world example's procedural models: trees, rocks, grass and flowers built in code, no files. Exp… |
|
|
57
|
+
| art/shapes.js | 10 | The ground pickup shape, registered as the asset model name 'pickup' (assets in art/index.js). It i… |
|
|
58
|
+
| assets.js | 7 | The asset packs this game registers (main.js: engine.assets.manifest(packs)). Kept in their own fil… |
|
|
54
59
|
| content/actions.js | 9 | |
|
|
55
60
|
| content/audio.js | 26 | |
|
|
56
61
|
| content/bodies.js | 13 | |
|
|
@@ -66,14 +71,16 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
66
71
|
| content/rules.js | 24 | |
|
|
67
72
|
| content/templates.js | 6 | |
|
|
68
73
|
| content/vegetation.js | 33 | |
|
|
69
|
-
| main.js |
|
|
74
|
+
| main.js | 173 | Open-world example (slow photography life): riverside cabin + an old fisherman who walks by the clo… |
|
|
70
75
|
| models.js | 29 | Models this game builds in code: the cabin (registered by name in main.js, placed by content/props.… |
|
|
76
|
+
| style/index.js | 62 | The world example's look: one folder = one style (recipes/09-style.md). Starting values only; the g… |
|
|
77
|
+
| style/plugins/10-bloom.js | 6 | The world look's bloom: a post effect plugin of the style (look.post.add puts it in the chain; look… |
|
|
71
78
|
|
|
72
79
|
## NPCs (content/npcs.js)
|
|
73
80
|
|
|
74
|
-
| id | Name | Schedule |
|
|
81
|
+
| id | Name | Schedule | Interact |
|
|
75
82
|
|---|---|---|---|
|
|
76
|
-
| fisher | 老渔夫 | 06:00 river · 12:00 home(-4,4) · 19:12 home(1,4.5) | fisher → start |
|
|
83
|
+
| fisher | 老渔夫 | 06:00 river · 12:00 home(-4,4) · 19:12 home(1,4.5) | talk fisher → start |
|
|
77
84
|
|
|
78
85
|
## Dialogues (content/dialogues.js, node → destination)
|
|
79
86
|
|
|
@@ -112,7 +119,7 @@ Starting inventory: film×12. Pickups: 8: feather×3, berry×5 (respawn after 12
|
|
|
112
119
|
|
|
113
120
|
- Condition **timeAfter** (clock): the day has passed this clock time
|
|
114
121
|
|
|
115
|
-
## Object templates (content/templates.js; placed with props { template }, spawned with engine.spawn)
|
|
122
|
+
## Object templates (content/templates.js; placed with props { template }, spawned with engine.content.spawn)
|
|
116
123
|
|
|
117
124
|
| Template | Model | Collide | Interact (op / label) | Container | State (defaults) | Instances |
|
|
118
125
|
|---|---|---|---|---|---|---|
|
|
@@ -161,11 +168,11 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
161
168
|
- Save prefix saveKey: default
|
|
162
169
|
- Save slots: slot1
|
|
163
170
|
- Autosave: every 3 minutes
|
|
164
|
-
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `
|
|
171
|
+
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `threedog catalog` (saves per module)
|
|
165
172
|
|
|
166
|
-
## Style
|
|
173
|
+
## Style keys
|
|
167
174
|
|
|
168
|
-
- Style
|
|
175
|
+
- Style: none (all neutral fallback look)
|
|
169
176
|
- Models (asset names): pine, pineLow, roundTree, roundTreeLow, rock, grass, flower, cabin
|
|
170
177
|
- Particle presets (style.particles): smoke, leaves, dust
|
|
171
178
|
- Vegetation (content/vegetation.js): 松树, 圆树, 石头, 草, 野花
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// The 'humanoid' body: the procedural character body, exported in the world example's asset pack (art/index.js `assets`), so a character picks it like any model:
|
|
2
|
+
// createPlayer({ model: 'humanoid' }), npcs content { model: 'humanoid' }. It is an asset and not a style part because a body is content the
|
|
3
|
+
// game chooses per character (a GLB hero next to procedural villagers), while a style only decides how things look.
|
|
4
|
+
// Looks still come from the style: each part uses a material ROLE (skin / cloth / trousers / hair), so any style that defines those roles
|
|
5
|
+
// tints and shades it (style: [style, { materials: { cloth: { color: 0x3a6ea5 } } }]; the world example's style/ gives all four); a role the
|
|
6
|
+
// style leaves out is the neutral 'default' material. Per-character colors ({ colors: { body, skin, legs, hair } }) recolor the parts marked userData.part.
|
|
7
|
+
// The rig (which object is the hips, which joints swing) is plain data by NAME in root.userData.rig, because names survive asset copies and
|
|
8
|
+
// GLB export: Character reads it back (rigFromObject) and swings the limbs for walk / run / swim / jump.
|
|
9
|
+
import * as THREE from 'three';
|
|
10
|
+
import { makeMaterial } from '../../../index.js';
|
|
11
|
+
|
|
12
|
+
// part (the key of a character's `colors`) -> material role
|
|
13
|
+
const ROLE = { body: 'cloth', skin: 'skin', legs: 'trousers', hair: 'hair' };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Low-poly humanoid (cylinder body, icosahedron head, box limbs). Each joint is a named empty Group with the limb under it; rotating it swings
|
|
17
|
+
* the limb. Joints armL / armR / legL / legR are exposed on the character (c.armL ...). Written with `function`: this = { palette, engine }.
|
|
18
|
+
* @this {{ engine?: any } | undefined}
|
|
19
|
+
*/
|
|
20
|
+
export function humanoid() {
|
|
21
|
+
const engine = this?.engine, mats = {};
|
|
22
|
+
const mat = part => mats[part] ??= makeMaterial(ROLE[part], {}, engine); // look.materials decides each role (style table, then the game's set / replace)
|
|
23
|
+
const mesh = (geo, part, name) => { const m = new THREE.Mesh(geo, mat(part)); m.castShadow = true; m.userData.part = part; m.name = name; return m; };
|
|
24
|
+
const group = (name, parent, x, y) => { const g = new THREE.Group(); g.name = name; g.position.set(x, y, 0); parent.add(g); return g; };
|
|
25
|
+
const root = new THREE.Group(); root.name = 'humanoid';
|
|
26
|
+
const hips = group('hips', root, 0, 0.85);
|
|
27
|
+
hips.add(mesh(new THREE.CylinderGeometry(0.28, 0.33, 0.7, 6).translate(0, 0.35, 0), 'body', 'torso'));
|
|
28
|
+
const head = group('head', hips, 0, 0.78);
|
|
29
|
+
head.add(mesh(new THREE.IcosahedronGeometry(0.27, 0).translate(0, 0.2, 0), 'skin', 'face'));
|
|
30
|
+
head.add(mesh(new THREE.IcosahedronGeometry(0.28, 0).scale(1, 0.55, 1).translate(0, 0.36, -0.03), 'hair', 'hairCap'));
|
|
31
|
+
const limb = (name, len, w, part, x, y) => { const j = group(name, hips, x, y); j.add(mesh(new THREE.BoxGeometry(w, len, w).translate(0, -len / 2, 0), part, name + 'Mesh')); };
|
|
32
|
+
limb('armL', 0.6, 0.13, 'body', -0.37, 0.65); limb('armR', 0.6, 0.13, 'body', 0.37, 0.65);
|
|
33
|
+
limb('legL', 0.85, 0.17, 'legs', -0.14, 0.02); limb('legR', 0.85, 0.17, 'legs', 0.14, 0.02);
|
|
34
|
+
root.userData.rig = {
|
|
35
|
+
body: 'hips', head: 'head', joints: ['armL', 'armR', 'legL', 'legR'],
|
|
36
|
+
limbs: [
|
|
37
|
+
{ joint: 'legL', offset: 0, amp: 0.9, kind: 'leg' }, { joint: 'legR', offset: Math.PI, amp: 0.9, kind: 'leg' },
|
|
38
|
+
{ joint: 'armL', offset: Math.PI, amp: 0.8, kind: 'arm', side: -1 }, { joint: 'armR', offset: 0, amp: 0.8, kind: 'arm', side: 1 },
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
return root;
|
|
42
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// The world example's own art: procedural models built in code (trees, rocks, grass, flowers, the 'humanoid' body, the 'pickup' shape).
|
|
2
|
+
// An asset pack, not a style: content names the models (pine, ['flower', color], humanoid), and how they are shaded comes from the style's
|
|
3
|
+
// material roles (style/index.js). engine.assets.manifest(assets) registers them; `models` is the same generators as a plain name -> function map.
|
|
4
|
+
import { models as scenery } from './models.js';
|
|
5
|
+
import { humanoid } from './humanoid.js';
|
|
6
|
+
import { pickup } from './shapes.js';
|
|
7
|
+
|
|
8
|
+
/** The procedural models as a plain name -> generator map */
|
|
9
|
+
export const models = { ...scenery, humanoid, pickup };
|
|
10
|
+
/** Asset pack: engine.assets.manifest(assets) registers pine, roundTree, rock, flower, grass, humanoid, pickup... as model names */
|
|
11
|
+
export const assets = { name: 'world-art', models };
|