diff --git a/MMD.js/MMD_SA.js b/MMD.js/MMD_SA.js index 737235c..4711f4d 100644 --- a/MMD.js/MMD_SA.js +++ b/MMD.js/MMD_SA.js @@ -1,5 +1,5 @@ // MMD for System Animator -// (2024-06-19) +// (2024-07-14) var use_full_spectrum = true @@ -8974,9 +8974,9 @@ Model_obj.call(this, index, vrm, para); this.mesh = vrm.scene; this._joints_settings = []; -vrm.springBoneManager.joints.forEach( e => { +for ( const e of vrm.springBoneManager.joints ) { this._joints_settings.push(Object.assign({}, e.settings)); -}); +} if (!MMD_SA.MMD_started) vrm_list.push(this) @@ -9033,12 +9033,12 @@ const restrict_physics = MMD_SA.motion[_THREE.MMD.getModels()[this.index].skin._ const settings_default = this._joints_settings; // Set has no index let i = 0; -this.model.springBoneManager.joints.forEach( e => { -// e.settings.dragForce = 1 - e.settings.stiffness = settings_default[i].stiffness * ((restrict_physics) ? 10 : 1) * vrm_scale; +for ( const e of this.model.springBoneManager.joints ) { +//e.settings.dragForce = 1;//settings_default[i].dragForce; + e.settings.stiffness = settings_default[i].stiffness * ((restrict_physics) ? 10 : 1) * VRM.joint_stiffness_percent/100 * vrm_scale;//this.mesh.scale.x; e.settings.gravityPower = settings_default[i].gravityPower; i++; -}); +}; this.model.springBoneManager.reset(); //this.model.springBoneManager.setInitState(); @@ -9085,7 +9085,7 @@ if (vrm.springBoneManager) { for ( const joint of vrm.springBoneManager.joints ) { let j = model_para._joints[i]; if (!j) - j = model_para._joints[i] = { settings:{ stiffness:joint.settings.stiffness, hitRadius:joint.settings.hitRadius } }; + j = model_para._joints[i] = { settings:this._joints_settings[i] }; i++; joint.settings.stiffness = j.settings.stiffness * scale; @@ -9877,12 +9877,17 @@ if (!mesh.matrixAutoUpdate) { const finger_list_en = ["Thumb", "Index", "Middle", "Ring", "Little"]; const nj_list = ["0","1","2","3"]; + let joint_stiffness_percent; + return { get list() { return vrm_list; }, set list(v) { vrm_list = v; }, get vrm_scale() { return vrm_scale; }, + get joint_stiffness_percent () { return (joint_stiffness_percent == null) ? 100 : joint_stiffness_percent; }, + set joint_stiffness_percent (v) { joint_stiffness_percent = v; }, + get bone_map_MMD_to_VRM() { return bone_map_MMD_to_VRM; }, get bone_map_VRM_to_MMD() { return bone_map_VRM_to_MMD; }, @@ -15553,7 +15558,10 @@ case "口角下げ": case "上": case "下": morph_alt.push(m, 'まゆ'+m, '眉'+((m=='上')?'↑':'↓')); - break + break; +case "照れ": + morph_alt.push(m, '赤面'); + break; default: morph_alt.push(m); } diff --git a/images/XR Animator/animate.js b/images/XR Animator/animate.js index 22dd7ef..494a5f8 100644 --- a/images/XR Animator/animate.js +++ b/images/XR Animator/animate.js @@ -1,5 +1,5 @@ // XR Animator -// (2024-07-02) +// (2024-07-14) var MMD_SA_options = { @@ -2341,6 +2341,7 @@ if (diff > 0) { }, hip_adjustment: { feet_fixed_weight:1, + rotation_weight:1/3, }, arm_default_stickiness: { 'right' : { parent:{ name:'頭', weight:{ x:{left:1.5, right:0.5}, y:{down:1.5, up:0.5}, z:{backward:0.5, forward:1.5} } }, default_position_weight:0.1, default_rotation_weight:0.5, }, @@ -2391,6 +2392,7 @@ if (diff > 0) { }, hip_adjustment: { feet_fixed_weight:1, + rotation_weight:0.25, }, arm_default_stickiness: { 'left' : { parent:{ name:'頭', weight:{ x:{left:0.5, right:1.5}, y:{down:1.5, up:0.5}, z:{backward:0.5, forward:1.5} } }, default_position_weight:0.1, default_rotation_weight:0.5, }, @@ -2466,6 +2468,7 @@ if (z_para) { }, hip_adjustment: { feet_fixed_weight:0.9, + rotation_weight:0.25, }, arm_default_stickiness: { parent:{ weight:0.5 }, default_position_weight:1, default_rotation_weight:0.5, @@ -2867,7 +2870,7 @@ if (z_para) { position: { x: { add:0.2, scale:1.5 }, y: { add:0.4, scale:1.5 }, - z: { add:0.4, scale:2 }, + z: { add:0.3, scale:1.75 }, camera_weight: 0.75, }, }, @@ -3392,7 +3395,7 @@ wireframe:{ // hidden:true, // align_with_video:true, top:0.5, -//left:-(0.5),top:-1, +// left:(0.5),top:-1, //left:1, //top:0.8,left:0.4, //top:0,left:3, @@ -4104,8 +4107,7 @@ function swap_motion(index, index_to_swap=0, is_swap) { //DEBUG_show(index+'/'+index_to_swap+'/'+!!is_swap,0,1) let motion_id; if (index == null) { - const motion_para = MMD_SA.MMD.motionManager.para_SA; - motion_id = motion_para._path.replace(/^.+[\/\\]/, '').replace(/\.\w{3,4}$/, ''); + motion_id = MMD_SA.MMD.motionManager.filename;//MMD_SA.MMD.motionManager.para_SA._path.replace(/^.+[\/\\]/, '').replace(/\.\w{3,4}$/, ''); index = _motion_list[0].findIndex(m=>m.name==motion_id); } else { @@ -4376,7 +4378,7 @@ _motion_list[0] = [ {name:"sitting_sexy01", info:"Sit 04 (🙋/🦶)"}, - {name:"Mixamo - Female Sitting Pose01", info:"Sit 05 (🙋/🦶))"}, + {name:"Mixamo - Female Sitting Pose01", info:"Sit 05 (🙋/🦶)"}, {name:"Mixamo - Female Sitting Pose02", info:"Sit 06 (🙋/🦶)"}, @@ -4507,6 +4509,9 @@ MMD_SA_options.Dungeon.run_event('_POSE_',0,0); } }; +const hip_adjustment_set = ['_default_', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']; +const hip_adjustment_set_emoji = ['', 'Ⓐ', 'Ⓑ', 'Ⓒ', 'Ⓓ', 'Ⓔ', 'Ⓕ', 'Ⓖ', 'Ⓗ']; + MMD_SA_options.Dungeon_options.events_default["_POSE_"] = [ //0 [ @@ -4544,9 +4549,15 @@ const content = _motion_list[index].slice(ini, ini+9).map((m,i)=>{ info_suffix = '🏃'; } + const s = System._browser.camera.poseNet.hip_adjustment_set_by_motion_name[m.name]; + let _index = hip_adjustment_set.findIndex(_s=>_s==s); + if (_index == -1) + _index = 0; + info_suffix += hip_adjustment_set_emoji[_index]; + return (i+1)+'. ' + info_prefix + (m.info||m.name) + info_suffix; }).join('\n') -+ ((_has_custom_animation_) ? '\n0. (👤' + System._browser.translation.get('XR_Animator.UI.pose.custom_pose') + ')' : ''); ++ ((_has_custom_animation_) ? '\n0. (👤' + System._browser.translation.get('XR_Animator.UI.pose.custom_pose') + ')' : '') + ('\nN. ⏭️' + System._browser.translation.get('XR_Animator.UI.pose.next_poses')); //+ ((_has_custom_animation_) ? ('\n0. (👤Custom motion: ' + (((this._animation_on_ != null) ? this._animation_on_ : (MMD_SA.THREEX.enabled && MMD_SA.THREEX.get_model(0).animation.enabled) || (THREE.MMD.getModels()[0].skin._motion_index >= MMD_SA.motion_max_default))?'ON':'OFF') + ') (🙋)') : ''); //DEBUG_show(''+this._animation_on_,0,1) @@ -4558,7 +4569,7 @@ return content; }, bubble_index: 3, - para: { row_max:11, font_size:17, no_word_break:true }, + para: { row_max:11, font_size:16, no_word_break:true }, get branch_list() { const index = (System._browser.camera.poseNet.enabled) ? 2 : 1; @@ -4577,26 +4588,72 @@ return _motion_list[index].slice(ini, ini+9).map((m,i) => { return { key:i+1, on message: { index: 1, bubble_index: 3, - para: { row_max:11 }, - get content() { return System._browser.translation.get('XR_Animator.UI.pose.pose') + (_motion_page*9+1) + '-' + (_motion_page*9+9) + ' (' + System._browser.translation.get('XR_Animator.UI.pose.page') + (_motion_page+1) + ')\n' + ((_motion_page <= 1) ? '・' + System._browser.translation.get('XR_Animator.UI.pose.hotkey') + ': ' + ((_motion_page == 0) ? 'Alt' : 'Ctrl') + '+Numpad' + ((_has_custom_animation_) ? 0 : 1) + '-9\n' : '・' + System._browser.translation.get('XR_Animator.UI.pose.hotkey') + ': N/A') + '\nA. ' + System._browser.translation.get('XR_Animator.UI.pose.next_poses') + '\nB. ' + System._browser.translation.get('XR_Animator.UI.pose.shoulder_adjust') + ': ' + System._browser.translation.get('XR_Animator.UI.pose.shoulder_adjust.' + (MMD_SA.THREEX.shoulder_adjust||'Default')) + '\n' + System._browser.translation.get('XR_Animator.UI.pose.extra'); }, + para: { row_max:12, font_scale:0.95 }, + get content() { + const motion_id = MMD_SA.MMD.motionManager.filename; + const m_obj = MMD_SA_options._XRA_pose_list[0].find(p=>p.name==motion_id); + const info = m_obj?.info || 'N/A'; + + return [ +System._browser.translation.get('XR_Animator.UI.pose.pose') + (_motion_page*9+1) + '-' + (_motion_page*9+9) + ' (' + System._browser.translation.get('XR_Animator.UI.pose.page') + (_motion_page+1) + ')', +((_motion_page <= 1) ? '・' + System._browser.translation.get('XR_Animator.UI.pose.hotkey') + ': ' + ((_motion_page == 0) ? 'Alt' : 'Ctrl') + '+Numpad' + ((_has_custom_animation_) ? 0 : 1) + '-9' : '・' + System._browser.translation.get('XR_Animator.UI.pose.hotkey') + ': N/A'), +'・' + info, +'A. ┣ ' + System._browser.translation.get('XR_Animator.UI.pose.hip_adjustment_set') + ': ' + ((m_obj) ? (System._browser.camera.poseNet.hip_adjustment_set_by_motion_name[motion_id] || System._browser.translation.get('Misc.default')) : 'N/A') + '⬅️➡️', +System._browser.translation.get('XR_Animator.UI.pose.extra_current_pose'), +'E. ' + System._browser.translation.get('XR_Animator.UI.pose.shoulder_adjust') + ': ' + System._browser.translation.get('XR_Animator.UI.pose.shoulder_adjust.' + (MMD_SA.THREEX.shoulder_adjust||'Default')), +System._browser.translation.get('XR_Animator.UI.pose.extra'), +'X. ' + System._browser.translation.get('Misc.done'), + ].join('\n'); + }, branch_list: [ - { key:'A', event_id:{ func:()=>{ _motion_page++ }, goto_event:{id:'_POSE_',branch_index:0} } }, - { key:'B', event_id:{ func:()=>{ -const para = ['Full', '', 'Upper half', 'None']; -let index = (para.indexOf(MMD_SA.THREEX.shoulder_adjust||'')) + 1; -if (index >= para.length) - index = 0; -MMD_SA.THREEX.shoulder_adjust = para[index]; -System._browser.camera.DEBUG_show('NOTE: Restart the app for changes to apply to existing motions and poses.', 5); - }, goto_event:{id:'_POSE_',branch_index:0} }, + { key:'any', func:(e)=>{ +let step; + +if (/Arrow(Left|Right)/.test(e.code)) { + step = (e.code == 'ArrowLeft') ? -1 : 1; + + const motion_id = MMD_SA.MMD.motionManager.filename; + const m_obj = MMD_SA_options._XRA_pose_list[0].find(p=>p.name==motion_id); + if (!m_obj) return false; + + const s = System._browser.camera.poseNet.hip_adjustment_set_by_motion_name[motion_id]; + let index = hip_adjustment_set.findIndex(_s=>_s==s); + if (index == -1) + index = 0; + + index += step; + if (index < 0) { + index = hip_adjustment_set.length-1; + } + else if (index >= hip_adjustment_set.length) { + index = 0; + } + + if (index == 0) { + delete System._browser.camera.poseNet.hip_adjustment_set_by_motion_name[motion_id]; + } + else { + System._browser.camera.poseNet.hip_adjustment_set_by_motion_name[motion_id] = hip_adjustment_set[index]; + } +} +else { + return false; +} + +MMD_SA_options.Dungeon.run_event(null, 0, 0); + +return true; + } }, + + { key:'A', event_index:0, onmouseover: function (e) { MMD_SA_options.Dungeon.utils.tooltip( e.clientX, e.clientY, - System._browser.translation.get('XR_Animator.UI.pose.shoulder_adjust.tooltip') + System._browser.translation.get('XR_Animator.UI.pose.hip_adjustment_set.tooltip') ); } }, - { key:'C', event_id:{ func:()=>{ mirror_pose(); }, goto_event:{id:'_POSE_',branch_index:0} }, + { key:'B', event_id:{ func:()=>{ mirror_pose(); }, goto_event:{id:'_POSE_',branch_index:0} }, onmouseover: function (e) { MMD_SA_options.Dungeon.utils.tooltip( e.clientX, e.clientY, @@ -4604,7 +4661,7 @@ MMD_SA_options.Dungeon.utils.tooltip( ); } }, - { key:'D', event_id:{ func:()=>{ swap_motion(); }, goto_event:{id:'_POSE_',branch_index:0} }, + { key:'C', event_id:{ func:()=>{ swap_motion(); }, goto_event:{id:'_POSE_',branch_index:0} }, onmouseover: function (e) { MMD_SA_options.Dungeon.utils.tooltip( e.clientX, e.clientY, @@ -4612,7 +4669,30 @@ MMD_SA_options.Dungeon.utils.tooltip( ); } }, - { key:'E', event_id:{ func:()=>{ reset_list_order(); DEBUG_show('(pose list reset)',3); }, goto_event:{id:'_POSE_',branch_index:0} }, + { key:'D', event_id:{ func:()=>{ export_motion_config() }, goto_event:{id:'_POSE_',branch_index:0} }, + onmouseover: function (e) { +MMD_SA_options.Dungeon.utils.tooltip( + e.clientX, e.clientY, + System._browser.translation.get('XR_Animator.UI.pose.export_current_pose_config.tooltip') +); + } + }, + { key:'E', event_id:{ func:()=>{ +const para = ['Full', '', 'Upper half', 'None']; +let index = (para.indexOf(MMD_SA.THREEX.shoulder_adjust||'')) + 1; +if (index >= para.length) + index = 0; +MMD_SA.THREEX.shoulder_adjust = para[index]; +System._browser.camera.DEBUG_show('NOTE: Restart the app for changes to apply to existing motions and poses.', 5); + }, goto_event:{id:'_POSE_',branch_index:0} }, + onmouseover: function (e) { +MMD_SA_options.Dungeon.utils.tooltip( + e.clientX, e.clientY, + System._browser.translation.get('XR_Animator.UI.pose.shoulder_adjust.tooltip') +); + } + }, + { key:'F', event_id:{ func:()=>{ reset_list_order(); DEBUG_show('(pose list reset)',3); }, goto_event:{id:'_POSE_',branch_index:0} }, onmouseover: function (e) { MMD_SA_options.Dungeon.utils.tooltip( e.clientX, e.clientY, @@ -4620,7 +4700,7 @@ MMD_SA_options.Dungeon.utils.tooltip( ); } }, - { key:'F', event_id:{ + { key:'G', event_id:{ message: { index: 1, bubble_index: 3, @@ -4638,14 +4718,7 @@ MMD_SA_options.Dungeon.utils.tooltip( ); } }, - { key:'G', event_id:{ func:()=>{ export_motion_config() }, goto_event:{id:'_POSE_',branch_index:0} }, - onmouseover: function (e) { -MMD_SA_options.Dungeon.utils.tooltip( - e.clientX, e.clientY, - System._browser.translation.get('XR_Animator.UI.pose.export_current_pose_config.tooltip') -); - } - }, + { key:'N', event_id:{ func:()=>{ _motion_page++ }, goto_event:{id:'_POSE_',branch_index:0} } }, { key:'X', is_closing_event:true, event_id:{ next_step:{} } }, ] } @@ -8749,7 +8822,7 @@ return System._browser.translation.get('XR_Animator.UI.UI_options.scene.skybox') ,bubble_index: 3 ,para: { row_max:11 } ,branch_list: [ - { key:'any', func:(e)=>{ + { key:'any', func:(e)=>{ let step; if (/Arrow(Up|Down)/.test(e.code)) { @@ -8805,7 +8878,7 @@ else { MMD_SA_options.Dungeon.run_event(null, panorama_branch, 0); return true; - } } + } } ,{ key:1, event_id: { func: function () { remove_skybox(); @@ -9180,7 +9253,7 @@ MMD_SA_options.Dungeon.para_by_grid_id[2].ground_y = explorer_ground_y; ,[ { message: { - get content() { return 'XR Animator (v0.25.0)\n' + System._browser.translation.get('XR_Animator.UI.UI_options.about_XR_Animator.message'); } + get content() { return 'XR Animator (v0.26.0)\n' + System._browser.translation.get('XR_Animator.UI.UI_options.about_XR_Animator.message'); } ,bubble_index: 3 ,branch_list: [ { key:1, event_id: { @@ -9405,15 +9478,47 @@ setTimeout(()=>{ { message: { get content() { -return System._browser.translation.get('XR_Animator.UI.UI_options.miscellaneous_options.message').replace(/\/, (MMD_SA_options.camera_face_locking==null)?System._browser.translation.get('Misc.auto'):(MMD_SA_options.camera_face_locking)?'ON':'OFF').replace(/\/, (MMD_SA_options.use_CircularSpectrum)?'ON':'OFF'); +return System._browser.translation.get('XR_Animator.UI.UI_options.miscellaneous_options.message').replace(/\/, MMD_SA.THREEX.VRM.joint_stiffness_percent).replace(/\/, (MMD_SA_options.camera_face_locking==null)?System._browser.translation.get('Misc.auto'):(MMD_SA_options.camera_face_locking)?'ON':'OFF').replace(/\/, (MMD_SA_options.use_CircularSpectrum)?'ON':'OFF'); //return '1. ⌨️Hotkey list and options\n2. Camera face-locking: ' + ((MMD_SA_options.camera_face_locking==null)?'Auto':(MMD_SA_options.camera_face_locking)?'ON':'OFF') + '\n3. Audio visualizer: ' + ((MMD_SA_options.use_CircularSpectrum) ? 'ON' : 'OFF') + '\n4. Export all settings\n5. Reset all settings\n6. Done'; }, bubble_index: 3, para: { no_word_break:true }, branch_list: [ + { key:'any', func:(()=>{ +// NOTE: resetPhysics function is not considered unique for comparison (==) if defined as an inner function of a dynamic function (?), instead of inside a self-invoking function here, which will make on_animation_update.remove failed +function resetPhysics() { + MMD_SA.THREEX.get_model(0).resetPhysics(); +} + return (e)=>{ +let step; +if (MMD_SA.THREEX.enabled && /(\+|\-)/.test(e.key)) { + step = (e.key == '+') ? 1 : -1; + MMD_SA.THREEX.VRM.joint_stiffness_percent = THREEX.Math.clamp(MMD_SA.THREEX.VRM.joint_stiffness_percent + step*2, 20,200); + System._browser.on_animation_update.remove(resetPhysics, 0); + System._browser.on_animation_update.add(resetPhysics, 60,0); +} +else { + return false; +} + +MMD_SA_options.Dungeon.run_event(null,null,0); + +return true; + }; + })() + }, + { key:1, event_index:3 }, { key:2, event_index:9 }, - { key:3, event_index:1, + { key:3, event_index:0, + onmouseover: function (e) { +MMD_SA_options.Dungeon.utils.tooltip( + e.clientX, e.clientY, + System._browser.translation.get('XR_Animator.UI.UI_options.miscellaneous_options.VRM_joint_stiffness.tooltip') +); + } + }, + { key:4, event_index:1, onmouseover: function (e) { MMD_SA_options.Dungeon.utils.tooltip( e.clientX, e.clientY, @@ -9421,7 +9526,7 @@ MMD_SA_options.Dungeon.utils.tooltip( ); } }, - { key:4, event_index:2, + { key:5, event_index:2, onmouseover: function (e) { MMD_SA_options.Dungeon.utils.tooltip( e.clientX, e.clientY, @@ -9429,7 +9534,7 @@ MMD_SA_options.Dungeon.utils.tooltip( ); } }, - { key:5, event_index:6, + { key:6, event_index:6, onmouseover: function (e) { MMD_SA_options.Dungeon.utils.tooltip( e.clientX, e.clientY, @@ -9437,8 +9542,8 @@ MMD_SA_options.Dungeon.utils.tooltip( ); } }, - { key:6, event_index:7 }, - { key:7, is_closing_event:true, event_index:99 }, + { key:7, event_index:7 }, + { key:8, is_closing_event:true, event_index:99 }, ], } }, @@ -10246,8 +10351,13 @@ MMD_SA_options.Dungeon.utils.tooltip( const body_collider_index = 4; const z_depth_scale_event_index = 5; + + let hip_adjustment_option_active = 'General weighting'; - const hip_adjustment_options = ['General weighting', 'Head motion weight', 'Head pitch rotation', 'Y-axis adjustment', 'Scale X', 'Scale Y', 'Scale Z', 'Smoothing']; + const hip_adjustment_options = ['Configuration set', 'General weighting', 'Head motion weight', 'Head pitch rotation', 'Y-axis adjustment', 'Scale X', 'Scale Y', 'Scale Z', 'Rotation', 'Smoothing']; + + let hip_adjustment_set = '_default_'; + const hip_adjustment_config = ['_default_', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']; let body_collider_option_active = 'Chest size'; const body_collider_options = ['Head size', 'Chest size', 'Waist size', 'Hip size']; @@ -10339,8 +10449,25 @@ else if ((page2_index == hip_adjustment_index) && /Arrow(Up|Down)/.test(e.code)) else if ((page2_index == hip_adjustment_index) && /Arrow(Left|Right)/.test(e.code)) { step = hip_adjustment_index; + System._browser.camera.poseNet.hip_adjustment_set = hip_adjustment_set; + const v = (e.code == 'ArrowRight') ? 1 : -1; switch (hip_adjustment_option_active) { + case 'Configuration set': +let _index = hip_adjustment_config.findIndex(c=>c==hip_adjustment_set) + v; +if (_index < 0) { + _index = hip_adjustment_config.length-1; +} +else if (_index >= hip_adjustment_config.length) { + _index = 0; +} +hip_adjustment_set = hip_adjustment_config[_index]; + +if (!System._browser.camera.poseNet.hip_adjustment[hip_adjustment_set]) + System._browser.camera.poseNet.hip_adjustment[hip_adjustment_set] = {}; + +System._browser.camera.poseNet.hip_adjustment_set = hip_adjustment_set; + break; case 'General weighting': System._browser.camera.poseNet.hip_adjustment_weight_percent = THREE.Math.clamp(System._browser.camera.poseNet.hip_adjustment_weight_percent + v, 0,200); break; @@ -10362,6 +10489,9 @@ System._browser.camera.poseNet.hip_adjustment_scale_y_percent = THREE.Math.clamp case 'Scale Z': System._browser.camera.poseNet.hip_adjustment_scale_z_percent = THREE.Math.clamp(System._browser.camera.poseNet.hip_adjustment_scale_z_percent + v*5, -300,300); break; + case 'Rotation': +System._browser.camera.poseNet.hip_adjustment_rotation_percent = THREE.Math.clamp(System._browser.camera.poseNet.hip_adjustment_rotation_percent + v*5, -300,300); + break; case 'Smoothing': System._browser.camera.poseNet.hip_adjustment_smoothing_percent = THREE.Math.clamp(System._browser.camera.poseNet.hip_adjustment_smoothing_percent + v, 0,100); break; @@ -10669,26 +10799,42 @@ MMD_SA_options.Dungeon.utils.tooltip( get content() { const scale = System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.scale'); + System._browser.camera.poseNet.hip_adjustment_set = hip_adjustment_set; + return [ System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment') + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.upper_body_mocap'), -//'・Press ⬆️⬇️ to switch option', -'・' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.press_to_change_value'), -'A. ' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.general_weighting') + ': ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'OFF' : System._browser.camera.poseNet.hip_adjustment_weight_percent + '%') + ((hip_adjustment_option_active=='General weighting')?'⬅️➡️':''), -'B. ┣ ' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.head_motion_weight') + ': ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_head_weight_percent + '%') + ((hip_adjustment_option_active=='Head motion weight')?'⬅️➡️':''), -'C. ┗ ' + ' ' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.head_motion_weight.pitch_rotation') + ': ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_head_pitch_rotation_percent + '%') + ((hip_adjustment_option_active=='Head pitch rotation')?'⬅️➡️':''), -'D. ┣ ' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.y_axis_adjustment') + ': ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_adjust_y_axis_percent + '%') + ((hip_adjustment_option_active=='Y-axis adjustment')?'⬅️➡️':''), -'E. ┣ ' + scale + ' X: ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_scale_x_percent + '%') + ((hip_adjustment_option_active=='Scale X')?'⬅️➡️':''), -'F. ┣ ' + scale + ' Y: ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_scale_y_percent + '%') + ((hip_adjustment_option_active=='Scale Y')?'⬅️➡️':''), -'G. ┣ ' + scale + ' Z: ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_scale_z_percent + '%') + ((hip_adjustment_option_active=='Scale Z')?'⬅️➡️':''), -'H. ┗ ' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.smoothing') + ': ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_smoothing_percent + '%') + ((hip_adjustment_option_active=='Smoothing')?'⬅️➡️':''), +//'・' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.press_to_change_value'), +'A. ' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.configuration_set') + ': ' + ((hip_adjustment_set == '_default_') ? System._browser.translation.get('Misc.default') : hip_adjustment_set) + ((hip_adjustment_option_active=='Configuration set')?'⬅️➡️':''), +'B. ┣ ' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.general_weighting') + ': ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'OFF' : System._browser.camera.poseNet.hip_adjustment_weight_percent + '%') + ((hip_adjustment_option_active=='General weighting')?'⬅️➡️':''), +'C. ┣ ' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.head_motion_weight') + ': ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_head_weight_percent + '%') + ((hip_adjustment_option_active=='Head motion weight')?'⬅️➡️':''), +'D. ┗ ' + ' ' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.head_motion_weight.pitch_rotation') + ': ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_head_pitch_rotation_percent + '%') + ((hip_adjustment_option_active=='Head pitch rotation')?'⬅️➡️':''), +'E. ┣ ' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.y_axis_adjustment') + ': ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_adjust_y_axis_percent + '%') + ((hip_adjustment_option_active=='Y-axis adjustment')?'⬅️➡️':''), +'F. ┣ ' + scale + ' X: ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_scale_x_percent + '%') + ((hip_adjustment_option_active=='Scale X')?'⬅️➡️':''), +'G. ┣ ' + scale + ' Y: ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_scale_y_percent + '%') + ((hip_adjustment_option_active=='Scale Y')?'⬅️➡️':''), +'H. ┣ ' + scale + ' Z: ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_scale_z_percent + '%') + ((hip_adjustment_option_active=='Scale Z')?'⬅️➡️':''), +'R. ┣ ' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.rotation') + ': ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_rotation_percent + '%') + ((hip_adjustment_option_active=='Rotation')?'⬅️➡️':''), +'S. ┗ ' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.smoothing') + ': ' + ((System._browser.camera.poseNet.hip_adjustment_weight_percent == 0) ? 'N/A' : System._browser.camera.poseNet.hip_adjustment_smoothing_percent + '%') + ((hip_adjustment_option_active=='Smoothing')?'⬅️➡️':''), ].join('\n'); }, index: 1, bubble_index: 3, - para: { row_max:11 }, + para: { row_max:11, font_scale:0.95 }, branch_list: [ { key:'A', event_id: { func:()=>{ +hip_adjustment_option_active = 'Configuration set'; + }, + goto_event: { branch_index:mocap_options_branch, step:hip_adjustment_index }, + }, + onmouseover: function (e) { +MMD_SA_options.Dungeon.utils.tooltip( + e.clientX, e.clientY, + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.configuration_set') + ((hip_adjustment_option_active=='Configuration set')?' (' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.press_to_change_value.short') + ')':'') + ':\n' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.configuration_set.tooltip') +); + } + }, + { key:'B', event_id: { + func:()=>{ hip_adjustment_option_active = 'General weighting'; }, goto_event: { branch_index:mocap_options_branch, step:hip_adjustment_index }, @@ -10700,7 +10846,7 @@ MMD_SA_options.Dungeon.utils.tooltip( ); } }, - { key:'B', event_id: { + { key:'C', event_id: { func:()=>{ hip_adjustment_option_active = 'Head motion weight'; }, @@ -10713,7 +10859,7 @@ MMD_SA_options.Dungeon.utils.tooltip( ); } }, - { key:'C', event_id: { + { key:'D', event_id: { func:()=>{ hip_adjustment_option_active = 'Head pitch rotation'; }, @@ -10726,7 +10872,7 @@ MMD_SA_options.Dungeon.utils.tooltip( ); } }, - { key:'D', event_id: { + { key:'E', event_id: { func:()=>{ hip_adjustment_option_active = 'Y-axis adjustment'; }, @@ -10739,7 +10885,7 @@ MMD_SA_options.Dungeon.utils.tooltip( ); } }, - { key:'E', event_id: { + { key:'F', event_id: { func:()=>{ hip_adjustment_option_active = 'Scale X'; }, @@ -10752,7 +10898,7 @@ MMD_SA_options.Dungeon.utils.tooltip( ); } }, - { key:'F', event_id: { + { key:'G', event_id: { func:()=>{ hip_adjustment_option_active = 'Scale Y'; }, @@ -10765,7 +10911,7 @@ MMD_SA_options.Dungeon.utils.tooltip( ); } }, - { key:'G', event_id: { + { key:'H', event_id: { func:()=>{ hip_adjustment_option_active = 'Scale Z'; }, @@ -10778,7 +10924,20 @@ MMD_SA_options.Dungeon.utils.tooltip( ); } }, - { key:'H', event_id: { + { key:'R', event_id: { + func:()=>{ +hip_adjustment_option_active = 'Rotation'; + }, + goto_event: { branch_index:mocap_options_branch, step:hip_adjustment_index }, + }, + onmouseover: function (e) { +MMD_SA_options.Dungeon.utils.tooltip( + e.clientX, e.clientY, + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.rotation') + ((hip_adjustment_option_active=='Rotation')?' (' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.press_to_change_value.short') + ')':'') + ':\n' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.rotation.tooltip') +); + } + }, + { key:'S', event_id: { func:()=>{ hip_adjustment_option_active = 'Smoothing'; }, @@ -10788,7 +10947,6 @@ hip_adjustment_option_active = 'Smoothing'; MMD_SA_options.Dungeon.utils.tooltip( e.clientX, e.clientY, System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.smoothing') + ((hip_adjustment_option_active=='Smoothing')?' (' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.press_to_change_value.short') + ')':'') + ':\n' + System._browser.translation.get('XR_Animator.UI.motion_capture.mocap_options.body_tracking_options.hip_adjustment.smoothing.tooltip') - ); } }, @@ -12211,6 +12369,8 @@ function custom_motion() { return cm.slice(Math.max(cm.length-10,0)); } +System._browser.camera.poseNet.hip_adjustment_set = null; + const config = {}; config.user_camera = { @@ -12235,6 +12395,15 @@ config.user_camera = { shoulder_tracking: System._browser.camera.poseNet.shoulder_tracking, body_bend_reduction_power: System._browser.camera.poseNet.body_bend_reduction_power, hip_camera: System._browser.camera.poseNet.hip_camera, + + hip_adjustment: System._browser.camera.poseNet.hip_adjustment, + hip_adjustment_set_by_motion_name: (()=>{ + Object.keys(System._browser.camera.poseNet.hip_adjustment_set_by_motion_name).forEach(name=>{ + if (!MMD_SA_options._XRA_pose_list[0].find(p=>p.name==name)) + delete System._browser.camera.poseNet.hip_adjustment_set_by_motion_name[name]; + }); + return System._browser.camera.poseNet.hip_adjustment_set_by_motion_name; + })(), hip_adjustment_weight_percent: System._browser.camera.poseNet.hip_adjustment_weight_percent, hip_adjustment_head_weight_percent: System._browser.camera.poseNet.hip_adjustment_head_weight_percent, hip_adjustment_adjust_y_axis_percent: System._browser.camera.poseNet.hip_adjustment_adjust_y_axis_percent, @@ -12242,7 +12411,9 @@ config.user_camera = { hip_adjustment_scale_y_percent: System._browser.camera.poseNet.hip_adjustment_scale_y_percent, hip_adjustment_head_pitch_rotation_percent: System._browser.camera.poseNet.hip_adjustment_head_pitch_rotation_percent, hip_adjustment_scale_z_percent: System._browser.camera.poseNet.hip_adjustment_scale_z_percent, + hip_adjustment_rotation_percent: System._browser.camera.poseNet.hip_adjustment_rotation_percent, hip_adjustment_smoothing_percent: System._browser.camera.poseNet.hip_adjustment_smoothing_percent, + upper_rotation_offset: MMD_SA_options.user_camera.ML_models.pose.upper_rotation_offset, arm_horizontal_offset_percent: System._browser.camera.poseNet.arm_horizontal_offset_percent, arm_vertical_offset_percent: System._browser.camera.poseNet.arm_vertical_offset_percent, @@ -12317,6 +12488,7 @@ config.hotkeys = { return _config; }), }; +config.VRM_joint_stiffness_percent = MMD_SA.THREEX.VRM.joint_stiffness_percent; config.camera_face_locking = MMD_SA_options.camera_face_locking; config.audio_visualizer = MMD_SA_options.use_CircularSpectrum; @@ -12447,6 +12619,10 @@ try { System._browser.camera.poseNet.arm_vertical_offset_percent = config[p].ML_models.pose.arm_vertical_offset_percent; System._browser.camera.poseNet.limb_entry_duration_percent = config[p].ML_models.pose.limb_entry_duration_percent; System._browser.camera.poseNet.limb_return_duration_percent = config[p].ML_models.pose.limb_return_duration_percent; + + System._browser.camera.poseNet.hip_adjustment_set_by_motion_name = Object.assign({}, config[p].ML_models.pose.hip_adjustment_set_by_motion_name); + System._browser.camera.poseNet.hip_adjustment = Object.assign({ _default_:{} }, config[p].ML_models.pose.hip_adjustment); + System._browser.camera.poseNet.hip_adjustment_set = null; System._browser.camera.poseNet.hip_adjustment_weight_percent = config[p].ML_models.pose.hip_adjustment_weight_percent; System._browser.camera.poseNet.hip_adjustment_head_weight_percent = config[p].ML_models.pose.hip_adjustment_head_weight_percent; System._browser.camera.poseNet.hip_adjustment_adjust_y_axis_percent = config[p].ML_models.pose.hip_adjustment_adjust_y_axis_percent; @@ -12454,7 +12630,9 @@ try { System._browser.camera.poseNet.hip_adjustment_scale_y_percent = config[p].ML_models.pose.hip_adjustment_scale_y_percent; System._browser.camera.poseNet.hip_adjustment_head_pitch_rotation_percent = config[p].ML_models.pose.hip_adjustment_head_pitch_rotation_percent; System._browser.camera.poseNet.hip_adjustment_scale_z_percent = config[p].ML_models.pose.hip_adjustment_scale_z_percent; + System._browser.camera.poseNet.hip_adjustment_rotation_percent = config[p].ML_models.pose.hip_adjustment_rotation_percent; System._browser.camera.poseNet.hip_adjustment_smoothing_percent = config[p].ML_models.pose.hip_adjustment_smoothing_percent; + System._browser.camera.poseNet.hip_depth_scale_percent = config[p].ML_models.pose.hip_depth_scale_percent; System._browser.camera.poseNet.hip_y_position_offset_percent = config[p].ML_models.pose.hip_y_position_offset_percent; System._browser.camera.poseNet.hip_z_position_offset_percent = config[p].ML_models.pose.hip_z_position_offset_percent; @@ -12520,6 +12698,9 @@ try { hotkeys.add(Object.assign({}, config_default, config)); }); break; + case 'VRM_joint_stiffness_percent': + MMD_SA.THREEX.VRM.joint_stiffness_percent = config[p]; + break; case 'camera_face_locking': MMD_SA_options.camera_face_locking = config[p]; break; diff --git a/images/XR Animator/translation.json b/images/XR Animator/translation.json index af6edde..5fdc341 100644 --- a/images/XR Animator/translation.json +++ b/images/XR Animator/translation.json @@ -225,6 +225,20 @@ "zh": "接下來的9個姿勢" } }, + "hip_adjustment_set": { + "_translation_": { + "_default_": "Hip adjustment set", + "ja": "腰の調整の設定セット", + "zh": "腰部調整設的設定集" + }, + "tooltip": { + "_translation_": { + "_default_": "Hip adjustment set:\nThis option allows you to change the configuration set (A-H) for \"Hip adjutsment\" of upper body mocap, which can be defined under mocap options. Configuration is applied on a per-pose basis. Press ⬅️➡️ key to change value.", + "ja": "腰の調整の設定セット:\nこのオプションを使用すると、モーションキャプチャ設定で定義できる上半身のモーキャプの「腰の調整」の設定セット (A-H) を変更できます。 設定はポーズごとに適用されます。 ⬅️➡️キーを押して設定セットを変更します。", + "zh": "腰部調整設的設定集:\n此選項可讓您變更上半身動捕的「腰部調整」的設定集 (A-H),可在「動態捕捉設定」下定義。 每個姿勢均可選用不同的設定集。 按⬅️➡️鍵更改設定集。" + } + } + }, "shoulder_adjust": { "_translation_": { "_default_": "Shoulder adjust", @@ -314,7 +328,7 @@ "tooltip": { "_translation_": { "_default_": "Export current pose config:\nThis experimental feature allows you to export the config of the current pose/motion as a JSON file. You can then change the JSON to adjust every finest detail, from arm IK anchors, hip adjustment, to arm-as-leg control. Drop the adjusted JSON file back to the app to apply changes. For now, changes are not saved and will be reset on app start.", - "ja": "現在のポーズ設定をエクスポートする\nこの実験的な機能を使用すると、現在のポーズの構成を JSON ファイルとしてエクスポートできます。 その後、JSON を変更して、腕の IK から脚のコントロールの調整まで、あらゆる詳細を調整できます。 調整した JSON ファイルをアプリにドロップして戻し、変更を適用します。 現時点では、変更は保存されず、アプリの起動時にリセットされます。", + "ja": "現在のポーズ設定をエクスポートする:\nこの実験的な機能を使用すると、現在のポーズの構成を JSON ファイルとしてエクスポートできます。 その後、JSON を変更して、腕の IK から脚のコントロールの調整まで、あらゆる詳細を調整できます。 調整した JSON ファイルをアプリにドロップして戻し、変更を適用します。 現時点では、変更は保存されず、アプリの起動時にリセットされます。", "zh": "匯出現在姿勢的設定:\n此實驗性的選項可將現在的姿勢匯出到 JSON 格式的檔案上。 你可透過改變此檔案的內容更改此姿勢的所有參數,包括 IK 設定、腰部補正及「以手代足」控制模式等等。 將改變後的檔案拖曳到程式中即可生效. 現時來說,改變後的設定不會被儲存而將於程式啟動時被還原。" } } @@ -326,11 +340,18 @@ "zh": "自訂的姿勢" } }, + "extra_current_pose": { + "_translation_": { + "_default_": "B. ┣ Mirror current pose (Ctrl+M)\nC. ┣ Push current pose to list top\nD. ┗ Export current pose config", + "ja": "B. ┣ 現在のポーズをミラーリングする(Ctrl+M)\nC. ┣ 現在のポーズをリストの一番上に置く\nD. ┗ 現在のポーズ設定をエクスポートする", + "zh": "B. ┣ 鏡像化現在的姿勢 (Ctrl+M)\nC. ┣ 置頂現在的姿勢\nD. ┗ 匯出現在姿勢的設定" + } + }, "extra": { "_translation_": { - "_default_": "C. Mirror current pose (Ctrl+M)\nD. Push current pose to list top\nE. Reset pose list order\nF. Clear all custom poses\nG. Export current pose config\nX. Done", - "ja": "C. 現在のポーズをミラーリングする(Ctrl+M)\nD. 現在のポーズをリストの一番上に置く\nE. ポーズリストの順序をリセット\nF. すべてのカスタムポーズをクリアする\nG. 現在のポーズ設定をエクスポートする\nX. 終了", - "zh": "C. 鏡像化現在的姿勢 (Ctrl+M)\nD. 置頂現在的姿勢\nE. 還原姿勢列表的順序\nF. 清空所有自訂動作\nG. 匯出現在姿勢的設定\nX. 結束" + "_default_": "F. Reset pose list order\nG. Clear all custom poses", + "ja": "F. ポーズリストの順序をリセット\nG. すべてのカスタムポーズをクリアする", + "zh": "F. 還原姿勢列表的順序\nG. 清空所有自訂動作" } } }, @@ -854,6 +875,20 @@ } } }, + "configuration_set": { + "_translation_": { + "_default_": "Configuration set", + "ja": "設定セット", + "zh": "設定集" + }, + "tooltip": { + "_translation_": { + "_default_": "XR Animator allows you to define multiple sets of configuration (A-H) for hip adjustment, which can be applied to different poses for upper body mocap under \"Pose/Motion\".", + "ja": "XR Animator を使用すると、腰の調整用の複数の設定セット (A-H) を定義できます。 これは、「ポーズ/モーション」の下の上半身のモーションキャプチャのさまざまなポーズに適用できます。", + "zh": "XR Animator 可讓您定義多組腰部調整的設定集 (A-H),並套用於「姿勢/動作」下上半身動作捕捉的不同姿勢。" + } + } + }, "general_weighting": { "_translation_": { "_default_": "General weighting", @@ -864,7 +899,7 @@ "_translation_": { "_default_": "By default, when using upper body mocap, hip position and rotation will be adjusted according to your upper body motion. This option determines the general weighting of the hip adjustment applied. Default is \"100%\".", "ja": "デフォルトでは、上半身のモーションキャプチャを使用すると、上半身の動きに応じて腰の位置と回転が調整されます。 このオプションは、適用される腰の調整の一般的な重み付けを決定します。 デフォルトは「100%」です。", - "zh": "在預設情況下,在使用上半身動捕時,人物的腰部會隨上半身的動作作出相應的位置及回轉調整。 此設定可改變此腰部調整功能的整體比重。 預設是「100%」。" + "zh": "在預設情況下,在使用上半身動捕時,人物的腰部會隨上半身的動作作出相應的位置及回轉調整。 此設定可改變腰部調整功能的整體比重。 預設是「100%」。" } } }, @@ -944,6 +979,20 @@ } } }, + "rotation": { + "_translation_": { + "_default_": "Rotation", + "ja": "回転", + "zh": "旋轉" + }, + "tooltip": { + "_translation_": { + "_default_": "By default, hip rotates according to the rotation of your upper body. This option determines the degree of rotation. Negative value meanns the direction of rotation is inverted. Default is \"100%\".", + "ja": "デフォルトでは、ヒップは上半身の回転に応じて回転します。 このオプションは回転の度合いを決定します。 負の値は回転方向が反転することを意味します。 デフォルトは「100%」です。", + "zh": "預設情況下,臀部隨著上半身的旋轉而旋轉。 此選項決定旋轉的幅度。 負值表示旋轉方向反轉。 預設是「100%」。" + } + } + }, "smoothing": { "_translation_": { "_default_": "Smoothing", @@ -2025,9 +2074,9 @@ }, "message": { "_translation_": { - "_default_": "1. ⌨️Hotkey list and options\n2. 🎮Gamepad options\n3. Camera face-locking: \n4. Audio visualizer: \n5. Export all settings\n6. Reset all settings\n7. Done", - "ja": "1. ⌨️ホットキーの一覧とオプション\n2. 🎮ゲームパッドのオプション\n3. カメラのフェイスロック: \n4. オーディオ視覚効果: \n5. すべての設定をエクスポートする\n6. すべての設定をリセットする\n7. 終了", - "zh": "1. ⌨️熱鍵列表及設定\n2. 🎮遊戲手把選項\n3. 鏡頭鎖定面部: \n4. 音訊視覺化工具: \n5. 匯出所有設定\n6. 重置所有設定\n7. 結束" + "_default_": "1. ⌨️Hotkey list and options\n2. 🎮Gamepad options\n3. VRM joint stiffness: %➕➖\n4. Camera face-locking: \n5. Audio visualizer: \n6. Export all settings\n7. Reset all settings\n8. Done", + "ja": "1. ⌨️ホットキーの一覧とオプション\n2. 🎮ゲームパッドのオプション\n3. VRM 関節の剛性: %➕➖\n4. カメラのフェイスロック: \n5. オーディオ視覚効果: \n6. すべての設定をエクスポートする\n7. すべての設定をリセットする\n8. 終了", + "zh": "1. ⌨️熱鍵列表及設定\n2. 🎮遊戲手把選項\n3. VRM 關節剛度: %➕➖\n4. 鏡頭鎖定面部: \n5. 音訊視覺化工具: \n6. 匯出所有設定\n7. 重置所有設定\n8. 結束" } }, "hotkey": { @@ -2342,6 +2391,15 @@ } } }, + "VRM_joint_stiffness": { + "tooltip": { + "_translation_": { + "_default_": "VRM joint stiffness:\nThis setting determines the stiffness of springbone joints of VRM model. Smaller value makes springbone-related parts (e.g. hairs) look softer. Press ➕➖ key to change value. Default is \"100%\".", + "ja": "VRM 関節の剛性:\nこの設定は、VRM モデルのスプリングボーン ジョイントの剛性を決定します。 値が小さいほど、スプリングボーン関連のパーツ (髪の毛など) が柔らかく見えます。 ➕➖キーを押して値を変更します。 デフォルトは「100%」です。", + "zh": "VRM 關節剛度:\n此設定決定 VRM 模型的彈簧骨關節的剛度。 數值越小,與彈簧骨相關的部分(例如頭髮)看起來越柔軟。 按➕➖鍵更改數值。 預設是「100%」。" + } + } + }, "camera_face_locking": { "tooltip": { "_translation_": { diff --git a/js/SA_system_emulation.min.js b/js/SA_system_emulation.min.js index 08c604e..3c0ff32 100644 --- a/js/SA_system_emulation.min.js +++ b/js/SA_system_emulation.min.js @@ -1,2 +1,2 @@ -// (2024-07-02) -var System=function(){var System={_init:function(){try{if(!Shell_OBJ)Shell_OBJ=new ActiveXObject("Shell.Application");if(!FSO_OBJ)FSO_OBJ=new ActiveXObject("Scripting.FileSystemObject");if(!oShell)oShell=new ActiveXObject("WScript.Shell")}catch(e){alert(e.message)}this._child_html_filename=xul_mode?"SystemAnimator_xul.html":webkit_mode?WallpaperEngine_CEF_mode&&!browser_native_mode?"SystemAnimator_cef.html":"SystemAnimator_webkit.html":"SystemAnimator_ie.html";this.Gadget._init();this.Machine._init();if(!is_SA_child_animation){SA_top_window.getScreenBounds=function(){var o=-1;var n;return function(e,t,i){if(i||o!=RAF_timestamp){o=RAF_timestamp;n=webkit_electron_mode?webkit_electron_screen.getDisplayNearestPoint({x:~~e,y:~~t}).bounds:{x:0,y:0,width:parent.screen.width,height:parent.screen.height}}return n}}()}else{SA_top_window.getScreenBounds=function(e,t,i){return SA_topmost_window.getScreenBounds(e,t,i)}}if(webkit_electron_mode){if(!is_SA_child_animation){SA_top_window.getPos=function(){var t=-1;var i;return function(e){if(e||t!=RAF_timestamp){t=RAF_timestamp;i=webkit_window.getPosition()}return i}}();SA_top_window.getCursorPos=function(){var t=-1;var i;return function(e){if(e||t!=RAF_timestamp){t=RAF_timestamp;i=webkit_electron_screen.getCursorScreenPoint()}return i}}()}else{SA_top_window.getPos=function(e){return SA_topmost_window.getPos(e)};SA_top_window.getCursorPos=function(e){return SA_topmost_window.getCursorPos(e)}}}SA_top_window.resizeToAbsolute=function(){var i;return function(e,t){webkit_window.setContentSize(e,t);i=true;if(absolute_screen_mode&&!System._browser._window_move_timerID){System._browser._window_move_timerID=setInterval(function(){var t=SA_top_window.screenLeftAbsolute;var i=SA_top_window.screenTopAbsolute;var o=0;return function(){var e=SA_top_window.getPos(true);if(t!=e[0]||i!=e[1]){DEBUG_show("(window position adjusted)",3);webkit_window.setPosition(t,i);System._browser.moveWallpaper(t,i);o=999}if(++o>10){clearInterval(System._browser._window_move_timerID);System._browser._window_move_timerID=null}}}(),100)}}}();(()=>{function o(){function e(){const e=document.body.style;webkit_window.setContentSize(e.pixelWidth,e.pixelHeight)}if(webkit_electron_mode&&window.devicePixelRatio!=1){window.removeEventListener("resize",e);window.addEventListener("resize",e,{once:true})}}SA_top_window.moveToAbsolute=function(e,t,i){o();if(absolute_screen_mode&&!i){webkit_window.setPosition(~~e,~~t)}else{this.moveTo(e,t)}};SA_top_window.moveByAbsolute=function(t,i){o();if(absolute_screen_mode){let e=SA_top_window.getPos(true);t+=~~e[0];i+=~~e[1];webkit_window.setPosition(t,i)}else{this.moveBy(t,i)}}})();Object.defineProperty(SA_top_window,"screenLeftAbsolute",{get:function(){return absolute_screen_mode?SA_top_window.getPos()[0]:this.screenLeft}});Object.defineProperty(SA_top_window,"screenTopAbsolute",{get:function(){return absolute_screen_mode?SA_top_window.getPos()[1]:this.screenTop}})},Gadget:{_init:function(){this.Settings.read=this.Settings.readString;this.Settings.write=this.Settings.writeString;Object.defineProperty(this,"onSettingsClosing",{get:function(){return this._onSettingsClosing},set:function(e){this._onSettingsClosing=e;this.settings_window.onbeforeunload=function(){e({closeAction:!!this.returnValue,Action:{commit:true}});System.Gadget.settings_window.System=null;System.Gadget.settings_window.onbeforeunload=null;System.Gadget.settings_window=null}}});var e=new ActiveXObject("Microsoft.XMLDOM");e["async"]=false;e.resolveExternals=false;e.validateOnParse=false;e.load("gadget.xml");this.version=e.selectSingleNode("//version").text},path:xul_mode?XPCOM_object._SA_root:use_SA_browser_mode?toLocalPath(self.location.href).replace(/[\/\\][^\/\\]+$/,""):"",_path_folder:function(){return this.path.replace(/[\/\\][^\/\\]+$/,"")},document:document,version:"1.0.0.0",docked:is_SA_child_animation,visible:true,Settings:{_settings_need_update:false,_settings:{},_changed:{},readString:function(name,raw_read){var v=this._settings[name];v=v?raw_read?decodeURIComponent(v):decodeURIComponent(v).replace(/\$([^\$]+)\$/g,function($0,$1,$2){return eval($1)}):Settings_default._custom_[name]||"";return v},writeString:function(e,t){var i=this._settings[e]||"";var o=encodeURIComponent(t);this._settings[e]=o;if(WallpaperEngine_CEF_mode){var n=JSON.parse(localStorage.Settings_by_path);if(!SA_HTA_folder||!n[SA_HTA_folder]){console.error(SA_HTA_folder)}else{if(n[SA_HTA_folder][e]!=o){n[SA_HTA_folder][e]=o;localStorage.Settings_by_path=JSON.stringify(n)}}}if(i!=o)this._changed[e]=this._settings_need_update=true},_writeSettings:function(e,t){if(!e&&!this._settings_need_update)return;this._settings_need_update=false;SystemEXT._save_settings_only=t;try{this._writeSettings_CORE()}catch(i){}SystemEXT._save_settings_only=false},_writeSettings_CORE:function(){var e=[];var t=this._settings;t._screenLeft=t._screenTop="";for(var i in t){var o=System.Gadget.Settings.readString(i);if(!o)continue;if(i=="_screenLeft"){o=SA_top_window.screenLeftAbsolute}else if(i=="_screenTop"){o=SA_top_window.screenTopAbsolute}e.push('"'+i+'":"'+encodeURIComponent(o)+'"')}SystemEXT.SaveLocalSettings(e)}}},Environment:{win32_env:null,getEnvironmentVariable:function(e){return oShell.ExpandEnvironmentStrings("%"+e+"%")}},Machine:{_init:function(){this._init_memory=function(){if(webkit_mode)return;if(this._WMI_obj_memory)return;try{this._WMI_obj_memory=new WMI_Refresher("Win32_PerfFormattedData_PerfOS_Memory","EV");this._WMI_obj_memory.init()}catch(e){}};Object.defineProperty(this,"availableMemory",{get:function(){if(webkit_mode)return SA_require("os").freemem()/(1024*1024);this._init_memory();var e=this._WMI_obj_memory.update();return e.length?parseInt(e[e.length-1].AvailableMBytes):0}});Object.defineProperty(this,"totalMemory",{get:function(){if(webkit_mode)return SA_require("os").totalmem()/(1024*1024);if(!this._totalMemory){try{var e=new WMI_Refresher("Win32_OperatingSystem");e.init();this._totalMemory=parseInt(e.update()[0].TotalVisibleMemorySize)/1024}catch(t){}}return this._totalMemory}});this.totalMemory=0;var e={_WMI_obj:null,_cpu_obj:null,_get_cpu_obj:null,_init:function(){if(webkit_mode){if(this._get_cpu_obj)return;this._cpu_obj=[{count:-1,cpus:SA_require("os").cpus()}];this._get_cpu_obj=function(){var e=this._cpu_obj;if(e[0].count!=PC_count_absolute){if(e.unshift({count:PC_count_absolute,cpus:SA_require("os").cpus()})==3)e.pop()}return e};return}if(this._WMI_obj)return;try{this._WMI_obj=new WMI_Refresher("Win32_PerfFormattedData_PerfOS_Processor","EV");this._WMI_obj.init()}catch(e){}},item:function(e){if(webkit_mode){var t=this._get_cpu_obj();var i=[];for(var o=0;o<2;o++){var n=t[o].cpus[e].times;var a=0;for(var s in n)a+=n[s];i[o]={total:a,idle:n.idle}}var r=i[0].idle-i[1].idle;var a=i[0].total-i[1].total;return{usagePercentage:a?(1-r/a)*100:0}}return{usagePercentage:parseFloat(this._WMI_obj.update()[e].PercentProcessorTime)}}};Object.defineProperty(e,"count",{get:function(){if(webkit_mode){return this._get_cpu_obj()[0].cpus.length}return this._WMI_obj.update().length-1}});this._CPUs=e;Object.defineProperty(this,"CPUs",{get:function(){this._CPUs._init();return this._CPUs}});var t={_WMI_obj:null,_init:function(){if(this._battery)return;this._battery={level:1,charging:false};if("getBattery"in navigator){var t=this;navigator.getBattery().then(function(e){DEBUG_show("Use Battery Status API",2);t._battery=e})}}};Object.defineProperty(t,"batteryPercentRemaining",{get:function(){return this._battery.level*100}});Object.defineProperty(t,"isPowerLineConnected",{get:function(){return this._battery.level==1||this._battery.charging}});Object.defineProperty(t,"isBatteryCharging",{get:function(){return this._battery.charging}});this._PowerStatus=t;Object.defineProperty(this,"PowerStatus",{get:function(){this._PowerStatus._init();return this._PowerStatus}})}},Shell:{itemFromFileDrop:function(e,t){return{path:""}},itemFromPath:function(e){e=toLocalPath(e);var t=e.replace(/[\/\\][^\/\\]+$/,"");var i=e.replace(/^.+[\/\\]/,"");var o=Shell_OBJ.NameSpace(t);if(o)o=o.ParseName(i);return o?new this._FolderItem(o):null},execute:function(e,t){Shell_OBJ.ShellExecute(e,t)},chooseFolder:function(e,t){var i=Shell_OBJ.BrowseForFolder(0,e,t);return i?new this._FolderItem(i.Self):null},_FolderItem:function(e){if(!this._constructor_initialized){this.constructor.prototype._constructor_initialized=true;this.constructor.prototype.metadata=function(e){var t=this.obj.ExtendedProperty("Dimensions");if(!t){var i=this.obj.Path.replace(/[\/\\][^\/\\]+$/,"");var o=Shell_OBJ.NameSpace(i);t=o.GetDetailsOf(this.obj,26)}return t};Object.defineProperty(this.constructor.prototype,"isFolder",{get:function(){return this.obj.IsFolder}});Object.defineProperty(this.constructor.prototype,"isFileSystem",{get:function(){return(ie9_native?!this.obj.IsFolder:true)&&this.obj.IsFileSystem}});Object.defineProperty(this.constructor.prototype,"isLink",{get:function(){return this.obj.IsLink}});Object.defineProperty(this.constructor.prototype,"link",{get:function(){return new System.Shell._FolderItem(this.obj.GetLink)}});Object.defineProperty(this.constructor.prototype,"path",{get:function(){return this.obj.Path}});Object.defineProperty(this.constructor.prototype,"type",{get:function(){return this.obj.Type}});Object.defineProperty(this.constructor.prototype,"SHFolder",{get:function(){return new System.Shell._Folder(this.obj.GetFolder)}})}this.obj=e},_Folder:function(e){if(!this._constructor_initialized){this.constructor.prototype._constructor_initialized=true;Object.defineProperty(this.constructor.prototype,"Items",{get:function(){return new System.Shell._FolderItems(this.obj.Items())}})}this.obj=e},_FolderItems:function(e){if(!this._constructor_initialized){this.constructor.prototype._constructor_initialized=true;this.constructor.prototype.item=function(e){return new System.Shell._FolderItem(this.obj.Item(e))};Object.defineProperty(this.constructor.prototype,"count",{get:function(){return this.obj.Count}})}this.obj=e}},Debug:{outputString:function(e){}},_browser:{init:function(){document.ondragstart=document.onselectstart=function(e){return false};document.onmousedown=function(e){System._browser.onmousedown(e)};document.onmouseup=function(e){System._browser.onmouseup(e)};document.onmousemove=function(e){System._browser.onmousemove(e)};document.onkeydown=function(e){System._browser.onkeydown(e)};if(!WallpaperEngine_CEF_mode||!is_SA_child_animation||browser_native_mode){document.addEventListener("mouseover",function(e){System._browser.onmouseover(e)},false);document.addEventListener("mouseout",function(e){System._browser.onmouseout_waiting(e)},false)}Object.defineProperty(document,"onmouseover",{set:function(e){System._browser.onmouseover_custom=e}});Object.defineProperty(document,"onmouseout",{set:function(e){System._browser.onmouseout_waiting_custom=e}});var e=w3c_mode?CSSStyleDeclaration.prototype:document.body.style.constructor.prototype;this.document_body_style_pixelWidth=Object.getOwnPropertyDescriptor(e,"pixelWidth");this.document_body_style_pixelHeight=Object.getOwnPropertyDescriptor(e,"pixelHeight");var t=function(){if(System._browser.resize_timerID)clearTimeout(System._browser.resize_timerID);if(System._browser._window_move_timerID){let i=SA_top_window.getPos();System._browser.resize_timerID=setInterval(function(){var t=0;return function(){let e=SA_top_window.getPos(true);if(++t>10||i[0]!=e[0]||i[1]!=e[1]){clearInterval(System._browser.resize_timerID);System._browser.resize_timerID=setTimeout("System._browser.resize()",0)}}}(),10)}else System._browser.resize_timerID=setTimeout("System._browser.resize()",0)};Object.defineProperty(e,"_set",{get:function(){return t}});if(ie9_native){Object.defineProperty(document.body.style,"pixelWidth",{get:function(){return System._browser.document_body_style_pixelWidth.get.call(this)},set:function(e){this._set();System._browser.document_body_style_pixelWidth.set.call(this,e)}});Object.defineProperty(document.body.style,"pixelHeight",{get:function(){return System._browser.document_body_style_pixelHeight.get.call(this)},set:function(e){this._set();System._browser.document_body_style_pixelHeight.set.call(this,e)}})}Object.defineProperty(this,"overlay_mode",function(){var t=0;var i=null;var o=null;return{get:function(){return t},set:function(e){if(e==t)return;switch(e){case 2:if(i==null)i=LdesktopBG_host.style.display;LdesktopBG_host.style.display="none";if(o==null)o=document.body.style.backgroundColor;document.body.style.backgroundColor="#00FF00";case 1:Lmenu_host.style.visibility="hidden";if(this.camera.video_host){this.camera.video_host.style.visibility="hidden";this.camera.video_host.style.display="none"}if(document.getElementById("Ldungeon_UI")){document.getElementById("Ldungeon_UI").style.visibility="hidden";document.getElementById("Ldungeon_inventory").style.visibility="hidden";document.getElementById("Ldungeon_inventory_backpack").style.visibility="hidden";DEBUG_show("(Press Esc to toggle "+(this.overlay_mode_TEMP?"UI":"bottom menu")+" display)",5)}break;default:if(i!=null)LdesktopBG_host.style.display=i;if(o!=null)document.body.style.backgroundColor=o;i=o=null;Lmenu_host.style.visibility="inherit";if(this.camera.video_host){this.camera.video_host.style.visibility="inherit";this.camera.video_host.style.display="block"}if(document.getElementById("Ldungeon_UI")){document.getElementById("Ldungeon_UI").style.visibility="inherit";document.getElementById("Ldungeon_inventory").style.visibility="inherit";document.getElementById("Ldungeon_inventory_backpack").style.visibility="hidden"}}t=e}}}());var i=is_SA_child_animation&&parent.MMD_SA_options&&parent.MMD_SA_options.child_animation_as_texture;if(i){this.onkeydown({keyCode:97+SA_child_animation_id})}var o=System.Gadget.Settings.readString("SA_docked");if(o)System.Gadget.docked=!!parseInt(o);else{if(i)System.Gadget.docked=false}var o=document.createElement("div");o.id="Ldrag_dummy";var n=o.style;n.position="absolute";n.posLeft=n.posTop=0;n.zIndex=999;n.border="1px solid rgba(128,128,128,0.5)";n.visibility="hidden";document.body.appendChild(o);this.body=document.getElementById("Lbody_host")||document.body;if(w3c_mode)this.body.style.transition="opacity 0.5s";this.Opacity=1;var a=document.getElementById("LdesktopBG")&&!is_SA_BG_transparent;if(a){if(!self.SA_wallpaper_src){var s=System.Gadget.path+toLocalPath("\\TEMP\\SA_wallpaper_src.txt");if(FSO_OBJ.FileExists(s)){try{var r=FSO_OBJ.OpenTextFile(s,1);self.SA_wallpaper_src=r.ReadLine();r.Close()}catch(A){}}}if(!self.SA_wallpaper_mask_src){var _=System.Gadget.path+toLocalPath("\\TEMP\\SA_wallpaper_mask_src.txt");if(FSO_OBJ.FileExists(_)){try{var r=FSO_OBJ.OpenTextFile(_,1);self.SA_wallpaper_mask_src=r.ReadLine();r.Close()}catch(A){}}}}if(a)a=System.Gadget.Settings.readString("WallpaperAsBG")||self.SA_wallpaper_src;var l;if(self.CANVAS_Video_Overlay&&CANVAS_Video_Overlay.use_wallpaper_as_bg||self.EQP_use_wallpaper){l=a=true}var m;var c,d;this.Opacity=is_SA_child_animation?parent.document.getElementById("Ichild_animation"+SA_child_animation_id).style.opacity||1:parseFloat(System.Gadget.Settings.readString("Opacity")||1);if(is_SA_child_animation&&!self.SA_wallpaper_src&&!l){a=a&&parent.WMP_wallpaper_mask&&parent.use_HTML5&&!parent.System.Gadget.Settings.readString("CSSTransform3D")&&!System.Gadget.Settings.readString("DisableWallpaperMask");if(a&&self.EQP_video_options&&EQP_video_options.use_canvas_video){a=false;this.C_WMP_wallpaper_mask_resized=document.createElement("canvas");this.C_WMP_wallpaper_mask_mixed_resized=document.createElement("canvas");this.WMPMask_Draw()}this.wallpaper_mask_disabled=!a;if(a)m=parent.WMP_wallpaper_mask}else{var p;if(!is_SA_child_animation){c=System.Gadget.Settings.readString("_screenLeft");d=System.Gadget.Settings.readString("_screenTop")}c=c?parseInt(c):null;d=d?parseInt(d):null;if(a){const D=w3c_mode&&self.SA_wallpaper_src&&/\.(mp4|mkv|webm)$/i.test(SA_wallpaper_src)&&SA_wallpaper_src;this.wallpaper_mask_disabled=WallpaperEngine_CEF_mode||!!System.Gadget.Settings.readString("DisableWallpaperMask");var u,h,f;var n=LdesktopBG.style;try{n.pixelWidth=parent.screen.width;n.pixelHeight=parent.screen.height;var M=oShell.RegRead("HKCU\\Control Panel\\Colors\\Background");n.backgroundColor=/^\#/.test(M)?M:"rgb("+M.replace(/\W+/g,",")+")";u="HKCU\\Control Panel\\Desktop\\";if(WallpaperEngine_CEF_mode)h=oShell.RegRead(u+"Wallpaper")||self.SA_wallpaper_src&&/\.(png|bpm|jpg|jpeg)$/i.test(SA_wallpaper_src)&&SA_wallpaper_src;else h=self.SA_wallpaper_src==""?"":self.SA_wallpaper_src&&/\.(png|bpm|jpg|jpeg)$/i.test(SA_wallpaper_src)&&SA_wallpaper_src||oShell.RegRead(u+"Wallpaper");if(h){if(!this.wallpaper_mask_disabled){m=self.SA_wallpaper_mask_src||h.replace(/\.\w{3,4}$/,"_mask.png");if(!ValidatePath(m))m=null}f=oShell.RegRead(u+"WallpaperStyle");this.updateWallpaper(h,f)}if(D){this.updateWallpaper(D)}this.moveWallpaper(c||0,d||0);if(!is_SA_child_animation||self.SA_wallpaper_src)LdesktopBG_host.style.display="block"}catch(A){console.error(A);LdesktopBG_host.style.display="none"}if(m){if(!this.bg_mask)this.bg_mask="(blank)"}else{p=true}}else{p=true}if(p&&this.Opacity<1&&(w3c_mode||HTA_use_GPU_acceleration)){this.body.style.opacity=this.Opacity;DEBUG_show("Opacity:"+this.Opacity*100+"%",2)}}if(l&&!m)this.bg_mask="(blank)";if(a&&(m||this.bg_mask)){var y=document.createElement("canvas");y.id="C_wallpaper_mask";y._WallpaperAsBG_custom=l;y.onmousedown=function(){return false};if(!is_SA_child_animation||l){try{var g=y.width=parent.screen.width;var b=y.height=parent.screen.height;var v=y.getContext("2d");var w;if(!this.wallpaper_canvas_update){this.wallpaper_canvas_update=function(e,d){v.fillStyle=n.backgroundColor;v.fillRect(0,0,g,b);if(!e){if(self.CANVAS_Video_Overlay&&CANVAS_Video_Overlay._canvas_wall)CANVAS_Video_Overlay._canvas_wall._match_str=null;if(self.EQP_use_wallpaper){EQP_ps.forEach(function(e){if(e.is_wallpaper)e.img.img_obj._match_str=null})}return}var t;if(d=="0"){t=function(){var e=this.width;var t=this.height;var i=parent.screen.width;var o=parent.screen.height;var n,a,s,r,_,l,c,d;if(i>e){n=0;_=(i-e)/2;s=c=e}else{n=(e-i)/2;_=0;s=c=i}if(o>t){a=0;l=(o-t)/2;r=d=t}else{a=(t-o)/2;l=0;r=d=o}var p=C_wallpaper_mask.getContext("2d");p.drawImage(this,n,a,s,r,_,l,c,d);System._browser.BGMask_Create(!m);if(!m)return;var u=new Image;u.onload=function(){var e=C_wallpaper_mask.getContext("2d");e.globalCompositeOperation="destination-in";e.drawImage(this,n,a,s,r,_,l,c,d);C_wallpaper_mask.style.visibility="inherit";DEBUG_show("Use wallpaper mask",2)};u.src=toFileProtocol(m)}}else{t=function(){var e=this.width;var t=this.height;var i=parent.screen.width;var o=parent.screen.height;var n,a,s,r,_;var l=C_wallpaper_mask.getContext("2d");if(d=="6"){n=Math.max(e/i,t/o);r=Math.round((i-e/n)/2);_=Math.round((o-t/n)/2);a=Math.round(e/n);s=Math.round(t/n);l.drawImage(this,0,0,e,t,r,_,a,s)}else{n=Math.min(e/i,t/o);r=Math.round((e/n-i)/2*n);_=Math.round((t/n-o)/2*n);a=Math.round(i*n);s=Math.round(o*n);l.drawImage(this,r,_,a,s,0,0,C_wallpaper_mask.width,C_wallpaper_mask.height)}System._browser.BGMask_Create(!m);if(!m)return;var c=new Image;c.onload=function(){var e=C_wallpaper_mask.getContext("2d");e.globalCompositeOperation="destination-in";e.drawImage(this,r,_,a,s);C_wallpaper_mask.style.visibility="inherit";DEBUG_show("Use wallpaper mask",2)};c.src=toFileProtocol(m)}}if(w)w.onload=null;w=new Image;w.onload=t;w.src=toFileProtocol(e)}}this.wallpaper_canvas_update(h,f);if(!h){setTimeout("System._browser.BGMask_Create(true)",0)}}catch(A){}}var S=y.style;S.position="absolute";S.posLeft=-(c||0);S.posTop=-(d||0);S.zIndex=60;S.visibility="hidden";document.body.appendChild(y);this.mouseover_hide_list.push(y);if(is_SA_child_animation){this.C_WMP_wallpaper_mask_resized=document.createElement("canvas");this.C_WMP_wallpaper_mask_mixed_resized=document.createElement("canvas");if(this.bg_mask)System._browser.BGMask_Create(!m);this.WMPMask_Draw()}}this._s_left=c;this._s_top=d},updateWallpaper:function(e,t){let i=document.getElementById("VdesktopBG");if(e&&/\.(mp4|mkv|webm)$/i.test(e)){if(!i){i=document.createElement("video");i.id="VdesktopBG";const c=i.style;c.position="absolute";c.top=c.left="0px";c.width=parent.screen.width+"px";c.height=parent.screen.height+"px";c.objectFit="cover";LdesktopBG.appendChild(i);i.autoplay=i.loop=true}i.src=toFileProtocol(e);i.style.visibility="inherit";return}if(i){i.pause();i.style.visibility="hidden"}var o=LdesktopBG.style;var n;if(e!=null){e=decodeURIComponent(e);if(this._wallpaper_last!=e){n=true;this._wallpaper_last=e;o.backgroundImage=e?"url("+toFileProtocol(/^(\/|[\w\-]+\:)/.test(e)?e:System.Gadget.path+"/"+e).replace(/\s/g,encodeURIComponent(" "))+")":"";if(this.wallpaper_opacity)o.opacity=this.wallpaper_opacity;if(this.wallpaper_bg_color)LdesktopBG_host.style.backgroundColor=this.wallpaper_bg_color}}else e=this._wallpaper_last;var a="HKCU\\Control Panel\\Desktop\\";if(t==null){t=oShell.RegRead(a+"WallpaperStyle")}if(this._wallpaper_style!=t){n=true;this._wallpaper_style=t}if(t=="0"){o.backgroundSize="";o.backgroundPosition="center center";if(oShell.RegRead(a+"TileWallpaper")=="0"){o.backgroundRepeat="no-repeat"}else{o.backgroundRepeat=""}}else if(t=="2"){o.backgroundSize="100% 100%";o.backgroundPosition="";o.backgroundRepeat=""}else if(t=="6"){o.backgroundSize="contain";o.backgroundPosition="center center";o.backgroundRepeat="no-repeat"}else{o.backgroundSize="cover";o.backgroundPosition="center center";o.backgroundRepeat="no-repeat";if(browser_native_mode){o.width="100%";o.height="100%"}else{o.pixelWidth=parent.screen.width;o.pixelHeight=parent.screen.height}if(windows_mode&&e){var s=loadImageDim(/^(\/|[\w\-]+\:)/.test(e)?e:System.Gadget.path+toLocalPath("\\")+e);if(s.w){var r=parent.screen.width/parent.screen.height;var _=(parent.screen.width*2-parent.screen.availWidth)/(parent.screen.height*2-parent.screen.availHeight);var l=s.w/s.h;if(lr){o.pixelWidth=l>_?parent.screen.width*2-parent.screen.availWidth:Math.round(parent.screen.height*l)}}}}if(this.wallpaper_canvas_update&&n){this.wallpaper_canvas_update(e,t);DEBUG_show("(Wallpaper canvas updated)",2)}},WMPMask_Draw:function(e){if(!this.C_WMP_wallpaper_mask_resized)return;if(!e)e=parent.SL;if(!e||!e.width)return;var t=document.body.style;var i=t.pixelWidth;var o=t.pixelHeight;if(!i)return;var n=0;var a=0;var s=e.width;var r=e.height;var _=this.C_WMP_wallpaper_mask_resized;if(_.width!=s){_.width=s;_.height=r;var l=parent.C_WMP_wallpaper_mask;_.getContext("2d").drawImage(l,0,0,l.width,l.height,0,0,s,r)}var c=this.bg_mask_image_resized;if(c&&c.width!=i){c.width=i;c.height=o;var d=this.bg_mask_image;c.getContext("2d").drawImage(d,0,0,d.width,d.height,0,0,i,o)}var i,o;i=self.B_content_width?B_content_width:document.body.style.pixelWidth;o=self.B_content_height?B_content_height:document.body.style.pixelHeight;var p=parent.SA_child_animation[SA_child_animation_id];var u=p.x;var m=p.y;if(is_SA_child_animation&&parent.EQP_border_width){u-=parent.EQP_border_width;m-=parent.EQP_border_width}var h=u-n;var f=h;if(h<0)h=0;if(f<0)f=-f;else f=0;var M=m-a;var y=M;if(M<0)M=0;if(y<0)y=-y;else y=0;var g=s+n-u;if(g>i)g=i;var b=r+a-m;if(b>o)b=o;var v=this.C_WMP_wallpaper_mask_mixed_resized;if(v.width!=i||v._x!=h||v._y!=M){v.width=i;v.height=o;var w=v.getContext("2d");w.drawImage(_,h,M,g,b,f,y,g,b);if(c)w.drawImage(c,0,0);v._x=h;v._y=M}var S=document.getElementById("C_wallpaper_mask");if(!S)return;S.width=i;S.height=o;var w=S.getContext("2d");w.globalCompositeOperation="copy";w.drawImage(e,h,M,g,b,f,y,g,b);w.globalCompositeOperation="destination-in";w.drawImage(v,0,0)},BGMask_CreateCanvas:function(e,t){if(!e)return null;if(!/^\((.+)\)$/.test(e)){return null}var i=RegExp.$1.split("|");var o=i[0];var n;if(o=="circle"){var a=parseInt(i[1]);var s=parseInt(i[2]);n=document.createElement("canvas");n.width=a;n.height=s;var r=a=a-l)y=(a-h)/(l+1);y=1-(1-y)*M;if(y<0)y=0;var g=1;if(f=s-l)g=(s-f)/(l+1);g=1-(1-g)*M;if(g<0)g=0;var b=yw?w/v:v/w;var A=Math.sqrt(1+S*S);b=1-(1-b)*A;if(b<0)b=0}d[p]=t?Math.round(255*(1-b)):Math.round(255*b)}_.putImageData(c,0,0)}return n},BGMask_Create:function(e){var t=this.bg_mask;if(!t)return;if(e){this.wallpaper_canvas=C_wallpaper_mask;C_wallpaper_mask.style.display="none"}else{var i=this.wallpaper_canvas=document.createElement("canvas");if(!is_SA_child_animation){i.width=parent.screen.width;i.height=parent.screen.height;i.getContext("2d").drawImage(C_wallpaper_mask,0,0)}}if(self.CANVAS_Video_Overlay&&CANVAS_Video_Overlay._canvas_wall)CANVAS_Video_Overlay._canvas_wall._match_str=null;if(self.EQP_use_wallpaper){EQP_ps.forEach(function(e){if(e.is_wallpaper&&e.img)e.img.img_obj._match_str=null})}if(/^\((.+)\)$/.test(t)){this.bg_mask_image=this.BGMask_CreateCanvas(t,is_SA_child_animation);this.BGMask_onload();return}var o=this.bg_mask_image=new Image;o.onload=this.BGMask_onload;o.src=toFileProtocol(t)},BGMask_onload:function(){var e=document.getElementById("C_BG_mask");if(!e){e=document.createElement("canvas");e.id="C_BG_mask";var t=e.style;t.position="absolute";t.posTop=t.posLeft=0;t.zIndex=60+1;document.body.appendChild(e)}if(System._browser.mouseover_hide_list.indexOf(e)==-1)System._browser.mouseover_hide_list.push(e);if(is_SA_child_animation){System._browser.bg_mask_image_resized=document.createElement("canvas")}else{System._browser.BGMask_Draw()}},BGMask_Draw:function(e){if(is_SA_child_animation&&(!document.getElementById("C_wallpaper_mask")||!C_wallpaper_mask._WallpaperAsBG_custom)){this.WMPMask_Draw();return}if(!document.getElementById("C_BG_mask"))return;var t,i,o,n;t=o=self.B_content_width?B_content_width:document.body.style.pixelWidth;i=n=self.B_content_height?B_content_height:document.body.style.pixelHeight;if(o>parent.screen.width)o=parent.screen.width;if(n>parent.screen.height)n=parent.screen.height;var a,s,r,_;var l=C_wallpaper_mask.style;if(l.posLeft>0){a=0;r=l.posLeft}else{a=-l.posLeft;r=0}if(l.posTop>0){s=0;_=l.posTop}else{s=-l.posTop;_=0}if(e){var c=a+","+s+","+o+","+n+","+r+","+_+","+o+","+n;if(e._match_str==c)return;e._match_str=c;e.width=t;e.height=i;var d=e.getContext("2d");d.globalCompositeOperation="copy";d.drawImage(this.wallpaper_canvas,a,s,o,n,r,_,o,n);return}if(!this.bg_mask_image&&this.Opacity==1){document.getElementById("C_BG_mask").style.display="none";return}C_BG_mask.width=t;C_BG_mask.height=i;var d=C_BG_mask.getContext("2d");d.globalCompositeOperation="copy";d.globalAlpha=this.bg_mask_image?1:1-this.Opacity;d.drawImage(this.wallpaper_canvas,a,s,o,n,r,_,o,n);if(this.bg_mask_image){d.globalCompositeOperation="destination-out";d.globalAlpha=this.Opacity;d.drawImage(this.bg_mask_image,0,0,o,n)}else C_BG_mask.style.display="block"},resize_timerID:null,resize_cooling_timestamp:0,resize:function(){var e=false;function i(){if(!e){e=true;setTimeout(function(){window.dispatchEvent(new CustomEvent("SA_resized_once"))},0)}}return function(){this.resize_timerID=null;if(use_SA_browser_mode){let t=document.body.style;if(is_SA_child_animation){let e=parent.document.getElementById("Ichild_animation"+SA_child_animation_id).style;e.width=t.pixelWidth+"px";e.height=t.pixelHeight+"px";i()}else{if(webkit_electron_mode){if(webkit_electron_mode&&SA_topmost_window.System._browser.capturePage_in_process){this.resize_timerID=setTimeout("System._browser.resize()",50);return}if(webkit_electron_mode)System._browser.resize_cooling_timestamp=performance.now();SA_top_window.resizeToAbsolute(t.pixelWidth+(xul_mode?SA_top_window.outerWidth-SA_top_window.innerWidth:0),t.pixelHeight+(xul_mode?SA_top_window.outerHeight-SA_top_window.innerHeight:0))}i()}}}}(),drag_mouse_x:-1,drag_mouse_y:-1,drag_timerID:null,_is_dragging:false,get is_dragging(){return this._is_dragging},set is_dragging(e){this._is_dragging=e;document.body.style.cursor=e?"move":"auto"},mouseout_timerID:null,mouseover_hide_list:[],onmouseover_custom:null,onmouseover:function(e){if(webkit_electron_mode&&(SA_topmost_window.returnBoolean("IgnoreMouseEvents")||SA_topmost_window.returnBoolean("AutoItStayOnDesktop"))&&!SA_topmost_window.webkit_IgnoreMouseEvents_disabled)return;if(this.onmouseover_custom&&this.onmouseover_custom(e))return;if(this.mouseout_timerID){clearTimeout(this.mouseout_timerID);this.mouseout_timerID=null}var t=this.mouseover_hide_list;for(var i=0;i0&&t0&&i20||e.clientYe.is_closing_event);if(MMD_SA_options.Dungeon.dialogue_branch_mode&&!n)return false;new Promise(i=>{if(n){const o=Array.isArray(n.key)?n.key[0]:n.key;let e,t;if(typeof o=="number"){t=o+96}else if(o=="Esc"){e="Escape"}else{e="Key"+o}document.dispatchEvent(new KeyboardEvent("keydown",{code:e,keyCode:t}));System._browser.on_animation_update.add(i,0,0)}else{i()}}).then(()=>{new Promise(e=>{MMD_SA_options.Dungeon.run_event([[{message:{content:System._browser.translation.get("XR_Animator.settings.confirm"),branch_list:[{key:1,func:()=>{e()},ended:true},{key:2}]}}]])}).then(()=>{this.onSettings(true)})});return false}if(!System.Gadget.settingsUI)return false;if(use_inline_dialog){if(document.getElementById("Idialog").style.visibility=="hidden"){document.getElementById("Idialog").contentWindow.location.replace("settings.html")}return true}System._browser.showFocus(true,true);var t=showModalDialog(System.Gadget.settingsUI,self);t=xul_mode?self.returnValue:t;System._browser.showFocus(false);this.onSettingsClosed(t);return true},onSettingsClosed:function(e){if(System.Gadget.onSettingsClosed)System.Gadget.onSettingsClosed({closeAction:!!e,Action:{commit:true}})},onkeydown:function(e){var t=(is_SA_child_animation||document.getElementById("Lchild_animation_parent"))&&!is_SA_child_animation_host;const i=e.altKey;const o=i||!self.MMD_SA||!MMD_SA_options.Dungeon_options||!e.preventDefault;var n=e.keyCode;if(n==67&&i){this.confirmClose();return true}else if(n==69&&o){return this.onSettings()}else if(n==79&&o){var a;if(is_SA_child_animation){var s=parent.document.getElementById("Ichild_animation"+SA_child_animation_id).style;a=this.Opacity;if("_opacity_"in e){a=e._opacity_}else{a-=.25;if(a<.25)a=1}parent.System.Gadget.Settings._settings_need_update=true;parent.SA_child_animation[SA_child_animation_id].opacity=a;s.opacity=a}else if(this.bg_mask){a=this.Opacity;if("_opacity_"in e){a=e._opacity_}else{a-=.25;if(a<.25)a=1}System.Gadget.Settings.writeString("Opacity",a);this.Opacity=a;this.BGMask_Draw()}else if(w3c_mode||HTA_use_GPU_acceleration){var s=this.body.style;a=this.Opacity;if("_opacity_"in e){a=e._opacity_}else{a-=.25;if(a<.25)a=1}System.Gadget.Settings.writeString("Opacity",a);s.opacity=a}else return false;this.Opacity=a;DEBUG_show("Opacity:"+a*100+"%",2);this.update_tray();return true}else if(n==83&&o){var r=System.Gadget.docked?System.Gadget.onUndock:System.Gadget.onDock;if(!r)return false;setTimeout(System._browser.ondockundock,0);return true}else if(t&&(n>=49&&n<49+SA_child_animation_max)&&o){var _=n-49;var l=is_SA_child_animation?parent:self;var c=l.document.getElementById("Ichild_animation"+_);if(!c||!c.contentWindow.is_SA_child_animation){DEBUG_show("(child animation "+(_+1)+" not found)",2);return true}var d=c.contentWindow;var p=d.parent;var u=p.System._browser;if(d.System.Gadget.Settings.readString("CSSTransform3D")||p.System.Gadget.Settings.readString("CSSTransform3D")){if(u._child_selected==_){u._child_selected=null;d.DEBUG_show("(deselected)",2);p.DEBUG_show("(child"+(_+1)+" deselected)",2);return true}u._child_selected=_}d.DEBUG_show("(selected)",2);p.DEBUG_show("(child"+(_+1)+" selected)",2);u.arrangeChildZ(_);d.focus();return true}else if(t&&n==96&&o){var l=is_SA_child_animation?parent:self;var s=l.Lchild_animation_parent.style;s.visibility=s.visibility=="hidden"?"visible":"hidden";if(webkit_mode)s.display=s.visibility=="hidden"?"none":"block";l.System._browser._child_selected=null;return true}else if(t&&(n>=97&&n<97+SA_child_animation_max)&&o){var _=n-97;var l=is_SA_child_animation?parent:self;var c=l.document.getElementById("Ichild_animation"+_);if(!c||!c.contentWindow.is_SA_child_animation){DEBUG_show("(child animation "+(_+1)+" not found)",2);return true}var s=c.style;s.visibility=s.visibility=="hidden"?"visible":"hidden";if(webkit_mode)s.display=s.visibility=="hidden"?"none":"block";l.System._browser._child_selected=null;var m=false;for(var h=0;h=96&&n<96+10){if(self.MMD_SA&&MMD_SA_options.motion_shuffle&&MMD_SA.use_jThree&&MMD_SA.MMD_started){if(this.camera.ML_enabled){}else if(n==96){if(MMD_SA_options.audio_to_dance_disabled)return true;if(MMD_SA_options._motion_shuffle){if(!MMD_SA_options.motion_shuffle_list_default&&MMD_SA_options._motion_shuffle_list_default){MMD_SA_options.motion_shuffle_list_default=MMD_SA_options._motion_shuffle_list_default.slice();MMD_SA._force_motion_shuffle=true}else{MMD_SA_options.motion_shuffle=MMD_SA_options._motion_shuffle.slice(0);MMD_SA_options.motion_shuffle_list_default=null;MMD_SA._force_motion_shuffle=true;DEBUG_show("(MMD motions shuffled)",2)}}}else{var _=n-97;if(MMD_SA_options.motion_by_song_name){if(MMD_SA_options.motion_by_song_name._loading_){DEBUG_show("(music/motion loading)",2);return true}let e=Object.keys(MMD_SA_options.motion_by_song_name).find(e=>{return MMD_SA_options.motion_by_song_name[e].key==_+1});if(e){let t=MMD_SA_options.motion_by_song_name[e].song_path;if(/\.zip\#/i.test(t)){MMD_SA_options.motion_by_song_name._loading_=true;t=t.replace(/^.+[\/\\]([^\/\\]+\.zip)/i,"$1");let e=new self.XMLHttpRequestZIP;e.onload=function(){MMD_SA_options.motion_by_song_name._loading_=false;let e=this.response;e.name=t.replace(/^.+[\/\\]/,"");e.isFileSystem=true;SA_DragDropEMU(e)};e.open("GET",t,true);e.responseType="blob";e.send()}else SA_DragDropEMU(t);return true}}if(MMD_SA_options.audio_to_dance_disabled)return true;if(_>=MMD_SA.normal_action_length){DEBUG_show("(MMD motion not found)",2);return true}if(!MMD_SA_options._motion_shuffle)MMD_SA_options._motion_shuffle=MMD_SA_options.motion_shuffle.slice(0);MMD_SA_options.motion_shuffle=[_];MMD_SA_options.motion_shuffle_list_default=null;MMD_SA._force_motion_shuffle=true;DEBUG_show("(MMD motion changed)",2)}return true}}return false},ondockundock:function(){DEBUG_show("Dock state changed",2);var e=!System.Gadget.docked;System.Gadget.docked=e;System.Gadget.Settings.writeString("SA_docked",!!e==!!is_SA_child_animation?"":e?"1":"0");var t=!e?System.Gadget.onUndock:System.Gadget.onDock;if(!t)return;t()},onmousemove_custom:null,onmousemove:function(e){var t,i;t=this._WE_mouse_x=e.x;i=this._WE_mouse_y=e.y;if(this.onmousemove_custom&&this.onmousemove_custom(e))return;if(!this.is_dragging){if(is_SA_child_animation&&parent.System._browser.is_dragging){parent.System._browser.onmousemove(e)}return}if(!WallpaperEngine_mode){if(absolute_screen_mode){t=SA_top_window.getCursorPos().x;i=SA_top_window.getCursorPos().y}else{t=e.screenX;i=e.screenY}}if(is_SA_child_animation||this._child_selected!=null){var o,n,a;if(is_SA_child_animation){a=SA_child_animation_id;o=self;n=parent}else{a=this._child_selected;o=document.getElementById("Ichild_animation"+a).contentWindow;n=self}n.System.Gadget.Settings._settings_need_update=true;var s=n.SA_child_animation[a];var r=n.document.getElementById("Ichild_animation"+a).style;var _=o.document.body.style;var l=n.document.body.style;var c=s.x+t-this.drag_mouse_x;var d=s.y+i-this.drag_mouse_y;r.posLeft=s.x=c;r.posTop=s.y=d;o.document.getElementById("Ldebug").innerText=n.document.getElementById("Ldebug").innerText="(moving)";o.DEBUG_hide_sec=n.DEBUG_hide_sec=0;o.DEBUG_show("("+c+","+d+")",2)}else{System.Gadget.Settings._settings_need_update=true;this.moveBy(t-this.drag_mouse_x,i-this.drag_mouse_y,e)}this.moveWallpaper();this.drag_mouse_x=t;this.drag_mouse_y=i},moveWallpaper:function(e,t){if(is_SA_child_animation&&(!document.getElementById("C_wallpaper_mask")||!C_wallpaper_mask._WallpaperAsBG_custom))return;if(is_SA_child_animation||document.getElementById("LdesktopBG")&&LdesktopBG.style.display!="none"){if(WallpaperEngine_mode){e=0;t=0}else{if(absolute_screen_mode){if(e==null)e=SA_top_window.screenLeftAbsolute;if(t==null)t=SA_top_window.screenTopAbsolute;var i=SA_top_window.getScreenBounds(e,t);e=-(e-i.x);t=-(t-i.y)}else{if(e==null)e=SA_top_window.screenLeft;if(t==null)t=SA_top_window.screenTop;e=-(e%parent.screen.width);t=-(t%parent.screen.height)}}if(is_SA_child_animation){var o=parent.SA_child_animation[SA_child_animation_id];e-=o.x;t-=o.y}else{var n=(is_SA_child_animation_host&&Ichild_animation0.contentWindow.document.getElementById("LdesktopBG")||LdesktopBG).style;n.posLeft=e;n.posTop=t}if(document.getElementById("C_wallpaper_mask")){var a=C_wallpaper_mask.style;a.posLeft=e;a.posTop=t}}},moveBy:function(e,t,i){SA_top_window.moveByAbsolute(e,t)},update_tray:function(e){try{if(!webkit_electron_mode||IPC.active_window!=self)return;if(this._tray_last_updated==RAF_timestamp){return}this._tray_last_updated=RAF_timestamp;if(!e){e={active_window_id:IPC.active_window_id,click_thru:SA_topmost_window.returnBoolean("IgnoreMouseEvents"),click_thru_partial:SA_topmost_window.returnBoolean("IgnoreMouseEventsPartial"),always_on_top:SA_topmost_window.returnBoolean("AutoItAlwaysOnTop"),stay_on_desktop:SA_topmost_window.returnBoolean("AutoItStayOnDesktop"),use_electron_as_wallpaper:SA_topmost_window.WebKit_object.use_electron_as_wallpaper,auto_pause:SA_topmost_window.returnBoolean("AutoItAutoPause"),opacity:is_SA_child_animation?parent.SA_child_animation[SA_child_animation_id].opacity:parseFloat(System.Gadget.Settings.readString("Opacity")||1),opacity_on_hover:parseFloat(System.Gadget.Settings.readString("OpacityOnHover")||1),size:Settings.CSSTransformFullscreen?-1:Settings.CSSTransformScale,animation_path:Settings.f_path_folder,media_control:self.SL&&SL._mouse_event_main&&SL._mouse_event_main(),MMD:null};var t=[true];for(var i=0;i{if(e.func==t)e.canceled=true})},run:function(e){var t=[];var i=a[e];if(!i.length)return;var o=[];for(let e=0;e=0){o.push(n)}else{n.func();if(n.loop&&--n.loop!=0)o.push(n)}}a[e]=o}}}(),get css_scale(){return window.devicePixelRatio>=2?.5:1},virtual_numpad_toggle:function(e){if(e==null)e=Lnumpad_row0.style.display=="none";Lnumpad_row0.style.display=e?"inline":"none";Lnumpad_rows.style.display=e?"block":"none";if(e&&self.ChatboxAT)ChatboxAT.chatW_minimize(0,true)},virtual_numpad:function(){var d={};var p={A:1,B:2,C:3,D:4,E:5,F:6,G:7,H:8,X:9};return function(e,t){e.preventDefault();e.stopPropagation();var i=MMD_SA_options.Dungeon&&MMD_SA_options.Dungeon.character.combat_mode;var o=e.target.textContent;var n=d[o]=d[o]||{};var a,s,r;switch(o){case"S":a=16;n.pressed=!n.pressed;const l=document.getElementsByClassName("Lnumpad_button");if(n.pressed&&MMD_SA_options.Dungeon&&MMD_SA_options.Dungeon.event_mode){for(let e=0;ee[1]==RegExp.$1)[0]}}else{for(let e=0;ee[0]==RegExp.$1)[1]}}t=n.pressed?"keydown":"keyup";break;case"+":a=107;if(i){if(t=="keyup")return;n.pressed=!n.pressed;t=n.pressed?"keydown":"keyup"}break;case"-":a=109;break;case"*":a=106;break;case"/":a=111;break;case"⏎":a=13;break;case"J":a=32;break;case"↑":a=38;r="ArrowUp";break;case"↓":a=40;r="ArrowDown";break;case"←":a=37;r="ArrowLeft";break;case"→":a=39;r="ArrowRight";break;default:if(/([0-9])/.test(o))a=parseInt(o)+96;else r="Key"+o}if(n.timeoutID)clearTimeout(n.timeoutID);if(n.intervalID)clearTimeout(n.intervalID);n.timeoutID=n.intervalID=null;let _=new KeyboardEvent(t,{bubbles:true,cancelable:true,key:o,keyCode:a,code:r,shiftKey:d["S"]&&d["S"].pressed});document.dispatchEvent(_);if(t=="keydown"){if(/[\+S]/.test(o)&&(o!="+"||i)){e.target.style.opacity="0.75"}else{n.timeoutID=setTimeout(function(){n.intervalID=setInterval(function(){document.dispatchEvent(_)},100)},400)}}else{e.target.style.opacity=""}}}(),P2P_network:function(){var o;var n=0;var a={events:{peer:{},connection:{handshake_request:function(e,t){console.log("P2P_network: Remote Peer"+"("+t.peer+"/"+t.label+"/host) responding handshake request from Peer-"+e.index+"("+e.id+")");t.send({handshake:{request:true}})},handshake_respond:function(e,t,i){if(i.request){t.status="connected";console.log("P2P_network: Remote Peer"+"("+t.peer+"/"+t.label+"/client)'s handshake request accepted from Peer-"+e.index+"("+e.id+")");t.send({handshake:{accepted:true}})}else if(i.accepted){t.status="connected";console.log("P2P_network: Remote Peer"+"("+t.peer+"/"+t.label+"/host) accepted handshake request from Peer-"+e.index+"("+e.id+")");if(e.para.events.connection.handshake_request_accecpted&&e.para.events.connection.handshake_request_accecpted[t.label]){e.para.events.connection.handshake_request_accecpted[t.label]({peer:e,connection:t,handshake:i});delete e.para.events.connection.handshake_request_accecpted[t.label]}}else{console.log("P2P_network: Remote Peer"+"("+t.peer+"/"+t.label+"/host) rejected handshake request from Peer-"+e.index+"("+e.id+")");if(e.para.events.connection.handshake_request_rejected&&e.para.events.connection.handshake_request_rejected[t.label]){e.para.events.connection.handshake_request_rejected[t.label]({peer:e,connection:t,handshake:i});delete e.para.events.connection.handshake_request_rejected[t.label]}}},data:function(e,t,i){}},send_message:function(e){if(!e.command)t.content_window.ChatboxAT.ChatShow([e.name+": "+e.msg]);return null}}};function s(t,i){this._connection=i;this.status="connecting";t.connections[i.label]=this;var o=this;i.on("data",function(e){if(e.handshake){t.para.events.connection.handshake_respond(t,o,e.handshake)}else{t.para.events.connection.data(t,o,e)}});i.on("close",function(e){console.log("P2P_network: DataConnection"+"("+i.peer+"/"+i.label+"/host) closed");o.close(t)})}s.prototype.send=function(e){this._connection.send(e)};s.prototype.close=function(e){if(!e.connections[this.label])return;if(e.para.events.connection.close&&e.para.events.connection.close(e,this))return;delete e.connections[this.label];var t=this;setTimeout(function(){t._connection.close();t._connection=null},1e3)};Object.defineProperty(s.prototype,"peer",{get:function(){return this._connection.peer}});Object.defineProperty(s.prototype,"label",{get:function(){return this._connection.label}});function r(){}Object.defineProperty(r.prototype,"length",{get:function(){return Object.keys(this).length}});function e(t=Object.clone(a)){this.para=t;this.id=null;var e=this._peer=new Peer;this.index=n;this.connections=new r;this.status="connecting";var i=this;e.on("open",function(e){n++;if(!o)o=i;i.id=e;i.status="connected";console.log("P2P_network: Peer-"+i.index+"("+e+") connected");i.para.events.peer.open&&i.para.events.peer.open(i)});e.on("error",function(e){console.log("P2P_network: Peer-"+i.index+" error",e);if(i.para.events.peer.error_by_connection){i.para.events.peer.error_by_connection(e);delete i.para.events.peer.error_by_connection}else i.para.events.peer.error&&i.para.events.peer.error(i,e)});e.on("connection",function(e){if(t.events.peer.connection&&t.events.peer.connection(i,e))return;console.log("P2P_network: Remote Peer"+"("+e.peer+"/"+e.label+"/client) connecting to Peer-"+i.index+"("+i.id+")");e.on("open",function(){console.log("P2P_network: Remote Peer"+"("+e.peer+"/"+e.label+"/client) connected to Peer-"+i.index+"("+i.id+")");new s(i,e)})})}e.prototype.connect=function(n,e){var a=this;return new Promise(function(i,o){var e=function(){var e={serialization:"json"};var t=a._peer.connect(n,e);t.on("open",function(){console.log("P2P_network: Remote Peer"+"("+t.peer+"/"+t.label+"/host) connecting to Peer-"+a.index+"("+a.id+")");var e=new s(a,t);a.para.events.connection.handshake_request(a,e);a.para.events.connection.handshake_request_accecpted=a.para.events.connection.handshake_request_accecpted||{};a.para.events.connection.handshake_request_rejected=a.para.events.connection.handshake_request_rejected||{};a.para.events.connection.handshake_request_accecpted[t.label]=i;a.para.events.connection.handshake_request_rejected[t.label]=o;delete a.para.events.peer.error_by_connection});t.on("error",function(e){console.log("P2P_network: Remote connection failed",e);o(e)});a.para.events.peer.error_by_connection=o};switch(a.status){case"connected":e();break;default:setTimeout(function(){o(a)},0)}})};var t={peer:e,get peer_default(){return o},status:"off",get content_window(){return is_SA_child_animation_host?document.getElementById("Ichild_animation0").contentWindow:self},process_message:function(e,t){var i=this.peer_default;if(!i)return e;var o=this.content_window.document.getElementById("Flogin").id.value;var n=this.content_window.document.getElementById("Flogin").pass.value;var a=this.content_window.MMD_SA_options;var s=(o||a&&a.model_para_obj.character&&a.model_para_obj.character.name||"Anonymous").substring(0,16);var r=i&&i.connections.length;var _;if(!/^\//.test(e)){_=i.para.events.send_message({name:s,msg:e,id:o,pass:n})}else{var l,c,d;var p=this.content_window.ChatboxAT.checkChatCommand(e);l=p.command;c=p.para1;d=p.para2;_=i.para.events.send_message({name:s,msg:e,command:l,para1:c,para2:d,id:o,pass:n})}if(!t)this.content_window.document.getElementById("Fchat").msg.value="";if(_!=null)return _;return e}};return t}(),camera:function(){var je;var c,r;var d;var Fe,Le;var Ce;var Be;var T=true;var t=new URLSearchParams(self.location.search.substring(1));var He="";var Oe="";var i=true;var _;var k=0;var P="";function n(){var s=je.video;if(!s.videoWidth||s.readyState<2){return}if(d.busy||RAF_animation_frame_unlimited&&!MMD_SA.WebXR.session&&P==je.video_frame_id&&!Ce.bb_clear){Fe.wireframe._skip_frame=true;return}P=je.video_frame_id;k=RAF_timestamp;var n=je.video_canvas;var r=n.getContext("2d");if(Ce.bb_clear){if(s.pause&&!s.paused||--Ce.bb_clear<=0||Ce._bb&&Ce._bb_waiting){Ce.bb_clear=Ce._bb=Ce._bb_waiting=null;r.globalCompositeOperation="copy"}else{if(Ce._bb){r.globalCompositeOperation="source-over";r.fillStyle="black";let e=Ce._bb[3];let t=Ce._bb[0];let i=Ce._bb[1]-e;let o=Ce._bb[2]-t;e=Math.max(e-i*.25,0);t=Math.max(t-o*.25,0);i=Math.min(i*1.5,n.width);o=Math.min(o*1.5,n.height);if(je.video_flipped){e=n.width-(e+i)}r.fillRect(e,t,i,o);Ce._bb=null;Ce._bb_waiting=true}return}}var _,l;if(MMD_SA_options.user_camera.pixel_limit.disabled){_=s.videoWidth;l=s.videoHeight}else if(je.is_local_media){_=s.videoWidth;l=s.videoHeight;const e=MMD_SA_options.user_camera.pixel_limit.current||MMD_SA_options.user_camera.pixel_limit._default_;if(_*l>e[0]*e[1]){const t=Math.sqrt(_*l/(e[0]*e[1]));_=Math.round(_/t);l=Math.round(l/t)}}else{_=je.target_width;l=je.target_height}var a=MMD_SA_options.user_camera.display.webcam_as_bg?{scale:1,top:0}:MMD_SA_options.user_camera.display.video;if(!a.scale){if(n.style.pixelWidth!=window.innerWidth||n.style.pixelHeight!=window.innerHeight){n.style.width=window.innerWidth+"px";n.style.height=window.innerHeight+"px"}}else{let e=a.scale*(je.display_floating?MMD_SA_options.user_camera.display.floating_scale||MMD_SA_options.user_camera.display.floating&&1||.5:1);let i=~~(window.innerWidth*e);let o=~~(window.innerHeight*e);if(n.style.pixelWidth!=i||n.style.pixelHeight!=o){n.style.width=i+"px";n.style.height=o+"px";let e=(window.innerWidth-i)/2;let t=(window.innerHeight-o)/2;n.style.left=e*(1+(a.left!=null?a.left:-1))+"px";n.style.top=t*(1+(a.top!=null?a.top:0))+"px"}n.style.objectFit="contain"}if(n.width!=_||n.height!=l){n.width=_;n.height=l;r.globalCompositeOperation="copy";if(je.video_flipped){r.translate(_,0);r.scale(-1,1)}}if(_==s.videoWidth&&l==s.videoHeight){r.drawImage(s,0,0)}else{let e=_/l;let t=s.videoWidth/s.videoHeight;let i,o,n,a;if(e<=t){n=s.videoHeight*e;i=(s.videoWidth-n)/2;a=s.videoHeight;o=0}else{n=s.videoWidth;i=0;a=s.videoWidth/e;o=(s.videoHeight-a)/2}r.drawImage(s,i,o,n,a,0,0,_,l)}n.style.visibility=!je.visible||d.enabled||c.initialized&&c.worker_initialized&&!c.dets||je.hidden_enforced?"hidden":"inherit"}function a(){if(d.enabled){d.update_frame()}else{if(Fe.enabled){Fe.update_frame(true)}else if(c.enabled){c.update_frame(true)}if(Ce.enabled||Be.enabled){D(true)}}const i=je.video_canvas_facemesh.style;const e=je.video_canvas.style;const t=MMD_SA_options.user_camera.display.wireframe.align_with_video?1:MMD_SA_options.user_camera.display.wireframe.scale||(is_mobile?.25:1);const o=~~(e.pixelWidth*t);const n=~~(e.pixelHeight*t);if(i.pixelWidth!=o||i.pixelHeight!=n){i.pixelWidth=o;i.pixelHeight=n;if(MMD_SA_options.user_camera.display.wireframe.align_with_video){i.posLeft=e.posLeft;i.posTop=e.posTop}else{let e=(window.innerWidth-o)/2;let t=(window.innerHeight-n)/2;i.left=e*(1+(MMD_SA_options.user_camera.display.wireframe.left!=null?MMD_SA_options.user_camera.display.wireframe.left:1))+"px";i.top=t*(1+(MMD_SA_options.user_camera.display.wireframe.top!=null?MMD_SA_options.user_camera.display.wireframe.top:-1))+"px"}}i.objectFit=e.objectFit;i.visibility=je.ML_enabled&&!MMD_SA_options.user_camera.display.wireframe.hidden&&!MMD_SA_options.user_camera.display.webcam_as_bg?"inherit":"hidden"}var R;function s(){if(je.initialized){SL.style.transform=SL_2D_front.style.transform=je.mirror_3D?"scaleX(-1)":"none";je.video_canvas.style.transform=je.display_flipped?"scaleX(-1)":"none";je.reset_video_canvas()}if(!R&&je.initialized){R=true;System._browser.on_animation_update.add(n,0,0,-1);System._browser.on_animation_update.add(a,2,1,-1)}}function l(){SL.style.transform=SL_2D_front.style.transform=je.mirror_3D?"scaleX(-1)":"none";je.video_canvas.style.transform="none";je.reset_video_canvas();if(je.visible)return;if(R&&!je.ML_enabled){R=false;System._browser.on_animation_update.remove(n,0);System._browser.on_animation_update.remove(a,1);je.video_canvas_facemesh.style.visibility="hidden"}}var o=100;function p(e){if(!je.visible)return;var t=e.detail.keyCode;if(t==107)o+=10;else if(t==109)o-=10;else return;o=Math.max(Math.min(o,180),20);var i=je.video_canvas.getContext("2d");if(o==1){i.filter="none";DEBUG_show("Brightness:100%",2)}else{i.filter="brightness("+o+"%) contrast("+(100+(o-100)*.25)+"%)";DEBUG_show("Brightness:"+o+"%",2)}e.detail.result.return_value=true}var u=0;function m(e){if(!e)e=je.local_src||(webkit_electron_mode?"C:\\Users\\user\\Documents\\_.mp4":System.Gadget.path+"/js/headtrackr.mp4");if(/\.(png|jpg|jpeg|bmp|webp)$/i.test(e)){if(!je._image){je._image=new Image;Object.defineProperty(je._image,"videoWidth",{get:function(){return this.width}});Object.defineProperty(je._image,"videoHeight",{get:function(){return this.height}});Object.defineProperty(je._image,"readyState",{get:function(){return this.complete?4:0}})}if(je.video&&je.video.pause)je.video.pause();je.video=je._image;je._image.src=toFileProtocol(e)}else{je.video=je._video;je.video.loop=true;if(!je.video._initialized){je.video._initialized=true;je.video.addEventListener("canplaythrough",function(e){if(je.stream){if(je.media_control_enabled){je.media_control_enabled=false}}else{je.media_control_enabled=true;let e=it.speed;if(e){je.video.playbackRate=e;if(e<1)je.video.muted=true}else{je.video.playbackRate=1}}});je.video.addEventListener("ended",function(e){if(it.speed)it.stop()})}je.video.src=toFileProtocol(e)}je.video_id=e;je.local_src=e}let h=false;function f(e){SL_MC_Timeupdate(je.video)}window.addEventListener("MMDStarted",()=>{function e(e){if(!System._browser.camera.poseNet.enabled)return;const t=MMD_SA.MMD.motionManager.para_SA;if(!t.motion_tracking_upper_body_only||!t.motion_tracking?.arm_as_leg)return;window.addEventListener("SA_camera_poseNet_update",()=>{t.motion_tracking.arm_as_leg.enabled=!t.motion_tracking.arm_as_leg.enabled;tt.reset_to_default_motion_once=true;DEBUG_show("Arm-as-leg control:"+(t.motion_tracking.arm_as_leg.enabled?"ON":"OFF"),3)},{once:true})}const t={id:"arm_to_leg_control_mode",accelerator:["Alt+Q"],process:e};if(System._browser.hotkeys._hotkey_config){System._browser.hotkeys._hotkey_config.push(t)}else{System._browser.hotkeys.add(t)}});var M=false;function B(){Je();var e=Fe.enabled||Ce.enabled;if(M==!!e)return;M=!!e;if(e){s();tt.reset();tt.add_events();DEBUG_show("(Camera ML Mode:ON)",2)}else{if(je.initialized){je.video_canvas_face_detection.style.visibility="hidden";je.video_canvas_facemesh.style.visibility="hidden";l()}tt.remove_events();je._info="";DEBUG_show("(Camera ML Mode:OFF)",2)}}var H,O,ot;var qe,Te,Ie,ze;var Xe,Ue,Ke,nt,at,st;var Ge,We;var X,U;var q;var rt;var _t={};var Qe=["親","人","中","薬","小"];var lt=["thumb","index","middle","ring","pinky"];var Ve=["0","1","2","3"];var ct={};window.addEventListener("jThree_ready",()=>{qe=new THREE.Vector3;Te=new THREE.Vector3;Ie=new THREE.Vector3;ze=new THREE.Vector3;q=new THREE.Vector3;Xe=new THREE.Quaternion;Ue=new THREE.Quaternion;Ke=new THREE.Quaternion;nt=new THREE.Quaternion;at=new THREE.Quaternion;st=new THREE.Quaternion;Ge=new THREE.Matrix4;We=new THREE.Quaternion;X=new THREE.Vector2;U=new THREE.Vector2;rt=new THREE.Quaternion;["左","右"].forEach(e=>{_t[e]=new System._browser.data_filter([{type:"one_euro",id:"shoulder_rot",para:[30,1,5,1,1]}])});for(const e of["左","右"]){const i=ct[e]=[];for(let t=0;t<5;t++){i[t]=[];for(let e=0;e<4;e++){i[t][e]={pos:new THREE.Vector3,rot:new THREE.Vector3}}}}});var e;var y;var g;var dt=true;var pt=true;var ut;var K=true;var b,mt,v;var Ne=false;var ht=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"];var ft=[0,2,5,7,8,11,12,13,14,15,16,23,24,25,26,27,28];var Mt=[];ht.forEach(e=>{Mt.push({part:e,score:0})});var Ye,Ze;var A;function I(){if(A)return;A=true;const r=THREE.MMD.getModels()[0];const o=r.mesh.bones_by_name;const s=MMD_SA.THREEX.get_model(0);const e=o["左腕"].pmxBone.origin;const t=o["左ひじ"].pmxBone.origin;MMD_SA_options.model_para_obj.left_arm_z_rot=Math.PI/2+Math.atan2(t[1]-e[1],t[0]-e[0]);const i=o["左腕IK"].pmxBone.origin;MMD_SA_options.model_para_obj.left_arm_to_IK_xy=[e[0]-i[0],e[1]-i[1],e[2]-i[2]];MMD_SA_options.model_para_obj.left_arm_length=MMD_SA.TEMP_v3.fromArray(MMD_SA_options.model_para_obj.left_arm_to_IK_xy).length();MMD_SA_options.model_para_obj.left_palm_length=MMD_SA.TEMP_v3.fromArray(o["左手首"].pmxBone.origin).distanceTo(MMD_SA._v3a.fromArray(o["左中指1"].pmxBone.origin));MMD_SA_options.model_para_obj.arm_IK_offset={"左":(new THREE.Vector3).fromArray(o["左腕"].pmxBone.origin).sub(Te.fromArray(o["左腕IK"].parent.pmxBone.origin)),"右":(new THREE.Vector3).fromArray(o["右腕"].pmxBone.origin).sub(Te.fromArray(o["右腕IK"].parent.pmxBone.origin))};let n=o["右腕"].pmxBone.origin;MMD_SA_options.model_para_obj.shoulder_width=Math.abs(e[0]-n[0]);MMD_SA_options.model_para_obj.arm_axis={"左":(new THREE.Vector3).fromArray(i).sub(MMD_SA.TEMP_v3.fromArray(e)).normalize()};MMD_SA_options.model_para_obj.arm_axis["右"]=MMD_SA_options.model_para_obj.arm_axis["左"].clone().setX(-MMD_SA_options.model_para_obj.arm_axis["左"].x);const a=o["左足"].pmxBone.origin;const _=o["左足首"].pmxBone.origin;MMD_SA_options.model_para_obj.hip_center=(new THREE.Vector3).fromArray(a).setX(0);MMD_SA_options.model_para_obj.hip_center_offset=(new THREE.Vector3).fromArray(o["下半身"].pmxBone.origin).sub(MMD_SA_options.model_para_obj.hip_center);MMD_SA_options.model_para_obj.spine_length=o["首"].pmxBone.origin[1]-MMD_SA_options.model_para_obj.hip_center.y;MMD_SA_options.model_para_obj.left_heel_height=_[1];MMD_SA_options.model_para_obj.leg_IK_offset={"左":(new THREE.Vector3).fromArray(o["左足"].pmxBone.origin).sub(Te.fromArray(o["左足IK"].parent?.pmxBone?.origin||[0,0,0])),"右":(new THREE.Vector3).fromArray(o["右足"].pmxBone.origin).sub(Te.fromArray(o["右足IK"].parent?.pmxBone?.origin||[0,0,0]))};MMD_SA_options.model_para_obj.left_leg_upper_length=a[1]-o["左ひざ"].pmxBone.origin[1];MMD_SA_options.model_para_obj.left_leg_lower_length=o["左ひざ"].pmxBone.origin[1]-_[1];MMD_SA_options.model_para_obj.left_leg_length=MMD_SA_options.model_para_obj.left_leg_upper_length+MMD_SA_options.model_para_obj.left_leg_lower_length;MMD_SA_options.model_para_obj.left_leg_IK=[a[0]-_[0],a[1]-_[1],a[2]-_[2]];let l=["左","右"];Ye={};l.forEach(n=>{["腕","ひじ"].forEach((e,t)=>{let i=n+e;let o=MMD_SA.get_bone_axis_rotation(r.mesh,i);Ye[i]={name:i,axis_rot:o,parent:t==0?{axis_rot:new THREE.Quaternion}:Ye[n+"腕"]};Ye[i].axis_rot_offset_inv=(new THREE.Quaternion).multiplyQuaternions(Ye[i].parent.axis_rot,MMD_SA.TEMP_q.copy(Ye[i].axis_rot).conjugate())})});const c={};c[1]=(new THREE.Quaternion).setFromEuler(MMD_SA.TEMP_v3.set(0,-Math.PI/2*1,Math.PI/2*1),"YZX");c[-1]=(new THREE.Quaternion).setFromEuler(MMD_SA.TEMP_v3.set(0,-Math.PI/2*-1,Math.PI/2*-1),"YZX");Ze={};Ze[1]=(new THREE.Quaternion).multiplyQuaternions(c[1],MMD_SA._q1.copy(Ye["左腕"].axis_rot).conjugate());Ze[-1]=(new THREE.Quaternion).multiplyQuaternions(c[-1],MMD_SA._q1.copy(Ye["右腕"].axis_rot).conjugate());MMD_SA_options.model_para_obj.rot_hand_adjust_base=c;MMD_SA_options.model_para_obj.rot_hand_adjust=Ze;MMD_SA_options.model_para_obj.finger_base={};l.forEach(s=>{Qe.forEach((e,t)=>{let n=s+e+"指";let i=t==0&&o[n+Ve[0]]?0:1;if(!o[n+Ve[i+0]])return;let a=MMD_SA_options.model_para_obj.finger_base[s+t]={base_index:i};for(let i=a.base_index+(t==0?0:-1),o=i;o<3;o++){let e=n+Ve[a.base_index+(o-i)];let t=MMD_SA.get_bone_axis_rotation(r.mesh,e,true);Ye[e]={name:e,axis_rot:t,parent:o==i?Ye[s+"ひじ"]:Ye[n+Ve[a.base_index+(o-1-i)]]};Ye[e].axis_rot_offset_inv=(new THREE.Quaternion).multiplyQuaternions(Ye[e].parent.axis_rot,MMD_SA.TEMP_q.copy(Ye[e].axis_rot).conjugate())}})});for(const y in Ye){if(y.indexOf("指")!=-1){MMD_SA.TEMP_v3.setEulerFromQuaternion(Ye[y].axis_rot,"ZYX");MMD_SA.TEMP_v3.z*=-1;Ye[y].axis_rot.setFromEuler(MMD_SA.TEMP_v3,"ZYX")}Ye[y].axis_rot_inv=Ye[y].axis_rot.clone().conjugate()}for(const y in Ye){if(y.indexOf("指")!=-1){Ye[y]._axis_rot_offset_inv_z=MMD_SA.TEMP_v3.setEulerFromQuaternion(MMD_SA.TEMP_q.copy(Ye[y].axis_rot_offset_inv).premultiply(Ye[y].parent.axis_rot_inv).multiply(Ye[y].parent.axis_rot),"ZYX").z}}MMD_SA_options.model_para_obj.rot_arm_adjust=Ye;console.log(Ye);const d=MMD_SA_options.model_para_obj.colliders_for_hands=MMD_SA_options.model_para_obj.colliders_for_hands||{};const p=qe.fromArray(s.get_bone_origin_by_MMD_name("左手首")).distanceTo(Te.fromArray(s.get_bone_origin_by_MMD_name("左中指"+Ve[1])));d.left_hand={children:[{bone:"leftHand",offset:[p,0,0],radius:p}]};d.generate_hand_parameters=function(){const e=this.left_hand.children[0].offset;const t=.5;const i={left:{offset:{x:e[0]*t,y:e[1]*t,z:e[2]*t}},right:{offset:{x:-e[0]*t,y:e[1]*t,z:e[2]*t}}};return i};d.reset_hit=function(){this._hit_={};for(const e of["左","右"])this._hit_[e]={}};d.reset_hit();d.record_hit=function(e,t){d._hit_[t][e.name.split("|")[0]]=true};d.debug_hit=(()=>{const n={head:"Head",chest:"Chest",spine:"Waist","下半身":"Hip"};return function(e,t){let i="";if(Ce.enabled&&Ce.body_collider.enabled){for(const t of["左","右"]){const o=t=="左"?"L":"R";i+="👊-"+o+":"+(Object.keys(this._hit_[t]).map(e=>n[e]).join(",")||"(no collider hit)")+"\n"}}this.reset_hit();return i}})();let u;if(s.type=="VRM"){u=s.model.springBoneManager.colliders.filter(e=>{if(!e.shape.radius)return false;let t=e;while(t){t=t.parent;if(t?.isBone){if(t.name=="Head")return true;break}}})}else if(!MMD_SA.THREEX.enabled){const g=o["頭"]._index;u=r.pmx.rigids.filter(e=>e.bone==g&&(e.shape==0||e.shape==2)).map(e=>{return{shape:{radius:e.size[0],offset:{x:e.ofs[0],y:e.ofs[1],z:e.ofs[2]}}}})}const m=s.get_bone_origin_by_MMD_name("頭")[1]-s.get_bone_origin_by_MMD_name("首")[1];const h=Math.max(s.para.shoulder_width/3,m);const f=s.type=="VRM"?1/MMD_SA.THREEX.VRM.vrm_scale:1;let M=[{shape:{radius:h,offset:{x:0,y:h*f,z:h*.5*f}}}];if(!d.head){d.head={get scale(){return Ce.body_collider.head.size_percent/100},_head_colliders:u,_head_colliders_default:M,reset:function(){let e=this._head_colliders_default;const i=.7071067811865476;const o=qe.set(9999,9999,9999);const n=Te.set(-9999,-9999,-9999);e.forEach(e=>{let t=MMD_SA.TEMP_v3.copy(e.shape.offset).addScalar(e.shape.radius*i);n.max(t);t=MMD_SA.TEMP_v3.copy(e.shape.offset).addScalar(-e.shape.radius*i);o.min(t)});const t=new MMD_SA.THREEX.THREEX.Box3(o,n);const a=t.getBoundingSphere(new MMD_SA.THREEX.THREEX.Sphere(t.getCenter(Ie)));d.head.parent={is_parent:true,bone:"head",offset:s.type=="VRM"?s.process_position(Ie.multiplyScalar(MMD_SA.THREEX.VRM.vrm_scale)).toArray():Ie.toArray(),radius:a.radius};d.head.children=e.map(e=>{function t(e,t,i){const o=-s.para.spine_length/5;return e.z>o}const i={validate:t,rotation_base:true};return{bone:"head",offset:s.type=="VRM"?s.process_position(MMD_SA.TEMP_v3.copy(e.shape.offset).multiplyScalar(MMD_SA.THREEX.VRM.vrm_scale)).toArray():MMD_SA.TEMP_v3.copy(e.shape.offset).toArray(),radius:e.shape.radius,z_push:i}});if(d.head.children.length==1){d.head.children=[Object.assign({},d.head.parent,{is_parent:false,z_push:d.head.children[0].z_push,use_vector_filter:true})];d.head.parent=null}console.log(d.head)},generate_colliders:(()=>{let n,e;let t;return function(){if(!Ce.body_collider.head.enabled)return[];if(n===this.scale&&e===Ce.body_collider.head.reaction_type)return t;n=this.scale;e=Ce.body_collider.head.reaction_type;t=(this.parent&&[this.parent]||[]).concat(this.children||[]).map((e,t)=>{const i=d.generate_hand_parameters();const o=e.radius*n+i.left.offset.x;return Object.assign({type:"bone",name:e.bone,offset:{x:e.offset[0],y:e.offset[1],z:e.offset[2]},hand_affected:i,auto_scale:false,peak_barrier:true,is_parent:e.is_parent,use_vector_filter:e.use_vector_filter,z_push:!e.is_parent&&Ce.body_collider.head.reaction_type=="z_push"?e.z_push:null,magnet_id:"head_collider"+t,keep_validation_state_until_reset:true,on_hit:!e.is_parent&&d.record_hit},e.line_end?{magnet_type:"line",line_end:{x:e.line_end[0],y:e.line_end[1],z:e.line_end[2]},effective_distance:o,peak_distance:o}:{radius:o,peak_radius:o})});return t}})()}}d.head.reset();if(!d.chest){const b=s.para.shoulder_width/4;d.chest={get scale(){return Ce.body_collider.chest.size_percent/100},children:[-1,1].map(e=>{function t(e,t,i){return true}const i=s.get_bone_origin_by_MMD_name("首")[1]-s.para.spine_length/3-s.get_bone_origin_by_MMD_name("上半身2")[1];return{bone:"chest",offset:[b*e,i,b*.5],radius:b,z_push:{validate:t,rotation_base:true}}}),generate_colliders:(()=>{let o;let e;return function(){if(!Ce.body_collider.chest.enabled)return[];if(o===this.scale)return e;o=this.scale;e=(this.children||[]).map(e=>{const t=d.generate_hand_parameters();const i=e.radius*o+t.left.offset.x;return{type:"bone",name:e.bone,offset:{x:e.offset[0]*(1-THREE.Math.clamp(o-1,0,1)*.5),y:e.offset[1],z:e.offset[2]*(1+THREE.Math.clamp(o-1,0,2)*.5)},hand_affected:t,auto_scale:false,radius:i,peak_radius:i,peak_barrier:true,is_parent:e.is_parent,z_push:e.z_push,on_hit:d.record_hit}})}})()}}if(!d.waist){const v=s.para.shoulder_width/4;d.waist={get scale(){return Ce.body_collider.waist.size_percent/100},children:[0,-v*.75,-v*1.5].map(e=>{function t(e,t,i){return true}return{bone:"spine",offset:[-v*1,e,-v*.5],radius:v*1.5,line_end:[v*1*2,0,0],z_push:{validate:t,rotation_base:true}}}),generate_colliders:(()=>{let o;let e;return function(){if(!Ce.body_collider.waist.enabled)return[];if(o===this.scale)return e;o=this.scale;e=(this.children||[]).map(e=>{const t=d.generate_hand_parameters();const i=e.radius*o+t.left.offset.x;return{type:"bone",name:e.bone,offset:{x:e.offset[0],y:e.offset[1],z:e.offset[2]},hand_affected:t,magnet_type:"line",line_end:{x:e.line_end[0],y:e.line_end[1],z:e.line_end[2]},auto_scale:false,effective_distance:i,peak_distance:i,peak_barrier:true,is_parent:e.is_parent,use_vector_filter:true,z_push:e.z_push,on_hit:d.record_hit}})}})()}}if(!d.hip){const w=s.get_bone_origin_by_MMD_name("左足")[0];const S=MMD_SA.TEMP_v3.copy(s.para.hip_center_offset).negate();d.hip={get scale(){return Ce.body_collider.hip.size_percent/100},children:[{bone:"下半身|hips",offset:[S.x-w*.5,S.y-w,S.z-w*.5],radius:w*.6,line_end:[w+w*.5*2,0,0],z_push:{validate:()=>true,rotation_base:true}},{bone:"下半身|hips",offset:[S.x-w*.5,S.y-w,S.z],radius:w*1.2,line_end:[w+w*.5*2,0,0]}],generate_colliders:(()=>{let n;let e;return function(){if(!Ce.body_collider.hip.enabled)return[];if(n===this.scale)return e;n=this.scale;e=(this.children||[]).map((e,t)=>{const i=d.generate_hand_parameters();const o=e.radius*n+i.left.offset.x;return{type:"bone",name:e.bone,offset:{x:e.offset[0],y:e.offset[1]-Math.max(n-1,0)*e.radius*.5,z:e.offset[2]},hand_affected:i,magnet_type:"line",line_end:{x:e.line_end[0],y:e.line_end[1],z:e.line_end[2]},auto_scale:false,effective_distance:o,peak_distance:o,peak_barrier:true,is_parent:e.is_parent,use_vector_filter:true,z_push:e.z_push,on_hit:d.record_hit}})}})()}}}window.addEventListener("MMDStarted",()=>{if(MMD_SA_options.is_XR_Animator)I()});const F={};let L;let C;let G;class W{constructor(e,t){this.id=e;this.worker=t}initialized=false}async function Q(){if(H)return;H=true;I();var t=[];if(is_mobile){t.push("use_mobilenet=1")}if(K){t.push("use_holistic=1");e=y=false;pt=ut=true}if(e){t.push("use_human=1");b=true;e=true;y=false;g=false;mt=true;v=true}else if(y){t.push("use_mixed_human=1");e=true;y=true;g=true;v=true}else{e=false;y=false;g=true}if(pt){t.push("use_blazepose=1");ut=true}if(ut){t.push("use_mediapipe=1");if(e){mt=true;v=false}dt=true}if(dt){t.push("use_movenet=1")}if(MMD_SA_options.user_camera.ML_models.worker_disabled&&Fe.initialized&&!Fe.worker_initialized){await new Promise(function(e,t){var i=setInterval(()=>{if(Fe.worker_initialized){clearInterval(i);e()}},100)})}else{await Fe.init()}if(MMD_SA_options.user_camera.ML_models.worker_disabled){L={postMessage:function(e,t){PoseAT.onmessage({data:e})}};let e=document.createElement("script");e.onload=function(){PoseAT.init(L,t)};e.src="js/pose_lib.js";document.head.appendChild(e)}else{G="js/pose_worker.js"+(t.length?"?"+t.join("&"):"");C=Ce.use_holistic?"legacy_holistic":"tasks_vision";console.log("Web worker ID:"+C);L=new Worker(G);F[C]=new W(C,L)}L.onmessage=vt}var yt=function(){let g,b;window.addEventListener("jThree_ready",()=>{g=new System._browser.data_filter([{type:"one_euro",id:"head_rot",para:[30,1,2,1,4]}]);b=new System._browser.data_filter([{type:"one_euro",id:"head_chest_rot",para:[30,.25,.5,1,3]}])});return function(e,t){const i=e.bones_by_name[t];const o=this.skin[t];let n=Math.max(Math.min(o[0].t_delta/o[0].t_delta_frame,1),0);const a=MMD_SA.TEMP_q.set(0,0,0,1);var s=o[0].no_blending?MMD_SA._q2.copy(o[0].rot):MMD_SA._q2.copy(o[1].rot).slerp(o[0].rot,n);if(!i){o[0]._rot_from_pose.copy(s);return}const r=MMD_SA.MMD.motionManager.para_SA;const _=Ce.enabled||r.motion_tracking_upper_body_only;var l=o[0].rot_parent;if(!l){const m=_&&r.motion_tracking?.head_rotation_weight||0;if(m==1){l=new THREE.Quaternion}else{l=MMD_SA.get_bone_rotation_parent(e,t,e).conjugate();if(_)l.premultiply(Ue.copy(this._rot_body_offset).multiply(this._rot_body_camera));if(m)l.slerp(a,m)}}o[0]._rot_parent=l;if(o[0].info[1]=="facemesh"&&this.skin[t+"_DUMMY_"]){let e=Math.min(Math.max(.25-o[0]._rot_ratio,0)*5,1);s.slerp(this.skin[t+"_DUMMY_"][0]._rot_from_pose,e*e*.667);o[0]._rot_mixed=s.clone()}let c=s.toAxisAngle()[1]%(Math.PI*2);if(c>Math.PI)c=Math.PI*2-c;else if(c<0&&c<-Math.PI)c+=Math.PI*2;c=Math.abs(c);n=Ce.use_3D_pose?.5:.3+Math.max(c-Math.PI/2,0)/(Math.PI/2)*.2;var d=Xe.multiplyQuaternions(l,s);d.fromArray(g.filter(d.toArray()));var p=qe.setEulerFromQuaternion(d,"YZX");var u=[p.x<0?n+(.5-n)*.5:n,n,n];d.setFromEuler(Te.fromArray(p.toArray().map((e,t)=>Math.sign(e)*Math.min(Math.abs(e),Math.PI/2)*u[t])),"YZX");if(_){const h=r.motion_tracking;const f=1-(h?.motion_default_weight?.head||0)*this.camera_weight;if(f){const M=Ue.copy(i.quaternion).premultiply(Ke.copy(this._body_motion_rot[0]["首"]).conjugate());i.quaternion.slerp(M,f);M.copy(e.bones_by_name["頭"].quaternion).premultiply(Ke.copy(this._body_motion_rot[0]["頭"]).conjugate());e.bones_by_name["頭"].quaternion.slerp(M,f)}}i.quaternion.multiply(d);e.bones_by_name["頭"].quaternion.premultiply(d);o[0]._rot_neck=i.quaternion.clone();o[0]._rot_head=e.bones_by_name["頭"].quaternion.clone();if(it.active){it.set_boneKey(t,null,i.quaternion,true);it.set_boneKey("頭",null,e.bones_by_name["頭"].quaternion,false)}if(n<.5){const i=e.bones_by_name["上半身2"];const y=Xe.setFromEuler(qe.fromArray(b.filter(qe.setEulerFromQuaternion(s,"YZX").multiply(Te.fromArray(u.map(e=>1-e*2))).toArray())),"YZX");if(!Ce.enabled){tt.add("skin","上半身2",{no_blending:true,rot:y.clone()})}else{i.quaternion.multiply(y)}}}}();var gt=1*10;var $e=function(){var g=[];var o;var L;var C,B,H;window.addEventListener("jThree_ready",()=>{o=new System._browser.data_filter([{type:"one_euro",id:"camera_depth",para:[30,1,1/5,1,1]}]);L=new System._browser.data_filter([{type:"one_euro",id:"camera_distance",para:[30,1,1/5,1,1]}]);$e.v_hip=C=new THREE.Vector3;H=new THREE.Vector3;B=new System._browser.data_filter([{type:"one_euro",id:"v_hip",para:[30,1,1/2,1,3]}])});var O;var i;function e(e){O=null;i=0;var r=e.keypoints[5];var _=e.keypoints[6];var l=e.keypoints[11];var c=e.keypoints[12];if(r.score<=0||_.score<=0)return;let d,p;if(e.keypoints3D_raw){d=e.keypoints3D_raw[11];p=e.keypoints3D_raw[12]}else{d=e.keypoints3D[5];p=e.keypoints3D[6]}g=[{point2D:[{position:new THREE.Vector2},{position:new THREE.Vector2}],data3D:{length:0,z_diff:0}}];const u=Ce.spine_length_ref;var t=je.video_canvas.width;var m=je.video_canvas.height;var h=true;let f=1;if(l.score>0&&c.score>0){h=l.position.y>m||c.position.y>m;let e=MMD_SA._v3a.addVectors(d,p).multiplyScalar(.5);let t=e.length();let i=MMD_SA.TEMP_v3.set(0,1,0);i.y*=-1;let o=MMD_SA._v3b.setEulerFromQuaternion(MMD_SA.TEMP_q.setFromUnitVectors(i,e.normalize()),"ZXY").x;f=Math.abs(o)/(Math.PI/2);f=f<=1?Math.max(f-.5,0)/.5:Math.max(2-f,0);let n=X.copy(l.position).add(c.position).multiplyScalar(.5);let a=U.copy(r.position).add(_.position).multiplyScalar(.5);let s=n.distanceTo(a);a.copy(n);a.y=a.y-s/Math.abs(Math.cos(o));g[0].point2D[0].position.copy(a);g[0].point2D[1].position.copy(n);g[0].data3D.length=u*(t*2)}if(f){let e=MMD_SA._v3b.copy(d).sub(p);let t=e.length();let i=MMD_SA.TEMP_v3.set(1,0,0);let o=MMD_SA._v3b.setEulerFromQuaternion(MMD_SA.TEMP_q.setFromUnitVectors(i,e.normalize()),"ZYX").y;let n=U.copy(r.position).add(_.position).multiplyScalar(.5);let a=n.clone();let s=X.copy(r.position).distanceTo(_.position);const M=1.5;n.y=n.y+s*M/Math.abs(Math.cos(o));O=n.y;if(n.y>je.video_canvas.height){a.y=Math.max(a.y-(n.y-je.video_canvas.height),0);n.y=je.video_canvas.height}if(g[0].data3D.length!=0){let e=Math.abs(o)/(Math.PI/2);e=e<=1?Math.max(e-.5,0)/.5:Math.max(2-e,0);f*=1-e}g[0].point2D[0].position.lerp(a,f);g[0].point2D[1].position.lerp(n,f);g[0].data3D.length=g[0].data3D.length*(1-f)+u*(t*M*2)*f}i=g[0].point2D[1].position.y{h.set((e.point2D[0].position.x/u*2-1)*M,(-(e.point2D[0].position.y/m)*2+1)*y,.5);var t=MMD_SA._v3a.copy(h.unproject(p._camera_reset).sub(p._camera_reset.position).normalize());h.set((e.point2D[1].position.x/u*2-1)*M,(-(e.point2D[1].position.y/m)*2+1)*y,.5);var i=MMD_SA._v3b.copy(h.unproject(p._camera_reset).sub(p._camera_reset.position).normalize());var o,n;o=e.data3D.length;n=e.data3D.z_diff;let a=Math.sqrt(Math.pow(t.x-i.x*t.z/i.z,2)+Math.pow(t.y-i.y*t.z/i.z,2)+0);let s=t.x-i.x*t.z/i.z+(t.y-i.y*t.z/i.z)+0;let r=s/a;let _=1;let l=(Math.sqrt(o*o+1)-1)/(a/r);t.multiplyScalar(l);let c=2*Math.tan(Math.PI/180*MMD_SA.THREEX.camera.obj.fov/2)/.9326153163099972;c=1+(c-1)*.5;let d=c*Ce.hip_depth_scale_percent/100;f.push({z:-t.z*1.5*d,id:e.id})});f.sort((e,t)=>t.z-e.z);var i=f[0].z;this.z=i;z=o.filter(i);this.z_smoothed=z;g=[]}var q;function n(e){if(MMD_SA.WebXR.session){C.set(0,0,0);return}H.copy(C);const F=MMD_SA.MMD.motionManager.para_SA;const t=je.video_canvas.width;const i=je.video_canvas.height;const o=e.keypoints[11];const n=e.keypoints[12];const a=e.keypoints[5];const s=e.keypoints[6];const r=a.score>0&&s.score>0?X.copy(a.position).add(s.position).multiplyScalar(.5):null;const _=t/i;const l=SL.width/SL.height;const c=_0&&n.score>0){p=U.copy(o.position).add(n.position).multiplyScalar(.5);const T=p.x;const I=p.y;u=1;if(r){if(I<0||I>i){u=1-Math.min((I<0?-I:I-i)/Math.abs(r.y-I),1)}if(T<0||T>t){u=Math.min(u,1-Math.min((T<0?-T:T-t)/Math.abs(r.x-T),1))}u=Math.max(u-.5,0)/.5}C.set(((o.position.x+n.position.x)/2/t*2-1)*c,(-((o.position.y+n.position.y)/2/i)*2+1)*d,.5).unproject(je._camera_reset).sub(je._camera_reset.position).normalize()}let m;if(u<1){m=Ie.set(((a.position.x+s.position.x)/2/t*2-1)*c,(-((a.position.y+s.position.y)/2/i)*2+1)*d,.5).unproject(je._camera_reset).sub(je._camera_reset.position).normalize()}if(gt)$e.estimate();const h=je._camera_reset.position.z-THREE.MMD.getModels()[0].mesh.position.z;let f=h;if(gt&&$e.z)f=$e.z_smoothed||$e.z;const M=MMD_SA.THREEX.get_model(0).para.spine_length;const y=.95;let g=u;if(g==0&&O){const I=O;if(I>i){g=1-Math.min((I<0?-I:I-i)/Math.abs(r.y-I),1);g=Math.max(g-.5,0)/.5}}let b=g+(1-g)*y;L.filter(b);f*=b;if(u>0)C.multiplyScalar(-f/C.z);if(m){const z=Ce.spine_length_ref;const j=MMD_SA.TEMP_v3.set(0,-z,0);C.lerp(m.multiplyScalar(-f/m.z).add(j),1-u)}let v=MMD_SA.THREEX.get_model(0).para.left_leg_length/10.569580078125;const w=v>1?1:Math.pow(1/v,.75);let S=Ce.hip_depth_scale_percent/100;let A;if(w*S>1){q=w*S;A=1/S}else{q=1;A=w}C.multiply(MMD_SA.TEMP_v3.set(A,A,w));if(isNaN(C.x)||isNaN(C.y)||isNaN(C.z)){console.error("(Invalid v_hip)");C.copy(H);return}let D=1;C.z=Je("v_hip_z",C.z,!!Ce._upper_body_only_mode);const E=B.filters[0].filter;const k=Math.min(Math.max(M/4.97462,1),Math.max(MMD_SA.THREEX.get_model(0).para.left_leg_length/10.569580078125,1));const x=k*10;const P=Math.max(Math.abs(C.z)-x,0)/x*D;let R=Ce._upper_body_only_mode?.2:.2+P*.8;E.minCutOff=Math.min(R,10);E.beta=Math.min(R*(Ce._upper_body_only_mode?1/k:1),1);E.dCutOff=Math.min(R,1);C.fromArray(B.filter(C.toArray()))}return{prepare:e,estimate:t,get_hip_center:n,get z_scale_base(){return q},get grounding_factor(){return i}}}();var w=(()=>{function k(e,t,i,o,n){function a(e){return e*e}const s=Math.sqrt;var r=1+a(o);var _=-t*2+o*(n-i)*2;var l=a(t)+a(n-i)-a(e);var c=a(_)-4*r*l;if(c>=0){var d=[(-_+s(a(_)-4*r*l))/(2*r),(-_-s(a(_)-4*r*l))/(2*r)];if(c==0){return[d[0]]}return d}return[]}var x,P,R;var T;var I,z;window.addEventListener("jThree_ready",()=>{x=new THREE.Vector3;P=new THREE.Vector3;R=new THREE.Vector3;T=new THREE.Quaternion;I=new THREE.Plane;z=new THREE.Plane});return function(e,t,i){const o=e._elbow_y;const n=MMD_SA.get_bone_position(t,i+"ひじ",t);if(n.y>o)return;const a=MMD_SA.get_bone_position(t,i+"手首",t);const s=MMD_SA.get_bone_position(t,i+"腕",t);const r=s;const _=R.copy(a).sub(r);const l=n;const c=(l.x*_.x+l.y*_.y+l.z*_.z-(r.x*_.x+r.y*_.y+r.z*_.z))/_.lengthSq();const d=MMD_SA._v3b.set(r.x+_.x*c,r.y+_.y*c,r.z+_.z*c);const p=_.normalize();const u=P.copy(n).sub(d).normalize().negate();const m=x.crossVectors(p,u).normalize();I.setFromNormalAndCoplanarPoint(p,n);z.setFromNormalAndCoplanarPoint(MMD_SA.TEMP_v3.set(0,1,0),MMD_SA._v3a.set(0,o,0));const h=I.intersectPlane(z);if(!h)return;Ge.set(p.x,p.y,p.z,0,u.x,u.y,u.z,0,m.x,m.y,m.z,0,0,0,0,1);We.setFromBasis(Ge);const f=MMD_SA.TEMP_v3.copy(n).sub(d).length();let M=z.intersectLine(new THREE.Line3(n,d),R);if(!M)return;M=-M.sub(n).length();h[1].applyQuaternion(We);const y=h[1].y/h[1].z;n.sub(s);n.applyQuaternion(We);const g=k(f,n.z,n.y,y,M);if(!g.length)return;const b=g.map(e=>{e-=n.z;return Math.asin(e/f)});const v=i=="左"?1:-1;const w=MMD_SA.get_bone_rotation(t,"上半身2",null,t);const S=T.copy(w).conjugate();const A=P.copy(a).sub(s).normalize().applyQuaternion(S);const D=e.use_smallest_angle?b.sort((e,t)=>Math.abs(e)-Math.abs(t))[0]:b[v==-1?b.length-1:0];const E=MMD_SA.TEMP_q.setFromAxisAngle(A,D);t.bones_by_name[i+"腕"].quaternion.premultiply(E)}})();var bt=(()=>{let l;let t;window.addEventListener("jThree_ready",()=>{t=new THREE.Vector3;l=new System._browser.data_filter([{type:"one_euro",id:"z_lean",para:[30,.5,.5,1,1]}])});return function(a,e){const s=MMD_SA.MMD.motionManager.para_SA;let r=Je("lean",e?1:0,e);if(!r)return;if(Fe.enabled&&Fe.lean_tracking&&Fe.face_width_average&&Fe.face_width_average>.075){let o=0;o+=(2-(Fe.lean_tracking-1))/2;let n=Fe.face_width/Math.max(je.video_canvas.width,je.video_canvas.height);const _=Fe.face_width_average*(1.1+.1*o);if(n>_){let t=!Ce.enabled||s.motion_tracking_upper_body_only?1:.5;let i=Math.sqrt(a.x*a.x+a.y*a.y);if(a.z*t10){a.z=0}else{a.normalize();t.set(0,a.y,a.z).normalize();a.z*=Math.pow(Math.abs(t.z)/2,s.motion_tracking.lean_reduction_power)*2/Math.abs(t.z)}}}})();const Je=(()=>{let a={};return function(e,i,t){if(!e){a={};return}let o=a[e];if(!o){o=a[e]={};switch(e){case"lean":o.type=1;o.duration=500;break;case"hip_angle_x":o.type=1;o.duration=1e3;break;case"v_hip_z":o.type=1;o.duration=500;break;case"hip":o.type=3;o.duration=1e3;o.v=new THREE.Vector3;o.v_to_lerp=new THREE.Vector3;break}}const n=o.type;if(o.state==null){o.timestamp=o.duration;if(n==1){o.v=o.v_to_lerp=i}else if(n>=3){o.v.copy(i);o.v_to_lerp.copy(i)}}else if(o.state===t){let e=RAF_timestamp-(o._timestamp||RAF_timestamp);o.timestamp=Math.min(o.timestamp+e,o.duration);let t=1-o.timestamp/o.duration;if(o.type==1){if(t)i=i*(1-t)+o.v_to_lerp*t;o.v=i}else if(o.type==3){if(t)i.lerp(o.v_to_lerp,t);o.v.copy(i)}else if(o.type==4){if(t)i.slerp(o.v_to_lerp,t);o.v.copy(i)}}else{o.timestamp=0;if(n==1){i=o.v;o.v_to_lerp=i}else if(n>=3){i.copy(o.v);o.v_to_lerp.copy(i)}}o._timestamp=RAF_timestamp;o.state=t;return i}})();const et=[0,0,0];var vt=function(){function we(e,t){let i=Ye[t];e.premultiply(i.axis_rot).multiply(i.axis_rot_inv);e.multiplyQuaternions(i.axis_rot_offset_inv,e)}function G(e,t){if(Ce.IK_disabled_check(t))return;var i=e.bones_by_name[t];var o=this.skin[t];var n=t.charAt(0);var a=MMD_SA.TEMP_v3.fromArray(e.bones_by_name[n+"足"].pmxBone.origin);var s=MMD_SA.get_bone_position(e,n+"足","全ての親").sub(a);i.position.add(s);e.bones_by_name[n+"ひざ"].quaternion.set(0,0,0,1);if(it.active){if(MMD_SA_options.user_camera.ML_models.pose.use_legIK){const r=MMD_SA.TEMP_v3.copy(i.position);r.sub(qe.fromArray(e.bones_by_name[t].pmxBone.origin).sub(Te.fromArray(e.bones_by_name[t].parent?.pmxBone?.origin||[0,0,0])));it.set_boneKey(t,r,o[0].rot?i.quaternion:null,true)}window.addEventListener("SA_MMD_model"+e._model_index+"_process_bones_after_IK",()=>{it.set_boneKey(n+"足",null,e.bones_by_name[n+"足"].quaternion,false);it.set_boneKey(n+"ひざ",null,e.bones_by_name[n+"ひざ"].quaternion,false)},{once:true})}i.quaternion.set(0,0,0,1)}function Se(e,t){const i=t.charAt(0);const o=e.bones_by_name;const n=o[t].quaternion;a.call(this,e,t);if(MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only)n.premultiply(rt)}function Ae(e,t){const i=this.skin[t];if(!i._IK_disabled)e.bones_by_name[t].quaternion.set(0,0,0,1)}function a(e,t){const i=t.charAt(0);const o=e.bones_by_name;const n=o[t].quaternion;const a=this.skin[i+"肩"];if(a){let e=Math.max(Math.min(a[0].t_delta/a[0].t_delta_frame,1),0);n.premultiply(MMD_SA.TEMP_q.copy(a[1].rot).slerp(a[0].rot,e).conjugate())}}var W=(()=>{var f;var M;window.addEventListener("jThree_ready",()=>{f=new THREE.Vector3;M=new System._browser.data_filter([{type:"one_euro",id:"grounding_y",para:[30,1,1,1,1]}])});return function(n,e){var t=n.bones_by_name[e];var i=this.skin[e];var o=Math.max(Math.min(i[0].t_delta/i[0].t_delta_frame,1),0);const a=MMD_SA.THREEX.get_model(0);const s=MMD_SA.MMD.motionManager.para_SA;const r=qe.copy($e.v_hip);if(MMD_SA.WebXR.session){r.set(0,0,0)}else{const h=je._camera_reset.position.z-n.position.z;r.z=MMD_SA_options.user_camera.ML_models.pose.estimate_z_depth===false?0:h+r.z}if(MMD_SA_options.user_camera.ML_models.pose.position_offset)r.add(MMD_SA_options.user_camera.ML_models.pose.position_offset);i[0].pos.copy(r);f.copy(i[1].pos).lerp(i[0].pos,o);let _=Te.set(0,0,0);let l=Math.max(a.para.left_leg_length/MMD_SA_options.model_para_obj.left_leg_length,1);let c,d;if(!MMD_SA.THREEX.enabled||s.motion_tracking_upper_body_only){c=MMD_SA.get_bone_position(n,"左足","全ての親");d=MMD_SA.get_bone_position(n,"右足","全ての親");_.copy(c).add(d).multiplyScalar(.5).sub(MMD_SA_options.model_para_obj.hip_center).negate();_.multiplyScalar(l)}else{c=a.get_bone_position_by_MMD_name("左足",true);d=a.get_bone_position_by_MMD_name("右足",true);let e=a.get_bone_position_by_MMD_name("センター",true).sub(a.para.hip_center_offset);_.copy(c).add(d).multiplyScalar(.5).sub(e).negate()}if(s.motion_tracking_upper_body_only)f.y/=$e.z_scale_base;let p=a.para.hip_center.y+a.para.spine_length/2-(11.364640235900879+4.97462/2);p*=.75;if(p<0)p*=.85;if(!s.motion_tracking_upper_body_only){f.y-=p*.5}f.z+=Ce.hip_z_position_offset_percent/100*a.para.left_leg_length*2;f.y+=Ce.hip_y_position_offset_percent/100*a.para.left_leg_length;if(Ce.auto_grounding&&!s.motion_tracking_upper_body_only){let e,t;e=a.get_bone_position_by_MMD_name("左足首",true);t=a.get_bone_position_by_MMD_name("右足首",true);let i=e.y0){THREE.MMD.getModels()[n._model_index].resetPhysics(15+m*2/u)}q.copy(f)}})();var Q=(()=>{const L=(()=>{const s={};let r,_;window.addEventListener("jThree_ready",()=>{r=new THREE.Vector3;_=new THREE.Quaternion});return function(e,t,i){const o=e.magnet_id||e.name;let n=s[o];if(!n){n=s[o]={};for(const a of["左","右"])n[a]={vector:new THREE.Vector3,f:new System._browser.data_filter([{type:"one_euro",id:"magnet_vector",para:[30,.5,.5,1,4]}])}}n=n[t];_.setFromUnitVectors(r.set(0,0,1),i);_.fromArray(n.f.filter(_.toArray()));return n.vector.set(0,0,1).applyQuaternion(_)}})();const o={};function n(e){if(!e.keep_validation_state_until_reset)return null;const t=e.magnet_id||e.name;let i=o[t];if(!i){i=o[t]={}}return i}function C(e,t){const i=n(e);return i?i[t]!==false:true}function B(e,t,i){const o=n(e);if(o)o[t]=i}const H=(()=>{const s={};return function(e,t,i){if(!e.use_reference_point_filter)return i;const o=e.magnet_id||e.name;let n=s[o];if(!n){n=s[o]={};for(const a of["左","右"])n[a]=new System._browser.data_filter([{type:"one_euro",id:"reference_point_filter",para:[30,.5,.5,1,3]}])}n=n[t];return i.fromArray(n.filter(i.toArray()))}})();const O=(()=>{const n={};window.addEventListener("jThree_ready",()=>{for(const e of["左","右"]){n["_"+e+"_"]={};n[e]={f:new System._browser.data_filter([{type:"one_euro",id:"magnet_offset_rot",para:[30,1,1,1,4]}])}}});return function(e,t){const i=n[t?e:"_"+e+"_"];if(i.timestamp!=RAF_timestamp){const o=U.get_bone_rotation_by_MMD_name(e+"手首",true);i.rot=t?o.fromArray(i.f.filter(o.toArray())):o}i.timestamp=RAF_timestamp;return i.rot}})();function q(e,t,i,o){const n=i.x;const a=i.y;const s=i.z;const r=e.x;const _=e.y;const l=e.z;const c=t.x-r;const d=t.y-_;const p=t.z-l;let u=c*c+d*d+p*p;let m=2*(r*c+_*d+l*p-c*n-d*a-p*s);let h=r*r-2*r*n+n*n+_*_-2*_*a+a*a+l*l-2*l*s+s*s-o*o;let f=m*m-4*u*h;let M=(-m-Math.sqrt(f))/(2*u);const y=[e.x*(1-M)+M*t.x,e.y*(1-M)+M*t.y,e.z*(1-M)+M*t.z];let g=(-m+Math.sqrt(f))/(2*u);const b=[e.x*(1-g)+g*t.x,e.y*(1-g)+g*t.y,e.z*(1-g)+g*t.z];if(f<0||M>1||g>1){return[]}else if(f==0){return[y]}else{return[y,b]}}let X,U;return function(D,E,i,e){function t(e,t,i,o){if(typeof e=="number")return Ce.auto_scale_property(e,D,o);if(/^(\w+)([\+\-])([\d\.])$/.test(e)){const n=Ce.auto_scale_property((RegExp.$2=="+"?1:-1)*parseFloat(RegExp.$3),D,o);const a=MMD_SA.TEMP_v3.copy(E);const s=RegExp.$1;if(s=="default"){a.copy(tt._skin[D].pos).sub(D.indexOf("腕")!=-1?MMD_SA_options.model_para_obj.arm_IK_offset[k]:MMD_SA_options.model_para_obj.leg_IK_offset[k]).applyQuaternion(tt._skin[D].rot_parent_inv)}else if(s=="elbow"){if(t=="y"){const r=_?.motion_tracking?.arm_tracking?.elbow_lock?.[k=="左"?"left":"right"]?._elbow_y;if(r!=null&&r!=0){a.y=r-MMD_SA.get_bone_position(P,k+"腕",P).y}}}return(a[t]+n)/i}return 0}const k=D.charAt(0);const o=D.indexOf("足")==-1?MMD_SA_options.model_para_obj.left_arm_length:MMD_SA_options.model_para_obj.left_leg_length;const x=k=="左"?"left":"right";X=THREE.MMD.getModels()[0];U=MMD_SA.THREEX.get_model(0);const P=X.mesh;const _=MMD_SA.motion[X.skin._motion_index].para_SA;let n;if(i){for(const c of["x","y","z"]){const d=i[c];if(!d)continue;const s=d.unit_length||o;let e=!MMD_SA.THREEX.enabled&&d.unit_length?d.auto_scale:false;if(d.scale!=null)E[c]*=typeof d.scale?.[x]=="number"&&d.scale[x]||d.scale;if(d.add)E[c]+=t(d.add?.[x]||d.add,c,s,e)*s;if(d.min!=null)E[c]=Math.max(E[c],t(d.min?.[x]||d.min,c,s,e)*s);if(d.max!=null)E[c]=Math.min(E[c],t(d.max?.[x]||d.max,c,s,e)*s)}if(i.rotation)E.applyEuler(MMD_SA.TEMP_v3.copy(i.rotation).multiplyScalar(Math.PI/180));if(i.camera_weight&&D.indexOf("腕")==-1)E.applyQuaternion(MMD_SA.TEMP_q.set(0,0,0,1).slerp(tt._rot_camera,i.camera_weight));const l=i.position_to_rotation;if(l){const p=P.bones_by_name;const u=Ie.set(Math.atan2(E.z,E.y),0,-Math.atan2(E.x,E.z));const m={upper:{q:Xe},lower:{q:Ue}};for(const v of["upper","lower"]){const w=k+(v=="upper"?"足":"ひざ");const S=p[w];m[v].name=w;m[v].q.copy(S.quaternion);S.quaternion.set(0,0,0,1);if(!l[v])continue;const A=ze.set(0,0,0);for(const c of["x","y","z"]){const d=l[v][c];if(!d)continue;let e=0;const T=d.rot_formula?.[x]||d.rot_formula;if(T?.length==1){e=u[T]*180/Math.PI}if(d.add)e+=d.add?.[x]||d.add;if(d.scale!=null)e*=typeof d.scale?.[x]=="number"&&d.scale[x]||d.scale;if(d.curve){const I=d.curve?.[x]||d.curve;const z=(e-I.ini)/(I.end-I.ini);if(z>0&&z<1)e=Math.pow(z,I.pow_factor)*(I.end-I.ini)+I.ini}if(d.min!=null)e=Math.max(e,d.min?.[x]||d.min);if(d.max!=null)e=Math.min(e,d.max?.[x]||d.max);A[c]=e/180*Math.PI}S.quaternion.setFromEuler(A,"XZY");if(v=="upper")n=S.quaternion.clone()}const h=MMD_SA.get_bone_position(P,k+"足","全ての親");const f=MMD_SA.get_bone_position(P,k+"足首","全ての親");const M=je.x_flipped?-1:1;const y=Ie.fromArray(p[k+"足"].pmxBone.origin);const g=y.sub(h).negate();const b=h.sub(f);b.x*=M;b.y*=-1;b.z*=-1;b.add(MMD_SA_options.model_para_obj.leg_IK_offset[k]);b.add(g);b.y-=MMD_SA_options.model_para_obj.left_leg_IK[1]+(p["センター"].position.y-p["センター"].pmxBone.origin[1]);E.copy(b);for(const v in m)p[m[v].name].quaternion.copy(m[v].q)}}else{if(e)e(E)}const a=E.length();E.normalize().multiplyScalar(a*(typeof i?.length?.scale=="number"?i?.length?.scale:i?.length?.scale?.[x]||1));let R;i?.magnet?.forEach(i=>{if(i.is_parent){R={name:i.name}}else if(R&&!i.is_parent&&R.name==i.name&&!R.vector){return}const t=i.hand_affected[x];if(!t)return;if(!tt.skin[D]?.[0]._hand_visible)return;let o=MMD_SA._v3a.set(0,0,0);let n;let a=MMD_SA._q1.set(0,0,0,1);let s,r;if(i.type=="object3D"){s=MMD_SA.THREEX._XR_Animator_scene_?.object3D_list.find(e=>e.id==i.id);if(!s)return;r=MMD_SA.THREEX._object3d_list_.find(e=>e.uuid==s._object3d_uuid);o.copy(i.reference_point).multiply(r._mesh.scale);a=MMD_SA._q1.copy(P.quaternion).conjugate().multiply(i.use_default_rotation&&r.user_data._rot_default_||r._mesh.quaternion);o.applyQuaternion(a);n=MMD_SA._v3b.copy(r._mesh.position).sub(P.position).applyQuaternion(MMD_SA.TEMP_q.copy(P.quaternion).conjugate());o.add(n)}else if(i.type=="bone"){let t;i.name.split("|").some(e=>{t=MMD_SA.THREEX.VRM.bone_map_VRM_to_MMD[e]||!MMD_SA.THREEX.enabled&&e;return t});o=U.get_bone_position_by_MMD_name(t,true);if(i.offset){a=U.get_bone_rotation_by_MMD_name(t,true);o.add(MMD_SA._v3a.copy(i.offset).applyQuaternion(a))}}else{o.copy(i.position)}const _=U.get_bone_position_by_MMD_name(D.substring(0,2),true);o.sub(_);let l=1;if(MMD_SA.THREEX.enabled){l=MMD_SA_options.model_para_obj.left_arm_length/U.para.left_arm_length;o.multiplyScalar(l)}let e=MMD_SA._v3a_.set(0,0,0);if(t.offset){if(t.offset=="parent_bone"){pb=MMD_SA.THREEX._object3d_list_.find(e=>e.parent_bone?.name==k+"手首"&&!e.parent_bone.disabled)?.parent_bone;if(pb){e.fromArray(Ce.auto_scale_property([pb.position.x,pb.position.y,-pb.position.z],"手首",MMD_SA.THREEX.enabled?false:t.auto_scale))}else{pb=s?.model_para?.parent_bone?.rotation?.align_with_external_point?.external_point?.offset;if(pb){e.fromArray(Ce.auto_scale_property([pb.x,pb.y,pb.z],"手首",MMD_SA.THREEX.enabled?false:t.auto_scale));if(!U.is_T_pose)e.applyQuaternion(MMD_SA_options.model_para_obj.rot_arm_adjust[k+"腕"].axis_rot)}}}else{e.copy(t.offset);if(!U.is_T_pose)e.applyQuaternion(MMD_SA_options.model_para_obj.rot_arm_adjust[k+"腕"].axis_rot)}e.applyQuaternion(O(k,t.offset.use_filter))}E.add(e);const c=MMD_SA.THREEX.enabled||i.auto_scale===false?false:.9;let d=0;let p;if(i.magnet_type=="line"){const u=MMD_SA.THREEX.l1;u.start.copy(o);if(i.type=="object3D"){if(i.line_end){u.end.copy(i.line_end).multiply(r._mesh.scale).applyQuaternion(a);u.end.add(n)}else{u.end.copy(n||MMD_SA.TEMP_v3.set(0,0,0))}u.end.sub(_).multiplyScalar(l)}else if(i.type=="bone"){u.end.copy(i.line_end).applyQuaternion(a).multiplyScalar(l).add(o)}if(i.line_offset){const m=MMD_SA.TEMP_v3.copy(i.line_offset).multiply(r._mesh.scale).applyQuaternion(a).multiplyScalar(l);u.start.add(m);u.end.add(m)}u.closestPointToPoint(E,true,o);let e=E.distanceTo(o);let t=Ce.auto_scale_property(i.effective_distance,"腕",c);if(e-9?Math.pow(d,1-i.power):0}}}else if(i.magnet_type=="plane"){const h=MMD_SA.TEMP_v3.copy(i.plane_normal);if(!i.plane_normal.absolute)h.applyQuaternion(a);const f=MMD_SA.THREEX.p1.setFromNormalAndCoplanarPoint(h,o);const u=MMD_SA.THREEX.l1;u.start.copy(E);u.end.copy(MMD_SA.TEMP_v3.copy(f.normal).multiplyScalar(999).add(E));let t=f.intersectsLine(u);if(t&&!i.plane_crossable){d=1}else{if(!t)u.end.sub(E).negate().add(E);const y=f.distanceToPoint(E);let e=Ce.auto_scale_property(i.effective_distance,"腕",c);if(y-9?Math.pow(d,1-i.power):0}}const M=MMD_SA.THREEX.v1;f.intersectLine(u,M);o.copy(M)}else{const y=E.distanceTo(o);let e=Ce.auto_scale_property(i.radius,"腕",c);if(y-9?Math.pow(d,1-i.power):0}}}if(d){if(p){const g=R&&!i.is_parent&&R.name==i.name?ze.copy(R.vector):ze.copy(E).sub(o).normalize();if(i.z_push){if(d==1){const b=C(i,k)&&(i.z_push.rotation_base?i.z_push.rotation_base===true?a:U.get_bone_rotation_by_MMD_name(i.z_push.rotation_base,true):null);if(i.z_push.validate?i.z_push.validate(E,g,b):(b?g.dot(MMD_SA.TEMP_v3.set(0,0,1).applyQuaternion(b)):g.z)>-0){_dir=Ie.set(0,0,999);if(b)_dir.applyQuaternion(b);linePoint0=MMD_SA._v3b_.copy(E).add(_dir);linePoint1=_dir.negate().add(E);const v=o;const w=p;let e=q(linePoint0,linePoint1,v,w).sort((e,t)=>t[2]-e[2]);o.fromArray(e[0]);const S=tt.skin[k+"手首"]?.[0].rot;if(S){const A=MMD_SA.TEMP_v3.set(1,0,0);if(b)A.applyQuaternion(b);A.applyQuaternion(S);_dir.set(0,0,1);if(b)_dir.applyQuaternion(b);o.add(_dir.multiplyScalar(t.offset.z*Math.abs(A.z)))}i.on_hit&&i.on_hit(i,k)}else{d=0}B(i,k,!!d)}else{d=0;B(i,k,null)}}else{let e;if(i.is_parent||i.use_vector_filter){e=L(i,k,g);g.copy(e)}o.add(g.multiplyScalar(p));if(i.is_parent){R.vector=e;d=0}if(d){i.on_hit&&i.on_hit(i,k)}}}E.add(H(i,k,MMD_SA.TEMP_v3.set(0,0,0).lerp(o.sub(E),d)))}else{H(i,k,MMD_SA.TEMP_v3.set(0,0,0));B(i,k,null)}i._frame_count_=EV_sync_update.count_frame;i._weight_=d;E.sub(e)});let s=E.length();for(const j of["max","min"]){const F="length_"+j;let e,t=o;if(i?.[F]||i?.length){if(typeof i[F]=="number"){e=i[F]}else{e=i.length[j];if(e==null)continue;if(typeof e!="number"){e=e[x];if(e==null)continue}if(i.length.unit_length)t=i.length.unit_length}}else{continue}if(j=="max"){if(s>t*e)s=t*e}else{if(s{const q={};const X={};window.addEventListener("jThree_ready",()=>{for(const e of["左","右"]){q[e]=new System._browser.data_filter([{type:"one_euro",id:"armIK",para:[30,1,1/5,1,3]}]);X[e]=new System._browser.data_filter([{type:"one_euro",id:"pos0_offset",para:[30,1,1,1,3]}])}});return function(i,e){if(Ce.IK_disabled_check(e))return;let t=i.bones_by_name[e];let o=this.skin[e];let n=Math.max(Math.min(o[0].t_delta/o[0].t_delta_frame,1),0);let a=qe.copy(o[1].pos).lerp(o[0].pos,n);const s=e.charAt(0);const r=MMD_SA.MMD.motionManager.para_SA;const L=s=="左"?"left":"right";let _=r?.motion_tracking?.arm_tracking?.transformation;let l=_?.position?.magnet;const c=MMD_SA_options.model_para_obj.colliders_for_hands;const d=c.left_hand.children[0].offset;const p=.5;const C={left:{offset:{x:d[0]*p,y:d[1]*p,z:d[2]*p}},right:{offset:{x:-d[0]*p,y:d[1]*p,z:d[2]*p}}};let u;if(Ce.body_collider.active){u=[];u=u.concat(c.head?.generate_colliders()||[]);u=u.concat(c.chest?.generate_colliders()||[]);u=u.concat(c.waist?.generate_colliders()||[]);u=u.concat(c.hip?.generate_colliders()||[])}if(!_&&u)_={position:{}};if(_&&u){if(!_.position)_.position={};_.position.magnet=u.concat(l||[])}const m=MMD_SA.get_bone_rotation_parent(i,e,i);let h=!o[0]._IK_absolute?this.offset_upper_body_camera_rotation(Xe.copy(m).conjugate(),r?.motion_tracking?.arm_tracking?.transformation?.position?.camera_weight||1):null;let f=st.set(0,0,0,1);if(_){const v=_.position;Q(s+"腕IK",a,v);let t=_.root_rotation?.[L];if(t){const w=s+"腕";f.setFromEuler(MMD_SA.TEMP_v3.set(t.x,t.y,t.z).multiplyScalar(Math.PI/180),t.order);let e=Ye[w];f.premultiply(e.axis_rot).multiply(e.axis_rot_inv);i.bones_by_name[w].quaternion.multiply(f)}if(_.position)_.position.magnet=l}if(o[0].data_filter||o[1].data_filter){a.fromArray(q[s].filter(a.toArray()))}if(h)a.applyQuaternion(h);const M=Ce._arm_IK_adjust?.[s];if(M){const S=MMD_SA_options.model_para_obj.left_arm_length;const A=["x","y","z"];if(M.add){if(typeof M.min=="number"){}else{for(const b of A){if(M.add[b]!=null){a[b]+=M.add[b]*S}}}}if(M.min){if(typeof M.min=="number"){}else{for(const b of A){if(M.min[b]!=null){if(a[b]b.target_radius){const O=j.sub(b.target).add(F.normalize().multiplyScalar(b.target_radius));a.sub(O.applyQuaternion(m.conjugate()))}}a.add(MMD_SA_options.model_para_obj.arm_IK_offset[s]);t.position.copy(a)}})();var De=function(){let D={};let E={};window.addEventListener("jThree_ready",()=>{for(const t of["左","右"]){D[t]=new System._browser.data_filter([{type:"one_euro",para:[30,.3,.3,.3,3]}]);E[t]=[];for(let e=0;e<5;e++){E[t][e]=new System._browser.data_filter([{type:"one_euro",para:[30,1,1,1,1]}])}}});return function(n,e){var t=THREE.MMD.getModels()[n._model_index];var i=n.bones_by_name[e];var a=e.charAt(0);var o=i.quaternion;const s=this.skin[e];const r=Math.max(Math.min(s[0].t_delta/s[0].t_delta_frame,1),0);o.copy(s[1].rot).slerp(s[0].rot,r);const _="YXZ";const l=MMD_SA.TEMP_v3.setEulerFromQuaternion(o,_);const c=MMD_SA.MMD.motionManager.para_SA.motion_tracking.arm_as_leg.transformation?.rotation||{};let d=Math.sign(l.y)*Math.min(Math.abs(l.y*(c.y?.scale||1)),Math.PI/2.5)+(c.y?.add||0)*Math.PI/180;const p=c.y?.foot_ratio||.25;l.y=d*p;l.z=Math.sign(l.z)*Math.min(Math.abs(l.z*(c.z?.scale||.5)),Math.PI/4);l.x*=c.x?.scale||.4;let u=[];let m=0;let h;if(s[0]._finger_x){if(s[1]._finger_x){h=s[0]._finger_x.map((e,t)=>e*r+s[1]._finger_x[t]*(1-r))}else{h=s[0]._finger_x}}if(h){for(let e=0;e<5;e++)u[e]=E[a][e].filter(h[e]);u[0]=(u[0]+u[1])/2;u.forEach(e=>{m+=e});m/=5;l.x-=m}l.x=Math.sign(l.x)*Math.min(Math.abs(l.x),Math.PI/2.5);l.fromArray(D[a].filter(l.toArray()));d=l.y/p;o.setFromEuler(l,_);this._rot_=o.clone();this._rot_y=d;const f=this.get_blend_default_motion("skin",a+"足IK",true);if(f)d*=1-f;const M=MMD_SA.get_bone_position(n,a+"足",n);const y=MMD_SA.get_bone_rotation_parent(n,a+"足",n).conjugate();const g=MMD_SA.get_bone_position(n,e,n).sub(M).negate().normalize().applyQuaternion(y);const b=MMD_SA.TEMP_q.setFromAxisAngle(g,d*(1-p));if(0&&n.bones_by_name[a+"足D"]){n.bones_by_name[a+"足"].quaternion.premultiply(b);n.bones_by_name[a+"足D"].quaternion.premultiply(b)}else{t._update_IK_and_AddTrans(false,a+"足","下半身",true);if(this.skin[a+"足"]&&this.skin[a+"足"][0]._rot_){n.bones_by_name[a+"足"].quaternion.copy(this.skin[a+"足"][0]._rot_)}else{const v=MMD_SA.get_bone_position(n,a+"ひざ",n).sub(M).negate().normalize().applyQuaternion(y);const w=Xe.setFromUnitVectors(qe.set(0,1,0),g);n.bones_by_name[a+"足"].quaternion.copy(w).multiply(Ue.setFromEuler(qe.set(-v.angleTo(g),0,0)))}n.bones_by_name[a+"足"].quaternion.premultiply(b);t._update_IK_and_AddTrans(false,a+"足","下半身")}if(m&&n.bones_by_name[a+"足先EX"]){const e=a+"足人指";const S=!MMD_SA.MMD.motionManager.para_SA.motion_tracking.arm_as_leg.toes_disabled&&(n.bones_by_name[e]||n.bones_by_name[e+Ve[1]]);if(!S){let t=0;for(let e=1;e<4;e++){t+=u[e]}t/=4;const A=(u[1]-t)/2;n.bones_by_name[a+"足先EX"].quaternion.setFromEuler(qe.set(-m*.5,0,A),"XZY")}else{n.bones_by_name[a+"足先EX"].quaternion.setFromEuler(qe.set(-m*.5,0,0))}t._update_IK_and_AddTrans(false,a+"足先EX")}if(h){Qe.forEach((e,t)=>{const i=a+"足"+e+"指";const o=n.bones_by_name[i]||n.bones_by_name[i+Ve[1]];if(o)o.quaternion.multiply(Xe.setFromEuler(qe.set(-u[t]*.5,0,0)))})}}}();var N=function(){let E={};window.addEventListener("jThree_ready",()=>{for(const e of["左","右"]){E[e]=new System._browser.data_filter([{type:"one_euro",id:"hand_rot_filter",para:[30,1,1,1,4]}])}});const k={"左":{},"右":{}};return function(e,t){var i=THREE.MMD.getModels()[e._model_index];const o=MMD_SA.THREEX.get_model(e._model_index);var n=o.is_T_pose;const a=e.bones_by_name[t];const s=t.charAt(0);const r=s=="左"?"left":"right";var _,l,c,d;var p=e.bones_by_name[s+"手捩"];var u;var m=this.skin[t];var h=Math.max(Math.min(m[0].t_delta/m[0].t_delta_frame,1),0);const f=MMD_SA.motion[i.skin._motion_index].para_SA;l=Xe.set(0,0,0,1);if(p){if(p.quaternion.x||p.quaternion.y||p.quaternion.z){p.quaternion.conjugate();i._update_IK_and_AddTrans(false,s+"手捩")}p.quaternion.set(0,0,0,1)}const M=s=="左"?1:-1;var y=m[0].rot_parent;if(!y){y=MMD_SA.get_bone_rotation(e,"上半身2",null,e);y.premultiply(Ue.copy(this._rot_body_offset).multiply(this._rot_camera).conjugate());y.multiply(MMD_SA.get_bone_rotation_parent(e,s+"手首","上半身2")).conjugate()}m[0]._rot_parent=y;const g=m[0].no_blending?Ke.copy(m[0].rot):Ke.copy(m[1].rot).slerp(m[0].rot,h);if(m[0]._rot_pose&&m[0]._rot_pose_ratio){let t=m[0]._rot_pose_ratio;if(m[0]._rot_pose_ratio_by_angle_difference){let e=MMD_SA.TEMP_q.copy(g).conjugate().multiply(m[0]._rot_pose).toAxisAngle()[1]%(Math.PI*2);if(e>Math.PI){e-=Math.PI*2}else if(e<-Math.PI){e+=Math.PI*2}const v=Math.pow(1-Math.abs(e)/Math.PI,1-m[0]._rot_pose_ratio_by_angle_difference);t*=v}if(m[0]._rot_pose_constrained){const w=qe.setEulerFromQuaternion(g,"YXZ");const S=Te.setEulerFromQuaternion(m[0]._rot_pose,"YXZ");let e=Math.abs(w.y-S.y);if(e>Math.PI)e=Math.PI*2-e;if(e>Math.PI*2/3&&Math.abs(w.x)S.y?Math.PI*2:0)-w.y:-(w.y+(w.yRAF_timestamp-250&&Math.abs(t-D.angle)>Math.PI){let e=t+Math.PI*2*(t>0?-1:1);if(Math.abs(e)Math.PI/4){const l=r{ae=new System._browser.data_filter([{type:"one_euro",id:"torso_rot",para:[30,.5,1,1,3]}]);Ee=new System._browser.data_filter([{type:"one_euro",id:"chest_rot",para:[30,.5,1,1,3]}]);ke=new System._browser.data_filter([{type:"one_euro",id:"shoulder_rot_z_filter",para:[30,1,1,1,1]}]);_e=new System._browser.data_filter([{type:"one_euro",id:"hand_depth_weight",para:[30,.5,.1,1,1]}]);for(const e of["左","右"]){xe[e]=new System._browser.data_filter([{type:"one_euro",id:"arm_IK"+e,para:[30,.5,1/2,1,3]}]);se[e]=new System._browser.data_filter([{type:"one_euro",id:"_arm_IK"+e,para:[30,.5,1/2,1,3]}]);Pe[e]=new System._browser.data_filter([{type:"one_euro",id:"arm_rot"+e,para:[30,.5,1/2,1,4]}]);re[e]=new System._browser.data_filter([{type:"one_euro",id:"hand_depth"+e,para:[30,.5,.1,1,1]}]);Re[e]=new System._browser.data_filter([{type:"one_euro",id:"rot_pose_ratio"+e,para:[30,.5,.1,1,1]}])}});return function(e){var he=typeof e.data=="string"&&e.data.charAt(0)==="{"?JSON.parse(e.data):e.data;if(typeof he==="string"){if(he=="OK"){Ce.worker_initialized=true}else{DEBUG_show(he,2);System._browser.console.log(he)}}else if(Ce.enabled){window.dispatchEvent(new CustomEvent("SA_camera_poseNet_update"));je._needs_RAF=true;Ce._bb=null;const fe=MMD_SA.THREEX.get_model(0).model_para;const o=wt[Ce.use_holistic?1:0];let e;if(Ce.enabled&&!o.poseNet){e=true;o.poseNet=true}if(Be.enabled&&!o.handpose){e=true;o.handpose=true}if(e)DEBUG_show("Pose ML ready",2);He=(Fe.enabled?"\n":"")+je.video_canvas.width+"x"+je.video_canvas.height+"("+Ce.camera_video_frame_id+")\n";let t=je.video_timestamp;let i=0;if(ee){i=Math.max(Math.min(t-ee,1e3),10);J+=i;if(++$>=20){Z=1e3/(J/$);$=J=0}}ee=t;Ce._t=he._t;tt.t_delta=((tt.t_delta||i)+i)/2;if(he.handpose){i=0;if(ne){i=Math.max(Math.min(t-ne,1e3),10);oe+=i;if(++ie>=20){te=1e3/(oe/ie);ie=oe=0}}ne=t;Ce._t_hands=he._t_hands;tt.t_delta_hands=((tt.t_delta_hands||i)+i)/2}if(Ce.use_holistic){o.facemesh=true;if(!he.facemesh){Fe.data_detected=0}}let le=[];let ce=[];let de=je.x_flipped?1:-1;let pe;const s=THREE.MMD.getModels()[0];const n=s.mesh.bones_by_name;const ve=MMD_SA.THREEX.get_model(0).is_T_pose;const L=MMD_SA.THREEX.get_model(0);const Me=MMD_SA.MMD.motionManager.para_SA;const M=Me.motion_tracking&&Me.motion_tracking.arm_as_leg;const ye={"左":M&&M.enabled&&(!M.linked_side||M.linked_side=="left"),"右":M&&M.enabled&&(!M.linked_side||M.linked_side=="right")};let D;let ue,a;let me;if(Ce.enabled){if(he.posenet&&he.posenet.score>.3){Ce.data_detected++;Ce.initial_data_detected=true;if(Ce.data_detected_stable){if(Ne){Ne=false;s.mesh.visible=true}D=Me.motion_tracking?.camera?.tilt_adjustment||je.tilt_adjustment;if(D.enabled){a=D.angle*D.pose_weight*Math.PI/180;ue=(new THREE.Quaternion).set(Math.sin(a/2),0,0,Math.cos(a/2))}me=he.posenet;let re=Ce.use_3D_pose;if(pt){me._keypoints=me.keypoints;me._keypoints3D=me.keypoints3D;let o=[];let n=[];ft.forEach((e,t)=>{let i=me.keypoints[e];i.part=ht[t];o.push(i);i=me.keypoints3D[e];i.part=ht[t];n.push(i)});me.keypoints=o;me.keypoints3D=n}const c=dt?.3:!mt?.5:.1;me.keypoints.forEach(e=>{e.score-=c});if(re){me._keypoints3D.forEach(e=>{e.score-=c})}if(mt){let i={};me.keypoints.forEach(e=>{i[e.part]=e});let o=[];for(let t=0;t<=16;t++){let e=me.keypoints[t];if(!e)o.push(Mt[t]);else if(e.part!=ht[t])o.push(i[ht[t]]||Mt[t]);else o.push(e)}me.keypoints=o}let e=me._keypoints||me.keypoints;let t=e.map(e=>e.position.x);let i=e.map(e=>e.position.y);const p=[Math.min(...i),Math.max(...t),Math.max(...i),Math.min(...t)];e=me.keypoints.slice(0,5);t=e.map(e=>e.position.x);i=e.map(e=>e.position.y);const u=[Math.min(...i),Math.max(...t),Math.max(...i),Math.min(...t)];const g=Math.max(u[1]-u[3],u[2]-u[0])/2;p[0]=Math.min(p[0],u[0]-g);p[1]=Math.max(p[1],u[1]+g);p[2]=Math.max(p[2],u[2]-g);p[3]=Math.min(p[3],u[3]-g);Ce._bb=p;if(!Fe.head_pose_enabled){Fe.bb_center[0]=me.keypoints[0].position.x/je.video_canvas.width;Fe.bb_center[1]=me.keypoints[0].position.y/je.video_canvas.height}if(re&&Ce.use_head_mocap){let e=me._keypoints[0].position;let t=me._keypoints[3].position;let i=me._keypoints[6].position;const v=qe.copy(i);const k=Te.copy(t);k.sub(v);const x=MMD_SA._v3a_.copy(e);const P=(x.x*k.x+x.y*k.y+x.z*k.z-(v.x*k.x+v.y*k.y+v.z*k.z))/k.lengthSq();const C=MMD_SA._v3b.set(v.x+k.x*P,v.y+k.y*P,v.z+k.z*P);let o=x.sub(C).normalize();let n=MMD_SA._v3b_.copy(t).sub(MMD_SA._v3b.copy(i));n.normalize();let a=MMD_SA.TEMP_v3.crossVectors(n,o).normalize();n.crossVectors(o,a);Ge.set(n.x,n.y,n.z,0,o.x,o.y,o.z,0,a.x,a.y,a.z,0,0,0,0,1);We.setFromBasis(Ge);let s=We.conjugate();s=s.clone().multiply(MMD_SA.TEMP_q.set(Math.sin(Math.PI/3.5/2),0,0,Math.cos(Math.PI/3.5/2)));Fe._neck.shoulder_center=Te.copy(me._keypoints[11].position).add(MMD_SA.TEMP_v3.copy(me._keypoints[12].position)).multiplyScalar(.5).toArray();if(ue)s.premultiply(ue);if(!Fe.head_pose_enabled){tt.add("skin","首",{after_IK:true,rot:s,onProcessRotation:yt});tt.skin["首"][1]._rot_mixed&&tt.skin["首"][1].rot.copy(tt.skin["首"][1]._rot_mixed)}tt.add("skin","首_DUMMY_",{rot:s,_rot_from_pose:s.clone(),onProcessRotation:yt})}let o=me.keypoints[5];let n=me.keypoints[6];let w=new THREE.Quaternion;pe=Me.motion_tracking_upper_body_only;He+="\n"+(pe?(Me.motion_tracking?.arm_as_leg?.enabled?"🦶":"🙋")+"upper body":"💃full body"+(Ce.auto_grounding?"👣":""));const b=MMD_SA_options.Dungeon_options?.item_base.hand_camera;if(b&&b._hand_camera_side){He+="/"+(b.selfie_mode?"🤳selfie":"📷handcam")+(b._hand_camera_side=="左"?"-L":"-R")}else if(pe&&Ce.hip_camera){He+="/"+"📷hip cam"}He+="\n";if(re&>)$e.prepare(me);let M=0,S=0;if(Be.enabled&&he.handpose)Be.hand_visible_timestamp={};et[0]=et[1]=0;let _e;if(o.score>0&&n.score>0&&[o,n].some(e=>e.position.x>=0&&e.position.x<=je.video_canvas.width&&e.position.y>=0&&e.position.y<=je.video_canvas.height)){let u,m;let h,f;if(re){u=me.keypoints3D[5];m=me.keypoints3D[6];let e=me.keypoints3D[11];let i=me.keypoints3D[12];Ce._hip_visible=e.score>0&&i.score>0&&me.keypoints[11].position.yMath.PI)p=Math.PI*2-p;else if(p<0&&p<-Math.PI)p+=Math.PI*2;h.multiply(Xe.set(0,Math.sin((p/2-c)/2),0,Math.cos((p/2-c)/2)));f.multiply(Xe.set(0,Math.sin((p/2-d)/2),0,Math.cos((p/2-d)/2)));tt.add("skin","センター",{rot:w.clone(),priority:9});if(it.active){if(!tt.skin["センター"][0].pos&&tt.skin["センター"][1].pos)tt.skin["センター"][0].pos=tt.skin["センター"][1].pos}const H=h.clone();if(ue){const O=Xe.copy(ue);const q=Me.motion_tracking?.ML_models?.pose||MMD_SA_options.user_camera.ML_models.pose;if(q.upper_rotation_offset){const X=-(q.upper_rotation_offset-p)*2/3*Math.PI/180;const U=ue.toAxisAngle();O.setFromAxisAngle(U[0].applyQuaternion(MMD_SA.TEMP_q.set(0,Math.sin(X/2),0,Math.cos(X/2))),U[1])}Xe.premultiply(MMD_SA.TEMP_q.copy(w).conjugate()).multiply(w);H.premultiply(O)}tt.add("skin","上半身",{rot:H});tt.add("skin","上半身2",{rot:f.clone()});_e=Xe.copy(w).multiply(h).multiply(f);_e.conjugate()}const R=MMD_SA.TEMP_v3.set(1,1,1/3);Ce.shoulder_width=qe.copy(o.position).multiply(R).distanceTo(Te.copy(n.position).multiply(R));let se=Math.sqrt(Math.pow(o.position.x-n.position.x,2)+Math.pow(o.position.y-n.position.y,2));let e=0;if(!re){e=Math.asin((o.position.y-n.position.y)/se);e=Math.max(Math.min(e/(Math.PI/4),1),-1)*Math.PI/4*de}let t=de==1?[1,0]:[0,1];se=Fe.face_width*2||se;Ce._upper_body_only_mode=pe;const ge=[0,0];const be=[];t.forEach(function(i,l){let n,a,s;let r;let c=l==0?"左":"右";let _=me.keypoints[5+i];let d=me.keypoints[7+i];let p=me.keypoints[9+i];let u=(Me.motion_tracking?.arm_tracking?.use_IK!=null?!Me.motion_tracking.arm_tracking.use_IK:MMD_SA_options.user_camera.ML_models.pose.use_armIK==null?!pe&&!Ce.body_collider.active&&MMD_SA_options.Dungeon_options?.item_base.hand_camera?._hand_camera_side!=c:!MMD_SA_options.user_camera.ML_models.pose.use_armIK)&&!ye[c];let m=false;be[l]=new THREE.Quaternion;if(ve)be[l].fromArray(MMD_SA.THREEX.utils.convert_A_pose_rotation_to_T_pose(c+"肩",be[l].toArray()));let h,f,M;if(re){h=me.keypoints3D[5+i];f=me.keypoints3D[7+i];M=me.keypoints3D[9+i];let e=(fe.camera?.poseNet?.arm_vertical_offset_percent||0)/100+(Ce.arm_vertical_offset_percent||0)/100;if(e){const x=MMD_SA.TEMP_v3.copy(f).distanceTo(h)+MMD_SA.TEMP_v3.distanceTo(M);const X=MMD_SA.TEMP_v3.copy(M).sub(h);const U=-(1-Math.abs(X.y)/x)*(x*e);M={x:M.x,y:M.y+U,z:M.z};f={x:f.x,y:f.y+U/2,z:f.z}}let t=(fe.camera?.poseNet?.arm_horizontal_offset_percent||0)/100+(Ce.arm_horizontal_offset_percent||0)/100;if(t){const P=t>0?1/(1+t):1-t;const K=Te.copy(me.keypoints3D[5]).add(me.keypoints3D[6]).multiplyScalar(.5);const R=Ie.copy(h).sub(K);const T=ze.copy(R).multiplyScalar(P).add(K);R.copy(T).sub(h).multiplyScalar(.5);h={x:T.x,y:T.y,z:T.z};T.copy(f).add(R);f={x:T.x,y:T.y,z:T.z}}}let y=p.score>0&&p.position.x>=0&&p.position.x<=je.video_canvas.width&&p.position.y>=0&&p.position.y<=je.video_canvas.height;if(y&&ye[c]&&Ce._hip_visible&&re){let e=MMD_SA.TEMP_v3.copy(h).distanceTo(f);e+=MMD_SA.TEMP_v3.copy(f).distanceTo(M);let t=MMD_SA.TEMP_v3.copy(M).sub(h).y;if(e-t0&&Be.enabled&&Be.stabilize_hand_percent&&Ce.shoulder_width){const I=je.video_canvas.width;const G=je.video_canvas.height;const z=Be._hand_last[c];let o;if(he.handpose&&he.handpose.length){const Q=he.handpose.find(e=>e.label==(c=="左"?"Left":"Right"));if(Q){o=z.hand=Q.annotations.palm[0];z.timestamp=RAF_timestamp;z.w=I;z.h=G}}if(!o){o=z.hand}const W=1e3*(Be.stabilize_hand_percent/100)*(pe||!u?1:.5);let n=RAF_timestamp-z.timestamp;if(o&&z.w==I&&z.h==G&&n(Me.motion_tracking_upper_body_only?0:1);const B="YZX";let w;let t=Me.motion_tracking?.arm_tracking?.data_filter?.[c=="左"?"left":"right"];if(t)t=Object.assign({},t);let S;let A=Me.motion_tracking?.arm_tracking?.off_screen_allowed?.[c=="左"?"left":"right"];if(p.score>0){let e;if(pe&&Be.enabled&&Be.use_hands_worker&&!he.handpose){if(Be.hand_visible_timestamp[c]+200>RAF_timestamp)y=e=true}let o,t;if(Be.enabled&&he.handpose){o=he.handpose.find(e=>e.label==(c=="左"?"Left":"Right"));if(o){y=true}}if(o){Be.hand_visible_timestamp[c]=RAF_timestamp;if(!pe)Be.hand_visible_session[c]=RAF_timestamp}if(Be.enabled&&pe){let t;let i=Be.hand_visible_session[c]||0;if(o||e){if(i<1e3){Be.hand_visible_session[c]=1e3;if(!Be.stabilize_arm_time){w=true}else{t=true}}else if(i<1200){Be.hand_visible_session[c]+=Ce._t_hands;if(Be.hand_visible_session[c]>1e3+Be.stabilize_arm_time){w=true}else{t=true}}else{Be.hand_visible_session[c]=RAF_timestamp}}else{Be.hand_visible_timestamp[c]=0;let e=!y;if(y&&i<1e3+Be.stabilize_arm_time){if(i>=1e3)i=Be.hand_visible_session[c]=201;e=true;t=true}if(e){w=y;if(!i){Be.hand_visible_session[c]=0;t=true}else if(i>200){Be.hand_visible_session[c]=200}else{Be.hand_visible_session[c]-=Ce._t_hands;if(Be.hand_visible_session[c]<0)Be.hand_visible_session[c]=0}}}if(C){if(t){let e=A||!Me.motion_tracking_upper_body_only;let t=e&&A;let i,n;i=!e;let a;if(!e||y){p.score=0;if(!e&&tt.skin[c+"ひじ"]?.[0].rot.w!=1){a=a||new THREE.Quaternion;tt.add("skin",c+"ひじ",{absolute:true,no_blending:i,blending_ratio:n,rot:a})}}if(e&&!p.score){S=true}if(!t&&tt.skin[c+"手首"]?.[0].rot.w!=1){a=a||new THREE.Quaternion;tt.add("skin",c+"手首",{after_IK:true,absolute:true,no_blending:i,blending_ratio:n,rot:a});tt.add("skin",c+"手捩",{after_IK:true,absolute:true,no_blending:i,blending_ratio:n,rot:a})}if(!t&&(e&&Be.enabled)){Qe.forEach((t,e)=>{let i=e==0?0:1;for(let e=i;ee.magnet_id==t.weight_by_magnet.id);o=Y&&Y._frame_count_>=EV_sync_update.count_frame-1-(Be.use_hands_worker?6:0)?Y._weight_:0}}const D=pe?.5:2;e.minCutOff=D*(1-o)+(t?.minCutOff||D)*o;e.beta=D*(1-o)+(t?.beta||D)*o;e.dCutOff=1*(1-o)+(t?.dCutOff||1)*o;const H=Pe[c].filters[0].filter;H.beta=e.beta;H.minCutOff=e.minCutOff;H.dCutOff=e.dCutOff;const E=c+(ye[c]?"足IK":"腕IK");let O=true;if(re&&d.score>0){if(!A&&C&&!y&&pe&&!Me.motion_tracking_upper_body_only){const Z=MMD_SA._v3b.copy(h).sub(f);if(p.score>0){const $=Z.length();const j=MMD_SA.TEMP_v3.copy(M).sub(f);f.z=h.z;const J=MMD_SA._v3b.copy(h).sub(f).length()/$;j.multiplyScalar(J).add(f);M.x=j.x;M.y=j.y;M.z=j.z}f.z=h.z}g=MMD_SA._v3b.copy(h).sub(f).normalize().applyQuaternion(_e);b=MMD_SA.TEMP_v3.set(L,0,0);v=(new THREE.Quaternion).setFromUnitVectors(b,g);ge[l]=Te.setFromVectorSpherical(b,g).z}let k;if(p.score>0){if(re){let e=d.score>0?MMD_SA.TEMP_v3.copy(h).distanceTo(f)+MMD_SA.TEMP_v3.copy(f).distanceTo(M):.5;let o=Math.min(MMD_SA.TEMP_v3.copy(h).sub(M).length()/e,1);if(d.score>0){let e=MMD_SA_options.model_para_obj.colliders_for_hands?.chest?.scale;if(e>1&&Ce.body_collider.mode>(pe?0:1)){let r=MMD_SA._v3a.copy(h).sub(M).applyQuaternion(_e);r.normalize().multiplyScalar(o*MMD_SA_options.model_para_obj.left_arm_length);const ee=c=="左"?-1:1;let _=THREE.Math.clamp(r.x/MMD_SA_options.model_para_obj.shoulder_width*ee,0,1)*THREE.Math.clamp(1-r.y/(MMD_SA_options.model_para_obj.shoulder_width*.75),0,1)*THREE.Math.clamp(1-(r.z-MMD_SA_options.model_para_obj.left_arm_length*.5)/(MMD_SA_options.model_para_obj.left_arm_length*.5),0,1);_=Math.sin(_*Math.PI/2)*Math.sin(Math.min((e-1)*.5,1)*Math.PI/2)*2;if(_){r=MMD_SA._v3a.copy(h).sub(M).normalize();let e=MMD_SA.TEMP_q.setFromAxisAngle(r,-Math.PI/4*_*ee);const t=h;const i=ze.copy(M).sub(t);const o=f;const n=(o.x*i.x+o.y*i.y+o.z*i.z-(t.x*i.x+t.y*i.y+t.z*i.z))/i.lengthSq();const a=MMD_SA._v3b.set(t.x+i.x*n,t.y+i.y*n,t.z+i.z*n);let s=MMD_SA.TEMP_v3.copy(f).sub(a);s.applyQuaternion(e).add(a);f.x=s.x;f.y=s.y;f.z=s.z;g=MMD_SA._v3b.copy(h).sub(f).normalize().applyQuaternion(_e);b=MMD_SA.TEMP_v3.set(L,0,0);v=(new THREE.Quaternion).setFromUnitVectors(b,g);ge[l]=Te.setFromVectorSpherical(b,g).z}}let t=qe.copy(f).sub(M);t.normalize().applyQuaternion(_e).applyQuaternion(MMD_SA.TEMP_q.copy(v).conjugate());b=MMD_SA.TEMP_v3.set(L,0,0);if(!S){k=(new THREE.Quaternion).setFromUnitVectors(b,t)}}if(d.score>0){const g=MMD_SA.TEMP_v3.copy(h).sub(f).applyQuaternion(_e);O=g.y<0}if(!u||d.score<=0){u=false;let i=MMD_SA._v3a.copy(h).sub(M);if(ue)i.applyQuaternion(ue);i.normalize().multiplyScalar(o*MMD_SA_options.model_para_obj.left_arm_length);if(Me.motion_tracking_upper_body_only&&!ye[c]&&tt._skin["左腕"]?.pos_local&&tt._skin["右腕"]?.pos_local){const te=MMD_SA.TEMP_v3.copy(tt._skin["左腕"].pos_local).sub(tt._skin["右腕"].pos_local);let e=Math.min(te.z*(c=="左"?1:-1),0)*.75;let t=Math.min(Math.abs(te.x)-MMD_SA_options.model_para_obj.shoulder_width,0)*(c=="左"?1:-1)*.5;i.x-=t;i.z-=e;const ie=Math.min(i.length(),MMD_SA_options.model_para_obj.left_arm_length);i.normalize().multiplyScalar(ie)}n=i.x;a=i.y;s=i.z;r=s;if(v){if(!u)v.fromArray(S&&Pe[c].timestamp!=null?Pe[c].filter(null,true):Pe[c].filter(v.toArray()));we(v,c+"腕");tt.add("skin",c+"腕",{absolute:true,rot:v,priority:-1,onFinish:Se});const oe=tt.skin[c+"腕"];const F=Ye[c+"腕"];const ne=MMD_SA.TEMP_q.copy(v).premultiply(F.axis_rot_inv).multiply(F.axis_rot);oe[0]._elbow0=new THREE.Vector3((c=="左"?1:-1)*MMD_SA_options.model_para_obj.left_arm_length/2,0,0).applyQuaternion(ne);if(k){we(k,c+"ひじ");tt.add("skin",c+"ひじ",{absolute:true,rot:k,_IK_disabled:u,onFinish:Ae})}}}else{we(k,c+"ひじ");we(v,c+"腕");tt.add("skin",c+"腕",{absolute:true,rot:v,priority:-1,onFinish:Se});tt.add("skin",c+"ひじ",{absolute:true,rot:k})}}else{m=true;let e=_.position.x-p.position.x;let t=_.position.y-p.position.y;n=e/se*MMD_SA_options.model_para_obj.shoulder_width*de;a=t/se*MMD_SA_options.model_para_obj.shoulder_width;if(d.score>0){let e=Math.min(Math.sqrt(Math.pow(p.position.x-d.position.x,2)+Math.pow(p.position.y-d.position.y,2))/se,1);let t=Math.min(Math.sqrt(Math.pow(_.position.x-d.position.x,2)+Math.pow(_.position.y-d.position.y,2))/se,1);r=(.25+(Math.sin(Math.acos(e))+Math.sin(Math.acos(t)))/2*.75)*MMD_SA_options.model_para_obj.left_arm_length}}}else{let t;if(d.score>0){if(re){let e=!!v;if(!u){u=false;if(Me.motion_tracking_upper_body_only&&tt._skin[E]?._pos_&&tt.get_blend_default_motion("skin",E)%1){e=false;[n,a,s]=tt._skin[E]._pos_;const ae=tt._skin[E]._foot_;if(ae){t=true;tt.add("skin",c+"足首",{after_IK:true,rot:ae.rot,_finger_x:null,absolute:true,onFinish:De})}}else{g=MMD_SA._v3a.copy(h).sub(f).normalize();g.multiplyScalar(MMD_SA_options.model_para_obj.left_arm_length);g.x*=de;n=g.x*de;a=g.y;s=g.z}r=s}else{u=true}if(e){if(!u)v.fromArray(S&&Pe[c].timestamp!=null?Pe[c].filter(null,true):Pe[c].filter(v.toArray()));we(v,c+"腕");tt.add("skin",c+"腕",{absolute:true,rot:v,priority:-1,onFinish:Se});const oe=tt.skin[c+"腕"];const F=Ye[c+"腕"];const ne=MMD_SA.TEMP_q.copy(v).premultiply(F.axis_rot_inv).multiply(F.axis_rot);oe[0]._elbow0=new THREE.Vector3((c=="左"?1:-1)*MMD_SA_options.model_para_obj.left_arm_length/2,0,0).applyQuaternion(ne)}}else{u=false;m=true;let e=_.position.x-d.position.x;let t=_.position.y-d.position.y;let i=Math.sqrt(e*e+t*t);let o=Math.asin(e/i);n=Math.sin(o)*MMD_SA_options.model_para_obj.left_arm_length*de;a=Math.cos(o)*MMD_SA_options.model_para_obj.left_arm_length*Math.sign(t)}}else{if(re){if(!Me.motion_tracking_upper_body_only)return;s=r=0}else{m=true}if(n==null){u=false;n=MMD_SA_options.model_para_obj.left_arm_to_IK_xy[1]*(c=="左"?1:-1)*.2;a=-Math.sqrt(MMD_SA_options.model_para_obj.left_arm_length*MMD_SA_options.model_para_obj.left_arm_length-n*n)}}if(ye[c]){tt.add("skin",c+"手首",{rot:new THREE.Quaternion});if(!t){tt.remove("skin",c+"足首")}}}let q=!u;if(!u&&(Me.motion_tracking?.arm_tracking?.use_IK||pe)&&!t?.disabled){if(S&&xe[c].timestamp!=null){q=false;[n,a,s]=xe[c].filter(null,true)}}if(Me.motion_tracking_upper_body_only&&tt._skin[E]){tt._skin[E]._pos_=[n,a,s]}le.push({pos:{x:n,y:a,z:s,z_posenet:r},z_limited:O,dir:i,d:c,IK_disabled:u,IK_absolute:m,use_filter:q})});ge[0]=ge[0]==null?0:Math.max(ge[0]+Math.PI/2,0);ge[1]=ge[1]==null?0:Math.max(Math.PI/2-ge[1],0);const T=ge[0]>ge[1]?1:0;const B=Math.min(Math.abs(ge[0]-ge[1])/(Math.PI/2),1);ge[T==0?1:0]=1;ge[T]=1-B*B*.5;t.forEach(function(e,i){let o=i==0?"左":"右";if(be[i]){et[i]*=ge[i];let e=(Fe.enabled?et[2]:0)*(i==0?1:-1);let t=et[i]+e;const n=Math.PI/6;if(Math.abs(t)>n){e=Math.sign(e)*(n-Math.abs(et[i]));t=et[i]+e}t=_t[o].filter(t);be[i].multiply(MMD_SA.TEMP_q.set(0,0,Math.sin(t/2),Math.cos(t/2)));tt.add("skin",o+"肩",{priority:-2,absolute:!(Me.motion_tracking_upper_body_only&&Me.motion_tracking?.motion_default_weight?.shoulder),rot:be[i],_rot_z:et[i],_rot_shrug:e,_rot_total:t,onFinish:Y})}})}else{pe=true}const A=M;if(re&&!Me.motion_tracking_upper_body_only){if(ue){w.premultiply(MMD_SA.TEMP_q.copy(ue).conjugate());M=A-MMD_SA.TEMP_v3.setEulerFromQuaternion(w,"YZX").z}}if(re&&!pe){$e.get_hip_center(me);let e=de==1?[1,0]:[0,1];let b=[];let t=[];let v=0;let i=[];e.forEach(function(n,e){let a=e==0?"左":"右";let i=me.keypoints3D[11+n];let s=me.keypoints3D[13+n];let r=me.keypoints3D[15+n];let t,o,_;if(r.score>0){t=MMD_SA._v3a.copy(i).sub(r);o=t.length();_=s.score>0?MMD_SA.TEMP_v3.copy(i).distanceTo(s)+MMD_SA.TEMP_v3.copy(s).distanceTo(r):.7;t.normalize().multiplyScalar(Math.min(o/_,1)*MMD_SA_options.model_para_obj.left_leg_length)}let l,c;let d;if(s.score>0){d=MMD_SA._v3b.copy(i).sub(s).normalize().applyQuaternion(MMD_SA.TEMP_q.copy(w).conjugate());let e=MMD_SA.TEMP_v3.set(0,1,0);e.y*=-1;c=Te.setFromVectorSpherical(e,d);l=(new THREE.Quaternion).setFromEuler(c,"XZY");const t=qe.setFromVectorSpherical(e,MMD_SA._v3b.copy(i).sub(s).normalize().applyQuaternion(MMD_SA.TEMP_q.copy(w).multiply(MMD_SA._q2.set(0,0,Math.sin(A/2),Math.cos(A/2))).multiply(MMD_SA._q1.set(Math.sin(S/2),0,0,Math.cos(S/2))).conjugate()));v+=t.x}let p=!MMD_SA_options.user_camera.ML_models.pose.use_legIK;if(r.score>0){let i,o;if(s.score>0){i=qe.copy(s).sub(r).normalize().applyQuaternion(MMD_SA.TEMP_q.copy(w).conjugate());o=Ie.copy(i).applyQuaternion(MMD_SA.TEMP_q.copy(l).conjugate());o.z=Math.max(-o.z,0);o.x*=-1;let e=o.normalize().toSphericalCoords();let t=Math.sqrt(Math.min((Math.PI-e[2])/(Math.PI/2),1));c.y=e[1]*t;l.setFromEuler(c,"XZY")}if(!p||s.score<=0){Ce.enable_IK(a+"足IK",true);b.push({pos:t.clone(),rot:[l],dir:n,d:a})}else{o=Ie.copy(i).applyQuaternion(MMD_SA.TEMP_q.copy(l).conjugate());let e=MMD_SA.TEMP_v3.set(0,1,0);e.y*=-1;let t=(new THREE.Quaternion).setFromVectorSpherical(e,o);Ce.enable_IK(a+"足IK",false);b.push({rot:[l,t],dir:n,d:a})}const u=me._keypoints3D[29+n];const m=me._keypoints3D[31+n];if(u.score>0&&m.score>0){let e=MMD_SA._v3a_.copy(u).sub(r).normalize();let t=MMD_SA._v3b_.copy(u).sub(m).normalize();let i=qe.crossVectors(e,t).normalize();e.crossVectors(t,i);Ge.set(i.x,i.y,i.z,0,e.x,e.y,e.z,0,t.x,t.y,t.z,0,0,0,0,1);We.setFromBasis(Ge);let o=We.conjugate();const h=-Math.PI/(MMD_SA_options.user_camera.ML_models.pose.model_quality=="Best"?10:8);o=o.clone().multiply(MMD_SA.TEMP_q.set(Math.sin(h/2),0,0,Math.cos(h/2)));if(ue)o.premultiply(ue);const f=Xe.copy(w);if(ue)f.premultiply(ue);const M=MMD_SA.TEMP_v3.setEulerFromQuaternion(f,"YZX");const y=Math.abs(M.y)%Math.PI;let n=y>Math.PI/2?1-(y-Math.PI/2)/(Math.PI/2):1;if(MMD_SA_options.user_camera.ML_models.pose.use_legIK){const g=o.clone();if(n<1){M.x=M.z=0;g.slerp(Ue.setFromEuler(M,"YZX"),1-n)}b[b.length-1].rot[2]=g}tt.add("skin",a+"足首",{after_IK:true,absolute:true,parent_based:true,motion_recorder_disabled:MMD_SA_options.user_camera.ML_models.pose.use_legIK,rot:o,ratio:n,ratio_euler:MMD_SA_options.user_camera.ML_models.pose.model_quality=="Best"?{x:1,y:1,z:.5,order:"YXZ"}:null})}}else{if(s.score>0){if(!p){t=MMD_SA._v3a.copy(i).sub(s).normalize().multiplyScalar(MMD_SA_options.model_para_obj.left_leg_length);if(ue)t.applyQuaternion(ue);Ce.enable_IK(a+"足IK",true);b.push({pos:t.clone(),rot:[l],dir:n,d:a})}else{Ce.enable_IK(a+"足IK",false);b.push({rot:[l],dir:n,d:a})}}if(tt.skin[a+"足首"]?.[0].rot.w!=1)tt.add("skin",a+"足首",{after_IK:true,absolute:true,no_blending:true,rot:new THREE.Quaternion})}});let o=0;i.forEach(e=>{const t=e.y*(1-e.scale);if(t>0){o=Math.max(t,o)}else if(i.length>1){o=Math.max(t,o||t)}});if(o){$e.v_hip.y+=o;He+="\nleg_offset_y:"+o+"\n"}v*=.5*.5;v+=S;v=Je("hip_angle_x",v,!!pe);let n=(new THREE.Quaternion).setFromEuler(MMD_SA.TEMP_v3.set(v,0,M),"YZX");tt.add("skin","下半身",{absolute:true,rot:n.clone()});if(!pe){tt.add("skin","全ての親",{pos:new THREE.Vector3,after_IK:true,priority:999,onProcessPosition:W})}n.conjugate();b.forEach(e=>{var t=e.d;if(e.rot[0]){e.rot[0].multiplyQuaternions(n,e.rot[0]);tt.add("skin",t+"足",{absolute:true,rot:e.rot[0]})}if(e.pos){e.pos.add(MMD_SA_options.model_para_obj.leg_IK_offset[t]);const i=e.rot[2]||tt.skin[t+"足IK"]?.[0].rot;tt.add("skin",t+"足IK",{absolute:true,pos:e.pos,rot:i,priority:999,onFinish:G});if(i&&!tt.skin[t+"足IK"][1].rot)tt.skin[t+"足IK"][1].rot=i}else{if(e.rot[1]){tt.add("skin",t+"ひざ",{absolute:true,rot:e.rot[1]})}else if(tt.skin[t+"ひざ"]?.[0].rot.w!=1){tt.add("skin",t+"ひざ",{absolute:true,no_blending:true,rot:new THREE.Quaternion})}}})}else{if(Me.motion_tracking_upper_body_only){$e.get_hip_center(me);tt.add("skin","全ての親",{pos:new THREE.Vector3,after_IK:true,priority:999,onProcessPosition:W})}else if(re&&o.score>0&&n.score>0&&je.video_canvas.width){$e.get_hip_center(me);tt.add("skin","全ての親",{pos:new THREE.Vector3,after_IK:true,priority:999,onProcessPosition:W})}if(!ye["左"]||!ye["右"]){let t=Je("hip_angle_x",0,!!pe);if(M||t){let e=(new THREE.Quaternion).setFromEuler(MMD_SA.TEMP_v3.set(t,0,M),"YZX");tt.add("skin","下半身",{absolute:true,rot:e.clone()})}else{tt.add("skin","下半身",{is_dummy:true,rot:true})}}for(const j of["左","右"]){if(!ye[j]){tt.add("skin",j+"足IK",{is_dummy:true,pos:true,priority:999});tt.add("skin",j+"足",{is_dummy:true,rot:true});tt.add("skin",j+"ひざ",{is_dummy:true,rot:true});tt.add("skin",j+"足首",{is_dummy:true,after_IK:true,rot:true})}}}}}else{Ce.data_detected=0}}if(Ce.enabled&&!Ce.data_detected_stable&&!Ne){Ne=true;if(!Me.motion_tracking_upper_body_only&&Ce.initial_data_detected)s.mesh.visible=false}let I;let E=[];const r=!Be.enabled&&me&&Ce.use_3D_pose;const _=de==1?[1,0]:[0,1];const d={};const l=Be.enabled&&Ce.shoulder_width?Math.min(Math.max(Math.max(je.video_canvas.width,je.video_canvas.height)/Ce.shoulder_width-5,0)/5,1)*.5:0;const m={"左":l,"右":l};if(r||!Me.motion_tracking_upper_body_only&&l){_.forEach(function(e,t){let i=t==0?"左":"右";if(!ce.find(e=>e.d==i)?.visible)return;let o=me._keypoints3D[15+e];let n=me._keypoints3D[17+e];let a=me._keypoints3D[19+e];if(o.score<=0||n.score<=0||a.score<=0)return;let s=e==1?[a,n]:[n,a];let r=MMD_SA._v3a_.copy(o).sub(MMD_SA._v3b.copy(n).add(a).multiplyScalar(.5)).normalize();r.x=r.x*de;let _=MMD_SA._v3b_.copy(s[0]).sub(s[1]).normalize();_.z=_.z*de;_.y=_.y*de;let l=MMD_SA.TEMP_v3.crossVectors(_,r).normalize();_.crossVectors(r,l);Ge.set(_.x,_.y,_.z,0,r.x,r.y,r.z,0,l.x,l.y,l.z,0,0,0,0,1);We.setFromBasis(Ge);let c=new THREE.Quaternion;c.copy(We).conjugate();if(ue)c.premultiply(ue);d[i]=c})}if(Be.enabled&&he.handpose&&he.handpose.length&&ce.length){const K=ut?1:2;he.handpose.forEach(e=>{e._offset={};I=e.annotations;if(K>1){for(let e in I){I[e].forEach(e=>{e[2]*=K})}}});ce.forEach((c,e)=>{var d=c.dir;let p=c.handpose;if(p&&c.visible){c.visible=true;p._used=true;let k=c.d;p._d=k;I=p.annotations;let e=le.find(e=>e.dir==d);const u=ze.set(1,1,p.z_adjust_ratio||1);let t=Me.motion_tracking?.hand_tracking?.depth_adjustment_disabled?0:MMD_SA_options.user_camera.ML_models.hands.depth_adjustment_percent/100;if(t&&pe&&e.pos.z>0&&MMD_SA_options.Dungeon_options?.item_base.hand_camera?._hand_camera_side!=k){const b=(MMD_SA._v3a.fromArray(I.palm[0]).multiply(u).distanceTo(MMD_SA._v3b.fromArray(I.middle[0]).multiply(u))+MMD_SA._v3a.fromArray(I.index[0]).multiply(u).distanceTo(MMD_SA._v3b.fromArray(I.pinky[0]).multiply(u)))/2/Ce.shoulder_width;const v=MMD_SA_options.user_camera.ML_models.hands.palm_shoulder_scale_percent/100;const w=Math.max(je.video_canvas.width,je.video_canvas.height)/Ce.shoulder_width;_e.filter(Math.max(3-Math.max(w-5,0),0)/3);palm_far_scale=(1.8+(1-Math.min(Math.max(w-4,0),1))*.4)*((1-MMD_SA_options.user_camera.ML_models.hands.depth_scale_percent/100)*2);re[k].filter(Math.min(Math.max(b-v,0)/Math.max(v*palm_far_scale-v,.1),1))}if(p.worldLandmarks){I=p.worldLandmarks.annotations;u.set(1,1,1)}E.push(k+"手");const m="pinky";let i=d==1?[I.index[0],I[m][0]]:[I[m][0],I.index[0]];let o,n,a;let s=MMD_SA._v3a_.fromArray(I.palm[0]).multiply(u).sub(MMD_SA._v3b.fromArray(I.middle[0]).multiply(u)).normalize();s.x=s.x*de;let r=MMD_SA._v3b_.fromArray(i[0]).multiply(u).sub(MMD_SA._v3b.fromArray(i[1]).multiply(u)).normalize();r.z=r.z*de;r.y=r.y*de;let _=MMD_SA.TEMP_v3.crossVectors(r,s).normalize();r.crossVectors(s,_);Ge.set(r.x,r.y,r.z,0,s.x,s.y,s.z,0,_.x,_.y,_.z,0,0,0,0,1);We.setFromBasis(Ge);let l=new THREE.Quaternion;l.copy(We).conjugate();if(D.enabled){const S=D.angle*Math.PI/180;const A=MMD_SA._q2.set(Math.sin(S/2),0,0,Math.cos(S/2));l.premultiply(A)}const M=MMD_SA.TEMP_v3.setEulerFromQuaternion(l,"YXZ").y;const y=1;const g=(Math.abs(M){let i=x[(de==1?k:k=="左"?"右":"左")+t];let o=i.base_index+(t==0?0:-1);let n=I[lt[t]];let a=Ue.copy(P);const s="XZY";if(t==0||t==4)return;const r=ct[k][t];const _=MMD_SA.TEMP_v3.fromArray(I.palm[0]);let l=MMD_SA._v3a_.fromArray(n[0]).sub(_);let c=MMD_SA._v3b_.fromArray(n[1]).sub(_);l.y*=-1;c.y*=-1;l.applyQuaternion(a);c.applyQuaternion(a);let d=MMD_SA.TEMP_v3.set(0,1,0);let p=c.sub(l).normalize();let u=Te.setFromVectorSpherical(d,p);const m=1;h+=u.z*m;f+=m});h/=f;rot_y_offset=MMD_SA.TEMP_q.set(0,Math.sin(h/2),0,Math.cos(h/2));P.conjugate().multiply(rot_y_offset).conjugate();rot_y_offset.set(0,Math.sin(h/4),0,Math.cos(h/4));l.multiply(rot_y_offset);tt.add("skin",k+"手首",{after_IK:true,rot:l,onProcessRotation:N});tt.add("skin",k+"手捩",{after_IK:true,absolute:true,priority:1,no_blending:true,rot:new THREE.Quaternion});Qe.forEach((e,t)=>{let i=x[(de==1?k:k=="左"?"右":"左")+t];let o=i.base_index+(t==0?0:-1);let n=I[lt[t]];let a=Ue.copy(P);const s="XZY";const r=ct[k][t];const _=MMD_SA.TEMP_v3.fromArray(I.palm[0]);for(let e=0;e<4;e++){const l=r[e].pos.fromArray(n[e]).sub(_);l.y*=-1;l.applyQuaternion(a)}});Qe.forEach((p,u)=>{let m=x[(de==1?k:k=="左"?"右":"左")+u];let h=m.base_index+(u==0?0:-1);let f=I[lt[u]];let M;const y="XZY";const g=k+p+"指"+Ve[m.base_index];const b=u==0?1:0;for(let d=h;d<3;d++){let e=k+p+"指"+Ve[m.base_index+(d-h)];const v=ct[k][u];const w=MMD_SA.TEMP_v3.copy(v[d].pos);for(let e=d;e<4;e++){const S=v[e].pos;S.sub(w);if(M&&e>d)S.applyQuaternion(M)}M=Ue;let t=v[d+0].pos;let i=v[d+1].pos;let o=MMD_SA._v3a_.set(0,1,0);let n=MMD_SA._v3b_.copy(i).sub(t).normalize();let a=MMD_SA._q1.set(0,0,0,1);let s=v[d].rot;if(u>0||d==2){s.setFromVectorSpherical(o,n);a.setFromEuler(s,y)}else{a.setFromUnitVectors(o,n);s.setEulerFromQuaternion(a,y)}M=Ue.copy(a).conjugate();if(Math.abs(s.z)>Math.PI/(u==0?1.1:2.5)||s.x>Math.PI/(u==0?1.1:3)){s.set(-Math.abs(o.angleTo(n)),0,0)}let r;if(u==0&&d>h+1){}else if(s.x>0){if(u>0&&d==0&&T>.5&&s.x>Math.PI/8){s.x*=-T}else s.x*=u==0?1:d>h?v[0].rot.x<0?-Math.min(Math.abs(v[0].rot.x)/(Math.PI/3),1):0:.75}if(s.x<0){r=-Math.PI/(u==0?1.25:1.8)}if(u==0){if(d==h){s.z=s.z*(d==0?1.25:1)+(Math.PI/8+(d==0?Math.PI/8:0))*(k=="左"?1:-1)}else if(d==1){s.z-=Math.PI/8*(k=="左"?1:-1)}else if(d==2){s.x=0;const A=Math.min(Math.abs(s.z)/(Math.PI/2),1);if(s.z>0){s.y=-Math.PI/4*Math.min(A*2,1);s.z=Math.PI/2*A}else{s.z=-Math.PI/2*A*1.5}}}else{let e=Math.min(...v.filter((e,t)=>t<=d).map(e=>e.rot.x));if(d==0){if(u>2){s.z=R*Math.abs(s.z)}}else{let t=1-(e<-Math.PI/6?Math.min(Math.abs(e+Math.PI/6)/(Math.PI/2-Math.PI/6),1):0);s.z*=t*(d==0?1:d==1?.75:.5);if(t<1){if(a.w>1)a.normalize();let e=2*Math.acos(a.w);s.x=s.x*t+Math.sign(s.x)*Math.abs(e)*(1-t)}}}if(T&&u>0&&d==h){const e=MMD_SA._v3a.fromArray(f[d+1]);e.y*=-1;e.applyQuaternion(P);const D=MMD_SA._v3b.fromArray(f[d+3]);D.y*=-1;D.applyQuaternion(P);if(e.y>D.y){const E=T;let e=1-E;s.z*=e;if(a.w>1)a.normalize();let t=2*Math.acos(a.w);s.x=s.x*e+Math.sign(s.x)*Math.abs(t)*(1-e)}}if(r)s.x=Math.max(s.x,r);a.setFromEuler(s,y);let _=e;let l=a.toAxisAngle();axis=l[0];angle=l[1];axis.z*=-1;let c=!MMD_SA.THREEX.enabled&&u==0?Math.min((Math.PI/8-Ye[g]._axis_rot_offset_inv_z*R)/(Math.PI/8),1.5):1;if(!MMD_SA.THREEX.enabled&&u==0)axis.applyEuler(MMD_SA.TEMP_v3.set(0,Math.PI/4*R*c,0));axis.applyEuler(qe.set(MMD_SA.THREEX.enabled?Math.PI/2:0,-Math.PI/2*R,0),"YXZ");if(u==0&&MMD_SA.THREEX.enabled){a.setFromAxisAngle(axis,angle)}else{if(u==0&&!MMD_SA.THREEX.enabled&&c<.5){axis.applyQuaternion(MMD_SA.TEMP_q.set(0,0,0,1).slerp(Ye[_].axis_rot,c/.5));if(c<.5)c=.5+(1-c/.5)}else{axis.applyQuaternion(Ye[_].axis_rot)}a.setFromAxisAngle(axis,angle)}if(d==b)a.premultiply(MMD_SA.TEMP_q.set(0,0,0,1).slerp(Ye[g].axis_rot_offset_inv,u==0?.5*c:1));if(ye[k]){if(d==h){const e=tt.skin[k+"手首"][0];if(!e._finger_x)e._finger_x=[];e._finger_x[u]=s.x}}else{tt.add("skin",e,{absolute:true,rot:a.clone()})}}})}else{const e=c.d;if(Me.motion_tracking_upper_body_only&&(!Me.motion_tracking?.hand_tracking?.stabilize_arm_disabled&&Be.stabilize_arm)&&tt.get_blend_default_motion("skin",e+(ye[e]?"足首":"手首"))!=0){c.visible=false}}})}else if(r){_.forEach(function(e,t){let i=t==0?"左":"右";if(d[i]){tt.add("skin",i+"手首",{after_IK:true,rot:d[i],onProcessRotation:N});tt.add("skin",i+"手捩",{after_IK:true,absolute:true,priority:1,no_blending:true,rot:new THREE.Quaternion})}})}const h={};const f={};_.forEach(function(e,t){let s=t==0?"左":"右";const o=Me.motion_tracking?.hand_tracking?.rotation_reference?.[s=="左"?"left":"right"];if(o){let a=o.weight||1;if(o.type=="object3D"){const i=MMD_SA.THREEX._XR_Animator_scene_.object3D_list.find(e=>e.id==o.name);if(!i)return;const n=MMD_SA.THREEX._object3d_list_.find(e=>e.uuid==i._object3d_uuid);if(n._rot_aligned_&&n.parent_bone.name==s+"手首"){if(n._rot_aligned_weight_!=null)a=n._rot_aligned_weight_}f[s]=o.weight_by_angle_difference;h[s]=o.constrained_direction}if(o.weight_by_magnet){const r=Me.motion_tracking.arm_tracking?.transformation?.position?.magnet?.find(e=>e.magnet_id==o.weight_by_magnet.id);a=r&&r._frame_count_>=EV_sync_update.count_frame-1-(Be.use_hands_worker?6:0)?r._weight_*(o.weight_by_magnet.max||a):0}if(!ce.find(e=>e.d==s)?.handpose?._used){a=1}a=Re[s].filter(a);m[s]=a;if(a){if(!tt.skin[s+"手首"]){const _=new THREE.Quaternion;tt.add("skin",s+"手首",{after_IK:true,rot:_,onProcessRotation:N});tt.add("skin",s+"手捩",{after_IK:true,absolute:true,priority:1,no_blending:true,rot:new THREE.Quaternion})}else if(tt.skin[s+"手首"][0].timestamp{i.forEach(e=>{const t=s+n+"指"+e;const i=c+n+"指"+e;let o=tt.skin[i]?.[0].rot;if(o){o=MMD_SA.TEMP_q.copy(o);o.y*=-1;o.z*=-1;if(!tt.skin[t]){tt.add("skin",t,{absolute:true,rot:o.clone()})}else{tt.skin[t][0].rot.slerp(o,a)}}})})}else if(o.fingers){for(const d in o.fingers){let[e,t]=d.split("|");e=l[e];t=i[parseInt(t)+(e=="親"?-1:0)];e=s+e+"指"+t;const p=tt.skin[e];if(p&&p[0].timestamp==RAF_timestamp){const u=o.fingers[d];let e=MMD_SA.TEMP_q;if(u.w==null){e=MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.copy(u).multiplyScalar(Math.PI/180));u.x=e.x;u.y=e.y;u.z=e.z;u.w=e.w}else{e.copy(u)}p[0].rot.slerp(e,a)}}}}}}});for(const j of["左","右"]){const w=tt.skin[j+"手首"];if(w){w[0]._rot_pose=d[j];w[0]._rot_pose_ratio=m[j];w[0]._rot_pose_constrained=h[j];w[0]._rot_pose_ratio_by_angle_difference=f[j];if(!w[0]._finger_x)w[0]._finger_x=w[1]._finger_x}}const y=[];le.forEach(function(n){var a=n.d;const t=new THREE.Vector3;if(n.use_filter){const i=xe[a].filters[0].filter;const o=se[a].filters[0].filter;for(const e of["minCutOff","beta","dCutOff"])o[e]=i[e];t.fromArray(se[a].filter([n.pos.x,n.pos.y,n.pos.z]))}else{se[a].filter(null,true);t.copy(n.pos)}let s=Me.motion_tracking?.hand_tracking?.depth_adjustment_disabled?0:MMD_SA_options.user_camera.ML_models.hands.depth_adjustment_percent/100;if(s&&Be.enabled&&pe&&MMD_SA_options.Dungeon_options?.item_base.hand_camera?._hand_camera_side!=a){let i=re[a].filter();let e=(RAF_timestamp-re[a].timestamp)/1e3;let o=1-Math.min(Math.max(e-.2,0)/(1-.2),1);const r=L.para.spine_length/5;if(n.pos.z>=0){if(o){let e=_e.filter();s*=o*e;let t=i*MMD_SA_options.model_para_obj.left_arm_length*s+n.pos.z*(1-s);n.pos.z=t}}if(n.pos.z_)n.pos.z=Math.sign(n.pos.z)*_}if(n.use_filter){const e=xe[a].filter([n.pos.x,n.pos.y,n.pos.z]);n.pos.x=e[0];n.pos.y=e[1];n.pos.z=e[2]}if(ye[a]){if(n.IK_disabled)return;Ce.enable_IK(a+"足IK",true);if(tt.skin[a+"手首"]&&tt.skin[a+"腕"]&&tt.skin[a+"手首"][0].timestamp==tt.skin[a+"腕"][0].timestamp){let e;if(e){}else{const d=MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.set(Math.PI/2,0,0));const p=tt.skin[a+"手首"][0].rot.premultiply(d).multiply(d.conjugate());if(tt._skin[a+"足IK"])tt._skin[a+"足IK"]._foot_={rot:p.clone(),_finger_x:tt.skin[a+"手首"][0]._finger_x};tt.add("skin",a+"足首",{after_IK:true,rot:p,_finger_x:tt.skin[a+"手首"][0]._finger_x,absolute:true,onFinish:De})}}else{const u=tt.skin[a+"足首"];if(u){u[0].rot_parent=u[0]._rot_parent}}tt.remove("skin",a+"手首");tt.remove("skin",a+"腕");tt.remove("skin",a+"ひじ");tt.remove("skin",a+"手捩");tt.remove("skin",a+"腕IK");if(Be.enabled){Qe.forEach((t,e)=>{let i=e==0?0:1;for(let e=i;ee.d==a);if(!e?.visible){if(tt.skin[a+"足首"]&&tt.get_blend_default_motion("skin",a+"足首")%1==0)delete tt.skin[a+"足首"][0].onFinish}const l=(new THREE.Vector3).copy(n.pos);const t=M.transformation?.position;const c=Q(a+"足IK",l,t,e=>{const t=MMD_SA_options.model_para_obj.left_leg_length;e.y+=t*1/3;e.z+=t*.25;e.multiplyScalar(1.5)});y.push({d:a,pos:l,rot:c[1]})}else{Ce.enable_IK(a+"腕IK",!n.IK_disabled);if(!n.IK_disabled){if(n.pos.z==null)n.pos.z=n.pos.z_posenet||(Ce.use_3D_pose?0:MMD_SA_options.model_para_obj.left_arm_length*.2);const m=ce.find(e=>e.d==a);const h=(new THREE.Vector3).copy(n.pos);let e=Me.motion_tracking?.arm_tracking?.off_screen_allowed?.[a=="左"?"left":"right"];tt.add("skin",a+"腕IK",{priority:999,pos:h,_IK_absolute:n.IK_absolute,_hand_visible:e||m?.visible,_pos0:t,onProcessPosition:V});const f=tt.skin[a+"腕IK"];if(!f[1]._pos0)f[1]._pos0=f[0]._pos0;if(f[0]!=f[1]&&f[0]._blending_ratio)f[0]._pos0.lerp(f[1]._pos0,1-f[0]._blending_ratio)}const e=tt.skin[a+"手首"];if(e){e[0].rot_parent=e[0]._rot_parent}}});if(y.length&&M.transformation?.position?.process)M.transformation.position.process(y);y.forEach(e=>{const t=e.d;const i=e.pos;i.y+=MMD_SA_options.model_para_obj.left_leg_IK[1]+(n["センター"].position.y-n["センター"].pmxBone.origin[1]);if(e.rot){tt.add("skin",t+"足",{absolute:true,rot:e.rot,onFinish:function(e,t){this.skin[t][0]._rot_=e.bones_by_name[t].quaternion.clone()}})}else{tt.remove("skin",t+"足")}tt.remove("skin",t+"ひざ");tt.add("skin",t+"足IK",{absolute:true,priority:999,pos:i})});if(Ne){if(Me.motion_tracking_upper_body_only){for(const j of["左","右"]){Ce.enable_IK(j+"腕IK",Me.has_arm_IK)}}}else if(Me.motion_tracking_upper_body_only){for(const j of["左","右"]){let e=Me.motion_tracking?.arm_tracking?.off_screen_allowed?.[j=="左"?"left":"right"];const w=ce.find(e=>e.d==j);const S=e?false:!w?.visible;if(ye[j]){tt.set_blend_default_motion("skin",j+"足IK",S);tt.set_blend_default_motion("skin",j+"足",S);tt.set_blend_default_motion("skin",j+"ひざ",S);tt.set_blend_default_motion("skin",j+"足首",S)}else{if(Me.has_leg_IK){tt.set_blend_default_motion("skin",j+"足IK",true);tt.remove("skin",j+"足首")}else{tt.set_blend_default_motion("skin",j+"足",true);tt.set_blend_default_motion("skin",j+"ひざ",true);tt.set_blend_default_motion("skin",j+"足首",true)}Ce.enable_IK(j+"足IK",Me.has_leg_IK);Ce.enable_IK(j+"つま先IK",Me.has_leg_IK);tt.set_blend_default_motion("skin",j+"肩",S);tt.set_blend_default_motion("skin",j+"腕",S);tt.set_blend_default_motion("skin",j+"ひじ",S);tt.set_blend_default_motion("skin",j+"手捩",S);tt.set_blend_default_motion("skin",j+"手首",S);tt.set_blend_default_motion("skin",j+"腕IK",S);if(Be.enabled){Qe.forEach((t,e)=>{let i=e==0?0:1;for(let e=i;e{DEBUG_show((Ce.use_holistic&&"(no facemesh data)\n"||"")+(Oe?"\n"+Oe+"\n":"")+He+"\n"+"FPS:"+EV_sync_update.fps_last)},0,0)}if(he.facemesh){Fe.worker_onmessage({data:he.facemesh})}if(Fe.draw_canvas&&me&&Fe.worker_initialized){let e={posenet:me,w:je.video_canvas.width,h:je.video_canvas.height,flip_canvas:je.display_flipped};if(he.handpose&&he.handpose.length)e.handpose=he.handpose;if(he.facemesh)e.facemesh=he.facemesh.faces;if(Ce.use_holistic||!Fe.enabled){e.draw_canvas=true;if(self.FacemeshAT){e.canvas=je.video_canvas_facemesh}else if(!je.video_canvas_facemesh._offscreen&&self.OffscreenCanvas){e.canvas=je.video_canvas_facemesh.transferControlToOffscreen();je.video_canvas_facemesh._offscreen=true;console.log("(Facemesh: use offscreen canvas)")}}Le.postMessage(e,e.canvas?[e.canvas]:undefined)}if(!Fe.draw_canvas){Fe.wireframe._data.pose=me;if(he.handpose)Fe.wireframe._data.handpose=he.handpose;if(he.facemesh)Fe.wireframe._data.facemesh=he.facemesh.faces;if(he.facemesh){Fe.wireframe._data.bb={x:0,y:0,w:je.video_canvas.width,h:je.video_canvas.height}}}ot=0}D()}}();function D(e){async function t(){var e=Ce.enabled&&Ce.worker_initialized&&k&&!Ce.busy&&R&&Ce.camera_video_timestamp!=k;if(!e)return;ot=RAF_timestamp;Ce.camera_video_timestamp=k;Ce.camera_video_frame_id=P;if(Ce.use_holistic){Fe.camera_video_timestamp=k;Fe.camera_video_frame_id=P}if(Ce.use_holistic&&Fe.blink_detection){MMD_SA_options.auto_blink=Fe.auto_blink||false}let t,i,o;t=je.video_canvas;i=t.width;o=t.height;let n=self.PoseAT?t:T?await createImageBitmap(t):t.getContext("2d").getImageData(0,0,i,o).data.buffer;let a=!Ce.use_holistic&&(!MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only||System._browser.camera.handpose.constrain_tracking_region);Ce._timestamp=je.video_timestamp;let s={rgba:n,w:i,h:o,options:{video_flipped:je.video_flipped,use_canvas_hands:a,use_holistic:Ce.use_holistic,use_holistic_landmarker:Ce.use_holistic_landmarker,use_holistic_legacy:Ce.use_holistic_legacy,use_posenet:true,use_handpose:Be.enabled,use_hands_worker:Be.use_hands_worker,skip_hand_countdown_max:Ce.skip_hand_countdown_max,model_quality:MMD_SA_options.user_camera.ML_models.pose.model_quality||"",z_depth_scale:MMD_SA_options.user_camera.ML_models.pose.z_depth_scale,timestamp:Ce._timestamp}};Object.assign(s.options,MMD_SA.MMD.motionManager.para_SA.motion_tracking?.hand_tracking?.mocap_options);let r=[s.rgba];if(!Ce.canvas_hands){const _=Ce.canvas_hands=document.createElement("canvas");_.width=_.height=768;s.canvas_hands=_.transferControlToOffscreen();r.push(s.canvas_hands)}if(Be.use_hands_worker&&!Be.canvas_hands_worker){const _=Be.canvas_hands_worker=document.createElement("canvas");_.width=_.height=768;s.canvas_hands_worker=_.transferControlToOffscreen();r.push(s.canvas_hands_worker)}L.postMessage(s,r);r.length=0;r=undefined;s.rgba=n=undefined;s=undefined}if(e||self.PoseAT){setTimeout(()=>{t()},0)}else{t()}}var S=function(){const r=()=>{};var _,l;var Me={};var ye={},ge={},be={};var ve={};var we,Se;window.addEventListener("jThree_ready",e=>{_=new THREE.Vector3;l=new THREE.Quaternion;for(const t of["センター","上半身","上半身2","首","頭"]){Me[t]=new THREE.Quaternion}for(const i of["左","右"]){ve[i]={target:new THREE.Vector3,arm_pos:new THREE.Vector3};ye[i]={target:new THREE.Vector3,effector:new THREE.Quaternion,links:[]};ge[i]={effector:new THREE.Quaternion,links:[]};be[i]={effector:new THREE.Quaternion,parent:new THREE.Quaternion,links:[]};for(let e=0;e<2;e++){ye[i].links[e]=new THREE.Quaternion;ge[i].links[e]=new THREE.Quaternion;be[i].links[e]=new THREE.Quaternion}}we=new System._browser.data_filter([{type:"one_euro",id:"hip_rot",para:[30,1,.2,.2,4]}]);Se=new System._browser.data_filter([{type:"one_euro",id:"hip_mov",para:[30,1,.2,.2,3]}])});let c=250;let d=500;let p=0;function e(e,t,i){if(!this[e][t])return 0;const o=this[e][t][0];let n;if(o._blend_default_motion>0){n=Math.min((RAF_timestamp-o._blend_default_motion)/(d*Ce.limb_return_duration_percent/100),1)}else if(o._blend_default_motion<0){n=1-Math.min((RAF_timestamp+o._blend_default_motion)/(c*Ce.limb_entry_duration_percent/100),1)}else{n=0}if(n==0){this[e][t].forEach(e=>{if(e._blend_default_motion!=null)e._blend_default_motion=0})}else if(i){n=n<.5?(1-Math.cos(n*Math.PI))*.5:.5+Math.sin((n-.5)*Math.PI)*.5}return n}function t(e,t,i,o){if(!this[e][t]){if(!i)return;const n=t.indexOf("IK")!=-1;const a={_blend_default_motion:i?1:0};if(n)a.pos=new THREE.Vector3;else a.rot=new THREE.Quaternion;this.add("skin",t,a)}else{const s=this[e][t][1];if(i){if(this.reset_to_default_motion_once||s._blend_default_motion==null){s._idle_blend_default_motion=0;s._blend_default_motion=1}else if(s._blend_default_motion==0){if(!s._idle_blend_default_motion)s._idle_blend_default_motion=RAF_timestamp;if(RAF_timestamp-s._idle_blend_default_motion>=(typeof o=="number"?o:p)){s._idle_blend_default_motion=0;s._blend_default_motion=RAF_timestamp-RAF_timestamp_delta}}else if(s._blend_default_motion<0){s._blend_default_motion=RAF_timestamp-this.get_blend_default_motion(e,t)*(d*Ce.limb_return_duration_percent/100)}}else{s._idle_blend_default_motion=0;if(s._blend_default_motion>0){s._blend_default_motion=-(RAF_timestamp-(1-this.get_blend_default_motion(e,t))*(c*Ce.limb_entry_duration_percent/100))}}this[e][t][0]._blend_default_motion=s._blend_default_motion;this[e][t][0]._idle_blend_default_motion=s._idle_blend_default_motion}if(!this["_"+e][t])this["_"+e][t]={pos:new THREE.Vector3,rot:new THREE.Quaternion}}const i=new RegExp("("+toRegExp(["腕"],"|")+")$");function Ae(i,o){const e=THREE.MMD.getModels()[i._model_index];const n=MMD_SA.motion[e.skin._motion_index].para_SA;let t;const a=i.bones_by_name;const s=a[o];const r=this.skin[o];if(Ce.enabled&&!Ce.data_detected_stable)return;if(r[0].info[1]=="facemesh"){}let _,l;r[0].t_delta+=RAF_timestamp_delta;let c=Math.max(Math.min(r[0].t_delta/r[0].t_delta_frame,1),0);if(r[0].rot){if(r[0].after_IK){t=!s._update_IK_and_AddTrans||s._update_IK_and_AddTrans.length;if(t){if(s.quaternion.x||s.quaternion.y||s.quaternion.z){s.quaternion.conjugate();e._update_IK_and_AddTrans(false,o);s.quaternion.conjugate()}}}if(r[0].onProcessRotation){r[0].onProcessRotation.call(this,i,o)}else{let t=Xe.set(0,0,0,1);if(r[0].absolute){s.quaternion.set(0,0,0,1)}else{let e;if(n.motion_tracking_upper_body_only){if(o.indexOf("上半身")!=-1){e=n.motion_tracking?.motion_default_weight?.upper_body}else if(o.indexOf("肩")!=-1){e=n.motion_tracking?.motion_default_weight?.shoulder}}if(e==null)e=1;if(e<1)s.quaternion.slerp(MMD_SA.TEMP_q.set(0,0,0,1),1-e)}if(r[0].parent_based){let e=r[0].rot_parent;if(!e){e=MMD_SA.get_bone_rotation_parent(i,o,i).conjugate()}r[0]._rot_parent=e;t.copy(e)}t.multiply(r[0].no_blending?r[0].rot:MMD_SA.TEMP_q.copy(r[1].rot).slerp(r[0].rot,c));const p=r[0].ratio_euler;if(p){const m=MMD_SA.TEMP_v3.setEulerFromQuaternion(t,p.order);const h=r[0].ratio<1?r[0].ratio:1;m.x*=p.x*h;m.y*=p.y*h;m.z*=p.z*h;t.setFromEuler(m,p.order)}else if(r[0].ratio<1){t.slerp(Ue.set(0,0,0,1),1-r[0].ratio)}const u=MMD_SA_options.model_para_obj_all[i._model_index].skin_default[o];if(u&&u.rot_scale){if(typeof u.rot_scale=="number")u.rot_scale={x:u.rot_scale,y:u.rot_scale,z:u.rot_scale};t.setFromEuler(MMD_SA.TEMP_v3.setEulerFromQuaternion(t,"YXZ").multiply(u.rot_scale),"YXZ")}s.quaternion.multiply(t);_=it.active&&!r[0].motion_recorder_disabled&&o.indexOf("IK")==-1}}if(r[0].pos){if(r[0].onProcessPosition){r[0].onProcessPosition.call(this,i,o)}else{if(r[0].absolute)s.position.set(0,0,0);const f=MMD_SA.TEMP_v3.copy(r[1].pos).lerp(r[0].pos,c);s.position.add(f);l=it.active&&!r[0].motion_recorder_disabled&&o.indexOf("IK")==-1}}r[0].onFinish&&r[0].onFinish.call(this,i,o);if(_)it.set_boneKey(o,null,s.quaternion,true);if(l)it.set_boneKey(o,qe.copy(s.position).sub(Te.fromArray(o=="センター"?MMD_SA.THREEX.get_model(i._model_index).get_bone_origin_by_MMD_name("センター",true):s.pmxBone.origin)),null,true);let d=this.get_blend_default_motion("skin",o,true);if(d){if(r[0].rot&&this._skin[o]?.rot){const M=MMD_SA.TEMP_q.copy(this._skin[o].rot);s.quaternion.slerp(this._skin[o].onProcessRotation&&this._skin[o].onProcessRotation.call(this,i,o,M)||M,d)}if(r[0].pos&&this._skin[o]?.pos){s.position.lerp(this._skin[o].pos,d)}if(it.active&&!r[0].motion_recorder_disabled){if(o.indexOf("IK")!=-1)it.set_boneKey(o,r[0].pos&&s.position,r[0].rot&&s.quaternion,false)}}t&&e._update_IK_and_AddTrans(false,o)}var De=0;function o(e){function t(){if(P)return;P=Me;for(const e of["センター","上半身","上半身2","首"]){const t=this.skin[e];if(!t){P[e].set(0,0,0,1);continue}if(e=="首"){P[e].copy(t[0]._rot_neck||t[1]._rot_neck||MMD_SA._q1.set(0,0,0,1));P["頭"].copy(t[0]._rot_head||t[1]._rot_head||MMD_SA._q1.set(0,0,0,1))}else{const i=MMD_SA._q1.set(0,0,0,1);const o=Math.max(Math.min((t[0].t_delta+RAF_timestamp_delta)/t[0].t_delta_frame,1),0);i.multiply(t[0].no_blending?t[0].rot:MMD_SA.TEMP_q.copy(t[1].rot).slerp(t[0].rot,o));if(t[0].ratio<1)i.slerp(MMD_SA._q2.set(0,0,0,1),1-t[0].ratio);P[e].copy(i)}}R=st.copy(P["センター"]).multiply(P["上半身"]).multiply(P["上半身2"]).conjugate()}let L,C,B,D;function H(n){function a(){if(L==RAF_timestamp)return;L=RAF_timestamp;const e=MMD_SA.TEMP_q.copy(this._body_motion_rot[0]["上半身"]).multiply(this._body_motion_rot[0]["上半身2"]);B=1;C=at.copy(R).conjugate().premultiply(e.conjugate().multiply(nt.copy(this._body_motion_rot[1]["上半身"]).multiply(this._body_motion_rot[1]["上半身2"]))).conjugate();const t=C.toAxisAngle();D=t[1]%(Math.PI*2);if(Math.abs(D)>Math.PI)D-=Math.sign(D)*Math.PI*2;D*=2/3;if(Math.abs(D)>Math.PI/4)D=Math.sign(D)*Math.PI/4}const e=["センター","上半身","上半身2","首","頭"];let o;const s=T&&T.parent;const r=qe.set(0,0,0);if(s){const M=s.name||n+"足";const y=M.charAt(0);const g=1-this.get_blend_default_motion("skin",M.indexOf("足")!=-1?y+"足IK":M,true);let t,i;switch(M){case"頭":o=g&&this.skin["首"];if(o){for(const M of["首","頭"])k[M].quaternion.copy(P[M]);t=MMD_SA.get_bone_position(E,"頭","首").add(Te.set(0,.75,.75).applyQuaternion(MMD_SA.TEMP_q.copy(k["首"].quaternion).multiply(k["頭"].quaternion)));k["首"].quaternion.copy(this._body_motion_rot[0]["首"]);k["頭"].quaternion.copy(this._body_motion_rot[0]["頭"]);i=MMD_SA.get_bone_position(E,"頭","首").add(Te.set(0,.75,.75).applyQuaternion(MMD_SA.TEMP_q.copy(k["首"].quaternion).multiply(k["頭"].quaternion)))}break;case"左足":case"右足":o=g;if(o){if(!ge[y].updated){ye[y].enabled=true;o=false}}else{ye[y].enabled=false;ge[y].updated=0}if(o){const b=Te.fromArray(k[n+"ひざ"].pmxBone.origin).sub(Ie.fromArray(k[M].pmxBone.origin));t=Ie.copy(b).applyQuaternion(Xe.copy(be[y].parent).multiply(be[y].links[1]));i=b.applyQuaternion(Xe.copy(be[y].parent).multiply(ge[y].links[1]))}break}if(o){o=M;r.copy(t).sub(i);let e=s.weight||.5;if(typeof e=="object"){r.x*=r.x<0?e.x.left:e.x.right;r.y*=r.y<0?e.y.down:e.y.up;r.z*=r.z<0?e.z.backward:e.z.forward}else{r.multiplyScalar(e)}r.multiplyScalar(g)}}let t,i,_;for(const M of e)k[M].quaternion.copy(this._body_motion_rot[0][M]);const l=x.motion_tracking?.arm_tracking?.elbow_lock?.[n=="左"?"left":"right"];if(l){l._elbow_y=l.y_absolute!=null?l.y_absolute:MMD_SA.get_bone_position(E,n+"ひじ",E).y+(l.y||0)}if(!o||o!="頭"){t=MMD_SA.get_bone_position(E,n+"腕",E);_=MMD_SA.get_bone_rotation_parent(E,n+"腕IK",E);i=!x.has_arm_IK?MMD_SA.get_bone_position(E,n+"手首",E):(new THREE.Vector3).copy(k[n+"腕IK"].position).sub(MMD_SA_options.model_para_obj.arm_IK_offset[n]).applyQuaternion(_).add(t);_.conjugate()}for(const M of e)k[M].quaternion.copy(this._body_motion_rot[1][M]);if(!t){t=MMD_SA.get_bone_position(E,n+"腕",E);_=MMD_SA.get_bone_rotation_parent(E,n+"腕IK",E);i=!x.has_arm_IK?MMD_SA.get_bone_position(E,n+"手首",E):(new THREE.Vector3).copy(k[n+"腕IK"].position).sub(MMD_SA_options.model_para_obj.arm_IK_offset[n]).applyQuaternion(_).add(t);_.conjugate()}for(const M of["センター","上半身","上半身2"]){let e;if(M.indexOf("上半身")!=-1)e=x.motion_tracking?.motion_default_weight?.upper_body;if(e==null)e=1;if(this.skin[M]){if(e<1)k[M].quaternion.slerp(MMD_SA.TEMP_q.set(0,0,0,1),1-e);k[M].quaternion.multiply(P[M])}}let c=T&&T.default_position_weight;if(typeof c!="number")c=.5;const d=MMD_SA.get_bone_rotation_parent(E,n+"腕IK",E).conjugate();let p;let u=x.motion_tracking?.arm_tracking?.IK_constraint;if(u)u=u[n=="左"?"left":"right"]||u;if(u&&this.skin[n+"腕IK"]&&this.get_blend_default_motion("skin",n+"腕IK")<1){const v=ve[n];v.enabled=true;v.target.copy(i);v.target_radius=0;if(u.target_offset){const w=qe.fromArray(u.target_offset);v.target.add(w);v.target_radius=w.length()}if(u.target_radius)v.target_radius+=u.target_radius;p=MMD_SA.get_bone_position(E,n+"腕",E);v.arm_pos.copy(p)}p=c==0?t:(p||MMD_SA.get_bone_position(E,n+"腕",E)).lerp(t,1-c);const m=p.sub(i);if(c<1)d.slerp(_,1-c);if(o&&o.indexOf("足")!=-1){r.applyQuaternion(d)}const h=je.x_flipped?-1:1;m.x*=h;m.y*=-1;m.z*=-1;if(o&&o=="頭"){m.applyQuaternion(d)}else{m.applyQuaternion(d)}if(!this._skin[n+"腕IK"])this._skin[n+"腕IK"]={pos:new THREE.Vector3,rot:new THREE.Quaternion};if(!this._skin[n+"腕IK"].rot_parent_inv)this._skin[n+"腕IK"].rot_parent_inv=new THREE.Quaternion;this._skin[n+"腕IK"].rot_parent_inv.copy(d).conjugate();m.add(MMD_SA_options.model_para_obj.arm_IK_offset[n]);m.add(r);for(const M of e)k[M].quaternion.copy(this._body_motion_rot[1][M]);const f=this.skin[n+"手首"];if(f){if(K){f[0].after_IK=true;if(this._skin[n+"手首"])this._skin[n+"手首"]._rot_absolute=MMD_SA.get_bone_rotation(E,n+"手首",false,E)}if(this._skin[n+"手首"])this._skin[n+"手首"].onProcessRotation=O;if(this._skin[n+"手捩"])this._skin[n+"手捩"].onProcessRotation=q}if(this._skin[n+"腕"]){a.call(this);let e=Math.min(c*2,1);let t=Math.abs(D/(Math.PI/4))*e*B;const S=n=="左"?1:-1;let i=S*Math.PI/4*t;let o=nt.set(0,Math.sin(i),0,Math.cos(i));const A=Ye[n+"腕"];o.premultiply(A.axis_rot).multiply(A.axis_rot_inv);this._skin[n+"腕"].rot.premultiply(o)}return m}function O(e,t,i){const o=t.charAt(0);const n=x.motion_tracking&&x.motion_tracking.arm_default_stickiness&&(x.motion_tracking.arm_default_stickiness[o]||x.motion_tracking.arm_default_stickiness).default_rotation_weight;if(!n)return i;const a=MMD_SA.get_bone_rotation_parent(e,t,e).conjugate();const s=a.multiply(this._skin[t]._rot_absolute);return s.slerp(i,1-n)}function q(e,t,i){return i.set(0,0,0,1)}function i(){if(Ce.data_detected){Ee();System._browser.on_animation_update.remove(i,0)}}const o=e.detail.model;const X=MMD_SA.THREEX.get_model(o._model_index);const U=X.is_T_pose;const E=o.mesh;const k=E.bones_by_name;const x=MMD_SA.motion[o.skin._motion_index].para_SA;for(const a of["左","右"]){const s=x.motion_tracking?.hand_tracking?.rotation_reference?.[a=="左"?"left":"right"];if(!s)continue;hand_f=tt.skin[a+"手首"]?.[0];if(!hand_f||!hand_f._rot_pose_ratio)continue;let e;if(s.type=="object3D"){const r=MMD_SA.THREEX._XR_Animator_scene_.object3D_list.find(e=>e.id==s.name);if(!r)return;const _=MMD_SA.THREEX._object3d_list_.find(e=>e.uuid==r._object3d_uuid);if(_._rot_aligned_&&_.parent_bone.name==a+"手首"){e=_._rot_aligned_}else{e=_._mesh.quaternion.clone()}if(s.offset){if(s.offset=="parent_bone"){const W=MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.set(-_.parent_bone.rotation.x,-_.parent_bone.rotation.y,_.parent_bone.rotation.z).multiplyScalar(Math.PI/180),"YXZ").toAxisAngle();e.multiply(MMD_SA.TEMP_q.setFromAxisAngle(W[0].applyQuaternion(Xe.copy(Ze[a=="左"?1:-1]).conjugate()),W[1]))}else{if(s.offset.w==null){const l=MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.copy(s.offset).multiplyScalar(Math.PI/180),s.offset.order);s.offset.x=l.x;s.offset.y=l.y;s.offset.z=l.z;s.offset.w=l.w}e.multiply(MMD_SA.TEMP_q.copy(s.offset))}}}else{if(s.rotation){if(s.rotation.w==null){const l=MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.copy(s.rotation).multiplyScalar(Math.PI/180));s.rotation.x=l.x;s.rotation.y=l.y;s.rotation.z=l.z;s.rotation.w=l.w}e=MMD_SA.TEMP_q.copy(s.rotation)}}if(!hand_f._rot_pose)hand_f._rot_pose=new THREE.Quaternion;if(e){hand_f._rot_pose.copy(e)}else{hand_f._rot_pose.set(0,0,0,1)}}if(!this._reset_disabled&&this._motion_path&&(this._motion_path!=x._path||this._motion_tracking_upper_body_only!=!!x.motion_tracking_upper_body_only)){this._motion_path=x._path;this._motion_tracking_upper_body_only=!!x.motion_tracking_upper_body_only;this.reset();ke();Ce.data_detected=0;Ce.initial_data_detected=false;System._browser.on_animation_update.remove(i,0);System._browser.on_animation_update.add(i,0,0,-1);return}this._motion_path=x._path;this._motion_tracking_upper_body_only=!!x.motion_tracking_upper_body_only;if(it.enabled&&De!=Ce.data_detected){De=Ce.data_detected;it.timestamp_for_recording=RAF_timestamp;if(it.active)window.dispatchEvent(new CustomEvent("SA_motion_recorder_on_active",e))}for(const a of["左","右"]){this.arm_IK_constraint[a].enabled=false}rt.copy(this.get_upper_body_rotation()).multiply(this._rot_body_camera_offset);this.upper_body_rotation_limiter(rt);let P,R,T,K;if((Ce.enabled||Fe.enabled)&&x.motion_tracking_upper_body_only){const c=x.motion_tracking&&x.motion_tracking.arm_as_leg;const d={"左":c&&c.enabled&&(!c.linked_side||c.linked_side=="left"),"右":c&&c.enabled&&(!c.linked_side||c.linked_side=="right")};for(const m in this._skin){this._skin[m].pos.copy(k[m].position);this._skin[m].rot.copy(k[m].quaternion)}for(const a of["左","右"]){if(tt._skin[a+"腕"])tt._skin[a+"腕"].pos_local=MMD_SA.get_bone_position(E,a+"腕",E)}const p=Ce.hip_adjustment_weight_percent/100;let e=p&&(Ce.data_detected||!Ce.enabled&&Fe.data_detected);let o,n;if(e){t.call(this);const h=Xe.copy(R);const u=x.motion_tracking?.ML_models?.pose||MMD_SA_options.user_camera.ML_models.pose;if(u.upper_rotation_offset){const V=u.upper_rotation_offset*Math.PI/180;h.premultiply(MMD_SA.TEMP_q.set(0,Math.sin(V/2),0,Math.cos(V/2)))}h.conjugate();const Q=x.motion_tracking?.hip_adjustment?.rotation_weight;o=(new THREE.Quaternion).copy(h).slerp(Ue.set(0,0,0,1),1-(typeof Q=="number"?Q:.5)*p);let i=Ce.hip_adjustment_smoothing_percent/100;if(i)i=.1+(1-i)*(1-i)*.9;if(i){we.filters[0].filter.minCutOff=i;o.fromArray(we.filter(o.toArray()))}this.remove("skin","下半身");this.add("skin","下半身",{no_blending:true,rot:o});if(this.skin["センター"]){let e=x.motion_tracking?.hip_adjustment?.displacement_weight;if(e==null)e=.25;const f=qe;const M=Te;if(typeof e=="number"){if(e){e*=p;f.set(0,MMD_SA_options.model_para_obj.left_leg_length/3*e,0);M.set(-1,1,-1)}}else{f.copy(e.axis||MMD_SA.TEMP_v3.set(0,e.weight,0)).multiplyScalar(MMD_SA_options.model_para_obj.left_leg_length/3*p);M.copy(e.scale)}M.x*=Ce.hip_adjustment_scale_x_percent/100;M.y*=Ce.hip_adjustment_scale_y_percent/100;M.z*=Ce.hip_adjustment_scale_z_percent/100;const N=Ce.hip_adjustment_adjust_y_axis_percent/100;if(N&&!e.axis){const Y=Math.PI/4*N;const Z=f.y;f.y=Z*Math.cos(Y);f.z=Z*Math.sin(Y)}if(e){axis_default=Ie.copy(f);let e=MMD_SA.TEMP_v3.setEulerFromQuaternion(P["首"],"YZX");e.x*=Ce.hip_adjustment_head_pitch_rotation_percent/100;h.multiply(MMD_SA.TEMP_q.set(0,0,0,1).slerp(MMD_SA._q1.setFromEuler(e,"YZX"),Ce.hip_adjustment_head_weight_percent/100));f.applyQuaternion(h);f.sub(axis_default).multiply(M);if(i){Se.filters[0].filter.minCutOff=i;f.fromArray(Se.filter(f.toArray()))}const $=MMD_SA_options.model_para_obj.left_leg_length*.1;if(f.y>0)f.y=Math.pow(Math.min(f.y/($*4),1),.5)*$;let t=x.motion_tracking?.hip_adjustment?.knee_fixed_weight;if(t){const y=new THREE.Vector3;for(const a of["左","右"]){const g=MMD_SA.get_bone_position(E,a+"ひざ","全ての親");const J=Ke.copy(k["下半身"].quaternion);const ee=MMD_SA.get_bone_position(E,a+"足","全ての親");k["下半身"].quaternion.multiply(o);k["センター"].position.add(f);const te=MMD_SA.get_bone_position(E,a+"足","全ての親");const b=Ie.copy(g).sub(ee);const ie=b.length();b.normalize();const v=ze.copy(g).sub(te);const oe=v.length();v.normalize();const ne=MMD_SA._q1.copy(k["センター"].quaternion).multiply(J).conjugate();const ae=MMD_SA._v3a.copy(b).applyQuaternion(ne);const se=MMD_SA._q2.copy(k["センター"].quaternion).multiply(P["センター"]).multiply(k["下半身"].quaternion).conjugate();const re=MMD_SA._v3b.copy(v).applyQuaternion(se);const _e=MMD_SA.TEMP_q.setFromUnitVectors(ae,re);if(t<1)_e.slerp(nt.set(0,0,0,1),t);k[a+"足"].quaternion.multiply(_e);const le=v.multiplyScalar(ie).sub(g).negate();le.sub(te);y.add(le);k["下半身"].quaternion.multiply(MMD_SA.TEMP_q.copy(o).conjugate());k["センター"].position.sub(f)}y.multiplyScalar(.5*t);f.add(y)}this.skin["センター"][0].pos=(this.skin["センター"][0].pos||new THREE.Vector3).copy(f);this.skin["センター"][0]._hip_adjustment_offset=(this.skin["センター"][0]._hip_adjustment_offset||new THREE.Vector3).copy(f);this.skin["センター"][1].pos=this.skin["センター"][0].pos;n=this.skin["センター"][0].pos}}}for(const a of["左","右"]){const w=a=="左"?"left":"right";T=x.motion_tracking&&x.motion_tracking.arm_default_stickiness&&(x.motion_tracking.arm_default_stickiness[w]||x.motion_tracking.arm_default_stickiness);K=T&&T.default_rotation_weight;let i=x.motion_tracking?.hip_adjustment?.[w]?x.motion_tracking.hip_adjustment[w].feet_fixed_weight:x.motion_tracking?.hip_adjustment?.feet_fixed_weight;if(typeof i!="number")i=1;if(i<1||(e||d[a])&&!x.has_leg_IK){const m=a+"足IK";let e,t;if(o){e=Xe.copy(k["下半身"].quaternion);k["下半身"].quaternion.multiply(o)}if(n){t=qe.copy(k["センター"].position);k["センター"].position.add(n)}const ce=x.has_leg_IK?null:MMD_SA.get_bone_position(E,a+"足","全ての親");const S=i<1?MMD_SA.get_bone_position(E,a+"足首","全ての親"):Te;if(e)k["下半身"].quaternion.copy(e);if(n)k["センター"].position.copy(t);const A=x.has_leg_IK||i>0?MMD_SA.get_bone_position(E,a+"足首","全ての親"):S;const de=je.x_flipped?-1:1;if(x.has_leg_IK){const I=qe.copy(A).sub(S.lerp(A,i));I.x*=de;I.y*=-1;I.z*=-1;if(!this._skin[m])this._skin[m]={pos:new THREE.Vector3,rot:new THREE.Quaternion};this._skin[m].pos.add(I);k[m].position.add(I)}else{const pe=qe.fromArray(k[a+"足"].pmxBone.origin);const ue=pe.sub(ce).negate();const I=ce.sub(S.lerp(A,i));I.x*=de;I.y*=-1;I.z*=-1;I.add(MMD_SA_options.model_para_obj.leg_IK_offset[a]);I.add(ue);if(!this._skin[m])this._skin[m]={pos:new THREE.Vector3,rot:new THREE.Quaternion};this._skin[m].pos.copy(I);if(!d[a]){Ce.enable_IK(m,true);if(!this.skin[m])this.add("skin",m,{absolute:true,is_dummy:true,pos:true,priority:999})}else{Ce.enable_IK(a+"つま先IK",false)}k[m].position.copy(I);if(Ce.data_detected)k[a+"ひざ"].quaternion.set(0,0,0,1)}k[m].position.y+=this._skin[m]._offset_y_||0}if(d[a]){t.call(this);const I=H.call(this,a);k[a+"腕IK"].position.copy(I);Ce.enable_IK(a+"腕IK",true)}else{const m=a+"腕IK";let e;const me=this.skin[a+"手首"];if(me){t.call(this);if(!Ce.IK_disabled_check(m)){e=H.call(this,a)}else{if(this._skin[a+"腕"])this._skin[a+"腕"].rot.premultiply(R);if(this._skin[a+"手首"])this._skin[a+"手首"].rot.premultiply(MMD_SA.TEMP_q.copy(R).conjugate())}}if(e)this._skin[m].pos.copy(e)}if(ye[a].enabled){const he=k[a+"足IK"];const z=ye[a];z.target.copy(he.position);const j=he.pmxBone.IK;z.effector.copy(E.bones[j.effector].quaternion);for(let e=0;e{e.detail.result.links=z;e.detail.result.links_result=ge[a]},{once:true});window.addEventListener("SA_camera_poseNet_process_bones_onended",e=>{const t=be[a];t.parent.copy(MMD_SA.get_bone_rotation_parent(E,a+"足","全ての親"));t.effector.copy(E.bones[j.effector].quaternion);for(let e=0;e{const t=e.detail.model;const i=t.mesh.bones_by_name;let o=u.upper_rotation_offset*Math.PI/180;const n=MMD_SA.TEMP_q.set(0,Math.sin(o/2*-.5),0,Math.cos(o/2*-.5));i["上半身"].quaternion.premultiply(n);i["上半身2"].quaternion.premultiply(n);n.set(0,Math.sin(o/2),0,Math.cos(o/2));i["全ての親"].quaternion.premultiply(n);if(it.active){it.set_boneKey("上半身",null,i["上半身"].quaternion,false);it.set_boneKey("上半身2",null,i["上半身2"].quaternion,false);it.set_boneKey("全ての親",null,i["全ての親"].quaternion,false)}},{once:true})}if(it.active){window.addEventListener("SA_camera_poseNet_process_bones_onended",e=>{const t=e.detail.model;const a=t.mesh.bones_by_name;for(const n of["左","右"]){it.set_boneKey(n+"足",null,a[n+"足"].quaternion,false);it.set_boneKey(n+"ひざ",null,a[n+"ひざ"].quaternion,false);it.set_boneKey(n+"足首",null,a[n+"足首"].quaternion,false);if(a[n+"足先EX"])it.set_boneKey(n+"足先EX",null,a[n+"足先EX"].quaternion,false);for(const e of[n+"肩",n+"腕",n+"ひじ",n+"手首"]){if(a[e])it.set_boneKey(e,null,a[e].quaternion,false)}Qe.forEach((i,e)=>{let o=e==0?0:1;for(let t=o;tthis._z_max_timestamp+1e3?this._z_max||0:0,this._skin[m].pos.z)}window.dispatchEvent(new CustomEvent("SA_camera_poseNet_process_bones_onstart",e));var n=this.skin;var G=Object.keys(n).filter(e=>!n[e][0].after_IK).sort((e,t)=>{let i=n[e][0].priority||0;let o=n[t][0].priority||0;return i-o});G.forEach(e=>{let t=k[e];if(!t&&!/_DUMMY_/.test(e))return;var i=n[e][0].info[1];if((!i||/pose/.test(i))&&!x.motion_tracking_enabled)return;Ae.call(this,E,e)})}function n(e){var t=e.detail.model;var o=t.mesh;var n=MMD_SA.motion[t.skin._motion_index].para_SA;if(n.motion_tracking_upper_body_only){for(const s of["左","右"]){const r=n.motion_tracking?.arm_tracking?.elbow_lock?.[s=="左"?"left":"right"];if(r){const _=r._elbow_y!=null?r._elbow_y:null;if(_!=null)w(r,o,s)}}}var a=this.skin;var i=Object.keys(a).filter(e=>a[e][0].after_IK).sort((e,t)=>{let i=a[e][0].priority||0;let o=a[t][0].priority||0;return i-o});i.forEach(e=>{let t=o.bones_by_name[e];if(!t&&!/_DUMMY_/.test(e))return;var i=a[e][0].info[1];if((!i||/pose/.test(i))&&!n.motion_tracking_enabled)return;Ae.call(this,o,e)});window.dispatchEvent(new CustomEvent("SA_camera_poseNet_process_bones_onended",e))}function a(e){if(!Ce.use_head_mocap)return;var _=e.detail.model;var l=_.mesh;var c=_.morph.targets;_.pmx.morphs.forEach(function(e){if(e.panel!=3)return;var t=e.name;if(!_.pmx.morphs_weight_by_name[t])return;var i=_.morph.target_index_by_name[t];if(i==null)return;var o=c[i];var n=o.keys[0];if(n.morph_type==1){l.morphTargetInfluences[i]=0}else{let e={name:t,weight:0,morph_type:n.morph_type,morph_index:n.morph_index};_.morph.onupdate(e,e,0,i)}});var d=MMD_SA_options.model_para_obj.facemesh_morph;var p=this.morph;var u={};var n=0;Object.keys(p).forEach(function(e){let t=p[e];if(t.disabled)return;t[0].t_delta+=RAF_timestamp_delta;let i=Math.max(Math.min(t[0].t_delta/t[0].t_delta_frame,1),0);let o=t[0].weight*i+t[1].weight*(1-i);u[e]=o;if(o)n++});Object.keys(u).forEach(function(t){let e=p[t];let i=u[t];if(i<0){it.morph_active&&it.set_morphKey(t,0,true);switch(t){case"にやり":t="ω";break;case"口角上げ":t="口角下げ";break;case"上":t="下";break}i=-i}if(it.morph_active){let e=t;if(t=="まばたきL")e="ウィンク";else if(t=="まばたきR")e="ウィンク右";it.set_morphKey(e,i,true)}let o=d[t];let n=o&&o.name||t;let a=_.morph.target_index_by_name[n];if(a==null)return;i*=o&&o.weight||1;let s=c[a];let r=s.keys[0];if(r.morph_type==1){l.morphTargetInfluences[a]=i}else{let e={name:n,weight:i,morph_type:r.morph_type,morph_index:r.morph_index};_.morph.onupdate(e,e,0,a)}})}let u=0;let s=[];function m(e,t,i){function o(){u++}i.name=t;i.info=e.split("|");let n=i.info[0];let a=this[n][t];if(i.is_dummy){if(a&&a[0].is_dummy)return;i.no_blending=true;i.onProcessPosition=i.onProcessRotation=r;if(i.pos)i.pos=_;if(i.rot)i.rot=l}else{if(i.pos){if(isNaN(i.pos.x)||isNaN(i.pos.y)||isNaN(i.pos.z)){o();i.pos.copy(a?.[0].pos||new THREE.Vector3)}}if(i.rot){if(isNaN(i.rot.x)||isNaN(i.rot.y)||isNaN(i.rot.z)||isNaN(i.rot.w)){o();i.rot.copy(a?.[0].rot||new THREE.Quaternion)}}if(i.weight!=null){if(isNaN(i.weight)){o();i.weight=a?.[0].weight||0}}}const s=t.indexOf("指")!=-1||t.indexOf("手首")!=-1;i.timestamp=RAF_timestamp;i.t_delta=0;i.t_delta_frame=Be.enabled&&s&&this.t_delta_hands||this.t_delta||0;i.t_delta_frame=Math.max(Math.min(i.t_delta_frame,200),16.6667);if(it.speed){if(t.indexOf("指")!=-1){i.blending_ratio=.75}else{i.no_blending=true}}if(a){if(RAF_timestamp==a[0].timestamp){a[0]=Object.assign(a[0],i)}else{if(!i.no_blending&&!je.video.paused){let e=i._blending_ratio=i.blending_ratio||(Ce.use_3D_pose||i.info[1]=="facemesh"?.5+Math.max(Math.min((Math.max(i.t_delta_frame,RAF_timestamp-a[0].timestamp)-50)/150,1),0)*.5:1);if(e<1){if(i.pos&&a[0].pos){i.pos.lerp(a[0].pos,1-e)}if(i.rot&&a[0].rot){i.rot.slerp(a[0].rot,1-e)}if(i.weight!=null&&a[0].weight!=null){i.weight=i.weight*e+a[0].weight*(1-e)}}}this[n][t]=[i,a[0]]}i._blend_default_motion=a[1]._blend_default_motion;i._idle_blend_default_motion=a[1]._idle_blend_default_motion}else{this[n][t]=[i,i]}if(it.speed)i.no_blending=true}function h(e,t){delete this[e][t]}function f(){this.skin={};this.morph={};this._skin={};this._morph={};this.reset_to_default_motion_once=true;this._motion_path=""}function Ee(){window.addEventListener("SA_MMD_model"+this.model_num+"_process_morphs",this.process_morphs);window.addEventListener("SA_MMD_model"+this.model_num+"_process_bones_before_IK",this.process_bones);window.addEventListener("SA_MMD_model"+this.model_num+"_process_bones_after_IK",this.process_bones_after_IK)}function ke(){window.removeEventListener("SA_MMD_model"+this.model_num+"_process_morphs",this.process_morphs);window.removeEventListener("SA_MMD_model"+this.model_num+"_process_bones_before_IK",this.process_bones);window.removeEventListener("SA_MMD_model"+this.model_num+"_process_bones_after_IK",this.process_bones_after_IK)}var M=function(e){this.model_num=e;this.reset();this._body_motion_rot=[{},{}];this._rot_body_motion=new THREE.Quaternion;this._rot_body_camera=new THREE.Quaternion;this._rot_body_camera_offset=new THREE.Quaternion;this._rot_head_camera=new THREE.Quaternion;this._rot_head_camera_offset=new THREE.Quaternion;this._rot_body_offset=new THREE.Quaternion;this._rot_camera=new THREE.Quaternion;this._rot_camera_angle=0;this.process_bones=o.bind(this);this.process_bones_after_IK=n.bind(this);this.process_morphs=a.bind(this)};M.prototype.set_upper_body_rotation=function(e,t){if(!je.ML_enabled||this.model_num!=e)return;const i=THREE.MMD.getModels()[this.model_num].mesh.bones_by_name;for(const o of["センター","上半身","上半身2","首","頭"]){if(!i[o])continue;let e=this._body_motion_rot[t][o];if(!e)e=this._body_motion_rot[t][o]=new THREE.Quaternion;e.copy(i[o].quaternion)}};M.prototype.get_upper_body_rotation=function(){const e=THREE.MMD.getModels()[this.model_num].mesh.bones_by_name;this._rot_camera.setFromEuler(MMD_SA.TEMP_v3.set(MMD_SA._rx_last,MMD_SA._ry_last,0));this._rot_camera_angle=this._rot_camera.toAxisAngle()[1];const t=Xe.set(0,0,0,1);const i=Ue.set(0,0,0,1);for(const n of["センター","上半身","上半身2"]){t.multiply(this._body_motion_rot[0][n]||e[n].quaternion);i.multiply(this._body_motion_rot[1][n]||e[n].quaternion)}this._rot_body_camera.copy(t).conjugate().multiply(i);this._rot_body_camera_offset.copy(this._rot_body_camera).conjugate().multiply(this._rot_camera);this._rot_body_motion.copy(t);const o=Ke.copy(t).conjugate();return o};M.prototype.upper_body_rotation_limiter=function(t,i=Math.PI/3){var o=t.toAxisAngle();var n=o[1];this._rot_body_offset.set(0,0,0,1);if(Math.abs(n)>i){let e;if(Math.abs(n){S.prototype._q1=new THREE.Quaternion;S.prototype._q2=new THREE.Quaternion;tt=new S(0)});var it=function(){function _(e,t,i,o){this.name=e;this.pos=t&&t.toArray()||[0,0,0];this.rot=i&&i.toArray()||[0,0,0,1];this.time=o;c[e].index=l.boneKeys.length}function s(e,t,i){this.name=e;this.weight=t;this.time=i;r[e].index=l.morphKeys.length}var l;var c,r;var d=0;var o=0;var p=0;var u=0;var n;var a=0;var i=0;const m=2;return{timestamp_for_recording:0,get enabled(){return i&&!je.video.paused},get morph_active(){return Ce.enabled?this.enabled:this.active},get active(){if(!this.enabled)return false;if(this.timestamp_for_recording&&this.timestamp_for_recording!=RAF_timestamp)return false;if(n!=P){let e=1;if(n){e=this.get_frame(P)-this.get_frame(n);if(e<0||e>30)e=1;if(e>1){const t=e-1;o+=t;for(const i in c){c[i].frame_length+=t}for(const i in r){r[i].frame_length+=t}}}d+=e;n=P;a=RAF_timestamp}if(a==RAF_timestamp){return true}return false},get_frame:function(e){var t=e.split(":");return parseInt(t[0])*30+(parseInt(t[1])-1)},get frame_count(){return d},get stats(){return[o,l.boneKeys.length,l.morphKeys.length,p,u]},get time(){return Math.floor(d/30)+":"+(d%30+1)},get speed(){return i},set speed(e){i=e;if(e){this.start(e);MMD_SA.playbackRate=e}else{this.stop();MMD_SA.playbackRate=1}},get vmd(){return i?null:l},set vmd(e){l=null},set_boneKey:function(e,t,i,o){if(e.indexOf("腕IK")!=-1)return;let n=c[e];if(n==null){n=c[e]={frame_length:1};if(d>0)l.boneKeys.push(new _(e,null,null,0))}if(o&&tt.skin[e]&&n.timestamp==tt.skin[e][0].timestamp){let e;if(n.frame_count==d){const a=l.boneKeys[n.index];e=(!t||a.pos)&&(!i||a.rot)}else e=true;if(e){if(n.frame_count!=d){n.frame_length++;p++}return}}if(!t&&i&&n.is_rot_identity&&i.w==1){p++;return}n.is_rot_identity=i?i.w==1:n.is_rot_identity;if(n.frame_count==d){const a=l.boneKeys[n.index];if(t)a.pos=t.toArray();if(i)a.rot=i.toArray()}else{if(n.index!=null&&e.indexOf("手")==-1&&e.indexOf("指")==-1){const a=l.boneKeys[n.index];const s=Math.round(d-a.time*30);if(s>n.frame_length||s>10){const r=new _(e,null,null,(d-1)/30);r.pos=a.pos;r.rot=a.rot;l.boneKeys.push(r);p--}}n.timestamp=tt.skin[e]&&tt.skin[e][0].timestamp||0;l.boneKeys.push(new _(e,t,i,d/30))}n.frame_length=1;n.frame_count=d;return true},set_morphKey:(()=>{function o(e,t,i){let o=r[e];if(o==null){o=r[e]={frame_length:1};if(d>0)l.morphKeys.push(new s(e,0,0))}if(i&&tt.morph[e]&&o.timestamp==tt.morph[e][0].timestamp){if(o.frame_count!=d){o.frame_length++;u++}return}t=Math.round(t*20)/20;if(t==o.weight){u++;return}o.weight=t;if(o.frame_count==d){const n=l.morphKeys[o.index];n.weight=t}else{if(o.index!=null){const n=l.morphKeys[o.index];const a=Math.round(d-n.time*30);if(ao.frame_length||a>10){l.morphKeys.push(new s(e,n.weight,(d-m)/30));u--}}o.timestamp=tt.morph[e]&&tt.morph[e][0].timestamp||0;l.morphKeys.push(new s(e,t,d/30))}o.frame_length=1;o.frame_count=d;return true}return function(e,t,i){if(Ce.enabled){window.addEventListener("SA_motion_recorder_on_active",()=>{o.call(this,e,t,i)},{once:true})}}})(),start:function(e){i=e;if(MMD_SA.THREEX.get_model(0).use_faceBlendshapes){MMD_SA.THREEX.get_model(0)._disable_faceBlendshapes=true;for(const t of Fe.faceBlendshapes_list){tt.remove("morph",t)}}n="";a=0;if(je.is_local_video){je.video.playbackRate=e;if(e<1)je.video.muted=true;je.video.loop=false;je.video.pause();MMD_SA.SpeechBubble.message(0,System._browser.translation.get("XR_Animator.UI.motion_capture.ML_on.record_motion.choose_speed.begin_recording"),5*1e3);C_media_control.style.visibility="inherit"}d=-1;o=0;p=0;u=0;c={};r={};l={boneKeys:[],morphKeys:[]}},stop:function(){i=0;MMD_SA.THREEX.get_model(0)._disable_faceBlendshapes=false;if(je.is_local_video){je.video.playbackRate=1;je.video.muted=false;je.video.loop=true;je.video.pause();MMD_SA.SpeechBubble.message(0,System._browser.translation.get("XR_Animator.UI.motion_capture.ML_on.record_motion.choose_speed.begin_recording.recording_stopped"),5*1e3)}else if(je.is_local_photo){l.boneKeys=l.boneKeys.filter(e=>e.time==0);l.morphKeys=l.morphKeys.filter(e=>e.time==0);l.boneKeys=l.boneKeys.concat(l.boneKeys.map(e=>{const t={name:e.name,pos:e.pos.slice(),rot:e.rot.slice(),time:60};return t}));l.morphKeys=l.morphKeys.concat(l.morphKeys.map(e=>{const t={name:e.name,weight:e.weight,time:60};return t}))}}}}();const E=(()=>{function r(){p=p.slice(Math.max(p.length-8,0),p.length);MMD_SA_options.Dungeon.run_event([[{message:{content:p.join("\n")+"\n("+System._browser.translation.get("XR_Animator.UI.streamer_mode.press_x_to_abort")+")",para:h,branch_list:[{key:"X",is_closing_event:true,event_id:{func:()=>{m=true;if(u)u()},ended:true}}]}}]])}function _(){if(--i==0){p.push("✅"+System._browser.translation.get("XR_Animator.UI.streamer_mode.mocap_model_loaded"));if(u)u()}}function l(e){if(!Fe.calibrated){i++;window.addEventListener("SA_camera_facemesh_calibrating",c);p.push("✅"+System._browser.translation.get("XR_Animator.UI.streamer_mode.face_data_calibrating")+"...");r()}_(e)}function c(e){const t=e.detail.percent;if(t>=100){window.removeEventListener("SA_camera_facemesh_calibrating",c);MMD_SA.SpeechBubble.list[1].message(0,"("+System._browser.translation.get("XR_Animator.UI.streamer_mode.calibrating_face_data")+" - 100%)",0,h);p.push("✅"+System._browser.translation.get("XR_Animator.UI.streamer_mode.face_data_calibrated"));_()}else{MMD_SA.SpeechBubble.list[1].message(0,"("+System._browser.translation.get("XR_Animator.UI.streamer_mode.calibrating_face_data")+" - "+t+"%)\n"+System._browser.translation.get("XR_Animator.UI.streamer_mode.face_data_calibrating_message"),0,h)}}let d;let p=[];let i;let u;let m;const h={font_scale:1,font:'"Segoe UI",Roboto,Ubuntu,"SF Pro"'};const e={get running(){return d},init_mocap:function(e){function t(){if(d){if(MMD_SA_options.user_camera.streamer_mode.motion_id!=null){const e=typeof MMD_SA_options.user_camera.streamer_mode.motion_id=="number"?MMD_SA_options.user_camera.streamer_mode.motion_id+(System._browser.camera.facemesh.enabled&&!System._browser.camera.poseNet.enabled?1:0):MMD_SA_options._XRA_pose_list?.[2].findIndex(e=>e.name==MMD_SA_options.user_camera.streamer_mode.motion_id);if(typeof e=="number"&&e>=0)MMD_SA_options.Dungeon_options.item_base.pose?._change_motion_(e,true);return new Promise(t=>{window.addEventListener("SA_MMD_model0_onmotionchange",e=>{p.push("✅"+System._browser.translation.get("XR_Animator.UI.streamer_mode.motion_changed")+" ("+e.detail.motion_new.filename+")");t()},{once:true})})}}if(MMD_SA.WebXR.user_camera.poseNet.enabled){if(!MMD_SA.MMD.motionManager.para_SA.motion_tracking_enabled)MMD_SA_options.Dungeon_options.item_base.pose?._change_motion_(0,true)}}switch(e){case"Face":MMD_SA.WebXR.user_camera.poseNet.use_holistic=false;MMD_SA.WebXR.user_camera.facemesh.enabled=true;MMD_SA.WebXR.user_camera.poseNet.enabled=false;MMD_SA.WebXR.user_camera.handpose.enabled=false;DEBUG_show("Facemesh AI:ON",2);i=1;break;case"Body":MMD_SA.WebXR.user_camera.poseNet.use_holistic=false;MMD_SA.WebXR.user_camera.poseNet.enabled=true;MMD_SA.WebXR.user_camera.handpose.enabled=false;MMD_SA.WebXR.user_camera.facemesh.enabled=false;DEBUG_show("Pose AI:ON",3);i=1;break;case"Body+Hands":MMD_SA.WebXR.user_camera.poseNet.use_holistic=false;MMD_SA.WebXR.user_camera.poseNet.enabled=true;MMD_SA.WebXR.user_camera.handpose.enabled=true;MMD_SA.WebXR.user_camera.facemesh.enabled=false;DEBUG_show("Pose/Hands AI:ON",3);i=1;break;case"Face+Body":MMD_SA.WebXR.user_camera.poseNet.use_holistic=false;MMD_SA.WebXR.user_camera.facemesh.enabled=true;MMD_SA.WebXR.user_camera.poseNet.enabled=true;MMD_SA.WebXR.user_camera.handpose.enabled=false;DEBUG_show("Facemesh/Pose AI:ON",3);i=2;break;case"Full Body":MMD_SA.WebXR.user_camera.poseNet.use_holistic=false;MMD_SA.WebXR.user_camera.facemesh.enabled=true;MMD_SA.WebXR.user_camera.poseNet.enabled=true;MMD_SA.WebXR.user_camera.handpose.enabled=true;DEBUG_show("Facemesh/Pose/Hands AI:ON",4);i=2;break;case"Full Body Holistic":MMD_SA.WebXR.user_camera.poseNet.use_holistic=true;MMD_SA.WebXR.user_camera.poseNet.use_holistic_legacy=true;MMD_SA.WebXR.user_camera.facemesh.enabled=true;MMD_SA.WebXR.user_camera.poseNet.enabled=true;MMD_SA.WebXR.user_camera.handpose.enabled=true;DEBUG_show("Facemesh/Pose/Hands AI:ON",4);i=2;break;default:return}MMD_SA_options.user_camera.streamer_mode.mocap_type=e;return t()},start:async function(){function e(){p.length=0;u=null;m=false;d=false}function t(){e();MMD_SA_options.Dungeon.event_mode=false}if(MMD_SA.WebXR.user_camera.bodyPix.enabled){DEBUG_show("(You can't enable motion capture and Selfie Segmentation AI at the same time.)",5);return}if(d){DEBUG_show("(Streamer mode running)");return}e();d=true;MMD_SA_options.Dungeon.event_mode=true;const i=je.stream&&MMD_SA_options.user_camera.streamer_mode.camera_preference.label;MMD_SA.WebXR.user_camera.video_flipped=!!MMD_SA_options.user_camera.streamer_mode.camera_preference.video_flipped;const o=await je.start();if(!o){MMD_SA.SpeechBubble.message(0,System._browser.translation.get("XR_Animator.UI.streamer_mode.webcam_not_accessible"),5*1e3);t();return}if(i!=MMD_SA_options.user_camera.streamer_mode.camera_preference.label)p.push("✅"+System._browser.translation.get("XR_Animator.UI.streamer_mode.webcam_on")+" ("+MMD_SA_options.user_camera.streamer_mode.camera_preference.label+")");let n;if(webkit_electron_mode&&MMD_SA.THREEX.enabled){n=!!MMD_SA_options.user_camera.streamer_mode.VMC_sender_enabled;if(n){if(!MMD_SA.OSC.VMC.sender_enabled){MMD_SA_options.user_camera.streamer_mode.VMC_sender_enabled=MMD_SA.OSC.VMC.sender_enabled=true;p.push("✅"+System._browser.translation.get("XR_Animator.UI.streamer_mode.VMC_protocol_on"));MMD_SA.OSC.VMC.send_camera_data=!!MMD_SA_options.user_camera.streamer_mode.VMC_send_camera_data;if(MMD_SA.OSC.VMC.send_camera_data)p.push("✅- "+System._browser.translation.get("XR_Animator.UI.streamer_mode.VMC_protocol_on.send_camera_data"));System._browser.update_tray()}}}if(!je.ML_enabled){const a=MMD_SA_options.user_camera.streamer_mode.mocap_type||(is_mobile?System._browser.translation.get("XR_Animator.UI.streamer_mode.mocap_initializing.face","en"):System._browser.translation.get("XR_Animator.UI.streamer_mode.mocap_initializing.full_body","en"));const s=MMD_SA_options.user_camera.streamer_mode.mocap_type||(is_mobile?System._browser.translation.get("XR_Animator.UI.streamer_mode.mocap_initializing.face"):System._browser.translation.get("XR_Animator.UI.streamer_mode.mocap_initializing.full_body"));p.push("✅"+System._browser.translation.get("XR_Animator.UI.streamer_mode.mocap_initializing")+" ("+s+")...");r();await new Promise(e=>{u=e;if(/Face|Full Body/.test(a))window.addEventListener("SA_camera_facemesh_update",l,{once:true});if(/Body/.test(a))window.addEventListener("SA_camera_poseNet_update",_,{once:true});const t=E.init_mocap(a);if(t)t.then(r)})}if(m){window.removeEventListener("SA_camera_poseNet_update",_);window.removeEventListener("SA_camera_facemesh_update",l);window.removeEventListener("SA_camera_facemesh_calibrating",c);MMD_SA.SpeechBubble.list.forEach(e=>{e.hide()});t();return}u=null;MMD_SA.SpeechBubble.hide();if(n){if(p.length){await new Promise(e=>{MMD_SA_options.Dungeon.run_event([[{message:{content:System._browser.translation.get("XR_Animator.UI.streamer_mode.finish_VMC"),para:h,index:1,branch_list:[{key:1,event_id:{func:()=>{MMD_SA.hide_3D_avatar=true;System._browser.update_tray();e()},ended:true}},{key:"X",is_closing_event:true,event_id:{func:()=>{e()},ended:true}}]}}]])})}}else{if(p.length){await new Promise(e=>{MMD_SA_options.Dungeon.run_event([[{message:{content:System._browser.translation.get("XR_Animator.UI.streamer_mode.finish"),para:h,index:1,branch_list:[{key:1,event_id:{func:()=>{System._browser.overlay_mode=1;e()},ended:true}},{key:"X",is_closing_event:true,event_id:{func:()=>{e()},ended:true}}]}}]])})}}if(!p.length)MMD_SA.SpeechBubble.message(0,"XR Animator is ready!",3e3);if(je.initialized&&je.visible)je.hide();t()}};return e})();var wt=[{},{}];var x=t.get("camera_hidden");var j;je={initialized:false,get ML_enabled(){return M},get ML_busy(){return Fe.busy||Ce.busy},get ML_fps(){return 1e3/(Ce.enabled&&Ce._t||Fe.enabled&&Fe._t||1e3)},get ML_warmed_up(){var e=wt[Ce.use_holistic?1:0];var t=!Fe.enabled||e.facemesh;var i=!Ce.enabled||e.poseNet;var o=!Be.enabled||e.handpose;return t&&i&&o},get target_devicePixelRatio(){return u||window.devicePixelRatio},set target_devicePixelRatio(e){u=e==window.devicePixelRatio?0:e},get double_flip_mode(){return i&&!je.mirror_3D},set double_flip_mode(e){i=e},get video_flipped(){return!M?_:!!_^!!je.double_flip_mode},set video_flipped(e){_=e;this.reset_video_canvas()},get display_flipped(){return je.mirror_3D?false:_!=je.video_flipped},get mirror_3D(){return!M||!MMD_SA_options.user_camera.mirror_3D?false:MMD_SA_options.user_camera.mirror_3D==1?je.visible:true},get x_flipped(){return je.double_flip_mode||je.mirror_3D},get hidden_enforced(){return x||(MMD_SA_options.user_camera.display.video.hidden==null?!!this.stream:MMD_SA_options.user_camera.display.video.hidden)||System._browser.overlay_mode>0||this.stream&&MMD_SA_options.user_camera.display.video.hidden_on_webcam},get display_floating(){return MMD_SA_options.user_camera.display.floating||j},set display_floating(e){j=e;if(this.video_host)this.video_host.style.zIndex=this.display_floating?2:0},get video_timestamp(){return je.video.currentTime==null?performance.now()/2:je.video.currentTime*1e3},get video_frame_id(){const e=this.video_timestamp/1e3;const t=Math.floor(e);return t+":"+Math.floor((e-t)*30+1)},get is_local_media(){return this.local_src&&!this.stream},get is_local_video(){return this.is_local_media&&this.video.currentTime!=null},get is_local_photo(){return this.is_local_media&&this.video.currentTime==null},get media_control_enabled(){return h},set media_control_enabled(e){if(h==!!e)return;h=!!e;this.video.removeEventListener("timeupdate",f,true);if(h){MMD_SA.motion_player_control.enabled=false;this.video.addEventListener("timeupdate",f,true);SL_MC_simple_mode=true;SL_MC_video_obj=je.video;SL_MC_Place(1,0,-64)}else{SL_MC_Place(-1);if(!MMD_SA.motion_player_control.enabled&&MMD_SA_options._XRA_pose_list?.[0].find(e=>e.is_custom_motion&&e.name==MMD_SA.MMD.motionManager.filename)!=null){MMD_SA.motion_player_control.enabled=true}}},DEBUG_show:(()=>{let o="";let n="";let a=0;let s=[];window.addEventListener("MMDStarted",()=>{System._browser.on_animation_update.add(()=>{s=s.filter(e=>RAF_timestampe.msg).join("\n")+"\n":"";Oe=n+o},0,0,-1)});return function(e,t,i){if(!je.ML_enabled||!Ce.data_detected&&!Fe.data_detected||je.video?.paused){DEBUG_show(e,t,i);return}if(t){s.push({msg:e,duration:t*1e3,timestamp:RAF_timestamp});return}if(a!=RAF_timestamp){a=RAF_timestamp;o=""}o=(o?o+"\n":o)+e;Oe=n+o}})(),motion_recorder:it,tilt_adjustment:{enabled:false,angle:0,pose_weight:.5},camera_list:null,deviceId:null,start:async function(i){async function n(){try{stream=await navigator.mediaDevices.getUserMedia(a);return stream}catch(e){console.error(e)}}var e=MMD_SA_options.WebXR&&MMD_SA_options.WebXR.AR;this._update_camera_reset();if(this.initialized&&!E.running){if(this.visible){this.hide();DEBUG_show("User camera:HIDDEN",2);return}}var a={video:this.set_constraints()};try{if(i){this.init_stream(i)}else{if(is_mobile){a.video.facingMode="user"}if(MMD_SA_options.Dungeon){MMD_SA_options.Dungeon.run_event([[{message:{get content(){return System._browser.translation.get("XR_Animator.UI.webcam_media.finding_camera")}}},{goto_branch:0}]])}let t;if(is_mobile){if(!this.stream)t=await n();if(MMD_SA_options.Dungeon)MMD_SA_options.Dungeon.run_event(null,0,2);if(!this.stream&&!t){DEBUG_show("(Camera not accessible)",3);return}}else{let o=this.camera_list;if(!o){try{o=await navigator.mediaDevices.enumerateDevices();o=o.filter(e=>e.kind=="videoinput");const r=MMD_SA_options.user_camera.streamer_mode.camera_preference&&{label:{test:e=>e.indexOf(MMD_SA_options.user_camera.streamer_mode.camera_preference.label)!=-1}}||MMD_SA_options.user_camera.preference;o.sort((e,t)=>r?.label?.test(e.label)&&-1||r?.label?.test(t.label)&&1||/warudo/i.test(e.label)&&1||/warudo/i.test(t.label)&&-1||0);this.camera_list=o=o.slice(0,7);if(E.running&&!o.length)throw new Error("(No camera detected)")}catch(s){console.error(s);if(MMD_SA_options.Dungeon)MMD_SA_options.Dungeon.run_event(null,0,2);DEBUG_show("(No camera detected)",3);return}}let e;if(MMD_SA_options.Dungeon){await new Promise(t=>{MMD_SA_options.Dungeon.run_event([[{message:{get content(){return(o.length?System._browser.translation.get("XR_Animator.UI.webcam_media.choose_an_input")+o.map((e,t)=>"\n"+(t+1)+". "+e.label.substring(0,25)).join(""):System._browser.translation.get("XR_Animator.UI.webcam_media.no_camera"))+"\n"+(o.length+1)+". "+System._browser.translation.get("XR_Animator.UI.webcam_media.local_media_file")+"\n"+(o.length+2)+". "+System._browser.translation.get("Misc.cancel")},para:{row_max:11,no_word_break:true},bubble_index:3,branch_list:o.map((e,t)=>{return{key:t+1,branch_index:t+1}}).concat([{key:Math.min(o.length+1,8),branch_index:Math.min(o.length+1,8)},{key:Math.min(o.length+2,9),is_closing_event:true,branch_index:Math.min(o.length+2,9)}])}}]].concat(o.map(e=>[{func:()=>{const i=e.label;MMD_SA_options.user_camera.streamer_mode.camera_preference=Object.assign(MMD_SA_options.user_camera.streamer_mode.camera_preference||{},{label:i,video_flipped:!!_});o.sort((e,t)=>e.label==i&&-1||t.label==i&&1||0);a.video.deviceId=e.deviceId;t()},ended:true}]).concat([[{func:()=>{if(je.local_src){i=je.local_src;t();return true}else{DEBUG_show("(No local media file found)",3);MMD_SA_options.Dungeon.run_event(null,0,0)}}}],[{func:()=>{e=true;t()},ended:true}]])));if(E.running&&MMD_SA_options.user_camera.streamer_mode.camera_preference?.label){MMD_SA_options.Dungeon.run_event(null,1,0)}})}if(e){DEBUG_show("(Canceled)",2);return}if(!i&&a.video.deviceId!=this.deviceId){t=await n();if(!t){DEBUG_show("(Camera not accessible)",3);return}}}if(i){je.init_stream(i)}else if(t){je.init_stream(t);this.deviceId=a.video.deviceId}if(e&&e.dom_overlay)e.dom_overlay.use_dummy_webgl=true;DEBUG_show("(User camera:ON)",2)}if(!this.visible){this.show();DEBUG_show("User camera:VISIBLE",2)}return E.running}catch(s){if(MMD_SA_options.Dungeon&&MMD_SA_options.Dungeon.event_mode)MMD_SA_options.Dungeon.run_event({ended:true});je.init_stream();console.error(s);DEBUG_show("(ERROR: Camera unavailable, using fallback video instead)",3)}},_update_camera_reset:function(){MMD_SA.reset_camera();this._camera_reset=MMD_SA._trackball_camera.object.clone();this._camera_reset.children.length=0;this._camera_reset.quaternion.set(0,0,0,1);this._camera_reset.updateMatrixWorld();Ce.frames._z_max=Ce.frames._z_max_timestamp=0},init_stream:function(e){if(!this.initialized){this.video=this._video=document.createElement("video");this.video.autoplay=true;let e;this.video_host=document.createElement("div");e=this.video_host.style;e.position="absolute";e.left="0px";e.top="0px";e.zIndex=this.display_floating?2:0;e.visibility=System._browser.overlay_mode?"hidden":"inherit";e.display=System._browser.overlay_mode?"none":"block";SL_Host.appendChild(this.video_host);this.video_canvas=document.createElement("canvas");e=this.video_canvas.style;e.position="absolute";e.left="0px";e.top="0px";e.zIndex=0;e.visibility="hidden";this.video_host.appendChild(this.video_canvas);this.video_canvas_bodyPix=document.createElement("canvas");e=this.video_canvas_bodyPix.style;e.position="absolute";e.left="0px";e.top="0px";e.zIndex=0;e.visibility="hidden";this.video_host.appendChild(this.video_canvas_bodyPix);this.video_canvas_face_detection=document.createElement("canvas");e=this.video_canvas_face_detection.style;e.position="absolute";e.left="0px";e.top="0px";e.zIndex=0;e.visibility="hidden";this.video_host.appendChild(this.video_canvas_face_detection);this.video_canvas_facemesh=document.createElement("canvas");e=this.video_canvas_facemesh.style;e.position="absolute";e.left="0px";e.top="0px";e.zIndex=0;e.visibility="hidden";this.video_host.appendChild(this.video_canvas_facemesh);is_mobile&&window.addEventListener("resize",function(){je.video_track?.applyConstraints(je.set_constraints()).then(function(){DEBUG_show("(camera size updated)",2)})["catch"](function(e){DEBUG_show("ERROR:camera size failed to update")})});navigator.mediaDevices.addEventListener("devicechange",()=>{console.log("mediaDevices: new device detected");this.camera_list=null})}this.initialized=true;if(this.stream){this.stream.getTracks().forEach(e=>{e.stop()});this.video.srcObject=this.stream=this.video_track=this.deviceId=null;console.log("(Previous stream stopped)")}if(!e||typeof e=="string"){m(e)}else{this.stream=e;this.video_id=e.id;this.video_track=e.getVideoTracks()[0];this.video=this._video;this.video.srcObject=e;console.log("(New stream started)");setTimeout(function(){let e=je.video_track.getCapabilities?.();if(!e)return;System._browser.console.log(Object.entries(e).map(e=>e[0]+":"+JSON.stringify(e[1])).join("\n"));let t=je.video_track.getSettings();const i=Object.entries(t).map(e=>e[0]+":"+JSON.stringify(e[1])).join("\n");console.log("MediaTrackCapabilities",i);if(is_mobile)System._browser.console.log()},2e3)}this.show();if(Fe.enabled)Fe.reset_calibration()},get use_armIK(){return Ce.enabled||Be.enabled||Fe.enabled},bodyPix:function(){var o;var i=false;d={get enabled(){return i},set enabled(e){if(i==!!e)return;i=!!e;const t=MMD_SA.THREEX.SL;if(i){MMD_SA._renderer.devicePixelRatio=1;MMD_SA._renderer.__resize(EV_width,EV_height);t.style.visibility="hidden"}else{MMD_SA._renderer.devicePixelRatio=window.devicePixelRatio;MMD_SA._renderer.__resize(EV_width,EV_height);t.style.visibility="inherit";je.video_canvas_bodyPix.style.visibility="hidden"}},busy:0,mask:null,allPoses:null,use_bodySegmentation:true,load:async function(e){this.enabled=true;if(o)return;if(!this.mask){this.mask=document.createElement("canvas");c.load_face_cover()}if(this.use_bodySegmentation){const t=bodySegmentation.SupportedModels.MediaPipeSelfieSegmentation;const i={runtime:"mediapipe",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/selfie_segmentation"};o=await bodySegmentation.createSegmenter(t,i)}else{o=await bodyPix.load(e||(1||is_mobile)?{architecture:"MobileNetV1",outputStride:16,multiplier:.5,quantBytes:2}:{architecture:"ResNet50",outputStride:32,quantBytes:2})}console.log("bodyPix loaded")},segmentPerson:async function(e,t){await this.load();if(this.use_bodySegmentation){return await o.segmentPeople(e)}else{return await o.segmentPerson(e,t||{flipHorizontal:false,internalResolution:"medium",segmentationThreshold:.7})}},toMask:async function(e,t,i){const o=await this.segmentPerson(e,t);i=i||{foregroundColor:{r:0,g:0,b:0,a:255},backgroundColor:{r:0,g:0,b:0,a:0}};if(this.use_bodySegmentation){return await bodySegmentation.toBinaryMask(o,i.foregroundColor,i.backgroundColor)}else{this.allPoses=o.allPoses;return bodyPix.toMask(o,i.foregroundColor,i.backgroundColor)}},update_frame:async function(e=je.video_canvas,t,i,o){const n=MMD_SA.THREEX.SL;if(System._browser.snapshot.check_bodyPix()){je.video_canvas.style.visibility="inherit";je.video_canvas_bodyPix.style.visibility="hidden";n.style.visibility="inherit";return}if(this.busy)return;this.busy=RAF_timestamp;const a=await this.toMask(e,t,i);this.busy=0;if(!this.enabled)return;if(this.mask.width!=a.width||this.mask.height!=a.height){this.mask.width=a.width;this.mask.height=a.height}this.mask.getContext("2d").putImageData(a,0,0);const s=n.width;const r=n.height;if(je.video_canvas_bodyPix.width!=s||je.video_canvas_bodyPix.height!=r){je.video_canvas_bodyPix.width=s;je.video_canvas_bodyPix.height=r}const _=s/r/(e.width/e.height);const l=Math.round(s*Math.min(1/_,1));const c=Math.round(r*Math.min(_,1));const d=(s-l)/2;const p=(r-c)/2;const u=je.video_canvas_bodyPix.getContext("2d");u.globalCompositeOperation="copy";u.filter="blur("+Math.ceil(3/window.devicePixelRatio)+"px)";u.drawImage(this.mask,0,0,a.width,a.height,d,p,l,c);u.globalCompositeOperation="source-out";u.filter="none";u.save();if(je.mirror_3D){u.translate(s,0);u.scale(-1,1)}u.drawImage(n,0,0);u.restore();u.globalCompositeOperation="destination-over";u.drawImage(e,0,0,e.width,e.height,d,p,l,c);je.video_canvas_bodyPix.style.visibility="inherit";n.style.visibility="hidden";this.update_frame_for_face_detection();System._browser.snapshot.check_bodyPix()},update_frame_for_face_detection:function(){let e=c.face_cover;if(!c.enabled||!e.complete)return;je.video_canvas_face_detection.style.visibility="hidden";let t=e.width;let s=e.height;let r=[];this.allPoses.forEach(function(e){let t=e.keypoints;let i=t.find(e=>e.part=="nose");if(!i)return;let o=t.find(e=>e.part=="leftEye");let n=t.find(e=>e.part=="rightEye");let a;if(o&&n){let e=o.position.x-n.position.x;let t=o.position.y-n.position.y;a=Math.sqrt(e*e+t*t)*4}else{a=s}r.push([i.position.y,i.position.x,Math.max(a,s/2),100])});this.allPoses=undefined;c.update_frame_local(je.video_canvas_bodyPix,r)}};return d}(),face_detection:function(){var t=false;function i(){c.initialized=true;if(!self.OffscreenCanvas)c.load_face_cover();r=new Worker("js/pico.worker.js");r.onmessage=function(e){var t=typeof e.data=="string"&&e.data.charAt(0)==="{"?JSON.parse(e.data):e.data;if(typeof t==="string"){DEBUG_show(t,2);c.worker_initialized=true}else{je._needs_RAF=true;if(t._t)DEBUG_show(t._t);c.dets=t.dets;c.busy=0;je.video_canvas_face_detection.style.left=je.video_canvas.style.left;je.video_canvas_face_detection.style.top=je.video_canvas.style.top;if(!self.OffscreenCanvas){System._browser.on_animation_update.add(function(){c.update_frame_local(null,c.dets)},0,0)}}c.update_frame()}}c={initialized:false,worker_initialized:false,get enabled(){return t},set enabled(e){if(t==!!e)return;t=!!e;if(t){this.dets=null;if(!this.initialized)i()}else{if(je.initialized)je.video_canvas_face_detection.style.visibility="hidden"}},load_face_cover:function(){if(!this.face_cover){this.face_cover=new Image;this.face_cover.src="images/laughing_man_134x120.png"}},dets:null,camera_video_timestamp:0,update_frame:function(e){function t(){var e=c.enabled&&c.worker_initialized&&k&&!c.busy&&R&&c.camera_video_timestamp!=k;if(!e)return;c.busy=RAF_timestamp;c.camera_video_timestamp=k;c.camera_video_frame_id=P;je.video_canvas_face_detection.style.visibility="inherit";let t,i,o;t=je.video_canvas;i=t.width;o=t.height;let n=t.getContext("2d").getImageData(0,0,i,o).data.buffer;let a=je.video_canvas_face_detection.style;if(a.width!=t.style.width||a.height!=t.style.height){a.width=t.style.width;a.height=t.style.height}let s={rgba:n,w:i,h:o};if(!je.video_canvas_face_detection._offscreen&&self.OffscreenCanvas){s.canvas=je.video_canvas_face_detection.transferControlToOffscreen();je.video_canvas_face_detection._offscreen=true;console.log("(Face detection: use offscreen canvas)")}r.postMessage(s,s.canvas?[s.canvas,s.rgba]:[s.rgba]);s.rgba=n=undefined;s=undefined}if(e||self.PoseAT){setTimeout(()=>{t()},0)}else{t()}},update_frame_local:function(e,i){let t=je.video_canvas.width;let o=je.video_canvas.height;let n;if(!e){e=je.video_canvas_face_detection;if(e.width!=t||e.height!=o){e.width=t;e.height=o}n=e.getContext("2d");n.clearRect(0,0,t,o)}else{n=e.getContext("2d")}n.globalCompositeOperation="source-over";let a=this.face_cover;let s=a.width;let r=a.height;let _,l,c,d;if(i.length){let t=1;i.forEach(function(e){_=e[2]*t;l=_*s/r;c=e[1]*t-l/2;d=e[0]*t-_/2;n.drawImage(a,0,0,s,r,c,d,l,_)})}else{_=Math.min(t,o);l=_*s/r;c=(t-l)/2;d=(o-_)/2;n.drawImage(a,0,0,s,r,c,d,l,_)}}};return c}(),streamer_mode:E,facemesh:function(){var i=false;var ye=0;var ge=0;var be=true;var ve=0;var we=[];var Se;var Ae;var y;var De=[];var Ee=[];var ke;var b=false;var xe;var g=-1;var t;function o(e){if(!e&&t&&t==je.video_id)return;t=je.video_id;ye=0;ge=0;be=true;ve=0;we=[];Se={};Ae={L:[],R:[]};y=0;De=[];Fe.face_width_average=0;Ee=[];var o={L:[159,145],R:[386,374]};["L","R"].forEach(function(t){for(var i=0;i<1;i++){let e=Ae[t][i]={};e.index=i;e._eye_open_average=0;e.eye_open_average=0;e.eye_open_lower=999;e.eye_open_data=[];e.height_ref_pts=o[t]}Se[t]={_height_average:0,height_average:0,height_data:[],height_ref_pts:t=="R"?[334,330]:[105,101]}});xe={sad:0,angry:0,surprise:0,blush:0,tongue_out:0}}var n;var Ie=[];var Pe,ze,v;Pe=!is_mobile;v=!is_chrome||is_mobile;var x;function w(){if(Fe.initialized)return;Fe.initialized=true;for(var e=0;e<4;e++)Ie[e]=new THREE.Vector3;var o=[];if(System._browser.use_WASM_SIMD){o.push("simd=1")}if(K){Pe=true}if(v){Pe=true;o.push("use_mediapipe_facemesh=1")}if(Pe){Pe=true;if(Fe.blink_detection==null)Fe.blink_detection=true;o.push("use_face_landmarks=1")}if(ze){o.push("use_human_facemesh=1")}var t;if(MMD_SA_options.user_camera.ML_models.facemesh.worker_disabled){t=new Promise((e,t)=>{Le={postMessage:function(e,t){FacemeshAT.onmessage({data:e})}};let i=document.createElement("script");i.onload=async function(){await FacemeshAT.init(Le,o);e()};i.src="js/facemesh_lib.js";document.head.appendChild(i)})}else{Le=new Worker("js/facemesh_worker.js"+(o.length?"?"+o.join("&"):""))}Le.onmessage=A;if(!Fe.draw_canvas){fetch("js/facemesh_triangulation.json").then(e=>e.json()).then(e=>{x=e});System._browser.on_animation_update.add(()=>{Re.draw()},0,1,-1);console.log("(Facemesh: drawing wireframe in main thread)")}return t}const Re=(()=>{var v;var w;var S;function e(e,t,i,o){function n(e,t){return Math.sqrt(Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2))}const a=Math.round(t/2);const s=Math.round(i/2);if(D.width!=a||D.height!=s){D.width=a;D.height=s}E.globalAlpha=.5;E.save();if(v){E.translate(D.width,0);E.scale(-1,1)}E.clearRect(0,0,a,s);E.fillStyle="black";E.fillRect(0,0,a,s);if(!x||!e.length){S=false;E.restore();return}S=true;const r=e[0].bb;if(w){E.globalAlpha=1;E.drawImage(w,r.x/2,r.y/2,r.w/2,r.h/2)}E.fillStyle="#32EEDB";E.strokeStyle="#32EEDB";E.lineWidth=.5;const _=e[0].scaledMesh;for(let e=0,t=x.length/3;e_[e]);A(E,l,true)}if(w&&Pe){const c=E;const d=468;const p=5;const u="#FF2C35";c.strokeStyle=u;c.lineWidth=1;const m=_[d];const h=n(_[d+4],_[d+2]);const f=n(_[d+3],_[d+1]);c.beginPath();c.ellipse(m[0]/2,m[1]/2,f/2/2,h/2/2,0,0,2*Math.PI);c.stroke();if(_.length>d+p){const M=_[d+p];const y=n(_[d+p+2],_[d+p+4]);const g=n(_[d+p+3],_[d+p+1]);c.beginPath();c.ellipse(M[0]/2,M[1]/2,g/2/2,y/2/2,0,0,2*Math.PI);c.stroke()}}else{k.forEach(function(e){if(!e)return;var t=e[0]/2;var i=e[1]/2;E.beginPath();E.arc(t,i,1,0,2*Math.PI,false);E.lineWidth=3;E.strokeStyle="red";E.stroke()})}if(r.wn[e]);const i=new Path2D;i.moveTo(t[0][0]/a,t[0][1]/a);for(let e=1;e500)a=undefined}_();t=n=null}}}})();const e=["_neutral","BrowInnerUp","BrowDownLeft","BrowDownRight","BrowOuterUpLeft","BrowOuterUpRight","EyeLookUpLeft","EyeLookUpRight","EyeLookDownLeft","EyeLookDownRight","EyeLookInLeft","EyeLookInRight","EyeLookOutLeft","EyeLookOutRight","EyeBlinkLeft","EyeBlinkRight","EyeSquintRight","EyeSquintLeft","EyeWideLeft","EyeWideRight","CheekPuff","CheekSquintLeft","CheekSquintRight","NoseSneerLeft","NoseSneerRight","JawOpen","JawForward","JawLeft","JawRight","MouthFunnel","MouthPucker","MouthLeft","MouthRight","MouthRollUpper","MouthRollLower","MouthShrugUpper","MouthShrugLower","MouthClose","MouthSmileLeft","MouthSmileRight","MouthFrownLeft","MouthFrownRight","MouthDimpleLeft","MouthDimpleRight","MouthUpperUpLeft","MouthUpperUpRight","MouthLowerDownLeft","MouthLowerDownRight","MouthPressLeft","MouthPressRight","MouthStretchLeft","MouthStretchRight","TongueOut"];let Te;const S=["あ","い","う","え","お","にやり","ω","口角上げ","口角下げ","ぺろっ","上","下","にこり","困る","怒り","照れ","まばたき","笑い","びっくり","まばたきL","まばたきR"];var A=function(){function de(e){if(!e||Te)return;Te={};e.categories.forEach((e,t)=>{const i=e.categoryName;Te[i.charAt(0)+i.substring(1)]=t})}var pe;var ue=0,me=0,he=0,fe=0;const Me={};window.addEventListener("jThree_ready",()=>{for(const e of S.concat(["両目"])){Me[e]=new System._browser.data_filter([{type:"one_euro",id:e,para:e=="両目"?[30,1,5,1,4]:[30,1,1,1,1]}])}});return function(e){var S=typeof e.data=="string"&&e.data.charAt(0)==="{"?JSON.parse(e.data):e.data;if(typeof S==="string"){if(S=="OK"){Fe.worker_initialized=true}else{DEBUG_show(S,2);System._browser.console.log(S)}}else if(S.posenet){vt({data:S})}else if(Fe.enabled){window.dispatchEvent(new CustomEvent("SA_camera_facemesh_update"));je._needs_RAF=true;const t=wt[Ce.use_holistic?1:0];if(!t.facemesh){t.facemesh=true;DEBUG_show("Facemesh ML ready",2)}let w="";if(S.faces.length){Fe.data_detected++}else{Fe.data_detected=0}if(S.faces.length&&S.faces[0].bb_center){D=S.faces[0].bb_center}else if(!Ce.enabled){D=[.5,.5]}if(S.faces.length&&Fe.data_detected_stable){if(!Fe.draw_canvas)Re._data.faces=S.faces;let D=S.faces[0];de(D.faceBlendshapes);let c=je.x_flipped?1:-1;const A={facemesh_data:D};let E,k,l;if(D.rotation){const H=D.rotation.matrix;Ge.set(H[0],H[1],H[2],0,H[3],H[4],H[5],0,H[6],H[7],H[8],0,0,0,0,1)}else{let e=MMD_SA._v3a_.fromArray(D.mesh[152]).sub(MMD_SA._v3b.fromArray(D.mesh[10])).normalize();let t=MMD_SA._v3b_.fromArray(D.mesh[454]).sub(MMD_SA._v3b.fromArray(D.mesh[234])).normalize();let i=MMD_SA.TEMP_v3.crossVectors(t,e).normalize();t.crossVectors(e,i);Ge.set(t.x,t.y,t.z,0,e.x,e.y,e.z,0,i.x,i.y,i.z,0,0,0,0,1)}let e=MMD_SA.TEMP_v3.setEulerFromRotationMatrix(Ge,"YZX");E=-e.x;k=-e.y;l=-e.z;let t=D.scaledMesh[454][0]-D.scaledMesh[234][0];let i=D.scaledMesh[454][1]-D.scaledMesh[234][1];let o;if(S.recalculate_z_rotation_from_scaledMesh){t/=Math.cos(k);i/=Math.cos(E);o=Math.sqrt(t*t+i*i)}else{t/=Math.cos(l);o=Math.abs(t/Math.cos(k))}Fe.face_width=o;let n;if(S.recalculate_z_rotation_from_scaledMesh){n=Math.asin(i/o)}else{n=l}let a=new THREE.Quaternion;let s=MMD_SA._v3a.set(E,k*c,n*c);a.setFromEuler(s,"YZX");Fe.calculate_neck_data({is_face:true,timestamp:Fe.camera_video_frame_id,f_axis:qe.set(D.scaledMesh[454][0],D.scaledMesh[454][1],0).add(MMD_SA.TEMP_v3.set(D.scaledMesh[234][0],D.scaledMesh[234][1],0)).multiplyScalar(.5).setZ(0).toArray(),face_width:Fe.face_width,face_rot:a.toArray()});const j=MMD_SA.MMD.motionManager.para_SA;let r=0;let _=j.motion_tracking?.camera?.tilt_adjustment||je.tilt_adjustment;if(_.enabled){r=_.angle*Math.PI/180;const O=MMD_SA._q2.set(Math.sin(r/2),0,0,Math.cos(r/2));a.premultiply(O)}let d=je.video_timestamp;let p=0;if(fe){p=Math.max(Math.min(d-fe,1e3),10);he+=p;if(++me>=20){ue=1e3/(he/me);me=he=0}}fe=d;Fe._t=S._t;tt.t_delta=ue&&1e3/ue||p||S.fps&&1e3/S.fps||S._t;pe="";if(Fe.head_pose_enabled){if(System._browser.motion_control.enabled)A.head_rot=MMD_SA._v3a.clone();tt.add("skin|facemesh","首",{after_IK:true,rot:a,_rot_ratio:Fe.face_width/Math.min(je.video_canvas.width,je.video_canvas.height),onProcessRotation:yt})}ye+=Math.min(S._t,75);if(be){ge=~~(Math.min(ye/5e3,we.length/60,ke?Ae.L[0].eye_open_data.length/60:1,Ce.enabled?De.length/60:1,1)*100);be=ge<100;window.dispatchEvent(new CustomEvent("SA_camera_facemesh_calibrating",{detail:{percent:ge}}))}let u=D.faceInViewConfidence>(ze?.75:.9)&&(je.video==je._image||!je.video.paused&&Math.abs(k)e-t).slice(e,Ee.length-e).reduce((e,t)=>e+t)/(Ee.length-e*2)}let m=MMD_SA._v3a.fromArray(D.mesh[13]).distanceTo(MMD_SA._v3b.fromArray(D.mesh[14]));let h=D.faceBlendshapes?Math.max(D.faceBlendshapes.categories[Te["mouthPucker"]].score,.01):MMD_SA._v3a.fromArray(D.mesh[61]).distanceTo(MMD_SA._v3b.fromArray(D.mesh[291]));let f=ve;if(!f){if(u&&m<2*(1+Math.abs(r)/(Math.PI/4)*4))we.push(h);if(!we.length){f=0}else{let e=parseInt(we.length*.3);f=we.sort((e,t)=>e-t).slice(e,we.length-e).reduce((e,t)=>e+t)/(we.length-e*2);if(!be){ve=f}}}let M=0;let x=0;let y=0;let g=0;["L","R"].forEach(function(e){let t=Se[e];t.height=D.faceBlendshapes?Math.max(D.faceBlendshapes.categories[Te["eyeSquint"+(e=="L"?"Left":"Right")]].score,.01):MMD_SA._v3a.fromArray(D.mesh[t.height_ref_pts[0]]).distanceTo(MMD_SA._v3b.fromArray(D.mesh[t.height_ref_pts[1]]));t._height_average=t.height_average;if(!t._height_average){if(u)t.height_data.push(t.height);if(!t.height_data.length){t._height_average=t.height}else{let e=parseInt(we.length*.3);t._height_average=t.height_data.sort((e,t)=>e-t).slice(e,t.height_data.length-e).reduce((e,t)=>e+t)/(t.height_data.length-e*2);if(!be){t.height_average=t._height_average}}}y+=t.height/t._height_average});y/=2;y=(y-1)/.25*(y>1?2:1);if(f){if(h>f*1.05){x=Math.sqrt(Math.min((h-f*1.05)/(f*.25),1))}else if(h2){M=Math.pow(Math.min((m-2)/(f*1/3),1),.5);if(x>.25)g=(x-.25)/.75*.3}}let P=0;let R=0;let T=0;let b=0;let I=0;let z=0;const F=Fe.face_width/Math.min(je.video_canvas.width,je.video_canvas.height);const L=MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only||F>.2?1:Math.max(1-(.2-F)*8,0);let v={L:[0],R:[0]};if(Pe){["L","R"].forEach(function(t){let i=0;v[t][i]=0;let o=Ae[t][i];let n=D.faceBlendshapes?Math.max(1-D.faceBlendshapes.categories[Te["eyeBlink"+(t=="L"?"Left":"Right")]].score*.9,.2):MMD_SA._v3a.fromArray(D.mesh[o.height_ref_pts[0]]).distanceTo(MMD_SA._v3b.fromArray(D.mesh[o.height_ref_pts[1]]));let a=o.eye_open_average;if(!a){if(u){o.eye_open_data.push(n);let e=parseInt(o.eye_open_data.length*.3);a=o.eye_open_data.sort((e,t)=>e-t).slice(e,o.eye_open_data.length-e).reduce((e,t)=>e+t)/(o.eye_open_data.length-e*2);if(!be){o.eye_open_average=a}}else{a=o._eye_open_average}}if(u){if(o.eye_open_lower>n)o.eye_open_lower=n}o._eye_open_average=a;if(a){if(n>a){v[t][i]=Math.min(n/a,1.25)}else{let e=Math.min(o.eye_open_lower,a/2);v[t][i]=Math.max((n-e)/(a-e),0)}}})}const C=MMD_SA.THREEX.get_model(0).use_faceBlendshapes;if(D.faceBlendshapes){const q=D.faceBlendshapes.categories;if(!Fe.eye_tracking){q.forEach(e=>{if(e.categoryName.indexOf("eye")!=-1)e.score=0})}const r=[q[Te["eyeBlinkLeft"]].score,q[Te["eyeBlinkRight"]].score];r.forEach((e,t)=>{const i=t==0?"L":"R";const o=Ae[i][0];const n=1-(1-Math.max(o._eye_open_average||0,.5))*.8;const a=Math.min(o.eye_open_lower,.3);const s=n-a;e=Math.min(Math.max(e-(1-n),0)/s,1);r[t]=e<.5?Math.pow(e*2,1.5)/2:Math.pow((e-.5)*2,.667)/2+.5});const X=!Fe.blink_sync;const U=(X?Math.min(Math.abs(r[0]-r[1])/.4,1):0)*L;let e=X?Math.min(...r):(r[0]+r[1])/2;q[Te["eyeBlinkLeft"]].score=r[0]*U+e*(1-U);q[Te["eyeBlinkRight"]].score=r[1]*U+e*(1-U);for(const G of["eyeSquintLeft","eyeSquintRight"]){const W=G=="eyeSquintLeft"?"L":"R";const Q=Math.min(Math.max((Se[W]._height_average||0)*.8,.2),.5);q[Te[G]].score=Math.max(q[Te[G]].score-Q,0)/(1-Q)}const K=Math.min(Math.max((f||0)*.8,.2),.6);q[Te["mouthPucker"]].score=Math.pow(Math.max(q[Te["mouthPucker"]].score-K,0)/(1-K),2);if(C){q.forEach(e=>{const t=e.categoryName;let i=t.charAt(0).toUpperCase()+t.substring(1);i=i.indexOf("Left")!=-1?i.replace("Left","Right"):i.replace("Right","Left");tt.add("morph|facemesh",i,{weight:e.score})})}}if(Array.isArray(D.emotion)){D.emotion.forEach(e=>{switch(e.emotion){case"happy":P+=e.score;break;case"sad":R+=e.score;break;case"angry":case"disgust":T+=e.score;break;case"fear":b+=e.score;break;case"surprise":I+=e.score;break}})}const B=MMD_SA.THREEX.get_model(0);if(D.faceBlendshapes){const V=B.type=="VRM";const q=D.faceBlendshapes.categories;let i=q[Te["jawOpen"]].score;let o=(q[Te["mouthSmileLeft"]].score+q[Te["mouthSmileRight"]].score)/2;let n=(q[Te["mouthUpperUpLeft"]].score+q[Te["mouthUpperUpRight"]].score)/2;let a=(q[Te["mouthLowerDownLeft"]].score+q[Te["mouthLowerDownRight"]].score)/2;let s=q[Te["mouthPucker"]].score;let r=q[Te["mouthFunnel"]].score;let e=q[Te["mouthShrugLower"]].score;e*=e;const N=.3*(E>0?1-Math.min(E/(Math.PI/12),1):1);R=Math.min(Math.max(e-N,0)/.7,1);if(E<0){const oe=Math.min(Math.abs(E)/(Math.PI/4),1);R=Math.pow(Math.max(R-oe*.5,0)/(1-oe*.5),oe*3)}let t=q[Te["browInnerUp"]].score;t*=t;let _=(q[Te["browOuterUpLeft"]].score+q[Te["browOuterUpRight"]].score)/2;let l=(q[Te["browDownLeft"]].score+q[Te["browDownRight"]].score)/2;let c=0,d=0,p=0,u=0,m=0;const Y=Math.min(Fe.mouth_tracking_sensitivity,2)/2;const Z=Math.max(Fe.mouth_tracking_sensitivity-1,0)/2;const $=.2+.1*Y;if(i<.2){if(s>.1){p=s;if(r>.1)m=(r-.1)/2}else{d=Math.pow(Math.min(n+a/2,1),1-.5*Z);u=Math.pow(Math.min((o+n/2)*(i/.1),1),1-.5*Z);const oe=Math.min(o*(i/.1)/(n+a||.1),1);d*=1-oe;u*=oe}let e=1-i/.2*.5;let t=1-Math.min(Math.max(d,p,u,m),.2)/.2;t=e-t*.3;t=1-(1-t)*Y;c=Math.pow(i/.2,t)*$;if(C){i=c;tt.morph["JawOpen"][0].weight=i}}else{let e=$+Math.pow((i-.2)/.8,1-.5*Z)*(1-$);i=$+(i-.2)/.8*(1-$);if(C)tt.morph["JawOpen"][0].weight=i;m=Math.min(e+r/2,1);c=Math.min(e+(o+n)/3,1);if(s>.1){const oe=Math.min((s-.1)*5,1);m*=oe;c*=1-oe}else{m=0}}if(r>.1){x=-(r-.1)*.75}else{x=Math.min(Math.max(o-.2,0)*1+Math.max(n-.5,0)*1.5,1);if(x>.5)u*=1-(x-.5)*2*.25}P=Math.min(Math.max(x,0)-R,1);if(P<0){R=-P;P=0}else{R=0}const J=.2+s/2;T=Math.max(q[Te["mouthLeft"]].score-J,q[Te["mouthRight"]].score-J,0);o=Math.min(P*.8,V?.7-Math.max(P*.4-.3,0):.6);P*=.4;R*=.5;T=Math.max(T-P,0);let h=Math.max(Math.max((q[Te["mouthPressLeft"]].score+q[Te["mouthPressRight"]].score)/2,(q[Te["mouthRollLower"]].score+q[Te["mouthRollUpper"]].score)/2)-.2,0);if(l>.1){_=-(l-.1)/.9}else if(t>.1&&_>.1){_=((t-.1)/.9+(_-.1)/.9)/2}let f=(q[Te["eyeBlinkRight"]].score+q[Te["eyeBlinkLeft"]].score)/2;I=Math.max(_-f-.1,0);I=I*I/2;if(V)I=Math.min(I*Math.max(i*3,1),1);let M=1;const ee=Fe.use_tongue_out&&B.blendshape_map_by_MMD_name?.["ぺろっ"];let y=Math.min(Fe.emotion_weight_percent/100/.75,1)*Fe.emotion_tongue_out_percent/100;const te=y&&(B.use_tongue_out||ee);let g=Math.min(q[Te["mouthLowerDownLeft"]].score,q[Te["mouthLowerDownRight"]].score);if(te&&g>.2+.1*(1-y)&&i>.35+.15*(1-y)){let e=Math.max(q[Te["mouthUpperUpLeft"]].score,q[Te["mouthUpperUpRight"]].score);z=Math.max(g-e*(1.2+.1*(1-y)),0);if(Math.abs(k)>Math.PI/18){M=Math.max(1-(Math.abs(k)-Math.PI/18)/(Math.PI/4),1/3);z*=M}if(z<.1){z=0}else{z=Math.min(z*(1+(q[Te["mouthDimpleLeft"]].score+q[Te["mouthDimpleRight"]].score)/2),1)}}let b=Fe.emotion_weight_percent/100;if(C)b*=b;for(const ne in xe){let e=xe[ne];let t=Fe.emotion_weight_by_name(ne,b,1);let i=-1,o=1;let n=V?1:t*.8;let a=t*.75;let s=0;let r;switch(ne){case"sad":s=R;r=.25;break;case"angry":s=T;r=.25;break;case"surprise":s=I;if(V){r=.25}break;case"blush":s=h;r=.2;o=.5;n=1;break;case"tongue_out":s=z;r=.2;a=.6;n=1;break}if(r){let e=Math.min(s/r,1);e*=e;n=Math.min(s+Math.max(n-s,0)*e*(e<1?a:1),n);i=s*e*o}xe[ne]=THREE.Math.clamp(Math.max(e,s)+i*Fe._t/1e3*4,0,n)}({sad:R,angry:T,surprise:I,blush:h,tongue_out:z}=xe);if(z){if(ee){z=z<.5?(1-Math.cos(z*Math.PI))*.5:.5+Math.sin((z-.5)*Math.PI)*.5}else{if(z<.5){z=0}else{z=Math.sqrt(z);c*=1-z+z/2}}}if(C&&!ee)tt.add("morph|facemesh","TongueOut",{weight:z});if(!V){b=Math.min(b/.75,1);if(h)R+=h*.25*b}const ie=Fe.emotion_weight_by_name("smile",Math.sqrt(b));o=Math.min(o*ie,1);P=Math.min(P*ie,1);R=Math.min(R,Fe.emotion_weight_by_name("sad",b));T=Math.min(T,Fe.emotion_weight_by_name("angry",b));h=Math.min(h,Math.min(Fe.emotion_weight_by_name("blush",b)/.75,1));I=Math.min(I,Fe.emotion_weight_by_name("surprise",b));if(V)I*=I;tt.add("morph|facemesh","あ",{weight:c});tt.add("morph|facemesh","い",{weight:d});tt.add("morph|facemesh","う",{weight:p});tt.add("morph|facemesh","え",{weight:u});tt.add("morph|facemesh","お",{weight:m});tt.add("morph|facemesh","にやり",{weight:x});tt.add("morph|facemesh","口角上げ",{weight:n-e});tt.add("morph|facemesh","上",{weight:_});tt.add("morph|facemesh","にこり",{weight:o});tt.add("morph|facemesh","困る",{weight:R});tt.add("morph|facemesh","怒り",{weight:T});tt.add("morph|facemesh","笑い",{weight:P});tt.add("morph|facemesh","びっくり",{weight:I});tt.add("morph|facemesh","照れ",{weight:h});tt.add("morph|facemesh","ぺろっ",{weight:z});const X=!Fe.blink_sync&&THREE.MMD.getModels()[0].pmx.morphs_index_by_name["まばたきL"]!=null;if(X){tt.add("morph|facemesh","まばたきL",{weight:Math.max(q[Te["eyeBlinkRight"]].score-P,0)});tt.add("morph|facemesh","まばたきR",{weight:Math.max(q[Te["eyeBlinkLeft"]].score-P,0)});tt.add("morph|facemesh","まばたき",{weight:0})}else{tt.add("morph|facemesh","まばたきL",{weight:0});tt.add("morph|facemesh","まばたきR",{weight:0});tt.add("morph|facemesh","まばたき",{weight:Math.max(f-P,0)})}let v,w,S,A;if(Fe.auto_look_at_camera){const ae=THREE.MMD.getModels()[0].mesh;const se=MMD_SA.TEMP_v3.copy(MMD_SA._trackball_camera.object.position).sub(MMD_SA._head_pos).normalize().applyQuaternion(MMD_SA.get_bone_rotation(ae,"頭").conjugate());const re=MMD_SA._v3b.setEulerFromQuaternion(MMD_SA.TEMP_q.setFromUnitVectors(MMD_SA._v3a.set(0,0,1),se));v=-Math.sign(re.x)*Math.min(Math.abs(re.x/(Math.PI/4)),1);w=-Math.sign(re.y)*Math.min(Math.abs(re.y/(Math.PI/4)),1);A=1}else{v=(q[Te["eyeLookUpLeft"]].score+q[Te["eyeLookUpRight"]].score)/2-(q[Te["eyeLookDownLeft"]].score+q[Te["eyeLookDownRight"]].score)/2;w=(q[Te["eyeLookInRight"]].score+q[Te["eyeLookOutLeft"]].score)/2-(q[Te["eyeLookInLeft"]].score+q[Te["eyeLookOutRight"]].score)/2;A=Fe.eye_bone_rotation_percent/100}S={absolute:true,rot:(new THREE.Quaternion).setFromEuler(MMD_SA._v3a.set(-v*15/180*Math.PI,-w*20/180*Math.PI,0).multiplyScalar(A),"YZX")};tt.add("skin|facemesh","両目",S)}else{let e=P-(R+T+b+I*.5);if(e<0){g*=Math.max(1+e*2,0)}else{g=Math.min(e*.2+g*(1+e*.5),.4)}tt.add("morph|facemesh","にこり",{weight:Me["にこり"].filter(Math.min(g+P*.75,.75))});tt.add("morph|facemesh","困る",{weight:Me["困る"].filter(Math.min((R+b)/2*.75+(y<0?Math.max(-y*1-Math.max(x,0)*.5,0):0),.75))});tt.add("morph|facemesh","怒り",{weight:Me["怒り"].filter(Math.min(T*.75,.75))});y+=I*.2;tt.add("morph|facemesh","笑い",{weight:Me["笑い"].filter(g)});tt.add("morph|facemesh","びっくり",{weight:Me["びっくり"].filter(I*.75)});tt.add("morph|facemesh","にやり",{weight:Me["にやり"].filter(x)});let i=MMD_SA.TEMP_q.setFromEuler(MMD_SA._v3a.set(E,k,l),"YZX").conjugate();let o=[];[13,14,61,291].forEach(function(e,t){o[e]=Ie[t].fromArray(D.mesh[e]).applyQuaternion(i).setZ(0)});let t=MMD_SA._v3a.copy(o[61]).add(o[291]).multiplyScalar(.5);let n=o[61].distanceTo(o[291])*.5;let a=Math.atan2(o[13].y-t.y,n);let s=Math.atan2(o[14].y-t.y,n);let r=Math.max(-(a+s)*180/Math.PI+20*M,0);if(r)r=Math.min(r/20,.75);r=Math.min(r+R*.25,1);r*=.5;M=M*(1-r);tt.add("morph|facemesh","あ",{weight:Me["あ"].filter(M)});tt.add("morph|facemesh","お",{weight:Me["お"].filter(r)});let _={L:[],R:[]};if(!Fe.eye_tracking){}else if(Pe){let i=[0,0];let o=[0,0];D.eyes.forEach(function(e,t){if(e){i[t]=Math.max(Math.min((e[3]*2+E/(Math.PI/2))*(1-Math.abs(E)/Math.PI),1),-1);o[t]=Math.max(Math.min((e[2]*2-k/(Math.PI/2))*(1-Math.abs(k)/Math.PI),1),-1)}});let e=(v.L[0]+v.R[0])/2;if(e>1)y+=(e-1)*2;else y-=(1-e)*.5;y=Math.min(y,1);let t=v.L[0]+v.R[0];if(t)t=v.L[0]/t;else t=.5;let n=i[0]*t+i[1]*(1-t);let a=o[0]*t+o[1]*(1-t);let s={absolute:true,rot:(new THREE.Quaternion).fromArray(Me["両目"].filter(MMD_SA.TEMP_q.setFromEuler(MMD_SA._v3a.set(-(n-.3)*15/180*Math.PI,a*c*20/180*Math.PI,0),"YZX").toArray()))};tt.add("skin|facemesh","両目",s);let r=!Fe.blink_sync&&THREE.MMD.getModels()[0].pmx.morphs_index_by_name["まばたきL"]!=null;let _=(r?Math.min(Math.max(Math.abs(v.L[0]-v.R[0])-(.25+(1-Math.min(Math.max((Math.PI/6-Math.abs(k))/(Math.PI/12),0),1))*1),0)/.25,1):0)*L;let l=r?Math.min(v.L[0],v.R[0]):(v.L[0]+v.R[0])/2;v.L[0]=v.L[0]*_+l*(1-_);v.R[0]=v.R[0]*_+l*(1-_);if(r){let e="まばたき"+(c==1?"L":"R");tt.add("morph|facemesh",e,{weight:Me[e].filter(Math.max(Math.min(1-v.L[0]*.8-g,1),0))});e="まばたき"+(c==1?"R":"L");tt.add("morph|facemesh",e,{weight:Me[e].filter(Math.max(Math.min(1-v.R[0]*.8-g,1),0))});tt.add("morph|facemesh","まばたき",{weight:0})}else{tt.add("morph|facemesh","まばたきL",{weight:0});tt.add("morph|facemesh","まばたきR",{weight:0});tt.add("morph|facemesh","まばたき",{weight:Me["まばたき"].filter(Math.max(Math.min(1-v.L[0]*.8-g,1),0))})}}else{let e=D.eyes[0];let t=0;let i=0;if(e){t=Math.max(Math.min((e[3]*2+E/(Math.PI/2))*(1-Math.abs(E)/Math.PI),1),-1);i=Math.max(Math.min((e[2]*2-k/(Math.PI/2))*(1-Math.abs(k)/Math.PI),1),-1)}let o=y*.25;if(o<0)o=Math.min(o+g,0);let n=Math.max(Math.min(.1-t*(t<0?2:1)*.2-o,.5),0);tt.add("morph|facemesh","まばたき",{weight:n});let a=1.25+Math.pow((v.L[0]+v.R[0])/2,2)*1.75;t=Math.sign(t)*Math.pow(Math.abs(t),a);i=Math.sign(i)*Math.pow(Math.abs(i),a);let s={absolute:true,rot:(new THREE.Quaternion).setFromEuler(MMD_SA._v3a.set(-t*15/180*Math.PI,i*c*20/180*Math.PI,0),"YZX")};tt.add("skin|facemesh","両目",s)}if(Fe.eye_tracking)tt.add("morph|facemesh","上",{weight:Me["上"].filter(Math.max(Math.min(y,1),-1))})}if(!Ce.enabled){if(!tt.skin["センター"])tt.add("skin","センター",{rot:new THREE.Quaternion});const _e=MMD_SA.TEMP_v3.set(0,1,0);bt(_e,true);const le=_e.z?Math.atan2(_e.z,_e.y):0;tt.add("skin","上半身",{rot:new THREE.Quaternion(Math.sin(-le/2),0,0,Math.cos(-le/2))});const j=MMD_SA.MMD.motionManager.para_SA;if(j.motion_tracking_upper_body_only){for(const W of["左","右"]){const ce=true;if(j.has_leg_IK){tt.set_blend_default_motion("skin",W+"足IK",true);tt.remove("skin",W+"足首")}else{tt.set_blend_default_motion("skin",W+"足",true);tt.set_blend_default_motion("skin",W+"ひざ",true);tt.set_blend_default_motion("skin",W+"足首",true)}Ce.enable_IK(W+"足IK",j.has_leg_IK);Ce.enable_IK(W+"つま先IK",j.has_leg_IK);tt.set_blend_default_motion("skin",W+"肩",ce);tt.set_blend_default_motion("skin",W+"腕",ce);tt.set_blend_default_motion("skin",W+"ひじ",ce);tt.set_blend_default_motion("skin",W+"手捩",ce);tt.set_blend_default_motion("skin",W+"手首",ce);tt.set_blend_default_motion("skin",W+"腕IK",ce);Ce.enable_IK(W+"腕IK",true)}}else{for(const W of["左","右"]){Ce.enable_IK(W+"腕IK",j.has_arm_IK)}tt.remove("skin","センター")}}w=w||D.eyes.length&&[(!Ce.enabled?je.video_canvas.width+"x"+je.video_canvas.height+"("+Fe.camera_video_frame_id+")\n":"")+(be?"Calibrating("+ge+"%):Make a calm face!":"(face data calibrated)")+"/"+Math.round(D.faceInViewConfidence*100)+"%",D.emotion?JSON.stringify(D.emotion):"Neutral"].join("\n");if(pe)w+="\n"+pe;w+=(He||!Ce.enabled?Oe?"\n"+Oe+"\n":"":"")+(He||"");System._browser.motion_control.process(A)}else{if(!Fe.draw_canvas)Re._data.faces=[];w="(no facemesh data)\n"+He}if(!System._browser.overlay_mode&&!MMD_SA_options.user_camera.ML_models.debug_hidden){System._browser.on_animation_update.add(()=>{DEBUG_show(w&&w+(!Ce.enabled||!Ce.use_holistic?"\nF-FPS:"+Math.round(ue)+"/"+Math.round(S.fps||0):"")+"\n"+"FPS:"+EV_sync_update.fps_last||"")},0,0)}Fe.busy=0}Fe.update_frame()}}();var E=document.createElement("canvas");var a=true;var s;var r;var _,l,c,d,p,u,m;var h;var D=[];var f=0;var M=0;Fe={initialized:false,worker_initialized:false,faceBlendshapes_list:e,MMD_morph_list:S,wireframe:Re,draw_canvas:false,get data_detected(){return f},set data_detected(e){if(e){if(!f){M=RAF_timestamp}}else{M=0}f=e},get data_detected_stable(){return i&&M&&RAF_timestamp-M>250/(it.speed||1)},get head_pose_enabled(){return this.data_detected_stable||!Ce.enabled},get blink_detection(){return ke},set blink_detection(e){ke=e;if(i){if(ke){o()}else{MMD_SA_options.auto_blink=n!=null?n:MMD_SA_options.auto_blink}}},get auto_blink(){return b},set auto_blink(e){b=e},get eye_bone_rotation_percent(){return h==null?100:h},set eye_bone_rotation_percent(e){h=e},get eye_tracking(){return a},set eye_tracking(e){a=e;if(a){this.blink_detection=!!Pe}else{this.blink_detection=false}if(i){if(!a){tt.remove("skin","両目");tt.remove("morph","まばたきL");tt.remove("morph","まばたきR");tt.remove("morph","まばたき");tt.remove("morph","上");tt.remove("morph","下")}}},get use_faceLandmarksDetection(){return Pe},set use_faceLandmarksDetection(e){if(!this.initialized)Pe=e},get use_mediapipe(){return v||Ce.enabled&&Ce.use_holistic},set use_mediapipe(e){return v=e},get use_faceBlendshapes(){return!Ce.enabled||!Ce.use_holistic_legacy},get calibrated(){return!be&&ge>=100},get mouth_tracking_sensitivity(){return r==null?1:r},set mouth_tracking_sensitivity(e){r=e},get lean_tracking(){return s==null?2:s},set lean_tracking(e){s=e},get emotion_weight_percent(){return _==null?75:_},set emotion_weight_percent(e){_=e},get emotion_joy_fun_percent(){return l==null?100:l},set emotion_joy_fun_percent(e){l=e},get emotion_angry_percent(){return c==null?100:c},set emotion_angry_percent(e){c=e},get emotion_sorrow_percent(){return d==null?100:d},set emotion_sorrow_percent(e){d=e},get emotion_surprised_percent(){return p==null?100:p},set emotion_surprised_percent(e){p=e},get emotion_tongue_out_percent(){return u==null?100:u},set emotion_tongue_out_percent(e){u=e},get emotion_others_percent(){return m==null?100:m},set emotion_others_percent(e){m=e},emotion_weight_by_name:function(e,t=1,i=2){switch(e){case"smile":t*=this.emotion_joy_fun_percent/100;break;case"angry":t*=this.emotion_angry_percent/100;break;case"sad":t*=this.emotion_sorrow_percent/100;break;case"surprise":t*=this.emotion_surprised_percent/100;break;case"tongue_out":t*=this.emotion_tongue_out_percent/100;break;case"blush":t*=this.emotion_others_percent/100;break}return Math.min(t,i)},export_calibration:function(){const e={facemesh_calibration_type:Ce.use_holistic_legacy?"holistic_legacy":"facemesh",lips_width_average:ve,eyebrow_data:{L:{height_average:Se.L.height_average},R:{height_average:Se.R.height_average}},eye_data:{L:{eye_open_average:Ae.L[0].eye_open_average},R:{eye_open_average:Ae.R[0].eye_open_average}},neck_length_average:y};System._browser.save_file("facemesh_calibration.json",JSON.stringify(e,null,"\t"),"application/json")},import_calibration:function(e){this.reset_calibration();ve=e.lips_width_average;for(const t of["L","R"]){Object.assign(Se[t],e.eyebrow_data[t]);Object.assign(Ae[t][0],e.eye_data[t])}y=e.neck_length_average||1.25;ge=100;be=false},face_width:0,_neck:{},calculate_neck_data:(()=>{let u,m,h;let f;let M;window.addEventListener("jThree_ready",()=>{u=new THREE.Vector3;m=new THREE.Vector3;h=new THREE.Vector3;f=new THREE.Quaternion;M=new System._browser.data_filter([{type:"one_euro",id:"neck_length",para:[30,1,1,1,1]}])});return function(t){if(!Ce.enabled||!Fe.enabled||!this._neck.data)return false;let e=this._neck.data.find(e=>e.timestamp===t.timestamp);if(!e){this._neck.data.unshift(t);return false}Object.assign(e,t);if(!(e.is_pose&&e.is_face))return false;const i=u.fromArray(e.f_axis);const o=m.fromArray(e.shoulder_center).setZ(0);const n=h.set(0,0,e.face_width/3).applyQuaternion(f.fromArray(e.face_rot).conjugate()).setZ(0).y;const a=MMD_SA.MMD.motionManager.para_SA;let s=a.motion_tracking?.camera?.tilt_adjustment||je.tilt_adjustment;let r=s.enabled?s.angle*Math.PI/180:0;const _=a.motion_tracking?.ML_models?.pose||MMD_SA_options.user_camera.ML_models.pose;if(_.upper_rotation_offset){const p=_.upper_rotation_offset*Math.PI/180;r*=Math.cos(p)}const l=e.spine_rot_absolute[0]+r;this._neck._spine_rot_absolute=e.spine_rot_absolute.slice();this._neck._spine_rot_absolute[0]+=r;let c=M.filter(i.distanceTo(o)+n)/e.face_width/Math.max(Math.abs(Math.cos(l)));if(be){window.addEventListener("SA_camera_facemesh_calibrating",()=>{De.push(c);let e=parseInt(De.length*.3);y=De.sort((e,t)=>e-t).slice(e,De.length-e).reduce((e,t)=>e+t)/(De.length-e*2)},{once:true})}this._neck.data.length=0;if(!y)return false;let d=c/y;et[2]=!Ce.shoulder_tracking||d>.95?0:(1-Math.max((d/.95-.8)/(1-.8),0))*Math.PI/8;if(t.is_pose)return true;return true}})(),get enabled(){return i},set enabled(e){if(i==!!e)return;i=!!e;I();this.busy=0;this.data_detected=0;D[0]=D[1]=.5;this._neck={data:[]};if(i){if(!this.initialized)w();n=MMD_SA_options.auto_blink;const t=Ce.use_holistic_legacy?1:0;o(g!=t);g=t}else{MMD_SA_options.auto_blink=n}B()},get bb_center(){return D},set bb_center(e){D=e},reset_calibration:o,get frames(){return tt},init:w,worker_onmessage:A,camera_video_timestamp:0,update_frame:function(e){async function t(){var e=Fe.enabled&&Fe.worker_initialized&&k&&!Fe.busy&&!(Ce.enabled&&Ce.use_holistic)&&R&&Fe.camera_video_timestamp!=k;if(!e)return;Fe.busy=RAF_timestamp;Fe.camera_video_timestamp=k;Fe.camera_video_frame_id=P;if(ke){MMD_SA_options.auto_blink=b||false}let n;let a,s;let r,_;let l,c;let t;n=je.video_canvas;let i=n.width,o=n.height;l=c=0;a=r=i;s=_=o;let d=1;let p=MMD_SA_options.user_camera.pixel_limit.facemesh;if(p){if(a*s>p[0]*p[1]){d=Math.sqrt(a*s/(p[0]*p[1]));a=r=Math.round(a/d);s=_=Math.round(s/d);n=E;t=true}}let u,m,h;if(MMD_SA_options.user_camera.pixel_limit.facemesh_bb_ratio){u=MMD_SA_options.user_camera.pixel_limit.facemesh_bb_ratio;h=Math.round(Math.min(a,s)*u);r=h;_=h;let e=1;const g=5*(v?2:1);if(Fe.data_detected"+r+"x"+_+"):"+[e,t,h,h].join(",")+"=>"+[l,c,r,_].join(","))}}else{if(n.width!=r||n.height!=_){n.width=r;n.height=_;console.log("Facemesh canvas("+a+"x"+s+")")}}f.drawImage(je.video_canvas,Math.round(e*d),Math.round(t*d),Math.round(i*d),Math.round(o*d),0,0,r,_)}let M=T&&v?await createImageBitmap(n,t?0:l,t?0:c,r,_):f.getImageData(t?0:l,t?0:c,r,_).data.buffer;Fe._timestamp=je.video_timestamp;let y={rgba:M,w:a*(m||1),h:s*(m||1),options:{use_facemesh:true,draw_canvas:Fe.draw_canvas,flip_canvas:je.display_flipped,bb:{x:Math.round(l),y:Math.round(c),w:r,h:_,ratio:u||0,scale:m||1,timestamp:Fe._timestamp}}};if(Fe.draw_canvas){if(self.FacemeshAT){y.canvas=je.video_canvas_facemesh}else if(!je.video_canvas_facemesh._offscreen&&self.OffscreenCanvas){y.canvas=je.video_canvas_facemesh.transferControlToOffscreen();je.video_canvas_facemesh._offscreen=true;console.log("(Facemesh: use offscreen canvas)")}}else{Fe.wireframe._data.bb=y.options.bb}Le.postMessage(y,y.canvas?[y.canvas,y.rgba]:[y.rgba]);y.rgba=M=undefined;y=undefined}if(e||self.FacemeshAT){setTimeout(()=>{t()},0)}else{t()}}};return Fe}(),poseNet:function(){var i=false;var t=true;var n=true;var a={};var o=null;var s=null;var r=null;var _=0;var l=0;var c=0;var d=null;var p=null;var u=0;var m;var h;var f,M,y,g;var b,v,w,S;var A,D,E;var k,x;var P;var R,T,I,z;var j;Ce={get enabled(){return i},set enabled(e){if(i==!!e)return;i=!!e;ot=0;Ne=false;this.data_detected=0;this.initial_data_detected=false;c=0;THREE.MMD.getModels()[0].mesh.visible=true;q.set(0,0,0);if(i){if(!this.initialized)Q();if(G){worker_id=Ce.use_holistic?"legacy_holistic":"tasks_vision";if(!F[worker_id]){wt=[{},{}];L.terminate();for(const t in F)delete F[t];L=new Worker(G);L.onmessage=vt;C=worker_id;F[C]=new W(C,L)}console.log("Web worker ID:"+C);L=F[C].worker;O=F[C].initialized}MMD_SA_options.user_camera.ML_models.pose.events.enabled&&MMD_SA_options.user_camera.ML_models.pose.events.enabled()}else{THREE.MMD.getModels()[0].resetPhysics();MMD_SA_options.user_camera.ML_models.pose.events.disabled&&MMD_SA_options.user_camera.ML_models.pose.events.disabled();MMD_SA.TEMP_v3.set(0,0,0);MMD_SA.Camera_MOD.adjust_camera("hip_camera",MMD_SA.TEMP_v3,MMD_SA.TEMP_v3)}B();if(Ce.use_holistic){setTimeout(()=>{if(i)Fe.enabled=Be.enabled=true;else Be.enabled=false;DEBUG_show("(Holistic Mode:"+(i?"ON":"OFF")+")",2)},0)}},get data_detected(){return _},set data_detected(e){if(e){if(!_){l=RAF_timestamp}if(this.data_detected_stable){c=0}}else{l=0;if(!c){c=RAF_timestamp}if(RAF_timestamp-c>250/(it.speed||1)){tt.reset()}}_=e},get data_detected_stable(){return i&&(!c||RAF_timestamp-c<250/(it.speed||1)||l&&RAF_timestamp-l>500/(it.speed||1))},get use_head_mocap(){return(!this.enabled||this.data_detected_stable)&&(Fe.enabled||!MMD_SA.MMD.motionManager.para_SA.is_custom_motion||!MMD_SA.vmd_by_filename[MMD_SA.MMD.motionManager.filename]?.morphKeys.length)},get use_3D_pose(){return i&&t&&pt},set use_3D_pose(e){t=e},get use_holistic(){return o==null?K:o},set use_holistic(e){o=e},get _use_holistic_(){return K},set _use_holistic_(e){K=e},get use_holistic_landmarker(){return this.use_holistic&&s},set use_holistic_landmarker(e){s=e;r=!e},get use_holistic_legacy(){return this.use_holistic&&r},set use_holistic_legacy(e){s=!e;r=e},get skip_hand_countdown_max(){return 0},set IK_disabled(e){n=e},get auto_grounding(){return d!=null?d:MMD_SA_options.user_camera.ML_models.pose.auto_grounding||MMD_SA.WebXR.session},set auto_grounding(e){d=e},get ground_plane_visible(){return p!=null?p:!i||!!this.auto_grounding||MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only},set ground_plane_visible(e){p=e},get spine_length_ref(){if(u)return u;const e=MMD_SA.THREEX.get_model(0).para.spine_length;return e},set spine_length_ref(e){u=e},get shoulder_tracking(){return m==null?1:m},set shoulder_tracking(e){m=e},get hip_camera(){return h==null?false:h},set hip_camera(e){h=e;if(!e){MMD_SA.TEMP_v3.set(0,0,0);MMD_SA.Camera_MOD.adjust_camera("hip_camera",MMD_SA.TEMP_v3,MMD_SA.TEMP_v3)}},get hip_adjustment_weight_percent(){return f==null?100:f},set hip_adjustment_weight_percent(e){f=e},get hip_adjustment_head_weight_percent(){return M==null?100:M},set hip_adjustment_head_weight_percent(e){M=e},get hip_adjustment_adjust_y_axis_percent(){return y==null?66:y},set hip_adjustment_adjust_y_axis_percent(e){y=e},get hip_adjustment_scale_x_percent(){return b==null?100:b},set hip_adjustment_scale_x_percent(e){b=e},get hip_adjustment_scale_y_percent(){return v==null?100:v},set hip_adjustment_scale_y_percent(e){v=e},get hip_adjustment_head_pitch_rotation_percent(){return w==null?100:w},set hip_adjustment_head_pitch_rotation_percent(e){w=e},get hip_adjustment_scale_z_percent(){return S==null?100:S},set hip_adjustment_scale_z_percent(e){S=e},get hip_adjustment_smoothing_percent(){return g==null?0:g},set hip_adjustment_smoothing_percent(e){g=e},get hip_depth_scale_percent(){return A==null?100:A},set hip_depth_scale_percent(e){A=e},get hip_z_position_offset_percent(){return D==null?0:D},set hip_z_position_offset_percent(e){D=e},get hip_y_position_offset_percent(){return E==null?0:E},set hip_y_position_offset_percent(e){E=e},get limb_entry_duration_percent(){return k==null?100:k},set limb_entry_duration_percent(e){k=e},get limb_return_duration_percent(){return x==null?100:x},set limb_return_duration_percent(e){x=e},auto_scale_property:function(e,t,i){if(i===false)return e;let o,n;if(t.indexOf("腕")!=-1){o="left_arm_length";n=5.153592238246502}else if(t.indexOf("手首")!=-1){o="left_palm_length";n=.9020481908808872}else if(t.indexOf("上半身")!=-1){o="spine_length";n=4.97462}else if(t=="ROOT"){o="left_leg_length";n=10.569580078125}else{return e}let a=.9;let s=typeof i=="number"?i:1;let r=MMD_SA.THREEX.get_model(0).para[o]/n;r=r>1?Math.max(r*a,1):Math.min(r/a,1);r=1+(r-1)*s;return Array.isArray(e)?e.map(e=>e*r):e*r},body_collider:{get mode(){return P==null?1:P},set mode(e){P=e},get enabled(){return this.mode>0&&["head","chest","waist","hip"].some(e=>this[e].enabled)},get active(){return this.enabled&&Ce.enabled&&(Ce._upper_body_only_mode||this.mode>1)},head:{get enabled(){return!!this.size_percent},get size_percent(){return R==null?0:R},set size_percent(e){R=e},get reaction_type(){return j==null?"z_push":j},set reaction_type(e){j=e}},chest:{get enabled(){return!!this.size_percent},get size_percent(){return T==null?125:T},set size_percent(e){T=e}},waist:{get enabled(){return!!this.size_percent},get size_percent(){return I==null?100:I},set size_percent(e){I=e}},hip:{get enabled(){return!!this.size_percent},get size_percent(){return z==null?100:z},set size_percent(e){z=e}}},IK_disabled_check:function(){var o=new RegExp("("+toRegExp(["腕IK","足IK","つま先IK"],"|")+")$");var e=new RegExp("("+toRegExp(["腕IK"],"|")+")$");return function(e){const t=MMD_SA.MMD.motionManager.para_SA;if(!n||!this.data_detected&&(this.enabled||!Fe.enabled||!Fe.data_detected)||!t.motion_tracking_enabled)return null;let i=!e||o.test(e);if(i&&e){if(a[e])i=false}return i}}(),enable_IK:function(e,t){a[e]=t},get frames(){return tt},camera_video_timestamp:0,get busy(){return ot},get initialized(){return H},get worker_initialized(){return O},set worker_initialized(e){O=e;if(!self.PoseAT)F[C].initialized=e}};return Ce}(),handpose:function(){var t=false;var i={};var o={};var n,a;var s;Be={get enabled(){return t},set enabled(e){if(t==!!e)return;t=!!e;if(t){i={};o={};if(!this.initialized)Q()}},get hand_visible_timestamp(){return i},get hand_visible_session(){return o},get frames(){return tt},get busy(){return ot},get initialized(){return H},get worker_initialized(){return O},set worker_initialized(e){O=F[C].initialized=e},get stabilize_arm(){return n==null?2:n},set stabilize_arm(e){n=e},get stabilize_arm_time(){return a==null?0:a},set stabilize_arm_time(e){a=e},get stabilize_hand_percent(){return s==null?20:s},set stabilize_hand_percent(e){s=e},_hand_last:{"左":{},"右":{}}};return Be}(),reset_video_canvas:function(){if(this.video_canvas){this.video_canvas.width=this.video_canvas.height=k=0;P=""}},show:function(){if(!this.initialized||this.visible)return;this.visible=true;if(je.target_devicePixelRatio!=window.devicePixelRatio){je.target_devicePixelRatio=0;je.video_track.applyConstraints(je.set_constraints()).then(function(){DEBUG_show("(camera size updated)",2)})["catch"](function(e){DEBUG_show("ERROR:camera size failed to update")})}s();if(this.hidden_enforced){this.hide()}},hide:function(){if(!this.initialized||!this.visible)return;this.visible=false;this.video_canvas.style.visibility="hidden";c.enabled=false;d.enabled=false;l()},set_constraints:function(e){var t={};const i=window.devicePixelRatio/this.target_devicePixelRatio;let o,n;const a=is_mobile?Math.min(270/Math.min(window.innerWidth,window.innerHeight),i):i;o=Math.round(window.innerWidth*a);n=Math.round(window.innerHeight*a);var s=MMD_SA_options.user_camera.pixel_limit.current||MMD_SA_options.user_camera.pixel_limit._default_;if(!u){if(MMD_SA_options.user_camera.pixel_limit.fixed){o=s[0];n=s[1]}else if(o*n>s[0]*s[1]){const r=Math.sqrt(o*n/(s[0]*s[1]));o=Math.round(o/r);n=Math.round(n/r)}}je.target_width=o;je.target_height=n;if(!MMD_SA_options.user_camera.pixel_limit.disabled){if(!is_mobile||!screen.orientation||/landscape/.test(screen.orientation.type)){t.width=o;t.height=n}else{t.width=n;t.height=o}}if(MMD_SA_options.user_camera.fps)t.frameRate=MMD_SA_options.user_camera;if(e)t=Object.assign(t,e);console.log("Camera constraints",t);return t}};return je}(),data_filter:function(){class e{constructor(){}filter(e){return e}}class n{constructor(e){this.filters=e;e.forEach(e=>{switch(e.type){case"one_euro":if(e.transition_time){e.para[1]=1/(1/(1/e.transition_time/60)-1)*60/(2*Math.PI);console.log("transition_time => minCutoff",e.para[1])}e.filter=new OneEuroFilter(...e.para||[]);break}if(e.id)e.filter.id=e.id})}static#get_timestamp(){return System._browser.camera.initialized&&System._browser.camera.ML_enabled?System._browser.camera.video_timestamp:RAF_timestamp}filter(t,i=n.#get_timestamp(),o=System._browser.camera.motion_recorder.speed||1){if(t!=null){if(Array.isArray(t)?t.some(e=>isNaN(e)):isNaN(t)){console.error("Data filter error",this.filters[0].id);return t}this.filters.forEach(e=>{if(!e.condition||e.condition()){this.data=e.filter.filter(t,i,o);this.timestamp=RAF_timestamp}})}else{if(i!=null){if(i===true)i=n.#get_timestamp();this.filters.forEach(e=>{e.filter.lasttime=i;if(this.timestamp!=null)this.timestamp=RAF_timestamp})}}return this.data}}return n}(),motion_control:function(){var s,u,p,i,_,m;var d;var h;var f=function(){var r={};var a={};return{pressed:r,map:a,temp:{},set_options:function(e){if(!l)return;if(!e.timeout_list){const t=["W","A","S","D"];for(const i of["L","R"]){for(const o in e[i]){const n=e[i][o];if(n.press)t.push(...n.press)}}e.timeout_list=t.map(e=>m[e])}if(!e.clear_list)e.clear_list={};for(const i of["L","R"]){if(!e.clear_list[i]){const t=i=="L"?["W","A","S","D"]:[];for(const o in e[i]){const n=e[i][o];if(n.press)t.push(...n.press)}e.clear_list[i]=t.map(e=>[m[e]])}}this.temp={};Object.assign(a,e);console.log(a)},action:function(e,t,i){var o=a[t][i]||{};return{press:o.press&&(!o.press_check||o.press_check(e))&&o.press||[],release:o.release||[],click:o.click&&(!o.click_check||o.click_check(e))&&o.click||[]}},activate:async function(e,t,i,o=[]){const n=this.action(e,t,i);if(n.click.length)await f.click(...n.click.map(e=>[m[e]]));if(n.press.length){const a=n.press.map(e=>m[e]);o=[...o.filter(e=>a.indexOf(e[0])==-1),...n.release.map(e=>[m[e]])];if(o.length)await f.releaseKey(...o);await f.pressKey(...a.map(e=>[e]))}},clear_list:function(e){return a.clear_list[e]},pressKey:async function(...e){let t=Array.isArray(e[0])&&e||[e];var i=[];for(const o of t){const n=o.filter(e=>!r[e]);if(n.length){for(const s of n)r[s]=-1;await _.pressKey(...n);const a=n.filter(e=>r[e]==-2);if(a.length){await _.releaseKey(...a);for(const s of a)r[s]=0;console.log("key released enforced",a.length)}}for(const s of o){if(r[s])r[s]=RAF_timestamp}}},releaseKey:async function(...e){const t=!e.length?Object.keys(r).map(e=>[parseInt(e)]):Array.isArray(e[0])&&e||[e];const i=[];for(const o of t){const n=o.filter(e=>r[e]>0);if(n.length){i.push(_.releaseKey(...n).then(()=>{for(const e of n)r[e]=0}))}const a=o.filter(e=>r[e]<0);a.forEach(e=>{r[e]=-2})}if(i.length){await Promise.all(i)}},releaseIdleKey:async function(...e){const t=!e.length?Object.keys(r).map(e=>[parseInt(e)]):Array.isArray(e[0])&&e||[e];const i=t.map(e=>e.filter(e=>r[e]&&(a.timeout_list.indexOf(e)==-1||RAF_timestamp-(r[e]>0?r[e]:RAF_timestamp)>500))).filter(e=>e.length);if(i.length){await f.releaseKey(...i)}},click:async function(...e){const t=Array.isArray(e[0])&&e||[e];await this.pressKey(...t);await this.releaseKey(...t)}}}();var M={custom:{},list:[],estimate:function(e,t,i=9){const o=e.estimate(t.keypoints,i);if(o.gestures.length){o.gestures.forEach(e=>{e._d=t._d;e.hand_facing=this.list[0].hand_facing[t._d];e.hand_rot_YXZ=this.list[0].hand_rot_YXZ[t._d];e.thumb_out=this.list[0].thumb_out[t._d];e.poseData=o.poseData});this.list[0].gestures=this.list[0].gestures.concat(o.gestures)}return o},search:function(i,n={}){function a(e){return e.gestures.find(t=>i.split("|").some(e=>t.name==e&&(!n.hand||n.hand._d==t._d)&&(!n.hand_facing||n.hand_facing===t.hand_facing)&&(n.thumb_out==null||n.thumb_out===t.thumb_out)&&(!n.condition||t._condition_passed||n.condition(t)&&(t._condition_passed=true))))}var e=n.time_limit||0;var t;for(let i=0,o=this.list.length;i=n.duration)break}else break}if(e{const t=M.list;for(let e=t.length-1;e>=0;e--){if(t[e].timestamp>RAF_timestamp-3e3){if(eMath.max(...o);var a,s;if(n){s=e.hand_rot_YXZ[1];if(s<=20)a="Horizontal Left";else if(s>20&&s<=50)a="Diagonal Down Left";else if(s>130&&s<=160)a="Diagonal Down Right";else if(s>160)a="Horizontal Right";else a="Vertical Down";if(!e.thumb_out&&/Horizontal/.test(a)){a="";s=0}}else{if(!e.thumb_out){a="";s=0}else{const r=-(i[3][1]-i[1][1]);const _=i[3][0]-i[1][0];s=Math.atan2(r,_)*180/Math.PI-90;if(s<-180)s+=360;s=-s;if(s>20&&s<=60)a="Diagonal Up Right";else if(s>60&&s<=120)a="Horizontal Right";else if(s<-20&&s>=-60)a="Diagonal Up Left";else if(s<-60&&s>=-120)a="Horizontal Left";else a="Vertical Up"}}return[a+"\n"+(i[1][1]>Math.max(...o))+"\n"+e.hand_rot_YXZ.join("\n"),s]}var E=function(){var i,o,n,e,a;return function(){if(e!=RAF_timestamp){e=RAF_timestamp;i=null;a=[];s().then(async e=>{[o,n]=await Promise.all([e.title,e.region]);i=e;const t={w:i,title:o,region:n};a.forEach(e=>{e(t)})})}return new Promise((e,t)=>{if(i){e({w:i,title:o,region:n})}else{a.push(e)}})}}();var k=["0","1","2","3"];var x=[];var P=[];const R={get enabled(){return a},set enabled(e){if(a==!!e)return;a=!!e;if(a){A()}else{this.setMousePosition(null)}DEBUG_show("Motion control:"+(a?"ON":"OFF"),3)},get enabled_nut(){return r},get ready(){return a&&!c},get handedness(){return h},get off_hand(){return h=="左"?"右":"左"},get window_active(){return window_active},get _debug_msg(){return x},get debug_msg(){return a&&x.length?x.join("\n")+"\n":""},get Key(){return m},get key_pressed(){return f.pressed},gestures:M,get plugins(){return P},add_plugin:function(e){if(P.indexOf(e)==-1)P.push(e)},process:async function(t){if(!this.ready)return;if(t.posenet_data){if(!M.list.length||M.list[0].timestamp!=RAF_timestamp){M.list.unshift({timestamp:RAF_timestamp,gestures:[]})}x=["Motion control"+(S?"(PAUSED)":"")+":"];const e=t.posenet_data.handpose;if(e&&e.length){const _={};const l={};const c={};e.forEach(e=>{if(!e._used)return;const t=System._browser.camera.poseNet.frames.skin[e._d+"手首"];if(!t)return;const i=MMD_SA.TEMP_v3.setEulerFromQuaternion(t[0].rot,"YXZ");l[e._d]=i.toArray().map(e=>e*180/Math.PI);_[e._d]=Math.abs(i.y)1.3*Math.abs(Math.abs(l[e._d][1])-90)/90+.2});M.list[0].hand_rot_YXZ=l;M.list[0].hand_facing=_;M.list[0].thumb_out=c;e.forEach(e=>{if(!r)return;if(!e._used)return;if(S){M.estimate(d,e);const t=M.search("index_up",{duration:1e3,hand_facing:"front",thumb_out:false});if(t){S=false;h=t._d;DEBUG_show("Motion control:READY",2)}}else if(e._d==h){M.estimate(d,e);const t=M.search("index_up",{duration:1e3,hand_facing:"back",thumb_out:false});if(t){S=true;DEBUG_show("Motion control:PAUSED",2)}}})}}else if(t.facemesh_data){}P.forEach(e=>{e.process(t)});if(!r)return;if(S)return;this.virtual_mouse.process(t);this.game01.process(t)},setMousePosition:function(){var t;return async function(e){if(e===null){t=null;return}if(!a)return;if(!r)return;if(e){t=e}else if(!e){return}await i.setPosition(t)}}(),game01:function(){var t,e;var i={id:"PSO2NGS",L:{thumb:{release:["Space","X"]},thumb_index:{press:["X"],release:["Space"]},thumb_palm:{press:["Space"],release:["X"]}},R:function(){function e(e){const t=f.temp.index_middle||0;const i=e.thumb_out?1:0;f.temp.index_middle=i;return t!=i}return{index_thumb:{press:["Tab"],press_check:function(){if(!f.temp.index_thumb)f.temp.index_thumb={};f.temp.index_thumb.clicked=true;return true}},index_up:{press:["Q"],press_check:function(){var e=f.temp.index_thumb&&f.temp.index_thumb.clicked;if(e)f.temp.index_thumb.clicked=false;return e}},index_middle1:{press:["Period"],click:["Semicolon"],click_check:e},index_middle2:{press:["Slash"],click:["Semicolon"],click_check:e},index_middle3:{press:["Quote"],click:["Semicolon"],click_check:e},thumb_palm:{press:["Backslash"]}}}()};var c;var o,n;function d(){if(e)return;c=new fp.GestureEstimator([M.custom.index_up,M.custom.index_thumb,M.custom.index_middle,M.custom.index_pinky,M.custom.palm_open,M.custom.thumb,M.custom.thumb_index,M.custom.thumb_palm]);f.set_options(i);e=true}return{get enabled(){return t},set enabled(e){t=e;if(t){f.set_options(i)}else{}},process:async function(i){if(!this.enabled){await f.releaseKey();return}d();const a=await E();const e=await a.title;if(i.facemesh_data&&i.head_rot){let e=i.head_rot.x*180/Math.PI;let t=i.head_rot.y*180/Math.PI;let o=Math.round(Math.sign(e)*Math.pow(Math.min(Math.max((Math.abs(e)-8)/15,0),1),2)*40);let n=Math.round(Math.sign(t)*Math.pow(Math.min(Math.max((Math.abs(t)-10)/20,0),1),2)*40);x.push(e,t,n,o);Promise.resolve(a.region).then(async e=>{const t=await p(e);const i=e.width-1280<64?[1280,720]:[1920,1080];t.y+=Math.round((e.height-i[1]-(e.width-i[0]))/2);t.x+=n;t.y+=o;t.y+=1;t.x+=1;await R.setMousePosition(t)})}let t;if(i.posenet_data){t=i.posenet_data.handpose;let e="";if(!t||!t.length){t=null;if(M.search("palm_open",{time_limit:500,hand_facing:"front",condition:()=>{}})){e+="/CANCEL";await f.releaseKey()}else{await f.releaseIdleKey()}}x.push((t?"":"(no hand data)")+e+"/key active:"+Object.keys(f.pressed).filter(e=>f.pressed[e]).join(","))}if(!t)return;for(const n of t){if(!n._used)continue;const s=n._d==h?"R":"L";x.push(s+":");M.estimate(c,n);let i;i=M.search("palm_open",{hand:n,hand_facing:"front",condition:function(e){const t=this.hand;const i=y.fromArray(t.annotations.index[0]).sub(g.fromArray(t.annotations.index[3]));const o=b.fromArray(t.annotations.pinky[0]).sub(v.fromArray(t.annotations.pinky[3]));return i.angleTo(o)*180/Math.PI>30}});if(i){x.push("CANCEL");await f.releaseKey(...f.clear_list(s));continue}if(n._d==h){i=M.search("index_thumb",{hand:n,hand_facing:"back",thumb_out:true});if(i){await f.activate(i,s,i.name,f.clear_list(s));x.push("index_thumb");continue}i=M.search("index_up",{hand:n,hand_facing:"front",thumb_out:true});if(i){await f.activate(i,s,i.name,f.clear_list(s));x.push("index_up");continue}i=M.search("index_middle",{hand:n});if(i){let e=i.name;switch(i.poseData[1][2]){case"Vertical Up":e+=2;break;case"Diagonal Up Left":e+=h=="右"?1:3;break;case"Diagonal Up Right":e+=h=="右"?3:1;break}await f.activate(i,s,e,f.clear_list(s));x.push(e);continue}i=M.search("thumb_palm",{hand:n,condition:function(e){if(!/(Horizontal|Diagonal Up)/.test(e.poseData[2][2]))return false;const t=this.hand;const i=y.fromArray(t.annotations.index[0]).sub(g.fromArray(t.annotations.index[3]));const o=b.fromArray(t.annotations.pinky[0]).sub(v.fromArray(t.annotations.pinky[3]));return i.angleTo(o)*180/Math.PI<20}});if(i){await f.activate(i,s,i.name,f.clear_list(s));x.push("thumb_palm");continue}i=M.search("thumb",{hand:n});if(i){x.push("CANCEL");await f.releaseKey(...f.clear_list(s));continue}i=M.search("index_pinky",{hand:n});if(i){x.push("index_pinky");continue}}else{i=M.search("thumb_palm|thumb_index|thumb",{hand:n,condition:function(e){if(e.name!="thumb_palm")return true;const t=this.hand;const i=y.fromArray(t.annotations.index[0]).sub(g.fromArray(t.annotations.index[3]));const o=b.fromArray(t.annotations.pinky[0]).sub(v.fromArray(t.annotations.pinky[3]));return i.angleTo(o)*180/Math.PI<20}});if(i){const r=D(i,n);const _=r[0];let e=[];let t=[];switch(_){case"Vertical Up":e.push("W");t.push("A","S","D");break;case"Diagonal Up Right":e.push("W","A");t.push("S","D");break;case"Horizontal Right":e.push("A");t.push("W","S","D");break;case"Diagonal Up Left":e.push("W","D");t.push("A","S");break;case"Horizontal Left":e.push("D");t.push("W","A","S");break;case"Diagonal Down Right":e.push("S","A");t.push("W","D");break;case"Diagonal Down Left":e.push("S","D");t.push("W","A");break;case"Vertical Down":e.push("S");t.push("W","A","D");break;default:t.push("W","A","S","D")}var o=f.action(i,s,i.name);if(o.press.length)e.push(...o.press);if(o.release.length)t.push(...o.release);if(e.length)await f.pressKey(...e.map(e=>[m[e]]));if(t.length)await f.releaseKey(...t.map(e=>[m[e]]));x.push([i.name,_].join("/")+"/"+RAF_timestamp);continue}}if(!i)await f.releaseIdleKey(...f.clear_list(s))}for(const l of[[0,t.findIndex(e=>e._used&&e._d==h)],[1,t.findIndex(e=>e._used&&e._d!=h)]]){if(l[1]!=-1)continue;const s=l[0]==0?"R":"L";if(M.search("palm_open",{time_limit:500,hand:{_d:l[0]==0?h:R.off_hand},hand_facing:"front",condition:()=>{}})){await f.releaseKey(...f.clear_list(s))}else{await f.releaseIdleKey(...f.clear_list(s))}}}}}(),virtual_mouse:function(){var e;var t;function p(){if(e)return;t=new fp.GestureEstimator([fp.Gestures.VictoryGesture,fp.Gestures.ThumbsUpGesture,M.custom.index_up]);e=true}return{enabled:false,process:async function(e){if(!this.enabled)return;if(!e.posenet_data)return;p();const t=e.posenet_data.handpose;if(!t||!t.length)return;const i=t[0]._d==h?0:1;const o=h=="右"?0:1;if(!t[i]||!t[i]._used)return;const n=screen.width/2;const a=screen.height/2;const s=System._browser.camera.video_canvas;const r=s.width/s.height/(n/a);const _=.5;const l=t[i].annotations.index[0];const c={x:-(-s.width/2+l[0])/(s.width/2*_),y:(-s.height/2+l[1])/(s.height/2*_)};c.x=Math.round(n+THREE.Math.clamp(c.x*r,-1,1)*n);c.y=Math.round(a+THREE.Math.clamp(c.y/r,-1,1)*a);const d=new u(c.x,c.y);await R.setMousePosition(d)}}}()};return R}(),snapshot:function(){var i=false;var o=false;var n;var a;function s(){const e=MMD_SA.THREEX.SL;const t=System._browser.camera;var i=Math.ceil(3-(Date.now()-n)/1e3);if(i<=0){if(!t.visible){l(e);return}DEBUG_show("Capturing...");if(!t.stream){if(!t.bodyPix.enabled){r();return}o=true}else{t.target_devicePixelRatio=1;t.video_track.applyConstraints(t.set_constraints()).then(function(){System._browser.console.log("(Ready to capture)");System._browser.on_animation_update.add(function(){MMD_SA._renderer.devicePixelRatio=window.devicePixelRatio;MMD_SA._renderer.__resize(EV_width,EV_height);if(!t.bodyPix.enabled){System._browser.on_animation_update.add(function(){r()},0,1);return}o=true},0,0)})["catch"](function(e){DEBUG_show("ERROR:camera size failed to update");_()})}System._browser.on_animation_update.remove(s,0)}else if(a!=i){a=i;DEBUG_show(a)}}function r(){const e=MMD_SA.THREEX.SL;const t=System._browser.camera;let i=t.video_canvas_bodyPix;i.width=e.width;i.height=e.height;let o=i.getContext("2d");o.globalCompositeOperation="source-over";const n=t.video_canvas.width;const a=t.video_canvas.height;const s=Math.min(e.width/n,e.height/a);const r=Math.round(n*s);const _=Math.round(a*s);o.drawImage(t.video_canvas,0,0,n,a,(e.width-r)/2,(e.height-_)/2,r,_);if(t.face_detection.enabled)o.drawImage(t.video_canvas_face_detection,0,0);o.save();o.translate(i.width,0);o.scale(-1,1);o.drawImage(e,0,0);o.restore();l(i)}function l(e){i=true;o=false;System._browser.on_animation_update.remove(s,0);e.toBlob(function(e){if(webkit_electron_mode){System._browser.save_file("snapshot_"+Date.now()+".png",e)}else{const t=URL.createObjectURL(e);window.open(t)}_()})}function _(){const e=System._browser.camera;Ldebug.style.posLeft=Ldebug.style.posTop=0;Ldebug.style.transform=Ldebug.style.transformOrigin="";DEBUG_show();o=false;e.target_devicePixelRatio=0;i=false}const e={init:function(){if(i){return true}const e=MMD_SA.THREEX.SL;const t=System._browser.camera;if(MMD_SA.WebXR.session){let e=MMD_SA_options.WebXR&&MMD_SA_options.WebXR.AR;if(!e.dom_overlay||!e.dom_overlay.use_dummy_webgl){DEBUG_show("(No snapshot in AR WebGL)",3);return true}}if(!t.visible){l(e)}else{i=true;n=Date.now();Ldebug.style.posLeft=Ldebug.style.posTop=50;Ldebug.style.transformOrigin="0 0";Ldebug.style.transform="scale(5,5)";a=3;DEBUG_show();DEBUG_show(a);System._browser.on_animation_update.add(s,0,0,-1)}},check_bodyPix:function(){if(!i)return false;const e=System._browser.camera;if(o){l(e.video_canvas_bodyPix)}return true}};return e}(),video_capture:(()=>{const l=document.createElement("canvas");function r(){const e=u.get_specs();l.width=e.width;l.height=e.height;u._fps=e.fps;u.mime_type=e.mime_type;System._browser.on_animation_update.add(t,0,1,-1)}function t(){const e=MMD_SA.THREEX.SL;const t=l.getContext("2d");if(MMD_SA.music_mode){const i=SL_MC_video_obj.vo.media_linked&&SL_MC_video_obj.vo.media_linked.find(e=>e.id=="motion_bg_video");if(i&&i.style.visibility!="hidden"){const o=Math.min(i.videoWidth/i.videoHeight,l.width/l.height);const n=Math.round(Math.min(i.videoWidth,i.videoHeight)*o);const a=Math.min(n,i.videoWidth);const s=Math.min(n,i.videoHeight);const r=(i.videoWidth-a)/2;const _=(i.videoHeight-s)/2;t.drawImage(i,r,_,a,s,0,0,l.width,l.height)}}else{t.fillStyle=document.body.style.backgroundColor||"white";t.fillRect(0,0,l.width,l.height)}if(l.width==e.width&&l.height==e.height){t.drawImage(e,0,0)}else{t.drawImage(e,0,0,l.width,l.height)}}let _;function c(){if(!u.media_recorder||u.started)return;u.started=true;u.media_recorder.start();if(_&&u.stream.getAudioTracks().length&&(MMD_SA.music_mode?SL_MC_video_obj.vo.audio_obj.paused:MMD_SA.motion_player_control.enabled&&MMD_SA.motion_player_control.paused)){SL_MC_Play()}}function d(){System._browser.video_capture.stop()}var p=[];const u={enabled:false,started:false,fps:undefined,target_width:undefined,target_height:undefined,FFmpeg:(()=>{var e;var t;var n;var a;const i={enabled:webkit_electron_mode,load:async function(){if(e)return;e=true;return new Promise(o=>{n=new Worker("js/ffmpeg_worker.js");n.onmessage=e=>{const t=e.data;if(typeof t==="string"){if(t=="OK"){o()}}else{const i=new Blob([t.buffer],{type:t.output_type});return a(i)}}})},encode:async function(...e){await this.load();const t={inputs:[]};for(const i of e){if(i.blob)i.blob=await i.blob.arrayBuffer();t.inputs.push(i)}n.postMessage(t,t.inputs.filter(e=>e.blob).map(e=>e.blob));return new Promise(e=>{a=e})}};return i})(),get_specs:function(){const e=MMD_SA.THREEX.SL;const t=e.width*e.height;let i=this.target_width,o=this.target_height,n=this.fps;if(!i){if(is_mobile){i=1280;o=720;if(e.widthi*o){const _=Math.min(i/e.width,o/e.height);i=Math.min(Math.round(e.width*_/4)*4,i);o=Math.min(Math.round(e.height*_/4)*4,o)}else{i=e.width;o=e.height}const a=["video/webm;codecs=h264","video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm"];let s;for(const l of a){if(MediaRecorder.isTypeSupported(l)){s=l;break}}return{width:i,height:o,fps:n,mime_type:s}},start:function(){if(this.busy){DEBUG_show("(Media recorder still in use)",3);return}if(this.enabled)return;this.enabled=true;r();const e=this._fps==-1?undefined:this._fps;const t=l.captureStream(e);this.stream=new MediaStream;this.stream.addTrack(t.getTracks()[0]);this.audio_src=MMD_SA.music_mode&&SL_MC_video_obj.vo.audio_obj.src;if(this.audio_src&&(!this.FFmpeg.enabled||this.target_mime_type||!SL_MC_video_obj.vo.motion_by_song_name_mode||SL_MC_video_obj.vo.audio_obj.currentTime)){const n=SL_MC_video_obj.vo.audio_obj.captureStream();this.stream.addTrack(n.getTracks()[0])}this.file_ext="."+(this.mime_type.indexOf("x-matroska")!=-1?"mkv":this.mime_type.replace(/^.+[\/]/,"").replace(/\;.+$/,""));this.media_recorder=new MediaRecorder(this.stream,{videoBitsPerSecond:l.width*l.height*4,mimeType:this.mime_type});p.length=0;this.media_recorder.addEventListener("dataavailable",async e=>{p.push(e.data);if(!this.enabled){let e=new Blob(p,{type:this.mime_type});this.stream.getTracks().forEach(e=>{e.stop()});let t=this.file_ext;this.busy=true;if(this.FFmpeg.enabled&&/h264/.test(this.mime_type)&&!this.target_mime_type){try{DEBUG_show("Encoding MP4...");const o=[{name:"video",blob:e}];if(this.audio_src){const n={name:"audio"};if(!this.stream.getAudioTracks().length)n.blob=await fetch(this.audio_src).then(e=>e.blob());o.push(n)}e=await this.FFmpeg.encode(...o);t=".mp4"}catch(i){console.error(i);this.FFmpeg.enabled=false}}this.busy=false;p.length=0;DEBUG_show("🔴Video Capture:OFF",5);System._browser.save_file("video_"+Date.now()+t,e)}});const i=new Promise(e=>{_=e;this.media_recorder.addEventListener("start",()=>{DEBUG_show();DEBUG_show("🔴Video Capture:ON ("+(l.width+"x"+l.height+(u._fps>-1?"/"+u._fps+"fps":""))+"/"+u.mime_type+")",10);if(MMD_SA.music_mode?SL_MC_video_obj.vo.audio_obj.paused:MMD_SA.motion_player_control.enabled&&MMD_SA.motion_player_control.paused){SL_MC_Play()}_();_=null},{once:true})});DEBUG_show();const o=MMD_SA.THREEX.get_model(0).animation.time;if(o||(MMD_SA.music_mode?!SL_MC_video_obj.vo.motion_by_song_name_mode||!SL_MC_video_obj.vo.audio_obj.paused:!MMD_SA.motion_player_control.enabled||!MMD_SA.motion_player_control.paused)){c()}else{if(u.audio_src){window.addEventListener("SA_audio_onended",e=>{System._browser.video_capture.stop()},{once:true})}else if(MMD_SA.motion_player_control.enabled){const s=MMD_SA.THREEX.get_model(0).animation;if(s.enabled){s.mixer.addEventListener("loop",d,{once:true});s.mixer.addEventListener("finished",d,{once:true})}else{window.addEventListener("SA_MMD_model0_onmotionended",d,{once:true})}}const a=MMD_SA_options.reset_rigid_body_physics_step;MMD_SA_options.reset_rigid_body_physics_step=0;new Promise(e=>{DEBUG_show("(Resetting physics)",3);let t=60*3;System._browser.on_animation_update.add(()=>{MMD_SA.seek_motion(o,true);if(MMD_SA.THREEX.get_model(0).animation.enabled)THREE.MMD.getModels()[0].seekMotion(0);if(--t==0)e()},0,0,t)}).then(()=>{MMD_SA.seek_motion(o);if(MMD_SA.motion_player_control.enabled){MMD_SA.motion_player_control.pause()}else{jThree.MMD.pause()}MMD_SA_options.reset_rigid_body_physics_step=a;c()})}DEBUG_show("🔴Video Capture",3);return i},stop:function(){if(!this.media_recorder)return;if(!this.enabled)return;this.enabled=false;System._browser.on_animation_update.remove(t,1);const e=MMD_SA.THREEX.get_model(0).animation;if(e.enabled){e.mixer.removeEventListener("loop",d);e.mixer.removeEventListener("finished",d)}else{window.removeEventListener("SA_MMD_model0_onmotionended",d)}this.media_recorder.stop();this.media_recorder=undefined;this.started=false},pause:function(){if(this.started&&this.media_recorder.state!="paused")this.media_recorder.pause()},resume:function(){if(this.started&&this.media_recorder.state=="paused")this.media_recorder.resume()}};return u})(),hotkeys:(()=>{class s{constructor(e,t){this.id=e.id;this.index=t;this.config=s.config_by_id[this.id]=e;this.event={};this.accelerator=e.accelerator[t];const i=this.accelerator.split("+");i.forEach(e=>{if(/^(Cmd|Command|Ctrl|Control)$/.test(e)){this.event.ctrlKey=true}else if(e=="Shift"){this.event.shiftKey=true}else if(e=="Alt"){this.event.altKey=true}else if(/^[0-9]$/.test(e)){this.event.code="Digit"+e}else if(/^num([0-9])$/.test(e)){this.event.code="Numpad"+RegExp.$1}else if(/^[A-Z]$/.test(e)){this.event.code="Key"+e}})}static config_by_id={};static get_config(e){return s.config_by_id[e]}static accelerators={};static register(e,t,i){if(!s.unregister(e))return false;const o=s.get_config(e);if(i)Object.assign(o,i);o.accelerator=t;t.forEach((e,t)=>{s.accelerators[e]=new s(o,t)});return s.enable_global(e)}static unregister(e){const t=s.get_config(e);if(!t)return false;t.accelerator.forEach(e=>{if(s.accelerators[e].is_global){try{webkit_electron_remote.globalShortcut.unregister(e)}catch(t){}}delete s.accelerators[e]});return true}static enable_global(e,o){if(!webkit_electron_mode)return true;const t=s.get_config(e);if(!t)return;let n=o==null?!!s.accelerators[t.accelerator[0]].config.global_disabled:!o;o=n?false:s.is_global;let a=true;t.accelerator.forEach(e=>{const t=s.accelerators[e];t.config.global_disabled=n;try{if(o){if(!t.is_global&&!t.config.global_disabled)webkit_electron_remote.globalShortcut.register(e,()=>{SA_topmost_window.SA_OnKeyDown(t.event)})}else{if(t.is_global)webkit_electron_remote.globalShortcut.unregister(e)}t.is_global=webkit_electron_remote.globalShortcut.isRegistered(t.accelerator);if(a&&o&&!t.config.global_disabled)a=t.is_global}catch(i){}});return a}static remove(e){if(s.unregister(e))delete s.config_by_id[e]}static add(i){s.remove(i.id);i.accelerator.forEach((e,t)=>{s.accelerators[e]=new s(i,t)});s.enable_global(i.id)}static _is_global=null;static get is_global(){return this._is_global==null?true:this._is_global}static set is_global(e){this._is_global=e}static disabled=false;static register_global(i){if(browser_native_mode){DEBUG_show("(Global hotkey is for app mode only.)",5);return}s.is_global=i==null?s.is_global:i;DEBUG_show("Global hotkey:"+(i?"ON":"OFF"),3);Object.values(s.accelerators).forEach(e=>{try{if(i){if(!e.is_global&&!e.config.global_disabled)webkit_electron_remote.globalShortcut.register(e.accelerator,()=>{SA_topmost_window.SA_OnKeyDown(e.event)})}else{if(e.is_global)webkit_electron_remote.globalShortcut.unregister(e.accelerator)}e.is_global=webkit_electron_remote.globalShortcut.isRegistered(e.accelerator)}catch(t){}})}}window.addEventListener("SA_keydown",o=>{if(s.disabled)return;const n=o.detail.e;Object.values(s.config_by_id).some(e=>{const t=e.accelerator.some(e=>{const t=s.accelerators[e].event;if(t.code&&t.code!=n.code)return false;if(t.ctrlKey&&!n.ctrlKey)return false;if(t.shiftKey&&!n.shiftKey)return false;if(t.altKey&&!n.altKey)return false;return true});if(t){const i=e.process(o);if(i!==false)o.detail.result.return_value=true;return true}})});return s})(),load_script:function(){var n={};var a=function(e,t){this.url=e;this.name=e.replace(/^.+[\/\\]/,"");this.loaded=false;this.resolve_list=[];this.reject_list=[];if(t){const i=this;import(e).then(e=>{i.module=e;i.check_loaded()})}else{const o=document.createElement("script");o.onload=this.check_loaded.bind(this);o.src=e;document.head.appendChild(o)}};a.prototype.check_loaded=function(){this.loaded=true;console.log(this.name+" loaded");this.resolve_list.forEach(e=>{e(this.module)})};a.prototype.make_promise=function(e,t){this.resolve_list.push(e);if(t)this.reject_list.push(t)};return function(e,t){var i=e.replace(/^.+[\/\\]/,"");var o=n[i]=n[i];if(o){if(o.loaded)return Promise.resolve(o.module)}else{o=n[i]=new a(e,t)}return new Promise((e,t)=>{o.make_promise(e,t)})}}(),save_file:function(){var a;return function(e,t,i){const o=!i?t:new Blob([t],{type:i});const n=URL.createObjectURL(o);if(!a){a=document.createElement("a");a.style.display="none";document.body.appendChild(a)}else{URL.revokeObjectURL(a.href)}a.href=n;a.download=e||"";a.click()}}(),update_obj_url:async function(t,i){if(/^(.+\.zip)\#[\/\\](.+)$/i.test(t)){const e=SA_topmost_window.DragDrop._obj_url[t];if(!e||t==e){const o=XMLHttpRequestZIP.zip_by_url(RegExp.$1);let e=await o.file(RegExp.$2.replace(/\\/g,"/"))["async"]("blob");if(i)e=new Blob([e],{type:i});console.log("Object URL (inside zip) updated",t);SA_topmost_window.DragDrop._obj_url[t]=SA_topmost_window.URL.createObjectURL(e)}}},skip_background_rendering:true,skip_rendering:false,rendering_check:function(){if(this.skip_rendering&&!this.hidden)return false;if(!returnBoolean("DisableBackgroundThrottling"))return true;const e=this.skip_background_rendering&&this.hidden;let t=document.getElementById("canvas_DisableBackgroundThrottling");if(e){if(!t){t=document.createElement("canvas");t.id="canvas_DisableBackgroundThrottling";t.width=t.height=1;t.style.position="absolute";t.style.posLeft=t.style.posTop="0px";t.style.zIndex=9999;document.getElementById("Lbody_host").appendChild(t)}t.getContext("2d").clearRect(0,0,t.width,t.height)}if(t)t.style.visibility=e?"inherit":"hidden";return!e},console:{content_list:[],log:function(){for(var e=0;e{var t,n,i;const o=navigator.language+"-default";var a;var e={ja:'"Meiryo UI"',zh:'"Microsoft JhengHei UI"'};const s={get language(){return n},set language(e){t=e||o;n=t.split("-")[0].toLowerCase();if(t==o){i="System default"}else{switch(n){case"en":i="English";break;case"ja":i="日本語";break;case"zh":i="繁體中文";break;default:i="System default"}}},get language_full(){return t},get language_info(){return i},get language_default(){return o},get dictionary(){return a},set dictionary(e){a=Object.assign(a||{},e)},get font(){return e[n]},get:function(e,t=n){if(!a)return"(Now loading...)";let i=a;e.split(".").every(e=>{i=i[e];return i});const o=i&&(i._translation_?.[t]||i._translation_?._default_);return o!=null?o:"("+e+")"}};s.language=null;return s})(),DEBUG_show:function(){const t=self.DEBUG_show;self.DEBUG_show=function(...e){if(System._browser.overlay_mode>0){if(!e.length)t()}else{t(...e)}};return t}()},_hash_sha256:{_hash_cache:{},hash:function(e){if(webkit_electron_mode){var t=webkit_electron_remote.getGlobal("HASH_SHA256");if(t)return t.hash(e)}var i=this._hash_cache[e];if(i)return i;var o=require("crypto").createHash("sha256");o.update(e);i=this._hash_cache[e]=o.digest("hex");return i}},_media_objs_paused_:[],_gadget_resume:function(e){if(e&&!SA_topmost_window.EV_sync_update.RAF_auto_paused)return false;if(!SA_topmost_window.EV_sync_update.RAF_paused)return false;SA_topmost_window.EV_sync_update.RAF_paused=false;SA_topmost_window.EV_sync_update.RAF_auto_paused=false;SA_topmost_window.System._media_objs_paused_.forEach(function(e){if(e.SL_MC_Play)e.SL_MC_Play();else if(e.paused)e.play()});SA_topmost_window.System._media_objs_paused_=[];System._browser.update_tray();return true},_gadget_pause:function(e){if(SA_topmost_window.EV_sync_update.RAF_paused)return false;SA_topmost_window.EV_sync_update.RAF_paused=true;SA_topmost_window.EV_sync_update.RAF_auto_paused=e;var s=SA_topmost_window.System._media_objs_paused_;var t=[top];for(var i=0;i10){clearInterval(System._browser._window_move_timerID);System._browser._window_move_timerID=null}}}(),100)}}}();(()=>{function o(){function e(){const e=document.body.style;webkit_window.setContentSize(e.pixelWidth,e.pixelHeight)}if(webkit_electron_mode&&window.devicePixelRatio!=1){window.removeEventListener("resize",e);window.addEventListener("resize",e,{once:true})}}SA_top_window.moveToAbsolute=function(e,t,i){o();if(absolute_screen_mode&&!i){webkit_window.setPosition(~~e,~~t)}else{this.moveTo(e,t)}};SA_top_window.moveByAbsolute=function(t,i){o();if(absolute_screen_mode){let e=SA_top_window.getPos(true);t+=~~e[0];i+=~~e[1];webkit_window.setPosition(t,i)}else{this.moveBy(t,i)}}})();Object.defineProperty(SA_top_window,"screenLeftAbsolute",{get:function(){return absolute_screen_mode?SA_top_window.getPos()[0]:this.screenLeft}});Object.defineProperty(SA_top_window,"screenTopAbsolute",{get:function(){return absolute_screen_mode?SA_top_window.getPos()[1]:this.screenTop}})},Gadget:{_init:function(){this.Settings.read=this.Settings.readString;this.Settings.write=this.Settings.writeString;Object.defineProperty(this,"onSettingsClosing",{get:function(){return this._onSettingsClosing},set:function(e){this._onSettingsClosing=e;this.settings_window.onbeforeunload=function(){e({closeAction:!!this.returnValue,Action:{commit:true}});System.Gadget.settings_window.System=null;System.Gadget.settings_window.onbeforeunload=null;System.Gadget.settings_window=null}}});var e=new ActiveXObject("Microsoft.XMLDOM");e["async"]=false;e.resolveExternals=false;e.validateOnParse=false;e.load("gadget.xml");this.version=e.selectSingleNode("//version").text},path:xul_mode?XPCOM_object._SA_root:use_SA_browser_mode?toLocalPath(self.location.href).replace(/[\/\\][^\/\\]+$/,""):"",_path_folder:function(){return this.path.replace(/[\/\\][^\/\\]+$/,"")},document:document,version:"1.0.0.0",docked:is_SA_child_animation,visible:true,Settings:{_settings_need_update:false,_settings:{},_changed:{},readString:function(name,raw_read){var v=this._settings[name];v=v?raw_read?decodeURIComponent(v):decodeURIComponent(v).replace(/\$([^\$]+)\$/g,function($0,$1,$2){return eval($1)}):Settings_default._custom_[name]||"";return v},writeString:function(e,t){var i=this._settings[e]||"";var o=encodeURIComponent(t);this._settings[e]=o;if(WallpaperEngine_CEF_mode){var n=JSON.parse(localStorage.Settings_by_path);if(!SA_HTA_folder||!n[SA_HTA_folder]){console.error(SA_HTA_folder)}else{if(n[SA_HTA_folder][e]!=o){n[SA_HTA_folder][e]=o;localStorage.Settings_by_path=JSON.stringify(n)}}}if(i!=o)this._changed[e]=this._settings_need_update=true},_writeSettings:function(e,t){if(!e&&!this._settings_need_update)return;this._settings_need_update=false;SystemEXT._save_settings_only=t;try{this._writeSettings_CORE()}catch(i){}SystemEXT._save_settings_only=false},_writeSettings_CORE:function(){var e=[];var t=this._settings;t._screenLeft=t._screenTop="";for(var i in t){var o=System.Gadget.Settings.readString(i);if(!o)continue;if(i=="_screenLeft"){o=SA_top_window.screenLeftAbsolute}else if(i=="_screenTop"){o=SA_top_window.screenTopAbsolute}e.push('"'+i+'":"'+encodeURIComponent(o)+'"')}SystemEXT.SaveLocalSettings(e)}}},Environment:{win32_env:null,getEnvironmentVariable:function(e){return oShell.ExpandEnvironmentStrings("%"+e+"%")}},Machine:{_init:function(){this._init_memory=function(){if(webkit_mode)return;if(this._WMI_obj_memory)return;try{this._WMI_obj_memory=new WMI_Refresher("Win32_PerfFormattedData_PerfOS_Memory","EV");this._WMI_obj_memory.init()}catch(e){}};Object.defineProperty(this,"availableMemory",{get:function(){if(webkit_mode)return SA_require("os").freemem()/(1024*1024);this._init_memory();var e=this._WMI_obj_memory.update();return e.length?parseInt(e[e.length-1].AvailableMBytes):0}});Object.defineProperty(this,"totalMemory",{get:function(){if(webkit_mode)return SA_require("os").totalmem()/(1024*1024);if(!this._totalMemory){try{var e=new WMI_Refresher("Win32_OperatingSystem");e.init();this._totalMemory=parseInt(e.update()[0].TotalVisibleMemorySize)/1024}catch(t){}}return this._totalMemory}});this.totalMemory=0;var e={_WMI_obj:null,_cpu_obj:null,_get_cpu_obj:null,_init:function(){if(webkit_mode){if(this._get_cpu_obj)return;this._cpu_obj=[{count:-1,cpus:SA_require("os").cpus()}];this._get_cpu_obj=function(){var e=this._cpu_obj;if(e[0].count!=PC_count_absolute){if(e.unshift({count:PC_count_absolute,cpus:SA_require("os").cpus()})==3)e.pop()}return e};return}if(this._WMI_obj)return;try{this._WMI_obj=new WMI_Refresher("Win32_PerfFormattedData_PerfOS_Processor","EV");this._WMI_obj.init()}catch(e){}},item:function(e){if(webkit_mode){var t=this._get_cpu_obj();var i=[];for(var o=0;o<2;o++){var n=t[o].cpus[e].times;var a=0;for(var s in n)a+=n[s];i[o]={total:a,idle:n.idle}}var r=i[0].idle-i[1].idle;var a=i[0].total-i[1].total;return{usagePercentage:a?(1-r/a)*100:0}}return{usagePercentage:parseFloat(this._WMI_obj.update()[e].PercentProcessorTime)}}};Object.defineProperty(e,"count",{get:function(){if(webkit_mode){return this._get_cpu_obj()[0].cpus.length}return this._WMI_obj.update().length-1}});this._CPUs=e;Object.defineProperty(this,"CPUs",{get:function(){this._CPUs._init();return this._CPUs}});var t={_WMI_obj:null,_init:function(){if(this._battery)return;this._battery={level:1,charging:false};if("getBattery"in navigator){var t=this;navigator.getBattery().then(function(e){DEBUG_show("Use Battery Status API",2);t._battery=e})}}};Object.defineProperty(t,"batteryPercentRemaining",{get:function(){return this._battery.level*100}});Object.defineProperty(t,"isPowerLineConnected",{get:function(){return this._battery.level==1||this._battery.charging}});Object.defineProperty(t,"isBatteryCharging",{get:function(){return this._battery.charging}});this._PowerStatus=t;Object.defineProperty(this,"PowerStatus",{get:function(){this._PowerStatus._init();return this._PowerStatus}})}},Shell:{itemFromFileDrop:function(e,t){return{path:""}},itemFromPath:function(e){e=toLocalPath(e);var t=e.replace(/[\/\\][^\/\\]+$/,"");var i=e.replace(/^.+[\/\\]/,"");var o=Shell_OBJ.NameSpace(t);if(o)o=o.ParseName(i);return o?new this._FolderItem(o):null},execute:function(e,t){Shell_OBJ.ShellExecute(e,t)},chooseFolder:function(e,t){var i=Shell_OBJ.BrowseForFolder(0,e,t);return i?new this._FolderItem(i.Self):null},_FolderItem:function(e){if(!this._constructor_initialized){this.constructor.prototype._constructor_initialized=true;this.constructor.prototype.metadata=function(e){var t=this.obj.ExtendedProperty("Dimensions");if(!t){var i=this.obj.Path.replace(/[\/\\][^\/\\]+$/,"");var o=Shell_OBJ.NameSpace(i);t=o.GetDetailsOf(this.obj,26)}return t};Object.defineProperty(this.constructor.prototype,"isFolder",{get:function(){return this.obj.IsFolder}});Object.defineProperty(this.constructor.prototype,"isFileSystem",{get:function(){return(ie9_native?!this.obj.IsFolder:true)&&this.obj.IsFileSystem}});Object.defineProperty(this.constructor.prototype,"isLink",{get:function(){return this.obj.IsLink}});Object.defineProperty(this.constructor.prototype,"link",{get:function(){return new System.Shell._FolderItem(this.obj.GetLink)}});Object.defineProperty(this.constructor.prototype,"path",{get:function(){return this.obj.Path}});Object.defineProperty(this.constructor.prototype,"type",{get:function(){return this.obj.Type}});Object.defineProperty(this.constructor.prototype,"SHFolder",{get:function(){return new System.Shell._Folder(this.obj.GetFolder)}})}this.obj=e},_Folder:function(e){if(!this._constructor_initialized){this.constructor.prototype._constructor_initialized=true;Object.defineProperty(this.constructor.prototype,"Items",{get:function(){return new System.Shell._FolderItems(this.obj.Items())}})}this.obj=e},_FolderItems:function(e){if(!this._constructor_initialized){this.constructor.prototype._constructor_initialized=true;this.constructor.prototype.item=function(e){return new System.Shell._FolderItem(this.obj.Item(e))};Object.defineProperty(this.constructor.prototype,"count",{get:function(){return this.obj.Count}})}this.obj=e}},Debug:{outputString:function(e){}},_browser:{init:function(){document.ondragstart=document.onselectstart=function(e){return false};document.onmousedown=function(e){System._browser.onmousedown(e)};document.onmouseup=function(e){System._browser.onmouseup(e)};document.onmousemove=function(e){System._browser.onmousemove(e)};document.onkeydown=function(e){System._browser.onkeydown(e)};if(!WallpaperEngine_CEF_mode||!is_SA_child_animation||browser_native_mode){document.addEventListener("mouseover",function(e){System._browser.onmouseover(e)},false);document.addEventListener("mouseout",function(e){System._browser.onmouseout_waiting(e)},false)}Object.defineProperty(document,"onmouseover",{set:function(e){System._browser.onmouseover_custom=e}});Object.defineProperty(document,"onmouseout",{set:function(e){System._browser.onmouseout_waiting_custom=e}});var e=w3c_mode?CSSStyleDeclaration.prototype:document.body.style.constructor.prototype;this.document_body_style_pixelWidth=Object.getOwnPropertyDescriptor(e,"pixelWidth");this.document_body_style_pixelHeight=Object.getOwnPropertyDescriptor(e,"pixelHeight");var t=function(){if(System._browser.resize_timerID)clearTimeout(System._browser.resize_timerID);if(System._browser._window_move_timerID){let i=SA_top_window.getPos();System._browser.resize_timerID=setInterval(function(){var t=0;return function(){let e=SA_top_window.getPos(true);if(++t>10||i[0]!=e[0]||i[1]!=e[1]){clearInterval(System._browser.resize_timerID);System._browser.resize_timerID=setTimeout("System._browser.resize()",0)}}}(),10)}else System._browser.resize_timerID=setTimeout("System._browser.resize()",0)};Object.defineProperty(e,"_set",{get:function(){return t}});if(ie9_native){Object.defineProperty(document.body.style,"pixelWidth",{get:function(){return System._browser.document_body_style_pixelWidth.get.call(this)},set:function(e){this._set();System._browser.document_body_style_pixelWidth.set.call(this,e)}});Object.defineProperty(document.body.style,"pixelHeight",{get:function(){return System._browser.document_body_style_pixelHeight.get.call(this)},set:function(e){this._set();System._browser.document_body_style_pixelHeight.set.call(this,e)}})}Object.defineProperty(this,"overlay_mode",function(){var t=0;var i=null;var o=null;return{get:function(){return t},set:function(e){if(e==t)return;switch(e){case 2:if(i==null)i=LdesktopBG_host.style.display;LdesktopBG_host.style.display="none";if(o==null)o=document.body.style.backgroundColor;document.body.style.backgroundColor="#00FF00";case 1:Lmenu_host.style.visibility="hidden";if(this.camera.video_host){this.camera.video_host.style.visibility="hidden";this.camera.video_host.style.display="none"}if(document.getElementById("Ldungeon_UI")){document.getElementById("Ldungeon_UI").style.visibility="hidden";document.getElementById("Ldungeon_inventory").style.visibility="hidden";document.getElementById("Ldungeon_inventory_backpack").style.visibility="hidden";DEBUG_show("(Press Esc to toggle "+(this.overlay_mode_TEMP?"UI":"bottom menu")+" display)",5)}break;default:if(i!=null)LdesktopBG_host.style.display=i;if(o!=null)document.body.style.backgroundColor=o;i=o=null;Lmenu_host.style.visibility="inherit";if(this.camera.video_host){this.camera.video_host.style.visibility="inherit";this.camera.video_host.style.display="block"}if(document.getElementById("Ldungeon_UI")){document.getElementById("Ldungeon_UI").style.visibility="inherit";document.getElementById("Ldungeon_inventory").style.visibility="inherit";document.getElementById("Ldungeon_inventory_backpack").style.visibility="hidden"}}t=e}}}());var i=is_SA_child_animation&&parent.MMD_SA_options&&parent.MMD_SA_options.child_animation_as_texture;if(i){this.onkeydown({keyCode:97+SA_child_animation_id})}var o=System.Gadget.Settings.readString("SA_docked");if(o)System.Gadget.docked=!!parseInt(o);else{if(i)System.Gadget.docked=false}var o=document.createElement("div");o.id="Ldrag_dummy";var n=o.style;n.position="absolute";n.posLeft=n.posTop=0;n.zIndex=999;n.border="1px solid rgba(128,128,128,0.5)";n.visibility="hidden";document.body.appendChild(o);this.body=document.getElementById("Lbody_host")||document.body;if(w3c_mode)this.body.style.transition="opacity 0.5s";this.Opacity=1;var a=document.getElementById("LdesktopBG")&&!is_SA_BG_transparent;if(a){if(!self.SA_wallpaper_src){var s=System.Gadget.path+toLocalPath("\\TEMP\\SA_wallpaper_src.txt");if(FSO_OBJ.FileExists(s)){try{var r=FSO_OBJ.OpenTextFile(s,1);self.SA_wallpaper_src=r.ReadLine();r.Close()}catch(A){}}}if(!self.SA_wallpaper_mask_src){var _=System.Gadget.path+toLocalPath("\\TEMP\\SA_wallpaper_mask_src.txt");if(FSO_OBJ.FileExists(_)){try{var r=FSO_OBJ.OpenTextFile(_,1);self.SA_wallpaper_mask_src=r.ReadLine();r.Close()}catch(A){}}}}if(a)a=System.Gadget.Settings.readString("WallpaperAsBG")||self.SA_wallpaper_src;var l;if(self.CANVAS_Video_Overlay&&CANVAS_Video_Overlay.use_wallpaper_as_bg||self.EQP_use_wallpaper){l=a=true}var m;var c,d;this.Opacity=is_SA_child_animation?parent.document.getElementById("Ichild_animation"+SA_child_animation_id).style.opacity||1:parseFloat(System.Gadget.Settings.readString("Opacity")||1);if(is_SA_child_animation&&!self.SA_wallpaper_src&&!l){a=a&&parent.WMP_wallpaper_mask&&parent.use_HTML5&&!parent.System.Gadget.Settings.readString("CSSTransform3D")&&!System.Gadget.Settings.readString("DisableWallpaperMask");if(a&&self.EQP_video_options&&EQP_video_options.use_canvas_video){a=false;this.C_WMP_wallpaper_mask_resized=document.createElement("canvas");this.C_WMP_wallpaper_mask_mixed_resized=document.createElement("canvas");this.WMPMask_Draw()}this.wallpaper_mask_disabled=!a;if(a)m=parent.WMP_wallpaper_mask}else{var p;if(!is_SA_child_animation){c=System.Gadget.Settings.readString("_screenLeft");d=System.Gadget.Settings.readString("_screenTop")}c=c?parseInt(c):null;d=d?parseInt(d):null;if(a){const D=w3c_mode&&self.SA_wallpaper_src&&/\.(mp4|mkv|webm)$/i.test(SA_wallpaper_src)&&SA_wallpaper_src;this.wallpaper_mask_disabled=WallpaperEngine_CEF_mode||!!System.Gadget.Settings.readString("DisableWallpaperMask");var u,h,f;var n=LdesktopBG.style;try{n.pixelWidth=parent.screen.width;n.pixelHeight=parent.screen.height;var M=oShell.RegRead("HKCU\\Control Panel\\Colors\\Background");n.backgroundColor=/^\#/.test(M)?M:"rgb("+M.replace(/\W+/g,",")+")";u="HKCU\\Control Panel\\Desktop\\";if(WallpaperEngine_CEF_mode)h=oShell.RegRead(u+"Wallpaper")||self.SA_wallpaper_src&&/\.(png|bpm|jpg|jpeg)$/i.test(SA_wallpaper_src)&&SA_wallpaper_src;else h=self.SA_wallpaper_src==""?"":self.SA_wallpaper_src&&/\.(png|bpm|jpg|jpeg)$/i.test(SA_wallpaper_src)&&SA_wallpaper_src||oShell.RegRead(u+"Wallpaper");if(h){if(!this.wallpaper_mask_disabled){m=self.SA_wallpaper_mask_src||h.replace(/\.\w{3,4}$/,"_mask.png");if(!ValidatePath(m))m=null}f=oShell.RegRead(u+"WallpaperStyle");this.updateWallpaper(h,f)}if(D){this.updateWallpaper(D)}this.moveWallpaper(c||0,d||0);if(!is_SA_child_animation||self.SA_wallpaper_src)LdesktopBG_host.style.display="block"}catch(A){console.error(A);LdesktopBG_host.style.display="none"}if(m){if(!this.bg_mask)this.bg_mask="(blank)"}else{p=true}}else{p=true}if(p&&this.Opacity<1&&(w3c_mode||HTA_use_GPU_acceleration)){this.body.style.opacity=this.Opacity;DEBUG_show("Opacity:"+this.Opacity*100+"%",2)}}if(l&&!m)this.bg_mask="(blank)";if(a&&(m||this.bg_mask)){var y=document.createElement("canvas");y.id="C_wallpaper_mask";y._WallpaperAsBG_custom=l;y.onmousedown=function(){return false};if(!is_SA_child_animation||l){try{var g=y.width=parent.screen.width;var b=y.height=parent.screen.height;var v=y.getContext("2d");var w;if(!this.wallpaper_canvas_update){this.wallpaper_canvas_update=function(e,d){v.fillStyle=n.backgroundColor;v.fillRect(0,0,g,b);if(!e){if(self.CANVAS_Video_Overlay&&CANVAS_Video_Overlay._canvas_wall)CANVAS_Video_Overlay._canvas_wall._match_str=null;if(self.EQP_use_wallpaper){EQP_ps.forEach(function(e){if(e.is_wallpaper)e.img.img_obj._match_str=null})}return}var t;if(d=="0"){t=function(){var e=this.width;var t=this.height;var i=parent.screen.width;var o=parent.screen.height;var n,a,s,r,_,l,c,d;if(i>e){n=0;_=(i-e)/2;s=c=e}else{n=(e-i)/2;_=0;s=c=i}if(o>t){a=0;l=(o-t)/2;r=d=t}else{a=(t-o)/2;l=0;r=d=o}var p=C_wallpaper_mask.getContext("2d");p.drawImage(this,n,a,s,r,_,l,c,d);System._browser.BGMask_Create(!m);if(!m)return;var u=new Image;u.onload=function(){var e=C_wallpaper_mask.getContext("2d");e.globalCompositeOperation="destination-in";e.drawImage(this,n,a,s,r,_,l,c,d);C_wallpaper_mask.style.visibility="inherit";DEBUG_show("Use wallpaper mask",2)};u.src=toFileProtocol(m)}}else{t=function(){var e=this.width;var t=this.height;var i=parent.screen.width;var o=parent.screen.height;var n,a,s,r,_;var l=C_wallpaper_mask.getContext("2d");if(d=="6"){n=Math.max(e/i,t/o);r=Math.round((i-e/n)/2);_=Math.round((o-t/n)/2);a=Math.round(e/n);s=Math.round(t/n);l.drawImage(this,0,0,e,t,r,_,a,s)}else{n=Math.min(e/i,t/o);r=Math.round((e/n-i)/2*n);_=Math.round((t/n-o)/2*n);a=Math.round(i*n);s=Math.round(o*n);l.drawImage(this,r,_,a,s,0,0,C_wallpaper_mask.width,C_wallpaper_mask.height)}System._browser.BGMask_Create(!m);if(!m)return;var c=new Image;c.onload=function(){var e=C_wallpaper_mask.getContext("2d");e.globalCompositeOperation="destination-in";e.drawImage(this,r,_,a,s);C_wallpaper_mask.style.visibility="inherit";DEBUG_show("Use wallpaper mask",2)};c.src=toFileProtocol(m)}}if(w)w.onload=null;w=new Image;w.onload=t;w.src=toFileProtocol(e)}}this.wallpaper_canvas_update(h,f);if(!h){setTimeout("System._browser.BGMask_Create(true)",0)}}catch(A){}}var S=y.style;S.position="absolute";S.posLeft=-(c||0);S.posTop=-(d||0);S.zIndex=60;S.visibility="hidden";document.body.appendChild(y);this.mouseover_hide_list.push(y);if(is_SA_child_animation){this.C_WMP_wallpaper_mask_resized=document.createElement("canvas");this.C_WMP_wallpaper_mask_mixed_resized=document.createElement("canvas");if(this.bg_mask)System._browser.BGMask_Create(!m);this.WMPMask_Draw()}}this._s_left=c;this._s_top=d},updateWallpaper:function(e,t){let i=document.getElementById("VdesktopBG");if(e&&/\.(mp4|mkv|webm)$/i.test(e)){if(!i){i=document.createElement("video");i.id="VdesktopBG";const c=i.style;c.position="absolute";c.top=c.left="0px";c.width=parent.screen.width+"px";c.height=parent.screen.height+"px";c.objectFit="cover";LdesktopBG.appendChild(i);i.autoplay=i.loop=true}i.src=toFileProtocol(e);i.style.visibility="inherit";return}if(i){i.pause();i.style.visibility="hidden"}var o=LdesktopBG.style;var n;if(e!=null){e=decodeURIComponent(e);if(this._wallpaper_last!=e){n=true;this._wallpaper_last=e;o.backgroundImage=e?"url("+toFileProtocol(/^(\/|[\w\-]+\:)/.test(e)?e:System.Gadget.path+"/"+e).replace(/\s/g,encodeURIComponent(" "))+")":"";if(this.wallpaper_opacity)o.opacity=this.wallpaper_opacity;if(this.wallpaper_bg_color)LdesktopBG_host.style.backgroundColor=this.wallpaper_bg_color}}else e=this._wallpaper_last;var a="HKCU\\Control Panel\\Desktop\\";if(t==null){t=oShell.RegRead(a+"WallpaperStyle")}if(this._wallpaper_style!=t){n=true;this._wallpaper_style=t}if(t=="0"){o.backgroundSize="";o.backgroundPosition="center center";if(oShell.RegRead(a+"TileWallpaper")=="0"){o.backgroundRepeat="no-repeat"}else{o.backgroundRepeat=""}}else if(t=="2"){o.backgroundSize="100% 100%";o.backgroundPosition="";o.backgroundRepeat=""}else if(t=="6"){o.backgroundSize="contain";o.backgroundPosition="center center";o.backgroundRepeat="no-repeat"}else{o.backgroundSize="cover";o.backgroundPosition="center center";o.backgroundRepeat="no-repeat";if(browser_native_mode){o.width="100%";o.height="100%"}else{o.pixelWidth=parent.screen.width;o.pixelHeight=parent.screen.height}if(windows_mode&&e){var s=loadImageDim(/^(\/|[\w\-]+\:)/.test(e)?e:System.Gadget.path+toLocalPath("\\")+e);if(s.w){var r=parent.screen.width/parent.screen.height;var _=(parent.screen.width*2-parent.screen.availWidth)/(parent.screen.height*2-parent.screen.availHeight);var l=s.w/s.h;if(lr){o.pixelWidth=l>_?parent.screen.width*2-parent.screen.availWidth:Math.round(parent.screen.height*l)}}}}if(this.wallpaper_canvas_update&&n){this.wallpaper_canvas_update(e,t);DEBUG_show("(Wallpaper canvas updated)",2)}},WMPMask_Draw:function(e){if(!this.C_WMP_wallpaper_mask_resized)return;if(!e)e=parent.SL;if(!e||!e.width)return;var t=document.body.style;var i=t.pixelWidth;var o=t.pixelHeight;if(!i)return;var n=0;var a=0;var s=e.width;var r=e.height;var _=this.C_WMP_wallpaper_mask_resized;if(_.width!=s){_.width=s;_.height=r;var l=parent.C_WMP_wallpaper_mask;_.getContext("2d").drawImage(l,0,0,l.width,l.height,0,0,s,r)}var c=this.bg_mask_image_resized;if(c&&c.width!=i){c.width=i;c.height=o;var d=this.bg_mask_image;c.getContext("2d").drawImage(d,0,0,d.width,d.height,0,0,i,o)}var i,o;i=self.B_content_width?B_content_width:document.body.style.pixelWidth;o=self.B_content_height?B_content_height:document.body.style.pixelHeight;var p=parent.SA_child_animation[SA_child_animation_id];var u=p.x;var m=p.y;if(is_SA_child_animation&&parent.EQP_border_width){u-=parent.EQP_border_width;m-=parent.EQP_border_width}var h=u-n;var f=h;if(h<0)h=0;if(f<0)f=-f;else f=0;var M=m-a;var y=M;if(M<0)M=0;if(y<0)y=-y;else y=0;var g=s+n-u;if(g>i)g=i;var b=r+a-m;if(b>o)b=o;var v=this.C_WMP_wallpaper_mask_mixed_resized;if(v.width!=i||v._x!=h||v._y!=M){v.width=i;v.height=o;var w=v.getContext("2d");w.drawImage(_,h,M,g,b,f,y,g,b);if(c)w.drawImage(c,0,0);v._x=h;v._y=M}var S=document.getElementById("C_wallpaper_mask");if(!S)return;S.width=i;S.height=o;var w=S.getContext("2d");w.globalCompositeOperation="copy";w.drawImage(e,h,M,g,b,f,y,g,b);w.globalCompositeOperation="destination-in";w.drawImage(v,0,0)},BGMask_CreateCanvas:function(e,t){if(!e)return null;if(!/^\((.+)\)$/.test(e)){return null}var i=RegExp.$1.split("|");var o=i[0];var n;if(o=="circle"){var a=parseInt(i[1]);var s=parseInt(i[2]);n=document.createElement("canvas");n.width=a;n.height=s;var r=a=a-l)y=(a-h)/(l+1);y=1-(1-y)*M;if(y<0)y=0;var g=1;if(f=s-l)g=(s-f)/(l+1);g=1-(1-g)*M;if(g<0)g=0;var b=yw?w/v:v/w;var A=Math.sqrt(1+S*S);b=1-(1-b)*A;if(b<0)b=0}d[p]=t?Math.round(255*(1-b)):Math.round(255*b)}_.putImageData(c,0,0)}return n},BGMask_Create:function(e){var t=this.bg_mask;if(!t)return;if(e){this.wallpaper_canvas=C_wallpaper_mask;C_wallpaper_mask.style.display="none"}else{var i=this.wallpaper_canvas=document.createElement("canvas");if(!is_SA_child_animation){i.width=parent.screen.width;i.height=parent.screen.height;i.getContext("2d").drawImage(C_wallpaper_mask,0,0)}}if(self.CANVAS_Video_Overlay&&CANVAS_Video_Overlay._canvas_wall)CANVAS_Video_Overlay._canvas_wall._match_str=null;if(self.EQP_use_wallpaper){EQP_ps.forEach(function(e){if(e.is_wallpaper&&e.img)e.img.img_obj._match_str=null})}if(/^\((.+)\)$/.test(t)){this.bg_mask_image=this.BGMask_CreateCanvas(t,is_SA_child_animation);this.BGMask_onload();return}var o=this.bg_mask_image=new Image;o.onload=this.BGMask_onload;o.src=toFileProtocol(t)},BGMask_onload:function(){var e=document.getElementById("C_BG_mask");if(!e){e=document.createElement("canvas");e.id="C_BG_mask";var t=e.style;t.position="absolute";t.posTop=t.posLeft=0;t.zIndex=60+1;document.body.appendChild(e)}if(System._browser.mouseover_hide_list.indexOf(e)==-1)System._browser.mouseover_hide_list.push(e);if(is_SA_child_animation){System._browser.bg_mask_image_resized=document.createElement("canvas")}else{System._browser.BGMask_Draw()}},BGMask_Draw:function(e){if(is_SA_child_animation&&(!document.getElementById("C_wallpaper_mask")||!C_wallpaper_mask._WallpaperAsBG_custom)){this.WMPMask_Draw();return}if(!document.getElementById("C_BG_mask"))return;var t,i,o,n;t=o=self.B_content_width?B_content_width:document.body.style.pixelWidth;i=n=self.B_content_height?B_content_height:document.body.style.pixelHeight;if(o>parent.screen.width)o=parent.screen.width;if(n>parent.screen.height)n=parent.screen.height;var a,s,r,_;var l=C_wallpaper_mask.style;if(l.posLeft>0){a=0;r=l.posLeft}else{a=-l.posLeft;r=0}if(l.posTop>0){s=0;_=l.posTop}else{s=-l.posTop;_=0}if(e){var c=a+","+s+","+o+","+n+","+r+","+_+","+o+","+n;if(e._match_str==c)return;e._match_str=c;e.width=t;e.height=i;var d=e.getContext("2d");d.globalCompositeOperation="copy";d.drawImage(this.wallpaper_canvas,a,s,o,n,r,_,o,n);return}if(!this.bg_mask_image&&this.Opacity==1){document.getElementById("C_BG_mask").style.display="none";return}C_BG_mask.width=t;C_BG_mask.height=i;var d=C_BG_mask.getContext("2d");d.globalCompositeOperation="copy";d.globalAlpha=this.bg_mask_image?1:1-this.Opacity;d.drawImage(this.wallpaper_canvas,a,s,o,n,r,_,o,n);if(this.bg_mask_image){d.globalCompositeOperation="destination-out";d.globalAlpha=this.Opacity;d.drawImage(this.bg_mask_image,0,0,o,n)}else C_BG_mask.style.display="block"},resize_timerID:null,resize_cooling_timestamp:0,resize:function(){var e=false;function i(){if(!e){e=true;setTimeout(function(){window.dispatchEvent(new CustomEvent("SA_resized_once"))},0)}}return function(){this.resize_timerID=null;if(use_SA_browser_mode){let t=document.body.style;if(is_SA_child_animation){let e=parent.document.getElementById("Ichild_animation"+SA_child_animation_id).style;e.width=t.pixelWidth+"px";e.height=t.pixelHeight+"px";i()}else{if(webkit_electron_mode){if(webkit_electron_mode&&SA_topmost_window.System._browser.capturePage_in_process){this.resize_timerID=setTimeout("System._browser.resize()",50);return}if(webkit_electron_mode)System._browser.resize_cooling_timestamp=performance.now();SA_top_window.resizeToAbsolute(t.pixelWidth+(xul_mode?SA_top_window.outerWidth-SA_top_window.innerWidth:0),t.pixelHeight+(xul_mode?SA_top_window.outerHeight-SA_top_window.innerHeight:0))}i()}}}}(),drag_mouse_x:-1,drag_mouse_y:-1,drag_timerID:null,_is_dragging:false,get is_dragging(){return this._is_dragging},set is_dragging(e){this._is_dragging=e;document.body.style.cursor=e?"move":"auto"},mouseout_timerID:null,mouseover_hide_list:[],onmouseover_custom:null,onmouseover:function(e){if(webkit_electron_mode&&(SA_topmost_window.returnBoolean("IgnoreMouseEvents")||SA_topmost_window.returnBoolean("AutoItStayOnDesktop"))&&!SA_topmost_window.webkit_IgnoreMouseEvents_disabled)return;if(this.onmouseover_custom&&this.onmouseover_custom(e))return;if(this.mouseout_timerID){clearTimeout(this.mouseout_timerID);this.mouseout_timerID=null}var t=this.mouseover_hide_list;for(var i=0;i0&&t0&&i20||e.clientYe.is_closing_event);if(MMD_SA_options.Dungeon.dialogue_branch_mode&&!n)return false;new Promise(i=>{if(n){const o=Array.isArray(n.key)?n.key[0]:n.key;let e,t;if(typeof o=="number"){t=o+96}else if(o=="Esc"){e="Escape"}else{e="Key"+o}document.dispatchEvent(new KeyboardEvent("keydown",{code:e,keyCode:t}));System._browser.on_animation_update.add(i,0,0)}else{i()}}).then(()=>{new Promise(e=>{MMD_SA_options.Dungeon.run_event([[{message:{content:System._browser.translation.get("XR_Animator.settings.confirm"),branch_list:[{key:1,func:()=>{e()},ended:true},{key:2}]}}]])}).then(()=>{this.onSettings(true)})});return false}if(!System.Gadget.settingsUI)return false;if(use_inline_dialog){if(document.getElementById("Idialog").style.visibility=="hidden"){document.getElementById("Idialog").contentWindow.location.replace("settings.html")}return true}System._browser.showFocus(true,true);var t=showModalDialog(System.Gadget.settingsUI,self);t=xul_mode?self.returnValue:t;System._browser.showFocus(false);this.onSettingsClosed(t);return true},onSettingsClosed:function(e){if(System.Gadget.onSettingsClosed)System.Gadget.onSettingsClosed({closeAction:!!e,Action:{commit:true}})},onkeydown:function(e){var t=(is_SA_child_animation||document.getElementById("Lchild_animation_parent"))&&!is_SA_child_animation_host;const i=e.altKey;const o=i||!self.MMD_SA||!MMD_SA_options.Dungeon_options||!e.preventDefault;var n=e.keyCode;if(n==67&&i){this.confirmClose();return true}else if(n==69&&o){return this.onSettings()}else if(n==79&&o){var a;if(is_SA_child_animation){var s=parent.document.getElementById("Ichild_animation"+SA_child_animation_id).style;a=this.Opacity;if("_opacity_"in e){a=e._opacity_}else{a-=.25;if(a<.25)a=1}parent.System.Gadget.Settings._settings_need_update=true;parent.SA_child_animation[SA_child_animation_id].opacity=a;s.opacity=a}else if(this.bg_mask){a=this.Opacity;if("_opacity_"in e){a=e._opacity_}else{a-=.25;if(a<.25)a=1}System.Gadget.Settings.writeString("Opacity",a);this.Opacity=a;this.BGMask_Draw()}else if(w3c_mode||HTA_use_GPU_acceleration){var s=this.body.style;a=this.Opacity;if("_opacity_"in e){a=e._opacity_}else{a-=.25;if(a<.25)a=1}System.Gadget.Settings.writeString("Opacity",a);s.opacity=a}else return false;this.Opacity=a;DEBUG_show("Opacity:"+a*100+"%",2);this.update_tray();return true}else if(n==83&&o){var r=System.Gadget.docked?System.Gadget.onUndock:System.Gadget.onDock;if(!r)return false;setTimeout(System._browser.ondockundock,0);return true}else if(t&&(n>=49&&n<49+SA_child_animation_max)&&o){var _=n-49;var l=is_SA_child_animation?parent:self;var c=l.document.getElementById("Ichild_animation"+_);if(!c||!c.contentWindow.is_SA_child_animation){DEBUG_show("(child animation "+(_+1)+" not found)",2);return true}var d=c.contentWindow;var p=d.parent;var u=p.System._browser;if(d.System.Gadget.Settings.readString("CSSTransform3D")||p.System.Gadget.Settings.readString("CSSTransform3D")){if(u._child_selected==_){u._child_selected=null;d.DEBUG_show("(deselected)",2);p.DEBUG_show("(child"+(_+1)+" deselected)",2);return true}u._child_selected=_}d.DEBUG_show("(selected)",2);p.DEBUG_show("(child"+(_+1)+" selected)",2);u.arrangeChildZ(_);d.focus();return true}else if(t&&n==96&&o){var l=is_SA_child_animation?parent:self;var s=l.Lchild_animation_parent.style;s.visibility=s.visibility=="hidden"?"visible":"hidden";if(webkit_mode)s.display=s.visibility=="hidden"?"none":"block";l.System._browser._child_selected=null;return true}else if(t&&(n>=97&&n<97+SA_child_animation_max)&&o){var _=n-97;var l=is_SA_child_animation?parent:self;var c=l.document.getElementById("Ichild_animation"+_);if(!c||!c.contentWindow.is_SA_child_animation){DEBUG_show("(child animation "+(_+1)+" not found)",2);return true}var s=c.style;s.visibility=s.visibility=="hidden"?"visible":"hidden";if(webkit_mode)s.display=s.visibility=="hidden"?"none":"block";l.System._browser._child_selected=null;var m=false;for(var h=0;h=96&&n<96+10){if(self.MMD_SA&&MMD_SA_options.motion_shuffle&&MMD_SA.use_jThree&&MMD_SA.MMD_started){if(this.camera.ML_enabled){}else if(n==96){if(MMD_SA_options.audio_to_dance_disabled)return true;if(MMD_SA_options._motion_shuffle){if(!MMD_SA_options.motion_shuffle_list_default&&MMD_SA_options._motion_shuffle_list_default){MMD_SA_options.motion_shuffle_list_default=MMD_SA_options._motion_shuffle_list_default.slice();MMD_SA._force_motion_shuffle=true}else{MMD_SA_options.motion_shuffle=MMD_SA_options._motion_shuffle.slice(0);MMD_SA_options.motion_shuffle_list_default=null;MMD_SA._force_motion_shuffle=true;DEBUG_show("(MMD motions shuffled)",2)}}}else{var _=n-97;if(MMD_SA_options.motion_by_song_name){if(MMD_SA_options.motion_by_song_name._loading_){DEBUG_show("(music/motion loading)",2);return true}let e=Object.keys(MMD_SA_options.motion_by_song_name).find(e=>{return MMD_SA_options.motion_by_song_name[e].key==_+1});if(e){let t=MMD_SA_options.motion_by_song_name[e].song_path;if(/\.zip\#/i.test(t)){MMD_SA_options.motion_by_song_name._loading_=true;t=t.replace(/^.+[\/\\]([^\/\\]+\.zip)/i,"$1");let e=new self.XMLHttpRequestZIP;e.onload=function(){MMD_SA_options.motion_by_song_name._loading_=false;let e=this.response;e.name=t.replace(/^.+[\/\\]/,"");e.isFileSystem=true;SA_DragDropEMU(e)};e.open("GET",t,true);e.responseType="blob";e.send()}else SA_DragDropEMU(t);return true}}if(MMD_SA_options.audio_to_dance_disabled)return true;if(_>=MMD_SA.normal_action_length){DEBUG_show("(MMD motion not found)",2);return true}if(!MMD_SA_options._motion_shuffle)MMD_SA_options._motion_shuffle=MMD_SA_options.motion_shuffle.slice(0);MMD_SA_options.motion_shuffle=[_];MMD_SA_options.motion_shuffle_list_default=null;MMD_SA._force_motion_shuffle=true;DEBUG_show("(MMD motion changed)",2)}return true}}return false},ondockundock:function(){DEBUG_show("Dock state changed",2);var e=!System.Gadget.docked;System.Gadget.docked=e;System.Gadget.Settings.writeString("SA_docked",!!e==!!is_SA_child_animation?"":e?"1":"0");var t=!e?System.Gadget.onUndock:System.Gadget.onDock;if(!t)return;t()},onmousemove_custom:null,onmousemove:function(e){var t,i;t=this._WE_mouse_x=e.x;i=this._WE_mouse_y=e.y;if(this.onmousemove_custom&&this.onmousemove_custom(e))return;if(!this.is_dragging){if(is_SA_child_animation&&parent.System._browser.is_dragging){parent.System._browser.onmousemove(e)}return}if(!WallpaperEngine_mode){if(absolute_screen_mode){t=SA_top_window.getCursorPos().x;i=SA_top_window.getCursorPos().y}else{t=e.screenX;i=e.screenY}}if(is_SA_child_animation||this._child_selected!=null){var o,n,a;if(is_SA_child_animation){a=SA_child_animation_id;o=self;n=parent}else{a=this._child_selected;o=document.getElementById("Ichild_animation"+a).contentWindow;n=self}n.System.Gadget.Settings._settings_need_update=true;var s=n.SA_child_animation[a];var r=n.document.getElementById("Ichild_animation"+a).style;var _=o.document.body.style;var l=n.document.body.style;var c=s.x+t-this.drag_mouse_x;var d=s.y+i-this.drag_mouse_y;r.posLeft=s.x=c;r.posTop=s.y=d;o.document.getElementById("Ldebug").innerText=n.document.getElementById("Ldebug").innerText="(moving)";o.DEBUG_hide_sec=n.DEBUG_hide_sec=0;o.DEBUG_show("("+c+","+d+")",2)}else{System.Gadget.Settings._settings_need_update=true;this.moveBy(t-this.drag_mouse_x,i-this.drag_mouse_y,e)}this.moveWallpaper();this.drag_mouse_x=t;this.drag_mouse_y=i},moveWallpaper:function(e,t){if(is_SA_child_animation&&(!document.getElementById("C_wallpaper_mask")||!C_wallpaper_mask._WallpaperAsBG_custom))return;if(is_SA_child_animation||document.getElementById("LdesktopBG")&&LdesktopBG.style.display!="none"){if(WallpaperEngine_mode){e=0;t=0}else{if(absolute_screen_mode){if(e==null)e=SA_top_window.screenLeftAbsolute;if(t==null)t=SA_top_window.screenTopAbsolute;var i=SA_top_window.getScreenBounds(e,t);e=-(e-i.x);t=-(t-i.y)}else{if(e==null)e=SA_top_window.screenLeft;if(t==null)t=SA_top_window.screenTop;e=-(e%parent.screen.width);t=-(t%parent.screen.height)}}if(is_SA_child_animation){var o=parent.SA_child_animation[SA_child_animation_id];e-=o.x;t-=o.y}else{var n=(is_SA_child_animation_host&&Ichild_animation0.contentWindow.document.getElementById("LdesktopBG")||LdesktopBG).style;n.posLeft=e;n.posTop=t}if(document.getElementById("C_wallpaper_mask")){var a=C_wallpaper_mask.style;a.posLeft=e;a.posTop=t}}},moveBy:function(e,t,i){SA_top_window.moveByAbsolute(e,t)},update_tray:function(e){try{if(!webkit_electron_mode||IPC.active_window!=self)return;if(this._tray_last_updated==RAF_timestamp){return}this._tray_last_updated=RAF_timestamp;if(!e){e={active_window_id:IPC.active_window_id,click_thru:SA_topmost_window.returnBoolean("IgnoreMouseEvents"),click_thru_partial:SA_topmost_window.returnBoolean("IgnoreMouseEventsPartial"),always_on_top:SA_topmost_window.returnBoolean("AutoItAlwaysOnTop"),stay_on_desktop:SA_topmost_window.returnBoolean("AutoItStayOnDesktop"),use_electron_as_wallpaper:SA_topmost_window.WebKit_object.use_electron_as_wallpaper,auto_pause:SA_topmost_window.returnBoolean("AutoItAutoPause"),opacity:is_SA_child_animation?parent.SA_child_animation[SA_child_animation_id].opacity:parseFloat(System.Gadget.Settings.readString("Opacity")||1),opacity_on_hover:parseFloat(System.Gadget.Settings.readString("OpacityOnHover")||1),size:Settings.CSSTransformFullscreen?-1:Settings.CSSTransformScale,animation_path:Settings.f_path_folder,media_control:self.SL&&SL._mouse_event_main&&SL._mouse_event_main(),MMD:null};var t=[true];for(var i=0;i{if(e.func==t){e.canceled=true}})},run:function(e){var t=[];var i=a[e];if(!i.length)return;var o=[];for(let e=0;e=0){o.push(n)}else{n.func();if(n.loop&&--n.loop!=0)o.push(n)}}a[e]=o}}}(),get css_scale(){return window.devicePixelRatio>=2?.5:1},virtual_numpad_toggle:function(e){if(e==null)e=Lnumpad_row0.style.display=="none";Lnumpad_row0.style.display=e?"inline":"none";Lnumpad_rows.style.display=e?"block":"none";if(e&&self.ChatboxAT)ChatboxAT.chatW_minimize(0,true)},virtual_numpad:function(){var d={};var p={A:1,B:2,C:3,D:4,E:5,F:6,G:7,H:8,X:9};return function(e,t){e.preventDefault();e.stopPropagation();var i=MMD_SA_options.Dungeon&&MMD_SA_options.Dungeon.character.combat_mode;var o=e.target.textContent;var n=d[o]=d[o]||{};var a,s,r;switch(o){case"S":a=16;n.pressed=!n.pressed;const l=document.getElementsByClassName("Lnumpad_button");if(n.pressed&&MMD_SA_options.Dungeon&&MMD_SA_options.Dungeon.event_mode){for(let e=0;ee[1]==RegExp.$1)[0]}}else{for(let e=0;ee[0]==RegExp.$1)[1]}}t=n.pressed?"keydown":"keyup";break;case"+":a=107;if(i){if(t=="keyup")return;n.pressed=!n.pressed;t=n.pressed?"keydown":"keyup"}break;case"-":a=109;break;case"*":a=106;break;case"/":a=111;break;case"⏎":a=13;break;case"J":a=32;break;case"↑":a=38;r="ArrowUp";break;case"↓":a=40;r="ArrowDown";break;case"←":a=37;r="ArrowLeft";break;case"→":a=39;r="ArrowRight";break;default:if(/([0-9])/.test(o))a=parseInt(o)+96;else r="Key"+o}if(n.timeoutID)clearTimeout(n.timeoutID);if(n.intervalID)clearTimeout(n.intervalID);n.timeoutID=n.intervalID=null;let _=new KeyboardEvent(t,{bubbles:true,cancelable:true,key:o,keyCode:a,code:r,shiftKey:d["S"]&&d["S"].pressed});document.dispatchEvent(_);if(t=="keydown"){if(/[\+S]/.test(o)&&(o!="+"||i)){e.target.style.opacity="0.75"}else{n.timeoutID=setTimeout(function(){n.intervalID=setInterval(function(){document.dispatchEvent(_)},100)},400)}}else{e.target.style.opacity=""}}}(),P2P_network:function(){var o;var n=0;var a={events:{peer:{},connection:{handshake_request:function(e,t){console.log("P2P_network: Remote Peer"+"("+t.peer+"/"+t.label+"/host) responding handshake request from Peer-"+e.index+"("+e.id+")");t.send({handshake:{request:true}})},handshake_respond:function(e,t,i){if(i.request){t.status="connected";console.log("P2P_network: Remote Peer"+"("+t.peer+"/"+t.label+"/client)'s handshake request accepted from Peer-"+e.index+"("+e.id+")");t.send({handshake:{accepted:true}})}else if(i.accepted){t.status="connected";console.log("P2P_network: Remote Peer"+"("+t.peer+"/"+t.label+"/host) accepted handshake request from Peer-"+e.index+"("+e.id+")");if(e.para.events.connection.handshake_request_accecpted&&e.para.events.connection.handshake_request_accecpted[t.label]){e.para.events.connection.handshake_request_accecpted[t.label]({peer:e,connection:t,handshake:i});delete e.para.events.connection.handshake_request_accecpted[t.label]}}else{console.log("P2P_network: Remote Peer"+"("+t.peer+"/"+t.label+"/host) rejected handshake request from Peer-"+e.index+"("+e.id+")");if(e.para.events.connection.handshake_request_rejected&&e.para.events.connection.handshake_request_rejected[t.label]){e.para.events.connection.handshake_request_rejected[t.label]({peer:e,connection:t,handshake:i});delete e.para.events.connection.handshake_request_rejected[t.label]}}},data:function(e,t,i){}},send_message:function(e){if(!e.command)t.content_window.ChatboxAT.ChatShow([e.name+": "+e.msg]);return null}}};function s(t,i){this._connection=i;this.status="connecting";t.connections[i.label]=this;var o=this;i.on("data",function(e){if(e.handshake){t.para.events.connection.handshake_respond(t,o,e.handshake)}else{t.para.events.connection.data(t,o,e)}});i.on("close",function(e){console.log("P2P_network: DataConnection"+"("+i.peer+"/"+i.label+"/host) closed");o.close(t)})}s.prototype.send=function(e){this._connection.send(e)};s.prototype.close=function(e){if(!e.connections[this.label])return;if(e.para.events.connection.close&&e.para.events.connection.close(e,this))return;delete e.connections[this.label];var t=this;setTimeout(function(){t._connection.close();t._connection=null},1e3)};Object.defineProperty(s.prototype,"peer",{get:function(){return this._connection.peer}});Object.defineProperty(s.prototype,"label",{get:function(){return this._connection.label}});function r(){}Object.defineProperty(r.prototype,"length",{get:function(){return Object.keys(this).length}});function e(t=Object.clone(a)){this.para=t;this.id=null;var e=this._peer=new Peer;this.index=n;this.connections=new r;this.status="connecting";var i=this;e.on("open",function(e){n++;if(!o)o=i;i.id=e;i.status="connected";console.log("P2P_network: Peer-"+i.index+"("+e+") connected");i.para.events.peer.open&&i.para.events.peer.open(i)});e.on("error",function(e){console.log("P2P_network: Peer-"+i.index+" error",e);if(i.para.events.peer.error_by_connection){i.para.events.peer.error_by_connection(e);delete i.para.events.peer.error_by_connection}else i.para.events.peer.error&&i.para.events.peer.error(i,e)});e.on("connection",function(e){if(t.events.peer.connection&&t.events.peer.connection(i,e))return;console.log("P2P_network: Remote Peer"+"("+e.peer+"/"+e.label+"/client) connecting to Peer-"+i.index+"("+i.id+")");e.on("open",function(){console.log("P2P_network: Remote Peer"+"("+e.peer+"/"+e.label+"/client) connected to Peer-"+i.index+"("+i.id+")");new s(i,e)})})}e.prototype.connect=function(n,e){var a=this;return new Promise(function(i,o){var e=function(){var e={serialization:"json"};var t=a._peer.connect(n,e);t.on("open",function(){console.log("P2P_network: Remote Peer"+"("+t.peer+"/"+t.label+"/host) connecting to Peer-"+a.index+"("+a.id+")");var e=new s(a,t);a.para.events.connection.handshake_request(a,e);a.para.events.connection.handshake_request_accecpted=a.para.events.connection.handshake_request_accecpted||{};a.para.events.connection.handshake_request_rejected=a.para.events.connection.handshake_request_rejected||{};a.para.events.connection.handshake_request_accecpted[t.label]=i;a.para.events.connection.handshake_request_rejected[t.label]=o;delete a.para.events.peer.error_by_connection});t.on("error",function(e){console.log("P2P_network: Remote connection failed",e);o(e)});a.para.events.peer.error_by_connection=o};switch(a.status){case"connected":e();break;default:setTimeout(function(){o(a)},0)}})};var t={peer:e,get peer_default(){return o},status:"off",get content_window(){return is_SA_child_animation_host?document.getElementById("Ichild_animation0").contentWindow:self},process_message:function(e,t){var i=this.peer_default;if(!i)return e;var o=this.content_window.document.getElementById("Flogin").id.value;var n=this.content_window.document.getElementById("Flogin").pass.value;var a=this.content_window.MMD_SA_options;var s=(o||a&&a.model_para_obj.character&&a.model_para_obj.character.name||"Anonymous").substring(0,16);var r=i&&i.connections.length;var _;if(!/^\//.test(e)){_=i.para.events.send_message({name:s,msg:e,id:o,pass:n})}else{var l,c,d;var p=this.content_window.ChatboxAT.checkChatCommand(e);l=p.command;c=p.para1;d=p.para2;_=i.para.events.send_message({name:s,msg:e,command:l,para1:c,para2:d,id:o,pass:n})}if(!t)this.content_window.document.getElementById("Fchat").msg.value="";if(_!=null)return _;return e}};return t}(),camera:function(){var je;var c,r;var d;var Fe,Le;var Ce;var Be;var T=true;var t=new URLSearchParams(self.location.search.substring(1));var He="";var Oe="";var i=true;var _;var k=0;var P="";function n(){var s=je.video;if(!s.videoWidth||s.readyState<2){return}if(d.busy||RAF_animation_frame_unlimited&&!MMD_SA.WebXR.session&&P==je.video_frame_id&&!Ce.bb_clear){Fe.wireframe._skip_frame=true;return}P=je.video_frame_id;k=RAF_timestamp;var n=je.video_canvas;var r=n.getContext("2d");if(Ce.bb_clear){if(s.pause&&!s.paused||--Ce.bb_clear<=0||Ce._bb&&Ce._bb_waiting){Ce.bb_clear=Ce._bb=Ce._bb_waiting=null;r.globalCompositeOperation="copy"}else{if(Ce._bb){r.globalCompositeOperation="source-over";r.fillStyle="black";let e=Ce._bb[3];let t=Ce._bb[0];let i=Ce._bb[1]-e;let o=Ce._bb[2]-t;e=Math.max(e-i*.25,0);t=Math.max(t-o*.25,0);i=Math.min(i*1.5,n.width);o=Math.min(o*1.5,n.height);if(je.video_flipped){e=n.width-(e+i)}r.fillRect(e,t,i,o);Ce._bb=null;Ce._bb_waiting=true}return}}var _,l;if(MMD_SA_options.user_camera.pixel_limit.disabled){_=s.videoWidth;l=s.videoHeight}else if(je.is_local_media){_=s.videoWidth;l=s.videoHeight;const e=MMD_SA_options.user_camera.pixel_limit.current||MMD_SA_options.user_camera.pixel_limit._default_;if(_*l>e[0]*e[1]){const t=Math.sqrt(_*l/(e[0]*e[1]));_=Math.round(_/t);l=Math.round(l/t)}}else{_=je.target_width;l=je.target_height}var a=MMD_SA_options.user_camera.display.webcam_as_bg?{scale:1,top:0}:MMD_SA_options.user_camera.display.video;if(!a.scale){if(n.style.pixelWidth!=window.innerWidth||n.style.pixelHeight!=window.innerHeight){n.style.width=window.innerWidth+"px";n.style.height=window.innerHeight+"px"}}else{let e=a.scale*(je.display_floating?MMD_SA_options.user_camera.display.floating_scale||MMD_SA_options.user_camera.display.floating&&1||.5:1);let i=~~(window.innerWidth*e);let o=~~(window.innerHeight*e);if(n.style.pixelWidth!=i||n.style.pixelHeight!=o){n.style.width=i+"px";n.style.height=o+"px";let e=(window.innerWidth-i)/2;let t=(window.innerHeight-o)/2;n.style.left=e*(1+(a.left!=null?a.left:-1))+"px";n.style.top=t*(1+(a.top!=null?a.top:0))+"px"}n.style.objectFit="contain"}if(n.width!=_||n.height!=l){n.width=_;n.height=l;r.globalCompositeOperation="copy";if(je.video_flipped){r.translate(_,0);r.scale(-1,1)}}if(_==s.videoWidth&&l==s.videoHeight){r.drawImage(s,0,0)}else{let e=_/l;let t=s.videoWidth/s.videoHeight;let i,o,n,a;if(e<=t){n=s.videoHeight*e;i=(s.videoWidth-n)/2;a=s.videoHeight;o=0}else{n=s.videoWidth;i=0;a=s.videoWidth/e;o=(s.videoHeight-a)/2}r.drawImage(s,i,o,n,a,0,0,_,l)}n.style.visibility=!je.visible||d.enabled||c.initialized&&c.worker_initialized&&!c.dets||je.hidden_enforced?"hidden":"inherit"}function a(){if(d.enabled){d.update_frame()}else{if(Fe.enabled){Fe.update_frame(true)}else if(c.enabled){c.update_frame(true)}if(Ce.enabled||Be.enabled){D(true)}}const i=je.video_canvas_facemesh.style;if(!MMD_SA_options.user_camera.display.webcam_as_bg){const e=je.video_canvas.style;const t=MMD_SA_options.user_camera.display.wireframe.align_with_video?1:MMD_SA_options.user_camera.display.wireframe.scale||(is_mobile?.25:1);const o=~~(e.pixelWidth*t);const n=~~(e.pixelHeight*t);if(i.pixelWidth!=o||i.pixelHeight!=n){i.pixelWidth=o;i.pixelHeight=n;if(MMD_SA_options.user_camera.display.wireframe.align_with_video){i.posLeft=e.posLeft;i.posTop=e.posTop}else{let e=(window.innerWidth-o)/2;let t=(window.innerHeight-n)/2;i.left=e*(1+(MMD_SA_options.user_camera.display.wireframe.left!=null?MMD_SA_options.user_camera.display.wireframe.left:1))+"px";i.top=t*(1+(MMD_SA_options.user_camera.display.wireframe.top!=null?MMD_SA_options.user_camera.display.wireframe.top:-1))+"px"}}i.objectFit=e.objectFit}i.visibility=je.ML_enabled&&!MMD_SA_options.user_camera.display.wireframe.hidden?"inherit":"hidden"}var R;function s(){if(je.initialized){SL.style.transform=SL_2D_front.style.transform=je.mirror_3D?"scaleX(-1)":"none";je.video_canvas.style.transform=je.display_flipped?"scaleX(-1)":"none";je.reset_video_canvas()}if(!R&&je.initialized){R=true;System._browser.on_animation_update.add(n,0,0,-1);System._browser.on_animation_update.add(a,2,1,-1)}}function l(){SL.style.transform=SL_2D_front.style.transform=je.mirror_3D?"scaleX(-1)":"none";je.video_canvas.style.transform="none";je.reset_video_canvas();if(je.visible)return;if(R&&!je.ML_enabled){R=false;System._browser.on_animation_update.remove(n,0);System._browser.on_animation_update.remove(a,1);je.video_canvas_facemesh.style.visibility="hidden"}}var o=100;function p(e){if(!je.visible)return;var t=e.detail.keyCode;if(t==107)o+=10;else if(t==109)o-=10;else return;o=Math.max(Math.min(o,180),20);var i=je.video_canvas.getContext("2d");if(o==1){i.filter="none";DEBUG_show("Brightness:100%",2)}else{i.filter="brightness("+o+"%) contrast("+(100+(o-100)*.25)+"%)";DEBUG_show("Brightness:"+o+"%",2)}e.detail.result.return_value=true}var u=0;function m(e){if(!e)e=je.local_src||(webkit_electron_mode?"C:\\Users\\user\\Documents\\_.mp4":System.Gadget.path+"/js/headtrackr.mp4");if(/\.(png|jpg|jpeg|bmp|webp)$/i.test(e)){if(!je._image){je._image=new Image;Object.defineProperty(je._image,"videoWidth",{get:function(){return this.width}});Object.defineProperty(je._image,"videoHeight",{get:function(){return this.height}});Object.defineProperty(je._image,"readyState",{get:function(){return this.complete?4:0}})}if(je.video&&je.video.pause)je.video.pause();je.video=je._image;je._image.src=toFileProtocol(e)}else{je.video=je._video;je.video.loop=true;if(!je.video._initialized){je.video._initialized=true;je.video.addEventListener("canplaythrough",function(e){if(je.stream){if(je.media_control_enabled){je.media_control_enabled=false}}else{je.media_control_enabled=true;let e=it.speed;if(e){je.video.playbackRate=e;if(e<1)je.video.muted=true}else{je.video.playbackRate=1}}});je.video.addEventListener("ended",function(e){if(it.speed)it.stop()})}je.video.src=toFileProtocol(e)}je.video_id=e;je.local_src=e}let h=false;function f(e){SL_MC_Timeupdate(je.video)}window.addEventListener("MMDStarted",()=>{function e(e){if(!System._browser.camera.poseNet.enabled)return;const t=MMD_SA.MMD.motionManager.para_SA;if(!t.motion_tracking_upper_body_only||!t.motion_tracking?.arm_as_leg)return;window.addEventListener("SA_camera_poseNet_update",()=>{t.motion_tracking.arm_as_leg.enabled=!t.motion_tracking.arm_as_leg.enabled;tt.reset_to_default_motion_once=true;DEBUG_show("Arm-as-leg control:"+(t.motion_tracking.arm_as_leg.enabled?"ON":"OFF"),3)},{once:true})}const t={id:"arm_to_leg_control_mode",accelerator:["Alt+Q"],process:e};if(System._browser.hotkeys._hotkey_config){System._browser.hotkeys._hotkey_config.push(t)}else{System._browser.hotkeys.add(t)}});var M=false;function X(){Je();var e=Fe.enabled||Ce.enabled;if(M==!!e)return;M=!!e;if(e){s();tt.reset();tt.add_events();DEBUG_show("(Camera ML Mode:ON)",2)}else{if(je.initialized){je.video_canvas_face_detection.style.visibility="hidden";je.video_canvas_facemesh.style.visibility="hidden";l()}tt.remove_events();je._info="";DEBUG_show("(Camera ML Mode:OFF)",2)}}var U,K,ot;var qe,Te,Ie,ze;var Xe,Ue,Ke,nt,at,st;var Ge,We;var G,W;var le;var rt;var _t={};var Qe=["親","人","中","薬","小"];var lt=["thumb","index","middle","ring","pinky"];var Ve=["0","1","2","3"];var ct={};window.addEventListener("jThree_ready",()=>{qe=new THREE.Vector3;Te=new THREE.Vector3;Ie=new THREE.Vector3;ze=new THREE.Vector3;le=new THREE.Vector3;Xe=new THREE.Quaternion;Ue=new THREE.Quaternion;Ke=new THREE.Quaternion;nt=new THREE.Quaternion;at=new THREE.Quaternion;st=new THREE.Quaternion;Ge=new THREE.Matrix4;We=new THREE.Quaternion;G=new THREE.Vector2;W=new THREE.Vector2;rt=new THREE.Quaternion;["左","右"].forEach(e=>{_t[e]=new System._browser.data_filter([{type:"one_euro",id:"shoulder_rot",para:[30,1,5,1,1]}])});for(const e of["左","右"]){const i=ct[e]=[];for(let t=0;t<5;t++){i[t]=[];for(let e=0;e<4;e++){i[t][e]={pos:new THREE.Vector3,rot:new THREE.Vector3}}}}});var e;var y;var g;var dt=true;var pt=true;var ut;var Q=true;var b,mt,v;var Ne=false;var ht=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"];var ft=[0,2,5,7,8,11,12,13,14,15,16,23,24,25,26,27,28];var Mt=[];ht.forEach(e=>{Mt.push({part:e,score:0})});var Ye,Ze;var A;function I(){if(A)return;A=true;const r=THREE.MMD.getModels()[0];const o=r.mesh.bones_by_name;const s=MMD_SA.THREEX.get_model(0);const e=o["左腕"].pmxBone.origin;const t=o["左ひじ"].pmxBone.origin;MMD_SA_options.model_para_obj.left_arm_z_rot=Math.PI/2+Math.atan2(t[1]-e[1],t[0]-e[0]);const i=o["左腕IK"].pmxBone.origin;MMD_SA_options.model_para_obj.left_arm_to_IK_xy=[e[0]-i[0],e[1]-i[1],e[2]-i[2]];MMD_SA_options.model_para_obj.left_arm_length=MMD_SA.TEMP_v3.fromArray(MMD_SA_options.model_para_obj.left_arm_to_IK_xy).length();MMD_SA_options.model_para_obj.left_palm_length=MMD_SA.TEMP_v3.fromArray(o["左手首"].pmxBone.origin).distanceTo(MMD_SA._v3a.fromArray(o["左中指1"].pmxBone.origin));MMD_SA_options.model_para_obj.arm_IK_offset={"左":(new THREE.Vector3).fromArray(o["左腕"].pmxBone.origin).sub(Te.fromArray(o["左腕IK"].parent.pmxBone.origin)),"右":(new THREE.Vector3).fromArray(o["右腕"].pmxBone.origin).sub(Te.fromArray(o["右腕IK"].parent.pmxBone.origin))};let n=o["右腕"].pmxBone.origin;MMD_SA_options.model_para_obj.shoulder_width=Math.abs(e[0]-n[0]);MMD_SA_options.model_para_obj.arm_axis={"左":(new THREE.Vector3).fromArray(i).sub(MMD_SA.TEMP_v3.fromArray(e)).normalize()};MMD_SA_options.model_para_obj.arm_axis["右"]=MMD_SA_options.model_para_obj.arm_axis["左"].clone().setX(-MMD_SA_options.model_para_obj.arm_axis["左"].x);const a=o["左足"].pmxBone.origin;const _=o["左足首"].pmxBone.origin;MMD_SA_options.model_para_obj.hip_center=(new THREE.Vector3).fromArray(a).setX(0);MMD_SA_options.model_para_obj.hip_center_offset=(new THREE.Vector3).fromArray(o["下半身"].pmxBone.origin).sub(MMD_SA_options.model_para_obj.hip_center);MMD_SA_options.model_para_obj.spine_length=o["首"].pmxBone.origin[1]-MMD_SA_options.model_para_obj.hip_center.y;MMD_SA_options.model_para_obj.left_heel_height=_[1];MMD_SA_options.model_para_obj.leg_IK_offset={"左":(new THREE.Vector3).fromArray(o["左足"].pmxBone.origin).sub(Te.fromArray(o["左足IK"].parent?.pmxBone?.origin||[0,0,0])),"右":(new THREE.Vector3).fromArray(o["右足"].pmxBone.origin).sub(Te.fromArray(o["右足IK"].parent?.pmxBone?.origin||[0,0,0]))};MMD_SA_options.model_para_obj.left_leg_upper_length=a[1]-o["左ひざ"].pmxBone.origin[1];MMD_SA_options.model_para_obj.left_leg_lower_length=o["左ひざ"].pmxBone.origin[1]-_[1];MMD_SA_options.model_para_obj.left_leg_length=MMD_SA_options.model_para_obj.left_leg_upper_length+MMD_SA_options.model_para_obj.left_leg_lower_length;MMD_SA_options.model_para_obj.left_leg_IK=[a[0]-_[0],a[1]-_[1],a[2]-_[2]];let l=["左","右"];Ye={};l.forEach(n=>{["腕","ひじ"].forEach((e,t)=>{let i=n+e;let o=MMD_SA.get_bone_axis_rotation(r.mesh,i);Ye[i]={name:i,axis_rot:o,parent:t==0?{axis_rot:new THREE.Quaternion}:Ye[n+"腕"]};Ye[i].axis_rot_offset_inv=(new THREE.Quaternion).multiplyQuaternions(Ye[i].parent.axis_rot,MMD_SA.TEMP_q.copy(Ye[i].axis_rot).conjugate())})});const c={};c[1]=(new THREE.Quaternion).setFromEuler(MMD_SA.TEMP_v3.set(0,-Math.PI/2*1,Math.PI/2*1),"YZX");c[-1]=(new THREE.Quaternion).setFromEuler(MMD_SA.TEMP_v3.set(0,-Math.PI/2*-1,Math.PI/2*-1),"YZX");Ze={};Ze[1]=(new THREE.Quaternion).multiplyQuaternions(c[1],MMD_SA._q1.copy(Ye["左腕"].axis_rot).conjugate());Ze[-1]=(new THREE.Quaternion).multiplyQuaternions(c[-1],MMD_SA._q1.copy(Ye["右腕"].axis_rot).conjugate());MMD_SA_options.model_para_obj.rot_hand_adjust_base=c;MMD_SA_options.model_para_obj.rot_hand_adjust=Ze;MMD_SA_options.model_para_obj.finger_base={};l.forEach(s=>{Qe.forEach((e,t)=>{let n=s+e+"指";let i=t==0&&o[n+Ve[0]]?0:1;if(!o[n+Ve[i+0]])return;let a=MMD_SA_options.model_para_obj.finger_base[s+t]={base_index:i};for(let i=a.base_index+(t==0?0:-1),o=i;o<3;o++){let e=n+Ve[a.base_index+(o-i)];let t=MMD_SA.get_bone_axis_rotation(r.mesh,e,true);Ye[e]={name:e,axis_rot:t,parent:o==i?Ye[s+"ひじ"]:Ye[n+Ve[a.base_index+(o-1-i)]]};Ye[e].axis_rot_offset_inv=(new THREE.Quaternion).multiplyQuaternions(Ye[e].parent.axis_rot,MMD_SA.TEMP_q.copy(Ye[e].axis_rot).conjugate())}})});for(const y in Ye){if(y.indexOf("指")!=-1){MMD_SA.TEMP_v3.setEulerFromQuaternion(Ye[y].axis_rot,"ZYX");MMD_SA.TEMP_v3.z*=-1;Ye[y].axis_rot.setFromEuler(MMD_SA.TEMP_v3,"ZYX")}Ye[y].axis_rot_inv=Ye[y].axis_rot.clone().conjugate()}for(const y in Ye){if(y.indexOf("指")!=-1){Ye[y]._axis_rot_offset_inv_z=MMD_SA.TEMP_v3.setEulerFromQuaternion(MMD_SA.TEMP_q.copy(Ye[y].axis_rot_offset_inv).premultiply(Ye[y].parent.axis_rot_inv).multiply(Ye[y].parent.axis_rot),"ZYX").z}}MMD_SA_options.model_para_obj.rot_arm_adjust=Ye;console.log(Ye);const d=MMD_SA_options.model_para_obj.colliders_for_hands=MMD_SA_options.model_para_obj.colliders_for_hands||{};const p=qe.fromArray(s.get_bone_origin_by_MMD_name("左手首")).distanceTo(Te.fromArray(s.get_bone_origin_by_MMD_name("左中指"+Ve[1])));d.left_hand={children:[{bone:"leftHand",offset:[p,0,0],radius:p}]};d.generate_hand_parameters=function(){const e=this.left_hand.children[0].offset;const t=.5;const i={left:{offset:{x:e[0]*t,y:e[1]*t,z:e[2]*t}},right:{offset:{x:-e[0]*t,y:e[1]*t,z:e[2]*t}}};return i};d.reset_hit=function(){this._hit_={};for(const e of["左","右"])this._hit_[e]={}};d.reset_hit();d.record_hit=function(e,t){d._hit_[t][e.name.split("|")[0]]=true};d.debug_hit=(()=>{const n={head:"Head",chest:"Chest",spine:"Waist","下半身":"Hip"};return function(e,t){let i="";if(Ce.enabled&&Ce.body_collider.enabled){for(const t of["左","右"]){const o=t=="左"?"L":"R";i+="👊-"+o+":"+(Object.keys(this._hit_[t]).map(e=>n[e]).join(",")||"(no collider hit)")+"\n"}}this.reset_hit();return i}})();let u;if(s.type=="VRM"){u=s.model.springBoneManager.colliders.filter(e=>{if(!e.shape.radius)return false;let t=e;while(t){t=t.parent;if(t?.isBone){if(t.name=="Head")return true;break}}})}else if(!MMD_SA.THREEX.enabled){const g=o["頭"]._index;u=r.pmx.rigids.filter(e=>e.bone==g&&(e.shape==0||e.shape==2)).map(e=>{return{shape:{radius:e.size[0],offset:{x:e.ofs[0],y:e.ofs[1],z:e.ofs[2]}}}})}const m=s.get_bone_origin_by_MMD_name("頭")[1]-s.get_bone_origin_by_MMD_name("首")[1];const h=Math.max(s.para.shoulder_width/3,m);const f=s.type=="VRM"?1/MMD_SA.THREEX.VRM.vrm_scale:1;let M=[{shape:{radius:h,offset:{x:0,y:h*f,z:h*.5*f}}}];if(!d.head){d.head={get scale(){return Ce.body_collider.head.size_percent/100},_head_colliders:u,_head_colliders_default:M,reset:function(){let e=this._head_colliders_default;const i=.7071067811865476;const o=qe.set(9999,9999,9999);const n=Te.set(-9999,-9999,-9999);e.forEach(e=>{let t=MMD_SA.TEMP_v3.copy(e.shape.offset).addScalar(e.shape.radius*i);n.max(t);t=MMD_SA.TEMP_v3.copy(e.shape.offset).addScalar(-e.shape.radius*i);o.min(t)});const t=new MMD_SA.THREEX.THREEX.Box3(o,n);const a=t.getBoundingSphere(new MMD_SA.THREEX.THREEX.Sphere(t.getCenter(Ie)));d.head.parent={is_parent:true,bone:"head",offset:s.type=="VRM"?s.process_position(Ie.multiplyScalar(MMD_SA.THREEX.VRM.vrm_scale)).toArray():Ie.toArray(),radius:a.radius};d.head.children=e.map(e=>{function t(e,t,i){const o=-s.para.spine_length/5;return e.z>o}const i={validate:t,rotation_base:true};return{bone:"head",offset:s.type=="VRM"?s.process_position(MMD_SA.TEMP_v3.copy(e.shape.offset).multiplyScalar(MMD_SA.THREEX.VRM.vrm_scale)).toArray():MMD_SA.TEMP_v3.copy(e.shape.offset).toArray(),radius:e.shape.radius,z_push:i}});if(d.head.children.length==1){d.head.children=[Object.assign({},d.head.parent,{is_parent:false,z_push:d.head.children[0].z_push,use_vector_filter:true})];d.head.parent=null}console.log(d.head)},generate_colliders:(()=>{let n,e;let t;return function(){if(!Ce.body_collider.head.enabled)return[];if(n===this.scale&&e===Ce.body_collider.head.reaction_type)return t;n=this.scale;e=Ce.body_collider.head.reaction_type;t=(this.parent&&[this.parent]||[]).concat(this.children||[]).map((e,t)=>{const i=d.generate_hand_parameters();const o=e.radius*n+i.left.offset.x;return Object.assign({type:"bone",name:e.bone,offset:{x:e.offset[0],y:e.offset[1],z:e.offset[2]},hand_affected:i,auto_scale:false,peak_barrier:true,is_parent:e.is_parent,use_vector_filter:e.use_vector_filter,z_push:!e.is_parent&&Ce.body_collider.head.reaction_type=="z_push"?e.z_push:null,magnet_id:"head_collider"+t,keep_validation_state_until_reset:true,on_hit:!e.is_parent&&d.record_hit},e.line_end?{magnet_type:"line",line_end:{x:e.line_end[0],y:e.line_end[1],z:e.line_end[2]},effective_distance:o,peak_distance:o}:{radius:o,peak_radius:o})});return t}})()}}d.head.reset();if(!d.chest){const b=s.para.shoulder_width/4;d.chest={get scale(){return Ce.body_collider.chest.size_percent/100},children:[-1,1].map(e=>{function t(e,t,i){return true}const i=s.get_bone_origin_by_MMD_name("首")[1]-s.para.spine_length/3-s.get_bone_origin_by_MMD_name("上半身2")[1];return{bone:"chest",offset:[b*e,i,b*.5],radius:b,z_push:{validate:t,rotation_base:true}}}),generate_colliders:(()=>{let o;let e;return function(){if(!Ce.body_collider.chest.enabled)return[];if(o===this.scale)return e;o=this.scale;e=(this.children||[]).map(e=>{const t=d.generate_hand_parameters();const i=e.radius*o+t.left.offset.x;return{type:"bone",name:e.bone,offset:{x:e.offset[0]*(1-THREE.Math.clamp(o-1,0,1)*.5),y:e.offset[1],z:e.offset[2]*(1+THREE.Math.clamp(o-1,0,2)*.5)},hand_affected:t,auto_scale:false,radius:i,peak_radius:i,peak_barrier:true,is_parent:e.is_parent,z_push:e.z_push,on_hit:d.record_hit}})}})()}}if(!d.waist){const v=s.para.shoulder_width/4;d.waist={get scale(){return Ce.body_collider.waist.size_percent/100},children:[0,-v*.75,-v*1.5].map(e=>{function t(e,t,i){return true}return{bone:"spine",offset:[-v*1,e,-v*.5],radius:v*1.5,line_end:[v*1*2,0,0],z_push:{validate:t,rotation_base:true}}}),generate_colliders:(()=>{let o;let e;return function(){if(!Ce.body_collider.waist.enabled)return[];if(o===this.scale)return e;o=this.scale;e=(this.children||[]).map(e=>{const t=d.generate_hand_parameters();const i=e.radius*o+t.left.offset.x;return{type:"bone",name:e.bone,offset:{x:e.offset[0],y:e.offset[1],z:e.offset[2]},hand_affected:t,magnet_type:"line",line_end:{x:e.line_end[0],y:e.line_end[1],z:e.line_end[2]},auto_scale:false,effective_distance:i,peak_distance:i,peak_barrier:true,is_parent:e.is_parent,use_vector_filter:true,z_push:e.z_push,on_hit:d.record_hit}})}})()}}if(!d.hip){const w=s.get_bone_origin_by_MMD_name("左足")[0];const S=MMD_SA.TEMP_v3.copy(s.para.hip_center_offset).negate();d.hip={get scale(){return Ce.body_collider.hip.size_percent/100},children:[{bone:"下半身|hips",offset:[S.x-w*.5,S.y-w,S.z-w*.5],radius:w*.6,line_end:[w+w*.5*2,0,0],z_push:{validate:()=>true,rotation_base:true}},{bone:"下半身|hips",offset:[S.x-w*.5,S.y-w,S.z],radius:w*1.2,line_end:[w+w*.5*2,0,0]}],generate_colliders:(()=>{let n;let e;return function(){if(!Ce.body_collider.hip.enabled)return[];if(n===this.scale)return e;n=this.scale;e=(this.children||[]).map((e,t)=>{const i=d.generate_hand_parameters();const o=e.radius*n+i.left.offset.x;return{type:"bone",name:e.bone,offset:{x:e.offset[0],y:e.offset[1]-Math.max(n-1,0)*e.radius*.5,z:e.offset[2]},hand_affected:i,magnet_type:"line",line_end:{x:e.line_end[0],y:e.line_end[1],z:e.line_end[2]},auto_scale:false,effective_distance:o,peak_distance:o,peak_barrier:true,is_parent:e.is_parent,use_vector_filter:true,z_push:e.z_push,on_hit:d.record_hit}})}})()}}}window.addEventListener("MMDStarted",()=>{if(MMD_SA_options.is_XR_Animator)I()});const H={};let O;let q;let V;class N{constructor(e,t){this.id=e;this.worker=t}initialized=false}async function Y(){if(U)return;U=true;I();var t=[];if(is_mobile){t.push("use_mobilenet=1")}if(Q){t.push("use_holistic=1");e=y=false;pt=ut=true}if(e){t.push("use_human=1");b=true;e=true;y=false;g=false;mt=true;v=true}else if(y){t.push("use_mixed_human=1");e=true;y=true;g=true;v=true}else{e=false;y=false;g=true}if(pt){t.push("use_blazepose=1");ut=true}if(ut){t.push("use_mediapipe=1");if(e){mt=true;v=false}dt=true}if(dt){t.push("use_movenet=1")}if(MMD_SA_options.user_camera.ML_models.worker_disabled&&Fe.initialized&&!Fe.worker_initialized){await new Promise(function(e,t){var i=setInterval(()=>{if(Fe.worker_initialized){clearInterval(i);e()}},100)})}else{await Fe.init()}if(MMD_SA_options.user_camera.ML_models.worker_disabled){O={postMessage:function(e,t){PoseAT.onmessage({data:e})}};let e=document.createElement("script");e.onload=function(){PoseAT.init(O,t)};e.src="js/pose_lib.js";document.head.appendChild(e)}else{V="js/pose_worker.js"+(t.length?"?"+t.join("&"):"");q=Ce.use_holistic?"legacy_holistic":"tasks_vision";console.log("Web worker ID:"+q);O=new Worker(V);H[q]=new N(q,O)}O.onmessage=vt}var yt=function(){let g,b;window.addEventListener("jThree_ready",()=>{g=new System._browser.data_filter([{type:"one_euro",id:"head_rot",para:[30,1,2,1,4]}]);b=new System._browser.data_filter([{type:"one_euro",id:"head_chest_rot",para:[30,.25,.5,1,3]}])});return function(e,t){const i=e.bones_by_name[t];const o=this.skin[t];let n=Math.max(Math.min(o[0].t_delta/o[0].t_delta_frame,1),0);const a=MMD_SA.TEMP_q.set(0,0,0,1);var s=o[0].no_blending?MMD_SA._q2.copy(o[0].rot):MMD_SA._q2.copy(o[1].rot).slerp(o[0].rot,n);if(!i){o[0]._rot_from_pose.copy(s);return}const r=MMD_SA.MMD.motionManager.para_SA;const _=Ce.enabled||r.motion_tracking_upper_body_only;var l=o[0].rot_parent;if(!l){const m=_&&r.motion_tracking?.head_rotation_weight||0;if(m==1){l=new THREE.Quaternion}else{l=MMD_SA.get_bone_rotation_parent(e,t,e).conjugate();if(_)l.premultiply(Ue.copy(this._rot_body_offset).multiply(this._rot_body_camera));if(m)l.slerp(a,m)}}o[0]._rot_parent=l;if(o[0].info[1]=="facemesh"&&this.skin[t+"_DUMMY_"]){let e=Math.min(Math.max(.25-o[0]._rot_ratio,0)*5,1);s.slerp(this.skin[t+"_DUMMY_"][0]._rot_from_pose,e*e*.667);o[0]._rot_mixed=s.clone()}let c=s.toAxisAngle()[1]%(Math.PI*2);if(c>Math.PI)c=Math.PI*2-c;else if(c<0&&c<-Math.PI)c+=Math.PI*2;c=Math.abs(c);n=Ce.use_3D_pose?.5:.3+Math.max(c-Math.PI/2,0)/(Math.PI/2)*.2;var d=Xe.multiplyQuaternions(l,s);d.fromArray(g.filter(d.toArray()));var p=qe.setEulerFromQuaternion(d,"YZX");var u=[p.x<0?n+(.5-n)*.5:n,n,n];d.setFromEuler(Te.fromArray(p.toArray().map((e,t)=>Math.sign(e)*Math.min(Math.abs(e),Math.PI/2)*u[t])),"YZX");if(_){const h=r.motion_tracking;const f=1-(h?.motion_default_weight?.head||0)*this.camera_weight;if(f){const M=Ue.copy(i.quaternion).premultiply(Ke.copy(this._body_motion_rot[0]["首"]).conjugate());i.quaternion.slerp(M,f);M.copy(e.bones_by_name["頭"].quaternion).premultiply(Ke.copy(this._body_motion_rot[0]["頭"]).conjugate());e.bones_by_name["頭"].quaternion.slerp(M,f)}}i.quaternion.multiply(d);e.bones_by_name["頭"].quaternion.premultiply(d);o[0]._rot_neck=i.quaternion.clone();o[0]._rot_head=e.bones_by_name["頭"].quaternion.clone();if(it.active){it.set_boneKey(t,null,i.quaternion,true);it.set_boneKey("頭",null,e.bones_by_name["頭"].quaternion,false)}if(n<.5){const i=e.bones_by_name["上半身2"];const y=Xe.setFromEuler(qe.fromArray(b.filter(qe.setEulerFromQuaternion(s,"YZX").multiply(Te.fromArray(u.map(e=>1-e*2))).toArray())),"YZX");if(!Ce.enabled){tt.add("skin","上半身2",{no_blending:true,rot:y.clone()})}else{i.quaternion.multiply(y)}}}}();var gt=1*10;var $e=function(){var g=[];var o;var L;var C,B,H;window.addEventListener("jThree_ready",()=>{o=new System._browser.data_filter([{type:"one_euro",id:"camera_depth",para:[30,1,1/5,1,1]}]);L=new System._browser.data_filter([{type:"one_euro",id:"camera_distance",para:[30,1,1/5,1,1]}]);$e.v_hip=C=new THREE.Vector3;H=new THREE.Vector3;B=new System._browser.data_filter([{type:"one_euro",id:"v_hip",para:[30,1,1/2,1,3]}])});var O;var i;function e(e){O=null;i=0;var r=e.keypoints[5];var _=e.keypoints[6];var l=e.keypoints[11];var c=e.keypoints[12];if(r.score<=0||_.score<=0)return;let d,p;if(e.keypoints3D_raw){d=e.keypoints3D_raw[11];p=e.keypoints3D_raw[12]}else{d=e.keypoints3D[5];p=e.keypoints3D[6]}g=[{point2D:[{position:new THREE.Vector2},{position:new THREE.Vector2}],data3D:{length:0,z_diff:0}}];const u=Ce.spine_length_ref;var t=je.video_canvas.width;var m=je.video_canvas.height;var h=true;let f=1;if(l.score>0&&c.score>0){h=l.position.y>m||c.position.y>m;let e=MMD_SA._v3a.addVectors(d,p).multiplyScalar(.5);let t=e.length();let i=MMD_SA.TEMP_v3.set(0,1,0);i.y*=-1;let o=MMD_SA._v3b.setEulerFromQuaternion(MMD_SA.TEMP_q.setFromUnitVectors(i,e.normalize()),"ZXY").x;f=Math.abs(o)/(Math.PI/2);f=f<=1?Math.max(f-.5,0)/.5:Math.max(2-f,0);let n=G.copy(l.position).add(c.position).multiplyScalar(.5);let a=W.copy(r.position).add(_.position).multiplyScalar(.5);let s=n.distanceTo(a);a.copy(n);a.y=a.y-s/Math.abs(Math.cos(o));g[0].point2D[0].position.copy(a);g[0].point2D[1].position.copy(n);g[0].data3D.length=u*(t*2)}if(f){let e=MMD_SA._v3b.copy(d).sub(p);let t=e.length();let i=MMD_SA.TEMP_v3.set(1,0,0);let o=MMD_SA._v3b.setEulerFromQuaternion(MMD_SA.TEMP_q.setFromUnitVectors(i,e.normalize()),"ZYX").y;let n=W.copy(r.position).add(_.position).multiplyScalar(.5);let a=n.clone();let s=G.copy(r.position).distanceTo(_.position);const M=1.5;n.y=n.y+s*M/Math.abs(Math.cos(o));O=n.y;if(n.y>je.video_canvas.height){a.y=Math.max(a.y-(n.y-je.video_canvas.height),0);n.y=je.video_canvas.height}if(g[0].data3D.length!=0){let e=Math.abs(o)/(Math.PI/2);e=e<=1?Math.max(e-.5,0)/.5:Math.max(2-e,0);f*=1-e}g[0].point2D[0].position.lerp(a,f);g[0].point2D[1].position.lerp(n,f);g[0].data3D.length=g[0].data3D.length*(1-f)+u*(t*M*2)*f}i=g[0].point2D[1].position.y{h.set((e.point2D[0].position.x/u*2-1)*M,(-(e.point2D[0].position.y/m)*2+1)*y,.5);var t=MMD_SA._v3a.copy(h.unproject(p._camera_reset).sub(p._camera_reset.position).normalize());h.set((e.point2D[1].position.x/u*2-1)*M,(-(e.point2D[1].position.y/m)*2+1)*y,.5);var i=MMD_SA._v3b.copy(h.unproject(p._camera_reset).sub(p._camera_reset.position).normalize());var o,n;o=e.data3D.length;n=e.data3D.z_diff;let a=Math.sqrt(Math.pow(t.x-i.x*t.z/i.z,2)+Math.pow(t.y-i.y*t.z/i.z,2)+0);let s=t.x-i.x*t.z/i.z+(t.y-i.y*t.z/i.z)+0;let r=s/a;let _=1;let l=(Math.sqrt(o*o+1)-1)/(a/r);t.multiplyScalar(l);let c=2*Math.tan(Math.PI/180*MMD_SA.THREEX.camera.obj.fov/2)/.9326153163099972;c=1+(c-1)*.5;let d=c*Ce.hip_depth_scale_percent/100;f.push({z:-t.z*1.5*d,id:e.id})});f.sort((e,t)=>t.z-e.z);var i=f[0].z;this.z=i;z=o.filter(i);this.z_smoothed=z;g=[]}var q;function n(e){if(MMD_SA.WebXR.session){C.set(0,0,0);return}H.copy(C);const F=MMD_SA.MMD.motionManager.para_SA;const t=je.video_canvas.width;const i=je.video_canvas.height;const o=e.keypoints[11];const n=e.keypoints[12];const a=e.keypoints[5];const s=e.keypoints[6];const r=a.score>0&&s.score>0?G.copy(a.position).add(s.position).multiplyScalar(.5):null;const _=t/i;const l=SL.width/SL.height;const c=_0&&n.score>0){p=W.copy(o.position).add(n.position).multiplyScalar(.5);const T=p.x;const I=p.y;u=1;if(r){if(I<0||I>i){u=1-Math.min((I<0?-I:I-i)/Math.abs(r.y-I),1)}if(T<0||T>t){u=Math.min(u,1-Math.min((T<0?-T:T-t)/Math.abs(r.x-T),1))}u=Math.max(u-.5,0)/.5}C.set(((o.position.x+n.position.x)/2/t*2-1)*c,(-((o.position.y+n.position.y)/2/i)*2+1)*d,.5).unproject(je._camera_reset).sub(je._camera_reset.position).normalize()}let m;if(u<1){m=Ie.set(((a.position.x+s.position.x)/2/t*2-1)*c,(-((a.position.y+s.position.y)/2/i)*2+1)*d,.5).unproject(je._camera_reset).sub(je._camera_reset.position).normalize()}if(gt)$e.estimate();const h=je._camera_reset.position.z-THREE.MMD.getModels()[0].mesh.position.z;let f=h;if(gt&&$e.z)f=$e.z_smoothed||$e.z;const M=MMD_SA.THREEX.get_model(0).para.spine_length;const y=.95;let g=u;if(g==0&&O){const I=O;if(I>i){g=1-Math.min((I<0?-I:I-i)/Math.abs(r.y-I),1);g=Math.max(g-.5,0)/.5}}let b=g+(1-g)*y;L.filter(b);f*=b;if(u>0)C.multiplyScalar(-f/C.z);if(m){const z=Ce.spine_length_ref;const j=MMD_SA.TEMP_v3.set(0,-z,0);C.lerp(m.multiplyScalar(-f/m.z).add(j),1-u)}let v=MMD_SA.THREEX.get_model(0).para.left_leg_length/10.569580078125;const w=v>1?1:Math.pow(1/v,.75);let S=Ce.hip_depth_scale_percent/100;let A;if(w*S>1){q=w*S;A=1/S}else{q=1;A=w}C.multiply(MMD_SA.TEMP_v3.set(A,A,w));if(isNaN(C.x)||isNaN(C.y)||isNaN(C.z)){console.error("(Invalid v_hip)");C.copy(H);return}let D=1;C.z=Je("v_hip_z",C.z,!!Ce._upper_body_only_mode);const E=B.filters[0].filter;const k=Math.min(Math.max(M/4.97462,1),Math.max(MMD_SA.THREEX.get_model(0).para.left_leg_length/10.569580078125,1));const x=k*10;const P=Math.max(Math.abs(C.z)-x,0)/x*D;let R=Ce._upper_body_only_mode?.2:.2+P*.8;E.minCutOff=Math.min(R,10);E.beta=Math.min(R*(Ce._upper_body_only_mode?1/k:1),1);E.dCutOff=Math.min(R,1);C.fromArray(B.filter(C.toArray()))}return{prepare:e,estimate:t,get_hip_center:n,get z_scale_base(){return q},get grounding_factor(){return i}}}();var w=(()=>{function k(e,t,i,o,n){function a(e){return e*e}const s=Math.sqrt;var r=1+a(o);var _=-t*2+o*(n-i)*2;var l=a(t)+a(n-i)-a(e);var c=a(_)-4*r*l;if(c>=0){var d=[(-_+s(a(_)-4*r*l))/(2*r),(-_-s(a(_)-4*r*l))/(2*r)];if(c==0){return[d[0]]}return d}return[]}var x,P,R;var T;var I,z;window.addEventListener("jThree_ready",()=>{x=new THREE.Vector3;P=new THREE.Vector3;R=new THREE.Vector3;T=new THREE.Quaternion;I=new THREE.Plane;z=new THREE.Plane});return function(e,t,i){const o=e._elbow_y;const n=MMD_SA.get_bone_position(t,i+"ひじ",t);if(n.y>o)return;const a=MMD_SA.get_bone_position(t,i+"手首",t);const s=MMD_SA.get_bone_position(t,i+"腕",t);const r=s;const _=R.copy(a).sub(r);const l=n;const c=(l.x*_.x+l.y*_.y+l.z*_.z-(r.x*_.x+r.y*_.y+r.z*_.z))/_.lengthSq();const d=MMD_SA._v3b.set(r.x+_.x*c,r.y+_.y*c,r.z+_.z*c);const p=_.normalize();const u=P.copy(n).sub(d).normalize().negate();const m=x.crossVectors(p,u).normalize();I.setFromNormalAndCoplanarPoint(p,n);z.setFromNormalAndCoplanarPoint(MMD_SA.TEMP_v3.set(0,1,0),MMD_SA._v3a.set(0,o,0));const h=I.intersectPlane(z);if(!h)return;Ge.set(p.x,p.y,p.z,0,u.x,u.y,u.z,0,m.x,m.y,m.z,0,0,0,0,1);We.setFromBasis(Ge);const f=MMD_SA.TEMP_v3.copy(n).sub(d).length();let M=z.intersectLine(new THREE.Line3(n,d),R);if(!M)return;M=-M.sub(n).length();h[1].applyQuaternion(We);const y=h[1].y/h[1].z;n.sub(s);n.applyQuaternion(We);const g=k(f,n.z,n.y,y,M);if(!g.length)return;const b=g.map(e=>{e-=n.z;return Math.asin(e/f)});const v=i=="左"?1:-1;const w=MMD_SA.get_bone_rotation(t,"上半身2",null,t);const S=T.copy(w).conjugate();const A=P.copy(a).sub(s).normalize().applyQuaternion(S);const D=e.use_smallest_angle?b.sort((e,t)=>Math.abs(e)-Math.abs(t))[0]:b[v==-1?b.length-1:0];const E=MMD_SA.TEMP_q.setFromAxisAngle(A,D);t.bones_by_name[i+"腕"].quaternion.premultiply(E)}})();var bt=(()=>{let l;let t;window.addEventListener("jThree_ready",()=>{t=new THREE.Vector3;l=new System._browser.data_filter([{type:"one_euro",id:"z_lean",para:[30,.5,.5,1,1]}])});return function(a,e){const s=MMD_SA.MMD.motionManager.para_SA;let r=Je("lean",e?1:0,e);if(!r)return;if(Fe.enabled&&Fe.lean_tracking&&Fe.face_width_average&&Fe.face_width_average>.075){let o=0;o+=(2-(Fe.lean_tracking-1))/2;let n=Fe.face_width/Math.max(je.video_canvas.width,je.video_canvas.height);const _=Fe.face_width_average*(1.1+.1*o);if(n>_){let t=!Ce.enabled||s.motion_tracking_upper_body_only?1:.5;let i=Math.sqrt(a.x*a.x+a.y*a.y);if(a.z*t10){a.z=0}else{a.normalize();t.set(0,a.y,a.z).normalize();a.z*=Math.pow(Math.abs(t.z)/2,s.motion_tracking.lean_reduction_power)*2/Math.abs(t.z)}}}})();const Je=(()=>{let a={};return function(e,i,t){if(!e){a={};return}let o=a[e];if(!o){o=a[e]={};switch(e){case"lean":o.type=1;o.duration=500;break;case"hip_angle_x":o.type=1;o.duration=1e3;break;case"v_hip_z":o.type=1;o.duration=500;break;case"hip":o.type=3;o.duration=1e3;o.v=new THREE.Vector3;o.v_to_lerp=new THREE.Vector3;break}}const n=o.type;if(o.state==null){o.timestamp=o.duration;if(n==1){o.v=o.v_to_lerp=i}else if(n>=3){o.v.copy(i);o.v_to_lerp.copy(i)}}else if(o.state===t){let e=RAF_timestamp-(o._timestamp||RAF_timestamp);o.timestamp=Math.min(o.timestamp+e,o.duration);let t=1-o.timestamp/o.duration;if(o.type==1){if(t)i=i*(1-t)+o.v_to_lerp*t;o.v=i}else if(o.type==3){if(t)i.lerp(o.v_to_lerp,t);o.v.copy(i)}else if(o.type==4){if(t)i.slerp(o.v_to_lerp,t);o.v.copy(i)}}else{o.timestamp=0;if(n==1){i=o.v;o.v_to_lerp=i}else if(n>=3){i.copy(o.v);o.v_to_lerp.copy(i)}}o._timestamp=RAF_timestamp;o.state=t;return i}})();const et=[0,0,0];var vt=function(){function we(e,t){let i=Ye[t];e.premultiply(i.axis_rot).multiply(i.axis_rot_inv);e.multiplyQuaternions(i.axis_rot_offset_inv,e)}function G(e,t){if(Ce.IK_disabled_check(t))return;var i=e.bones_by_name[t];var o=this.skin[t];var n=t.charAt(0);var a=MMD_SA.TEMP_v3.fromArray(e.bones_by_name[n+"足"].pmxBone.origin);var s=MMD_SA.get_bone_position(e,n+"足","全ての親").sub(a);i.position.add(s);e.bones_by_name[n+"ひざ"].quaternion.set(0,0,0,1);if(it.active){if(MMD_SA_options.user_camera.ML_models.pose.use_legIK){const r=MMD_SA.TEMP_v3.copy(i.position);r.sub(qe.fromArray(e.bones_by_name[t].pmxBone.origin).sub(Te.fromArray(e.bones_by_name[t].parent?.pmxBone?.origin||[0,0,0])));it.set_boneKey(t,r,o[0].rot?i.quaternion:null,true)}window.addEventListener("SA_MMD_model"+e._model_index+"_process_bones_after_IK",()=>{it.set_boneKey(n+"足",null,e.bones_by_name[n+"足"].quaternion,false);it.set_boneKey(n+"ひざ",null,e.bones_by_name[n+"ひざ"].quaternion,false)},{once:true})}i.quaternion.set(0,0,0,1)}function Se(e,t){const i=t.charAt(0);const o=e.bones_by_name;const n=o[t].quaternion;a.call(this,e,t);if(MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only)n.premultiply(rt)}function Ae(e,t){const i=this.skin[t];if(!i._IK_disabled)e.bones_by_name[t].quaternion.set(0,0,0,1)}function a(e,t){const i=t.charAt(0);const o=e.bones_by_name;const n=o[t].quaternion;const a=this.skin[i+"肩"];if(a){let e=Math.max(Math.min(a[0].t_delta/a[0].t_delta_frame,1),0);n.premultiply(MMD_SA.TEMP_q.copy(a[1].rot).slerp(a[0].rot,e).conjugate())}}var W=(()=>{var f;var M;window.addEventListener("jThree_ready",()=>{f=new THREE.Vector3;M=new System._browser.data_filter([{type:"one_euro",id:"grounding_y",para:[30,1,1,1,1]}])});return function(n,e){var t=n.bones_by_name[e];var i=this.skin[e];var o=Math.max(Math.min(i[0].t_delta/i[0].t_delta_frame,1),0);const a=MMD_SA.THREEX.get_model(0);const s=MMD_SA.MMD.motionManager.para_SA;const r=qe.copy($e.v_hip);if(MMD_SA.WebXR.session){r.set(0,0,0)}else{const h=je._camera_reset.position.z-n.position.z;r.z=MMD_SA_options.user_camera.ML_models.pose.estimate_z_depth===false?0:h+r.z}if(MMD_SA_options.user_camera.ML_models.pose.position_offset)r.add(MMD_SA_options.user_camera.ML_models.pose.position_offset);i[0].pos.copy(r);f.copy(i[1].pos).lerp(i[0].pos,o);let _=Te.set(0,0,0);let l=Math.max(a.para.left_leg_length/MMD_SA_options.model_para_obj.left_leg_length,1);let c,d;if(!MMD_SA.THREEX.enabled||s.motion_tracking_upper_body_only){c=MMD_SA.get_bone_position(n,"左足","全ての親");d=MMD_SA.get_bone_position(n,"右足","全ての親");_.copy(c).add(d).multiplyScalar(.5).sub(MMD_SA_options.model_para_obj.hip_center).negate();_.multiplyScalar(l)}else{c=a.get_bone_position_by_MMD_name("左足",true);d=a.get_bone_position_by_MMD_name("右足",true);let e=a.get_bone_position_by_MMD_name("センター",true).sub(a.para.hip_center_offset);_.copy(c).add(d).multiplyScalar(.5).sub(e).negate()}if(s.motion_tracking_upper_body_only)f.y/=$e.z_scale_base;let p=a.para.hip_center.y+a.para.spine_length/2-(11.364640235900879+4.97462/2);p*=.75;if(p<0)p*=.85;if(!s.motion_tracking_upper_body_only){f.y-=p*.5}f.z+=Ce.hip_z_position_offset_percent/100*a.para.left_leg_length*2;f.y+=Ce.hip_y_position_offset_percent/100*a.para.left_leg_length;if(Ce.auto_grounding&&!s.motion_tracking_upper_body_only){let e,t;e=a.get_bone_position_by_MMD_name("左足首",true);t=a.get_bone_position_by_MMD_name("右足首",true);let i=e.y0){THREE.MMD.getModels()[n._model_index].resetPhysics(15+m*2/u)}le.copy(f)}})();var Q=(()=>{const L=(()=>{const s={};let r,_;window.addEventListener("jThree_ready",()=>{r=new THREE.Vector3;_=new THREE.Quaternion});return function(e,t,i){const o=e.magnet_id||e.name;let n=s[o];if(!n){n=s[o]={};for(const a of["左","右"])n[a]={vector:new THREE.Vector3,f:new System._browser.data_filter([{type:"one_euro",id:"magnet_vector",para:[30,.5,.5,1,4]}])}}n=n[t];_.setFromUnitVectors(r.set(0,0,1),i);_.fromArray(n.f.filter(_.toArray()));return n.vector.set(0,0,1).applyQuaternion(_)}})();const o={};function n(e){if(!e.keep_validation_state_until_reset)return null;const t=e.magnet_id||e.name;let i=o[t];if(!i){i=o[t]={}}return i}function C(e,t){const i=n(e);return i?i[t]!==false:true}function B(e,t,i){const o=n(e);if(o)o[t]=i}const H=(()=>{const s={};return function(e,t,i){if(!e.use_reference_point_filter)return i;const o=e.magnet_id||e.name;let n=s[o];if(!n){n=s[o]={};for(const a of["左","右"])n[a]=new System._browser.data_filter([{type:"one_euro",id:"reference_point_filter",para:[30,.5,.5,1,3]}])}n=n[t];return i.fromArray(n.filter(i.toArray()))}})();const O=(()=>{const n={};window.addEventListener("jThree_ready",()=>{for(const e of["左","右"]){n["_"+e+"_"]={};n[e]={f:new System._browser.data_filter([{type:"one_euro",id:"magnet_offset_rot",para:[30,1,1,1,4]}])}}});return function(e,t){const i=n[t?e:"_"+e+"_"];if(i.timestamp!=RAF_timestamp){const o=U.get_bone_rotation_by_MMD_name(e+"手首",true);i.rot=t?o.fromArray(i.f.filter(o.toArray())):o}i.timestamp=RAF_timestamp;return i.rot}})();function q(e,t,i,o){const n=i.x;const a=i.y;const s=i.z;const r=e.x;const _=e.y;const l=e.z;const c=t.x-r;const d=t.y-_;const p=t.z-l;let u=c*c+d*d+p*p;let m=2*(r*c+_*d+l*p-c*n-d*a-p*s);let h=r*r-2*r*n+n*n+_*_-2*_*a+a*a+l*l-2*l*s+s*s-o*o;let f=m*m-4*u*h;let M=(-m-Math.sqrt(f))/(2*u);const y=[e.x*(1-M)+M*t.x,e.y*(1-M)+M*t.y,e.z*(1-M)+M*t.z];let g=(-m+Math.sqrt(f))/(2*u);const b=[e.x*(1-g)+g*t.x,e.y*(1-g)+g*t.y,e.z*(1-g)+g*t.z];if(f<0||M>1||g>1){return[]}else if(f==0){return[y]}else{return[y,b]}}let X,U;return function(D,E,i,e){function t(e,t,i,o){if(typeof e=="number")return Ce.auto_scale_property(e,D,o);if(/^(\w+)([\+\-])([\d\.])$/.test(e)){const n=Ce.auto_scale_property((RegExp.$2=="+"?1:-1)*parseFloat(RegExp.$3),D,o);const a=MMD_SA.TEMP_v3.copy(E);const s=RegExp.$1;if(s=="default"){a.copy(tt._skin[D].pos).sub(D.indexOf("腕")!=-1?MMD_SA_options.model_para_obj.arm_IK_offset[k]:MMD_SA_options.model_para_obj.leg_IK_offset[k]).applyQuaternion(tt._skin[D].rot_parent_inv)}else if(s=="elbow"){if(t=="y"){const r=_?.motion_tracking?.arm_tracking?.elbow_lock?.[k=="左"?"left":"right"]?._elbow_y;if(r!=null&&r!=0){a.y=r-MMD_SA.get_bone_position(P,k+"腕",P).y}}}return(a[t]+n)/i}return 0}const k=D.charAt(0);const o=D.indexOf("足")==-1?MMD_SA_options.model_para_obj.left_arm_length:MMD_SA_options.model_para_obj.left_leg_length;const x=k=="左"?"left":"right";X=THREE.MMD.getModels()[0];U=MMD_SA.THREEX.get_model(0);const P=X.mesh;const _=MMD_SA.motion[X.skin._motion_index].para_SA;let n;if(i){for(const c of["x","y","z"]){const d=i[c];if(!d)continue;const s=d.unit_length||o;let e=!MMD_SA.THREEX.enabled&&d.unit_length?d.auto_scale:false;if(d.scale!=null)E[c]*=typeof d.scale?.[x]=="number"&&d.scale[x]||d.scale;if(d.add)E[c]+=t(d.add?.[x]||d.add,c,s,e)*s;if(d.min!=null)E[c]=Math.max(E[c],t(d.min?.[x]||d.min,c,s,e)*s);if(d.max!=null)E[c]=Math.min(E[c],t(d.max?.[x]||d.max,c,s,e)*s)}if(i.rotation)E.applyEuler(MMD_SA.TEMP_v3.copy(i.rotation).multiplyScalar(Math.PI/180));if(i.camera_weight&&D.indexOf("腕")==-1)E.applyQuaternion(MMD_SA.TEMP_q.set(0,0,0,1).slerp(tt._rot_camera,i.camera_weight));const l=i.position_to_rotation;if(l){const p=P.bones_by_name;const u=Ie.set(Math.atan2(E.z,E.y),0,-Math.atan2(E.x,E.z));const m={upper:{q:Xe},lower:{q:Ue}};for(const v of["upper","lower"]){const w=k+(v=="upper"?"足":"ひざ");const S=p[w];m[v].name=w;m[v].q.copy(S.quaternion);S.quaternion.set(0,0,0,1);if(!l[v])continue;const A=ze.set(0,0,0);for(const c of["x","y","z"]){const d=l[v][c];if(!d)continue;let e=0;const T=d.rot_formula?.[x]||d.rot_formula;if(T?.length==1){e=u[T]*180/Math.PI}if(d.add)e+=d.add?.[x]||d.add;if(d.scale!=null)e*=typeof d.scale?.[x]=="number"&&d.scale[x]||d.scale;if(d.curve){const I=d.curve?.[x]||d.curve;const z=(e-I.ini)/(I.end-I.ini);if(z>0&&z<1)e=Math.pow(z,I.pow_factor)*(I.end-I.ini)+I.ini}if(d.min!=null)e=Math.max(e,d.min?.[x]||d.min);if(d.max!=null)e=Math.min(e,d.max?.[x]||d.max);A[c]=e/180*Math.PI}S.quaternion.setFromEuler(A,"XZY");if(v=="upper")n=S.quaternion.clone()}const h=MMD_SA.get_bone_position(P,k+"足","全ての親");const f=MMD_SA.get_bone_position(P,k+"足首","全ての親");const M=je.x_flipped?-1:1;const y=Ie.fromArray(p[k+"足"].pmxBone.origin);const g=y.sub(h).negate();const b=h.sub(f);b.x*=M;b.y*=-1;b.z*=-1;b.add(MMD_SA_options.model_para_obj.leg_IK_offset[k]);b.add(g);b.y-=MMD_SA_options.model_para_obj.left_leg_IK[1]+(p["センター"].position.y-p["センター"].pmxBone.origin[1]);E.copy(b);for(const v in m)p[m[v].name].quaternion.copy(m[v].q)}}else{if(e)e(E)}const a=E.length();E.normalize().multiplyScalar(a*(typeof i?.length?.scale=="number"?i?.length?.scale:i?.length?.scale?.[x]||1));let R;i?.magnet?.forEach(i=>{if(i.is_parent){R={name:i.name}}else if(R&&!i.is_parent&&R.name==i.name&&!R.vector){return}const t=i.hand_affected[x];if(!t)return;if(!tt.skin[D]?.[0]._hand_visible)return;let o=MMD_SA._v3a.set(0,0,0);let n;let a=MMD_SA._q1.set(0,0,0,1);let s,r;if(i.type=="object3D"){s=MMD_SA.THREEX._XR_Animator_scene_?.object3D_list.find(e=>e.id==i.id);if(!s)return;r=MMD_SA.THREEX._object3d_list_.find(e=>e.uuid==s._object3d_uuid);o.copy(i.reference_point).multiply(r._mesh.scale);a=MMD_SA._q1.copy(P.quaternion).conjugate().multiply(i.use_default_rotation&&r.user_data._rot_default_||r._mesh.quaternion);o.applyQuaternion(a);n=MMD_SA._v3b.copy(r._mesh.position).sub(P.position).applyQuaternion(MMD_SA.TEMP_q.copy(P.quaternion).conjugate());o.add(n)}else if(i.type=="bone"){let t;i.name.split("|").some(e=>{t=MMD_SA.THREEX.VRM.bone_map_VRM_to_MMD[e]||!MMD_SA.THREEX.enabled&&e;return t});o=U.get_bone_position_by_MMD_name(t,true);if(i.offset){a=U.get_bone_rotation_by_MMD_name(t,true);o.add(MMD_SA._v3a.copy(i.offset).applyQuaternion(a))}}else{o.copy(i.position)}const _=U.get_bone_position_by_MMD_name(D.substring(0,2),true);o.sub(_);let l=1;if(MMD_SA.THREEX.enabled){l=MMD_SA_options.model_para_obj.left_arm_length/U.para.left_arm_length;o.multiplyScalar(l)}let e=MMD_SA._v3a_.set(0,0,0);if(t.offset){if(t.offset=="parent_bone"){pb=MMD_SA.THREEX._object3d_list_.find(e=>e.parent_bone?.name==k+"手首"&&!e.parent_bone.disabled)?.parent_bone;if(pb){e.fromArray(Ce.auto_scale_property([pb.position.x,pb.position.y,-pb.position.z],"手首",MMD_SA.THREEX.enabled?false:t.auto_scale))}else{pb=s?.model_para?.parent_bone?.rotation?.align_with_external_point?.external_point?.offset;if(pb){e.fromArray(Ce.auto_scale_property([pb.x,pb.y,pb.z],"手首",MMD_SA.THREEX.enabled?false:t.auto_scale));if(!U.is_T_pose)e.applyQuaternion(MMD_SA_options.model_para_obj.rot_arm_adjust[k+"腕"].axis_rot)}}}else{e.copy(t.offset);if(!U.is_T_pose)e.applyQuaternion(MMD_SA_options.model_para_obj.rot_arm_adjust[k+"腕"].axis_rot)}e.applyQuaternion(O(k,t.offset.use_filter))}E.add(e);const c=MMD_SA.THREEX.enabled||i.auto_scale===false?false:.9;let d=0;let p;if(i.magnet_type=="line"){const u=MMD_SA.THREEX.l1;u.start.copy(o);if(i.type=="object3D"){if(i.line_end){u.end.copy(i.line_end).multiply(r._mesh.scale).applyQuaternion(a);u.end.add(n)}else{u.end.copy(n||MMD_SA.TEMP_v3.set(0,0,0))}u.end.sub(_).multiplyScalar(l)}else if(i.type=="bone"){u.end.copy(i.line_end).applyQuaternion(a).multiplyScalar(l).add(o)}if(i.line_offset){const m=MMD_SA.TEMP_v3.copy(i.line_offset).multiply(r._mesh.scale).applyQuaternion(a).multiplyScalar(l);u.start.add(m);u.end.add(m)}u.closestPointToPoint(E,true,o);let e=E.distanceTo(o);let t=Ce.auto_scale_property(i.effective_distance,"腕",c);if(e-9?Math.pow(d,1-i.power):0}}}else if(i.magnet_type=="plane"){const h=MMD_SA.TEMP_v3.copy(i.plane_normal);if(!i.plane_normal.absolute)h.applyQuaternion(a);const f=MMD_SA.THREEX.p1.setFromNormalAndCoplanarPoint(h,o);const u=MMD_SA.THREEX.l1;u.start.copy(E);u.end.copy(MMD_SA.TEMP_v3.copy(f.normal).multiplyScalar(999).add(E));let t=f.intersectsLine(u);if(t&&!i.plane_crossable){d=1}else{if(!t)u.end.sub(E).negate().add(E);const y=f.distanceToPoint(E);let e=Ce.auto_scale_property(i.effective_distance,"腕",c);if(y-9?Math.pow(d,1-i.power):0}}const M=MMD_SA.THREEX.v1;f.intersectLine(u,M);o.copy(M)}else{const y=E.distanceTo(o);let e=Ce.auto_scale_property(i.radius,"腕",c);if(y-9?Math.pow(d,1-i.power):0}}}if(d){if(p){const g=R&&!i.is_parent&&R.name==i.name?ze.copy(R.vector):ze.copy(E).sub(o).normalize();if(i.z_push){if(d==1){const b=C(i,k)&&(i.z_push.rotation_base?i.z_push.rotation_base===true?a:U.get_bone_rotation_by_MMD_name(i.z_push.rotation_base,true):null);if(i.z_push.validate?i.z_push.validate(E,g,b):(b?g.dot(MMD_SA.TEMP_v3.set(0,0,1).applyQuaternion(b)):g.z)>-0){_dir=Ie.set(0,0,999);if(b)_dir.applyQuaternion(b);linePoint0=MMD_SA._v3b_.copy(E).add(_dir);linePoint1=_dir.negate().add(E);const v=o;const w=p;let e=q(linePoint0,linePoint1,v,w).sort((e,t)=>t[2]-e[2]);o.fromArray(e[0]);const S=tt.skin[k+"手首"]?.[0].rot;if(S){const A=MMD_SA.TEMP_v3.set(1,0,0);if(b)A.applyQuaternion(b);A.applyQuaternion(S);_dir.set(0,0,1);if(b)_dir.applyQuaternion(b);o.add(_dir.multiplyScalar(t.offset.z*Math.abs(A.z)))}i.on_hit&&i.on_hit(i,k)}else{d=0}B(i,k,!!d)}else{d=0;B(i,k,null)}}else{let e;if(i.is_parent||i.use_vector_filter){e=L(i,k,g);g.copy(e)}o.add(g.multiplyScalar(p));if(i.is_parent){R.vector=e;d=0}if(d){i.on_hit&&i.on_hit(i,k)}}}E.add(H(i,k,MMD_SA.TEMP_v3.set(0,0,0).lerp(o.sub(E),d)))}else{H(i,k,MMD_SA.TEMP_v3.set(0,0,0));B(i,k,null)}i._frame_count_=EV_sync_update.count_frame;i._weight_=d;E.sub(e)});let s=E.length();for(const j of["max","min"]){const F="length_"+j;let e,t=o;if(i?.[F]||i?.length){if(typeof i[F]=="number"){e=i[F]}else{e=i.length[j];if(e==null)continue;if(typeof e!="number"){e=e[x];if(e==null)continue}if(i.length.unit_length)t=i.length.unit_length}}else{continue}if(j=="max"){if(s>t*e)s=t*e}else{if(s{const q={};const X={};window.addEventListener("jThree_ready",()=>{for(const e of["左","右"]){q[e]=new System._browser.data_filter([{type:"one_euro",id:"armIK",para:[30,1,1/5,1,3]}]);X[e]=new System._browser.data_filter([{type:"one_euro",id:"pos0_offset",para:[30,1,1,1,3]}])}});return function(i,e){if(Ce.IK_disabled_check(e))return;let t=i.bones_by_name[e];let o=this.skin[e];let n=Math.max(Math.min(o[0].t_delta/o[0].t_delta_frame,1),0);let a=qe.copy(o[1].pos).lerp(o[0].pos,n);const s=e.charAt(0);const r=MMD_SA.MMD.motionManager.para_SA;const L=s=="左"?"left":"right";let _=r?.motion_tracking?.arm_tracking?.transformation;let l=_?.position?.magnet;const c=MMD_SA_options.model_para_obj.colliders_for_hands;const d=c.left_hand.children[0].offset;const p=.5;const C={left:{offset:{x:d[0]*p,y:d[1]*p,z:d[2]*p}},right:{offset:{x:-d[0]*p,y:d[1]*p,z:d[2]*p}}};let u;if(Ce.body_collider.active){u=[];u=u.concat(c.head?.generate_colliders()||[]);u=u.concat(c.chest?.generate_colliders()||[]);u=u.concat(c.waist?.generate_colliders()||[]);u=u.concat(c.hip?.generate_colliders()||[])}if(!_&&u)_={position:{}};if(_&&u){if(!_.position)_.position={};_.position.magnet=u.concat(l||[])}const m=MMD_SA.get_bone_rotation_parent(i,e,i);let h=!o[0]._IK_absolute?this.offset_upper_body_camera_rotation(Xe.copy(m).conjugate(),r?.motion_tracking?.arm_tracking?.transformation?.position?.camera_weight||1):null;let f=st.set(0,0,0,1);if(_){const v=_.position;Q(s+"腕IK",a,v);let t=_.root_rotation?.[L];if(t){const w=s+"腕";f.setFromEuler(MMD_SA.TEMP_v3.set(t.x,t.y,t.z).multiplyScalar(Math.PI/180),t.order);let e=Ye[w];f.premultiply(e.axis_rot).multiply(e.axis_rot_inv);i.bones_by_name[w].quaternion.multiply(f)}if(_.position)_.position.magnet=l}if(o[0].data_filter||o[1].data_filter){a.fromArray(q[s].filter(a.toArray()))}if(h)a.applyQuaternion(h);const M=Ce._arm_IK_adjust?.[s];if(M){const S=MMD_SA_options.model_para_obj.left_arm_length;const A=["x","y","z"];if(M.add){if(typeof M.min=="number"){}else{for(const b of A){if(M.add[b]!=null){a[b]+=M.add[b]*S}}}}if(M.min){if(typeof M.min=="number"){}else{for(const b of A){if(M.min[b]!=null){if(a[b]b.target_radius){const O=j.sub(b.target).add(F.normalize().multiplyScalar(b.target_radius));a.sub(O.applyQuaternion(m.conjugate()))}}a.add(MMD_SA_options.model_para_obj.arm_IK_offset[s]);t.position.copy(a)}})();var De=function(){let D={};let E={};window.addEventListener("jThree_ready",()=>{for(const t of["左","右"]){D[t]=new System._browser.data_filter([{type:"one_euro",para:[30,.3,.3,.3,3]}]);E[t]=[];for(let e=0;e<5;e++){E[t][e]=new System._browser.data_filter([{type:"one_euro",para:[30,1,1,1,1]}])}}});return function(n,e){var t=THREE.MMD.getModels()[n._model_index];var i=n.bones_by_name[e];var a=e.charAt(0);var o=i.quaternion;const s=this.skin[e];const r=Math.max(Math.min(s[0].t_delta/s[0].t_delta_frame,1),0);o.copy(s[1].rot).slerp(s[0].rot,r);const _="YXZ";const l=MMD_SA.TEMP_v3.setEulerFromQuaternion(o,_);const c=MMD_SA.MMD.motionManager.para_SA.motion_tracking.arm_as_leg.transformation?.rotation||{};let d=Math.sign(l.y)*Math.min(Math.abs(l.y*(c.y?.scale||1)),Math.PI/2.5)+(c.y?.add||0)*Math.PI/180;const p=c.y?.foot_ratio||.25;l.y=d*p;l.z=Math.sign(l.z)*Math.min(Math.abs(l.z*(c.z?.scale||.5)),Math.PI/4);l.x*=c.x?.scale||.4;let u=[];let m=0;let h;if(s[0]._finger_x){if(s[1]._finger_x){h=s[0]._finger_x.map((e,t)=>e*r+s[1]._finger_x[t]*(1-r))}else{h=s[0]._finger_x}}if(h){for(let e=0;e<5;e++)u[e]=E[a][e].filter(h[e]);u[0]=(u[0]+u[1])/2;u.forEach(e=>{m+=e});m/=5;l.x-=m}l.x=Math.sign(l.x)*Math.min(Math.abs(l.x),Math.PI/2.5);l.fromArray(D[a].filter(l.toArray()));d=l.y/p;o.setFromEuler(l,_);this._rot_=o.clone();this._rot_y=d;const f=this.get_blend_default_motion("skin",a+"足IK",true);if(f)d*=1-f;const M=MMD_SA.get_bone_position(n,a+"足",n);const y=MMD_SA.get_bone_rotation_parent(n,a+"足",n).conjugate();const g=MMD_SA.get_bone_position(n,e,n).sub(M).negate().normalize().applyQuaternion(y);const b=MMD_SA.TEMP_q.setFromAxisAngle(g,d*(1-p));if(0&&n.bones_by_name[a+"足D"]){n.bones_by_name[a+"足"].quaternion.premultiply(b);n.bones_by_name[a+"足D"].quaternion.premultiply(b)}else{t._update_IK_and_AddTrans(false,a+"足","下半身",true);if(this.skin[a+"足"]&&this.skin[a+"足"][0]._rot_){n.bones_by_name[a+"足"].quaternion.copy(this.skin[a+"足"][0]._rot_)}else{const v=MMD_SA.get_bone_position(n,a+"ひざ",n).sub(M).negate().normalize().applyQuaternion(y);const w=Xe.setFromUnitVectors(qe.set(0,1,0),g);n.bones_by_name[a+"足"].quaternion.copy(w).multiply(Ue.setFromEuler(qe.set(-v.angleTo(g),0,0)))}n.bones_by_name[a+"足"].quaternion.premultiply(b);t._update_IK_and_AddTrans(false,a+"足","下半身")}if(m&&n.bones_by_name[a+"足先EX"]){const e=a+"足人指";const S=!MMD_SA.MMD.motionManager.para_SA.motion_tracking.arm_as_leg.toes_disabled&&(n.bones_by_name[e]||n.bones_by_name[e+Ve[1]]);if(!S){let t=0;for(let e=1;e<4;e++){t+=u[e]}t/=4;const A=(u[1]-t)/2;n.bones_by_name[a+"足先EX"].quaternion.setFromEuler(qe.set(-m*.5,0,A),"XZY")}else{n.bones_by_name[a+"足先EX"].quaternion.setFromEuler(qe.set(-m*.5,0,0))}t._update_IK_and_AddTrans(false,a+"足先EX")}if(h){Qe.forEach((e,t)=>{const i=a+"足"+e+"指";const o=n.bones_by_name[i]||n.bones_by_name[i+Ve[1]];if(o)o.quaternion.multiply(Xe.setFromEuler(qe.set(-u[t]*.5,0,0)))})}}}();var N=function(){let E={};window.addEventListener("jThree_ready",()=>{for(const e of["左","右"]){E[e]=new System._browser.data_filter([{type:"one_euro",id:"hand_rot_filter",para:[30,1,1,1,4]}])}});const k={"左":{},"右":{}};return function(e,t){var i=THREE.MMD.getModels()[e._model_index];const o=MMD_SA.THREEX.get_model(e._model_index);var n=o.is_T_pose;const a=e.bones_by_name[t];const s=t.charAt(0);const r=s=="左"?"left":"right";var _,l,c,d;var p=e.bones_by_name[s+"手捩"];var u;var m=this.skin[t];var h=Math.max(Math.min(m[0].t_delta/m[0].t_delta_frame,1),0);const f=MMD_SA.motion[i.skin._motion_index].para_SA;l=Xe.set(0,0,0,1);if(p){if(p.quaternion.x||p.quaternion.y||p.quaternion.z){p.quaternion.conjugate();i._update_IK_and_AddTrans(false,s+"手捩")}p.quaternion.set(0,0,0,1)}const M=s=="左"?1:-1;var y=m[0].rot_parent;if(!y){y=MMD_SA.get_bone_rotation(e,"上半身2",null,e);y.premultiply(Ue.copy(this._rot_body_offset).multiply(this._rot_camera).conjugate());y.multiply(MMD_SA.get_bone_rotation_parent(e,s+"手首","上半身2")).conjugate()}m[0]._rot_parent=y;const g=m[0].no_blending?Ke.copy(m[0].rot):Ke.copy(m[1].rot).slerp(m[0].rot,h);if(m[0]._rot_pose&&m[0]._rot_pose_ratio){let t=m[0]._rot_pose_ratio;if(m[0]._rot_pose_ratio_by_angle_difference){let e=MMD_SA.TEMP_q.copy(g).conjugate().multiply(m[0]._rot_pose).toAxisAngle()[1]%(Math.PI*2);if(e>Math.PI){e-=Math.PI*2}else if(e<-Math.PI){e+=Math.PI*2}const v=Math.pow(1-Math.abs(e)/Math.PI,1-m[0]._rot_pose_ratio_by_angle_difference);t*=v}if(m[0]._rot_pose_constrained){const w=qe.setEulerFromQuaternion(g,"YXZ");const S=Te.setEulerFromQuaternion(m[0]._rot_pose,"YXZ");let e=Math.abs(w.y-S.y);if(e>Math.PI)e=Math.PI*2-e;if(e>Math.PI*2/3&&Math.abs(w.x)S.y?Math.PI*2:0)-w.y:-(w.y+(w.yRAF_timestamp-250&&Math.abs(t-D.angle)>Math.PI){let e=t+Math.PI*2*(t>0?-1:1);if(Math.abs(e)Math.PI/4){const l=r{ae=new System._browser.data_filter([{type:"one_euro",id:"torso_rot",para:[30,.5,1,1,3]}]);Ee=new System._browser.data_filter([{type:"one_euro",id:"chest_rot",para:[30,.5,1,1,3]}]);ke=new System._browser.data_filter([{type:"one_euro",id:"shoulder_rot_z_filter",para:[30,1,1,1,1]}]);_e=new System._browser.data_filter([{type:"one_euro",id:"hand_depth_weight",para:[30,.5,.1,1,1]}]);for(const e of["左","右"]){xe[e]=new System._browser.data_filter([{type:"one_euro",id:"arm_IK"+e,para:[30,.5,1/2,1,3]}]);se[e]=new System._browser.data_filter([{type:"one_euro",id:"_arm_IK"+e,para:[30,.5,1/2,1,3]}]);Pe[e]=new System._browser.data_filter([{type:"one_euro",id:"arm_rot"+e,para:[30,.5,1/2,1,4]}]);re[e]=new System._browser.data_filter([{type:"one_euro",id:"hand_depth"+e,para:[30,.5,.1,1,1]}]);Re[e]=new System._browser.data_filter([{type:"one_euro",id:"rot_pose_ratio"+e,para:[30,.5,.1,1,1]}])}});return function(e){var he=typeof e.data=="string"&&e.data.charAt(0)==="{"?JSON.parse(e.data):e.data;if(typeof he==="string"){if(he=="OK"){Ce.worker_initialized=true}else{DEBUG_show(he,2);System._browser.console.log(he)}}else if(Ce.enabled){window.dispatchEvent(new CustomEvent("SA_camera_poseNet_update"));je._needs_RAF=true;Ce._bb=null;const fe=MMD_SA.THREEX.get_model(0).model_para;const o=wt[Ce.use_holistic?1:0];let e;if(Ce.enabled&&!o.poseNet){e=true;o.poseNet=true}if(Be.enabled&&!o.handpose){e=true;o.handpose=true}if(e)DEBUG_show("Pose ML ready",2);He=(Fe.enabled?"\n":"")+je.video_canvas.width+"x"+je.video_canvas.height+"("+Ce.camera_video_frame_id+")\n";let t=je.video_timestamp;let i=0;if(ee){i=Math.max(Math.min(t-ee,1e3),10);J+=i;if(++$>=20){Z=1e3/(J/$);$=J=0}}ee=t;Ce._t=he._t;tt.t_delta=((tt.t_delta||i)+i)/2;if(he.handpose){i=0;if(ne){i=Math.max(Math.min(t-ne,1e3),10);oe+=i;if(++ie>=20){te=1e3/(oe/ie);ie=oe=0}}ne=t;Ce._t_hands=he._t_hands;tt.t_delta_hands=((tt.t_delta_hands||i)+i)/2}if(Ce.use_holistic){o.facemesh=true;if(!he.facemesh){Fe.data_detected=0}}let le=[];let ce=[];let de=je.x_flipped?1:-1;let pe;const s=THREE.MMD.getModels()[0];const n=s.mesh.bones_by_name;const ve=MMD_SA.THREEX.get_model(0).is_T_pose;const L=MMD_SA.THREEX.get_model(0);const Me=MMD_SA.MMD.motionManager.para_SA;const M=Me.motion_tracking&&Me.motion_tracking.arm_as_leg;const ye={"左":M&&M.enabled&&(!M.linked_side||M.linked_side=="left"),"右":M&&M.enabled&&(!M.linked_side||M.linked_side=="right")};let D;let ue,a;let me;if(Ce.enabled){if(he.posenet&&he.posenet.score>.3){Ce.data_detected++;Ce.initial_data_detected=true;if(Ce.data_detected_stable){if(Ne){Ne=false;s.mesh.visible=true}D=Me.motion_tracking?.camera?.tilt_adjustment||je.tilt_adjustment;if(D.enabled){a=D.angle*D.pose_weight*Math.PI/180;ue=(new THREE.Quaternion).set(Math.sin(a/2),0,0,Math.cos(a/2))}me=he.posenet;let re=Ce.use_3D_pose;if(pt){me._keypoints=me.keypoints;me._keypoints3D=me.keypoints3D;let o=[];let n=[];ft.forEach((e,t)=>{let i=me.keypoints[e];i.part=ht[t];o.push(i);i=me.keypoints3D[e];i.part=ht[t];n.push(i)});me.keypoints=o;me.keypoints3D=n}const c=dt?.3:!mt?.5:.1;me.keypoints.forEach(e=>{e.score-=c});if(re){me._keypoints3D.forEach(e=>{e.score-=c})}if(mt){let i={};me.keypoints.forEach(e=>{i[e.part]=e});let o=[];for(let t=0;t<=16;t++){let e=me.keypoints[t];if(!e)o.push(Mt[t]);else if(e.part!=ht[t])o.push(i[ht[t]]||Mt[t]);else o.push(e)}me.keypoints=o}let e=me._keypoints||me.keypoints;let t=e.map(e=>e.position.x);let i=e.map(e=>e.position.y);const p=[Math.min(...i),Math.max(...t),Math.max(...i),Math.min(...t)];e=me.keypoints.slice(0,5);t=e.map(e=>e.position.x);i=e.map(e=>e.position.y);const u=[Math.min(...i),Math.max(...t),Math.max(...i),Math.min(...t)];const g=Math.max(u[1]-u[3],u[2]-u[0])/2;p[0]=Math.min(p[0],u[0]-g);p[1]=Math.max(p[1],u[1]+g);p[2]=Math.max(p[2],u[2]-g);p[3]=Math.min(p[3],u[3]-g);Ce._bb=p;if(!Fe.head_pose_enabled){Fe.bb_center[0]=me.keypoints[0].position.x/je.video_canvas.width;Fe.bb_center[1]=me.keypoints[0].position.y/je.video_canvas.height}if(re&&Ce.use_head_mocap){let e=me._keypoints[0].position;let t=me._keypoints[3].position;let i=me._keypoints[6].position;const v=qe.copy(i);const k=Te.copy(t);k.sub(v);const x=MMD_SA._v3a_.copy(e);const P=(x.x*k.x+x.y*k.y+x.z*k.z-(v.x*k.x+v.y*k.y+v.z*k.z))/k.lengthSq();const C=MMD_SA._v3b.set(v.x+k.x*P,v.y+k.y*P,v.z+k.z*P);let o=x.sub(C).normalize();let n=MMD_SA._v3b_.copy(t).sub(MMD_SA._v3b.copy(i));n.normalize();let a=MMD_SA.TEMP_v3.crossVectors(n,o).normalize();n.crossVectors(o,a);Ge.set(n.x,n.y,n.z,0,o.x,o.y,o.z,0,a.x,a.y,a.z,0,0,0,0,1);We.setFromBasis(Ge);let s=We.conjugate();s=s.clone().multiply(MMD_SA.TEMP_q.set(Math.sin(Math.PI/3.5/2),0,0,Math.cos(Math.PI/3.5/2)));Fe._neck.shoulder_center=Te.copy(me._keypoints[11].position).add(MMD_SA.TEMP_v3.copy(me._keypoints[12].position)).multiplyScalar(.5).toArray();if(ue)s.premultiply(ue);if(!Fe.head_pose_enabled){tt.add("skin","首",{after_IK:true,rot:s,onProcessRotation:yt});tt.skin["首"][1]._rot_mixed&&tt.skin["首"][1].rot.copy(tt.skin["首"][1]._rot_mixed)}tt.add("skin","首_DUMMY_",{rot:s,_rot_from_pose:s.clone(),onProcessRotation:yt})}let o=me.keypoints[5];let n=me.keypoints[6];let w=new THREE.Quaternion;pe=Me.motion_tracking_upper_body_only;He+="\n"+(pe?(Me.motion_tracking?.arm_as_leg?.enabled?"🦶":"🙋")+"upper body":"💃full body"+(Ce.auto_grounding?"👣":""));const b=MMD_SA_options.Dungeon_options?.item_base.hand_camera;if(b&&b._hand_camera_side){He+="/"+(b.selfie_mode?"🤳selfie":"📷handcam")+(b._hand_camera_side=="左"?"-L":"-R")}else if(pe&&Ce.hip_camera){He+="/"+"📷hip cam"}He+="\n";if(re&>)$e.prepare(me);let M=0,S=0;if(Be.enabled&&he.handpose)Be.hand_visible_timestamp={};et[0]=et[1]=0;let _e;if(o.score>0&&n.score>0&&[o,n].some(e=>e.position.x>=0&&e.position.x<=je.video_canvas.width&&e.position.y>=0&&e.position.y<=je.video_canvas.height)){let u,m;let h,f;if(re){u=me.keypoints3D[5];m=me.keypoints3D[6];let e=me.keypoints3D[11];let i=me.keypoints3D[12];Ce._hip_visible=e.score>0&&i.score>0&&me.keypoints[11].position.yMath.PI)p=Math.PI*2-p;else if(p<0&&p<-Math.PI)p+=Math.PI*2;h.multiply(Xe.set(0,Math.sin((p/2-c)/2),0,Math.cos((p/2-c)/2)));f.multiply(Xe.set(0,Math.sin((p/2-d)/2),0,Math.cos((p/2-d)/2)));tt.add("skin","センター",{rot:w.clone(),priority:9});if(it.active){if(!tt.skin["センター"][0].pos&&tt.skin["センター"][1].pos)tt.skin["センター"][0].pos=tt.skin["センター"][1].pos}const H=h.clone();if(ue){const O=Xe.copy(ue);const q=Me.motion_tracking?.ML_models?.pose||MMD_SA_options.user_camera.ML_models.pose;if(q.upper_rotation_offset){const X=-(q.upper_rotation_offset-p)*2/3*Math.PI/180;const U=ue.toAxisAngle();O.setFromAxisAngle(U[0].applyQuaternion(MMD_SA.TEMP_q.set(0,Math.sin(X/2),0,Math.cos(X/2))),U[1])}Xe.premultiply(MMD_SA.TEMP_q.copy(w).conjugate()).multiply(w);H.premultiply(O)}tt.add("skin","上半身",{rot:H});tt.add("skin","上半身2",{rot:f.clone()});_e=Xe.copy(w).multiply(h).multiply(f);_e.conjugate()}const R=MMD_SA.TEMP_v3.set(1,1,1/3);Ce.shoulder_width=qe.copy(o.position).multiply(R).distanceTo(Te.copy(n.position).multiply(R));let se=Math.sqrt(Math.pow(o.position.x-n.position.x,2)+Math.pow(o.position.y-n.position.y,2));let e=0;if(!re){e=Math.asin((o.position.y-n.position.y)/se);e=Math.max(Math.min(e/(Math.PI/4),1),-1)*Math.PI/4*de}let t=de==1?[1,0]:[0,1];se=Fe.face_width*2||se;Ce._upper_body_only_mode=pe;const ge=[0,0];const be=[];t.forEach(function(i,l){let n,a,s;let r;let c=l==0?"左":"右";let _=me.keypoints[5+i];let d=me.keypoints[7+i];let p=me.keypoints[9+i];let u=(Me.motion_tracking?.arm_tracking?.use_IK!=null?!Me.motion_tracking.arm_tracking.use_IK:MMD_SA_options.user_camera.ML_models.pose.use_armIK==null?!pe&&!Ce.body_collider.active&&MMD_SA_options.Dungeon_options?.item_base.hand_camera?._hand_camera_side!=c:!MMD_SA_options.user_camera.ML_models.pose.use_armIK)&&!ye[c];let m=false;be[l]=new THREE.Quaternion;if(ve)be[l].fromArray(MMD_SA.THREEX.utils.convert_A_pose_rotation_to_T_pose(c+"肩",be[l].toArray()));let h,f,M;if(re){h=me.keypoints3D[5+i];f=me.keypoints3D[7+i];M=me.keypoints3D[9+i];let e=(fe.camera?.poseNet?.arm_vertical_offset_percent||0)/100+(Ce.arm_vertical_offset_percent||0)/100;if(e){const x=MMD_SA.TEMP_v3.copy(f).distanceTo(h)+MMD_SA.TEMP_v3.distanceTo(M);const X=MMD_SA.TEMP_v3.copy(M).sub(h);const U=-(1-Math.abs(X.y)/x)*(x*e);M={x:M.x,y:M.y+U,z:M.z};f={x:f.x,y:f.y+U/2,z:f.z}}let t=(fe.camera?.poseNet?.arm_horizontal_offset_percent||0)/100+(Ce.arm_horizontal_offset_percent||0)/100;if(t){const P=t>0?1/(1+t):1-t;const K=Te.copy(me.keypoints3D[5]).add(me.keypoints3D[6]).multiplyScalar(.5);const R=Ie.copy(h).sub(K);const T=ze.copy(R).multiplyScalar(P).add(K);R.copy(T).sub(h).multiplyScalar(.5);h={x:T.x,y:T.y,z:T.z};T.copy(f).add(R);f={x:T.x,y:T.y,z:T.z}}}let y=p.score>0&&p.position.x>=0&&p.position.x<=je.video_canvas.width&&p.position.y>=0&&p.position.y<=je.video_canvas.height;if(y&&ye[c]&&Ce._hip_visible&&re){let e=MMD_SA.TEMP_v3.copy(h).distanceTo(f);e+=MMD_SA.TEMP_v3.copy(f).distanceTo(M);let t=MMD_SA.TEMP_v3.copy(M).sub(h).y;if(e-t0&&Be.enabled&&Be.stabilize_hand_percent&&Ce.shoulder_width){const I=je.video_canvas.width;const G=je.video_canvas.height;const z=Be._hand_last[c];let o;if(he.handpose&&he.handpose.length){const Q=he.handpose.find(e=>e.label==(c=="左"?"Left":"Right"));if(Q){o=z.hand=Q.annotations.palm[0];z.timestamp=RAF_timestamp;z.w=I;z.h=G}}if(!o){o=z.hand}const W=1e3*(Be.stabilize_hand_percent/100)*(pe||!u?1:.5);let n=RAF_timestamp-z.timestamp;if(o&&z.w==I&&z.h==G&&n(Me.motion_tracking_upper_body_only?0:1);const B="YZX";let w;let t=Me.motion_tracking?.arm_tracking?.data_filter?.[c=="左"?"left":"right"];if(t)t=Object.assign({},t);let S;let A=Me.motion_tracking?.arm_tracking?.off_screen_allowed?.[c=="左"?"left":"right"];if(p.score>0){let e;if(pe&&Be.enabled&&Be.use_hands_worker&&!he.handpose){if(Be.hand_visible_timestamp[c]+200>RAF_timestamp)y=e=true}let o,t;if(Be.enabled&&he.handpose){o=he.handpose.find(e=>e.label==(c=="左"?"Left":"Right"));if(o){y=true}}if(o){Be.hand_visible_timestamp[c]=RAF_timestamp;if(!pe)Be.hand_visible_session[c]=RAF_timestamp}if(Be.enabled&&pe){let t;let i=Be.hand_visible_session[c]||0;if(o||e){if(i<1e3){Be.hand_visible_session[c]=1e3;if(!Be.stabilize_arm_time){w=true}else{t=true}}else if(i<1200){Be.hand_visible_session[c]+=Ce._t_hands;if(Be.hand_visible_session[c]>1e3+Be.stabilize_arm_time){w=true}else{t=true}}else{Be.hand_visible_session[c]=RAF_timestamp}}else{Be.hand_visible_timestamp[c]=0;let e=!y;if(y&&i<1e3+Be.stabilize_arm_time){if(i>=1e3)i=Be.hand_visible_session[c]=201;e=true;t=true}if(e){w=y;if(!i){Be.hand_visible_session[c]=0;t=true}else if(i>200){Be.hand_visible_session[c]=200}else{Be.hand_visible_session[c]-=Ce._t_hands;if(Be.hand_visible_session[c]<0)Be.hand_visible_session[c]=0}}}if(C){if(t){let e=A||!Me.motion_tracking_upper_body_only;let t=e&&A;let i,n;i=!e;let a;if(!e||y){p.score=0;if(!e&&tt.skin[c+"ひじ"]?.[0].rot.w!=1){a=a||new THREE.Quaternion;tt.add("skin",c+"ひじ",{absolute:true,no_blending:i,blending_ratio:n,rot:a})}}if(e&&!p.score){S=true}if(!t&&tt.skin[c+"手首"]?.[0].rot.w!=1){a=a||new THREE.Quaternion;tt.add("skin",c+"手首",{after_IK:true,absolute:true,no_blending:i,blending_ratio:n,rot:a});tt.add("skin",c+"手捩",{after_IK:true,absolute:true,no_blending:i,blending_ratio:n,rot:a})}if(!t&&(e&&Be.enabled)){Qe.forEach((t,e)=>{let i=e==0?0:1;for(let e=i;ee.magnet_id==t.weight_by_magnet.id);o=Y&&Y._frame_count_>=EV_sync_update.count_frame-1-(Be.use_hands_worker?6:0)?Y._weight_:0}}const D=pe?.5:2;e.minCutOff=D*(1-o)+(t?.minCutOff||D)*o;e.beta=D*(1-o)+(t?.beta||D)*o;e.dCutOff=1*(1-o)+(t?.dCutOff||1)*o;const H=Pe[c].filters[0].filter;H.beta=e.beta;H.minCutOff=e.minCutOff;H.dCutOff=e.dCutOff;const E=c+(ye[c]?"足IK":"腕IK");let O=true;if(re&&d.score>0){if(!A&&C&&!y&&pe&&!Me.motion_tracking_upper_body_only){const Z=MMD_SA._v3b.copy(h).sub(f);if(p.score>0){const $=Z.length();const j=MMD_SA.TEMP_v3.copy(M).sub(f);f.z=h.z;const J=MMD_SA._v3b.copy(h).sub(f).length()/$;j.multiplyScalar(J).add(f);M.x=j.x;M.y=j.y;M.z=j.z}f.z=h.z}g=MMD_SA._v3b.copy(h).sub(f).normalize().applyQuaternion(_e);b=MMD_SA.TEMP_v3.set(L,0,0);v=(new THREE.Quaternion).setFromUnitVectors(b,g);ge[l]=Te.setFromVectorSpherical(b,g).z}let k;if(p.score>0){if(re){let e=d.score>0?MMD_SA.TEMP_v3.copy(h).distanceTo(f)+MMD_SA.TEMP_v3.copy(f).distanceTo(M):.5;let o=Math.min(MMD_SA.TEMP_v3.copy(h).sub(M).length()/e,1);if(d.score>0){let e=MMD_SA_options.model_para_obj.colliders_for_hands?.chest?.scale;if(e>1&&Ce.body_collider.mode>(pe?0:1)){let r=MMD_SA._v3a.copy(h).sub(M).applyQuaternion(_e);r.normalize().multiplyScalar(o*MMD_SA_options.model_para_obj.left_arm_length);const ee=c=="左"?-1:1;let _=THREE.Math.clamp(r.x/MMD_SA_options.model_para_obj.shoulder_width*ee,0,1)*THREE.Math.clamp(1-r.y/(MMD_SA_options.model_para_obj.shoulder_width*.75),0,1)*THREE.Math.clamp(1-(r.z-MMD_SA_options.model_para_obj.left_arm_length*.5)/(MMD_SA_options.model_para_obj.left_arm_length*.5),0,1);_=Math.sin(_*Math.PI/2)*Math.sin(Math.min((e-1)*.5,1)*Math.PI/2)*2;if(_){r=MMD_SA._v3a.copy(h).sub(M).normalize();let e=MMD_SA.TEMP_q.setFromAxisAngle(r,-Math.PI/4*_*ee);const t=h;const i=ze.copy(M).sub(t);const o=f;const n=(o.x*i.x+o.y*i.y+o.z*i.z-(t.x*i.x+t.y*i.y+t.z*i.z))/i.lengthSq();const a=MMD_SA._v3b.set(t.x+i.x*n,t.y+i.y*n,t.z+i.z*n);let s=MMD_SA.TEMP_v3.copy(f).sub(a);s.applyQuaternion(e).add(a);f.x=s.x;f.y=s.y;f.z=s.z;g=MMD_SA._v3b.copy(h).sub(f).normalize().applyQuaternion(_e);b=MMD_SA.TEMP_v3.set(L,0,0);v=(new THREE.Quaternion).setFromUnitVectors(b,g);ge[l]=Te.setFromVectorSpherical(b,g).z}}let t=qe.copy(f).sub(M);t.normalize().applyQuaternion(_e).applyQuaternion(MMD_SA.TEMP_q.copy(v).conjugate());b=MMD_SA.TEMP_v3.set(L,0,0);if(!S){k=(new THREE.Quaternion).setFromUnitVectors(b,t)}}if(d.score>0){const g=MMD_SA.TEMP_v3.copy(h).sub(f).applyQuaternion(_e);O=g.y<0}if(!u||d.score<=0){u=false;let i=MMD_SA._v3a.copy(h).sub(M);if(ue)i.applyQuaternion(ue);i.normalize().multiplyScalar(o*MMD_SA_options.model_para_obj.left_arm_length);if(Me.motion_tracking_upper_body_only&&!ye[c]&&tt._skin["左腕"]?.pos_local&&tt._skin["右腕"]?.pos_local){const te=MMD_SA.TEMP_v3.copy(tt._skin["左腕"].pos_local).sub(tt._skin["右腕"].pos_local);let e=Math.min(te.z*(c=="左"?1:-1),0)*.75;let t=Math.min(Math.abs(te.x)-MMD_SA_options.model_para_obj.shoulder_width,0)*(c=="左"?1:-1)*.5;i.x-=t;i.z-=e;const ie=Math.min(i.length(),MMD_SA_options.model_para_obj.left_arm_length);i.normalize().multiplyScalar(ie)}n=i.x;a=i.y;s=i.z;r=s;if(v){if(!u)v.fromArray(S&&Pe[c].timestamp!=null?Pe[c].filter(null,true):Pe[c].filter(v.toArray()));we(v,c+"腕");tt.add("skin",c+"腕",{absolute:true,rot:v,priority:-1,onFinish:Se});const oe=tt.skin[c+"腕"];const F=Ye[c+"腕"];const ne=MMD_SA.TEMP_q.copy(v).premultiply(F.axis_rot_inv).multiply(F.axis_rot);oe[0]._elbow0=new THREE.Vector3((c=="左"?1:-1)*MMD_SA_options.model_para_obj.left_arm_length/2,0,0).applyQuaternion(ne);if(k){we(k,c+"ひじ");tt.add("skin",c+"ひじ",{absolute:true,rot:k,_IK_disabled:u,onFinish:Ae})}}}else{we(k,c+"ひじ");we(v,c+"腕");tt.add("skin",c+"腕",{absolute:true,rot:v,priority:-1,onFinish:Se});tt.add("skin",c+"ひじ",{absolute:true,rot:k})}}else{m=true;let e=_.position.x-p.position.x;let t=_.position.y-p.position.y;n=e/se*MMD_SA_options.model_para_obj.shoulder_width*de;a=t/se*MMD_SA_options.model_para_obj.shoulder_width;if(d.score>0){let e=Math.min(Math.sqrt(Math.pow(p.position.x-d.position.x,2)+Math.pow(p.position.y-d.position.y,2))/se,1);let t=Math.min(Math.sqrt(Math.pow(_.position.x-d.position.x,2)+Math.pow(_.position.y-d.position.y,2))/se,1);r=(.25+(Math.sin(Math.acos(e))+Math.sin(Math.acos(t)))/2*.75)*MMD_SA_options.model_para_obj.left_arm_length}}}else{let t;if(d.score>0){if(re){let e=!!v;if(!u){u=false;if(Me.motion_tracking_upper_body_only&&tt._skin[E]?._pos_&&tt.get_blend_default_motion("skin",E)%1){e=false;[n,a,s]=tt._skin[E]._pos_;const ae=tt._skin[E]._foot_;if(ae){t=true;tt.add("skin",c+"足首",{after_IK:true,rot:ae.rot,_finger_x:null,absolute:true,onFinish:De})}}else{g=MMD_SA._v3a.copy(h).sub(f).normalize();g.multiplyScalar(MMD_SA_options.model_para_obj.left_arm_length);g.x*=de;n=g.x*de;a=g.y;s=g.z}r=s}else{u=true}if(e){if(!u)v.fromArray(S&&Pe[c].timestamp!=null?Pe[c].filter(null,true):Pe[c].filter(v.toArray()));we(v,c+"腕");tt.add("skin",c+"腕",{absolute:true,rot:v,priority:-1,onFinish:Se});const oe=tt.skin[c+"腕"];const F=Ye[c+"腕"];const ne=MMD_SA.TEMP_q.copy(v).premultiply(F.axis_rot_inv).multiply(F.axis_rot);oe[0]._elbow0=new THREE.Vector3((c=="左"?1:-1)*MMD_SA_options.model_para_obj.left_arm_length/2,0,0).applyQuaternion(ne)}}else{u=false;m=true;let e=_.position.x-d.position.x;let t=_.position.y-d.position.y;let i=Math.sqrt(e*e+t*t);let o=Math.asin(e/i);n=Math.sin(o)*MMD_SA_options.model_para_obj.left_arm_length*de;a=Math.cos(o)*MMD_SA_options.model_para_obj.left_arm_length*Math.sign(t)}}else{if(re){if(!Me.motion_tracking_upper_body_only)return;s=r=0}else{m=true}if(n==null){u=false;n=MMD_SA_options.model_para_obj.left_arm_to_IK_xy[1]*(c=="左"?1:-1)*.2;a=-Math.sqrt(MMD_SA_options.model_para_obj.left_arm_length*MMD_SA_options.model_para_obj.left_arm_length-n*n)}}if(ye[c]){tt.add("skin",c+"手首",{rot:new THREE.Quaternion});if(!t){tt.remove("skin",c+"足首")}}}let q=!u;if(!u&&(Me.motion_tracking?.arm_tracking?.use_IK||pe)&&!t?.disabled){if(S&&xe[c].timestamp!=null){q=false;[n,a,s]=xe[c].filter(null,true)}}if(Me.motion_tracking_upper_body_only&&tt._skin[E]){tt._skin[E]._pos_=[n,a,s]}le.push({pos:{x:n,y:a,z:s,z_posenet:r},z_limited:O,dir:i,d:c,IK_disabled:u,IK_absolute:m,use_filter:q})});ge[0]=ge[0]==null?0:Math.max(ge[0]+Math.PI/2,0);ge[1]=ge[1]==null?0:Math.max(Math.PI/2-ge[1],0);const T=ge[0]>ge[1]?1:0;const B=Math.min(Math.abs(ge[0]-ge[1])/(Math.PI/2),1);ge[T==0?1:0]=1;ge[T]=1-B*B*.5;t.forEach(function(e,i){let o=i==0?"左":"右";if(be[i]){et[i]*=ge[i];let e=(Fe.enabled?et[2]:0)*(i==0?1:-1);let t=et[i]+e;const n=Math.PI/6;if(Math.abs(t)>n){e=Math.sign(e)*(n-Math.abs(et[i]));t=et[i]+e}t=_t[o].filter(t);be[i].multiply(MMD_SA.TEMP_q.set(0,0,Math.sin(t/2),Math.cos(t/2)));tt.add("skin",o+"肩",{priority:-2,absolute:!(Me.motion_tracking_upper_body_only&&Me.motion_tracking?.motion_default_weight?.shoulder),rot:be[i],_rot_z:et[i],_rot_shrug:e,_rot_total:t,onFinish:Y})}})}else{pe=true}const A=M;if(re&&!Me.motion_tracking_upper_body_only){if(ue){w.premultiply(MMD_SA.TEMP_q.copy(ue).conjugate());M=A-MMD_SA.TEMP_v3.setEulerFromQuaternion(w,"YZX").z}}if(re&&!pe){$e.get_hip_center(me);let e=de==1?[1,0]:[0,1];let b=[];let t=[];let v=0;let i=[];e.forEach(function(n,e){let a=e==0?"左":"右";let i=me.keypoints3D[11+n];let s=me.keypoints3D[13+n];let r=me.keypoints3D[15+n];let t,o,_;if(r.score>0){t=MMD_SA._v3a.copy(i).sub(r);o=t.length();_=s.score>0?MMD_SA.TEMP_v3.copy(i).distanceTo(s)+MMD_SA.TEMP_v3.copy(s).distanceTo(r):.7;t.normalize().multiplyScalar(Math.min(o/_,1)*MMD_SA_options.model_para_obj.left_leg_length)}let l,c;let d;if(s.score>0){d=MMD_SA._v3b.copy(i).sub(s).normalize().applyQuaternion(MMD_SA.TEMP_q.copy(w).conjugate());let e=MMD_SA.TEMP_v3.set(0,1,0);e.y*=-1;c=Te.setFromVectorSpherical(e,d);l=(new THREE.Quaternion).setFromEuler(c,"XZY");const t=qe.setFromVectorSpherical(e,MMD_SA._v3b.copy(i).sub(s).normalize().applyQuaternion(MMD_SA.TEMP_q.copy(w).multiply(MMD_SA._q2.set(0,0,Math.sin(A/2),Math.cos(A/2))).multiply(MMD_SA._q1.set(Math.sin(S/2),0,0,Math.cos(S/2))).conjugate()));v+=t.x}let p=!MMD_SA_options.user_camera.ML_models.pose.use_legIK;if(r.score>0){let i,o;if(s.score>0){i=qe.copy(s).sub(r).normalize().applyQuaternion(MMD_SA.TEMP_q.copy(w).conjugate());o=Ie.copy(i).applyQuaternion(MMD_SA.TEMP_q.copy(l).conjugate());o.z=Math.max(-o.z,0);o.x*=-1;let e=o.normalize().toSphericalCoords();let t=Math.sqrt(Math.min((Math.PI-e[2])/(Math.PI/2),1));c.y=e[1]*t;l.setFromEuler(c,"XZY")}if(!p||s.score<=0){Ce.enable_IK(a+"足IK",true);b.push({pos:t.clone(),rot:[l],dir:n,d:a})}else{o=Ie.copy(i).applyQuaternion(MMD_SA.TEMP_q.copy(l).conjugate());let e=MMD_SA.TEMP_v3.set(0,1,0);e.y*=-1;let t=(new THREE.Quaternion).setFromVectorSpherical(e,o);Ce.enable_IK(a+"足IK",false);b.push({rot:[l,t],dir:n,d:a})}const u=me._keypoints3D[29+n];const m=me._keypoints3D[31+n];if(u.score>0&&m.score>0){let e=MMD_SA._v3a_.copy(u).sub(r).normalize();let t=MMD_SA._v3b_.copy(u).sub(m).normalize();let i=qe.crossVectors(e,t).normalize();e.crossVectors(t,i);Ge.set(i.x,i.y,i.z,0,e.x,e.y,e.z,0,t.x,t.y,t.z,0,0,0,0,1);We.setFromBasis(Ge);let o=We.conjugate();const h=-Math.PI/(MMD_SA_options.user_camera.ML_models.pose.model_quality=="Best"?10:8);o=o.clone().multiply(MMD_SA.TEMP_q.set(Math.sin(h/2),0,0,Math.cos(h/2)));if(ue)o.premultiply(ue);const f=Xe.copy(w);if(ue)f.premultiply(ue);const M=MMD_SA.TEMP_v3.setEulerFromQuaternion(f,"YZX");const y=Math.abs(M.y)%Math.PI;let n=y>Math.PI/2?1-(y-Math.PI/2)/(Math.PI/2):1;if(MMD_SA_options.user_camera.ML_models.pose.use_legIK){const g=o.clone();if(n<1){M.x=M.z=0;g.slerp(Ue.setFromEuler(M,"YZX"),1-n)}b[b.length-1].rot[2]=g}tt.add("skin",a+"足首",{after_IK:true,absolute:true,parent_based:true,motion_recorder_disabled:MMD_SA_options.user_camera.ML_models.pose.use_legIK,rot:o,ratio:n,ratio_euler:MMD_SA_options.user_camera.ML_models.pose.model_quality=="Best"?{x:1,y:1,z:.5,order:"YXZ"}:null})}}else{if(s.score>0){if(!p){t=MMD_SA._v3a.copy(i).sub(s).normalize().multiplyScalar(MMD_SA_options.model_para_obj.left_leg_length);if(ue)t.applyQuaternion(ue);Ce.enable_IK(a+"足IK",true);b.push({pos:t.clone(),rot:[l],dir:n,d:a})}else{Ce.enable_IK(a+"足IK",false);b.push({rot:[l],dir:n,d:a})}}if(tt.skin[a+"足首"]?.[0].rot.w!=1)tt.add("skin",a+"足首",{after_IK:true,absolute:true,no_blending:true,rot:new THREE.Quaternion})}});let o=0;i.forEach(e=>{const t=e.y*(1-e.scale);if(t>0){o=Math.max(t,o)}else if(i.length>1){o=Math.max(t,o||t)}});if(o){$e.v_hip.y+=o;He+="\nleg_offset_y:"+o+"\n"}v*=.5*.5;v+=S;v=Je("hip_angle_x",v,!!pe);let n=(new THREE.Quaternion).setFromEuler(MMD_SA.TEMP_v3.set(v,0,M),"YZX");tt.add("skin","下半身",{absolute:true,rot:n.clone()});if(!pe){tt.add("skin","全ての親",{pos:new THREE.Vector3,after_IK:true,priority:999,onProcessPosition:W})}n.conjugate();b.forEach(e=>{var t=e.d;if(e.rot[0]){e.rot[0].multiplyQuaternions(n,e.rot[0]);tt.add("skin",t+"足",{absolute:true,rot:e.rot[0]})}if(e.pos){e.pos.add(MMD_SA_options.model_para_obj.leg_IK_offset[t]);const i=e.rot[2]||tt.skin[t+"足IK"]?.[0].rot;tt.add("skin",t+"足IK",{absolute:true,pos:e.pos,rot:i,priority:999,onFinish:G});if(i&&!tt.skin[t+"足IK"][1].rot)tt.skin[t+"足IK"][1].rot=i}else{if(e.rot[1]){tt.add("skin",t+"ひざ",{absolute:true,rot:e.rot[1]})}else if(tt.skin[t+"ひざ"]?.[0].rot.w!=1){tt.add("skin",t+"ひざ",{absolute:true,no_blending:true,rot:new THREE.Quaternion})}}})}else{if(Me.motion_tracking_upper_body_only){$e.get_hip_center(me);tt.add("skin","全ての親",{pos:new THREE.Vector3,after_IK:true,priority:999,onProcessPosition:W})}else if(re&&o.score>0&&n.score>0&&je.video_canvas.width){$e.get_hip_center(me);tt.add("skin","全ての親",{pos:new THREE.Vector3,after_IK:true,priority:999,onProcessPosition:W})}if(!ye["左"]||!ye["右"]){let t=Je("hip_angle_x",0,!!pe);if(M||t){let e=(new THREE.Quaternion).setFromEuler(MMD_SA.TEMP_v3.set(t,0,M),"YZX");tt.add("skin","下半身",{absolute:true,rot:e.clone()})}else{tt.add("skin","下半身",{is_dummy:true,rot:true})}}for(const j of["左","右"]){if(!ye[j]){tt.add("skin",j+"足IK",{is_dummy:true,pos:true,priority:999});tt.add("skin",j+"足",{is_dummy:true,rot:true});tt.add("skin",j+"ひざ",{is_dummy:true,rot:true});tt.add("skin",j+"足首",{is_dummy:true,after_IK:true,rot:true})}}}}}else{Ce.data_detected=0}}if(Ce.enabled&&!Ce.data_detected_stable&&!Ne){Ne=true;if(!Me.motion_tracking_upper_body_only&&Ce.initial_data_detected)s.mesh.visible=false}let I;let E=[];const r=!Be.enabled&&me&&Ce.use_3D_pose;const _=de==1?[1,0]:[0,1];const d={};const l=Be.enabled&&Ce.shoulder_width?Math.min(Math.max(Math.max(je.video_canvas.width,je.video_canvas.height)/Ce.shoulder_width-5,0)/5,1)*.5:0;const m={"左":l,"右":l};if(r||!Me.motion_tracking_upper_body_only&&l){_.forEach(function(e,t){let i=t==0?"左":"右";if(!ce.find(e=>e.d==i)?.visible)return;let o=me._keypoints3D[15+e];let n=me._keypoints3D[17+e];let a=me._keypoints3D[19+e];if(o.score<=0||n.score<=0||a.score<=0)return;let s=e==1?[a,n]:[n,a];let r=MMD_SA._v3a_.copy(o).sub(MMD_SA._v3b.copy(n).add(a).multiplyScalar(.5)).normalize();r.x=r.x*de;let _=MMD_SA._v3b_.copy(s[0]).sub(s[1]).normalize();_.z=_.z*de;_.y=_.y*de;let l=MMD_SA.TEMP_v3.crossVectors(_,r).normalize();_.crossVectors(r,l);Ge.set(_.x,_.y,_.z,0,r.x,r.y,r.z,0,l.x,l.y,l.z,0,0,0,0,1);We.setFromBasis(Ge);let c=new THREE.Quaternion;c.copy(We).conjugate();if(ue)c.premultiply(ue);d[i]=c})}if(Be.enabled&&he.handpose&&he.handpose.length&&ce.length){const K=ut?1:2;he.handpose.forEach(e=>{e._offset={};I=e.annotations;if(K>1){for(let e in I){I[e].forEach(e=>{e[2]*=K})}}});ce.forEach((c,e)=>{var d=c.dir;let p=c.handpose;if(p&&c.visible){c.visible=true;p._used=true;let k=c.d;p._d=k;I=p.annotations;let e=le.find(e=>e.dir==d);const u=ze.set(1,1,p.z_adjust_ratio||1);let t=Me.motion_tracking?.hand_tracking?.depth_adjustment_disabled?0:MMD_SA_options.user_camera.ML_models.hands.depth_adjustment_percent/100;if(t&&pe&&e.pos.z>0&&MMD_SA_options.Dungeon_options?.item_base.hand_camera?._hand_camera_side!=k){const b=(MMD_SA._v3a.fromArray(I.palm[0]).multiply(u).distanceTo(MMD_SA._v3b.fromArray(I.middle[0]).multiply(u))+MMD_SA._v3a.fromArray(I.index[0]).multiply(u).distanceTo(MMD_SA._v3b.fromArray(I.pinky[0]).multiply(u)))/2/Ce.shoulder_width;const v=MMD_SA_options.user_camera.ML_models.hands.palm_shoulder_scale_percent/100;const w=Math.max(je.video_canvas.width,je.video_canvas.height)/Ce.shoulder_width;_e.filter(Math.max(3-Math.max(w-5,0),0)/3);palm_far_scale=(1.8+(1-Math.min(Math.max(w-4,0),1))*.4)*((1-MMD_SA_options.user_camera.ML_models.hands.depth_scale_percent/100)*2);re[k].filter(Math.min(Math.max(b-v,0)/Math.max(v*palm_far_scale-v,.1),1))}if(p.worldLandmarks){I=p.worldLandmarks.annotations;u.set(1,1,1)}E.push(k+"手");const m="pinky";let i=d==1?[I.index[0],I[m][0]]:[I[m][0],I.index[0]];let o,n,a;let s=MMD_SA._v3a_.fromArray(I.palm[0]).multiply(u).sub(MMD_SA._v3b.fromArray(I.middle[0]).multiply(u)).normalize();s.x=s.x*de;let r=MMD_SA._v3b_.fromArray(i[0]).multiply(u).sub(MMD_SA._v3b.fromArray(i[1]).multiply(u)).normalize();r.z=r.z*de;r.y=r.y*de;let _=MMD_SA.TEMP_v3.crossVectors(r,s).normalize();r.crossVectors(s,_);Ge.set(r.x,r.y,r.z,0,s.x,s.y,s.z,0,_.x,_.y,_.z,0,0,0,0,1);We.setFromBasis(Ge);let l=new THREE.Quaternion;l.copy(We).conjugate();if(D.enabled){const S=D.angle*Math.PI/180;const A=MMD_SA._q2.set(Math.sin(S/2),0,0,Math.cos(S/2));l.premultiply(A)}const M=MMD_SA.TEMP_v3.setEulerFromQuaternion(l,"YXZ").y;const y=1;const g=(Math.abs(M){let i=x[(de==1?k:k=="左"?"右":"左")+t];let o=i.base_index+(t==0?0:-1);let n=I[lt[t]];let a=Ue.copy(P);const s="XZY";if(t==0||t==4)return;const r=ct[k][t];const _=MMD_SA.TEMP_v3.fromArray(I.palm[0]);let l=MMD_SA._v3a_.fromArray(n[0]).sub(_);let c=MMD_SA._v3b_.fromArray(n[1]).sub(_);l.y*=-1;c.y*=-1;l.applyQuaternion(a);c.applyQuaternion(a);let d=MMD_SA.TEMP_v3.set(0,1,0);let p=c.sub(l).normalize();let u=Te.setFromVectorSpherical(d,p);const m=1;h+=u.z*m;f+=m});h/=f;rot_y_offset=MMD_SA.TEMP_q.set(0,Math.sin(h/2),0,Math.cos(h/2));P.conjugate().multiply(rot_y_offset).conjugate();rot_y_offset.set(0,Math.sin(h/4),0,Math.cos(h/4));l.multiply(rot_y_offset);tt.add("skin",k+"手首",{after_IK:true,rot:l,onProcessRotation:N});tt.add("skin",k+"手捩",{after_IK:true,absolute:true,priority:1,no_blending:true,rot:new THREE.Quaternion});Qe.forEach((e,t)=>{let i=x[(de==1?k:k=="左"?"右":"左")+t];let o=i.base_index+(t==0?0:-1);let n=I[lt[t]];let a=Ue.copy(P);const s="XZY";const r=ct[k][t];const _=MMD_SA.TEMP_v3.fromArray(I.palm[0]);for(let e=0;e<4;e++){const l=r[e].pos.fromArray(n[e]).sub(_);l.y*=-1;l.applyQuaternion(a)}});Qe.forEach((p,u)=>{let m=x[(de==1?k:k=="左"?"右":"左")+u];let h=m.base_index+(u==0?0:-1);let f=I[lt[u]];let M;const y="XZY";const g=k+p+"指"+Ve[m.base_index];const b=u==0?1:0;for(let d=h;d<3;d++){let e=k+p+"指"+Ve[m.base_index+(d-h)];const v=ct[k][u];const w=MMD_SA.TEMP_v3.copy(v[d].pos);for(let e=d;e<4;e++){const S=v[e].pos;S.sub(w);if(M&&e>d)S.applyQuaternion(M)}M=Ue;let t=v[d+0].pos;let i=v[d+1].pos;let o=MMD_SA._v3a_.set(0,1,0);let n=MMD_SA._v3b_.copy(i).sub(t).normalize();let a=MMD_SA._q1.set(0,0,0,1);let s=v[d].rot;if(u>0||d==2){s.setFromVectorSpherical(o,n);a.setFromEuler(s,y)}else{a.setFromUnitVectors(o,n);s.setEulerFromQuaternion(a,y)}M=Ue.copy(a).conjugate();if(Math.abs(s.z)>Math.PI/(u==0?1.1:2.5)||s.x>Math.PI/(u==0?1.1:3)){s.set(-Math.abs(o.angleTo(n)),0,0)}let r;if(u==0&&d>h+1){}else if(s.x>0){if(u>0&&d==0&&T>.5&&s.x>Math.PI/8){s.x*=-T}else s.x*=u==0?1:d>h?v[0].rot.x<0?-Math.min(Math.abs(v[0].rot.x)/(Math.PI/3),1):0:.75}if(s.x<0){r=-Math.PI/(u==0?1.25:1.8)}if(u==0){if(d==h){s.z=s.z*(d==0?1.25:1)+(Math.PI/8+(d==0?Math.PI/8:0))*(k=="左"?1:-1)}else if(d==1){s.z-=Math.PI/8*(k=="左"?1:-1)}else if(d==2){s.x=0;const A=Math.min(Math.abs(s.z)/(Math.PI/2),1);if(s.z>0){s.y=-Math.PI/4*Math.min(A*2,1);s.z=Math.PI/2*A}else{s.z=-Math.PI/2*A*1.5}}}else{let e=Math.min(...v.filter((e,t)=>t<=d).map(e=>e.rot.x));if(d==0){if(u>2){s.z=R*Math.abs(s.z)}}else{let t=1-(e<-Math.PI/6?Math.min(Math.abs(e+Math.PI/6)/(Math.PI/2-Math.PI/6),1):0);s.z*=t*(d==0?1:d==1?.75:.5);if(t<1){if(a.w>1)a.normalize();let e=2*Math.acos(a.w);s.x=s.x*t+Math.sign(s.x)*Math.abs(e)*(1-t)}}}if(T&&u>0&&d==h){const e=MMD_SA._v3a.fromArray(f[d+1]);e.y*=-1;e.applyQuaternion(P);const D=MMD_SA._v3b.fromArray(f[d+3]);D.y*=-1;D.applyQuaternion(P);if(e.y>D.y){const E=T;let e=1-E;s.z*=e;if(a.w>1)a.normalize();let t=2*Math.acos(a.w);s.x=s.x*e+Math.sign(s.x)*Math.abs(t)*(1-e)}}if(r)s.x=Math.max(s.x,r);a.setFromEuler(s,y);let _=e;let l=a.toAxisAngle();axis=l[0];angle=l[1];axis.z*=-1;let c=!MMD_SA.THREEX.enabled&&u==0?Math.min((Math.PI/8-Ye[g]._axis_rot_offset_inv_z*R)/(Math.PI/8),1.5):1;if(!MMD_SA.THREEX.enabled&&u==0)axis.applyEuler(MMD_SA.TEMP_v3.set(0,Math.PI/4*R*c,0));axis.applyEuler(qe.set(MMD_SA.THREEX.enabled?Math.PI/2:0,-Math.PI/2*R,0),"YXZ");if(u==0&&MMD_SA.THREEX.enabled){a.setFromAxisAngle(axis,angle)}else{if(u==0&&!MMD_SA.THREEX.enabled&&c<.5){axis.applyQuaternion(MMD_SA.TEMP_q.set(0,0,0,1).slerp(Ye[_].axis_rot,c/.5));if(c<.5)c=.5+(1-c/.5)}else{axis.applyQuaternion(Ye[_].axis_rot)}a.setFromAxisAngle(axis,angle)}if(d==b)a.premultiply(MMD_SA.TEMP_q.set(0,0,0,1).slerp(Ye[g].axis_rot_offset_inv,u==0?.5*c:1));if(ye[k]){if(d==h){const e=tt.skin[k+"手首"][0];if(!e._finger_x)e._finger_x=[];e._finger_x[u]=s.x}}else{tt.add("skin",e,{absolute:true,rot:a.clone()})}}})}else{const e=c.d;if(Me.motion_tracking_upper_body_only&&(!Me.motion_tracking?.hand_tracking?.stabilize_arm_disabled&&Be.stabilize_arm)&&tt.get_blend_default_motion("skin",e+(ye[e]?"足首":"手首"))!=0){c.visible=false}}})}else if(r){_.forEach(function(e,t){let i=t==0?"左":"右";if(d[i]){tt.add("skin",i+"手首",{after_IK:true,rot:d[i],onProcessRotation:N});tt.add("skin",i+"手捩",{after_IK:true,absolute:true,priority:1,no_blending:true,rot:new THREE.Quaternion})}})}const h={};const f={};_.forEach(function(e,t){let s=t==0?"左":"右";const o=Me.motion_tracking?.hand_tracking?.rotation_reference?.[s=="左"?"left":"right"];if(o){let a=o.weight||1;if(o.type=="object3D"){const i=MMD_SA.THREEX._XR_Animator_scene_.object3D_list.find(e=>e.id==o.name);if(!i)return;const n=MMD_SA.THREEX._object3d_list_.find(e=>e.uuid==i._object3d_uuid);if(n._rot_aligned_&&n.parent_bone.name==s+"手首"){if(n._rot_aligned_weight_!=null)a=n._rot_aligned_weight_}f[s]=o.weight_by_angle_difference;h[s]=o.constrained_direction}if(o.weight_by_magnet){const r=Me.motion_tracking.arm_tracking?.transformation?.position?.magnet?.find(e=>e.magnet_id==o.weight_by_magnet.id);a=r&&r._frame_count_>=EV_sync_update.count_frame-1-(Be.use_hands_worker?6:0)?r._weight_*(o.weight_by_magnet.max||a):0}if(!ce.find(e=>e.d==s)?.handpose?._used){a=1}a=Re[s].filter(a);m[s]=a;if(a){if(!tt.skin[s+"手首"]){const _=new THREE.Quaternion;tt.add("skin",s+"手首",{after_IK:true,rot:_,onProcessRotation:N});tt.add("skin",s+"手捩",{after_IK:true,absolute:true,priority:1,no_blending:true,rot:new THREE.Quaternion})}else if(tt.skin[s+"手首"][0].timestamp{i.forEach(e=>{const t=s+n+"指"+e;const i=c+n+"指"+e;let o=tt.skin[i]?.[0].rot;if(o){o=MMD_SA.TEMP_q.copy(o);o.y*=-1;o.z*=-1;if(!tt.skin[t]){tt.add("skin",t,{absolute:true,rot:o.clone()})}else{tt.skin[t][0].rot.slerp(o,a)}}})})}else if(o.fingers){for(const d in o.fingers){let[e,t]=d.split("|");e=l[e];t=i[parseInt(t)+(e=="親"?-1:0)];e=s+e+"指"+t;const p=tt.skin[e];if(p&&p[0].timestamp==RAF_timestamp){const u=o.fingers[d];let e=MMD_SA.TEMP_q;if(u.w==null){e=MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.copy(u).multiplyScalar(Math.PI/180));u.x=e.x;u.y=e.y;u.z=e.z;u.w=e.w}else{e.copy(u)}p[0].rot.slerp(e,a)}}}}}}});for(const j of["左","右"]){const w=tt.skin[j+"手首"];if(w){w[0]._rot_pose=d[j];w[0]._rot_pose_ratio=m[j];w[0]._rot_pose_constrained=h[j];w[0]._rot_pose_ratio_by_angle_difference=f[j];if(!w[0]._finger_x)w[0]._finger_x=w[1]._finger_x}}const y=[];le.forEach(function(n){var a=n.d;const t=new THREE.Vector3;if(n.use_filter){const i=xe[a].filters[0].filter;const o=se[a].filters[0].filter;for(const e of["minCutOff","beta","dCutOff"])o[e]=i[e];t.fromArray(se[a].filter([n.pos.x,n.pos.y,n.pos.z]))}else{se[a].filter(null,true);t.copy(n.pos)}let s=Me.motion_tracking?.hand_tracking?.depth_adjustment_disabled?0:MMD_SA_options.user_camera.ML_models.hands.depth_adjustment_percent/100;if(s&&Be.enabled&&pe&&MMD_SA_options.Dungeon_options?.item_base.hand_camera?._hand_camera_side!=a){let i=re[a].filter();let e=(RAF_timestamp-re[a].timestamp)/1e3;let o=1-Math.min(Math.max(e-.2,0)/(1-.2),1);const r=L.para.spine_length/5;if(n.pos.z>=0){if(o){let e=_e.filter();s*=o*e;let t=i*MMD_SA_options.model_para_obj.left_arm_length*s+n.pos.z*(1-s);n.pos.z=t}}if(n.pos.z_)n.pos.z=Math.sign(n.pos.z)*_}if(n.use_filter){const e=xe[a].filter([n.pos.x,n.pos.y,n.pos.z]);n.pos.x=e[0];n.pos.y=e[1];n.pos.z=e[2]}if(ye[a]){if(n.IK_disabled)return;Ce.enable_IK(a+"足IK",true);if(tt.skin[a+"手首"]&&tt.skin[a+"腕"]&&tt.skin[a+"手首"][0].timestamp==tt.skin[a+"腕"][0].timestamp){let e;if(e){}else{const d=MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.set(Math.PI/2,0,0));const p=tt.skin[a+"手首"][0].rot.premultiply(d).multiply(d.conjugate());if(tt._skin[a+"足IK"])tt._skin[a+"足IK"]._foot_={rot:p.clone(),_finger_x:tt.skin[a+"手首"][0]._finger_x};tt.add("skin",a+"足首",{after_IK:true,rot:p,_finger_x:tt.skin[a+"手首"][0]._finger_x,absolute:true,onFinish:De})}}else{const u=tt.skin[a+"足首"];if(u){u[0].rot_parent=u[0]._rot_parent}}tt.remove("skin",a+"手首");tt.remove("skin",a+"腕");tt.remove("skin",a+"ひじ");tt.remove("skin",a+"手捩");tt.remove("skin",a+"腕IK");if(Be.enabled){Qe.forEach((t,e)=>{let i=e==0?0:1;for(let e=i;ee.d==a);if(!e?.visible){if(tt.skin[a+"足首"]&&tt.get_blend_default_motion("skin",a+"足首")%1==0)delete tt.skin[a+"足首"][0].onFinish}const l=(new THREE.Vector3).copy(n.pos);const t=M.transformation?.position;const c=Q(a+"足IK",l,t,e=>{const t=MMD_SA_options.model_para_obj.left_leg_length;e.y+=t*1/3;e.z+=t*.25;e.multiplyScalar(1.5)});y.push({d:a,pos:l,rot:c[1]})}else{Ce.enable_IK(a+"腕IK",!n.IK_disabled);if(!n.IK_disabled){if(n.pos.z==null)n.pos.z=n.pos.z_posenet||(Ce.use_3D_pose?0:MMD_SA_options.model_para_obj.left_arm_length*.2);const m=ce.find(e=>e.d==a);const h=(new THREE.Vector3).copy(n.pos);let e=Me.motion_tracking?.arm_tracking?.off_screen_allowed?.[a=="左"?"left":"right"];tt.add("skin",a+"腕IK",{priority:999,pos:h,_IK_absolute:n.IK_absolute,_hand_visible:e||m?.visible,_pos0:t,onProcessPosition:V});const f=tt.skin[a+"腕IK"];if(!f[1]._pos0)f[1]._pos0=f[0]._pos0;if(f[0]!=f[1]&&f[0]._blending_ratio)f[0]._pos0.lerp(f[1]._pos0,1-f[0]._blending_ratio)}const e=tt.skin[a+"手首"];if(e){e[0].rot_parent=e[0]._rot_parent}}});if(y.length&&M.transformation?.position?.process)M.transformation.position.process(y);y.forEach(e=>{const t=e.d;const i=e.pos;i.y+=MMD_SA_options.model_para_obj.left_leg_IK[1]+(n["センター"].position.y-n["センター"].pmxBone.origin[1]);if(e.rot){tt.add("skin",t+"足",{absolute:true,rot:e.rot,onFinish:function(e,t){this.skin[t][0]._rot_=e.bones_by_name[t].quaternion.clone()}})}else{tt.remove("skin",t+"足")}tt.remove("skin",t+"ひざ");tt.add("skin",t+"足IK",{absolute:true,priority:999,pos:i})});if(Ne){if(Me.motion_tracking_upper_body_only){for(const j of["左","右"]){Ce.enable_IK(j+"腕IK",Me.has_arm_IK)}}}else if(Me.motion_tracking_upper_body_only){for(const j of["左","右"]){let e=Me.motion_tracking?.arm_tracking?.off_screen_allowed?.[j=="左"?"left":"right"];const w=ce.find(e=>e.d==j);const S=e?false:!w?.visible;if(ye[j]){tt.set_blend_default_motion("skin",j+"足IK",S);tt.set_blend_default_motion("skin",j+"足",S);tt.set_blend_default_motion("skin",j+"ひざ",S);tt.set_blend_default_motion("skin",j+"足首",S)}else{if(Me.has_leg_IK){tt.set_blend_default_motion("skin",j+"足IK",true);tt.remove("skin",j+"足首")}else{tt.set_blend_default_motion("skin",j+"足",true);tt.set_blend_default_motion("skin",j+"ひざ",true);tt.set_blend_default_motion("skin",j+"足首",true)}Ce.enable_IK(j+"足IK",Me.has_leg_IK);Ce.enable_IK(j+"つま先IK",Me.has_leg_IK);tt.set_blend_default_motion("skin",j+"肩",S);tt.set_blend_default_motion("skin",j+"腕",S);tt.set_blend_default_motion("skin",j+"ひじ",S);tt.set_blend_default_motion("skin",j+"手捩",S);tt.set_blend_default_motion("skin",j+"手首",S);tt.set_blend_default_motion("skin",j+"腕IK",S);if(Be.enabled){Qe.forEach((t,e)=>{let i=e==0?0:1;for(let e=i;e{DEBUG_show((Ce.use_holistic&&"(no facemesh data)\n"||"")+(Oe?"\n"+Oe+"\n":"")+He+"\n"+"FPS:"+EV_sync_update.fps_last)},0,0)}if(he.facemesh){Fe.worker_onmessage({data:he.facemesh})}if(Fe.draw_canvas&&me&&Fe.worker_initialized){let e={posenet:me,w:je.video_canvas.width,h:je.video_canvas.height,flip_canvas:je.display_flipped};if(he.handpose&&he.handpose.length)e.handpose=he.handpose;if(he.facemesh)e.facemesh=he.facemesh.faces;if(Ce.use_holistic||!Fe.enabled){e.draw_canvas=true;if(self.FacemeshAT){e.canvas=je.video_canvas_facemesh}else if(!je.video_canvas_facemesh._offscreen&&self.OffscreenCanvas){e.canvas=je.video_canvas_facemesh.transferControlToOffscreen();je.video_canvas_facemesh._offscreen=true;console.log("(Facemesh: use offscreen canvas)")}}Le.postMessage(e,e.canvas?[e.canvas]:undefined)}if(!Fe.draw_canvas){Fe.wireframe._data.pose=me;if(he.handpose)Fe.wireframe._data.handpose=he.handpose;if(he.facemesh)Fe.wireframe._data.facemesh=he.facemesh.faces;if(he.facemesh){Fe.wireframe._data.bb={x:0,y:0,w:je.video_canvas.width,h:je.video_canvas.height}}}ot=0}D()}}();function D(e){async function t(){var e=Ce.enabled&&Ce.worker_initialized&&k&&!Ce.busy&&R&&Ce.camera_video_timestamp!=k;if(!e)return;ot=RAF_timestamp;Ce.camera_video_timestamp=k;Ce.camera_video_frame_id=P;if(Ce.use_holistic){Fe.camera_video_timestamp=k;Fe.camera_video_frame_id=P}if(Ce.use_holistic&&Fe.blink_detection){MMD_SA_options.auto_blink=Fe.auto_blink||false}let t,i,o;t=je.video_canvas;i=t.width;o=t.height;let n=self.PoseAT?t:T?await createImageBitmap(t):t.getContext("2d").getImageData(0,0,i,o).data.buffer;let a=!Ce.use_holistic&&(!MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only||System._browser.camera.handpose.constrain_tracking_region);Ce._timestamp=je.video_timestamp;let s={rgba:n,w:i,h:o,options:{video_flipped:je.video_flipped,use_canvas_hands:a,use_holistic:Ce.use_holistic,use_holistic_landmarker:Ce.use_holistic_landmarker,use_holistic_legacy:Ce.use_holistic_legacy,use_posenet:true,use_handpose:Be.enabled,use_hands_worker:Be.use_hands_worker,skip_hand_countdown_max:Ce.skip_hand_countdown_max,model_quality:MMD_SA_options.user_camera.ML_models.pose.model_quality||"",z_depth_scale:MMD_SA_options.user_camera.ML_models.pose.z_depth_scale,timestamp:Ce._timestamp}};Object.assign(s.options,MMD_SA.MMD.motionManager.para_SA.motion_tracking?.hand_tracking?.mocap_options);let r=[s.rgba];if(!Ce.canvas_hands){const _=Ce.canvas_hands=document.createElement("canvas");_.width=_.height=768;s.canvas_hands=_.transferControlToOffscreen();r.push(s.canvas_hands)}if(Be.use_hands_worker&&!Be.canvas_hands_worker){const _=Be.canvas_hands_worker=document.createElement("canvas");_.width=_.height=768;s.canvas_hands_worker=_.transferControlToOffscreen();r.push(s.canvas_hands_worker)}O.postMessage(s,r);r.length=0;r=undefined;s.rgba=n=undefined;s=undefined}if(e||self.PoseAT){setTimeout(()=>{t()},0)}else{t()}}var S=function(){const r=()=>{};var _,l;var Me={};var ye={},ge={},be={};var ve={};var we,Se;window.addEventListener("jThree_ready",e=>{_=new THREE.Vector3;l=new THREE.Quaternion;for(const t of["センター","上半身","上半身2","首","頭"]){Me[t]=new THREE.Quaternion}for(const i of["左","右"]){ve[i]={target:new THREE.Vector3,arm_pos:new THREE.Vector3};ye[i]={target:new THREE.Vector3,effector:new THREE.Quaternion,links:[]};ge[i]={effector:new THREE.Quaternion,links:[]};be[i]={effector:new THREE.Quaternion,parent:new THREE.Quaternion,links:[]};for(let e=0;e<2;e++){ye[i].links[e]=new THREE.Quaternion;ge[i].links[e]=new THREE.Quaternion;be[i].links[e]=new THREE.Quaternion}}we=new System._browser.data_filter([{type:"one_euro",id:"hip_rot",para:[30,1,.2,.2,4]}]);Se=new System._browser.data_filter([{type:"one_euro",id:"hip_mov",para:[30,1,.2,.2,3]}])});let c=250;let d=500;let p=0;function e(e,t,i){if(!this[e][t])return 0;const o=this[e][t][0];let n;if(o._blend_default_motion>0){n=Math.min((RAF_timestamp-o._blend_default_motion)/(d*Ce.limb_return_duration_percent/100),1)}else if(o._blend_default_motion<0){n=1-Math.min((RAF_timestamp+o._blend_default_motion)/(c*Ce.limb_entry_duration_percent/100),1)}else{n=0}if(n==0){this[e][t].forEach(e=>{if(e._blend_default_motion!=null)e._blend_default_motion=0})}else if(i){n=n<.5?(1-Math.cos(n*Math.PI))*.5:.5+Math.sin((n-.5)*Math.PI)*.5}return n}function t(e,t,i,o){if(!this[e][t]){if(!i)return;const n=t.indexOf("IK")!=-1;const a={_blend_default_motion:i?1:0};if(n)a.pos=new THREE.Vector3;else a.rot=new THREE.Quaternion;this.add("skin",t,a)}else{const s=this[e][t][1];if(i){if(this.reset_to_default_motion_once||s._blend_default_motion==null){s._idle_blend_default_motion=0;s._blend_default_motion=1}else if(s._blend_default_motion==0){if(!s._idle_blend_default_motion)s._idle_blend_default_motion=RAF_timestamp;if(RAF_timestamp-s._idle_blend_default_motion>=(typeof o=="number"?o:p)){s._idle_blend_default_motion=0;s._blend_default_motion=RAF_timestamp-RAF_timestamp_delta}}else if(s._blend_default_motion<0){s._blend_default_motion=RAF_timestamp-this.get_blend_default_motion(e,t)*(d*Ce.limb_return_duration_percent/100)}}else{s._idle_blend_default_motion=0;if(s._blend_default_motion>0){s._blend_default_motion=-(RAF_timestamp-(1-this.get_blend_default_motion(e,t))*(c*Ce.limb_entry_duration_percent/100))}}this[e][t][0]._blend_default_motion=s._blend_default_motion;this[e][t][0]._idle_blend_default_motion=s._idle_blend_default_motion}if(!this["_"+e][t])this["_"+e][t]={pos:new THREE.Vector3,rot:new THREE.Quaternion}}const i=new RegExp("("+toRegExp(["腕"],"|")+")$");function Ae(i,o){const e=THREE.MMD.getModels()[i._model_index];const n=MMD_SA.motion[e.skin._motion_index].para_SA;let t;const a=i.bones_by_name;const s=a[o];const r=this.skin[o];if(Ce.enabled&&!Ce.data_detected_stable)return;if(r[0].info[1]=="facemesh"){}let _,l;r[0].t_delta+=RAF_timestamp_delta;let c=Math.max(Math.min(r[0].t_delta/r[0].t_delta_frame,1),0);if(r[0].rot){if(r[0].after_IK){t=!s._update_IK_and_AddTrans||s._update_IK_and_AddTrans.length;if(t){if(s.quaternion.x||s.quaternion.y||s.quaternion.z){s.quaternion.conjugate();e._update_IK_and_AddTrans(false,o);s.quaternion.conjugate()}}}if(r[0].onProcessRotation){r[0].onProcessRotation.call(this,i,o)}else{let t=Xe.set(0,0,0,1);if(r[0].absolute){s.quaternion.set(0,0,0,1)}else{let e;if(n.motion_tracking_upper_body_only){if(o.indexOf("上半身")!=-1){e=n.motion_tracking?.motion_default_weight?.upper_body}else if(o.indexOf("肩")!=-1){e=n.motion_tracking?.motion_default_weight?.shoulder}}if(e==null)e=1;if(e<1)s.quaternion.slerp(MMD_SA.TEMP_q.set(0,0,0,1),1-e)}if(r[0].parent_based){let e=r[0].rot_parent;if(!e){e=MMD_SA.get_bone_rotation_parent(i,o,i).conjugate()}r[0]._rot_parent=e;t.copy(e)}t.multiply(r[0].no_blending?r[0].rot:MMD_SA.TEMP_q.copy(r[1].rot).slerp(r[0].rot,c));const p=r[0].ratio_euler;if(p){const m=MMD_SA.TEMP_v3.setEulerFromQuaternion(t,p.order);const h=r[0].ratio<1?r[0].ratio:1;m.x*=p.x*h;m.y*=p.y*h;m.z*=p.z*h;t.setFromEuler(m,p.order)}else if(r[0].ratio<1){t.slerp(Ue.set(0,0,0,1),1-r[0].ratio)}const u=MMD_SA_options.model_para_obj_all[i._model_index].skin_default[o];if(u&&u.rot_scale){if(typeof u.rot_scale=="number")u.rot_scale={x:u.rot_scale,y:u.rot_scale,z:u.rot_scale};t.setFromEuler(MMD_SA.TEMP_v3.setEulerFromQuaternion(t,"YXZ").multiply(u.rot_scale),"YXZ")}s.quaternion.multiply(t);_=it.active&&!r[0].motion_recorder_disabled&&o.indexOf("IK")==-1}}if(r[0].pos){if(r[0].onProcessPosition){r[0].onProcessPosition.call(this,i,o)}else{if(r[0].absolute)s.position.set(0,0,0);const f=MMD_SA.TEMP_v3.copy(r[1].pos).lerp(r[0].pos,c);s.position.add(f);l=it.active&&!r[0].motion_recorder_disabled&&o.indexOf("IK")==-1}}r[0].onFinish&&r[0].onFinish.call(this,i,o);if(_)it.set_boneKey(o,null,s.quaternion,true);if(l)it.set_boneKey(o,qe.copy(s.position).sub(Te.fromArray(o=="センター"?MMD_SA.THREEX.get_model(i._model_index).get_bone_origin_by_MMD_name("センター",true):s.pmxBone.origin)),null,true);let d=this.get_blend_default_motion("skin",o,true);if(d){if(r[0].rot&&this._skin[o]?.rot){const M=MMD_SA.TEMP_q.copy(this._skin[o].rot);s.quaternion.slerp(this._skin[o].onProcessRotation&&this._skin[o].onProcessRotation.call(this,i,o,M)||M,d)}if(r[0].pos&&this._skin[o]?.pos){s.position.lerp(this._skin[o].pos,d)}if(it.active&&!r[0].motion_recorder_disabled){if(o.indexOf("IK")!=-1)it.set_boneKey(o,r[0].pos&&s.position,r[0].rot&&s.quaternion,false)}}t&&e._update_IK_and_AddTrans(false,o)}var De=0;function o(e){function t(){if(R)return;R=Me;for(const e of["センター","上半身","上半身2","首"]){const t=this.skin[e];if(!t){R[e].set(0,0,0,1);continue}if(e=="首"){R[e].copy(t[0]._rot_neck||t[1]._rot_neck||MMD_SA._q1.set(0,0,0,1));R["頭"].copy(t[0]._rot_head||t[1]._rot_head||MMD_SA._q1.set(0,0,0,1))}else{const i=MMD_SA._q1.set(0,0,0,1);const o=Math.max(Math.min((t[0].t_delta+RAF_timestamp_delta)/t[0].t_delta_frame,1),0);i.multiply(t[0].no_blending?t[0].rot:MMD_SA.TEMP_q.copy(t[1].rot).slerp(t[0].rot,o));if(t[0].ratio<1)i.slerp(MMD_SA._q2.set(0,0,0,1),1-t[0].ratio);R[e].copy(i)}}T=st.copy(R["センター"]).multiply(R["上半身"]).multiply(R["上半身2"]).conjugate()}let L,C,B,E;function H(n){function a(){if(L==RAF_timestamp)return;L=RAF_timestamp;const e=MMD_SA.TEMP_q.copy(this._body_motion_rot[0]["上半身"]).multiply(this._body_motion_rot[0]["上半身2"]);B=1;C=at.copy(T).conjugate().premultiply(e.conjugate().multiply(nt.copy(this._body_motion_rot[1]["上半身"]).multiply(this._body_motion_rot[1]["上半身2"]))).conjugate();const t=C.toAxisAngle();E=t[1]%(Math.PI*2);if(Math.abs(E)>Math.PI)E-=Math.sign(E)*Math.PI*2;E*=2/3;if(Math.abs(E)>Math.PI/4)E=Math.sign(E)*Math.PI/4}const e=["センター","上半身","上半身2","首","頭"];let o;const s=I&&I.parent;const r=qe.set(0,0,0);if(s){const y=s.name||n+"足";const g=y.charAt(0);const b=1-this.get_blend_default_motion("skin",y.indexOf("足")!=-1?g+"足IK":y,true);let t,i;switch(y){case"頭":o=b&&this.skin["首"];if(o){for(const y of["首","頭"])x[y].quaternion.copy(R[y]);t=MMD_SA.get_bone_position(k,"頭","首").add(Te.set(0,.75,.75).applyQuaternion(MMD_SA.TEMP_q.copy(x["首"].quaternion).multiply(x["頭"].quaternion)));x["首"].quaternion.copy(this._body_motion_rot[0]["首"]);x["頭"].quaternion.copy(this._body_motion_rot[0]["頭"]);i=MMD_SA.get_bone_position(k,"頭","首").add(Te.set(0,.75,.75).applyQuaternion(MMD_SA.TEMP_q.copy(x["首"].quaternion).multiply(x["頭"].quaternion)))}break;case"左足":case"右足":o=b;if(o){if(!ge[g].updated){ye[g].enabled=true;o=false}}else{ye[g].enabled=false;ge[g].updated=0}if(o){const v=Te.fromArray(x[n+"ひざ"].pmxBone.origin).sub(Ie.fromArray(x[y].pmxBone.origin));t=Ie.copy(v).applyQuaternion(Xe.copy(be[g].parent).multiply(be[g].links[1]));i=v.applyQuaternion(Xe.copy(be[g].parent).multiply(ge[g].links[1]))}break}if(o){o=y;r.copy(t).sub(i);let e=s.weight||.5;if(typeof e=="object"){r.x*=r.x<0?e.x.left:e.x.right;r.y*=r.y<0?e.y.down:e.y.up;r.z*=r.z<0?e.z.backward:e.z.forward}else{r.multiplyScalar(e)}r.multiplyScalar(b)}}const t=je.x_flipped?-1:1;let i,_,l;let c;for(const y of e)x[y].quaternion.copy(this._body_motion_rot[0][y]);const d=P.motion_tracking?.arm_tracking?.elbow_lock?.[n=="左"?"left":"right"];if(d){d._elbow_y=d.y_absolute!=null?d.y_absolute:MMD_SA.get_bone_position(k,n+"ひじ",k).y+(d.y||0)}if(!o||o!="頭"){i=MMD_SA.get_bone_position(k,n+"腕",k);l=MMD_SA.get_bone_rotation_parent(k,n+"腕IK",k);_=!P.has_arm_IK?MMD_SA.get_bone_position(k,n+"手首",k):(new THREE.Vector3).copy(x[n+"腕IK"].position).sub(MMD_SA_options.model_para_obj.arm_IK_offset[n]).applyQuaternion(l).add(i);l.conjugate()}for(const y of e)x[y].quaternion.copy(this._body_motion_rot[1][y]);if(!i){i=MMD_SA.get_bone_position(k,n+"腕",k);l=MMD_SA.get_bone_rotation_parent(k,n+"腕IK",k);_=!P.has_arm_IK?MMD_SA.get_bone_position(k,n+"手首",k):(new THREE.Vector3).copy(x[n+"腕IK"].position).sub(MMD_SA_options.model_para_obj.arm_IK_offset[n]).applyQuaternion(l).add(i);l.conjugate()}for(const y of["センター","上半身","上半身2"]){let e;if(y.indexOf("上半身")!=-1)e=P.motion_tracking?.motion_default_weight?.upper_body;if(e==null)e=1;if(this.skin[y]){if(e<1)x[y].quaternion.slerp(MMD_SA.TEMP_q.set(0,0,0,1),1-e);x[y].quaternion.multiply(R[y])}}let p=I&&I.default_position_weight;if(typeof p!="number")p=.5;const u=MMD_SA.get_bone_rotation_parent(k,n+"腕IK",k).conjugate();let m;let h=P.motion_tracking?.arm_tracking?.IK_constraint;if(h)h=h[n=="左"?"left":"right"]||h;if(h&&this.skin[n+"腕IK"]&&this.get_blend_default_motion("skin",n+"腕IK")<1){const w=ve[n];w.enabled=true;w.target.copy(_);w.target_radius=0;if(h.target_offset){const S=qe.fromArray(h.target_offset);w.target.add(S);w.target_radius=S.length()}if(h.target_radius)w.target_radius+=h.target_radius;m=MMD_SA.get_bone_position(k,n+"腕",k);w.arm_pos.copy(m)}m=p==0?i:(m||MMD_SA.get_bone_position(k,n+"腕",k)).lerp(i,1-p);const f=m.sub(_);if(p<1)u.slerp(l,1-p);f.x*=t;f.y*=-1;f.z*=-1;if(o&&o=="頭"){f.applyQuaternion(u)}else{f.applyQuaternion(u)}if(!this._skin[n+"腕IK"])this._skin[n+"腕IK"]={pos:new THREE.Vector3,rot:new THREE.Quaternion};if(!this._skin[n+"腕IK"].rot_parent_inv)this._skin[n+"腕IK"].rot_parent_inv=new THREE.Quaternion;this._skin[n+"腕IK"].rot_parent_inv.copy(u).conjugate();f.add(r);f.add(MMD_SA_options.model_para_obj.arm_IK_offset[n]);for(const y of e)x[y].quaternion.copy(this._body_motion_rot[1][y]);const M=this.skin[n+"手首"];if(M){if(K){M[0].after_IK=true;if(this._skin[n+"手首"])this._skin[n+"手首"]._rot_absolute=MMD_SA.get_bone_rotation(k,n+"手首",false,k)}if(this._skin[n+"手首"])this._skin[n+"手首"].onProcessRotation=O;if(this._skin[n+"手捩"])this._skin[n+"手捩"].onProcessRotation=q}if(this._skin[n+"腕"]){a.call(this);let e=Math.min(p*2,1);let t=Math.abs(E/(Math.PI/4))*e*B;const A=n=="左"?1:-1;let i=A*Math.PI/4*t;let o=nt.set(0,Math.sin(i),0,Math.cos(i));const D=Ye[n+"腕"];o.premultiply(D.axis_rot).multiply(D.axis_rot_inv);this._skin[n+"腕"].rot.premultiply(o)}return f}function O(e,t,i){const o=t.charAt(0);const n=P.motion_tracking&&P.motion_tracking.arm_default_stickiness&&(P.motion_tracking.arm_default_stickiness[o]||P.motion_tracking.arm_default_stickiness).default_rotation_weight;if(!n)return i;const a=MMD_SA.get_bone_rotation_parent(e,t,e).conjugate();const s=a.multiply(this._skin[t]._rot_absolute);return s.slerp(i,1-n)}function q(e,t,i){return i.set(0,0,0,1)}function i(){if(Ce.data_detected){Ee();System._browser.on_animation_update.remove(i,0)}}const o=e.detail.model;const X=MMD_SA.THREEX.get_model(o._model_index);const U=X.is_T_pose;const k=o.mesh;const x=k.bones_by_name;const P=MMD_SA.motion[o.skin._motion_index].para_SA;for(const a of["左","右"]){const s=P.motion_tracking?.hand_tracking?.rotation_reference?.[a=="左"?"left":"right"];if(!s)continue;hand_f=tt.skin[a+"手首"]?.[0];if(!hand_f||!hand_f._rot_pose_ratio)continue;let e;if(s.type=="object3D"){const W=MMD_SA.THREEX._XR_Animator_scene_.object3D_list.find(e=>e.id==s.name);if(!W)return;const r=MMD_SA.THREEX._object3d_list_.find(e=>e.uuid==W._object3d_uuid);if(r._rot_aligned_&&r.parent_bone.name==a+"手首"){e=r._rot_aligned_}else{e=r._mesh.quaternion.clone()}if(s.offset){if(s.offset=="parent_bone"){const _=MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.set(-r.parent_bone.rotation.x,-r.parent_bone.rotation.y,r.parent_bone.rotation.z).multiplyScalar(Math.PI/180),"YXZ").toAxisAngle();e.multiply(MMD_SA.TEMP_q.setFromAxisAngle(_[0].applyQuaternion(Xe.copy(Ze[a=="左"?1:-1]).conjugate()),_[1]))}else{if(s.offset.w==null){const l=MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.copy(s.offset).multiplyScalar(Math.PI/180),s.offset.order);s.offset.x=l.x;s.offset.y=l.y;s.offset.z=l.z;s.offset.w=l.w}e.multiply(MMD_SA.TEMP_q.copy(s.offset))}}}else{if(s.rotation){if(s.rotation.w==null){const l=MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.copy(s.rotation).multiplyScalar(Math.PI/180));s.rotation.x=l.x;s.rotation.y=l.y;s.rotation.z=l.z;s.rotation.w=l.w}e=MMD_SA.TEMP_q.copy(s.rotation)}}if(!hand_f._rot_pose)hand_f._rot_pose=new THREE.Quaternion;if(e){hand_f._rot_pose.copy(e)}else{hand_f._rot_pose.set(0,0,0,1)}}if(!this._reset_disabled&&this._motion_path&&(this._motion_path!=P._path||this._motion_tracking_upper_body_only!=!!P.motion_tracking_upper_body_only)){this._motion_path=P._path;this._motion_tracking_upper_body_only=!!P.motion_tracking_upper_body_only;this.reset();ke();Ce.data_detected=0;Ce.initial_data_detected=false;System._browser.on_animation_update.remove(i,0);System._browser.on_animation_update.add(i,0,0,-1);return}this._motion_path=P._path;this._motion_tracking_upper_body_only=!!P.motion_tracking_upper_body_only;if(it.enabled&&De!=Ce.data_detected){De=Ce.data_detected;it.timestamp_for_recording=RAF_timestamp;if(it.active)window.dispatchEvent(new CustomEvent("SA_motion_recorder_on_active",e))}for(const a of["左","右"]){this.arm_IK_constraint[a].enabled=false}rt.copy(this.get_upper_body_rotation()).multiply(this._rot_body_camera_offset);this.upper_body_rotation_limiter(rt);let R,T,I,K;if((Ce.enabled||Fe.enabled)&&P.motion_tracking_upper_body_only){const c=P.motion_tracking&&P.motion_tracking.arm_as_leg;const d={"左":c&&c.enabled&&(!c.linked_side||c.linked_side=="left"),"右":c&&c.enabled&&(!c.linked_side||c.linked_side=="right")};for(const m in this._skin){this._skin[m].pos.copy(x[m].position);this._skin[m].rot.copy(x[m].quaternion)}for(const a of["左","右"]){if(tt._skin[a+"腕"])tt._skin[a+"腕"].pos_local=MMD_SA.get_bone_position(k,a+"腕",k)}Ce.hip_adjustment_set=MMD_SA.MMD.motionManager.filename;const p=Ce.hip_adjustment_weight_percent/100;let e=p&&(Ce.data_detected||!Ce.enabled&&Fe.data_detected);let o,n;if(e){t.call(this);const h=Xe.copy(T);const u=P.motion_tracking?.ML_models?.pose||MMD_SA_options.user_camera.ML_models.pose;if(u.upper_rotation_offset){const V=u.upper_rotation_offset*Math.PI/180;h.premultiply(MMD_SA.TEMP_q.set(0,Math.sin(V/2),0,Math.cos(V/2)))}h.conjugate();const Q=P.motion_tracking?.hip_adjustment?.rotation_weight;const _=h.toAxisAngle();o=(new THREE.Quaternion).setFromAxisAngle(_[0],_[1]*((typeof Q=="number"?Q:.5)*p)*Ce.hip_adjustment_rotation_percent/100);let i=Ce.hip_adjustment_smoothing_percent/100;if(i)i=.1+(1-i)*(1-i)*.9;if(i){we.filters[0].filter.minCutOff=i;o.fromArray(we.filter(o.toArray()))}this.remove("skin","下半身");this.add("skin","下半身",{no_blending:true,rot:o});if(this.skin["センター"]){let e=P.motion_tracking?.hip_adjustment?.displacement_weight;if(e==null)e=.25;const f=qe;const M=Te;if(typeof e=="number"){if(e){e*=p;f.set(0,MMD_SA_options.model_para_obj.left_leg_length/3*e,0);M.set(-1,1,-1)}}else{f.copy(e.axis||MMD_SA.TEMP_v3.set(0,e.weight,0)).multiplyScalar(MMD_SA_options.model_para_obj.left_leg_length/3*p);M.copy(e.scale)}M.x*=Ce.hip_adjustment_scale_x_percent/100;M.y*=Ce.hip_adjustment_scale_y_percent/100;M.z*=Ce.hip_adjustment_scale_z_percent/100;const N=Ce.hip_adjustment_adjust_y_axis_percent/100;if(N&&!e.axis){const Y=Math.PI/4*N;const Z=f.y;f.y=Z*Math.cos(Y);f.z=Z*Math.sin(Y)}if(e){axis_default=Ie.copy(f);let e=MMD_SA.TEMP_v3.setEulerFromQuaternion(R["首"],"YZX");e.x*=Ce.hip_adjustment_head_pitch_rotation_percent/100;h.multiply(MMD_SA.TEMP_q.set(0,0,0,1).slerp(MMD_SA._q1.setFromEuler(e,"YZX"),Ce.hip_adjustment_head_weight_percent/100));f.applyQuaternion(h);f.sub(axis_default).multiply(M);if(i){Se.filters[0].filter.minCutOff=i;f.fromArray(Se.filter(f.toArray()))}const $=MMD_SA_options.model_para_obj.left_leg_length*.1;if(f.y>0)f.y=Math.pow(Math.min(f.y/($*4),1),.5)*$;let t=P.motion_tracking?.hip_adjustment?.knee_fixed_weight;if(t){const y=new THREE.Vector3;for(const a of["左","右"]){const g=MMD_SA.get_bone_position(k,a+"ひざ","全ての親");const J=Ke.copy(x["下半身"].quaternion);const ee=MMD_SA.get_bone_position(k,a+"足","全ての親");x["下半身"].quaternion.multiply(o);x["センター"].position.add(f);const te=MMD_SA.get_bone_position(k,a+"足","全ての親");const b=Ie.copy(g).sub(ee);const ie=b.length();b.normalize();const v=ze.copy(g).sub(te);const oe=v.length();v.normalize();const ne=MMD_SA._q1.copy(x["センター"].quaternion).multiply(J).conjugate();const ae=MMD_SA._v3a.copy(b).applyQuaternion(ne);const se=MMD_SA._q2.copy(x["センター"].quaternion).multiply(R["センター"]).multiply(x["下半身"].quaternion).conjugate();const re=MMD_SA._v3b.copy(v).applyQuaternion(se);const _e=MMD_SA.TEMP_q.setFromUnitVectors(ae,re);if(t<1)_e.slerp(nt.set(0,0,0,1),t);x[a+"足"].quaternion.multiply(_e);const le=v.multiplyScalar(ie).sub(g).negate();le.sub(te);y.add(le);x["下半身"].quaternion.multiply(MMD_SA.TEMP_q.copy(o).conjugate());x["センター"].position.sub(f)}y.multiplyScalar(.5*t);f.add(y)}this.skin["センター"][0].pos=(this.skin["センター"][0].pos||new THREE.Vector3).copy(f);this.skin["センター"][0]._hip_adjustment_offset=(this.skin["センター"][0]._hip_adjustment_offset||new THREE.Vector3).copy(f);this.skin["センター"][1].pos=this.skin["センター"][0].pos;n=this.skin["センター"][0].pos}}}for(const a of["左","右"]){const w=a=="左"?"left":"right";I=P.motion_tracking&&P.motion_tracking.arm_default_stickiness&&(P.motion_tracking.arm_default_stickiness[w]||P.motion_tracking.arm_default_stickiness);K=I&&I.default_rotation_weight;let i=P.motion_tracking?.hip_adjustment?.[w]?P.motion_tracking.hip_adjustment[w].feet_fixed_weight:P.motion_tracking?.hip_adjustment?.feet_fixed_weight;if(typeof i!="number")i=1;if(i<1||(e||d[a])&&!P.has_leg_IK){const m=a+"足IK";let e,t;if(o){e=Xe.copy(x["下半身"].quaternion);x["下半身"].quaternion.multiply(o)}if(n){t=qe.copy(x["センター"].position);x["センター"].position.add(n)}const ce=P.has_leg_IK?null:MMD_SA.get_bone_position(k,a+"足","全ての親");const S=i<1?MMD_SA.get_bone_position(k,a+"足首","全ての親"):Te;if(e)x["下半身"].quaternion.copy(e);if(n)x["センター"].position.copy(t);const A=P.has_leg_IK||i>0?MMD_SA.get_bone_position(k,a+"足首","全ての親"):S;const de=je.x_flipped?-1:1;if(P.has_leg_IK){const D=qe.copy(A).sub(S.lerp(A,i));D.x*=de;D.y*=-1;D.z*=-1;if(!this._skin[m])this._skin[m]={pos:new THREE.Vector3,rot:new THREE.Quaternion};this._skin[m].pos.add(D);x[m].position.add(D)}else{const pe=qe.fromArray(x[a+"足"].pmxBone.origin);const ue=pe.sub(ce).negate();const D=ce.sub(S.lerp(A,i));D.x*=de;D.y*=-1;D.z*=-1;D.add(MMD_SA_options.model_para_obj.leg_IK_offset[a]);D.add(ue);if(!this._skin[m])this._skin[m]={pos:new THREE.Vector3,rot:new THREE.Quaternion};this._skin[m].pos.copy(D);if(!d[a]){Ce.enable_IK(m,true);if(!this.skin[m])this.add("skin",m,{absolute:true,is_dummy:true,pos:true,priority:999})}else{Ce.enable_IK(a+"つま先IK",false)}x[m].position.copy(D);if(Ce.data_detected)x[a+"ひざ"].quaternion.set(0,0,0,1)}x[m].position.y+=this._skin[m]._offset_y_||0}if(d[a]){t.call(this);const D=H.call(this,a);x[a+"腕IK"].position.copy(D);Ce.enable_IK(a+"腕IK",true)}else{const m=a+"腕IK";let e;const me=this.skin[a+"手首"];if(me){t.call(this);if(!Ce.IK_disabled_check(m)){e=H.call(this,a)}else{if(this._skin[a+"腕"])this._skin[a+"腕"].rot.premultiply(T);if(this._skin[a+"手首"])this._skin[a+"手首"].rot.premultiply(MMD_SA.TEMP_q.copy(T).conjugate())}}if(e)this._skin[m].pos.copy(e)}if(ye[a].enabled){const he=x[a+"足IK"];const z=ye[a];z.target.copy(he.position);const j=he.pmxBone.IK;z.effector.copy(k.bones[j.effector].quaternion);for(let e=0;e{e.detail.result.links=z;e.detail.result.links_result=ge[a]},{once:true});window.addEventListener("SA_camera_poseNet_process_bones_onended",e=>{const t=be[a];t.parent.copy(MMD_SA.get_bone_rotation_parent(k,a+"足","全ての親"));t.effector.copy(k.bones[j.effector].quaternion);for(let e=0;e{const t=e.detail.model;const i=t.mesh.bones_by_name;let o=u.upper_rotation_offset*Math.PI/180;const n=MMD_SA.TEMP_q.set(0,Math.sin(o/2*-.5),0,Math.cos(o/2*-.5));i["上半身"].quaternion.premultiply(n);i["上半身2"].quaternion.premultiply(n);n.set(0,Math.sin(o/2),0,Math.cos(o/2));i["全ての親"].quaternion.premultiply(n);if(it.active){it.set_boneKey("上半身",null,i["上半身"].quaternion,false);it.set_boneKey("上半身2",null,i["上半身2"].quaternion,false);it.set_boneKey("全ての親",null,i["全ての親"].quaternion,false)}},{once:true})}if(it.active){window.addEventListener("SA_camera_poseNet_process_bones_onended",e=>{const t=e.detail.model;const a=t.mesh.bones_by_name;for(const n of["左","右"]){it.set_boneKey(n+"足",null,a[n+"足"].quaternion,false);it.set_boneKey(n+"ひざ",null,a[n+"ひざ"].quaternion,false);it.set_boneKey(n+"足首",null,a[n+"足首"].quaternion,false);if(a[n+"足先EX"])it.set_boneKey(n+"足先EX",null,a[n+"足先EX"].quaternion,false);for(const e of[n+"肩",n+"腕",n+"ひじ",n+"手首"]){if(a[e])it.set_boneKey(e,null,a[e].quaternion,false)}Qe.forEach((i,e)=>{let o=e==0?0:1;for(let t=o;tthis._z_max_timestamp+1e3?this._z_max||0:0,this._skin[m].pos.z)}window.dispatchEvent(new CustomEvent("SA_camera_poseNet_process_bones_onstart",e));var n=this.skin;var G=Object.keys(n).filter(e=>!n[e][0].after_IK).sort((e,t)=>{let i=n[e][0].priority||0;let o=n[t][0].priority||0;return i-o});G.forEach(e=>{let t=x[e];if(!t&&!/_DUMMY_/.test(e))return;var i=n[e][0].info[1];if((!i||/pose/.test(i))&&!P.motion_tracking_enabled)return;Ae.call(this,k,e)})}function n(e){var t=e.detail.model;var o=t.mesh;var n=MMD_SA.motion[t.skin._motion_index].para_SA;if(n.motion_tracking_upper_body_only){for(const s of["左","右"]){const r=n.motion_tracking?.arm_tracking?.elbow_lock?.[s=="左"?"left":"right"];if(r){const _=r._elbow_y!=null?r._elbow_y:null;if(_!=null)w(r,o,s)}}}var a=this.skin;var i=Object.keys(a).filter(e=>a[e][0].after_IK).sort((e,t)=>{let i=a[e][0].priority||0;let o=a[t][0].priority||0;return i-o});i.forEach(e=>{let t=o.bones_by_name[e];if(!t&&!/_DUMMY_/.test(e))return;var i=a[e][0].info[1];if((!i||/pose/.test(i))&&!n.motion_tracking_enabled)return;Ae.call(this,o,e)});window.dispatchEvent(new CustomEvent("SA_camera_poseNet_process_bones_onended",e))}function a(e){if(!Ce.use_head_mocap)return;var _=e.detail.model;var l=_.mesh;var c=_.morph.targets;_.pmx.morphs.forEach(function(e){if(e.panel!=3)return;var t=e.name;if(!_.pmx.morphs_weight_by_name[t])return;var i=_.morph.target_index_by_name[t];if(i==null)return;var o=c[i];var n=o.keys[0];if(n.morph_type==1){l.morphTargetInfluences[i]=0}else{let e={name:t,weight:0,morph_type:n.morph_type,morph_index:n.morph_index};_.morph.onupdate(e,e,0,i)}});var d=MMD_SA_options.model_para_obj.facemesh_morph;var p=this.morph;var u={};var n=0;Object.keys(p).forEach(function(e){let t=p[e];if(t.disabled)return;t[0].t_delta+=RAF_timestamp_delta;let i=Math.max(Math.min(t[0].t_delta/t[0].t_delta_frame,1),0);let o=t[0].weight*i+t[1].weight*(1-i);u[e]=o;if(o)n++});Object.keys(u).forEach(function(t){let e=p[t];let i=u[t];if(i<0){it.morph_active&&it.set_morphKey(t,0,true);switch(t){case"にやり":t="ω";break;case"口角上げ":t="口角下げ";break;case"上":t="下";break}i=-i}if(it.morph_active){let e=t;if(t=="まばたきL")e="ウィンク";else if(t=="まばたきR")e="ウィンク右";it.set_morphKey(e,i,true)}let o=d[t];let n=o&&o.name||t;let a=_.morph.target_index_by_name[n];if(a==null)return;i*=o&&o.weight||1;let s=c[a];let r=s.keys[0];if(r.morph_type==1){l.morphTargetInfluences[a]=i}else{let e={name:n,weight:i,morph_type:r.morph_type,morph_index:r.morph_index};_.morph.onupdate(e,e,0,a)}})}let u=0;let s=[];function m(e,t,i){function o(){u++}i.name=t;i.info=e.split("|");let n=i.info[0];let a=this[n][t];if(i.is_dummy){if(a&&a[0].is_dummy)return;i.no_blending=true;i.onProcessPosition=i.onProcessRotation=r;if(i.pos)i.pos=_;if(i.rot)i.rot=l}else{if(i.pos){if(isNaN(i.pos.x)||isNaN(i.pos.y)||isNaN(i.pos.z)){o();i.pos.copy(a?.[0].pos||new THREE.Vector3)}}if(i.rot){if(isNaN(i.rot.x)||isNaN(i.rot.y)||isNaN(i.rot.z)||isNaN(i.rot.w)){o();i.rot.copy(a?.[0].rot||new THREE.Quaternion)}}if(i.weight!=null){if(isNaN(i.weight)){o();i.weight=a?.[0].weight||0}}}const s=t.indexOf("指")!=-1||t.indexOf("手首")!=-1;i.timestamp=RAF_timestamp;i.t_delta=0;i.t_delta_frame=Be.enabled&&s&&this.t_delta_hands||this.t_delta||0;i.t_delta_frame=Math.max(Math.min(i.t_delta_frame,200),16.6667);if(it.speed){if(t.indexOf("指")!=-1){i.blending_ratio=.75}else{i.no_blending=true}}if(a){if(RAF_timestamp==a[0].timestamp){a[0]=Object.assign(a[0],i)}else{if(!i.no_blending&&!je.video.paused){let e=i._blending_ratio=i.blending_ratio||(Ce.use_3D_pose||i.info[1]=="facemesh"?.5+Math.max(Math.min((Math.max(i.t_delta_frame,RAF_timestamp-a[0].timestamp)-50)/150,1),0)*.5:1);if(e<1){if(i.pos&&a[0].pos){i.pos.lerp(a[0].pos,1-e)}if(i.rot&&a[0].rot){i.rot.slerp(a[0].rot,1-e)}if(i.weight!=null&&a[0].weight!=null){i.weight=i.weight*e+a[0].weight*(1-e)}}}this[n][t]=[i,a[0]]}i._blend_default_motion=a[1]._blend_default_motion;i._idle_blend_default_motion=a[1]._idle_blend_default_motion}else{this[n][t]=[i,i]}if(it.speed)i.no_blending=true}function h(e,t){delete this[e][t]}function f(){this.skin={};this.morph={};this._skin={};this._morph={};this.reset_to_default_motion_once=true;this._motion_path=""}function Ee(){window.addEventListener("SA_MMD_model"+this.model_num+"_process_morphs",this.process_morphs);window.addEventListener("SA_MMD_model"+this.model_num+"_process_bones_before_IK",this.process_bones);window.addEventListener("SA_MMD_model"+this.model_num+"_process_bones_after_IK",this.process_bones_after_IK)}function ke(){window.removeEventListener("SA_MMD_model"+this.model_num+"_process_morphs",this.process_morphs);window.removeEventListener("SA_MMD_model"+this.model_num+"_process_bones_before_IK",this.process_bones);window.removeEventListener("SA_MMD_model"+this.model_num+"_process_bones_after_IK",this.process_bones_after_IK)}var M=function(e){this.model_num=e;this.reset();this._body_motion_rot=[{},{}];this._rot_body_motion=new THREE.Quaternion;this._rot_body_camera=new THREE.Quaternion;this._rot_body_camera_offset=new THREE.Quaternion;this._rot_head_camera=new THREE.Quaternion;this._rot_head_camera_offset=new THREE.Quaternion;this._rot_body_offset=new THREE.Quaternion;this._rot_camera=new THREE.Quaternion;this._rot_camera_angle=0;this.process_bones=o.bind(this);this.process_bones_after_IK=n.bind(this);this.process_morphs=a.bind(this)};M.prototype.set_upper_body_rotation=function(e,t){if(!je.ML_enabled||this.model_num!=e)return;const i=THREE.MMD.getModels()[this.model_num].mesh.bones_by_name;for(const o of["センター","上半身","上半身2","首","頭"]){if(!i[o])continue;let e=this._body_motion_rot[t][o];if(!e)e=this._body_motion_rot[t][o]=new THREE.Quaternion;e.copy(i[o].quaternion)}};M.prototype.get_upper_body_rotation=function(){const e=THREE.MMD.getModels()[this.model_num].mesh.bones_by_name;this._rot_camera.setFromEuler(MMD_SA.TEMP_v3.set(MMD_SA._rx_last,MMD_SA._ry_last,0));this._rot_camera_angle=this._rot_camera.toAxisAngle()[1];const t=Xe.set(0,0,0,1);const i=Ue.set(0,0,0,1);for(const n of["センター","上半身","上半身2"]){t.multiply(this._body_motion_rot[0][n]||e[n].quaternion);i.multiply(this._body_motion_rot[1][n]||e[n].quaternion)}this._rot_body_camera.copy(t).conjugate().multiply(i);this._rot_body_camera_offset.copy(this._rot_body_camera).conjugate().multiply(this._rot_camera);this._rot_body_motion.copy(t);const o=Ke.copy(t).conjugate();return o};M.prototype.upper_body_rotation_limiter=function(t,i=Math.PI/3){var o=t.toAxisAngle();var n=o[1];this._rot_body_offset.set(0,0,0,1);if(Math.abs(n)>i){let e;if(Math.abs(n){S.prototype._q1=new THREE.Quaternion;S.prototype._q2=new THREE.Quaternion;tt=new S(0)});var it=function(){function _(e,t,i,o){this.name=e;this.pos=t&&t.toArray()||[0,0,0];this.rot=i&&i.toArray()||[0,0,0,1];this.time=o;c[e].index=l.boneKeys.length}function s(e,t,i){this.name=e;this.weight=t;this.time=i;r[e].index=l.morphKeys.length}var l;var c,r;var d=0;var o=0;var p=0;var u=0;var n;var a=0;var i=0;const m=2;return{timestamp_for_recording:0,get enabled(){return i&&!je.video.paused},get morph_active(){return Ce.enabled?this.enabled:this.active},get active(){if(!this.enabled)return false;if(this.timestamp_for_recording&&this.timestamp_for_recording!=RAF_timestamp)return false;if(n!=P){let e=1;if(n){e=this.get_frame(P)-this.get_frame(n);if(e<0||e>30)e=1;if(e>1){const t=e-1;o+=t;for(const i in c){c[i].frame_length+=t}for(const i in r){r[i].frame_length+=t}}}d+=e;n=P;a=RAF_timestamp}if(a==RAF_timestamp){return true}return false},get_frame:function(e){var t=e.split(":");return parseInt(t[0])*30+(parseInt(t[1])-1)},get frame_count(){return d},get stats(){return[o,l.boneKeys.length,l.morphKeys.length,p,u]},get time(){return Math.floor(d/30)+":"+(d%30+1)},get speed(){return i},set speed(e){i=e;if(e){this.start(e);MMD_SA.playbackRate=e}else{this.stop();MMD_SA.playbackRate=1}},get vmd(){return i?null:l},set vmd(e){l=null},set_boneKey:function(e,t,i,o){if(e.indexOf("腕IK")!=-1)return;let n=c[e];if(n==null){n=c[e]={frame_length:1};if(d>0)l.boneKeys.push(new _(e,null,null,0))}if(o&&tt.skin[e]&&n.timestamp==tt.skin[e][0].timestamp){let e;if(n.frame_count==d){const a=l.boneKeys[n.index];e=(!t||a.pos)&&(!i||a.rot)}else e=true;if(e){if(n.frame_count!=d){n.frame_length++;p++}return}}if(!t&&i&&n.is_rot_identity&&i.w==1){p++;return}n.is_rot_identity=i?i.w==1:n.is_rot_identity;if(n.frame_count==d){const a=l.boneKeys[n.index];if(t)a.pos=t.toArray();if(i)a.rot=i.toArray()}else{if(n.index!=null&&e.indexOf("手")==-1&&e.indexOf("指")==-1){const a=l.boneKeys[n.index];const s=Math.round(d-a.time*30);if(s>n.frame_length||s>10){const r=new _(e,null,null,(d-1)/30);r.pos=a.pos;r.rot=a.rot;l.boneKeys.push(r);p--}}n.timestamp=tt.skin[e]&&tt.skin[e][0].timestamp||0;l.boneKeys.push(new _(e,t,i,d/30))}n.frame_length=1;n.frame_count=d;return true},set_morphKey:(()=>{function o(e,t,i){let o=r[e];if(o==null){o=r[e]={frame_length:1};if(d>0)l.morphKeys.push(new s(e,0,0))}if(i&&tt.morph[e]&&o.timestamp==tt.morph[e][0].timestamp){if(o.frame_count!=d){o.frame_length++;u++}return}t=Math.round(t*20)/20;if(t==o.weight){u++;return}o.weight=t;if(o.frame_count==d){const n=l.morphKeys[o.index];n.weight=t}else{if(o.index!=null){const n=l.morphKeys[o.index];const a=Math.round(d-n.time*30);if(ao.frame_length||a>10){l.morphKeys.push(new s(e,n.weight,(d-m)/30));u--}}o.timestamp=tt.morph[e]&&tt.morph[e][0].timestamp||0;l.morphKeys.push(new s(e,t,d/30))}o.frame_length=1;o.frame_count=d;return true}return function(e,t,i){if(Ce.enabled){window.addEventListener("SA_motion_recorder_on_active",()=>{o.call(this,e,t,i)},{once:true})}}})(),start:function(e){i=e;if(MMD_SA.THREEX.get_model(0).use_faceBlendshapes){MMD_SA.THREEX.get_model(0)._disable_faceBlendshapes=true;for(const t of Fe.faceBlendshapes_list){tt.remove("morph",t)}}n="";a=0;if(je.is_local_video){je.video.playbackRate=e;if(e<1)je.video.muted=true;je.video.loop=false;je.video.pause();MMD_SA.SpeechBubble.message(0,System._browser.translation.get("XR_Animator.UI.motion_capture.ML_on.record_motion.choose_speed.begin_recording"),5*1e3);C_media_control.style.visibility="inherit"}d=-1;o=0;p=0;u=0;c={};r={};l={boneKeys:[],morphKeys:[]}},stop:function(){i=0;MMD_SA.THREEX.get_model(0)._disable_faceBlendshapes=false;if(je.is_local_video){je.video.playbackRate=1;je.video.muted=false;je.video.loop=true;je.video.pause();MMD_SA.SpeechBubble.message(0,System._browser.translation.get("XR_Animator.UI.motion_capture.ML_on.record_motion.choose_speed.begin_recording.recording_stopped"),5*1e3)}else if(je.is_local_photo){l.boneKeys=l.boneKeys.filter(e=>e.time==0);l.morphKeys=l.morphKeys.filter(e=>e.time==0);l.boneKeys=l.boneKeys.concat(l.boneKeys.map(e=>{const t={name:e.name,pos:e.pos.slice(),rot:e.rot.slice(),time:60};return t}));l.morphKeys=l.morphKeys.concat(l.morphKeys.map(e=>{const t={name:e.name,weight:e.weight,time:60};return t}))}}}}();const E=(()=>{function r(){p=p.slice(Math.max(p.length-8,0),p.length);MMD_SA_options.Dungeon.run_event([[{message:{content:p.join("\n")+"\n("+System._browser.translation.get("XR_Animator.UI.streamer_mode.press_x_to_abort")+")",para:h,branch_list:[{key:"X",is_closing_event:true,event_id:{func:()=>{m=true;if(u)u()},ended:true}}]}}]])}function _(){if(--i==0){p.push("✅"+System._browser.translation.get("XR_Animator.UI.streamer_mode.mocap_model_loaded"));if(u)u()}}function l(e){if(!Fe.calibrated){i++;window.addEventListener("SA_camera_facemesh_calibrating",c);p.push("✅"+System._browser.translation.get("XR_Animator.UI.streamer_mode.face_data_calibrating")+"...");r()}_(e)}function c(e){const t=e.detail.percent;if(t>=100){window.removeEventListener("SA_camera_facemesh_calibrating",c);MMD_SA.SpeechBubble.list[1].message(0,"("+System._browser.translation.get("XR_Animator.UI.streamer_mode.calibrating_face_data")+" - 100%)",0,h);p.push("✅"+System._browser.translation.get("XR_Animator.UI.streamer_mode.face_data_calibrated"));_()}else{MMD_SA.SpeechBubble.list[1].message(0,"("+System._browser.translation.get("XR_Animator.UI.streamer_mode.calibrating_face_data")+" - "+t+"%)\n"+System._browser.translation.get("XR_Animator.UI.streamer_mode.face_data_calibrating_message"),0,h)}}let d;let p=[];let i;let u;let m;const h={font_scale:1,font:'"Segoe UI",Roboto,Ubuntu,"SF Pro"'};const e={get running(){return d},init_mocap:function(e){function t(){if(d){if(MMD_SA_options.user_camera.streamer_mode.motion_id!=null){const e=typeof MMD_SA_options.user_camera.streamer_mode.motion_id=="number"?MMD_SA_options.user_camera.streamer_mode.motion_id+(System._browser.camera.facemesh.enabled&&!System._browser.camera.poseNet.enabled?1:0):MMD_SA_options._XRA_pose_list?.[2].findIndex(e=>e.name==MMD_SA_options.user_camera.streamer_mode.motion_id);if(typeof e=="number"&&e>=0)MMD_SA_options.Dungeon_options.item_base.pose?._change_motion_(e,true);return new Promise(t=>{window.addEventListener("SA_MMD_model0_onmotionchange",e=>{p.push("✅"+System._browser.translation.get("XR_Animator.UI.streamer_mode.motion_changed")+" ("+e.detail.motion_new.filename+")");t()},{once:true})})}}if(MMD_SA.WebXR.user_camera.poseNet.enabled){if(!MMD_SA.MMD.motionManager.para_SA.motion_tracking_enabled)MMD_SA_options.Dungeon_options.item_base.pose?._change_motion_(0,true)}}switch(e){case"Face":MMD_SA.WebXR.user_camera.poseNet.use_holistic=false;MMD_SA.WebXR.user_camera.facemesh.enabled=true;MMD_SA.WebXR.user_camera.poseNet.enabled=false;MMD_SA.WebXR.user_camera.handpose.enabled=false;DEBUG_show("Facemesh AI:ON",2);i=1;break;case"Body":MMD_SA.WebXR.user_camera.poseNet.use_holistic=false;MMD_SA.WebXR.user_camera.poseNet.enabled=true;MMD_SA.WebXR.user_camera.handpose.enabled=false;MMD_SA.WebXR.user_camera.facemesh.enabled=false;DEBUG_show("Pose AI:ON",3);i=1;break;case"Body+Hands":MMD_SA.WebXR.user_camera.poseNet.use_holistic=false;MMD_SA.WebXR.user_camera.poseNet.enabled=true;MMD_SA.WebXR.user_camera.handpose.enabled=true;MMD_SA.WebXR.user_camera.facemesh.enabled=false;DEBUG_show("Pose/Hands AI:ON",3);i=1;break;case"Face+Body":MMD_SA.WebXR.user_camera.poseNet.use_holistic=false;MMD_SA.WebXR.user_camera.facemesh.enabled=true;MMD_SA.WebXR.user_camera.poseNet.enabled=true;MMD_SA.WebXR.user_camera.handpose.enabled=false;DEBUG_show("Facemesh/Pose AI:ON",3);i=2;break;case"Full Body":MMD_SA.WebXR.user_camera.poseNet.use_holistic=false;MMD_SA.WebXR.user_camera.facemesh.enabled=true;MMD_SA.WebXR.user_camera.poseNet.enabled=true;MMD_SA.WebXR.user_camera.handpose.enabled=true;DEBUG_show("Facemesh/Pose/Hands AI:ON",4);i=2;break;case"Full Body Holistic":MMD_SA.WebXR.user_camera.poseNet.use_holistic=true;MMD_SA.WebXR.user_camera.poseNet.use_holistic_legacy=true;MMD_SA.WebXR.user_camera.facemesh.enabled=true;MMD_SA.WebXR.user_camera.poseNet.enabled=true;MMD_SA.WebXR.user_camera.handpose.enabled=true;DEBUG_show("Facemesh/Pose/Hands AI:ON",4);i=2;break;default:return}MMD_SA_options.user_camera.streamer_mode.mocap_type=e;return t()},start:async function(){function e(){p.length=0;u=null;m=false;d=false}function t(){e();MMD_SA_options.Dungeon.event_mode=false}if(MMD_SA.WebXR.user_camera.bodyPix.enabled){DEBUG_show("(You can't enable motion capture and Selfie Segmentation AI at the same time.)",5);return}if(d){DEBUG_show("(Streamer mode running)");return}e();d=true;MMD_SA_options.Dungeon.event_mode=true;const i=je.stream&&MMD_SA_options.user_camera.streamer_mode.camera_preference.label;MMD_SA.WebXR.user_camera.video_flipped=!!MMD_SA_options.user_camera.streamer_mode.camera_preference.video_flipped;const o=await je.start();if(!o){MMD_SA.SpeechBubble.message(0,System._browser.translation.get("XR_Animator.UI.streamer_mode.webcam_not_accessible"),5*1e3);t();return}if(i!=MMD_SA_options.user_camera.streamer_mode.camera_preference.label)p.push("✅"+System._browser.translation.get("XR_Animator.UI.streamer_mode.webcam_on")+" ("+MMD_SA_options.user_camera.streamer_mode.camera_preference.label+")");let n;if(webkit_electron_mode&&MMD_SA.THREEX.enabled){n=!!MMD_SA_options.user_camera.streamer_mode.VMC_sender_enabled;if(n){if(!MMD_SA.OSC.VMC.sender_enabled){MMD_SA_options.user_camera.streamer_mode.VMC_sender_enabled=MMD_SA.OSC.VMC.sender_enabled=true;p.push("✅"+System._browser.translation.get("XR_Animator.UI.streamer_mode.VMC_protocol_on"));MMD_SA.OSC.VMC.send_camera_data=!!MMD_SA_options.user_camera.streamer_mode.VMC_send_camera_data;if(MMD_SA.OSC.VMC.send_camera_data)p.push("✅- "+System._browser.translation.get("XR_Animator.UI.streamer_mode.VMC_protocol_on.send_camera_data"));System._browser.update_tray()}}}if(!je.ML_enabled){const a=MMD_SA_options.user_camera.streamer_mode.mocap_type||(is_mobile?System._browser.translation.get("XR_Animator.UI.streamer_mode.mocap_initializing.face","en"):System._browser.translation.get("XR_Animator.UI.streamer_mode.mocap_initializing.full_body","en"));const s=MMD_SA_options.user_camera.streamer_mode.mocap_type||(is_mobile?System._browser.translation.get("XR_Animator.UI.streamer_mode.mocap_initializing.face"):System._browser.translation.get("XR_Animator.UI.streamer_mode.mocap_initializing.full_body"));p.push("✅"+System._browser.translation.get("XR_Animator.UI.streamer_mode.mocap_initializing")+" ("+s+")...");r();await new Promise(e=>{u=e;if(/Face|Full Body/.test(a))window.addEventListener("SA_camera_facemesh_update",l,{once:true});if(/Body/.test(a))window.addEventListener("SA_camera_poseNet_update",_,{once:true});const t=E.init_mocap(a);if(t)t.then(r)})}if(m){window.removeEventListener("SA_camera_poseNet_update",_);window.removeEventListener("SA_camera_facemesh_update",l);window.removeEventListener("SA_camera_facemesh_calibrating",c);MMD_SA.SpeechBubble.list.forEach(e=>{e.hide()});t();return}u=null;MMD_SA.SpeechBubble.hide();if(n){if(p.length){await new Promise(e=>{MMD_SA_options.Dungeon.run_event([[{message:{content:System._browser.translation.get("XR_Animator.UI.streamer_mode.finish_VMC"),para:h,index:1,branch_list:[{key:1,event_id:{func:()=>{MMD_SA.hide_3D_avatar=true;System._browser.update_tray();e()},ended:true}},{key:"X",is_closing_event:true,event_id:{func:()=>{e()},ended:true}}]}}]])})}}else{if(p.length){await new Promise(e=>{MMD_SA_options.Dungeon.run_event([[{message:{content:System._browser.translation.get("XR_Animator.UI.streamer_mode.finish"),para:h,index:1,branch_list:[{key:1,event_id:{func:()=>{System._browser.overlay_mode=1;e()},ended:true}},{key:"X",is_closing_event:true,event_id:{func:()=>{e()},ended:true}}]}}]])})}}if(!p.length)MMD_SA.SpeechBubble.message(0,"XR Animator is ready!",3e3);if(je.initialized&&je.visible)je.hide();t()}};return e})();var wt=[{},{}];var x=t.get("camera_hidden");var j;je={initialized:false,get ML_enabled(){return M},get ML_busy(){return Fe.busy||Ce.busy},get ML_fps(){return 1e3/(Ce.enabled&&Ce._t||Fe.enabled&&Fe._t||1e3)},get ML_warmed_up(){var e=wt[Ce.use_holistic?1:0];var t=!Fe.enabled||e.facemesh;var i=!Ce.enabled||e.poseNet;var o=!Be.enabled||e.handpose;return t&&i&&o},get target_devicePixelRatio(){return u||window.devicePixelRatio},set target_devicePixelRatio(e){u=e==window.devicePixelRatio?0:e},get double_flip_mode(){return i&&!je.mirror_3D},set double_flip_mode(e){i=e},get video_flipped(){return!M?_:!!_^!!je.double_flip_mode},set video_flipped(e){_=e;this.reset_video_canvas()},get display_flipped(){return je.mirror_3D?false:_!=je.video_flipped},get mirror_3D(){return!M||!MMD_SA_options.user_camera.mirror_3D?false:MMD_SA_options.user_camera.mirror_3D==1?je.visible:true},get x_flipped(){return je.double_flip_mode||je.mirror_3D},get hidden_enforced(){return x||(MMD_SA_options.user_camera.display.video.hidden==null?!!this.stream:MMD_SA_options.user_camera.display.video.hidden)||System._browser.overlay_mode>0||this.stream&&MMD_SA_options.user_camera.display.video.hidden_on_webcam},get display_floating(){return MMD_SA_options.user_camera.display.floating||j},set display_floating(e){j=e;if(this.video_host)this.video_host.style.zIndex=this.display_floating?2:0},get video_timestamp(){return je.video.currentTime==null?performance.now()/2:je.video.currentTime*1e3},get video_frame_id(){const e=this.video_timestamp/1e3;const t=Math.floor(e);return t+":"+Math.floor((e-t)*30+1)},get is_local_media(){return this.local_src&&!this.stream},get is_local_video(){return this.is_local_media&&this.video.currentTime!=null},get is_local_photo(){return this.is_local_media&&this.video.currentTime==null},get media_control_enabled(){return h},set media_control_enabled(e){if(h==!!e)return;h=!!e;this.video.removeEventListener("timeupdate",f,true);if(h){MMD_SA.motion_player_control.enabled=false;this.video.addEventListener("timeupdate",f,true);SL_MC_simple_mode=true;SL_MC_video_obj=je.video;SL_MC_Place(1,0,-64)}else{SL_MC_Place(-1);if(!MMD_SA.motion_player_control.enabled&&MMD_SA_options._XRA_pose_list?.[0].find(e=>e.is_custom_motion&&e.name==MMD_SA.MMD.motionManager.filename)!=null){MMD_SA.motion_player_control.enabled=true}}},DEBUG_show:(()=>{let o="";let n="";let a=0;let s=[];window.addEventListener("MMDStarted",()=>{System._browser.on_animation_update.add(()=>{s=s.filter(e=>RAF_timestampe.msg).join("\n")+"\n":"";Oe=n+o},0,0,-1)});return function(e,t,i){if(!je.ML_enabled||!Ce.data_detected&&!Fe.data_detected||je.video?.paused){DEBUG_show(e,t,i);return}if(t){s.push({msg:e,duration:t*1e3,timestamp:RAF_timestamp});return}if(a!=RAF_timestamp){a=RAF_timestamp;o=""}o=(o?o+"\n":o)+e;Oe=n+o}})(),motion_recorder:it,tilt_adjustment:{enabled:false,angle:0,pose_weight:.5},camera_list:null,deviceId:null,start:async function(i){async function n(){try{stream=await navigator.mediaDevices.getUserMedia(a);return stream}catch(e){console.error(e)}}var e=MMD_SA_options.WebXR&&MMD_SA_options.WebXR.AR;this._update_camera_reset();if(this.initialized&&!E.running){if(this.visible){this.hide();DEBUG_show("User camera:HIDDEN",2);return}}var a={video:this.set_constraints()};try{if(i){this.init_stream(i)}else{if(is_mobile){a.video.facingMode="user"}if(MMD_SA_options.Dungeon){MMD_SA_options.Dungeon.run_event([[{message:{get content(){return System._browser.translation.get("XR_Animator.UI.webcam_media.finding_camera")}}},{goto_branch:0}]])}let t;if(is_mobile){if(!this.stream)t=await n();if(MMD_SA_options.Dungeon)MMD_SA_options.Dungeon.run_event(null,0,2);if(!this.stream&&!t){DEBUG_show("(Camera not accessible)",3);return}}else{let o=this.camera_list;if(!o){try{o=await navigator.mediaDevices.enumerateDevices();o=o.filter(e=>e.kind=="videoinput");const r=MMD_SA_options.user_camera.streamer_mode.camera_preference&&{label:{test:e=>e.indexOf(MMD_SA_options.user_camera.streamer_mode.camera_preference.label)!=-1}}||MMD_SA_options.user_camera.preference;o.sort((e,t)=>r?.label?.test(e.label)&&-1||r?.label?.test(t.label)&&1||/warudo/i.test(e.label)&&1||/warudo/i.test(t.label)&&-1||0);this.camera_list=o=o.slice(0,7);if(E.running&&!o.length)throw new Error("(No camera detected)")}catch(s){console.error(s);if(MMD_SA_options.Dungeon)MMD_SA_options.Dungeon.run_event(null,0,2);DEBUG_show("(No camera detected)",3);return}}let e;if(MMD_SA_options.Dungeon){await new Promise(t=>{MMD_SA_options.Dungeon.run_event([[{message:{get content(){return(o.length?System._browser.translation.get("XR_Animator.UI.webcam_media.choose_an_input")+o.map((e,t)=>"\n"+(t+1)+". "+e.label.substring(0,25)).join(""):System._browser.translation.get("XR_Animator.UI.webcam_media.no_camera"))+"\n"+(o.length+1)+". "+System._browser.translation.get("XR_Animator.UI.webcam_media.local_media_file")+"\n"+(o.length+2)+". "+System._browser.translation.get("Misc.cancel")},para:{row_max:11,no_word_break:true},bubble_index:3,branch_list:o.map((e,t)=>{return{key:t+1,branch_index:t+1}}).concat([{key:Math.min(o.length+1,8),branch_index:Math.min(o.length+1,8)},{key:Math.min(o.length+2,9),is_closing_event:true,branch_index:Math.min(o.length+2,9)}])}}]].concat(o.map(e=>[{func:()=>{const i=e.label;MMD_SA_options.user_camera.streamer_mode.camera_preference=Object.assign(MMD_SA_options.user_camera.streamer_mode.camera_preference||{},{label:i,video_flipped:!!_});o.sort((e,t)=>e.label==i&&-1||t.label==i&&1||0);a.video.deviceId=e.deviceId;t()},ended:true}]).concat([[{func:()=>{if(je.local_src){i=je.local_src;t();return true}else{DEBUG_show("(No local media file found)",3);MMD_SA_options.Dungeon.run_event(null,0,0)}}}],[{func:()=>{e=true;t()},ended:true}]])));if(E.running&&MMD_SA_options.user_camera.streamer_mode.camera_preference?.label){MMD_SA_options.Dungeon.run_event(null,1,0)}})}if(e){DEBUG_show("(Canceled)",2);return}if(!i&&a.video.deviceId!=this.deviceId){t=await n();if(!t){DEBUG_show("(Camera not accessible)",3);return}}}if(i){je.init_stream(i)}else if(t){je.init_stream(t);this.deviceId=a.video.deviceId}if(e&&e.dom_overlay)e.dom_overlay.use_dummy_webgl=true;DEBUG_show("(User camera:ON)",2)}if(!this.visible){this.show();DEBUG_show("User camera:VISIBLE",2)}return E.running}catch(s){if(MMD_SA_options.Dungeon&&MMD_SA_options.Dungeon.event_mode)MMD_SA_options.Dungeon.run_event({ended:true});je.init_stream();console.error(s);DEBUG_show("(ERROR: Camera unavailable, using fallback video instead)",3)}},_update_camera_reset:function(){MMD_SA.reset_camera();this._camera_reset=MMD_SA._trackball_camera.object.clone();this._camera_reset.children.length=0;this._camera_reset.quaternion.set(0,0,0,1);this._camera_reset.updateMatrixWorld();Ce.frames._z_max=Ce.frames._z_max_timestamp=0},init_stream:function(e){if(!this.initialized){this.video=this._video=document.createElement("video");this.video.autoplay=true;let e;this.video_host=document.createElement("div");e=this.video_host.style;e.position="absolute";e.left="0px";e.top="0px";e.zIndex=this.display_floating?2:0;e.visibility=System._browser.overlay_mode?"hidden":"inherit";e.display=System._browser.overlay_mode?"none":"block";SL_Host.appendChild(this.video_host);this.video_canvas=document.createElement("canvas");e=this.video_canvas.style;e.position="absolute";e.left="0px";e.top="0px";e.zIndex=0;e.visibility="hidden";this.video_host.appendChild(this.video_canvas);this.video_canvas_bodyPix=document.createElement("canvas");e=this.video_canvas_bodyPix.style;e.position="absolute";e.left="0px";e.top="0px";e.zIndex=0;e.visibility="hidden";this.video_host.appendChild(this.video_canvas_bodyPix);this.video_canvas_face_detection=document.createElement("canvas");e=this.video_canvas_face_detection.style;e.position="absolute";e.left="0px";e.top="0px";e.zIndex=0;e.visibility="hidden";this.video_host.appendChild(this.video_canvas_face_detection);this.video_canvas_facemesh=document.createElement("canvas");e=this.video_canvas_facemesh.style;e.position="absolute";e.left="0px";e.top="0px";e.zIndex=0;e.visibility="hidden";this.video_host.appendChild(this.video_canvas_facemesh);is_mobile&&window.addEventListener("resize",function(){je.video_track?.applyConstraints(je.set_constraints()).then(function(){DEBUG_show("(camera size updated)",2)})["catch"](function(e){DEBUG_show("ERROR:camera size failed to update")})});navigator.mediaDevices.addEventListener("devicechange",()=>{console.log("mediaDevices: new device detected");this.camera_list=null})}this.initialized=true;if(this.stream){this.stream.getTracks().forEach(e=>{e.stop()});this.video.srcObject=this.stream=this.video_track=this.deviceId=null;console.log("(Previous stream stopped)")}if(!e||typeof e=="string"){m(e)}else{this.stream=e;this.video_id=e.id;this.video_track=e.getVideoTracks()[0];this.video=this._video;this.video.srcObject=e;console.log("(New stream started)");setTimeout(function(){let e=je.video_track.getCapabilities?.();if(!e)return;System._browser.console.log(Object.entries(e).map(e=>e[0]+":"+JSON.stringify(e[1])).join("\n"));let t=je.video_track.getSettings();const i=Object.entries(t).map(e=>e[0]+":"+JSON.stringify(e[1])).join("\n");console.log("MediaTrackCapabilities",i);if(is_mobile)System._browser.console.log()},2e3)}this.show();if(Fe.enabled)Fe.reset_calibration()},get use_armIK(){return Ce.enabled||Be.enabled||Fe.enabled},bodyPix:function(){var o;var i=false;d={get enabled(){return i},set enabled(e){if(i==!!e)return;i=!!e;const t=MMD_SA.THREEX.SL;if(i){MMD_SA._renderer.devicePixelRatio=1;MMD_SA._renderer.__resize(EV_width,EV_height);t.style.visibility="hidden"}else{MMD_SA._renderer.devicePixelRatio=window.devicePixelRatio;MMD_SA._renderer.__resize(EV_width,EV_height);t.style.visibility="inherit";je.video_canvas_bodyPix.style.visibility="hidden"}},busy:0,mask:null,allPoses:null,use_bodySegmentation:true,load:async function(e){this.enabled=true;if(o)return;if(!this.mask){this.mask=document.createElement("canvas");c.load_face_cover()}if(this.use_bodySegmentation){const t=bodySegmentation.SupportedModels.MediaPipeSelfieSegmentation;const i={runtime:"mediapipe",solutionPath:"https://cdn.jsdelivr.net/npm/@mediapipe/selfie_segmentation"};o=await bodySegmentation.createSegmenter(t,i)}else{o=await bodyPix.load(e||(1||is_mobile)?{architecture:"MobileNetV1",outputStride:16,multiplier:.5,quantBytes:2}:{architecture:"ResNet50",outputStride:32,quantBytes:2})}console.log("bodyPix loaded")},segmentPerson:async function(e,t){await this.load();if(this.use_bodySegmentation){return await o.segmentPeople(e)}else{return await o.segmentPerson(e,t||{flipHorizontal:false,internalResolution:"medium",segmentationThreshold:.7})}},toMask:async function(e,t,i){const o=await this.segmentPerson(e,t);i=i||{foregroundColor:{r:0,g:0,b:0,a:255},backgroundColor:{r:0,g:0,b:0,a:0}};if(this.use_bodySegmentation){return await bodySegmentation.toBinaryMask(o,i.foregroundColor,i.backgroundColor)}else{this.allPoses=o.allPoses;return bodyPix.toMask(o,i.foregroundColor,i.backgroundColor)}},update_frame:async function(e=je.video_canvas,t,i,o){const n=MMD_SA.THREEX.SL;if(System._browser.snapshot.check_bodyPix()){je.video_canvas.style.visibility="inherit";je.video_canvas_bodyPix.style.visibility="hidden";n.style.visibility="inherit";return}if(this.busy)return;this.busy=RAF_timestamp;const a=await this.toMask(e,t,i);this.busy=0;if(!this.enabled)return;if(this.mask.width!=a.width||this.mask.height!=a.height){this.mask.width=a.width;this.mask.height=a.height}this.mask.getContext("2d").putImageData(a,0,0);const s=n.width;const r=n.height;if(je.video_canvas_bodyPix.width!=s||je.video_canvas_bodyPix.height!=r){je.video_canvas_bodyPix.width=s;je.video_canvas_bodyPix.height=r}const _=s/r/(e.width/e.height);const l=Math.round(s*Math.min(1/_,1));const c=Math.round(r*Math.min(_,1));const d=(s-l)/2;const p=(r-c)/2;const u=je.video_canvas_bodyPix.getContext("2d");u.globalCompositeOperation="copy";u.filter="blur("+Math.ceil(3/window.devicePixelRatio)+"px)";u.drawImage(this.mask,0,0,a.width,a.height,d,p,l,c);u.globalCompositeOperation="source-out";u.filter="none";u.save();if(je.mirror_3D){u.translate(s,0);u.scale(-1,1)}u.drawImage(n,0,0);u.restore();u.globalCompositeOperation="destination-over";u.drawImage(e,0,0,e.width,e.height,d,p,l,c);je.video_canvas_bodyPix.style.visibility="inherit";n.style.visibility="hidden";this.update_frame_for_face_detection();System._browser.snapshot.check_bodyPix()},update_frame_for_face_detection:function(){let e=c.face_cover;if(!c.enabled||!e.complete)return;je.video_canvas_face_detection.style.visibility="hidden";let t=e.width;let s=e.height;let r=[];this.allPoses.forEach(function(e){let t=e.keypoints;let i=t.find(e=>e.part=="nose");if(!i)return;let o=t.find(e=>e.part=="leftEye");let n=t.find(e=>e.part=="rightEye");let a;if(o&&n){let e=o.position.x-n.position.x;let t=o.position.y-n.position.y;a=Math.sqrt(e*e+t*t)*4}else{a=s}r.push([i.position.y,i.position.x,Math.max(a,s/2),100])});this.allPoses=undefined;c.update_frame_local(je.video_canvas_bodyPix,r)}};return d}(),face_detection:function(){var t=false;function i(){c.initialized=true;if(!self.OffscreenCanvas)c.load_face_cover();r=new Worker("js/pico.worker.js");r.onmessage=function(e){var t=typeof e.data=="string"&&e.data.charAt(0)==="{"?JSON.parse(e.data):e.data;if(typeof t==="string"){DEBUG_show(t,2);c.worker_initialized=true}else{je._needs_RAF=true;if(t._t)DEBUG_show(t._t);c.dets=t.dets;c.busy=0;je.video_canvas_face_detection.style.left=je.video_canvas.style.left;je.video_canvas_face_detection.style.top=je.video_canvas.style.top;if(!self.OffscreenCanvas){System._browser.on_animation_update.add(function(){c.update_frame_local(null,c.dets)},0,0)}}c.update_frame()}}c={initialized:false,worker_initialized:false,get enabled(){return t},set enabled(e){if(t==!!e)return;t=!!e;if(t){this.dets=null;if(!this.initialized)i()}else{if(je.initialized)je.video_canvas_face_detection.style.visibility="hidden"}},load_face_cover:function(){if(!this.face_cover){this.face_cover=new Image;this.face_cover.src="images/laughing_man_134x120.png"}},dets:null,camera_video_timestamp:0,update_frame:function(e){function t(){var e=c.enabled&&c.worker_initialized&&k&&!c.busy&&R&&c.camera_video_timestamp!=k;if(!e)return;c.busy=RAF_timestamp;c.camera_video_timestamp=k;c.camera_video_frame_id=P;je.video_canvas_face_detection.style.visibility="inherit";let t,i,o;t=je.video_canvas;i=t.width;o=t.height;let n=t.getContext("2d").getImageData(0,0,i,o).data.buffer;let a=je.video_canvas_face_detection.style;if(a.width!=t.style.width||a.height!=t.style.height){a.width=t.style.width;a.height=t.style.height}let s={rgba:n,w:i,h:o};if(!je.video_canvas_face_detection._offscreen&&self.OffscreenCanvas){s.canvas=je.video_canvas_face_detection.transferControlToOffscreen();je.video_canvas_face_detection._offscreen=true;console.log("(Face detection: use offscreen canvas)")}r.postMessage(s,s.canvas?[s.canvas,s.rgba]:[s.rgba]);s.rgba=n=undefined;s=undefined}if(e||self.PoseAT){setTimeout(()=>{t()},0)}else{t()}},update_frame_local:function(e,i){let t=je.video_canvas.width;let o=je.video_canvas.height;let n;if(!e){e=je.video_canvas_face_detection;if(e.width!=t||e.height!=o){e.width=t;e.height=o}n=e.getContext("2d");n.clearRect(0,0,t,o)}else{n=e.getContext("2d")}n.globalCompositeOperation="source-over";let a=this.face_cover;let s=a.width;let r=a.height;let _,l,c,d;if(i.length){let t=1;i.forEach(function(e){_=e[2]*t;l=_*s/r;c=e[1]*t-l/2;d=e[0]*t-_/2;n.drawImage(a,0,0,s,r,c,d,l,_)})}else{_=Math.min(t,o);l=_*s/r;c=(t-l)/2;d=(o-_)/2;n.drawImage(a,0,0,s,r,c,d,l,_)}}};return c}(),streamer_mode:E,facemesh:function(){var i=false;var ye=0;var ge=0;var be=true;var ve=0;var we=[];var Se;var Ae;var y;var De=[];var Ee=[];var ke;var b=false;var xe;var g=-1;var t;function o(e){if(!e&&t&&t==je.video_id)return;t=je.video_id;ye=0;ge=0;be=true;ve=0;we=[];Se={};Ae={L:[],R:[]};y=0;De=[];Fe.face_width_average=0;Ee=[];var o={L:[159,145],R:[386,374]};["L","R"].forEach(function(t){for(var i=0;i<1;i++){let e=Ae[t][i]={};e.index=i;e._eye_open_average=0;e.eye_open_average=0;e.eye_open_lower=999;e.eye_open_data=[];e.height_ref_pts=o[t]}Se[t]={_height_average:0,height_average:0,height_data:[],height_ref_pts:t=="R"?[334,330]:[105,101]}});xe={sad:0,angry:0,surprise:0,blush:0,tongue_out:0}}var n;var Ie=[];var Pe,ze,v;Pe=!is_mobile;v=!is_chrome||is_mobile;var x;function w(){if(Fe.initialized)return;Fe.initialized=true;for(var e=0;e<4;e++)Ie[e]=new THREE.Vector3;var o=[];if(System._browser.use_WASM_SIMD){o.push("simd=1")}if(Q){Pe=true}if(v){Pe=true;o.push("use_mediapipe_facemesh=1")}if(Pe){Pe=true;if(Fe.blink_detection==null)Fe.blink_detection=true;o.push("use_face_landmarks=1")}if(ze){o.push("use_human_facemesh=1")}var t;if(MMD_SA_options.user_camera.ML_models.facemesh.worker_disabled){t=new Promise((e,t)=>{Le={postMessage:function(e,t){FacemeshAT.onmessage({data:e})}};let i=document.createElement("script");i.onload=async function(){await FacemeshAT.init(Le,o);e()};i.src="js/facemesh_lib.js";document.head.appendChild(i)})}else{Le=new Worker("js/facemesh_worker.js"+(o.length?"?"+o.join("&"):""))}Le.onmessage=A;if(!Fe.draw_canvas){fetch("js/facemesh_triangulation.json").then(e=>e.json()).then(e=>{x=e});System._browser.on_animation_update.add(()=>{Re.draw()},0,1,-1);console.log("(Facemesh: drawing wireframe in main thread)")}return t}const Re=(()=>{var v;var w;var S;function e(e,t,i,o){function n(e,t){return Math.sqrt(Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2))}const a=Math.round(t/2);const s=Math.round(i/2);if(D.width!=a||D.height!=s){D.width=a;D.height=s}E.globalAlpha=.5;E.save();if(v){E.translate(D.width,0);E.scale(-1,1)}E.clearRect(0,0,a,s);E.fillStyle="black";E.fillRect(0,0,a,s);if(!x||!e.length){S=false;E.restore();return}S=true;const r=e[0].bb;if(w){E.globalAlpha=1;E.drawImage(w,r.x/2,r.y/2,r.w/2,r.h/2)}E.fillStyle="#32EEDB";E.strokeStyle="#32EEDB";E.lineWidth=.5;const _=e[0].scaledMesh;for(let e=0,t=x.length/3;e_[e]);A(E,l,true)}if(w&&Pe){const c=E;const d=468;const p=5;const u="#FF2C35";c.strokeStyle=u;c.lineWidth=1;const m=_[d];const h=n(_[d+4],_[d+2]);const f=n(_[d+3],_[d+1]);c.beginPath();c.ellipse(m[0]/2,m[1]/2,f/2/2,h/2/2,0,0,2*Math.PI);c.stroke();if(_.length>d+p){const M=_[d+p];const y=n(_[d+p+2],_[d+p+4]);const g=n(_[d+p+3],_[d+p+1]);c.beginPath();c.ellipse(M[0]/2,M[1]/2,g/2/2,y/2/2,0,0,2*Math.PI);c.stroke()}}else{k.forEach(function(e){if(!e)return;var t=e[0]/2;var i=e[1]/2;E.beginPath();E.arc(t,i,1,0,2*Math.PI,false);E.lineWidth=3;E.strokeStyle="red";E.stroke()})}if(r.wn[e]);const i=new Path2D;i.moveTo(t[0][0]/a,t[0][1]/a);for(let e=1;e500)a=undefined}_();t=n=null}}}})();const e=["_neutral","BrowInnerUp","BrowDownLeft","BrowDownRight","BrowOuterUpLeft","BrowOuterUpRight","EyeLookUpLeft","EyeLookUpRight","EyeLookDownLeft","EyeLookDownRight","EyeLookInLeft","EyeLookInRight","EyeLookOutLeft","EyeLookOutRight","EyeBlinkLeft","EyeBlinkRight","EyeSquintRight","EyeSquintLeft","EyeWideLeft","EyeWideRight","CheekPuff","CheekSquintLeft","CheekSquintRight","NoseSneerLeft","NoseSneerRight","JawOpen","JawForward","JawLeft","JawRight","MouthFunnel","MouthPucker","MouthLeft","MouthRight","MouthRollUpper","MouthRollLower","MouthShrugUpper","MouthShrugLower","MouthClose","MouthSmileLeft","MouthSmileRight","MouthFrownLeft","MouthFrownRight","MouthDimpleLeft","MouthDimpleRight","MouthUpperUpLeft","MouthUpperUpRight","MouthLowerDownLeft","MouthLowerDownRight","MouthPressLeft","MouthPressRight","MouthStretchLeft","MouthStretchRight","TongueOut"];let Te;const S=["あ","い","う","え","お","にやり","ω","口角上げ","口角下げ","ぺろっ","上","下","にこり","困る","怒り","照れ","まばたき","笑い","びっくり","まばたきL","まばたきR"];var A=function(){function de(e){if(!e||Te)return;Te={};e.categories.forEach((e,t)=>{const i=e.categoryName;Te[i.charAt(0)+i.substring(1)]=t})}var pe;var ue=0,me=0,he=0,fe=0;const Me={};window.addEventListener("jThree_ready",()=>{for(const e of S.concat(["両目"])){Me[e]=new System._browser.data_filter([{type:"one_euro",id:e,para:e=="両目"?[30,1,5,1,4]:[30,1,1,1,1]}])}});return function(e){var S=typeof e.data=="string"&&e.data.charAt(0)==="{"?JSON.parse(e.data):e.data;if(typeof S==="string"){if(S=="OK"){Fe.worker_initialized=true}else{DEBUG_show(S,2);System._browser.console.log(S)}}else if(S.posenet){vt({data:S})}else if(Fe.enabled){window.dispatchEvent(new CustomEvent("SA_camera_facemesh_update"));je._needs_RAF=true;const t=wt[Ce.use_holistic?1:0];if(!t.facemesh){t.facemesh=true;DEBUG_show("Facemesh ML ready",2)}let w="";if(S.faces.length){Fe.data_detected++}else{Fe.data_detected=0}if(S.faces.length&&S.faces[0].bb_center){D=S.faces[0].bb_center}else if(!Ce.enabled){D=[.5,.5]}if(S.faces.length&&Fe.data_detected_stable){if(!Fe.draw_canvas)Re._data.faces=S.faces;let D=S.faces[0];de(D.faceBlendshapes);let c=je.x_flipped?1:-1;const A={facemesh_data:D};let E,k,l;if(D.rotation){const H=D.rotation.matrix;Ge.set(H[0],H[1],H[2],0,H[3],H[4],H[5],0,H[6],H[7],H[8],0,0,0,0,1)}else{let e=MMD_SA._v3a_.fromArray(D.mesh[152]).sub(MMD_SA._v3b.fromArray(D.mesh[10])).normalize();let t=MMD_SA._v3b_.fromArray(D.mesh[454]).sub(MMD_SA._v3b.fromArray(D.mesh[234])).normalize();let i=MMD_SA.TEMP_v3.crossVectors(t,e).normalize();t.crossVectors(e,i);Ge.set(t.x,t.y,t.z,0,e.x,e.y,e.z,0,i.x,i.y,i.z,0,0,0,0,1)}let e=MMD_SA.TEMP_v3.setEulerFromRotationMatrix(Ge,"YZX");E=-e.x;k=-e.y;l=-e.z;let t=D.scaledMesh[454][0]-D.scaledMesh[234][0];let i=D.scaledMesh[454][1]-D.scaledMesh[234][1];let o;if(S.recalculate_z_rotation_from_scaledMesh){t/=Math.cos(k);i/=Math.cos(E);o=Math.sqrt(t*t+i*i)}else{t/=Math.cos(l);o=Math.abs(t/Math.cos(k))}Fe.face_width=o;let n;if(S.recalculate_z_rotation_from_scaledMesh){n=Math.asin(i/o)}else{n=l}let a=new THREE.Quaternion;let s=MMD_SA._v3a.set(E,k*c,n*c);a.setFromEuler(s,"YZX");Fe.calculate_neck_data({is_face:true,timestamp:Fe.camera_video_frame_id,f_axis:qe.set(D.scaledMesh[454][0],D.scaledMesh[454][1],0).add(MMD_SA.TEMP_v3.set(D.scaledMesh[234][0],D.scaledMesh[234][1],0)).multiplyScalar(.5).setZ(0).toArray(),face_width:Fe.face_width,face_rot:a.toArray()});const j=MMD_SA.MMD.motionManager.para_SA;let r=0;let _=j.motion_tracking?.camera?.tilt_adjustment||je.tilt_adjustment;if(_.enabled){r=_.angle*Math.PI/180;const O=MMD_SA._q2.set(Math.sin(r/2),0,0,Math.cos(r/2));a.premultiply(O)}let d=je.video_timestamp;let p=0;if(fe){p=Math.max(Math.min(d-fe,1e3),10);he+=p;if(++me>=20){ue=1e3/(he/me);me=he=0}}fe=d;Fe._t=S._t;tt.t_delta=ue&&1e3/ue||p||S.fps&&1e3/S.fps||S._t;pe="";if(Fe.head_pose_enabled){if(System._browser.motion_control.enabled)A.head_rot=MMD_SA._v3a.clone();tt.add("skin|facemesh","首",{after_IK:true,rot:a,_rot_ratio:Fe.face_width/Math.min(je.video_canvas.width,je.video_canvas.height),onProcessRotation:yt})}ye+=Math.min(S._t,75);if(be){ge=~~(Math.min(ye/5e3,we.length/60,ke?Ae.L[0].eye_open_data.length/60:1,Ce.enabled?De.length/60:1,1)*100);be=ge<100;window.dispatchEvent(new CustomEvent("SA_camera_facemesh_calibrating",{detail:{percent:ge}}))}let u=D.faceInViewConfidence>(ze?.75:.9)&&(je.video==je._image||!je.video.paused&&Math.abs(k)e-t).slice(e,Ee.length-e).reduce((e,t)=>e+t)/(Ee.length-e*2)}let m=MMD_SA._v3a.fromArray(D.mesh[13]).distanceTo(MMD_SA._v3b.fromArray(D.mesh[14]));let h=D.faceBlendshapes?Math.max(D.faceBlendshapes.categories[Te["mouthPucker"]].score,.01):MMD_SA._v3a.fromArray(D.mesh[61]).distanceTo(MMD_SA._v3b.fromArray(D.mesh[291]));let f=ve;if(!f){if(u&&m<2*(1+Math.abs(r)/(Math.PI/4)*4))we.push(h);if(!we.length){f=0}else{let e=parseInt(we.length*.3);f=we.sort((e,t)=>e-t).slice(e,we.length-e).reduce((e,t)=>e+t)/(we.length-e*2);if(!be){ve=f}}}let M=0;let x=0;let y=0;let g=0;["L","R"].forEach(function(e){let t=Se[e];t.height=D.faceBlendshapes?Math.max(D.faceBlendshapes.categories[Te["eyeSquint"+(e=="L"?"Left":"Right")]].score,.01):MMD_SA._v3a.fromArray(D.mesh[t.height_ref_pts[0]]).distanceTo(MMD_SA._v3b.fromArray(D.mesh[t.height_ref_pts[1]]));t._height_average=t.height_average;if(!t._height_average){if(u)t.height_data.push(t.height);if(!t.height_data.length){t._height_average=t.height}else{let e=parseInt(we.length*.3);t._height_average=t.height_data.sort((e,t)=>e-t).slice(e,t.height_data.length-e).reduce((e,t)=>e+t)/(t.height_data.length-e*2);if(!be){t.height_average=t._height_average}}}y+=t.height/t._height_average});y/=2;y=(y-1)/.25*(y>1?2:1);if(f){if(h>f*1.05){x=Math.sqrt(Math.min((h-f*1.05)/(f*.25),1))}else if(h2){M=Math.pow(Math.min((m-2)/(f*1/3),1),.5);if(x>.25)g=(x-.25)/.75*.3}}let P=0;let R=0;let T=0;let b=0;let I=0;let z=0;const F=Fe.face_width/Math.min(je.video_canvas.width,je.video_canvas.height);const L=MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only||F>.2?1:Math.max(1-(.2-F)*8,0);let v={L:[0],R:[0]};if(Pe){["L","R"].forEach(function(t){let i=0;v[t][i]=0;let o=Ae[t][i];let n=D.faceBlendshapes?Math.max(1-D.faceBlendshapes.categories[Te["eyeBlink"+(t=="L"?"Left":"Right")]].score*.9,.2):MMD_SA._v3a.fromArray(D.mesh[o.height_ref_pts[0]]).distanceTo(MMD_SA._v3b.fromArray(D.mesh[o.height_ref_pts[1]]));let a=o.eye_open_average;if(!a){if(u){o.eye_open_data.push(n);let e=parseInt(o.eye_open_data.length*.3);a=o.eye_open_data.sort((e,t)=>e-t).slice(e,o.eye_open_data.length-e).reduce((e,t)=>e+t)/(o.eye_open_data.length-e*2);if(!be){o.eye_open_average=a}}else{a=o._eye_open_average}}if(u){if(o.eye_open_lower>n)o.eye_open_lower=n}o._eye_open_average=a;if(a){if(n>a){v[t][i]=Math.min(n/a,1.25)}else{let e=Math.min(o.eye_open_lower,a/2);v[t][i]=Math.max((n-e)/(a-e),0)}}})}const C=MMD_SA.THREEX.get_model(0).use_faceBlendshapes;if(D.faceBlendshapes){const q=D.faceBlendshapes.categories;if(!Fe.eye_tracking){q.forEach(e=>{if(e.categoryName.indexOf("eye")!=-1)e.score=0})}const r=[q[Te["eyeBlinkLeft"]].score,q[Te["eyeBlinkRight"]].score];r.forEach((e,t)=>{const i=t==0?"L":"R";const o=Ae[i][0];const n=1-(1-Math.max(o._eye_open_average||0,.5))*.8;const a=Math.min(o.eye_open_lower,.3);const s=n-a;e=Math.min(Math.max(e-(1-n),0)/s,1);r[t]=e<.5?Math.pow(e*2,1.5)/2:Math.pow((e-.5)*2,.667)/2+.5});const X=!Fe.blink_sync;const U=(X?Math.min(Math.abs(r[0]-r[1])/.4,1):0)*L;let e=X?Math.min(...r):(r[0]+r[1])/2;q[Te["eyeBlinkLeft"]].score=r[0]*U+e*(1-U);q[Te["eyeBlinkRight"]].score=r[1]*U+e*(1-U);for(const G of["eyeSquintLeft","eyeSquintRight"]){const W=G=="eyeSquintLeft"?"L":"R";const Q=Math.min(Math.max((Se[W]._height_average||0)*.8,.2),.5);q[Te[G]].score=Math.max(q[Te[G]].score-Q,0)/(1-Q)}const K=Math.min(Math.max((f||0)*.8,.2),.6);q[Te["mouthPucker"]].score=Math.pow(Math.max(q[Te["mouthPucker"]].score-K,0)/(1-K),2);if(C){q.forEach(e=>{const t=e.categoryName;let i=t.charAt(0).toUpperCase()+t.substring(1);i=i.indexOf("Left")!=-1?i.replace("Left","Right"):i.replace("Right","Left");tt.add("morph|facemesh",i,{weight:e.score})})}}if(Array.isArray(D.emotion)){D.emotion.forEach(e=>{switch(e.emotion){case"happy":P+=e.score;break;case"sad":R+=e.score;break;case"angry":case"disgust":T+=e.score;break;case"fear":b+=e.score;break;case"surprise":I+=e.score;break}})}const B=MMD_SA.THREEX.get_model(0);if(D.faceBlendshapes){const V=B.type=="VRM";const q=D.faceBlendshapes.categories;let i=q[Te["jawOpen"]].score;let o=(q[Te["mouthSmileLeft"]].score+q[Te["mouthSmileRight"]].score)/2;let n=(q[Te["mouthUpperUpLeft"]].score+q[Te["mouthUpperUpRight"]].score)/2;let a=(q[Te["mouthLowerDownLeft"]].score+q[Te["mouthLowerDownRight"]].score)/2;let s=q[Te["mouthPucker"]].score;let r=q[Te["mouthFunnel"]].score;let e=q[Te["mouthShrugLower"]].score;e*=e;let t=q[Te["browInnerUp"]].score;t*=t;let _=(q[Te["browOuterUpLeft"]].score+q[Te["browOuterUpRight"]].score)/2;let l=(q[Te["browDownLeft"]].score+q[Te["browDownRight"]].score)/2;const N=.3*(E>0?1-Math.min(E/(Math.PI/12),1):1);R=Math.min(Math.max(e-N,0)/.7,1);if(E<0){const oe=Math.min(Math.abs(E)/(Math.PI/4),1);R=Math.pow(Math.max(R-oe*.5,0)/(1-oe*.5),oe*3)}R=Math.max(R,Math.pow(Math.max(l-.1,0)/.9,.5));let c=0,d=0,p=0,u=0,m=0;const Y=Math.min(Fe.mouth_tracking_sensitivity,2)/2;const Z=Math.max(Fe.mouth_tracking_sensitivity-1,0)/2;const $=.2+.1*Y;if(i<.2){if(s>.1){p=s;if(r>.1)m=(r-.1)/2}else{d=Math.pow(Math.min(n+a/2,1),1-.5*Z);u=Math.pow(Math.min((o+n/2)*(i/.1),1),1-.5*Z);const oe=Math.min(o*(i/.1)/(n+a||.1),1);d*=1-oe;u*=oe}let e=1-i/.2*.5;let t=1-Math.min(Math.max(d,p,u,m),.2)/.2;t=e-t*.3;t=1-(1-t)*Y;c=Math.pow(i/.2,t)*$;if(C){i=c;tt.morph["JawOpen"][0].weight=i}}else{let e=$+Math.pow((i-.2)/.8,1-.5*Z)*(1-$);i=$+(i-.2)/.8*(1-$);if(C)tt.morph["JawOpen"][0].weight=i;m=Math.min(e+r/2,1);c=Math.min(e+(o+n)/3,1);if(s>.1){const oe=Math.min((s-.1)*5,1);m*=oe;c*=1-oe}else{m=0}}if(r>.1){x=-(r-.1)*.75}else{x=Math.min(Math.max(o-.2,0)*1+Math.max(n-.5,0)*1.5,1);if(x>.5)u*=1-(x-.5)*2*.25}P=Math.min(Math.max(x,0)-R,1);if(P<0){R=-P;P=0}else{R=0}const J=.2+s/2;T=Math.max(q[Te["mouthLeft"]].score-J,q[Te["mouthRight"]].score-J,0);o=Math.min(P*.8,V?.7-Math.max(P*.4-.3,0):.6);P*=.4;R*=.5;T=Math.max(T-P,0);let h=Math.max(Math.max((q[Te["mouthPressLeft"]].score+q[Te["mouthPressRight"]].score)/2,(q[Te["mouthRollLower"]].score+q[Te["mouthRollUpper"]].score)/2)-.2,0);if(l>.1){_=-(l-.1)/.9}else if(t>.1&&_>.1){_=((t-.1)/.9+(_-.1)/.9)/2}let f=(q[Te["eyeBlinkRight"]].score+q[Te["eyeBlinkLeft"]].score)/2;I=_>0?Math.max(Math.pow(_,2/3)-Math.pow(f,3/2)-.1,0):0;I=I*I*2/3;if(V)I=Math.min(I*Math.max(i*3,1),1);let M=1;const ee=Fe.use_tongue_out&&B.blendshape_map_by_MMD_name?.["ぺろっ"];let y=Math.min(Fe.emotion_weight_percent/100/.75,1)*Fe.emotion_tongue_out_percent/100;const te=y&&(B.use_tongue_out||ee);let g=Math.min(q[Te["mouthLowerDownLeft"]].score,q[Te["mouthLowerDownRight"]].score);if(te&&g>.2+.1*(1-y)&&i>.35+.15*(1-y)){let e=Math.max(q[Te["mouthUpperUpLeft"]].score,q[Te["mouthUpperUpRight"]].score);z=Math.max(g-e*(1.2+.1*(1-y)),0);if(Math.abs(k)>Math.PI/18){M=Math.max(1-(Math.abs(k)-Math.PI/18)/(Math.PI/4),1/3);z*=M}if(z<.1){z=0}else{z=Math.min(z*(1+(q[Te["mouthDimpleLeft"]].score+q[Te["mouthDimpleRight"]].score)/2),1)}}let b=Fe.emotion_weight_percent/100;if(C)b*=b;for(const ne in xe){let e=xe[ne];let t=Fe.emotion_weight_by_name(ne,b,1);let i=-1,o=1;let n=V?1:t*.8;let a=t*.75;let s=0;let r;switch(ne){case"sad":s=R;r=.25;break;case"angry":s=T;r=.25;break;case"surprise":s=I;if(V){r=.25}break;case"blush":s=h;r=.2;o=.5;n=1;break;case"tongue_out":s=z;r=.2;a=.6;n=1;break}if(r){let e=Math.min(s/r,1);e*=e;n=Math.min(s+Math.max(n-s,0)*e*(e<1?a:1),n);i=s*e*o}xe[ne]=THREE.Math.clamp(Math.max(e,s)+i*Fe._t/1e3*4,0,n)}({sad:R,angry:T,surprise:I,blush:h,tongue_out:z}=xe);if(z){if(ee){z=z<.5?(1-Math.cos(z*Math.PI))*.5:.5+Math.sin((z-.5)*Math.PI)*.5}else{if(z<.5){z=0}else{z=Math.sqrt(z);c*=1-z+z/2}}}if(C&&!ee)tt.add("morph|facemesh","TongueOut",{weight:z});if(!V){b=Math.min(b/.75,1);if(h)R+=h*.25*b}const ie=Fe.emotion_weight_by_name("smile",Math.sqrt(b));o=Math.min(o*ie,1);P=Math.min(P*ie,1);R=Math.min(R,Fe.emotion_weight_by_name("sad",b));T=Math.min(T,Fe.emotion_weight_by_name("angry",b));h=Math.min(h,Math.min(Fe.emotion_weight_by_name("blush",b)/.75,1));I=Math.min(I,Fe.emotion_weight_by_name("surprise",b));if(V)I*=I;tt.add("morph|facemesh","あ",{weight:c});tt.add("morph|facemesh","い",{weight:d});tt.add("morph|facemesh","う",{weight:p});tt.add("morph|facemesh","え",{weight:u});tt.add("morph|facemesh","お",{weight:m});tt.add("morph|facemesh","にやり",{weight:x});tt.add("morph|facemesh","口角上げ",{weight:n-e});tt.add("morph|facemesh","上",{weight:_});tt.add("morph|facemesh","にこり",{weight:o});tt.add("morph|facemesh","困る",{weight:R});tt.add("morph|facemesh","怒り",{weight:T});tt.add("morph|facemesh","笑い",{weight:P});tt.add("morph|facemesh","びっくり",{weight:I});tt.add("morph|facemesh","照れ",{weight:h});tt.add("morph|facemesh","ぺろっ",{weight:z});const X=!Fe.blink_sync&&THREE.MMD.getModels()[0].pmx.morphs_index_by_name["まばたきL"]!=null;if(X){tt.add("morph|facemesh","まばたきL",{weight:Math.max(q[Te["eyeBlinkRight"]].score-P,0)});tt.add("morph|facemesh","まばたきR",{weight:Math.max(q[Te["eyeBlinkLeft"]].score-P,0)});tt.add("morph|facemesh","まばたき",{weight:0})}else{tt.add("morph|facemesh","まばたきL",{weight:0});tt.add("morph|facemesh","まばたきR",{weight:0});tt.add("morph|facemesh","まばたき",{weight:Math.max(f-P,0)})}let v,w,S,A;if(Fe.auto_look_at_camera){const ae=THREE.MMD.getModels()[0].mesh;const se=MMD_SA.TEMP_v3.copy(MMD_SA._trackball_camera.object.position).sub(MMD_SA._head_pos).normalize().applyQuaternion(MMD_SA.get_bone_rotation(ae,"頭").conjugate());const re=MMD_SA._v3b.setEulerFromQuaternion(MMD_SA.TEMP_q.setFromUnitVectors(MMD_SA._v3a.set(0,0,1),se));v=-Math.sign(re.x)*Math.min(Math.abs(re.x/(Math.PI/4)),1);w=-Math.sign(re.y)*Math.min(Math.abs(re.y/(Math.PI/4)),1);A=1}else{v=(q[Te["eyeLookUpLeft"]].score+q[Te["eyeLookUpRight"]].score)/2-(q[Te["eyeLookDownLeft"]].score+q[Te["eyeLookDownRight"]].score)/2;w=(q[Te["eyeLookInRight"]].score+q[Te["eyeLookOutLeft"]].score)/2-(q[Te["eyeLookInLeft"]].score+q[Te["eyeLookOutRight"]].score)/2;A=Fe.eye_bone_rotation_percent/100}S={absolute:true,rot:(new THREE.Quaternion).setFromEuler(MMD_SA._v3a.set(-v*15/180*Math.PI,-w*20/180*Math.PI,0).multiplyScalar(A),"YZX")};tt.add("skin|facemesh","両目",S)}else{let e=P-(R+T+b+I*.5);if(e<0){g*=Math.max(1+e*2,0)}else{g=Math.min(e*.2+g*(1+e*.5),.4)}tt.add("morph|facemesh","にこり",{weight:Me["にこり"].filter(Math.min(g+P*.75,.75))});tt.add("morph|facemesh","困る",{weight:Me["困る"].filter(Math.min((R+b)/2*.75+(y<0?Math.max(-y*1-Math.max(x,0)*.5,0):0),.75))});tt.add("morph|facemesh","怒り",{weight:Me["怒り"].filter(Math.min(T*.75,.75))});y+=I*.2;tt.add("morph|facemesh","笑い",{weight:Me["笑い"].filter(g)});tt.add("morph|facemesh","びっくり",{weight:Me["びっくり"].filter(I*.75)});tt.add("morph|facemesh","にやり",{weight:Me["にやり"].filter(x)});let i=MMD_SA.TEMP_q.setFromEuler(MMD_SA._v3a.set(E,k,l),"YZX").conjugate();let o=[];[13,14,61,291].forEach(function(e,t){o[e]=Ie[t].fromArray(D.mesh[e]).applyQuaternion(i).setZ(0)});let t=MMD_SA._v3a.copy(o[61]).add(o[291]).multiplyScalar(.5);let n=o[61].distanceTo(o[291])*.5;let a=Math.atan2(o[13].y-t.y,n);let s=Math.atan2(o[14].y-t.y,n);let r=Math.max(-(a+s)*180/Math.PI+20*M,0);if(r)r=Math.min(r/20,.75);r=Math.min(r+R*.25,1);r*=.5;M=M*(1-r);tt.add("morph|facemesh","あ",{weight:Me["あ"].filter(M)});tt.add("morph|facemesh","お",{weight:Me["お"].filter(r)});let _={L:[],R:[]};if(!Fe.eye_tracking){}else if(Pe){let i=[0,0];let o=[0,0];D.eyes.forEach(function(e,t){if(e){i[t]=Math.max(Math.min((e[3]*2+E/(Math.PI/2))*(1-Math.abs(E)/Math.PI),1),-1);o[t]=Math.max(Math.min((e[2]*2-k/(Math.PI/2))*(1-Math.abs(k)/Math.PI),1),-1)}});let e=(v.L[0]+v.R[0])/2;if(e>1)y+=(e-1)*2;else y-=(1-e)*.5;y=Math.min(y,1);let t=v.L[0]+v.R[0];if(t)t=v.L[0]/t;else t=.5;let n=i[0]*t+i[1]*(1-t);let a=o[0]*t+o[1]*(1-t);let s={absolute:true,rot:(new THREE.Quaternion).fromArray(Me["両目"].filter(MMD_SA.TEMP_q.setFromEuler(MMD_SA._v3a.set(-(n-.3)*15/180*Math.PI,a*c*20/180*Math.PI,0),"YZX").toArray()))};tt.add("skin|facemesh","両目",s);let r=!Fe.blink_sync&&THREE.MMD.getModels()[0].pmx.morphs_index_by_name["まばたきL"]!=null;let _=(r?Math.min(Math.max(Math.abs(v.L[0]-v.R[0])-(.25+(1-Math.min(Math.max((Math.PI/6-Math.abs(k))/(Math.PI/12),0),1))*1),0)/.25,1):0)*L;let l=r?Math.min(v.L[0],v.R[0]):(v.L[0]+v.R[0])/2;v.L[0]=v.L[0]*_+l*(1-_);v.R[0]=v.R[0]*_+l*(1-_);if(r){let e="まばたき"+(c==1?"L":"R");tt.add("morph|facemesh",e,{weight:Me[e].filter(Math.max(Math.min(1-v.L[0]*.8-g,1),0))});e="まばたき"+(c==1?"R":"L");tt.add("morph|facemesh",e,{weight:Me[e].filter(Math.max(Math.min(1-v.R[0]*.8-g,1),0))});tt.add("morph|facemesh","まばたき",{weight:0})}else{tt.add("morph|facemesh","まばたきL",{weight:0});tt.add("morph|facemesh","まばたきR",{weight:0});tt.add("morph|facemesh","まばたき",{weight:Me["まばたき"].filter(Math.max(Math.min(1-v.L[0]*.8-g,1),0))})}}else{let e=D.eyes[0];let t=0;let i=0;if(e){t=Math.max(Math.min((e[3]*2+E/(Math.PI/2))*(1-Math.abs(E)/Math.PI),1),-1);i=Math.max(Math.min((e[2]*2-k/(Math.PI/2))*(1-Math.abs(k)/Math.PI),1),-1)}let o=y*.25;if(o<0)o=Math.min(o+g,0);let n=Math.max(Math.min(.1-t*(t<0?2:1)*.2-o,.5),0);tt.add("morph|facemesh","まばたき",{weight:n});let a=1.25+Math.pow((v.L[0]+v.R[0])/2,2)*1.75;t=Math.sign(t)*Math.pow(Math.abs(t),a);i=Math.sign(i)*Math.pow(Math.abs(i),a);let s={absolute:true,rot:(new THREE.Quaternion).setFromEuler(MMD_SA._v3a.set(-t*15/180*Math.PI,i*c*20/180*Math.PI,0),"YZX")};tt.add("skin|facemesh","両目",s)}if(Fe.eye_tracking)tt.add("morph|facemesh","上",{weight:Me["上"].filter(Math.max(Math.min(y,1),-1))})}if(!Ce.enabled){if(!tt.skin["センター"])tt.add("skin","センター",{rot:new THREE.Quaternion});const _e=MMD_SA.TEMP_v3.set(0,1,0);bt(_e,true);const le=_e.z?Math.atan2(_e.z,_e.y):0;tt.add("skin","上半身",{rot:new THREE.Quaternion(Math.sin(-le/2),0,0,Math.cos(-le/2))});const j=MMD_SA.MMD.motionManager.para_SA;if(j.motion_tracking_upper_body_only){for(const W of["左","右"]){const ce=true;if(j.has_leg_IK){tt.set_blend_default_motion("skin",W+"足IK",true);tt.remove("skin",W+"足首")}else{tt.set_blend_default_motion("skin",W+"足",true);tt.set_blend_default_motion("skin",W+"ひざ",true);tt.set_blend_default_motion("skin",W+"足首",true)}Ce.enable_IK(W+"足IK",j.has_leg_IK);Ce.enable_IK(W+"つま先IK",j.has_leg_IK);tt.set_blend_default_motion("skin",W+"肩",ce);tt.set_blend_default_motion("skin",W+"腕",ce);tt.set_blend_default_motion("skin",W+"ひじ",ce);tt.set_blend_default_motion("skin",W+"手捩",ce);tt.set_blend_default_motion("skin",W+"手首",ce);tt.set_blend_default_motion("skin",W+"腕IK",ce);Ce.enable_IK(W+"腕IK",true)}}else{for(const W of["左","右"]){Ce.enable_IK(W+"腕IK",j.has_arm_IK)}tt.remove("skin","センター")}}w=w||D.eyes.length&&[(!Ce.enabled?je.video_canvas.width+"x"+je.video_canvas.height+"("+Fe.camera_video_frame_id+")\n":"")+(be?"Calibrating("+ge+"%):Make a calm face!":"(face data calibrated)")+"/"+Math.round(D.faceInViewConfidence*100)+"%",D.emotion?JSON.stringify(D.emotion):"Neutral"].join("\n");if(pe)w+="\n"+pe;w+=(He||!Ce.enabled?Oe?"\n"+Oe+"\n":"":"")+(He||"");System._browser.motion_control.process(A)}else{if(!Fe.draw_canvas)Re._data.faces=[];w="(no facemesh data)\n"+He}if(!System._browser.overlay_mode&&!MMD_SA_options.user_camera.ML_models.debug_hidden){System._browser.on_animation_update.add(()=>{DEBUG_show(w&&w+(!Ce.enabled||!Ce.use_holistic?"\nF-FPS:"+Math.round(ue)+"/"+Math.round(S.fps||0):"")+"\n"+"FPS:"+EV_sync_update.fps_last||"")},0,0)}Fe.busy=0}Fe.update_frame()}}();var E=document.createElement("canvas");var a=true;var s;var r;var _,l,c,d,p,u,m;var h;var D=[];var f=0;var M=0;Fe={initialized:false,worker_initialized:false,faceBlendshapes_list:e,MMD_morph_list:S,wireframe:Re,draw_canvas:false,get data_detected(){return f},set data_detected(e){if(e){if(!f){M=RAF_timestamp}}else{M=0}f=e},get data_detected_stable(){return i&&M&&RAF_timestamp-M>250/(it.speed||1)},get head_pose_enabled(){return this.data_detected_stable||!Ce.enabled},get blink_detection(){return ke},set blink_detection(e){ke=e;if(i){if(ke){o()}else{MMD_SA_options.auto_blink=n!=null?n:MMD_SA_options.auto_blink}}},get auto_blink(){return b},set auto_blink(e){b=e},get eye_bone_rotation_percent(){return h==null?100:h},set eye_bone_rotation_percent(e){h=e},get eye_tracking(){return a},set eye_tracking(e){a=e;if(a){this.blink_detection=!!Pe}else{this.blink_detection=false}if(i){if(!a){tt.remove("skin","両目");tt.remove("morph","まばたきL");tt.remove("morph","まばたきR");tt.remove("morph","まばたき");tt.remove("morph","上");tt.remove("morph","下")}}},get use_faceLandmarksDetection(){return Pe},set use_faceLandmarksDetection(e){if(!this.initialized)Pe=e},get use_mediapipe(){return v||Ce.enabled&&Ce.use_holistic},set use_mediapipe(e){return v=e},get use_faceBlendshapes(){return!Ce.enabled||!Ce.use_holistic_legacy},get calibrated(){return!be&&ge>=100},get mouth_tracking_sensitivity(){return r==null?1:r},set mouth_tracking_sensitivity(e){r=e},get lean_tracking(){return s==null?2:s},set lean_tracking(e){s=e},get emotion_weight_percent(){return _==null?75:_},set emotion_weight_percent(e){_=e},get emotion_joy_fun_percent(){return l==null?100:l},set emotion_joy_fun_percent(e){l=e},get emotion_angry_percent(){return c==null?100:c},set emotion_angry_percent(e){c=e},get emotion_sorrow_percent(){return d==null?100:d},set emotion_sorrow_percent(e){d=e},get emotion_surprised_percent(){return p==null?100:p},set emotion_surprised_percent(e){p=e},get emotion_tongue_out_percent(){return u==null?100:u},set emotion_tongue_out_percent(e){u=e},get emotion_others_percent(){return m==null?100:m},set emotion_others_percent(e){m=e},emotion_weight_by_name:function(e,t=1,i=2){switch(e){case"smile":t*=this.emotion_joy_fun_percent/100;break;case"angry":t*=this.emotion_angry_percent/100;break;case"sad":t*=this.emotion_sorrow_percent/100;break;case"surprise":t*=this.emotion_surprised_percent/100;break;case"tongue_out":t*=this.emotion_tongue_out_percent/100;break;case"blush":t*=this.emotion_others_percent/100;break}return Math.min(t,i)},export_calibration:function(){const e={facemesh_calibration_type:Ce.use_holistic_legacy?"holistic_legacy":"facemesh",lips_width_average:ve,eyebrow_data:{L:{height_average:Se.L.height_average},R:{height_average:Se.R.height_average}},eye_data:{L:{eye_open_average:Ae.L[0].eye_open_average},R:{eye_open_average:Ae.R[0].eye_open_average}},neck_length_average:y};System._browser.save_file("facemesh_calibration.json",JSON.stringify(e,null,"\t"),"application/json")},import_calibration:function(e){this.reset_calibration();ve=e.lips_width_average;for(const t of["L","R"]){Object.assign(Se[t],e.eyebrow_data[t]);Object.assign(Ae[t][0],e.eye_data[t])}y=e.neck_length_average||1.25;ge=100;be=false},face_width:0,_neck:{},calculate_neck_data:(()=>{let u,m,h;let f;let M;window.addEventListener("jThree_ready",()=>{u=new THREE.Vector3;m=new THREE.Vector3;h=new THREE.Vector3;f=new THREE.Quaternion;M=new System._browser.data_filter([{type:"one_euro",id:"neck_length",para:[30,1,1,1,1]}])});return function(t){if(!Ce.enabled||!Fe.enabled||!this._neck.data)return false;let e=this._neck.data.find(e=>e.timestamp===t.timestamp);if(!e){this._neck.data.unshift(t);return false}Object.assign(e,t);if(!(e.is_pose&&e.is_face))return false;const i=u.fromArray(e.f_axis);const o=m.fromArray(e.shoulder_center).setZ(0);const n=h.set(0,0,e.face_width/3).applyQuaternion(f.fromArray(e.face_rot).conjugate()).setZ(0).y;const a=MMD_SA.MMD.motionManager.para_SA;let s=a.motion_tracking?.camera?.tilt_adjustment||je.tilt_adjustment;let r=s.enabled?s.angle*Math.PI/180:0;const _=a.motion_tracking?.ML_models?.pose||MMD_SA_options.user_camera.ML_models.pose;if(_.upper_rotation_offset){const p=_.upper_rotation_offset*Math.PI/180;r*=Math.cos(p)}const l=e.spine_rot_absolute[0]+r;this._neck._spine_rot_absolute=e.spine_rot_absolute.slice();this._neck._spine_rot_absolute[0]+=r;let c=M.filter(i.distanceTo(o)+n)/e.face_width/Math.max(Math.abs(Math.cos(l)));if(be){window.addEventListener("SA_camera_facemesh_calibrating",()=>{De.push(c);let e=parseInt(De.length*.3);y=De.sort((e,t)=>e-t).slice(e,De.length-e).reduce((e,t)=>e+t)/(De.length-e*2)},{once:true})}this._neck.data.length=0;if(!y)return false;let d=c/y;et[2]=!Ce.shoulder_tracking||d>.95?0:(1-Math.max((d/.95-.8)/(1-.8),0))*Math.PI/8;if(t.is_pose)return true;return true}})(),get enabled(){return i},set enabled(e){if(i==!!e)return;i=!!e;I();this.busy=0;this.data_detected=0;D[0]=D[1]=.5;this._neck={data:[]};if(i){if(!this.initialized)w();n=MMD_SA_options.auto_blink;const t=Ce.use_holistic_legacy?1:0;o(g!=t);g=t}else{MMD_SA_options.auto_blink=n}X()},get bb_center(){return D},set bb_center(e){D=e},reset_calibration:o,get frames(){return tt},init:w,worker_onmessage:A,camera_video_timestamp:0,update_frame:function(e){async function t(){var e=Fe.enabled&&Fe.worker_initialized&&k&&!Fe.busy&&!(Ce.enabled&&Ce.use_holistic)&&R&&Fe.camera_video_timestamp!=k;if(!e)return;Fe.busy=RAF_timestamp;Fe.camera_video_timestamp=k;Fe.camera_video_frame_id=P;if(ke){MMD_SA_options.auto_blink=b||false}let n;let a,s;let r,_;let l,c;let t;n=je.video_canvas;let i=n.width,o=n.height;l=c=0;a=r=i;s=_=o;let d=1;let p=MMD_SA_options.user_camera.pixel_limit.facemesh;if(p){if(a*s>p[0]*p[1]){d=Math.sqrt(a*s/(p[0]*p[1]));a=r=Math.round(a/d);s=_=Math.round(s/d);n=E;t=true}}let u,m,h;if(MMD_SA_options.user_camera.pixel_limit.facemesh_bb_ratio){u=MMD_SA_options.user_camera.pixel_limit.facemesh_bb_ratio;h=Math.round(Math.min(a,s)*u);r=h;_=h;let e=1;const g=5*(v?2:1);if(Fe.data_detected"+r+"x"+_+"):"+[e,t,h,h].join(",")+"=>"+[l,c,r,_].join(","))}}else{if(n.width!=r||n.height!=_){n.width=r;n.height=_;console.log("Facemesh canvas("+a+"x"+s+")")}}f.drawImage(je.video_canvas,Math.round(e*d),Math.round(t*d),Math.round(i*d),Math.round(o*d),0,0,r,_)}let M=T&&v?await createImageBitmap(n,t?0:l,t?0:c,r,_):f.getImageData(t?0:l,t?0:c,r,_).data.buffer;Fe._timestamp=je.video_timestamp;let y={rgba:M,w:a*(m||1),h:s*(m||1),options:{use_facemesh:true,draw_canvas:Fe.draw_canvas,flip_canvas:je.display_flipped,bb:{x:Math.round(l),y:Math.round(c),w:r,h:_,ratio:u||0,scale:m||1,timestamp:Fe._timestamp}}};if(Fe.draw_canvas){if(self.FacemeshAT){y.canvas=je.video_canvas_facemesh}else if(!je.video_canvas_facemesh._offscreen&&self.OffscreenCanvas){y.canvas=je.video_canvas_facemesh.transferControlToOffscreen();je.video_canvas_facemesh._offscreen=true;console.log("(Facemesh: use offscreen canvas)")}}else{Fe.wireframe._data.bb=y.options.bb}Le.postMessage(y,y.canvas?[y.canvas,y.rgba]:[y.rgba]);y.rgba=M=undefined;y=undefined}if(e||self.FacemeshAT){setTimeout(()=>{t()},0)}else{t()}}};return Fe}(),poseNet:function(){var i=false;var t=true;var C=true;var B={};var o=null;var n=null;var a=null;var s=0;var r=0;var _=0;var l=null;var c=null;var d=0;var p;var u;var m,h,f,M;var y,g,b,v;var w;let S={};let A={_default_:{}};let D="_default_";var E,k,x;var P,R;var T;var I,z,j,F;var L;Ce={get enabled(){return i},set enabled(e){if(i==!!e)return;i=!!e;ot=0;Ne=false;this.data_detected=0;this.initial_data_detected=false;_=0;THREE.MMD.getModels()[0].mesh.visible=true;le.set(0,0,0);if(i){if(!this.initialized)Y();if(V){worker_id=Ce.use_holistic?"legacy_holistic":"tasks_vision";if(!H[worker_id]){wt=[{},{}];O.terminate();for(const t in H)delete H[t];O=new Worker(V);O.onmessage=vt;q=worker_id;H[q]=new N(q,O)}console.log("Web worker ID:"+q);O=H[q].worker;K=H[q].initialized}MMD_SA_options.user_camera.ML_models.pose.events.enabled&&MMD_SA_options.user_camera.ML_models.pose.events.enabled()}else{THREE.MMD.getModels()[0].resetPhysics();MMD_SA_options.user_camera.ML_models.pose.events.disabled&&MMD_SA_options.user_camera.ML_models.pose.events.disabled();MMD_SA.TEMP_v3.set(0,0,0);MMD_SA.Camera_MOD.adjust_camera("hip_camera",MMD_SA.TEMP_v3,MMD_SA.TEMP_v3)}X();if(Ce.use_holistic){setTimeout(()=>{if(i)Fe.enabled=Be.enabled=true;else Be.enabled=false;DEBUG_show("(Holistic Mode:"+(i?"ON":"OFF")+")",2)},0)}},get data_detected(){return s},set data_detected(e){if(e){if(!s){r=RAF_timestamp}if(this.data_detected_stable){_=0}}else{r=0;if(!_){_=RAF_timestamp}if(RAF_timestamp-_>250/(it.speed||1)){tt.reset()}}s=e},get data_detected_stable(){return i&&(!_||RAF_timestamp-_<250/(it.speed||1)||r&&RAF_timestamp-r>500/(it.speed||1))},get use_head_mocap(){return(!this.enabled||this.data_detected_stable)&&(Fe.enabled||!MMD_SA.MMD.motionManager.para_SA.is_custom_motion||!MMD_SA.vmd_by_filename[MMD_SA.MMD.motionManager.filename]?.morphKeys.length)},get use_3D_pose(){return i&&t&&pt},set use_3D_pose(e){t=e},get use_holistic(){return o==null?Q:o},set use_holistic(e){o=e},get _use_holistic_(){return Q},set _use_holistic_(e){Q=e},get use_holistic_landmarker(){return this.use_holistic&&n},set use_holistic_landmarker(e){n=e;a=!e},get use_holistic_legacy(){return this.use_holistic&&a},set use_holistic_legacy(e){n=!e;a=e},get skip_hand_countdown_max(){return 0},set IK_disabled(e){C=e},get auto_grounding(){return l!=null?l:MMD_SA_options.user_camera.ML_models.pose.auto_grounding||MMD_SA.WebXR.session},set auto_grounding(e){l=e},get ground_plane_visible(){return c!=null?c:!i||!!this.auto_grounding||MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only},set ground_plane_visible(e){c=e},get spine_length_ref(){if(d)return d;const e=MMD_SA.THREEX.get_model(0).para.spine_length;return e},set spine_length_ref(e){d=e},get shoulder_tracking(){return p==null?1:p},set shoulder_tracking(e){p=e},get hip_camera(){return u==null?false:u},set hip_camera(e){u=e;if(!e){MMD_SA.TEMP_v3.set(0,0,0);MMD_SA.Camera_MOD.adjust_camera("hip_camera",MMD_SA.TEMP_v3,MMD_SA.TEMP_v3)}},get hip_adjustment(){return A},set hip_adjustment(e){A=e||{_default_:{}}},get hip_adjustment_set_by_motion_name(){return S},set hip_adjustment_set_by_motion_name(e){S=e||{}},get hip_adjustment_set(){return D},set hip_adjustment_set(e){D=A[e]?e:S[e];if(!D)D="_default_";if(!A[D])A[D]={};({hip_adjustment_weight_percent:m,hip_adjustment_head_weight_percent:h,hip_adjustment_adjust_y_axis_percent:f,hip_adjustment_smoothing_percent:M,hip_adjustment_scale_x_percent:y,hip_adjustment_scale_y_percent:g,hip_adjustment_head_pitch_rotation_percent:b,hip_adjustment_scale_z_percent:v,hip_adjustment_rotation_percent:w}=A[D])},get hip_adjustment_weight_percent(){return m==null?100:m},set hip_adjustment_weight_percent(e){A[D].hip_adjustment_weight_percent=m=e},get hip_adjustment_head_weight_percent(){return h==null?100:h},set hip_adjustment_head_weight_percent(e){A[D].hip_adjustment_head_weight_percent=h=e},get hip_adjustment_adjust_y_axis_percent(){return f==null?66:f},set hip_adjustment_adjust_y_axis_percent(e){A[D].hip_adjustment_adjust_y_axis_percent=f=e},get hip_adjustment_scale_x_percent(){return y==null?100:y},set hip_adjustment_scale_x_percent(e){A[D].hip_adjustment_scale_x_percent=y=e},get hip_adjustment_scale_y_percent(){return g==null?100:g},set hip_adjustment_scale_y_percent(e){A[D].hip_adjustment_scale_y_percent=g=e},get hip_adjustment_head_pitch_rotation_percent(){return b==null?100:b},set hip_adjustment_head_pitch_rotation_percent(e){A[D].hip_adjustment_head_pitch_rotation_percent=b=e},get hip_adjustment_scale_z_percent(){return v==null?100:v},set hip_adjustment_scale_z_percent(e){A[D].hip_adjustment_scale_z_percent=v=e},get hip_adjustment_smoothing_percent(){return M==null?0:M},set hip_adjustment_smoothing_percent(e){A[D].hip_adjustment_smoothing_percent=M=e},get hip_adjustment_rotation_percent(){return w==null?100:w},set hip_adjustment_rotation_percent(e){A[D].hip_adjustment_rotation_percent=w=e},get hip_depth_scale_percent(){return E==null?100:E},set hip_depth_scale_percent(e){E=e},get hip_z_position_offset_percent(){return k==null?0:k},set hip_z_position_offset_percent(e){k=e},get hip_y_position_offset_percent(){return x==null?0:x},set hip_y_position_offset_percent(e){x=e},get limb_entry_duration_percent(){return P==null?100:P},set limb_entry_duration_percent(e){P=e},get limb_return_duration_percent(){return R==null?100:R},set limb_return_duration_percent(e){R=e},auto_scale_property:function(e,t,i){if(i===false)return e;let o,n;if(t.indexOf("腕")!=-1){o="left_arm_length";n=5.153592238246502}else if(t.indexOf("手首")!=-1){o="left_palm_length";n=.9020481908808872}else if(t.indexOf("上半身")!=-1){o="spine_length";n=4.97462}else if(t=="ROOT"){o="left_leg_length";n=10.569580078125}else{return e}let a=.9;let s=typeof i=="number"?i:1;let r=MMD_SA.THREEX.get_model(0).para[o]/n;r=r>1?Math.max(r*a,1):Math.min(r/a,1);r=1+(r-1)*s;return Array.isArray(e)?e.map(e=>e*r):e*r},body_collider:{get mode(){return T==null?1:T},set mode(e){T=e},get enabled(){return this.mode>0&&["head","chest","waist","hip"].some(e=>this[e].enabled)},get active(){return this.enabled&&Ce.enabled&&(Ce._upper_body_only_mode||this.mode>1)},head:{get enabled(){return!!this.size_percent},get size_percent(){return I==null?0:I},set size_percent(e){I=e},get reaction_type(){return L==null?"z_push":L},set reaction_type(e){L=e}},chest:{get enabled(){return!!this.size_percent},get size_percent(){return z==null?125:z},set size_percent(e){z=e}},waist:{get enabled(){return!!this.size_percent},get size_percent(){return j==null?100:j},set size_percent(e){j=e}},hip:{get enabled(){return!!this.size_percent},get size_percent(){return F==null?100:F},set size_percent(e){F=e}}},IK_disabled_check:function(){var o=new RegExp("("+toRegExp(["腕IK","足IK","つま先IK"],"|")+")$");var e=new RegExp("("+toRegExp(["腕IK"],"|")+")$");return function(e){const t=MMD_SA.MMD.motionManager.para_SA;if(!C||!this.data_detected&&(this.enabled||!Fe.enabled||!Fe.data_detected)||!t.motion_tracking_enabled)return null;let i=!e||o.test(e);if(i&&e){if(B[e])i=false}return i}}(),enable_IK:function(e,t){B[e]=t},get frames(){return tt},camera_video_timestamp:0,get busy(){return ot},get initialized(){return U},get worker_initialized(){return K},set worker_initialized(e){K=e;if(!self.PoseAT)H[q].initialized=e}};return Ce}(),handpose:function(){var t=false;var i={};var o={};var n,a;var s;Be={get enabled(){return t},set enabled(e){if(t==!!e)return;t=!!e;if(t){i={};o={};if(!this.initialized)Y()}},get hand_visible_timestamp(){return i},get hand_visible_session(){return o},get frames(){return tt},get busy(){return ot},get initialized(){return U},get worker_initialized(){return K},set worker_initialized(e){K=H[q].initialized=e},get stabilize_arm(){return n==null?2:n},set stabilize_arm(e){n=e},get stabilize_arm_time(){return a==null?0:a},set stabilize_arm_time(e){a=e},get stabilize_hand_percent(){return s==null?20:s},set stabilize_hand_percent(e){s=e},_hand_last:{"左":{},"右":{}}};return Be}(),reset_video_canvas:function(){if(this.video_canvas){this.video_canvas.width=this.video_canvas.height=k=0;P=""}},show:function(){if(!this.initialized||this.visible)return;this.visible=true;if(je.target_devicePixelRatio!=window.devicePixelRatio){je.target_devicePixelRatio=0;je.video_track.applyConstraints(je.set_constraints()).then(function(){DEBUG_show("(camera size updated)",2)})["catch"](function(e){DEBUG_show("ERROR:camera size failed to update")})}s();if(this.hidden_enforced){this.hide()}},hide:function(){if(!this.initialized||!this.visible)return;this.visible=false;this.video_canvas.style.visibility="hidden";c.enabled=false;d.enabled=false;l()},set_constraints:function(e){var t={};const i=window.devicePixelRatio/this.target_devicePixelRatio;let o,n;const a=is_mobile?Math.min(270/Math.min(window.innerWidth,window.innerHeight),i):i;o=Math.round(window.innerWidth*a);n=Math.round(window.innerHeight*a);var s=MMD_SA_options.user_camera.pixel_limit.current||MMD_SA_options.user_camera.pixel_limit._default_;if(!u){if(MMD_SA_options.user_camera.pixel_limit.fixed){o=s[0];n=s[1]}else if(o*n>s[0]*s[1]){const r=Math.sqrt(o*n/(s[0]*s[1]));o=Math.round(o/r);n=Math.round(n/r)}}je.target_width=o;je.target_height=n;if(!MMD_SA_options.user_camera.pixel_limit.disabled){if(!is_mobile||!screen.orientation||/landscape/.test(screen.orientation.type)){t.width=o;t.height=n}else{t.width=n;t.height=o}}if(MMD_SA_options.user_camera.fps)t.frameRate=MMD_SA_options.user_camera;if(e)t=Object.assign(t,e);console.log("Camera constraints",t);return t}};return je}(),data_filter:function(){class e{constructor(){}filter(e){return e}}class n{constructor(e){this.filters=e;e.forEach(e=>{switch(e.type){case"one_euro":if(e.transition_time){e.para[1]=1/(1/(1/e.transition_time/60)-1)*60/(2*Math.PI);console.log("transition_time => minCutoff",e.para[1])}e.filter=new OneEuroFilter(...e.para||[]);break}if(e.id)e.filter.id=e.id})}static#get_timestamp(){return System._browser.camera.initialized&&System._browser.camera.ML_enabled?System._browser.camera.video_timestamp:RAF_timestamp}filter(t,i=n.#get_timestamp(),o=System._browser.camera.motion_recorder.speed||1){if(t!=null){if(Array.isArray(t)?t.some(e=>isNaN(e)):isNaN(t)){console.error("Data filter error",this.filters[0].id);return t}this.filters.forEach(e=>{if(!e.condition||e.condition()){this.data=e.filter.filter(t,i,o);this.timestamp=RAF_timestamp}})}else{if(i!=null){if(i===true)i=n.#get_timestamp();this.filters.forEach(e=>{e.filter.lasttime=i;if(this.timestamp!=null)this.timestamp=RAF_timestamp})}}return this.data}}return n}(),motion_control:function(){var s,u,p,i,_,m;var d;var h;var f=function(){var r={};var a={};return{pressed:r,map:a,temp:{},set_options:function(e){if(!l)return;if(!e.timeout_list){const t=["W","A","S","D"];for(const i of["L","R"]){for(const o in e[i]){const n=e[i][o];if(n.press)t.push(...n.press)}}e.timeout_list=t.map(e=>m[e])}if(!e.clear_list)e.clear_list={};for(const i of["L","R"]){if(!e.clear_list[i]){const t=i=="L"?["W","A","S","D"]:[];for(const o in e[i]){const n=e[i][o];if(n.press)t.push(...n.press)}e.clear_list[i]=t.map(e=>[m[e]])}}this.temp={};Object.assign(a,e);console.log(a)},action:function(e,t,i){var o=a[t][i]||{};return{press:o.press&&(!o.press_check||o.press_check(e))&&o.press||[],release:o.release||[],click:o.click&&(!o.click_check||o.click_check(e))&&o.click||[]}},activate:async function(e,t,i,o=[]){const n=this.action(e,t,i);if(n.click.length)await f.click(...n.click.map(e=>[m[e]]));if(n.press.length){const a=n.press.map(e=>m[e]);o=[...o.filter(e=>a.indexOf(e[0])==-1),...n.release.map(e=>[m[e]])];if(o.length)await f.releaseKey(...o);await f.pressKey(...a.map(e=>[e]))}},clear_list:function(e){return a.clear_list[e]},pressKey:async function(...e){let t=Array.isArray(e[0])&&e||[e];var i=[];for(const o of t){const n=o.filter(e=>!r[e]);if(n.length){for(const s of n)r[s]=-1;await _.pressKey(...n);const a=n.filter(e=>r[e]==-2);if(a.length){await _.releaseKey(...a);for(const s of a)r[s]=0;console.log("key released enforced",a.length)}}for(const s of o){if(r[s])r[s]=RAF_timestamp}}},releaseKey:async function(...e){const t=!e.length?Object.keys(r).map(e=>[parseInt(e)]):Array.isArray(e[0])&&e||[e];const i=[];for(const o of t){const n=o.filter(e=>r[e]>0);if(n.length){i.push(_.releaseKey(...n).then(()=>{for(const e of n)r[e]=0}))}const a=o.filter(e=>r[e]<0);a.forEach(e=>{r[e]=-2})}if(i.length){await Promise.all(i)}},releaseIdleKey:async function(...e){const t=!e.length?Object.keys(r).map(e=>[parseInt(e)]):Array.isArray(e[0])&&e||[e];const i=t.map(e=>e.filter(e=>r[e]&&(a.timeout_list.indexOf(e)==-1||RAF_timestamp-(r[e]>0?r[e]:RAF_timestamp)>500))).filter(e=>e.length);if(i.length){await f.releaseKey(...i)}},click:async function(...e){const t=Array.isArray(e[0])&&e||[e];await this.pressKey(...t);await this.releaseKey(...t)}}}();var M={custom:{},list:[],estimate:function(e,t,i=9){const o=e.estimate(t.keypoints,i);if(o.gestures.length){o.gestures.forEach(e=>{e._d=t._d;e.hand_facing=this.list[0].hand_facing[t._d];e.hand_rot_YXZ=this.list[0].hand_rot_YXZ[t._d];e.thumb_out=this.list[0].thumb_out[t._d];e.poseData=o.poseData});this.list[0].gestures=this.list[0].gestures.concat(o.gestures)}return o},search:function(i,n={}){function a(e){return e.gestures.find(t=>i.split("|").some(e=>t.name==e&&(!n.hand||n.hand._d==t._d)&&(!n.hand_facing||n.hand_facing===t.hand_facing)&&(n.thumb_out==null||n.thumb_out===t.thumb_out)&&(!n.condition||t._condition_passed||n.condition(t)&&(t._condition_passed=true))))}var e=n.time_limit||0;var t;for(let i=0,o=this.list.length;i=n.duration)break}else break}if(e{const t=M.list;for(let e=t.length-1;e>=0;e--){if(t[e].timestamp>RAF_timestamp-3e3){if(eMath.max(...o);var a,s;if(n){s=e.hand_rot_YXZ[1];if(s<=20)a="Horizontal Left";else if(s>20&&s<=50)a="Diagonal Down Left";else if(s>130&&s<=160)a="Diagonal Down Right";else if(s>160)a="Horizontal Right";else a="Vertical Down";if(!e.thumb_out&&/Horizontal/.test(a)){a="";s=0}}else{if(!e.thumb_out){a="";s=0}else{const r=-(i[3][1]-i[1][1]);const _=i[3][0]-i[1][0];s=Math.atan2(r,_)*180/Math.PI-90;if(s<-180)s+=360;s=-s;if(s>20&&s<=60)a="Diagonal Up Right";else if(s>60&&s<=120)a="Horizontal Right";else if(s<-20&&s>=-60)a="Diagonal Up Left";else if(s<-60&&s>=-120)a="Horizontal Left";else a="Vertical Up"}}return[a+"\n"+(i[1][1]>Math.max(...o))+"\n"+e.hand_rot_YXZ.join("\n"),s]}var E=function(){var i,o,n,e,a;return function(){if(e!=RAF_timestamp){e=RAF_timestamp;i=null;a=[];s().then(async e=>{[o,n]=await Promise.all([e.title,e.region]);i=e;const t={w:i,title:o,region:n};a.forEach(e=>{e(t)})})}return new Promise((e,t)=>{if(i){e({w:i,title:o,region:n})}else{a.push(e)}})}}();var k=["0","1","2","3"];var x=[];var P=[];const R={get enabled(){return a},set enabled(e){if(a==!!e)return;a=!!e;if(a){A()}else{this.setMousePosition(null)}DEBUG_show("Motion control:"+(a?"ON":"OFF"),3)},get enabled_nut(){return r},get ready(){return a&&!c},get handedness(){return h},get off_hand(){return h=="左"?"右":"左"},get window_active(){return window_active},get _debug_msg(){return x},get debug_msg(){return a&&x.length?x.join("\n")+"\n":""},get Key(){return m},get key_pressed(){return f.pressed},gestures:M,get plugins(){return P},add_plugin:function(e){if(P.indexOf(e)==-1)P.push(e)},process:async function(t){if(!this.ready)return;if(t.posenet_data){if(!M.list.length||M.list[0].timestamp!=RAF_timestamp){M.list.unshift({timestamp:RAF_timestamp,gestures:[]})}x=["Motion control"+(S?"(PAUSED)":"")+":"];const e=t.posenet_data.handpose;if(e&&e.length){const _={};const l={};const c={};e.forEach(e=>{if(!e._used)return;const t=System._browser.camera.poseNet.frames.skin[e._d+"手首"];if(!t)return;const i=MMD_SA.TEMP_v3.setEulerFromQuaternion(t[0].rot,"YXZ");l[e._d]=i.toArray().map(e=>e*180/Math.PI);_[e._d]=Math.abs(i.y)1.3*Math.abs(Math.abs(l[e._d][1])-90)/90+.2});M.list[0].hand_rot_YXZ=l;M.list[0].hand_facing=_;M.list[0].thumb_out=c;e.forEach(e=>{if(!r)return;if(!e._used)return;if(S){M.estimate(d,e);const t=M.search("index_up",{duration:1e3,hand_facing:"front",thumb_out:false});if(t){S=false;h=t._d;DEBUG_show("Motion control:READY",2)}}else if(e._d==h){M.estimate(d,e);const t=M.search("index_up",{duration:1e3,hand_facing:"back",thumb_out:false});if(t){S=true;DEBUG_show("Motion control:PAUSED",2)}}})}}else if(t.facemesh_data){}P.forEach(e=>{e.process(t)});if(!r)return;if(S)return;this.virtual_mouse.process(t);this.game01.process(t)},setMousePosition:function(){var t;return async function(e){if(e===null){t=null;return}if(!a)return;if(!r)return;if(e){t=e}else if(!e){return}await i.setPosition(t)}}(),game01:function(){var t,e;var i={id:"PSO2NGS",L:{thumb:{release:["Space","X"]},thumb_index:{press:["X"],release:["Space"]},thumb_palm:{press:["Space"],release:["X"]}},R:function(){function e(e){const t=f.temp.index_middle||0;const i=e.thumb_out?1:0;f.temp.index_middle=i;return t!=i}return{index_thumb:{press:["Tab"],press_check:function(){if(!f.temp.index_thumb)f.temp.index_thumb={};f.temp.index_thumb.clicked=true;return true}},index_up:{press:["Q"],press_check:function(){var e=f.temp.index_thumb&&f.temp.index_thumb.clicked;if(e)f.temp.index_thumb.clicked=false;return e}},index_middle1:{press:["Period"],click:["Semicolon"],click_check:e},index_middle2:{press:["Slash"],click:["Semicolon"],click_check:e},index_middle3:{press:["Quote"],click:["Semicolon"],click_check:e},thumb_palm:{press:["Backslash"]}}}()};var c;var o,n;function d(){if(e)return;c=new fp.GestureEstimator([M.custom.index_up,M.custom.index_thumb,M.custom.index_middle,M.custom.index_pinky,M.custom.palm_open,M.custom.thumb,M.custom.thumb_index,M.custom.thumb_palm]);f.set_options(i);e=true}return{get enabled(){return t},set enabled(e){t=e;if(t){f.set_options(i)}else{}},process:async function(i){if(!this.enabled){await f.releaseKey();return}d();const a=await E();const e=await a.title;if(i.facemesh_data&&i.head_rot){let e=i.head_rot.x*180/Math.PI;let t=i.head_rot.y*180/Math.PI;let o=Math.round(Math.sign(e)*Math.pow(Math.min(Math.max((Math.abs(e)-8)/15,0),1),2)*40);let n=Math.round(Math.sign(t)*Math.pow(Math.min(Math.max((Math.abs(t)-10)/20,0),1),2)*40);x.push(e,t,n,o);Promise.resolve(a.region).then(async e=>{const t=await p(e);const i=e.width-1280<64?[1280,720]:[1920,1080];t.y+=Math.round((e.height-i[1]-(e.width-i[0]))/2);t.x+=n;t.y+=o;t.y+=1;t.x+=1;await R.setMousePosition(t)})}let t;if(i.posenet_data){t=i.posenet_data.handpose;let e="";if(!t||!t.length){t=null;if(M.search("palm_open",{time_limit:500,hand_facing:"front",condition:()=>{}})){e+="/CANCEL";await f.releaseKey()}else{await f.releaseIdleKey()}}x.push((t?"":"(no hand data)")+e+"/key active:"+Object.keys(f.pressed).filter(e=>f.pressed[e]).join(","))}if(!t)return;for(const n of t){if(!n._used)continue;const s=n._d==h?"R":"L";x.push(s+":");M.estimate(c,n);let i;i=M.search("palm_open",{hand:n,hand_facing:"front",condition:function(e){const t=this.hand;const i=y.fromArray(t.annotations.index[0]).sub(g.fromArray(t.annotations.index[3]));const o=b.fromArray(t.annotations.pinky[0]).sub(v.fromArray(t.annotations.pinky[3]));return i.angleTo(o)*180/Math.PI>30}});if(i){x.push("CANCEL");await f.releaseKey(...f.clear_list(s));continue}if(n._d==h){i=M.search("index_thumb",{hand:n,hand_facing:"back",thumb_out:true});if(i){await f.activate(i,s,i.name,f.clear_list(s));x.push("index_thumb");continue}i=M.search("index_up",{hand:n,hand_facing:"front",thumb_out:true});if(i){await f.activate(i,s,i.name,f.clear_list(s));x.push("index_up");continue}i=M.search("index_middle",{hand:n});if(i){let e=i.name;switch(i.poseData[1][2]){case"Vertical Up":e+=2;break;case"Diagonal Up Left":e+=h=="右"?1:3;break;case"Diagonal Up Right":e+=h=="右"?3:1;break}await f.activate(i,s,e,f.clear_list(s));x.push(e);continue}i=M.search("thumb_palm",{hand:n,condition:function(e){if(!/(Horizontal|Diagonal Up)/.test(e.poseData[2][2]))return false;const t=this.hand;const i=y.fromArray(t.annotations.index[0]).sub(g.fromArray(t.annotations.index[3]));const o=b.fromArray(t.annotations.pinky[0]).sub(v.fromArray(t.annotations.pinky[3]));return i.angleTo(o)*180/Math.PI<20}});if(i){await f.activate(i,s,i.name,f.clear_list(s));x.push("thumb_palm");continue}i=M.search("thumb",{hand:n});if(i){x.push("CANCEL");await f.releaseKey(...f.clear_list(s));continue}i=M.search("index_pinky",{hand:n});if(i){x.push("index_pinky");continue}}else{i=M.search("thumb_palm|thumb_index|thumb",{hand:n,condition:function(e){if(e.name!="thumb_palm")return true;const t=this.hand;const i=y.fromArray(t.annotations.index[0]).sub(g.fromArray(t.annotations.index[3]));const o=b.fromArray(t.annotations.pinky[0]).sub(v.fromArray(t.annotations.pinky[3]));return i.angleTo(o)*180/Math.PI<20}});if(i){const r=D(i,n);const _=r[0];let e=[];let t=[];switch(_){case"Vertical Up":e.push("W");t.push("A","S","D");break;case"Diagonal Up Right":e.push("W","A");t.push("S","D");break;case"Horizontal Right":e.push("A");t.push("W","S","D");break;case"Diagonal Up Left":e.push("W","D");t.push("A","S");break;case"Horizontal Left":e.push("D");t.push("W","A","S");break;case"Diagonal Down Right":e.push("S","A");t.push("W","D");break;case"Diagonal Down Left":e.push("S","D");t.push("W","A");break;case"Vertical Down":e.push("S");t.push("W","A","D");break;default:t.push("W","A","S","D")}var o=f.action(i,s,i.name);if(o.press.length)e.push(...o.press);if(o.release.length)t.push(...o.release);if(e.length)await f.pressKey(...e.map(e=>[m[e]]));if(t.length)await f.releaseKey(...t.map(e=>[m[e]]));x.push([i.name,_].join("/")+"/"+RAF_timestamp);continue}}if(!i)await f.releaseIdleKey(...f.clear_list(s))}for(const l of[[0,t.findIndex(e=>e._used&&e._d==h)],[1,t.findIndex(e=>e._used&&e._d!=h)]]){if(l[1]!=-1)continue;const s=l[0]==0?"R":"L";if(M.search("palm_open",{time_limit:500,hand:{_d:l[0]==0?h:R.off_hand},hand_facing:"front",condition:()=>{}})){await f.releaseKey(...f.clear_list(s))}else{await f.releaseIdleKey(...f.clear_list(s))}}}}}(),virtual_mouse:function(){var e;var t;function p(){if(e)return;t=new fp.GestureEstimator([fp.Gestures.VictoryGesture,fp.Gestures.ThumbsUpGesture,M.custom.index_up]);e=true}return{enabled:false,process:async function(e){if(!this.enabled)return;if(!e.posenet_data)return;p();const t=e.posenet_data.handpose;if(!t||!t.length)return;const i=t[0]._d==h?0:1;const o=h=="右"?0:1;if(!t[i]||!t[i]._used)return;const n=screen.width/2;const a=screen.height/2;const s=System._browser.camera.video_canvas;const r=s.width/s.height/(n/a);const _=.5;const l=t[i].annotations.index[0];const c={x:-(-s.width/2+l[0])/(s.width/2*_),y:(-s.height/2+l[1])/(s.height/2*_)};c.x=Math.round(n+THREE.Math.clamp(c.x*r,-1,1)*n);c.y=Math.round(a+THREE.Math.clamp(c.y/r,-1,1)*a);const d=new u(c.x,c.y);await R.setMousePosition(d)}}}()};return R}(),snapshot:function(){var i=false;var o=false;var n;var a;function s(){const e=MMD_SA.THREEX.SL;const t=System._browser.camera;var i=Math.ceil(3-(Date.now()-n)/1e3);if(i<=0){if(!t.visible){l(e);return}DEBUG_show("Capturing...");if(!t.stream){if(!t.bodyPix.enabled){r();return}o=true}else{t.target_devicePixelRatio=1;t.video_track.applyConstraints(t.set_constraints()).then(function(){System._browser.console.log("(Ready to capture)");System._browser.on_animation_update.add(function(){MMD_SA._renderer.devicePixelRatio=window.devicePixelRatio;MMD_SA._renderer.__resize(EV_width,EV_height);if(!t.bodyPix.enabled){System._browser.on_animation_update.add(function(){r()},0,1);return}o=true},0,0)})["catch"](function(e){DEBUG_show("ERROR:camera size failed to update");_()})}System._browser.on_animation_update.remove(s,0)}else if(a!=i){a=i;DEBUG_show(a)}}function r(){const e=MMD_SA.THREEX.SL;const t=System._browser.camera;let i=t.video_canvas_bodyPix;i.width=e.width;i.height=e.height;let o=i.getContext("2d");o.globalCompositeOperation="source-over";const n=t.video_canvas.width;const a=t.video_canvas.height;const s=Math.min(e.width/n,e.height/a);const r=Math.round(n*s);const _=Math.round(a*s);o.drawImage(t.video_canvas,0,0,n,a,(e.width-r)/2,(e.height-_)/2,r,_);if(t.face_detection.enabled)o.drawImage(t.video_canvas_face_detection,0,0);o.save();o.translate(i.width,0);o.scale(-1,1);o.drawImage(e,0,0);o.restore();l(i)}function l(e){i=true;o=false;System._browser.on_animation_update.remove(s,0);e.toBlob(function(e){if(webkit_electron_mode){System._browser.save_file("snapshot_"+Date.now()+".png",e)}else{const t=URL.createObjectURL(e);window.open(t)}_()})}function _(){const e=System._browser.camera;Ldebug.style.posLeft=Ldebug.style.posTop=0;Ldebug.style.transform=Ldebug.style.transformOrigin="";DEBUG_show();o=false;e.target_devicePixelRatio=0;i=false}const e={init:function(){if(i){return true}const e=MMD_SA.THREEX.SL;const t=System._browser.camera;if(MMD_SA.WebXR.session){let e=MMD_SA_options.WebXR&&MMD_SA_options.WebXR.AR;if(!e.dom_overlay||!e.dom_overlay.use_dummy_webgl){DEBUG_show("(No snapshot in AR WebGL)",3);return true}}if(!t.visible){l(e)}else{i=true;n=Date.now();Ldebug.style.posLeft=Ldebug.style.posTop=50;Ldebug.style.transformOrigin="0 0";Ldebug.style.transform="scale(5,5)";a=3;DEBUG_show();DEBUG_show(a);System._browser.on_animation_update.add(s,0,0,-1)}},check_bodyPix:function(){if(!i)return false;const e=System._browser.camera;if(o){l(e.video_canvas_bodyPix)}return true}};return e}(),video_capture:(()=>{const l=document.createElement("canvas");function r(){const e=u.get_specs();l.width=e.width;l.height=e.height;u._fps=e.fps;u.mime_type=e.mime_type;System._browser.on_animation_update.add(t,0,1,-1)}function t(){const e=MMD_SA.THREEX.SL;const t=l.getContext("2d");if(MMD_SA.music_mode){const i=SL_MC_video_obj.vo.media_linked&&SL_MC_video_obj.vo.media_linked.find(e=>e.id=="motion_bg_video");if(i&&i.style.visibility!="hidden"){const o=Math.min(i.videoWidth/i.videoHeight,l.width/l.height);const n=Math.round(Math.min(i.videoWidth,i.videoHeight)*o);const a=Math.min(n,i.videoWidth);const s=Math.min(n,i.videoHeight);const r=(i.videoWidth-a)/2;const _=(i.videoHeight-s)/2;t.drawImage(i,r,_,a,s,0,0,l.width,l.height)}}else{t.fillStyle=document.body.style.backgroundColor||"white";t.fillRect(0,0,l.width,l.height)}if(l.width==e.width&&l.height==e.height){t.drawImage(e,0,0)}else{t.drawImage(e,0,0,l.width,l.height)}}let _;function c(){if(!u.media_recorder||u.started)return;u.started=true;u.media_recorder.start();if(_&&u.stream.getAudioTracks().length&&(MMD_SA.music_mode?SL_MC_video_obj.vo.audio_obj.paused:MMD_SA.motion_player_control.enabled&&MMD_SA.motion_player_control.paused)){SL_MC_Play()}}function d(){System._browser.video_capture.stop()}var p=[];const u={enabled:false,started:false,fps:undefined,target_width:undefined,target_height:undefined,FFmpeg:(()=>{var e;var t;var n;var a;const i={enabled:webkit_electron_mode,load:async function(){if(e)return;e=true;return new Promise(o=>{n=new Worker("js/ffmpeg_worker.js");n.onmessage=e=>{const t=e.data;if(typeof t==="string"){if(t=="OK"){o()}}else{const i=new Blob([t.buffer],{type:t.output_type});return a(i)}}})},encode:async function(...e){await this.load();const t={inputs:[]};for(const i of e){if(i.blob)i.blob=await i.blob.arrayBuffer();t.inputs.push(i)}n.postMessage(t,t.inputs.filter(e=>e.blob).map(e=>e.blob));return new Promise(e=>{a=e})}};return i})(),get_specs:function(){const e=MMD_SA.THREEX.SL;const t=e.width*e.height;let i=this.target_width,o=this.target_height,n=this.fps;if(!i){if(is_mobile){i=1280;o=720;if(e.widthi*o){const _=Math.min(i/e.width,o/e.height);i=Math.min(Math.round(e.width*_/4)*4,i);o=Math.min(Math.round(e.height*_/4)*4,o)}else{i=e.width;o=e.height}const a=["video/webm;codecs=h264","video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm"];let s;for(const l of a){if(MediaRecorder.isTypeSupported(l)){s=l;break}}return{width:i,height:o,fps:n,mime_type:s}},start:function(){if(this.busy){DEBUG_show("(Media recorder still in use)",3);return}if(this.enabled)return;this.enabled=true;r();const e=this._fps==-1?undefined:this._fps;const t=l.captureStream(e);this.stream=new MediaStream;this.stream.addTrack(t.getTracks()[0]);this.audio_src=MMD_SA.music_mode&&SL_MC_video_obj.vo.audio_obj.src;if(this.audio_src&&(!this.FFmpeg.enabled||this.target_mime_type||!SL_MC_video_obj.vo.motion_by_song_name_mode||SL_MC_video_obj.vo.audio_obj.currentTime)){const n=SL_MC_video_obj.vo.audio_obj.captureStream();this.stream.addTrack(n.getTracks()[0])}this.file_ext="."+(this.mime_type.indexOf("x-matroska")!=-1?"mkv":this.mime_type.replace(/^.+[\/]/,"").replace(/\;.+$/,""));this.media_recorder=new MediaRecorder(this.stream,{videoBitsPerSecond:l.width*l.height*4,mimeType:this.mime_type});p.length=0;this.media_recorder.addEventListener("dataavailable",async e=>{p.push(e.data);if(!this.enabled){let e=new Blob(p,{type:this.mime_type});this.stream.getTracks().forEach(e=>{e.stop()});let t=this.file_ext;this.busy=true;if(this.FFmpeg.enabled&&/h264/.test(this.mime_type)&&!this.target_mime_type){try{DEBUG_show("Encoding MP4...");const o=[{name:"video",blob:e}];if(this.audio_src){const n={name:"audio"};if(!this.stream.getAudioTracks().length)n.blob=await fetch(this.audio_src).then(e=>e.blob());o.push(n)}e=await this.FFmpeg.encode(...o);t=".mp4"}catch(i){console.error(i);this.FFmpeg.enabled=false}}this.busy=false;p.length=0;DEBUG_show("🔴Video Capture:OFF",5);System._browser.save_file("video_"+Date.now()+t,e)}});const i=new Promise(e=>{_=e;this.media_recorder.addEventListener("start",()=>{DEBUG_show();DEBUG_show("🔴Video Capture:ON ("+(l.width+"x"+l.height+(u._fps>-1?"/"+u._fps+"fps":""))+"/"+u.mime_type+")",10);if(MMD_SA.music_mode?SL_MC_video_obj.vo.audio_obj.paused:MMD_SA.motion_player_control.enabled&&MMD_SA.motion_player_control.paused){SL_MC_Play()}_();_=null},{once:true})});DEBUG_show();const o=MMD_SA.THREEX.get_model(0).animation.time;if(o||(MMD_SA.music_mode?!SL_MC_video_obj.vo.motion_by_song_name_mode||!SL_MC_video_obj.vo.audio_obj.paused:!MMD_SA.motion_player_control.enabled||!MMD_SA.motion_player_control.paused)){c()}else{if(u.audio_src){window.addEventListener("SA_audio_onended",e=>{System._browser.video_capture.stop()},{once:true})}else if(MMD_SA.motion_player_control.enabled){const s=MMD_SA.THREEX.get_model(0).animation;if(s.enabled){s.mixer.addEventListener("loop",d,{once:true});s.mixer.addEventListener("finished",d,{once:true})}else{window.addEventListener("SA_MMD_model0_onmotionended",d,{once:true})}}const a=MMD_SA_options.reset_rigid_body_physics_step;MMD_SA_options.reset_rigid_body_physics_step=0;new Promise(e=>{DEBUG_show("(Resetting physics)",3);let t=60*3;System._browser.on_animation_update.add(()=>{MMD_SA.seek_motion(o,true);if(MMD_SA.THREEX.get_model(0).animation.enabled)THREE.MMD.getModels()[0].seekMotion(0);if(--t==0)e()},0,0,t)}).then(()=>{MMD_SA.seek_motion(o);if(MMD_SA.motion_player_control.enabled){MMD_SA.motion_player_control.pause()}else{jThree.MMD.pause()}MMD_SA_options.reset_rigid_body_physics_step=a;c()})}DEBUG_show("🔴Video Capture",3);return i},stop:function(){if(!this.media_recorder)return;if(!this.enabled)return;this.enabled=false;System._browser.on_animation_update.remove(t,1);const e=MMD_SA.THREEX.get_model(0).animation;if(e.enabled){e.mixer.removeEventListener("loop",d);e.mixer.removeEventListener("finished",d)}else{window.removeEventListener("SA_MMD_model0_onmotionended",d)}this.media_recorder.stop();this.media_recorder=undefined;this.started=false},pause:function(){if(this.started&&this.media_recorder.state!="paused")this.media_recorder.pause()},resume:function(){if(this.started&&this.media_recorder.state=="paused")this.media_recorder.resume()}};return u})(),hotkeys:(()=>{class s{constructor(e,t){this.id=e.id;this.index=t;this.config=s.config_by_id[this.id]=e;this.event={};this.accelerator=e.accelerator[t];const i=this.accelerator.split("+");i.forEach(e=>{if(/^(Cmd|Command|Ctrl|Control)$/.test(e)){this.event.ctrlKey=true}else if(e=="Shift"){this.event.shiftKey=true}else if(e=="Alt"){this.event.altKey=true}else if(/^[0-9]$/.test(e)){this.event.code="Digit"+e}else if(/^num([0-9])$/.test(e)){this.event.code="Numpad"+RegExp.$1}else if(/^[A-Z]$/.test(e)){this.event.code="Key"+e}})}static config_by_id={};static get_config(e){return s.config_by_id[e]}static accelerators={};static register(e,t,i){if(!s.unregister(e))return false;const o=s.get_config(e);if(i)Object.assign(o,i);o.accelerator=t;t.forEach((e,t)=>{s.accelerators[e]=new s(o,t)});return s.enable_global(e)}static unregister(e){const t=s.get_config(e);if(!t)return false;t.accelerator.forEach(e=>{if(s.accelerators[e].is_global){try{webkit_electron_remote.globalShortcut.unregister(e)}catch(t){}}delete s.accelerators[e]});return true}static enable_global(e,o){if(!webkit_electron_mode)return true;const t=s.get_config(e);if(!t)return;let n=o==null?!!s.accelerators[t.accelerator[0]].config.global_disabled:!o;o=n?false:s.is_global;let a=true;t.accelerator.forEach(e=>{const t=s.accelerators[e];t.config.global_disabled=n;try{if(o){if(!t.is_global&&!t.config.global_disabled)webkit_electron_remote.globalShortcut.register(e,()=>{SA_topmost_window.SA_OnKeyDown(t.event)})}else{if(t.is_global)webkit_electron_remote.globalShortcut.unregister(e)}t.is_global=webkit_electron_remote.globalShortcut.isRegistered(t.accelerator);if(a&&o&&!t.config.global_disabled)a=t.is_global}catch(i){}});return a}static remove(e){if(s.unregister(e))delete s.config_by_id[e]}static add(i){s.remove(i.id);i.accelerator.forEach((e,t)=>{s.accelerators[e]=new s(i,t)});s.enable_global(i.id)}static _is_global=null;static get is_global(){return this._is_global==null?true:this._is_global}static set is_global(e){this._is_global=e}static disabled=false;static register_global(i){if(browser_native_mode){DEBUG_show("(Global hotkey is for app mode only.)",5);return}s.is_global=i==null?s.is_global:i;DEBUG_show("Global hotkey:"+(i?"ON":"OFF"),3);Object.values(s.accelerators).forEach(e=>{try{if(i){if(!e.is_global&&!e.config.global_disabled)webkit_electron_remote.globalShortcut.register(e.accelerator,()=>{SA_topmost_window.SA_OnKeyDown(e.event)})}else{if(e.is_global)webkit_electron_remote.globalShortcut.unregister(e.accelerator)}e.is_global=webkit_electron_remote.globalShortcut.isRegistered(e.accelerator)}catch(t){}})}}window.addEventListener("SA_keydown",o=>{if(s.disabled)return;const n=o.detail.e;Object.values(s.config_by_id).some(e=>{const t=e.accelerator.some(e=>{const t=s.accelerators[e].event;if(t.code&&t.code!=n.code)return false;if(t.ctrlKey&&!n.ctrlKey)return false;if(t.shiftKey&&!n.shiftKey)return false;if(t.altKey&&!n.altKey)return false;return true});if(t){const i=e.process(o);if(i!==false)o.detail.result.return_value=true;return true}})});return s})(),load_script:function(){var n={};var a=function(e,t){this.url=e;this.name=e.replace(/^.+[\/\\]/,"");this.loaded=false;this.resolve_list=[];this.reject_list=[];if(t){const i=this;import(e).then(e=>{i.module=e;i.check_loaded()})}else{const o=document.createElement("script");o.onload=this.check_loaded.bind(this);o.src=e;document.head.appendChild(o)}};a.prototype.check_loaded=function(){this.loaded=true;console.log(this.name+" loaded");this.resolve_list.forEach(e=>{e(this.module)})};a.prototype.make_promise=function(e,t){this.resolve_list.push(e);if(t)this.reject_list.push(t)};return function(e,t){var i=e.replace(/^.+[\/\\]/,"");var o=n[i]=n[i];if(o){if(o.loaded)return Promise.resolve(o.module)}else{o=n[i]=new a(e,t)}return new Promise((e,t)=>{o.make_promise(e,t)})}}(),save_file:function(){var a;return function(e,t,i){const o=!i?t:new Blob([t],{type:i});const n=URL.createObjectURL(o);if(!a){a=document.createElement("a");a.style.display="none";document.body.appendChild(a)}else{URL.revokeObjectURL(a.href)}a.href=n;a.download=e||"";a.click()}}(),update_obj_url:async function(t,i){if(/^(.+\.zip)\#[\/\\](.+)$/i.test(t)){const e=SA_topmost_window.DragDrop._obj_url[t];if(!e||t==e){const o=XMLHttpRequestZIP.zip_by_url(RegExp.$1);let e=await o.file(RegExp.$2.replace(/\\/g,"/"))["async"]("blob");if(i)e=new Blob([e],{type:i});console.log("Object URL (inside zip) updated",t);SA_topmost_window.DragDrop._obj_url[t]=SA_topmost_window.URL.createObjectURL(e)}}},skip_background_rendering:true,skip_rendering:false,rendering_check:function(){if(this.skip_rendering&&!this.hidden)return false;if(!returnBoolean("DisableBackgroundThrottling"))return true;const e=this.skip_background_rendering&&this.hidden;let t=document.getElementById("canvas_DisableBackgroundThrottling");if(e){if(!t){t=document.createElement("canvas");t.id="canvas_DisableBackgroundThrottling";t.width=t.height=1;t.style.position="absolute";t.style.posLeft=t.style.posTop="0px";t.style.zIndex=9999;document.getElementById("Lbody_host").appendChild(t)}t.getContext("2d").clearRect(0,0,t.width,t.height)}if(t)t.style.visibility=e?"inherit":"hidden";return!e},console:{content_list:[],log:function(){for(var e=0;e{var t,n,i;const o=navigator.language+"-default";var a;var e={ja:'"Meiryo UI"',zh:'"Microsoft JhengHei UI"'};const s={get language(){return n},set language(e){t=e||o;n=t.split("-")[0].toLowerCase();if(t==o){i="System default"}else{switch(n){case"en":i="English";break;case"ja":i="日本語";break;case"zh":i="繁體中文";break;default:i="System default"}}},get language_full(){return t},get language_info(){return i},get language_default(){return o},get dictionary(){return a},set dictionary(e){a=Object.assign(a||{},e)},get font(){return e[n]},get:function(e,t=n){if(!a)return"(Now loading...)";let i=a;e.split(".").every(e=>{i=i[e];return i});const o=i&&(i._translation_?.[t]||i._translation_?._default_);return o!=null?o:"("+e+")"}};s.language=null;return s})(),DEBUG_show:function(){const t=self.DEBUG_show;self.DEBUG_show=function(...e){if(System._browser.overlay_mode>0){if(!e.length)t()}else{t(...e)}};return t}()},_hash_sha256:{_hash_cache:{},hash:function(e){if(webkit_electron_mode){var t=webkit_electron_remote.getGlobal("HASH_SHA256");if(t)return t.hash(e)}var i=this._hash_cache[e];if(i)return i;var o=require("crypto").createHash("sha256");o.update(e);i=this._hash_cache[e]=o.digest("hex");return i}},_media_objs_paused_:[],_gadget_resume:function(e){if(e&&!SA_topmost_window.EV_sync_update.RAF_auto_paused)return false;if(!SA_topmost_window.EV_sync_update.RAF_paused)return false;SA_topmost_window.EV_sync_update.RAF_paused=false;SA_topmost_window.EV_sync_update.RAF_auto_paused=false;SA_topmost_window.System._media_objs_paused_.forEach(function(e){if(e.SL_MC_Play)e.SL_MC_Play();else if(e.paused)e.play()});SA_topmost_window.System._media_objs_paused_=[];System._browser.update_tray();return true},_gadget_pause:function(e){if(SA_topmost_window.EV_sync_update.RAF_paused)return false;SA_topmost_window.EV_sync_update.RAF_paused=true;SA_topmost_window.EV_sync_update.RAF_auto_paused=e;var s=SA_topmost_window.System._media_objs_paused_;var t=[top];for(var i=0;i