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 specularPbrMaterial— 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 A3DObjectEnumerations
| Enumerations | Enumerations | Enumerations |
|---|---|---|
name | string | Tê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 | nullsetTexture(slotName, texture)
Gán một TextureBase đối tượng vào khe được đặt tên.
setTexture(slotName: string, texture: TextureBase): voidLớ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 MaterialEnumerations
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
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
diffuseColor | `Vector3 | null` | null |
ambientColor | `Vector3 | null` | null |
emissiveColor | `Vector3 | null` | null |
transparentColor | `Vector3 | null` | null |
transparency | number | 0.0 | Hệ 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 LambertMaterialEnumerations
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
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
specularColor | `Vector3 | null` | null |
specularFactor | number | 0.0 | Hệ số nhân vô hướng cho thành phần gương. |
shininess | number | 0.0 | Số mũ độ bóng Phong — giá trị cao hơn tạo ra các điểm sáng chặt chẽ hơn. |
reflectionColor | `Vector3 | null` | null |
reflectionFactor | number | 0.0 | Hệ 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 MaterialEnumerations
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
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
albedo | `Vector3 | null` | null |
albedoTexture | `TextureBase | null` | null |
normalTexture | `TextureBase | null` | null |
metallicFactor | number | 0.0 | Hệ số kim loại trong khoảng 0–1. 1.0 = hoàn toàn kim loại. |
roughnessFactor | number | 0.0 | Hệ số độ nhám trong khoảng 0–1. 0.0 = mịn như gương. |
metallicRoughness | `TextureBase | null` | null |
occlusionTexture | `TextureBase | null` | null |
occlusionFactor | number | 0.0 | Mức độ mạnh của hiệu ứng che khuất môi trường. |
emissiveColor | `Vector3 | null` | null |
emissiveTexture | `TextureBase | null` | null |
transparency | number | 0.0 | Hệ 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