64 lines
24 KiB
JavaScript
64 lines
24 KiB
JavaScript
/**
|
|
* skinview3d (https://github.com/to2mbn/skinview3d)
|
|
*
|
|
* MIT License
|
|
*
|
|
* Copyright (c) 2014-2018 Kent Rasmussen
|
|
* Copyright (c) 2017-2018 Haowei Wen, Sean Boult 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,Q){"use strict";var K=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},a=function(){function a(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(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),e}}(),t=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)},J=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 i(e,t,n,a,i,o){return[new Q.Vector2(e/i,1-a/o),new Q.Vector2(n/i,1-a/o),new Q.Vector2(n/i,1-t/o),new Q.Vector2(e/i,1-t/o)]}function _(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 C(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 N=.002,r=function(e){function I(e,t){K(this,I);var n=J(this,(I.__proto__||Object.getPrototypeOf(I)).call(this));n.modelListeners=[],n.head=new Q.Group;var a=new Q.BoxGeometry(8,8,8,0,0,0);C(a,_(8,0,16,8),_(16,0,24,8),_(0,8,8,16),_(8,8,16,16),_(16,8,24,16),_(24,8,32,16));var i=new Q.Mesh(a,e);n.head.add(i);var o=new Q.BoxGeometry(9,9,9,0,0,0);C(o,_(40,0,48,8),_(48,0,56,8),_(32,8,40,16),_(40,8,48,16),_(48,8,56,16),_(56,8,64,16));var r=new Q.Mesh(o,t);r.renderOrder=-1,n.head.add(r),n.add(n.head),n.body=new Q.Group;var s=new Q.BoxGeometry(8,12,4,0,0,0);C(s,_(20,16,28,20),_(28,16,36,20),_(16,20,20,32),_(20,20,28,32),_(28,20,32,32),_(32,20,40,32));var c=new Q.Mesh(s,e);n.body.add(c);var h=new Q.BoxGeometry(9,13.5,4.5,0,0,0);C(h,_(20,32,28,36),_(28,32,36,36),_(16,36,20,48),_(20,36,28,48),_(28,36,32,48),_(32,36,40,48));var d=new Q.Mesh(h,t);n.body.add(d),n.body.position.y=-10,n.add(n.body),n.rightArm=new Q.Group;var u=new Q.Group,l=new Q.BoxGeometry(1,1,1,0,0,0),m=new Q.Mesh(l,e);u.add(m),n.modelListeners.push(function(){m.scale.x=(n.slim?3:4)-N,m.scale.y=12-N,m.scale.z=4-N,n.slim?C(l,_(44,16,47,20),_(47,16,50,20),_(40,20,44,32),_(44,20,47,32),_(47,20,51,32),_(51,20,54,32)):C(l,_(44,16,48,20),_(48,16,52,20),_(40,20,44,32),_(44,20,48,32),_(48,20,52,32),_(52,20,56,32)),l.uvsNeedUpdate=!0,l.elementsNeedUpdate=!0});var p=new Q.BoxGeometry(1,1,1,0,0,0),f=new Q.Mesh(p,t);f.renderOrder=1,u.add(f),n.modelListeners.push(function(){f.scale.x=(n.slim?3.375:4.5)-N,f.scale.y=13.498,f.scale.z=4.498,n.slim?C(p,_(44,32,47,36),_(47,32,50,36),_(40,36,44,48),_(44,36,47,48),_(47,36,51,48),_(51,36,54,48)):C(p,_(44,32,48,36),_(48,32,52,36),_(40,36,44,48),_(44,36,48,48),_(48,36,52,48),_(52,36,56,48)),p.uvsNeedUpdate=!0,p.elementsNeedUpdate=!0}),u.position.y=-6,n.rightArm.add(u),n.rightArm.position.y=-4,n.modelListeners.push(function(){n.rightArm.position.x=n.slim?-5.5:-6}),n.add(n.rightArm),n.leftArm=new Q.Group;var g=new Q.Group,v=new Q.BoxGeometry(1,1,1,0,0,0),b=new Q.Mesh(v,e);g.add(b),n.modelListeners.push(function(){b.scale.x=(n.slim?3:4)-N,b.scale.y=12-N,b.scale.z=4-N,n.slim?C(v,_(36,48,39,52),_(39,48,42,52),_(32,52,36,64),_(36,52,39,64),_(39,52,43,64),_(43,52,46,64)):C(v,_(36,48,40,52),_(40,48,44,52),_(32,52,36,64),_(36,52,40,64),_(40,52,44,64),_(44,52,48,64)),v.uvsNeedUpdate=!0,v.elementsNeedUpdate=!0});var w=new Q.BoxGeometry(1,1,1,0,0,0),y=new Q.Mesh(w,t);y.renderOrder=1,g.add(y),n.modelListeners.push(function(){y.scale.x=(n.slim?3.375:4.5)-N,y.scale.y=13.498,y.scale.z=4.498,n.slim?C(w,_(52,48,55,52),_(55,48,58,52),_(48,52,52,64),_(52,52,55,64),_(55,52,59,64),_(59,52,62,64)):C(w,_(52,48,56,52),_(56,48,60,52),_(48,52,52,64),_(52,52,56,64),_(56,52,60,64),_(60,52,64,64)),w.uvsNeedUpdate=!0,w.elementsNeedUpdate=!0}),g.position.y=-6,n.leftArm.add(g),n.leftArm.position.y=-4,n.modelListeners.push(function(){n.leftArm.position.x=n.slim?5.5:6}),n.add(n.leftArm),n.rightLeg=new Q.Group;var x=new Q.Group,M=new Q.BoxGeometry(4-N,12-N,4-N,0,0,0);C(M,_(4,16,8,20),_(8,16,12,20),_(0,20,4,32),_(4,20,8,32),_(8,20,12,32),_(12,20,16,32));var E=new Q.Mesh(M,e);x.add(E);var O=new Q.BoxGeometry(4.498,13.498,4.498,0,0,0);C(O,_(4,32,8,36),_(8,32,12,36),_(0,36,4,48),_(4,36,8,48),_(8,36,12,48),_(12,36,16,48));var k=new Q.Mesh(O,t);k.renderOrder=1,x.add(k),x.position.y=-6,n.rightLeg.add(x),n.rightLeg.position.y=-16,n.rightLeg.position.x=-2,n.add(n.rightLeg),n.leftLeg=new Q.Group;var P=new Q.Group,j=new Q.BoxGeometry(4-N,12-N,4-N,0,0,0);C(j,_(20,48,24,52),_(24,48,28,52),_(16,52,20,64),_(20,52,24,64),_(24,52,28,64),_(28,52,32,64));var L=new Q.Mesh(j,e);P.add(L);var T=new Q.BoxGeometry(4.498,13.498,4.498,0,0,0);C(T,_(4,48,8,52),_(8,48,12,52),_(0,52,4,64),_(4,52,8,64),_(8,52,12,64),_(12,52,16,64));var A=new Q.Mesh(T,t);return A.renderOrder=1,P.add(A),P.position.y=-6,n.leftLeg.add(P),n.leftLeg.position.y=-16,n.leftLeg.position.x=2,n.add(n.leftLeg),n.slim=!1,n}return t(I,e),a(I,[{key:"slim",get:function(){return this._slim},set:function(e){this._slim!==e&&(this._slim=e,this.modelListeners.forEach(function(e){return e()}))}}]),I}(Q.Group),s=function(e){function a(e){K(this,a);var t=J(this,(a.__proto__||Object.getPrototypeOf(a)).call(this)),n=new Q.BoxGeometry(10,16,1,0,0,0);return C(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 Q.Mesh(n,e),t.cape.position.y=-8,t.cape.position.z=-.5,t.add(t.cape),t}return t(a,e),a}(Q.Group),c=function(e){function i(e,t,n){K(this,i);var a=J(this,(i.__proto__||Object.getPrototypeOf(i)).call(this));return a.skin=new r(e,t),a.skin.visible=!1,a.add(a.skin),a.cape=new s(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(i,e),i}(Q.Group);function h(e,t,n){if(e instanceof u)e.play(t,n);else{if(!(e instanceof Function))throw"Not an animation: "+e;e(t,n)}}var d=function(){function t(e){K(this,t),this.animation=e,this.paused=this._paused=!1,this.speed=this._speed=1,this._lastChange=null,this._lastChangeX=null}return a(t,[{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;h(this.animation,e,i)}}},{key:"reset",value:function(){this._lastChange=null}}]),t}(),u=function(){function e(){K(this,e),this.handles=new Set}return a(e,[{key:"add",value:function(e){var t=this,n=new d(e);return n.remove=function(){return t.handles.delete(n)},this.handles.add(n),n}},{key:"play",value: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),r=0;r<a;r++)for(var s=0;s<i;s++){var c=4*(r+s*a);if(255!==o.data[c+3])return!0}return!1}function m(e){return e/64}function p(s,e){var c=m(e),t=function(e,t,n,a,i,o,r){return function(e,t,n,a,i,o,r,s){var c=e.getImageData(t,n,a,i);if(s)for(var h=0;h<i;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,o,r)}(s,e*c,t*c,n*c,a*c,i*c,o*c,r)};!function(i,e){if(!l(i,0,0,e,e/2)){var o=m(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)}}(s,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 f(e,t){var n=!1;if(t.width!==t.height){if(t.width!==2*t.height)throw"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),p(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 g(e){if(e instanceof HTMLCanvasElement){var t=e,i=m(t.width),o=t.getContext("2d"),n=function(e,t,n,a){return l(o,e*i,t*i,n*i,a*i)};return n(50,16,2,4)||n(54,20,2,12)||n(42,48,2,4)||n(46,52,2,12)}if(e instanceof HTMLImageElement){var a=e,r=document.createElement("canvas");return f(r,a),g(r)}throw"Illegal argument: "+e}var n=function(){function n(e){var t=this;K(this,n),this.domElement=e.domElement,this.animation=e.animation||null,this.detectModel=!1!==e.detectModel,this.animationPaused=!1,this.animationTime=0,this.disposed=!1,this.skinImg=new Image,this.skinCanvas=document.createElement("canvas"),this.skinTexture=new Q.Texture(this.skinCanvas),this.skinTexture.magFilter=Q.NearestFilter,this.skinTexture.minFilter=Q.NearestFilter,this.capeImg=new Image,this.capeCanvas=document.createElement("canvas"),this.capeTexture=new Q.Texture(this.capeCanvas),this.capeTexture.magFilter=Q.NearestFilter,this.capeTexture.minFilter=Q.NearestFilter,this.layer1Material=new Q.MeshBasicMaterial({map:this.skinTexture,side:Q.FrontSide}),this.layer2Material=new Q.MeshBasicMaterial({map:this.skinTexture,transparent:!0,opacity:1,side:Q.DoubleSide,alphaTest:.5}),this.capeMaterial=new Q.MeshBasicMaterial({map:this.capeTexture,transparent:!0,opacity:1,side:Q.DoubleSide,alphaTest:.5}),this.scene=new Q.Scene,this.camera=new Q.PerspectiveCamera(40),this.camera.position.y=-12,this.camera.position.z=60,this.renderer=new Q.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 c(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(){f(t.skinCanvas,t.skinImg),t.detectModel&&(t.playerObject.skin.slim=g(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"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);!function e(){t.disposed||(window.requestAnimationFrame(e),t.animationPaused||(t.animationTime++,t.animation&&h(t.animation,t.playerObject,t.animationTime/100)),t.renderer.render(t.scene,t.camera))}()}return a(n,[{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)}}]),n}(),v=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 q(e,t){K(this,q);var n,a,i,o,r,s=J(this,(q.__proto__||Object.getPrototypeOf(q)).call(this));s.object=e,s.domElement=void 0!==t?t:document,s.enabled=!0,s.target=new Q.Vector3,s.minDistance=0,s.maxDistance=1/0,s.minZoom=0,s.maxZoom=1/0,s.minPolarAngle=0,s.maxPolarAngle=Math.PI,s.minAzimuthAngle=-1/0,s.maxAzimuthAngle=1/0,s.enableDamping=!1,s.dampingFactor=.25,s.enableZoom=!0,s.zoomSpeed=1,s.enableRotate=!0,s.rotateSpeed=1,s.enablePan=!0,s.keyPanSpeed=7,s.autoRotate=!1,s.autoRotateSpeed=2,s.enableKeys=!0,s.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40},s.mouseButtons={ORBIT:Q.MOUSE.LEFT,ZOOM:Q.MOUSE.MIDDLE,PAN:Q.MOUSE.RIGHT},s.target0=s.target.clone(),s.position0=s.object.position.clone(),s.zoom0=s.object.zoom,s.getPolarAngle=function(){return f.phi},s.getAzimuthalAngle=function(){return f.theta},s.saveState=function(){c.target0.copy(c.target),c.position0.copy(c.object.position),c.zoom0=c.object.zoom},s.reset=function(){c.target.copy(c.target0),c.object.position.copy(c.position0),c.object.zoom=c.zoom0,c.object.updateProjectionMatrix(),c.dispatchEvent(h),c.update(),m=l.NONE},s.update=(n=new Q.Vector3,a=(new Q.Quaternion).setFromUnitVectors(e.up,new Q.Vector3(0,1,0)),i=a.clone().inverse(),o=new Q.Vector3,r=new Q.Quaternion,function(){var e=c.object.position;return n.copy(e).sub(c.target),n.applyQuaternion(a),f.setFromVector3(n),c.autoRotate&&m===l.NONE&&A(2*Math.PI/60/60*c.autoRotateSpeed),f.theta+=g.theta,f.phi+=g.phi,f.theta=Math.max(c.minAzimuthAngle,Math.min(c.maxAzimuthAngle,f.theta)),f.phi=Math.max(c.minPolarAngle,Math.min(c.maxPolarAngle,f.phi)),f.makeSafe(),f.radius*=v,f.radius=Math.max(c.minDistance,Math.min(c.maxDistance,f.radius)),c.target.add(b),n.setFromSpherical(f),n.applyQuaternion(i),e.copy(c.target).add(n),c.object.lookAt(c.target),!0===c.enableDamping?(g.theta*=1-c.dampingFactor,g.phi*=1-c.dampingFactor):g.set(0,0,0),v=1,b.set(0,0,0),!(!(w||o.distanceToSquared(c.object.position)>p||8*(1-r.dot(c.object.quaternion))>p)||(c.dispatchEvent(h),o.copy(c.object.position),r.copy(c.object.quaternion),w=!1))}),s.dispose=function(){c.domElement.removeEventListener("contextmenu",W,!1),c.domElement.removeEventListener("mousedown",G,!1),c.domElement.removeEventListener("wheel",F,!1),c.domElement.removeEventListener("touchstart",H,!1),c.domElement.removeEventListener("touchend",Z,!1),c.domElement.removeEventListener("touchmove",X,!1),document.removeEventListener("mousemove",D,!1),document.removeEventListener("mouseup",B,!1),window.removeEventListener("keydown",Y,!1)};var c=s,h={type:"change"},d={type:"start"},u={type:"end"},l={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5},m=l.NONE,p=1e-6,f=new Q.Spherical,g=new Q.Spherical,v=1,b=new Q.Vector3,w=!1,y=new Q.Vector2,x=new Q.Vector2,M=new Q.Vector2,E=new Q.Vector2,O=new Q.Vector2,k=new Q.Vector2,P=new Q.Vector2,j=new Q.Vector2,L=new Q.Vector2;function T(){return Math.pow(.95,c.zoomSpeed)}function A(e){g.theta-=e}function I(e){g.phi-=e}var _,C,N,U=(_=new Q.Vector3,function(e,t){_.setFromMatrixColumn(t,0),_.multiplyScalar(-e),b.add(_)}),V=(C=new Q.Vector3,function(e,t){C.setFromMatrixColumn(t,1),C.multiplyScalar(e),b.add(C)}),S=(N=new Q.Vector3,function(e,t){var n=c.domElement===document?c.domElement.body:c.domElement;if(c.object instanceof Q.PerspectiveCamera){var a=c.object.position;N.copy(a).sub(c.target);var i=N.length();i*=Math.tan(c.object.fov/2*Math.PI/180),U(2*e*i/n.clientHeight,c.object.matrix),V(2*t*i/n.clientHeight,c.object.matrix)}else c.object instanceof Q.OrthographicCamera?(U(e*(c.object.right-c.object.left)/c.object.zoom/n.clientWidth,c.object.matrix),V(t*(c.object.top-c.object.bottom)/c.object.zoom/n.clientHeight,c.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),c.enablePan=!1)});function z(e){c.object instanceof Q.PerspectiveCamera?v/=e:c.object instanceof Q.OrthographicCamera?(c.object.zoom=Math.max(c.minZoom,Math.min(c.maxZoom,c.object.zoom*e)),c.object.updateProjectionMatrix(),w=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),c.enableZoom=!1)}function R(e){c.object instanceof Q.PerspectiveCamera?v*=e:c.object instanceof Q.OrthographicCamera?(c.object.zoom=Math.max(c.minZoom,Math.min(c.maxZoom,c.object.zoom/e)),c.object.updateProjectionMatrix(),w=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),c.enableZoom=!1)}function G(e){if(!1!==c.enabled){switch(e.button){case c.mouseButtons.ORBIT:if(!1===c.enableRotate)return;a=e,y.set(a.clientX,a.clientY),m=l.ROTATE;break;case c.mouseButtons.ZOOM:if(!1===c.enableZoom)return;n=e,P.set(n.clientX,n.clientY),m=l.DOLLY;break;case c.mouseButtons.PAN:if(!1===c.enablePan)return;t=e,E.set(t.clientX,t.clientY),m=l.PAN}var t,n,a;e.preventDefault(),m!==l.NONE&&(document.addEventListener("mousemove",D,!1),document.addEventListener("mouseup",B,!1),c.dispatchEvent(d))}}function D(e){if(!1!==c.enabled){switch(m){case l.ROTATE:if(!1===c.enableRotate)return;!function(e){x.set(e.clientX,e.clientY),M.subVectors(x,y);var t=c.domElement===document?c.domElement.body:c.domElement;A(2*Math.PI*M.x/t.clientWidth*c.rotateSpeed),I(2*Math.PI*M.y/t.clientHeight*c.rotateSpeed),y.copy(x),c.update()}(e);break;case l.DOLLY:if(!1===c.enableZoom)return;n=e,j.set(n.clientX,n.clientY),L.subVectors(j,P),0<L.y?z(T()):L.y<0&&R(T()),P.copy(j),c.update();break;case l.PAN:if(!1===c.enablePan)return;t=e,O.set(t.clientX,t.clientY),k.subVectors(O,E),S(k.x,k.y),E.copy(O),c.update()}var t,n;e.preventDefault()}}function B(e){!1!==c.enabled&&(document.removeEventListener("mousemove",D,!1),document.removeEventListener("mouseup",B,!1),c.dispatchEvent(u),m=l.NONE)}function F(e){var t;!1===c.enabled||!1===c.enableZoom||m!==l.NONE&&m!==l.ROTATE||(e.preventDefault(),e.stopPropagation(),(t=e).deltaY<0?R(T()):0<t.deltaY&&z(T()),c.update(),c.dispatchEvent(d),c.dispatchEvent(u))}function Y(e){!1!==c.enabled&&!1!==c.enableKeys&&!1!==c.enablePan&&function(e){switch(e.keyCode){case c.keys.UP:S(0,c.keyPanSpeed),c.update();break;case c.keys.BOTTOM:S(0,-c.keyPanSpeed),c.update();break;case c.keys.LEFT:S(c.keyPanSpeed,0),c.update();break;case c.keys.RIGHT:S(-c.keyPanSpeed,0),c.update()}}(e)}function H(e){if(!1!==c.enabled){switch(e.touches.length){case 1:if(!1===c.enableRotate)return;r=e,y.set(r.touches[0].pageX,r.touches[0].pageY),m=l.TOUCH_ROTATE;break;case 2:if(!1===c.enableZoom)return;a=(n=e).touches[0].pageX-n.touches[1].pageX,i=n.touches[0].pageY-n.touches[1].pageY,o=Math.sqrt(a*a+i*i),P.set(0,o),m=l.TOUCH_DOLLY;break;case 3:if(!1===c.enablePan)return;t=e,E.set(t.touches[0].pageX,t.touches[0].pageY),m=l.TOUCH_PAN;break;default:m=l.NONE}var t,n,a,i,o,r;m!==l.NONE&&c.dispatchEvent(d)}}function X(e){if(!1!==c.enabled){switch(e.touches.length){case 1:if(!1===c.enableRotate)return;if(m!==l.TOUCH_ROTATE)return;!function(e){x.set(e.touches[0].pageX,e.touches[0].pageY),M.subVectors(x,y);var t=c.domElement===document?c.domElement.body:c.domElement;A(2*Math.PI*M.x/t.clientWidth*c.rotateSpeed),I(2*Math.PI*M.y/t.clientHeight*c.rotateSpeed),y.copy(x),c.update()}(e);break;case 2:if(!1===c.enableZoom)return;if(m!==l.TOUCH_DOLLY)return;a=(n=e).touches[0].pageX-n.touches[1].pageX,i=n.touches[0].pageY-n.touches[1].pageY,o=Math.sqrt(a*a+i*i),j.set(0,o),L.subVectors(j,P),0<L.y?R(T()):L.y<0&&z(T()),P.copy(j),c.update();break;case 3:if(!1===c.enablePan)return;if(m!==l.TOUCH_PAN)return;t=e,O.set(t.touches[0].pageX,t.touches[0].pageY),k.subVectors(O,E),S(k.x,k.y),E.copy(O),c.update();break;default:m=l.NONE}var t,n,a,i,o;e.preventDefault(),e.stopPropagation()}}function Z(e){!1!==c.enabled&&(c.dispatchEvent(u),m=l.NONE)}function W(e){!1!==c.enabled&&!1!==c.enablePan&&e.preventDefault()}return c.domElement.addEventListener("contextmenu",W,!1),c.domElement.addEventListener("mousedown",G,!1),c.domElement.addEventListener("wheel",F,!1),c.domElement.addEventListener("touchstart",H,!1),c.domElement.addEventListener("touchend",Z,!1),c.domElement.addEventListener("touchmove",X,!1),window.addEventListener("keydown",Y,!1),s.update(),s}return t(q,e),q}(Q.EventDispatcher);e.SkinObject=r,e.CapeObject=s,e.PlayerObject=c,e.SkinViewer=n,e.OrbitControls=v,e.createOrbitControls=function(e){var t=new v(e.camera,e.renderer.domElement);return t.enablePan=!1,t.target=new Q.Vector3(0,-12,0),t.minDistance=10,t.maxDistance=256,t.update(),t},e.invokeAnimation=h,e.CompositeAnimation=u,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=g,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
//# sourceMappingURL=skinview3d.min.js.map
|