import type { AssetContainer } from "@babylonjs/core/assetContainer"; import type { ISceneLoaderProgressEvent } from "@babylonjs/core/Loading/sceneLoader"; import { Material } from "@babylonjs/core/Materials/material"; import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture"; import type { Mesh } from "@babylonjs/core/Meshes/mesh"; import type { Scene } from "@babylonjs/core/scene"; import type { Nullable } from "@babylonjs/core/types"; import type { IMmdMaterialBuilder, MaterialInfo, ReferencedMesh, TextureInfo } from "./IMmdMaterialBuilder"; import { MmdAsyncTextureLoader } from "./mmdAsyncTextureLoader"; import type { ILogger } from "./Parser/ILogger"; import type { IArrayBufferFile } from "./referenceFileResolver"; import { ReferenceFileResolver } from "./referenceFileResolver"; import { TextureAlphaChecker } from "./textureAlphaChecker"; /** * Render method of MMD material * * The drawing behavior of MMD is not conducive to modern renderers like Babylon.js * That's why you need to decide which shading method is right for your use case */ export declare enum MmdMaterialRenderMethod { /** * Force depth write alpha blending with alpha evaluation * * This approach first determines via alpha evaluation if the meshes to be rendered are opaque, * and then only enables forceDepthWrite and performs alphaBlending on non-opaque meshes * * This approach is similar to mmd, but is more performance friendly and partially solves the draw order problem */ DepthWriteAlphaBlendingWithEvaluation = 0, /** * Force depth write alpha blending * * Materials loaded this way will all have forceDepthWrite true and will alphaBlend true * * Since it does depth writing and alpha blending, the draw order becomes very important * * This approach gives you exactly the same results as mmd, * but it introduces a problem that mmd is known for: manually managing the draw order */ DepthWriteAlphaBlending = 1, /** * Alpha evaluation * * This method uses an alpha evaluation to determine whether the mesh is best rendered as opaque, alphatest, or alphablend * * Since this method does not use forceDepthWrite, it can give different results than mmd but has better compatibility for several shader effects */ AlphaEvaluation = 2 } /** * Material constructor type for mmd material builder */ export type MmdMaterialConstructor = new (name: string, scene: Scene) => TMaterial; /** * Material builder base class for creating mmd model materials */ export declare abstract class MaterialBuilderBase implements IMmdMaterialBuilder { /** * Render method of MMD standard material (default: DepthWriteAlphaBlendingWithEvaluation) */ renderMethod: MmdMaterialRenderMethod; /** * Whether to force disable alpha evaluation (default: false) * * If true, load time alpha evaluation will be disabled * * For load time optimization, it is recommended to disable alpha evaluation feature and set the blending mode for the material manually */ forceDisableAlphaEvaluation: boolean; /** * The threshold of material alpha to use transparency mode. (default: 195) * * lower value is more likely to use transparency mode. (0 - 255) */ alphaThreshold: number; /** * The threshold of transparency mode to use alpha blend. (default: 100) * * lower value is more likely to use alpha test mode. otherwise use alpha blend mode */ alphaBlendThreshold: number; /** * The canvas resolution to evaluate alpha (default: 512) * * Resolution of the render canvas used to evaluate alpha internally * * The higher the resolution, the higher the accuracy and the longer the load time */ alphaEvaluationResolution: number; /** * Whether to delete the texture buffer after loading (default: true) */ deleteTextureBufferAfterLoad: boolean; /** * For parallel texture loading and caching duplicate texture requests * * we use a custom texture loader to load the textures */ protected readonly _textureLoader: MmdAsyncTextureLoader; /** * Next starting alpha index for force depth write alpha blending rendering */ nextStartingAlphaIndex: number; /** * Alpha index increments per model for force depth write alpha blending rendering */ alphaIndexIncrementsPerModel: number; private readonly _materialConstructor; /** * pass the material constructor to the builder for creating the material * @param materialConstructor material constructor */ constructor(materialConstructor: MmdMaterialConstructor); buildMaterials(uniqueId: number, materialsInfo: readonly MaterialInfo[], texturesInfo: readonly TextureInfo[], imagePathTable: readonly string[], rootUrl: string, fileRootId: string, referenceFiles: readonly File[] | readonly IArrayBufferFile[], referencedMeshes: (readonly ReferencedMesh[])[], meshes: Mesh[], scene: Scene, assetContainer: Nullable, textureNameMap: Nullable>, logger: ILogger, onTextureLoadProgress?: (event: ISceneLoaderProgressEvent) => void, onTextureLoadComplete?: () => void): Material[]; /** * Texture name map should preserve the original texture name for lossless bpmx conversion * * @param materialsInfo materials information * @param materials materials * @param imagePathTable image path table * @param texturesInfo textures information * @param textureNameMap texture name map to be built */ protected abstract _buildTextureNameMap(materialsInfo: readonly MaterialInfo[], materials: TMaterial[], imagePathTable: readonly string[], texturesInfo: readonly TextureInfo[], textureNameMap: Map): void; private _setMeshesAlphaIndex; /** * Load general scalar properties (diffuse, specular, ambient, alpha, shininess) * * This method can be overridden for customizing the material loading process * @param material Material * @param materialInfo Material information * @param meshes Meshes that use the material */ abstract loadGeneralScalarProperties(material: TMaterial, materialInfo: MaterialInfo, meshes: readonly ReferencedMesh[]): Promise | void; /** * Load diffuse texture * * This method can be overridden for customizing the material loading process * @param uniqueId Model unique id * @param material Material * @param materialInfo Material information * @param imagePathTable Image path table * @param textureInfo Texture information * @param scene Scene * @param assetContainer Asset container * @param rootUrl Root url * @param referenceFileResolver Reference file resolver * @param logger Logger * @param onTextureLoadComplete Texture load complete callback */ abstract loadDiffuseTexture(uniqueId: number, material: TMaterial, materialInfo: MaterialInfo, imagePathTable: readonly string[], textureInfo: Nullable, scene: Scene, assetContainer: Nullable, rootUrl: string, referenceFileResolver: ReferenceFileResolver, logger: ILogger, onTextureLoadComplete?: () => void): Promise | void; /** * Evaluate diffuse texture transparency mode from the diffuse texture and meshes * @param diffuseTexture diffuse texture * @param evaluatedTransparency evaluated transparency * @param referencedMeshes meshes that use the diffuse texture * @param logger logger * @param getTextureAlphaChecker get texture alpha checker function * @returns transparency mode */ protected _evaluateDiffuseTextureTransparencyModeAsync(diffuseTexture: BaseTexture, evaluatedTransparency: number, referencedMeshes: readonly ReferencedMesh[], logger: ILogger, getTextureAlphaChecker: () => Nullable): Promise>; /** * set material alpha blend mode * * this method is called after diffuse texture loading * @param material Material * @param materialInfo Material information * @param meshes Meshes that use the material * @param logger Logger * @param getTextureAlphaChecker Get texture alpha checker function */ abstract setAlphaBlendMode(material: TMaterial, materialInfo: MaterialInfo, meshes: readonly ReferencedMesh[], logger: ILogger, getTextureAlphaChecker: () => Nullable): Promise | void; /** * Load sphere texture * * This method can be overridden for customizing the material loading process * @param uniqueId Model unique id * @param material Material * @param materialInfo Material information * @param imagePathTable Texture path table * @param textureInfo Texture information * @param scene Scene * @param assetContainer Asset container * @param rootUrl Root url * @param referenceFileResolver Reference file resolver * @param logger Logger * @param onTextureLoadComplete Texture load complete callback */ abstract loadSphereTexture(uniqueId: number, material: TMaterial, materialInfo: MaterialInfo, imagePathTable: readonly string[], textureInfo: Nullable, scene: Scene, assetContainer: Nullable, rootUrl: string, referenceFileResolver: ReferenceFileResolver, logger: ILogger, onTextureLoadComplete?: () => void): Promise | void; /** * Load toon texture * * This method can be overridden for customizing the material loading process * @param uniqueId Model unique id * @param material Material * @param materialInfo Material information * @param imagePathTable Image path table * @param textureInfo Texture information * @param scene Scene * @param assetContainer Asset container * @param rootUrl Root url * @param referenceFileResolver Reference file resolver * @param logger Logger * @param onTextureLoadComplete Texture load complete callback */ abstract loadToonTexture(uniqueId: number, material: TMaterial, materialInfo: MaterialInfo, imagePathTable: readonly string[], textureInfo: Nullable, scene: Scene, assetContainer: Nullable, rootUrl: string, referenceFileResolver: ReferenceFileResolver, logger: ILogger, onTextureLoadComplete?: () => void): Promise | void; /** * Load outline rendering properties * * This method can be overridden for customizing the material loading process * @param material Material * @param materialInfo Material information * @param logger Logger */ abstract loadOutlineRenderingProperties(material: TMaterial, materialInfo: MaterialInfo, logger: ILogger): Promise | void; /** * Called after building a single material * * This method is called after the material and textures have been loaded * @param material Material * @param materialIndex Material index * @param materialInfo Material information * @param imagePathTable Image path table * @param texturesInfo Texture information * @param scene Scene * @param rootUrl Root url */ afterBuildSingleMaterial: (material: TMaterial, materialIndex: number, materialInfo: MaterialInfo, imagePathTable: readonly string[], texturesInfo: readonly TextureInfo[], scene: Scene, rootUrl: string) => void; }