Materials — LambertMaterial, PhongMaterial, PbrMaterial
Materials — LambertMaterial, PhongMaterial, PbrMaterial
包:: @aspose/3d (v24.12.0)
@aspose/3d 提供三个具体的材质类,继承自抽象的 Material 基类。它们覆盖了 3D 交换格式中最常见的三种着色模型::
LambertMaterial— 漫反射 + 环境光 + 自发光(OBJ/MTL 和较旧的 FBX 资源使用)PhongMaterial— 在 Lambert 基础上扩展了高光属性PbrMaterial— 与 glTF 2.0 材质定义相匹配的基于物理的模型
所有材质类都从 main 导出 @aspose/3d 入口点。.
import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';类 Material(抽象基类)
Material 是所有材质的抽象基类。它扩展自 A3DObject,,提供 name 属性以及纹理槽 API。.
export class Material extends A3DObjectProperties
| Properties | Properties | Properties |
|---|---|---|
name | string | 材质名称,在场景图和导出输出中显示的名称。. |
Properties
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 MaterialProperties
A3DObject ← Material ← LambertMaterial
Properties
为节点分配一个红色漫反射材质。.
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 | 不透明度因子,范围为 0.0(完全不透明)到 1.0(完全透明)。会自动限制。. |
类 PhongMaterial
PhongMaterial 扩展 LambertMaterial 支持镜面高光,实现经典的 Phong 着色模型。它在 FBX 和 COLLADA 资源中很常见。.
export class PhongMaterial extends LambertMaterialProperties
A3DObject ← Material ← LambertMaterial ← PhongMaterial
Properties
创建一个光亮的蓝色 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
Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
specularColor | `Vector3 | null` | null |
specularFactor | number | 0.0 | 镜面贡献的标量乘数。. |
shininess | number | 0.0 | Phong 高光指数 — 值越高产生越紧凑的高光。. |
reflectionColor | `Vector3 | null` | null |
reflectionFactor | number | 0.0 | 反射贡献的标量乘数。. |
类 PbrMaterial
PbrMaterial 实现 glTF 2.0 金属-粗糙度 PBR 模型。将此类用于将保存为 glTF/GLB 的场景,或当源 FBX 资源包含 PBR 材质时使用。.
export class PbrMaterial extends MaterialProperties
A3DObject ← Material ← PbrMaterial
Properties
构建一个金色的 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);Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
albedo | `Vector3 | null` | null |
albedoTexture | `TextureBase | null` | null |
normalTexture | `TextureBase | null` | null |
metallicFactor | number | 0.0 | 金属度因子在 0–1 范围内。1.0 = 完全金属。. |
roughnessFactor | number | 0.0 | 粗糙度因子在 0–1 范围内。0.0 = 镜面光滑。. |
metallicRoughness | `TextureBase | null` | null |
occlusionTexture | `TextureBase | null` | null |
occlusionFactor | number | 0.0 | 环境遮蔽效果的强度。. |
emissiveColor | `Vector3 | null` | null |
emissiveTexture | `TextureBase | null` | null |
transparency | number | 0.0 | 不透明度因子在 0–1 范围内。自动钳位。. |
静态方法
PbrMaterial.fromMaterial(material)
创建一个新的 PbrMaterial 从通用的 Material 实例,复制 name.
static fromMaterial(material: Material): PbrMaterial