LambertMaterial and PhongMaterial — Aspose.3D FOSS for Python API Reference

: aspose.threed.shading (aspose-3d-foss)

Aspose.3D FOSS cung cấp hai lớp vật liệu trong hệ thống shading cổ điển:

  • LambertMaterial: shading matte khuếch tán (không có độ phản chiếu)
  • PhongMaterial: mở rộng Lambert với các điểm sáng phản chiếu và độ bóng

Cả hai đều được gán cho một Node qua node.material. Màu sắc được đặt bằng cách sử dụng Vector3(r, g, b) trong đó các thành phần nằm trong [0.0, 1.0].


LambertMaterial

class LambertMaterial(Material):

A3DObjectMaterialLambertMaterial

LambertMaterial(name: str = None)

ambient_color`Vector3None`
diffuse_color`Vector3None`
emissive_color`Vector3None`
transparent_color`Vector3None`
transparencyfloatMức độ mờ đục: 0.0 = hoàn toàn đục, 1.0 = hoàn toàn trong suốt. Giới hạn tới [0.0, 1.0].

PhongMaterial

class PhongMaterial(LambertMaterial):

A3DObjectMaterialLambertMaterialPhongMaterial

Kế thừa tất cả LambertMaterial các thuộc tính và thêm:

Các thuộc tính bổ sung

specular_color`Vector3None`
specular_factorfloatTỷ lệ của đóng góp specular. Mặc định 0.0.
shininessfloatSố mũ độ bóng Phong. Cao hơn = các điểm sáng chặt hơn/nhỏ hơn. Mặc định 0.0.
reflection_color`Vector3None`
reflection_factorfloatLượng pha trộn cho phản chiếu. Mặc định 0.0.

Ví dụ sử dụng

Vật liệu 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")

Vật liệu 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")

Vật liệu bán trong suốt

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

Đọc vật liệu từ cảnh đã nhập

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):

A3DObjectMaterialPbrMaterial

Vật liệu PBR (Physically Based Rendering). Được sử dụng bởi glTF 2.0 và các định dạng hỗ trợ PBR khác. Được gán cho một Node qua node.material.

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

albedo`Vector3None`
albedo_texturebất kỳBản đồ kết cấu cho kênh albedo.
normal_texturebất kỳKết cấu bản đồ pháp tuyến.
metallic_factorfloatĐóng góp kim loại: 0.0 = hoàn toàn điện môi, 1.0 = hoàn toàn kim loại.
roughness_factorfloatĐộ nhám bề mặt: 0.0 = mịn/gương, 1.0 = hoàn toàn nhám.
metallic_roughnessbất kỳKết cấu metallic-roughness kết hợp (theo quy ước glTF: B=metallic, G=roughness).
occlusion_texturebất kỳKết cấu Ambient occlusion.
occlusion_factorfloatMức độ mạnh của hiệu ứng Ambient occlusion.
emissive_texturebất kỳKết cấu phát sáng cho các vùng tự chiếu sáng.
emissive_color`Vector3None`
transparencyfloatMức độ trong suốt: 0.0 = hoàn toàn không trong suốt, 1.0 = hoàn toàn trong suốt.

Phương thức lớp

Kiểu trả về
PbrMaterial.from_material(material)PbrMaterialChuyển đổi một LambertMaterial hoặc PhongMaterial thành một PbrMaterial xấp xỉ.

Ví dụ sử dụng

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")

Xem thêm

 Tiếng Việt