Material
Pacote: @aspose/3d (v24.12.0)
@aspose/3d fornece três classes concretas de material que estendem a abstrata Material base. Elas cobrem os três modelos de sombreamento mais comuns em formatos de intercâmbio 3D:
LambertMaterial— difuso + ambiente + emissivo (usado por ativos OBJ/MTL e FBX mais antigos)PhongMaterial— estende Lambert com propriedades de realce especularPbrMaterial— modelo baseado em física que corresponde à definição de material glTF 2.0
Todas as classes de material são exportadas do principal @aspose/3d ponto de entrada.
import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';Classe Material (base abstrata)
Material é a classe base abstrata para todos os materiais. Ela estende A3DObject, fornecendo o name propriedade e a API de slot de textura.
export class Material extends A3DObjectImageRenderOptions
| 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. |
ImageRenderOptions
getTexture(slotName)
Retorna o TextureBase atribuído ao slot nomeado, ou null se nenhum foi atribuído.
getTexture(slotName: string): TextureBase | nullsetTexture(slotName, texture)
Atribui um TextureBase instância ao slot nomeado.
setTexture(slotName: string, texture: TextureBase): voidClasse LambertMaterial
LambertMaterial modela reflexão difusa com contribuições opcionais de ambiente e emissiva. É o tipo de material comumente gerado ao carregar arquivos OBJ com .mtl bibliotecas.
export class LambertMaterial extends MaterialImageRenderOptions
A3DObject ← Material ← LambertMaterial
ImageRenderOptions
Atribua um material difuso vermelho a um nó.
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
| Signature | Description |
|---|---|
| `constructor(name: string | null)` |
getTexture(_slotName: string) → `TextureBase | null` |
setTexture(_slotName: string, _texture: TextureBase) | Sets the texture value. |
Classe PhongMaterial
PhongMaterial estende LambertMaterial com suporte a realces especulares, implementando o clássico modelo de sombreamento Phong. É comum em ativos FBX e COLLADA.
export class PhongMaterial extends LambertMaterialImageRenderOptions
A3DObject ← Material ← LambertMaterial ← PhongMaterial
ImageRenderOptions
Crie um material Phong azul brilhante.
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
Classe PbrMaterial
PbrMaterial implementa o modelo PBR metalicidade-aspereza glTF 2.0. Use esta classe para cenas que serão salvas como glTF/GLB, ou quando o ativo FBX de origem contém materiais PBR.
export class PbrMaterial extends MaterialImageRenderOptions
A3DObject ← Material ← PbrMaterial
ImageRenderOptions
Crie um material PBR dourado e salve-o em um arquivo 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
Métodos estáticos
PbrMaterial.fromMaterial(material)
Cria um novo PbrMaterial de um genérico Material instância, copiando o name.
static fromMaterial(material: Material): PbrMaterial