Materials — LambertMaterial, PhongMaterial, PbrMaterial
パッケージ: @aspose/3d (v24.12.0)
@aspose/3d 抽象基底を拡張する具体的なマテリアルクラスを3つ提供します。 Material それらは、3D 交換フォーマットで最も一般的に見られる3つのシェーディングモデルをカバーしています::
LambertMaterial— diffuse + ambient + emissive(OBJ/MTL および古い FBX アセットで使用)PhongMaterial— Lambert を拡張し、スペキュラハイライト特性を持ちますPbrMaterial— glTF 2.0 のマテリアル定義に一致する物理ベースモデル
すべてのマテリアルクラスはメインからエクスポートされます @aspose/3d エントリーポイントです。.
import { LambertMaterial, PhongMaterial, PbrMaterial } from '@aspose/3d';クラス Material(抽象基底)
Material はすべてのマテリアルの抽象基底クラスです。拡張します A3DObject, 提供する name プロパティとテクスチャスロット API。.
export class Material extends A3DObjectImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
name | string | シーン グラフおよびエクスポート出力に表示されるマテリアル名。. |
ImageRenderOptions
getTexture(slotName)
返す TextureBase 指定されたスロットに割り当てられたもの、または null 割り当てがない場合。.
getTexture(slotName: string): TextureBase | nullsetTexture(slotName, texture)
割り当てます TextureBase インスタンスを指定されたスロットに。.
setTexture(slotName: string, texture: TextureBase): voidクラス LambertMaterial
LambertMaterial 拡散反射をオプションの環境光および放射光の寄与とともにモデル化します。これは OBJ ファイルを使用してロードする際に一般的に生成されるマテリアルタイプです。 .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
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
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 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
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
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 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
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
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