Material
חבילה: @aspose/3d (v24.12.0)
@aspose/3d מגיע עם שלוש מחלקות חומר קונקרטיות שמרחיבות את המחלקה המופשטת. Material בסיס. הן מכסות את שלושת מודלי ההצללה הנפוצים ביותר בפורמטים להחלפת 3D:
LambertMaterial— פיזור + סביבתי + פולט (משמשים ב‑OBJ/MTL ובנכסי FBX ישנים)PhongMaterial— מרחיב את למברט עם תכונות הילה מראהPbrMaterial— מודל מבוסס פיזיקה המתאים להגדרת החומר של glTF 2.0
כל מחלקות החומר מיוצאות מה‑main @aspose/3d נקודת כניסה.
import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';מחלקה Material (בסיס מופשט)
Material היא מחלקת הבסיס המופשטת לכל החומרים. היא מרחיבה A3DObject, המספקת את name המאפיין ואת ממשק ה‑API של משבצת המרקם.
export class Material extends A3DObjectImageRenderOptions
| Name | Type | Access | Description |
|---|---|---|---|
MAP_SPECULAR | `` | Read | Gets the map specular. |
MAP_DIFFUSE | `` | Read | Gets the map diffuse. |
MAP_EMISSIVE | `` | Read | Gets the map emissive. |
MAP_AMBIENT | `` | Read | Gets the map ambient. |
MAP_NORMAL | `` | Read | Gets the map normal. |
ImageRenderOptions
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 MaterialImageRenderOptions
A3DObject ← Material ← LambertMaterial
ImageRenderOptions
הקצה חומר פיזור אדום לצומת.
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');ImageRenderOptions
| Signature | Description |
|---|---|
| `constructor(name: string | null)` |
getTexture(_slotName: string) → `TextureBase | null` |
setTexture(_slotName: string, _texture: TextureBase) | Sets the texture value. |
מחלקה PhongMaterial
PhongMaterial מרחיב LambertMaterial עם תמיכה בהדגשות ספקולריות, מיישם את מודל הצללה הקלאסי של Phong. הוא נפוץ בנכסי FBX ו‑COLLADA.
export class PhongMaterial extends LambertMaterialImageRenderOptions
A3DObject ← Material ← LambertMaterial ← PhongMaterial
ImageRenderOptions
צור חומר 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
ImageRenderOptions
מחלקה PbrMaterial
PbrMaterial מיישם את מודל ה‑PBR מתכתי‑גס של glTF 2.0. השתמש במחלקה זו עבור סצנות שישמרו כ‑glTF/GLB, או כאשר נכס המקור ב‑FBX מכיל חומרים PBR.
export class PbrMaterial extends MaterialImageRenderOptions
A3DObject ← Material ← PbrMaterial
ImageRenderOptions
בנה חומר 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);ImageRenderOptions
מתודות סטטיות
PbrMaterial.fromMaterial(material)
יוצר חדש PbrMaterial מתוך generic Material מופע, מעתיק את name.
static fromMaterial(material: Material): PbrMaterial