Materials and Shading
Overview
This fork ships three working material classes — LambertMaterial, PhongMaterial (which extends LambertMaterial), and PbrMaterial — each assigned to a Node alongside its entity. All three work through solid color and scalar properties. The Texture class itself is not implemented in this fork (its constructor raises NotImplementedError), so texture-image slots on any material cannot actually be populated — stick to the color and scalar properties documented below.
LambertMaterial: flat diffuse shading
LambertMaterial models simple diffuse shading with a diffuse color, an ambient color, an emissive color, and a transparency value:
from aspose.threed import Scene
from aspose.threed.entities import Box
from aspose.threed.shading import LambertMaterial
from aspose.threed.utilities import Vector3
scene = Scene()
box = Box(length=2.0, width=1.0, height=1.0)
material = LambertMaterial()
material.diffuse_color = Vector3(0.2, 0.6, 0.9)
scene.root_node.create_child_node("Crate", entity=box.to_mesh(), material=material)
scene.save("crate.gltf")LambertMaterial also accepts an optional name argument at construction, and exposes transparent_color in addition to diffuse_color, ambient_color, emissive_color, and transparency.
PhongMaterial: adding specular highlights
PhongMaterial extends LambertMaterial with specular_color, specular_factor, and shininess, on top of every LambertMaterial property:
from aspose.threed.shading import PhongMaterial
from aspose.threed.utilities import Vector3
material = PhongMaterial("RedMaterial")
material.diffuse_color = Vector3(1.0, 0.0, 0.0)
material.specular_color = Vector3(1.0, 1.0, 1.0)
material.shininess = 32.0Higher shininess values produce a tighter, sharper specular highlight; lower values spread it out.
PbrMaterial: metallic/roughness workflow
PbrMaterial follows the metallic/roughness model: albedo is the base color, and metallic_factor / roughness_factor are plain floats in the 0.0-1.0 range:
from aspose.threed import Scene
from aspose.threed.entities import Sphere
from aspose.threed.shading import PbrMaterial
from aspose.threed.utilities import Vector3
scene = Scene()
sphere = Sphere()
material = PbrMaterial(albedo=Vector3(0.8, 0.1, 0.1))
material.metallic_factor = 0.9
material.roughness_factor = 0.2
scene.root_node.create_child_node("Ball", entity=sphere.to_mesh(), material=material)
scene.save("ball.stl")PbrMaterial also exposes emissive_color, occlusion_factor, and transparency as plain values — only the *_texture properties (albedo_texture, normal_texture, occlusion_texture, emissive_texture, metallic_roughness) require a Texture instance, which this fork cannot construct.
Setting multiple properties at once
Every property on these three classes can be read back immediately after setting it, which is useful for verifying a material was configured correctly before export:
from aspose.threed.shading import PbrMaterial
from aspose.threed.utilities import Vector3
material = PbrMaterial()
material.albedo = Vector3(1.0, 0.5, 0.2)
material.metallic_factor = 0.8
material.roughness_factor = 0.3
material.transparency = 0.5
material.emissive_color = Vector3(0.1, 0.2, 0.3)Tips and Best Practices
- Choose LambertMaterial for flat, non-specular shading; PhongMaterial when you need a specular highlight; PbrMaterial when the target format (glTF is the most common) expects a metallic/roughness workflow.
- Do not assign anything to a *_texture property — Texture cannot be constructed in this fork, so there is no working value to put there.
- Pass a name to LambertMaterial/PhongMaterial (or set node.material directly) so exported formats that preserve material names (glTF, COLLADA, 3MF) keep a meaningful label.
- Keep color values as Vector3 instances in the 0.0-1.0 range for predictable results across exporters.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
| NotImplementedError constructing Texture() | Texture is not implemented in this fork | Do not use texture images; use the material’s solid color and scalar properties instead |
| Material looks unlit / flat after export | LambertMaterial has no specular component by design | Use PhongMaterial if a specular highlight is required |
| PbrMaterial.metallic_factor has no visible effect in some viewers | The exported format or viewer does not fully honor the metallic/roughness model | Confirm the target format is one with PBR support (glTF) and that the viewer implements it |
FAQ
Can I load a texture image file and apply it to a material?
No — Texture’s constructor raises NotImplementedError in this fork, so there is no way to build a texture object to assign to any material’s texture slots.
Is PhongMaterial a separate class from LambertMaterial, or built on top of it?
PhongMaterial extends LambertMaterial, so every LambertMaterial property (diffuse_color, ambient_color, emissive_color, transparency) is also available on a PhongMaterial instance.
Which material class should I use when exporting to glTF?
PbrMaterial, since glTF 2.0’s native material model is metallic/roughness-based and maps directly onto PbrMaterial’s albedo, metallic_factor, and roughness_factor.
API Reference Summary
| Class/Method | Description |
|---|---|
| LambertMaterial | diffuse_color, ambient_color, emissive_color, transparent_color, transparency |
| PhongMaterial | LambertMaterial plus specular_color, specular_factor, shininess |
| PbrMaterial | albedo, metallic_factor, roughness_factor, emissive_color, occlusion_factor, transparency |
| Material.get_texture / set_texture | Present in the API surface; not usable in this fork (Texture cannot be constructed) |
| Node.material | Where a material is attached to the scene graph |