Materials — LambertMaterial, PhongMaterial, PbrMaterial
Paket: @aspose/3d (v24.12.0)
@aspose/3d liefert drei konkrete Materialklassen, die die abstrakte Material Basis. Sie decken die drei am häufigsten in 3D-Austauschformaten vorkommenden Shading-Modelle ab:
LambertMaterial— diffus + ambient + emissiv (verwendet von OBJ/MTL und älteren FBX-Assets)PhongMaterial— erweitert Lambert um spekulare GlanzlichteeigenschaftenPbrMaterial— physikalisch basiertes Modell, das der glTF 2.0 Materialdefinition entspricht
Alle Materialklassen werden aus dem Haupt @aspose/3d Einstiegspunkt exportiert.
import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';Klasse Material (abstrakte Basis)
Material ist die abstrakte Basisklasse für alle Materialien. Sie erweitert A3DObject, die bereitstellt name Eigenschaft und die Texture Slot API.
export class Material extends A3DObjectProperties
| Properties | Properties | Properties |
|---|---|---|
name | string | Der Materialname, wie er im Szenengraphen und in der Exportausgabe erscheint. |
Properties
getTexture(slotName)
Gibt zurück TextureBase zugewiesene zum benannten Slot, oder null falls keiner zugewiesen wurde.
getTexture(slotName: string): TextureBase | nullsetTexture(slotName, texture)
Weist ein TextureBase Instanz dem benannten Slot zu.
setTexture(slotName: string, texture: TextureBase): voidKlasse LambertMaterial
LambertMaterial modelliert diffuse Reflexion mit optionalen Umgebungs- und Emissionsbeiträgen. Es ist der Materialtyp, der üblicherweise erzeugt wird, wenn OBJ-Dateien mit .mtl Bibliotheken.
export class LambertMaterial extends MaterialProperties
A3DObject ← Material ← LambertMaterial
Properties
Weisen Sie einem Knoten ein rotes diffuses Material zu.
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
| Properties | Properties | Properties | Properties |
|---|---|---|---|
diffuseColor | `Vector3 | null` | null |
ambientColor | `Vector3 | null` | null |
emissiveColor | `Vector3 | null` | null |
transparentColor | `Vector3 | null` | null |
transparency | number | 0.0 | Opazitätsfaktor im Bereich 0.0 (vollständig undurchsichtig) bis 1.0 (vollständig transparent). Automatisch geklemmt. |
Klasse PhongMaterial
PhongMaterial erweitert LambertMaterial mit Unterstützung für spekulare Glanzlichter, implementiert das klassische Phong-Shading-Modell. Es ist in FBX- und COLLADA-Assets üblich.
export class PhongMaterial extends LambertMaterialProperties
A3DObject ← Material ← LambertMaterial ← PhongMaterial
Properties
Erstellen Sie ein glänzendes blaues 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
| Properties | Properties | Properties | Properties |
|---|---|---|---|
specularColor | `Vector3 | null` | null |
specularFactor | number | 0.0 | Skalarer Multiplikator für den spekularen Beitrag. |
shininess | number | 0.0 | Phong-Glanzexponent — höhere Werte erzeugen engere Glanzlichter. |
reflectionColor | `Vector3 | null` | null |
reflectionFactor | number | 0.0 | Skalarer Multiplikator für den Reflexionsbeitrag. |
Klasse PbrMaterial
PbrMaterial implementiert das glTF 2.0 Metallic‑Roughness PBR‑Modell. Verwenden Sie diese Klasse für Szenen, die als glTF/GLB gespeichert werden, oder wenn das Quell‑FBX‑Asset PBR‑Materialien enthält.
export class PbrMaterial extends MaterialProperties
A3DObject ← Material ← PbrMaterial
Properties
Erstelle ein goldenes PBR-Material und speichere es in einer glTF-Datei.
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
| Properties | Properties | Properties | Properties |
|---|---|---|---|
albedo | `Vector3 | null` | null |
albedoTexture | `TextureBase | null` | null |
normalTexture | `TextureBase | null` | null |
metallicFactor | number | 0.0 | Metallic‑Faktor im Bereich 0–1. 1.0 = vollständig metallic. |
roughnessFactor | number | 0.0 | Roughness‑Faktor im Bereich 0–1. 0.0 = spiegelglatt. |
metallicRoughness | `TextureBase | null` | null |
occlusionTexture | `TextureBase | null` | null |
occlusionFactor | number | 0.0 | Stärke des Ambient‑Occlusion‑Effekts. |
emissiveColor | `Vector3 | null` | null |
emissiveTexture | `TextureBase | null` | null |
transparency | number | 0.0 | Opazitätsfaktor im Bereich 0–1. Automatisch begrenzt. |
Statische Methoden
PbrMaterial.fromMaterial(material)
Erstellt ein neues PbrMaterial aus einem generischen Material Instanz, die kopiert. name.
static fromMaterial(material: Material): PbrMaterial