diff --git a/jThree/three.core.min.js b/jThree/three.core.min.js index 39b0015..37e6065 100644 --- a/jThree/three.core.min.js +++ b/jThree/three.core.min.js @@ -25,6 +25,6 @@ THREE.ShaderLib.mirror={uniforms:{mirrorSampler:{type:"t",value:null},mirrorPosi THREE.TrackballControls=function(e,t){var d=this,n={NONE:-1,ROTATE:0,ZOOM:1,PAN:2,TOUCH_ROTATE:3,TOUCH_ZOOM:4,TOUCH_PAN:5};this.object=e;this.domElement=t!==undefined?t:document;this.enabled=true;this.screen={left:0,top:0,width:0,height:0};this.rotateSpeed=1;this.zoomSpeed=1.2;this.panSpeed=.3;this.noRotate=this.noZoom=this.noPan=this.noRoll=false;this.damping=.2;this.minDistance=0;this.maxDistance=Infinity;this.target=e._lookAt;this.lastPosition=new THREE.Vector3;this._eye=new THREE.Vector3;var a=n.NONE,i=n.NONE,g=new THREE.Vector3,y=new THREE.Vector3,s=new THREE.Vector2,o=new THREE.Vector2,r=0,c=0,h=new THREE.Vector2,u=new THREE.Vector2;this.target0=this.target.clone();this.position0=this.object.position.clone();this.up0=this.object.up.clone();this._fixed=false;this.objectUp=new THREE.Vector3;var _=new THREE.Vector2;var E=new THREE.Vector2;var m=new THREE.Vector2;this.rotate_with_up_fixed=false;this.getMouseOnScreen_fixed_up=function(e,t,i){return this.getMouseOnScreen(e,t,i||new THREE.Vector2)};this.rotateCamera=function(){var n=new THREE.Vector3,a=new THREE.Quaternion;var r=new THREE.Vector3;var c=new THREE.Vector3;var h=new THREE.Vector3;var u=new THREE.Vector3;var l=new THREE.Quaternion;var i,o;function p(){i=o=null;if(!self.MMD_SA||!MMD_SA_options.trackball_camera_limit)return false;var e=MMD_SA_options.trackball_camera_limit;i=e.max;o=e.min;r.copy(this._eye).applyQuaternion(a);var t=e.adjust&&e.adjust(r);if(t){return t}if(i){if(r.x>i.x||r.y>i.y||r.z>i.z){return true}}if(o){if(r.xthis.EPS){r.subVectors(this.position0,this.target);h.set(0,r.y,-Math.sqrt(r.x*r.x+r.z*r.z));let e=Math.atan2(h.y,-h.z);let t=1.9-e/(Math.PI/4);let i=-1.9-e/(Math.PI/4);u.copy(m).add(E).sub(_);u.y=THREE.Math.clamp(u.y,i,t);a.setFromEuler(MMD_SA.TEMP_v3.set(u.y*45/180*Math.PI,-u.x*180/180*Math.PI,0),"YXZ");c.copy(this._eye);let s=h.angleTo(r);l.setFromAxisAngle(n.set(0,1,0),s);a.multiplyQuaternions(l,a);this._eye.copy(h);let o=p.call(this);if(o){this._eye.copy(c);_.copy(E);return}this._eye.applyQuaternion(a);if(f.call(this)){this._eye.copy(c);_.y=E.y}m.add(E).sub(_);m.y=THREE.Math.clamp(m.y,i,t);_.add(u.copy(E).sub(_).multiplyScalar(this.damping))}return}var e=g.angleTo(y);if(e){n.crossVectors(g,y).normalize();e*=d.rotateSpeed;a.setFromAxisAngle(n,-e);if(p.call(this)){g.copy(y);return}this._eye.applyQuaternion(a);!d._fixed&&d.object.up.applyQuaternion(a);y.applyQuaternion(a);a.setFromAxisAngle(n,e*(d.damping-1));g.applyQuaternion(a);if(f.call(this)){let e=u.crossVectors(r,c).normalize();let t=r.angleTo(c);l.setFromAxisAngle(e,t);this._eye.applyQuaternion(l);!d._fixed&&d.object.up.applyQuaternion(l);y.applyQuaternion(l);g.applyQuaternion(l)}}}}();var l=function(){var a=new THREE.Vector3;return function(e,t){if(!self.MMD_SA||!MMD_SA_options.trackball_camera_limit){e.multiplyScalar(t);return}var i=MMD_SA_options.trackball_camera_limit;var s=i.max;var o=i.min;var n=a.copy(e).multiplyScalar(t).length();if(s&&n>s.length||o&&ns.x)e.x=s.x;if(e.y>s.y)e.y=s.y;if(e.z>s.z)e.z=s.z}if(o){if(e.x0){l(this._eye,e);s.y+=(o.y-s.y)*this.damping}}};this.panCamera=function(){var e=new THREE.Vector2,t=new THREE.Vector3,i=new THREE.Vector3;return function(){e.copy(u).sub(h);if(e.lengthSq()){e.multiplyScalar(this._eye.length()*d.panSpeed);i.copy(this._eye).cross(d.object.up).setLength(e.x);i.add(t.copy(d.object.up).setLength(e.y));d.object.position.add(i);d.target.add(i);h.add(e.subVectors(u,h).multiplyScalar(d.damping))}}}();var b=new THREE.Vector3;var T=1;this.reset=function(){if(self.MMD_SA)System._browser._wallpaper_mousedown=false;b.set(0,0,0);T=1;_=new THREE.Vector2;E=new THREE.Vector2;m=new THREE.Vector2;g=new THREE.Vector3;y=new THREE.Vector3;a=i=n.NONE;this.object.position.copy(this.position0);this.object.up.copy(this.up0);this.object.lookAt(this.target0);this._eye.subVectors(this.object.position,this.target);this.lastPosition.copy(this.object.position);return this};if(self.MMD_SA){this.SA_adjust=function(){var y=new THREE.Vector3;var _=new THREE.Vector3;var E=new THREE.Vector3;var m=new THREE.Quaternion;var v={filter:function(e){return e.no_camera_collision}};return function(e,t){y.copy(this.object.position);var i,s;if(e){if(e instanceof Array){i=e[0];s=e[1]}else i=s=e;this.object.position.sub(this.target).multiplyScalar(1/T).add(this.target).add(i);this.target.add(s);T=1}if(t){b.add(t)}var o=10;var n=2;var a=1;var r=2;var c=0;var h;if(b.x||b.y||b.z)h=m.setFromEuler(b);for(var u=10;u>=n;u--){E.copy(_.copy(this.object.position).sub(this.target).multiplyScalar(1/T*(c+u/o)));if(h)_.applyQuaternion(h);var l={return_value:null};window.dispatchEvent(new CustomEvent("SA_camera_adjust",{detail:{rot_delta:b,pos_v3:_,result:l}}));if(!l.return_value){if(a1||u>n)){a++;c+=u/o;o=Math.pow(10,a);u=10;n=0;continue}if(a==r||a==1&&(u==10||u==n))b.set(0,0,0);this.object.position.copy(_).add(this.target);T=c+u/o;break}if(a==1&&u==n){this.object.position.copy(E).add(this.target);T=c+u/o}}var p=MMD_SA_options.Dungeon;if(p&&T>2/10){var f=!p.no_camera_collision&&p.check_ray_intersection(this.target,_.copy(this.object.position).sub(this.target),v);if(f){var d=_.length()/T;var g=Math.max(f.nearest.distance/d,2/10);this.object.position.sub(this.target).multiplyScalar(1/T*g).add(this.target);T=g}}if(s&&s.lengthSq()>.01*.01)MMD_SA._mouse_pos_3D=[];this.object.updateMatrixWorld();this.position0.add(this.object.position).sub(y)}}()}function p(e){if(!d.enabled)return;e.preventDefault();e.stopPropagation();if(a===n.NONE){a=e.ctrlKey?n.PAN:e.button}if(a===n.ROTATE&&!d.noRotate){g=d.getMouseProjectionOnBall(e.pageX,e.pageY,g);y.copy(g);d.rotate_with_up_fixed&&E.copy(d.getMouseOnScreen_fixed_up(e.pageX,e.pageY,_))}else if(a===n.ZOOM&&!d.noZoom){s=d.getMouseOnScreen(e.pageX,e.pageY,s);o.copy(s)}else if(a===n.PAN&&!d.noPan){h=d.getMouseOnScreen(e.pageX,e.pageY,h);u.copy(h)}document.addEventListener("mousemove",f,false);document.addEventListener("mouseup",v,false)}function f(e){if(!d.enabled)return;e.preventDefault();e.stopPropagation();if(a===n.ROTATE&&!d.noRotate){y=d.getMouseProjectionOnBall(e.pageX,e.pageY,y);d.rotate_with_up_fixed&&d.getMouseOnScreen_fixed_up(e.pageX,e.pageY,E)}else if(a===n.ZOOM&&!d.noZoom){o=d.getMouseOnScreen(e.pageX,e.pageY,o)}else if(a===n.PAN&&!d.noPan){u=d.getMouseOnScreen(e.pageX,e.pageY,u)}}function v(e){if(!d.enabled)return;e.preventDefault();e.stopPropagation();a=n.NONE;document.removeEventListener("mousemove",f);document.removeEventListener("mouseup",v)}function w(e){if(!d.enabled)return;e.preventDefault();e.stopPropagation();var t=0;if(e.deltaY){t=e.deltaY/(e.deltaMode==0?40:1)}else if(e.wheelDelta){t=e.wheelDelta/40}else if(e.detail){t=-e.detail/3}s.y+=t*.01}function M(e){if(d.enabled===false)return;var t=[];for(var i=0;i1){s.normalize()}else{s.z=Math.sqrt(1-o*o)}this._eye.copy(this.object.position).sub(this.target);i.copy(this.object.up).setLength(s.y);i.add(this.objectUp.copy(this.object.up).cross(this._eye).setLength(s.x));i.add(this._eye.setLength(s.z));return i},checkDistances:function(){if(!this.noZoom||!this.noPan){if(this._eye.lengthSq()>this.maxDistance*this.maxDistance){this.object.position.addVectors(this.target,this._eye.setLength(this.maxDistance))}if(this._eye.lengthSq()this.EPS){this.lastPosition.copy(this.object.position)}}};jThree.Trackball=function(e){var i=[];jThree(isFinite(e)?"rdr:eq("+e+")":e||"rdr").each(function(){var t=new THREE.TrackballControls(jThree.three(jThree.getCamera(this)),jThree.getCanvas(this));jThree.update(this,function(){t.callback&&t.callback();t.update()});jThree(this).resize(function(){t.resize()}).on("attrChange",function(e){if(e.attrName!=="camera")return;t.object=jThree.three(jThree.getCamera(this));t.target=t.object._lookAt});i.push(t)});if(self.MMD_SA)MMD_SA._trackball_camera=i[0];return i.length>1?i:i[0]}; (function(){function a(){d.call(this),this.type='AudioListener',this.context=j.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0}function b(k){d.call(this),this.type='Audio',this.listener=k,this.context=k.context,this.gain=this.context.createGain(),this.gain.connect(k.getInput()),this.autoplay=!1,this.buffer=null,this.detune=0,this.loop=!1,this.startTime=0,this.offset=0,this.playbackRate=1,this.isPlaying=!1,this.hasPlaybackControl=!0,this.sourceType='empty',this.filters=[]}function c(k){b.call(this,k),this.panner=this.context.createPanner(),this.panner.connect(this.gain)}var d=THREE.Object3D,e=THREE.Vector3,f=THREE.Quaternion,g=THREE.Clock,h,j={getContext:function(){return void 0===h&&(h=new(window.AudioContext||window.webkitAudioContext)),h},setContext:function(k){h=k}};a.prototype=Object.assign(Object.create(d.prototype),{constructor:a,getInput:function(){return this.gain},removeFilter:function(){return null!==this.filter&&(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination),this.gain.connect(this.context.destination),this.filter=null),this},getFilter:function(){return this.filter},setFilter:function(k){return null===this.filter?this.gain.disconnect(this.context.destination):(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination)),this.filter=k,this.gain.connect(this.filter),this.filter.connect(this.context.destination),this},getMasterVolume:function(){return this.gain.gain.value},setMasterVolume:function(k){return this.gain.gain.setTargetAtTime(k,this.context.currentTime,0.01),this},updateMatrixWorld:function(){var k=new e,m=new f,n=new e,o=new e,p=new g;return function(r){d.prototype.updateMatrixWorld.call(this,r);var s=this.context.listener,t=this.up;if(this.timeDelta=p.getDelta(),this.matrixWorld.decompose(k,m,n),o.set(0,0,-1).applyQuaternion(m),s.positionX){var u=this.context.currentTime+this.timeDelta;s.positionX.linearRampToValueAtTime(k.x,u),s.positionY.linearRampToValueAtTime(k.y,u),s.positionZ.linearRampToValueAtTime(k.z,u),s.forwardX.linearRampToValueAtTime(o.x,u),s.forwardY.linearRampToValueAtTime(o.y,u),s.forwardZ.linearRampToValueAtTime(o.z,u),s.upX.linearRampToValueAtTime(t.x,u),s.upY.linearRampToValueAtTime(t.y,u),s.upZ.linearRampToValueAtTime(t.z,u)}else s.setPosition(k.x,k.y,k.z),s.setOrientation(o.x,o.y,o.z,t.x,t.y,t.z)}}()}),b.prototype=Object.assign(Object.create(d.prototype),{constructor:b,getOutput:function(){return this.gain},setNodeSource:function(k){return this.hasPlaybackControl=!1,this.sourceType='audioNode',this.source=k,this.connect(),this},setMediaElementSource:function(k){return this.hasPlaybackControl=!1,this.sourceType='mediaNode',this.source=this.context.createMediaElementSource(k),this.connect(),this},setBuffer:function(k){return this.buffer=k,this.sourceType='buffer',this.autoplay&&this.play(),this},play:function(){if(!0===this.isPlaying)return void console.warn('THREE.Audio: Audio is already playing.');if(!1===this.hasPlaybackControl)return void console.warn('THREE.Audio: this Audio has no playback control.');this._player&&this._player._dispatchEvent('playing');var k=this.context.createBufferSource();return k.buffer=this.buffer,k.detune.value=this.detune,k.loop=this.loop,k.onended=this.onEnded.bind(this),k.playbackRate.setValueAtTime(this.playbackRate,this.startTime),this.startTime=this.context.currentTime,k.start(this.startTime,this.offset),this.isPlaying=!0,this.source=k,this.connect()},pause:function(){return!1===this.hasPlaybackControl?void console.warn('THREE.Audio: this Audio has no playback control.'):(!0===this.isPlaying&&(this.source.stop(),this.source.onended=null,this.offset+=(this.context.currentTime-this.startTime)*this.playbackRate,this.isPlaying=!1),this)},stop:function(){return!1===this.hasPlaybackControl?void console.warn('THREE.Audio: this Audio has no playback control.'):(this.source.stop(),this.source.onended=null,this.offset=0,this.isPlaying=!1,this)},connect:function(){if(0/\.fbx$/i.test(e.path)).length;if(this.lengtht+2){DEBUG_show("loading error(?)",0,1);console.log("loading error(?)",this.length+"/"+t)}}},x_object_init:function(){function n(e){if(!MMD_SA._x_object_displayed_once)return;if(!this.visible||e){this.visible=true;if(!/^\#mikuPmx/.test(this.id)){MMD_SA.THREEX.mesh_obj.get(this.id).show();return true}}}function _(e){if(!MMD_SA._x_object_displayed_once)return;if(this.visible||e){this.visible=false;if(!/^\#mikuPmx/.test(this.id)){MMD_SA.THREEX.mesh_obj.get(this.id).hide();return true}}}return function(){MMD_SA_options.x_object.forEach(function(t,e){MMD_SA_options.x_object_by_name[t.path.replace(/^.+[\/\\]/,"").replace(/\.x$/i,"")]=t;t.id=t.id||"#x_object"+e;t.show=n;t.hide=_;t._obj=MMD_SA.THREEX.mesh_obj.get_three(t.id);if(t.boundingBox_list!=null){const o=MMD_SA.get_bounding_host(t._obj);o.boundingBox_list=[];t.boundingBox_list.forEach(function(e){if(e==null){o.boundingBox_list.push(o.boundingBox)}else{var t=(new THREE.Box3).set(e.min,e.max);t.oncollide=e.oncollide;t.onaway=e.onaway;o.boundingBox_list.push(t)}});if(t.bb_adjust){o.boundingBox_list.forEach(function(e){if(t.bb_adjust.min)e.min.add(t.bb_adjust.min)})}}if(t.scale==null)t.scale=t._obj.scale.x==0?0:1;t.visible=t.hidden_on_start?false:t._obj.scale.x>0});MMD_SA_options.mesh_obj.forEach(function(e,t){MMD_SA_options.mesh_obj_by_id[e.id]=MMD_SA_options.mesh_obj_by_id["#"+e.id]=e;e.id="#"+e.id;e.show=n;e.hide=_;if(/^\#mikuPmx(\d+)$/.test(e.id)){e._obj=THREE.MMD.getModels()[parseInt(RegExp.$1)].mesh;Object.defineProperty(e,"visible",{get:function(){return this._obj.visible},set:function(e){this._obj.visible=e}});if(e.scale==null)e.scale=1;e.visible=true}else{if(!e._obj)e._obj=MMD_SA.THREEX.mesh_obj.get_three(e.id);var o=e._obj.children.length?e._obj.children[0]:e._obj;if(e.castShadow){o.castShadow=true}if(e.receiveShadow){o.receiveShadow=true}if(e.scale==null)e.scale=e._obj.scale.x==0?0:1;e.visible=e.hidden_on_start?false:e._obj.scale.x>0}});MMD_SA_options.mesh_obj_all=MMD_SA_options.x_object.concat(MMD_SA_options.mesh_obj)}}(),init:function(){var n=jThree;this.x_object_init();var e=this;var t=THREE.MMD.getModels()[0];var o=[];t.pmx.materials.forEach(function(e){o.push(e.name)});MMD_SA._material_list=o;var _=[{path:MMD_SA_options.model_path_default}];for(var i in MMD_SA_options.MME_saved){var a=MMD_SA_options.MME_saved[i];if(a.path_full)_.push({path:toLocalPath(a.path_full)})}_.forEach(function(e){var t=e.path;if(!/^(\w+\:|\/)/.test(t))t=System.Gadget.path+toLocalPath("\\"+t);e.in_use=t==MMD_SA_options.model_path||MMD_SA_options.model_path_extra.indexOf(t)!=-1});MMD_SA._model_list=_;THREE.MMD.getModels().forEach(function(e){e.skin_MMD_SA_extra=[MMD_SA.Animation_dummy];e.morph_MMD_SA_extra=[MMD_SA.Animation_dummy]});MMD_SA.MMD={MotionManager:function(){this._model_index=0},setFrameNumber:function(){},play:function(){jThree.MMD.play()},pause:function(){jThree.MMD.pause()}};Object.defineProperty(MMD_SA.MMD.MotionManager.prototype,"lastFrame",{get:function(){var e=THREE.MMD.getModels()[this._model_index]._MMD_SA_cache[this.para_SA._path];return e.skin.duration*30}});Object.defineProperty(MMD_SA.MMD.MotionManager.prototype,"_timeMax",{get:function(){var e=THREE.MMD.getModels()[this._model_index]._MMD_SA_cache[this.para_SA._path];return e.skin._timeMax}});Object.defineProperty(MMD_SA.MMD.MotionManager.prototype,"lastFrame_",{get:function(){if(this._lastFrame_!=null)return this._lastFrame_;var e=MMD_SA.MMD.motionManager;return e.para_SA.multi_model_motion_list&&e.para_SA.multi_model_motion_list.indexOf(this.filename)!=-1?e._lastFrame_:this.lastFrame},set:function(e){this._lastFrame_=e}});Object.defineProperty(MMD_SA.MMD.MotionManager.prototype,"firstFrame_",{get:function(){if(this._firstFrame_!=null)return this._firstFrame_;var e=MMD_SA.MMD.motionManager;return e.para_SA.multi_model_motion_list&&e.para_SA.multi_model_motion_list.indexOf(this.filename)!=-1?e._firstFrame_:0},set:function(e){this._firstFrame_=e}});MMD_SA.motion=[];var M=MMD_SA_options.motion_shuffle_list_default&&MMD_SA_options.motion_shuffle_list_default[0]||0;window.dispatchEvent(new CustomEvent("SA_MMD_before_motion_init"));for(var l=0,r=MMD_SA_options.motion.length;l0&&!a.is_PC_candidate&&(o||!a.mirror_motion_from_first_model)){r=true}if(a.motion_name_default==m){r=false}if(r){if(t==MMD_SA_options.model_para_obj_all.length-1&&(!MMD_SA.motion.length||MMD_SA.motion[MMD_SA.motion.length-1].filename!=m))MMD_SA.motion.push({});return}n=e.setupMotion_MMD_SA(u,p.match,o);d=MMD_SA_options.motion_para[m]||d;_=n.skin;i=n.morph;if(o){_._is_MMD_SA_custom_animation=i._is_MMD_SA_custom_animation=MMD_SA.custom_action_index&&l>=MMD_SA.custom_action_index&&l0&&!a.mirror_motion_from_first_model)a.motion_name_default=m}e._MMD_SA_cache_current=n;e.skin=_;e.morph=i;THREE.MMD.adjustMotionDuration()}})}MMD_SA.motion_max_default=MMD_SA_options.motion.length;MMD_SA.MMD.motionManager=MMD_SA.motion[0];if(MMD_SA_options.use_speech_bubble){MMD_SA.SpeechBubble.onload()}MMD_SA._tray_updatable=true;System._browser.update_tray();setTimeout(function(){MMD_SA.MMD_started=true;resize();n.MMD.cameraMotion=true;MMD_SA._head_pos=new THREE.Vector3(0,15,0);MMD_SA_options.model_para_obj.onMotionChange&&MMD_SA_options.model_para_obj.onMotionChange();var o=(()=>{const y={};const g={minCutOff:1,beta:1,dCutOff:1};return function(){var b=this;var E=this.mesh;var e=MMD_SA_options.Dungeon&&MMD_SA_options.Dungeon.accessory_list||MMD_SA_options.mesh_obj_all;e.forEach(function(t){var o=t.parent_bone;if(!o)return;var e=o.model_index||0;if(b._model_index!=e)return;const i=t._obj;if(MMD_SA_options.Dungeon){if(!E.visible||o.disabled){if(!E.visible||!t.placement?.position||o.attached&&!o._detached_){t._obj_proxy.hidden=true;t._obj_proxy.visible=false}else{if(o.attached){o.attached=false;i.matrixAutoUpdate=true;t._obj_proxy.hidden=false;t._obj_proxy.visible=true;i.position.copy(o._detached_.pos);i.quaternion.copy(o._detached_.rot)}else{if(!o._detached_)o._detached_={pos:new THREE.Vector3,rot:new THREE.Quaternion};o._detached_.pos.copy(i.position);o._detached_.rot.copy(i.quaternion)}}return}t._obj_proxy.hidden=false;t._obj_proxy.visible=true}if(o.condition&&!o.condition(t,e))return;var n=MMD_SA.motion[b.skin._motion_index].para_SA;var _;_=n.adjustment_per_model&&(n.adjustment_per_model[MMD_SA_options.model_para_obj._filename]||n.adjustment_per_model[MMD_SA_options.model_para_obj._filename_cleaned]);_=_&&_.accessory_default&&_.accessory_default[t.path.replace(/^.+[\/\\]/,"")];if(_)o=_.parent_bone;var a=o.name=="ROOT";var r;if(!a){r=E.bones_by_name[o.name];if(!r)return}t.parent_bone.attached=true;var s,M;var l,p;p=MMD_SA.THREEX.get_model(e);if(a){l=MMD_SA.THREEX._THREE.MMD.getModels()[e].mesh;M=MMD_SA._q2.copy(l.bones_by_name["全ての親"].quaternion)}if(MMD_SA.THREEX.enabled){if(a){const d=p.getBoneNode("hips");s=MMD_SA.THREEX.v1.copy(d.position);if(!o.hips_as_root){s.y=0}s=p.process_position(s).multiplyScalar(MMD_SA.THREEX.VRM.vrm_scale)}else{const u=p.get_bone_by_MMD_name(o.name);if(!u)return;s=MMD_SA.THREEX.v1;M=MMD_SA.THREEX.q1;u.matrixWorld.decompose(MMD_SA.THREEX.v1,MMD_SA.THREEX.q1,MMD_SA.THREEX.v2);const c=MMD_SA.THREEX.q2.copy(p.mesh.quaternion).conjugate();s.sub(p.mesh.position).applyQuaternion(c);M.premultiply(c);if(p.type=="VRM"&&!p.is_VRM1){M.premultiply(MMD_SA.THREEX.q2.set(0,1,0,0));M.x*=-1;M.z*=-1}}}else{i.useQuaternion=true;if(a){r=E.bones_by_name["センター"]}bone_objs=r.skinMatrix.decompose();s=bone_objs[0];if(a){if(o.hips_as_root){s.y=MMD_SA.TEMP_v3.setFromMatrixPosition(E.bones_by_name["下半身"].skinMatrix).y}else{s.y=0}}if(!M)M=bone_objs[1]}i.position.copy(s);if(o.position){const f=MMD_SA.TEMP_v3.set(o.position.x,o.position.y,-o.position.z);i.position.add(f.applyQuaternion(M))}i.quaternion.copy(M);if(o.rotation){let e;if(o.rotation.fixed){i.quaternion.set(0,0,0,1);e=MMD_SA._q1.setFromEuler(MMD_SA.TEMP_v3.set(-o.rotation.fixed.x,-o.rotation.fixed.y,o.rotation.fixed.z).multiplyScalar(Math.PI/180),"YXZ")}else{e=MMD_SA._q1.setFromEuler(MMD_SA.TEMP_v3.set(-o.rotation.x,-o.rotation.y,o.rotation.z).multiplyScalar(Math.PI/180),"YXZ")}i.quaternion.multiply(e)}var m=MMD_SA.TEMP_m4.makeFromPositionQuaternionScale(i.position,i.quaternion,i.scale).multiplyMatrices(E.matrixWorld,MMD_SA.TEMP_m4).decompose();i.position.copy(m[0]);i.quaternion.copy(m[1]);if(o.rotation){const h=o.rotation.align_with_external_point;if(h&&(!h.mocap_only||System._browser.camera.poseNet.enabled&&System._browser.camera.ML_warmed_up)){if(h.reset_rotation)i.quaternion.set(0,0,0,1);let n=MMD_SA._v3a_;if(h.reference_origin){n.copy(h.reference_origin).multiplyScalar(t.placement.scale).applyQuaternion(i.quaternion).add(i.position)}else{n.copy(i.position)}let _;if(h.external_point.type=="bone"){let e;let t;let o;if(h.external_point.name.indexOf("hand")!=-1){e=h.external_point.name.indexOf("left")!=-1?"左":"右";if(System._browser.camera.poseNet.enabled&&(!MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only||!System._browser.camera.poseNet.frames.get_blend_default_motion("skin",e+"腕IK"))){t=p.get_bone_position_by_MMD_name(e+"手首");o=MMD_SA.TEMP_v3.set(0,0,0);if(h.external_point.offset)o.add(h.external_point.offset);o.applyQuaternion(MMD_SA_options.model_para_obj.rot_arm_adjust[e+"腕"].axis_rot).applyQuaternion(p.get_bone_rotation_by_MMD_name(e+"手首"))}}else if(h.external_point.name.indexOf("arm")!=-1){e=h.external_point.name.indexOf("left")!=-1?"左":"右";t=p.get_bone_position_by_MMD_name(e+"腕");o=MMD_SA.TEMP_v3.set(0,0,0);if(h.external_point.offset)o.add(h.external_point.offset);o.applyQuaternion(p.get_bone_rotation_by_MMD_name(!h.external_point.offset?.ignore_local_rotation?e+"腕":"上半身2"))}else if(h.external_point.name=="head"){t=p.get_bone_position_by_MMD_name("頭");o=MMD_SA.TEMP_v3.set(0,0,0);if(h.external_point.offset)o.add(h.external_point.offset);o.applyQuaternion(p.get_bone_rotation_by_MMD_name("頭"))}if(t){if(o)t.add(o);_=t.sub(n)}}else if(h.external_point.type=="object3D"){const S=MMD_SA.THREEX._XR_Animator_scene_.object3D_list.find(e=>e.id==h.external_point.name);if(S){const t=MMD_SA.THREEX._object3d_list_.find(e=>e.uuid==S._object3d_uuid);_=MMD_SA._v3b.copy(h.external_point.reference_point).multiplyScalar(t.placement.scale).applyQuaternion(t._mesh.quaternion).add(t._mesh.position).sub(n)}}if(_){let e=MMD_SA._v3a.copy(h.reference_point);if(h.reference_origin)e.sub(MMD_SA.TEMP_v3.copy(h.reference_origin));e.normalize().applyQuaternion(i.quaternion);e.multiplyScalar(_.length()).add(n).sub(i.position);_=_.add(n).sub(i.position);e.normalize();_.normalize();const A=MMD_SA.TEMP_q.setFromUnitVectors(e,_);i.quaternion.premultiply(A)}}const D=o.rotation.data_filter;if(D){if(!t.uuid)t.uuid=THREE.Math.generateUUID();let e=y[t.uuid];if(!e)e=y[t.uuid]=new System._browser.data_filter([{type:"one_euro",id:"propr_rot",para:[30,1,1,1,4]}]);Object.assign(e.filters[0].filter,g,D);i.quaternion.fromArray(e.filter(i.quaternion.toArray()))}}if(i.updateMatrix){i.matrixAutoUpdate=false;i.updateMatrix()}})}})();THREE.MMD.getModels().forEach(function(e,t){e.simulateCallback=o});var e=MMD_SA_options.MME.PostProcessingEffects;MMD_SA_options._PPE_enabled=e.enabled;if(MMD_SA_options.PPE_disabled_on_idle){if(MMD_SA_options._PPE_enabled){e.enabled=false}}MMD_SA.fadeout_opacity=.95;MMD_SA.fadeout_canvas.width=SL.width;MMD_SA.fadeout_canvas.height=SL.height;var t=MMD_SA.fadeout_canvas.getContext("2d");t.globalCompositeOperation="copy";t.globalAlpha=.01;t.fillRect(0,0,SL.width,SL.height);t.globalAlpha=1;MMD_SA_options.model_para_obj_all.forEach(function(e,t){var o=THREE.MMD.getModels()[t].mesh;if(e.position_loading||e.bone_connection||o.bones_by_name["全ての親"])o.position.set(0,0,0);if(e.scale)o.scale.set(e.scale,e.scale,e.scale)});THREE.MMD.getModels().forEach(function(){function o(e){this.mesh=e;this.m4=new THREE.Matrix4;this.pos=new THREE.Vector3;this.pos_world=new THREE.Vector3;this.reset()}o.prototype.reset=function(){this.pos.set(0,0,0);this.pos_world.set(0,0,0)};o.prototype.update=function(){this.m4.copy(this.mesh.matrixWorld);e.getPositionFromMatrix(this.m4);t.copy(e).sub(this.pos_world);t.multiplyScalar(MMD_SA_options.matrixWorld_physics_scale);this.pos.add(t);this.pos_world.copy(e);t.y+=this.mesh._model_index*25;this.m4.setPosition(t)};var e=new THREE.Vector3;var t=new THREE.Vector3;return function(e){let t=e.mesh;t.matrixWorld_physics=new o(t)}}());MMD_SA_options.onstart&&MMD_SA_options.onstart();window.dispatchEvent(new CustomEvent("MMDStarted"));MMD_SA.toggle_shadowMap();n.MMD.play(true);DEBUG_show("(MMD started)",2);if(MMD_SA.use_webgl2)DEBUG_show("Use WebGL2",2);if(MMD_SA.use_MSAA_FBO)DEBUG_show("Use MSAA FBO",2)},0);if(jThree.Trackball)jThree.trackball=jThree.Trackball;n.trackball();if(!returnBoolean("MMDTrackballCamera"))MMD_SA._trackball_camera.stop();MMD_SA_options.edgeScale=MMD_SA_options.model_para_obj.edgeScale>=0?MMD_SA_options.model_para_obj.edgeScale:MMD_SA_options.edgeScale>=0?MMD_SA_options.edgeScale:1;n.MMD.edgeScale=parseFloat(System.Gadget.Settings.readString("MMDEdgeScale")||Settings_default.MMDEdgeScale)*MMD_SA_options.edgeScale;jQuery("canvas").on("mousedown mousewheel DOMMouseScroll",function(){n.MMD.cameraMotion=false}).dblclick(function(){n.MMD.cameraMotion=true})}};(function(){MMD_SA.TEMP_q=new THREE.Quaternion;MMD_SA._q1=new THREE.Quaternion;MMD_SA._q2=new THREE.Quaternion;MMD_SA.TEMP_v3=new THREE.Vector3;MMD_SA._v3a=new THREE.Vector3;MMD_SA._v3b=new THREE.Vector3;MMD_SA.TEMP_m4=new THREE.Matrix4;MMD_SA._m4a=new THREE.Matrix4;MMD_SA._m4b=new THREE.Matrix4;MMD_SA.TEMP_b3=new THREE.Box3;MMD_SA._v3a_=new THREE.Vector3;MMD_SA._v3b_=new THREE.Vector3;MMD_SA.process_bone=function(e,t,o){const n=MMD_SA.MMD.motionManager.para_SA.look_at_screen_euler_order||"XYZ";const _=MMD_SA._v3a_.setEulerFromQuaternion(e.quaternion,n);if(o){_.x*=o[0];_.y*=o[1];_.z*=o[2]}if(t instanceof THREE.Quaternion)t=MMD_SA._v3b_.setEulerFromQuaternion(t,n);_.add(t);e.quaternion.setFromEuler(_,n)};MMD_SA.copy_first_bone_frame=function(e,t,o){if(!o)o=MMD_SA_options.motion[e].match;var _=o&&o.skin_jThree?o.skin_jThree:null;if(!t._is_skin)t=THREE.MMD.getModels()[0].skin_MMD_SA_extra[t._motion_index_extra];var i=t.mesh;t.targets.forEach(function(e){var t=e.keys[0];if(!t||_&&!_.test(t.name)||t.time){return}var o=i.bones_by_name[t.name];var n=i.geometry.bones[o._index];t.pos[0]=o.position.x-n.pos[0];t.pos[1]=o.position.y-n.pos[1];t.pos[2]=o.position.z-n.pos[2];t.rot=o.quaternion.toArray()})};MMD_SA.reset_skin=function(M){THREE.MMD.getModels().forEach(function(e,t){if(M!=null&&t!=M)return;var o=e.skin;if(!o||o._is_dummy){return}var n=o.mesh;var _=n.geometry;for(var i=0,a=n.bones.length;i0){if(n)return null;a=1}else if(i<0){a=-1;i=-i}else{return null}l.subVectors(this.origin,e);var r=a*this.direction.dot(m.crossVectors(l,m));if(r<0){return null}var s=a*this.direction.dot(p.cross(l));if(s<0){return null}if(r+s>i){return null}var M=-a*l.dot(d);if(M<0){return null}return this.at(M/i,_)}}();MMD_SA.bone_to_position=function(){var m=new THREE.Vector3;var d=new THREE.Vector3;var u=new THREE.Vector3;var c=new THREE.Vector3;function e(){this.by_bone_name=[];this.pos_delta=new THREE.Vector3;this.pos_delta_rotated=new THREE.Vector3;this.bone_pos_offset=new THREE.Vector3}e.prototype.init=function(e,t,o,n){var _=this.by_bone_name[t];if(!_){_=this.by_bone_name[t]={gbone:{position:(new THREE.Vector3).fromArray(e.geometry.bones[e.bones_by_name[t]._index].pos)},position:new THREE.Vector3,quaternion:new THREE.Quaternion,path:"",motion_time:0}}if(_.path!=o||_.motion_time>n){_.position.set(0,0,0);_.quaternion.set(0,0,0,1);_.path=o}_.motion_time=n;this.gbone=_.gbone;this.position=_.position;this.quaternion=_.quaternion};return function(s){var M=this;if(!M.skin)return null;var l=this.mesh;if(l._bone_to_position_last){l._bone_to_position_last.pos_delta.set(0,0,0);l._bone_to_position_last.pos_delta_rotated.set(0,0,0);l._bone_to_position_last.bone_pos_offset.set(0,0,0)}else l._bone_to_position_last=new e;if(!s.bone_to_position)return null;var p=s.adjustment_per_model&&(s.adjustment_per_model[MMD_SA_options.model_para_obj_all[this._model_index]._filename_cleaned]||s.adjustment_per_model._default_)||{};s.bone_to_position.forEach(function(e){var t=e.name;var o=e.scale||{x:1,y:1,z:1};var n=l.bones_by_name[t];var _=M.skin.time;var i=_*30;l._bone_to_position_last.init(l,t,s._path,_);if(!e.frame_range||e.frame_range.some(function(e){return i>=e[0]&&i<=e[1]})){m.copy(n.position).sub(l._bone_to_position_last.gbone.position).multiply(o)}else{m.set(0,0,0)}u.copy(m);var a;var r;if(p.skin_default){let e=p.skin_default[t]||{};a=e.rot_add||e.rot;if(!a&&!s.bone_to_position.some(function(e){return e.name=="全ての親"})){e=p.skin_default["全ての親"]||{};a=e.rot_add||e.rot;r=!!a}if(a){u.applyEuler(c.copy(a).multiplyScalar(Math.PI/180))}}if(!e.position_disabled){d.copy(u).sub(l._bone_to_position_last.position);l._bone_to_position_last.position.copy(u)}else{d.set(0,0,0);u.set(0,0,0)}if(t=="全ての親"){n.position.sub(m);l._bone_to_position_last.bone_pos_offset.add(m)}else{let e=r?m.applyEuler(c.copy(a).multiplyScalar(Math.PI/180)):m;l.bones_by_name["全ての親"].position.sub(e);l._bone_to_position_last.bone_pos_offset.add(e)}l._bone_to_position_last.pos_delta.add(d)});l._bone_to_position_last.pos_delta_rotated.copy(l._bone_to_position_last.pos_delta).applyQuaternion(l.quaternion);return l._bone_to_position_last.pos_delta}}();if(MMD_SA.use_jThree_v1)jThree.goml("index.goml");var e={extractPathBase:function(e){var t=e.split("/");t.pop();return t.length===0?"":t.join("/")+"/"},extractPathExt:function(e){var t=e.split(".").pop();if(t===e){return""}return t}}})(); +MMD_SA.fn={length:1+1,load_length_extra:MMD_SA_options.load_length_extra||0,_ready_for_model_creation:[],_model_creation_timerID:[],setupUI:function(e){this.length++;var t=MMD_SA_options.motion.length+(MMD_SA_options.x_object.length+MMD_SA.GOML_head_list.length)+1+this.load_length_extra;t+=MMD_SA_options.model_path_extra.length;if(!this._ready_for_model_creation[0])t-=MMD_SA_options.motion.filter(e=>/\.fbx$/i.test(e.path)).length;if(this.lengtht+2){DEBUG_show("loading error(?)",0,1);console.log("loading error(?)",this.length+"/"+t)}}},x_object_init:function(){function n(e){if(!MMD_SA._x_object_displayed_once)return;if(!this.visible||e){this.visible=true;if(!/^\#mikuPmx/.test(this.id)){MMD_SA.THREEX.mesh_obj.get(this.id).show();return true}}}function _(e){if(!MMD_SA._x_object_displayed_once)return;if(this.visible||e){this.visible=false;if(!/^\#mikuPmx/.test(this.id)){MMD_SA.THREEX.mesh_obj.get(this.id).hide();return true}}}return function(){MMD_SA_options.x_object.forEach(function(t,e){MMD_SA_options.x_object_by_name[t.path.replace(/^.+[\/\\]/,"").replace(/\.x$/i,"")]=t;t.id=t.id||"#x_object"+e;t.show=n;t.hide=_;t._obj=MMD_SA.THREEX.mesh_obj.get_three(t.id);if(t.boundingBox_list!=null){const o=MMD_SA.get_bounding_host(t._obj);o.boundingBox_list=[];t.boundingBox_list.forEach(function(e){if(e==null){o.boundingBox_list.push(o.boundingBox)}else{var t=(new THREE.Box3).set(e.min,e.max);t.oncollide=e.oncollide;t.onaway=e.onaway;o.boundingBox_list.push(t)}});if(t.bb_adjust){o.boundingBox_list.forEach(function(e){if(t.bb_adjust.min)e.min.add(t.bb_adjust.min)})}}if(t.scale==null)t.scale=t._obj.scale.x==0?0:1;t.visible=t.hidden_on_start?false:t._obj.scale.x>0});MMD_SA_options.mesh_obj.forEach(function(e,t){MMD_SA_options.mesh_obj_by_id[e.id]=MMD_SA_options.mesh_obj_by_id["#"+e.id]=e;e.id="#"+e.id;e.show=n;e.hide=_;if(/^\#mikuPmx(\d+)$/.test(e.id)){e._obj=THREE.MMD.getModels()[parseInt(RegExp.$1)].mesh;Object.defineProperty(e,"visible",{get:function(){return this._obj.visible},set:function(e){this._obj.visible=e}});if(e.scale==null)e.scale=1;e.visible=true}else{if(!e._obj)e._obj=MMD_SA.THREEX.mesh_obj.get_three(e.id);var o=e._obj.children.length?e._obj.children[0]:e._obj;if(e.castShadow){o.castShadow=true}if(e.receiveShadow){o.receiveShadow=true}if(e.scale==null)e.scale=e._obj.scale.x==0?0:1;e.visible=e.hidden_on_start?false:e._obj.scale.x>0}});MMD_SA_options.mesh_obj_all=MMD_SA_options.x_object.concat(MMD_SA_options.mesh_obj)}}(),init:function(){var n=jThree;this.x_object_init();var e=this;var t=THREE.MMD.getModels()[0];var o=[];t.pmx.materials.forEach(function(e){o.push(e.name)});MMD_SA._material_list=o;var _=[{path:MMD_SA_options.model_path_default}];for(var i in MMD_SA_options.MME_saved){var a=MMD_SA_options.MME_saved[i];if(a.path_full)_.push({path:toLocalPath(a.path_full)})}_.forEach(function(e){var t=e.path;if(!/^(\w+\:|\/)/.test(t))t=System.Gadget.path+toLocalPath("\\"+t);e.in_use=t==MMD_SA_options.model_path||MMD_SA_options.model_path_extra.indexOf(t)!=-1});MMD_SA._model_list=_;THREE.MMD.getModels().forEach(function(e){e.skin_MMD_SA_extra=[MMD_SA.Animation_dummy];e.morph_MMD_SA_extra=[MMD_SA.Animation_dummy]});MMD_SA.MMD={MotionManager:function(){this._model_index=0},setFrameNumber:function(){},play:function(){jThree.MMD.play()},pause:function(){jThree.MMD.pause()}};Object.defineProperty(MMD_SA.MMD.MotionManager.prototype,"lastFrame",{get:function(){var e=THREE.MMD.getModels()[this._model_index]._MMD_SA_cache[this.para_SA._path];return e.skin.duration*30}});Object.defineProperty(MMD_SA.MMD.MotionManager.prototype,"_timeMax",{get:function(){var e=THREE.MMD.getModels()[this._model_index]._MMD_SA_cache[this.para_SA._path];return e.skin._timeMax}});Object.defineProperty(MMD_SA.MMD.MotionManager.prototype,"lastFrame_",{get:function(){if(this._lastFrame_!=null)return this._lastFrame_;var e=MMD_SA.MMD.motionManager;return e.para_SA.multi_model_motion_list&&e.para_SA.multi_model_motion_list.indexOf(this.filename)!=-1?e._lastFrame_:this.lastFrame},set:function(e){this._lastFrame_=e}});Object.defineProperty(MMD_SA.MMD.MotionManager.prototype,"firstFrame_",{get:function(){if(this._firstFrame_!=null)return this._firstFrame_;var e=MMD_SA.MMD.motionManager;return e.para_SA.multi_model_motion_list&&e.para_SA.multi_model_motion_list.indexOf(this.filename)!=-1?e._firstFrame_:0},set:function(e){this._firstFrame_=e}});MMD_SA.motion=[];var M=MMD_SA_options.motion_shuffle_list_default&&MMD_SA_options.motion_shuffle_list_default[0]||0;window.dispatchEvent(new CustomEvent("SA_MMD_before_motion_init"));for(var l=0,r=MMD_SA_options.motion.length;l0&&!a.is_PC_candidate&&(o||!a.mirror_motion_from_first_model)){r=true}if(a.motion_name_default==m){r=false}if(r){if(t==MMD_SA_options.model_para_obj_all.length-1&&(!MMD_SA.motion.length||MMD_SA.motion[MMD_SA.motion.length-1].filename!=m))MMD_SA.motion.push({});return}n=e.setupMotion_MMD_SA(u,p.match,o);d=MMD_SA_options.motion_para[m]||d;_=n.skin;i=n.morph;if(o){_._is_MMD_SA_custom_animation=i._is_MMD_SA_custom_animation=MMD_SA.custom_action_index&&l>=MMD_SA.custom_action_index&&l0&&!a.mirror_motion_from_first_model)a.motion_name_default=m}e._MMD_SA_cache_current=n;e.skin=_;e.morph=i;THREE.MMD.adjustMotionDuration()}})}MMD_SA.motion_max_default=MMD_SA_options.motion.length;MMD_SA.MMD.motionManager=MMD_SA.motion[0];if(MMD_SA_options.use_speech_bubble){MMD_SA.SpeechBubble.onload()}MMD_SA._tray_updatable=true;System._browser.update_tray();setTimeout(function(){MMD_SA.MMD_started=true;resize();n.MMD.cameraMotion=true;MMD_SA._head_pos=new THREE.Vector3(0,15,0);MMD_SA_options.model_para_obj.onMotionChange&&MMD_SA_options.model_para_obj.onMotionChange();var o=(()=>{const T={};const j={minCutOff:1,beta:1,dCutOff:1};return function(){var g=this;var v=this.mesh;var e=MMD_SA_options.Dungeon&&MMD_SA_options.Dungeon.accessory_list||MMD_SA_options.mesh_obj_all;e.forEach(function(t){var o=t.parent_bone;if(!o)return;var e=o.model_index||0;if(g._model_index!=e)return;const i=t._obj;if(MMD_SA_options.Dungeon){if(!v.visible||o.disabled){if(!v.visible||!t.placement?.position||o.attached&&!o._detached_){t._obj_proxy.hidden=true;t._obj_proxy.visible=false}else{if(o.attached){o.attached=false;i.matrixAutoUpdate=true;t._obj_proxy.hidden=false;t._obj_proxy.visible=true;i.position.copy(o._detached_.pos);i.quaternion.copy(o._detached_.rot)}else{if(!o._detached_)o._detached_={pos:new THREE.Vector3,rot:new THREE.Quaternion};o._detached_.pos.copy(i.position);o._detached_.rot.copy(i.quaternion)}}return}t._obj_proxy.hidden=false;t._obj_proxy.visible=true}if(o.condition&&!o.condition(t,e))return;var n=MMD_SA.motion[g.skin._motion_index].para_SA;var _;_=n.adjustment_per_model&&(n.adjustment_per_model[MMD_SA_options.model_para_obj._filename]||n.adjustment_per_model[MMD_SA_options.model_para_obj._filename_cleaned]);_=_&&_.accessory_default&&_.accessory_default[t.path.replace(/^.+[\/\\]/,"")];if(_)o=_.parent_bone;var a=o.name=="ROOT";var r;if(!a){r=v.bones_by_name[o.name];if(!r)return}t.parent_bone.attached=true;var s,M;var l,p;p=MMD_SA.THREEX.get_model(e);if(a){l=MMD_SA.THREEX._THREE.MMD.getModels()[e].mesh;M=MMD_SA._q2.copy(l.bones_by_name["全ての親"].quaternion)}if(MMD_SA.THREEX.enabled){if(a){const d=p.getBoneNode("hips");s=MMD_SA.THREEX.v1.copy(d.position);if(!o.hips_as_root){s.y=0}s=p.process_position(s).multiplyScalar(MMD_SA.THREEX.VRM.vrm_scale)}else{const u=p.get_bone_by_MMD_name(o.name);if(!u)return;s=MMD_SA.THREEX.v1;M=MMD_SA.THREEX.q1;u.matrixWorld.decompose(MMD_SA.THREEX.v1,MMD_SA.THREEX.q1,MMD_SA.THREEX.v2);const c=MMD_SA.THREEX.q2.copy(p.mesh.quaternion).conjugate();s.sub(p.mesh.position).applyQuaternion(c);M.premultiply(c);if(p.type=="VRM"&&!p.is_VRM1){M.premultiply(MMD_SA.THREEX.q2.set(0,1,0,0));M.x*=-1;M.z*=-1}}}else{i.useQuaternion=true;if(a){r=v.bones_by_name["センター"]}bone_objs=r.skinMatrix.decompose();s=bone_objs[0];if(a){if(o.hips_as_root){s.y=MMD_SA.TEMP_v3.setFromMatrixPosition(v.bones_by_name["下半身"].skinMatrix).y}else{s.y=0}}if(!M)M=bone_objs[1]}i.position.copy(s);if(o.position){const f=MMD_SA.TEMP_v3.set(o.position.x,o.position.y,-o.position.z);i.position.add(f.applyQuaternion(M))}i.quaternion.copy(M);if(o.rotation){let e;if(o.rotation.fixed){i.quaternion.set(0,0,0,1);e=MMD_SA._q1.setFromEuler(MMD_SA.TEMP_v3.set(-o.rotation.fixed.x,-o.rotation.fixed.y,o.rotation.fixed.z).multiplyScalar(Math.PI/180),"YXZ")}else{e=MMD_SA._q1.setFromEuler(MMD_SA.TEMP_v3.set(-o.rotation.x,-o.rotation.y,o.rotation.z).multiplyScalar(Math.PI/180),"YXZ")}i.quaternion.multiply(e)}var m=MMD_SA.TEMP_m4.makeFromPositionQuaternionScale(i.position,i.quaternion,i.scale).multiplyMatrices(v.matrixWorld,MMD_SA.TEMP_m4).decompose();i.position.copy(m[0]);i.quaternion.copy(m[1]);if(o.rotation){const h=o.rotation.align_with_external_point;if(h&&(!h.mocap_only||System._browser.camera.poseNet.enabled&&System._browser.camera.ML_warmed_up)){if(h.reset_rotation)i.quaternion.set(0,0,0,1);const S=MMD_SA._v3b_.set(0,0,0);let n=MMD_SA._v3a_;if(h.reference_origin){const A=MMD_SA._v3a.copy(h.reference_origin);const b=MMD_SA._v3b.copy(h.reference_point);b.sub(A);const E=(0-(A.x*b.x+A.y*b.y+A.z*b.z))/b.lengthSq();S.set(A.x+b.x*E,A.y+b.y*E,A.z+b.z*E);n.copy(S).multiplyScalar(t.placement.scale).applyQuaternion(i.quaternion).add(i.position)}else{n.copy(i.position)}let _;if(h.external_point.type=="bone"){let e;let t;let o;if(h.external_point.name.indexOf("hand")!=-1){e=h.external_point.name.indexOf("left")!=-1?"左":"右";if(System._browser.camera.poseNet.enabled&&(!MMD_SA.MMD.motionManager.para_SA.motion_tracking_upper_body_only||!System._browser.camera.poseNet.frames.get_blend_default_motion("skin",e+"腕IK"))){t=p.get_bone_position_by_MMD_name(e+"手首");o=MMD_SA.TEMP_v3.set(0,0,0);if(h.external_point.offset)o.add(h.external_point.offset);o.applyQuaternion(MMD_SA_options.model_para_obj.rot_arm_adjust[e+"腕"].axis_rot).applyQuaternion(p.get_bone_rotation_by_MMD_name(e+"手首"))}}else if(h.external_point.name.indexOf("arm")!=-1){e=h.external_point.name.indexOf("left")!=-1?"左":"右";t=p.get_bone_position_by_MMD_name(e+"腕");o=MMD_SA.TEMP_v3.set(0,0,0);if(h.external_point.offset)o.add(h.external_point.offset);o.applyQuaternion(p.get_bone_rotation_by_MMD_name(!h.external_point.offset?.ignore_local_rotation?e+"腕":"上半身2"))}else if(h.external_point.name=="head"){t=p.get_bone_position_by_MMD_name("頭");o=MMD_SA.TEMP_v3.set(0,0,0);if(h.external_point.offset)o.add(h.external_point.offset);o.applyQuaternion(p.get_bone_rotation_by_MMD_name("頭"))}if(t){if(o)t.add(o);_=t.sub(n)}}else if(h.external_point.type=="object3D"){const y=MMD_SA.THREEX._XR_Animator_scene_.object3D_list.find(e=>e.id==h.external_point.name);if(y){const t=MMD_SA.THREEX._object3d_list_.find(e=>e.uuid==y._object3d_uuid);_=MMD_SA._v3b.copy(h.external_point.reference_point).multiplyScalar(t.placement.scale).applyQuaternion(t._mesh.quaternion).add(t._mesh.position).sub(n)}}if(_){let e=MMD_SA._v3a.copy(h.reference_point).sub(S);e.normalize().applyQuaternion(i.quaternion);e.multiplyScalar(_.length()).add(n).sub(i.position);_=_.add(n).sub(i.position);e.normalize();_.normalize();const x=MMD_SA.TEMP_q.setFromUnitVectors(e,_);i.quaternion.premultiply(x)}}const D=o.rotation.data_filter;if(D){if(!t.uuid)t.uuid=THREE.Math.generateUUID();let e=T[t.uuid];if(!e)e=T[t.uuid]=new System._browser.data_filter([{type:"one_euro",id:"propr_rot",para:[30,1,1,1,4]}]);Object.assign(e.filters[0].filter,j,D);i.quaternion.fromArray(e.filter(i.quaternion.toArray()))}}if(i.updateMatrix){i.matrixAutoUpdate=false;i.updateMatrix()}})}})();THREE.MMD.getModels().forEach(function(e,t){e.simulateCallback=o});var e=MMD_SA_options.MME.PostProcessingEffects;MMD_SA_options._PPE_enabled=e.enabled;if(MMD_SA_options.PPE_disabled_on_idle){if(MMD_SA_options._PPE_enabled){e.enabled=false}}MMD_SA.fadeout_opacity=.95;MMD_SA.fadeout_canvas.width=SL.width;MMD_SA.fadeout_canvas.height=SL.height;var t=MMD_SA.fadeout_canvas.getContext("2d");t.globalCompositeOperation="copy";t.globalAlpha=.01;t.fillRect(0,0,SL.width,SL.height);t.globalAlpha=1;MMD_SA_options.model_para_obj_all.forEach(function(e,t){var o=THREE.MMD.getModels()[t].mesh;if(e.position_loading||e.bone_connection||o.bones_by_name["全ての親"])o.position.set(0,0,0);if(e.scale)o.scale.set(e.scale,e.scale,e.scale)});THREE.MMD.getModels().forEach(function(){function o(e){this.mesh=e;this.m4=new THREE.Matrix4;this.pos=new THREE.Vector3;this.pos_world=new THREE.Vector3;this.reset()}o.prototype.reset=function(){this.pos.set(0,0,0);this.pos_world.set(0,0,0)};o.prototype.update=function(){this.m4.copy(this.mesh.matrixWorld);e.getPositionFromMatrix(this.m4);t.copy(e).sub(this.pos_world);t.multiplyScalar(MMD_SA_options.matrixWorld_physics_scale);this.pos.add(t);this.pos_world.copy(e);t.y+=this.mesh._model_index*25;this.m4.setPosition(t)};var e=new THREE.Vector3;var t=new THREE.Vector3;return function(e){let t=e.mesh;t.matrixWorld_physics=new o(t)}}());MMD_SA_options.onstart&&MMD_SA_options.onstart();window.dispatchEvent(new CustomEvent("MMDStarted"));MMD_SA.toggle_shadowMap();n.MMD.play(true);DEBUG_show("(MMD started)",2);if(MMD_SA.use_webgl2)DEBUG_show("Use WebGL2",2);if(MMD_SA.use_MSAA_FBO)DEBUG_show("Use MSAA FBO",2)},0);if(jThree.Trackball)jThree.trackball=jThree.Trackball;n.trackball();if(!returnBoolean("MMDTrackballCamera"))MMD_SA._trackball_camera.stop();MMD_SA_options.edgeScale=MMD_SA_options.model_para_obj.edgeScale>=0?MMD_SA_options.model_para_obj.edgeScale:MMD_SA_options.edgeScale>=0?MMD_SA_options.edgeScale:1;n.MMD.edgeScale=parseFloat(System.Gadget.Settings.readString("MMDEdgeScale")||Settings_default.MMDEdgeScale)*MMD_SA_options.edgeScale;jQuery("canvas").on("mousedown mousewheel DOMMouseScroll",function(){n.MMD.cameraMotion=false}).dblclick(function(){n.MMD.cameraMotion=true})}};(function(){MMD_SA.TEMP_q=new THREE.Quaternion;MMD_SA._q1=new THREE.Quaternion;MMD_SA._q2=new THREE.Quaternion;MMD_SA.TEMP_v3=new THREE.Vector3;MMD_SA._v3a=new THREE.Vector3;MMD_SA._v3b=new THREE.Vector3;MMD_SA.TEMP_m4=new THREE.Matrix4;MMD_SA._m4a=new THREE.Matrix4;MMD_SA._m4b=new THREE.Matrix4;MMD_SA.TEMP_b3=new THREE.Box3;MMD_SA._v3a_=new THREE.Vector3;MMD_SA._v3b_=new THREE.Vector3;MMD_SA.process_bone=function(e,t,o){const n=MMD_SA.MMD.motionManager.para_SA.look_at_screen_euler_order||"XYZ";const _=MMD_SA._v3a_.setEulerFromQuaternion(e.quaternion,n);if(o){_.x*=o[0];_.y*=o[1];_.z*=o[2]}if(t instanceof THREE.Quaternion)t=MMD_SA._v3b_.setEulerFromQuaternion(t,n);_.add(t);e.quaternion.setFromEuler(_,n)};MMD_SA.copy_first_bone_frame=function(e,t,o){if(!o)o=MMD_SA_options.motion[e].match;var _=o&&o.skin_jThree?o.skin_jThree:null;if(!t._is_skin)t=THREE.MMD.getModels()[0].skin_MMD_SA_extra[t._motion_index_extra];var i=t.mesh;t.targets.forEach(function(e){var t=e.keys[0];if(!t||_&&!_.test(t.name)||t.time){return}var o=i.bones_by_name[t.name];var n=i.geometry.bones[o._index];t.pos[0]=o.position.x-n.pos[0];t.pos[1]=o.position.y-n.pos[1];t.pos[2]=o.position.z-n.pos[2];t.rot=o.quaternion.toArray()})};MMD_SA.reset_skin=function(M){THREE.MMD.getModels().forEach(function(e,t){if(M!=null&&t!=M)return;var o=e.skin;if(!o||o._is_dummy){return}var n=o.mesh;var _=n.geometry;for(var i=0,a=n.bones.length;i0){if(n)return null;a=1}else if(i<0){a=-1;i=-i}else{return null}l.subVectors(this.origin,e);var r=a*this.direction.dot(m.crossVectors(l,m));if(r<0){return null}var s=a*this.direction.dot(p.cross(l));if(s<0){return null}if(r+s>i){return null}var M=-a*l.dot(d);if(M<0){return null}return this.at(M/i,_)}}();MMD_SA.bone_to_position=function(){var m=new THREE.Vector3;var d=new THREE.Vector3;var u=new THREE.Vector3;var c=new THREE.Vector3;function e(){this.by_bone_name=[];this.pos_delta=new THREE.Vector3;this.pos_delta_rotated=new THREE.Vector3;this.bone_pos_offset=new THREE.Vector3}e.prototype.init=function(e,t,o,n){var _=this.by_bone_name[t];if(!_){_=this.by_bone_name[t]={gbone:{position:(new THREE.Vector3).fromArray(e.geometry.bones[e.bones_by_name[t]._index].pos)},position:new THREE.Vector3,quaternion:new THREE.Quaternion,path:"",motion_time:0}}if(_.path!=o||_.motion_time>n){_.position.set(0,0,0);_.quaternion.set(0,0,0,1);_.path=o}_.motion_time=n;this.gbone=_.gbone;this.position=_.position;this.quaternion=_.quaternion};return function(s){var M=this;if(!M.skin)return null;var l=this.mesh;if(l._bone_to_position_last){l._bone_to_position_last.pos_delta.set(0,0,0);l._bone_to_position_last.pos_delta_rotated.set(0,0,0);l._bone_to_position_last.bone_pos_offset.set(0,0,0)}else l._bone_to_position_last=new e;if(!s.bone_to_position)return null;var p=s.adjustment_per_model&&(s.adjustment_per_model[MMD_SA_options.model_para_obj_all[this._model_index]._filename_cleaned]||s.adjustment_per_model._default_)||{};s.bone_to_position.forEach(function(e){var t=e.name;var o=e.scale||{x:1,y:1,z:1};var n=l.bones_by_name[t];var _=M.skin.time;var i=_*30;l._bone_to_position_last.init(l,t,s._path,_);if(!e.frame_range||e.frame_range.some(function(e){return i>=e[0]&&i<=e[1]})){m.copy(n.position).sub(l._bone_to_position_last.gbone.position).multiply(o)}else{m.set(0,0,0)}u.copy(m);var a;var r;if(p.skin_default){let e=p.skin_default[t]||{};a=e.rot_add||e.rot;if(!a&&!s.bone_to_position.some(function(e){return e.name=="全ての親"})){e=p.skin_default["全ての親"]||{};a=e.rot_add||e.rot;r=!!a}if(a){u.applyEuler(c.copy(a).multiplyScalar(Math.PI/180))}}if(!e.position_disabled){d.copy(u).sub(l._bone_to_position_last.position);l._bone_to_position_last.position.copy(u)}else{d.set(0,0,0);u.set(0,0,0)}if(t=="全ての親"){n.position.sub(m);l._bone_to_position_last.bone_pos_offset.add(m)}else{let e=r?m.applyEuler(c.copy(a).multiplyScalar(Math.PI/180)):m;l.bones_by_name["全ての親"].position.sub(e);l._bone_to_position_last.bone_pos_offset.add(e)}l._bone_to_position_last.pos_delta.add(d)});l._bone_to_position_last.pos_delta_rotated.copy(l._bone_to_position_last.pos_delta).applyQuaternion(l.quaternion);return l._bone_to_position_last.pos_delta}}();if(MMD_SA.use_jThree_v1)jThree.goml("index.goml");var e={extractPathBase:function(e){var t=e.split("/");t.pop();return t.length===0?"":t.join("/")+"/"},extractPathExt:function(e){var t=e.split(".").pop();if(t===e){return""}return t}}})(); class LowPassFilter{constructor(t,i){this.setAlpha(t);this.y=null;this.s=null;this.type=i;LowPassFilter.#init()}static#q1;static#q2;static#initialized=false;static#init(){if(LowPassFilter.#initialized)return;LowPassFilter.#initialized=true;if(self.THREE){LowPassFilter.#q1=new THREE.Quaternion;LowPassFilter.#q2=new THREE.Quaternion}}setAlpha(t){if(t<=0||t>1){throw new Error}this.alpha=t}filter(t,i,e){if(e){this.setAlpha(e)}let s;if(!this.y){s=t}else{if(Array.isArray(t)){if(this.type==4){s=LowPassFilter.#q1.fromArray(this.s).slerp(LowPassFilter.#q2.fromArray(t),this.alpha).toArray()}else s=t.map((t,i)=>this.alpha*t+(1-this.alpha)*this.s[i])}else{s=this.alpha*t+(1-this.alpha)*this.s}}this.y=t;this.s=s;return s}lastValue(){return this.y}}class OneEuroFilter{constructor(t=30,i=1,e=0,s=1,r=0){if(t<=0||i<=0||s<=0){throw new Error}this.freq=t;this.minCutOff=i;this.beta=e;this.dCutOff=s;this.x=new LowPassFilter(this.alpha(this.minCutOff),r);this.dx=new LowPassFilter(this.alpha(this.dCutOff),r);this.lasttime=null;this.type=r;OneEuroFilter.#init()}static#q1_dx;static#q2_dx;static#initialized=false;static#init(){if(OneEuroFilter.#initialized)return;OneEuroFilter.#initialized=true;if(self.THREE){OneEuroFilter.#q1_dx=new THREE.Quaternion;OneEuroFilter.#q2_dx=new THREE.Quaternion}}computeDerivative(t){const e=this.x.lastValue();let i;if(!e){switch(this.type){case 3:i=[0,0,0];break;case 4:i=[0,0,0,1];break;default:i=0}}else{if(this.type==3){const s=1/this.freq;i=t.map((t,i)=>(t-e[i])/s)}else if(this.type==4){const s=1/this.freq;const r=1/s;OneEuroFilter.#q1_dx.fromArray(e).conjugate();i=OneEuroFilter.#q2_dx.fromArray(t).multiply(OneEuroFilter.#q1_dx);i=OneEuroFilter.#q1_dx.set(0,0,0,1).slerp(i,r).toArray()}else{i=(t-e)*this.freq}}return i}computeDerivativeMagnitude(t){let e;if(this.type==3){let i=0;t.forEach(t=>{i+=t*t});e=Math.sqrt(i)}else if(this.type==4){e=2*Math.acos(t[3])}else{e=Math.abs(t)}return e}alpha(t){const i=1/this.freq;const e=1/(2*Math.PI*t);return 1/(1+e/i)}filter(t,i=null){if(this.lasttime&&i){this.freq=1/Math.max((i-this.lasttime)/1e3,1/60)}this.lasttime=i;const e=this.computeDerivative(t);const s=this.computeDerivativeMagnitude(this.dx.filter(e,i,this.alpha(this.dCutOff)));const r=this.minCutOff+this.beta*s;return this.x.filter(t,i,this.alpha(r))}}