From 9f274b7ab8c55953307afa31071e969c47ca7d6a Mon Sep 17 00:00:00 2001 From: ButzYung Date: Tue, 27 Jun 2023 23:34:04 +0800 Subject: [PATCH] Update SA_system_emulation.min.js --- js/SA_system_emulation.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/SA_system_emulation.min.js b/js/SA_system_emulation.min.js index cb36ed1..a6fc786 100644 --- a/js/SA_system_emulation.min.js +++ b/js/SA_system_emulation.min.js @@ -1,2 +1,2 @@ // (2023-06-24) -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)}}}();SA_top_window.moveToAbsolute=function(e,t,i){if(absolute_screen_mode&&!i){webkit_window.setPosition(~~e,~~t)}else{this.moveTo(e,t)}};SA_top_window.moveByAbsolute=function(t,i){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;function n(){document.getElementById("Ldungeon_inventory").style.visibility=document.getElementById("Ldungeon_inventory").style.visibility=="hidden"?"inherit":"hidden"}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";document.body.addEventListener("dblclick",n);DEBUG_show("(NOTE: Double-click to show the menu)",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";document.body.removeEventListener("dblclick",n)}}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 h;var d,c;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)h=parent.WMP_wallpaper_mask}else{var u;if(!is_SA_child_animation){d=System.Gadget.Settings.readString("_screenLeft");c=System.Gadget.Settings.readString("_screenTop")}d=d?parseInt(d):null;c=c?parseInt(c):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 p,m,f;var n=LdesktopBG.style;try{n.pixelWidth=parent.screen.width;n.pixelHeight=parent.screen.height;var g=oShell.RegRead("HKCU\\Control Panel\\Colors\\Background");n.backgroundColor=/^\#/.test(g)?g:"rgb("+g.replace(/\W+/g,",")+")";p="HKCU\\Control Panel\\Desktop\\";if(WallpaperEngine_CEF_mode)m=oShell.RegRead(p+"Wallpaper")||self.SA_wallpaper_src&&/\.(png|bpm|jpg|jpeg)$/i.test(SA_wallpaper_src)&&SA_wallpaper_src;else m=self.SA_wallpaper_src==""?"":self.SA_wallpaper_src&&/\.(png|bpm|jpg|jpeg)$/i.test(SA_wallpaper_src)&&SA_wallpaper_src||oShell.RegRead(p+"Wallpaper");if(m){if(!this.wallpaper_mask_disabled){h=self.SA_wallpaper_mask_src||m.replace(/\.\w{3,4}$/,"_mask.png");if(!ValidatePath(h))h=null}f=oShell.RegRead(p+"WallpaperStyle");this.updateWallpaper(m,f)}if(D){this.updateWallpaper(D)}this.moveWallpaper(d||0,c||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(h){if(!this.bg_mask)this.bg_mask="(blank)"}else{u=true}}else{u=true}if(u&&this.Opacity<1&&(w3c_mode||HTA_use_GPU_acceleration)){this.body.style.opacity=this.Opacity;DEBUG_show("Opacity:"+this.Opacity*100+"%",2)}}if(l&&!h)this.bg_mask="(blank)";if(a&&(h||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 M=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,c){v.fillStyle=n.backgroundColor;v.fillRect(0,0,M,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(c=="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,d,c;if(i>e){n=0;_=(i-e)/2;s=d=e}else{n=(e-i)/2;_=0;s=d=i}if(o>t){a=0;l=(o-t)/2;r=c=t}else{a=(t-o)/2;l=0;r=c=o}var u=C_wallpaper_mask.getContext("2d");u.drawImage(this,n,a,s,r,_,l,d,c);System._browser.BGMask_Create(!h);if(!h)return;var p=new Image;p.onload=function(){var e=C_wallpaper_mask.getContext("2d");e.globalCompositeOperation="destination-in";e.drawImage(this,n,a,s,r,_,l,d,c);C_wallpaper_mask.style.visibility="inherit";DEBUG_show("Use wallpaper mask",2)};p.src=toFileProtocol(h)}}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(c=="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(!h);if(!h)return;var d=new Image;d.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)};d.src=toFileProtocol(h)}}if(w)w.onload=null;w=new Image;w.onload=t;w.src=toFileProtocol(e)}}this.wallpaper_canvas_update(m,f);if(!m){setTimeout("System._browser.BGMask_Create(true)",0)}}catch(A){}}var S=y.style;S.position="absolute";S.posLeft=-(d||0);S.posTop=-(c||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(!h);this.WMPMask_Draw()}}this._s_left=d;this._s_top=c},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 d=i.style;d.position="absolute";d.top=d.left="0px";d.width=parent.screen.width+"px";d.height=parent.screen.height+"px";d.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 d=this.bg_mask_image_resized;if(d&&d.width!=i){d.width=i;d.height=o;var c=this.bg_mask_image;d.getContext("2d").drawImage(c,0,0,c.width,c.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 u=parent.SA_child_animation[SA_child_animation_id];var p=u.x;var h=u.y;if(is_SA_child_animation&&parent.EQP_border_width){p-=parent.EQP_border_width;h-=parent.EQP_border_width}var m=p-n;var f=m;if(m<0)m=0;if(f<0)f=-f;else f=0;var g=h-a;var y=g;if(g<0)g=0;if(y<0)y=-y;else y=0;var M=s+n-p;if(M>i)M=i;var b=r+a-h;if(b>o)b=o;var v=this.C_WMP_wallpaper_mask_mixed_resized;if(v.width!=i||v._x!=m||v._y!=g){v.width=i;v.height=o;var w=v.getContext("2d");w.drawImage(_,m,g,M,b,f,y,M,b);if(d)w.drawImage(d,0,0);v._x=m;v._y=g}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,m,g,M,b,f,y,M,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-m)/(l+1);y=1-(1-y)*g;if(y<0)y=0;var M=1;if(f=s-l)M=(s-f)/(l+1);M=1-(1-M)*g;if(M<0)M=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}c[u]=t?Math.round(255*(1-b)):Math.round(255*b)}_.putImageData(d,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 d=a+","+s+","+o+","+n+","+r+","+_+","+o+","+n;if(e._match_str==d)return;e._match_str=d;e.width=t;e.height=i;var c=e.getContext("2d");c.globalCompositeOperation="copy";c.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 c=C_BG_mask.getContext("2d");c.globalCompositeOperation="copy";c.globalAlpha=this.bg_mask_image?1:1-this.Opacity;c.drawImage(this.wallpaper_canvas,a,s,o,n,r,_,o,n);if(this.bg_mask_image){c.globalCompositeOperation="destination-out";c.globalAlpha=this.Opacity;c.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,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.clientY=49&&n<49+SA_child_animation_max)&&o){var _=n-49;var l=is_SA_child_animation?parent:self;var d=l.document.getElementById("Ichild_animation"+_);if(!d||!d.contentWindow.is_SA_child_animation){DEBUG_show("(child animation "+(_+1)+" not found)",2);return true}var c=d.contentWindow;var u=c.parent;var p=u.System._browser;if(c.System.Gadget.Settings.readString("CSSTransform3D")||u.System.Gadget.Settings.readString("CSSTransform3D")){if(p._child_selected==_){p._child_selected=null;c.DEBUG_show("(deselected)",2);u.DEBUG_show("(child"+(_+1)+" deselected)",2);return true}p._child_selected=_}c.DEBUG_show("(selected)",2);u.DEBUG_show("(child"+(_+1)+" selected)",2);p.arrangeChildZ(_);c.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 d=l.document.getElementById("Ichild_animation"+_);if(!d||!d.contentWindow.is_SA_child_animation){DEBUG_show("(child animation "+(_+1)+" not found)",2);return true}var s=d.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 h=false;for(var m=0;m=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._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.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;if(WallpaperEngine_mode||browser_native_mode){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 d=s.x+t-this.drag_mouse_x;var c=s.y+i-this.drag_mouse_y;r.posLeft=s.x=d;r.posTop=s.y=c;o.document.getElementById("Ldebug").innerText=n.document.getElementById("Ldebug").innerText="(moving)";o.DEBUG_hide_sec=n.DEBUG_hide_sec=0;o.DEBUG_show("("+d+","+c+")",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 c={};var u={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=c[o]=c[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;break;case"↓":a=40;break;case"←":a=37;break;case"→":a=39;break;default:if(/([1-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:c["S"]&&c["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,d,c;var u=this.content_window.ChatboxAT.checkChatCommand(e);l=u.command;d=u.para1;c=u.para2;_=i.para.events.send_message({name:s,msg:e,command:l,para1:d,para2:c,id:o,pass:n})}if(!t)this.content_window.document.getElementById("Fchat").msg.value="";if(_!=null)return _;return e}};return t}(),camera:function(){var re;var d,r;var c;var _e,le;var de;var Z;var E=true;var n=new URLSearchParams(self.location.search.substring(1));var ce="";var ue="";var a=true;var s;var A=0;var D="";function _(){var s=re.video;if(!s.videoWidth||s.readyState<2){return}if(c.busy||RAF_animation_frame_unlimited&&!MMD_SA.WebXR.session&&D==re.video_frame_id&&!de.bb_clear){return}D=re.video_frame_id;A=RAF_timestamp;var n=re.video_canvas;var r=n.getContext("2d");if(de.bb_clear){if(s.pause&&!s.paused||--de.bb_clear<=0||de._bb&&de._bb_waiting){de.bb_clear=de._bb=de._bb_waiting=null;r.globalCompositeOperation="copy"}else{if(de._bb){r.globalCompositeOperation="source-over";r.fillStyle="black";let e=Math.max(de._bb[3],0);let t=Math.max(de._bb[0],0);const _=Math.min(de._bb[1]-e,n.width);const l=Math.min(de._bb[2]-t,n.height);if(re.video_flipped){e=n.width-(e+_)}r.fillRect(e,t,_,l);de._bb=null;de._bb_waiting=true}return}}var _,l;if(re.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{_=re.target_width;l=re.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*(re.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(re.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=!re.visible||c.enabled||d.initialized&&d.worker_initialized&&!d.dets||re.hidden_enforced?"hidden":"inherit"}function l(){if(c.enabled){c.update_frame()}else{if(_e.enabled){_e.update_frame(true)}else if(d.enabled){d.update_frame(true)}if(de.enabled||Z.enabled){Le(true)}}const i=re.video_canvas_facemesh.style;const e=re.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=re.ML_enabled&&!MMD_SA_options.user_camera.display.wireframe.hidden&&!MMD_SA_options.user_camera.display.webcam_as_bg?"inherit":"hidden"}var k;function g(){if(re.initialized){SL.style.transform=SL_2D_front.style.transform=re.mirror_3D?"scaleX(-1)":"none";re.video_canvas.style.transform=re.display_flipped?"scaleX(-1)":"none";re.reset_video_canvas()}if(!k&&re.initialized){k=true;System._browser.on_animation_update.add(_,0,0,-1);System._browser.on_animation_update.add(l,2,1,-1)}}function y(){SL.style.transform=SL_2D_front.style.transform=re.mirror_3D?"scaleX(-1)":"none";re.video_canvas.style.transform="none";re.reset_video_canvas();if(re.visible)return;if(k&&!re.ML_enabled){k=false;System._browser.on_animation_update.remove(_,0);System._browser.on_animation_update.remove(l,1);re.video_canvas_facemesh.style.visibility="hidden"}}var o=100;function M(e){if(!re.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=re.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 b=0;function v(e){if(!e)e=re.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(!re._image){re._image=new Image;Object.defineProperty(re._image,"videoWidth",{get:function(){return this.width}});Object.defineProperty(re._image,"videoHeight",{get:function(){return this.height}});Object.defineProperty(re._image,"readyState",{get:function(){return this.complete?4:0}})}if(re.video&&re.video.pause)re.video.pause();re.video=re._image;re._image.src=toFileProtocol(e)}else{re.video=re._video;re.video.loop=true;if(!re.video._initialized){re.video._initialized=true;re.video.addEventListener("canplaythrough",function(e){re.video.muted=true;re.media_control_enabled=true;SL_MC_simple_mode=true;SL_MC_video_obj=re.video;SL_MC_Place(1,0,-64);var t=ye.speed;if(t){re.video.playbackRate=t;if(t<1)re.video.muted=true}else{re.video.playbackRate=1}});re.video.addEventListener("timeupdate",function(e){SL_MC_Timeupdate(this)},true);re.video.addEventListener("ended",function(e){if(ye.speed)ye.stop()})}re.video.src=toFileProtocol(e)}re.video_id=e;re.local_src=e}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;const i=e.detail.e;switch(i.code){case"KeyZ":if(!i.ctrlKey)return;window.addEventListener("SA_camera_poseNet_update",()=>{t.motion_tracking.arm_as_leg.enabled=!t.motion_tracking.arm_as_leg.enabled;ge.reset_to_default_motion_once=true;DEBUG_show("Arm-as-leg control:"+(t.motion_tracking.arm_as_leg.enabled?"ON":"OFF"),3)},{once:true});break;default:return}}System._browser.hotkeys.add({id:"switch_motion_control_mode",accelerator:["Ctrl+Z"],process:e})});var t=false;function x(){var e=_e.enabled||de.enabled;if(t==!!e)return;t=!!e;if(e){g();ge.reset();ge.add_events();DEBUG_show("(Camera ML Mode:ON)",2)}else{if(re.initialized){re.video_canvas_face_detection.style.visibility="hidden";re.video_canvas_facemesh.style.visibility="hidden";y()}ge.remove_events();re._info="";DEBUG_show("(Camera ML Mode:OFF)",2)}}var w,u,$;var J,ee,te,Me;var ie,oe,S,P,I,R;var pe,ne;var T,L;var F;var be;var ae=["親","人","中","薬","小"];var ve=["thumb","index","middle","ring","pinky"];var se=["0","1","2","3"];var C={};window.addEventListener("jThree_ready",()=>{J=new THREE.Vector3;ee=new THREE.Vector3;te=new THREE.Vector3;Me=new THREE.Vector3;F=new THREE.Vector3;ie=new THREE.Quaternion;oe=new THREE.Quaternion;S=new THREE.Quaternion;P=new THREE.Quaternion;I=new THREE.Quaternion;R=new THREE.Quaternion;pe=new THREE.Matrix4;ne=new THREE.Quaternion;T=new THREE.Vector2;L=new THREE.Vector2;be=new THREE.Quaternion});var e;var i;var j;var we=true;var Se=true;var he;var h=true;var B,Ae,H;var De=false;var ke=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"];var Ee=[0,2,5,7,8,11,12,13,14,15,16,23,24,25,26,27,28];var xe=[];ke.forEach(e=>{xe.push({part:e,score:0})});var me,Pe;var O;function q(){if(O)return;O=true;const r=THREE.MMD.getModels()[0];const o=r.mesh.bones_by_name;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.arm_IK_offset={"左":(new THREE.Vector3).fromArray(o["左腕"].pmxBone.origin).sub(ee.fromArray(o["左腕IK"].parent.pmxBone.origin)),"右":(new THREE.Vector3).fromArray(o["右腕"].pmxBone.origin).sub(ee.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 s=o["左足首"].pmxBone.origin;MMD_SA_options.model_para_obj.hip_center=(new THREE.Vector3).fromArray(a).setX(0);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=s[1];MMD_SA_options.model_para_obj.leg_IK_offset={"左":(new THREE.Vector3).fromArray(o["左足"].pmxBone.origin).sub(ee.fromArray(o["左足IK"].parent.pmxBone.origin)),"右":(new THREE.Vector3).fromArray(o["右足"].pmxBone.origin).sub(ee.fromArray(o["右足IK"].parent.pmxBone.origin))};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]-s[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]-s[0],a[1]-s[1],a[2]-s[2]];let _=["左","右"];me={};_.forEach(n=>{["腕","ひじ"].forEach((e,t)=>{let i=n+e;let o=MMD_SA.get_bone_axis_rotation(r.mesh,i);me[i]={name:i,axis_rot:o,parent:t==0?{axis_rot:new THREE.Quaternion}:me[n+"腕"]};me[i].axis_rot_offset_inv=(new THREE.Quaternion).multiplyQuaternions(me[i].parent.axis_rot,MMD_SA.TEMP_q.copy(me[i].axis_rot).conjugate())})});Pe={};Pe[1]=(new THREE.Quaternion).multiplyQuaternions(MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.set(0,-Math.PI/2*1,Math.PI/2*1),"YZX"),MMD_SA._q1.copy(me["左腕"].axis_rot).conjugate());Pe[-1]=(new THREE.Quaternion).multiplyQuaternions(MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.set(0,-Math.PI/2*-1,Math.PI/2*-1),"YZX"),MMD_SA._q1.copy(me["右腕"].axis_rot).conjugate());MMD_SA_options.model_para_obj.finger_base={};_.forEach(s=>{let e=o[s+"手首"].pmxBone.origin;ae.forEach((e,t)=>{let n=s+e+"指";let i=t==0&&o[n+se[0]]?0:1;if(!o[n+se[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+se[a.base_index+(o-i)];let t=MMD_SA.get_bone_axis_rotation(r.mesh,e);me[e]={name:e,axis_rot:t,parent:o==i?me[s+"ひじ"]:me[n+se[a.base_index+(o-1-i)]]};me[e].axis_rot_offset_inv=(new THREE.Quaternion).multiplyQuaternions(me[e].parent.axis_rot,MMD_SA.TEMP_q.copy(me[e].axis_rot).conjugate())}})});for(const l in me){if(l.indexOf("指")!=-1){MMD_SA.TEMP_v3.setEulerFromQuaternion(me[l].axis_rot,"ZYX");MMD_SA.TEMP_v3.z*=-1;me[l].axis_rot.setFromEuler(MMD_SA.TEMP_v3,"ZYX")}me[l].axis_rot_inv=me[l].axis_rot.clone().conjugate()}MMD_SA_options.model_para_obj.rot_arm_adjust=me;console.log(me)}const p={};let m;let f;let G;class K{constructor(e,t){this.id=e;this.worker=t}initialized=false}async function U(){if(w)return;w=true;q();var t=[];if(is_mobile){t.push("use_mobilenet=1")}if(h){t.push("use_holistic=1");e=i=false;Se=he=true}if(e){t.push("use_human=1");B=true;e=true;i=false;j=false;Ae=true;H=true}else if(i){t.push("use_mixed_human=1");e=true;i=true;j=true;H=true}else{e=false;i=false;j=true}if(Se){t.push("use_blazepose=1");he=true}if(he){t.push("use_mediapipe=1");if(e){Ae=true;H=false}we=true}if(we){t.push("use_movenet=1")}if(MMD_SA_options.user_camera.ML_models.worker_disabled&&_e.initialized&&!_e.worker_initialized){await new Promise(function(e,t){var i=setInterval(()=>{if(_e.worker_initialized){clearInterval(i);e()}},100)})}else{await _e.init()}if(MMD_SA_options.user_camera.ML_models.worker_disabled){m={postMessage:function(e,t){PoseAT.onmessage({data:e})}};let e=document.createElement("script");e.onload=function(){PoseAT.init(m,t)};e.src="js/pose_lib.js";document.head.appendChild(e)}else{G="js/pose_worker.js"+(t.length?"?"+t.join("&"):"");f=de.use_holistic?"legacy_holistic":"tasks_vision";console.log("Web worker ID:"+f);m=new Worker(G);p[f]=new K(f,m)}m.onmessage=Te}var Ie=function(){let f;window.addEventListener("jThree_ready",()=>{f=new System._browser.data_filter([{type:"one_euro",id:"head_rot",para:[30,1,2,1,4]}])});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}var r=o[0].rot_parent;if(!r){const u=de.enabled&&MMD_SA.MMD.motionManager.para_SA.motion_tracking?.head_rotation_weight||0;if(u==1){r=new THREE.Quaternion}else{r=MMD_SA.get_bone_rotation_parent(e,t,e).conjugate();if(de.enabled)r.premultiply(oe.copy(this._rot_body_offset).multiply(this._rot_body_camera));if(u)r.slerp(a,u)}}o[0]._rot_parent=r;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()}var _=s.toAxisAngle()[1]%(Math.PI*2);if(_>Math.PI)_=Math.PI*2-_;else if(_<0&&_<-Math.PI)_+=Math.PI*2;_=Math.abs(_);n=de.use_3D_pose?.5:.3+Math.max(_-Math.PI/2,0)/(Math.PI/2)*.2;var l=ie.multiplyQuaternions(r,s);l.fromArray(f.filter(l.toArray()));var d=J.setEulerFromQuaternion(l,"YZX");var c=[d.x<0?n+(.5-n)*.5:n,n,n];l.setFromEuler(ee.fromArray(d.toArray().map((e,t)=>Math.sign(e)*Math.min(Math.abs(e),Math.PI/2)*c[t])),"YZX");if(de.enabled){const p=MMD_SA.MMD.motionManager.para_SA.motion_tracking;const h=1-(p?.motion_default_weight?.head||0)*this.camera_weight;if(h){const m=oe.copy(i.quaternion).premultiply(S.copy(this._body_motion_rot[0]["首"]).conjugate());i.quaternion.slerp(m,h);m.copy(e.bones_by_name["頭"].quaternion).premultiply(S.copy(this._body_motion_rot[0]["頭"]).conjugate());e.bones_by_name["頭"].quaternion.slerp(m,h)}}i.quaternion.multiply(l);e.bones_by_name["頭"].quaternion.multiply(l);o[0]._rot_neck=i.quaternion.clone();o[0]._rot_head=e.bones_by_name["頭"].quaternion.clone();if(ye.active){ye.set_boneKey(t,null,i.quaternion,true);ye.set_boneKey("頭",null,e.bones_by_name["頭"].quaternion,false)}if(n<.5){const i=e.bones_by_name["上半身2"];i.quaternion.multiply(ie.setFromEuler(J.setEulerFromQuaternion(s,"YZX").multiply(ee.fromArray(c.map(e=>1-e*2))),"YZX"))}}}();var Re=1*10;var fe=function(){var g=[];var o;var n;window.addEventListener("jThree_ready",()=>{o=new System._browser.data_filter([{type:"average"}]);fe.v_hip=n=new THREE.Vector3});function e(e){var r=e.keypoints[5];var _=e.keypoints[6];var l=e.keypoints[11];var d=e.keypoints[12];if(r.score<=0||_.score<=0)return;var c=e.keypoints3D[5];var u=e.keypoints3D[6];g=[{point2D:[{position:new THREE.Vector3},{position:new THREE.Vector3}],data3D:{length:0,z_diff:0}}];const p=de.spine_length_ref;let h=1;if(l.score>0&&d.score>0){let e=MMD_SA._v3a.addVectors(c,u).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;h=Math.min(Math.max((Math.abs(o)-Math.PI/4)/(Math.PI/4),0),1);let n=T.copy(l.position).add(d.position).multiplyScalar(.5);let a=L.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=p*(t*2)}if(h){let e=MMD_SA._v3b.copy(c).sub(u);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=L.copy(r.position).add(_.position).multiplyScalar(.5);let a=n.clone();let s=T.copy(r.position).distanceTo(_.position);n.y=n.y+s*1.5/Math.abs(Math.cos(o));if(n.y>re.video_canvas.height){a.y=Math.max(a.y-(n.y-re.video_canvas.height),0);n.y=re.video_canvas.height}g[0].point2D[0].position.lerp(a,h);g[0].point2D[1].position.lerp(n,h);g[0].data3D.length=g[0].data3D.length*(1-h)+p*(t*3)*h}}function t(){if(!g.length)return;var d=System._browser.camera;var c=d.video_canvas.width;var u=d.video_canvas.height;var p=J;var h=[];const e=c/u;const t=SL.width/SL.height;const m=e{p.set((e.point2D[0].position.x/c*2-1)*m,(-(e.point2D[0].position.y/u)*2+1)*f,.5);var t=MMD_SA._v3a.copy(p.unproject(d._camera_reset).sub(d._camera_reset.position).normalize());p.set((e.point2D[1].position.x/c*2-1)*m,(-(e.point2D[1].position.y/u)*2+1)*f,.5);var i=MMD_SA._v3b.copy(p.unproject(d._camera_reset).sub(d._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);h.push({z:-t.z*1.5,id:e.id})});h.sort((e,t)=>t.z-e.z);var i=h[0].z;this.z=i;z=o.filter(i);this.z_smoothed=z;g=[]}function i(e){if(MMD_SA.WebXR.session){n.set(0,0,0);return}n.copy(e).unproject(re._camera_reset).sub(re._camera_reset.position).normalize();if(Re)fe.estimate();const t=re._camera_reset.position.z-THREE.MMD.getModels()[0].mesh.position.z;let i=t;if(Re&&fe.z)i=fe.z_smoothed||fe.z;n.multiplyScalar(-i/n.z)}return{prepare:e,estimate:t,get_hip_center:i}}();var Q=(()=>{function P(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 d=a(_)-4*r*l;if(d>=0){var c=[(-_+s(a(_)-4*r*l))/(2*r),(-_-s(a(_)-4*r*l))/(2*r)];if(d==0){return[c[0]]}return c}return[]}var I,R,T;var L;window.addEventListener("jThree_ready",()=>{I=new THREE.Vector3;R=new THREE.Vector3;T=new THREE.Vector3;L=new THREE.Quaternion});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 _=T.copy(a).sub(r);const l=n;const d=(l.x*_.x+l.y*_.y+l.z*_.z-(r.x*_.x+r.y*_.y+r.z*_.z))/_.lengthSq();const c=MMD_SA._v3b.set(r.x+_.x*d,r.y+_.y*d,r.z+_.z*d);const u=_.normalize();const p=R.copy(n).sub(c).normalize().negate();const h=I.crossVectors(u,p).normalize();const m=(new THREE.Plane).setFromNormalAndCoplanarPoint(u,n);const f=(new THREE.Plane).setFromNormalAndCoplanarPoint(MMD_SA.TEMP_v3.set(0,1,0),MMD_SA._v3a.set(0,o,0));const g=m.intersectPlane(f);if(!g)return;pe.set(u.x,u.y,u.z,0,p.x,p.y,p.z,0,h.x,h.y,h.z,0,0,0,0,1);ne.setFromBasis(pe);const y=MMD_SA.TEMP_v3.copy(n).sub(c).length();let M=f.intersectLine(new THREE.Line3(n,c),T);if(!M)return;M=-M.sub(n).length();g[1].applyQuaternion(ne);const b=g[1].y/g[1].z;n.sub(s);n.applyQuaternion(ne);const v=P(y,n.z,n.y,b,M);if(!v.length)return;const w=v.map(e=>{e-=n.z;return Math.asin(e/y)});const S=i=="左"?1:-1;const A=MMD_SA.get_bone_rotation(t,"上半身2",null,t);const D=L.copy(A).conjugate();const k=R.copy(a).sub(s).normalize().applyQuaternion(D);const E=e.use_smallest_angle?w.sort((e,t)=>Math.abs(e)-Math.abs(t))[0]:w[S==-1?w.length-1:0];const x=MMD_SA.TEMP_q.setFromAxisAngle(k,E);t.bones_by_name[i+"腕"].quaternion.premultiply(x)}})();var Te=function(){function O(e,t){let i=me[t];e.premultiply(i.axis_rot).multiply(i.axis_rot_inv);e.multiplyQuaternions(i.axis_rot_offset_inv,e)}function q(e,t){if(de.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(ye.active){if(MMD_SA_options.user_camera.ML_models.pose.use_legIK){const r=MMD_SA.TEMP_v3.copy(i.position);r.sub(s);ye.set_boneKey(t,r,o[0].rot?i.quaternion:null,true)}window.addEventListener("SA_MMD_model"+e._model_index+"_process_bones_after_IK",()=>{ye.set_boneKey(n+"足",null,e.bones_by_name[n+"足"].quaternion,true);ye.set_boneKey(n+"ひざ",null,e.bones_by_name[n+"ひざ"].quaternion,true)},{once:true})}i.quaternion.set(0,0,0,1)}function G(e,t){const i=t.charAt(0);if(!MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only)return;var o=e.bones_by_name;var n=o[t].quaternion;n.multiplyQuaternions(be,n)}function K(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=J.copy(fe.v_hip);if(MMD_SA.WebXR.session){a.set(0,0,0)}else{const c=re._camera_reset.position.z-THREE.MMD.getModels()[0].mesh.position.z;a.z=MMD_SA_options.user_camera.ML_models.pose.estimate_z_depth===false?0:c+a.z;if(i[0]._v_hip_offset)a.add(i[0]._v_hip_offset)}if(MMD_SA_options.user_camera.ML_models.pose.position_offset)a.add(MMD_SA_options.user_camera.ML_models.pose.position_offset);i[0].pos.copy(a);var s=(new THREE.Vector3).copy(i[1].pos).lerp(i[0].pos,o);var r=MMD_SA.get_bone_position(n,"左足","全ての親");var _=MMD_SA.get_bone_position(n,"右足","全ての親");var l=MMD_SA.TEMP_v3.copy(r).add(_).multiplyScalar(.5).sub(MMD_SA_options.model_para_obj.hip_center).negate();if(de.auto_grounding){let e=MMD_SA.get_bone_position(n,"左足首","全ての親");let t=MMD_SA.get_bone_position(n,"右足首","全ての親");let i=e.y0){THREE.MMD.getModels()[n._model_index].resetPhysics(15+d*2)}F.copy(s)}function D(r,_,e,t){function i(e,t,i){if(typeof e=="number")return e;if(/^(\w+)([\+\-])([\d\.])$/.test(e)){const o=(RegExp.$2=="+"?1:-1)*parseFloat(RegExp.$3);const n=MMD_SA.TEMP_v3.copy(_);const a=RegExp.$1;if(a=="default"){n.copy(ge._skin[r].pos).sub(r.indexOf("腕")!=-1?MMD_SA_options.model_para_obj.arm_IK_offset[l]:MMD_SA_options.model_para_obj.leg_IK_offset[l]).applyQuaternion(ge._skin[r].rot_parent_inv)}else if(a=="elbow"){if(t=="y"){const s=c?.motion_tracking?.arm_tracking?.elbow_lock?.[l=="左"?"left":"right"]?._elbow_y;if(s!=null&&s!=0){n.y=s-MMD_SA.get_bone_position(d,l+"腕",d).y}}}return(n[t]+o)/i}return 0}const l=r.charAt(0);const o=r.indexOf("腕")!=-1?MMD_SA_options.model_para_obj.left_arm_length:MMD_SA_options.model_para_obj.left_leg_length;const n=l=="左"?"left":"right";const a=THREE.MMD.getModels()[0];const d=a.mesh;const c=MMD_SA.motion[a.skin._motion_index].para_SA;let s;if(e){for(const g of["x","y","z"]){const y=e[g];if(!y)continue;const u=y.unit_length||o;if(y.scale!=null)_[g]*=typeof y.scale?.[n]=="number"&&y.scale[n]||y.scale;if(y.add)_[g]+=i(y.add?.[n]||y.add,g,u)*u;if(y.min!=null)_[g]=Math.max(_[g],i(y.min?.[n]||y.min,g,u)*u);if(y.max!=null)_[g]=Math.min(_[g],i(y.max?.[n]||y.max,g,u)*u)}if(e.rotation)_.applyEuler(MMD_SA.TEMP_v3.copy(e.rotation).multiplyScalar(Math.PI/180));if(e.camera_weight&&r.indexOf("腕")==-1)_.applyQuaternion(MMD_SA.TEMP_q.set(0,0,0,1).slerp(ge._rot_camera,e.camera_weight));const f=e.position_to_rotation;if(f){const M=d.bones_by_name;const b=te.set(Math.atan2(_.z,_.y),0,-Math.atan2(_.x,_.z));const v={upper:{q:ie},lower:{q:oe}};for(const x of["upper","lower"]){const P=l+(x=="upper"?"足":"ひざ");const I=M[P];v[x].name=P;v[x].q.copy(I.quaternion);I.quaternion.set(0,0,0,1);if(!f[x])continue;const R=Me.set(0,0,0);for(const g of["x","y","z"]){const y=f[x][g];if(!y)continue;let e=0;const T=y.rot_formula?.[n]||y.rot_formula;if(T?.length==1){e=b[T]*180/Math.PI}if(y.add)e+=y.add?.[n]||y.add;if(y.scale!=null)e*=typeof y.scale?.[n]=="number"&&y.scale[n]||y.scale;if(y.curve){const L=y.curve?.[n]||y.curve;const F=(e-L.ini)/(L.end-L.ini);if(F>0&&F<1)e=Math.pow(F,L.pow_factor)*(L.end-L.ini)+L.ini}if(y.min!=null)e=Math.max(e,y.min?.[n]||y.min);if(y.max!=null)e=Math.min(e,y.max?.[n]||y.max);R[g]=e/180*Math.PI}I.quaternion.setFromEuler(R,"XZY");if(x=="upper")s=I.quaternion.clone()}const w=MMD_SA.get_bone_position(d,l+"足","全ての親");const S=MMD_SA.get_bone_position(d,l+"足首","全ての親");const A=re.x_flipped?-1:1;const D=te.fromArray(M[l+"足"].pmxBone.origin);const k=D.sub(w).negate();const E=w.sub(S);E.x*=A;E.y*=-1;E.z*=-1;E.add(MMD_SA_options.model_para_obj.leg_IK_offset[l]);E.add(k);E.y-=MMD_SA_options.model_para_obj.left_leg_IK[1]+(M["センター"].position.y-M["センター"].pmxBone.origin[1]);_.copy(E);for(const x in v)M[v[x].name].quaternion.copy(v[x].q)}}else{if(t)t(_)}const u=_.length();const p=e?.length_max||1;const h=e?.length_min;if(u>o*p)_.normalize().multiplyScalar(o*p);else if(h!=null&&u{var f;window.addEventListener("jThree_ready",()=>{f=new System._browser.data_filter([{type:"average",para:[200,"vector3"]}])});return function(e,t){if(de.IK_disabled_check(t))return;var i=e.bones_by_name[t];var o=this.skin[t];var n=Math.max(Math.min(o[0].t_delta/o[0].t_delta_frame,1),0);var a=t.charAt(0);var s=J.copy(o[1].pos).lerp(o[0].pos,n);if(o[0].data_filter||o[1].data_filter){s.fromArray(f.filter(s.toArray()))}const r=MMD_SA.MMD.motionManager.para_SA;if(r.motion_tracking_upper_body_only){const u=r?.motion_tracking?.arm_tracking?.transformation?.position;D(a+"腕IK",s,u)}const _=MMD_SA.get_bone_rotation_parent(e,t,e);if(!o[0]._IK_absolute){s.applyQuaternion(this.offset_upper_body_camera_rotation(ie.copy(_).conjugate(),r?.motion_tracking?.arm_tracking?.transformation?.position?.camera_weight||1))}var l=ee.fromArray(e.bones_by_name[a+"腕"].pmxBone.origin).sub(te.fromArray(i.parent.pmxBone.origin));var d=MMD_SA.get_bone_position(e,a+"腕",i.parent.name).sub(l);s.add(d);const c=this.arm_IK_constraint[a];if(c.enabled){arm0=MMD_SA.get_bone_position(e,a+"腕",e);const p=ee.copy(s).applyQuaternion(_).add(c.arm_pos);const h=te.copy(c.target).sub(p);if(!c.target_radius||h.length()>c.target_radius){const m=p.sub(c.target).add(h.normalize().multiplyScalar(c.target_radius));s.sub(m.applyQuaternion(_.conjugate()))}}s.add(MMD_SA_options.model_para_obj.arm_IK_offset[a]);i.position.copy(s)}})();var k=function(){let D={};let k={};window.addEventListener("jThree_ready",()=>{D["左"]=new System._browser.data_filter([{type:"one_euro",para:[30,1,1,1,4]}]);D["右"]=new System._browser.data_filter([{type:"one_euro",para:[30,1,1,1,4]}]);k["左"]=[];k["右"]=[];for(let e=0;e<5;e++){k["左"][e]=new System._browser.data_filter([{type:"average",para:[200]}]);k["右"][e]=new System._browser.data_filter([{type:"average",para:[200]}])}});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;o.fromArray(D[a].filter(o.toArray()));const s="YXZ";const r=MMD_SA.TEMP_v3.setEulerFromQuaternion(o,s);const _=MMD_SA.MMD.motionManager.para_SA.motion_tracking.arm_as_leg.transformation?.rotation||{};let l=Math.sign(r.y)*Math.min(Math.abs(r.y*(_.y?.scale||1)),Math.PI/2);const d=_.y?.foot_ratio||.25;r.y=l*d;r.z=Math.sign(r.z)*Math.min(Math.abs(r.z*(_.z?.scale||.5)),Math.PI/3);r.x*=_.x?.scale||.5;const c=[];let u=0;const p=this.skin[e];let h;if(p[0]._finger_x){if(p[1]._finger_x){const b=Math.max(Math.min(p[0].t_delta/p[0].t_delta_frame,1),0);h=p[0]._finger_x.map((e,t)=>e*b+p[1]._finger_x[t]*(1-b))}else{h=p[0]._finger_x}}if(h){for(let e=0;e<5;e++){c[e]=k[a][e].filter(h[e])}c[0]=(c[0]+c[1])/2;c.forEach(e=>{u+=e});u/=5;r.x-=u}r.x=Math.sign(r.x)*Math.min(Math.abs(r.x),Math.PI/2);o.setFromEuler(r,s);this._rot_=o.clone();this._rot_y=l;const m=this.get_blend_default_motion("skin",a+"足IK",true);if(m)l*=1-m;const f=MMD_SA.get_bone_position(n,a+"足",n);const g=MMD_SA.get_bone_rotation_parent(n,a+"足",n).conjugate();const y=MMD_SA.get_bone_position(n,e,n).sub(f).negate().normalize().applyQuaternion(g);const M=MMD_SA.TEMP_q.setFromAxisAngle(y,l*(1-d));if(0&&n.bones_by_name[a+"足D"]){n.bones_by_name[a+"足"].quaternion.premultiply(M);n.bones_by_name[a+"足D"].quaternion.premultiply(M)}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(f).negate().normalize().applyQuaternion(g);const w=ie.setFromUnitVectors(J.set(0,1,0),y);n.bones_by_name[a+"足"].quaternion.copy(w).multiply(oe.setFromEuler(J.set(-v.angleTo(y),0,0)))}n.bones_by_name[a+"足"].quaternion.premultiply(M);t._update_IK_and_AddTrans(false,a+"足","下半身")}if(u&&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+se[1]]);if(!S){let t=0;for(let e=1;e<4;e++){t+=c[e]}t/=4;const A=(c[1]-t)/2;n.bones_by_name[a+"足先EX"].quaternion.setFromEuler(J.set(-u*.5,0,A),"XZY")}else{n.bones_by_name[a+"足先EX"].quaternion.setFromEuler(J.set(-u*.5,0,0))}t._update_IK_and_AddTrans(false,a+"足先EX")}if(h){ae.forEach((e,t)=>{const i=a+"足"+e+"指";const o=n.bones_by_name[i]||n.bones_by_name[i+se[1]];if(o)o.quaternion.multiply(ie.setFromEuler(J.set(-c[t]*.5,0,0)))})}}}();var U=function(){let g={};window.addEventListener("jThree_ready",()=>{g["左"]=new System._browser.data_filter([{type:"one_euro",para:[30,1,1,1,4]}]);g["右"]=new System._browser.data_filter([{type:"one_euro",para:[30,1,1,1,4]}])});return function(e,t){var i=THREE.MMD.getModels()[e._model_index];var o=MMD_SA.THREEX.get_model(e._model_index).is_T_pose;var n=e.bones_by_name[t];var a=t.charAt(0);var s,r,_,l;var d=e.bones_by_name[a+"手捩"];var c;var u=this.skin[t];var p=Math.max(Math.min(u[0].t_delta/u[0].t_delta_frame,1),0);r=ie.set(0,0,0,1);if(d){if(d.quaternion.x||d.quaternion.y||d.quaternion.z){d.quaternion.conjugate();i._update_IK_and_AddTrans(false,a+"手捩")}d.quaternion.set(0,0,0,1)}const h=a=="左"?1:-1;var m=u[0].rot_parent;if(!m){m=MMD_SA.get_bone_rotation(e,"上半身2",null,e);m.premultiply(oe.copy(this._rot_body_offset).multiply(this._rot_camera).conjugate());m.multiply(MMD_SA.get_bone_rotation_parent(e,a+"手首","上半身2")).conjugate()}u[0]._rot_parent=m;r.multiply(u[0].no_blending?u[0].rot:MMD_SA.TEMP_q.copy(u[1].rot).slerp(u[0].rot,p));r.multiplyQuaternions(m,r).multiply(Pe[h]);r.fromArray(g[a].filter(r.toArray(),System._browser.camera.video_timestamp));n.quaternion.copy(r);if(d){_=d.pmxBone.fixedAxis;if(_){_=MMD_SA._v3a.fromArray(_);if(o)_.setY(0).setZ(0).normalize();const f=n.quaternion.toAxisAngle();let e=J.setEulerFromQuaternion(MMD_SA.TEMP_q.setFromAxisAngle(f[0].applyQuaternion(MMD_SA._q1.copy(me[a+"腕"].axis_rot).conjugate()),f[1]),"XZY").x*-h;if(e*h<-Math.PI/1.5)e+=Math.PI*2*h;l=-e*.5;c=oe.setFromAxisAngle(_,l);this.skin[a+"手捩"][0].rot.copy(c);n.quaternion.multiplyQuaternions(c.conjugate(),n.quaternion)}}if(ye.active){ye.set_boneKey(t,null,n.quaternion,true);if(!de.IK_disabled_check(a+"腕IK")){ye.set_boneKey(a+"腕",null,e.bones_by_name[a+"腕"].quaternion,true);ye.set_boneKey(a+"ひじ",null,e.bones_by_name[a+"ひじ"].quaternion,true)}}}}();var W=0,V=0,Q=0,X=0;let N,Y;window.addEventListener("jThree_ready",()=>{N=new System._browser.data_filter([{type:"one_euro",id:"torso_rot",para:[30,1,1,1,3]}]);Y=new System._browser.data_filter([{type:"one_euro",id:"chest_rot",para:[30,1,1,1,3]}])});return function(e){var o=typeof e.data=="string"&&e.data.charAt(0)==="{"?JSON.parse(e.data):e.data;if(typeof o==="string"){if(o=="OK"){de.worker_initialized=true}else{DEBUG_show(o,2);System._browser.console.log(o)}}else if(de.enabled){window.dispatchEvent(new CustomEvent("SA_camera_poseNet_update"));re._needs_RAF=true;de._bb=null;const n=Fe[de.use_holistic?1:0];let e;if(de.enabled&&!n.poseNet){e=true;n.poseNet=true}if(Z.enabled&&!n.handpose){e=true;n.handpose=true}if(e)DEBUG_show("Pose ML ready",2);ce=(_e.enabled?"\n":"")+re.video_canvas.width+"x"+re.video_canvas.height+"("+de.camera_video_frame_id+")\n";let t=re.video_timestamp;let i=0;if(X){i=Math.max(Math.min(t-X,1e3),10);Q+=i;if(++V>=20){W=1e3/(Q/V);V=Q=0}}X=t;de._t=o._t;ge.t_delta=W&&1e3/W||i||o.fps&&1e3/o.fps||o._t;if(de.use_holistic){n.facemesh=true;if(!o.facemesh){_e.data_detected=0}}let x=[];let P=[];let I=re.x_flipped?1:-1;const r=THREE.MMD.getModels()[0];const a=r.mesh.bones_by_name;const E=MMD_SA.THREEX.get_model(0).is_T_pose;const T=MMD_SA.MMD.motionManager.para_SA;const l=T.motion_tracking&&T.motion_tracking.arm_as_leg;const L={"左":l&&l.enabled&&(!l.linked_side||l.linked_side=="left"),"右":l&&l.enabled&&(!l.linked_side||l.linked_side=="right")};let B;if(de.enabled){if(o.posenet&&o.posenet.score>.3){de.data_detected++;de.initial_data_detected=true;if(de.data_detected_stable){if(De){De=false;r.mesh.visible=true}B=o.posenet;let D=de.use_3D_pose;if(Se){B._keypoints=B.keypoints;B._keypoints3D=B.keypoints3D;let o=[];let n=[];Ee.forEach((e,t)=>{let i=B.keypoints[e];i.part=ke[t];o.push(i);i=B.keypoints3D[e];i.part=ke[t];n.push(i)});B.keypoints=o;B.keypoints3D=n}const _=we?.3:!Ae?.5:.1;B.keypoints.forEach(e=>{e.score-=_});if(D){B._keypoints3D.forEach(e=>{e.score-=_})}if(Ae){let i={};B.keypoints.forEach(e=>{i[e.part]=e});let o=[];for(let t=0;t<=16;t++){let e=B.keypoints[t];if(!e)o.push(xe[t]);else if(e.part!=ke[t])o.push(i[ke[t]]||xe[t]);else o.push(e)}B.keypoints=o}let e=B._keypoints||B.keypoints;let t=e.map(e=>e.position.x);let i=e.map(e=>e.position.y);const c=[Math.min(...i),Math.max(...t),Math.max(...i),Math.min(...t)];e=B.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 f=Math.max(u[1]-u[3],u[2]-u[0])/2;c[0]=Math.min(c[0],u[0]-f);c[1]=Math.max(c[1],u[1]+f);c[2]=Math.max(c[2],u[2]-f);c[3]=Math.min(c[3],u[3]-f);de._bb=c;if(!_e.head_pose_enabled){_e.bb_center[0]=B.keypoints[0].position.x/re.video_canvas.width;_e.bb_center[1]=B.keypoints[0].position.y/re.video_canvas.height}if(D){let e=B._keypoints[0].position;let t=B._keypoints[3].position;let i=B._keypoints[6].position;const g=J.copy(i);const M=ee.copy(t).sub(g);const b=MMD_SA._v3a_.copy(e);const v=(b.x*M.x+b.y*M.y+b.z*M.z-(g.x*M.x+g.y*M.y+g.z*M.z))/M.lengthSq();const w=MMD_SA._v3b.set(g.x+M.x*v,g.y+M.y*v,g.z+M.z*v);let o=b.sub(w).normalize();let n=MMD_SA._v3b_.copy(t).sub(MMD_SA._v3b.copy(i)).normalize();let a=MMD_SA.TEMP_v3.crossVectors(n,o).normalize();n.crossVectors(o,a);pe.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);ne.setFromBasis(pe);let s=ne.conjugate();s=s.clone().multiply(MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.set(Math.PI/4,0,0)));if(!_e.head_pose_enabled){ge.add("skin","首",{after_IK:true,rot:s,onProcessRotation:Ie});ge.skin["首"][1]._rot_mixed&&ge.skin["首"][1].rot.copy(ge.skin["首"][1]._rot_mixed)}ge.add("skin","首_DUMMY_",{rot:s,_rot_from_pose:s.clone(),onProcessRotation:Ie})}let a=B.keypoints[5];let s=B.keypoints[6];let p=new THREE.Quaternion;let h=T.motion_tracking_upper_body_only;if(h){ce+="\n("+(T.motion_tracking?.arm_as_leg?.enabled?"🦶":"🙋")+"upper body only)\n"}if(D&&Re)fe.prepare(B);let m=0;let k;if(a.score>0&&s.score>0){let l,d;let c,u;if(D){l=B.keypoints3D[5];d=B.keypoints3D[6];let o=B.keypoints3D[11];let n=B.keypoints3D[12];if(h||o.score<=0||n.score<=0){h=true}else{if(B.keypoints[11].position.y>re.video_canvas.height||B.keypoints[12].position.y>re.video_canvas.height){h=true}let e=MMD_SA._v3b.copy(o).sub(n).normalize();let t=MMD_SA.TEMP_v3.set(1,0,0);let i=ee.setFromVectorSpherical(t,e);m=i.z;if(1||h)i.z=0;p.setFromEuler(i,"YZX")}let e=MMD_SA._v3a.addVectors(l,d).multiplyScalar(.5).normalize();e.applyQuaternion(MMD_SA.TEMP_q.copy(p).conjugate());let t=MMD_SA.TEMP_v3.set(0,1,0);t.y*=-1;if(T.motion_tracking_upper_body_only){const F=ee.setFromVectorSpherical(t,e);F.fromArray(N.filter(F.toArray()));c=(new THREE.Quaternion).setFromEuler(F,"YZX")}else{c=(new THREE.Quaternion).setFromVectorSpherical(t,e);if(h){c.multiplyQuaternions(p,c);p.set(0,0,0,1)}}let i=MMD_SA._v3b.copy(l).sub(d).normalize();i.applyQuaternion(MMD_SA.TEMP_q.multiplyQuaternions(p,c).conjugate());x_axis=MMD_SA.TEMP_v3.set(1,0,0);let a=ee.setFromVectorSpherical(x_axis,i);if(T.motion_tracking_upper_body_only)a.fromArray(Y.filter(a.toArray()));u=(new THREE.Quaternion).setFromEuler(a,"YZX");let s=0;let r=a.y;let _=(s+r)%(Math.PI*2);if(_>Math.PI)_=Math.PI*2-_;else if(_<0&&_<-Math.PI)_+=Math.PI*2;c.multiply(ie.setFromEuler(J.set(0,_/2-s,0),"YZX"));u.multiply(ie.setFromEuler(J.set(0,_/2-r,0),"YZX"));ge.add("skin","センター",{rot:p.clone(),priority:9});if(ye.active){if(!ge.skin["センター"][0].pos&&ge.skin["センター"][1].pos)ge.skin["センター"][0].pos=ge.skin["センター"][1].pos}ge.add("skin","上半身",{rot:c.clone()});ge.add("skin","上半身2",{rot:u.clone()});k=ie.copy(p).multiply(c).multiply(u).conjugate()}de.shoulder_width=J.copy(a.position).distanceTo(ee.copy(s.position));let w=Math.sqrt(Math.pow(a.position.x-s.position.x,2)+Math.pow(a.position.y-s.position.y,2));let S=0;if(!D){S=Math.asin((a.position.y-s.position.y)/w);S=Math.max(Math.min(S/(Math.PI/4),1),-1)*Math.PI/4*I}let e=I==1?[1,0]:[0,1];let t=[B.keypoints[9],B.keypoints[10]];let A=-1;if(!D&&t[0].score>0&&t[1].score>0&&Math.sqrt(Math.pow(t[0].position.x-t[1].position.x,2)+Math.pow(t[0].position.y-t[1].position.y,2))<(re.video_canvas.width+re.video_canvas.height)/2/25){A=t[1].score>t[0].score?0:1;if(t[A].score>.3)A=-1}w=_e.face_width*2||w;e.forEach(function(e,t){let n,a,s;let r;let _=t==0?"左":"右";let l=B.keypoints[5+e];let d=B.keypoints[7+e];let i=B.keypoints[9+e];let c=(MMD_SA_options.user_camera.ML_models.pose.use_armIK==null?!T.motion_tracking_upper_body_only:!MMD_SA_options.user_camera.ML_models.pose.use_armIK)&&!L[_];let u=false;let o=i.score>0&&i.position.x>=0&&i.position.x<=re.video_canvas.width&&i.position.y>=0&&i.position.y<=re.video_canvas.height;if(T.motion_tracking_upper_body_only&&!o){c=false}const p=(new THREE.Quaternion).setFromEuler(MMD_SA.TEMP_v3.set(0,0,S));if(0&&T.motion_tracking_upper_body_only){ge.add("skin",_+"肩",{is_dummy:true,rot:true})}else{if(E)p.fromArray(MMD_SA.THREEX.utils.convert_A_pose_rotation_to_T_pose(_+"肩",p.toArray()));ge.add("skin",_+"肩",{absolute:!(T.motion_tracking_upper_body_only&&T.motion_tracking?.motion_default_weight?.shoulder),rot:p})}let h,m,f;if(D){h=B.keypoints3D[5+e];m=B.keypoints3D[7+e];f=B.keypoints3D[9+e]}let g=I*(e==0?-1:1);let y,M,b;const v="YZX";if(D&&d.score>0){y=MMD_SA._v3b.copy(h).sub(m).normalize().applyQuaternion(k);M=MMD_SA.TEMP_v3.set(g,0,0);b=(new THREE.Quaternion).setFromUnitVectors(M,y);if(E)b.premultiply(MMD_SA.TEMP_q.copy(p).conjugate())}if(i.score>0&&e!=A){P.push({pos:i.position,dir:e,d:_,visible:o});if(D){let o;if(d.score>0){let e=J.copy(m).sub(f).normalize().applyQuaternion(k).applyQuaternion(MMD_SA.TEMP_q.copy(b).conjugate());M=MMD_SA.TEMP_v3.set(g,0,0);o=(new THREE.Quaternion).setFromUnitVectors(M,e)}if(!c||d.score<=0){c=false;let e=MMD_SA._v3a.copy(h).sub(f);let t=d.score>0?MMD_SA.TEMP_v3.copy(h).distanceTo(m)+MMD_SA.TEMP_v3.copy(m).distanceTo(f):.5;let i=Math.min(e.length()/t,1);e.normalize().multiplyScalar(i*MMD_SA_options.model_para_obj.left_arm_length);n=e.x;a=e.y;s=r=e.z;if(b){let e;if(L[_]){e=k.clone().conjugate().multiply(b).multiply(o).conjugate()}O(b,_+"腕");ge.add("skin",_+"腕",{absolute:true,rot:b,_rot_hand_parent:e});if(o){O(o,_+"ひじ");ge.add("skin",_+"ひじ",{absolute:true,rot:o})}}}else{O(o,_+"ひじ");O(b,_+"腕");ge.add("skin",_+"腕",{absolute:true,rot:b,priority:-1,onFinish:G});ge.add("skin",_+"ひじ",{absolute:true,rot:o})}}else{u=true;let e=l.position.x-i.position.x;let t=l.position.y-i.position.y;n=e/w*MMD_SA_options.model_para_obj.shoulder_width*I;a=t/w*MMD_SA_options.model_para_obj.shoulder_width;if(d.score>0){let e=Math.min(Math.sqrt(Math.pow(i.position.x-d.position.x,2)+Math.pow(i.position.y-d.position.y,2))/w,1);let t=Math.min(Math.sqrt(Math.pow(l.position.x-d.position.x,2)+Math.pow(l.position.y-d.position.y,2))/w,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{if(L[_]){ge.add("skin",_+"手首",{rot:new THREE.Quaternion});ge.remove("skin",_+"足首")}if(d.score>0){if(D){if(!c){c=false;y=MMD_SA._v3a.copy(h).sub(m).normalize();y.multiplyScalar(MMD_SA_options.model_para_obj.left_arm_length);n=y.x*I;a=y.y;s=r=y.z}else{c=true;O(b,_+"腕");ge.add("skin",_+"腕",{absolute:true,rot:b,priority:-1,onFinish:G})}}else{c=false;u=true;let e=l.position.x-d.position.x;let t=l.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*I;a=Math.cos(o)*MMD_SA_options.model_para_obj.left_arm_length*Math.sign(t)}}else{if(D){if(!T.motion_tracking_upper_body_only)return;s=r=0}else{u=true}if(n==null){c=false;n=MMD_SA_options.model_para_obj.left_arm_to_IK_xy[1]*(_=="左"?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)}}}x.push({pos:{x:n,y:a,z:s,z_posenet:r},dir:e,d:_,IK_disabled:c,IK_absolute:u})})}else{h=true}if(D&&!h){if(!h){let e=re.video_canvas.width;let t=re.video_canvas.height;let i=new THREE.Vector3;let o=B.keypoints[11].position;let n=B.keypoints[12].position;const S=e/t;const A=SL.width/SL.height;const C=S0){v=MMD_SA._v3a.copy(y).sub(b);w=v.length();S=M.score>0?MMD_SA.TEMP_v3.copy(y).distanceTo(M)+MMD_SA.TEMP_v3.copy(M).distanceTo(b):.7;v.normalize().multiplyScalar(Math.min(w/S,1)*MMD_SA_options.model_para_obj.left_leg_length)}if(de.leg_scale_adjustment&&b.score>0){let e=1;let t=1;let i,o,n;let a,s,r;const _=te.copy(y);const l=Me.copy(b).sub(_);let d,c;if(M.score>0){const e=ee.copy(M);const t=(e.x*l.x+e.y*l.y+e.z*l.z-(_.x*l.x+_.y*l.y+_.z*l.z))/l.lengthSq();d=J.set(_.x+l.x*t,_.y+l.y*t,_.z+l.z*t);c=e.sub(d);s=te.copy(y).sub(M).length();r=te.copy(y).sub(d).length();a=c.length()}else{s=S/2;r=Math.min(l.length()/2,s);a=Math.sqrt(s*s-r*r)}const A=a/S;const D=re.video_canvas.width;const k=re.video_canvas.height;const E=MMD_SA.TEMP_v3;const x=fe.v_hip;const P=B.keypoints[11+f];const I=B.keypoints[15+f];const R=MMD_SA_options.model_para_obj.left_leg_length;const u=D/k;const p=SL.width/SL.height;const h=u0){t=Math.sqrt((s*s-e*e*r*r)/(a*a))||0;if(t){}else{o=0;n=true;i=s/r}if(o!=null){ce+="\n"+g+":"+i+"(x"+o+")"+(n?"<>":"")+"\n";e=i;t=o}else ce+="\n"+g+":"+e+"(x"+t+")\n";if(e!=1){const F=te.copy(y).add(l.multiplyScalar(e)).sub(b);for(const j of[27,29,31]){const e=B._keypoints3D[j+f];Object.assign(e,MMD_SA.TEMP_v3.copy(e).add(F))}b=B.keypoints3D[15+f];const C=d.sub(y).multiplyScalar(e).add(y).add(c.multiplyScalar(t));M=B.keypoints3D[13+f]=Object.assign(M,C);v.multiplyScalar(e)}}else{v.multiplyScalar(e);ce+="\n"+g+"(IK):"+e+"(x"+t+")\n"}}let n,a;let t;if(M.score>0){t=MMD_SA._v3b.copy(y).sub(M).normalize().applyQuaternion(MMD_SA.TEMP_q.copy(p).conjugate());let e=MMD_SA.TEMP_v3.set(0,1,0);e.y*=-1;a=ee.setFromVectorSpherical(e,t);n=(new THREE.Quaternion).setFromEuler(a,"XZY");i+=a.x}let s=!MMD_SA_options.user_camera.ML_models.pose.use_legIK;if(b.score>0){let i,o;if(M.score>0){i=J.copy(M).sub(b).normalize().applyQuaternion(MMD_SA.TEMP_q.copy(p).conjugate());o=te.copy(i).applyQuaternion(MMD_SA.TEMP_q.copy(n).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));a.y=e[1]*t;n.setFromEuler(a,"XZY")}if(!s||M.score<=0){de.enable_IK(g+"足IK",true);u.push({pos:v.clone(),rot:[n],dir:f,d:g})}else{o=te.copy(i).applyQuaternion(MMD_SA.TEMP_q.copy(n).conjugate());let e=MMD_SA.TEMP_v3.set(0,1,0);e.y*=-1;let t=(new THREE.Quaternion).setFromVectorSpherical(e,o);de.enable_IK(g+"足IK",false);u.push({rot:[n,t],dir:f,d:g})}const r=B._keypoints3D[29+f];const _=B._keypoints3D[31+f];if(r.score>0&&_.score>0){let e=MMD_SA._v3a_.copy(r).sub(b).normalize();let t=MMD_SA._v3b_.copy(r).sub(_).normalize();let i=J.crossVectors(e,t).normalize();e.crossVectors(t,i);pe.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);ne.setFromBasis(pe);let o=ne.conjugate();o=o.clone().multiply(MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.set(-Math.PI/8,0,0)));const l=MMD_SA.TEMP_v3.setEulerFromQuaternion(p,"YZX");const d=Math.abs(l.y)%Math.PI;let n=d>Math.PI/2?1-(d-Math.PI/2)/(Math.PI/2):1;if(MMD_SA_options.user_camera.ML_models.pose.use_legIK){const c=o.clone();if(n<1){l.x=l.z=0;c.slerp(oe.setFromEuler(l,"YZX"),1-n)}u[u.length-1].rot[2]=c}ge.add("skin",g+"足首",{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})}}else if(M.score>0){}});let n=0;o.forEach(e=>{const t=e.y*(1-e.scale);if(t>0){n=Math.max(t,n)}else if(o.length>1){n=Math.max(t,n||t)}});if(n){fe.v_hip.y+=n;ce+="\nleg_offset_y:"+n+"\n"}i*=.5*.5;let a=(new THREE.Quaternion).setFromEuler(MMD_SA.TEMP_v3.set(i,0,m),"XZY");ge.add("skin","下半身",{absolute:true,rot:a.clone()});if(!h){ge.add("skin","全ての親",{pos:new THREE.Vector3,after_IK:true,priority:999,onProcessPosition:K})}a.conjugate();u.forEach(e=>{var t=e.d;if(e.rot[0]){e.rot[0].multiplyQuaternions(a,e.rot[0]);ge.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]||ge.skin[t+"足IK"]&&ge.skin[t+"足IK"][0].rot;ge.add("skin",t+"足IK",{absolute:true,pos:e.pos,rot:i,priority:999,onFinish:q})}else{ge.add("skin",t+"ひざ",{absolute:true,rot:e.rot[1]})}})}else{if(T.motion_tracking_upper_body_only){ge.add("skin","全ての親",{is_dummy:true,pos:true,after_IK:true,priority:999})}else if(D&&a.score>0&&s.score>0&&re.video_canvas.width){let e=re.video_canvas.width;let t=re.video_canvas.height;let i=new THREE.Vector3;let o=e/t;let n=SL.width/SL.height;i.set(((a.position.x+s.position.x)/2/e*2-1)*(o{if(e.label)i[e.label].list.push(e)})}const s=he?1:2;o.handpose.forEach(t=>{t._offset={};R=t.annotations;if(s>1){for(let e in R){R[e].forEach(e=>{e[2]*=s})}}let i=MMD_SA.TEMP_v3.fromArray(R.palm[0]);P.forEach(e=>{t._offset[e.dir]=Math.sqrt(Math.pow(e.pos.x-i.x,2)+Math.pow(e.pos.y-i.y,2))})});P.forEach((u,e)=>{var p=u.dir;var t=i?i[i.Left.dir==p?"Left":"Right"].list:o.handpose;if(!t.length)t=o.handpose;let h=e==0?o.handpose.length==1&&P.length>1?t[0]._offset[p]e._offset[p]-t._offset[p])[0]:t.find(e=>!e._used);if(h&&h._offset[p]e.dir==p);let t=MMD_SA._v3a.fromArray(R.palm[0]).distanceTo(MMD_SA._v3b.fromArray(R.middle[0]))/MMD_SA._v3a.fromArray(R.index[0]).distanceTo(MMD_SA._v3b.fromArray(R.pinky[0]));t=t<1?1/t:t>2?t/2:0;if(t){for(const g of["thumb","index","middle","ring","pinky","palm"]){R[g].forEach(e=>{e[2]*=t})}}let S=u.d;h._d=S;y.push(S+"手");let i=p==1?[R.index[0],R.ring[0]]:[R.ring[0],R.index[0]];let o,n,a;let s=MMD_SA._v3a_.fromArray(R.palm[0]).sub(MMD_SA._v3b.fromArray(R.middle[0])).normalize();s.x=s.x*I;let r=MMD_SA._v3b_.fromArray(i[0]).sub(MMD_SA._v3b.fromArray(i[1])).normalize();r.z=r.z*I;r.y=r.y*I;let _=MMD_SA.TEMP_v3.crossVectors(r,s).normalize();r.crossVectors(s,_);pe.set(r.x,r.y,r.z,0,s.x,s.y,s.z,0,_.x,_.y,_.z,0,0,0,0,1);ne.setFromBasis(pe);let l=new THREE.Quaternion;l.copy(ne).conjugate();ge.add("skin",S+"手首",{after_IK:true,rot:l,onProcessRotation:U});ge.add("skin",S+"手捩",{after_IK:true,absolute:true,priority:1,no_blending:true,rot:new THREE.Quaternion});const m=MMD_SA.TEMP_v3.setEulerFromQuaternion(l,"YXZ").y;const f=1;const k=(Math.abs(m){let f=c[(I==1?S:S=="左"?"右":"左")+m];let g=f.base_index+(m==0?0:-1);let y=R[ve[m]];let M=oe.copy(A);const b="XZY";if(k&&m>0){const e=Math.max(MMD_SA._v3a.fromArray(y[2]).sub(MMD_SA._v3b.fromArray(y[1])).length()*1.2,MMD_SA._v3a.fromArray(R.palm[0]).sub(MMD_SA._v3b.fromArray(y[0])).length()*(k==1?.2:.3));const v=MMD_SA._v3a.fromArray(y[1]).sub(MMD_SA._v3b.fromArray(y[0]));if(e/v.length()>1){const t=-k*Math.sqrt(e*e-(v.x*v.x+v.y*v.y))-v.z;for(let e=1;e<3;e++)y[e][2]+=t}}for(let p=g;p<3;p++){let e=S+h+"指"+se[f.base_index+(p-g)];let t=MMD_SA._v3a.fromArray(y[p+0]);let i=MMD_SA._v3b.fromArray(y[p+1]);let o=MMD_SA.TEMP_v3.fromArray(p==g?R.palm[0]:y[p-1]);t.y=-t.y;i.y=-i.y;o.y=-o.y;let n=MMD_SA._v3a_.copy(t).sub(o);let a=MMD_SA._v3b_.copy(i).sub(t);n.normalize();a.normalize();let s,r;let _;n.applyQuaternion(M);a.applyQuaternion(M);if(p==g){let e=MMD_SA.TEMP_q.set(0,0,0,1);e.setFromVectorSpherical(MMD_SA.TEMP_v3.set(0,1,0),n).conjugate();a.applyQuaternion(e);M.multiplyQuaternions(e,M)}let l=MMD_SA._q1.set(0,0,0,1);let d=MMD_SA._q2.set(0,0,0,1);n.set(0,1,0);_=ee.setFromVectorSpherical(n,a);l.setFromEuler(_,b);d.copy(l);if(Math.abs(_.z)>Math.PI/(m==0?1.1:2.5)||_.x>Math.PI/(m==0?1.1:3)){_.set(-Math.abs(n.angleTo(a)),0,0)}if(m==0&&p>g){}if(_.x>0){_.x*=m==0?0:p>g?0:.75}else{_.x=Math.max(_.x,-Math.PI/(m==0?1.25:2))}if(m==0||p==g){_.z+=(m-2)/2*Math.PI/8*D*(m>0?1:.5);_.z*=m>0?Math.min(Math.max(Math.PI/2-Math.abs(_.x),0)/(Math.PI/2.5),1):1}else{_.z=0}if(E&&m>0&&p==g){const v=MMD_SA._v3a.fromArray(y[p+1]);v.y*=-1;v.applyQuaternion(A);const w=MMD_SA._v3b.fromArray(y[p+3]);w.y*=-1;w.applyQuaternion(A);if(v.y>w.y){_.x-=Math.abs(_.z)*E;_.z*=1-E}}_.y=0;if(m==0)M.multiplyQuaternions(l.conjugate(),M);l.setFromEuler(_,b);if(m>0){M.multiplyQuaternions(l.conjugate(),M);l.conjugate()}let c=e;let u=l.toAxisAngle();r=u[0];s=u[1];r.z*=-1;r.applyEuler(J.set(MMD_SA.THREEX.enabled?Math.PI/2:0,-Math.PI/2*D,0),"YXZ");if(MMD_SA.THREEX.enabled){l.setFromAxisAngle(r,s)}else{r.applyQuaternion(me[c].axis_rot);l.setFromAxisAngle(r,s)}if(L[S]){if(p==g){const e=ge.skin[S+"手首"][0];if(!e._finger_x)e._finger_x=[];e._finger_x[m]=_.x}}else{ge.add("skin",e,{absolute:true,rot:l.clone()})}}})}else{const e=u.d;if(T.motion_tracking_upper_body_only&&ge.get_blend_default_motion("skin",e+(L[e]?"足首":"手首"))!=0){u.visible=false}}})}else if(!Z.enabled&&B&&de.use_3D_pose){let e=I==1?[1,0]:[0,1];e.forEach(function(e,t){let i=t==0?"左":"右";if(!P.find(e=>e.d==i)?.visible)return;let o=B._keypoints3D[15+e];let n=B._keypoints3D[17+e];let a=B._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*I;let _=MMD_SA._v3b_.copy(s[0]).sub(s[1]).normalize();_.z=_.z*I;_.y=_.y*I;let l=MMD_SA.TEMP_v3.crossVectors(_,r).normalize();_.crossVectors(r,l);pe.set(_.x,_.y,_.z,0,r.x,r.y,r.z,0,l.x,l.y,l.z,0,0,0,0,1);ne.setFromBasis(pe);let d=new THREE.Quaternion;d.copy(ne).conjugate();ge.add("skin",i+"手首",{after_IK:true,rot:d,onProcessRotation:U});ge.add("skin",i+"手捩",{after_IK:true,absolute:true,priority:1,no_blending:true,rot:new THREE.Quaternion})})}for(const H of["左","右"]){if(ge.skin[H+"手首"]&&!ge.skin[H+"手首"][0]._finger_x)ge.skin[H+"手首"][0]._finger_x=ge.skin[H+"手首"][1]._finger_x}const d=[];x.forEach(function(t){var o=t.d;if(L[o]){if(t.IK_disabled)return;de.enable_IK(o+"足IK",true);if(ge.skin[o+"手首"]&&ge.skin[o+"腕"]&&ge.skin[o+"手首"][0].timestamp==ge.skin[o+"腕"][0].timestamp){let e;if(e){}else{const a=MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.set(Math.PI/2,0,0));const s=ge.skin[o+"手首"][0].rot.premultiply(a).multiply(a.conjugate());ge.add("skin",o+"足首",{after_IK:true,rot:s,_finger_x:ge.skin[o+"手首"][0]._finger_x,absolute:true,onFinish:k})}}else{const r=ge.skin[o+"足首"];if(r){r[0].rot_parent=r[0]._rot_parent}}ge.remove("skin",o+"手首");ge.remove("skin",o+"腕");ge.remove("skin",o+"ひじ");ge.remove("skin",o+"手捩");ge.remove("skin",o+"腕IK");if(Z.enabled){ae.forEach((t,e)=>{let i=e==0?0:1;for(let e=i;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)});d.push({d:o,pos:i,rot:n[1]})}else{de.enable_IK(o+"腕IK",!t.IK_disabled);if(!t.IK_disabled){if(t.pos.z==null)t.pos.z=t.pos.z_posenet||(de.use_3D_pose?0:MMD_SA_options.model_para_obj.left_arm_length*.2);const _=(new THREE.Vector3).copy(t.pos);ge.add("skin",o+"腕IK",{priority:999,pos:_,_IK_absolute:t.IK_absolute,onProcessPosition:m})}const e=ge.skin[o+"手首"];if(e){e[0].rot_parent=e[0]._rot_parent}}});if(d.length&&l.transformation?.position?.process)l.transformation.position.process(d);d.forEach(e=>{const t=e.d;const i=e.pos;i.y+=MMD_SA_options.model_para_obj.left_leg_IK[1]+(a["センター"].position.y-a["センター"].pmxBone.origin[1]);if(e.rot){ge.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{ge.remove("skin",t+"足")}ge.remove("skin",t+"ひざ");ge.add("skin",t+"足IK",{absolute:true,priority:999,pos:i})});if(T.motion_tracking_upper_body_only){for(const H of["左","右"]){const p=!P.find(e=>e.d==H)?.visible;if(L[H]){ge.set_blend_default_motion("skin",H+"足IK",p);ge.set_blend_default_motion("skin",H+"足",p);ge.set_blend_default_motion("skin",H+"ひざ",p);ge.set_blend_default_motion("skin",H+"足首",p)}else{if(T.has_leg_IK){ge.set_blend_default_motion("skin",H+"足IK",true);ge.remove("skin",H+"足首")}else{ge.set_blend_default_motion("skin",H+"足",true);ge.set_blend_default_motion("skin",H+"ひざ",true);ge.set_blend_default_motion("skin",H+"足首",true)}de.enable_IK(H+"足IK",T.has_leg_IK);de.enable_IK(H+"つま先IK",T.has_leg_IK);ge.set_blend_default_motion("skin",H+"肩",p);ge.set_blend_default_motion("skin",H+"腕",p);ge.set_blend_default_motion("skin",H+"ひじ",p);ge.set_blend_default_motion("skin",H+"手捩",p);ge.set_blend_default_motion("skin",H+"手首",p);ge.set_blend_default_motion("skin",H+"腕IK",p);if(Z.enabled){ae.forEach((t,e)=>{let i=e==0?0:1;for(let e=i;e{DEBUG_show((de.use_holistic&&"(no facemesh data)\n"||"")+(ue?"\n"+ue+"\n":"")+ce+"\n"+"FPS:"+EV_sync_update.fps_last)},0,0)}if(o.facemesh){_e.worker_onmessage({data:o.facemesh})}if(B&&_e.worker_initialized){let e={posenet:B,w:re.video_canvas.width,h:re.video_canvas.height,flip_canvas:re.display_flipped};if(o.handpose&&o.handpose.length)e.handpose=o.handpose;if(o.facemesh)e.facemesh=o.facemesh.faces;if(de.use_holistic||!_e.enabled){e.draw_canvas=true;if(self.FacemeshAT){e.canvas=re.video_canvas_facemesh}else if(!re.video_canvas_facemesh._offscreen&&self.OffscreenCanvas){e.canvas=re.video_canvas_facemesh.transferControlToOffscreen();re.video_canvas_facemesh._offscreen=true;console.log("(Facemesh: use offscreen canvas)")}}le.postMessage(e,e.canvas?[e.canvas]:undefined)}$=0}Le()}}();function Le(e){async function t(){var e=de.enabled&&de.worker_initialized&&A&&!de.busy&&k&&de.camera_video_timestamp!=A;if(!e)return;$=RAF_timestamp;de.camera_video_timestamp=A;de.camera_video_frame_id=D;if(de.use_holistic&&_e.blink_detection){MMD_SA_options.auto_blink=_e.auto_blink||false}let t,i,o;t=re.video_canvas;i=t.width;o=t.height;let n=self.PoseAT?t:E?await createImageBitmap(t):t.getContext("2d").getImageData(0,0,i,o).data.buffer;let a={rgba:n,w:i,h:o,options:{video_flipped:re.video_flipped,use_canvas_hands:!MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only,use_holistic:de.use_holistic,use_posenet:true,use_handpose:Z.enabled,skip_hand_countdown_max:de.skip_hand_countdown_max,timestamp:re.video_timestamp}};let s=[a.rgba];if(!de.canvas_hands){const r=de.canvas_hands=document.createElement("canvas");r.width=r.height=768;a.canvas_hands=r.transferControlToOffscreen();s.push(a.canvas_hands)}m.postMessage(a,s);s.length=0;s=undefined;a.rgba=n=undefined;a=undefined}if(e||self.PoseAT){setTimeout(()=>{t()},0)}else{t()}}var W=function(){const a=()=>{};var s,r;var z={};var H={},O={},q={};var G={};window.addEventListener("jThree_ready",e=>{s=new THREE.Vector3;r=new THREE.Quaternion;for(const t of["センター","上半身","上半身2","首","頭"]){z[t]=new THREE.Quaternion}for(const i of["左","右"]){G[i]={target:new THREE.Vector3,arm_pos:new THREE.Vector3};H[i]={target:new THREE.Vector3,effector:new THREE.Quaternion,links:[]};O[i]={effector:new THREE.Quaternion,links:[]};q[i]={effector:new THREE.Quaternion,parent:new THREE.Quaternion,links:[]};for(let e=0;e<2;e++){H[i].links[e]=new THREE.Quaternion;O[i].links[e]=new THREE.Quaternion;q[i].links[e]=new THREE.Quaternion}}});const _=250;const l=500;const d=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)/l,1)}else if(o._blend_default_motion<0){n=1-Math.min((RAF_timestamp+o._blend_default_motion)/_,1)}else{n=0}if(n==0){this[e][t].forEach(e=>{e._blend_default_motion=0})}else if(i){const e=2;n=n<.5?Math.pow(n*2,e)*.5:.5+Math.pow((n-.5)*2,1/e)*.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];const r=this[e][t][1]._blend_default_motion;if(i){if(this.reset_to_default_motion_once){s._idle_blend_default_motion=0;s._blend_default_motion=1}else if(!s._blend_default_motion){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:d)){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)*l}}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))*_)}}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 K(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(de.enabled&&!de.data_detected_stable)return;if(r[0].info[1]=="facemesh"){}r[0].t_delta+=RAF_timestamp_delta;let _=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=ie.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,_));if(r[0].ratio<1)t.slerp(oe.set(0,0,0,1),1-r[0].ratio);const d=MMD_SA_options.model_para_obj_all[i._model_index].skin_default[o];if(d&&d.rot_scale){if(typeof d.rot_scale=="number")d.rot_scale={x:d.rot_scale,y:d.rot_scale,z:d.rot_scale};t.setFromEuler(MMD_SA.TEMP_v3.setEulerFromQuaternion(t,"YXZ").multiply(d.rot_scale),"YXZ")}s.quaternion.multiply(t);ye.active&&!r[0].motion_recorder_disabled&&o.indexOf("IK")==-1&&ye.set_boneKey(o,null,s.quaternion,true)}}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 c=MMD_SA.TEMP_v3.copy(r[1].pos).lerp(r[0].pos,_);s.position.add(c);ye.active&&!r[0].motion_recorder_disabled&&o.indexOf("IK")==-1&&ye.set_boneKey(o,J.copy(s.position).sub(ee.fromArray(s.pmxBone.origin)),null,true)}}r[0].onFinish&&r[0].onFinish.call(this,i,o);const l=this.get_blend_default_motion("skin",o,true);if(l){if(r[0].rot&&this._skin[o]?.rot){const u=MMD_SA.TEMP_q.copy(this._skin[o].rot);s.quaternion.slerp(this._skin[o].onProcessRotation&&this._skin[o].onProcessRotation.call(this,i,o,u)||u,l)}if(r[0].pos&&this._skin[o]?.pos){s.position.lerp(this._skin[o].pos,l)}if(ye.active&&!r[0].motion_recorder_disabled){if(o.indexOf("IK")!=-1)ye.set_boneKey(o,r[0].pos&&s.position,r[0].rot&&s.quaternion,false)}}t&&e._update_IK_and_AddTrans(false,o)}var U=0;function o(e){function t(){if(E)return;E=z;for(const e of["センター","上半身","上半身2","首"]){const t=this.skin[e];if(!t){E[e].set(0,0,0,1);continue}if(e=="首"){E[e].copy(t[0]._rot_neck||t[1]._rot_neck||MMD_SA._q1.set(0,0,0,1));E["頭"].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);E[e].copy(i)}}r=MMD_SA._q1.copy(E["センター"]).multiply(E["上半身"]).multiply(E["上半身2"]).conjugate()}function a(e){const t=["センター","上半身","上半身2","首","頭"];let o;const n=x&&x.parent;const a=J.set(0,0,0);if(n){const f=n.name||e+"足";const g=f.charAt(0);const y=1-this.get_blend_default_motion("skin",f.indexOf("足")!=-1?g+"足IK":f,true);let t,i;switch(f){case"頭":o=y&&this.skin["首"];if(o){for(const f of["首","頭"])D[f].quaternion.copy(E[f]);t=MMD_SA.get_bone_position(A,"頭","首").add(ee.set(0,.75,.75).applyQuaternion(MMD_SA.TEMP_q.copy(D["首"].quaternion).multiply(D["頭"].quaternion)));D["首"].quaternion.copy(this._body_motion_rot[0]["首"]);D["頭"].quaternion.copy(this._body_motion_rot[0]["頭"]);i=MMD_SA.get_bone_position(A,"頭","首").add(ee.set(0,.75,.75).applyQuaternion(MMD_SA.TEMP_q.copy(D["首"].quaternion).multiply(D["頭"].quaternion)))}break;case"左足":case"右足":o=y;if(o){if(!O[g].updated){H[g].enabled=true;o=false}}else{H[g].enabled=false;O[g].updated=0}if(o){const M=ee.fromArray(D[e+"ひざ"].pmxBone.origin).sub(te.fromArray(D[f].pmxBone.origin));t=te.copy(M).applyQuaternion(ie.copy(q[g].parent).multiply(q[g].links[1]));i=M.applyQuaternion(ie.copy(q[g].parent).multiply(O[g].links[1]))}break}if(o){o=f;a.copy(t).sub(i);let e=n.weight||.5;if(typeof e=="object"){a.x*=a.x<0?e.x.left:e.x.right;a.y*=a.y<0?e.y.down:e.y.up;a.z*=a.z<0?e.z.backward:e.z.forward}else{a.multiplyScalar(e)}a.multiplyScalar(y)}}let i,s,r;for(const f of t)D[f].quaternion.copy(this._body_motion_rot[0][f]);const _=k.motion_tracking?.arm_tracking?.elbow_lock?.[e=="左"?"left":"right"];if(_){_._elbow_y=_.y_absolute!=null?_.y_absolute:MMD_SA.get_bone_position(A,e+"ひじ",A).y+(_.y||0)}if(!o||o!="頭"){i=MMD_SA.get_bone_position(A,e+"腕",A);r=MMD_SA.get_bone_rotation_parent(A,e+"腕IK",A);s=!k.has_arm_IK?MMD_SA.get_bone_position(A,e+"手首",A):(new THREE.Vector3).copy(D[e+"腕IK"].position).sub(MMD_SA_options.model_para_obj.arm_IK_offset[e]).applyQuaternion(r).add(i);r.conjugate()}for(const f of t)D[f].quaternion.copy(this._body_motion_rot[1][f]);if(!i){i=MMD_SA.get_bone_position(A,e+"腕",A);r=MMD_SA.get_bone_rotation_parent(A,e+"腕IK",A);s=!k.has_arm_IK?MMD_SA.get_bone_position(A,e+"手首",A):(new THREE.Vector3).copy(D[e+"腕IK"].position).sub(MMD_SA_options.model_para_obj.arm_IK_offset[e]).applyQuaternion(r).add(i);r.conjugate()}for(const f of["センター","上半身","上半身2"]){let e;if(f.indexOf("上半身")!=-1)e=k.motion_tracking?.motion_default_weight?.upper_body;if(e==null)e=1;if(this.skin[f]){if(e<1)D[f].quaternion.slerp(MMD_SA.TEMP_q.set(0,0,0,1),1-e);D[f].quaternion.multiply(E[f])}}let l=x&&x.default_position_weight;if(typeof l!="number")l=.5;const d=MMD_SA.get_bone_rotation_parent(A,e+"腕IK",A).conjugate();let c;let u=k.motion_tracking?.arm_tracking?.IK_constraint;if(u)u=u[e=="左"?"left":"right"]||u;if(u&&this.skin[e+"腕IK"]&&this.get_blend_default_motion("skin",e+"腕IK")<1){const b=G[e];b.enabled=true;b.target.copy(s);b.target_radius=0;if(u.target_offset){const v=J.fromArray(u.target_offset);b.target.add(v);b.target_radius=v.length()}if(u.target_radius)b.target_radius+=u.target_radius;c=MMD_SA.get_bone_position(A,e+"腕",A);b.arm_pos.copy(c)}c=l==0?i:(c||MMD_SA.get_bone_position(A,e+"腕",A)).lerp(i,1-l);const p=c.sub(s);if(l<1)d.slerp(r,1-l);if(o&&o.indexOf("足")!=-1){a.applyQuaternion(d)}const h=re.x_flipped?-1:1;p.x*=h;p.y*=-1;p.z*=-1;if(o&&o=="頭"){p.applyQuaternion(d)}else{p.applyQuaternion(d)}if(!this._skin[e+"腕IK"])this._skin[e+"腕IK"]={pos:new THREE.Vector3,rot:new THREE.Quaternion};if(!this._skin[e+"腕IK"].rot_parent_inv)this._skin[e+"腕IK"].rot_parent_inv=new THREE.Quaternion;this._skin[e+"腕IK"].rot_parent_inv.copy(d).conjugate();p.add(MMD_SA_options.model_para_obj.arm_IK_offset[e]);p.add(a);for(const f of t)D[f].quaternion.copy(this._body_motion_rot[1][f]);const m=this.skin[e+"手首"];if(m){if(P){m[0].after_IK=true;this._skin[e+"手首"]._rot_absolute=MMD_SA.get_bone_rotation(A,e+"手首",false,A)}this._skin[e+"手首"].onProcessRotation=w;this._skin[e+"手捩"].onProcessRotation=S}return p}function w(e,t,i){const o=t.charAt(0);const n=k.motion_tracking&&k.motion_tracking.arm_default_stickiness&&(k.motion_tracking.arm_default_stickiness[o]||k.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 S(e,t,i){return i.set(0,0,0,1)}function i(){if(de.data_detected){W();System._browser.on_animation_update.remove(i,0)}}const s=e.detail.model;const o=MMD_SA.THREEX.get_model(s._model_index).is_T_pose;const A=s.mesh;const D=A.bones_by_name;const k=MMD_SA.motion[s.skin._motion_index].para_SA;if(!this._reset_disabled&&this._motion_path&&(this._motion_path!=k._path||this._motion_tracking_upper_body_only!=!!k.motion_tracking_upper_body_only)){this._motion_path=k._path;this._motion_tracking_upper_body_only=!!k.motion_tracking_upper_body_only;this.reset();V();de.data_detected=0;de.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=k._path;this._motion_tracking_upper_body_only=!!k.motion_tracking_upper_body_only;if(ye.enabled&&U!=de.data_detected){U=de.data_detected;ye.timestamp_for_recording=RAF_timestamp;if(ye.active)window.dispatchEvent(new CustomEvent("SA_motion_recorder_on_active",e))}for(const _ of["左","右"]){this.arm_IK_constraint[_].enabled=false}be.copy(this.get_upper_body_rotation()).multiply(this._rot_body_camera_offset);this.upper_body_rotation_limiter(be);let E,r,x,P;if(de.enabled&&k.motion_tracking_upper_body_only){if(k.has_leg_IK==null)k.has_leg_IK=!k.IK_disabled?.test("左足IK")&&s.skin.targets.findIndex(e=>e.keys[0].name.indexOf("足IK")!=-1)!=-1;if(k.has_arm_IK==null)k.has_arm_IK=s.skin.targets.findIndex(e=>e.keys[0].name.indexOf("腕IK")!=-1)!=-1;const l=k.motion_tracking&&k.motion_tracking.arm_as_leg;const d={"左":l&&l.enabled&&(!l.linked_side||l.linked_side=="left"),"右":l&&l.enabled&&(!l.linked_side||l.linked_side=="right")};for(const c in this._skin){this._skin[c].pos.copy(D[c].position);this._skin[c].rot.copy(D[c].quaternion)}let e=de.data_detected;let o,n;if(e){t.call(this);const u=System._browser.camera.poseNet.hip_adjustment_weight;const p=ie.copy(E["センター"]).multiply(E["上半身"]);const h=k.motion_tracking?.hip_adjustment?.rotation_weight;o=(new THREE.Quaternion).copy(p).slerp(oe.set(0,0,0,1),1-(typeof h=="number"?h*u:.5));this.remove("skin","下半身");this.add("skin","下半身",{rot:o});if(this.skin["センター"]){let e=k.motion_tracking?.hip_adjustment?.displacement_weight;if(typeof e!="number")e=.25;e*=u;if(e){const m=MMD_SA_options.model_para_obj.left_leg_length/3*e;const f=J.set(0,m,0).applyQuaternion(p);f.x*=-1;f.z*=-1;f.sub(ee.set(0,m,0));if(this.skin["センター"][0].pos)this.skin["センター"][0].pos.copy(f);else this.skin["センター"][0].pos=f.clone();if(!this.skin["センター"][1].pos)this.skin["センター"][1].pos=this.skin["センター"][0].pos;n=this.skin["センター"][0].pos}}}for(const _ of["左","右"]){const g=_=="左"?"left":"right";x=k.motion_tracking&&k.motion_tracking.arm_default_stickiness&&(k.motion_tracking.arm_default_stickiness[g]||k.motion_tracking.arm_default_stickiness);P=x&&x.default_rotation_weight;let i=k.motion_tracking?.hip_adjustment?.[g]?k.motion_tracking.hip_adjustment[g].feet_fixed_weight:k.motion_tracking?.hip_adjustment?.feet_fixed_weight;if(typeof i!="number")i=1;if(i<1||(e||d[_])&&!k.has_leg_IK){const c=_+"足IK";let e,t;if(o){e=ie.copy(D["下半身"].quaternion);D["下半身"].quaternion.multiply(o)}if(n){t=J.copy(D["センター"].position);D["センター"].position.add(n)}const y=k.has_leg_IK?null:MMD_SA.get_bone_position(A,_+"足","全ての親");const M=i<1?MMD_SA.get_bone_position(A,_+"足首","全ての親"):ee;if(e)D["下半身"].quaternion.copy(e);if(n)D["センター"].position.copy(t);const b=k.has_leg_IK||i>0?MMD_SA.get_bone_position(A,_+"足首","全ての親"):M;const v=re.x_flipped?-1:1;if(k.has_leg_IK){const I=J.copy(b).sub(M.lerp(b,i));I.x*=v;I.y*=-1;I.z*=-1;if(!this._skin[c])this._skin[c]={pos:new THREE.Vector3,rot:new THREE.Quaternion};this._skin[c].pos.add(I);D[c].position.add(I)}else{const R=J.fromArray(D[_+"足"].pmxBone.origin);const T=R.sub(y).negate();const I=y.sub(M.lerp(b,i));I.x*=v;I.y*=-1;I.z*=-1;I.add(MMD_SA_options.model_para_obj.leg_IK_offset[_]);I.add(T);if(!this._skin[c])this._skin[c]={pos:new THREE.Vector3,rot:new THREE.Quaternion};this._skin[c].pos.copy(I);if(!d[_]){de.enable_IK(c,true);if(!this.skin[c])this.add("skin",c,{absolute:true,is_dummy:true,pos:true,priority:999})}D[c].position.copy(I);if(de.data_detected)D[_+"ひざ"].quaternion.set(0,0,0,1)}D[c].position.y+=this._skin[c]._offset_y_||0}if(d[_]){t.call(this);const I=a.call(this,_);D[_+"腕IK"].position.copy(I);de.enable_IK(_+"腕IK",true)}else{const c=_+"腕IK";let e;const L=this.skin[_+"手首"];if(L){t.call(this);if(!de.IK_disabled_check(c)){e=a.call(this,_)}else{if(this._skin[_+"腕"])this._skin[_+"腕"].rot.premultiply(r);if(this._skin[_+"手首"])this._skin[_+"手首"].rot.premultiply(MMD_SA.TEMP_q.copy(r).conjugate())}}if(e)this._skin[c].pos.copy(e)}if(H[_].enabled){const F=D[_+"足IK"];const C=H[_];C.target.copy(F.position);const j=F.pmxBone.IK;C.effector.copy(A.bones[j.effector].quaternion);for(let e=0;e{e.detail.result.links=C;e.detail.result.links_result=O[_]},{once:true});window.addEventListener("SA_camera_poseNet_process_bones_onended",e=>{const t=q[_];t.parent.copy(MMD_SA.get_bone_rotation_parent(A,_+"足","全ての親"));t.effector.copy(A.bones[j.effector].quaternion);for(let e=0;e{const t=e.detail.model;const a=t.mesh.bones_by_name;for(const n of["左","右"]){ye.set_boneKey(n+"足",null,a[n+"足"].quaternion,false);ye.set_boneKey(n+"ひざ",null,a[n+"ひざ"].quaternion,false);ye.set_boneKey(n+"足首",null,a[n+"足首"].quaternion,false);if(a[n+"足先EX"])ye.set_boneKey(n+"足先EX",null,a[n+"足先EX"].quaternion,false);for(const e of[n+"肩",n+"腕",n+"ひじ",n+"手首"]){if(a[e])ye.set_boneKey(e,null,a[e].quaternion,false)}ae.forEach((i,e)=>{let o=e==0?0:1;for(let t=o;t!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});B.forEach(e=>{let t=D[e];if(!t&&!/_DUMMY_/.test(e))return;var i=n[e][0].info[1];if((!i||/pose/.test(i))&&!k.motion_tracking_enabled)return;K.call(this,A,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)Q(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;K.call(this,o,e)});window.dispatchEvent(new CustomEvent("SA_camera_poseNet_process_bones_onended",e))}function c(e){if(de.enabled&&!de.data_detected_stable)return;var _=e.detail.model;var l=_.mesh;var d=_.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=d[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 c=MMD_SA_options.model_para_obj.facemesh_morph;var u=this.morph;var p={};var n=0;Object.keys(u).forEach(function(e){let t=u[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);p[e]=o;if(o)n++});Object.keys(p).forEach(function(t){let e=u[t];let i=p[t];if(i<0){ye.morph_active&&ye.set_morphKey(t,0,true);switch(t){case"にやり":t="ω";break;case"口角上げ":t="口角下げ";break;case"上":t="下";break}i=-i}if(ye.morph_active){let e=t;if(t=="まばたきL")e="ウィンク";else if(t=="まばたきR")e="ウィンク右";ye.set_morphKey(e,i,true)}let o=c[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=d[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)}})}function u(e,t,i){i.name=t;i.info=e.split("|");var o=i.info[0];var n=this[o][t];if(i.is_dummy){if(n&&n[0].is_dummy)return;i.no_blending=true;i.onProcessPosition=i.onProcessRotation=a;if(i.pos)i.pos=s;if(i.rot)i.rot=r}i.timestamp=RAF_timestamp;i.t_delta=0;i.t_delta_frame=(this.t_delta||0)*(t.indexOf("指")!=-1||t.indexOf("手首")!=-1?de.skip_hand_countdown_max+1:1);i.t_delta_frame=Math.max(Math.min(i.t_delta_frame,200),16.6667);if(n){if(RAF_timestamp==n[0].timestamp){n[0]=Object.assign(n[0],i)}else{if(!i.no_blending&&!re.video.paused){let e=de.use_3D_pose||i.info[1]=="facemesh"?.5+Math.max(Math.min((Math.max(i.t_delta_frame,RAF_timestamp-n[0].timestamp)-50)/150,1),0)*.5:1;if(i.pos&&n[0].pos){i.pos.lerp(n[0].pos,1-e)}if(i.rot&&n[0].rot){i.rot.slerp(n[0].rot,1-e)}if(i.weight!=null&&n[0].weight!=null){i.weight=i.weight*e+n[0].weight*(1-e)}}this[o][t]=[i,n[0]]}i._blend_default_motion=n[1]._blend_default_motion;i._idle_blend_default_motion=n[1]._idle_blend_default_motion}else{this[o][t]=[i,i]}if(ye.speed&&re.is_local_video&&ye.speed<1)i.no_blending=true}function p(e,t){delete this[e][t]}function h(){this.skin={};this.morph={};this._skin={};this._morph={};this.reset_to_default_motion_once=true;this._motion_path=""}function W(){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 V(){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=c.bind(this)};m.prototype.set_upper_body_rotation=function(e,t){if(!de.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=ie.set(0,0,0,1);const i=oe.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=S.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){W.prototype._q1=new THREE.Quaternion;W.prototype._q2=new THREE.Quaternion;ge=new W(0)});var ye=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;d[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 d,r;var c=0;var o=0;var u=0;var p=0;var n;var a=0;var t=0;const h=2;return{timestamp_for_recording:0,get enabled(){return t&&!re.video.paused},get morph_active(){return de.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!=D){let e=1;if(n){e=this.get_frame(D)-this.get_frame(n);if(e<0||e>30)e=1;if(e>1){const t=e-1;o+=t;for(const i in d){d[i].frame_length+=t}for(const i in r){r[i].frame_length+=t}}}c+=e;n=D;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 c},get stats(){return[o,l.boneKeys.length,l.morphKeys.length,u,p]},get time(){return Math.floor(c/30)+":"+(c%30+1)},get speed(){return t},set speed(e){t=e;if(e)this.start(e);else this.stop()},get vmd(){return t?null:l},set vmd(e){l=null},set_boneKey:function(e,t,i,o){let n=d[e];if(n==null){n=d[e]={frame_length:1};if(c>0)l.boneKeys.push(new _(e,null,null,0))}if(o&&ge.skin[e]&&n.timestamp==ge.skin[e][0].timestamp){let e;if(n.frame_count==c){const a=l.boneKeys[n.index];e=(!t||a.pos)&&(!i||a.rot)}else e=true;if(e){if(n.frame_count!=c){n.frame_length++;u++}return}}if(!t&&i&&n.is_rot_identity&&i.w==1){u++;return}n.is_rot_identity=i?i.w==1:n.is_rot_identity;if(n.frame_count==c){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(c-a.time*30);if(s>n.frame_length||s>10){const r=new _(e,null,null,(c-1)/30);r.pos=a.pos;r.rot=a.rot;l.boneKeys.push(r);u--}}n.timestamp=ge.skin[e]&&ge.skin[e][0].timestamp||0;l.boneKeys.push(new _(e,t,i,c/30))}n.frame_length=1;n.frame_count=c},set_morphKey:(()=>{function o(e,t,i){let o=r[e];if(o==null){o=r[e]={frame_length:1};if(c>0)l.morphKeys.push(new s(e,0,0))}if(i&&ge.morph[e]&&o.timestamp==ge.morph[e][0].timestamp){if(o.frame_count!=c){o.frame_length++;p++}return}t=Math.round(t*20)/20;if(t==o.weight){p++;return}o.weight=t;if(o.frame_count==c){const n=l.morphKeys[o.index];n.weight=t}else{if(o.index!=null){const n=l.morphKeys[o.index];const a=Math.round(c-n.time*30);if(ao.frame_length||a>10){l.morphKeys.push(new s(e,n.weight,(c-h)/30));p--}}o.timestamp=ge.morph[e]&&ge.morph[e][0].timestamp||0;l.morphKeys.push(new s(e,t,c/30))}o.frame_length=1;o.frame_count=c}return function(e,t,i){if(de.enabled){window.addEventListener("SA_motion_recorder_on_active",()=>{o.call(this,e,t,i)},{once:true})}}})(),start:function(e){t=e;n="";a=0;if(re.is_local_video){re.video.playbackRate=e;if(e<1)re.video.muted=true;re.video.loop=false;re.video.pause();MMD_SA.SpeechBubble.message(0,"Use the seek bar to go to the desired frame, press the play button and begin recording~!",5*1e3);C_media_control.style.visibility="inherit"}c=-1;o=0;u=0;p=0;d={};r={};l={boneKeys:[],morphKeys:[]}},stop:function(){t=0;if(re.is_local_video){re.video.playbackRate=1;re.video.muted=false;re.video.loop=true;re.video.pause();MMD_SA.SpeechBubble.message(0,"Motion recording has stopped. Double-click and you can export the motion to a file in VMD format~!",5*1e3)}else if(re.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}))}}}}();var Fe=[{},{}];var V=n.get("camera_hidden");var X;re={initialized:false,get ML_enabled(){return t},get ML_busy(){return _e.busy||de.busy},get ML_fps(){return 1e3/(de.enabled&&de._t||_e.enabled&&_e._t||1e3)},get ML_warmed_up(){var e=Fe[de.use_holistic?1:0];var t=!_e.enabled||e.facemesh;var i=!de.enabled||e.poseNet;var o=!Z.enabled||e.handpose;return t&&i&&o},get target_devicePixelRatio(){return b||window.devicePixelRatio},set target_devicePixelRatio(e){b=e==window.devicePixelRatio?0:e},get double_flip_mode(){return a&&!re.mirror_3D},set double_flip_mode(e){a=e},get video_flipped(){return!t?s:!!s^!!re.double_flip_mode},set video_flipped(e){s=e;this.reset_video_canvas()},get display_flipped(){return re.mirror_3D?false:s!=re.video_flipped},get mirror_3D(){return!t||!MMD_SA_options.user_camera.mirror_3D?false:MMD_SA_options.user_camera.mirror_3D==1?re.visible:true},get x_flipped(){return re.double_flip_mode||re.mirror_3D},get hidden_enforced(){return V||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||X},set display_floating(e){X=e;if(this.video_host)this.video_host.style.zIndex=this.display_floating?2:0},get video_timestamp(){return re.video.currentTime==null?performance.now()/2:re.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},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":"";ue=n+o},0,0,-1)});return function(e,t,i){if(!re.ML_enabled||!de.data_detected&&!_e.data_detected){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;ue=n+o}})(),motion_recorder:ye,camera_list:null,deviceId:null,start:async function(o){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;MMD_SA.reset_camera();this._camera_reset=MMD_SA._trackball_camera.object.clone();if(this.initialized){if(this.visible){this.hide();DEBUG_show("User camera:HIDDEN",2);return}}var a={video:this.set_constraints()};try{if(o){this.init_stream(o)}else{if(is_mobile){a.video.facingMode="user"}if(MMD_SA_options.Dungeon){MMD_SA_options.Dungeon.run_event([[{message:{content:"(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 e=this.camera_list;if(!e){try{e=await navigator.mediaDevices.enumerateDevices();e=e.filter(e=>e.kind=="videoinput");if(MMD_SA_options.user_camera.preference)e.sort((e,t)=>MMD_SA_options.user_camera.preference.label.test(e.label)&&-1||MMD_SA_options.user_camera.preference.label.test(e.label)&&1||0);this.camera_list=e}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 i;if(MMD_SA_options.Dungeon){await new Promise(t=>{MMD_SA_options.Dungeon.run_event([[{message:{content:(e.length?"Choose a camera."+e.map((e,t)=>"\n"+(t+1)+". "+e.label).join(""):"No camera is available on this device. Drop a local media file as input instead.")+"\n"+(e.length+1)+". Local media file\n"+(e.length+2)+". Cancel",bubble_index:3,branch_list:e.map((e,t)=>{return{key:t+1,branch_index:t+1}}).concat([{key:Math.min(e.length+1,8),branch_index:Math.min(e.length+1,8)},{key:Math.min(e.length+2,9),branch_index:Math.min(e.length+2,9)}])}}]].concat(e.map(e=>[{func:()=>{a.video.deviceId=e.deviceId;t()},ended:true}]).slice(0,7).concat([[{func:()=>{if(re.local_src){o=re.local_src;t();return true}else{DEBUG_show("(No local media file found)",3);MMD_SA_options.Dungeon.run_event(null,0,0)}}}],[{func:()=>{i=true;t()},ended:true}]])))})}if(i){DEBUG_show("(Canceled)",2);return}if(!o&&a.video.deviceId!=this.deviceId){t=await n();if(!t){DEBUG_show("(Camera not accessible)",3);return}}}if(o){re.init_stream(o)}else if(t){re.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)}}catch(s){if(MMD_SA_options.Dungeon&&MMD_SA_options.Dungeon.event_mode)MMD_SA_options.Dungeon.run_event({ended:true});re.init_stream();console.error(s);DEBUG_show("(ERROR: Camera unavailable, using fallback video instead)",3)}},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);window.addEventListener("resize",function(){re.video_track&&re.video_track.applyConstraints(re.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;this.show();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"){v(e)}else{this.stream=e;this.video_id=e.id;this.video_track=e.getVideoTracks()[0];this.video.srcObject=e;console.log("(New stream started)");setTimeout(function(){let e=re.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=re.video_track.getSettings();System._browser.console.log(Object.entries(t).map(e=>e[0]+":"+JSON.stringify(e[1])).join("\n"))},2e3)}if(_e.enabled)_e.reset_calibration()},get use_armIK(){return de.enabled||Z.enabled},bodyPix:function(){var o;var i=false;c={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";re.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");d.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=re.video_canvas,t,i,o){const n=MMD_SA.THREEX.SL;if(System._browser.snapshot.check_bodyPix()){re.video_canvas.style.visibility="inherit";re.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(re.video_canvas_bodyPix.width!=s||re.video_canvas_bodyPix.height!=r){re.video_canvas_bodyPix.width=s;re.video_canvas_bodyPix.height=r}const _=s/r/(e.width/e.height);const l=Math.round(s*Math.min(1/_,1));const d=Math.round(r*Math.min(_,1));const c=(s-l)/2;const u=(r-d)/2;const p=re.video_canvas_bodyPix.getContext("2d");p.globalCompositeOperation="copy";p.filter="blur("+Math.ceil(3/window.devicePixelRatio)+"px)";p.drawImage(this.mask,0,0,a.width,a.height,c,u,l,d);p.globalCompositeOperation="source-out";p.filter="none";p.save();if(re.mirror_3D){p.translate(s,0);p.scale(-1,1)}p.drawImage(n,0,0);p.restore();p.globalCompositeOperation="destination-over";p.drawImage(e,0,0,e.width,e.height,c,u,l,d);re.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=d.face_cover;if(!d.enabled||!e.complete)return;re.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;d.update_frame_local(re.video_canvas_bodyPix,r)}};return c}(),face_detection:function(){var t=false;function i(){d.initialized=true;if(!self.OffscreenCanvas)d.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);d.worker_initialized=true}else{re._needs_RAF=true;if(t._t)DEBUG_show(t._t);d.dets=t.dets;d.busy=0;re.video_canvas_face_detection.style.left=re.video_canvas.style.left;re.video_canvas_face_detection.style.top=re.video_canvas.style.top;if(!self.OffscreenCanvas){System._browser.on_animation_update.add(function(){d.update_frame_local(null,d.dets)},0,0)}}d.update_frame()}}d={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(re.initialized)re.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=d.enabled&&d.worker_initialized&&A&&!d.busy&&k&&d.camera_video_timestamp!=A;if(!e)return;d.busy=RAF_timestamp;d.camera_video_timestamp=A;d.camera_video_frame_id=D;re.video_canvas_face_detection.style.visibility="inherit";let t,i,o;t=re.video_canvas;i=t.width;o=t.height;let n=t.getContext("2d").getImageData(0,0,i,o).data.buffer;let a=re.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(!re.video_canvas_face_detection._offscreen&&self.OffscreenCanvas){s.canvas=re.video_canvas_face_detection.transferControlToOffscreen();re.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=re.video_canvas.width;let o=re.video_canvas.height;let n;if(!e){e=re.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,d,c;if(i.length){let t=1;i.forEach(function(e){_=e[2]*t;l=_*s/r;d=e[1]*t-l/2;c=e[0]*t-_/2;n.drawImage(a,0,0,s,r,d,c,l,_)})}else{_=Math.min(t,o);l=_*s/r;d=(t-l)/2;c=(o-_)/2;n.drawImage(a,0,0,s,r,d,c,l,_)}}};return d}(),facemesh:function(){var i=false;var N=0;var Y=0;var Z=true;var $=0;var J=[];var ee;var te;var ie;var b=false;var o=-1;var t;function n(e){if(!e&&t&&t==re.video_id)return;t=re.video_id;N=0;Y=0;Z=true;$=0;J=[];ee={};te={L:[],R:[]};var o={L:[159,145],R:[386,374]};["L","R"].forEach(function(t){for(var i=0;i<1;i++){let e=te[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]}ee[t]={_height_average:0,height_average:0,height_data:[],height_ref_pts:t=="R"?[334,330]:[105,101]}})}var a;var oe=[];var ne,ae,v;ne=!is_mobile;v=!is_chrome||is_mobile;var e;function s(){if(_e.initialized)return;_e.initialized=true;for(var e=0;e<4;e++)oe[e]=new THREE.Vector3;var o=[];if(System._browser.use_WASM_SIMD){o.push("simd=1")}if(h){ne=true}if(v){ne=true;o.push("use_mediapipe_facemesh=1")}if(ne){ne=true;if(_e.blink_detection==null)_e.blink_detection=true;o.push("use_face_landmarks=1")}if(ae){o.push("use_human_facemesh=1")}var t;if(MMD_SA_options.user_camera.ML_models.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=d;return t}function r(e,t,i){const o=new Path2D;o.moveTo(t[0][0]/2,t[0][1]/2);for(let e=1;e<3;e++){const n=t[e];o.lineTo(n[0]/2,n[1]/2)}if(i){o.closePath()}e.stroke(o)}const _=["_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 se;const l=["あ","い","う","お","にやり","ω","口角上げ","口角下げ","上","下","にこり","困る","怒り","まばたき","笑い","びっくり","まばたきL","まばたきR"];var d=function(){function K(e){if(!e||se)return;se={};e.categories.forEach((e,t)=>{const i=e.categoryName;se[i.charAt(0)+i.substring(1)]=t})}var U=0,W=0,V=0,Q=0;const X={};window.addEventListener("jThree_ready",()=>{for(const e of l.concat(["両目"])){X[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 x=typeof e.data=="string"&&e.data.charAt(0)==="{"?JSON.parse(e.data):e.data;if(typeof x==="string"){if(x=="OK"){_e.worker_initialized=true}else{DEBUG_show(x,2);System._browser.console.log(x)}}else if(x.posenet){Te({data:x})}else if(_e.enabled){re._needs_RAF=true;const t=Fe[de.use_holistic?1:0];if(!t.facemesh){t.facemesh=true;DEBUG_show("Facemesh ML ready",2)}let E="";if(x.faces.length){_e.data_detected++}else{_e.data_detected=0}if(x.faces.length&&x.faces[0].bb_center){S=x.faces[0].bb_center}else if(!de.enabled){S=[.5,.5]}if(x.faces.length&&_e.data_detected_stable){let g=x.faces[0];K(g.faceBlendshapes);let d=re.x_flipped?1:-1;const P={facemesh_data:g};let c,u,l;if(g.rotation){const T=g.rotation.matrix;pe.set(T[0],T[1],T[2],0,T[3],T[4],T[5],0,T[6],T[7],T[8],0,0,0,0,1)}else{let e=MMD_SA._v3a_.fromArray(g.mesh[152]).sub(MMD_SA._v3b.fromArray(g.mesh[10])).normalize();let t=MMD_SA._v3b_.fromArray(g.mesh[454]).sub(MMD_SA._v3b.fromArray(g.mesh[234])).normalize();let i=MMD_SA.TEMP_v3.crossVectors(t,e).normalize();t.crossVectors(e,i);pe.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(pe,"YZX");c=-e.x;u=-e.y;l=-e.z;let t=g.scaledMesh[454][0]-g.scaledMesh[234][0];let i=g.scaledMesh[454][1]-g.scaledMesh[234][1];let o;if(x.recalculate_z_rotation_from_scaledMesh){t/=Math.cos(u);i/=Math.cos(c);o=Math.sqrt(t*t+i*i)}else{t/=Math.cos(l);o=Math.abs(t/Math.cos(u))}_e.face_width=o;let n;if(x.recalculate_z_rotation_from_scaledMesh){n=Math.asin(i/o)}else{n=l}let a=new THREE.Quaternion;a.setFromEuler(MMD_SA._v3a.set(c,u*d,n*d),"YZX");let s=re.video_timestamp;let r=0;if(Q){r=Math.max(Math.min(s-Q,1e3),10);V+=r;if(++W>=20){U=1e3/(V/W);W=V=0}}Q=s;_e._t=x._t;ge.t_delta=U&&1e3/U||r||x.fps&&1e3/x.fps||x._t;if(_e.head_pose_enabled){if(System._browser.motion_control.enabled)P.head_rot=MMD_SA._v3a.clone();ge.add("skin|facemesh","首",{after_IK:true,rot:a,_rot_ratio:_e.face_width/Math.min(re.video_canvas.width,re.video_canvas.height),onProcessRotation:Ie})}if(!N)N=Date.now();if(Z){Y=~~(Math.min((Date.now()-N)/5e3,J.length/30,ie?te.L[0].eye_open_data.length/30:1,1)*100);Z=Y<100}let _=g.faceInViewConfidence>(ae?.75:.9)&&(re.video==re._image||!re.video.paused&&Math.abs(u)e-t).slice(e,J.length-e).reduce((e,t)=>e+t)/(J.length-e*2);if(!Z){$=m}}}let f=0;let y=0;let M=0;let b=0;["L","R"].forEach(function(e){let t=ee[e];t.height=g.faceBlendshapes?Math.max(g.faceBlendshapes.categories[se["eyeSquint"+(e=="L"?"Left":"Right")]].score,.01):MMD_SA._v3a.fromArray(g.mesh[t.height_ref_pts[0]]).distanceTo(MMD_SA._v3b.fromArray(g.mesh[t.height_ref_pts[1]]));t._height_average=t.height_average;if(!t._height_average){if(_)t.height_data.push(t.height);if(!t.height_data.length){t._height_average=t.height}else{let e=parseInt(J.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(!Z){t.height_average=t._height_average}}}M+=t.height/t._height_average});M/=2;M=(M-1)/.25*(M>1?2:1);if(m){if(h>m*1.05){y=Math.sqrt(Math.min((h-m*1.05)/(m*.25),1))}else if(h2){f=Math.pow(Math.min((p-2)/(m*1/3),1),.5);if(y>.25)b=(y-.25)/.75*.3}}let v=0;let w=0;let S=0;let A=0;let D=0;const I=_e.face_width/Math.min(re.video_canvas.width,re.video_canvas.height);const R=MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only||I>.2?1:Math.max(1-(.2-I)*8,0);let k={L:[0],R:[0]};if(ne){["L","R"].forEach(function(t){let i=0;k[t][i]=0;let o=te[t][i];let n=g.faceBlendshapes?Math.max(1-g.faceBlendshapes.categories[se["eyeBlink"+(t=="L"?"Left":"Right")]].score,.2):MMD_SA._v3a.fromArray(g.mesh[o.height_ref_pts[0]]).distanceTo(MMD_SA._v3b.fromArray(g.mesh[o.height_ref_pts[1]]));let a=o.eye_open_average;if(!a){if(_){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(!Z){o.eye_open_average=a}}else{a=o._eye_open_average}}if(_){if(o.eye_open_lower>n)o.eye_open_lower=n}o._eye_open_average=a;if(a){if(n>a){k[t][i]=Math.min(n/a,1.25)}else{let e=Math.min(o.eye_open_lower,a/2);k[t][i]=Math.max((n-e)/(a-e),0)}}})}if(g.faceBlendshapes){const L=g.faceBlendshapes.categories;const r=[L[se["eyeBlinkLeft"]].score,L[se["eyeBlinkRight"]].score];r.forEach((e,t)=>{const i=t==0?"L":"R";const o=te[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 F=!_e.blink_sync;const C=(F?Math.min(Math.abs(r[0]-r[1])/.4,1):0)*R;let e=F?Math.min(...r):(r[0]+r[1])/2;L[se["eyeBlinkLeft"]].score=r[0]*C+e*(1-C);L[se["eyeBlinkRight"]].score=r[1]*C+e*(1-C);for(const B of["eyeSquintLeft","eyeSquintRight"]){const z=B=="eyeSquintLeft"?"L":"R";const H=Math.min(Math.max((ee[z]._height_average||0)*.8,.2),.5);L[se[B]].score=Math.max(L[se[B]].score-H,0)/(1-H)}const j=Math.min(Math.max((m||0)*.8,.2),.6);L[se["mouthPucker"]].score=Math.pow(Math.max(L[se["mouthPucker"]].score-j,0)/(1-j),2);if(MMD_SA.THREEX.get_model(0).use_faceBlendshapes){L.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");ge.add("morph|facemesh",i,{weight:e.score})})}}if(Array.isArray(g.emotion)){g.emotion.forEach(e=>{switch(e.emotion){case"happy":v+=e.score;break;case"sad":w+=e.score;break;case"angry":case"disgust":S+=e.score;break;case"fear":A+=e.score;break;case"surprise":D+=e.score;break}})}if(g.faceBlendshapes){const L=g.faceBlendshapes.categories;let e=L[se["jawOpen"]].score;let t=(L[se["mouthSmileLeft"]].score+L[se["mouthSmileRight"]].score)/2;let i=(L[se["mouthUpperUpLeft"]].score+L[se["mouthUpperUpRight"]].score)/2;let o=L[se["mouthPucker"]].score;let n=L[se["mouthFunnel"]].score;let a=L[se["mouthShrugLower"]].score;a*=a;let s=L[se["browInnerUp"]].score;s*=s;let r=(L[se["browOuterUpLeft"]].score+L[se["browOuterUpRight"]].score)/2;let _=(L[se["browDownLeft"]].score+L[se["browDownRight"]].score)/2;let l=0,d=0,c=0,u=0;if(e<.2){if(o>.05){c=o;if(n>.1)u=(n-.1)/2}else if(t>.1){d=Math.min(t+i/2,1)}else{l=e+t}}else{if(o>.05){u=Math.min(e+n/2,1)}else{l=Math.min(e+(t+i)/3,1)}}if(n>.1){y=-(n-.1)*.75}else{y=Math.min(Math.max(t-.5,0)*1.5+Math.max(i-.5,0)*1.5,1)}v=Math.min(Math.max(t-.5,0)*1.5+Math.max(i-.5,0)*1.5-a,1);if(v<0){w=-v;v=0}v*=.6;w*=.5;t=Math.min(v,.4);if(_>.1){r=-(_-.1)/.9}else if(s>.1&&r>.1){r=((s-.1)/.9+(r-.1)/.9)/2}let p=(L[se["eyeBlinkRight"]].score+L[se["eyeBlinkLeft"]].score)/2;D=Math.max(r-p-.1,0);D=D*D/2;ge.add("morph|facemesh","あ",{weight:l});ge.add("morph|facemesh","い",{weight:d});ge.add("morph|facemesh","う",{weight:c});ge.add("morph|facemesh","お",{weight:u});ge.add("morph|facemesh","にやり",{weight:y});ge.add("morph|facemesh","口角上げ",{weight:i-a});ge.add("morph|facemesh","上",{weight:r});ge.add("morph|facemesh","にこり",{weight:v});ge.add("morph|facemesh","困る",{weight:w});ge.add("morph|facemesh","笑い",{weight:t});ge.add("morph|facemesh","びっくり",{weight:D});const F=!_e.blink_sync&&THREE.MMD.getModels()[0].pmx.morphs_index_by_name["まばたきL"]!=null;if(F){ge.add("morph|facemesh","まばたきL",{weight:Math.max(L[se["eyeBlinkRight"]].score-t,0)});ge.add("morph|facemesh","まばたきR",{weight:Math.max(L[se["eyeBlinkLeft"]].score-t,0)});ge.add("morph|facemesh","まばたき",{weight:0})}else{ge.add("morph|facemesh","まばたきL",{weight:0});ge.add("morph|facemesh","まばたきR",{weight:0});ge.add("morph|facemesh","まばたき",{weight:Math.max(p-t,0)})}let h,m,f;if(_e.auto_look_at_camera){const O=THREE.MMD.getModels()[0].mesh;const q=MMD_SA.TEMP_v3.copy(MMD_SA._trackball_camera.object.position).sub(MMD_SA._head_pos).normalize().applyQuaternion(MMD_SA.get_bone_rotation(O,"頭").conjugate());const G=MMD_SA._v3b.setEulerFromQuaternion(MMD_SA.TEMP_q.setFromUnitVectors(MMD_SA._v3a.set(0,0,1),q));h=-Math.sign(G.x)*Math.min(Math.abs(G.x/(Math.PI/4)),1);m=-Math.sign(G.y)*Math.min(Math.abs(G.y/(Math.PI/4)),1)}else{h=(L[se["eyeLookUpLeft"]].score+L[se["eyeLookUpRight"]].score)/2-(L[se["eyeLookDownLeft"]].score+L[se["eyeLookDownRight"]].score)/2;m=(L[se["eyeLookInRight"]].score+L[se["eyeLookOutLeft"]].score)/2-(L[se["eyeLookInLeft"]].score+L[se["eyeLookOutRight"]].score)/2}f={absolute:true,rot:(new THREE.Quaternion).setFromEuler(MMD_SA._v3a.set(-h*15/180*Math.PI,-m*20/180*Math.PI,0),"YZX")};ge.add("skin|facemesh","両目",f)}else{let e=v-(w+S+A+D*.5);if(e<0){b*=Math.max(1+e*2,0)}else{b=Math.min(e*.2+b*(1+e*.5),.4)}ge.add("morph|facemesh","にこり",{weight:X["にこり"].filter(Math.min(b+v*.75,.75))});ge.add("morph|facemesh","困る",{weight:X["困る"].filter(Math.min((w+A)/2*.75+(M<0?Math.max(-M*1-Math.max(y,0)*.5,0):0),.75))});ge.add("morph|facemesh","怒り",{weight:X["怒り"].filter(Math.min(S*.75,.75))});M+=D*.2;ge.add("morph|facemesh","笑い",{weight:X["笑い"].filter(b)});ge.add("morph|facemesh","びっくり",{weight:X["びっくり"].filter(D*.75)});ge.add("morph|facemesh","にやり",{weight:X["にやり"].filter(y)});let i=MMD_SA.TEMP_q.setFromEuler(MMD_SA._v3a.set(c,u,l),"YZX").conjugate();let o=[];[13,14,61,291].forEach(function(e,t){o[e]=oe[t].fromArray(g.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*f,0);if(r)r=Math.min(r/20,.75);r=Math.min(r+w*.25,1);r*=.5;f=f*(1-r);ge.add("morph|facemesh","あ",{weight:X["あ"].filter(f)});ge.add("morph|facemesh","お",{weight:X["お"].filter(r)});let _={L:[],R:[]};if(!_e.eye_tracking){}else if(ne){let i=[0,0];let o=[0,0];g.eyes.forEach(function(e,t){if(e){i[t]=Math.max(Math.min((e[3]*2+c/(Math.PI/2))*(1-Math.abs(c)/Math.PI),1),-1);o[t]=Math.max(Math.min((e[2]*2-u/(Math.PI/2))*(1-Math.abs(u)/Math.PI),1),-1)}});let e=(k.L[0]+k.R[0])/2;if(e>1)M+=(e-1)*2;else M-=(1-e)*.5;M=Math.min(M,1);let t=k.L[0]+k.R[0];if(t)t=k.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(X["両目"].filter(MMD_SA.TEMP_q.setFromEuler(MMD_SA._v3a.set(-(n-.3)*15/180*Math.PI,a*d*20/180*Math.PI,0),"YZX").toArray()))};ge.add("skin|facemesh","両目",s);let r=!_e.blink_sync&&THREE.MMD.getModels()[0].pmx.morphs_index_by_name["まばたきL"]!=null;let _=(r?Math.min(Math.max(Math.abs(k.L[0]-k.R[0])-(.25+(1-Math.min(Math.max((Math.PI/6-Math.abs(u))/(Math.PI/12),0),1))*1),0)/.25,1):0)*R;let l=r?Math.min(k.L[0],k.R[0]):(k.L[0]+k.R[0])/2;k.L[0]=k.L[0]*_+l*(1-_);k.R[0]=k.R[0]*_+l*(1-_);if(r){let e="まばたき"+(d==1?"L":"R");ge.add("morph|facemesh",e,{weight:X[e].filter(Math.max(Math.min(1-k.L[0]*.8-b,1),0))});e="まばたき"+(d==1?"R":"L");ge.add("morph|facemesh",e,{weight:X[e].filter(Math.max(Math.min(1-k.R[0]*.8-b,1),0))});ge.add("morph|facemesh","まばたき",{weight:0})}else{ge.add("morph|facemesh","まばたきL",{weight:0});ge.add("morph|facemesh","まばたきR",{weight:0});ge.add("morph|facemesh","まばたき",{weight:X["まばたき"].filter(Math.max(Math.min(1-k.L[0]*.8-b,1),0))})}}else{let e=g.eyes[0];let t=0;let i=0;if(e){t=Math.max(Math.min((e[3]*2+c/(Math.PI/2))*(1-Math.abs(c)/Math.PI),1),-1);i=Math.max(Math.min((e[2]*2-u/(Math.PI/2))*(1-Math.abs(u)/Math.PI),1),-1)}let o=M*.25;if(o<0)o=Math.min(o+b,0);let n=Math.max(Math.min(.1-t*(t<0?2:1)*.2-o,.5),0);ge.add("morph|facemesh","まばたき",{weight:n});let a=1.25+Math.pow((k.L[0]+k.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*d*20/180*Math.PI,0),"YZX")};ge.add("skin|facemesh","両目",s)}if(_e.eye_tracking)ge.add("morph|facemesh","上",{weight:X["上"].filter(Math.max(Math.min(M,1),-1))})}E=E||g.eyes.length&&[(!de.enabled?re.video_canvas.width+"x"+re.video_canvas.height+"("+_e.camera_video_frame_id+")\n":"")+(Z?"Calibrating("+Y+"%):Make a calm face!":"(face data calibrated)")+"/"+Math.round(g.faceInViewConfidence*100)+"%",g.emotion?JSON.stringify(g.emotion):"Neutral"].join("\n");if(ce)E+=(ue?"\n"+ue+"\n":"")+ce;System._browser.motion_control.process(P)}else{E="(no facemesh data)\n"+ce}if(!System._browser.overlay_mode&&!MMD_SA_options.user_camera.ML_models.debug_hidden){System._browser.on_animation_update.add(()=>{DEBUG_show(E&&E+(!de.enabled||!de.use_holistic?"\nF-FPS:"+Math.round(U)+"/"+Math.round(x.fps||0):"")+"\n"+"FPS:"+EV_sync_update.fps_last||"")},0,0)}_e.busy=0}_e.update_frame()}}();var w=document.createElement("canvas");var c=true;var S=[];var u=0;var p=0;_e={initialized:false,worker_initialized:false,faceBlendshapes_list:_,MMD_morph_list:l,get data_detected(){return u},set data_detected(e){if(e){if(!u){p=RAF_timestamp}}else{p=0}u=e},get data_detected_stable(){return i&&p&&RAF_timestamp-p>250},get head_pose_enabled(){return this.data_detected_stable||!de.enabled},get blink_detection(){return ie},set blink_detection(e){ie=e;if(i){if(ie){n()}else{MMD_SA_options.auto_blink=a!=null?a:MMD_SA_options.auto_blink}}},get auto_blink(){return b},set auto_blink(e){b=e},get eye_tracking(){return c},set eye_tracking(e){c=e;if(c){this.blink_detection=!!ne}else{this.blink_detection=false}if(i){if(!c){ge.remove("skin","両目");ge.remove("morph","まばたきL");ge.remove("morph","まばたきR");ge.remove("morph","まばたき");ge.remove("morph","上");ge.remove("morph","下")}}},get use_faceLandmarksDetection(){return ne},set use_faceLandmarksDetection(e){if(!this.initialized)ne=e},get use_mediapipe(){return v||de.enabled&&de.use_holistic},set use_mediapipe(e){return v=e},get use_faceBlendshapes(){return!de.enabled||!de.use_holistic},get calibrated(){return!Z&&Y>=100},export_calibration:function(){const e={facemesh_calibration_type:de.use_holistic?"holistic":"facemesh",lips_width_average:$,eyebrow_data:{L:{height_average:ee.L.height_average},R:{height_average:ee.R.height_average}},eye_data:{L:{eye_open_average:te.L[0].eye_open_average},R:{eye_open_average:te.R[0].eye_open_average}}};System._browser.save_file("facemesh_calibration.json",JSON.stringify(e,null,"\t"),"application/json")},import_calibration:function(e){this.reset_calibration();$=e.lips_width_average;for(const t of["L","R"]){Object.assign(ee[t],e.eyebrow_data[t]);Object.assign(te[t][0],e.eye_data[t])}Y=100;Z=false},face_width:0,get enabled(){return i},set enabled(e){if(i==!!e)return;i=!!e;this.busy=0;this.data_detected=0;S[0]=S[1]=.5;if(i){if(!this.initialized)s();a=MMD_SA_options.auto_blink;const t=de.use_holistic?1:0;n(o!=t);o=t}else{MMD_SA_options.auto_blink=a}x()},get bb_center(){return S},set bb_center(e){S=e},reset_calibration:n,get frames(){return ge},init:s,worker_onmessage:d,camera_video_timestamp:0,update_frame:function(e){async function t(){var e=_e.enabled&&_e.worker_initialized&&A&&!_e.busy&&!(de.enabled&&de.use_holistic)&&k&&_e.camera_video_timestamp!=A;if(!e)return;_e.busy=RAF_timestamp;_e.camera_video_timestamp=A;_e.camera_video_frame_id=D;if(ie){MMD_SA_options.auto_blink=b||false}let n;let a,s;let r,_;let l,d;let t;n=re.video_canvas;let i=n.width,o=n.height;l=d=0;a=r=i;s=_=o;let c=1;let u=MMD_SA_options.user_camera.pixel_limit.facemesh;if(u){if(a*s>u[0]*u[1]){c=Math.sqrt(a*s/(u[0]*u[1]));a=r=Math.round(a/c);s=_=Math.round(s/c);n=w;t=true}}let p,h,m;if(MMD_SA_options.user_camera.pixel_limit.facemesh_bb_ratio){p=MMD_SA_options.user_camera.pixel_limit.facemesh_bb_ratio;m=Math.round(Math.min(a,s)*p);r=m;_=m;let e=1;const M=5*(v?2:1);if(_e.data_detected"+r+"x"+_+"):"+[e,t,m,m].join(",")+"=>"+[l,d,r,_].join(","))}}else{if(n.width!=r||n.height!=_){n.width=r;n.height=_;console.log("Facemesh canvas("+a+"x"+s+")")}}f.drawImage(re.video_canvas,Math.round(e*c),Math.round(t*c),Math.round(i*c),Math.round(o*c),0,0,r,_)}let g=E&&v?await createImageBitmap(n,t?0:l,t?0:d,r,_):f.getImageData(t?0:l,t?0:d,r,_).data.buffer;let y={rgba:g,w:a*(h||1),h:s*(h||1),options:{use_facemesh:true,draw_canvas:true,flip_canvas:re.display_flipped,bb:{x:Math.round(l),y:Math.round(d),w:r,h:_,ratio:p||0,scale:h||1,timestamp:re.video_timestamp}}};if(self.FacemeshAT){y.canvas=re.video_canvas_facemesh}else if(!re.video_canvas_facemesh._offscreen&&self.OffscreenCanvas){y.canvas=re.video_canvas_facemesh.transferControlToOffscreen();re.video_canvas_facemesh._offscreen=true;console.log("(Facemesh: use offscreen canvas)")}le.postMessage(y,y.canvas?[y.canvas,y.rgba]:[y.rgba]);y.rgba=g=undefined;y=undefined}if(e||self.FacemeshAT){setTimeout(()=>{t()},0)}else{t()}}};return _e}(),poseNet:function(){var i=false;var t=true;var n=true;var a={};var o=null;var s=0;var r=0;var _=0;var l=null;var d=null;var c=0;de={get enabled(){return i},set enabled(e){if(i==!!e)return;i=!!e;$=0;De=false;this.data_detected=0;this.initial_data_detected=false;_=0;THREE.MMD.getModels()[0].mesh.visible=true;F.set(0,0,0);if(i){if(!this.initialized)U();if(G){worker_id=de.use_holistic?"legacy_holistic":"tasks_vision";if(!p[worker_id]){Fe=[{},{}];m.terminate();for(const t in p)delete p[t];m=new Worker(G);m.onmessage=Te;f=worker_id;p[f]=new K(f,m)}console.log("Web worker ID:"+f);m=p[f].worker;u=p[f].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()}x();if(de.use_holistic){setTimeout(()=>{if(i)_e.enabled=Z.enabled=true;else Z.enabled=false;DEBUG_show("(Holistic Mode:"+(i?"ON":"OFF")+")",2)},0)}},get data_detected(){return s},set data_detected(e){if(1){if(e){if(!s){r=RAF_timestamp}if(this.data_detected_stable){_=0}}else{r=0;if(!_){_=RAF_timestamp}if(RAF_timestamp-_>250){ge.reset()}}}s=e},get data_detected_stable(){return i&&(!_||RAF_timestamp-_<250||r&&RAF_timestamp-r>500)},get use_3D_pose(){return i&&t&&Se},set use_3D_pose(e){t=e},get use_holistic(){return o==null?h:o},set use_holistic(e){o=e},get _use_holistic_(){return h},set _use_holistic_(e){h=e},get skip_hand_countdown_max(){return this.use_holistic||B||MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only||de.shoulder_width/Math.min(re.video_canvas.width,re.video_canvas.height)>1/3?0:1},set IK_disabled(e){n=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 d!=null?d:!i||!!MMD_SA_options.user_camera.ML_models.pose.auto_grounding},set ground_plane_visible(e){d=e},get spine_length_ref(){if(c)return c;const e=MMD_SA_options.model_para_obj.left_leg_length/MMD_SA_options.model_para_obj.spine_length;return de.leg_scale_adjustment?Math.max(4.97462,MMD_SA_options.model_para_obj.spine_length*(e/1.83))*(21-de.leg_scale_adjustment)/20:Math.max(4.97462,MMD_SA_options.model_para_obj.spine_length)},set spine_length_ref(e){c=e},hip_adjustment_weight:1,leg_scale_adjustment:0,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||!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 ge},camera_video_timestamp:0,get busy(){return $},get initialized(){return w},get worker_initialized(){return u},set worker_initialized(e){u=p[f].initialized=e}};return de}(),handpose:function(){var t=false;Z={get enabled(){return t},set enabled(e){if(t==!!e)return;t=!!e;if(t){if(!this.initialized)U()}},get frames(){return ge},get busy(){return $},get initialized(){return w},get worker_initialized(){return u},set worker_initialized(e){u=p[f].initialized=e}};return Z}(),reset_video_canvas:function(){if(this.video_canvas){this.video_canvas.width=this.video_canvas.height=A=0;D=""}},show:function(){if(!this.initialized||this.visible)return;this.visible=true;if(re.target_devicePixelRatio!=window.devicePixelRatio){re.target_devicePixelRatio=0;re.video_track.applyConstraints(re.set_constraints()).then(function(){DEBUG_show("(camera size updated)",2)})["catch"](function(e){DEBUG_show("ERROR:camera size failed to update")})}g();if(this.hidden_enforced)this.hide()},hide:function(){if(!this.initialized||!this.visible)return;this.visible=false;this.video_canvas.style.visibility="hidden";d.enabled=false;c.enabled=false;y()},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(!b){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)}}re.target_width=o;re.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(e)t=Object.assign(t,e);console.log("Camera constraints",t);return t}};return re}(),data_filter:function(){class n{constructor(e=200,t=n.#reducer_scalar){this.data_list=[];this.time_average=e;if(typeof t=="string"){switch(t){case"vector3":this.reducer=n.#reducer_vector3;break;case"quaternion":this.reducer=n.#reducer_quaternion;break}}else{this.reducer=t}n.#init()}static#initialized;static#init(){if(n.#initialized)return;n.#initialized=true;n.#v1=new THREE.Vector3;n.#v2=new THREE.Vector3;n.#q1=new THREE.Quaternion;n.#q2=new THREE.Quaternion}static#reducer_scalar(e,t,i,o){return(typeof e=="number"?e:e.value/o.length)+t.value/o.length}static#v1;static#v2;static#reducer_vector3=function(e,t,i,o){return n.#v1.fromArray(Array.isArray(e)?e:e.value).lerp(n.#v2.fromArray(t.value),1/(i+1)).toArray()};static#q1;static#q2;static#reducer_quaternion=function(e,t,i,o){return n.#q1.fromArray(Array.isArray(e)?e:e.value).slerp(n.#q2.fromArray(t.value),1/(i+1)).toArray()};filter(e,i=System._browser.camera.initialized&&System._browser.camera.ML_enabled?System._browser.camera.video_timestamp:RAF_timestamp){if(!this.data_list.length||i!=this.data_list[this.data_list.length-1].timestamp)this.data_list.push({timestamp:i,value:e});if(this.data_list.length>1){this.data_list=this.data_list.filter((e,t)=>t==this.data_list.length-1||Math.abs(i-e.timestamp){switch(e.type){case"average":e.filter=new n(...e.para||[]);break;case"one_euro":e.filter=new OneEuroFilter(...e.para||[]);break}if(e.id)e.filter.id=e.id})}filter(t,i=System._browser.camera.initialized&&System._browser.camera.ML_enabled?System._browser.camera.video_timestamp:RAF_timestamp){this.filters.forEach(e=>{if(!e.condition||e.condition())t=e.filter.filter(t,i)});return t}}return t}(),motion_control:function(){var s,p,u,i,_,h;var c;var m;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=>h[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=>[h[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=>[h[e]]));if(n.press.length){const a=n.press.map(e=>h[e]);o=[...o.filter(e=>a.indexOf(e[0])==-1),...n.release.map(e=>[h[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 g={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);for(let e=this.list.length-1;e>=0;e--){if(this.list[e].timestamp>RAF_timestamp-3e3){if(ei.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(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 k=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 E=["0","1","2","3"];var x=[];var P=[];const I={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&&!d},get handedness(){return m},get off_hand(){return m=="左"?"右":"左"},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 h},get key_pressed(){return f.pressed},gestures:g,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(!g.list.length||g.list[0].timestamp!=RAF_timestamp){g.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 d={};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});g.list[0].hand_rot_YXZ=l;g.list[0].hand_facing=_;g.list[0].thumb_out=d;e.forEach(e=>{if(!r)return;if(!e._used)return;if(S){g.estimate(c,e);const t=g.search("index_up",{duration:1e3,hand_facing:"front",thumb_out:false});if(t){S=false;m=t._d;DEBUG_show("Motion control:READY",2)}}else if(e._d==m){g.estimate(c,e);const t=g.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 d;var o,n;function c(){if(e)return;d=new fp.GestureEstimator([g.custom.index_up,g.custom.index_thumb,g.custom.index_middle,g.custom.index_pinky,g.custom.palm_open,g.custom.thumb,g.custom.thumb_index,g.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}c();const a=await k();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 u(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 I.setMousePosition(t)})}let t;if(i.posenet_data){t=i.posenet_data.handpose;let e="";if(!t||!t.length){t=null;if(g.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==m?"R":"L";x.push(s+":");g.estimate(d,n);let i;i=g.search("palm_open",{hand:n,hand_facing:"front",condition:function(e){const t=this.hand;const i=y.fromArray(t.annotations.index[0]).sub(M.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==m){i=g.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=g.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=g.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+=m=="右"?1:3;break;case"Diagonal Up Right":e+=m=="右"?3:1;break}await f.activate(i,s,e,f.clear_list(s));x.push(e);continue}i=g.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(M.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=g.search("thumb",{hand:n});if(i){x.push("CANCEL");await f.releaseKey(...f.clear_list(s));continue}i=g.search("index_pinky",{hand:n});if(i){x.push("index_pinky");continue}}else{i=g.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(M.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=>[h[e]]));if(t.length)await f.releaseKey(...t.map(e=>[h[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==m)],[1,t.findIndex(e=>e._used&&e._d!=m)]]){if(l[1]!=-1)continue;const s=l[0]==0?"R":"L";if(g.search("palm_open",{time_limit:500,hand:{_d:l[0]==0?m:I.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 u(){if(e)return;t=new fp.GestureEstimator([fp.Gestures.VictoryGesture,fp.Gestures.ThumbsUpGesture,g.custom.index_up]);e=true}return{enabled:false,process:async function(e){if(!this.enabled)return;if(!e.posenet_data)return;u();const t=e.posenet_data.handpose;if(!t||!t.length)return;const i=t[0]._d==m?0:1;const o=m=="右"?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 d={x:-(-s.width/2+l[0])/(s.width/2*_),y:(-s.height/2+l[1])/(s.height/2*_)};d.x=Math.round(n+THREE.Math.clamp(d.x*r,-1,1)*n);d.y=Math.round(a+THREE.Math.clamp(d.y/r,-1,1)*a);const c=new p(d.x,d.y);await I.setMousePosition(c)}}}()};return I}(),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=p.get_specs();l.width=e.width;l.height=e.height;p._fps=e.fps;p.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 d(){if(!p.media_recorder||p.started)return;p.started=true;p.media_recorder.start();if(_&&p.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 c(){System._browser.video_capture.stop()}var u=[];const p={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});u.length=0;this.media_recorder.addEventListener("dataavailable",async e=>{u.push(e.data);if(!this.enabled){let e=new Blob(u,{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;u.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+(p._fps>-1?"/"+p._fps+"fps":""))+"/"+p.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)){d()}else{if(p.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",c,{once:true});s.mixer.addEventListener("finished",c,{once:true})}else{window.addEventListener("SA_MMD_model0_onmotionended",c,{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;d()})}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",c);e.mixer.removeEventListener("finished",c)}else{window.removeEventListener("SA_MMD_model0_onmotionended",c)}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 p})(),hotkeys:(()=>{class a{constructor(e,t){this.id=e.id;this.index=t;this.config=a.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 a.config_by_id[e]}static accelerators={};static register(e,t){if(!a.unregister(e))return false;const i=a.get_config(e);i.accelerator=t;t.forEach((e,t)=>{a.accelerators[e]=new a(i,t)});return true}static unregister(e){const t=a.get_config(e);if(!t)return false;t.accelerator.forEach(e=>{if(a.accelerators[e].is_global){try{webkit_electron_remote.globalShortcut.unregister(_acc)}catch(t){}}delete a.accelerators[e]});return true}static remove(e){if(a.unregister(e))delete a.config_by_id[e]}static add(i){a.remove(i.id);i.accelerator.forEach((e,t)=>{a.accelerators[e]=new a(i,t)})}static is_global=null;static register_global(i=!a.is_global){if(browser_native_mode){DEBUG_show("(Global hotkey is for app mode only.)",5);return}a.is_global=i;DEBUG_show("Global hotkey:"+(i?"ON":"OFF"),3);Object.values(a.accelerators).forEach(e=>{if(e.config.global_disabled)return;try{if(i){webkit_electron_remote.globalShortcut.register(e.accelerator,()=>{SA_topmost_window.SA_OnKeyDown(e.event)})}else{webkit_electron_remote.globalShortcut.unregister(e.accelerator)}e.is_global=webkit_electron_remote.globalShortcut.isRegistered(e.accelerator)}catch(t){}})}}window.addEventListener("SA_keydown",o=>{const n=o.detail.e;Object.values(a.config_by_id).some(e=>{const t=e.accelerator.some(e=>{const t=a.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 a})(),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;e0){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)}}}();SA_top_window.moveToAbsolute=function(e,t,i){if(absolute_screen_mode&&!i){webkit_window.setPosition(~~e,~~t)}else{this.moveTo(e,t)}};SA_top_window.moveByAbsolute=function(t,i){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;function n(){document.getElementById("Ldungeon_inventory").style.visibility=document.getElementById("Ldungeon_inventory").style.visibility=="hidden"?"inherit":"hidden"}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";document.body.addEventListener("dblclick",n);DEBUG_show("(NOTE: Double-click to show the menu)",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";document.body.removeEventListener("dblclick",n)}}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 h;var d,c;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)h=parent.WMP_wallpaper_mask}else{var u;if(!is_SA_child_animation){d=System.Gadget.Settings.readString("_screenLeft");c=System.Gadget.Settings.readString("_screenTop")}d=d?parseInt(d):null;c=c?parseInt(c):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 p,m,f;var n=LdesktopBG.style;try{n.pixelWidth=parent.screen.width;n.pixelHeight=parent.screen.height;var g=oShell.RegRead("HKCU\\Control Panel\\Colors\\Background");n.backgroundColor=/^\#/.test(g)?g:"rgb("+g.replace(/\W+/g,",")+")";p="HKCU\\Control Panel\\Desktop\\";if(WallpaperEngine_CEF_mode)m=oShell.RegRead(p+"Wallpaper")||self.SA_wallpaper_src&&/\.(png|bpm|jpg|jpeg)$/i.test(SA_wallpaper_src)&&SA_wallpaper_src;else m=self.SA_wallpaper_src==""?"":self.SA_wallpaper_src&&/\.(png|bpm|jpg|jpeg)$/i.test(SA_wallpaper_src)&&SA_wallpaper_src||oShell.RegRead(p+"Wallpaper");if(m){if(!this.wallpaper_mask_disabled){h=self.SA_wallpaper_mask_src||m.replace(/\.\w{3,4}$/,"_mask.png");if(!ValidatePath(h))h=null}f=oShell.RegRead(p+"WallpaperStyle");this.updateWallpaper(m,f)}if(D){this.updateWallpaper(D)}this.moveWallpaper(d||0,c||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(h){if(!this.bg_mask)this.bg_mask="(blank)"}else{u=true}}else{u=true}if(u&&this.Opacity<1&&(w3c_mode||HTA_use_GPU_acceleration)){this.body.style.opacity=this.Opacity;DEBUG_show("Opacity:"+this.Opacity*100+"%",2)}}if(l&&!h)this.bg_mask="(blank)";if(a&&(h||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 M=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,c){v.fillStyle=n.backgroundColor;v.fillRect(0,0,M,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(c=="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,d,c;if(i>e){n=0;_=(i-e)/2;s=d=e}else{n=(e-i)/2;_=0;s=d=i}if(o>t){a=0;l=(o-t)/2;r=c=t}else{a=(t-o)/2;l=0;r=c=o}var u=C_wallpaper_mask.getContext("2d");u.drawImage(this,n,a,s,r,_,l,d,c);System._browser.BGMask_Create(!h);if(!h)return;var p=new Image;p.onload=function(){var e=C_wallpaper_mask.getContext("2d");e.globalCompositeOperation="destination-in";e.drawImage(this,n,a,s,r,_,l,d,c);C_wallpaper_mask.style.visibility="inherit";DEBUG_show("Use wallpaper mask",2)};p.src=toFileProtocol(h)}}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(c=="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(!h);if(!h)return;var d=new Image;d.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)};d.src=toFileProtocol(h)}}if(w)w.onload=null;w=new Image;w.onload=t;w.src=toFileProtocol(e)}}this.wallpaper_canvas_update(m,f);if(!m){setTimeout("System._browser.BGMask_Create(true)",0)}}catch(A){}}var S=y.style;S.position="absolute";S.posLeft=-(d||0);S.posTop=-(c||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(!h);this.WMPMask_Draw()}}this._s_left=d;this._s_top=c},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 d=i.style;d.position="absolute";d.top=d.left="0px";d.width=parent.screen.width+"px";d.height=parent.screen.height+"px";d.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 d=this.bg_mask_image_resized;if(d&&d.width!=i){d.width=i;d.height=o;var c=this.bg_mask_image;d.getContext("2d").drawImage(c,0,0,c.width,c.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 u=parent.SA_child_animation[SA_child_animation_id];var p=u.x;var h=u.y;if(is_SA_child_animation&&parent.EQP_border_width){p-=parent.EQP_border_width;h-=parent.EQP_border_width}var m=p-n;var f=m;if(m<0)m=0;if(f<0)f=-f;else f=0;var g=h-a;var y=g;if(g<0)g=0;if(y<0)y=-y;else y=0;var M=s+n-p;if(M>i)M=i;var b=r+a-h;if(b>o)b=o;var v=this.C_WMP_wallpaper_mask_mixed_resized;if(v.width!=i||v._x!=m||v._y!=g){v.width=i;v.height=o;var w=v.getContext("2d");w.drawImage(_,m,g,M,b,f,y,M,b);if(d)w.drawImage(d,0,0);v._x=m;v._y=g}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,m,g,M,b,f,y,M,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-m)/(l+1);y=1-(1-y)*g;if(y<0)y=0;var M=1;if(f=s-l)M=(s-f)/(l+1);M=1-(1-M)*g;if(M<0)M=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}c[u]=t?Math.round(255*(1-b)):Math.round(255*b)}_.putImageData(d,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 d=a+","+s+","+o+","+n+","+r+","+_+","+o+","+n;if(e._match_str==d)return;e._match_str=d;e.width=t;e.height=i;var c=e.getContext("2d");c.globalCompositeOperation="copy";c.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 c=C_BG_mask.getContext("2d");c.globalCompositeOperation="copy";c.globalAlpha=this.bg_mask_image?1:1-this.Opacity;c.drawImage(this.wallpaper_canvas,a,s,o,n,r,_,o,n);if(this.bg_mask_image){c.globalCompositeOperation="destination-out";c.globalAlpha=this.Opacity;c.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,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.clientY=49&&n<49+SA_child_animation_max)&&o){var _=n-49;var l=is_SA_child_animation?parent:self;var d=l.document.getElementById("Ichild_animation"+_);if(!d||!d.contentWindow.is_SA_child_animation){DEBUG_show("(child animation "+(_+1)+" not found)",2);return true}var c=d.contentWindow;var u=c.parent;var p=u.System._browser;if(c.System.Gadget.Settings.readString("CSSTransform3D")||u.System.Gadget.Settings.readString("CSSTransform3D")){if(p._child_selected==_){p._child_selected=null;c.DEBUG_show("(deselected)",2);u.DEBUG_show("(child"+(_+1)+" deselected)",2);return true}p._child_selected=_}c.DEBUG_show("(selected)",2);u.DEBUG_show("(child"+(_+1)+" selected)",2);p.arrangeChildZ(_);c.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 d=l.document.getElementById("Ichild_animation"+_);if(!d||!d.contentWindow.is_SA_child_animation){DEBUG_show("(child animation "+(_+1)+" not found)",2);return true}var s=d.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 h=false;for(var m=0;m=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._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.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;if(WallpaperEngine_mode||browser_native_mode){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 d=s.x+t-this.drag_mouse_x;var c=s.y+i-this.drag_mouse_y;r.posLeft=s.x=d;r.posTop=s.y=c;o.document.getElementById("Ldebug").innerText=n.document.getElementById("Ldebug").innerText="(moving)";o.DEBUG_hide_sec=n.DEBUG_hide_sec=0;o.DEBUG_show("("+d+","+c+")",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 c={};var u={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=c[o]=c[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;break;case"↓":a=40;break;case"←":a=37;break;case"→":a=39;break;default:if(/([1-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:c["S"]&&c["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,d,c;var u=this.content_window.ChatboxAT.checkChatCommand(e);l=u.command;d=u.para1;c=u.para2;_=i.para.events.send_message({name:s,msg:e,command:l,para1:d,para2:c,id:o,pass:n})}if(!t)this.content_window.document.getElementById("Fchat").msg.value="";if(_!=null)return _;return e}};return t}(),camera:function(){var re;var d,r;var c;var _e,le;var de;var Z;var E=true;var n=new URLSearchParams(self.location.search.substring(1));var ce="";var ue="";var a=true;var s;var A=0;var D="";function _(){var s=re.video;if(!s.videoWidth||s.readyState<2){return}if(c.busy||RAF_animation_frame_unlimited&&!MMD_SA.WebXR.session&&D==re.video_frame_id&&!de.bb_clear){return}D=re.video_frame_id;A=RAF_timestamp;var n=re.video_canvas;var r=n.getContext("2d");if(de.bb_clear){if(s.pause&&!s.paused||--de.bb_clear<=0||de._bb&&de._bb_waiting){de.bb_clear=de._bb=de._bb_waiting=null;r.globalCompositeOperation="copy"}else{if(de._bb){r.globalCompositeOperation="source-over";r.fillStyle="black";let e=Math.max(de._bb[3],0);let t=Math.max(de._bb[0],0);const _=Math.min(de._bb[1]-e,n.width);const l=Math.min(de._bb[2]-t,n.height);if(re.video_flipped){e=n.width-(e+_)}r.fillRect(e,t,_,l);de._bb=null;de._bb_waiting=true}return}}var _,l;if(re.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.disabled?[_,l]: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{_=re.target_width;l=re.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*(re.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(re.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=!re.visible||c.enabled||d.initialized&&d.worker_initialized&&!d.dets||re.hidden_enforced?"hidden":"inherit"}function l(){if(c.enabled){c.update_frame()}else{if(_e.enabled){_e.update_frame(true)}else if(d.enabled){d.update_frame(true)}if(de.enabled||Z.enabled){Le(true)}}const i=re.video_canvas_facemesh.style;const e=re.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=re.ML_enabled&&!MMD_SA_options.user_camera.display.wireframe.hidden&&!MMD_SA_options.user_camera.display.webcam_as_bg?"inherit":"hidden"}var k;function g(){if(re.initialized){SL.style.transform=SL_2D_front.style.transform=re.mirror_3D?"scaleX(-1)":"none";re.video_canvas.style.transform=re.display_flipped?"scaleX(-1)":"none";re.reset_video_canvas()}if(!k&&re.initialized){k=true;System._browser.on_animation_update.add(_,0,0,-1);System._browser.on_animation_update.add(l,2,1,-1)}}function y(){SL.style.transform=SL_2D_front.style.transform=re.mirror_3D?"scaleX(-1)":"none";re.video_canvas.style.transform="none";re.reset_video_canvas();if(re.visible)return;if(k&&!re.ML_enabled){k=false;System._browser.on_animation_update.remove(_,0);System._browser.on_animation_update.remove(l,1);re.video_canvas_facemesh.style.visibility="hidden"}}var o=100;function M(e){if(!re.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=re.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 b=0;function v(e){if(!e)e=re.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(!re._image){re._image=new Image;Object.defineProperty(re._image,"videoWidth",{get:function(){return this.width}});Object.defineProperty(re._image,"videoHeight",{get:function(){return this.height}});Object.defineProperty(re._image,"readyState",{get:function(){return this.complete?4:0}})}if(re.video&&re.video.pause)re.video.pause();re.video=re._image;re._image.src=toFileProtocol(e)}else{re.video=re._video;re.video.loop=true;if(!re.video._initialized){re.video._initialized=true;re.video.addEventListener("canplaythrough",function(e){re.video.muted=true;re.media_control_enabled=true;SL_MC_simple_mode=true;SL_MC_video_obj=re.video;SL_MC_Place(1,0,-64);var t=ye.speed;if(t){re.video.playbackRate=t;if(t<1)re.video.muted=true}else{re.video.playbackRate=1}});re.video.addEventListener("timeupdate",function(e){SL_MC_Timeupdate(this)},true);re.video.addEventListener("ended",function(e){if(ye.speed)ye.stop()})}re.video.src=toFileProtocol(e)}re.video_id=e;re.local_src=e}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;const i=e.detail.e;switch(i.code){case"KeyZ":if(!i.ctrlKey)return;window.addEventListener("SA_camera_poseNet_update",()=>{t.motion_tracking.arm_as_leg.enabled=!t.motion_tracking.arm_as_leg.enabled;ge.reset_to_default_motion_once=true;DEBUG_show("Arm-as-leg control:"+(t.motion_tracking.arm_as_leg.enabled?"ON":"OFF"),3)},{once:true});break;default:return}}System._browser.hotkeys.add({id:"switch_motion_control_mode",accelerator:["Ctrl+Z"],process:e})});var t=false;function x(){var e=_e.enabled||de.enabled;if(t==!!e)return;t=!!e;if(e){g();ge.reset();ge.add_events();DEBUG_show("(Camera ML Mode:ON)",2)}else{if(re.initialized){re.video_canvas_face_detection.style.visibility="hidden";re.video_canvas_facemesh.style.visibility="hidden";y()}ge.remove_events();re._info="";DEBUG_show("(Camera ML Mode:OFF)",2)}}var w,u,$;var J,ee,te,Me;var ie,oe,S,P,I,R;var pe,ne;var T,L;var F;var be;var ae=["親","人","中","薬","小"];var ve=["thumb","index","middle","ring","pinky"];var se=["0","1","2","3"];var C={};window.addEventListener("jThree_ready",()=>{J=new THREE.Vector3;ee=new THREE.Vector3;te=new THREE.Vector3;Me=new THREE.Vector3;F=new THREE.Vector3;ie=new THREE.Quaternion;oe=new THREE.Quaternion;S=new THREE.Quaternion;P=new THREE.Quaternion;I=new THREE.Quaternion;R=new THREE.Quaternion;pe=new THREE.Matrix4;ne=new THREE.Quaternion;T=new THREE.Vector2;L=new THREE.Vector2;be=new THREE.Quaternion});var e;var i;var j;var we=true;var Se=true;var he;var h=true;var B,Ae,H;var De=false;var ke=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"];var Ee=[0,2,5,7,8,11,12,13,14,15,16,23,24,25,26,27,28];var xe=[];ke.forEach(e=>{xe.push({part:e,score:0})});var me,Pe;var O;function q(){if(O)return;O=true;const r=THREE.MMD.getModels()[0];const o=r.mesh.bones_by_name;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.arm_IK_offset={"左":(new THREE.Vector3).fromArray(o["左腕"].pmxBone.origin).sub(ee.fromArray(o["左腕IK"].parent.pmxBone.origin)),"右":(new THREE.Vector3).fromArray(o["右腕"].pmxBone.origin).sub(ee.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 s=o["左足首"].pmxBone.origin;MMD_SA_options.model_para_obj.hip_center=(new THREE.Vector3).fromArray(a).setX(0);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=s[1];MMD_SA_options.model_para_obj.leg_IK_offset={"左":(new THREE.Vector3).fromArray(o["左足"].pmxBone.origin).sub(ee.fromArray(o["左足IK"].parent.pmxBone.origin)),"右":(new THREE.Vector3).fromArray(o["右足"].pmxBone.origin).sub(ee.fromArray(o["右足IK"].parent.pmxBone.origin))};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]-s[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]-s[0],a[1]-s[1],a[2]-s[2]];let _=["左","右"];me={};_.forEach(n=>{["腕","ひじ"].forEach((e,t)=>{let i=n+e;let o=MMD_SA.get_bone_axis_rotation(r.mesh,i);me[i]={name:i,axis_rot:o,parent:t==0?{axis_rot:new THREE.Quaternion}:me[n+"腕"]};me[i].axis_rot_offset_inv=(new THREE.Quaternion).multiplyQuaternions(me[i].parent.axis_rot,MMD_SA.TEMP_q.copy(me[i].axis_rot).conjugate())})});Pe={};Pe[1]=(new THREE.Quaternion).multiplyQuaternions(MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.set(0,-Math.PI/2*1,Math.PI/2*1),"YZX"),MMD_SA._q1.copy(me["左腕"].axis_rot).conjugate());Pe[-1]=(new THREE.Quaternion).multiplyQuaternions(MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.set(0,-Math.PI/2*-1,Math.PI/2*-1),"YZX"),MMD_SA._q1.copy(me["右腕"].axis_rot).conjugate());MMD_SA_options.model_para_obj.finger_base={};_.forEach(s=>{let e=o[s+"手首"].pmxBone.origin;ae.forEach((e,t)=>{let n=s+e+"指";let i=t==0&&o[n+se[0]]?0:1;if(!o[n+se[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+se[a.base_index+(o-i)];let t=MMD_SA.get_bone_axis_rotation(r.mesh,e);me[e]={name:e,axis_rot:t,parent:o==i?me[s+"ひじ"]:me[n+se[a.base_index+(o-1-i)]]};me[e].axis_rot_offset_inv=(new THREE.Quaternion).multiplyQuaternions(me[e].parent.axis_rot,MMD_SA.TEMP_q.copy(me[e].axis_rot).conjugate())}})});for(const l in me){if(l.indexOf("指")!=-1){MMD_SA.TEMP_v3.setEulerFromQuaternion(me[l].axis_rot,"ZYX");MMD_SA.TEMP_v3.z*=-1;me[l].axis_rot.setFromEuler(MMD_SA.TEMP_v3,"ZYX")}me[l].axis_rot_inv=me[l].axis_rot.clone().conjugate()}MMD_SA_options.model_para_obj.rot_arm_adjust=me;console.log(me)}const p={};let m;let f;let G;class K{constructor(e,t){this.id=e;this.worker=t}initialized=false}async function U(){if(w)return;w=true;q();var t=[];if(is_mobile){t.push("use_mobilenet=1")}if(h){t.push("use_holistic=1");e=i=false;Se=he=true}if(e){t.push("use_human=1");B=true;e=true;i=false;j=false;Ae=true;H=true}else if(i){t.push("use_mixed_human=1");e=true;i=true;j=true;H=true}else{e=false;i=false;j=true}if(Se){t.push("use_blazepose=1");he=true}if(he){t.push("use_mediapipe=1");if(e){Ae=true;H=false}we=true}if(we){t.push("use_movenet=1")}if(MMD_SA_options.user_camera.ML_models.worker_disabled&&_e.initialized&&!_e.worker_initialized){await new Promise(function(e,t){var i=setInterval(()=>{if(_e.worker_initialized){clearInterval(i);e()}},100)})}else{await _e.init()}if(MMD_SA_options.user_camera.ML_models.worker_disabled){m={postMessage:function(e,t){PoseAT.onmessage({data:e})}};let e=document.createElement("script");e.onload=function(){PoseAT.init(m,t)};e.src="js/pose_lib.js";document.head.appendChild(e)}else{G="js/pose_worker.js"+(t.length?"?"+t.join("&"):"");f=de.use_holistic?"legacy_holistic":"tasks_vision";console.log("Web worker ID:"+f);m=new Worker(G);p[f]=new K(f,m)}m.onmessage=Te}var Ie=function(){let f;window.addEventListener("jThree_ready",()=>{f=new System._browser.data_filter([{type:"one_euro",id:"head_rot",para:[30,1,2,1,4]}])});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}var r=o[0].rot_parent;if(!r){const u=de.enabled&&MMD_SA.MMD.motionManager.para_SA.motion_tracking?.head_rotation_weight||0;if(u==1){r=new THREE.Quaternion}else{r=MMD_SA.get_bone_rotation_parent(e,t,e).conjugate();if(de.enabled)r.premultiply(oe.copy(this._rot_body_offset).multiply(this._rot_body_camera));if(u)r.slerp(a,u)}}o[0]._rot_parent=r;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()}var _=s.toAxisAngle()[1]%(Math.PI*2);if(_>Math.PI)_=Math.PI*2-_;else if(_<0&&_<-Math.PI)_+=Math.PI*2;_=Math.abs(_);n=de.use_3D_pose?.5:.3+Math.max(_-Math.PI/2,0)/(Math.PI/2)*.2;var l=ie.multiplyQuaternions(r,s);l.fromArray(f.filter(l.toArray()));var d=J.setEulerFromQuaternion(l,"YZX");var c=[d.x<0?n+(.5-n)*.5:n,n,n];l.setFromEuler(ee.fromArray(d.toArray().map((e,t)=>Math.sign(e)*Math.min(Math.abs(e),Math.PI/2)*c[t])),"YZX");if(de.enabled){const p=MMD_SA.MMD.motionManager.para_SA.motion_tracking;const h=1-(p?.motion_default_weight?.head||0)*this.camera_weight;if(h){const m=oe.copy(i.quaternion).premultiply(S.copy(this._body_motion_rot[0]["首"]).conjugate());i.quaternion.slerp(m,h);m.copy(e.bones_by_name["頭"].quaternion).premultiply(S.copy(this._body_motion_rot[0]["頭"]).conjugate());e.bones_by_name["頭"].quaternion.slerp(m,h)}}i.quaternion.multiply(l);e.bones_by_name["頭"].quaternion.multiply(l);o[0]._rot_neck=i.quaternion.clone();o[0]._rot_head=e.bones_by_name["頭"].quaternion.clone();if(ye.active){ye.set_boneKey(t,null,i.quaternion,true);ye.set_boneKey("頭",null,e.bones_by_name["頭"].quaternion,false)}if(n<.5){const i=e.bones_by_name["上半身2"];i.quaternion.multiply(ie.setFromEuler(J.setEulerFromQuaternion(s,"YZX").multiply(ee.fromArray(c.map(e=>1-e*2))),"YZX"))}}}();var Re=1*10;var fe=function(){var g=[];var o;var n;window.addEventListener("jThree_ready",()=>{o=new System._browser.data_filter([{type:"average"}]);fe.v_hip=n=new THREE.Vector3});function e(e){var r=e.keypoints[5];var _=e.keypoints[6];var l=e.keypoints[11];var d=e.keypoints[12];if(r.score<=0||_.score<=0)return;var c=e.keypoints3D[5];var u=e.keypoints3D[6];g=[{point2D:[{position:new THREE.Vector3},{position:new THREE.Vector3}],data3D:{length:0,z_diff:0}}];const p=de.spine_length_ref;let h=1;if(l.score>0&&d.score>0){let e=MMD_SA._v3a.addVectors(c,u).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;h=Math.min(Math.max((Math.abs(o)-Math.PI/4)/(Math.PI/4),0),1);let n=T.copy(l.position).add(d.position).multiplyScalar(.5);let a=L.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=p*(t*2)}if(h){let e=MMD_SA._v3b.copy(c).sub(u);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=L.copy(r.position).add(_.position).multiplyScalar(.5);let a=n.clone();let s=T.copy(r.position).distanceTo(_.position);n.y=n.y+s*1.5/Math.abs(Math.cos(o));if(n.y>re.video_canvas.height){a.y=Math.max(a.y-(n.y-re.video_canvas.height),0);n.y=re.video_canvas.height}g[0].point2D[0].position.lerp(a,h);g[0].point2D[1].position.lerp(n,h);g[0].data3D.length=g[0].data3D.length*(1-h)+p*(t*3)*h}}function t(){if(!g.length)return;var d=System._browser.camera;var c=d.video_canvas.width;var u=d.video_canvas.height;var p=J;var h=[];const e=c/u;const t=SL.width/SL.height;const m=e{p.set((e.point2D[0].position.x/c*2-1)*m,(-(e.point2D[0].position.y/u)*2+1)*f,.5);var t=MMD_SA._v3a.copy(p.unproject(d._camera_reset).sub(d._camera_reset.position).normalize());p.set((e.point2D[1].position.x/c*2-1)*m,(-(e.point2D[1].position.y/u)*2+1)*f,.5);var i=MMD_SA._v3b.copy(p.unproject(d._camera_reset).sub(d._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);h.push({z:-t.z*1.5,id:e.id})});h.sort((e,t)=>t.z-e.z);var i=h[0].z;this.z=i;z=o.filter(i);this.z_smoothed=z;g=[]}function i(e){if(MMD_SA.WebXR.session){n.set(0,0,0);return}n.copy(e).unproject(re._camera_reset).sub(re._camera_reset.position).normalize();if(Re)fe.estimate();const t=re._camera_reset.position.z-THREE.MMD.getModels()[0].mesh.position.z;let i=t;if(Re&&fe.z)i=fe.z_smoothed||fe.z;n.multiplyScalar(-i/n.z)}return{prepare:e,estimate:t,get_hip_center:i}}();var Q=(()=>{function P(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 d=a(_)-4*r*l;if(d>=0){var c=[(-_+s(a(_)-4*r*l))/(2*r),(-_-s(a(_)-4*r*l))/(2*r)];if(d==0){return[c[0]]}return c}return[]}var I,R,T;var L;window.addEventListener("jThree_ready",()=>{I=new THREE.Vector3;R=new THREE.Vector3;T=new THREE.Vector3;L=new THREE.Quaternion});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 _=T.copy(a).sub(r);const l=n;const d=(l.x*_.x+l.y*_.y+l.z*_.z-(r.x*_.x+r.y*_.y+r.z*_.z))/_.lengthSq();const c=MMD_SA._v3b.set(r.x+_.x*d,r.y+_.y*d,r.z+_.z*d);const u=_.normalize();const p=R.copy(n).sub(c).normalize().negate();const h=I.crossVectors(u,p).normalize();const m=(new THREE.Plane).setFromNormalAndCoplanarPoint(u,n);const f=(new THREE.Plane).setFromNormalAndCoplanarPoint(MMD_SA.TEMP_v3.set(0,1,0),MMD_SA._v3a.set(0,o,0));const g=m.intersectPlane(f);if(!g)return;pe.set(u.x,u.y,u.z,0,p.x,p.y,p.z,0,h.x,h.y,h.z,0,0,0,0,1);ne.setFromBasis(pe);const y=MMD_SA.TEMP_v3.copy(n).sub(c).length();let M=f.intersectLine(new THREE.Line3(n,c),T);if(!M)return;M=-M.sub(n).length();g[1].applyQuaternion(ne);const b=g[1].y/g[1].z;n.sub(s);n.applyQuaternion(ne);const v=P(y,n.z,n.y,b,M);if(!v.length)return;const w=v.map(e=>{e-=n.z;return Math.asin(e/y)});const S=i=="左"?1:-1;const A=MMD_SA.get_bone_rotation(t,"上半身2",null,t);const D=L.copy(A).conjugate();const k=R.copy(a).sub(s).normalize().applyQuaternion(D);const E=e.use_smallest_angle?w.sort((e,t)=>Math.abs(e)-Math.abs(t))[0]:w[S==-1?w.length-1:0];const x=MMD_SA.TEMP_q.setFromAxisAngle(k,E);t.bones_by_name[i+"腕"].quaternion.premultiply(x)}})();var Te=function(){function O(e,t){let i=me[t];e.premultiply(i.axis_rot).multiply(i.axis_rot_inv);e.multiplyQuaternions(i.axis_rot_offset_inv,e)}function q(e,t){if(de.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(ye.active){if(MMD_SA_options.user_camera.ML_models.pose.use_legIK){const r=MMD_SA.TEMP_v3.copy(i.position);r.sub(s);ye.set_boneKey(t,r,o[0].rot?i.quaternion:null,true)}window.addEventListener("SA_MMD_model"+e._model_index+"_process_bones_after_IK",()=>{ye.set_boneKey(n+"足",null,e.bones_by_name[n+"足"].quaternion,true);ye.set_boneKey(n+"ひざ",null,e.bones_by_name[n+"ひざ"].quaternion,true)},{once:true})}i.quaternion.set(0,0,0,1)}function G(e,t){const i=t.charAt(0);if(!MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only)return;var o=e.bones_by_name;var n=o[t].quaternion;n.multiplyQuaternions(be,n)}function K(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=J.copy(fe.v_hip);if(MMD_SA.WebXR.session){a.set(0,0,0)}else{const c=re._camera_reset.position.z-THREE.MMD.getModels()[0].mesh.position.z;a.z=MMD_SA_options.user_camera.ML_models.pose.estimate_z_depth===false?0:c+a.z;if(i[0]._v_hip_offset)a.add(i[0]._v_hip_offset)}if(MMD_SA_options.user_camera.ML_models.pose.position_offset)a.add(MMD_SA_options.user_camera.ML_models.pose.position_offset);i[0].pos.copy(a);var s=(new THREE.Vector3).copy(i[1].pos).lerp(i[0].pos,o);var r=MMD_SA.get_bone_position(n,"左足","全ての親");var _=MMD_SA.get_bone_position(n,"右足","全ての親");var l=MMD_SA.TEMP_v3.copy(r).add(_).multiplyScalar(.5).sub(MMD_SA_options.model_para_obj.hip_center).negate();if(de.auto_grounding){let e=MMD_SA.get_bone_position(n,"左足首","全ての親");let t=MMD_SA.get_bone_position(n,"右足首","全ての親");let i=e.y0){THREE.MMD.getModels()[n._model_index].resetPhysics(15+d*2)}F.copy(s)}function D(r,_,e,t){function i(e,t,i){if(typeof e=="number")return e;if(/^(\w+)([\+\-])([\d\.])$/.test(e)){const o=(RegExp.$2=="+"?1:-1)*parseFloat(RegExp.$3);const n=MMD_SA.TEMP_v3.copy(_);const a=RegExp.$1;if(a=="default"){n.copy(ge._skin[r].pos).sub(r.indexOf("腕")!=-1?MMD_SA_options.model_para_obj.arm_IK_offset[l]:MMD_SA_options.model_para_obj.leg_IK_offset[l]).applyQuaternion(ge._skin[r].rot_parent_inv)}else if(a=="elbow"){if(t=="y"){const s=c?.motion_tracking?.arm_tracking?.elbow_lock?.[l=="左"?"left":"right"]?._elbow_y;if(s!=null&&s!=0){n.y=s-MMD_SA.get_bone_position(d,l+"腕",d).y}}}return(n[t]+o)/i}return 0}const l=r.charAt(0);const o=r.indexOf("腕")!=-1?MMD_SA_options.model_para_obj.left_arm_length:MMD_SA_options.model_para_obj.left_leg_length;const n=l=="左"?"left":"right";const a=THREE.MMD.getModels()[0];const d=a.mesh;const c=MMD_SA.motion[a.skin._motion_index].para_SA;let s;if(e){for(const g of["x","y","z"]){const y=e[g];if(!y)continue;const u=y.unit_length||o;if(y.scale!=null)_[g]*=typeof y.scale?.[n]=="number"&&y.scale[n]||y.scale;if(y.add)_[g]+=i(y.add?.[n]||y.add,g,u)*u;if(y.min!=null)_[g]=Math.max(_[g],i(y.min?.[n]||y.min,g,u)*u);if(y.max!=null)_[g]=Math.min(_[g],i(y.max?.[n]||y.max,g,u)*u)}if(e.rotation)_.applyEuler(MMD_SA.TEMP_v3.copy(e.rotation).multiplyScalar(Math.PI/180));if(e.camera_weight&&r.indexOf("腕")==-1)_.applyQuaternion(MMD_SA.TEMP_q.set(0,0,0,1).slerp(ge._rot_camera,e.camera_weight));const f=e.position_to_rotation;if(f){const M=d.bones_by_name;const b=te.set(Math.atan2(_.z,_.y),0,-Math.atan2(_.x,_.z));const v={upper:{q:ie},lower:{q:oe}};for(const x of["upper","lower"]){const P=l+(x=="upper"?"足":"ひざ");const I=M[P];v[x].name=P;v[x].q.copy(I.quaternion);I.quaternion.set(0,0,0,1);if(!f[x])continue;const R=Me.set(0,0,0);for(const g of["x","y","z"]){const y=f[x][g];if(!y)continue;let e=0;const T=y.rot_formula?.[n]||y.rot_formula;if(T?.length==1){e=b[T]*180/Math.PI}if(y.add)e+=y.add?.[n]||y.add;if(y.scale!=null)e*=typeof y.scale?.[n]=="number"&&y.scale[n]||y.scale;if(y.curve){const L=y.curve?.[n]||y.curve;const F=(e-L.ini)/(L.end-L.ini);if(F>0&&F<1)e=Math.pow(F,L.pow_factor)*(L.end-L.ini)+L.ini}if(y.min!=null)e=Math.max(e,y.min?.[n]||y.min);if(y.max!=null)e=Math.min(e,y.max?.[n]||y.max);R[g]=e/180*Math.PI}I.quaternion.setFromEuler(R,"XZY");if(x=="upper")s=I.quaternion.clone()}const w=MMD_SA.get_bone_position(d,l+"足","全ての親");const S=MMD_SA.get_bone_position(d,l+"足首","全ての親");const A=re.x_flipped?-1:1;const D=te.fromArray(M[l+"足"].pmxBone.origin);const k=D.sub(w).negate();const E=w.sub(S);E.x*=A;E.y*=-1;E.z*=-1;E.add(MMD_SA_options.model_para_obj.leg_IK_offset[l]);E.add(k);E.y-=MMD_SA_options.model_para_obj.left_leg_IK[1]+(M["センター"].position.y-M["センター"].pmxBone.origin[1]);_.copy(E);for(const x in v)M[v[x].name].quaternion.copy(v[x].q)}}else{if(t)t(_)}const u=_.length();const p=e?.length_max||1;const h=e?.length_min;if(u>o*p)_.normalize().multiplyScalar(o*p);else if(h!=null&&u{var f;window.addEventListener("jThree_ready",()=>{f=new System._browser.data_filter([{type:"average",para:[200,"vector3"]}])});return function(e,t){if(de.IK_disabled_check(t))return;var i=e.bones_by_name[t];var o=this.skin[t];var n=Math.max(Math.min(o[0].t_delta/o[0].t_delta_frame,1),0);var a=t.charAt(0);var s=J.copy(o[1].pos).lerp(o[0].pos,n);if(o[0].data_filter||o[1].data_filter){s.fromArray(f.filter(s.toArray()))}const r=MMD_SA.MMD.motionManager.para_SA;if(r.motion_tracking_upper_body_only){const u=r?.motion_tracking?.arm_tracking?.transformation?.position;D(a+"腕IK",s,u)}const _=MMD_SA.get_bone_rotation_parent(e,t,e);if(!o[0]._IK_absolute){s.applyQuaternion(this.offset_upper_body_camera_rotation(ie.copy(_).conjugate(),r?.motion_tracking?.arm_tracking?.transformation?.position?.camera_weight||1))}var l=ee.fromArray(e.bones_by_name[a+"腕"].pmxBone.origin).sub(te.fromArray(i.parent.pmxBone.origin));var d=MMD_SA.get_bone_position(e,a+"腕",i.parent.name).sub(l);s.add(d);const c=this.arm_IK_constraint[a];if(c.enabled){arm0=MMD_SA.get_bone_position(e,a+"腕",e);const p=ee.copy(s).applyQuaternion(_).add(c.arm_pos);const h=te.copy(c.target).sub(p);if(!c.target_radius||h.length()>c.target_radius){const m=p.sub(c.target).add(h.normalize().multiplyScalar(c.target_radius));s.sub(m.applyQuaternion(_.conjugate()))}}s.add(MMD_SA_options.model_para_obj.arm_IK_offset[a]);i.position.copy(s)}})();var k=function(){let D={};let k={};window.addEventListener("jThree_ready",()=>{D["左"]=new System._browser.data_filter([{type:"one_euro",para:[30,1,1,1,4]}]);D["右"]=new System._browser.data_filter([{type:"one_euro",para:[30,1,1,1,4]}]);k["左"]=[];k["右"]=[];for(let e=0;e<5;e++){k["左"][e]=new System._browser.data_filter([{type:"average",para:[200]}]);k["右"][e]=new System._browser.data_filter([{type:"average",para:[200]}])}});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;o.fromArray(D[a].filter(o.toArray()));const s="YXZ";const r=MMD_SA.TEMP_v3.setEulerFromQuaternion(o,s);const _=MMD_SA.MMD.motionManager.para_SA.motion_tracking.arm_as_leg.transformation?.rotation||{};let l=Math.sign(r.y)*Math.min(Math.abs(r.y*(_.y?.scale||1)),Math.PI/2);const d=_.y?.foot_ratio||.25;r.y=l*d;r.z=Math.sign(r.z)*Math.min(Math.abs(r.z*(_.z?.scale||.5)),Math.PI/3);r.x*=_.x?.scale||.5;const c=[];let u=0;const p=this.skin[e];let h;if(p[0]._finger_x){if(p[1]._finger_x){const b=Math.max(Math.min(p[0].t_delta/p[0].t_delta_frame,1),0);h=p[0]._finger_x.map((e,t)=>e*b+p[1]._finger_x[t]*(1-b))}else{h=p[0]._finger_x}}if(h){for(let e=0;e<5;e++){c[e]=k[a][e].filter(h[e])}c[0]=(c[0]+c[1])/2;c.forEach(e=>{u+=e});u/=5;r.x-=u}r.x=Math.sign(r.x)*Math.min(Math.abs(r.x),Math.PI/2);o.setFromEuler(r,s);this._rot_=o.clone();this._rot_y=l;const m=this.get_blend_default_motion("skin",a+"足IK",true);if(m)l*=1-m;const f=MMD_SA.get_bone_position(n,a+"足",n);const g=MMD_SA.get_bone_rotation_parent(n,a+"足",n).conjugate();const y=MMD_SA.get_bone_position(n,e,n).sub(f).negate().normalize().applyQuaternion(g);const M=MMD_SA.TEMP_q.setFromAxisAngle(y,l*(1-d));if(0&&n.bones_by_name[a+"足D"]){n.bones_by_name[a+"足"].quaternion.premultiply(M);n.bones_by_name[a+"足D"].quaternion.premultiply(M)}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(f).negate().normalize().applyQuaternion(g);const w=ie.setFromUnitVectors(J.set(0,1,0),y);n.bones_by_name[a+"足"].quaternion.copy(w).multiply(oe.setFromEuler(J.set(-v.angleTo(y),0,0)))}n.bones_by_name[a+"足"].quaternion.premultiply(M);t._update_IK_and_AddTrans(false,a+"足","下半身")}if(u&&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+se[1]]);if(!S){let t=0;for(let e=1;e<4;e++){t+=c[e]}t/=4;const A=(c[1]-t)/2;n.bones_by_name[a+"足先EX"].quaternion.setFromEuler(J.set(-u*.5,0,A),"XZY")}else{n.bones_by_name[a+"足先EX"].quaternion.setFromEuler(J.set(-u*.5,0,0))}t._update_IK_and_AddTrans(false,a+"足先EX")}if(h){ae.forEach((e,t)=>{const i=a+"足"+e+"指";const o=n.bones_by_name[i]||n.bones_by_name[i+se[1]];if(o)o.quaternion.multiply(ie.setFromEuler(J.set(-c[t]*.5,0,0)))})}}}();var U=function(){let g={};window.addEventListener("jThree_ready",()=>{g["左"]=new System._browser.data_filter([{type:"one_euro",para:[30,1,1,1,4]}]);g["右"]=new System._browser.data_filter([{type:"one_euro",para:[30,1,1,1,4]}])});return function(e,t){var i=THREE.MMD.getModels()[e._model_index];var o=MMD_SA.THREEX.get_model(e._model_index).is_T_pose;var n=e.bones_by_name[t];var a=t.charAt(0);var s,r,_,l;var d=e.bones_by_name[a+"手捩"];var c;var u=this.skin[t];var p=Math.max(Math.min(u[0].t_delta/u[0].t_delta_frame,1),0);r=ie.set(0,0,0,1);if(d){if(d.quaternion.x||d.quaternion.y||d.quaternion.z){d.quaternion.conjugate();i._update_IK_and_AddTrans(false,a+"手捩")}d.quaternion.set(0,0,0,1)}const h=a=="左"?1:-1;var m=u[0].rot_parent;if(!m){m=MMD_SA.get_bone_rotation(e,"上半身2",null,e);m.premultiply(oe.copy(this._rot_body_offset).multiply(this._rot_camera).conjugate());m.multiply(MMD_SA.get_bone_rotation_parent(e,a+"手首","上半身2")).conjugate()}u[0]._rot_parent=m;r.multiply(u[0].no_blending?u[0].rot:MMD_SA.TEMP_q.copy(u[1].rot).slerp(u[0].rot,p));r.multiplyQuaternions(m,r).multiply(Pe[h]);r.fromArray(g[a].filter(r.toArray(),System._browser.camera.video_timestamp));n.quaternion.copy(r);if(d){_=d.pmxBone.fixedAxis;if(_){_=MMD_SA._v3a.fromArray(_);if(o)_.setY(0).setZ(0).normalize();const f=n.quaternion.toAxisAngle();let e=J.setEulerFromQuaternion(MMD_SA.TEMP_q.setFromAxisAngle(f[0].applyQuaternion(MMD_SA._q1.copy(me[a+"腕"].axis_rot).conjugate()),f[1]),"XZY").x*-h;if(e*h<-Math.PI/1.5)e+=Math.PI*2*h;l=-e*.5;c=oe.setFromAxisAngle(_,l);this.skin[a+"手捩"][0].rot.copy(c);n.quaternion.multiplyQuaternions(c.conjugate(),n.quaternion)}}if(ye.active){ye.set_boneKey(t,null,n.quaternion,true);if(!de.IK_disabled_check(a+"腕IK")){ye.set_boneKey(a+"腕",null,e.bones_by_name[a+"腕"].quaternion,true);ye.set_boneKey(a+"ひじ",null,e.bones_by_name[a+"ひじ"].quaternion,true)}}}}();var W=0,V=0,Q=0,X=0;let N,Y;window.addEventListener("jThree_ready",()=>{N=new System._browser.data_filter([{type:"one_euro",id:"torso_rot",para:[30,1,1,1,3]}]);Y=new System._browser.data_filter([{type:"one_euro",id:"chest_rot",para:[30,1,1,1,3]}])});return function(e){var o=typeof e.data=="string"&&e.data.charAt(0)==="{"?JSON.parse(e.data):e.data;if(typeof o==="string"){if(o=="OK"){de.worker_initialized=true}else{DEBUG_show(o,2);System._browser.console.log(o)}}else if(de.enabled){window.dispatchEvent(new CustomEvent("SA_camera_poseNet_update"));re._needs_RAF=true;de._bb=null;const n=Fe[de.use_holistic?1:0];let e;if(de.enabled&&!n.poseNet){e=true;n.poseNet=true}if(Z.enabled&&!n.handpose){e=true;n.handpose=true}if(e)DEBUG_show("Pose ML ready",2);ce=(_e.enabled?"\n":"")+re.video_canvas.width+"x"+re.video_canvas.height+"("+de.camera_video_frame_id+")\n";let t=re.video_timestamp;let i=0;if(X){i=Math.max(Math.min(t-X,1e3),10);Q+=i;if(++V>=20){W=1e3/(Q/V);V=Q=0}}X=t;de._t=o._t;ge.t_delta=W&&1e3/W||i||o.fps&&1e3/o.fps||o._t;if(de.use_holistic){n.facemesh=true;if(!o.facemesh){_e.data_detected=0}}let x=[];let P=[];let I=re.x_flipped?1:-1;const r=THREE.MMD.getModels()[0];const a=r.mesh.bones_by_name;const E=MMD_SA.THREEX.get_model(0).is_T_pose;const T=MMD_SA.MMD.motionManager.para_SA;const l=T.motion_tracking&&T.motion_tracking.arm_as_leg;const L={"左":l&&l.enabled&&(!l.linked_side||l.linked_side=="left"),"右":l&&l.enabled&&(!l.linked_side||l.linked_side=="right")};let B;if(de.enabled){if(o.posenet&&o.posenet.score>.3){de.data_detected++;de.initial_data_detected=true;if(de.data_detected_stable){if(De){De=false;r.mesh.visible=true}B=o.posenet;let D=de.use_3D_pose;if(Se){B._keypoints=B.keypoints;B._keypoints3D=B.keypoints3D;let o=[];let n=[];Ee.forEach((e,t)=>{let i=B.keypoints[e];i.part=ke[t];o.push(i);i=B.keypoints3D[e];i.part=ke[t];n.push(i)});B.keypoints=o;B.keypoints3D=n}const _=we?.3:!Ae?.5:.1;B.keypoints.forEach(e=>{e.score-=_});if(D){B._keypoints3D.forEach(e=>{e.score-=_})}if(Ae){let i={};B.keypoints.forEach(e=>{i[e.part]=e});let o=[];for(let t=0;t<=16;t++){let e=B.keypoints[t];if(!e)o.push(xe[t]);else if(e.part!=ke[t])o.push(i[ke[t]]||xe[t]);else o.push(e)}B.keypoints=o}let e=B._keypoints||B.keypoints;let t=e.map(e=>e.position.x);let i=e.map(e=>e.position.y);const c=[Math.min(...i),Math.max(...t),Math.max(...i),Math.min(...t)];e=B.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 f=Math.max(u[1]-u[3],u[2]-u[0])/2;c[0]=Math.min(c[0],u[0]-f);c[1]=Math.max(c[1],u[1]+f);c[2]=Math.max(c[2],u[2]-f);c[3]=Math.min(c[3],u[3]-f);de._bb=c;if(!_e.head_pose_enabled){_e.bb_center[0]=B.keypoints[0].position.x/re.video_canvas.width;_e.bb_center[1]=B.keypoints[0].position.y/re.video_canvas.height}if(D){let e=B._keypoints[0].position;let t=B._keypoints[3].position;let i=B._keypoints[6].position;const g=J.copy(i);const M=ee.copy(t).sub(g);const b=MMD_SA._v3a_.copy(e);const v=(b.x*M.x+b.y*M.y+b.z*M.z-(g.x*M.x+g.y*M.y+g.z*M.z))/M.lengthSq();const w=MMD_SA._v3b.set(g.x+M.x*v,g.y+M.y*v,g.z+M.z*v);let o=b.sub(w).normalize();let n=MMD_SA._v3b_.copy(t).sub(MMD_SA._v3b.copy(i)).normalize();let a=MMD_SA.TEMP_v3.crossVectors(n,o).normalize();n.crossVectors(o,a);pe.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);ne.setFromBasis(pe);let s=ne.conjugate();s=s.clone().multiply(MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.set(Math.PI/4,0,0)));if(!_e.head_pose_enabled){ge.add("skin","首",{after_IK:true,rot:s,onProcessRotation:Ie});ge.skin["首"][1]._rot_mixed&&ge.skin["首"][1].rot.copy(ge.skin["首"][1]._rot_mixed)}ge.add("skin","首_DUMMY_",{rot:s,_rot_from_pose:s.clone(),onProcessRotation:Ie})}let a=B.keypoints[5];let s=B.keypoints[6];let p=new THREE.Quaternion;let h=T.motion_tracking_upper_body_only;if(h){ce+="\n("+(T.motion_tracking?.arm_as_leg?.enabled?"🦶":"🙋")+"upper body only)\n"}if(D&&Re)fe.prepare(B);let m=0;let k;if(a.score>0&&s.score>0){let l,d;let c,u;if(D){l=B.keypoints3D[5];d=B.keypoints3D[6];let o=B.keypoints3D[11];let n=B.keypoints3D[12];if(h||o.score<=0||n.score<=0){h=true}else{if(B.keypoints[11].position.y>re.video_canvas.height||B.keypoints[12].position.y>re.video_canvas.height){h=true}let e=MMD_SA._v3b.copy(o).sub(n).normalize();let t=MMD_SA.TEMP_v3.set(1,0,0);let i=ee.setFromVectorSpherical(t,e);m=i.z;if(1||h)i.z=0;p.setFromEuler(i,"YZX")}let e=MMD_SA._v3a.addVectors(l,d).multiplyScalar(.5).normalize();e.applyQuaternion(MMD_SA.TEMP_q.copy(p).conjugate());let t=MMD_SA.TEMP_v3.set(0,1,0);t.y*=-1;if(T.motion_tracking_upper_body_only){const F=ee.setFromVectorSpherical(t,e);F.fromArray(N.filter(F.toArray()));c=(new THREE.Quaternion).setFromEuler(F,"YZX")}else{c=(new THREE.Quaternion).setFromVectorSpherical(t,e);if(h){c.multiplyQuaternions(p,c);p.set(0,0,0,1)}}let i=MMD_SA._v3b.copy(l).sub(d).normalize();i.applyQuaternion(MMD_SA.TEMP_q.multiplyQuaternions(p,c).conjugate());x_axis=MMD_SA.TEMP_v3.set(1,0,0);let a=ee.setFromVectorSpherical(x_axis,i);if(T.motion_tracking_upper_body_only)a.fromArray(Y.filter(a.toArray()));u=(new THREE.Quaternion).setFromEuler(a,"YZX");let s=0;let r=a.y;let _=(s+r)%(Math.PI*2);if(_>Math.PI)_=Math.PI*2-_;else if(_<0&&_<-Math.PI)_+=Math.PI*2;c.multiply(ie.setFromEuler(J.set(0,_/2-s,0),"YZX"));u.multiply(ie.setFromEuler(J.set(0,_/2-r,0),"YZX"));ge.add("skin","センター",{rot:p.clone(),priority:9});if(ye.active){if(!ge.skin["センター"][0].pos&&ge.skin["センター"][1].pos)ge.skin["センター"][0].pos=ge.skin["センター"][1].pos}ge.add("skin","上半身",{rot:c.clone()});ge.add("skin","上半身2",{rot:u.clone()});k=ie.copy(p).multiply(c).multiply(u).conjugate()}de.shoulder_width=J.copy(a.position).distanceTo(ee.copy(s.position));let w=Math.sqrt(Math.pow(a.position.x-s.position.x,2)+Math.pow(a.position.y-s.position.y,2));let S=0;if(!D){S=Math.asin((a.position.y-s.position.y)/w);S=Math.max(Math.min(S/(Math.PI/4),1),-1)*Math.PI/4*I}let e=I==1?[1,0]:[0,1];let t=[B.keypoints[9],B.keypoints[10]];let A=-1;if(!D&&t[0].score>0&&t[1].score>0&&Math.sqrt(Math.pow(t[0].position.x-t[1].position.x,2)+Math.pow(t[0].position.y-t[1].position.y,2))<(re.video_canvas.width+re.video_canvas.height)/2/25){A=t[1].score>t[0].score?0:1;if(t[A].score>.3)A=-1}w=_e.face_width*2||w;e.forEach(function(e,t){let n,a,s;let r;let _=t==0?"左":"右";let l=B.keypoints[5+e];let d=B.keypoints[7+e];let i=B.keypoints[9+e];let c=(MMD_SA_options.user_camera.ML_models.pose.use_armIK==null?!T.motion_tracking_upper_body_only:!MMD_SA_options.user_camera.ML_models.pose.use_armIK)&&!L[_];let u=false;let o=i.score>0&&i.position.x>=0&&i.position.x<=re.video_canvas.width&&i.position.y>=0&&i.position.y<=re.video_canvas.height;if(T.motion_tracking_upper_body_only&&!o){c=false}const p=(new THREE.Quaternion).setFromEuler(MMD_SA.TEMP_v3.set(0,0,S));if(0&&T.motion_tracking_upper_body_only){ge.add("skin",_+"肩",{is_dummy:true,rot:true})}else{if(E)p.fromArray(MMD_SA.THREEX.utils.convert_A_pose_rotation_to_T_pose(_+"肩",p.toArray()));ge.add("skin",_+"肩",{absolute:!(T.motion_tracking_upper_body_only&&T.motion_tracking?.motion_default_weight?.shoulder),rot:p})}let h,m,f;if(D){h=B.keypoints3D[5+e];m=B.keypoints3D[7+e];f=B.keypoints3D[9+e]}let g=I*(e==0?-1:1);let y,M,b;const v="YZX";if(D&&d.score>0){y=MMD_SA._v3b.copy(h).sub(m).normalize().applyQuaternion(k);M=MMD_SA.TEMP_v3.set(g,0,0);b=(new THREE.Quaternion).setFromUnitVectors(M,y);if(E)b.premultiply(MMD_SA.TEMP_q.copy(p).conjugate())}if(i.score>0&&e!=A){P.push({pos:i.position,dir:e,d:_,visible:o});if(D){let o;if(d.score>0){let e=J.copy(m).sub(f).normalize().applyQuaternion(k).applyQuaternion(MMD_SA.TEMP_q.copy(b).conjugate());M=MMD_SA.TEMP_v3.set(g,0,0);o=(new THREE.Quaternion).setFromUnitVectors(M,e)}if(!c||d.score<=0){c=false;let e=MMD_SA._v3a.copy(h).sub(f);let t=d.score>0?MMD_SA.TEMP_v3.copy(h).distanceTo(m)+MMD_SA.TEMP_v3.copy(m).distanceTo(f):.5;let i=Math.min(e.length()/t,1);e.normalize().multiplyScalar(i*MMD_SA_options.model_para_obj.left_arm_length);n=e.x;a=e.y;s=r=e.z;if(b){let e;if(L[_]){e=k.clone().conjugate().multiply(b).multiply(o).conjugate()}O(b,_+"腕");ge.add("skin",_+"腕",{absolute:true,rot:b,_rot_hand_parent:e});if(o){O(o,_+"ひじ");ge.add("skin",_+"ひじ",{absolute:true,rot:o})}}}else{O(o,_+"ひじ");O(b,_+"腕");ge.add("skin",_+"腕",{absolute:true,rot:b,priority:-1,onFinish:G});ge.add("skin",_+"ひじ",{absolute:true,rot:o})}}else{u=true;let e=l.position.x-i.position.x;let t=l.position.y-i.position.y;n=e/w*MMD_SA_options.model_para_obj.shoulder_width*I;a=t/w*MMD_SA_options.model_para_obj.shoulder_width;if(d.score>0){let e=Math.min(Math.sqrt(Math.pow(i.position.x-d.position.x,2)+Math.pow(i.position.y-d.position.y,2))/w,1);let t=Math.min(Math.sqrt(Math.pow(l.position.x-d.position.x,2)+Math.pow(l.position.y-d.position.y,2))/w,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{if(L[_]){ge.add("skin",_+"手首",{rot:new THREE.Quaternion});ge.remove("skin",_+"足首")}if(d.score>0){if(D){if(!c){c=false;y=MMD_SA._v3a.copy(h).sub(m).normalize();y.multiplyScalar(MMD_SA_options.model_para_obj.left_arm_length);n=y.x*I;a=y.y;s=r=y.z}else{c=true;O(b,_+"腕");ge.add("skin",_+"腕",{absolute:true,rot:b,priority:-1,onFinish:G})}}else{c=false;u=true;let e=l.position.x-d.position.x;let t=l.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*I;a=Math.cos(o)*MMD_SA_options.model_para_obj.left_arm_length*Math.sign(t)}}else{if(D){if(!T.motion_tracking_upper_body_only)return;s=r=0}else{u=true}if(n==null){c=false;n=MMD_SA_options.model_para_obj.left_arm_to_IK_xy[1]*(_=="左"?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)}}}x.push({pos:{x:n,y:a,z:s,z_posenet:r},dir:e,d:_,IK_disabled:c,IK_absolute:u})})}else{h=true}if(D&&!h){if(!h){let e=re.video_canvas.width;let t=re.video_canvas.height;let i=new THREE.Vector3;let o=B.keypoints[11].position;let n=B.keypoints[12].position;const S=e/t;const A=SL.width/SL.height;const C=S0){v=MMD_SA._v3a.copy(y).sub(b);w=v.length();S=M.score>0?MMD_SA.TEMP_v3.copy(y).distanceTo(M)+MMD_SA.TEMP_v3.copy(M).distanceTo(b):.7;v.normalize().multiplyScalar(Math.min(w/S,1)*MMD_SA_options.model_para_obj.left_leg_length)}if(de.leg_scale_adjustment&&b.score>0){let e=1;let t=1;let i,o,n;let a,s,r;const _=te.copy(y);const l=Me.copy(b).sub(_);let d,c;if(M.score>0){const e=ee.copy(M);const t=(e.x*l.x+e.y*l.y+e.z*l.z-(_.x*l.x+_.y*l.y+_.z*l.z))/l.lengthSq();d=J.set(_.x+l.x*t,_.y+l.y*t,_.z+l.z*t);c=e.sub(d);s=te.copy(y).sub(M).length();r=te.copy(y).sub(d).length();a=c.length()}else{s=S/2;r=Math.min(l.length()/2,s);a=Math.sqrt(s*s-r*r)}const A=a/S;const D=re.video_canvas.width;const k=re.video_canvas.height;const E=MMD_SA.TEMP_v3;const x=fe.v_hip;const P=B.keypoints[11+f];const I=B.keypoints[15+f];const R=MMD_SA_options.model_para_obj.left_leg_length;const u=D/k;const p=SL.width/SL.height;const h=u0){t=Math.sqrt((s*s-e*e*r*r)/(a*a))||0;if(t){}else{o=0;n=true;i=s/r}if(o!=null){ce+="\n"+g+":"+i+"(x"+o+")"+(n?"<>":"")+"\n";e=i;t=o}else ce+="\n"+g+":"+e+"(x"+t+")\n";if(e!=1){const F=te.copy(y).add(l.multiplyScalar(e)).sub(b);for(const j of[27,29,31]){const e=B._keypoints3D[j+f];Object.assign(e,MMD_SA.TEMP_v3.copy(e).add(F))}b=B.keypoints3D[15+f];const C=d.sub(y).multiplyScalar(e).add(y).add(c.multiplyScalar(t));M=B.keypoints3D[13+f]=Object.assign(M,C);v.multiplyScalar(e)}}else{v.multiplyScalar(e);ce+="\n"+g+"(IK):"+e+"(x"+t+")\n"}}let n,a;let t;if(M.score>0){t=MMD_SA._v3b.copy(y).sub(M).normalize().applyQuaternion(MMD_SA.TEMP_q.copy(p).conjugate());let e=MMD_SA.TEMP_v3.set(0,1,0);e.y*=-1;a=ee.setFromVectorSpherical(e,t);n=(new THREE.Quaternion).setFromEuler(a,"XZY");i+=a.x}let s=!MMD_SA_options.user_camera.ML_models.pose.use_legIK;if(b.score>0){let i,o;if(M.score>0){i=J.copy(M).sub(b).normalize().applyQuaternion(MMD_SA.TEMP_q.copy(p).conjugate());o=te.copy(i).applyQuaternion(MMD_SA.TEMP_q.copy(n).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));a.y=e[1]*t;n.setFromEuler(a,"XZY")}if(!s||M.score<=0){de.enable_IK(g+"足IK",true);u.push({pos:v.clone(),rot:[n],dir:f,d:g})}else{o=te.copy(i).applyQuaternion(MMD_SA.TEMP_q.copy(n).conjugate());let e=MMD_SA.TEMP_v3.set(0,1,0);e.y*=-1;let t=(new THREE.Quaternion).setFromVectorSpherical(e,o);de.enable_IK(g+"足IK",false);u.push({rot:[n,t],dir:f,d:g})}const r=B._keypoints3D[29+f];const _=B._keypoints3D[31+f];if(r.score>0&&_.score>0){let e=MMD_SA._v3a_.copy(r).sub(b).normalize();let t=MMD_SA._v3b_.copy(r).sub(_).normalize();let i=J.crossVectors(e,t).normalize();e.crossVectors(t,i);pe.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);ne.setFromBasis(pe);let o=ne.conjugate();o=o.clone().multiply(MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.set(-Math.PI/8,0,0)));const l=MMD_SA.TEMP_v3.setEulerFromQuaternion(p,"YZX");const d=Math.abs(l.y)%Math.PI;let n=d>Math.PI/2?1-(d-Math.PI/2)/(Math.PI/2):1;if(MMD_SA_options.user_camera.ML_models.pose.use_legIK){const c=o.clone();if(n<1){l.x=l.z=0;c.slerp(oe.setFromEuler(l,"YZX"),1-n)}u[u.length-1].rot[2]=c}ge.add("skin",g+"足首",{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})}}else if(M.score>0){}});let n=0;o.forEach(e=>{const t=e.y*(1-e.scale);if(t>0){n=Math.max(t,n)}else if(o.length>1){n=Math.max(t,n||t)}});if(n){fe.v_hip.y+=n;ce+="\nleg_offset_y:"+n+"\n"}i*=.5*.5;let a=(new THREE.Quaternion).setFromEuler(MMD_SA.TEMP_v3.set(i,0,m),"XZY");ge.add("skin","下半身",{absolute:true,rot:a.clone()});if(!h){ge.add("skin","全ての親",{pos:new THREE.Vector3,after_IK:true,priority:999,onProcessPosition:K})}a.conjugate();u.forEach(e=>{var t=e.d;if(e.rot[0]){e.rot[0].multiplyQuaternions(a,e.rot[0]);ge.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]||ge.skin[t+"足IK"]&&ge.skin[t+"足IK"][0].rot;ge.add("skin",t+"足IK",{absolute:true,pos:e.pos,rot:i,priority:999,onFinish:q})}else{ge.add("skin",t+"ひざ",{absolute:true,rot:e.rot[1]})}})}else{if(T.motion_tracking_upper_body_only){ge.add("skin","全ての親",{is_dummy:true,pos:true,after_IK:true,priority:999})}else if(D&&a.score>0&&s.score>0&&re.video_canvas.width){let e=re.video_canvas.width;let t=re.video_canvas.height;let i=new THREE.Vector3;let o=e/t;let n=SL.width/SL.height;i.set(((a.position.x+s.position.x)/2/e*2-1)*(o{if(e.label)i[e.label].list.push(e)})}const s=he?1:2;o.handpose.forEach(t=>{t._offset={};R=t.annotations;if(s>1){for(let e in R){R[e].forEach(e=>{e[2]*=s})}}let i=MMD_SA.TEMP_v3.fromArray(R.palm[0]);P.forEach(e=>{t._offset[e.dir]=Math.sqrt(Math.pow(e.pos.x-i.x,2)+Math.pow(e.pos.y-i.y,2))})});P.forEach((u,e)=>{var p=u.dir;var t=i?i[i.Left.dir==p?"Left":"Right"].list:o.handpose;if(!t.length)t=o.handpose;let h=e==0?o.handpose.length==1&&P.length>1?t[0]._offset[p]e._offset[p]-t._offset[p])[0]:t.find(e=>!e._used);if(h&&h._offset[p]e.dir==p);let t=MMD_SA._v3a.fromArray(R.palm[0]).distanceTo(MMD_SA._v3b.fromArray(R.middle[0]))/MMD_SA._v3a.fromArray(R.index[0]).distanceTo(MMD_SA._v3b.fromArray(R.pinky[0]));t=t<1?1/t:t>2?t/2:0;if(t){for(const g of["thumb","index","middle","ring","pinky","palm"]){R[g].forEach(e=>{e[2]*=t})}}let S=u.d;h._d=S;y.push(S+"手");let i=p==1?[R.index[0],R.ring[0]]:[R.ring[0],R.index[0]];let o,n,a;let s=MMD_SA._v3a_.fromArray(R.palm[0]).sub(MMD_SA._v3b.fromArray(R.middle[0])).normalize();s.x=s.x*I;let r=MMD_SA._v3b_.fromArray(i[0]).sub(MMD_SA._v3b.fromArray(i[1])).normalize();r.z=r.z*I;r.y=r.y*I;let _=MMD_SA.TEMP_v3.crossVectors(r,s).normalize();r.crossVectors(s,_);pe.set(r.x,r.y,r.z,0,s.x,s.y,s.z,0,_.x,_.y,_.z,0,0,0,0,1);ne.setFromBasis(pe);let l=new THREE.Quaternion;l.copy(ne).conjugate();ge.add("skin",S+"手首",{after_IK:true,rot:l,onProcessRotation:U});ge.add("skin",S+"手捩",{after_IK:true,absolute:true,priority:1,no_blending:true,rot:new THREE.Quaternion});const m=MMD_SA.TEMP_v3.setEulerFromQuaternion(l,"YXZ").y;const f=1;const k=(Math.abs(m){let f=c[(I==1?S:S=="左"?"右":"左")+m];let g=f.base_index+(m==0?0:-1);let y=R[ve[m]];let M=oe.copy(A);const b="XZY";if(k&&m>0){const e=Math.max(MMD_SA._v3a.fromArray(y[2]).sub(MMD_SA._v3b.fromArray(y[1])).length()*1.2,MMD_SA._v3a.fromArray(R.palm[0]).sub(MMD_SA._v3b.fromArray(y[0])).length()*(k==1?.2:.3));const v=MMD_SA._v3a.fromArray(y[1]).sub(MMD_SA._v3b.fromArray(y[0]));if(e/v.length()>1){const t=-k*Math.sqrt(e*e-(v.x*v.x+v.y*v.y))-v.z;for(let e=1;e<3;e++)y[e][2]+=t}}for(let p=g;p<3;p++){let e=S+h+"指"+se[f.base_index+(p-g)];let t=MMD_SA._v3a.fromArray(y[p+0]);let i=MMD_SA._v3b.fromArray(y[p+1]);let o=MMD_SA.TEMP_v3.fromArray(p==g?R.palm[0]:y[p-1]);t.y=-t.y;i.y=-i.y;o.y=-o.y;let n=MMD_SA._v3a_.copy(t).sub(o);let a=MMD_SA._v3b_.copy(i).sub(t);n.normalize();a.normalize();let s,r;let _;n.applyQuaternion(M);a.applyQuaternion(M);if(p==g){let e=MMD_SA.TEMP_q.set(0,0,0,1);e.setFromVectorSpherical(MMD_SA.TEMP_v3.set(0,1,0),n).conjugate();a.applyQuaternion(e);M.multiplyQuaternions(e,M)}let l=MMD_SA._q1.set(0,0,0,1);let d=MMD_SA._q2.set(0,0,0,1);n.set(0,1,0);_=ee.setFromVectorSpherical(n,a);l.setFromEuler(_,b);d.copy(l);if(Math.abs(_.z)>Math.PI/(m==0?1.1:2.5)||_.x>Math.PI/(m==0?1.1:3)){_.set(-Math.abs(n.angleTo(a)),0,0)}if(m==0&&p>g){}if(_.x>0){_.x*=m==0?0:p>g?0:.75}else{_.x=Math.max(_.x,-Math.PI/(m==0?1.25:2))}if(m==0||p==g){_.z+=(m-2)/2*Math.PI/8*D*(m>0?1:.5);_.z*=m>0?Math.min(Math.max(Math.PI/2-Math.abs(_.x),0)/(Math.PI/2.5),1):1}else{_.z=0}if(E&&m>0&&p==g){const v=MMD_SA._v3a.fromArray(y[p+1]);v.y*=-1;v.applyQuaternion(A);const w=MMD_SA._v3b.fromArray(y[p+3]);w.y*=-1;w.applyQuaternion(A);if(v.y>w.y){_.x-=Math.abs(_.z)*E;_.z*=1-E}}_.y=0;if(m==0)M.multiplyQuaternions(l.conjugate(),M);l.setFromEuler(_,b);if(m>0){M.multiplyQuaternions(l.conjugate(),M);l.conjugate()}let c=e;let u=l.toAxisAngle();r=u[0];s=u[1];r.z*=-1;r.applyEuler(J.set(MMD_SA.THREEX.enabled?Math.PI/2:0,-Math.PI/2*D,0),"YXZ");if(MMD_SA.THREEX.enabled){l.setFromAxisAngle(r,s)}else{r.applyQuaternion(me[c].axis_rot);l.setFromAxisAngle(r,s)}if(L[S]){if(p==g){const e=ge.skin[S+"手首"][0];if(!e._finger_x)e._finger_x=[];e._finger_x[m]=_.x}}else{ge.add("skin",e,{absolute:true,rot:l.clone()})}}})}else{const e=u.d;if(T.motion_tracking_upper_body_only&&ge.get_blend_default_motion("skin",e+(L[e]?"足首":"手首"))!=0){u.visible=false}}})}else if(!Z.enabled&&B&&de.use_3D_pose){let e=I==1?[1,0]:[0,1];e.forEach(function(e,t){let i=t==0?"左":"右";if(!P.find(e=>e.d==i)?.visible)return;let o=B._keypoints3D[15+e];let n=B._keypoints3D[17+e];let a=B._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*I;let _=MMD_SA._v3b_.copy(s[0]).sub(s[1]).normalize();_.z=_.z*I;_.y=_.y*I;let l=MMD_SA.TEMP_v3.crossVectors(_,r).normalize();_.crossVectors(r,l);pe.set(_.x,_.y,_.z,0,r.x,r.y,r.z,0,l.x,l.y,l.z,0,0,0,0,1);ne.setFromBasis(pe);let d=new THREE.Quaternion;d.copy(ne).conjugate();ge.add("skin",i+"手首",{after_IK:true,rot:d,onProcessRotation:U});ge.add("skin",i+"手捩",{after_IK:true,absolute:true,priority:1,no_blending:true,rot:new THREE.Quaternion})})}for(const H of["左","右"]){if(ge.skin[H+"手首"]&&!ge.skin[H+"手首"][0]._finger_x)ge.skin[H+"手首"][0]._finger_x=ge.skin[H+"手首"][1]._finger_x}const d=[];x.forEach(function(t){var o=t.d;if(L[o]){if(t.IK_disabled)return;de.enable_IK(o+"足IK",true);if(ge.skin[o+"手首"]&&ge.skin[o+"腕"]&&ge.skin[o+"手首"][0].timestamp==ge.skin[o+"腕"][0].timestamp){let e;if(e){}else{const a=MMD_SA.TEMP_q.setFromEuler(MMD_SA.TEMP_v3.set(Math.PI/2,0,0));const s=ge.skin[o+"手首"][0].rot.premultiply(a).multiply(a.conjugate());ge.add("skin",o+"足首",{after_IK:true,rot:s,_finger_x:ge.skin[o+"手首"][0]._finger_x,absolute:true,onFinish:k})}}else{const r=ge.skin[o+"足首"];if(r){r[0].rot_parent=r[0]._rot_parent}}ge.remove("skin",o+"手首");ge.remove("skin",o+"腕");ge.remove("skin",o+"ひじ");ge.remove("skin",o+"手捩");ge.remove("skin",o+"腕IK");if(Z.enabled){ae.forEach((t,e)=>{let i=e==0?0:1;for(let e=i;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)});d.push({d:o,pos:i,rot:n[1]})}else{de.enable_IK(o+"腕IK",!t.IK_disabled);if(!t.IK_disabled){if(t.pos.z==null)t.pos.z=t.pos.z_posenet||(de.use_3D_pose?0:MMD_SA_options.model_para_obj.left_arm_length*.2);const _=(new THREE.Vector3).copy(t.pos);ge.add("skin",o+"腕IK",{priority:999,pos:_,_IK_absolute:t.IK_absolute,onProcessPosition:m})}const e=ge.skin[o+"手首"];if(e){e[0].rot_parent=e[0]._rot_parent}}});if(d.length&&l.transformation?.position?.process)l.transformation.position.process(d);d.forEach(e=>{const t=e.d;const i=e.pos;i.y+=MMD_SA_options.model_para_obj.left_leg_IK[1]+(a["センター"].position.y-a["センター"].pmxBone.origin[1]);if(e.rot){ge.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{ge.remove("skin",t+"足")}ge.remove("skin",t+"ひざ");ge.add("skin",t+"足IK",{absolute:true,priority:999,pos:i})});if(T.motion_tracking_upper_body_only){for(const H of["左","右"]){const p=!P.find(e=>e.d==H)?.visible;if(L[H]){ge.set_blend_default_motion("skin",H+"足IK",p);ge.set_blend_default_motion("skin",H+"足",p);ge.set_blend_default_motion("skin",H+"ひざ",p);ge.set_blend_default_motion("skin",H+"足首",p)}else{if(T.has_leg_IK){ge.set_blend_default_motion("skin",H+"足IK",true);ge.remove("skin",H+"足首")}else{ge.set_blend_default_motion("skin",H+"足",true);ge.set_blend_default_motion("skin",H+"ひざ",true);ge.set_blend_default_motion("skin",H+"足首",true)}de.enable_IK(H+"足IK",T.has_leg_IK);de.enable_IK(H+"つま先IK",T.has_leg_IK);ge.set_blend_default_motion("skin",H+"肩",p);ge.set_blend_default_motion("skin",H+"腕",p);ge.set_blend_default_motion("skin",H+"ひじ",p);ge.set_blend_default_motion("skin",H+"手捩",p);ge.set_blend_default_motion("skin",H+"手首",p);ge.set_blend_default_motion("skin",H+"腕IK",p);if(Z.enabled){ae.forEach((t,e)=>{let i=e==0?0:1;for(let e=i;e{DEBUG_show((de.use_holistic&&"(no facemesh data)\n"||"")+(ue?"\n"+ue+"\n":"")+ce+"\n"+"FPS:"+EV_sync_update.fps_last)},0,0)}if(o.facemesh){_e.worker_onmessage({data:o.facemesh})}if(B&&_e.worker_initialized){let e={posenet:B,w:re.video_canvas.width,h:re.video_canvas.height,flip_canvas:re.display_flipped};if(o.handpose&&o.handpose.length)e.handpose=o.handpose;if(o.facemesh)e.facemesh=o.facemesh.faces;if(de.use_holistic||!_e.enabled){e.draw_canvas=true;if(self.FacemeshAT){e.canvas=re.video_canvas_facemesh}else if(!re.video_canvas_facemesh._offscreen&&self.OffscreenCanvas){e.canvas=re.video_canvas_facemesh.transferControlToOffscreen();re.video_canvas_facemesh._offscreen=true;console.log("(Facemesh: use offscreen canvas)")}}le.postMessage(e,e.canvas?[e.canvas]:undefined)}$=0}Le()}}();function Le(e){async function t(){var e=de.enabled&&de.worker_initialized&&A&&!de.busy&&k&&de.camera_video_timestamp!=A;if(!e)return;$=RAF_timestamp;de.camera_video_timestamp=A;de.camera_video_frame_id=D;if(de.use_holistic&&_e.blink_detection){MMD_SA_options.auto_blink=_e.auto_blink||false}let t,i,o;t=re.video_canvas;i=t.width;o=t.height;let n=self.PoseAT?t:E?await createImageBitmap(t):t.getContext("2d").getImageData(0,0,i,o).data.buffer;let a={rgba:n,w:i,h:o,options:{video_flipped:re.video_flipped,use_canvas_hands:!MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only,use_holistic:de.use_holistic,use_posenet:true,use_handpose:Z.enabled,skip_hand_countdown_max:de.skip_hand_countdown_max,timestamp:re.video_timestamp}};let s=[a.rgba];if(!de.canvas_hands){const r=de.canvas_hands=document.createElement("canvas");r.width=r.height=768;a.canvas_hands=r.transferControlToOffscreen();s.push(a.canvas_hands)}m.postMessage(a,s);s.length=0;s=undefined;a.rgba=n=undefined;a=undefined}if(e||self.PoseAT){setTimeout(()=>{t()},0)}else{t()}}var W=function(){const a=()=>{};var s,r;var z={};var H={},O={},q={};var G={};window.addEventListener("jThree_ready",e=>{s=new THREE.Vector3;r=new THREE.Quaternion;for(const t of["センター","上半身","上半身2","首","頭"]){z[t]=new THREE.Quaternion}for(const i of["左","右"]){G[i]={target:new THREE.Vector3,arm_pos:new THREE.Vector3};H[i]={target:new THREE.Vector3,effector:new THREE.Quaternion,links:[]};O[i]={effector:new THREE.Quaternion,links:[]};q[i]={effector:new THREE.Quaternion,parent:new THREE.Quaternion,links:[]};for(let e=0;e<2;e++){H[i].links[e]=new THREE.Quaternion;O[i].links[e]=new THREE.Quaternion;q[i].links[e]=new THREE.Quaternion}}});const _=250;const l=500;const d=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)/l,1)}else if(o._blend_default_motion<0){n=1-Math.min((RAF_timestamp+o._blend_default_motion)/_,1)}else{n=0}if(n==0){this[e][t].forEach(e=>{e._blend_default_motion=0})}else if(i){const e=2;n=n<.5?Math.pow(n*2,e)*.5:.5+Math.pow((n-.5)*2,1/e)*.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];const r=this[e][t][1]._blend_default_motion;if(i){if(this.reset_to_default_motion_once){s._idle_blend_default_motion=0;s._blend_default_motion=1}else if(!s._blend_default_motion){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:d)){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)*l}}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))*_)}}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 K(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(de.enabled&&!de.data_detected_stable)return;if(r[0].info[1]=="facemesh"){}r[0].t_delta+=RAF_timestamp_delta;let _=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=ie.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,_));if(r[0].ratio<1)t.slerp(oe.set(0,0,0,1),1-r[0].ratio);const d=MMD_SA_options.model_para_obj_all[i._model_index].skin_default[o];if(d&&d.rot_scale){if(typeof d.rot_scale=="number")d.rot_scale={x:d.rot_scale,y:d.rot_scale,z:d.rot_scale};t.setFromEuler(MMD_SA.TEMP_v3.setEulerFromQuaternion(t,"YXZ").multiply(d.rot_scale),"YXZ")}s.quaternion.multiply(t);ye.active&&!r[0].motion_recorder_disabled&&o.indexOf("IK")==-1&&ye.set_boneKey(o,null,s.quaternion,true)}}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 c=MMD_SA.TEMP_v3.copy(r[1].pos).lerp(r[0].pos,_);s.position.add(c);ye.active&&!r[0].motion_recorder_disabled&&o.indexOf("IK")==-1&&ye.set_boneKey(o,J.copy(s.position).sub(ee.fromArray(s.pmxBone.origin)),null,true)}}r[0].onFinish&&r[0].onFinish.call(this,i,o);const l=this.get_blend_default_motion("skin",o,true);if(l){if(r[0].rot&&this._skin[o]?.rot){const u=MMD_SA.TEMP_q.copy(this._skin[o].rot);s.quaternion.slerp(this._skin[o].onProcessRotation&&this._skin[o].onProcessRotation.call(this,i,o,u)||u,l)}if(r[0].pos&&this._skin[o]?.pos){s.position.lerp(this._skin[o].pos,l)}if(ye.active&&!r[0].motion_recorder_disabled){if(o.indexOf("IK")!=-1)ye.set_boneKey(o,r[0].pos&&s.position,r[0].rot&&s.quaternion,false)}}t&&e._update_IK_and_AddTrans(false,o)}var U=0;function o(e){function t(){if(E)return;E=z;for(const e of["センター","上半身","上半身2","首"]){const t=this.skin[e];if(!t){E[e].set(0,0,0,1);continue}if(e=="首"){E[e].copy(t[0]._rot_neck||t[1]._rot_neck||MMD_SA._q1.set(0,0,0,1));E["頭"].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);E[e].copy(i)}}r=MMD_SA._q1.copy(E["センター"]).multiply(E["上半身"]).multiply(E["上半身2"]).conjugate()}function a(e){const t=["センター","上半身","上半身2","首","頭"];let o;const n=x&&x.parent;const a=J.set(0,0,0);if(n){const f=n.name||e+"足";const g=f.charAt(0);const y=1-this.get_blend_default_motion("skin",f.indexOf("足")!=-1?g+"足IK":f,true);let t,i;switch(f){case"頭":o=y&&this.skin["首"];if(o){for(const f of["首","頭"])D[f].quaternion.copy(E[f]);t=MMD_SA.get_bone_position(A,"頭","首").add(ee.set(0,.75,.75).applyQuaternion(MMD_SA.TEMP_q.copy(D["首"].quaternion).multiply(D["頭"].quaternion)));D["首"].quaternion.copy(this._body_motion_rot[0]["首"]);D["頭"].quaternion.copy(this._body_motion_rot[0]["頭"]);i=MMD_SA.get_bone_position(A,"頭","首").add(ee.set(0,.75,.75).applyQuaternion(MMD_SA.TEMP_q.copy(D["首"].quaternion).multiply(D["頭"].quaternion)))}break;case"左足":case"右足":o=y;if(o){if(!O[g].updated){H[g].enabled=true;o=false}}else{H[g].enabled=false;O[g].updated=0}if(o){const M=ee.fromArray(D[e+"ひざ"].pmxBone.origin).sub(te.fromArray(D[f].pmxBone.origin));t=te.copy(M).applyQuaternion(ie.copy(q[g].parent).multiply(q[g].links[1]));i=M.applyQuaternion(ie.copy(q[g].parent).multiply(O[g].links[1]))}break}if(o){o=f;a.copy(t).sub(i);let e=n.weight||.5;if(typeof e=="object"){a.x*=a.x<0?e.x.left:e.x.right;a.y*=a.y<0?e.y.down:e.y.up;a.z*=a.z<0?e.z.backward:e.z.forward}else{a.multiplyScalar(e)}a.multiplyScalar(y)}}let i,s,r;for(const f of t)D[f].quaternion.copy(this._body_motion_rot[0][f]);const _=k.motion_tracking?.arm_tracking?.elbow_lock?.[e=="左"?"left":"right"];if(_){_._elbow_y=_.y_absolute!=null?_.y_absolute:MMD_SA.get_bone_position(A,e+"ひじ",A).y+(_.y||0)}if(!o||o!="頭"){i=MMD_SA.get_bone_position(A,e+"腕",A);r=MMD_SA.get_bone_rotation_parent(A,e+"腕IK",A);s=!k.has_arm_IK?MMD_SA.get_bone_position(A,e+"手首",A):(new THREE.Vector3).copy(D[e+"腕IK"].position).sub(MMD_SA_options.model_para_obj.arm_IK_offset[e]).applyQuaternion(r).add(i);r.conjugate()}for(const f of t)D[f].quaternion.copy(this._body_motion_rot[1][f]);if(!i){i=MMD_SA.get_bone_position(A,e+"腕",A);r=MMD_SA.get_bone_rotation_parent(A,e+"腕IK",A);s=!k.has_arm_IK?MMD_SA.get_bone_position(A,e+"手首",A):(new THREE.Vector3).copy(D[e+"腕IK"].position).sub(MMD_SA_options.model_para_obj.arm_IK_offset[e]).applyQuaternion(r).add(i);r.conjugate()}for(const f of["センター","上半身","上半身2"]){let e;if(f.indexOf("上半身")!=-1)e=k.motion_tracking?.motion_default_weight?.upper_body;if(e==null)e=1;if(this.skin[f]){if(e<1)D[f].quaternion.slerp(MMD_SA.TEMP_q.set(0,0,0,1),1-e);D[f].quaternion.multiply(E[f])}}let l=x&&x.default_position_weight;if(typeof l!="number")l=.5;const d=MMD_SA.get_bone_rotation_parent(A,e+"腕IK",A).conjugate();let c;let u=k.motion_tracking?.arm_tracking?.IK_constraint;if(u)u=u[e=="左"?"left":"right"]||u;if(u&&this.skin[e+"腕IK"]&&this.get_blend_default_motion("skin",e+"腕IK")<1){const b=G[e];b.enabled=true;b.target.copy(s);b.target_radius=0;if(u.target_offset){const v=J.fromArray(u.target_offset);b.target.add(v);b.target_radius=v.length()}if(u.target_radius)b.target_radius+=u.target_radius;c=MMD_SA.get_bone_position(A,e+"腕",A);b.arm_pos.copy(c)}c=l==0?i:(c||MMD_SA.get_bone_position(A,e+"腕",A)).lerp(i,1-l);const p=c.sub(s);if(l<1)d.slerp(r,1-l);if(o&&o.indexOf("足")!=-1){a.applyQuaternion(d)}const h=re.x_flipped?-1:1;p.x*=h;p.y*=-1;p.z*=-1;if(o&&o=="頭"){p.applyQuaternion(d)}else{p.applyQuaternion(d)}if(!this._skin[e+"腕IK"])this._skin[e+"腕IK"]={pos:new THREE.Vector3,rot:new THREE.Quaternion};if(!this._skin[e+"腕IK"].rot_parent_inv)this._skin[e+"腕IK"].rot_parent_inv=new THREE.Quaternion;this._skin[e+"腕IK"].rot_parent_inv.copy(d).conjugate();p.add(MMD_SA_options.model_para_obj.arm_IK_offset[e]);p.add(a);for(const f of t)D[f].quaternion.copy(this._body_motion_rot[1][f]);const m=this.skin[e+"手首"];if(m){if(P){m[0].after_IK=true;this._skin[e+"手首"]._rot_absolute=MMD_SA.get_bone_rotation(A,e+"手首",false,A)}this._skin[e+"手首"].onProcessRotation=w;this._skin[e+"手捩"].onProcessRotation=S}return p}function w(e,t,i){const o=t.charAt(0);const n=k.motion_tracking&&k.motion_tracking.arm_default_stickiness&&(k.motion_tracking.arm_default_stickiness[o]||k.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 S(e,t,i){return i.set(0,0,0,1)}function i(){if(de.data_detected){W();System._browser.on_animation_update.remove(i,0)}}const s=e.detail.model;const o=MMD_SA.THREEX.get_model(s._model_index).is_T_pose;const A=s.mesh;const D=A.bones_by_name;const k=MMD_SA.motion[s.skin._motion_index].para_SA;if(!this._reset_disabled&&this._motion_path&&(this._motion_path!=k._path||this._motion_tracking_upper_body_only!=!!k.motion_tracking_upper_body_only)){this._motion_path=k._path;this._motion_tracking_upper_body_only=!!k.motion_tracking_upper_body_only;this.reset();V();de.data_detected=0;de.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=k._path;this._motion_tracking_upper_body_only=!!k.motion_tracking_upper_body_only;if(ye.enabled&&U!=de.data_detected){U=de.data_detected;ye.timestamp_for_recording=RAF_timestamp;if(ye.active)window.dispatchEvent(new CustomEvent("SA_motion_recorder_on_active",e))}for(const _ of["左","右"]){this.arm_IK_constraint[_].enabled=false}be.copy(this.get_upper_body_rotation()).multiply(this._rot_body_camera_offset);this.upper_body_rotation_limiter(be);let E,r,x,P;if(de.enabled&&k.motion_tracking_upper_body_only){if(k.has_leg_IK==null)k.has_leg_IK=!k.IK_disabled?.test("左足IK")&&s.skin.targets.findIndex(e=>e.keys[0].name.indexOf("足IK")!=-1)!=-1;if(k.has_arm_IK==null)k.has_arm_IK=s.skin.targets.findIndex(e=>e.keys[0].name.indexOf("腕IK")!=-1)!=-1;const l=k.motion_tracking&&k.motion_tracking.arm_as_leg;const d={"左":l&&l.enabled&&(!l.linked_side||l.linked_side=="left"),"右":l&&l.enabled&&(!l.linked_side||l.linked_side=="right")};for(const c in this._skin){this._skin[c].pos.copy(D[c].position);this._skin[c].rot.copy(D[c].quaternion)}let e=de.data_detected;let o,n;if(e){t.call(this);const u=System._browser.camera.poseNet.hip_adjustment_weight;const p=ie.copy(E["センター"]).multiply(E["上半身"]);const h=k.motion_tracking?.hip_adjustment?.rotation_weight;o=(new THREE.Quaternion).copy(p).slerp(oe.set(0,0,0,1),1-(typeof h=="number"?h*u:.5));this.remove("skin","下半身");this.add("skin","下半身",{rot:o});if(this.skin["センター"]){let e=k.motion_tracking?.hip_adjustment?.displacement_weight;if(typeof e!="number")e=.25;e*=u;if(e){const m=MMD_SA_options.model_para_obj.left_leg_length/3*e;const f=J.set(0,m,0).applyQuaternion(p);f.x*=-1;f.z*=-1;f.sub(ee.set(0,m,0));if(this.skin["センター"][0].pos)this.skin["センター"][0].pos.copy(f);else this.skin["センター"][0].pos=f.clone();if(!this.skin["センター"][1].pos)this.skin["センター"][1].pos=this.skin["センター"][0].pos;n=this.skin["センター"][0].pos}}}for(const _ of["左","右"]){const g=_=="左"?"left":"right";x=k.motion_tracking&&k.motion_tracking.arm_default_stickiness&&(k.motion_tracking.arm_default_stickiness[g]||k.motion_tracking.arm_default_stickiness);P=x&&x.default_rotation_weight;let i=k.motion_tracking?.hip_adjustment?.[g]?k.motion_tracking.hip_adjustment[g].feet_fixed_weight:k.motion_tracking?.hip_adjustment?.feet_fixed_weight;if(typeof i!="number")i=1;if(i<1||(e||d[_])&&!k.has_leg_IK){const c=_+"足IK";let e,t;if(o){e=ie.copy(D["下半身"].quaternion);D["下半身"].quaternion.multiply(o)}if(n){t=J.copy(D["センター"].position);D["センター"].position.add(n)}const y=k.has_leg_IK?null:MMD_SA.get_bone_position(A,_+"足","全ての親");const M=i<1?MMD_SA.get_bone_position(A,_+"足首","全ての親"):ee;if(e)D["下半身"].quaternion.copy(e);if(n)D["センター"].position.copy(t);const b=k.has_leg_IK||i>0?MMD_SA.get_bone_position(A,_+"足首","全ての親"):M;const v=re.x_flipped?-1:1;if(k.has_leg_IK){const I=J.copy(b).sub(M.lerp(b,i));I.x*=v;I.y*=-1;I.z*=-1;if(!this._skin[c])this._skin[c]={pos:new THREE.Vector3,rot:new THREE.Quaternion};this._skin[c].pos.add(I);D[c].position.add(I)}else{const R=J.fromArray(D[_+"足"].pmxBone.origin);const T=R.sub(y).negate();const I=y.sub(M.lerp(b,i));I.x*=v;I.y*=-1;I.z*=-1;I.add(MMD_SA_options.model_para_obj.leg_IK_offset[_]);I.add(T);if(!this._skin[c])this._skin[c]={pos:new THREE.Vector3,rot:new THREE.Quaternion};this._skin[c].pos.copy(I);if(!d[_]){de.enable_IK(c,true);if(!this.skin[c])this.add("skin",c,{absolute:true,is_dummy:true,pos:true,priority:999})}D[c].position.copy(I);if(de.data_detected)D[_+"ひざ"].quaternion.set(0,0,0,1)}D[c].position.y+=this._skin[c]._offset_y_||0}if(d[_]){t.call(this);const I=a.call(this,_);D[_+"腕IK"].position.copy(I);de.enable_IK(_+"腕IK",true)}else{const c=_+"腕IK";let e;const L=this.skin[_+"手首"];if(L){t.call(this);if(!de.IK_disabled_check(c)){e=a.call(this,_)}else{if(this._skin[_+"腕"])this._skin[_+"腕"].rot.premultiply(r);if(this._skin[_+"手首"])this._skin[_+"手首"].rot.premultiply(MMD_SA.TEMP_q.copy(r).conjugate())}}if(e)this._skin[c].pos.copy(e)}if(H[_].enabled){const F=D[_+"足IK"];const C=H[_];C.target.copy(F.position);const j=F.pmxBone.IK;C.effector.copy(A.bones[j.effector].quaternion);for(let e=0;e{e.detail.result.links=C;e.detail.result.links_result=O[_]},{once:true});window.addEventListener("SA_camera_poseNet_process_bones_onended",e=>{const t=q[_];t.parent.copy(MMD_SA.get_bone_rotation_parent(A,_+"足","全ての親"));t.effector.copy(A.bones[j.effector].quaternion);for(let e=0;e{const t=e.detail.model;const a=t.mesh.bones_by_name;for(const n of["左","右"]){ye.set_boneKey(n+"足",null,a[n+"足"].quaternion,false);ye.set_boneKey(n+"ひざ",null,a[n+"ひざ"].quaternion,false);ye.set_boneKey(n+"足首",null,a[n+"足首"].quaternion,false);if(a[n+"足先EX"])ye.set_boneKey(n+"足先EX",null,a[n+"足先EX"].quaternion,false);for(const e of[n+"肩",n+"腕",n+"ひじ",n+"手首"]){if(a[e])ye.set_boneKey(e,null,a[e].quaternion,false)}ae.forEach((i,e)=>{let o=e==0?0:1;for(let t=o;t!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});B.forEach(e=>{let t=D[e];if(!t&&!/_DUMMY_/.test(e))return;var i=n[e][0].info[1];if((!i||/pose/.test(i))&&!k.motion_tracking_enabled)return;K.call(this,A,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)Q(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;K.call(this,o,e)});window.dispatchEvent(new CustomEvent("SA_camera_poseNet_process_bones_onended",e))}function c(e){if(de.enabled&&!de.data_detected_stable)return;var _=e.detail.model;var l=_.mesh;var d=_.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=d[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 c=MMD_SA_options.model_para_obj.facemesh_morph;var u=this.morph;var p={};var n=0;Object.keys(u).forEach(function(e){let t=u[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);p[e]=o;if(o)n++});Object.keys(p).forEach(function(t){let e=u[t];let i=p[t];if(i<0){ye.morph_active&&ye.set_morphKey(t,0,true);switch(t){case"にやり":t="ω";break;case"口角上げ":t="口角下げ";break;case"上":t="下";break}i=-i}if(ye.morph_active){let e=t;if(t=="まばたきL")e="ウィンク";else if(t=="まばたきR")e="ウィンク右";ye.set_morphKey(e,i,true)}let o=c[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=d[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)}})}function u(e,t,i){i.name=t;i.info=e.split("|");var o=i.info[0];var n=this[o][t];if(i.is_dummy){if(n&&n[0].is_dummy)return;i.no_blending=true;i.onProcessPosition=i.onProcessRotation=a;if(i.pos)i.pos=s;if(i.rot)i.rot=r}i.timestamp=RAF_timestamp;i.t_delta=0;i.t_delta_frame=(this.t_delta||0)*(t.indexOf("指")!=-1||t.indexOf("手首")!=-1?de.skip_hand_countdown_max+1:1);i.t_delta_frame=Math.max(Math.min(i.t_delta_frame,200),16.6667);if(n){if(RAF_timestamp==n[0].timestamp){n[0]=Object.assign(n[0],i)}else{if(!i.no_blending&&!re.video.paused){let e=de.use_3D_pose||i.info[1]=="facemesh"?.5+Math.max(Math.min((Math.max(i.t_delta_frame,RAF_timestamp-n[0].timestamp)-50)/150,1),0)*.5:1;if(i.pos&&n[0].pos){i.pos.lerp(n[0].pos,1-e)}if(i.rot&&n[0].rot){i.rot.slerp(n[0].rot,1-e)}if(i.weight!=null&&n[0].weight!=null){i.weight=i.weight*e+n[0].weight*(1-e)}}this[o][t]=[i,n[0]]}i._blend_default_motion=n[1]._blend_default_motion;i._idle_blend_default_motion=n[1]._idle_blend_default_motion}else{this[o][t]=[i,i]}if(ye.speed&&re.is_local_video&&ye.speed<1)i.no_blending=true}function p(e,t){delete this[e][t]}function h(){this.skin={};this.morph={};this._skin={};this._morph={};this.reset_to_default_motion_once=true;this._motion_path=""}function W(){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 V(){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=c.bind(this)};m.prototype.set_upper_body_rotation=function(e,t){if(!de.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=ie.set(0,0,0,1);const i=oe.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=S.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){W.prototype._q1=new THREE.Quaternion;W.prototype._q2=new THREE.Quaternion;ge=new W(0)});var ye=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;d[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 d,r;var c=0;var o=0;var u=0;var p=0;var n;var a=0;var t=0;const h=2;return{timestamp_for_recording:0,get enabled(){return t&&!re.video.paused},get morph_active(){return de.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!=D){let e=1;if(n){e=this.get_frame(D)-this.get_frame(n);if(e<0||e>30)e=1;if(e>1){const t=e-1;o+=t;for(const i in d){d[i].frame_length+=t}for(const i in r){r[i].frame_length+=t}}}c+=e;n=D;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 c},get stats(){return[o,l.boneKeys.length,l.morphKeys.length,u,p]},get time(){return Math.floor(c/30)+":"+(c%30+1)},get speed(){return t},set speed(e){t=e;if(e)this.start(e);else this.stop()},get vmd(){return t?null:l},set vmd(e){l=null},set_boneKey:function(e,t,i,o){let n=d[e];if(n==null){n=d[e]={frame_length:1};if(c>0)l.boneKeys.push(new _(e,null,null,0))}if(o&&ge.skin[e]&&n.timestamp==ge.skin[e][0].timestamp){let e;if(n.frame_count==c){const a=l.boneKeys[n.index];e=(!t||a.pos)&&(!i||a.rot)}else e=true;if(e){if(n.frame_count!=c){n.frame_length++;u++}return}}if(!t&&i&&n.is_rot_identity&&i.w==1){u++;return}n.is_rot_identity=i?i.w==1:n.is_rot_identity;if(n.frame_count==c){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(c-a.time*30);if(s>n.frame_length||s>10){const r=new _(e,null,null,(c-1)/30);r.pos=a.pos;r.rot=a.rot;l.boneKeys.push(r);u--}}n.timestamp=ge.skin[e]&&ge.skin[e][0].timestamp||0;l.boneKeys.push(new _(e,t,i,c/30))}n.frame_length=1;n.frame_count=c},set_morphKey:(()=>{function o(e,t,i){let o=r[e];if(o==null){o=r[e]={frame_length:1};if(c>0)l.morphKeys.push(new s(e,0,0))}if(i&&ge.morph[e]&&o.timestamp==ge.morph[e][0].timestamp){if(o.frame_count!=c){o.frame_length++;p++}return}t=Math.round(t*20)/20;if(t==o.weight){p++;return}o.weight=t;if(o.frame_count==c){const n=l.morphKeys[o.index];n.weight=t}else{if(o.index!=null){const n=l.morphKeys[o.index];const a=Math.round(c-n.time*30);if(ao.frame_length||a>10){l.morphKeys.push(new s(e,n.weight,(c-h)/30));p--}}o.timestamp=ge.morph[e]&&ge.morph[e][0].timestamp||0;l.morphKeys.push(new s(e,t,c/30))}o.frame_length=1;o.frame_count=c}return function(e,t,i){if(de.enabled){window.addEventListener("SA_motion_recorder_on_active",()=>{o.call(this,e,t,i)},{once:true})}}})(),start:function(e){t=e;n="";a=0;if(re.is_local_video){re.video.playbackRate=e;if(e<1)re.video.muted=true;re.video.loop=false;re.video.pause();MMD_SA.SpeechBubble.message(0,"Use the seek bar to go to the desired frame, press the play button and begin recording~!",5*1e3);C_media_control.style.visibility="inherit"}c=-1;o=0;u=0;p=0;d={};r={};l={boneKeys:[],morphKeys:[]}},stop:function(){t=0;if(re.is_local_video){re.video.playbackRate=1;re.video.muted=false;re.video.loop=true;re.video.pause();MMD_SA.SpeechBubble.message(0,"Motion recording has stopped. Double-click and you can export the motion to a file in VMD format~!",5*1e3)}else if(re.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}))}}}}();var Fe=[{},{}];var V=n.get("camera_hidden");var X;re={initialized:false,get ML_enabled(){return t},get ML_busy(){return _e.busy||de.busy},get ML_fps(){return 1e3/(de.enabled&&de._t||_e.enabled&&_e._t||1e3)},get ML_warmed_up(){var e=Fe[de.use_holistic?1:0];var t=!_e.enabled||e.facemesh;var i=!de.enabled||e.poseNet;var o=!Z.enabled||e.handpose;return t&&i&&o},get target_devicePixelRatio(){return b||window.devicePixelRatio},set target_devicePixelRatio(e){b=e==window.devicePixelRatio?0:e},get double_flip_mode(){return a&&!re.mirror_3D},set double_flip_mode(e){a=e},get video_flipped(){return!t?s:!!s^!!re.double_flip_mode},set video_flipped(e){s=e;this.reset_video_canvas()},get display_flipped(){return re.mirror_3D?false:s!=re.video_flipped},get mirror_3D(){return!t||!MMD_SA_options.user_camera.mirror_3D?false:MMD_SA_options.user_camera.mirror_3D==1?re.visible:true},get x_flipped(){return re.double_flip_mode||re.mirror_3D},get hidden_enforced(){return V||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||X},set display_floating(e){X=e;if(this.video_host)this.video_host.style.zIndex=this.display_floating?2:0},get video_timestamp(){return re.video.currentTime==null?performance.now()/2:re.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},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":"";ue=n+o},0,0,-1)});return function(e,t,i){if(!re.ML_enabled||!de.data_detected&&!_e.data_detected){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;ue=n+o}})(),motion_recorder:ye,camera_list:null,deviceId:null,start:async function(o){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;MMD_SA.reset_camera();this._camera_reset=MMD_SA._trackball_camera.object.clone();if(this.initialized){if(this.visible){this.hide();DEBUG_show("User camera:HIDDEN",2);return}}var a={video:this.set_constraints()};try{if(o){this.init_stream(o)}else{if(is_mobile){a.video.facingMode="user"}if(MMD_SA_options.Dungeon){MMD_SA_options.Dungeon.run_event([[{message:{content:"(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 e=this.camera_list;if(!e){try{e=await navigator.mediaDevices.enumerateDevices();e=e.filter(e=>e.kind=="videoinput");if(MMD_SA_options.user_camera.preference)e.sort((e,t)=>MMD_SA_options.user_camera.preference.label.test(e.label)&&-1||MMD_SA_options.user_camera.preference.label.test(e.label)&&1||0);this.camera_list=e}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 i;if(MMD_SA_options.Dungeon){await new Promise(t=>{MMD_SA_options.Dungeon.run_event([[{message:{content:(e.length?"Choose a camera."+e.map((e,t)=>"\n"+(t+1)+". "+e.label).join(""):"No camera is available on this device. Drop a local media file as input instead.")+"\n"+(e.length+1)+". Local media file\n"+(e.length+2)+". Cancel",bubble_index:3,branch_list:e.map((e,t)=>{return{key:t+1,branch_index:t+1}}).concat([{key:Math.min(e.length+1,8),branch_index:Math.min(e.length+1,8)},{key:Math.min(e.length+2,9),branch_index:Math.min(e.length+2,9)}])}}]].concat(e.map(e=>[{func:()=>{a.video.deviceId=e.deviceId;t()},ended:true}]).slice(0,7).concat([[{func:()=>{if(re.local_src){o=re.local_src;t();return true}else{DEBUG_show("(No local media file found)",3);MMD_SA_options.Dungeon.run_event(null,0,0)}}}],[{func:()=>{i=true;t()},ended:true}]])))})}if(i){DEBUG_show("(Canceled)",2);return}if(!o&&a.video.deviceId!=this.deviceId){t=await n();if(!t){DEBUG_show("(Camera not accessible)",3);return}}}if(o){re.init_stream(o)}else if(t){re.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)}}catch(s){if(MMD_SA_options.Dungeon&&MMD_SA_options.Dungeon.event_mode)MMD_SA_options.Dungeon.run_event({ended:true});re.init_stream();console.error(s);DEBUG_show("(ERROR: Camera unavailable, using fallback video instead)",3)}},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);window.addEventListener("resize",function(){re.video_track&&re.video_track.applyConstraints(re.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;this.show();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"){v(e)}else{this.stream=e;this.video_id=e.id;this.video_track=e.getVideoTracks()[0];this.video.srcObject=e;console.log("(New stream started)");setTimeout(function(){let e=re.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=re.video_track.getSettings();System._browser.console.log(Object.entries(t).map(e=>e[0]+":"+JSON.stringify(e[1])).join("\n"))},2e3)}if(_e.enabled)_e.reset_calibration()},get use_armIK(){return de.enabled||Z.enabled},bodyPix:function(){var o;var i=false;c={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";re.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");d.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=re.video_canvas,t,i,o){const n=MMD_SA.THREEX.SL;if(System._browser.snapshot.check_bodyPix()){re.video_canvas.style.visibility="inherit";re.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(re.video_canvas_bodyPix.width!=s||re.video_canvas_bodyPix.height!=r){re.video_canvas_bodyPix.width=s;re.video_canvas_bodyPix.height=r}const _=s/r/(e.width/e.height);const l=Math.round(s*Math.min(1/_,1));const d=Math.round(r*Math.min(_,1));const c=(s-l)/2;const u=(r-d)/2;const p=re.video_canvas_bodyPix.getContext("2d");p.globalCompositeOperation="copy";p.filter="blur("+Math.ceil(3/window.devicePixelRatio)+"px)";p.drawImage(this.mask,0,0,a.width,a.height,c,u,l,d);p.globalCompositeOperation="source-out";p.filter="none";p.save();if(re.mirror_3D){p.translate(s,0);p.scale(-1,1)}p.drawImage(n,0,0);p.restore();p.globalCompositeOperation="destination-over";p.drawImage(e,0,0,e.width,e.height,c,u,l,d);re.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=d.face_cover;if(!d.enabled||!e.complete)return;re.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;d.update_frame_local(re.video_canvas_bodyPix,r)}};return c}(),face_detection:function(){var t=false;function i(){d.initialized=true;if(!self.OffscreenCanvas)d.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);d.worker_initialized=true}else{re._needs_RAF=true;if(t._t)DEBUG_show(t._t);d.dets=t.dets;d.busy=0;re.video_canvas_face_detection.style.left=re.video_canvas.style.left;re.video_canvas_face_detection.style.top=re.video_canvas.style.top;if(!self.OffscreenCanvas){System._browser.on_animation_update.add(function(){d.update_frame_local(null,d.dets)},0,0)}}d.update_frame()}}d={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(re.initialized)re.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=d.enabled&&d.worker_initialized&&A&&!d.busy&&k&&d.camera_video_timestamp!=A;if(!e)return;d.busy=RAF_timestamp;d.camera_video_timestamp=A;d.camera_video_frame_id=D;re.video_canvas_face_detection.style.visibility="inherit";let t,i,o;t=re.video_canvas;i=t.width;o=t.height;let n=t.getContext("2d").getImageData(0,0,i,o).data.buffer;let a=re.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(!re.video_canvas_face_detection._offscreen&&self.OffscreenCanvas){s.canvas=re.video_canvas_face_detection.transferControlToOffscreen();re.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=re.video_canvas.width;let o=re.video_canvas.height;let n;if(!e){e=re.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,d,c;if(i.length){let t=1;i.forEach(function(e){_=e[2]*t;l=_*s/r;d=e[1]*t-l/2;c=e[0]*t-_/2;n.drawImage(a,0,0,s,r,d,c,l,_)})}else{_=Math.min(t,o);l=_*s/r;d=(t-l)/2;c=(o-_)/2;n.drawImage(a,0,0,s,r,d,c,l,_)}}};return d}(),facemesh:function(){var i=false;var N=0;var Y=0;var Z=true;var $=0;var J=[];var ee;var te;var ie;var b=false;var o=-1;var t;function n(e){if(!e&&t&&t==re.video_id)return;t=re.video_id;N=0;Y=0;Z=true;$=0;J=[];ee={};te={L:[],R:[]};var o={L:[159,145],R:[386,374]};["L","R"].forEach(function(t){for(var i=0;i<1;i++){let e=te[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]}ee[t]={_height_average:0,height_average:0,height_data:[],height_ref_pts:t=="R"?[334,330]:[105,101]}})}var a;var oe=[];var ne,ae,v;ne=!is_mobile;v=!is_chrome||is_mobile;var e;function s(){if(_e.initialized)return;_e.initialized=true;for(var e=0;e<4;e++)oe[e]=new THREE.Vector3;var o=[];if(System._browser.use_WASM_SIMD){o.push("simd=1")}if(h){ne=true}if(v){ne=true;o.push("use_mediapipe_facemesh=1")}if(ne){ne=true;if(_e.blink_detection==null)_e.blink_detection=true;o.push("use_face_landmarks=1")}if(ae){o.push("use_human_facemesh=1")}var t;if(MMD_SA_options.user_camera.ML_models.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=d;return t}function r(e,t,i){const o=new Path2D;o.moveTo(t[0][0]/2,t[0][1]/2);for(let e=1;e<3;e++){const n=t[e];o.lineTo(n[0]/2,n[1]/2)}if(i){o.closePath()}e.stroke(o)}const _=["_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 se;const l=["あ","い","う","お","にやり","ω","口角上げ","口角下げ","上","下","にこり","困る","怒り","まばたき","笑い","びっくり","まばたきL","まばたきR"];var d=function(){function K(e){if(!e||se)return;se={};e.categories.forEach((e,t)=>{const i=e.categoryName;se[i.charAt(0)+i.substring(1)]=t})}var U=0,W=0,V=0,Q=0;const X={};window.addEventListener("jThree_ready",()=>{for(const e of l.concat(["両目"])){X[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 x=typeof e.data=="string"&&e.data.charAt(0)==="{"?JSON.parse(e.data):e.data;if(typeof x==="string"){if(x=="OK"){_e.worker_initialized=true}else{DEBUG_show(x,2);System._browser.console.log(x)}}else if(x.posenet){Te({data:x})}else if(_e.enabled){re._needs_RAF=true;const t=Fe[de.use_holistic?1:0];if(!t.facemesh){t.facemesh=true;DEBUG_show("Facemesh ML ready",2)}let E="";if(x.faces.length){_e.data_detected++}else{_e.data_detected=0}if(x.faces.length&&x.faces[0].bb_center){S=x.faces[0].bb_center}else if(!de.enabled){S=[.5,.5]}if(x.faces.length&&_e.data_detected_stable){let g=x.faces[0];K(g.faceBlendshapes);let d=re.x_flipped?1:-1;const P={facemesh_data:g};let c,u,l;if(g.rotation){const T=g.rotation.matrix;pe.set(T[0],T[1],T[2],0,T[3],T[4],T[5],0,T[6],T[7],T[8],0,0,0,0,1)}else{let e=MMD_SA._v3a_.fromArray(g.mesh[152]).sub(MMD_SA._v3b.fromArray(g.mesh[10])).normalize();let t=MMD_SA._v3b_.fromArray(g.mesh[454]).sub(MMD_SA._v3b.fromArray(g.mesh[234])).normalize();let i=MMD_SA.TEMP_v3.crossVectors(t,e).normalize();t.crossVectors(e,i);pe.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(pe,"YZX");c=-e.x;u=-e.y;l=-e.z;let t=g.scaledMesh[454][0]-g.scaledMesh[234][0];let i=g.scaledMesh[454][1]-g.scaledMesh[234][1];let o;if(x.recalculate_z_rotation_from_scaledMesh){t/=Math.cos(u);i/=Math.cos(c);o=Math.sqrt(t*t+i*i)}else{t/=Math.cos(l);o=Math.abs(t/Math.cos(u))}_e.face_width=o;let n;if(x.recalculate_z_rotation_from_scaledMesh){n=Math.asin(i/o)}else{n=l}let a=new THREE.Quaternion;a.setFromEuler(MMD_SA._v3a.set(c,u*d,n*d),"YZX");let s=re.video_timestamp;let r=0;if(Q){r=Math.max(Math.min(s-Q,1e3),10);V+=r;if(++W>=20){U=1e3/(V/W);W=V=0}}Q=s;_e._t=x._t;ge.t_delta=U&&1e3/U||r||x.fps&&1e3/x.fps||x._t;if(_e.head_pose_enabled){if(System._browser.motion_control.enabled)P.head_rot=MMD_SA._v3a.clone();ge.add("skin|facemesh","首",{after_IK:true,rot:a,_rot_ratio:_e.face_width/Math.min(re.video_canvas.width,re.video_canvas.height),onProcessRotation:Ie})}if(!N)N=Date.now();if(Z){Y=~~(Math.min((Date.now()-N)/5e3,J.length/30,ie?te.L[0].eye_open_data.length/30:1,1)*100);Z=Y<100}let _=g.faceInViewConfidence>(ae?.75:.9)&&(re.video==re._image||!re.video.paused&&Math.abs(u)e-t).slice(e,J.length-e).reduce((e,t)=>e+t)/(J.length-e*2);if(!Z){$=m}}}let f=0;let y=0;let M=0;let b=0;["L","R"].forEach(function(e){let t=ee[e];t.height=g.faceBlendshapes?Math.max(g.faceBlendshapes.categories[se["eyeSquint"+(e=="L"?"Left":"Right")]].score,.01):MMD_SA._v3a.fromArray(g.mesh[t.height_ref_pts[0]]).distanceTo(MMD_SA._v3b.fromArray(g.mesh[t.height_ref_pts[1]]));t._height_average=t.height_average;if(!t._height_average){if(_)t.height_data.push(t.height);if(!t.height_data.length){t._height_average=t.height}else{let e=parseInt(J.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(!Z){t.height_average=t._height_average}}}M+=t.height/t._height_average});M/=2;M=(M-1)/.25*(M>1?2:1);if(m){if(h>m*1.05){y=Math.sqrt(Math.min((h-m*1.05)/(m*.25),1))}else if(h2){f=Math.pow(Math.min((p-2)/(m*1/3),1),.5);if(y>.25)b=(y-.25)/.75*.3}}let v=0;let w=0;let S=0;let A=0;let D=0;const I=_e.face_width/Math.min(re.video_canvas.width,re.video_canvas.height);const R=MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only||I>.2?1:Math.max(1-(.2-I)*8,0);let k={L:[0],R:[0]};if(ne){["L","R"].forEach(function(t){let i=0;k[t][i]=0;let o=te[t][i];let n=g.faceBlendshapes?Math.max(1-g.faceBlendshapes.categories[se["eyeBlink"+(t=="L"?"Left":"Right")]].score*.9,.2):MMD_SA._v3a.fromArray(g.mesh[o.height_ref_pts[0]]).distanceTo(MMD_SA._v3b.fromArray(g.mesh[o.height_ref_pts[1]]));let a=o.eye_open_average;if(!a){if(_){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(!Z){o.eye_open_average=a}}else{a=o._eye_open_average}}if(_){if(o.eye_open_lower>n)o.eye_open_lower=n}o._eye_open_average=a;if(a){if(n>a){k[t][i]=Math.min(n/a,1.25)}else{let e=Math.min(o.eye_open_lower,a/2);k[t][i]=Math.max((n-e)/(a-e),0)}}})}if(g.faceBlendshapes){const L=g.faceBlendshapes.categories;const r=[L[se["eyeBlinkLeft"]].score,L[se["eyeBlinkRight"]].score];r.forEach((e,t)=>{const i=t==0?"L":"R";const o=te[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 F=!_e.blink_sync;const C=(F?Math.min(Math.abs(r[0]-r[1])/.4,1):0)*R;let e=F?Math.min(...r):(r[0]+r[1])/2;L[se["eyeBlinkLeft"]].score=r[0]*C+e*(1-C);L[se["eyeBlinkRight"]].score=r[1]*C+e*(1-C);for(const B of["eyeSquintLeft","eyeSquintRight"]){const z=B=="eyeSquintLeft"?"L":"R";const H=Math.min(Math.max((ee[z]._height_average||0)*.8,.2),.5);L[se[B]].score=Math.max(L[se[B]].score-H,0)/(1-H)}const j=Math.min(Math.max((m||0)*.8,.2),.6);L[se["mouthPucker"]].score=Math.pow(Math.max(L[se["mouthPucker"]].score-j,0)/(1-j),2);if(MMD_SA.THREEX.get_model(0).use_faceBlendshapes){L.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");ge.add("morph|facemesh",i,{weight:e.score})})}}if(Array.isArray(g.emotion)){g.emotion.forEach(e=>{switch(e.emotion){case"happy":v+=e.score;break;case"sad":w+=e.score;break;case"angry":case"disgust":S+=e.score;break;case"fear":A+=e.score;break;case"surprise":D+=e.score;break}})}if(g.faceBlendshapes){const L=g.faceBlendshapes.categories;let e=L[se["jawOpen"]].score;let t=(L[se["mouthSmileLeft"]].score+L[se["mouthSmileRight"]].score)/2;let i=(L[se["mouthUpperUpLeft"]].score+L[se["mouthUpperUpRight"]].score)/2;let o=L[se["mouthPucker"]].score;let n=L[se["mouthFunnel"]].score;let a=L[se["mouthShrugLower"]].score;a*=a;let s=L[se["browInnerUp"]].score;s*=s;let r=(L[se["browOuterUpLeft"]].score+L[se["browOuterUpRight"]].score)/2;let _=(L[se["browDownLeft"]].score+L[se["browDownRight"]].score)/2;let l=0,d=0,c=0,u=0;if(e<.2){if(o>.05){c=o;if(n>.1)u=(n-.1)/2}else if(t>.1){d=Math.min(t+i/2,1)}else{l=e+t}}else{if(o>.05){u=Math.min(e+n/2,1)}else{l=Math.min(e+(t+i)/3,1)}}if(n>.1){y=-(n-.1)*.75}else{y=Math.min(Math.max(t-.5,0)*1.5+Math.max(i-.5,0)*1.5,1)}v=Math.min(Math.max(t-.5,0)*1.5+Math.max(i-.5,0)*1.5-a,1);if(v<0){w=-v;v=0}v*=.6;w*=.5;t=Math.min(v,.4);if(_>.1){r=-(_-.1)/.9}else if(s>.1&&r>.1){r=((s-.1)/.9+(r-.1)/.9)/2}let p=(L[se["eyeBlinkRight"]].score+L[se["eyeBlinkLeft"]].score)/2;D=Math.max(r-p-.1,0);D=D*D/2;ge.add("morph|facemesh","あ",{weight:l});ge.add("morph|facemesh","い",{weight:d});ge.add("morph|facemesh","う",{weight:c});ge.add("morph|facemesh","お",{weight:u});ge.add("morph|facemesh","にやり",{weight:y});ge.add("morph|facemesh","口角上げ",{weight:i-a});ge.add("morph|facemesh","上",{weight:r});ge.add("morph|facemesh","にこり",{weight:v});ge.add("morph|facemesh","困る",{weight:w});ge.add("morph|facemesh","笑い",{weight:t});ge.add("morph|facemesh","びっくり",{weight:D});const F=!_e.blink_sync&&THREE.MMD.getModels()[0].pmx.morphs_index_by_name["まばたきL"]!=null;if(F){ge.add("morph|facemesh","まばたきL",{weight:Math.max(L[se["eyeBlinkRight"]].score-t,0)});ge.add("morph|facemesh","まばたきR",{weight:Math.max(L[se["eyeBlinkLeft"]].score-t,0)});ge.add("morph|facemesh","まばたき",{weight:0})}else{ge.add("morph|facemesh","まばたきL",{weight:0});ge.add("morph|facemesh","まばたきR",{weight:0});ge.add("morph|facemesh","まばたき",{weight:Math.max(p-t,0)})}let h,m,f;if(_e.auto_look_at_camera){const O=THREE.MMD.getModels()[0].mesh;const q=MMD_SA.TEMP_v3.copy(MMD_SA._trackball_camera.object.position).sub(MMD_SA._head_pos).normalize().applyQuaternion(MMD_SA.get_bone_rotation(O,"頭").conjugate());const G=MMD_SA._v3b.setEulerFromQuaternion(MMD_SA.TEMP_q.setFromUnitVectors(MMD_SA._v3a.set(0,0,1),q));h=-Math.sign(G.x)*Math.min(Math.abs(G.x/(Math.PI/4)),1);m=-Math.sign(G.y)*Math.min(Math.abs(G.y/(Math.PI/4)),1)}else{h=(L[se["eyeLookUpLeft"]].score+L[se["eyeLookUpRight"]].score)/2-(L[se["eyeLookDownLeft"]].score+L[se["eyeLookDownRight"]].score)/2;m=(L[se["eyeLookInRight"]].score+L[se["eyeLookOutLeft"]].score)/2-(L[se["eyeLookInLeft"]].score+L[se["eyeLookOutRight"]].score)/2}f={absolute:true,rot:(new THREE.Quaternion).setFromEuler(MMD_SA._v3a.set(-h*15/180*Math.PI,-m*20/180*Math.PI,0),"YZX")};ge.add("skin|facemesh","両目",f)}else{let e=v-(w+S+A+D*.5);if(e<0){b*=Math.max(1+e*2,0)}else{b=Math.min(e*.2+b*(1+e*.5),.4)}ge.add("morph|facemesh","にこり",{weight:X["にこり"].filter(Math.min(b+v*.75,.75))});ge.add("morph|facemesh","困る",{weight:X["困る"].filter(Math.min((w+A)/2*.75+(M<0?Math.max(-M*1-Math.max(y,0)*.5,0):0),.75))});ge.add("morph|facemesh","怒り",{weight:X["怒り"].filter(Math.min(S*.75,.75))});M+=D*.2;ge.add("morph|facemesh","笑い",{weight:X["笑い"].filter(b)});ge.add("morph|facemesh","びっくり",{weight:X["びっくり"].filter(D*.75)});ge.add("morph|facemesh","にやり",{weight:X["にやり"].filter(y)});let i=MMD_SA.TEMP_q.setFromEuler(MMD_SA._v3a.set(c,u,l),"YZX").conjugate();let o=[];[13,14,61,291].forEach(function(e,t){o[e]=oe[t].fromArray(g.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*f,0);if(r)r=Math.min(r/20,.75);r=Math.min(r+w*.25,1);r*=.5;f=f*(1-r);ge.add("morph|facemesh","あ",{weight:X["あ"].filter(f)});ge.add("morph|facemesh","お",{weight:X["お"].filter(r)});let _={L:[],R:[]};if(!_e.eye_tracking){}else if(ne){let i=[0,0];let o=[0,0];g.eyes.forEach(function(e,t){if(e){i[t]=Math.max(Math.min((e[3]*2+c/(Math.PI/2))*(1-Math.abs(c)/Math.PI),1),-1);o[t]=Math.max(Math.min((e[2]*2-u/(Math.PI/2))*(1-Math.abs(u)/Math.PI),1),-1)}});let e=(k.L[0]+k.R[0])/2;if(e>1)M+=(e-1)*2;else M-=(1-e)*.5;M=Math.min(M,1);let t=k.L[0]+k.R[0];if(t)t=k.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(X["両目"].filter(MMD_SA.TEMP_q.setFromEuler(MMD_SA._v3a.set(-(n-.3)*15/180*Math.PI,a*d*20/180*Math.PI,0),"YZX").toArray()))};ge.add("skin|facemesh","両目",s);let r=!_e.blink_sync&&THREE.MMD.getModels()[0].pmx.morphs_index_by_name["まばたきL"]!=null;let _=(r?Math.min(Math.max(Math.abs(k.L[0]-k.R[0])-(.25+(1-Math.min(Math.max((Math.PI/6-Math.abs(u))/(Math.PI/12),0),1))*1),0)/.25,1):0)*R;let l=r?Math.min(k.L[0],k.R[0]):(k.L[0]+k.R[0])/2;k.L[0]=k.L[0]*_+l*(1-_);k.R[0]=k.R[0]*_+l*(1-_);if(r){let e="まばたき"+(d==1?"L":"R");ge.add("morph|facemesh",e,{weight:X[e].filter(Math.max(Math.min(1-k.L[0]*.8-b,1),0))});e="まばたき"+(d==1?"R":"L");ge.add("morph|facemesh",e,{weight:X[e].filter(Math.max(Math.min(1-k.R[0]*.8-b,1),0))});ge.add("morph|facemesh","まばたき",{weight:0})}else{ge.add("morph|facemesh","まばたきL",{weight:0});ge.add("morph|facemesh","まばたきR",{weight:0});ge.add("morph|facemesh","まばたき",{weight:X["まばたき"].filter(Math.max(Math.min(1-k.L[0]*.8-b,1),0))})}}else{let e=g.eyes[0];let t=0;let i=0;if(e){t=Math.max(Math.min((e[3]*2+c/(Math.PI/2))*(1-Math.abs(c)/Math.PI),1),-1);i=Math.max(Math.min((e[2]*2-u/(Math.PI/2))*(1-Math.abs(u)/Math.PI),1),-1)}let o=M*.25;if(o<0)o=Math.min(o+b,0);let n=Math.max(Math.min(.1-t*(t<0?2:1)*.2-o,.5),0);ge.add("morph|facemesh","まばたき",{weight:n});let a=1.25+Math.pow((k.L[0]+k.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*d*20/180*Math.PI,0),"YZX")};ge.add("skin|facemesh","両目",s)}if(_e.eye_tracking)ge.add("morph|facemesh","上",{weight:X["上"].filter(Math.max(Math.min(M,1),-1))})}E=E||g.eyes.length&&[(!de.enabled?re.video_canvas.width+"x"+re.video_canvas.height+"("+_e.camera_video_frame_id+")\n":"")+(Z?"Calibrating("+Y+"%):Make a calm face!":"(face data calibrated)")+"/"+Math.round(g.faceInViewConfidence*100)+"%",g.emotion?JSON.stringify(g.emotion):"Neutral"].join("\n");if(ce)E+=(ue?"\n"+ue+"\n":"")+ce;System._browser.motion_control.process(P)}else{E="(no facemesh data)\n"+ce}if(!System._browser.overlay_mode&&!MMD_SA_options.user_camera.ML_models.debug_hidden){System._browser.on_animation_update.add(()=>{DEBUG_show(E&&E+(!de.enabled||!de.use_holistic?"\nF-FPS:"+Math.round(U)+"/"+Math.round(x.fps||0):"")+"\n"+"FPS:"+EV_sync_update.fps_last||"")},0,0)}_e.busy=0}_e.update_frame()}}();var w=document.createElement("canvas");var c=true;var S=[];var u=0;var p=0;_e={initialized:false,worker_initialized:false,faceBlendshapes_list:_,MMD_morph_list:l,get data_detected(){return u},set data_detected(e){if(e){if(!u){p=RAF_timestamp}}else{p=0}u=e},get data_detected_stable(){return i&&p&&RAF_timestamp-p>250},get head_pose_enabled(){return this.data_detected_stable||!de.enabled},get blink_detection(){return ie},set blink_detection(e){ie=e;if(i){if(ie){n()}else{MMD_SA_options.auto_blink=a!=null?a:MMD_SA_options.auto_blink}}},get auto_blink(){return b},set auto_blink(e){b=e},get eye_tracking(){return c},set eye_tracking(e){c=e;if(c){this.blink_detection=!!ne}else{this.blink_detection=false}if(i){if(!c){ge.remove("skin","両目");ge.remove("morph","まばたきL");ge.remove("morph","まばたきR");ge.remove("morph","まばたき");ge.remove("morph","上");ge.remove("morph","下")}}},get use_faceLandmarksDetection(){return ne},set use_faceLandmarksDetection(e){if(!this.initialized)ne=e},get use_mediapipe(){return v||de.enabled&&de.use_holistic},set use_mediapipe(e){return v=e},get use_faceBlendshapes(){return!de.enabled||!de.use_holistic},get calibrated(){return!Z&&Y>=100},export_calibration:function(){const e={facemesh_calibration_type:de.use_holistic?"holistic":"facemesh",lips_width_average:$,eyebrow_data:{L:{height_average:ee.L.height_average},R:{height_average:ee.R.height_average}},eye_data:{L:{eye_open_average:te.L[0].eye_open_average},R:{eye_open_average:te.R[0].eye_open_average}}};System._browser.save_file("facemesh_calibration.json",JSON.stringify(e,null,"\t"),"application/json")},import_calibration:function(e){this.reset_calibration();$=e.lips_width_average;for(const t of["L","R"]){Object.assign(ee[t],e.eyebrow_data[t]);Object.assign(te[t][0],e.eye_data[t])}Y=100;Z=false},face_width:0,get enabled(){return i},set enabled(e){if(i==!!e)return;i=!!e;this.busy=0;this.data_detected=0;S[0]=S[1]=.5;if(i){if(!this.initialized)s();a=MMD_SA_options.auto_blink;const t=de.use_holistic?1:0;n(o!=t);o=t}else{MMD_SA_options.auto_blink=a}x()},get bb_center(){return S},set bb_center(e){S=e},reset_calibration:n,get frames(){return ge},init:s,worker_onmessage:d,camera_video_timestamp:0,update_frame:function(e){async function t(){var e=_e.enabled&&_e.worker_initialized&&A&&!_e.busy&&!(de.enabled&&de.use_holistic)&&k&&_e.camera_video_timestamp!=A;if(!e)return;_e.busy=RAF_timestamp;_e.camera_video_timestamp=A;_e.camera_video_frame_id=D;if(ie){MMD_SA_options.auto_blink=b||false}let n;let a,s;let r,_;let l,d;let t;n=re.video_canvas;let i=n.width,o=n.height;l=d=0;a=r=i;s=_=o;let c=1;let u=MMD_SA_options.user_camera.pixel_limit.facemesh;if(u){if(a*s>u[0]*u[1]){c=Math.sqrt(a*s/(u[0]*u[1]));a=r=Math.round(a/c);s=_=Math.round(s/c);n=w;t=true}}let p,h,m;if(MMD_SA_options.user_camera.pixel_limit.facemesh_bb_ratio){p=MMD_SA_options.user_camera.pixel_limit.facemesh_bb_ratio;m=Math.round(Math.min(a,s)*p);r=m;_=m;let e=1;const M=5*(v?2:1);if(_e.data_detected"+r+"x"+_+"):"+[e,t,m,m].join(",")+"=>"+[l,d,r,_].join(","))}}else{if(n.width!=r||n.height!=_){n.width=r;n.height=_;console.log("Facemesh canvas("+a+"x"+s+")")}}f.drawImage(re.video_canvas,Math.round(e*c),Math.round(t*c),Math.round(i*c),Math.round(o*c),0,0,r,_)}let g=E&&v?await createImageBitmap(n,t?0:l,t?0:d,r,_):f.getImageData(t?0:l,t?0:d,r,_).data.buffer;let y={rgba:g,w:a*(h||1),h:s*(h||1),options:{use_facemesh:true,draw_canvas:true,flip_canvas:re.display_flipped,bb:{x:Math.round(l),y:Math.round(d),w:r,h:_,ratio:p||0,scale:h||1,timestamp:re.video_timestamp}}};if(self.FacemeshAT){y.canvas=re.video_canvas_facemesh}else if(!re.video_canvas_facemesh._offscreen&&self.OffscreenCanvas){y.canvas=re.video_canvas_facemesh.transferControlToOffscreen();re.video_canvas_facemesh._offscreen=true;console.log("(Facemesh: use offscreen canvas)")}le.postMessage(y,y.canvas?[y.canvas,y.rgba]:[y.rgba]);y.rgba=g=undefined;y=undefined}if(e||self.FacemeshAT){setTimeout(()=>{t()},0)}else{t()}}};return _e}(),poseNet:function(){var i=false;var t=true;var n=true;var a={};var o=null;var s=0;var r=0;var _=0;var l=null;var d=null;var c=0;de={get enabled(){return i},set enabled(e){if(i==!!e)return;i=!!e;$=0;De=false;this.data_detected=0;this.initial_data_detected=false;_=0;THREE.MMD.getModels()[0].mesh.visible=true;F.set(0,0,0);if(i){if(!this.initialized)U();if(G){worker_id=de.use_holistic?"legacy_holistic":"tasks_vision";if(!p[worker_id]){Fe=[{},{}];m.terminate();for(const t in p)delete p[t];m=new Worker(G);m.onmessage=Te;f=worker_id;p[f]=new K(f,m)}console.log("Web worker ID:"+f);m=p[f].worker;u=p[f].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()}x();if(de.use_holistic){setTimeout(()=>{if(i)_e.enabled=Z.enabled=true;else Z.enabled=false;DEBUG_show("(Holistic Mode:"+(i?"ON":"OFF")+")",2)},0)}},get data_detected(){return s},set data_detected(e){if(1){if(e){if(!s){r=RAF_timestamp}if(this.data_detected_stable){_=0}}else{r=0;if(!_){_=RAF_timestamp}if(RAF_timestamp-_>250){ge.reset()}}}s=e},get data_detected_stable(){return i&&(!_||RAF_timestamp-_<250||r&&RAF_timestamp-r>500)},get use_3D_pose(){return i&&t&&Se},set use_3D_pose(e){t=e},get use_holistic(){return o==null?h:o},set use_holistic(e){o=e},get _use_holistic_(){return h},set _use_holistic_(e){h=e},get skip_hand_countdown_max(){return this.use_holistic||B||MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only||de.shoulder_width/Math.min(re.video_canvas.width,re.video_canvas.height)>1/3?0:1},set IK_disabled(e){n=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 d!=null?d:!i||!!MMD_SA_options.user_camera.ML_models.pose.auto_grounding},set ground_plane_visible(e){d=e},get spine_length_ref(){if(c)return c;const e=MMD_SA_options.model_para_obj.left_leg_length/MMD_SA_options.model_para_obj.spine_length;return de.leg_scale_adjustment?Math.max(4.97462,MMD_SA_options.model_para_obj.spine_length*(e/1.83))*(21-de.leg_scale_adjustment)/20:Math.max(4.97462,MMD_SA_options.model_para_obj.spine_length)},set spine_length_ref(e){c=e},hip_adjustment_weight:1,leg_scale_adjustment:0,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||!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 ge},camera_video_timestamp:0,get busy(){return $},get initialized(){return w},get worker_initialized(){return u},set worker_initialized(e){u=p[f].initialized=e}};return de}(),handpose:function(){var t=false;Z={get enabled(){return t},set enabled(e){if(t==!!e)return;t=!!e;if(t){if(!this.initialized)U()}},get frames(){return ge},get busy(){return $},get initialized(){return w},get worker_initialized(){return u},set worker_initialized(e){u=p[f].initialized=e}};return Z}(),reset_video_canvas:function(){if(this.video_canvas){this.video_canvas.width=this.video_canvas.height=A=0;D=""}},show:function(){if(!this.initialized||this.visible)return;this.visible=true;if(re.target_devicePixelRatio!=window.devicePixelRatio){re.target_devicePixelRatio=0;re.video_track.applyConstraints(re.set_constraints()).then(function(){DEBUG_show("(camera size updated)",2)})["catch"](function(e){DEBUG_show("ERROR:camera size failed to update")})}g();if(this.hidden_enforced)this.hide()},hide:function(){if(!this.initialized||!this.visible)return;this.visible=false;this.video_canvas.style.visibility="hidden";d.enabled=false;c.enabled=false;y()},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(!b){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)}}re.target_width=o;re.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(e)t=Object.assign(t,e);console.log("Camera constraints",t);return t}};return re}(),data_filter:function(){class n{constructor(e=200,t=n.#reducer_scalar){this.data_list=[];this.time_average=e;if(typeof t=="string"){switch(t){case"vector3":this.reducer=n.#reducer_vector3;break;case"quaternion":this.reducer=n.#reducer_quaternion;break}}else{this.reducer=t}n.#init()}static#initialized;static#init(){if(n.#initialized)return;n.#initialized=true;n.#v1=new THREE.Vector3;n.#v2=new THREE.Vector3;n.#q1=new THREE.Quaternion;n.#q2=new THREE.Quaternion}static#reducer_scalar(e,t,i,o){return(typeof e=="number"?e:e.value/o.length)+t.value/o.length}static#v1;static#v2;static#reducer_vector3=function(e,t,i,o){return n.#v1.fromArray(Array.isArray(e)?e:e.value).lerp(n.#v2.fromArray(t.value),1/(i+1)).toArray()};static#q1;static#q2;static#reducer_quaternion=function(e,t,i,o){return n.#q1.fromArray(Array.isArray(e)?e:e.value).slerp(n.#q2.fromArray(t.value),1/(i+1)).toArray()};filter(e,i=System._browser.camera.initialized&&System._browser.camera.ML_enabled?System._browser.camera.video_timestamp:RAF_timestamp){if(!this.data_list.length||i!=this.data_list[this.data_list.length-1].timestamp)this.data_list.push({timestamp:i,value:e});if(this.data_list.length>1){this.data_list=this.data_list.filter((e,t)=>t==this.data_list.length-1||Math.abs(i-e.timestamp){switch(e.type){case"average":e.filter=new n(...e.para||[]);break;case"one_euro":e.filter=new OneEuroFilter(...e.para||[]);break}if(e.id)e.filter.id=e.id})}filter(t,i=System._browser.camera.initialized&&System._browser.camera.ML_enabled?System._browser.camera.video_timestamp:RAF_timestamp){this.filters.forEach(e=>{if(!e.condition||e.condition())t=e.filter.filter(t,i)});return t}}return t}(),motion_control:function(){var s,p,u,i,_,h;var c;var m;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=>h[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=>[h[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=>[h[e]]));if(n.press.length){const a=n.press.map(e=>h[e]);o=[...o.filter(e=>a.indexOf(e[0])==-1),...n.release.map(e=>[h[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 g={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);for(let e=this.list.length-1;e>=0;e--){if(this.list[e].timestamp>RAF_timestamp-3e3){if(ei.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(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 k=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 E=["0","1","2","3"];var x=[];var P=[];const I={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&&!d},get handedness(){return m},get off_hand(){return m=="左"?"右":"左"},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 h},get key_pressed(){return f.pressed},gestures:g,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(!g.list.length||g.list[0].timestamp!=RAF_timestamp){g.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 d={};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});g.list[0].hand_rot_YXZ=l;g.list[0].hand_facing=_;g.list[0].thumb_out=d;e.forEach(e=>{if(!r)return;if(!e._used)return;if(S){g.estimate(c,e);const t=g.search("index_up",{duration:1e3,hand_facing:"front",thumb_out:false});if(t){S=false;m=t._d;DEBUG_show("Motion control:READY",2)}}else if(e._d==m){g.estimate(c,e);const t=g.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 d;var o,n;function c(){if(e)return;d=new fp.GestureEstimator([g.custom.index_up,g.custom.index_thumb,g.custom.index_middle,g.custom.index_pinky,g.custom.palm_open,g.custom.thumb,g.custom.thumb_index,g.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}c();const a=await k();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 u(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 I.setMousePosition(t)})}let t;if(i.posenet_data){t=i.posenet_data.handpose;let e="";if(!t||!t.length){t=null;if(g.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==m?"R":"L";x.push(s+":");g.estimate(d,n);let i;i=g.search("palm_open",{hand:n,hand_facing:"front",condition:function(e){const t=this.hand;const i=y.fromArray(t.annotations.index[0]).sub(M.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==m){i=g.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=g.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=g.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+=m=="右"?1:3;break;case"Diagonal Up Right":e+=m=="右"?3:1;break}await f.activate(i,s,e,f.clear_list(s));x.push(e);continue}i=g.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(M.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=g.search("thumb",{hand:n});if(i){x.push("CANCEL");await f.releaseKey(...f.clear_list(s));continue}i=g.search("index_pinky",{hand:n});if(i){x.push("index_pinky");continue}}else{i=g.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(M.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=>[h[e]]));if(t.length)await f.releaseKey(...t.map(e=>[h[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==m)],[1,t.findIndex(e=>e._used&&e._d!=m)]]){if(l[1]!=-1)continue;const s=l[0]==0?"R":"L";if(g.search("palm_open",{time_limit:500,hand:{_d:l[0]==0?m:I.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 u(){if(e)return;t=new fp.GestureEstimator([fp.Gestures.VictoryGesture,fp.Gestures.ThumbsUpGesture,g.custom.index_up]);e=true}return{enabled:false,process:async function(e){if(!this.enabled)return;if(!e.posenet_data)return;u();const t=e.posenet_data.handpose;if(!t||!t.length)return;const i=t[0]._d==m?0:1;const o=m=="右"?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 d={x:-(-s.width/2+l[0])/(s.width/2*_),y:(-s.height/2+l[1])/(s.height/2*_)};d.x=Math.round(n+THREE.Math.clamp(d.x*r,-1,1)*n);d.y=Math.round(a+THREE.Math.clamp(d.y/r,-1,1)*a);const c=new p(d.x,d.y);await I.setMousePosition(c)}}}()};return I}(),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=p.get_specs();l.width=e.width;l.height=e.height;p._fps=e.fps;p.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 d(){if(!p.media_recorder||p.started)return;p.started=true;p.media_recorder.start();if(_&&p.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 c(){System._browser.video_capture.stop()}var u=[];const p={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});u.length=0;this.media_recorder.addEventListener("dataavailable",async e=>{u.push(e.data);if(!this.enabled){let e=new Blob(u,{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;u.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+(p._fps>-1?"/"+p._fps+"fps":""))+"/"+p.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)){d()}else{if(p.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",c,{once:true});s.mixer.addEventListener("finished",c,{once:true})}else{window.addEventListener("SA_MMD_model0_onmotionended",c,{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;d()})}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",c);e.mixer.removeEventListener("finished",c)}else{window.removeEventListener("SA_MMD_model0_onmotionended",c)}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 p})(),hotkeys:(()=>{class a{constructor(e,t){this.id=e.id;this.index=t;this.config=a.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 a.config_by_id[e]}static accelerators={};static register(e,t){if(!a.unregister(e))return false;const i=a.get_config(e);i.accelerator=t;t.forEach((e,t)=>{a.accelerators[e]=new a(i,t)});return true}static unregister(e){const t=a.get_config(e);if(!t)return false;t.accelerator.forEach(e=>{if(a.accelerators[e].is_global){try{webkit_electron_remote.globalShortcut.unregister(_acc)}catch(t){}}delete a.accelerators[e]});return true}static remove(e){if(a.unregister(e))delete a.config_by_id[e]}static add(i){a.remove(i.id);i.accelerator.forEach((e,t)=>{a.accelerators[e]=new a(i,t)})}static is_global=null;static register_global(i=!a.is_global){if(browser_native_mode){DEBUG_show("(Global hotkey is for app mode only.)",5);return}a.is_global=i;DEBUG_show("Global hotkey:"+(i?"ON":"OFF"),3);Object.values(a.accelerators).forEach(e=>{if(e.config.global_disabled)return;try{if(i){webkit_electron_remote.globalShortcut.register(e.accelerator,()=>{SA_topmost_window.SA_OnKeyDown(e.event)})}else{webkit_electron_remote.globalShortcut.unregister(e.accelerator)}e.is_global=webkit_electron_remote.globalShortcut.isRegistered(e.accelerator)}catch(t){}})}}window.addEventListener("SA_keydown",o=>{const n=o.detail.e;Object.values(a.config_by_id).some(e=>{const t=e.accelerator.some(e=>{const t=a.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 a})(),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;e0){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