Material

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

NameTypeAccessDescription
MAP_SPECULAR``ReadGets the map specular.
MAP_DIFFUSE``ReadGets the map diffuse.
MAP_EMISSIVE``ReadGets the map emissive.
MAP_AMBIENT``ReadGets the map ambient.
MAP_NORMAL``ReadGets the map normal.

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

SignatureDescription
`constructor(name: stringnull)`
getTexture(_slotName: string) → `TextureBasenull`
setTexture(_slotName: string, _texture: TextureBase)Sets the texture value.

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


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

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