!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,t){"use strict";var n=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},a=function(){function e(e,t){for(var n=0;nb||8*(1-h.dot(m.object.quaternion))>b)&&(m.dispatchEvent(l),d.copy(m.object.position),h.copy(m.object.quaternion),x=!1,!0)}),u.dispose=function(){m.domElement.removeEventListener("contextmenu",Q,!1),m.domElement.removeEventListener("mousedown",D,!1),m.domElement.removeEventListener("wheel",H,!1),m.domElement.removeEventListener("touchstart",Z,!1),m.domElement.removeEventListener("touchend",q,!1),m.domElement.removeEventListener("touchmove",W,!1),document.removeEventListener("mousemove",F,!1),document.removeEventListener("mouseup",Y,!1),window.removeEventListener("keydown",X,!1)};var m=u,l={type:"change"},p={type:"start"},f={type:"end"},v={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5},g=v.NONE,b=1e-6,w=new t.Spherical,y=new t.Spherical,k=1,E=new t.Vector3,x=!1,O=new t.Vector2,M=new t.Vector2,C=new t.Vector2,P=new t.Vector2,j=new t.Vector2,T=new t.Vector2,I=new t.Vector2,L=new t.Vector2,A=new t.Vector2;function _(){return Math.pow(.95,m.zoomSpeed)}function V(e){y.theta-=e}function N(e){y.phi-=e}var S,U=(S=new t.Vector3,function(e,t){S.setFromMatrixColumn(t,0),S.multiplyScalar(-e),E.add(S)}),z=function(){var e=new t.Vector3;return function(t,n){e.setFromMatrixColumn(n,1),e.multiplyScalar(t),E.add(e)}}(),G=function(){var e=new t.Vector3;return function(n,a){var i=m.domElement===document?m.domElement.body:m.domElement;if(m.object instanceof t.PerspectiveCamera){var o=m.object.position;e.copy(o).sub(m.target);var r=e.length();r*=Math.tan(m.object.fov/2*Math.PI/180),U(2*n*r/i.clientHeight,m.object.matrix),z(2*a*r/i.clientHeight,m.object.matrix)}else m.object instanceof t.OrthographicCamera?(U(n*(m.object.right-m.object.left)/m.object.zoom/i.clientWidth,m.object.matrix),z(a*(m.object.top-m.object.bottom)/m.object.zoom/i.clientHeight,m.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),m.enablePan=!1)}}();function R(e){m.object instanceof t.PerspectiveCamera?k/=e:m.object instanceof t.OrthographicCamera?(m.object.zoom=Math.max(m.minZoom,Math.min(m.maxZoom,m.object.zoom*e)),m.object.updateProjectionMatrix(),x=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),m.enableZoom=!1)}function B(e){m.object instanceof t.PerspectiveCamera?k*=e:m.object instanceof t.OrthographicCamera?(m.object.zoom=Math.max(m.minZoom,Math.min(m.maxZoom,m.object.zoom/e)),m.object.updateProjectionMatrix(),x=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),m.enableZoom=!1)}function D(e){if(!1!==m.enabled){switch(e.button){case m.mouseButtons.ORBIT:if(!1===m.enableRotate)return;!function(e){O.set(e.clientX,e.clientY)}(e),g=v.ROTATE;break;case m.mouseButtons.ZOOM:if(!1===m.enableZoom)return;!function(e){I.set(e.clientX,e.clientY)}(e),g=v.DOLLY;break;case m.mouseButtons.PAN:if(!1===m.enablePan)return;!function(e){P.set(e.clientX,e.clientY)}(e),g=v.PAN}e.preventDefault(),g!==v.NONE&&(document.addEventListener("mousemove",F,!1),document.addEventListener("mouseup",Y,!1),m.dispatchEvent(p))}}function F(e){if(!1!==m.enabled){switch(g){case v.ROTATE:if(!1===m.enableRotate)return;!function(e){M.set(e.clientX,e.clientY),C.subVectors(M,O);var t=m.domElement===document?m.domElement.body:m.domElement;V(2*Math.PI*C.x/t.clientWidth*m.rotateSpeed),N(2*Math.PI*C.y/t.clientHeight*m.rotateSpeed),O.copy(M),m.update()}(e);break;case v.DOLLY:if(!1===m.enableZoom)return;!function(e){L.set(e.clientX,e.clientY),A.subVectors(L,I),A.y>0?R(_()):A.y<0&&B(_()),I.copy(L),m.update()}(e);break;case v.PAN:if(!1===m.enablePan)return;!function(e){j.set(e.clientX,e.clientY),T.subVectors(j,P),G(T.x,T.y),P.copy(j),m.update()}(e)}e.preventDefault()}}function Y(e){!1!==m.enabled&&(document.removeEventListener("mousemove",F,!1),document.removeEventListener("mouseup",Y,!1),m.dispatchEvent(f),g=v.NONE)}function H(e){!1===m.enabled||!1===m.enableZoom||g!==v.NONE&&g!==v.ROTATE||(e.preventDefault(),e.stopPropagation(),function(e){e.deltaY<0?B(_()):e.deltaY>0&&R(_()),m.update()}(e),m.dispatchEvent(p),m.dispatchEvent(f))}function X(e){!1!==m.enabled&&!1!==m.enableKeys&&!1!==m.enablePan&&function(e){switch(e.keyCode){case m.keys.UP:G(0,m.keyPanSpeed),m.update();break;case m.keys.BOTTOM:G(0,-m.keyPanSpeed),m.update();break;case m.keys.LEFT:G(m.keyPanSpeed,0),m.update();break;case m.keys.RIGHT:G(-m.keyPanSpeed,0),m.update()}}(e)}function Z(e){if(!1!==m.enabled){switch(e.touches.length){case 1:if(!1===m.enableRotate)return;!function(e){O.set(e.touches[0].pageX,e.touches[0].pageY)}(e),g=v.TOUCH_ROTATE;break;case 2:if(!1===m.enableZoom)return;!function(e){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);I.set(0,a)}(e),g=v.TOUCH_DOLLY;break;case 3:if(!1===m.enablePan)return;!function(e){P.set(e.touches[0].pageX,e.touches[0].pageY)}(e),g=v.TOUCH_PAN;break;default:g=v.NONE}g!==v.NONE&&m.dispatchEvent(p)}}function W(e){if(!1!==m.enabled){switch(e.touches.length){case 1:if(!1===m.enableRotate)return;if(g!==v.TOUCH_ROTATE)return;!function(e){M.set(e.touches[0].pageX,e.touches[0].pageY),C.subVectors(M,O);var t=m.domElement===document?m.domElement.body:m.domElement;V(2*Math.PI*C.x/t.clientWidth*m.rotateSpeed),N(2*Math.PI*C.y/t.clientHeight*m.rotateSpeed),O.copy(M),m.update()}(e);break;case 2:if(!1===m.enableZoom)return;if(g!==v.TOUCH_DOLLY)return;!function(e){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);L.set(0,a),A.subVectors(L,I),A.y>0?B(_()):A.y<0&&R(_()),I.copy(L),m.update()}(e);break;case 3:if(!1===m.enablePan)return;if(g!==v.TOUCH_PAN)return;!function(e){j.set(e.touches[0].pageX,e.touches[0].pageY),T.subVectors(j,P),G(T.x,T.y),P.copy(j),m.update()}(e);break;default:g=v.NONE}e.preventDefault(),e.stopPropagation()}}function q(e){!1!==m.enabled&&(m.dispatchEvent(f),g=v.NONE)}function Q(e){!1!==m.enabled&&!1!==m.enablePan&&e.preventDefault()}return m.domElement.addEventListener("contextmenu",Q,!1),m.domElement.addEventListener("mousedown",D,!1),m.domElement.addEventListener("wheel",H,!1),m.domElement.addEventListener("touchstart",Z,!1),m.domElement.addEventListener("touchend",q,!1),m.domElement.addEventListener("touchmove",W,!1),window.addEventListener("keydown",X,!1),u.update(),u}return i(a,e),a}(t.EventDispatcher);function f(e,t,n){if(e instanceof g)e.play(t,n);else{if(!(e instanceof Function))throw"Not an animation: "+e;e(t,n)}}var v=function(){function e(t){n(this,e),this.animation=t,this.paused=this._paused=!1,this.speed=this._speed=1,this._lastChange=null,this._lastChangeX=null}return a(e,[{key:"play",value: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){var a=t-this._lastChange,i=this._lastChangeX+this.speed*a;f(this.animation,e,i)}}},{key:"reset",value:function(){this._lastChange=null}}]),e}(),g=function(){function e(){n(this,e),this.handles=new Set}return a(e,[{key:"add",value:function(e){var t=this,n=new v(e);return n.remove=function(){return t.handles.delete(n)},this.handles.add(n),n}},{key:"play",value:function(e,t){this.handles.forEach(function(n){return n.play(e,t)})}}]),e}();var b=function(){function e(a){var i=this;n(this,e),this.domElement=a.domElement,this.animation=a.animation||null,this.animationPaused=!1,this.animationTime=0,this.disposed=!1,this.skinImg=new Image,this.skinCanvas=document.createElement("canvas"),this.skinTexture=new t.Texture(this.skinCanvas),this.skinTexture.magFilter=t.NearestFilter,this.skinTexture.minFilter=t.NearestMipMapNearestFilter,this.capeImg=new Image,this.capeCanvas=document.createElement("canvas"),this.capeTexture=new t.Texture(this.capeCanvas),this.capeTexture.magFilter=t.NearestFilter,this.capeTexture.minFilter=t.NearestMipMapNearestFilter,this.layer1Material=new t.MeshBasicMaterial({map:this.skinTexture,side:t.FrontSide}),this.layer2Material=new t.MeshBasicMaterial({map:this.skinTexture,transparent:!0,opacity:1,side:t.DoubleSide}),this.capeMaterial=new t.MeshBasicMaterial({map:this.capeTexture}),this.scene=new t.Scene,this.camera=new t.PerspectiveCamera(75),this.camera.position.y=-12,this.camera.position.z=30,this.renderer=new t.WebGLRenderer({angleRot:!0,alpha:!0,antialias:!1}),this.renderer.setSize(300,300),this.renderer.context.getShaderInfoLog=function(){return""},this.domElement.appendChild(this.renderer.domElement),this.playerObject=new l(!0===a.slim,this.layer1Material,this.layer2Material,this.capeMaterial),this.scene.add(this.playerObject),this.skinImg.crossOrigin="",this.skinImg.onerror=function(){return console.error("Failed loading "+i.skinImg.src)},this.skinImg.onload=function(){var e=!1;if(i.skinImg.width!==i.skinImg.height){if(i.skinImg.width!==2*i.skinImg.height)return void console.error("Bad skin size");e=!0}var t=i.skinCanvas.getContext("2d");if(e){var n=i.skinImg.width;i.skinCanvas.width=n,i.skinCanvas.height=n,t.clearRect(0,0,n,n),t.drawImage(i.skinImg,0,0,n,n/2),function(e,t){var n=t/64,a=function(e,t,a,i,o,r,s,c){return function(e,t,n,a,i,o,r,s){var c=e.getImageData(t,n,a,i);if(s)for(var d=0;d * * Copyright (C) 2017 the original author or authors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * * @author yushijinhun * @author Hacksore * @author Kent Rasmussen */ e.SkinObject=u,e.CapeObject=m,e.PlayerObject=l,e.SkinViewer=b,e.SkinControl=w,e.CompositeAnimation=g,e.WalkAnimation=function(e,t){var n=e.skin,a=t+Math.PI/2;n.leftLeg.rotation.x=Math.cos(a),n.rightLeg.rotation.x=Math.cos(a+Math.PI),n.leftArm.rotation.x=Math.cos(a+Math.PI),n.rightArm.rotation.x=Math.cos(a)},Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=skinview3d.min.js.map