LambertMaterial and PhongMaterial — Aspose.3D FOSS for Python API Reference

Package: aspose.threed.shading (aspose-3d-foss)

Aspose.3D FOSS provides two material classes in the classic shading hierarchy:

  • LambertMaterial: diffuse matte shading (no specularity)
  • PhongMaterial: extends Lambert with specular highlights and shininess

Both are assigned to a Node via node.material. Colors are set using Vector3(r, g, b) where components are in [0.0, 1.0].


LambertMaterial

class LambertMaterial(Material):

Inheritance

A3DObjectMaterialLambertMaterial

Constructor

LambertMaterial(name: str = None)

Properties

PropertyTypeDescription
ambient_colorVector3 | NoneAmbient light contribution. Default None (unset).
diffuse_colorVector3 | NoneBase color under diffuse illumination. Default None.
emissive_colorVector3 | NoneSelf-emitted light color. Default None.
transparent_colorVector3 | NoneTransmission/transparency tint color. Default None.
transparencyfloatOpacity level: 0.0 = fully opaque, 1.0 = fully transparent. Clamped to [0.0, 1.0].

Class Constants

ConstantValueDescription
MAP_DIFFUSE"Diffuse"Key for a diffuse texture map.
MAP_AMBIENT"Ambient"Key for an ambient texture map.
MAP_EMISSIVE"Emissive"Key for an emissive texture map.
MAP_SPECULAR"Specular"Key for a specular texture map.
MAP_NORMAL"Normal"Key for a normal map.

PhongMaterial

class PhongMaterial(LambertMaterial):

Inheritance

A3DObjectMaterialLambertMaterialPhongMaterial

Inherits all LambertMaterial properties and adds:

Additional Properties

PropertyTypeDescription
specular_colorVector3 | NoneColor of specular (shiny) highlights. Default None.
specular_factorfloatScale of the specular contribution. Default 0.0.
shininessfloatPhong shininess exponent. Higher = tighter/smaller highlights. Default 0.0.
reflection_colorVector3 | NoneEnvironment reflection tint. Default None.
reflection_factorfloatBlend amount for reflection. Default 0.0.

Usage Examples

Lambert Matte Material

from aspose.threed import Scene
from aspose.threed.entities import Mesh
from aspose.threed.shading import LambertMaterial
from aspose.threed.utilities import Vector3, Vector4

scene = Scene()

# Build a simple triangle mesh
mesh = Mesh()
mesh.control_points.append(Vector4(0, 0, 0, 1))
mesh.control_points.append(Vector4(1, 0, 0, 1))
mesh.control_points.append(Vector4(0.5, 1, 0, 1))
mesh.create_polygon(0, 1, 2)

# Create a matte red material
mat = LambertMaterial("red-matte")
mat.diffuse_color = Vector3(0.8, 0.1, 0.1)    # R, G, B in [0, 1]
mat.ambient_color = Vector3(0.1, 0.05, 0.05)

node = scene.root_node.create_child_node("triangle", mesh)
node.material = mat

scene.save("lambert.obj")

Phong Shiny Material

from aspose.threed import Scene
from aspose.threed.entities import Mesh
from aspose.threed.shading import PhongMaterial
from aspose.threed.utilities import Vector3, Vector4

scene = Scene()

mesh = Mesh()
mesh.control_points.append(Vector4(0, 0, 0, 1))
mesh.control_points.append(Vector4(1, 0, 0, 1))
mesh.control_points.append(Vector4(0.5, 1, 0, 1))
mesh.create_polygon(0, 1, 2)

mat = PhongMaterial("shiny-blue")
mat.diffuse_color = Vector3(0.1, 0.2, 0.8)   # blue
mat.specular_color = Vector3(1.0, 1.0, 1.0)  # white highlights
mat.specular_factor = 0.5
mat.shininess = 64.0                           # tight specular lobe
mat.ambient_color = Vector3(0.05, 0.05, 0.1)

node = scene.root_node.create_child_node("mesh", mesh)
node.material = mat

scene.save("phong.obj")

Semi-Transparent Material

from aspose.threed.shading import LambertMaterial
from aspose.threed.utilities import Vector3

mat = LambertMaterial("glass")
mat.diffuse_color = Vector3(0.7, 0.9, 1.0)   # faint blue tint
mat.transparency = 0.7                         # 70% transparent

Read Material from Imported Scene

from aspose.threed import Scene
from aspose.threed.shading import LambertMaterial, PhongMaterial

scene = Scene()
scene.open("model.obj")

def inspect_node(node):
    if node.material:
        m = node.material
        kind = "Phong" if isinstance(m, PhongMaterial) else "Lambert"
        print(f"Node '{node.name}': {kind}: diffuse={m.diffuse_color}")
        if isinstance(m, PhongMaterial):
            print(f"  shininess={m.shininess}")
    for child in node.child_nodes:
        inspect_node(child)

inspect_node(scene.root_node)

PbrMaterial

class PbrMaterial(Material):

Inheritance

A3DObjectMaterialPbrMaterial

PBR (Physically Based Rendering) material. Used by glTF 2.0 and other PBR-capable formats. Assigned to a Node via node.material.

Constructor

PbrMaterial(name: str = None, albedo: Vector3 = None)

Properties

PropertyTypeDescription
albedoVector3 | NoneBase color (albedo) of the surface. Default None.
albedo_textureanyTexture map for the albedo channel.
normal_textureanyNormal map texture.
metallic_factorfloatMetallic contribution: 0.0 = fully dielectric, 1.0 = fully metallic.
roughness_factorfloatSurface roughness: 0.0 = smooth/mirror, 1.0 = fully rough.
metallic_roughnessanyCombined metallic-roughness texture (glTF convention: B=metallic, G=roughness).
occlusion_textureanyAmbient occlusion texture.
occlusion_factorfloatStrength of the ambient occlusion effect.
emissive_textureanyEmissive texture for self-illuminated regions.
emissive_colorVector3 | NoneSelf-emitted light color. Default None.
transparencyfloatOpacity level: 0.0 = fully opaque, 1.0 = fully transparent.

Class Method

MethodReturn TypeDescription
PbrMaterial.from_material(material)PbrMaterialConverts a LambertMaterial or PhongMaterial to a PbrMaterial approximation.

Usage Example

from aspose.threed import Scene
from aspose.threed.entities import Mesh
from aspose.threed.shading import PbrMaterial
from aspose.threed.utilities import Vector3, Vector4

scene = Scene()

mesh = Mesh()
mesh.control_points.append(Vector4(0, 0, 0, 1))
mesh.control_points.append(Vector4(1, 0, 0, 1))
mesh.control_points.append(Vector4(0.5, 1, 0, 1))
mesh.create_polygon(0, 1, 2)

mat = PbrMaterial("pbr-metal")
mat.albedo = Vector3(0.8, 0.6, 0.2)    # gold-ish base color
mat.metallic_factor = 0.9
mat.roughness_factor = 0.2

node = scene.root_node.create_child_node("mesh", mesh)
node.material = mat

scene.save("pbr.glb")

See Also