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āmPbrMaterial— 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 A3DObjectImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
name | string | Materiā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 | nullsetTexture(slotName, texture)
Piešķir TextureBase instanci norādītajam slotam.
setTexture(slotName: string, texture: TextureBase): voidKlase 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 MaterialImageRenderOptions
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
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
diffuseColor | `Vector3 | null` | null |
ambientColor | `Vector3 | null` | null |
emissiveColor | `Vector3 | null` | null |
transparentColor | `Vector3 | null` | null |
transparency | number | 0.0 | Caurspī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 LambertMaterialImageRenderOptions
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
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
specularColor | `Vector3 | null` | null |
specularFactor | number | 0.0 | Skaitliska reizinātāja koeficients spekulārā ieguldījumam. |
shininess | number | 0.0 | Phong spīdīguma eksponents — augstākas vērtības rada asākus spīdējumus. |
reflectionColor | `Vector3 | null` | null |
reflectionFactor | number | 0.0 | Skaitliska 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 MaterialImageRenderOptions
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
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
albedo | `Vector3 | null` | null |
albedoTexture | `TextureBase | null` | null |
normalTexture | `TextureBase | null` | null |
metallicFactor | number | 0.0 | Metāla koeficients 0–1 diapazonā. 1.0 = pilnīgi metāla. |
roughnessFactor | number | 0.0 | Rūdas koeficients 0–1 diapazonā. 0.0 = spoguļgluds. |
metallicRoughness | `TextureBase | null` | null |
occlusionTexture | `TextureBase | null` | null |
occlusionFactor | number | 0.0 | Vides aptumšošanas efekta stiprums. |
emissiveColor | `Vector3 | null` | null |
emissiveTexture | `TextureBase | null` | null |
transparency | number | 0.0 | Caurspī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