MobMaterialsMixin

Qualified name: algan.animatable\_base.mob\_materials.MobMaterialsMixin

class MobMaterialsMixin[source]

Bases: object

set_shader / set_fragment_shader / set_material – all must be called before the mob is spawned.

Methods

get_shader_params

Get this Mob's current shader parameter values, by name.

set_fragment_shader

Set a per-fragment shader for this Mob and its descendants.

set_material

Give this Mob a material, deciding how it looks under light.

set_shader

Set the per-vertex lighting shader for this Mob and its descendants.

get_shader_params()[source]

Get this Mob’s current shader parameter values, by name.

The parameters a shader or material installed as animatable attributes, e.g. {"roughness": ..., "metalness": ...}. Useful for inspecting what a material actually set, or copying it onto another Mob.

Returns:

Parameter names mapped to their current values; empty if the Mob has no shader-specific parameters.

Return type:

dict

set_fragment_shader(shader)[source]

Set a per-fragment shader for this Mob and its descendants.

Shading runs once per rendered fragment rather than once per vertex as with set_shader(), so effects can vary smoothly across a surface instead of being interpolated between its corners – at a higher render cost.

shader is a FragmentStage (a Taichi @ti.func stage plus its parameter specs), a built-in material shader function (e.g. phong_shader), or a list of these forming a pipeline run left-to-right – each stage receives the previous stage’s output color. For example mob.set_fragment_shader([cosine_color, phong_shader]) recolors each fragment with a cosine wave and then lights the result with Blinn-Phong.

The stages’ parameters become animatable attributes (duplicate names across stages are suffixed). Setting a fragment shader forces the deterministic renderer’s per-fragment path on for any scene the mob appears in; it is ignored by the Monte Carlo / physical path tracer.

Animation

Not animated, and must be called before the Mob is spawned. The stage parameters it registers are animatable afterwards, so mob.wave_speed = 3 animates like any other attribute.

Parameters:

shader – A fragment stage, a built-in material shader, or a list of these forming a pipeline. None clears the fragment shader.

Returns:

This Mob, so calls can be chained.

Return type:

Mob

Raises:

.ModifiedProtectedAttributeError – If called on a Mob that has already been spawned.

set_material(material)[source]

Give this Mob a material, deciding how it looks under light.

The Three.js-style entry point to appearance, and the one to reach for first: the material picks the lighting shader and fills in its values, so MeshStandardMaterial(metalness=1.0, roughness=0.2) gives you polished metal without touching a shader directly. Applies to this Mob and all its descendants.

The material’s numeric and color properties land on the Mob as animatable attributes – mob.roughness, mob.emissive_intensity and so on – so they can be animated afterwards like any other. Its color drives the Mob’s base color and its opacity the Mob’s maximum opacity.

The material is also the sole public source of ray-transport properties. metalness and roughness drive reflections, while a transmissive MeshPhysicalMaterial supplies ior for refraction. This mirrors the Three.js material workflow; there are no separate mob-level reflectivity, roughness, or refractive-index setters.

Its texture maps are forwarded onto the geometry, which is what samples them: map, normal_map, roughness_map and metalness_map each take a file path or an [H, W, C] image and are sampled bilinearly per fragment. That needs per-vertex UVs, so it reaches a Surface (a Sphere, Cylinder, ImageMob, …) or a TriangleMesh built with uvs; on anything else the maps are ignored, with a warning. A forwarded map is static – unlike the scalar properties above it is not an animatable attribute – except map on a Surface, which lands on the animatable color_texture.

Every built-in material class shades per fragment in the render kernel, so it sees every light type, receives shadows, and its look no longer depends on the mesh’s tessellation. Only a custom per-vertex shader (set_shader with a plain function) is baked into vertex colors before the frame renders – lit only by a plain PointLight and never receiving shadows. Applying one under a lighting rig that asks for more than that warns, rather than quietly dropping the difference.

Animation

Not animated, and must be called before the Mob is spawned, since it sets the shader. The properties it installs are animatable from then on.

Parameters:

material – A Material instance, e.g. MeshStandardMaterial(metalness=1.0, roughness=0.2). A material built with the default color=None leaves the Mob’s own color alone, so material and color can be chosen independently.

Returns:

This Mob, so calls can be chained.

Return type:

Mob

Raises:

.ModifiedProtectedAttributeError – If called on a Mob that has already been spawned.

Examples

Example: Example1MobSetMaterial

from algan import *

sphere = Sphere(color=BLUE)
sphere.set_material(MeshStandardMaterial(metalness=1.0, roughness=0.15))
sphere.spawn()
sphere.rotate(180, UP)

Scene.save_video()
set_shader(shader)[source]

Set the per-vertex lighting shader for this Mob and its descendants.

The shader decides how the Mob responds to light. Its parameters become animatable attributes on the Mob, so a shader with a roughness parameter gives you mob.roughness to animate. Most scenes should set a set_material() instead, which picks the matching shader and fills in its values.

Animation

Not animated, and must be called before the Mob is spawned – the shader cannot be changed afterwards. To re-shade something already on screen, swap in a fresh clone:

with Off():
    new_mob = mob.clone(spawn=False)
    new_mob.set_shader(new_shader)
    mob.despawn()
    new_mob.spawn()
    mob = new_mob
Parameters:

shader – Shading function used at render time, e.g. phong_shader or standard_shader. None clears the shader, leaving the Mob unlit.

Returns:

This Mob, so calls can be chained.

Return type:

Mob

Raises:

.ModifiedProtectedAttributeError – If called on a Mob that has already been spawned.

See also

set_material()

Three.js-style materials, the usual entry point.

set_fragment_shader()

Shade per fragment instead of per vertex.