MobMaterialsMixin¶
Qualified name: algan.animatable\_base.mob\_materials.MobMaterialsMixin
- class MobMaterialsMixin[source]¶
Bases:
objectset_shader/set_fragment_shader/set_material– all must be called before the mob is spawned.Methods
Get this Mob's current shader parameter values, by name.
Set a per-fragment shader for this Mob and its descendants.
Give this Mob a material, deciding how it looks under light.
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.shaderis aFragmentStage(a Taichi@ti.funcstage 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 examplemob.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 = 3animates like any other attribute.- Parameters:
shader – A fragment stage, a built-in material shader, or a list of these forming a pipeline.
Noneclears the fragment shader.- Returns:
This Mob, so calls can be chained.
- Return type:
- 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_intensityand so on – so they can be animated afterwards like any other. Its color drives the Mob’s base color and itsopacitythe Mob’s maximum opacity.The material is also the sole public source of ray-transport properties.
metalnessandroughnessdrive reflections, while a transmissiveMeshPhysicalMaterialsuppliesiorfor 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_mapandmetalness_mapeach take a file path or an[H, W, C]image and are sampled bilinearly per fragment. That needs per-vertex UVs, so it reaches aSurface(aSphere,Cylinder,ImageMob, …) or aTriangleMeshbuilt withuvs; 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 – exceptmapon a Surface, which lands on the animatablecolor_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_shaderwith a plain function) is baked into vertex colors before the frame renders – lit only by a plainPointLightand 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
Materialinstance, e.g.MeshStandardMaterial(metalness=1.0, roughness=0.2). A material built with the defaultcolor=Noneleaves the Mob’s own color alone, so material and color can be chosen independently.- Returns:
This Mob, so calls can be chained.
- Return type:
- 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
roughnessparameter gives youmob.roughnessto animate. Most scenes should set aset_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_shaderorstandard_shader.Noneclears the shader, leaving the Mob unlit.- Returns:
This Mob, so calls can be chained.
- Return type:
- 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.