Materials — LambertMaterial, PhongMaterial, PbrMaterial

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 properties
  • PbrMaterial — 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 A3DObject

Properties

PropertyTypeDescription
namestringThe material name as it appears in the scene graph and export output.

Static Properties

PropertyValueDescription
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 | null

setTexture(slotName, texture)

Assigns a TextureBase instance to the named slot.

setTexture(slotName: string, texture: TextureBase): void

Class 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 Material

Inheritance

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

PropertyTypeDefaultDescription
diffuseColorVector3 | nullnullThe base surface color as an RGB Vector3 (components in 0–1 range).
ambientColorVector3 | nullnullThe ambient light contribution color.
emissiveColorVector3 | nullnullColor emitted by the surface regardless of incoming light.
transparentColorVector3 | nullnullColor of the transparent region, used by some FBX exporters.
transparencynumber0.0Opacity 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 LambertMaterial

Inheritance

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)

PropertyTypeDefaultDescription
specularColorVector3 | nullnullThe color of specular highlights.
specularFactornumber0.0Scalar multiplier for the specular contribution.
shininessnumber0.0Phong shininess exponent — higher values produce tighter highlights.
reflectionColorVector3 | nullnullThe color of environment reflections.
reflectionFactornumber0.0Scalar 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 Material

Inheritance

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

PropertyTypeDefaultDescription
albedoVector3 | nullnullBase color (albedo) as an RGB Vector3 with components in 0–1 range.
albedoTextureTextureBase | nullnullTexture used as the albedo/base-color map.
normalTextureTextureBase | nullnullTangent-space normal map texture.
metallicFactornumber0.0Metallic factor in 0–1 range. 1.0 = fully metallic.
roughnessFactornumber0.0Roughness factor in 0–1 range. 0.0 = mirror-smooth.
metallicRoughnessTextureBase | nullnullCombined metallic-roughness texture (B channel = metallic, G channel = roughness).
occlusionTextureTextureBase | nullnullAmbient occlusion texture.
occlusionFactornumber0.0Strength of the ambient occlusion effect.
emissiveColorVector3 | nullnullEmissive color as an RGB Vector3.
emissiveTextureTextureBase | nullnullEmissive texture map.
transparencynumber0.0Opacity 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