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

A3DObjectMaterialLambertMaterial

Properties

LambertMaterial(name: str = None)

Properties

PropertiesPropertiesProperties
ambient_color`Vector3None`
diffuse_color`Vector3None`
emissive_color`Vector3None`
transparent_color`Vector3None`
transparencyfloatระดับความทึบ: 0.0 = ทึบเต็มที่, 1.0 = โปร่งใสเต็มที่. จำกัดที่ [0.0, 1.0].

PhongMaterial

class PhongMaterial(LambertMaterial):

Properties

A3DObjectMaterialLambertMaterialPhongMaterial

สืบทอดทั้งหมด LambertMaterial คุณสมบัติและเพิ่ม:

คุณสมบัติเพิ่มเติม

PropertiesPropertiesProperties
specular_color`Vector3None`
specular_factorfloatสเกลของการมีส่วนสเปคคูลาร์ ค่าเริ่มต้น 0.0.
shininessfloatเอ็กซ์โพเนนท์ความเงาของ Phong. ค่ามากกว่าจะทำให้ไฮไลท์แคบ/เล็กลง ค่าเริ่มต้น 0.0.
reflection_color`Vector3None`
reflection_factorfloatปริมาณการผสมสำหรับการสะท้อน ค่าเริ่มต้น 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

A3DObjectMaterialPbrMaterial

วัสดุ PBR (Physically Based Rendering) ใช้โดย glTF 2.0 และรูปแบบอื่นที่รองรับ PBR. ถูกกำหนดให้กับ Node ผ่าน node.material.

Properties

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

Properties

PropertiesPropertiesProperties
albedo`Vector3None`
albedo_textureใดก็ได้แผนที่เทกซ์เจอร์สำหรับช่อง albedo.
normal_textureใดก็ได้เทกซ์เจอร์แผนที่ปกติ.
metallic_factorfloatส่วนการเป็นโลหะ: 0.0 = เป็นสารฉนวนเต็มที่, 1.0 = เป็นโลหะเต็มที่.
roughness_factorfloatความหยาบของพื้นผิว: 0.0 = เรียบ/กระจก, 1.0 = หยาบเต็มที่.
metallic_roughnessใดก็ได้เทกเจอร์เมทัลลิก-รัฟเฟสที่รวมกัน (glTF convention: B=metallic, G=roughness).
occlusion_textureใดก็ได้เทกเจอร์ Ambient Occlusion.
occlusion_factorfloatความแรงของเอฟเฟกต์ Ambient Occlusion.
emissive_textureใดก็ได้เทกเจอร์เรืองแสงสำหรับบริเวณที่ส่องสว่างด้วยตนเอง.
emissive_color`Vector3None`
transparencyfloatระดับความทึบ: 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")

ดูเพิ่มเติม

 ภาษาไทย