8 lines
24 KiB
JavaScript
8 lines
24 KiB
JavaScript
/**
|
|
* skinview3d (https://github.com/bs-community/skinview3d)
|
|
*
|
|
* MIT License
|
|
*/
|
|
|
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("three")):"function"==typeof define&&define.amd?define(["exports","three"],t):t(e.skinview3d={},e.THREE)}(this,function(e,U){"use strict";var a=function(e,t){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function t(e,t){function n(){this.constructor=e}a(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function i(e,t,n,a,i,o){return[new U.Vector2(e/i,1-a/o),new U.Vector2(n/i,1-a/o),new U.Vector2(n/i,1-t/o),new U.Vector2(e/i,1-t/o)]}function V(e,t,n,a){return i(e,t,n,a,64,64)}function o(e,t,n,a){return i(e,t,n,a,64,32)}function A(e,t,n,a,i,o,s){e.faceVertexUvs[0]=[],e.faceVertexUvs[0][0]=[o[3],o[0],o[2]],e.faceVertexUvs[0][1]=[o[0],o[1],o[2]],e.faceVertexUvs[0][2]=[a[3],a[0],a[2]],e.faceVertexUvs[0][3]=[a[0],a[1],a[2]],e.faceVertexUvs[0][4]=[t[3],t[0],t[2]],e.faceVertexUvs[0][5]=[t[0],t[1],t[2]],e.faceVertexUvs[0][6]=[n[0],n[3],n[1]],e.faceVertexUvs[0][7]=[n[3],n[2],n[1]],e.faceVertexUvs[0][8]=[i[3],i[0],i[2]],e.faceVertexUvs[0][9]=[i[0],i[1],i[2]],e.faceVertexUvs[0][10]=[s[3],s[0],s[2]],e.faceVertexUvs[0][11]=[s[0],s[1],s[2]]}var C=.002,z=function(a){function e(e,t){var n=a.call(this)||this;return n.innerLayer=e,n.outerLayer=t,n}return t(e,a),e}(U.Group),s=function(D){function e(e,t){var n=D.call(this)||this;n.modelListeners=[],n._slim=!1;var a=new U.BoxGeometry(8,8,8,0,0,0);A(a,V(8,0,16,8),V(16,0,24,8),V(0,8,8,16),V(8,8,16,16),V(16,8,24,16),V(24,8,32,16));var i=new U.Mesh(a,e),o=new U.BoxGeometry(9,9,9,0,0,0);A(o,V(40,0,48,8),V(48,0,56,8),V(32,8,40,16),V(40,8,48,16),V(48,8,56,16),V(56,8,64,16));var s=new U.Mesh(o,t);s.renderOrder=-1,n.head=new z(i,s),n.head.add(i,s),n.add(n.head);var r=new U.BoxGeometry(8,12,4,0,0,0);A(r,V(20,16,28,20),V(28,16,36,20),V(16,20,20,32),V(20,20,28,32),V(28,20,32,32),V(32,20,40,32));var h=new U.Mesh(r,e),c=new U.BoxGeometry(9,13.5,4.5,0,0,0);A(c,V(20,32,28,36),V(28,32,36,36),V(16,36,20,48),V(20,36,28,48),V(28,36,32,48),V(32,36,40,48));var d=new U.Mesh(c,t);n.body=new z(h,d),n.body.add(h,d),n.body.position.y=-10,n.add(n.body);var l=new U.BoxGeometry(1,1,1,0,0,0),p=new U.Mesh(l,e);n.modelListeners.push(function(){p.scale.x=(n.slim?3:4)-C,p.scale.y=12-C,p.scale.z=4-C,n.slim?A(l,V(44,16,47,20),V(47,16,50,20),V(40,20,44,32),V(44,20,47,32),V(47,20,51,32),V(51,20,54,32)):A(l,V(44,16,48,20),V(48,16,52,20),V(40,20,44,32),V(44,20,48,32),V(48,20,52,32),V(52,20,56,32)),l.uvsNeedUpdate=!0,l.elementsNeedUpdate=!0});var u=new U.BoxGeometry(1,1,1,0,0,0),m=new U.Mesh(u,t);m.renderOrder=1,n.modelListeners.push(function(){m.scale.x=(n.slim?3.375:4.5)-C,m.scale.y=13.498,m.scale.z=4.498,n.slim?A(u,V(44,32,47,36),V(47,32,50,36),V(40,36,44,48),V(44,36,47,48),V(47,36,51,48),V(51,36,54,48)):A(u,V(44,32,48,36),V(48,32,52,36),V(40,36,44,48),V(44,36,48,48),V(48,36,52,48),V(52,36,56,48)),u.uvsNeedUpdate=!0,u.elementsNeedUpdate=!0});var f=new U.Group;f.add(p,m),f.position.y=-6,n.rightArm=new z(p,m),n.rightArm.add(f),n.rightArm.position.y=-4,n.modelListeners.push(function(){n.rightArm.position.x=n.slim?-5.5:-6}),n.add(n.rightArm);var y=new U.BoxGeometry(1,1,1,0,0,0),g=new U.Mesh(y,e);n.modelListeners.push(function(){g.scale.x=(n.slim?3:4)-C,g.scale.y=12-C,g.scale.z=4-C,n.slim?A(y,V(36,48,39,52),V(39,48,42,52),V(32,52,36,64),V(36,52,39,64),V(39,52,43,64),V(43,52,46,64)):A(y,V(36,48,40,52),V(40,48,44,52),V(32,52,36,64),V(36,52,40,64),V(40,52,44,64),V(44,52,48,64)),y.uvsNeedUpdate=!0,y.elementsNeedUpdate=!0});var v=new U.BoxGeometry(1,1,1,0,0,0),w=new U.Mesh(v,t);w.renderOrder=1,n.modelListeners.push(function(){w.scale.x=(n.slim?3.375:4.5)-C,w.scale.y=13.498,w.scale.z=4.498,n.slim?A(v,V(52,48,55,52),V(55,48,58,52),V(48,52,52,64),V(52,52,55,64),V(55,52,59,64),V(59,52,62,64)):A(v,V(52,48,56,52),V(56,48,60,52),V(48,52,52,64),V(52,52,56,64),V(56,52,60,64),V(60,52,64,64)),v.uvsNeedUpdate=!0,v.elementsNeedUpdate=!0});var b=new U.Group;b.add(g,w),b.position.y=-6,n.leftArm=new z(g,w),n.leftArm.add(b),n.leftArm.position.y=-4,n.modelListeners.push(function(){n.leftArm.position.x=n.slim?5.5:6}),n.add(n.leftArm);var M=new U.BoxGeometry(4-C,12-C,4-C,0,0,0);A(M,V(4,16,8,20),V(8,16,12,20),V(0,20,4,32),V(4,20,8,32),V(8,20,12,32),V(12,20,16,32));var x=new U.Mesh(M,e),E=new U.BoxGeometry(4.498,13.498,4.498,0,0,0);A(E,V(4,32,8,36),V(8,32,12,36),V(0,36,4,48),V(4,36,8,48),V(8,36,12,48),V(12,36,16,48));var L=new U.Mesh(E,t);L.renderOrder=1;var S=new U.Group;S.add(x,L),S.position.y=-6,n.rightLeg=new z(x,L),n.rightLeg.add(S),n.rightLeg.position.y=-16,n.rightLeg.position.x=-2,n.add(n.rightLeg);var P=new U.BoxGeometry(4-C,12-C,4-C,0,0,0);A(P,V(20,48,24,52),V(24,48,28,52),V(16,52,20,64),V(20,52,24,64),V(24,52,28,64),V(28,52,32,64));var O=new U.Mesh(P,e),k=new U.BoxGeometry(4.498,13.498,4.498,0,0,0);A(k,V(4,48,8,52),V(8,48,12,52),V(0,52,4,64),V(4,52,8,64),V(8,52,12,64),V(12,52,16,64));var I=new U.Mesh(k,t);I.renderOrder=1;var j=new U.Group;return j.add(O,I),j.position.y=-6,n.leftLeg=new z(O,I),n.leftLeg.add(j),n.leftLeg.position.y=-16,n.leftLeg.position.x=2,n.add(n.leftLeg),n.slim=!1,n}return t(e,D),Object.defineProperty(e.prototype,"slim",{get:function(){return this._slim},set:function(e){this._slim=e,this.modelListeners.forEach(function(e){return e()})},enumerable:!0,configurable:!0}),e.prototype.getBodyParts=function(){return this.children.filter(function(e){return e instanceof z})},e.prototype.setInnerLayerVisible=function(t){this.getBodyParts().forEach(function(e){return e.innerLayer.visible=t})},e.prototype.setOuterLayerVisible=function(t){this.getBodyParts().forEach(function(e){return e.outerLayer.visible=t})},e}(U.Group),r=function(a){function e(e){var t=a.call(this)||this,n=new U.BoxGeometry(10,16,1,0,0,0);return A(n,o(1,0,11,1),o(11,0,21,1),o(11,1,12,17),o(12,1,22,17),o(0,1,1,17),o(1,1,11,17)),t.cape=new U.Mesh(n,e),t.cape.position.y=-8,t.cape.position.z=-.5,t.add(t.cape),t}return t(e,a),e}(U.Group),h=function(i){function e(e,t,n){var a=i.call(this)||this;return a.skin=new s(e,t),a.skin.visible=!1,a.add(a.skin),a.cape=new r(n),a.cape.position.z=-2,a.cape.position.y=-4,a.cape.rotation.x=25*Math.PI/180,a.cape.visible=!1,a.add(a.cape),a}return t(e,i),e}(U.Group);function c(e,t,n){e instanceof Function?e(t,n):e.play(t,n)}var d=function(){function e(e){this.paused=!1,this.speed=1,this._paused=!1,this._lastChange=null,this._speed=1,this._lastChangeX=null,this.animation=e}return e.prototype.play=function(e,t){if(null===this._lastChange)this._lastChange=t,this._lastChangeX=0;else if(this.paused!==this._paused||this.speed!==this._speed){var n=t-this._lastChange;!1===this._paused&&(this._lastChangeX+=n*this._speed),this._paused=this.paused,this._speed=this.speed,this._lastChange=t}if(!1===this.paused){n=t-this._lastChange;var a=this._lastChangeX+this.speed*n;c(this.animation,e,a)}},e.prototype.reset=function(){this._lastChange=null},e.prototype.remove=function(){},e}(),n=function(){function e(){this.handles=new Set}return e.prototype.add=function(e){var t=this,n=new d(e);return n.remove=function(){return t.handles.delete(n)},this.handles.add(n),n},e.prototype.play=function(t,n){this.handles.forEach(function(e){return e.play(t,n)})},e}();function l(e,t,n,a,i){for(var o=e.getImageData(t,n,a,i),s=0;s<a;s++)for(var r=0;r<i;r++){var h=4*(s+r*a);if(255!==o.data[h+3])return!0}return!1}function p(e){return e/64}function u(r,e){var h=p(e),t=function(e,t,n,a,i,o,s){return function(e,t,n,a,i,o,s,r){var h=e.getImageData(t,n,a,i);if(r)for(var c=0;c<i;c++)for(var d=0;d<a/2;d++){var l=4*(d+c*a),p=4*(a-d-1+c*a),u=h.data[l],m=h.data[l+1],f=h.data[l+2],y=h.data[l+3],g=h.data[p],v=h.data[p+1],w=h.data[p+2],b=h.data[p+3];h.data[l]=g,h.data[l+1]=v,h.data[l+2]=w,h.data[l+3]=b,h.data[p]=u,h.data[p+1]=m,h.data[p+2]=f,h.data[p+3]=y}e.putImageData(h,o,s)}(r,e*h,t*h,n*h,a*h,i*h,o*h,s)};!function(i,e){if(!l(i,0,0,e,e/2)){var o=p(e),t=function(e,t,n,a){return i.clearRect(e*o,t*o,n*o,a*o)};t(40,0,8,8),t(48,0,8,8),t(32,8,8,8),t(40,8,8,8),t(48,8,8,8),t(56,8,8,8)}}(r,e),t(4,16,4,4,20,48,!0),t(8,16,4,4,24,48,!0),t(0,20,4,12,24,52,!0),t(4,20,4,12,20,52,!0),t(8,20,4,12,16,52,!0),t(12,20,4,12,28,52,!0),t(44,16,4,4,36,48,!0),t(48,16,4,4,40,48,!0),t(40,20,4,12,40,52,!0),t(44,20,4,12,36,52,!0),t(48,20,4,12,32,52,!0),t(52,20,4,12,44,52,!0)}function m(e,t){var n=!1;if(t.width!==t.height){if(t.width!==2*t.height)throw new Error("Bad skin size: "+t.width+"x"+t.height);n=!0}var a=e.getContext("2d");if(n){var i=t.width;e.width=i,e.height=i,a.clearRect(0,0,i,i),a.drawImage(t,0,0,i,i/2),u(a,i)}else e.width=t.width,e.height=t.height,a.clearRect(0,0,t.width,t.height),a.drawImage(t,0,0,e.width,e.height)}function f(e){if(e instanceof HTMLCanvasElement){var i=p((n=e).width),o=n.getContext("2d"),t=function(e,t,n,a){return l(o,e*i,t*i,n*i,a*i)};return t(50,16,2,4)||t(54,20,2,12)||t(42,48,2,4)||t(46,52,2,12)}var n,a=e;return m(n=document.createElement("canvas"),a),f(n)}var y=function(){function e(e){var t=this;this.detectModel=!0,this.animationPaused=!1,this.animationTime=0,this.disposed=!1,this.domElement=e.domElement,this.animation=e.animation||null,!1===e.detectModel&&(this.detectModel=!1),this.skinImg=new Image,this.skinCanvas=document.createElement("canvas"),this.skinTexture=new U.Texture(this.skinCanvas),this.skinTexture.magFilter=U.NearestFilter,this.skinTexture.minFilter=U.NearestFilter,this.capeImg=new Image,this.capeCanvas=document.createElement("canvas"),this.capeTexture=new U.Texture(this.capeCanvas),this.capeTexture.magFilter=U.NearestFilter,this.capeTexture.minFilter=U.NearestFilter,this.layer1Material=new U.MeshBasicMaterial({map:this.skinTexture,side:U.FrontSide}),this.layer2Material=new U.MeshBasicMaterial({map:this.skinTexture,transparent:!0,opacity:1,side:U.DoubleSide,alphaTest:.5}),this.capeMaterial=new U.MeshBasicMaterial({map:this.capeTexture,transparent:!0,opacity:1,side:U.DoubleSide,alphaTest:.5}),this.scene=new U.Scene,this.camera=new U.PerspectiveCamera(40),this.camera.position.y=-12,this.camera.position.z=60,this.renderer=new U.WebGLRenderer({alpha:!0,antialias:!1}),this.renderer.setSize(300,300),this.renderer.context.getShaderInfoLog=function(){return""},this.domElement.appendChild(this.renderer.domElement),this.playerObject=new h(this.layer1Material,this.layer2Material,this.capeMaterial),this.scene.add(this.playerObject),this.skinImg.crossOrigin="anonymous",this.skinImg.onerror=function(){return console.error("Failed loading "+t.skinImg.src)},this.skinImg.onload=function(){m(t.skinCanvas,t.skinImg),t.detectModel&&(t.playerObject.skin.slim=f(t.skinCanvas)),t.skinTexture.needsUpdate=!0,t.layer1Material.needsUpdate=!0,t.layer2Material.needsUpdate=!0,t.playerObject.skin.visible=!0},this.capeImg.crossOrigin="anonymous",this.capeImg.onerror=function(){return console.error("Failed loading "+t.capeImg.src)},this.capeImg.onload=function(){!function(e,t){var n=!1;if(t.width!==2*t.height){if(17*t.width!=22*t.height)throw new Error("Bad cape size: "+t.width+"x"+t.height);n=!0}var a=e.getContext("2d");if(n){var i=64*t.width/22;e.width=i,e.height=i/2}else e.width=t.width,e.height=t.height;a.clearRect(0,0,e.width,e.height),a.drawImage(t,0,0,t.width,t.height)}(t.capeCanvas,t.capeImg),t.capeTexture.needsUpdate=!0,t.capeMaterial.needsUpdate=!0,t.playerObject.cape.visible=!0},e.skinUrl&&(this.skinUrl=e.skinUrl),e.capeUrl&&(this.capeUrl=e.capeUrl),e.width&&(this.width=e.width),e.height&&(this.height=e.height);var n=function(){t.disposed||(window.requestAnimationFrame(n),t.animationPaused||(t.animationTime++,t.animation&&c(t.animation,t.playerObject,t.animationTime/100)),t.renderer.render(t.scene,t.camera))};n()}return e.prototype.setSize=function(e,t){this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.renderer.setSize(e,t)},e.prototype.dispose=function(){this.disposed=!0,this.domElement.removeChild(this.renderer.domElement),this.renderer.dispose(),this.skinTexture.dispose(),this.capeTexture.dispose()},Object.defineProperty(e.prototype,"skinUrl",{get:function(){return this.skinImg.src},set:function(e){this.skinImg.src=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"capeUrl",{get:function(){return this.capeImg.src},set:function(e){this.capeImg.src=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this.renderer.getSize().width},set:function(e){this.setSize(e,this.height)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.renderer.getSize().height},set:function(e){this.setSize(this.width,e)},enumerable:!0,configurable:!0}),e}(),g=-1,v=0,w=1,b=2,M=3,x=4,E=5,L={type:"change"},S={type:"start"},P={type:"end"},O=function(a){function e(e,t,n){var o=a.call(this)||this;return o.object=e,o.domElement=void 0!==t?t:document,o.window=void 0!==n?n:window,o.enabled=!0,o.target=new U.Vector3,o.minDistance=0,o.maxDistance=1/0,o.minZoom=0,o.maxZoom=1/0,o.minPolarAngle=0,o.maxPolarAngle=Math.PI,o.minAzimuthAngle=-1/0,o.maxAzimuthAngle=1/0,o.enableDamping=!1,o.dampingFactor=.25,o.enableZoom=!0,o.zoomSpeed=1,o.enableRotate=!0,o.rotateSpeed=1,o.enablePan=!0,o.keyPanSpeed=7,o.autoRotate=!1,o.autoRotateSpeed=2,o.enableKeys=!0,o.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40},o.mouseButtons={ORBIT:U.MOUSE.LEFT,ZOOM:U.MOUSE.MIDDLE,PAN:U.MOUSE.RIGHT},o.target0=o.target.clone(),o.position0=o.object.position.clone(),o.zoom0=o.object.zoom,o.updateOffset=new U.Vector3,o.updateQuat=(new U.Quaternion).setFromUnitVectors(e.up,new U.Vector3(0,1,0)),o.updateQuatInverse=o.updateQuat.clone().inverse(),o.updateLastPosition=new U.Vector3,o.updateLastQuaternion=new U.Quaternion,o.state=g,o.scale=1,o.spherical=new U.Spherical,o.sphericalDelta=new U.Spherical,o.panOffset=new U.Vector3,o.zoomChanged=!1,o.rotateStart=new U.Vector2,o.rotateEnd=new U.Vector2,o.rotateDelta=new U.Vector2,o.panStart=new U.Vector2,o.panEnd=new U.Vector2,o.panDelta=new U.Vector2,o.dollyStart=new U.Vector2,o.dollyEnd=new U.Vector2,o.dollyDelta=new U.Vector2,o.panLeftV=new U.Vector3,o.panUpV=new U.Vector3,o.panInternalOffset=new U.Vector3,o.onMouseDown=function(e){if(!1!==o.enabled){if(e.preventDefault(),e.button===o.mouseButtons.ORBIT){if(!1===o.enableRotate)return;o.rotateStart.set(e.clientX,e.clientY),o.state=v}else if(e.button===o.mouseButtons.ZOOM){if(!1===o.enableZoom)return;o.dollyStart.set(e.clientX,e.clientY),o.state=w}else if(e.button===o.mouseButtons.PAN){if(!1===o.enablePan)return;o.panStart.set(e.clientX,e.clientY),o.state=b}o.state!==g&&(document.addEventListener("mousemove",o.onMouseMove,!1),document.addEventListener("mouseup",o.onMouseUp,!1),o.dispatchEvent(S))}},o.onMouseMove=function(e){if(!1!==o.enabled)if(e.preventDefault(),o.state===v){if(!1===o.enableRotate)return;o.rotateEnd.set(e.clientX,e.clientY),o.rotateDelta.subVectors(o.rotateEnd,o.rotateStart);var t=o.domElement===document?o.domElement.body:o.domElement;o.rotateLeft(2*Math.PI*o.rotateDelta.x/t.clientWidth*o.rotateSpeed),o.rotateUp(2*Math.PI*o.rotateDelta.y/t.clientHeight*o.rotateSpeed),o.rotateStart.copy(o.rotateEnd),o.update()}else if(o.state===w){if(!1===o.enableZoom)return;o.dollyEnd.set(e.clientX,e.clientY),o.dollyDelta.subVectors(o.dollyEnd,o.dollyStart),0<o.dollyDelta.y?o.dollyIn(o.getZoomScale()):o.dollyDelta.y<0&&o.dollyOut(o.getZoomScale()),o.dollyStart.copy(o.dollyEnd),o.update()}else if(o.state===b){if(!1===o.enablePan)return;o.panEnd.set(e.clientX,e.clientY),o.panDelta.subVectors(o.panEnd,o.panStart),o.pan(o.panDelta.x,o.panDelta.y),o.panStart.copy(o.panEnd),o.update()}},o.onMouseUp=function(e){!1!==o.enabled&&(document.removeEventListener("mousemove",o.onMouseMove,!1),document.removeEventListener("mouseup",o.onMouseUp,!1),o.dispatchEvent(P),o.state=g)},o.onMouseWheel=function(e){!1===o.enabled||!1===o.enableZoom||o.state!==g&&o.state!==v||(e.preventDefault(),e.stopPropagation(),e.deltaY<0?o.dollyOut(o.getZoomScale()):0<e.deltaY&&o.dollyIn(o.getZoomScale()),o.update(),o.dispatchEvent(S),o.dispatchEvent(P))},o.onKeyDown=function(e){if(!1!==o.enabled&&!1!==o.enableKeys&&!1!==o.enablePan)switch(e.keyCode){case o.keys.UP:o.pan(0,o.keyPanSpeed),o.update();break;case o.keys.BOTTOM:o.pan(0,-o.keyPanSpeed),o.update();break;case o.keys.LEFT:o.pan(o.keyPanSpeed,0),o.update();break;case o.keys.RIGHT:o.pan(-o.keyPanSpeed,0),o.update()}},o.onTouchStart=function(e){if(!1!==o.enabled){switch(e.touches.length){case 1:if(!1===o.enableRotate)return;o.rotateStart.set(e.touches[0].pageX,e.touches[0].pageY),o.state=M;break;case 2:if(!1===o.enableZoom)return;var t=e.touches[0].pageX-e.touches[1].pageX,n=e.touches[0].pageY-e.touches[1].pageY,a=Math.sqrt(t*t+n*n);o.dollyStart.set(0,a),o.state=x;break;case 3:if(!1===o.enablePan)return;o.panStart.set(e.touches[0].pageX,e.touches[0].pageY),o.state=E;break;default:o.state=g}o.state!==g&&o.dispatchEvent(S)}},o.onTouchMove=function(e){if(!1!==o.enabled)switch(e.preventDefault(),e.stopPropagation(),e.touches.length){case 1:if(!1===o.enableRotate)return;if(o.state!==M)return;o.rotateEnd.set(e.touches[0].pageX,e.touches[0].pageY),o.rotateDelta.subVectors(o.rotateEnd,o.rotateStart);var t=o.domElement===document?o.domElement.body:o.domElement;o.rotateLeft(2*Math.PI*o.rotateDelta.x/t.clientWidth*o.rotateSpeed),o.rotateUp(2*Math.PI*o.rotateDelta.y/t.clientHeight*o.rotateSpeed),o.rotateStart.copy(o.rotateEnd),o.update();break;case 2:if(!1===o.enableZoom)return;if(o.state!==x)return;var n=e.touches[0].pageX-e.touches[1].pageX,a=e.touches[0].pageY-e.touches[1].pageY,i=Math.sqrt(n*n+a*a);o.dollyEnd.set(0,i),o.dollyDelta.subVectors(o.dollyEnd,o.dollyStart),0<o.dollyDelta.y?o.dollyOut(o.getZoomScale()):o.dollyDelta.y<0&&o.dollyIn(o.getZoomScale()),o.dollyStart.copy(o.dollyEnd),o.update();break;case 3:if(!1===o.enablePan)return;if(o.state!==E)return;o.panEnd.set(e.touches[0].pageX,e.touches[0].pageY),o.panDelta.subVectors(o.panEnd,o.panStart),o.pan(o.panDelta.x,o.panDelta.y),o.panStart.copy(o.panEnd),o.update();break;default:o.state=g}},o.onTouchEnd=function(e){!1!==o.enabled&&(o.dispatchEvent(P),o.state=g)},o.onContextMenu=function(e){e.preventDefault()},o.domElement.addEventListener("contextmenu",o.onContextMenu,!1),o.domElement.addEventListener("mousedown",o.onMouseDown,!1),o.domElement.addEventListener("wheel",o.onMouseWheel,!1),o.domElement.addEventListener("touchstart",o.onTouchStart,!1),o.domElement.addEventListener("touchend",o.onTouchEnd,!1),o.domElement.addEventListener("touchmove",o.onTouchMove,!1),o.window.addEventListener("keydown",o.onKeyDown,!1),o.update(),o}return t(e,a),e.prototype.update=function(){var e=this.object.position;return this.updateOffset.copy(e).sub(this.target),this.updateOffset.applyQuaternion(this.updateQuat),this.spherical.setFromVector3(this.updateOffset),this.autoRotate&&this.state===g&&this.rotateLeft(this.getAutoRotationAngle()),this.spherical.theta+=this.sphericalDelta.theta,this.spherical.phi+=this.sphericalDelta.phi,this.spherical.theta=Math.max(this.minAzimuthAngle,Math.min(this.maxAzimuthAngle,this.spherical.theta)),this.spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this.spherical.phi)),this.spherical.makeSafe(),this.spherical.radius*=this.scale,this.spherical.radius=Math.max(this.minDistance,Math.min(this.maxDistance,this.spherical.radius)),this.target.add(this.panOffset),this.updateOffset.setFromSpherical(this.spherical),this.updateOffset.applyQuaternion(this.updateQuatInverse),e.copy(this.target).add(this.updateOffset),this.object.lookAt(this.target),!0===this.enableDamping?(this.sphericalDelta.theta*=1-this.dampingFactor,this.sphericalDelta.phi*=1-this.dampingFactor):this.sphericalDelta.set(0,0,0),this.scale=1,this.panOffset.set(0,0,0),!!(this.zoomChanged||1e-6<this.updateLastPosition.distanceToSquared(this.object.position)||1e-6<8*(1-this.updateLastQuaternion.dot(this.object.quaternion)))&&(this.dispatchEvent(L),this.updateLastPosition.copy(this.object.position),this.updateLastQuaternion.copy(this.object.quaternion),!(this.zoomChanged=!1))},e.prototype.panLeft=function(e,t){this.panLeftV.setFromMatrixColumn(t,0),this.panLeftV.multiplyScalar(-e),this.panOffset.add(this.panLeftV)},e.prototype.panUp=function(e,t){this.panUpV.setFromMatrixColumn(t,1),this.panUpV.multiplyScalar(e),this.panOffset.add(this.panUpV)},e.prototype.pan=function(e,t){var n=this.domElement===document?this.domElement.body:this.domElement;if(this.object instanceof U.PerspectiveCamera){var a=this.object.position;this.panInternalOffset.copy(a).sub(this.target);var i=this.panInternalOffset.length();i*=Math.tan(this.object.fov/2*Math.PI/180),this.panLeft(2*e*i/n.clientHeight,this.object.matrix),this.panUp(2*t*i/n.clientHeight,this.object.matrix)}else this.object instanceof U.OrthographicCamera?(this.panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this.panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)},e.prototype.dollyIn=function(e){this.object instanceof U.PerspectiveCamera?this.scale/=e:this.object instanceof U.OrthographicCamera?(this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom*e)),this.object.updateProjectionMatrix(),this.zoomChanged=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)},e.prototype.dollyOut=function(e){this.object instanceof U.PerspectiveCamera?this.scale*=e:this.object instanceof U.OrthographicCamera?(this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/e)),this.object.updateProjectionMatrix(),this.zoomChanged=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)},e.prototype.getAutoRotationAngle=function(){return 2*Math.PI/60/60*this.autoRotateSpeed},e.prototype.getZoomScale=function(){return Math.pow(.95,this.zoomSpeed)},e.prototype.rotateLeft=function(e){this.sphericalDelta.theta-=e},e.prototype.rotateUp=function(e){this.sphericalDelta.phi-=e},e.prototype.getPolarAngle=function(){return this.spherical.phi},e.prototype.getAzimuthalAngle=function(){return this.spherical.theta},e.prototype.dispose=function(){this.domElement.removeEventListener("contextmenu",this.onContextMenu,!1),this.domElement.removeEventListener("mousedown",this.onMouseDown,!1),this.domElement.removeEventListener("wheel",this.onMouseWheel,!1),this.domElement.removeEventListener("touchstart",this.onTouchStart,!1),this.domElement.removeEventListener("touchend",this.onTouchEnd,!1),this.domElement.removeEventListener("touchmove",this.onTouchMove,!1),document.removeEventListener("mousemove",this.onMouseMove,!1),document.removeEventListener("mouseup",this.onMouseUp,!1),this.window.removeEventListener("keydown",this.onKeyDown,!1)},e.prototype.reset=function(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(L),this.update(),this.state=g},e}(U.EventDispatcher);e.SkinObject=s,e.BodyPart=z,e.CapeObject=r,e.PlayerObject=h,e.SkinViewer=y,e.OrbitControls=O,e.createOrbitControls=function(e){var t=new O(e.camera,e.renderer.domElement);return t.enablePan=!1,t.target=new U.Vector3(0,-12,0),t.minDistance=10,t.maxDistance=256,t.update(),t},e.invokeAnimation=c,e.CompositeAnimation=n,e.WalkingAnimation=function(e,t){var n=e.skin;t*=8,n.leftLeg.rotation.x=.5*Math.sin(t),n.rightLeg.rotation.x=.5*Math.sin(t+Math.PI),n.leftArm.rotation.x=.5*Math.sin(t+Math.PI),n.rightArm.rotation.x=.5*Math.sin(t);var a=.02*Math.PI;n.leftArm.rotation.z=.03*Math.cos(t)+a,n.rightArm.rotation.z=.03*Math.cos(t+Math.PI)-a,n.head.rotation.y=.2*Math.sin(t/4),n.head.rotation.x=.1*Math.sin(t/5);var i=.06*Math.PI;e.cape.rotation.x=.06*Math.sin(t/1.5)+i},e.RunningAnimation=function(e,t){var n=e.skin;t*=15,n.leftLeg.rotation.x=1.3*Math.cos(t+Math.PI),n.rightLeg.rotation.x=1.3*Math.cos(t),n.leftArm.rotation.x=1.5*Math.cos(t),n.rightArm.rotation.x=1.5*Math.cos(t+Math.PI);var a=.1*Math.PI;n.leftArm.rotation.z=.1*Math.cos(t)+a,n.rightArm.rotation.z=.1*Math.cos(t+Math.PI)-a,e.position.y=Math.cos(2*t),e.position.x=.15*Math.cos(t),e.rotation.z=.01*Math.cos(t+Math.PI);var i=.3*Math.PI;e.cape.rotation.x=.1*Math.sin(2*t)+i},e.RotatingAnimation=function(e,t){e.rotation.y=t},e.isSlimSkin=f,Object.defineProperty(e,"__esModule",{value:!0})});
|