Material

Pakiet: @aspose/3d (v24.12.0)

@aspose/3d dostarcza trzy konkretne klasy materiałów, które rozszerzają abstrakcyjną Material bazę. Obejmują trzy modele cieniowania najczęściej spotykane w formatach wymiany 3D:

  • LambertMaterial — dyfuzyjny + otoczenia + emisyjny (używany w zasobach OBJ/MTL i starszych FBX)
  • PhongMaterial — rozszerza model Lamberta o właściwości podświetlenia specularnego
  • PbrMaterial — model oparty na fizyce, odpowiadający definicji materiału glTF 2.0

Wszystkie klasy materiałów są eksportowane z głównego @aspose/3d punktu wejścia.

import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';

Klasa Material (abstrakcyjna baza)

Material jest abstrakcyjną klasą bazową dla wszystkich materiałów. Rozszerza A3DObject, zapewniając name właściwość i API slotu tekstury.

export class Material extends A3DObject

ImageRenderOptions

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.

ImageRenderOptions

getTexture(slotName)

Zwraca TextureBase przypisane do nazwanego slotu, lub null jeśli żadne nie zostało przypisane.

getTexture(slotName: string): TextureBase | null

setTexture(slotName, texture)

Przypisuje TextureBase instancję do nazwanego slotu.

setTexture(slotName: string, texture: TextureBase): void

Klasa LambertMaterial

LambertMaterial modeluje rozproszone odbicie z opcjonalnym wkładem ambientowym i emisji. Jest to typ materiału powszechnie generowany przy ładowaniu plików OBJ przy użyciu .mtl bibliotek.

export class LambertMaterial extends Material

ImageRenderOptions

A3DObject ← Material ← LambertMaterial

ImageRenderOptions

Przypisz czerwony materiał rozpraszający do węzła.

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

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

Klasa PhongMaterial

PhongMaterial rozszerza LambertMaterial z obsługą refleksów specularnych, implementując klasyczny model cieniowania Phonga. Jest powszechny w zasobach FBX i COLLADA.

export class PhongMaterial extends LambertMaterial

ImageRenderOptions

A3DObject ← Material ← LambertMaterial ← PhongMaterial

ImageRenderOptions

Utwórz błyszczący niebieski materiał 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


Klasa PbrMaterial

PbrMaterial implementuje model PBR metaliczno‑szorstkościowy glTF 2.0. Użyj tej klasy dla scen, które będą zapisywane jako glTF/GLB, lub gdy źródłowy zasób FBX zawiera materiały PBR.

export class PbrMaterial extends Material

ImageRenderOptions

A3DObject ← Material ← PbrMaterial

ImageRenderOptions

Zbuduj złoty materiał PBR i zapisz go w pliku 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

Metody statyczne

PbrMaterial.fromMaterial(material)

Tworzy nowy PbrMaterial z ogólnego Material instancji, kopiując name.

static fromMaterial(material: Material): PbrMaterial
 Polski