Log inGet started
World

Painted Valley

Branchmain
Branchesmain
Commit12ad3f264b

README.md

paintedValley/wanderer

The wanderer of Painted Valley (blendi/painted-valley on Patch; code MIT, art CC0), ported: the walker of src/valley/main.js, the figure (src/figure/man.js, animator.js, player.js, input.js, camera.js, cloak.js), his cel paint (src/valley/wanderer.js) and his footsteps (src/valley/sounds.js), with Patch's starter man (public/figure/starter-man.glb, starter-man-clips.glb) and the five Kenney footsteps (public/audio, CC0).

How it is put together

The world is multiplayer, so the wanderer is a player's body: the scene's PlayerPrototype carries

  • body: Asset on paintedValley.wanderer.figure.starter_man (the imported bundle) + the paintedValley.wanderer.Wanderer component;
  • CameraRig (OwnerOnly): Camera whose behaviour is paintedValley.wanderer.Follow (FOV 52), + AudioListener.

require("paintedValley.wanderer.wanderer").setupPrototype(body, rig) does exactly that from a scene's build.luau.

On every peer Wanderer dresses the man (figure/dress: cel materials, hat, cloak) and poses him through the engine's pose sinks (skeleton.bindPose / applyPose), from a Luau port of the original's three.js skeleton and mixer (figure/skel) and animator (figure/animator):

  • the local player's: main.js's updateWanderer in third person (figure/player moving him, the Follow camera, foot placement, cloth, footsteps when a foot comes down, uWalker for his shadow, meadow.bend/setPusher for the grass) and main.js's own first-person walker on V (WALK 4.2, RUN 6.3, jump 4.4, gravity 12.5, eye 1.68, bob, dip, FOV 68). It keeps v.player ({x, y, z, vx, vz, onGround}) and states what he does on the avatar channel.
  • other players': played from their avatar channel (speed, move angle, mode, the one-shot clip and how far through it, strafe, tired, on ground, turn rate, acceleration, where his camera looks) through the same animator, feet, hat and cloth.

wanderer.module is the part's entry for the valley's scene driver (build, update, destroy) and carries player, tagEntities (+ tagsVersion), setThird, standAt, third and camera (the local shot).

Differences from the original, and why

  • The character controller. The original moves a Rapier capsule (radius 0.28, height 1.8, offset 0.02, snap 0.45, climbs 46°, slides from 52°, autostep 0.3) through a Rapier world of a heightfield (the meadow's heights a metre apart) and the trees' and stones' cylinders. Here figure/colliders holds the same shapes (core.groundAt; cylinders of the same radii and heights) and move meets them as Rapier's controller does on them: a vertical cylinder against a capsule is a circle push-out, the feet follow the heightfield, ground steeper than 46° can't be climbed. Rapier's slide on >52° moves him only by the controller's -0.1 m/s push and is left out; autostep never applies (the only obstacles are 1 m and taller). No engine physics bodies: they would need a 1141 x 1141 heightfield built on every peer for shapes this simple. The foot ray meets the ground and the top of a stone or trunk from above; a ray that starts inside one is not a hit (Rapier would answer 0 and lift the foot 45 cm: only when a foot overlaps a trunk).
  • Clips. The engine's importer adds a one-key track for every bone and property a clip does not animate (with the clip rig's rest). three.js plays only the file's tracks, so these are dropped (figure/man): the legs and head keep the man's own proportions, as in the original.
  • Mixer. three.js skips writing a property whose mixed value equals last frame's; here every bone is written every frame. Bone scale (1 everywhere) is not carried.
  • The ink line. The frame cannot read fragment alpha on this engine (deferred: alpha is coverage). cel still returns the original's alpha; the frame tags the wanderer's entities from tagEntities ({entity, tag}; the casualsuit {entity, shader = "paintedValley.wanderer.inkTag", properties} for its shirt and trousers numbers). The list changes as players come and go: tagsVersion goes up each time.
  • Per-vertex data. The casualsuit carries its bind height about the split (0.98 m) in vertex colour, so the shirt and trousers turn exactly where vBind.y < uSplit turned; the cloak carries its fold depth in vertex colour (0.5 + fold * 8) and its cloth coordinates as uv.
  • Hat and cloak are local, unsynced entities (Model on runtime meshes) placed every frame; the cloth mesh is re-sent each frame. No cast shadows: the original renders none; his shadow is uWalker on the meadow.
  • Sound. The footstep OGGs are Vorbis, which this engine build cannot decode: they are WAVs decoded losslessly from the repo's files. The ±0.15 random pan is a spatial one-shot a metre from the ears (the CameraRig's AudioListener). The five Sonniss ambiences are not in the repo (MISSING_ASSETS.md); sounds plays any put back as audio/<grass|leaves|summer|lake|crickets>.soundClip, at the original's levels, from their start (an Audio source has no start offset).
  • Multiplayer (new). Every player is a wanderer. Another player's gait phase is advanced from his speed on this peer, not received (his feet stay planted; his phase can differ from what his own peer shows). Another player's cloth far off is worked out in bursts (beyond 50 m every other frame, beyond 120 m every fourth). Only the local player casts uWalker (the shaders have one walker) and is heard; another player's walk bends the grass here too. A player in first person is seen by others walking (the strafe blend at his speed, facing his eyes' way).
  • Input. The original's first person reads only keys and the mouse; the pad and touch sticks move and look there too. V is also the pad's R3, and there are touch controls. When the pointer is taken or given back, the cursor's jump to the middle of the view is not read as a look (the browser's pointer lock has no such jump).
  • Start. He starts where the PlayerSpawn puts him (the main scene: START), facing down the valley as main.js does. main.js's load-time warm-up (44 walked frames to compile shaders) is not needed here.
  • Edit mode. Component updates don't run while edit mode is paused, so the prototype's body shows the starter man in his bind pose, undressed, until play.

Cost

About 3 ms a frame for the local wanderer on the test machine (the cloth about 2 ms, the animator, IK and the rest about 1 ms), measured with localBody:state().ms.

Files

  • figure/starter_man.bundle, figure/starter-man-clips_anims/*.animation: the imported man and clips.
  • audio/footstepOnGrass1-5Medium.soundClip: the footsteps.
  • figure/{q,man,skel,animator,player,colliders,camera,input,cloak,dress}.module, sounds.module, wanderer.module.
  • Wanderer.component (body), Follow.component (camera behaviour), controls.inputMap.
  • cel.shader (the paint), inkTag.shader (the casualsuit's tag for the frame's line pass).
  • wandererTest.scene: the part's own test scene.