Material

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

@aspose/3d szállít három konkrét anyag osztályt, amelyek kiterjesztik az absztrakt Material bázist. Lefedik a három árnyalási modellt, amely a leggyakrabban előfordul a 3D csereformátumokban:

  • LambertMaterial — diffúz + környezeti + emisszív (OBJ/MTL és régebbi FBX eszközök által használt)
  • PhongMaterial — kiterjeszti a Lambert modellt specular highlight tulajdonságokkal
  • PbrMaterial — fizikailag alapú modell, amely megfelel a glTF 2.0 anyagdefiníciónak

Minden anyag osztály exportálva van a fő @aspose/3d belépési pontból.

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

Osztály Material (absztrakt alaposztály)

Material az absztrakt bázisosztály minden anyag számára. Kiterjeszti A3DObject, biztosítva a name tulajdonságot és a textúra slot API-t.

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)

Visszaadja a TextureBase a megnevezett slot-hoz rendelt értéket, vagy null ha egy sem lett hozzárendelve.

getTexture(slotName: string): TextureBase | null

setTexture(slotName, texture)

Hozzárendel egy TextureBase példányt a megnevezett slotba.

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

Osztály LambertMaterial

LambertMaterial modellezi a diffúz visszaverődést opcionális környezeti és emisszív hozzájárulásokkal. Ez a anyagtípus gyakran keletkezik OBJ fájlok betöltésekor a .mtl könyvtárak.

export class LambertMaterial extends Material

ImageRenderOptions

A3DObject ← Material ← LambertMaterial

ImageRenderOptions

Rendeljen egy piros diffúz anyagot egy node-hoz.

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.

Osztály PhongMaterial

PhongMaterial kiterjeszti LambertMaterial specularis kiemelés támogatással, a klasszikus Phong árnyalási modell megvalósításával. Gyakori FBX és COLLADA eszközökben.

export class PhongMaterial extends LambertMaterial

ImageRenderOptions

A3DObject ← Material ← LambertMaterial ← PhongMaterial

ImageRenderOptions

Hozzon létre egy fényes kék Phong anyagot.

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


Osztály PbrMaterial

PbrMaterial megvalósítja a glTF 2.0 fémes-érdes PBR modellt. Használja ezt az osztályt olyan jelenetekhez, amelyeket glTF/GLB formátumban mentenek, vagy ha a forrás FBX eszköz PBR anyagokat tartalmaz.

export class PbrMaterial extends Material

ImageRenderOptions

A3DObject ← Material ← PbrMaterial

ImageRenderOptions

Készítsen egy arany PBR anyagot, és mentse el egy glTF fájlba.

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

Statikus metódusok

PbrMaterial.fromMaterial(material)

Létrehoz egy új PbrMaterial egy általános Material példányból, másolva a name.

static fromMaterial(material: Material): PbrMaterial
 Magyar