summit/frontend/node_modules/three-stdlib/exporters/MMDExporter.cjs.map

1 line
7.2 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"MMDExporter.cjs","sources":["../../src/exporters/MMDExporter.ts"],"sourcesContent":["import { Matrix4, Quaternion, Vector3, Bone, SkinnedMesh } from 'three'\n// @ts-ignore\nimport { CharsetEncoder } from '../libs/mmdparser'\n\n/**\n * Dependencies\n * - mmd-parser https://github.com/takahirox/mmd-parser\n */\n\nclass MMDExporter {\n /* TODO: implement\n\t// mesh -> pmd\n\tthis.parsePmd = function ( object ) {\n\t};\n\t*/\n\n /* TODO: implement\n\t// mesh -> pmx\n\tthis.parsePmx = function ( object ) {\n\t};\n\t*/\n\n /* TODO: implement\n\t// animation + skeleton -> vmd\n\tthis.parseVmd = function ( object ) {\n\t};\n\t*/\n\n /*\n * skeleton -> vpd\n * Returns Shift_JIS encoded Uint8Array. Otherwise return strings.\n */\n public parseVpd(skin: SkinnedMesh, outputShiftJis: boolean, useOriginalBones: boolean): Uint8Array | string | null {\n if (skin.isSkinnedMesh !== true) {\n console.warn('THREE.MMDExporter: parseVpd() requires SkinnedMesh instance.')\n return null\n }\n\n function toStringsFromNumber(num: number): string {\n if (Math.abs(num) < 1e-6) num = 0\n\n let a = num.toString()\n\n if (a.indexOf('.') === -1) {\n a += '.'\n }\n\n a += '000000'\n\n const index = a.indexOf('.')\n\n const d = a.slice(0, index)\n const p = a.slice(index + 1, index + 7)\n\n return d + '.' + p\n }\n\n function toStringsFromArray(array: number[]): string {\n const a = []\n\n for (let i = 0, il = array.length; i < il; i++) {\n a.push(toStringsFromNumber(array[i]))\n }\n\n return a.join(',')\n }\n\n skin.updateMatrixWorld(true)\n\n const bones = skin.skeleton.bones\n const bones2 = this.getBindBones(skin)\n\n const position = new Vector3()\n const quaternion = new Quaternion()\n const quaternion2 = new Quaternion()\n const matrix = new Matrix4()\n\n const array = []\n array.push('Vocaloid Pose Data file')\n array.push('')\n array.push((skin.name !== '' ? skin.name.replace(/\\s/g, '_') : 'skin') + '.osm;')\n array.push(bones.length + ';')\n array.push('')\n\n for (let i = 0, il = bones.length; i < il; i++) {\n const bone = bones[i]\n const bone2 = bones2[i]\n\n /*\n * use the bone matrix saved before solving IK.\n * see CCDIKSolver for the detail.\n */\n if (\n useOriginalBones === true &&\n bone.userData.ik !== undefined &&\n bone.userData.ik.originalMatrix !== undefined\n ) {\n matrix.fromArray(bone.userData.ik.originalMatrix)\n } else {\n matrix.copy(bone.matrix)\n }\n\n position.setFromMatrixPosition(matrix)\n quaternion.setFromRotationMatrix(matrix)\n\n const pArray = position.sub(bone2.position).toArray()\n const qArray = quaternion2.copy(bone2.quaternion).conjugate().multiply(quaternion).toArray()\n\n // right to left\n pArray[2] = -pArray[2]\n qArray[0] = -qArray[0]\n qArray[1] = -qArray[1]\n\n array.push('Bone' + i + '{' + bone.name)\n array.push(' ' + toStringsFromArray(pArray) + ';')\n array.push(' ' + toStringsFromArray(qArray) + ';')\n array.push('}')\n array.push('')\n }\n\n array.push('')\n\n const lines = array.join('\\n')\n\n return outputShiftJis === true ? this.unicodeToShiftjis(lines) : lines\n }\n\n // Unicode to Shift_JIS table\n private u2sTable: { [key: string]: number | undefined } | undefined\n\n private unicodeToShiftjis(str: string): Uint8Array {\n if (this.u2sTable === undefined) {\n const encoder = new CharsetEncoder()\n const table = encoder.s2uTable\n this.u2sTable = {}\n\n const keys = Object.keys(table)\n\n for (let i = 0, il = keys.length; i < il; i++) {\n let key = keys[i]\n\n const value = table[key]\n\n this.u2sTable[value] = parseInt(key)\n }\n }\n\n const array = []\n\n for (let i = 0, il = str.length; i < il; i++) {\n const code = str.charCodeAt(i)\n\n const value = this.u2sTable[cod