summit/frontend/node_modules/three-stdlib/animation/MMDPhysics.cjs.map

1 line
48 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"MMDPhysics.cjs","sources":["../../src/animation/MMDPhysics.js"],"sourcesContent":["import {\n Bone,\n BoxGeometry,\n Color,\n Euler,\n Matrix4,\n Mesh,\n MeshBasicMaterial,\n Object3D,\n Quaternion,\n SphereGeometry,\n Vector3,\n} from 'three'\nimport { CapsuleGeometry } from '../_polyfill/CapsuleGeometry'\n\n/**\n * Dependencies\n * - Ammo.js https://github.com/kripken/ammo.js\n *\n * MMDPhysics calculates physics with Ammo(Bullet based JavaScript Physics engine)\n * for MMD model loaded by MMDLoader.\n *\n * TODO\n * - Physics in Worker\n */\n\n/* global Ammo */\n\nclass MMDPhysics {\n /**\n * @param {THREE.SkinnedMesh} mesh\n * @param {Array<Object>} rigidBodyParams\n * @param {Array<Object>} (optional) constraintParams\n * @param {Object} params - (optional)\n * @param {Number} params.unitStep - Default is 1 / 65.\n * @param {Integer} params.maxStepNum - Default is 3.\n * @param {Vector3} params.gravity - Default is ( 0, - 9.8 * 10, 0 )\n */\n constructor(mesh, rigidBodyParams, constraintParams = [], params = {}) {\n if (typeof Ammo === 'undefined') {\n throw new Error('THREE.MMDPhysics: Import ammo.js https://github.com/kripken/ammo.js')\n }\n\n this.manager = new ResourceManager()\n\n this.mesh = mesh\n\n /*\n * I don't know why but 1/60 unitStep easily breaks models\n * so I set it 1/65 so far.\n * Don't set too small unitStep because\n * the smaller unitStep can make the performance worse.\n */\n this.unitStep = params.unitStep !== undefined ? params.unitStep : 1 / 65\n this.maxStepNum = params.maxStepNum !== undefined ? params.maxStepNum : 3\n this.gravity = new Vector3(0, -9.8 * 10, 0)\n\n if (params.gravity !== undefined) this.gravity.copy(params.gravity)\n\n this.world = params.world !== undefined ? params.world : null // experimental\n\n this.bodies = []\n this.constraints = []\n\n this._init(mesh, rigidBodyParams, constraintParams)\n }\n\n /**\n * Advances Physics calculation and updates bones.\n *\n * @param {Number} delta - time in second\n * @return {MMDPhysics}\n */\n update(delta) {\n const manager = this.manager\n const mesh = this.mesh\n\n // rigid bodies and constrains are for\n // mesh's world scale (1, 1, 1).\n // Convert to (1, 1, 1) if it isn't.\n\n let isNonDefaultScale = false\n\n const position = manager.allocThreeVector3()\n const quaternion = manager.allocThreeQuaternion()\n const scale = manager.allocThreeVector3()\n\n mesh.matrixWorld.decompose(position, quaternion, scale)\n\n if (scale.x !== 1 || scale.y !== 1 || scale.z !== 1) {\n isNonDefaultScale = true\n }\n\n let parent\n\n if (isNonDefaultScale) {\n parent = mesh.parent\n\n if (parent !== null) mesh.parent = null\n\n scale.copy(this.mesh.scale)\n\n mesh.scale.set(1, 1, 1)\n mesh.updateMatrixWorld(true)\n }\n\n // calculate physics and update bones\n\n this._updateRigidBodies()\n this._stepSimulation(delta)\n this._updateBones()\n\n // restore mesh if converted above\n\n if (isNonDefaultScale) {\n if (parent !== null) mesh.parent = parent\n\n mesh.scale.copy(scale)\n }\n\n manager.freeThreeVector3(scale)\n manager.freeThreeQuaternion(quaternion)\n manager.freeThreeVector3(position)\n\n return this\n }\n\n /**\n * Resets rigid bodies transorm to current bone's.\n *\n * @return {MMDPhysics}\n */\n reset() {\n for (let i = 0, il = this.bodies.length; i < il; i++) {\n this.bodies[i].reset()\n }\n\n return this\n }\n\n /**\n * Warm ups Rigid bodies. Calculates cycles steps.\n *\n * @param {Integer} cycles\n * @return {MMDPhysics}\n */\n warmup(cycles) {\n for (let i = 0; i < cycles; i++) {\n this.update(1 / 60)\n }\n\n return this\n }\n\n /**\n * Sets gravity.\n *\n * @param {Vector3} gravity\n * @return {MMDPhysicsHelper}\n */\n setGravity(gravity) {\n this.world.setGravity(new Ammo.btVector3(gravity.x, gravity.y, gravity.z))\