skinview3d/js/skinview3d.min.js

64 lines
24 KiB
JavaScript

/**
* skinview3d (https://github.com/to2mbn/skinview3d)
*
* MIT License
*
* Original work Copyright (c) 2014-2018 Kent Rasmussen
* Modified work Copyright (c) 2017-2018 Haowei Wen, Sean Boult, Pig Fang and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
!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;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),o=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},i=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t};function r(e,n,a,o,i,r){return[new t.Vector2(e/i,1-o/r),new t.Vector2(a/i,1-o/r),new t.Vector2(a/i,1-n/r),new t.Vector2(e/i,1-n/r)]}function s(e,t,n,a){return r(e,t,n,a,64,64)}function c(e,t,n,a){return r(e,t,n,a,64,32)}function h(e,t,n,a,o,i,r){e.faceVertexUvs[0]=[],e.faceVertexUvs[0][0]=[i[3],i[0],i[2]],e.faceVertexUvs[0][1]=[i[0],i[1],i[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]=[o[3],o[0],o[2]],e.faceVertexUvs[0][9]=[o[0],o[1],o[2]],e.faceVertexUvs[0][10]=[r[3],r[0],r[2]],e.faceVertexUvs[0][11]=[r[0],r[1],r[2]]}var d=.002,u=function(e){function a(e,o,r){n(this,a);var c=i(this,(a.__proto__||Object.getPrototypeOf(a)).call(this));c.slim=e,c.head=new t.Group;var u=new t.BoxGeometry(8,8,8,0,0,0);h(u,s(8,0,16,8),s(16,0,24,8),s(0,8,8,16),s(8,8,16,16),s(16,8,24,16),s(24,8,32,16));var l=new t.Mesh(u,o);c.head.add(l);var m=new t.BoxGeometry(9,9,9,0,0,0);h(m,s(40,0,48,8),s(48,0,56,8),s(32,8,40,16),s(40,8,48,16),s(48,8,56,16),s(56,8,64,16));var p=new t.Mesh(m,r);p.renderOrder=-1,c.head.add(p),c.add(c.head),c.body=new t.Group;var f=new t.BoxGeometry(8,12,4,0,0,0);h(f,s(20,16,28,20),s(28,16,36,20),s(16,20,20,32),s(20,20,28,32),s(28,20,32,32),s(32,20,40,32));var g=new t.Mesh(f,o);c.body.add(g);var v=new t.BoxGeometry(9,13.5,4.5,0,0,0);h(v,s(20,32,28,36),s(28,32,36,36),s(16,36,20,48),s(20,36,28,48),s(28,36,32,48),s(32,36,40,48));var b=new t.Mesh(v,r);c.body.add(b),c.body.position.y=-10,c.add(c.body),c.rightArm=new t.Group;var w=new t.Group,y=new t.BoxGeometry((e?3:4)-d,12-d,4-d,0,0,0);e?h(y,s(44,16,47,20),s(47,16,50,20),s(40,20,44,32),s(44,20,47,32),s(47,20,51,32),s(51,20,54,32)):h(y,s(44,16,48,20),s(48,16,52,20),s(40,20,44,32),s(44,20,48,32),s(48,20,52,32),s(52,20,56,32));var M=new t.Mesh(y,o);w.add(M);var k=new t.BoxGeometry((e?3.375:4.5)-d,13.5-d,4.5-d,0,0,0);e?h(k,s(44,32,47,36),s(47,32,50,36),s(40,36,44,48),s(44,36,47,48),s(47,36,51,48),s(51,36,54,48)):h(k,s(44,32,48,36),s(48,32,52,36),s(40,36,44,48),s(44,36,48,48),s(48,36,52,48),s(52,36,56,48));var x=new t.Mesh(k,r);x.renderOrder=1,w.add(x),w.position.y=-6,c.rightArm.add(w),c.rightArm.position.y=-4,c.rightArm.position.x=e?-5.5:-6,c.add(c.rightArm),c.leftArm=new t.Group;var E=new t.Group,O=new t.BoxGeometry((e?3:4)-d,12-d,4-d,0,0,0);e?h(O,s(36,48,39,52),s(39,48,42,52),s(32,52,36,64),s(36,52,39,64),s(39,52,43,64),s(43,52,46,64)):h(O,s(36,48,40,52),s(40,48,44,52),s(32,52,36,64),s(36,52,40,64),s(40,52,44,64),s(44,52,48,64));var C=new t.Mesh(O,o);E.add(C);var P=new t.BoxGeometry((e?3.375:4.5)-d,13.5-d,4.5-d,0,0,0);e?h(P,s(52,48,55,52),s(55,48,58,52),s(48,52,52,64),s(52,52,55,64),s(55,52,59,64),s(59,52,62,64)):h(P,s(52,48,56,52),s(56,48,60,52),s(48,52,52,64),s(52,52,56,64),s(56,52,60,64),s(60,52,64,64));var I=new t.Mesh(P,r);I.renderOrder=1,E.add(I),E.position.y=-6,c.leftArm.add(E),c.leftArm.position.y=-4,c.leftArm.position.x=e?5.5:6,c.add(c.leftArm),c.rightLeg=new t.Group;var j=new t.Group,A=new t.BoxGeometry(4-d,12-d,4-d,0,0,0);h(A,s(4,16,8,20),s(8,16,12,20),s(0,20,4,32),s(4,20,8,32),s(8,20,12,32),s(12,20,16,32));var T=new t.Mesh(A,o);j.add(T);var L=new t.BoxGeometry(4.5-d,13.5-d,4.5-d,0,0,0);h(L,s(4,32,8,36),s(8,32,12,36),s(0,36,4,48),s(4,36,8,48),s(8,36,12,48),s(12,36,16,48));var _=new t.Mesh(L,r);_.renderOrder=1,j.add(_),j.position.y=-6,c.rightLeg.add(j),c.rightLeg.position.y=-16,c.rightLeg.position.x=-2,c.add(c.rightLeg),c.leftLeg=new t.Group;var V=new t.Group,N=new t.BoxGeometry(4-d,12-d,4-d,0,0,0);h(N,s(20,48,24,52),s(24,48,28,52),s(16,52,20,64),s(20,52,24,64),s(24,52,28,64),s(28,52,32,64));var U=new t.Mesh(N,o);V.add(U);var S=new t.BoxGeometry(4.5-d,13.5-d,4.5-d,0,0,0);h(S,s(4,48,8,52),s(8,48,12,52),s(0,52,4,64),s(4,52,8,64),s(8,52,12,64),s(12,52,16,64));var z=new t.Mesh(S,r);return z.renderOrder=1,V.add(z),V.position.y=-6,c.leftLeg.add(V),c.leftLeg.position.y=-16,c.leftLeg.position.x=2,c.add(c.leftLeg),c}return o(a,e),a}(t.Group),l=function(e){function a(e){n(this,a);var o=i(this,(a.__proto__||Object.getPrototypeOf(a)).call(this)),r=new t.BoxGeometry(10,16,1,0,0,0);return h(r,c(1,0,11,1),c(11,0,21,1),c(11,1,12,17),c(12,1,22,17),c(0,1,1,17),c(1,1,11,17)),o.cape=new t.Mesh(r,e),o.cape.position.y=-8,o.cape.position.z=-.5,o.add(o.cape),o}return o(a,e),a}(t.Group),m=function(e){function t(e,a,o,r){n(this,t);var s=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return s.skin=new u(e,a,o),s.skin.visible=!1,s.add(s.skin),s.cape=new l(r),s.cape.position.z=-2,s.cape.position.y=-4,s.cape.rotation.x=25*Math.PI/180,s.cape.visible=!1,s.add(s.cape),s}return o(t,e),t}(t.Group),p=function(e){
/**
* @preserve
* The code was originally from https://github.com/mrdoob/three.js/blob/d45a042cf962e9b1aa9441810ba118647b48aacb/examples/js/controls/OrbitControls.js
*/
/**
* @license
* Copyright (C) 2010-2017 three.js authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*
* @author qiao / https://github.com/qiao
* @author mrdoob / http://mrdoob.com
* @author alteredq / http://alteredqualia.com/
* @author WestLangley / http://github.com/WestLangley
* @author erich666 / http://erichaines.com
*/
function a(e,o){n(this,a);var r,s,c,h,d,u=i(this,(a.__proto__||Object.getPrototypeOf(a)).call(this));u.object=e,u.domElement=void 0!==o?o:document,u.enabled=!0,u.target=new t.Vector3,u.minDistance=0,u.maxDistance=1/0,u.minZoom=0,u.maxZoom=1/0,u.minPolarAngle=0,u.maxPolarAngle=Math.PI,u.minAzimuthAngle=-1/0,u.maxAzimuthAngle=1/0,u.enableDamping=!1,u.dampingFactor=.25,u.enableZoom=!0,u.zoomSpeed=1,u.enableRotate=!0,u.rotateSpeed=1,u.enablePan=!0,u.keyPanSpeed=7,u.autoRotate=!1,u.autoRotateSpeed=2,u.enableKeys=!0,u.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40},u.mouseButtons={ORBIT:t.MOUSE.LEFT,ZOOM:t.MOUSE.MIDDLE,PAN:t.MOUSE.RIGHT},u.target0=u.target.clone(),u.position0=u.object.position.clone(),u.zoom0=u.object.zoom,u.getPolarAngle=function(){return w.phi},u.getAzimuthalAngle=function(){return w.theta},u.saveState=function(){l.target0.copy(l.target),l.position0.copy(l.object.position),l.zoom0=l.object.zoom},u.reset=function(){l.target.copy(l.target0),l.object.position.copy(l.position0),l.object.zoom=l.zoom0,l.object.updateProjectionMatrix(),l.dispatchEvent(m),l.update(),v=g.NONE},u.update=(r=new t.Vector3,s=(new t.Quaternion).setFromUnitVectors(e.up,new t.Vector3(0,1,0)),c=s.clone().inverse(),h=new t.Vector3,d=new t.Quaternion,function(){var e=l.object.position;return r.copy(e).sub(l.target),r.applyQuaternion(s),w.setFromVector3(r),l.autoRotate&&v===g.NONE&&V(2*Math.PI/60/60*l.autoRotateSpeed),w.theta+=y.theta,w.phi+=y.phi,w.theta=Math.max(l.minAzimuthAngle,Math.min(l.maxAzimuthAngle,w.theta)),w.phi=Math.max(l.minPolarAngle,Math.min(l.maxPolarAngle,w.phi)),w.makeSafe(),w.radius*=M,w.radius=Math.max(l.minDistance,Math.min(l.maxDistance,w.radius)),l.target.add(k),r.setFromSpherical(w),r.applyQuaternion(c),e.copy(l.target).add(r),l.object.lookAt(l.target),!0===l.enableDamping?(y.theta*=1-l.dampingFactor,y.phi*=1-l.dampingFactor):y.set(0,0,0),M=1,k.set(0,0,0),!!(x||h.distanceToSquared(l.object.position)>b||8*(1-d.dot(l.object.quaternion))>b)&&(l.dispatchEvent(m),h.copy(l.object.position),d.copy(l.object.quaternion),x=!1,!0)}),u.dispose=function(){l.domElement.removeEventListener("contextmenu",Q,!1),l.domElement.removeEventListener("mousedown",D,!1),l.domElement.removeEventListener("wheel",H,!1),l.domElement.removeEventListener("touchstart",Z,!1),l.domElement.removeEventListener("touchend",q,!1),l.domElement.removeEventListener("touchmove",W,!1),document.removeEventListener("mousemove",F,!1),document.removeEventListener("mouseup",Y,!1),window.removeEventListener("keydown",X,!1)};var l=u,m={type:"change"},p={type:"start"},f={type:"end"},g={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5},v=g.NONE,b=1e-6,w=new t.Spherical,y=new t.Spherical,M=1,k=new t.Vector3,x=!1,E=new t.Vector2,O=new t.Vector2,C=new t.Vector2,P=new t.Vector2,I=new t.Vector2,j=new t.Vector2,A=new t.Vector2,T=new t.Vector2,L=new t.Vector2;function _(){return Math.pow(.95,l.zoomSpeed)}function V(e){y.theta-=e}function N(e){y.phi-=e}var U,S=(U=new t.Vector3,function(e,t){U.setFromMatrixColumn(t,0),U.multiplyScalar(-e),k.add(U)}),z=function(){var e=new t.Vector3;return function(t,n){e.setFromMatrixColumn(n,1),e.multiplyScalar(t),k.add(e)}}(),R=function(){var e=new t.Vector3;return function(n,a){var o=l.domElement===document?l.domElement.body:l.domElement;if(l.object instanceof t.PerspectiveCamera){var i=l.object.position;e.copy(i).sub(l.target);var r=e.length();r*=Math.tan(l.object.fov/2*Math.PI/180),S(2*n*r/o.clientHeight,l.object.matrix),z(2*a*r/o.clientHeight,l.object.matrix)}else l.object instanceof t.OrthographicCamera?(S(n*(l.object.right-l.object.left)/l.object.zoom/o.clientWidth,l.object.matrix),z(a*(l.object.top-l.object.bottom)/l.object.zoom/o.clientHeight,l.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),l.enablePan=!1)}}();function G(e){l.object instanceof t.PerspectiveCamera?M/=e:l.object instanceof t.OrthographicCamera?(l.object.zoom=Math.max(l.minZoom,Math.min(l.maxZoom,l.object.zoom*e)),l.object.updateProjectionMatrix(),x=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),l.enableZoom=!1)}function B(e){l.object instanceof t.PerspectiveCamera?M*=e:l.object instanceof t.OrthographicCamera?(l.object.zoom=Math.max(l.minZoom,Math.min(l.maxZoom,l.object.zoom/e)),l.object.updateProjectionMatrix(),x=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),l.enableZoom=!1)}function D(e){if(!1!==l.enabled){switch(e.button){case l.mouseButtons.ORBIT:if(!1===l.enableRotate)return;!function(e){E.set(e.clientX,e.clientY)}(e),v=g.ROTATE;break;case l.mouseButtons.ZOOM:if(!1===l.enableZoom)return;!function(e){A.set(e.clientX,e.clientY)}(e),v=g.DOLLY;break;case l.mouseButtons.PAN:if(!1===l.enablePan)return;!function(e){P.set(e.clientX,e.clientY)}(e),v=g.PAN}e.preventDefault(),v!==g.NONE&&(document.addEventListener("mousemove",F,!1),document.addEventListener("mouseup",Y,!1),l.dispatchEvent(p))}}function F(e){if(!1!==l.enabled){switch(v){case g.ROTATE:if(!1===l.enableRotate)return;!function(e){O.set(e.clientX,e.clientY),C.subVectors(O,E);var t=l.domElement===document?l.domElement.body:l.domElement;V(2*Math.PI*C.x/t.clientWidth*l.rotateSpeed),N(2*Math.PI*C.y/t.clientHeight*l.rotateSpeed),E.copy(O),l.update()}(e);break;case g.DOLLY:if(!1===l.enableZoom)return;!function(e){T.set(e.clientX,e.clientY),L.subVectors(T,A),L.y>0?G(_()):L.y<0&&B(_()),A.copy(T),l.update()}(e);break;case g.PAN:if(!1===l.enablePan)return;!function(e){I.set(e.clientX,e.clientY),j.subVectors(I,P),R(j.x,j.y),P.copy(I),l.update()}(e)}e.preventDefault()}}function Y(e){!1!==l.enabled&&(document.removeEventListener("mousemove",F,!1),document.removeEventListener("mouseup",Y,!1),l.dispatchEvent(f),v=g.NONE)}function H(e){!1===l.enabled||!1===l.enableZoom||v!==g.NONE&&v!==g.ROTATE||(e.preventDefault(),e.stopPropagation(),function(e){e.deltaY<0?B(_()):e.deltaY>0&&G(_()),l.update()}(e),l.dispatchEvent(p),l.dispatchEvent(f))}function X(e){!1!==l.enabled&&!1!==l.enableKeys&&!1!==l.enablePan&&function(e){switch(e.keyCode){case l.keys.UP:R(0,l.keyPanSpeed),l.update();break;case l.keys.BOTTOM:R(0,-l.keyPanSpeed),l.update();break;case l.keys.LEFT:R(l.keyPanSpeed,0),l.update();break;case l.keys.RIGHT:R(-l.keyPanSpeed,0),l.update()}}(e)}function Z(e){if(!1!==l.enabled){switch(e.touches.length){case 1:if(!1===l.enableRotate)return;!function(e){E.set(e.touches[0].pageX,e.touches[0].pageY)}(e),v=g.TOUCH_ROTATE;break;case 2:if(!1===l.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);A.set(0,a)}(e),v=g.TOUCH_DOLLY;break;case 3:if(!1===l.enablePan)return;!function(e){P.set(e.touches[0].pageX,e.touches[0].pageY)}(e),v=g.TOUCH_PAN;break;default:v=g.NONE}v!==g.NONE&&l.dispatchEvent(p)}}function W(e){if(!1!==l.enabled){switch(e.touches.length){case 1:if(!1===l.enableRotate)return;if(v!==g.TOUCH_ROTATE)return;!function(e){O.set(e.touches[0].pageX,e.touches[0].pageY),C.subVectors(O,E);var t=l.domElement===document?l.domElement.body:l.domElement;V(2*Math.PI*C.x/t.clientWidth*l.rotateSpeed),N(2*Math.PI*C.y/t.clientHeight*l.rotateSpeed),E.copy(O),l.update()}(e);break;case 2:if(!1===l.enableZoom)return;if(v!==g.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);T.set(0,a),L.subVectors(T,A),L.y>0?B(_()):L.y<0&&G(_()),A.copy(T),l.update()}(e);break;case 3:if(!1===l.enablePan)return;if(v!==g.TOUCH_PAN)return;!function(e){I.set(e.touches[0].pageX,e.touches[0].pageY),j.subVectors(I,P),R(j.x,j.y),P.copy(I),l.update()}(e);break;default:v=g.NONE}e.preventDefault(),e.stopPropagation()}}function q(e){!1!==l.enabled&&(l.dispatchEvent(f),v=g.NONE)}function Q(e){!1!==l.enabled&&!1!==l.enablePan&&e.preventDefault()}return l.domElement.addEventListener("contextmenu",Q,!1),l.domElement.addEventListener("mousedown",D,!1),l.domElement.addEventListener("wheel",H,!1),l.domElement.addEventListener("touchstart",Z,!1),l.domElement.addEventListener("touchend",q,!1),l.domElement.addEventListener("touchmove",W,!1),window.addEventListener("keydown",X,!1),u.update(),u}return o(a,e),a}(t.EventDispatcher);function f(e,t,n){if(e instanceof v)e.play(t,n);else{if(!(e instanceof Function))throw"Not an animation: "+e;e(t,n)}}var g=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,o=this._lastChangeX+this.speed*a;f(this.animation,e,o)}}},{key:"reset",value:function(){this._lastChange=null}}]),e}(),v=function(){function e(){n(this,e),this.handles=new Set}return a(e,[{key:"add",value:function(e){var t=this,n=new g(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 o=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(40),this.camera.position.y=-12,this.camera.position.z=60,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 m(!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 "+o.skinImg.src)},this.skinImg.onload=function(){var e=!1;if(o.skinImg.width!==o.skinImg.height){if(o.skinImg.width!==2*o.skinImg.height)return void console.error("Bad skin size");e=!0}var t=o.skinCanvas.getContext("2d");if(e){var n=o.skinImg.width;o.skinCanvas.width=n,o.skinCanvas.height=n,t.clearRect(0,0,n,n),t.drawImage(o.skinImg,0,0,n,n/2),function(e,t){var n=t/64,a=function(e,t,a,o,i,r,s,c){return function(e,t,n,a,o,i,r,s){var c=e.getImageData(t,n,a,o);if(s)for(var h=0;h<o;h++)for(var d=0;d<a/2;d++){var u=4*(d+h*a),l=4*(a-d-1+h*a),m=c.data[u],p=c.data[u+1],f=c.data[u+2],g=c.data[u+3],v=c.data[l],b=c.data[l+1],w=c.data[l+2],y=c.data[l+3];c.data[u]=v,c.data[u+1]=b,c.data[u+2]=w,c.data[u+3]=y,c.data[l]=m,c.data[l+1]=p,c.data[l+2]=f,c.data[l+3]=g}e.putImageData(c,i,r)}(e,t*n,a*n,o*n,i*n,r*n,s*n,c)};a(e,4,16,4,4,20,48,!0),a(e,8,16,4,4,24,48,!0),a(e,0,20,4,12,24,52,!0),a(e,4,20,4,12,20,52,!0),a(e,8,20,4,12,16,52,!0),a(e,12,20,4,12,28,52,!0),a(e,44,16,4,4,36,48,!0),a(e,48,16,4,4,40,48,!0),a(e,40,20,4,12,40,52,!0),a(e,44,20,4,12,36,52,!0),a(e,48,20,4,12,32,52,!0),a(e,52,20,4,12,44,52,!0)}(t,n)}else o.skinCanvas.width=o.skinImg.width,o.skinCanvas.height=o.skinImg.height,t.clearRect(0,0,o.skinCanvas.width,o.skinCanvas.height),t.drawImage(o.skinImg,0,0,o.skinCanvas.width,o.skinCanvas.height);o.skinTexture.needsUpdate=!0,o.layer1Material.needsUpdate=!0,o.layer2Material.needsUpdate=!0,o.playerObject.skin.visible=!0},this.capeImg.crossOrigin="",this.capeImg.onerror=function(){return console.error("Failed loading "+o.capeImg.src)},this.capeImg.onload=function(){var e=!1;if(o.capeImg.width!==2*o.capeImg.height){if(17*o.capeImg.width!=22*o.capeImg.height)return void console.error("Bad cape size");e=!0}var t=o.capeCanvas.getContext("2d");if(e){var n=64*o.capeImg.width/22;o.capeCanvas.width=n,o.capeCanvas.height=n/2}else o.capeCanvas.width=o.capeImg.width,o.capeCanvas.height=o.capeImg.height;t.clearRect(0,0,o.capeCanvas.width,o.capeCanvas.height),t.drawImage(o.capeImg,0,0,o.capeImg.width,o.capeImg.height),o.capeTexture.needsUpdate=!0,o.capeMaterial.needsUpdate=!0,o.playerObject.cape.visible=!0},a.skinUrl&&(this.skinUrl=a.skinUrl),a.capeUrl&&(this.capeUrl=a.capeUrl),a.width&&(this.width=a.width),a.height&&(this.height=a.height);!function e(){o.disposed||(window.requestAnimationFrame(e),o.animationPaused||(o.animationTime++,o.animation&&f(o.animation,o.playerObject,o.animationTime/100)),o.renderer.render(o.scene,o.camera))}()}return a(e,[{key:"setSize",value:function(e,t){this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.renderer.setSize(e,t)}},{key:"dispose",value:function(){this.disposed=!0,this.domElement.removeChild(this.renderer.domElement),this.renderer.dispose(),this.skinTexture.dispose(),this.capeTexture.dispose()}},{key:"skinUrl",get:function(){return this.skinImg.src},set:function(e){this.skinImg.src=e}},{key:"capeUrl",get:function(){return this.capeImg.src},set:function(e){this.capeImg.src=e}},{key:"width",get:function(){return this.renderer.getSize().width},set:function(e){this.setSize(e,this.height)}},{key:"height",get:function(){return this.renderer.getSize().height},set:function(e){this.setSize(this.width,e)}}]),e}(),w=function(){function e(a){n(this,e),this.skinViewer=a,this.orbitControls=new p(a.camera,a.renderer.domElement),this.orbitControls.enablePan=!1,this.orbitControls.target=new t.Vector3(0,-12,0),this.orbitControls.minDistance=10,this.orbitControls.maxDistance=256,this.orbitControls.update()}return a(e,[{key:"dispose",value:function(){this.orbitControls.dispose()}},{key:"rotation",get:function(){return this.orbitControls.enableRotate},set:function(e){this.orbitControls.enableRotate=e}},{key:"zoom",get:function(){return this.orbitControls.enableZoom},set:function(e){this.orbitControls.enableZoom=e}},{key:"pan",get:function(){return this.orbitControls.enablePan},set:function(e){this.orbitControls.enablePan=e}}]),e}();e.SkinObject=u,e.CapeObject=l,e.PlayerObject=m,e.SkinViewer=b,e.MouseControl=w,e.invokeAnimation=f,e.CompositeAnimation=v,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 o=.06*Math.PI;e.cape.rotation.x=.06*Math.sin(t/1.5)+o},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 o=.3*Math.PI;e.cape.rotation.x=.1*Math.sin(2*t)+o},e.RotatingAnimation=function(e,t){e.rotation.y=t},Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=skinview3d.min.js.map