UNPKG

babylon-mmd

Version:
154 lines (153 loc) 6.7 kB
import "@babylonjs/core/Physics/joinedPhysicsEngineComponent"; import "@babylonjs/core/Physics/v1/physicsEngineComponent"; import type { VertexBuffer } from "@babylonjs/core"; import { BoundingInfo } from "@babylonjs/core/Culling/boundingInfo"; import { Matrix, Vector3 } from "@babylonjs/core/Maths/math.vector"; import type { IMeshDataOptions } from "@babylonjs/core/Meshes/abstractMesh"; import { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh"; import type { Geometry } from "@babylonjs/core/Meshes/geometry"; import type { Mesh } from "@babylonjs/core/Meshes/mesh"; import { PhysicsImpostor, type PhysicsImpostorParameters } from "@babylonjs/core/Physics/v1/physicsImpostor"; import type { Scene } from "@babylonjs/core/scene"; import type { DeepImmutable, Nullable } from "@babylonjs/core/types"; import { PmxObject } from "../../Loader/Parser/pmxObject"; import type { ILogger } from "../ILogger"; import type { IMmdRuntimeBone } from "../IMmdRuntimeBone"; import type { IMmdModelPhysicsCreationOptions } from "../mmdRuntime"; import type { IMmdPhysics, IMmdPhysicsModel } from "./IMmdPhysics"; declare class MmdPhysicsMesh extends AbstractMesh { readonly linkedBone: Nullable<IMmdRuntimeBone>; physicsMode: PmxObject.RigidBody.PhysicsMode; readonly bodyOffsetMatrix: Matrix; readonly bodyOffsetMatrixInverse: Matrix; private readonly _customBoundingInfo; physicsImpostor: Nullable<MmdAmmoPhysicsImpostor | MmdAmmoPhysicsImpostorWithBone>; constructor(name: string, scene: Scene, linkedBone: Nullable<IMmdRuntimeBone>, physicsMode: PmxObject.RigidBody.PhysicsMode, customBoundingInfo: Nullable<BoundingInfo>); private static readonly _WorldMatrix; computeBodyOffsetMatrix(parentWorldMatrixInverse: DeepImmutable<Matrix>): void; getBoundingInfo(): BoundingInfo; get _positions(): Nullable<Vector3[]>; copyVerticesData(_kind: string, _vertexData: { [kind: string]: Float32Array; }): void; refreshBoundingInfo(options: IMeshDataOptions): AbstractMesh; refreshBoundingInfo(applySkeletonOrOptions: boolean | IMeshDataOptions, applyMorph: boolean): AbstractMesh; get geometry(): Nullable<Geometry>; getVertexBuffer(_kind: string, _bypassInstanceData?: boolean): Nullable<VertexBuffer>; } interface IAmmoPhysicsImpostorParameters extends PhysicsImpostorParameters { group: number; mask: number; } declare class MmdAmmoPhysicsImpostor extends PhysicsImpostor { private _temporalKinematic; private _kinematicToggle; constructor(mesh: MmdPhysicsMesh, type: number, options: IAmmoPhysicsImpostorParameters, scene: Scene); private _makeKinematic; private static readonly _ZeroVector; private _restoreDynamic; get temporalKinematic(): boolean; set temporalKinematic(value: boolean); get kinematicToggle(): boolean; set kinematicToggle(value: boolean); } declare class MmdAmmoPhysicsImpostorWithBone extends MmdAmmoPhysicsImpostor { readonly linkedBone: Nullable<IMmdRuntimeBone>; constructor(mesh: MmdPhysicsMesh, type: number, options: IAmmoPhysicsImpostorParameters, linkedBone: Nullable<IMmdRuntimeBone>, scene: Scene); } /** * MMD ammo physics model is container of the ammo.js physics resources of the MMD model */ export declare class MmdAmmoPhysicsModel implements IMmdPhysicsModel { private readonly _mmdPhysics; private readonly _nodes; private readonly _impostors; private readonly _rootMesh; private readonly _syncedRigidBodyStates; private _disabledRigidBodyCount; private readonly _ammoInstance; private readonly _tmpBtVector3; private readonly _tmpBtQuaternion; private readonly _tmpBtTransform; /** * Create a new MMD ammo.js physics model * @param mmdPhysics MMD ammo physics * @param nodes MMD physics transform nodes * @param impostors Physics impostors * @param rootMesh Root mesh of the MMD model * @param ammoInstance Ammo.js instance */ constructor(mmdPhysics: MmdAmmoPhysics, nodes: Nullable<MmdPhysicsMesh>[], impostors: Nullable<MmdAmmoPhysicsImpostor>[], rootMesh: Mesh, ammoInstance: any); /** * Dispose the physics resources */ dispose(): void; private static readonly _NodeWorldMatrix; private static readonly _ZeroVector; private static readonly _Position; private static readonly _Rotation; /** * Reset the rigid body positions and velocities */ initialize(): void; /** * Indicate whether all IK must be solved */ get needDeoptimize(): boolean; /** * commit rigid body states to physics model * * if rigidBodyStates[i] is 0, the rigid body motion type is kinematic, * if rigidBodyStates[i] is 1 and physicsMode is not FollowBone, the rigid body motion type is dynamic. * * @param rigidBodyStates state of rigid bodies for physics toggle */ commitBodyStates(rigidBodyStates: Uint8Array): void; private static readonly _EulerAngles1; private static readonly _EulerAngles2; /** * 0: unknown, 1: kinematic, 2: target transform */ private _bodyKinematicToggleMap; /** * Set the rigid bodies transform to the bones transform */ syncBodies(): void; private static readonly _BoneWorldPosition; /** * Set the bones transform to the rigid bodies transform */ syncBones(): void; } /** * Use the v1 physics engine to build the physics model of the MMD model * * If you do not want to use a physics engine, you can reduce the bundling size by not import this class */ export declare class MmdAmmoPhysics implements IMmdPhysics { private readonly _scene; private readonly _kinematicOnces; /** * Create a new MMD ammo.js physics * * Scene must have a physics engine enabled * @param scene The scene to build the physics model */ constructor(scene: Scene); /** * Build the physics model of the MMD model * @param rootMesh Root mesh of the MMD model * @param bones MMD runtime bones * @param rigidBodies rigid bodies information * @param joints joints information * @param logger Logger * @param physicsOptions Optional physics options * @returns MMD physics model * @throws If the ammo physics engine is not enabled */ buildPhysics(rootMesh: Mesh, bones: readonly IMmdRuntimeBone[], rigidBodies: PmxObject["rigidBodies"], joints: PmxObject["joints"], logger: ILogger, physicsOptions: Nullable<IMmdModelPhysicsCreationOptions>): IMmdPhysicsModel; private readonly _onAfterPhysics; /** @internal */ _makeKinematicOnce(impostor: MmdAmmoPhysicsImpostor): void; } export {};