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
package/core/renamed.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// The ONE list of names renamed in 0.2: plain data with no imports (errorHints.js re-exports it for the stubs; rule R39 reads it through 'threedog/error-hints').
|
|
2
|
-
/**
|
|
3
|
-
* The ONE list of names renamed in 0.2 (recipes/52-look.md "Renamed in 0.2"): key -> { old call, new call, find = a regex source that spots a
|
|
4
|
-
* use of the old name in source text }. The throwing stubs read `old` / `now` through renamed(key); rule R39 reads `find` to keep the old names out of the repo.
|
|
5
|
-
* `find: null` = no safe text pattern (the old name is a field name shared with unrelated objects).
|
|
6
|
-
* @type {Record<string, { old: string, now: string, find: string | null }>}
|
|
7
|
-
*/
|
|
8
|
-
export const RENAMED = {
|
|
9
|
-
setExposure: { old: 'engine.setExposure(v)', now: 'engine.look.tone.set({ exposure: v })', find: '\\bsetExposure\\b' },
|
|
10
|
-
setToneMapping: { old: 'engine.setToneMapping(kind)', now: "engine.look.tone.set({ mapping: 'aces' })", find: '\\bsetToneMapping\\b' },
|
|
11
|
-
setEnvironment: { old: 'engine.sky.setEnvironment(o)', now: "engine.look.env.replace('sky') then engine.look.env.set({ intensity, rotation }); engine.look.env.replace(false) turns it off", find: '\\bsetEnvironment\\b' },
|
|
12
|
-
setShadow: { old: 'engine.sky.setShadow(o)', now: 'engine.look.shadow.set(o)', find: '\\bsetShadow\\b' },
|
|
13
|
-
weatherDefine: { old: 'engine.weather.define(field, spec)', now: 'engine.look.weather.replace({ [field]: spec })', find: '\\bweather\\??\\.define\\b' },
|
|
14
|
-
postAdd: { old: 'engine.post.add(effect)', now: 'engine.look.post.add(effect, { owner }) for one pass (returns { remove() }), patch(name, { glsl }) for a color effect, or replace([...effects]) for the whole chain', find: '(?<!look\\.)\\bpost\\??\\.add\\b' },
|
|
15
|
-
postEnable: { old: 'engine.post.enable(name, on)', now: "engine.look.post.set({ 'bloom.enabled': on }); MSAA: engine.post.setAntialias(on)", find: '\\bpost\\??\\.enable\\b' },
|
|
16
|
-
postHandle: { old: 'engine.post.get(name).set / .enable / .remove', now: "engine.look.post.set({ 'bloom.strength': 0.6 }); read with engine.post.get(name)", find: '\\bpost\\??\\.get\\([^)]*\\)\\??\\.(set|enable|remove)\\b' },
|
|
17
|
-
lookClouds: { old: 'engine.look.clouds', now: 'engine.look.cloudShadow', find: '\\blook\\.clouds\\b' },
|
|
18
|
-
cameraOverride: { old: 'engine.cameraOverride = {...}', now: "const cam = engine.takeCamera('owner', { focus }); cam.remove() releases it", find: '\\bcameraOverride\\s*=(?!=)' },
|
|
19
|
-
viewsPos: { old: "views.define(name, { pos })", now: 'views.define(name, { position: [x, y, z] })', find: null },
|
|
20
|
-
reason: { old: 'result.reason (ops.run / can / undo failures), ops.recent() / catalog(op).last / net:result .reason', now: 'result.code (the same name in history, catalog and net:result)', find: null },
|
|
21
|
-
};
|
package/docs/api/entities.md
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# engine.entities — entities()
|
|
2
|
-
|
|
3
|
-
Entities: single stateful, saved objects such as saplings, campfires and chests; the data is a record of engine.world, the model is built only when nearby (entities() module)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
## Methods and properties
|
|
7
|
-
- `entities.define(type: string, def: EntityDef<S>)` — Define an entity type
|
|
8
|
-
- `entities.spawn(type: string, data?: EntitySpawnData) → Entity | null` — Spawn an entity (returns null if the type is not defined)
|
|
9
|
-
- `entities.nearest(position: PositionLike, opts?: { radius?, type? }) → Entity | null` — The entity nearest to position within radius meters (default 3) (type restricts to one type)
|
|
10
|
-
- `entities.clear()` — Delete all entities
|
|
11
|
-
- `entities.setStage(ent: Entity, i: number)` — Jump straight to a growth stage
|
|
12
|
-
- Also: `entities.get(id: string) → Entity | null`, `entities.byType(type: string) → Entity[]`, `entities.list() → Entity[]`, `entities.remove(id: string) → boolean`
|
|
13
|
-
- Properties:
|
|
14
|
-
- `types: Map<string, EntityDef>` Type definitions
|
|
15
|
-
- `now: number` Game seconds (= engine.clock.now)
|
|
16
|
-
|
|
17
|
-
## Data structures
|
|
18
|
-
- **EntityDef** Entity type definition: engine.entities.define('sapling', {...})
|
|
19
|
-
- `create: (engine: Engine, ent: Entity<S>) => Object3D` Create the model (required), returns a THREE.Object3D
|
|
20
|
-
- `state?: S` Default state (merged with the state given at spawn)
|
|
21
|
-
- `stages?: EntityStage[]` Growth stages
|
|
22
|
-
- `canGrow?: (ent: Entity<S>, engine: Engine) => boolean` Growth stops when this returns false
|
|
23
|
-
- `update?: (dt: number, ent: Entity<S>, engine: Engine) => void` Called every fixed step (dt in seconds); runs only near the player, far away only growth is caught up
|
|
24
|
-
- `interact?: EntityInteract` Interaction
|
|
25
|
-
- `collider?: number` Circular collision radius (meters, needs the collision module; follows the model, exists only near the player)
|
|
26
|
-
- `colliderHeight?: number` Collision height (meters), default 3
|
|
27
|
-
- `dispose?: (ent: Entity<S>, engine: Engine) => void` Cleanup when the model is torn down (called both when walking away and on deletion; don't clear data while the data still exists)
|
|
28
|
-
- `save?: boolean` false = not saved (temporary things, cleared on load), default true
|
|
29
|
-
- **EntityStage** Growth stage
|
|
30
|
-
- `name: string` Stage name, e.g. 'seed'
|
|
31
|
-
- `duration?: number` How many game seconds to stay in this stage (leave out on the last one = stay here forever)
|
|
32
|
-
- `scale?: number` Model size multiplier
|
|
33
|
-
- `model?: (engine: Engine, ent: Entity) => Object3D` Swap the model
|
|
34
|
-
- **EntityInteract** Entity interaction settings (needs the interactions module)
|
|
35
|
-
- `label?: string | ((ent: Entity, engine: Engine) => string)` Prompt text: an i18n key, plain text, or a function ent => text
|
|
36
|
-
- `action?: string` Interaction action name, default 'interact'
|
|
37
|
-
- `radius?: number` How close you must be to interact (meters), default 2.5
|
|
38
|
-
- `height?: number` How high the prompt floats (meters)
|
|
39
|
-
- `enabled?: (ent: Entity, engine: Engine) => boolean` Whether it can be interacted with
|
|
40
|
-
- `onUse?: (ent: Entity, engine: Engine) => void` When the interact key is pressed
|
|
41
|
-
- **EntitySpawnData** Parameters of spawn()
|
|
42
|
-
- `id?: string` Specify the id (generated automatically if omitted)
|
|
43
|
-
- `position?: PositionLike` Position: Vector3 / object / [x, y, z] / { x, z } ({ x, z } without y snaps to the ground), default origin
|
|
44
|
-
- `rotation?: number` Heading (radians)
|
|
45
|
-
- `state?: Record<string, any>` Initial state (merged onto the default state)
|
|
46
|
-
- `extra?: Record<string, any>` Extra data (ent.data, saved)
|
|
47
|
-
- **Entity** An entity: x / y / z / rotation / state / data read engine.world data directly (kind is 'entity:<type>'); object / visual exist only near the player
|
|
48
|
-
- `id: string`
|
|
49
|
-
- `type: string`
|
|
50
|
-
- `def: EntityDef<S>`
|
|
51
|
-
- `x: number` Position (meters)
|
|
52
|
-
- `z: number`
|
|
53
|
-
- `y: number`
|
|
54
|
-
- `rotation: number`
|
|
55
|
-
- `state: S & { stage?: number; stageAt?: number }` State (stage is the current stage index, stageAt the time it was entered); change values with ent.set() so that events fire
|
|
56
|
-
- `object: Object3D | null` Root node (heading and interactions hang on it); null when there is no model far away, built the frame after spawn
|
|
57
|
-
- `visual: Object3D | null` Model (a child of the root node)
|
|
58
|
-
- `data: Record<string, any>` Extra data
|
|
59
|
-
- `stageName: string | null` Current stage name
|
|
60
|
-
- `set(key: string, value: any)` — Change one state value (emits the entity:state event)
|
|
61
|
-
- `remove() → boolean` — Delete this entity
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
# Changing the art / writing a style pack
|
|
2
|
-
|
|
3
|
-
**The engine ships no art.** No default style, character model, terrain look or terrain generator: with no style pack and no model everything is a
|
|
4
|
-
plain neutral placeholder (a gray capsule for characters, a gray box for props and pickups, flat gray ground at y = 0, one white hemisphere light plus
|
|
5
|
-
one neutral directional light without shadows or tone mapping), and the console says once in dev what is missing and how to fix it.
|
|
6
|
-
|
|
7
|
-
A style pack is a plain object passed in as `createEngine({ style })`. It holds **looks only**: colors, the default character / pickup shapes,
|
|
8
|
-
materials and shaders, sky and lighting, post effects, UI look. Not part of it: model / texture / sound files and procedural models content names (an
|
|
9
|
-
**asset pack**, `engine.assets.manifest`, recipe 05 "Asset packs"), sounds (section 5), gameplay data and timing (a **content pack**, recipe 20;
|
|
10
|
-
`sky({ hoursPerDay })`). Which key is read by whom is in the "style pack keys" table of `../CODEMAP.md`; the field list is in `../api/style.md`. Every
|
|
11
|
-
entry can be omitted; omitted entries are the neutral placeholders above (the city example passes no style pack at all). Write it as a plain object literal, no `@type` or `as const`: fields with a fixed set of words (`shading`, `mode`, `type` …) accept any string in the types, and a wrong word is reported by `threedog style check` with the fix.
|
|
12
|
-
|
|
13
|
-
## 0. Installing the lowpoly style pack
|
|
14
|
-
The low-poly look is an optional package, `@threedog/style-lowpoly` (source in the monorepo: `packages/styles/lowpoly/`):
|
|
15
|
-
```sh
|
|
16
|
-
npm install @threedog/style-lowpoly
|
|
17
|
-
```
|
|
18
|
-
```js
|
|
19
|
-
import { createEngine, presets, openWorld } from 'threedog';
|
|
20
|
-
import lowpoly from '@threedog/style-lowpoly';
|
|
21
|
-
import { terrainPreset, terrainStrings } from '@threedog/terrain-noise'; // the world shape is not a look: its own package
|
|
22
|
-
const engine = createEngine({ canvas, style: lowpoly, strings: terrainStrings }); // terrainStrings: names of the preset's ground types
|
|
23
|
-
engine.use(openWorld({ camera: 'follow', seed: 7, terrain: terrainPreset() })); // noise terrain (hills, rivers, biomes) that lowpoly colors, see recipes/28
|
|
24
|
-
```
|
|
25
|
-
Besides the style object it exports `assets` (an asset pack of procedural trees, rocks, grass, flowers: `engine.assets.manifest(assets)`; the same
|
|
26
|
-
generators as a plain map are `models`). Its `bloom` / `ao` / `outline` come from `@threedog/post-effects` (style packs never import each other; R34 checks). The terrain generator `terrainPreset` / `riverAt` / `BIOMES` /
|
|
27
|
-
`terrainStrings` is a separate package, `@threedog/terrain-noise`: the shape of the world is gameplay, so a style pack keeps only the colors of its
|
|
28
|
-
ground types (`terrain.colors`, `biomeColors`).
|
|
29
|
-
|
|
30
|
-
## 0b. Composing a style from parts
|
|
31
|
-
`style` may be a list of parts, deep-merged left to right into `engine.style`, so one pack's materials, another pack's sky and the game's own colors
|
|
32
|
-
mix without copying whole packs:
|
|
33
|
-
```js
|
|
34
|
-
import lowpoly from '@threedog/style-lowpoly';
|
|
35
|
-
const dusk = { sky: { sunSize: 600, keyframes: myDuskKeyframes } }; // only these two sky fields change
|
|
36
|
-
const engine = createEngine({ canvas, style: [lowpoly, dusk, { ui: { accent: '#7fd3ff' }, post: null }] });
|
|
37
|
-
```
|
|
38
|
-
Rules (`core/styleParts.js`): plain `{ }` objects merge key by key at every depth; everything else replaces whole (arrays such as `sky.keyframes` and
|
|
39
|
-
`post`, functions, three.js objects); a key set to `null` removes it; `undefined` is ignored; nested lists flatten, so a pack can itself be a list of
|
|
40
|
-
parts; parts are never mutated. One object (not a list) is used as it is.
|
|
41
|
-
|
|
42
|
-
**Post effects by name.** `post` is a list, so `{ post: [myGrain] }` replaces everything before it. To add to or trim the list use the two helpers
|
|
43
|
-
(exported by `threedog`); they are parts too:
|
|
44
|
-
```js
|
|
45
|
-
import { createEngine, postAdd, postRemove } from 'threedog';
|
|
46
|
-
import lowpoly from '@threedog/style-lowpoly';
|
|
47
|
-
import { bloom } from '@threedog/post-effects';
|
|
48
|
-
createEngine({ canvas, style: [lowpoly, postAdd(myGrain, bloom({ strength: 0.6 })), postRemove('ao')] });
|
|
49
|
-
```
|
|
50
|
-
`postAdd(...effects)` appends; an effect whose `name` is already in the list (`'bloom'`, `'ao'`, `'outline'`) replaces that one in place.
|
|
51
|
-
`postRemove(...names)` drops effects by name. `{ post: null }` still clears the list; `{ post: [...] }` still replaces it whole.
|
|
52
|
-
|
|
53
|
-
**Retinting the procedural models.** `style.palette` holds the colors the trees, rocks, grass and flowers are built from (lowpoly: `bark`, `pine`,
|
|
54
|
-
`pineLight`, `leaf`, `rock`, `grassBase`, `grassTip`, `bloom`...; the keys are in `lowpoly.palette`). One part changes them all:
|
|
55
|
-
`style: [lowpoly, { palette: { pine: 0xa07a2e, leaf: 0xd98a3a } }]` (autumn); keys left out keep the pack's colors. A generator of your own written
|
|
56
|
-
with `function` (not an arrow) reads `this.palette`; the palette is part of the model cache key, so a changed palette rebuilds. `.glb` files and
|
|
57
|
-
models baked earlier keep their colors.
|
|
58
|
-
|
|
59
|
-
## 0c. What a style may not hold
|
|
60
|
-
Swapping the style must never change the map or the rules, only how they look. So these are **not** style fields, and a dev run throws an error
|
|
61
|
-
naming where each goes:
|
|
62
|
-
- water level, whether there is a sea, the water mesh size: `style.water.level / sea / size` -> `engine.use(water({ level, sea, size }))`
|
|
63
|
-
- terrain shape and size (seed, chunk size, resolution, water level, height functions): `style.terrain.config.*` -> `terrain({ ... })`. The one
|
|
64
|
-
look in `terrain.config` is `shading: 'flat' | 'smooth'`
|
|
65
|
-
Quality settings are not world state and may stay in a style (shadow `mapSize` and `low` overrides, water `segments`); players can override them in
|
|
66
|
-
settings. Packs under `packages/styles/**` are also checked by `threedog check` (R34).
|
|
67
|
-
|
|
68
|
-
## 1. Creating a new style pack
|
|
69
|
-
Copy `packages/styles/lowpoly/` to your game (or a new package `@threedog/style-toon`), edit the values in `index.js`, then switch to it in the game:
|
|
70
|
-
```js
|
|
71
|
-
import toon from './style/index.js';
|
|
72
|
-
const engine = createEngine({ canvas, style: toon });
|
|
73
|
-
```
|
|
74
|
-
**A material role is a free label inside the style, not a fixed list.** `makeMaterial('anything', { color })` is always legal: a role the style does not
|
|
75
|
-
name falls back to `materials.default`, and a new role (`'lantern'`, `'roof'`) becomes real the moment the style adds `materials.lantern`. The engine
|
|
76
|
-
warns only when a name looks like a typo of a known role (`'buidling'`).
|
|
77
|
-
|
|
78
|
-
Keys you will change most often:
|
|
79
|
-
| Key | What it controls |
|
|
80
|
-
|---|---|
|
|
81
|
-
| `materials` | The material per role. Three forms: a spec `{ default: { type: 'toon', steps: 3 }, water: { type: 'phong', shininess: 90 } }` (lambert / phong / standard / physical / toon / basic; a wrong type throws), any three.js material instance `water: new THREE.MeshMatcapMaterial({ matcap })` (cloned per use), or a function `prop: (params, role) => new THREE.ShaderMaterial({...})`. Style packs may create materials directly; games still go through `makeMaterial` |
|
|
82
|
-
| `antialias` | `false` for sharp pixel edges; omitted = on for desktop, off for phones (players can switch it in settings) |
|
|
83
|
-
| `post` | List of post effects, see 2c (lowpoly: `[outline(), ao(), bloom()]`; `outline({ enabled: true })` for a cartoon look) |
|
|
84
|
-
| `sky` `weather` `water` `terrain` `seasons` `clouds` | Sky keyframes (sun color and intensity over the day, fog color, shadows), rain and snow, water, terrain colors (`terrain.colors` palette, `terrain.biomeColors` ground type -> palette names, `terrain.steep` slope colors; a type with no color is gray; `terrain.config.shading: 'flat'` for facets (the only `terrain.config` key; engine default smooth); `terrain.material` swaps the whole ground material, chunks have `uv` = world xz / chunk size; `water.material: (engine, { uniforms, waves, normalMap }) => Material` swaps the whole water surface, e.g. `applyEffects(new THREE.MeshToonMaterial({ color }), { clouds: false, patches: [waves] })` keeps the built-in waves), seasonal tints |
|
|
85
|
-
| `character` | Default character colors `colors`; `create(engine, colors)` builds the procedural character (lowpoly: its `shapes.js`; without it a gray capsule); `model` a registered model every character uses |
|
|
86
|
-
| `pickup` `particles` | Items on the ground (`pickup.model(item, { color, size })` returns an Object3D or geometry; without it a plain gray box), particle presets (dust smoke leaves splash sparks...) |
|
|
87
|
-
| `triggers` `grid` | Tool colors, not art: trigger zone wireframe (`debugColor`), grid placement preview (`ok` / `bad`). The engine has neutral defaults (gray; light = can place, dark = cannot); a pack may recolor them |
|
|
88
|
-
| `ui` | UI colors, `font` (a CSS font-family list), `fonts` (font asset names to load at start, the files in an asset pack: recipes/05 §3b), extra `css`, `templates` that replace a whole UI piece |
|
|
89
|
-
|
|
90
|
-
Lights: every engine has `engine.lights = { sun, hemi }`, plain three.js lights. Without a style pack they are a neutral placeholder (white
|
|
91
|
-
hemisphere + neutral directional light, no shadows); the look (sun color and intensity curves, sky colors, fog, shadow softness, exposure, tone
|
|
92
|
-
mapping) comes from the style pack's `sky`, `exposure` and `toneMapping`, and the sky module drives the same two lights. For your own lighting hide or
|
|
93
|
-
retune them and add three.js lights.
|
|
94
|
-
|
|
95
|
-
**Lights and stalls.** three.js builds one shader program per material for each light setup. `engine.start()` compiles everything visible behind the
|
|
96
|
-
loading screen (`engine.startup.compileMs`), but adding or removing a light later, or toggling `visible` on one, changes the setup and compiles again:
|
|
97
|
-
a frame can freeze for hundreds of milliseconds. Keep the number of lights fixed: create them up front and fade with `intensity` (0 = off, no
|
|
98
|
-
recompile). In dev the console warns (code `light-recompile`) when programs were compiled in a frame where the lights changed.
|
|
99
|
-
|
|
100
|
-
For many torches, street lamps, campfires, muzzle flashes or neon signs use the light pool: a fixed number of real lights, created once at install,
|
|
101
|
-
moves to the sources that matter most (near the camera, bright, high `priority`) and fades with intensity, so the light setup never changes. Install
|
|
102
|
-
it before `engine.start()` so the startup compile covers its lights:
|
|
103
|
-
```js
|
|
104
|
-
import { lightPool } from 'threedog';
|
|
105
|
-
engine.use(lightPool({ point: 8 })); // 8 PointLights; lightPool({ spot: 2, shadows: 1 }) adds spots / lets one point light cast
|
|
106
|
-
for (const t of torches) engine.lightPool.add(t, { // an Object3D is followed; a position stays put
|
|
107
|
-
color: 0xffa040, intensity: 4, distance: 8,
|
|
108
|
-
flicker: (time, i) => 0.85 + 0.15 * Math.sin(time * 13 + i),
|
|
109
|
-
glow: t.getObjectByName('halo'), // stand-in while it has no real light: its material's opacity / emissiveIntensity fades to 0 as the light fades in
|
|
110
|
-
});
|
|
111
|
-
const flash = engine.lightPool.add(gun.muzzle, { intensity: 0, priority: 5, distance: 6 });
|
|
112
|
-
flash.set({ intensity: 8 }); /* next frame */ flash.set({ intensity: 0 }); // muzzle flash: no light is created
|
|
113
|
-
```
|
|
114
|
-
`engine.lightPool.usage()` (and `describe().lightPool`) lists which source each real light holds; `focus` measures from the player instead of the
|
|
115
|
-
camera. Options and handle: `../api/lightPool.md`.
|
|
116
|
-
|
|
117
|
-
## 2. Using your own models instead of procedural ones
|
|
118
|
-
Models are assets, not style keys: content names them, an asset pack maps the names to files or generators. Register a later manifest with the same
|
|
119
|
-
name to swap one:
|
|
120
|
-
```js
|
|
121
|
-
engine.assets.manifest(lowpolyAssets); // import { assets as lowpolyAssets } from '@threedog/style-lowpoly': pine, rock, flower... built in code
|
|
122
|
-
engine.assets.manifest({ name: 'mine', models: { pine: () => myPineGeometry(), well: '/models/well.glb' } }); // replaces pine, adds well
|
|
123
|
-
```
|
|
124
|
-
Vegetation takes a geometry (`geometry: await engine.assets.geometry('pine')`, the first mesh in the model) or a whole model with one material per
|
|
125
|
-
mesh, e.g. bark trunk + alpha-cut leaf cards:
|
|
126
|
-
`engine.vegetation.add('oak', { model: await engine.assets.model('oak'), wind: 0.02 })` (still one draw call per part; felling hides every part). For
|
|
127
|
-
the import workflow see `10-blender-level.md`.
|
|
128
|
-
`mergeColored(parts, { flat: false })` keeps smooth normals; UVs survive when every part has them.
|
|
129
|
-
A generator in `models` may also return an Object3D with its own materials; those are used as they are.
|
|
130
|
-
|
|
131
|
-
## 2b. Wind, cloud shadows and season tint on your own materials
|
|
132
|
-
The engine's shader effects are named patches that work on any material that has the usual three.js chunks (WebGL only):
|
|
133
|
-
```js
|
|
134
|
-
import { applyEffects } from 'threedog';
|
|
135
|
-
const leaves = applyEffects(new THREE.MeshToonMaterial({ color: 0x5a8a3a }), { wind: 0.03, season: 'foliage' }); // clouds default on
|
|
136
|
-
engine.vegetation.add('bush', { geometry, material: leaves }); // vegetation adds them itself; effects: false keeps the material untouched
|
|
137
|
-
```
|
|
138
|
-
The shadow sways with the wind automatically. Your own effect (pixel snapping, dissolve...) is a patch too, and stacks with the built-in ones and with
|
|
139
|
-
the material's own `onBeforeCompile`:
|
|
140
|
-
`applyEffects(mat, { patches:
|
|
141
|
-
[{ name: 'snap', cacheKey: 64, uniforms, glsl: { vertex: { pars: '...', project_vertex: '...code after #include <project_vertex>' } } }] })`.
|
|
142
|
-
A missing `#include` anchor throws. A hand-written `ShaderMaterial` can `#include <threedog_wind_vertex>`, `<threedog_clouds_pars_fragment>` etc. (see
|
|
143
|
-
`render/effects.js`) with `engine.uniforms` as its uniforms.
|
|
144
|
-
`material.clone()` does not carry patches (three's `Material.copy` skips `onBeforeCompile`): a pack's Material instance in `materials` is fine
|
|
145
|
-
(`makeMaterial` keeps its patches); when you clone one yourself, apply the effects to the clone again.
|
|
146
|
-
|
|
147
|
-
Patches on one material must agree. Each patch declares what it relies on, and a bad combination throws when it is added (or logs once at compile):
|
|
148
|
-
| Field | Meaning | Checked |
|
|
149
|
-
|---|---|---|
|
|
150
|
-
| `needs.data` | Program inputs the code reads: `'instancing'`, `'instancingColor'`, `'vertexColors'`, `'skinning'`, `'batching'` | when the program compiles (console.error once per material) |
|
|
151
|
-
| `needs.patches` | Patches it builds on, e.g. `['world']` for the `vThreedogWorld` varying (world position; `applyEffects` adds `world` itself when a patch needs it) | when added |
|
|
152
|
-
| `conflicts` | Patch names it cannot share a material with | when added, both ways |
|
|
153
|
-
| `uniforms` | A uniform name belongs to one patch; share `engine.uniforms` (`uTime`, `uWind`, `uCloud`...) instead of making your own `uTime` | when added |
|
|
154
|
-
| `shadow` | Render steps: without it the color pass only; `true` also runs its vertex code in the depth (sun / spot shadows) and distance (point-light shadows) passes | - |
|
|
155
|
-
| `cacheKey` | Changes whenever the GLSL text changes (defines, branches), never for uniform values; the program key joins every patch's `name=cacheKey` in order | same name + cacheKey with different code throws |
|
|
156
|
-
```js
|
|
157
|
-
applyEffects(mat, { wind: 0.03, season: 'foliage', patches: [{ name: 'ripple', needs: { patches: ['world'] }, conflicts: ['wind'],
|
|
158
|
-
glsl: { fragment: { color_fragment: 'diffuseColor.rgb *= 0.9 + 0.1 * sin(vThreedogWorld.x);' } } }] }); // throws: 'wind' and 'ripple' cannot be combined
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
## 2c. Post effects (slots)
|
|
162
|
-
Post-processing is an ordered list of named effects. Each runs in a slot, then by `order` (low first):
|
|
163
|
-
`scene` (replaces the scene render, one at a time, e.g. pixelation) -> `hdr` (linear color: outline, AO, bloom) -> tone mapping -> `ldr` (sRGB: LUT,
|
|
164
|
-
palette, grain, vignette) -> `final` (FXAA / SMAA).
|
|
165
|
-
An effect is `{ name, slot, order, params, create(ctx) => pass, update?(pass, params) }`; under WebGL the pass is any three.js postprocessing Pass. It
|
|
166
|
-
is built the first time it is on.
|
|
167
|
-
```js
|
|
168
|
-
import { bloom, outline } from '@threedog/post-effects'; // never from another style pack: packs do not depend on each other
|
|
169
|
-
import { LUTPass } from 'three/addons/postprocessing/LUTPass.js';
|
|
170
|
-
const toon = { name: 'toon', post: [outline({ enabled: true, thickness: 1.5 }), bloom({ strength: 0.2 }),
|
|
171
|
-
{ name: 'lut', slot: 'ldr', params: { lut: myLut }, create: ({ params }) => new LUTPass({ lut: params.lut }) }] };
|
|
172
|
-
// at runtime (settings, photo mode, a game's own effect):
|
|
173
|
-
engine.look.post.set({ 'bloom.strength': 0.6 });
|
|
174
|
-
engine.look.post.set({ 'outline.enabled': false }); // MSAA: engine.post.setAntialias(false)
|
|
175
|
-
engine.look.post.patch('vignette', { glsl: 'color.rgb *= 0.9;', slot: 'ldr', order: 10 }); // patch('vignette', null) removes it
|
|
176
|
-
```
|
|
177
|
-
An effect that reads scene depth (`needsDepth: true`, e.g. `outline`) must run before any pass that swaps buffers (a `ShaderPass`, a scene-slot
|
|
178
|
-
`RenderPixelatedPass`, the tone-mapping output): only the buffer the scene render wrote holds scene depth. A chain that breaks this throws when the
|
|
179
|
-
effect is added or enabled, naming both effects; give the depth reader a lower `order`. `dof` copies the scene depth into its own output
|
|
180
|
-
(`pass.keepsDepth = true`, no extra pass), so `dof` and `outline` can both be on as long as `dof` has the lower `order` (default: dof 5, outline 10;
|
|
181
|
-
lines stay sharp over the blur). `threedog style check` reports the other order as an error.
|
|
182
|
-
`createEngine({ post: { bloom: false } })` overrides an effect's startup on/off; `costly: true` effects start off on low-tier devices. MSAA
|
|
183
|
-
(`antialias`) works with every effect on.
|
|
184
|
-
The settings menu shows `bloom` / `ao` toggles only when the style pack registers effects with those names.
|
|
185
|
-
|
|
186
|
-
### Optional post effects package and `fuse`
|
|
187
|
-
The engine ships no effects; `@threedog/post-effects` (install it like `@threedog/terrain-noise`, import only what you use) has `bloom`, `ao`,
|
|
188
|
-
`outline`, `dof` (all `hdr`; outline and dof read depth) and `lut` (contrast / saturation / warm-cool / optional 3D LUT), `grain`, `vignette`,
|
|
189
|
-
`chromatic` (`ldr`). A style pack lists the ones it wants in its own `post`. `lut`, `grain`, `vignette`, `chromatic`, `dof`, `ao` and `outline` are off
|
|
190
|
-
until `enabled: true`.
|
|
191
|
-
```js
|
|
192
|
-
import { vignette, grain, lut } from '@threedog/post-effects';
|
|
193
|
-
createEngine({ canvas, style: [lowpoly, postAdd(lut({ saturation: 1.1, temperature: 0.15 }), vignette(), grain({ amount: 0.04 }))] });
|
|
194
|
-
engine.look.post.set({ 'vignette.enabled': true }); // photo mode, settings...
|
|
195
|
-
engine.look.post.set({ 'grain.amount': 0.1 }); // updates in place
|
|
196
|
-
```
|
|
197
|
-
`fuse` is how a light color effect avoids a fullscreen pass of its own: instead of `create()` it carries a GLSL snippet
|
|
198
|
-
`fuse: { uniforms: { uMyAmount: 'float' }, values: p => ({ uMyAmount: p.amount }), glsl: 'color.rgb *= 1.0 - uMyAmount * length(vUv - 0.5);' }`.
|
|
199
|
-
Effects with a `fuse` that are on and next to each other in one slot (never `scene`) are compiled into ONE shader and drawn in one pass, in
|
|
200
|
-
`order`; turning one off, `set()` or `remove()` recompiles or just updates the uniforms. The snippet edits `vec4 color` and may use `vUv`,
|
|
201
|
-
`tDiffuse`, `uTime`, `uResolution`, `fxHash(vec2)`; uniform names are shared by the whole group, so prefix them with the effect name. A snippet that
|
|
202
|
-
samples `tDiffuse` at other positions (blur, color fringe) sets `reads: true` and then starts a new group. Four ldr effects: 1 pass instead of 4.
|
|
203
|
-
Effects without `fuse` (bloom, outline, `dof`...) stay one pass each.
|
|
204
|
-
|
|
205
|
-
### Outline modes
|
|
206
|
-
`outline({ mode: 'depth' | 'normal' | 'both' })`: `depth` (default, silhouettes), `normal` (creases; the scene is drawn once more with normals, so
|
|
207
|
-
it is `costly` and off on low-tier devices), `both`. `fadeWithDistance: false` keeps lines at any distance; `wobble: 1.5` jitters the lines by up to 1.5
|
|
208
|
-
pixels at 8 steps a second (hand-drawn). To exempt objects: `outline({ offLayer: OUTLINE_OFF_LAYER })` and `mesh.layers.enable(OUTLINE_OFF_LAYER)`
|
|
209
|
-
(three.js layers; layer 0 stays on, so the object still renders normally; costs one extra render of just the exempt objects, nothing when
|
|
210
|
-
`offLayer` is `null`). Normal mode draws the scene with a plain override material, so wind-animated foliage lines up with its static shape.
|
|
211
|
-
|
|
212
|
-
Textures by asset name, grain / paper / strokes (`detail`), shadow tint, rim light, toon ramps and the GLSL exits are all spec keys: recipe 37.
|
|
213
|
-
|
|
214
|
-
## 3. When the engine gets a new "look parameter"
|
|
215
|
-
Hard rule 1: a module only writes a neutral gray fallback and reads `engine.style.xxx ?? fallback`, **and the real value is added to the lowpoly pack
|
|
216
|
-
(its `index.js`) at the same time** (with a one-line comment saying what it means),
|
|
217
|
-
and the new field gets a doc comment in `types/style.d.ts` (`docs/api/` is generated from there). Materials always go through
|
|
218
|
-
`makeMaterial('role', { color })`, leaving the surface feel to `style.materials[role]`. Whose style: `engine.makeMaterial('role', { color })` uses that
|
|
219
|
-
engine's pack; the free `makeMaterial()` uses the first engine created (fine for one engine, a dev warning when two packs run). Engine code and style packs always
|
|
220
|
-
go through the engine (`create(engine, colors)`, `pickup.model(item, { color, size }, engine)`, `water.material(engine, ...)`), so two engines never share materials.
|
|
221
|
-
Look parameters only: a field that changes the world (a level, a size, a seed) goes to the module's options, not the style (section 0c).
|
|
222
|
-
|
|
223
|
-
## 4. Verify
|
|
224
|
-
- `npm run check`: the hard-rule check reports "material created directly" (in engine modules, games and examples; style packs are allowed) and
|
|
225
|
-
"non-gray fallback color"; the type check catches misspelled keys in the style pack.
|
|
226
|
-
- `npm run map`: the "style pack keys" table in CODEMAP is updated.
|
|
227
|
-
- Take screenshots only when the look changed, and compare two times of day: `npm run shot -- / --time 12:00`, `npm run shot -- / --time 18:30`
|
|
228
|
-
(images go to .threedog/shots/).
|
|
229
|
-
- It must still run without a style pack: `npm test -- 小城`.
|
|
230
|
-
|
|
231
|
-
## 5. Sounds and music (the game's, not the style pack's)
|
|
232
|
-
Sounds are game config, passed to `createEngine({ audio: { sounds, ambience, music, footsteps, levels } })` and read back as `engine.audio.config`; a
|
|
233
|
-
style pack carries none. The engine plays nothing the game did not name. Buses, sounds by name, the ambience rule table, music rules, footsteps and
|
|
234
|
-
ducking: `recipes/31-audio.md`.
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// What the style workbench exports: the values the user changed, as a plain object literal to paste into `style: [lowpoly, { ... }]`.
|
|
2
|
-
// Pure functions (no DOM, no engine) so a test can run them on their own.
|
|
3
|
-
|
|
4
|
-
/** Set a value at a path of keys inside a nested plain object, creating the objects on the way */
|
|
5
|
-
export function putAt(obj, path, value) {
|
|
6
|
-
let o = obj;
|
|
7
|
-
for (const k of path.slice(0, -1)) o = o[k] ??= {};
|
|
8
|
-
o[path.at(-1)] = value;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** '#rrggbb' <-> 0xrrggbb (the pack's color form); other strings (rgba(...)) pass through */
|
|
12
|
-
export const hexOf = n => '#' + n.toString(16).padStart(6, '0');
|
|
13
|
-
export const numOf = s => (/^#[0-9a-f]{6}$/i.test(s) ? parseInt(s.slice(1), 16) : s);
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Object literal source of the changes. A number under a key listed in `colors` (dotted paths such as 'palette.pine') prints as 0xrrggbb,
|
|
17
|
-
* other numbers as they are rounded to 3 decimals, strings quoted.
|
|
18
|
-
* @param {Record<string, any>} obj @param {Set<string>} [colors] @param {string} [prefix] @param {number} [depth]
|
|
19
|
-
*/
|
|
20
|
-
export function literal(obj, colors = new Set(), prefix = '', depth = 0) {
|
|
21
|
-
const pad = ' '.repeat(depth + 1), keys = Object.keys(obj);
|
|
22
|
-
if (!keys.length) return '{}';
|
|
23
|
-
const rows = keys.map(k => {
|
|
24
|
-
const v = obj[k], path = prefix ? `${prefix}.${k}` : k, name = /^[A-Za-z_$][\w$]*$/.test(k) ? k : JSON.stringify(k);
|
|
25
|
-
let src;
|
|
26
|
-
if (v === null) src = 'null';
|
|
27
|
-
else if (typeof v === 'object') src = literal(v, colors, path, depth + 1);
|
|
28
|
-
else if (typeof v === 'number') src = colors.has(path) ? '0x' + v.toString(16).padStart(6, '0') : String(+v.toFixed(3));
|
|
29
|
-
else src = JSON.stringify(v);
|
|
30
|
-
return `${pad}${name}: ${src},`;
|
|
31
|
-
});
|
|
32
|
-
return `{\n${rows.join('\n')}\n${' '.repeat(depth)}}`;
|
|
33
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
// Style workbench (?panel=1): sliders and color pickers over the running style test, plus an export of what changed.
|
|
2
|
-
// Tweakpane is a dev tool, not an engine dependency: it is a devDependency of the repo and found at build time by the glob below.
|
|
3
|
-
// If it is not installed the page says so and runs on without the panel.
|
|
4
|
-
//
|
|
5
|
-
// Two kinds of values, never mixed up in the panel:
|
|
6
|
-
// live the engine has an API that changes it while running: renderer exposure, sky time, environment lighting, water color, fog,
|
|
7
|
-
// post effects, UI colors (CSS variables). The picture changes at once.
|
|
8
|
-
// rebuild values read once at startup (the procedural models' palette, terrain colors, wave shape). The panel keeps them and
|
|
9
|
-
// "apply and rebuild" reloads the page with them as an extra style part (?ov=...). The picture does NOT change until then.
|
|
10
|
-
// The exported object holds style fields only (what `style: [lowpoly, {...}]` accepts); the running engine.style and the pack are never written.
|
|
11
|
-
import { putAt, hexOf, numOf, literal } from './overrides.js';
|
|
12
|
-
|
|
13
|
-
// @ts-ignore Vite's import.meta.glob (not in ImportMeta outside Vite); empty when the package is not installed
|
|
14
|
-
const loaders = import.meta.glob('../../../../node_modules/tweakpane/dist/tweakpane.js');
|
|
15
|
-
const UI_KEYS = ['bg', 'fg', 'muted', 'accent', 'good', 'line'];
|
|
16
|
-
const LIVE = 'live', REBUILD = ' [needs rebuild]';
|
|
17
|
-
const HOW = 'Run `npm install` in the repository root (tweakpane is a devDependency), then reload. 风格工作台需要 tweakpane:先运行 npm install。';
|
|
18
|
-
|
|
19
|
-
/** Show why there is no panel, in the page (not only the console) */
|
|
20
|
-
function note(text) {
|
|
21
|
-
const el = document.getElementById('panel-note');
|
|
22
|
-
if (el) { el.textContent = text; el.hidden = false; }
|
|
23
|
-
console.warn('styletest panel: ' + text);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @param {any} engine
|
|
28
|
-
* @param {Record<string, any> | null} base overrides already in the URL (?ov=), kept and extended
|
|
29
|
-
* @returns {Promise<boolean>} whether the panel is open
|
|
30
|
-
*/
|
|
31
|
-
export async function openPanel(engine, base) {
|
|
32
|
-
const load = Object.values(loaders)[0];
|
|
33
|
-
if (!load) { note('Style workbench needs the dev package "tweakpane", which is not installed. ' + HOW); return false; }
|
|
34
|
-
/** @type {any} */ let Pane;
|
|
35
|
-
try { ({ Pane } = await load()); } catch (e) { note(`Style workbench could not load tweakpane (${String(e).slice(0, 100)}). ` + HOW); return false; }
|
|
36
|
-
const changes = structuredClone(base ?? {}), colors = new Set();
|
|
37
|
-
const notes = new Map(); // post effect -> changed params (an effect list cannot be written as a style literal)
|
|
38
|
-
const put = (path, v, isColor = false) => { putAt(changes, path, v); if (isColor) colors.add(path.join('.')); };
|
|
39
|
-
const host = document.createElement('div');
|
|
40
|
-
host.style.cssText = 'position:fixed;top:8px;right:8px;width:310px;max-height:calc(100vh - 16px);overflow:auto;z-index:1000';
|
|
41
|
-
document.body.appendChild(host);
|
|
42
|
-
const pane = new Pane({ title: 'Style workbench', container: host });
|
|
43
|
-
|
|
44
|
-
// ---- live: exposure, sky time, light multipliers (preview aids: not style fields, never exported) ----
|
|
45
|
-
const sky = pane.addFolder({ title: `Light (${LIVE})` });
|
|
46
|
-
const light = { exposure: engine.renderer.toneMappingExposure, time: engine.sky.timeOfDay * 24, sun: 1, ambient: 1, fog: 1 };
|
|
47
|
-
sky.addBinding(light, 'exposure', { min: 0.2, max: 3, step: 0.01, label: '曝光 exposure' })
|
|
48
|
-
.on('change', e => { engine.renderer.toneMappingExposure = e.value; put(['exposure'], e.value); });
|
|
49
|
-
sky.addBinding(light, 'time', { min: 0, max: 24, step: 0.1, label: '天空时间 hour (preview)' })
|
|
50
|
-
.on('change', e => { engine.sky.timeOfDay = e.value / 24 % 1; });
|
|
51
|
-
const layer = () => engine.sky.modify('workbench', { sun: light.sun, ambient: light.ambient, fog: light.fog });
|
|
52
|
-
for (const [k, label] of [['sun', '阳光倍率 sun x (preview)'], ['ambient', '环境光倍率 ambient x (preview)'], ['fog', '雾距离倍率 fog x (preview)']]) {
|
|
53
|
-
sky.addBinding(light, k, { min: 0.1, max: 3, step: 0.05, label }).on('change', layer);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// ---- live: environment lighting ----
|
|
57
|
-
const envState = { on: !!engine.sky.environment, intensity: engine.sky.environment?.intensity ?? 0.8 };
|
|
58
|
-
const env = pane.addFolder({ title: `环境照明 (${LIVE})` });
|
|
59
|
-
const applyEnv = () => {
|
|
60
|
-
const on = envState.on, opts = { source: 'sky', intensity: envState.intensity };
|
|
61
|
-
(on ? (engine.look.env.replace('sky'), engine.look.env.set({ intensity: opts.intensity })) : engine.look.env.replace(false));
|
|
62
|
-
put(['sky', 'environment'], on ? opts : null);
|
|
63
|
-
};
|
|
64
|
-
env.addBinding(envState, 'on', { label: '开 on' }).on('change', applyEnv);
|
|
65
|
-
env.addBinding(envState, 'intensity', { min: 0, max: 2, step: 0.05, label: '强度 intensity' }).on('change', () => { if (envState.on) applyEnv(); });
|
|
66
|
-
|
|
67
|
-
// ---- live: water color (the shared water material) ----
|
|
68
|
-
const wm = engine.water?.material;
|
|
69
|
-
if (wm?.color) {
|
|
70
|
-
const water = { color: hexOf(wm.color.getHex()) };
|
|
71
|
-
pane.addFolder({ title: `水 (${LIVE})` }).addBinding(water, 'color', { label: '颜色 color' })
|
|
72
|
-
.on('change', e => { wm.color.set(e.value); put(['water', 'color'], numOf(e.value), true); });
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// ---- live: post effects, from engine.post.list() / get() / set() ----
|
|
76
|
-
const post = pane.addFolder({ title: `后期 post (${LIVE})`, expanded: false });
|
|
77
|
-
for (const { name, enabled } of engine.post.list()) {
|
|
78
|
-
const h = engine.post.get(name), f = post.addFolder({ title: name, expanded: false });
|
|
79
|
-
const noteOf = () => notes.get(name) ?? notes.set(name, {}).get(name);
|
|
80
|
-
f.addBinding({ enabled }, 'enabled', { label: '开 on' }).on('change', e => { engine.look.post.set({ [name + '.enabled']: e.value }); noteOf().enabled = e.value; });
|
|
81
|
-
for (const [k, v] of Object.entries(h.params)) {
|
|
82
|
-
if (typeof v !== 'number' && typeof v !== 'boolean') continue; // lut textures, functions...: not editable here
|
|
83
|
-
const range = typeof v === 'number' ? { step: Math.abs(v) >= 10 ? 1 : 0.01, min: Math.min(0, v * 2), max: Math.max(1, v * 3) } : {};
|
|
84
|
-
f.addBinding({ [k]: v }, k, range).on('change', e => { engine.look.post.set({ [name + '.' + k]: e.value }); noteOf()[k] = e.value; });
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// ---- live: UI colors, CSS variables on engine.uiRoot ----
|
|
89
|
-
const css = getComputedStyle(engine.uiRoot), uiVals = {};
|
|
90
|
-
for (const k of UI_KEYS) { const v = css.getPropertyValue('--threedog-' + k).trim(); if (v) uiVals[k] = v; }
|
|
91
|
-
const ui = pane.addFolder({ title: `界面颜色 ui (${LIVE})`, expanded: false });
|
|
92
|
-
for (const k of Object.keys(uiVals)) ui.addBinding(uiVals, k).on('change', e => { engine.uiRoot.style.setProperty('--threedog-' + k, e.value); put(['ui', k], e.value); });
|
|
93
|
-
|
|
94
|
-
// ---- rebuild: values the engine reads at startup ----
|
|
95
|
-
const rb = pane.addFolder({ title: 'Needs rebuild (press "apply and rebuild")', expanded: false });
|
|
96
|
-
const style = engine.style ?? {};
|
|
97
|
-
for (const [path, src, title] of [['palette', style.palette, '材质用途/模型色 palette'], ['terrain.colors', style.terrain?.colors, '地形色 terrain.colors']]) {
|
|
98
|
-
if (!src) continue;
|
|
99
|
-
const f = rb.addFolder({ title: title + REBUILD, expanded: false }), vals = {};
|
|
100
|
-
for (const [k, v] of Object.entries(src)) if (typeof v === 'number') vals[k] = hexOf(v);
|
|
101
|
-
for (const k of Object.keys(vals)) f.addBinding(vals, k).on('change', e => put([...path.split('.'), k], numOf(e.value), true));
|
|
102
|
-
}
|
|
103
|
-
if (style.water) {
|
|
104
|
-
const f = rb.addFolder({ title: '水波 water' + REBUILD, expanded: false }), vals = {};
|
|
105
|
-
for (const k of ['waveHeight', 'waveScale', 'waveSpeed', 'fresnel']) if (typeof style.water[k] === 'number') vals[k] = style.water[k];
|
|
106
|
-
for (const k of Object.keys(vals)) f.addBinding(vals, k, { step: 0.01 }).on('change', e => put(['water', k], e.value));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// ---- export / rebuild ----
|
|
110
|
-
const out = { text: '' };
|
|
111
|
-
const exportText = () => {
|
|
112
|
-
let s = `// paste into createEngine({ style: [lowpoly, { ... }] }):\n${literal(changes, colors)}`;
|
|
113
|
-
const posts = [...notes].filter(([, v]) => Object.keys(v).length);
|
|
114
|
-
if (posts.length) {
|
|
115
|
-
s += '\n// post effects are a list, not a literal: call the factory again with these (postAdd(bloom({ strength: 0.6 }))):\n';
|
|
116
|
-
s += posts.map(([n, v]) => `// ${n}: ${JSON.stringify(v)}`).join('\n');
|
|
117
|
-
}
|
|
118
|
-
return s;
|
|
119
|
-
};
|
|
120
|
-
const ex = pane.addFolder({ title: '导出 / 重建' });
|
|
121
|
-
const mon = ex.addBinding(out, 'text', { readonly: true, multiline: true, rows: 8, label: '' });
|
|
122
|
-
const show = () => { out.text = exportText(); mon.refresh(); return out.text; };
|
|
123
|
-
ex.addButton({ title: '导出覆盖配置 export overrides' }).on('click', () => { navigator.clipboard?.writeText(show()).catch(() => {}); });
|
|
124
|
-
const reload = ov => {
|
|
125
|
-
const u = new URL(location.href);
|
|
126
|
-
if (ov) u.searchParams.set('ov', JSON.stringify(ov)); else u.searchParams.delete('ov');
|
|
127
|
-
location.href = u.href;
|
|
128
|
-
};
|
|
129
|
-
ex.addButton({ title: '应用并重建预览 apply and rebuild' }).on('click', () => reload(changes));
|
|
130
|
-
ex.addButton({ title: '清除覆盖 clear overrides' }).on('click', () => reload(null));
|
|
131
|
-
|
|
132
|
-
engine.describe.add('stylePanel', () => ({ open: true, changes: JSON.parse(JSON.stringify(changes)) }));
|
|
133
|
-
/** @type {any} */ (engine).styleWorkbench = { pane, export: show, changes }; // for tests and the dev bridge
|
|
134
|
-
return true;
|
|
135
|
-
}
|