Materials — LambertMaterial, PhongMaterial, PbrMaterial
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
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
name | string | O nome do material como aparece no grafo de cena e na saída de exportação. |
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
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
diffuseColor | `Vector3 | null` | null |
ambientColor | `Vector3 | null` | null |
emissiveColor | `Vector3 | null` | null |
transparentColor | `Vector3 | null` | null |
transparency | number | 0.0 | Fator de opacidade no intervalo de 0.0 (totalmente opaco) a 1.0 (totalmente transparente). Limitado automaticamente. |
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
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
specularColor | `Vector3 | null` | null |
specularFactor | number | 0.0 | Multiplicador escalar para a contribuição especular. |
shininess | number | 0.0 | Expoente de brilho Phong — valores mais altos produzem realces mais estreitos. |
reflectionColor | `Vector3 | null` | null |
reflectionFactor | number | 0.0 | Multiplicador escalar para a contribuição da reflexão. |
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
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
albedo | `Vector3 | null` | null |
albedoTexture | `TextureBase | null` | null |
normalTexture | `TextureBase | null` | null |
metallicFactor | number | 0.0 | Fator metálico no intervalo de 0–1. 1.0 = totalmente metálico. |
roughnessFactor | number | 0.0 | Fator de aspereza no intervalo de 0–1. 0.0 = espelhado suave. |
metallicRoughness | `TextureBase | null` | null |
occlusionTexture | `TextureBase | null` | null |
occlusionFactor | number | 0.0 | Intensidade do efeito de oclusão ambiente. |
emissiveColor | `Vector3 | null` | null |
emissiveTexture | `TextureBase | null` | null |
transparency | number | 0.0 | Fator de opacidade no intervalo 0–1. Limitado automaticamente. |
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