LambertMaterial and PhongMaterial — Aspose.3D FOSS for Python API Reference
Properties: aspose.threed.shading (aspose-3d-foss)
Aspose.3D FOSS מספקת שני מחלקות חומר במבנה ההצללה הקלאסי:
LambertMaterial: הצללה מתמטית פיזורית (ללא ברק)PhongMaterial: מרחיב את למברט עם הדגשות מראה וברק
שניהם מוקצים ל- Node באמצעות node.material. הצבעים מוגדרים באמצעות Vector3(r, g, b) כאשר הרכיבים ב- [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 | רמת אטימות: 0.0 = אטום לחלוטין, 1.0 = שקוף לחלוטין. מוגבל ל- [0.0, 1.0]. |
PhongMaterial
class PhongMaterial(LambertMaterial):Properties
A3DObject → Material → LambertMaterial → PhongMaterial
יורש את כל LambertMaterial מאפיינים ומוסיף:
מאפיינים נוספים
| Properties | Properties | Properties |
|---|---|---|
specular_color | `Vector3 | None` |
specular_factor | float | קנה מידה של התרומה המראה (specular). Default 0.0. |
shininess | float | מכפלת הברק של Phong. גבוה יותר = הבליטות חזקות/קטנות יותר. Default 0.0. |
reflection_color | `Vector3 | None` |
reflection_factor | float | כמות המיזוג עבור השתקפות. ברירת מחדל 0.0. |
דוגמאות שימוש
חומר למברט מט
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")חומר פונג מבריק
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")חומר חצי-שקוף
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קריאת חומר מהסצנה המיובאת
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). משמש ב‑glTF 2.0 ובפורמטים אחרים התומכים ב‑PBR. מוקצה ל‑ Node באמצעות node.material.
Properties
PbrMaterial(name: str = None, albedo: Vector3 = None)Properties
| Properties | Properties | Properties |
|---|---|---|
albedo | `Vector3 | None` |
albedo_texture | כלשהו | מפת מרקם לערוץ האלבדו. |
normal_texture | כלשהו | מרקם מפת נורמל. |
metallic_factor | float | תרומה מתכתית: 0.0 = דיאלקטרי מלא, 1.0 = מתכתי מלא. |
roughness_factor | float | חוסר חלקות המשטח: 0.0 = חלק/מראה, 1.0 = מחוספס לחלוטין. |
metallic_roughness | כלשהו | מרקם משולב metallic-roughness (קונבנציה של glTF: B=metallic, G=roughness). |
occlusion_texture | כל | מרקם Ambient occlusion. |
occlusion_factor | float | עוצמת אפקט ה-Ambient occlusion. |
emissive_texture | כל | מרקם פולט אור לאזורים המוארים בעצמם. |
emissive_color | `Vector3 | None` |
transparency | float | רמת שקיפות: 0.0 = אטום לחלוטין, 1.0 = שקוף לחלוטין. |
מתודת מחלקה
| Properties | סוג החזרה | Properties |
|---|---|---|
PbrMaterial.from_material(material) | PbrMaterial | ממיר a LambertMaterial או PhongMaterial ל- a PbrMaterial קירוב. |
הפניה ל-API של המחלקה CompositeNode ב‑aspose-note גרסה 26.3.1. מחלקת בסיס לכל צמתים במסמך שיכולים להכיל צמתים ילדים.
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")