Material

แพคเกจ: @aspose/3d (v24.12.0)

@aspose/3d มาพร้อมกับคลาสวัสดุที่เป็นรูปธรรมสามคลาสที่สืบทอดจากคลาสฐานเชิงนามธรรม Material ฐาน พวกมันครอบคลุมโมเดลการแรเงาสามแบบที่พบมากที่สุดในรูปแบบการแลกเปลี่ยน 3D:

  • LambertMaterial — diffuse + ambient + emissive (ใช้ในไฟล์ OBJ/MTL และสินทรัพย์ FBX รุ่นเก่า)
  • PhongMaterial — ขยาย Lambert ด้วยคุณสมบัติไฮไลท์สเปคคูลาร์
  • PbrMaterial — โมเดลเชิงกายภาพที่สอดคล้องกับการกำหนดวัสดุของ glTF 2.0

คลาสวัสดุทั้งหมดจะถูกส่งออกจาก @aspose/3d จุดเริ่มต้นหลัก.

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

คลาส Material (ฐานเชิงนามธรรม)

Material เป็นคลาสฐานเชิงนามธรรมสำหรับวัสดุทั้งหมด มันสืบทอดจาก A3DObject, ให้บริการ name คุณสมบัติและ API ของสล็อตเทกเจอร์.

export class Material extends A3DObject

Properties

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.

Properties

getTexture(slotName)

คืนค่า TextureBase ที่กำหนดให้กับสล็อตที่ระบุ, หรือ null หากไม่มีการมอบหมายใด ๆ.

getTexture(slotName: string): TextureBase | null

setTexture(slotName, texture)

กำหนด TextureBase อินสแตนซ์ให้กับสล็อตที่ตั้งชื่อ.

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

คลาส LambertMaterial

LambertMaterial จำลองการสะท้อนแบบกระจายพร้อมส่วนร่วมของแสงรอบด้านและการปล่อยแสงที่เป็นตัวเลือก มันเป็นประเภทวัสดุที่มักสร้างขึ้นเมื่อโหลดไฟล์ OBJ ด้วย .mtl ไลบรารี.

export class LambertMaterial extends Material

Properties

A3DObject ← Material ← LambertMaterial

Properties

กำหนดวัสดุแบบกระจายสีแดงให้กับโหนดหนึ่ง.

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');

Properties

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

คลาส PhongMaterial

PhongMaterial ขยาย LambertMaterial พร้อมการสนับสนุนไฮไลท์สเปคคูลาร์, ใช้โมเดลการแรเงาแบบ Phong คลาสสิก. มักพบในสินทรัพย์ FBX และ COLLADA.

export class PhongMaterial extends LambertMaterial

Properties

A3DObject ← Material ← LambertMaterial ← PhongMaterial

Properties

สร้างวัสดุ Phong สีฟ้าเงางาม.

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

Properties


คลาส PbrMaterial

PbrMaterial ใช้โมเดล PBR แบบ metallic-roughness ของ glTF 2.0. ใช้คลาสนี้สำหรับฉากที่จะบันทึกเป็น glTF/GLB, หรือเมื่อสินทรัพย์ FBX ต้นฉบับมีวัสดุ PBR.

export class PbrMaterial extends Material

Properties

A3DObject ← Material ← PbrMaterial

Properties

สร้างวัสดุ PBR สีทองและบันทึกลงไฟล์ 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);

Properties

เมธอดสถิตย์

PbrMaterial.fromMaterial(material)

สร้างใหม่ PbrMaterial จากทั่วไป Material อินสแตนซ์, คัดลอก name.

static fromMaterial(material: Material): PbrMaterial
 ภาษาไทย