Materials — LambertMaterial, PhongMaterial, PbrMaterial
الحزمة: @aspose/3d (v24.12.0)
@aspose/3d يُصدر ثلاث فئات مواد ملموسة تُوسّع الفئة المجردة Material الأساسية. تغطي النماذج الثلاثة للإضاءة الأكثر شيوعًا في صيغ تبادل 3D:
LambertMaterial— الانتشار + المحيط + الانبعاث (يُستخدم في OBJ/MTL وأصول FBX القديمة)PhongMaterial— يوسّع Lambert بخصائص اللمعان الانعكاسيPbrMaterial— نموذج قائم على الفيزياء يطابق تعريف مادة glTF 2.0
جميع فئات المواد يتم تصديرها من النقطة الرئيسية @aspose/3d نقطة الدخول.
import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';الفئة Material (قاعدة مجردة)
Material هو الفئة الأساسية المجردة لجميع المواد. يمدد A3DObject,، موفرًا الـ name خاصية وواجهة برمجة تطبيقات فتحة القوام.
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 بدعم الإبرازات اللامعة، يطبق نموذج التظليل الفونغ الكلاسيكي. وهو شائع في أصول 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 | معامل اللمعان في نموذج فونغ — القيم الأعلى تنتج بروزًا أكثر حدة. |
reflectionColor | `Vector3 | null` | null |
reflectionFactor | number | 0.0 | مضاعف قياسي للمساهمة الانعكاسية. |
الفئة PbrMaterial
PbrMaterial يطبق نموذج PBR المعدني‑الخشون 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 | عامل المعدن في النطاق 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