Material

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

NameTypeAccessDescription
MAP_SPECULAR``ReadGets the map specular.
MAP_DIFFUSE``ReadGets the map diffuse.
MAP_EMISSIVE``ReadGets the map emissive.
MAP_AMBIENT``ReadGets the map ambient.
MAP_NORMAL``ReadGets the map normal.

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

SignatureDescription
`constructor(name: stringnull)`
getTexture(_slotName: string) → `TextureBasenull`
setTexture(_slotName: string, _texture: TextureBase)Sets the texture value.

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


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

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