Skip to content

Class: BodyMaterial

Example

ts
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

ts
new BodyMaterial(
   type, 
   params?, 
   options?): BodyMaterial;

Parameters

ParameterType
typeLibBodyType
paramsParamMap
optionsBodyMaterialOptions

Returns

BodyMaterial

Accessors

material

Get Signature

ts
get material(): ShaderMaterial;

THREE.ShaderMaterial ready to assign to a THREE.Mesh.

Returns

ShaderMaterial


params

Get Signature

ts
get params(): ParamMap;

Snapshot of the current scalar/string params (excludes light config).

Returns

ParamMap

Methods

tick()

ts
tick(elapsed): void;

Updates time (call every frame in the render loop).

Parameters

ParameterType
elapsednumber

Returns

void


setParams()

ts
setParams(partial): void;

Updates one or more params without rebuilding the material.

Parameters

ParameterType
partialParamMap

Returns

void


setType()

ts
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

ParameterType
typeLibBodyType

Returns

void


setVertexColors()

ts
setVertexColors(enabled): void;

Toggles vertex-colour support. The material is rebuilt.

Parameters

ParameterType
enabledboolean

Returns

void


setLight()

ts
setLight(__namedParameters?): void;

Updates the light config. Only provided fields are changed.

Parameters

ParameterType
__namedParametersBodyLightUpdate

Returns

void


setFlatLighting()

ts
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

ParameterType
enabledboolean

Returns

void


setSeaLevel()

ts
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

ParameterType
simplexThresholdnumber

Returns

void


setViewDim()

ts
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

ParameterType
valuenumber

Returns

void


setPalette()

ts
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

ParameterType
paletteTerrainLevel[] | null | undefined

Returns

void


dispose()

ts
dispose(): void;

Releases the material's GPU memory.

Returns

void

Distribué sous la licence indiquée dans le dépôt.