Materials — LambertMaterial, PhongMaterial, PbrMaterial
Package: @aspose/3d (v24.12.0)
@aspose/3d ships three concrete material classes that extend the abstract Material base. They cover the three shading models most commonly found in 3D interchange formats:
LambertMaterial— diffuse + ambient + emissive (used by OBJ/MTL and older FBX assets)PhongMaterial— extends Lambert with specular highlight propertiesPbrMaterial— physically-based model matching the glTF 2.0 material definition
All material classes are exported from the main @aspose/3d entry point.
import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';Class Material (abstract base)
Material is the abstract base class for all materials. It extends A3DObject, providing the name property and the texture slot API.
export class Material extends A3DObjectProperties
| Property | Type | Description |
|---|---|---|
name | string | The material name as it appears in the scene graph and export output. |
Static Properties
| Property | Value | Description |
|---|---|---|
Material.MAP_DIFFUSE | 'Diffuse' | Texture slot key for the diffuse/albedo map. |
Material.MAP_SPECULAR | 'Specular' | Texture slot key for the specular map. |
Material.MAP_EMISSIVE | 'Emissive' | Texture slot key for the emissive map. |
Material.MAP_AMBIENT | 'Ambient' | Texture slot key for the ambient occlusion map. |
Material.MAP_NORMAL | 'Normal' | Texture slot key for the normal map. |
Methods
getTexture(slotName)
Returns the TextureBase assigned to the named slot, or null if none has been assigned.
getTexture(slotName: string): TextureBase | nullsetTexture(slotName, texture)
Assigns a TextureBase instance to the named slot.
setTexture(slotName: string, texture: TextureBase): voidClass LambertMaterial
LambertMaterial models diffuse reflection with optional ambient and emissive contributions. It is the material type commonly produced when loading OBJ files with .mtl libraries.
export class LambertMaterial extends MaterialInheritance
A3DObject ← Material ← LambertMaterial
Examples
Assign a red diffuse material to a node.
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');Properties
| Property | Type | Default | Description |
|---|---|---|---|
diffuseColor | Vector3 | null | null | The base surface color as an RGB Vector3 (components in 0–1 range). |
ambientColor | Vector3 | null | null | The ambient light contribution color. |
emissiveColor | Vector3 | null | null | Color emitted by the surface regardless of incoming light. |
transparentColor | Vector3 | null | null | Color of the transparent region, used by some FBX exporters. |
transparency | number | 0.0 | Opacity factor in the range 0.0 (fully opaque) to 1.0 (fully transparent). Clamped automatically. |
Class PhongMaterial
PhongMaterial extends LambertMaterial with specular highlight support, implementing the classic Phong shading model. It is common in FBX and COLLADA assets.
export class PhongMaterial extends LambertMaterialInheritance
A3DObject ← Material ← LambertMaterial ← PhongMaterial
Examples
Create a shiny blue Phong material.
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
Properties (additions to LambertMaterial)
| Property | Type | Default | Description |
|---|---|---|---|
specularColor | Vector3 | null | null | The color of specular highlights. |
specularFactor | number | 0.0 | Scalar multiplier for the specular contribution. |
shininess | number | 0.0 | Phong shininess exponent — higher values produce tighter highlights. |
reflectionColor | Vector3 | null | null | The color of environment reflections. |
reflectionFactor | number | 0.0 | Scalar multiplier for the reflection contribution. |
Class PbrMaterial
PbrMaterial implements the glTF 2.0 metallic-roughness PBR model. Use this class for scenes that will be saved as glTF/GLB, or when the source FBX asset contains PBR materials.
export class PbrMaterial extends MaterialInheritance
A3DObject ← Material ← PbrMaterial
Examples
Build a gold PBR material and save it in a glTF file.
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);Properties
| Property | Type | Default | Description |
|---|---|---|---|
albedo | Vector3 | null | null | Base color (albedo) as an RGB Vector3 with components in 0–1 range. |
albedoTexture | TextureBase | null | null | Texture used as the albedo/base-color map. |
normalTexture | TextureBase | null | null | Tangent-space normal map texture. |
metallicFactor | number | 0.0 | Metallic factor in 0–1 range. 1.0 = fully metallic. |
roughnessFactor | number | 0.0 | Roughness factor in 0–1 range. 0.0 = mirror-smooth. |
metallicRoughness | TextureBase | null | null | Combined metallic-roughness texture (B channel = metallic, G channel = roughness). |
occlusionTexture | TextureBase | null | null | Ambient occlusion texture. |
occlusionFactor | number | 0.0 | Strength of the ambient occlusion effect. |
emissiveColor | Vector3 | null | null | Emissive color as an RGB Vector3. |
emissiveTexture | TextureBase | null | null | Emissive texture map. |
transparency | number | 0.0 | Opacity factor in 0–1 range. Clamped automatically. |
Static Methods
PbrMaterial.fromMaterial(material)
Creates a new PbrMaterial from a generic Material instance, copying the name.
static fromMaterial(material: Material): PbrMaterial