Material
Paket: @aspose/3d (v24.12.0)
@aspose/3d isporučuje tri konkretne klase materijala koje proširuju apstraktni Material bazu. Pokrivaju tri modela osvetljenja najčešće nađene u 3D formatima za razmenu:
LambertMaterial— diffuse + ambient + emissive (koristi se u OBJ/MTL i starijim FBX resursima)PhongMaterial— proširuje Lambert sa svojstvima specular highlightPbrMaterial— fizički zasnovani model koji odgovara definiciji materijala glTF 2.0
Sve klase materijala se izvoze iz glavnog @aspose/3d ulazna tačka.
import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';Klasa Material (apstraktna baza)
Material je apstraktna osnovna klasa za sve materijale. Proširuje A3DObject, pružajući name svojstvo i API za teksturne slotove.
export class Material extends A3DObject| Name | Type | Access | Description |
|---|---|---|---|
MAP_SPECULAR | `` | Read | Gets the map specular. |
MAP_DIFFUSE | `` | Read | Gets the map diffuse. |
MAP_EMISSIVE | `` | Read | Gets the map emissive. |
MAP_AMBIENT | `` | Read | Gets the map ambient. |
MAP_NORMAL | `` | Read | Gets the map normal. |
getTexture(slotName)
Vraća TextureBase dodeljeno nazvanom slotu, ili null ako nijedan nije dodeljen.
getTexture(slotName: string): TextureBase | nullsetTexture(slotName, texture)
Dodeljuje TextureBase instancu imenovanom slotu.
setTexture(slotName: string, texture: TextureBase): voidKlasa LambertMaterial
LambertMaterial modeluje difuzno reflektovanje sa opcionim ambijentalnim i emisijskim doprinosima. To je tip materijala koji se obično generiše prilikom učitavanja OBJ fajlova sa .mtl bibliotekama.
export class LambertMaterial extends MaterialA3DObject ← Material ← LambertMaterial
Dodeli crveni difuzni materijal čvoru.
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');| Signature | Description |
|---|---|
| `constructor(name: string | null)` |
getTexture(_slotName: string) → `TextureBase | null` |
setTexture(_slotName: string, _texture: TextureBase) | Sets the texture value. |
Klasa PhongMaterial
PhongMaterial proširuje LambertMaterial sa podrškom za spejularne odsjaje, implementirajući klasični Phong model osvetljenja. Često se koristi u FBX i COLLADA resursima.
export class PhongMaterial extends LambertMaterialA3DObject ← Material ← LambertMaterial ← PhongMaterial
Kreiraj sjajni plavi Phong materijal.
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
Klasa PbrMaterial
PbrMaterial implementira glTF 2.0 metallic-roughness PBR model. Koristite ovu klasu za scene koje će biti sačuvane kao glTF/GLB, ili kada izvorni FBX asset sadrži PBR materijale.
export class PbrMaterial extends MaterialA3DObject ← Material ← PbrMaterial
Izgradi zlatni PBR materijal i sačuvaj ga u glTF fajlu.
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);Statičke metode
PbrMaterial.fromMaterial(material)
Kreira novi PbrMaterial iz generičkog Material instancu, kopirajući name.
static fromMaterial(material: Material): PbrMaterial