LambertMaterial and PhongMaterial — Aspose.3D FOSS for Python API Reference
Properties: aspose.threed.shading (aspose-3d-foss)
Aspose.3D FOSS provides two material classes in the classic shading hierarchy:
LambertMaterial: การเชดดิ้งแบบกระจายด้านสี (ไม่มีการสะท้อนแสง)PhongMaterial: ขยาย Lambert ด้วยไฮไลท์แบบสเปคคูลาร์และความเงางาม
ทั้งสองถูกกำหนดให้กับ 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 | สเกลของการมีส่วนสเปคคูลาร์ ค่าเริ่มต้น 0.0. |
shininess | float | เอ็กซ์โพเนนท์ความเงาของ Phong. ค่ามากกว่าจะทำให้ไฮไลท์แคบ/เล็กลง ค่าเริ่มต้น 0.0. |
reflection_color | `Vector3 | None` |
reflection_factor | float | ปริมาณการผสมสำหรับการสะท้อน ค่าเริ่มต้น 0.0. |
ตัวอย่างการใช้งาน
วัสดุ Lambert Matte
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
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 | ใดก็ได้ | แผนที่เทกซ์เจอร์สำหรับช่อง albedo. |
normal_texture | ใดก็ได้ | เทกซ์เจอร์แผนที่ปกติ. |
metallic_factor | float | ส่วนการเป็นโลหะ: 0.0 = เป็นสารฉนวนเต็มที่, 1.0 = เป็นโลหะเต็มที่. |
roughness_factor | float | ความหยาบของพื้นผิว: 0.0 = เรียบ/กระจก, 1.0 = หยาบเต็มที่. |
metallic_roughness | ใดก็ได้ | เทกเจอร์เมทัลลิก-รัฟเฟสที่รวมกัน (glTF convention: 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 | แปลง LambertMaterial หรือ PhongMaterial เป็น PbrMaterial การประมาณค่า. |
ตัวอย่างการใช้งาน
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")