Materials — LambertMaterial, PhongMaterial, PbrMaterial
بسته: @aspose/3d (v24.12.0)
@aspose/3d سه کلاس مادهٔ ملموس را که از کلاس پایهٔ انتزاعی ارث میبرند، ارائه میدهد Material پایه. آنها سه مدل سایهزنی که بیشترین استفاده را در فرمتهای تبادل 3D دارند، پوشش میدهند:
LambertMaterial— انتشار + محیطی + تابش (که توسط داراییهای OBJ/MTL و FBXهای قدیمی استفاده میشود)PhongMaterial— لامبرت را با ویژگیهای برجستگی specular گسترش میدهدPbrMaterial— مدل فیزیکی مبتنی بر واقعیت که تعریف ماده glTF 2.0 را مطابقت میدهد
تمام کلاسهای ماده از بخش اصلی صادر میشوند @aspose/3d نقطه ورودی.
import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';کلاس Material (پایهٔ انتزاعی)
Material کلاس پایهٔ انتزاعی برای تمام مواد است. این کلاس extends A3DObject,، فراهمکنندهٔ name ویژگی و API اسلات بافت.
export class Material extends A3DObjectExample
| Example | Example | Example |
|---|---|---|
name | string | نام ماده همانگونه که در گراف صحنه و خروجی صادرات ظاهر میشود. |
Example
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 MaterialExample
A3DObject ← Material ← LambertMaterial
Example
یک مادهٔ پخشکنندهٔ قرمز به یک گره اختصاص دهید.
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');Example
| Example | Example | Example | Example |
|---|---|---|---|
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 با پشتیبانی از specular highlight، مدل سایهزنی کلاسیک Phong را پیادهسازی میکند. این ویژگی در داراییهای FBX و COLLADA رایج است.
export class PhongMaterial extends LambertMaterialExample
A3DObject ← Material ← LambertMaterial ← PhongMaterial
Example
یک مادهٔ 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
Example
| Example | Example | Example | Example |
|---|---|---|---|
specularColor | `Vector3 | null` | null |
specularFactor | number | 0.0 | ضریب اسکالر برای specular contribution. |
shininess | number | 0.0 | نمایی shininess Phong — مقادیر بالاتر هایلایتهای تنگتری تولید میکنند. |
reflectionColor | `Vector3 | null` | null |
reflectionFactor | number | 0.0 | ضریب اسکالر برای reflection contribution. |
کلاس PbrMaterial
PbrMaterial مدل PBR metallic-roughness glTF 2.0 را پیادهسازی میکند. از این کلاس برای صحنههایی که به صورت glTF/GLB ذخیره میشوند، یا زمانی که دارایی منبع FBX شامل مواد PBR است، استفاده کنید.
export class PbrMaterial extends MaterialExample
A3DObject ← Material ← PbrMaterial
Example
یک مادهٔ 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);Example
| Example | Example | Example | Example |
|---|---|---|---|
albedo | `Vector3 | null` | null |
albedoTexture | `TextureBase | null` | null |
normalTexture | `TextureBase | null` | null |
metallicFactor | number | 0.0 | Metallic factor در بازه 0–1. 1.0 = کاملاً فلزی. |
roughnessFactor | number | 0.0 | Roughness factor در بازه 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 | عامل شفافیت در بازه ۰–۱. بهصورت خودکار محدود میشود. |
inverse()
PbrMaterial.fromMaterial(material)
یک مورد جدید ایجاد میکند PbrMaterial از یک عمومی Material نمونه، کپی کردن name.
static fromMaterial(material: Material): PbrMaterial