Materials — LambertMaterial, PhongMaterial, PbrMaterial

Materials — LambertMaterial, PhongMaterial, PbrMaterial

Pakotne: @aspose/3d (v24.12.0)

@aspose/3d piegādā trīs konkrētas materiālu klases, kas paplašina abstrakto Material bāzi. Tās aptver trīs ēnošanas modeļus, kas visbiežāk sastopami 3D apmaiņas formātos:

  • LambertMaterial — difūzs + ambients + emisīvs (izmanto OBJ/MTL un vecākos FBX resursus)
  • PhongMaterial — paplašina Lambertu ar spekulāro izceluma īpašībām
  • PbrMaterial — fiziski balstīts modelis, kas atbilst glTF 2.0 materiālu definīcijai

Visas materiālu klases tiek eksportētas no galvenā @aspose/3d ieejas punkta.

import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';

Klase Material (abstraktā bāze)

Material ir abstraktā pamata klase visām materiāliem. Tā paplašina A3DObject, nodrošinot name īpašību un tekstūras slotu API.

export class Material extends A3DObject

ImageRenderOptions

ImageRenderOptionsImageRenderOptionsImageRenderOptions
namestringMateriāla nosaukums, kā tas parādās ainas grafā un eksporta izvādē.

ImageRenderOptions

getTexture(slotName)

Atgriež TextureBase piešķirts norādītajam slotam, vai null ja neviens nav piešķirts.

getTexture(slotName: string): TextureBase | null

setTexture(slotName, texture)

Piešķir TextureBase instanci norādītajam slotam.

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

Klase LambertMaterial

LambertMaterial modelē difūzu atspoguļojumu ar izvēles iespēju ambientālajām un emisijas sastāvdaļām. Tas ir materiāla veids, kas parasti tiek radīts, ielādējot OBJ failus ar .mtl bibliotēkas.

export class LambertMaterial extends Material

ImageRenderOptions

A3DObject ← Material ← LambertMaterial

ImageRenderOptions

Piešķiriet sarkanam difūzajam materiālam mezglam.

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

ImageRenderOptionsImageRenderOptionsImageRenderOptionsImageRenderOptions
diffuseColor`Vector3null`null
ambientColor`Vector3null`null
emissiveColor`Vector3null`null
transparentColor`Vector3null`null
transparencynumber0.0Caurspīdīguma koeficients diapazonā no 0.0 (pilnīgi necaurspīdīgs) līdz 1.0 (pilnīgi caurspīdīgs). Automātiski ierobežots.

Klase PhongMaterial

PhongMaterial paplašina LambertMaterial ar spekulāro spīduma atbalstu, īstenojot klasisko Phong ēnošanas modeli. Tas ir izplatīts FBX un COLLADA aktīvos.

export class PhongMaterial extends LambertMaterial

ImageRenderOptions

A3DObject ← Material ← LambertMaterial ← PhongMaterial

ImageRenderOptions

Izveidojiet spīdīgu zilu Phong materiālu.

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

ImageRenderOptionsImageRenderOptionsImageRenderOptionsImageRenderOptions
specularColor`Vector3null`null
specularFactornumber0.0Skaitliska reizinātāja koeficients spekulārā ieguldījumam.
shininessnumber0.0Phong spīdīguma eksponents — augstākas vērtības rada asākus spīdējumus.
reflectionColor`Vector3null`null
reflectionFactornumber0.0Skaitliska reizinātāja koeficients atspoguļojuma ieguldījumam.

Klase PbrMaterial

PbrMaterial īsteno glTF 2.0 metāla-raušuma PBR modeli. Izmantojiet šo klasi ainas, kas tiks saglabātas kā glTF/GLB, vai kad avota FBX resurss satur PBR materiālus.

export class PbrMaterial extends Material

ImageRenderOptions

A3DObject ← Material ← PbrMaterial

ImageRenderOptions

Izveidojiet zelta PBR materiālu un saglabājiet to glTF failā.

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

ImageRenderOptionsImageRenderOptionsImageRenderOptionsImageRenderOptions
albedo`Vector3null`null
albedoTexture`TextureBasenull`null
normalTexture`TextureBasenull`null
metallicFactornumber0.0Metāla koeficients 0–1 diapazonā. 1.0 = pilnīgi metāla.
roughnessFactornumber0.0Rūdas koeficients 0–1 diapazonā. 0.0 = spoguļgluds.
metallicRoughness`TextureBasenull`null
occlusionTexture`TextureBasenull`null
occlusionFactornumber0.0Vides aptumšošanas efekta stiprums.
emissiveColor`Vector3null`null
emissiveTexture`TextureBasenull`null
transparencynumber0.0Caurspīdīguma koeficients 0–1 diapazonā. Automātiski ierobežots.

Statiskās metodes

PbrMaterial.fromMaterial(material)

Izveido jaunu PbrMaterial no vispārēja Material instanci, kopējot name.

static fromMaterial(material: Material): PbrMaterial
 Latviešu