UNPKG

babylon-mmd

Version:
76 lines (75 loc) 3.85 kB
import type { Material } from "@babylonjs/core/Materials/material"; import type { Mesh } from "@babylonjs/core/Meshes/mesh"; import type { MorphTargetManager } from "@babylonjs/core/Morph/morphTargetManager"; import type { Nullable } from "@babylonjs/core/types"; import type { MmdModelMetadata } from "../../Loader/mmdModelMetadata"; import type { IMmdMaterialProxyConstructor } from "../IMmdMaterialProxy"; import type { IRuntimeMorph } from "../mmdMorphControllerBase"; import { MmdMorphControllerBase } from "../mmdMorphControllerBase"; import type { IWasmTypedArray } from "./Misc/IWasmTypedArray"; /** * The MmdWasmMorphController uses `MorphTargetManager` to handle position uv morphs, while the material, bone, and group morphs are handled by CPU bound * * bone morphs are handled by WASM * * As a result, it reproduces the behavior of the MMD morph system */ export declare class MmdWasmMorphController extends MmdMorphControllerBase { private readonly _wasmMorphWeights; private readonly _wasmMorphIndexMap; /** * Creates a new MmdWasmMorphController * @param wasmMorphWeights WASM side morph weights * @param wasmMorphIndexMap Mmd morph to WASM morph index map * @param materials MMD materials which are order of mmd metadata * @param meshes MMD meshes which are order of mmd metadata * @param materialProxyConstructor The constructor of `IMmdMaterialProxy` * @param morphsMetadata Morphs metadata * @param morphTargetManagers MorphTargetManagers */ constructor(wasmMorphWeights: IWasmTypedArray<Float32Array>, wasmMorphIndexMap: Int32Array, materials: readonly Material[], meshes: readonly Mesh[], materialProxyConstructor: Nullable<IMmdMaterialProxyConstructor<Material>>, morphsMetadata: readonly MmdModelMetadata.Morph[], morphTargetManagers: MorphTargetManager[]); /** * Sets the weight of the morph * * If there are multiple morphs with the same name, all of them will be set to the same weight, this is the behavior of MMD * * IMPORTANT: when wasm runtime using buffered evaluation, this method must be called before waiting for the WasmMmdRuntime.lock * otherwise, it can cause a datarace * @param morphName Name of the morph * @param weight Weight of the morph */ setMorphWeight(morphName: string, weight: number): void; /** * Sets the weight of the morph from the index * * This method is faster than `setMorphWeight` because it does not need to search the morphs with the given name * * IMPORTANT: when wasm runtime using buffere evaluation, this method with upadteWasm must be called before waiting for the WasmMmdRuntime.lock * otherwise, it can cause a datarace * @param morphIndex Index of the morph * @param weight Weight of the morph * @param updateWasm Whether to update the WASM side morph weight (default: true) */ setMorphWeightFromIndex(morphIndex: number, weight: number, updateWasm?: boolean): void; /** * Set the weights of all morphs to 0 * * IMPORTANT: when wasm runtime using buffered evaluation, this method must be called before waiting for the WasmMmdRuntime.lock * otherwise, it can cause a datarace */ resetMorphWeights(): void; /** * Synchronize the morph weights to WASM side * * IMPORTANT: when wasm runtime using buffered evaluation, this method must be called before waiting for the WasmMmdRuntime.lock * otherwise, it can cause a datarace */ syncWasmMorphWeights(): void; protected _resetBoneMorph(_morph: IRuntimeMorph): void; protected _applyBoneMorph(_morph: IRuntimeMorph, _weight: number): void; /** * @internal * Morph index map from js morph index to wasm morph index */ get wasmMorphIndexMap(): ArrayLike<number>; }