LambertMaterial and PhongMaterial — Aspose.3D FOSS for Python API Reference
Properties: aspose.threed.shading (aspose-3d-foss)
Aspose.3D FOSS pruža dvije klase materijala u klasičnoj hijerarhiji sjenčanja:
LambertMaterial: difuzno matirano sjenčanje (bez specularnosti)PhongMaterial: proširuje Lambert s specularnim naglascima i sjajem
Oboje se dodjeljuje Node preko node.material. Boje se postavljaju pomoću Vector3(r, g, b) gdje su komponente u [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 | Razina neprozirnosti: 0.0 = potpuno neprozirno, 1.0 = potpuno prozirno. Ograničeno na [0.0, 1.0]. |
PhongMaterial
class PhongMaterial(LambertMaterial):Properties
A3DObject → Material → LambertMaterial → PhongMaterial
Nasljeđuje sve LambertMaterial svojstva i dodaje:
Dodatna svojstva
| Properties | Properties | Properties |
|---|---|---|
specular_color | `Vector3 | None` |
specular_factor | float | Skala spekularnog doprinosa. Zadano 0.0. |
shininess | float | Phong eksponent sjajnosti. Veći = zategnutiji/manjih naglasaka. Zadano 0.0. |
reflection_color | `Vector3 | None` |
reflection_factor | float | Količina miješanja za odraz. Zadano 0.0. |
Primjeri upotrebe
Lambert mat materijal
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 sjajni materijal
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")Poluprozirni materijal
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% transparentUčitaj materijal iz uvezene 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):Properties
A3DObject → Material → PbrMaterial
PBR (Physically Based Rendering) materijal. Koristi se u glTF 2.0 i drugim formatima koji podržavaju PBR. Dodijeljen Node preko node.material.
Properties
PbrMaterial(name: str = None, albedo: Vector3 = None)Properties
| Properties | Properties | Properties |
|---|---|---|
albedo | `Vector3 | None` |
albedo_texture | bilo koji | Teksturna mapa za albedo kanal. |
normal_texture | bilo koji | Tekstura normalne karte. |
metallic_factor | float | Metalni doprinos: 0.0 = potpuno dielektričan, 1.0 = potpuno metalni. |
roughness_factor | float | Hrapavost površine: 0.0 = glatko/ogledalo, 1.0 = potpuno hrapav. |
metallic_roughness | bilo koji | Kombinirana tekstura metallic‑roughness (glTF konvencija: B=metallic, G=roughness). |
occlusion_texture | bilo koji | Tekstura ambient occlusion. |
occlusion_factor | float | Jačina efekta ambient occlusion. |
emissive_texture | bilo koji | Emisijska tekstura za samoispravljene regije. |
emissive_color | `Vector3 | None` |
transparency | float | Razina neprozirnosti: 0.0 = potpuno neprozirno, 1.0 = potpuno prozirno. |
Metoda klase
| Properties | Tip povratka | Properties |
|---|---|---|
PbrMaterial.from_material(material) | PbrMaterial | Pretvara LambertMaterial ili PhongMaterial u PbrMaterial približak. |
Primjer upotrebe
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")