Material
패키지: @aspose/3d (v24.12.0)
@aspose/3d 추상 클래스를 확장하는 세 가지 구체적인 재질 클래스를 제공합니다. Material 기반입니다. 이들은 3D 교환 포맷에서 가장 일반적으로 사용되는 세 가지 셰이딩 모델을 다룹니다:
LambertMaterial— diffuse + ambient + emissive (OBJ/MTL 및 오래된 FBX 에셋에서 사용됨)PhongMaterial— Lambert를 확장하여 specular highlight 속성을 포함PbrMaterial— glTF 2.0 재질 정의와 일치하는 물리 기반 모델
모든 재질 클래스는 메인 @aspose/3d 진입점에서 내보내집니다.
import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';클래스 Material (추상 기반)
Material 은 모든 재질의 추상 기반 클래스입니다. 이를 확장하여 A3DObject, 다음을 제공합니다: name 속성과 텍스처 슬롯 API를 제공합니다.
export class Material extends A3DObjectImageRenderOptions
| Name | Type | Access | Description |
|---|---|---|---|
MAP_SPECULAR | `` | Read | Gets the map specular. |
MAP_DIFFUSE | `` | Read | Gets the map diffuse. |
MAP_EMISSIVE | `` | Read | Gets the map emissive. |
MAP_AMBIENT | `` | Read | Gets the map ambient. |
MAP_NORMAL | `` | Read | Gets the map normal. |
ImageRenderOptions
getTexture(slotName)
다음을 반환합니다: TextureBase 지정된 슬롯에 할당된 값, 또는 null 할당된 것이 없을 경우.
getTexture(slotName: string): TextureBase | nullsetTexture(slotName, texture)
할당합니다 TextureBase 인스턴스를 명명된 슬롯에.
setTexture(slotName: string, texture: TextureBase): void클래스 LambertMaterial
LambertMaterial 옵션인 주변광 및 방출 기여를 포함한 확산 반사를 모델링합니다. 이는 OBJ 파일을 로드할 때 일반적으로 생성되는 재질 유형입니다 with .mtl 라이브러리.
export class LambertMaterial extends MaterialImageRenderOptions
A3DObject ← Material ← LambertMaterial
ImageRenderOptions
노드에 빨간색 디퓨즈 재질을 할당합니다.
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
| Signature | Description |
|---|---|
| `constructor(name: string | null)` |
getTexture(_slotName: string) → `TextureBase | null` |
setTexture(_slotName: string, _texture: TextureBase) | Sets the texture value. |
클래스 PhongMaterial
PhongMaterial 확장 LambertMaterial specular 하이라이트 지원을 포함하고, 고전적인 Phong 셰이딩 모델을 구현합니다. 이는 FBX 및 COLLADA 에셋에서 일반적입니다.
export class PhongMaterial extends LambertMaterialImageRenderOptions
A3DObject ← Material ← LambertMaterial ← PhongMaterial
ImageRenderOptions
빛나는 파란색 Phong 재질을 생성합니다.
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
클래스 PbrMaterial
PbrMaterial glTF 2.0 metallic-roughness PBR 모델을 구현합니다. 이 클래스를 glTF/GLB 로 저장될 씬이나, 원본 FBX 에셋에 PBR 재질이 포함된 경우에 사용하십시오.
export class PbrMaterial extends MaterialImageRenderOptions
A3DObject ← Material ← PbrMaterial
ImageRenderOptions
금색 PBR 재질을 만들고 이를 glTF 파일에 저장합니다.
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
정적 메서드
PbrMaterial.fromMaterial(material)
새로운 것을 생성합니다 PbrMaterial 일반적인 Material 인스턴스, 복사하여 name.
static fromMaterial(material: Material): PbrMaterial