Material
Paquete: @aspose/3d (v24.12.0)
@aspose/3d incluye tres clases de material concretas que extienden la abstracta Material base. Cubren los tres modelos de sombreado más comunes en los formatos de intercambio 3D:
LambertMaterial— difuso + ambiente + emisivo (usado por OBJ/MTL y FBX más antiguos)PhongMaterial— extiende Lambert con propiedades de reflejo especularPbrMaterial— modelo basado en la física que coincide con la definición de material glTF 2.0
Todas las clases de material se exportan desde el punto de entrada principal @aspose/3d punto de entrada.
import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';Clase Material (base abstracta)
Material es la clase base abstracta para todos los materiales. Extiende A3DObject, proporcionando el name propiedad y la API de ranura de textura.
export class Material extends A3DObjectExample
| 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. |
Example
getTexture(slotName)
Devuelve el TextureBase asignado a la ranura nombrada, o null si no se ha asignado ninguno.
getTexture(slotName: string): TextureBase | nullsetTexture(slotName, texture)
Asigna un TextureBase instancia a la ranura nombrada.
setTexture(slotName: string, texture: TextureBase): voidClase LambertMaterial
LambertMaterial modela la reflexión difusa con contribuciones opcionales de ambiente y emisión. Es el tipo de material que se genera comúnmente al cargar archivos OBJ con .mtl bibliotecas.
export class LambertMaterial extends MaterialExample
A3DObject ← Material ← LambertMaterial
Example
Asigna un material difuso rojo 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');Example
| Signature | Description |
|---|---|
| `constructor(name: string | null)` |
getTexture(_slotName: string) → `TextureBase | null` |
setTexture(_slotName: string, _texture: TextureBase) | Sets the texture value. |
Clase PhongMaterial
PhongMaterial extiende LambertMaterial con soporte de reflejos especulares, implementando el modelo clásico de sombreado Phong. Es común en activos FBX y COLLADA.
export class PhongMaterial extends LambertMaterialExample
A3DObject ← Material ← LambertMaterial ← PhongMaterial
Example
Crea un material Phong azul 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
Example
Clase PbrMaterial
PbrMaterial Implementa el modelo PBR metálico‑áspero glTF 2.0. Use esta clase para escenas que se guardarán como glTF/GLB, o cuando el activo FBX de origen contiene materiales PBR.
export class PbrMaterial extends MaterialExample
A3DObject ← Material ← PbrMaterial
Example
Construye un material PBR dorado y guárdalo en un archivo 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);Example
Métodos estáticos
PbrMaterial.fromMaterial(material)
Crea un nuevo PbrMaterial de un genérico Material instancia, copiando el name.
static fromMaterial(material: Material): PbrMaterial