Materials — LambertMaterial, PhongMaterial, PbrMaterial
แพคเกจ: @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 A3DObjectProperties
| Properties | Properties | Properties |
|---|---|---|
name | string | ชื่อวัสดุตามที่ปรากฏในกราฟฉากและผลลัพธ์การส่งออก. |
Properties
getTexture(slotName)
คืนค่า TextureBase ที่กำหนดให้กับสล็อตที่ระบุ, หรือ null หากไม่มีการมอบหมายใด ๆ.
getTexture(slotName: string): TextureBase | nullsetTexture(slotName, texture)
กำหนด TextureBase อินสแตนซ์ให้กับสล็อตที่ตั้งชื่อ.
setTexture(slotName: string, texture: TextureBase): voidคลาส LambertMaterial
LambertMaterial จำลองการสะท้อนแบบกระจายพร้อมส่วนร่วมของแสงรอบด้านและการปล่อยแสงที่เป็นตัวเลือก มันเป็นประเภทวัสดุที่มักสร้างขึ้นเมื่อโหลดไฟล์ OBJ ด้วย .mtl ไลบรารี.
export class LambertMaterial extends MaterialProperties
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
| Properties | Properties | Properties | Properties |
|---|---|---|---|
diffuseColor | `Vector3 | null` | null |
ambientColor | `Vector3 | null` | null |
emissiveColor | `Vector3 | null` | null |
transparentColor | `Vector3 | null` | null |
transparency | number | 0.0 | ปัจจัยความทึบในช่วง 0.0 (ทึบเต็ม) ถึง 1.0 (โปร่งใสเต็ม). ถูกจำกัดอัตโนมัติ. |
คลาส PhongMaterial
PhongMaterial ขยาย LambertMaterial พร้อมการสนับสนุนไฮไลท์สเปคคูลาร์, ใช้โมเดลการแรเงาแบบ Phong คลาสสิก. มักพบในสินทรัพย์ FBX และ COLLADA.
export class PhongMaterial extends LambertMaterialProperties
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
| Properties | Properties | Properties | Properties |
|---|---|---|---|
specularColor | `Vector3 | null` | null |
specularFactor | number | 0.0 | ตัวคูณสเกลาร์สำหรับส่วนสเปคคูลาร์. |
shininess | number | 0.0 | ค่าเอ็กซ์โพเนนท์ความเงา Phong — ค่าที่สูงกว่าจะทำให้ไฮไลท์แคบลง. |
reflectionColor | `Vector3 | null` | null |
reflectionFactor | number | 0.0 | ตัวคูณสเกลาร์สำหรับส่วนการสะท้อน. |
คลาส PbrMaterial
PbrMaterial ใช้โมเดล PBR แบบ metallic-roughness ของ glTF 2.0. ใช้คลาสนี้สำหรับฉากที่จะบันทึกเป็น glTF/GLB, หรือเมื่อสินทรัพย์ FBX ต้นฉบับมีวัสดุ PBR.
export class PbrMaterial extends MaterialProperties
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
| Properties | Properties | Properties | Properties |
|---|---|---|---|
albedo | `Vector3 | null` | null |
albedoTexture | `TextureBase | null` | null |
normalTexture | `TextureBase | null` | null |
metallicFactor | number | 0.0 | ปัจจัย metallic อยู่ในช่วง 0–1. 1.0 = เป็นโลหะเต็มที่. |
roughnessFactor | number | 0.0 | ค่าปัจจัยความหยาบในช่วง 0–1. 0.0 = เรียบเหมือนกระจก. |
metallicRoughness | `TextureBase | null` | null |
occlusionTexture | `TextureBase | null` | null |
occlusionFactor | number | 0.0 | ความแรงของเอฟเฟกต์การบังแสงโดยรอบ. |
emissiveColor | `Vector3 | null` | null |
emissiveTexture | `TextureBase | null` | null |
transparency | number | 0.0 | ค่าปัจจัยความทึบในช่วง 0–1. ถูกจำกัดอัตโนมัติ. |
เมธอดสถิตย์
PbrMaterial.fromMaterial(material)
สร้างใหม่ PbrMaterial จากทั่วไป Material อินสแตนซ์, คัดลอก name.
static fromMaterial(material: Material): PbrMaterial