Materials — LambertMaterial, PhongMaterial, PbrMaterial

Materials — LambertMaterial, PhongMaterial, PbrMaterial

Gói: @aspose/3d (v24.12.0)

@aspose/3d cung cấp ba lớp vật liệu cụ thể mở rộng lớp trừu tượng Material cơ sở. Chúng bao gồm ba mô hình shading thường gặp nhất trong các định dạng trao đổi 3D:

  • LambertMaterial — diffuse + ambient + emissive (được sử dụng bởi tài sản OBJ/MTL và FBX cũ)
  • PhongMaterial — mở rộng Lambert với các thuộc tính điểm nhấn specular
  • PbrMaterial — mô hình dựa trên vật lý phù hợp với định nghĩa vật liệu glTF 2.0

Tất cả các lớp vật liệu đều được xuất từ @aspose/3d điểm vào.

import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';

Lớp Material (cơ sở trừu tượng)

Material là lớp cơ sở trừu tượng cho tất cả các vật liệu. Nó mở rộng A3DObject, cung cấp name thuộc tính và API khe kết cấu.

export class Material extends A3DObject

Enumerations

EnumerationsEnumerationsEnumerations
namestringTên vật liệu như nó xuất hiện trong đồ thị cảnh và đầu ra xuất.

Enumerations

getTexture(slotName)

Trả về TextureBase được gán cho khe có tên, hoặc null nếu không có gì được chỉ định.

getTexture(slotName: string): TextureBase | null

setTexture(slotName, texture)

Gán một TextureBase đối tượng vào khe được đặt tên.

setTexture(slotName: string, texture: TextureBase): void

Lớp LambertMaterial

LambertMaterial mô phỏng phản xạ khuếch tán với các đóng góp môi trường và phát xạ tùy chọn. Đây là loại vật liệu thường được tạo ra khi tải các tệp OBJ với .mtl thư viện.

export class LambertMaterial extends Material

Enumerations

A3DObject ← Material ← LambertMaterial

Enumerations

Gán một vật liệu khuếch tán màu đỏ cho một nút.

import { Scene, LambertMaterial } from '@aspose/3d';
import { Vector3 } from '@aspose/3d/utilities';

const scene = new Scene();
scene.open('model.obj');

const mat = new LambertMaterial('RedSurface');
mat.diffuseColor = new Vector3(1, 0, 0);   // R=1, G=0, B=0
mat.ambientColor = new Vector3(0.1, 0, 0);
mat.transparency = 0;

// Assign material to the first child node's entity
const firstNode = scene.rootNode.childNodes[0];
if (firstNode && firstNode.entity) {
  (firstNode.entity as any).material = mat;
}
scene.save('output.fbx');

Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
diffuseColor`Vector3null`null
ambientColor`Vector3null`null
emissiveColor`Vector3null`null
transparentColor`Vector3null`null
transparencynumber0.0Hệ số độ mờ trong khoảng 0.0 (độ mờ hoàn toàn) đến 1.0 (độ trong suốt hoàn toàn). Tự động giới hạn.

Lớp PhongMaterial

PhongMaterial mở rộng LambertMaterial với hỗ trợ điểm nhấn phản chiếu, thực hiện mô hình shading Phong cổ điển. Nó thường xuất hiện trong các tài sản FBX và COLLADA.

export class PhongMaterial extends LambertMaterial

Enumerations

A3DObject ← Material ← LambertMaterial ← PhongMaterial

Enumerations

Tạo một vật liệu Phong màu xanh bóng.

import { PhongMaterial } from '@aspose/3d';
import { Vector3 } from '@aspose/3d/utilities';

const mat = new PhongMaterial('ShinyBlue');
mat.diffuseColor = new Vector3(0, 0.2, 0.8);
mat.specularColor = new Vector3(1, 1, 1);
mat.shininess = 64;
mat.specularFactor = 0.8;
console.log(`Shininess: ${mat.shininess}`); // Shininess: 64

Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
specularColor`Vector3null`null
specularFactornumber0.0Hệ số nhân vô hướng cho thành phần gương.
shininessnumber0.0Số mũ độ bóng Phong — giá trị cao hơn tạo ra các điểm sáng chặt chẽ hơn.
reflectionColor`Vector3null`null
reflectionFactornumber0.0Hệ số nhân vô hướng cho thành phần phản chiếu.

Lớp PbrMaterial

PbrMaterial triển khai mô hình PBR kim loại-độ nhám glTF 2.0. Sử dụng lớp này cho các cảnh sẽ được lưu dưới dạng glTF/GLB, hoặc khi tài sản FBX nguồn chứa vật liệu PBR.

export class PbrMaterial extends Material

Enumerations

A3DObject ← Material ← PbrMaterial

Enumerations

Xây dựng một vật liệu PBR màu vàng và lưu nó vào tệp glTF.

import { Scene, PbrMaterial } from '@aspose/3d';
import { Vector3 } from '@aspose/3d/utilities';
import { GltfSaveOptions } from '@aspose/3d/formats/gltf';

const scene = new Scene();
scene.open('base-mesh.obj');

const gold = new PbrMaterial('Gold');
gold.albedo = new Vector3(1.0, 0.766, 0.336);  // gold base color
gold.metallicFactor = 1.0;
gold.roughnessFactor = 0.3;

// Attach material to the first mesh node
const meshNode = scene.rootNode.childNodes[0];
if (meshNode && meshNode.entity) {
  (meshNode.entity as any).material = gold;
}

const opts = new GltfSaveOptions();
opts.binaryMode = true;
scene.save('gold-model.glb', opts);

Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
albedo`Vector3null`null
albedoTexture`TextureBasenull`null
normalTexture`TextureBasenull`null
metallicFactornumber0.0Hệ số kim loại trong khoảng 0–1. 1.0 = hoàn toàn kim loại.
roughnessFactornumber0.0Hệ số độ nhám trong khoảng 0–1. 0.0 = mịn như gương.
metallicRoughness`TextureBasenull`null
occlusionTexture`TextureBasenull`null
occlusionFactornumber0.0Mức độ mạnh của hiệu ứng che khuất môi trường.
emissiveColor`Vector3null`null
emissiveTexture`TextureBasenull`null
transparencynumber0.0Hệ số độ trong suốt trong khoảng 0–1. Tự động giới hạn.

Phương thức tĩnh

PbrMaterial.fromMaterial(material)

Tạo một PbrMaterial từ một Material đối tượng, sao chép name.

static fromMaterial(material: Material): PbrMaterial
 Tiếng Việt