|
1 | 1 | // MMD for System Animator |
2 | | -// (2024-07-30) |
| 2 | +// (2024-08-18) |
3 | 3 |
|
4 | 4 | var use_full_spectrum = true |
5 | 5 |
|
@@ -1002,8 +1002,7 @@ if (!ao.ontimeupdate) |
1002 | 1002 |
|
1003 | 1003 | if (json.System_Animator_motion_para) { |
1004 | 1004 | for (const name in json.System_Animator_motion_para) { |
1005 | | - if (MMD_SA_options.motion_para[name]) |
1006 | | - MMD_SA_options.motion_para[name] = Object.assign(MMD_SA_options.motion_para[name]||{}, json.System_Animator_motion_para[name]); |
| 1005 | + MMD_SA_options.motion_para[name] = Object.assign(MMD_SA_options.motion_para[name]||{}, json.System_Animator_motion_para[name]); |
1007 | 1006 | } |
1008 | 1007 | DEBUG_show('✅Motion config imported', 3); |
1009 | 1008 | } |
@@ -12602,7 +12601,8 @@ function MMD_LR(name) { |
12602 | 12601 | const nj_list = ["0","1","2","3"]; |
12603 | 12602 | function MMD_finger(name) { |
12604 | 12603 | let j_index; |
12605 | | - var f = finger_map[RegExp.$1.toLowerCase().replace(/middle/, 'mid')]; |
| 12604 | +// use 'middle' instead of /middle/, as regular expression will change RegExp.$ values |
| 12605 | + var f = finger_map[RegExp.$1.toLowerCase().replace('middle', 'mid')]; |
12606 | 12606 | if (f) { |
12607 | 12607 | j_index = parseInt(RegExp.$2); |
12608 | 12608 | } |
@@ -12636,9 +12636,27 @@ function rig(k, v) { |
12636 | 12636 | _rig_map[k] = v |
12637 | 12637 | } |
12638 | 12638 |
|
| 12639 | +function is_armature(obj) { |
| 12640 | + if (!has_armature) return false; |
| 12641 | +/* |
| 12642 | +// FBX-to-glTF test |
| 12643 | + do { |
| 12644 | + obj = obj.parent; |
| 12645 | + if (!obj) return false; |
| 12646 | + if (obj.name == 'Armature') return true; |
| 12647 | + } |
| 12648 | + while (obj?.name); |
| 12649 | +*/ |
| 12650 | + return false; |
| 12651 | +} |
| 12652 | + |
12639 | 12653 | const bone_map = []; |
| 12654 | +let has_armature; |
12640 | 12655 | asset.traverse((obj)=>{ |
12641 | | - if (obj.isBone) { |
| 12656 | + if (obj.name == 'Armature') { |
| 12657 | + has_armature = true; |
| 12658 | + } |
| 12659 | + else if (obj.isBone || is_armature(obj)) { |
12642 | 12660 | if (bone_map.findIndex(name=>name==obj.name) == -1) |
12643 | 12661 | bone_map.push(obj.name); |
12644 | 12662 | } |
@@ -12794,6 +12812,9 @@ Object.entries(rig_map.VRM).forEach(kv=>{ |
12794 | 12812 |
|
12795 | 12813 | skeletons.forEach(s=>s.pose()); |
12796 | 12814 |
|
| 12815 | +// FBX-to-glTF test |
| 12816 | +//if (!skeletons.length) skeletons = [{}]; |
| 12817 | + |
12797 | 12818 | console.log('bone_clones', bone_clones) |
12798 | 12819 |
|
12799 | 12820 | VRM.fix_rig_map(rig_map.VRM); |
@@ -12871,6 +12892,15 @@ const hips_q_inv = hips_q.clone().conjugate(); |
12871 | 12892 |
|
12872 | 12893 | console.log('rig_rot,[hips_q]', rig_rot, [hips_q.clone()]);//, motion_hips.quaternion, motion_hips.parent.getWorldQuaternion(new THREE.Quaternion()), new THREE.Quaternion().copy(hips_q_inv).premultiply(motion_hips.quaternion).multiply(q2.copy(motion_hips.quaternion).conjugate()).multiply(hips_q)]); |
12873 | 12894 | let _rig_rot_perpendicular = Math.abs(rig_rot.w) % 1 < 0.0001; |
| 12895 | +/* |
| 12896 | +// FBX-to-glTF test |
| 12897 | +if (1) { |
| 12898 | + hips_q.set(-0.707,0,0,0.707).normalize(); |
| 12899 | + hips_q_inv.copy(hips_q).conjugate(); |
| 12900 | +// rig_rot.copy(hips_q) |
| 12901 | +} |
| 12902 | +else |
| 12903 | +*/ |
12874 | 12904 | if (skeletons.length && (bone_clones['hips'].clone.quaternion.w != 1)) { |
12875 | 12905 | if (_rig_rot_perpendicular) { |
12876 | 12906 | hips_q.copy(rig_rot); |
|
0 commit comments