LambertMaterial and PhongMaterial — Aspose.3D FOSS for Python API Reference
Properties: aspose.threed.shading (aspose-3d-foss)
Aspose.3D FOSS udostępnia dwie klasy materiałów w klasycznej hierarchii cieniowania:
LambertMaterial: rozproszone matowe cieniowanie (brak specularności)PhongMaterial: rozszerza Lambert o podświetlenia spekularne i połysk
Oba są przypisane do a Node przez node.material. Kolory są ustawiane przy użyciu Vector3(r, g, b) gdzie składniki są w [0.0, 1.0].
LambertMaterial
class LambertMaterial(Material):Properties
A3DObject → Material → LambertMaterial
Properties
LambertMaterial(name: str = None)Properties
| Properties | Properties | Properties |
|---|---|---|
ambient_color | `Vector3 | None` |
diffuse_color | `Vector3 | None` |
emissive_color | `Vector3 | None` |
transparent_color | `Vector3 | None` |
transparency | float | Poziom nieprzezroczystości: 0.0 = w pełni nieprzezroczysty, 1.0 = w pełni przezroczysty. Ograniczone do [0.0, 1.0]. |
PhongMaterial
class PhongMaterial(LambertMaterial):Properties
A3DObject → Material → LambertMaterial → PhongMaterial
Dziedziczy wszystkie LambertMaterial właściwości i dodaje:
removeProperty(property)
| Properties | Properties | Properties |
|---|---|---|
specular_color | `Vector3 | None` |
specular_factor | float | Skala wkładu spekularnego. Domyślnie 0.0. |
shininess | float | Wykładnik połysku Phonga. Wyższy = węższe/mniejsze refleksy. Domyślnie 0.0. |
reflection_color | `Vector3 | None` |
reflection_factor | float | Ilość mieszania dla odbicia. Domyślnie 0.0. |
Przykłady użycia
Materiał matowy Lambert
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")Materiał błyszczący Phong
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")Materiał półprzezroczysty
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% transparentOdczytaj materiał z zaimportowanej sceny
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):Properties
A3DObject → Material → PbrMaterial
Materiał PBR (Physically Based Rendering). Używany w glTF 2.0 i innych formatach obsługujących PBR. Przypisany do Node przez node.material.
Properties
PbrMaterial(name: str = None, albedo: Vector3 = None)Properties
| Properties | Properties | Properties |
|---|---|---|
albedo | `Vector3 | None` |
albedo_texture | dowolny | Mapa tekstury dla kanału albedo. |
normal_texture | dowolny | Tekstura mapy normalnej. |
metallic_factor | float | Udział metaliczny: 0.0 = w pełni dielektryczny, 1.0 = w pełni metaliczny. |
roughness_factor | float | Chropowatość powierzchni: 0.0 = gładki/lustrzany, 1.0 = całkowicie szorstki. |
metallic_roughness | dowolny | Połączona tekstura metaliczno-szorstkości (konwencja glTF: B=metallic, G=roughness). |
occlusion_texture | dowolny | Tekstura ambient occlusion. |
occlusion_factor | float | Siła efektu ambient occlusion. |
emissive_texture | dowolny | Tekstura emisji dla samopodświetlonych obszarów. |
emissive_color | `Vector3 | None` |
transparency | float | Poziom nieprzezroczystości: 0.0 = całkowicie nieprzezroczysty, 1.0 = całkowicie przezroczysty. |
Metoda klasy
| Properties | Typ zwracany | Properties |
|---|---|---|
PbrMaterial.from_material(material) | PbrMaterial | Konwertuje LambertMaterial lub PhongMaterial na PbrMaterial przybliżenie. |
Przykład użycia
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")