/** * 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=e||self).skinview3d={},e.THREE)}(this,(function(e,t){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */var n=function(e,t){return(n=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 a(e,t){function a(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(a.prototype=t.prototype,new a)}function o(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 i(e,t,n,a){return o(e,t,n,a,64,64)}function r(e,t,n,a){return o(e,t,n,a,64,32)}function s(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 h=.002,c=function(e){function t(t,n){var a=e.call(this)||this;return a.innerLayer=t,a.outerLayer=n,t.name="inner",n.name="outer",a}return a(t,e),t}(t.Group),d=function(e){function n(n,a){var o=e.call(this)||this;o.modelListeners=[],o._slim=!1;var r=new t.BoxGeometry(8,8,8,0,0,0);s(r,i(8,0,16,8),i(16,0,24,8),i(0,8,8,16),i(8,8,16,16),i(16,8,24,16),i(24,8,32,16));var d=new t.Mesh(r,n),l=new t.BoxGeometry(9,9,9,0,0,0);s(l,i(40,0,48,8),i(48,0,56,8),i(32,8,40,16),i(40,8,48,16),i(48,8,56,16),i(56,8,64,16));var p=new t.Mesh(l,a);p.renderOrder=-1,o.head=new c(d,p),o.head.name="head",o.head.add(d,p),o.add(o.head);var u=new t.BoxGeometry(8,12,4,0,0,0);s(u,i(20,16,28,20),i(28,16,36,20),i(16,20,20,32),i(20,20,28,32),i(28,20,32,32),i(32,20,40,32));var m=new t.Mesh(u,n),f=new t.BoxGeometry(9,13.5,4.5,0,0,0);s(f,i(20,32,28,36),i(28,32,36,36),i(16,36,20,48),i(20,36,28,48),i(28,36,32,48),i(32,36,40,48));var y=new t.Mesh(f,a);o.body=new c(m,y),o.body.name="body",o.body.add(m,y),o.body.position.y=-10,o.add(o.body);var g=new t.BoxGeometry(1,1,1,0,0,0),v=new t.Mesh(g,n);o.modelListeners.push((function(){v.scale.x=(o.slim?3:4)-h,v.scale.y=12-h,v.scale.z=4-h,o.slim?s(g,i(44,16,47,20),i(47,16,50,20),i(40,20,44,32),i(44,20,47,32),i(47,20,51,32),i(51,20,54,32)):s(g,i(44,16,48,20),i(48,16,52,20),i(40,20,44,32),i(44,20,48,32),i(48,20,52,32),i(52,20,56,32)),g.uvsNeedUpdate=!0,g.elementsNeedUpdate=!0}));var w=new t.BoxGeometry(1,1,1,0,0,0),b=new t.Mesh(w,a);b.renderOrder=1,o.modelListeners.push((function(){b.scale.x=(o.slim?3.375:4.5)-h,b.scale.y=13.5-h,b.scale.z=4.5-h,o.slim?s(w,i(44,32,47,36),i(47,32,50,36),i(40,36,44,48),i(44,36,47,48),i(47,36,51,48),i(51,36,54,48)):s(w,i(44,32,48,36),i(48,32,52,36),i(40,36,44,48),i(44,36,48,48),i(48,36,52,48),i(52,36,56,48)),w.uvsNeedUpdate=!0,w.elementsNeedUpdate=!0}));var M=new t.Group;M.add(v,b),M.position.y=-6,o.rightArm=new c(v,b),o.rightArm.name="rightArm",o.rightArm.add(M),o.rightArm.position.y=-4,o.modelListeners.push((function(){o.rightArm.position.x=o.slim?-5.5:-6})),o.add(o.rightArm);var E=new t.BoxGeometry(1,1,1,0,0,0),x=new t.Mesh(E,n);o.modelListeners.push((function(){x.scale.x=(o.slim?3:4)-h,x.scale.y=12-h,x.scale.z=4-h,o.slim?s(E,i(36,48,39,52),i(39,48,42,52),i(32,52,36,64),i(36,52,39,64),i(39,52,43,64),i(43,52,46,64)):s(E,i(36,48,40,52),i(40,48,44,52),i(32,52,36,64),i(36,52,40,64),i(40,52,44,64),i(44,52,48,64)),E.uvsNeedUpdate=!0,E.elementsNeedUpdate=!0}));var O=new t.BoxGeometry(1,1,1,0,0,0),L=new t.Mesh(O,a);L.renderOrder=1,o.modelListeners.push((function(){L.scale.x=(o.slim?3.375:4.5)-h,L.scale.y=13.5-h,L.scale.z=4.5-h,o.slim?s(O,i(52,48,55,52),i(55,48,58,52),i(48,52,52,64),i(52,52,55,64),i(55,52,59,64),i(59,52,62,64)):s(O,i(52,48,56,52),i(56,48,60,52),i(48,52,52,64),i(52,52,56,64),i(56,52,60,64),i(60,52,64,64)),O.uvsNeedUpdate=!0,O.elementsNeedUpdate=!0}));var P=new t.Group;P.add(x,L),P.position.y=-6,o.leftArm=new c(x,L),o.leftArm.name="leftArm",o.leftArm.add(P),o.leftArm.position.y=-4,o.modelListeners.push((function(){o.leftArm.position.x=o.slim?5.5:6})),o.add(o.leftArm);var A=new t.BoxGeometry(4-h,12-h,4-h,0,0,0);s(A,i(4,16,8,20),i(8,16,12,20),i(0,20,4,32),i(4,20,8,32),i(8,20,12,32),i(12,20,16,32));var k=new t.Mesh(A,n),S=new t.BoxGeometry(4.5-h,13.5-h,4.5-h,0,0,0);s(S,i(4,32,8,36),i(8,32,12,36),i(0,36,4,48),i(4,36,8,48),i(8,36,12,48),i(12,36,16,48));var T=new t.Mesh(S,a);T.renderOrder=1;var j=new t.Group;j.add(k,T),j.position.y=-6,o.rightLeg=new c(k,T),o.rightLeg.name="rightLeg",o.rightLeg.add(j),o.rightLeg.position.y=-16,o.rightLeg.position.x=-2,o.add(o.rightLeg);var D=new t.BoxGeometry(4-h,12-h,4-h,0,0,0);s(D,i(20,48,24,52),i(24,48,28,52),i(16,52,20,64),i(20,52,24,64),i(24,52,28,64),i(28,52,32,64));var U=new t.Mesh(D,n),I=new t.BoxGeometry(4.5-h,13.5-h,4.5-h,0,0,0);s(I,i(4,48,8,52),i(8,48,12,52),i(0,52,4,64),i(4,52,8,64),i(8,52,12,64),i(12,52,16,64));var V=new t.Mesh(I,a);V.renderOrder=1;var C=new t.Group;return C.add(U,V),C.position.y=-6,o.leftLeg=new c(U,V),o.leftLeg.name="leftLeg",o.leftLeg.add(C),o.leftLeg.position.y=-16,o.leftLeg.position.x=2,o.add(o.leftLeg),o.slim=!1,o}return a(n,e),Object.defineProperty(n.prototype,"slim",{get:function(){return this._slim},set:function(e){this._slim=e,this.modelListeners.forEach((function(e){return e()}))},enumerable:!0,configurable:!0}),n.prototype.getBodyParts=function(){return this.children.filter((function(e){return e instanceof c}))},n.prototype.setInnerLayerVisible=function(e){this.getBodyParts().forEach((function(t){return t.innerLayer.visible=e}))},n.prototype.setOuterLayerVisible=function(e){this.getBodyParts().forEach((function(t){return t.outerLayer.visible=e}))},n}(t.Group),l=function(e){function n(n){var a=e.call(this)||this,o=new t.BoxGeometry(10,16,1,0,0,0);return s(o,r(1,0,11,1),r(11,0,21,1),r(11,1,12,17),r(12,1,22,17),r(0,1,1,17),r(1,1,11,17)),a.cape=new t.Mesh(o,n),a.cape.position.y=-8,a.cape.position.z=-.5,a.add(a.cape),a}return a(n,e),n}(t.Group),p=function(e){function t(t,n,a){var o=e.call(this)||this;return o.skin=new d(t,n),o.skin.name="skin",o.skin.visible=!1,o.add(o.skin),o.cape=new l(a),o.cape.name="cape",o.cape.position.z=-2,o.cape.position.y=-4,o.cape.rotation.x=25*Math.PI/180,o.cape.visible=!1,o.add(o.cape),o}return a(t,e),t}(t.Group);function u(e,t,n){e instanceof Function?e(t,n):e.play(t,n)}var m=function(){function e(e){this.speed=1,this.paused=!1,this.progress=0,this.lastTime=0,this.started=!1,this.toResetAndRemove=!1,this.animation=e}return e.prototype.play=function(e,t){if(this.toResetAndRemove)return u(this.animation,e,0),void this.remove();var n;this.started?n=t-this.lastTime:(n=0,this.started=!0),this.lastTime=t,this.paused||(this.progress+=n*this.speed),u(this.animation,e,this.progress)},e.prototype.reset=function(){this.progress=0},e.prototype.remove=function(){},e.prototype.resetAndRemove=function(){this.toResetAndRemove=!0},e}(),f=function(){function e(){this.handles=new Set}return e.prototype.add=function(e){var t=this,n=new m(e);return n.remove=function(){t.handles.delete(n)},this.handles.add(n),n},e.prototype.play=function(e,t){this.handles.forEach((function(n){return n.play(e,t)}))},e}(),y=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.speed=1,n.progress=0,n.clock=new t.Clock(!0),n}return a(n,e),Object.defineProperty(n.prototype,"animation",{get:function(){return this},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"paused",{get:function(){return!this.clock.running},set:function(e){e?this.clock.stop():this.clock.start()},enumerable:!0,configurable:!0}),n.prototype.runAnimationLoop=function(e){0!==this.handles.size&&(this.progress+=this.clock.getDelta()*this.speed,this.play(e,this.progress))},n.prototype.reset=function(){this.progress=0},n}(f);function g(e,t,n,a,o){for(var i=e.getImageData(t,n,a,o),r=0;r0?i.dollyIn(i.getZoomScale()):i.dollyDelta.y<0&&i.dollyOut(i.getZoomScale()),i.dollyStart.copy(i.dollyEnd),i.update()}else if(i.state===x.PAN){if(!1===i.enablePan)return;i.panEnd.set(e.clientX,e.clientY),i.panDelta.subVectors(i.panEnd,i.panStart),i.pan(i.panDelta.x,i.panDelta.y),i.panStart.copy(i.panEnd),i.update()}},i.onMouseUp=function(e){!1!==i.enabled&&(document.removeEventListener("mousemove",i.onMouseMove,!1),document.removeEventListener("mouseup",i.onMouseUp,!1),i.dispatchEvent(P),i.state=x.NONE)},i.onMouseWheel=function(e){!1===i.enabled||!1===i.enableZoom||i.state!==x.NONE&&i.state!==x.ROTATE||(e.preventDefault(),e.stopPropagation(),e.deltaY<0?i.dollyOut(i.getZoomScale()):e.deltaY>0&&i.dollyIn(i.getZoomScale()),i.update(),i.dispatchEvent(L),i.dispatchEvent(P))},i.onKeyDown=function(e){if(!1!==i.enabled&&!1!==i.enableKeys&&!1!==i.enablePan)switch(e.keyCode){case i.keys.UP:i.pan(0,i.keyPanSpeed),i.update();break;case i.keys.BOTTOM:i.pan(0,-i.keyPanSpeed),i.update();break;case i.keys.LEFT:i.pan(i.keyPanSpeed,0),i.update();break;case i.keys.RIGHT:i.pan(-i.keyPanSpeed,0),i.update()}},i.onTouchStart=function(e){if(!1!==i.enabled){switch(e.touches.length){case 1:if(!1===i.enableRotate)return;i.rotateStart.set(e.touches[0].pageX,e.touches[0].pageY),i.state=x.TOUCH_ROTATE;break;case 2:if(!1===i.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);i.dollyStart.set(0,a),i.state=x.TOUCH_DOLLY;break;case 3:if(!1===i.enablePan)return;i.panStart.set(e.touches[0].pageX,e.touches[0].pageY),i.state=x.TOUCH_PAN;break;default:i.state=x.NONE}i.state!==x.NONE&&i.dispatchEvent(L)}},i.onTouchMove=function(e){if(!1!==i.enabled)switch(e.preventDefault(),e.stopPropagation(),e.touches.length){case 1:if(!1===i.enableRotate)return;if(i.state!==x.TOUCH_ROTATE)return;i.rotateEnd.set(e.touches[0].pageX,e.touches[0].pageY),i.rotateDelta.subVectors(i.rotateEnd,i.rotateStart);var t=i.domElement===document?i.domElement.body:i.domElement;i.rotateLeft(2*Math.PI*i.rotateDelta.x/t.clientWidth*i.rotateSpeed),i.rotateUp(2*Math.PI*i.rotateDelta.y/t.clientHeight*i.rotateSpeed),i.rotateStart.copy(i.rotateEnd),i.update();break;case 2:if(!1===i.enableZoom)return;if(i.state!==x.TOUCH_DOLLY)return;var n=e.touches[0].pageX-e.touches[1].pageX,a=e.touches[0].pageY-e.touches[1].pageY,o=Math.sqrt(n*n+a*a);i.dollyEnd.set(0,o),i.dollyDelta.subVectors(i.dollyEnd,i.dollyStart),i.dollyDelta.y>0?i.dollyOut(i.getZoomScale()):i.dollyDelta.y<0&&i.dollyIn(i.getZoomScale()),i.dollyStart.copy(i.dollyEnd),i.update();break;case 3:if(!1===i.enablePan)return;if(i.state!==x.TOUCH_PAN)return;i.panEnd.set(e.touches[0].pageX,e.touches[0].pageY),i.panDelta.subVectors(i.panEnd,i.panStart),i.pan(i.panDelta.x,i.panDelta.y),i.panStart.copy(i.panEnd),i.update();break;default:i.state=x.NONE}},i.onTouchEnd=function(e){!1!==i.enabled&&(i.dispatchEvent(P),i.state=x.NONE)},i.onContextMenu=function(e){e.preventDefault()},i.domElement.addEventListener("contextmenu",i.onContextMenu,!1),i.domElement.addEventListener("mousedown",i.onMouseDown,!1),i.domElement.addEventListener("wheel",i.onMouseWheel,!1),i.domElement.addEventListener("touchstart",i.onTouchStart,!1),i.domElement.addEventListener("touchend",i.onTouchEnd,!1),i.domElement.addEventListener("touchmove",i.onTouchMove,!1),i.window.addEventListener("keydown",i.onKeyDown,!1),i.update(),i}return a(n,e),n.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===x.NONE&&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||this.updateLastPosition.distanceToSquared(this.object.position)>1e-6||8*(1-this.updateLastQuaternion.dot(this.object.quaternion))>1e-6)&&(this.dispatchEvent(O),this.updateLastPosition.copy(this.object.position),this.updateLastQuaternion.copy(this.object.quaternion),this.zoomChanged=!1,!0)},n.prototype.panLeft=function(e,t){this.panLeftV.setFromMatrixColumn(t,0),this.panLeftV.multiplyScalar(-e),this.panOffset.add(this.panLeftV)},n.prototype.panUp=function(e,t){this.panUpV.setFromMatrixColumn(t,1),this.panUpV.multiplyScalar(e),this.panOffset.add(this.panUpV)},n.prototype.pan=function(e,n){var a=this.domElement===document?this.domElement.body:this.domElement;if(this.object instanceof t.PerspectiveCamera){var o=this.object.position;this.panInternalOffset.copy(o).sub(this.target);var i=this.panInternalOffset.length();i*=Math.tan(this.object.fov/2*Math.PI/180),this.panLeft(2*e*i/a.clientHeight,this.object.matrix),this.panUp(2*n*i/a.clientHeight,this.object.matrix)}else this.object instanceof t.OrthographicCamera?(this.panLeft(e*(this.object.right-this.object.left)/this.object.zoom/a.clientWidth,this.object.matrix),this.panUp(n*(this.object.top-this.object.bottom)/this.object.zoom/a.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)},n.prototype.dollyIn=function(e){this.object instanceof t.PerspectiveCamera?this.scale/=e:this.object instanceof t.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)},n.prototype.dollyOut=function(e){this.object instanceof t.PerspectiveCamera?this.scale*=e:this.object instanceof t.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)},n.prototype.getAutoRotationAngle=function(){return 2*Math.PI/60/60*this.autoRotateSpeed},n.prototype.getZoomScale=function(){return Math.pow(.95,this.zoomSpeed)},n.prototype.rotateLeft=function(e){this.sphericalDelta.theta-=e},n.prototype.rotateUp=function(e){this.sphericalDelta.phi-=e},n.prototype.getPolarAngle=function(){return this.spherical.phi},n.prototype.getAzimuthalAngle=function(){return this.spherical.theta},n.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)},n.prototype.reset=function(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(O),this.update(),this.state=x.NONE},n}(t.EventDispatcher);e.BodyPart=c,e.CapeObject=l,e.CompositeAnimation=f,e.OrbitControls=A,e.PlayerObject=p,e.RootAnimation=y,e.RotatingAnimation=function(e,t){e.rotation.y=t},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.SkinObject=d,e.SkinViewer=E,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.createOrbitControls=function(e){var n=new A(e.camera,e.renderer.domElement);return n.enablePan=!1,n.target=new t.Vector3(0,-12,0),n.minDistance=10,n.maxDistance=256,n.update(),n},e.invokeAnimation=u,e.isSlimSkin=M,Object.defineProperty(e,"__esModule",{value:!0})}));