threedog 0.2.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +290 -0
- package/README.md +9 -8
- package/core/Animator.js +15 -12
- package/core/Assets.js +83 -16
- package/core/Audio.js +45 -38
- package/core/Baked.js +32 -8
- package/core/Batching.js +102 -15
- package/core/Budget.js +39 -18
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +45 -10
- package/core/Describe.js +104 -43
- package/core/Engine.js +190 -57
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +168 -79
- package/core/Inspect.js +2 -2
- package/core/InspectMaterials.js +85 -0
- package/core/InspectPerf.js +61 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +5 -5
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +14 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +25 -9
- package/core/Views.js +9 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +22 -5
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +38 -11
- package/core/assetManifest.js +48 -9
- package/core/assetReport.js +1 -1
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +5 -2
- package/core/cells.js +62 -0
- package/core/checks.js +10 -8
- package/core/chunkStream.js +87 -0
- package/core/control.js +149 -0
- package/core/copies.js +32 -0
- package/core/dayTime.js +12 -6
- package/core/debugView.js +82 -15
- package/core/describeRender.js +43 -17
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +438 -19
- package/core/errorHints.js +37 -141
- package/core/errors.js +31 -8
- package/core/events.generated.js +12 -7
- package/core/gameLights.js +62 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +128 -0
- package/core/gridLoad.js +20 -0
- package/core/ground.js +6 -4
- package/core/headlessLoad.js +55 -0
- package/core/holds.js +78 -50
- package/core/inputContext.js +11 -7
- package/core/inputDefaults.js +24 -21
- package/core/inputPad.js +1 -1
- package/core/inputPointer.js +1 -1
- package/core/inputTouch.js +2 -2
- package/core/lifecycle.js +48 -12
- package/core/lightWatch.js +6 -4
- package/core/look/coreParts.js +137 -30
- package/core/look/part.js +175 -95
- package/core/look/points.js +255 -0
- package/core/look/report.js +34 -17
- package/core/look/shadowPart.js +63 -0
- package/core/look/state.js +45 -0
- package/core/look/write.js +12 -28
- package/core/loop.js +101 -37
- package/core/math.js +11 -3
- package/core/moduleSlots.js +75 -0
- package/core/moduleTypes.js +73 -0
- package/core/modules.js +145 -27
- package/core/movement.js +2 -2
- package/core/namedModel.js +70 -0
- package/core/opsCheck.js +3 -3
- package/core/opsFail.js +15 -6
- package/core/opsGuard.js +4 -4
- package/core/opsRun.js +4 -3
- package/core/owned.js +168 -0
- package/core/page.js +2 -1
- package/core/params.js +30 -8
- package/core/plugins.js +277 -0
- package/core/saveApply.js +99 -17
- package/core/saveFiles.js +8 -6
- package/core/saveValues.js +46 -0
- package/core/saveVersions.js +20 -3
- package/core/scatter.js +48 -19
- package/core/sceneDelta.js +203 -0
- package/core/sceneMethods.js +35 -30
- package/core/screenToGround.js +1 -1
- package/core/services.js +27 -11
- package/core/session.js +28 -25
- package/core/shaderCost.js +78 -0
- package/core/shadowTypes.js +2 -1
- package/core/sharedPoint.js +317 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +34 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -11
- package/core/streamSources.js +0 -11
- package/core/styleParts.js +65 -47
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +2 -2
- package/core/thingOps.js +29 -6
- package/core/things.js +21 -11
- package/core/threadPure.js +7 -3
- package/core/threePatches.js +47 -0
- package/core/tier.js +21 -10
- package/core/time.js +236 -0
- package/core/uiClock.js +25 -0
- package/core/util.js +7 -1
- package/core/validate.js +65 -86
- package/core/wrap.js +106 -0
- package/docs/AI.md +89 -97
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +224 -149
- package/docs/COMMANDS.md +57 -34
- package/docs/CONVENTIONS.md +92 -30
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +228 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +79 -27
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +12 -9
- package/docs/api/audio.md +10 -14
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -25
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +9 -6
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +65 -62
- package/docs/api/events.md +19 -14
- package/docs/api/grids.md +3 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +11 -6
- package/docs/api/interactions.md +7 -5
- package/docs/api/inventory.md +17 -16
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +15 -0
- package/docs/api/post.md +5 -4
- package/docs/api/quests.md +2 -3
- package/docs/api/rigid.md +16 -14
- package/docs/api/saves.md +6 -4
- package/docs/api/settings.md +2 -3
- package/docs/api/sky.md +11 -44
- package/docs/api/stream.md +1 -1
- package/docs/api/style.md +31 -29
- package/docs/api/terrain.md +9 -6
- package/docs/api/terrainLook.md +10 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +30 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +12 -8
- package/docs/api/vegetationLook.md +10 -0
- package/docs/api/water.md +4 -20
- package/docs/api/weather.md +5 -15
- package/docs/api/weatherLook.md +10 -0
- package/docs/api/world.md +2 -1
- package/docs/recipes/01-new-game.md +71 -59
- package/docs/recipes/02-npc.md +46 -29
- package/docs/recipes/03-items-pickups.md +38 -24
- package/docs/recipes/04-quests.md +34 -27
- package/docs/recipes/05-props-bake.md +154 -18
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +41 -10
- package/docs/recipes/08-weather-sky.md +146 -37
- package/docs/recipes/09-style.md +218 -0
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +34 -10
- package/docs/recipes/14-custom-module.md +65 -34
- package/docs/recipes/15-perf.md +35 -6
- package/docs/recipes/16-dev-bridge.md +65 -41
- package/docs/recipes/18-world.md +21 -8
- package/docs/recipes/19-shooting-picking.md +12 -11
- package/docs/recipes/20-content-actions-save.md +63 -25
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +18 -18
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +12 -6
- package/docs/recipes/28-terrain.md +35 -2
- package/docs/recipes/29-grid.md +71 -33
- package/docs/recipes/30-templates.md +64 -12
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +35 -2
- package/docs/recipes/34-environment-lighting.md +27 -4
- package/docs/recipes/35-style-from-reference.md +115 -51
- package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
- package/docs/recipes/37-terrain-look-hooks.md +37 -15
- package/docs/recipes/38-environment-look-hooks.md +64 -48
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +3 -3
- package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
- package/docs/recipes/44-water-weather-look-hooks.md +30 -21
- package/docs/recipes/45-cascaded-shadows.md +17 -8
- package/docs/recipes/46-blender-art-route.md +4 -4
- package/docs/recipes/47-island-snow-backdrop.md +11 -10
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +46 -33
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +4 -4
- package/docs/recipes/52-look.md +228 -54
- package/docs/recipes/53-ground-up-close.md +58 -0
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +112 -0
- package/docs/recipes/56-webgpu-tsl.md +260 -0
- package/docs/recipes/57-control.md +65 -0
- package/docs/recipes/58-input.md +57 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +55 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +17 -13
- package/examples/action/assets.js +8 -0
- package/examples/action/content/actions.js +1 -1
- package/examples/action/content/audio.js +5 -5
- package/examples/action/look.js +1 -1
- package/examples/action/main.js +10 -13
- package/examples/action/models.js +24 -23
- package/examples/pullable.json +111 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +83 -0
- package/examples/rc2d/README.md +52 -0
- package/examples/rc2d/main.js +63 -0
- package/examples/rc2d/rc2d.js +197 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +13 -11
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/main.js +17 -12
- package/examples/sheepisland/style/index.js +6 -6
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +15 -16
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/npcs.js +1 -1
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +18 -17
- package/examples/styletest/models.js +1 -1
- package/examples/styletest/params.js +3 -3
- package/examples/techniques/contact-shadows/README.md +92 -0
- package/examples/techniques/contact-shadows/contactShadows.js +51 -0
- package/examples/techniques/contact-shadows/main.js +53 -0
- package/examples/techniques/day-night-grade/README.md +86 -0
- package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
- package/examples/techniques/day-night-grade/main.js +51 -0
- package/examples/techniques/interior-light/README.md +103 -0
- package/examples/techniques/interior-light/interiorLight.js +45 -0
- package/examples/techniques/interior-light/main.js +124 -0
- package/examples/techniques/modular-building/README.md +125 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +47 -0
- package/examples/techniques/night-lights/README.md +94 -0
- package/examples/techniques/night-lights/main.js +70 -0
- package/examples/techniques/night-lights/nightLights.js +91 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +84 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/procedural-animation/README.md +77 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +45 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +67 -0
- package/examples/techniques/procedural-surface/main.js +103 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +75 -0
- package/examples/techniques/stylized-shading/main.js +93 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +135 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
- package/examples/techniques/sun-and-key-light/main.js +95 -0
- package/examples/techniques/wet-road/README.md +99 -0
- package/examples/techniques/wet-road/main.js +68 -0
- package/examples/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +84 -0
- package/examples/webgpu-tsl/README.md +42 -0
- package/examples/webgpu-tsl/main.js +21 -0
- package/examples/webgpu-tsl/tslScene.js +75 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +22 -15
- package/examples/world/art/humanoid.js +42 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +58 -0
- package/examples/world/art/shapes.js +9 -0
- package/examples/world/assets.js +6 -0
- package/examples/world/content/audio.js +5 -5
- package/examples/world/content/npcs.js +2 -2
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/rules.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +17 -13
- package/examples/world/style/index.js +61 -0
- package/examples/world/style/plugins/10-bloom.js +5 -0
- package/index.d.ts +50 -45
- package/index.js +27 -22
- package/llms.txt +20 -12
- package/modules/ambience/Ambience.js +34 -23
- package/modules/calendar/Calendar.js +163 -0
- package/modules/calendar/contract.js +21 -0
- package/modules/calendar/index.js +81 -0
- package/modules/{sky → calendar}/schedule.js +17 -16
- package/modules/calendar/seasons.js +55 -0
- package/modules/camera/FirstPersonCamera.js +6 -15
- package/modules/camera/FixedCamera.js +33 -15
- package/modules/camera/FollowCamera.js +90 -16
- package/modules/camera/RtsCamera.js +18 -17
- package/modules/camera/common.js +70 -19
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +196 -59
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +27 -8
- package/modules/characters/behaviors.js +2 -1
- package/modules/characters/contract.js +13 -0
- package/modules/characters/footsteps.js +1 -1
- package/modules/characters/index.js +87 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +97 -19
- package/modules/characters/movers/manual.js +20 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +172 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +12 -8
- package/modules/characters/npcView.js +44 -16
- package/modules/characters/pathAsync.js +7 -3
- package/modules/characters/playerStrings.js +4 -3
- package/modules/characters/proceduralRig.js +46 -10
- package/modules/characters/useModel.js +1 -1
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +65 -25
- package/modules/collision/grid.js +8 -6
- package/modules/content/explain.js +2 -2
- package/modules/content/fields.js +102 -0
- package/modules/content/ids.js +8 -6
- package/modules/content/index.js +97 -28
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +11 -40
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +16 -9
- package/modules/content/rules.js +58 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +121 -30
- package/modules/debug/DebugPanel.js +24 -17
- package/modules/flow/contract.js +16 -0
- package/modules/flow/index.js +21 -15
- package/modules/gameplay/Container.js +41 -32
- package/modules/gameplay/Containers.js +30 -15
- package/modules/gameplay/Dialogue.js +113 -55
- package/modules/gameplay/Interactions.js +193 -67
- package/modules/gameplay/Inventory.js +69 -73
- package/modules/gameplay/Quests.js +75 -39
- package/modules/gameplay/boxOps.js +3 -3
- package/modules/gameplay/dialogue.contract.js +21 -0
- package/modules/gameplay/dialogueBox.js +4 -2
- package/modules/gameplay/dialogueBubbles.js +116 -0
- package/modules/gameplay/interactionPrompt.js +4 -1
- package/modules/gameplay/interactions.contract.js +16 -0
- package/modules/gameplay/inventory.contract.js +23 -0
- package/modules/gameplay/inventoryOps.js +18 -16
- package/modules/gameplay/pickups.js +268 -85
- package/modules/gameplay/questLog.js +4 -4
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +14 -13
- package/modules/grid/index.js +60 -36
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +15 -16
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +6 -5
- package/modules/hlod/index.js +51 -19
- package/modules/hud/index.js +35 -20
- package/modules/hud/parts.js +20 -7
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +45 -20
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +42 -18
- package/modules/music/Music.js +38 -21
- package/modules/music/rules.js +1 -1
- package/modules/nav/index.js +48 -42
- package/modules/net/Client.js +13 -6
- package/modules/net/Host.js +19 -5
- package/modules/net/Net.js +2 -1
- package/modules/net/index.js +13 -8
- package/modules/net/sync.js +9 -8
- package/modules/net/transports.js +77 -27
- package/modules/particles/Particles.js +23 -14
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +39 -11
- package/modules/photo/Photo.js +53 -36
- package/modules/rigid/RigidBodies.js +194 -32
- package/modules/rigid/Vehicles.js +18 -15
- package/modules/rigid/sync.js +62 -17
- package/modules/settings/Settings.js +57 -52
- package/modules/settings/apply.js +38 -3
- package/modules/settings/sections.js +5 -3
- package/modules/settings/strings.js +3 -2
- package/modules/settings/view.js +5 -3
- package/modules/sky/Sky.js +88 -176
- package/modules/sky/cascades.js +86 -25
- package/modules/sky/cascades.tsl.js +82 -0
- package/modules/sky/clouds.js +34 -19
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +83 -13
- package/modules/sky/fog.js +140 -95
- package/modules/sky/frame.js +112 -44
- package/modules/sky/look.js +22 -19
- package/modules/sky/lookFog.js +48 -52
- package/modules/sky/lookShadow.js +53 -41
- package/modules/sky/lookSky.js +82 -21
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +41 -19
- package/modules/sky/shadow.js +44 -20
- package/modules/sky/skyModule.js +45 -33
- package/modules/sky/tint.js +61 -0
- package/modules/terrain/ChunkManager.js +175 -108
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/index.js +105 -50
- package/modules/terrain/look.js +83 -0
- package/modules/terrain/lookGround.js +21 -16
- package/modules/terrain/terrainDefaults.js +1 -1
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +5 -3
- package/modules/terrain/terrainIsland.js +5 -4
- package/modules/terrain/terrainShape.js +12 -12
- package/modules/terrain/terrainShapeMain.js +8 -7
- package/modules/terrain/terrainTexture.js +21 -19
- package/modules/timeline/Timeline.js +95 -43
- package/modules/timeline/Tween.js +18 -10
- package/modules/timeline/letterbox.js +2 -2
- package/modules/timeline/shots.js +5 -1
- package/modules/triggers/index.js +107 -76
- package/modules/vegetation/Vegetation.js +190 -102
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +31 -10
- package/modules/vegetation/look.js +119 -0
- package/modules/vegetation/lookWind.js +71 -10
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +45 -0
- package/modules/water/Water.js +65 -27
- package/modules/water/look.js +29 -18
- package/modules/water/surface.js +64 -25
- package/modules/water/surfaceDefaults.js +3 -0
- package/modules/weather/Weather.js +62 -104
- package/modules/weather/look.js +1 -2
- package/modules/weather/particles.js +24 -9
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherLook.js +135 -0
- package/modules/world/World.js +24 -7
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -4
- package/modules/world/persist.js +62 -2
- package/modules/world/pos.js +3 -2
- package/modules/world/records.js +8 -6
- package/modules/world/sim.js +60 -20
- package/modules/world/simFar.js +4 -3
- package/modules/world/state.js +3 -2
- package/modules/world/thingSource.js +1 -1
- package/modules/world/views.js +7 -5
- package/package.json +8 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +150 -45
- package/render/effects.js +130 -38
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +26 -0
- package/render/fx/lighting.tsl.js +28 -0
- package/render/fx/nodeErrors.tsl.js +68 -0
- package/render/fx/noise.tsl.js +12 -0
- package/render/fx/objectOrigin.tsl.js +42 -0
- package/render/fx/particles.tsl.js +139 -0
- package/render/fx/patchNodes.tsl.js +403 -0
- package/render/fx/postWebGPU.tsl.js +158 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +260 -0
- package/render/fx/uniforms.tsl.js +67 -0
- package/render/fx/water.tsl.js +53 -0
- package/render/fx/wind.tsl.js +22 -0
- package/render/fxNumbers.js +36 -0
- package/render/hotGlsl.js +24 -0
- package/render/lighting.js +66 -14
- package/render/lights.js +223 -4
- package/render/lookGlow.js +139 -0
- package/render/lookSurface.js +99 -36
- package/render/materials.js +71 -52
- package/render/modeling.js +73 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +311 -34
- package/render/postLook.js +124 -46
- package/render/postWebGL.js +197 -0
- package/render/probes.js +231 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/surface.js +53 -17
- package/render/terms.js +211 -0
- package/render/uniformDecl.js +3 -2
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +620 -244
- package/types/gameplay.d.ts +494 -318
- package/types/generated/core/Audio.d.ts +26 -42
- package/types/generated/core/Batching.d.ts +6 -2
- package/types/generated/core/Budget.d.ts +2 -8
- package/types/generated/core/DebugOverrides.d.ts +44 -3
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +102 -31
- package/types/generated/core/Ops.d.ts +31 -0
- package/types/generated/core/Random.d.ts +2 -2
- package/types/generated/core/Saves.d.ts +10 -2
- package/types/generated/core/Stream.d.ts +1 -1
- package/types/generated/core/Threads.d.ts +4 -1
- package/types/generated/core/Views.d.ts +0 -1
- package/types/generated/core/audioVoice.d.ts +17 -9
- package/types/generated/core/control.d.ts +55 -0
- package/types/generated/core/session.d.ts +2 -1
- package/types/generated/modules/ambience/Ambience.d.ts +0 -9
- package/types/generated/modules/calendar/Calendar.d.ts +84 -0
- package/types/generated/modules/calendar/index.d.ts +10 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Grid.d.ts +61 -25
- package/types/generated/modules/grid/Layer.d.ts +5 -5
- package/types/generated/modules/grid/index.d.ts +29 -17
- package/types/generated/modules/music/Music.d.ts +5 -3
- package/types/generated/modules/net/index.d.ts +3 -3
- package/types/generated/modules/net/transports.d.ts +12 -3
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +12 -104
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/weather/Weather.d.ts +17 -18
- package/types/generated/modules/weather/weatherLook.d.ts +12 -0
- package/types/generated/modules/world/World.d.ts +18 -3
- package/types/generated/render/PostFX.d.ts +67 -30
- package/types/generated/render/materials.d.ts +26 -20
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/patches.d.ts +16 -2
- package/types/generated/ui/UI.d.ts +6 -3
- package/types/nav.d.ts +6 -0
- package/types/physics.d.ts +137 -44
- package/types/style.d.ts +125 -92
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +164 -110
- package/ui/Focus.js +25 -14
- package/ui/LoadingScreen.js +1 -1
- package/ui/Parts.js +27 -11
- package/ui/UI.js +20 -10
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +9 -6
- package/ui/touchPart.js +1 -1
- package/core/claims.js +0 -51
- package/core/look/layers.js +0 -136
- package/core/renamed.js +0 -21
- package/docs/api/entities.md +0 -61
- package/docs/recipes/09-style-pack.md +0 -234
- package/examples/styletest/overrides.js +0 -33
- package/examples/styletest/panel.js +0 -135
- package/modules/entities/Entities.js +0 -243
- package/modules/entities/build.js +0 -25
- package/modules/entities/index.js +0 -4
- package/modules/sky/calendar.js +0 -80
- package/modules/sky/layers.js +0 -69
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/world/cells.js +0 -42
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# The game's style folder: changing the art
|
|
2
|
+
|
|
3
|
+
**In this recipe**: 0. Using a style · 0b. Composing a style from parts · 0c. What a style may not hold · 0d. Look plugins in a style folder · 1. Creating a new style ·
|
|
4
|
+
1b. Lights and stalls · 2. Using your own models instead of procedural ones · 2b. Wind, cloud shadows and season tint on your own… ·
|
|
5
|
+
3. When the engine gets a new "look parameter" · 4. Verify · 5. Sounds and music
|
|
6
|
+
|
|
7
|
+
**The engine ships no art.** No default style, character model, terrain look or terrain generator: with no style and no model everything is a
|
|
8
|
+
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
|
|
9
|
+
one neutral directional light without shadows or tone mapping), and the console says once in dev what is missing and how to fix it.
|
|
10
|
+
|
|
11
|
+
A game's style is a plain object its `style/` folder exports, passed in as `createEngine({ style })`. It holds **looks only**: colors,
|
|
12
|
+
materials and shaders, sky and lighting, post effects, UI look. Not part of it: model / texture / sound files and procedural models content names (an
|
|
13
|
+
**asset pack**, `engine.assets.manifest`, recipe 05 "Asset packs"), sounds (section 5), gameplay data and timing (a **content pack**, recipe 20;
|
|
14
|
+
`calendar({ hoursPerDay })`). Which key is read by whom is in the "style keys" table of `../CODEMAP.md`; the field list is in `../api/style.md`. Every
|
|
15
|
+
entry can be omitted; omitted entries are the neutral placeholders above (the city example passes no style 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.
|
|
16
|
+
|
|
17
|
+
## 0. Using a style
|
|
18
|
+
A game keeps its style in its `style/` folder (`style/index.js`; a new game starts with an empty one). Any art
|
|
19
|
+
direction fits: realistic, toon, pixel, painterly, flat, noir. The engine ships none (section 1).
|
|
20
|
+
```js
|
|
21
|
+
import { createEngine, presets, openWorld } from 'threedog';
|
|
22
|
+
import style from './style/index.js'; // the game's own look
|
|
23
|
+
import { terrainPreset, terrainStrings } from '@threedog/terrain-noise'; // the world shape is not a look: its own package
|
|
24
|
+
const engine = createEngine({ canvas, style, strings: terrainStrings }); // terrainStrings: names of the preset's ground types
|
|
25
|
+
engine.use(openWorld({ camera: 'follow', seed: 7, terrain: terrainPreset() })); // noise terrain (hills, rivers, biomes) that your pack colors, see recipes/28
|
|
26
|
+
```
|
|
27
|
+
Procedural models are an asset pack, not part of the style (`engine.assets.manifest(assets)`; the world example keeps its in `examples/world/art/`). Post effects such as `bloom` / `ao` / `outline` come from
|
|
28
|
+
`@threedog/post-effects`. The terrain generator `terrainPreset` / `riverAt` / `BIOMES` /
|
|
29
|
+
`terrainStrings` is a separate package, `@threedog/terrain-noise`: the shape of the world is gameplay, so a style keeps only the colors of its
|
|
30
|
+
ground types (`terrain.colors`, `biomeColors`).
|
|
31
|
+
|
|
32
|
+
## 0b. Composing a style from parts
|
|
33
|
+
`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
|
|
34
|
+
mix without copying whole packs:
|
|
35
|
+
```js
|
|
36
|
+
import base from './style/index.js';
|
|
37
|
+
const dusk = { sky: { sunSize: 600, keyframes: myDuskKeyframes } }; // only these two sky fields change
|
|
38
|
+
const engine = createEngine({ canvas, style: [base, dusk, { ui: { accent: '#7fd3ff' }, post: null }] });
|
|
39
|
+
```
|
|
40
|
+
Rules (`core/styleParts.js`): plain `{ }` objects merge key by key at every depth; everything else replaces whole (arrays such as `sky.keyframes` and
|
|
41
|
+
`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
|
|
42
|
+
parts; parts are never mutated. One object (not a list) is used as it is.
|
|
43
|
+
The merged style is the **style layer** of every look value (recipe 52 "How look values stack"): later parts win there and two parts never
|
|
44
|
+
conflict; a game's `look.<part>.set(...)` sits on top of it, and the weather and the sunset multiply whichever decides. A style starts the fog
|
|
45
|
+
distance (`sky.fog.far`) and the shadow filter (`sky.shadow.type`); there are no `createEngine` options for them.
|
|
46
|
+
|
|
47
|
+
**Post effects are plugins.** A style brings each post effect as a file in its `style/plugins/` folder (`10-bloom.js: export default bloom()`,
|
|
48
|
+
listed with `plugins: import.meta.glob('./plugins/*.js', { eager: true })`), the same file a game's `plugins/` folder takes: both go through
|
|
49
|
+
`engine.look.post.add`, the one way into the chain (recipe 52). Each part's plugins stay grouped under the part's name, so one pack's effect is
|
|
50
|
+
switched off with `engine.plugins.off('<pack>/<file>')` or `look.post.set({ bloom: false })`, and `plugins: null` drops the earlier parts' plugins.
|
|
51
|
+
There is no `style.post` list (it was a second way in, with its own on / off rules).
|
|
52
|
+
|
|
53
|
+
**Retinting the procedural models.** `style.palette` holds the colors the trees, rocks, grass and flowers are built from (the keys are the pack's own, e.g. `bark`, `leaf`, `rock`,
|
|
54
|
+
`grassTip`...; see `base.palette`). One part changes them all:
|
|
55
|
+
`style: [base, { palette: { leaf: 0xd98a3a } }]` (autumn); keys left out keep the base 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
|
+
The other way round, a look value is never a module option: water color, waves, normal map (`style.water.*`), sky keyframes, sun, moon, stars
|
|
64
|
+
(`style.sky.*`) and terrain `normals` (`style.terrain.config.normals`) are set in the style, and at run time with `engine.look.water` /
|
|
65
|
+
`look.sky` / `look.ground` `.set(...)`; `water({ color })`, `sky({ moonSize })`, `terrain({ normals })` throw naming that call
|
|
66
|
+
- terrain shape and size (seed, chunk size, resolution, water level, height functions): `style.terrain.config.*` -> `terrain({ ... })`. The looks
|
|
67
|
+
in `terrain.config` are `shading` (`'smooth'` | `'texture'` | `'flat'`), `colorResolution`, `normals` and `normalFn` (recipe 37); at run time
|
|
68
|
+
`engine.look.ground.set({ shading, colors, variation, detail })` (recipe 52)
|
|
69
|
+
Quality settings are not world state and may stay in a style (shadow `mapSize` and `low` overrides, water `segments`); players can override them in
|
|
70
|
+
settings. A game's `style/` folder is also checked by `threedog check` (R34).
|
|
71
|
+
|
|
72
|
+
## 0d. Look plugins in a style folder
|
|
73
|
+
One folder = one style: starting values, the material per role, and optional look plugins. A plugin is a file exporting the same shapes as the
|
|
74
|
+
game's `plugins/` folder (recipe 40 §1): a three.js `Pass`, a `Material` (its `name` is the role), a material patch `{ slot, glsl, roles }` (plugged with `look.materials.add`),
|
|
75
|
+
an `Object3D`, or a look module (a sky or vegetation look with `replaces`). The style lists them in `plugins`, and the engine plugs them through
|
|
76
|
+
`engine.plugins`, the same loader as the game's folder, so a plugin file works alone in `plugins/` or inside any number of style folders unchanged:
|
|
77
|
+
```js
|
|
78
|
+
// style/index.js style/plugins/10-paper.js: export default new ShaderPass(PaperShader)
|
|
79
|
+
export default { // style/plugins/20-stone.js: export default Object.assign(new THREE.MeshToonMaterial({ color: 0x777777 }), { name: 'stone' })
|
|
80
|
+
name: 'ink', exposure: 1.1, materials: { wood: { type: 'lambert', color: 0x8a5a36 } },
|
|
81
|
+
plugins: import.meta.glob('./plugins/*.js', { eager: true }), // without Vite: { paper: { default: paperPass } }
|
|
82
|
+
};
|
|
83
|
+
```
|
|
84
|
+
They sit **under** the game: a style plugin's material and patch are on the style layer of `engine.look.materials`, so the game's
|
|
85
|
+
`look.materials.set / replace` and the game's own plugins win. Names are `<style>/<file>` (`ink/10-paper`); `engine.plugins.off('ink')` takes
|
|
86
|
+
all of the style's plugins out, `off('ink/10-paper')` one; `describe().slots` lists them with `style ink: plugins/...`. `off('ink')` turns off
|
|
87
|
+
the pack's **plugins only**: its starting values (`exposure`, `fog`, the `materials` table and the other fields of `style/index.js`) are the
|
|
88
|
+
style itself and stay; the `off()` result and the off rows of `describe().slots` say so. To drop those too, start with another style.
|
|
89
|
+
Each plugin is its own owner (`style:ink/10-paper`), the pack only groups them: switching one off takes out only what that file wrote, and
|
|
90
|
+
the others keep theirs. Two plugins that write the same key on the same layer (two Materials named `stone`) are a `shared-conflict` naming
|
|
91
|
+
both files in development; to let one win on purpose, say so in that file: `export const replaces = '10-stone';` (the other is unplugged
|
|
92
|
+
while this one is on, and comes back when it goes off; `plugins.list()` shows `replacedBy`). In a list of parts each
|
|
93
|
+
part's plugins stay under that part's name, and `{ plugins: null }` drops the earlier parts'. The personal library (`threedog lib`) stores a
|
|
94
|
+
plugin once; `lib pull` puts its code in `plugins/<name>/` with the wiring file `plugins/<name>.js`, and copying both into a style folder's `plugins/` is all it takes to bundle it.
|
|
95
|
+
|
|
96
|
+
## 1. Creating a new style
|
|
97
|
+
Edit your game's `style/index.js` (`threedog new-game` makes it empty, every key commented out; fill one section at a time). To try a second look,
|
|
98
|
+
copy the folder (`style-toon/`) and point `createEngine` at it; `threedog style check style-toon` (a folder path; with no argument it checks the game's `style/`) finds mistakes before you look at pixels:
|
|
99
|
+
```js
|
|
100
|
+
import toon from './style-toon/index.js';
|
|
101
|
+
const engine = createEngine({ canvas, style: toon });
|
|
102
|
+
```
|
|
103
|
+
**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
|
|
104
|
+
name falls back to `materials.default`, and a new role (`'lantern'`, `'roof'`) becomes real the moment the style adds `materials.lantern`. The engine
|
|
105
|
+
warns only when a name looks like a typo of a known role (`'buidling'`).
|
|
106
|
+
|
|
107
|
+
Keys you will change most often:
|
|
108
|
+
| Key | What it controls |
|
|
109
|
+
|---|---|
|
|
110
|
+
| `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({...})`. The table is the style layer of `engine.look.materials`, the one entry `makeMaterial(role)` reads: the game changes a role with `look.materials.set / replace` (recipe 52), never by editing `engine.style.materials` |
|
|
111
|
+
| `antialias` | `false` for sharp pixel edges; omitted = on for desktop, off for phones (players can switch it in settings) |
|
|
112
|
+
| `post` | List of post effects (e.g. `[outline(), ao(), bloom()]`; `outline({ enabled: true })` draws edge lines); slots, the effects package, `fuse`, outline modes: [recipe 52](52-look.md#post-effect-chain) |
|
|
113
|
+
| `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` `'smooth'` (engine default) | `'texture'` (per-chunk color map) | `'flat'` (facets), `colorResolution`, `normals`, `normalFn`, recipe 37; `terrain.detail` a detail layer, recipe 53; `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 |
|
|
114
|
+
| `character` | `animation.fade`: skeletal animation transition seconds. Bodies are assets, not style: `createPlayer({ model })` with a registered model, a GLB asset name or `{ rig }`; part colors are material roles or `{ colors }` per character (recipe 13). Without a model a gray capsule |
|
|
115
|
+
| `pickup` `particles` | Items on the ground: look values only (`color`, `size`, `lift`; the shape is an asset model name, recipe 03), particle presets (dust smoke leaves splash sparks...) |
|
|
116
|
+
| `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 |
|
|
117
|
+
| `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 |
|
|
118
|
+
|
|
119
|
+
## 1b. Lights and stalls
|
|
120
|
+
Every engine has `engine.lights = { sun, hemi }`, plain three.js lights. Without a style they are a neutral placeholder (white
|
|
121
|
+
hemisphere + neutral directional light, no shadows); the look (sun color and intensity curves, sky colors, fog, shadow softness, exposure, tone
|
|
122
|
+
mapping) comes from the style's `sky`, `exposure` and `toneMapping`, and the sky module drives the same two lights. At run time:
|
|
123
|
+
`engine.look.lights.set(...)` (recipe 52); to light the world yourself: recipe 38. `toneMapping` is read once, when the engine creates its
|
|
124
|
+
renderer; later the curve is plain three.js (`engine.renderer.toneMapping = ...`).
|
|
125
|
+
|
|
126
|
+
three.js builds one shader program per material for each light setup. `engine.start()` compiles everything visible behind the
|
|
127
|
+
loading screen (`engine.startup.compileMs`), but adding or removing a light later, or toggling `visible` on one, changes the setup and compiles again:
|
|
128
|
+
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
|
|
129
|
+
recompile). In dev the console warns (code `light-recompile`) when programs were compiled in a frame where the lights changed.
|
|
130
|
+
|
|
131
|
+
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,
|
|
132
|
+
moves to the sources that matter most (near the camera, bright, high `priority`) and fades with intensity, so the light setup never changes. Install
|
|
133
|
+
it before `engine.start()` so the startup compile covers its lights:
|
|
134
|
+
```js
|
|
135
|
+
import { lightPool } from 'threedog';
|
|
136
|
+
engine.use(lightPool({ point: 8 })); // 8 PointLights; lightPool({ spot: 2, shadows: 1 }) adds spots / lets one point light cast
|
|
137
|
+
for (const t of torches) engine.lightPool.add(t, { // an Object3D is followed; a position stays put
|
|
138
|
+
color: 0xffa040, intensity: 4, distance: 8,
|
|
139
|
+
flicker: (time, i) => 0.85 + 0.15 * Math.sin(time * 13 + i),
|
|
140
|
+
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
|
|
141
|
+
});
|
|
142
|
+
const flash = engine.lightPool.add(gun.muzzle, { intensity: 0, priority: 5, distance: 6 });
|
|
143
|
+
flash.set({ intensity: 8 }); /* next frame */ flash.set({ intensity: 0 }); // muzzle flash: no light is created
|
|
144
|
+
```
|
|
145
|
+
`engine.lightPool.usage()` (and `describe().lightPool`) lists which source each real light holds; `focus` measures from the player instead of the
|
|
146
|
+
camera. Options and handle: `../api/lightPool.md`. Windows and signs that light up at night (many materials, no real light each):
|
|
147
|
+
`engine.look.materials.glow('window', { night: 2 })` (recipe 52 "Night glow").
|
|
148
|
+
|
|
149
|
+
Top-down or side-view games whose light should spread over the floor and stop at walls (soft shadows, any number or shape of emissive
|
|
150
|
+
lights) can copy the optional 2D radiance cascades example instead: `examples/rc2d/` (README there: when it fits, cost, limits). It is not a module.
|
|
151
|
+
|
|
152
|
+
## 2. Using your own models instead of procedural ones
|
|
153
|
+
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
|
|
154
|
+
name to swap one:
|
|
155
|
+
```js
|
|
156
|
+
engine.assets.manifest(yourAssets); // assets from an asset pack you have: trees, rocks, flowers... built in code
|
|
157
|
+
engine.assets.manifest({ name: 'mine', models: { pine: () => myPineGeometry(), well: '/models/well.glb' } }); // replaces pine, adds well
|
|
158
|
+
```
|
|
159
|
+
Vegetation takes a geometry (`geometry: await engine.assets.geometry('pine')`, the first mesh in the model) or a whole model with one material per
|
|
160
|
+
mesh, e.g. bark trunk + alpha-cut leaf cards:
|
|
161
|
+
`engine.vegetation.define('oak', { model: await engine.assets.model('oak'), wind: 0.02 })` (still one draw call per part; felling hides every part). For
|
|
162
|
+
the import workflow see `10-blender-level.md`.
|
|
163
|
+
`mergeColored(parts, { flat: false })` keeps smooth normals; UVs survive when every part has them.
|
|
164
|
+
A generator in `models` may also return an Object3D with its own materials; those are used as they are.
|
|
165
|
+
|
|
166
|
+
### 2a. Reusing art from somewhere else: copy it in, do not depend on it
|
|
167
|
+
Art code you already have (generator modules such as `art/my-crate.js` from an earlier game, a folder of your own, files someone gave you, a package
|
|
168
|
+
you installed) is reused by **copying** it into this game. The copy is the game's own: edit it freely; nothing links back and nothing updates it.
|
|
169
|
+
```sh
|
|
170
|
+
threedog art list ../earlier-game # modules, exported functions with their first JSDoc line, asset files (uses its art/ folder)
|
|
171
|
+
threedog art copy ../earlier-game crate lamp # by file or function name; none = every module
|
|
172
|
+
threedog art copy ../earlier-game crate --dry # what would be written, nothing written
|
|
173
|
+
```
|
|
174
|
+
It copies the named modules, every local file they import and every texture / model file they name ('./wood.png', `new URL(...)`, '/models/x.glb'
|
|
175
|
+
from the source's `public/`), rewrites relative import paths to the new layout (outside-the-art-folder helpers land in `art/shared/`), keeps package
|
|
176
|
+
imports and lists them, and prints the `engine.assets.manifest` lines to register the generators. An existing file with different content stops the
|
|
177
|
+
whole copy (nothing written) unless `--force`. The engine ships no art library and names no source: which art to reuse is yours to choose.
|
|
178
|
+
GLB files from Blender are copied the same way and checked with recipe 46 section 3.
|
|
179
|
+
|
|
180
|
+
## 2b. Wind, cloud shadows and season tint on your own materials
|
|
181
|
+
The engine's shader effects are named patches that work on any material that has the usual three.js chunks (WebGL only):
|
|
182
|
+
```js
|
|
183
|
+
import { applyEffects } from 'threedog';
|
|
184
|
+
const leaves = applyEffects(new THREE.MeshToonMaterial({ color: 0x5a8a3a }), { wind: 0.03, season: 'foliage' }); // clouds default on
|
|
185
|
+
engine.vegetation.define('bush', { geometry, material: leaves }); // vegetation adds them itself; effects: false keeps the material untouched
|
|
186
|
+
```
|
|
187
|
+
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
|
|
188
|
+
the material's own `onBeforeCompile`:
|
|
189
|
+
`applyEffects(mat, { patches:
|
|
190
|
+
[{ name: 'snap', cacheKey: 64, uniforms, glsl: { vertex: { pars: '...', project_vertex: '...code after #include <project_vertex>' } } }] })`.
|
|
191
|
+
A missing `#include` anchor throws. A hand-written `ShaderMaterial` can `#include <threedog_wind_vertex>`, `<threedog_clouds_pars_fragment>` etc. (see
|
|
192
|
+
`render/effects.js`) with `engine.uniforms` as its uniforms.
|
|
193
|
+
`material.clone()` does not carry patches (three's `Material.copy` skips `onBeforeCompile`): a pack's Material instance in `materials` is fine
|
|
194
|
+
(`makeMaterial` keeps its patches); when you clone one yourself, apply the effects to the clone again.
|
|
195
|
+
What a patch declares (`needs`, `conflicts`, `shadow`, `cacheKey`) and the chunk names: recipe 43, "Patch a slot". Textures by asset name are
|
|
196
|
+
material spec keys (recipe 48); the engine GLSL functions you can call in your own shader, and the spec keys that wire some of them in as a shortcut: recipe 43.
|
|
197
|
+
|
|
198
|
+
## 3. When the engine gets a new "look parameter"
|
|
199
|
+
Hard rule 1: a module only writes a neutral gray fallback and reads `engine.style.xxx ?? fallback`, **and the real value is added to a style
|
|
200
|
+
(its `index.js`) at the same time** (with a one-line comment saying what it means),
|
|
201
|
+
and the new field gets a doc comment in `types/style.d.ts` (`docs/api/` is generated from there). Materials always go through
|
|
202
|
+
`makeMaterial('role', { color })`, leaving the surface feel to the role in `engine.look.materials` (the style's `materials` table is its style layer). Whose style: `engine.makeMaterial('role', { color })` uses that
|
|
203
|
+
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 styles always
|
|
204
|
+
go through the engine (`water.material(engine, ...)`, a generator's `this.engine`), so two engines never share materials.
|
|
205
|
+
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).
|
|
206
|
+
|
|
207
|
+
## 4. Verify
|
|
208
|
+
- `npm run check`: R14 reports "creates a material directly" in engine code (games, examples and styles are plain three.js and not checked) and R39
|
|
209
|
+
"non-gray fallback color"; the type check catches misspelled keys in the style.
|
|
210
|
+
- `npm run map`: the "style keys" table in CODEMAP is updated.
|
|
211
|
+
- 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`
|
|
212
|
+
(images go to .threedog/shots/).
|
|
213
|
+
- It must still run without a style: start once with `createEngine({ canvas })` and no `style` (gray placeholders, one console note per missing piece).
|
|
214
|
+
|
|
215
|
+
## 5. Sounds and music (the game's, not the style's)
|
|
216
|
+
Sounds are game config, passed to `createEngine({ audio: { sounds, ambience, music, footsteps, levels } })` and read back as `engine.audio.config`; a
|
|
217
|
+
style carries none. The engine plays nothing the game did not name. Buses, sounds by name, the ambience rule table, music rules, footsteps and
|
|
218
|
+
ducking: `recipes/31-audio.md`.
|
|
@@ -49,8 +49,8 @@ the flat default. Rules read `engine.surface / slope / groundType`, so pick the
|
|
|
49
49
|
property, else its material name) with `rule.biomes`, and limit the scatter with `area`:
|
|
50
50
|
```js
|
|
51
51
|
engine.use(level({ url: '/models/town.glb' }), vegetation({ area: { min: [-80, -80], max: [80, 80] }, viewChunks: 3 }), collision());
|
|
52
|
-
engine.vegetation.
|
|
53
|
-
engine.vegetation.
|
|
52
|
+
engine.vegetation.define('grass', { geometry: grassGeo, nearOnly: true, rule: { perChunk: 500, biomes: { lawn: 1 } } });
|
|
53
|
+
engine.vegetation.define('tree', { model: oak, rule: { perChunk: 6, biomes: { lawn: 0.6, park: 1 }, maxSlope: 0.4, collider: 0.4 } });
|
|
54
54
|
```
|
|
55
55
|
Chunks stream around `engine.stream` sources and stay one InstancedMesh per species per chunk (LOD, shadows and felling work as on terrain:
|
|
56
56
|
`instanceAt` / `removeInstance`, saved). Collision and path planning see the trees through `engine.ground.forEachCollider`; a new level or `setGround`
|
|
@@ -58,6 +58,18 @@ re-places them; after changing a ground function behind the same provider call `
|
|
|
58
58
|
sets `minHeight / maxHeight`. Content `vegetation` works the same way. With `terrain()` installed, `vegetation()` takes no options (density and view
|
|
59
59
|
distance are terrain options). Rapier (`rigid()`) bodies collide with them too (cylinders from `engine.ground.forEachCollider`, gone when felled).
|
|
60
60
|
|
|
61
|
+
Where a species grows is decided in the same `add()` call, with up to three parts (on a level, a code-built ground or terrain alike):
|
|
62
|
+
```js
|
|
63
|
+
// rule: random scatter per chunk (above). positions: the game's own spots instead, [x, z] or [x, z, scale, yaw], planted at the ground height
|
|
64
|
+
engine.vegetation.define('hedge', { model: hedge, positions: hedgeSpots /* [[x, z], ...] from your level data */, rule: { collider: 0.5 } });
|
|
65
|
+
// densityMap: thins the rule's or the positions' result, 0..1 per spot -- a function of game data, or a gray image with the heightmap keys
|
|
66
|
+
engine.vegetation.define('weeds', { geometry: weedGeo, rule: { perChunk: 300 }, densityMap: (x, z) => farm.neglect(x, z) });
|
|
67
|
+
engine.vegetation.define('flowers', { geometry: flowerGeo, rule: { perChunk: 200 }, densityMap: { url: '/maps/flowers.png', size: [256, 256] } });
|
|
68
|
+
```
|
|
69
|
+
With `positions`, the rule keeps only what shapes an instance (`scale`, `stretch`, `sink`, `tints`, `tintJitter`, `collider`); the scatter filters
|
|
70
|
+
are refused. The id of a listed plant is its index in the list. After what a density function reads changes, call `engine.vegetation.rebuild()`.
|
|
71
|
+
A game that wants every instance under its own code still builds a plain `THREE.InstancedMesh` and adds it to the scene.
|
|
72
|
+
|
|
61
73
|
## 5. Verify
|
|
62
74
|
- `npm run assets` prints each file's size before and after compression; a browser 404 appears in `.threedog/errors.log` (asset load failure).
|
|
63
75
|
- `describe()`: `ready` is true and `loading` is empty; the player's coordinates are at the spawn point; `nearby` contains trigger zones
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Physics: rigid bodies, pushing, joints, vehicles
|
|
2
|
+
|
|
3
|
+
Any physics body (crates the player pushes, balls, doors on hinges, ropes): §3, read it first when the game has no car. Cars and
|
|
4
|
+
boarding: §1–2.
|
|
2
5
|
|
|
3
6
|
Required modules: `collision()` + `rigid()` (Rapier physics; the vehicle controller lives there) + `characters()`. With
|
|
4
7
|
`interactions({ ...presets.interactions.nearest })` installed, a "board/exit" prompt (E key) appears automatically near a vehicle.
|
|
@@ -24,29 +27,83 @@ function makeCar() {
|
|
|
24
27
|
engine.events.on('engine:ready', () => {
|
|
25
28
|
const { car, wheels } = makeCar();
|
|
26
29
|
car.position.set(10, engine.surface(10, 0) + 1.5, 0); // place it slightly above the ground and let it drop
|
|
27
|
-
const v = engine.rigid.
|
|
30
|
+
const v = engine.rigid.addWheeled(car, { wheels, mass: 600, engineForce: 1200, camera: { distance: 14, height: 2 } });
|
|
28
31
|
window.car = v; // handy for tests and the console
|
|
29
32
|
});
|
|
30
33
|
```
|
|
31
|
-
`
|
|
34
|
+
`addWheeled` options: `id` stable id (default `vehicle1`, `vehicle2`... in creation order; give one when that order varies), `wheels` (at least 3),
|
|
32
35
|
`mass` in kg, `engineForce` throttle force, `brakeForce`, `maxSteer` in radians, `suspension: { rest, stiffness, damping }`,
|
|
33
|
-
`
|
|
36
|
+
`seats` seat positions (the first drives, the rest ride; each exits on its own side), `hideDriver` (default true; false keeps riders visible on their seats: bikes, karts, open carts), `camera` camera distance/height while driving, `size` body collision box (by default the model's bounding box, wheels excluded),
|
|
34
37
|
`friction` grip, `exitOffset` how far from the side of the body the player lands when exiting (meters, default 0.8).
|
|
35
38
|
Rigid bodies and vehicles do not change a model's shadow settings: set `mesh.castShadow = true` yourself if you want a shadow.
|
|
36
39
|
|
|
37
40
|
## 2. Boarding and driving
|
|
38
41
|
- Player: press E near the car to board (when interactions is installed); while driving, WASD = throttle/steering; the brake key (action `brake`, only
|
|
39
|
-
when the game gives one: `
|
|
42
|
+
when the game gives one: `engine.input.bind(presets.bindings.brake)` is B / gamepad LT, or `engine.input.bind('brake', ['KeyX'])`; keep it off Space so
|
|
40
43
|
it doesn't compete with jumping) brakes, and without one the engine warns once; press E again to exit.
|
|
41
44
|
- Saving: the player save records which vehicle the player is in (its `id`); loading an on-foot save while driving exits the vehicle first, and
|
|
42
45
|
loading a driving save puts the player back in the car.
|
|
43
|
-
- Code: `engine.player.enter(v)`, `engine.player.exit()`; `engine.player.vehicle` is the vehicle being driven (null when on foot); `v.driver` is who is driving.
|
|
46
|
+
- Code: `engine.player.enter(v)`, `engine.player.exit()`; `engine.player.vehicle` is the vehicle being driven (null when on foot); `v.driver` is who is driving, `v.passengers` who rides, `character.seat` the seat (0 drives; a second `enter` takes a free passenger seat, which does not steer).
|
|
44
47
|
- NPCs/scripts driving: `v.drive(throttle -1..1, steer -1..1 (right is positive), brake 0-1)`; the last values set are used on every fixed step.
|
|
45
48
|
- Events: `vehicle:enter`, `vehicle:exit` (`{ character, vehicle }`). Removal: `v.remove()` (anyone inside exits first; the model stays,
|
|
46
49
|
`engine.remove(car)` deletes it).
|
|
47
50
|
- Native objects: `v.body` (Rapier rigid body), `v.controller` (vehicle controller), `v.speed` (m/s, negative when reversing).
|
|
48
51
|
|
|
49
|
-
## 3.
|
|
52
|
+
## 3. Rigid bodies: saves, joints, determinism
|
|
53
|
+
This section covers every `engine.rigid` body (crates, balls, hulls, vehicles), not only cars.
|
|
54
|
+
|
|
55
|
+
**Pushing bodies with the player.** Yes, with any mover: with `rigid()` installed the player carries a kinematic capsule
|
|
56
|
+
(`rigid.playerBody`) that follows it every fixed step, so walking into a dynamic body (`addBox(mesh, { mass })`, `addBall`, `addHull`) shoves it
|
|
57
|
+
ahead. The mover leaves dynamic bodies out of its own collision, so a body is pushed instead of stopping the player; how hard it resists is
|
|
58
|
+
its `mass` and friction. A body that should stop the player is `{ fixed: true }` with `mover: 'rapier'` (that mover collides with fixed bodies).
|
|
59
|
+
A puzzle reads the result from the body (`entry.body.translation()` in `onFixed`, or a trigger zone) and gives the body an `id`, so a save keeps
|
|
60
|
+
where it was pushed. Test: `npm test -- "rigid push"` (both movers).
|
|
61
|
+
|
|
62
|
+
**Saves.** A body added with an `id` (`rigid.addBox(mesh, { id: rec.id })`; vehicles always have one) is saved with its pose, rotation,
|
|
63
|
+
velocities and sleep, and a load gives that state back to the body with the same id, also when it is built after the load (a world presenter's
|
|
64
|
+
`build`). A body without an id is not saved: after a load it is wherever its record (or your code) puts it, upright and at rest.
|
|
65
|
+
|
|
66
|
+
**Joints** (hinges, doors, ropes, chains) are plain Rapier on engine bodies; the engine has no wrapper:
|
|
67
|
+
```js
|
|
68
|
+
const R = engine.rigid, J = R.R.JointData;
|
|
69
|
+
const post = R.addBox(postMesh, { fixed: true }), door = R.addBox(doorMesh, { mass: 8 });
|
|
70
|
+
// hinge on the post's right edge, turning around Y; anchors are in each body's local space
|
|
71
|
+
const hinge = R.world.createImpulseJoint(J.revolute({ x: 0.5, y: 0, z: 0 }, { x: -0.5, y: 0, z: 0 }, { x: 0, y: 1, z: 0 }), post.body, door.body, true);
|
|
72
|
+
hinge.setLimits(-1.5, 1.5);
|
|
73
|
+
// rope: the weight hangs at most 2 m below the hook
|
|
74
|
+
R.world.createImpulseJoint(J.rope(2, { x: 0, y: -0.5, z: 0 }, { x: 0, y: 0.5, z: 0 }), hook.body, weight.body, true);
|
|
75
|
+
```
|
|
76
|
+
`R.world` is the Rapier world and `entry.body` the Rapier body. newGame and a load rebuild the physics world (physics starts over like a fresh
|
|
77
|
+
page) and free the old world's joints with it; the engine does not copy them. It emits `rigid:rebuilt` once the bodies are back, and that is
|
|
78
|
+
where a game re-creates its joints, with the same code that made them:
|
|
79
|
+
```js
|
|
80
|
+
function hang() { // makes the joints; called after the bodies are added, and again after every rebuild
|
|
81
|
+
const h = R.world.createImpulseJoint(J.revolute({ x: 0.5, y: 0, z: 0 }, { x: -0.5, y: 0, z: 0 }, { x: 0, y: 1, z: 0 }), post.body, door.body, true);
|
|
82
|
+
h.setLimits(-1.5, 1.5);
|
|
83
|
+
R.world.createImpulseJoint(J.rope(2, { x: 0, y: -0.5, z: 0 }, { x: 0, y: 0.5, z: 0 }), hook.body, weight.body, true);
|
|
84
|
+
}
|
|
85
|
+
hang();
|
|
86
|
+
engine.events.on('rigid:rebuilt', hang); // { world, player, bodies }: bodies maps the ids you gave addBox / addBall / addHull
|
|
87
|
+
```
|
|
88
|
+
`entry.body` already points at the rebuilt body there; a joint object kept from before belongs to the freed world (hold the new one). A body
|
|
89
|
+
the game made with `world.createRigidBody` is not rebuilt: make anchors with `addBox(mesh, { fixed: true })`. In development a `rigid-misuse`
|
|
90
|
+
warning names a rebuild that dropped joints when none was re-created by the next step. Joints are not saved: on a load, bodies a presenter's
|
|
91
|
+
`build` adds come back after the event, so create their joints in that `build`. With a vehicle present the world is kept (no event, joints
|
|
92
|
+
stay). Removing a body removes its joints (Rapier does that).
|
|
93
|
+
|
|
94
|
+
**Determinism**, the one place this is stated (replay, `engine.step`, saves and net link here):
|
|
95
|
+
- Same build, same machine, same inputs and the same number of fixed steps give bit-identical bodies, in a fresh page and at any frame rate.
|
|
96
|
+
Physics only advances in fixed steps. Test: `npm test -- "rigid determinism"`: stacked boxes knocked over, a rolling ball, a driving car, the
|
|
97
|
+
`mover: 'rapier'` player, two fresh pages, `frameEvery` 1 / 2 / 4.
|
|
98
|
+
- A load restores each saved body exactly. Rapier's contact and warm-start caches and its solver order are not saved, so the run after a load
|
|
99
|
+
is not bit-identical to the run that went on without the load. A toppling stack can end some centimetres away (measured: 0.24 m after 1.5 s).
|
|
100
|
+
Bodies at rest stay at rest. Bit-identical continuation would need `world.takeSnapshot()`, which includes the terrain colliders (about 650 KB
|
|
101
|
+
for the open world's 9 chunks) and is not used.
|
|
102
|
+
- Across machines: the engine uses `@dimforge/rapier3d-compat`, which Rapier does not promise to be cross-platform deterministic (that is the
|
|
103
|
+
separate `rapier3d-deterministic` build). Two machines can drift apart. The net module does not depend on matching physics: the host owns the
|
|
104
|
+
state, and physics is not synced (each machine simulates its own bodies).
|
|
105
|
+
|
|
106
|
+
## 4. Verify
|
|
50
107
|
- In a test (no real key presses): `engine.player.enter(car); engine.input.autopilot = { x: 0, y: 1 }; engine.step(3)`,
|
|
51
108
|
then `describe().player.vehicle.speed` is above 0 and the car has moved; after `engine.player.exit()`, `engine.player.vehicle` is null and the
|
|
52
109
|
player stands outside the door.
|
|
@@ -14,7 +14,7 @@ const hero = await engine.assets.model('hero');
|
|
|
14
14
|
## 2. Mapping: game action names -> whatever the asset calls its clips
|
|
15
15
|
States are the mapping. The left side is what your game says (`idle`, `attack`, `hurt`), the right side is the clip name in the file, so a new model
|
|
16
16
|
only changes the right side:
|
|
17
|
-
```js
|
|
17
|
+
```js fragment
|
|
18
18
|
states: { idle: { clip: 'Idle_Sword' }, attack: { clip: 'Sword_Slash', loop: false }, hurt: { clip: 'HitRecieve', loop: false }, death: { clip: 'Death', loop: false } }
|
|
19
19
|
```
|
|
20
20
|
**Keep the mapping as data, on the model's manifest entry** (it describes the file, so it travels with it in an asset pack). `assets.animate(model)`
|
|
@@ -27,7 +27,7 @@ engine.assets.manifest({ name: 'heroes', models: { hero: { url: '/models/hero.gl
|
|
|
27
27
|
engine.characters.createPlayer({ ...presets.player.thirdPerson, model: 'hero' }); // no clips / animation in code
|
|
28
28
|
engine.assets.mapping(engine.player.anim.root); // after whenReady: the entry's mapping, or null
|
|
29
29
|
```
|
|
30
|
-
A character's default names (`Idle`, `Walk`...) never shadow a mapped state, and the entry's `fade` beats the style
|
|
30
|
+
A character's default names (`Idle`, `Walk`...) never shadow a mapped state, and the entry's `fade` beats the style's.
|
|
31
31
|
|
|
32
32
|
- A clip name also matches the part after the last `|`: Blender / FBX2glTF exports `CharacterArmature|Idle`, you write `Idle`.
|
|
33
33
|
- Dev checks: a state whose clip is not in the model warns at `assets.animate()` with the available clip names and where to fix it
|
|
@@ -48,6 +48,15 @@ engine.characters.createPlayer({ ...presets.player.thirdPerson, model: hero,
|
|
|
48
48
|
engine.player.playAction('Wave'); // one-shot clip (skipped if the clip doesn't exist); returns to the previous state when done
|
|
49
49
|
engine.player.anim.state; // current state name
|
|
50
50
|
```
|
|
51
|
+
**The game's own states** (crouch, climb, glide, dash, roll) go on top of the built-in ones through the `states` option, without taking the mover
|
|
52
|
+
over: it runs after the mover's state each step and returns a state name or null (keep the built-in `facts.base`); the clip comes from `clips`
|
|
53
|
+
like any other state, a speed change stays `engine.mod('move.speed')`.
|
|
54
|
+
```js
|
|
55
|
+
createPlayer({ ...presets.player.thirdPerson, model: hero, clips: { crouch: 'Crouch', glide: 'Glide' },
|
|
56
|
+
states: (c, f) => f.grounded && engine.input.down('crouch') ? 'crouch' : !f.grounded && f.vy < 0 && gliding ? 'glide' : null });
|
|
57
|
+
```
|
|
58
|
+
Deep water follows `water`: `'swim'` (default), `'block'` (never enters), `'wade'` (walks the bottom), or `(c, { depth }) => mode` per spot;
|
|
59
|
+
`character:water { in, mode, depth }` fires on each change.
|
|
51
60
|
For smooth walk/run blending, use `animation` instead of `clips` and write a `move` blend tree (when the model has no walk/run states, move is used
|
|
52
61
|
automatically; the `speed` parameter is in m/s):
|
|
53
62
|
```js
|
|
@@ -57,19 +66,34 @@ engine.characters.createPlayer({ ...presets.player.thirdPerson, model: hero, ani
|
|
|
57
66
|
jump: { clip: 'Jump', loop: false },
|
|
58
67
|
} } });
|
|
59
68
|
```
|
|
60
|
-
The default transition time comes from the style
|
|
69
|
+
The default transition time comes from the style's `style.character.animation.fade`.
|
|
61
70
|
|
|
62
|
-
**By asset name.** `model` also takes the name of a registered model asset,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
registered names; a failed load keeps the placeholder and warns once; a character disposed before loading ends never gets the model.
|
|
71
|
+
**By asset name.** `model` also takes the name of a registered model asset: a file model, or a procedural builder. The character is built at once
|
|
72
|
+
with a gray capsule; when the asset loads, a skeleton-correct copy replaces it under the same root, so position, facing, state, collision and the
|
|
73
|
+
world view stay. Then `ready` turns true, `whenReady` settles and `character:model` is emitted. A name no model asset has throws with the registered
|
|
74
|
+
names; a failed load keeps the capsule and warns once; a character disposed before loading ends never gets the model.
|
|
67
75
|
```js
|
|
68
76
|
engine.assets.manifest({ models: { hero: '/models/hero.glb' } });
|
|
69
|
-
const p = engine.characters.createPlayer({ ...presets.player.thirdPerson, model: 'hero' }); //
|
|
77
|
+
const p = engine.characters.createPlayer({ ...presets.player.thirdPerson, model: 'hero' }); // capsule now, the hero once loaded
|
|
70
78
|
await p.whenReady; // p.anim is set from here (unless the load failed)
|
|
71
79
|
```
|
|
72
80
|
|
|
81
|
+
## 3b. Procedural bodies are assets too (`model: 'humanoid'`)
|
|
82
|
+
Character bodies are assets, never style: every character picks one with `model`, the same path for a GLB and a procedural builder. an asset
|
|
83
|
+
pack can supply a code-built humanoid (e.g. box limbs, swung by the engine while walking, running, swimming, jumping); a builder is built at once, so its joints
|
|
84
|
+
(`player.armL`, `legR`...) exist right after `createPlayer`. Without `model` (and without `rig`) a character is a gray capsule, warned once.
|
|
85
|
+
```js
|
|
86
|
+
import { assets } from './assets.js'; // an asset pack of yours (or a published one) with a 'humanoid' builder
|
|
87
|
+
engine.assets.manifest(assets);
|
|
88
|
+
engine.characters.createPlayer({ ...presets.player.thirdPerson, model: 'humanoid' });
|
|
89
|
+
engine.npcs.add({ id: 'fisher', model: 'humanoid', colors: { body: 0x4f6d8f } }); // per-character part colors
|
|
90
|
+
```
|
|
91
|
+
- **Colors**: the humanoid's parts use material roles `cloth`, `skin`, `trousers`, `hair`, so any style tints every humanoid
|
|
92
|
+
(`style: [basePack, { materials: { cloth: { color: 0x3a6ea5 } } }]`); `colors: { body, skin, legs, hair }` recolors one character.
|
|
93
|
+
- **Your own procedural body**: a builder that returns an Object3D with `root.userData.rig = { body: 'hips', head: 'head', joints: ['armL'],
|
|
94
|
+
limbs: [{ joint: 'legL', offset: 0, amp: 0.9, kind: 'leg' }] }` (object names, so it survives copies and baking) animates like the humanoid; mark
|
|
95
|
+
meshes `userData.part = 'body'` for `colors`. A hand-built one-off passes `{ rig }` instead ([02-npc](02-npc.md)).
|
|
96
|
+
|
|
73
97
|
## 4. Non-character objects (a dog, a windmill, a door)
|
|
74
98
|
```js
|
|
75
99
|
const dog = await engine.assets.model('dog'); engine.add(dog);
|
|
@@ -92,7 +116,7 @@ anim.dispose(); // no longer
|
|
|
92
116
|
(step's frameEvery) and a model being torn down when it is far away all make it drift from game time. When an attack lands, cooldowns, recovery and
|
|
93
117
|
"finish the swing before moving" are timed in fixed steps:
|
|
94
118
|
```js
|
|
95
|
-
engine.input.
|
|
119
|
+
engine.input.action('attack', { label: 'Attack', keys: ['KeyF', 'Mouse0'] }); // no module binds it for you
|
|
96
120
|
let t = -1; // seconds since the swing started (-1 = not swinging); put it in a world record if it must be saved
|
|
97
121
|
engine.onFixed(dt => {
|
|
98
122
|
if (t < 0) { if (!engine.input.pressed('attack')) return; t = 0; }
|