Material

بسته: @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 A3DObject

Example

NameTypeAccessDescription
MAP_SPECULAR``ReadGets the map specular.
MAP_DIFFUSE``ReadGets the map diffuse.
MAP_EMISSIVE``ReadGets the map emissive.
MAP_AMBIENT``ReadGets the map ambient.
MAP_NORMAL``ReadGets the map normal.

Example

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

Example

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

SignatureDescription
`constructor(name: stringnull)`
getTexture(_slotName: string) → `TextureBasenull`
setTexture(_slotName: string, _texture: TextureBase)Sets the texture value.

کلاس PhongMaterial

PhongMaterial گسترش می‌یابد LambertMaterial با پشتیبانی از specular highlight، مدل سایه‌زنی کلاسیک Phong را پیاده‌سازی می‌کند. این ویژگی در دارایی‌های FBX و COLLADA رایج است.

export class PhongMaterial extends LambertMaterial

Example

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


کلاس PbrMaterial

PbrMaterial مدل PBR metallic-roughness glTF 2.0 را پیاده‌سازی می‌کند. از این کلاس برای صحنه‌هایی که به صورت glTF/GLB ذخیره می‌شوند، یا زمانی که دارایی منبع FBX شامل مواد PBR است، استفاده کنید.

export class PbrMaterial extends Material

Example

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

inverse()

PbrMaterial.fromMaterial(material)

یک مورد جدید ایجاد می‌کند PbrMaterial از یک عمومی Material نمونه، کپی کردن name.

static fromMaterial(material: Material): PbrMaterial
 فارسی