Materials — LambertMaterial, PhongMaterial, PbrMaterial

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 A3DObject

Properties

PropertiesPropertiesProperties
namestringชื่อวัสดุตามที่ปรากฏในกราฟฉากและผลลัพธ์การส่งออก.

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

PropertiesPropertiesPropertiesProperties
diffuseColor`Vector3null`null
ambientColor`Vector3null`null
emissiveColor`Vector3null`null
transparentColor`Vector3null`null
transparencynumber0.0ปัจจัยความทึบในช่วง 0.0 (ทึบเต็ม) ถึง 1.0 (โปร่งใสเต็ม). ถูกจำกัดอัตโนมัติ.

คลาส 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

PropertiesPropertiesPropertiesProperties
specularColor`Vector3null`null
specularFactornumber0.0ตัวคูณสเกลาร์สำหรับส่วนสเปคคูลาร์.
shininessnumber0.0ค่าเอ็กซ์โพเนนท์ความเงา Phong — ค่าที่สูงกว่าจะทำให้ไฮไลท์แคบลง.
reflectionColor`Vector3null`null
reflectionFactornumber0.0ตัวคูณสเกลาร์สำหรับส่วนการสะท้อน.

คลาส 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

PropertiesPropertiesPropertiesProperties
albedo`Vector3null`null
albedoTexture`TextureBasenull`null
normalTexture`TextureBasenull`null
metallicFactornumber0.0ปัจจัย metallic อยู่ในช่วง 0–1. 1.0 = เป็นโลหะเต็มที่.
roughnessFactornumber0.0ค่าปัจจัยความหยาบในช่วง 0–1. 0.0 = เรียบเหมือนกระจก.
metallicRoughness`TextureBasenull`null
occlusionTexture`TextureBasenull`null
occlusionFactornumber0.0ความแรงของเอฟเฟกต์การบังแสงโดยรอบ.
emissiveColor`Vector3null`null
emissiveTexture`TextureBasenull`null
transparencynumber0.0ค่าปัจจัยความทึบในช่วง 0–1. ถูกจำกัดอัตโนมัติ.

เมธอดสถิตย์

PbrMaterial.fromMaterial(material)

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

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