Class: BodyMaterial
Example
const planet = new BodyMaterial('rocky', { roughness: 0.8, colorA: '#c87941' })
sphere.material = planet.material
// Render loop
planet.tick(elapsed)
// Live-update params without rebuilding
planet.setParams({ lavaAmount: 0.5 })
// Switch type (rebuilds the material, keeps common params)
planet.setType('gaseous')
// Light configuration
planet.setLight({ kelvin: 3500, intensity: 1.8, direction: [0, 1, 0.5] })
planet.dispose()Constructors
Constructor
new BodyMaterial(
type,
params?,
options?): BodyMaterial;Parameters
| Parameter | Type |
|---|---|
type | LibBodyType |
params | ParamMap |
options | BodyMaterialOptions |
Returns
BodyMaterial
Accessors
material
Get Signature
get material(): ShaderMaterial;THREE.ShaderMaterial ready to assign to a THREE.Mesh.
Returns
ShaderMaterial
params
Get Signature
get params(): ParamMap;Snapshot of the current scalar/string params (excludes light config).
Returns
Methods
tick()
tick(elapsed): void;Updates time (call every frame in the render loop).
Parameters
| Parameter | Type |
|---|---|
elapsed | number |
Returns
void
setParams()
setParams(partial): void;Updates one or more params without rebuilding the material.
Parameters
| Parameter | Type |
|---|---|
partial | ParamMap |
Returns
void
setType()
setType(type): void;Switches the shader type. The material is rebuilt. Params that exist in the new type are preserved; the others are reset to defaults.
Parameters
| Parameter | Type |
|---|---|
type | LibBodyType |
Returns
void
setVertexColors()
setVertexColors(enabled): void;Toggles vertex-colour support. The material is rebuilt.
Parameters
| Parameter | Type |
|---|---|
enabled | boolean |
Returns
void
setLight()
setLight(__namedParameters?): void;Updates the light config. Only provided fields are changed.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | BodyLightUpdate |
Returns
void
setFlatLighting()
setFlatLighting(enabled): void;Enables / disables flat lighting (top-down view). When enabled, diff = 1 over the whole surface — removes directional gradients and dark areas caused by the surface normal when seen from above.
Parameters
| Parameter | Type |
|---|---|
enabled | boolean |
Returns
void
setSeaLevel()
setSeaLevel(simplexThreshold): void;Moves the liquid-mask waterline in simplex-noise space. Silently ignored when the material was built without a liquid mask (non-rocky or no surface liquid). Drives the uSeaLevel uniform consumed by liquidMask.glsl — cracks/lava/craters flip their submerged gating as the threshold slides.
Parameters
| Parameter | Type |
|---|---|
simplexThreshold | number |
Returns
void
setViewDim()
setViewDim(value): void;Backdrop attenuation in [0, 1] driving uViewDim on gas.frag. 1.0 = full-intensity (Shader view); lower values fade the disc into the background (Sol view). No-op on shaders that don't consume the uniform.
Parameters
| Parameter | Type |
|---|---|
value | number |
Returns
void
setPalette()
setPalette(palette): void;Replaces the terrain palette uniforms at runtime (no material rebuild). Pass null/undefined to clear the palette and fall back to the legacy two-tone gradient.
Parameters
| Parameter | Type |
|---|---|
palette | TerrainLevel[] | null | undefined |
Returns
void
dispose()
dispose(): void;Releases the material's GPU memory.
Returns
void