62 lines
23 KiB
JavaScript
62 lines
23 KiB
JavaScript
!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}}(),i=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)},o=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,i,o,r){return[new t.Vector2(e/o,1-i/r),new t.Vector2(a/o,1-i/r),new t.Vector2(a/o,1-n/r),new t.Vector2(e/o,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 d(e,t,n,a,i,o,r){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]=[r[3],r[0],r[2]],e.faceVertexUvs[0][11]=[r[0],r[1],r[2]]}var h=.002,u=function(e){function a(e,i,r){n(this,a);var c=o(this,(a.__proto__||Object.getPrototypeOf(a)).call(this));c.head=new t.Group;var u=new t.BoxGeometry(8,8,8,0,0,0);d(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 m=new t.Mesh(u,i);c.head.add(m);var l=new t.BoxGeometry(9,9,9,0,0,0);d(l,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(l,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);d(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 v=new t.Mesh(f,i);c.body.add(v);var g=new t.BoxGeometry(9,13.5,4.5,0,0,0);d(g,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(g,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)-h,12-h,4-h,0,0,0);e?d(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)):d(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 k=new t.Mesh(y,i);w.add(k);var E=new t.BoxGeometry((e?3.375:4.5)-h,13.5-h,4.5-h,0,0,0);e?d(E,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)):d(E,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(E,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 O=new t.Group,M=new t.BoxGeometry((e?3:4)-h,12-h,4-h,0,0,0);e?d(M,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)):d(M,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(M,i);O.add(C);var P=new t.BoxGeometry((e?3.375:4.5)-h,13.5-h,4.5-h,0,0,0);e?d(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)):d(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 j=new t.Mesh(P,r);j.renderOrder=1,O.add(j),O.position.y=-6,c.leftArm.add(O),c.leftArm.position.y=-4,c.leftArm.position.x=e?5.5:6,c.add(c.leftArm),c.rightLeg=new t.Group;var T=new t.Group,I=new t.BoxGeometry(4-h,12-h,4-h,0,0,0);d(I,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 L=new t.Mesh(I,i);T.add(L);var A=new t.BoxGeometry(4.5-h,13.5-h,4.5-h,0,0,0);d(A,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(A,r);_.renderOrder=1,T.add(_),T.position.y=-6,c.rightLeg.add(T),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-h,12-h,4-h,0,0,0);d(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 S=new t.Mesh(N,i);V.add(S);var U=new t.BoxGeometry(4.5-h,13.5-h,4.5-h,0,0,0);d(U,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(U,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 i(a,e),a}(t.Group),m=function(e){function a(e){n(this,a);var i=o(this,(a.__proto__||Object.getPrototypeOf(a)).call(this)),r=new t.BoxGeometry(10,16,1,0,0,0);return d(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)),i.cape=new t.Mesh(r,e),i.cape.position.y=-8,i.cape.position.z=-.5,i.add(i.cape),i}return i(a,e),a}(t.Group),l=function(e){function t(e,a,i,r){n(this,t);var s=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return s.slim=e,s.skin=new u(e,a,i),s.skin.visible=!1,s.add(s.skin),s.cape=new m(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 i(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,i){n(this,a);var r,s,c,d,h,u=o(this,(a.__proto__||Object.getPrototypeOf(a)).call(this));u.object=e,u.domElement=void 0!==i?i: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(){m.target0.copy(m.target),m.position0.copy(m.object.position),m.zoom0=m.object.zoom},u.reset=function(){m.target.copy(m.target0),m.object.position.copy(m.position0),m.object.zoom=m.zoom0,m.object.updateProjectionMatrix(),m.dispatchEvent(l),m.update(),g=v.NONE},u.update=(r=new t.Vector3,s=(new t.Quaternion).setFromUnitVectors(e.up,new t.Vector3(0,1,0)),c=s.clone().inverse(),d=new t.Vector3,h=new t.Quaternion,function(){var e=m.object.position;return r.copy(e).sub(m.target),r.applyQuaternion(s),w.setFromVector3(r),m.autoRotate&&g===v.NONE&&V(2*Math.PI/60/60*m.autoRotateSpeed),w.theta+=y.theta,w.phi+=y.phi,w.theta=Math.max(m.minAzimuthAngle,Math.min(m.maxAzimuthAngle,w.theta)),w.phi=Math.max(m.minPolarAngle,Math.min(m.maxPolarAngle,w.phi)),w.makeSafe(),w.radius*=k,w.radius=Math.max(m.minDistance,Math.min(m.maxDistance,w.radius)),m.target.add(E),r.setFromSpherical(w),r.applyQuaternion(c),e.copy(m.target).add(r),m.object.lookAt(m.target),!0===m.enableDamping?(y.theta*=1-m.dampingFactor,y.phi*=1-m.dampingFactor):y.set(0,0,0),k=1,E.set(0,0,0),!!(x||d.distanceToSquared(m.object.position)>b||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<i;d++)for(var h=0;h<a/2;h++){var u=4*(h+d*a),m=4*(a-h-1+d*a),l=c.data[u],p=c.data[u+1],f=c.data[u+2],v=c.data[u+3],g=c.data[m],b=c.data[m+1],w=c.data[m+2],y=c.data[m+3];c.data[u]=g,c.data[u+1]=b,c.data[u+2]=w,c.data[u+3]=y,c.data[m]=l,c.data[m+1]=p,c.data[m+2]=f,c.data[m+3]=v}e.putImageData(c,o,r)}(e,t*n,a*n,i*n,o*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 i.skinCanvas.width=i.skinImg.width,i.skinCanvas.height=i.skinImg.height,t.clearRect(0,0,i.skinCanvas.width,i.skinCanvas.height),t.drawImage(i.skinImg,0,0,i.skinCanvas.width,i.skinCanvas.height);i.skinTexture.needsUpdate=!0,i.layer1Material.needsUpdate=!0,i.layer2Material.needsUpdate=!0,i.playerObject.skin.visible=!0},this.capeImg.crossOrigin="",this.capeImg.onerror=function(){return console.error("Failed loading "+i.capeImg.src)},this.capeImg.onload=function(){if(i.capeImg.width===2*i.capeImg.height){i.capeCanvas.width=i.capeImg.width,i.capeCanvas.height=i.capeImg.height;var e=i.capeCanvas.getContext("2d");e.clearRect(0,0,i.capeCanvas.width,i.capeCanvas.height),e.drawImage(i.capeImg,0,0,i.capeCanvas.width,i.capeCanvas.height),i.capeTexture.needsUpdate=!0,i.capeMaterial.needsUpdate=!0,i.playerObject.cape.visible=!0}else console.error("Bad cape size")},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(){i.disposed||(window.requestAnimationFrame(e),i.animationPaused||(i.animationTime++,i.animation&&f(i.animation,i.playerObject,i.animationTime/100)),i.renderer.render(i.scene,i.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){var i=this;n(this,e),this.enableAnimationControl=!0,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(),this.animationPauseListener=function(e){i.enableAnimationControl&&(e.preventDefault(),i.skinViewer.animationPaused=!i.skinViewer.animationPaused)},this.skinViewer.domElement.addEventListener("contextmenu",this.animationPauseListener,!1)}return a(e,[{key:"dispose",value:function(){this.skinViewer.domElement.removeEventListener("contextmenu",this.animationPauseListener,!1),this.orbitControls.dispose()}}]),e}();
|
|
/**
|
|
* @license
|
|
* skinview3d <https://github.com/to2mbn/skinview3d>
|
|
*
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
*
|
|
*
|
|
* @author yushijinhun <https://github.com/yushijinhun>
|
|
* @author Hacksore <https://github.com/Hacksore>
|
|
* @author Kent Rasmussen <https://github.com/earthiverse>
|
|
*/
|
|
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
|