Materials — LambertMaterial, PhongMaterial, PbrMaterial
Pacchetto: @aspose/3d (v24.12.0)
@aspose/3d fornisce tre classi di materiale concrete che estendono l’astratta Material base. Coprono i tre modelli di shading più comunemente trovati nei formati di interscambio 3D:
LambertMaterial— diffuso + ambientale + emissivo (usato da OBJ/MTL e asset FBX più vecchi)PhongMaterial— estende Lambert con proprietà di evidenziazione specularePbrMaterial— modello basato sulla fisica che corrisponde alla definizione del materiale glTF 2.0
Tutte le classi di materiale sono esportate dal principale @aspose/3d punto di ingresso.
import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';Classe Material (base astratta)
Material è la classe base astratta per tutti i materiali. Estende A3DObject, fornendo il name proprietà e l’API dello slot texture.
export class Material extends A3DObjectImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
name | string | Il nome del materiale così come appare nel grafo della scena e nell’output di esportazione. |
ImageRenderOptions
getTexture(slotName)
Restituisce il TextureBase assegnato allo slot denominato, o null se nessuno è stato assegnato.
getTexture(slotName: string): TextureBase | nullsetTexture(slotName, texture)
Assegna un TextureBase istanza allo slot denominato.
setTexture(slotName: string, texture: TextureBase): voidClasse LambertMaterial
LambertMaterial modella la riflessione diffusa con contributi ambientali ed emissivi opzionali. È il tipo di materiale comunemente prodotto durante il caricamento di file OBJ con .mtl librerie.
export class LambertMaterial extends MaterialImageRenderOptions
A3DObject ← Material ← LambertMaterial
ImageRenderOptions
Assegna un materiale diffuso rosso a un nodo.
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
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
diffuseColor | `Vector3 | null` | null |
ambientColor | `Vector3 | null` | null |
emissiveColor | `Vector3 | null` | null |
transparentColor | `Vector3 | null` | null |
transparency | number | 0.0 | Fattore di opacità nell’intervallo 0.0 (completamente opaco) a 1.0 (completamente trasparente). Limitato automaticamente. |
Classe PhongMaterial
PhongMaterial estende LambertMaterial con supporto per evidenziazioni speculari, implementando il classico modello di shading Phong. È comune negli asset FBX e COLLADA.
export class PhongMaterial extends LambertMaterialImageRenderOptions
A3DObject ← Material ← LambertMaterial ← PhongMaterial
ImageRenderOptions
Crea un materiale Phong blu brillante.
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
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
specularColor | `Vector3 | null` | null |
specularFactor | number | 0.0 | Moltiplicatore scalare per il contributo speculare. |
shininess | number | 0.0 | Esponente di lucentezza Phong — valori più alti producono evidenziazioni più strette. |
reflectionColor | `Vector3 | null` | null |
reflectionFactor | number | 0.0 | Moltiplicatore scalare per il contributo di riflessione. |
Classe PbrMaterial
PbrMaterial implementa il modello PBR metallic-roughness glTF 2.0. Usa questa classe per scene che saranno salvate come glTF/GLB, o quando l’asset FBX di origine contiene materiali PBR.
export class PbrMaterial extends MaterialImageRenderOptions
A3DObject ← Material ← PbrMaterial
ImageRenderOptions
Crea un materiale PBR dorato e salvalo in un file 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
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
albedo | `Vector3 | null` | null |
albedoTexture | `TextureBase | null` | null |
normalTexture | `TextureBase | null` | null |
metallicFactor | number | 0.0 | Fattore metallic nell’intervallo 0–1. 1.0 = completamente metallico. |
roughnessFactor | number | 0.0 | Fattore di rugosità nell’intervallo 0–1. 0.0 = liscio come uno specchio. |
metallicRoughness | `TextureBase | null` | null |
occlusionTexture | `TextureBase | null` | null |
occlusionFactor | number | 0.0 | Intensità dell’effetto di occlusione ambientale. |
emissiveColor | `Vector3 | null` | null |
emissiveTexture | `TextureBase | null` | null |
transparency | number | 0.0 | Fattore di opacità nell’intervallo 0–1. Limitato automaticamente. |
Metodi statici
PbrMaterial.fromMaterial(material)
Crea un nuovo PbrMaterial da un generico Material istanza, copiando il name.
static fromMaterial(material: Material): PbrMaterial