Official Codebase of 3DCodeVerse
src/lib/ — the shipped effect library, an optional toolbox
Harness code copied into the workspace by 3dcode init, compiled and rendered on THIS
renderer; it carries the depth and fog chunks a hand-written shader silently loses. Importing
it is allowed where "never import a helper SDK" forbids everything else; edits to it are
reverted. Import with a relative path (src/zones/x.js and src/assets/x.js:
'../lib/grass.js'; src/scene.js: './lib/grass.js'), and only the names you CALL (120
unused imported names were measured over six scenes). Each module's JSDoc lists its options
and bounds: an option left out takes its default, an invalid one throws a RangeError naming it.
| Want | Call |
|---|---|
| a close-view fractured rock or a talus field | makeRock({ type: 'sandstone', size: [2, 1.5, 2], seed, moisture: 0.2 }) · makeRockField — lib/rock.js; sandstone / granite / basalt; rests at local y≈0 |
| a grassy surface | makeGrass({ extent, density, height, heightAt, patchy }) — lib/grass.js |
| a complete near/middle-distance tree or shrub | makeTree({ species: 'oak', height: 6, crownRadius: 2.5, leafDensity: 1, seed, wind: { dir: [1,0.3], strength: 0.5, speed: 1 } }) · makeShrub — lib/tree.js; oak / birch / willow, separate leaf cards, root at y=0, envelope in userData.bounds; heavy by default (species default 10–16 leafSegments for close views) — leafSegments: 4, lower maxLeaves / leafDensity for repeats, distant imposters when leaves are unresolved |
| trees, bushes, leaves | patchLeafSSS · patchWind · patchRootContact — lib/foliage_shade.js |
| ground and cliff geometry | ground({ size, rand: mulberry32(seed), relief, flat }) → { mesh, height } (the env's heightAt must return its real height; with no seeded rand it is flat; a floor, terraces or a canyon are not this call) · cliff({ length, height, rand }) — lib/terrain.js |
| countryside continuing beyond the content | makeOutskirts({ inner, baseY, heightAt, shellRadius, colors, seed }) — lib/environment.js; one option for a rural setting |
| the sun, the fill and the baked environment | sunRig({ azimuth, elevation, bounds }) — lib/environment.js → { sun, fill, sunDisc, envTex, sunDir }; add the lights, scene.environment = rig.envTex |
| a rectangular interior's walls, ceiling and openings | roomShell({ center, extents, openings, thickness, wallColor, ceilingColor, glazed, frameColor, bay }) — lib/environment.js; walls sit OUTWARD of the box you pass (its faces are the inner faces; it need not be the plan bounds), openings are cut as span / sill / lintel panels; glazed: true for a conservatory / greenhouse |
| the sky itself | makeSky(scene, { rig }) — lib/sky.js; the dome IS the backdrop; keeps a scene.background already set and gives an unset one its horizon colour |
| paper, wax, jade, petals; oil film, beetle shell | patchTranslucency · patchIridescence — lib/finish.js |
| a textured standard material without a texture file | brick · granite · cobble · asphalt · weatheredWood · brushedSteel · fabric · foliage · soil · skin · glass (21 in all) · tint(mat, variant) — lib/materials.js |
| noise on the CPU | fbm2 · fbm3 · mulberry32 · displaceY — lib/noise.js |
| your own shader, safely | makeShaderMaterial · patchStandard · shadowLike · tickShaders · clonePatchedMaterial — lib/shader.js |
| a scoped synchronous offscreen capture | withRendererState(renderer, callback) — lib/shader.js; restores target / viewport / scissor / tone mapping / clear state even after an error (transforms and visibility stay yours) |
| explicit cleanup for a procedural group | snapshotResources(group) · attachDisposal(group, resources) — lib/lifecycle.js; textures are borrowed unless added, disposal is idempotent and ignores later-added props |
Rules that apply to all of them:
patch*entries chain — any number on one material, in any order; prefix your own GLSL helpers (the library's areastra…). Copy a patched material withclonePatchedMaterial, not.clone().- Moving factories carry
userData.update(t, dt)(absolute seconds) anduserData.dispose(): store what they return and callupdateexactly ONCE per frame from the zone'suserData.update. Anything built withpatchStandardis driven instead by onetickShaders(scene, t)inscene.js'supdate. Their dimensions and height queries are LOCAL;userData.sampleHeight(x, z)returns the surface height ornulloff the patch. - Shadows: trees cast real moving shadows by default, grass behind
shadows: true; a displaced lattice of your own needsshadowLikeor the shadow is cast by the undisplaced geometry. - This renderer: a post chain is on (GTAO, selective emissive bloom, identity grade unless
scene.userData.grade = { exposure, contrast, saturation, warmth, tint }); ACES at exposure 1.0, sRGB out;logarithmicDepthBufferis off (the library's log-depth chunks compile to nothing — leave them). PasssunDir/ the rig; never hardcode a light colour in an effect.
A closed displaced surface for a crown (an icosahedron with noise) has no silhouette, lets no
light through and carries one hue — measured hue spread 3.6° vs 9.4° for separate leaf cards
(a photograph: 25–45). Any construction that gets there is fine; makeTree is the shipped one.