Material

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

Aspose.3D FOSS nodrošina divas materiālu klases klasiskajā ēnojuma hierarhijā:

  • LambertMaterial: difūzs matēts ēnojums (bez spekulāritātes)
  • PhongMaterial: paplašina Lambertu ar spekulāriem izcelumiem un spīdīgumu

Abi tiek piešķirti Node caur node.material. Krāsas tiek iestatītas, izmantojot Vector3(r, g, b) kur komponenti ir [0.0, 1.0].


LambertMaterial

class LambertMaterial(Material):

Properties

A3DObjectMaterialLambertMaterial

Properties

LambertMaterial(name: str = None)

Properties

NameTypeAccessDescription
namestrRead/WriteGets or sets the name.
propertiesPropertyCollectionReadGets the properties.

PhongMaterial

class PhongMaterial(LambertMaterial):

Properties

A3DObjectMaterialLambertMaterialPhongMaterial

Manto visus LambertMaterial īpašības un pievieno:

Šīs klases manto pamata īpašības no LoadOptions / SaveOptions attiecīgi. Papildu formāta specifiskas īpašības pašreizējai FOSS versijai nav dokumentētas.

SignatureDescription
__init__(name: str)
get_texture(slot_name: str)Not implemented in the FOSS edition — throws at runtime. Retrieves the texture assigned to the specified slot name
set_texture(slot_name: str, texture)Not implemented in the FOSS edition — throws at runtime. Sets the texture value.
find_property(property_name: str)
get_property(property: str)
set_property(property: str, value)Sets the property value.
remove_property(property)

Lietošanas piemēri

Lambert matētais materiāls

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 spīdīgs materiāls

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

Daļēji caurspīdīgs materiāls

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

Nolasīt materiālu no importētās ainas

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 (Fiziski balstīta renderēšana) materiāls. Lieto glTF 2.0 un citos PBR spējīgos formātos. Piešķirts Node caur node.material.

Properties

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

Properties

Gan LoadOptions, gan SaveOptions manto no IOConfig. Šādas īpašības ir pieejamas katram opciju objektam.

SaveOptions

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

Skatīt arī

 Latviešu