3 lines
24 KiB
JavaScript
3 lines
24 KiB
JavaScript
/* @preserve skinview3d / MIT License / https://github.com/bs-community/skinview3d */
|
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("three")):"function"==typeof define&&define.amd?define(["exports","three"],e):e((t=t||self).skinview3d={},t.THREE)}(this,(function(t,e){"use strict";function s(t,s,i,a,n,h){return[new e.Vector2(t/n,1-a/h),new e.Vector2(i/n,1-a/h),new e.Vector2(i/n,1-s/h),new e.Vector2(t/n,1-s/h)]}function i(t,e,i,a){return s(t,e,i,a,64,64)}function a(t,e,i,a){return s(t,e,i,a,64,32)}function n(t,e,s,i,a,n,h){t.faceVertexUvs[0]=[],t.faceVertexUvs[0][0]=[n[3],n[0],n[2]],t.faceVertexUvs[0][1]=[n[0],n[1],n[2]],t.faceVertexUvs[0][2]=[i[3],i[0],i[2]],t.faceVertexUvs[0][3]=[i[0],i[1],i[2]],t.faceVertexUvs[0][4]=[e[3],e[0],e[2]],t.faceVertexUvs[0][5]=[e[0],e[1],e[2]],t.faceVertexUvs[0][6]=[s[0],s[3],s[1]],t.faceVertexUvs[0][7]=[s[3],s[2],s[1]],t.faceVertexUvs[0][8]=[a[3],a[0],a[2]],t.faceVertexUvs[0][9]=[a[0],a[1],a[2]],t.faceVertexUvs[0][10]=[h[3],h[0],h[2]],t.faceVertexUvs[0][11]=[h[0],h[1],h[2]]}const h=.002;class o extends e.Group{constructor(t,e){super(),this.innerLayer=t,this.outerLayer=e,t.name="inner",e.name="outer"}}class r extends e.Group{constructor(t){super(),this.modelListeners=[],this._slim=!1;const s=new e.MeshBasicMaterial({map:t,side:e.FrontSide}),a=new e.MeshBasicMaterial({map:t,transparent:!0,opacity:1,side:e.DoubleSide,alphaTest:.5}),r=new e.BoxGeometry(8,8,8,0,0,0);n(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));const d=new e.Mesh(r,s),c=new e.BoxGeometry(9,9,9,0,0,0);n(c,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));const l=new e.Mesh(c,a);l.renderOrder=-1,this.head=new o(d,l),this.head.name="head",this.head.add(d,l),this.add(this.head);const p=new e.BoxGeometry(8,12,4,0,0,0);n(p,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));const m=new e.Mesh(p,s),u=new e.BoxGeometry(9,13.5,4.5,0,0,0);n(u,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));const g=new e.Mesh(u,a);this.body=new o(m,g),this.body.name="body",this.body.add(m,g),this.body.position.y=-10,this.add(this.body);const f=new e.BoxGeometry(1,1,1,0,0,0),w=new e.Mesh(f,s);this.modelListeners.push(()=>{w.scale.x=(this.slim?3:4)-h,w.scale.y=11.998,w.scale.z=3.998,this.slim?n(f,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)):n(f,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)),f.uvsNeedUpdate=!0,f.elementsNeedUpdate=!0});const y=new e.BoxGeometry(1,1,1,0,0,0),b=new e.Mesh(y,a);b.renderOrder=1,this.modelListeners.push(()=>{b.scale.x=(this.slim?3.375:4.5)-h,b.scale.y=13.498,b.scale.z=4.498,this.slim?n(y,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)):n(y,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)),y.uvsNeedUpdate=!0,y.elementsNeedUpdate=!0});const v=new e.Group;v.add(w,b),v.position.y=-6,this.rightArm=new o(w,b),this.rightArm.name="rightArm",this.rightArm.add(v),this.rightArm.position.y=-4,this.modelListeners.push(()=>{this.rightArm.position.x=this.slim?-5.5:-6}),this.add(this.rightArm);const M=new e.BoxGeometry(1,1,1,0,0,0),x=new e.Mesh(M,s);this.modelListeners.push(()=>{x.scale.x=(this.slim?3:4)-h,x.scale.y=11.998,x.scale.z=3.998,this.slim?n(M,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)):n(M,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)),M.uvsNeedUpdate=!0,M.elementsNeedUpdate=!0});const E=new e.BoxGeometry(1,1,1,0,0,0),L=new e.Mesh(E,a);L.renderOrder=1,this.modelListeners.push(()=>{L.scale.x=(this.slim?3.375:4.5)-h,L.scale.y=13.498,L.scale.z=4.498,this.slim?n(E,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)):n(E,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)),E.uvsNeedUpdate=!0,E.elementsNeedUpdate=!0});const k=new e.Group;k.add(x,L),k.position.y=-6,this.leftArm=new o(x,L),this.leftArm.name="leftArm",this.leftArm.add(k),this.leftArm.position.y=-4,this.modelListeners.push(()=>{this.leftArm.position.x=this.slim?5.5:6}),this.add(this.leftArm);const S=new e.BoxGeometry(3.998,11.998,3.998,0,0,0);n(S,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));const P=new e.Mesh(S,s),A=new e.BoxGeometry(4.498,13.498,4.498,0,0,0);n(A,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));const I=new e.Mesh(A,a);I.renderOrder=1;const O=new e.Group;O.add(P,I),O.position.y=-6,this.rightLeg=new o(P,I),this.rightLeg.name="rightLeg",this.rightLeg.add(O),this.rightLeg.position.y=-16,this.rightLeg.position.x=-2,this.add(this.rightLeg);const j=new e.BoxGeometry(3.998,11.998,3.998,0,0,0);n(j,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));const D=new e.Mesh(j,s),V=new e.BoxGeometry(4.498,13.498,4.498,0,0,0);n(V,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));const U=new e.Mesh(V,a);U.renderOrder=1;const z=new e.Group;z.add(D,U),z.position.y=-6,this.leftLeg=new o(D,U),this.leftLeg.name="leftLeg",this.leftLeg.add(z),this.leftLeg.position.y=-16,this.leftLeg.position.x=2,this.add(this.leftLeg),this.slim=!1}get slim(){return this._slim}set slim(t){this._slim=t,this.modelListeners.forEach(t=>t())}getBodyParts(){return this.children.filter(t=>t instanceof o)}setInnerLayerVisible(t){this.getBodyParts().forEach(e=>e.innerLayer.visible=t)}setOuterLayerVisible(t){this.getBodyParts().forEach(e=>e.outerLayer.visible=t)}}class d extends e.Group{constructor(t){super();const s=new e.MeshBasicMaterial({map:t,transparent:!0,opacity:1,side:e.DoubleSide,alphaTest:.5}),i=new e.BoxGeometry(10,16,1,0,0,0);n(i,a(1,0,11,1),a(11,0,21,1),a(11,1,12,17),a(12,1,22,17),a(0,1,1,17),a(1,1,11,17)),this.cape=new e.Mesh(i,s),this.cape.position.y=-8,this.cape.position.z=-.5,this.add(this.cape)}}class c extends e.Group{constructor(t,e){super(),this.skin=new r(t),this.skin.name="skin",this.add(this.skin),this.cape=new d(e),this.cape.name="cape",this.cape.position.z=-2,this.cape.position.y=-4,this.cape.rotation.x=25*Math.PI/180,this.add(this.cape)}}function l(t,e,s){t instanceof Function?t(e,s):t.play(e,s)}class p{constructor(t){this.speed=1,this.paused=!1,this.progress=0,this.lastTime=0,this.started=!1,this.toResetAndRemove=!1,this.animation=t}play(t,e){if(this.toResetAndRemove)return l(this.animation,t,0),void this.remove();let s;this.started?s=e-this.lastTime:(s=0,this.started=!0),this.lastTime=e,this.paused||(this.progress+=s*this.speed),l(this.animation,t,this.progress)}reset(){this.progress=0}remove(){}resetAndRemove(){this.toResetAndRemove=!0}}class m{constructor(){this.handles=new Set}add(t){const e=new p(t);return e.remove=()=>{this.handles.delete(e)},this.handles.add(e),e}play(t,e){this.handles.forEach(s=>s.play(t,e))}}class u extends m{constructor(){super(...arguments),this.speed=1,this.progress=0,this.clock=new e.Clock(!0)}get animation(){return this}get paused(){return!this.clock.running}set paused(t){t?this.clock.stop():this.clock.start()}runAnimationLoop(t){0!==this.handles.size&&(this.progress+=this.clock.getDelta()*this.speed,this.play(t,this.progress))}reset(){this.progress=0}}function g(t,e,s,i,a){for(var n=t.getImageData(e,s,i,a),h=0;h<i;h++)for(var o=0;o<a;o++){var r=4*(h+o*i);if(255!==n.data[r+3])return!0}return!1}function f(t){return t/64}function w(t,e){var s=f(e),i=function(e,i,a,n,h,o,r){return function(t,e,s,i,a,n,h,o){var r=t.getImageData(e,s,i,a);if(o)for(var d=0;d<a;d++)for(var c=0;c<i/2;c++){var l=4*(c+d*i),p=4*(i-c-1+d*i),m=r.data[l],u=r.data[l+1],g=r.data[l+2],f=r.data[l+3],w=r.data[p],y=r.data[p+1],b=r.data[p+2],v=r.data[p+3];r.data[l]=w,r.data[l+1]=y,r.data[l+2]=b,r.data[l+3]=v,r.data[p]=m,r.data[p+1]=u,r.data[p+2]=g,r.data[p+3]=f}t.putImageData(r,n,h)}(t,e*s,i*s,a*s,n*s,h*s,o*s,r)};!function(t,e){if(!g(t,0,0,e,e/2)){var s=f(e),i=function(e,i,a,n){return t.clearRect(e*s,i*s,a*s,n*s)};i(40,0,8,8),i(48,0,8,8),i(32,8,8,8),i(40,8,8,8),i(48,8,8,8),i(56,8,8,8)}}(t,e),i(4,16,4,4,20,48,!0),i(8,16,4,4,24,48,!0),i(0,20,4,12,24,52,!0),i(4,20,4,12,20,52,!0),i(8,20,4,12,16,52,!0),i(12,20,4,12,28,52,!0),i(44,16,4,4,36,48,!0),i(48,16,4,4,40,48,!0),i(40,20,4,12,40,52,!0),i(44,20,4,12,36,52,!0),i(48,20,4,12,32,52,!0),i(52,20,4,12,44,52,!0)}const y=-1,b=0,v=1,M=2,x=3,E=4,L=5,k={type:"change"},S={type:"start"},P={type:"end"};class A extends e.EventDispatcher{constructor(t,s,i){super(),this.object=t,this.domElement=s,this.window=void 0!==i?i:window,this.enabled=!0,this.target=new e.Vector3,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.25,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.enablePan=!0,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.enableKeys=!0,this.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40},this.mouseButtons={ORBIT:e.MOUSE.LEFT,ZOOM:e.MOUSE.MIDDLE,PAN:e.MOUSE.RIGHT},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this.updateOffset=new e.Vector3,this.updateQuat=(new e.Quaternion).setFromUnitVectors(t.up,new e.Vector3(0,1,0)),this.updateQuatInverse=this.updateQuat.clone().inverse(),this.updateLastPosition=new e.Vector3,this.updateLastQuaternion=new e.Quaternion,this.state=y,this.scale=1,this.spherical=new e.Spherical,this.sphericalDelta=new e.Spherical,this.panOffset=new e.Vector3,this.zoomChanged=!1,this.rotateStart=new e.Vector2,this.rotateEnd=new e.Vector2,this.rotateDelta=new e.Vector2,this.panStart=new e.Vector2,this.panEnd=new e.Vector2,this.panDelta=new e.Vector2,this.dollyStart=new e.Vector2,this.dollyEnd=new e.Vector2,this.dollyDelta=new e.Vector2,this.panLeftV=new e.Vector3,this.panUpV=new e.Vector3,this.panInternalOffset=new e.Vector3,this.onMouseDown=t=>{if(!1!==this.enabled){if(t.preventDefault(),t.button===this.mouseButtons.ORBIT){if(!1===this.enableRotate)return;this.rotateStart.set(t.clientX,t.clientY),this.state=b}else if(t.button===this.mouseButtons.ZOOM){if(!1===this.enableZoom)return;this.dollyStart.set(t.clientX,t.clientY),this.state=v}else if(t.button===this.mouseButtons.PAN){if(!1===this.enablePan)return;this.panStart.set(t.clientX,t.clientY),this.state=M}this.state!==y&&(document.addEventListener("mousemove",this.onMouseMove,!1),document.addEventListener("mouseup",this.onMouseUp,!1),this.dispatchEvent(S))}},this.onMouseMove=t=>{if(!1!==this.enabled)if(t.preventDefault(),this.state===b){if(!1===this.enableRotate)return;this.rotateEnd.set(t.clientX,t.clientY),this.rotateDelta.subVectors(this.rotateEnd,this.rotateStart),this.rotateLeft(2*Math.PI*this.rotateDelta.x/this.domElement.clientWidth*this.rotateSpeed),this.rotateUp(2*Math.PI*this.rotateDelta.y/this.domElement.clientHeight*this.rotateSpeed),this.rotateStart.copy(this.rotateEnd),this.update()}else if(this.state===v){if(!1===this.enableZoom)return;this.dollyEnd.set(t.clientX,t.clientY),this.dollyDelta.subVectors(this.dollyEnd,this.dollyStart),this.dollyDelta.y>0?this.dollyIn(this.getZoomScale()):this.dollyDelta.y<0&&this.dollyOut(this.getZoomScale()),this.dollyStart.copy(this.dollyEnd),this.update()}else if(this.state===M){if(!1===this.enablePan)return;this.panEnd.set(t.clientX,t.clientY),this.panDelta.subVectors(this.panEnd,this.panStart),this.pan(this.panDelta.x,this.panDelta.y),this.panStart.copy(this.panEnd),this.update()}},this.onMouseUp=()=>{!1!==this.enabled&&(document.removeEventListener("mousemove",this.onMouseMove,!1),document.removeEventListener("mouseup",this.onMouseUp,!1),this.dispatchEvent(P),this.state=y)},this.onMouseWheel=t=>{!1===this.enabled||!1===this.enableZoom||this.state!==y&&this.state!==b||(t.preventDefault(),t.stopPropagation(),t.deltaY<0?this.dollyOut(this.getZoomScale()):t.deltaY>0&&this.dollyIn(this.getZoomScale()),this.update(),this.dispatchEvent(S),this.dispatchEvent(P))},this.onKeyDown=t=>{if(!1!==this.enabled&&!1!==this.enableKeys&&!1!==this.enablePan)switch(t.keyCode){case this.keys.UP:this.pan(0,this.keyPanSpeed),this.update();break;case this.keys.BOTTOM:this.pan(0,-this.keyPanSpeed),this.update();break;case this.keys.LEFT:this.pan(this.keyPanSpeed,0),this.update();break;case this.keys.RIGHT:this.pan(-this.keyPanSpeed,0),this.update()}},this.onTouchStart=t=>{if(!1!==this.enabled){switch(t.touches.length){case 1:if(!1===this.enableRotate)return;this.rotateStart.set(t.touches[0].pageX,t.touches[0].pageY),this.state=x;break;case 2:{if(!1===this.enableZoom)return;const e=t.touches[0].pageX-t.touches[1].pageX,s=t.touches[0].pageY-t.touches[1].pageY,i=Math.sqrt(e*e+s*s);this.dollyStart.set(0,i),this.state=E;break}case 3:if(!1===this.enablePan)return;this.panStart.set(t.touches[0].pageX,t.touches[0].pageY),this.state=L;break;default:this.state=y}this.state!==y&&this.dispatchEvent(S)}},this.onTouchMove=t=>{if(!1!==this.enabled)switch(t.preventDefault(),t.stopPropagation(),t.touches.length){case 1:if(!1===this.enableRotate)return;if(this.state!==x)return;this.rotateEnd.set(t.touches[0].pageX,t.touches[0].pageY),this.rotateDelta.subVectors(this.rotateEnd,this.rotateStart),this.rotateLeft(2*Math.PI*this.rotateDelta.x/this.domElement.clientWidth*this.rotateSpeed),this.rotateUp(2*Math.PI*this.rotateDelta.y/this.domElement.clientHeight*this.rotateSpeed),this.rotateStart.copy(this.rotateEnd),this.update();break;case 2:{if(!1===this.enableZoom)return;if(this.state!==E)return;const e=t.touches[0].pageX-t.touches[1].pageX,s=t.touches[0].pageY-t.touches[1].pageY,i=Math.sqrt(e*e+s*s);this.dollyEnd.set(0,i),this.dollyDelta.subVectors(this.dollyEnd,this.dollyStart),this.dollyDelta.y>0?this.dollyOut(this.getZoomScale()):this.dollyDelta.y<0&&this.dollyIn(this.getZoomScale()),this.dollyStart.copy(this.dollyEnd),this.update();break}case 3:if(!1===this.enablePan)return;if(this.state!==L)return;this.panEnd.set(t.touches[0].pageX,t.touches[0].pageY),this.panDelta.subVectors(this.panEnd,this.panStart),this.pan(this.panDelta.x,this.panDelta.y),this.panStart.copy(this.panEnd),this.update();break;default:this.state=y}},this.onTouchEnd=()=>{!1!==this.enabled&&(this.dispatchEvent(P),this.state=y)},this.onContextMenu=t=>{t.preventDefault()},this.domElement.addEventListener("contextmenu",this.onContextMenu,!1),this.domElement.addEventListener("mousedown",this.onMouseDown,!1),this.domElement.addEventListener("wheel",this.onMouseWheel,!1),this.domElement.addEventListener("touchstart",this.onTouchStart,!1),this.domElement.addEventListener("touchend",this.onTouchEnd,!1),this.domElement.addEventListener("touchmove",this.onTouchMove,!1),this.window.addEventListener("keydown",this.onKeyDown,!1),this.update()}update(){const t=this.object.position;return this.updateOffset.copy(t).sub(this.target),this.updateOffset.applyQuaternion(this.updateQuat),this.spherical.setFromVector3(this.updateOffset),this.autoRotate&&this.state===y&&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),t.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(k),this.updateLastPosition.copy(this.object.position),this.updateLastQuaternion.copy(this.object.quaternion),this.zoomChanged=!1,!0)}panLeft(t,e){this.panLeftV.setFromMatrixColumn(e,0),this.panLeftV.multiplyScalar(-t),this.panOffset.add(this.panLeftV)}panUp(t,e){this.panUpV.setFromMatrixColumn(e,1),this.panUpV.multiplyScalar(t),this.panOffset.add(this.panUpV)}pan(t,s){if(this.object instanceof e.PerspectiveCamera){const e=this.object.position;this.panInternalOffset.copy(e).sub(this.target);let i=this.panInternalOffset.length();i*=Math.tan(this.object.fov/2*Math.PI/180),this.panLeft(2*t*i/this.domElement.clientHeight,this.object.matrix),this.panUp(2*s*i/this.domElement.clientHeight,this.object.matrix)}else this.object instanceof e.OrthographicCamera?(this.panLeft(t*(this.object.right-this.object.left)/this.object.zoom/this.domElement.clientWidth,this.object.matrix),this.panUp(s*(this.object.top-this.object.bottom)/this.object.zoom/this.domElement.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}dollyIn(t){this.object instanceof e.PerspectiveCamera?this.scale/=t:this.object instanceof e.OrthographicCamera?(this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom*t)),this.object.updateProjectionMatrix(),this.zoomChanged=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}dollyOut(t){this.object instanceof e.PerspectiveCamera?this.scale*=t:this.object instanceof e.OrthographicCamera?(this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/t)),this.object.updateProjectionMatrix(),this.zoomChanged=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}getAutoRotationAngle(){return 2*Math.PI/60/60*this.autoRotateSpeed}getZoomScale(){return Math.pow(.95,this.zoomSpeed)}rotateLeft(t){this.sphericalDelta.theta-=t}rotateUp(t){this.sphericalDelta.phi-=t}getPolarAngle(){return this.spherical.phi}getAzimuthalAngle(){return this.spherical.theta}dispose(){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)}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(k),this.update(),this.state=y}}t.BodyPart=o,t.CapeObject=d,t.CompositeAnimation=m,t.OrbitControls=A,t.PlayerObject=c,t.RootAnimation=u,t.RotatingAnimation=(t,e)=>{t.rotation.y=e},t.RunningAnimation=(t,e)=>{const s=t.skin;e*=15,s.leftLeg.rotation.x=1.3*Math.cos(e+Math.PI),s.rightLeg.rotation.x=1.3*Math.cos(e),s.leftArm.rotation.x=1.5*Math.cos(e),s.rightArm.rotation.x=1.5*Math.cos(e+Math.PI);const i=.1*Math.PI;s.leftArm.rotation.z=.1*Math.cos(e)+i,s.rightArm.rotation.z=.1*Math.cos(e+Math.PI)-i,t.position.y=Math.cos(2*e),t.position.x=.15*Math.cos(e),t.rotation.z=.01*Math.cos(e+Math.PI);const a=.3*Math.PI;t.cape.rotation.x=.1*Math.sin(2*e)+a},t.SkinObject=r,t.SkinViewer=class{constructor(t){this.animations=new u,this.detectModel=!0,this.disposed=!1,this._renderPaused=!1,this.domElement=t.domElement,!1===t.detectModel&&(this.detectModel=!1),this.skinImg=new Image,this.skinCanvas=document.createElement("canvas"),this.skinTexture=new e.Texture(this.skinCanvas),this.skinTexture.magFilter=e.NearestFilter,this.skinTexture.minFilter=e.NearestFilter,this.capeImg=new Image,this.capeCanvas=document.createElement("canvas"),this.capeTexture=new e.Texture(this.capeCanvas),this.capeTexture.magFilter=e.NearestFilter,this.capeTexture.minFilter=e.NearestFilter,this.scene=new e.Scene,this.camera=new e.PerspectiveCamera(40),this.camera.position.y=-12,this.camera.position.z=60,this.renderer=new e.WebGLRenderer({alpha:!0,antialias:!1}),this.renderer.setSize(300,300),this.domElement.appendChild(this.renderer.domElement),this.playerObject=new c(this.skinTexture,this.capeTexture),this.playerObject.name="player",this.playerObject.skin.visible=!1,this.playerObject.cape.visible=!1,this.scene.add(this.playerObject),this.skinImg.crossOrigin="anonymous",this.skinImg.onerror=()=>console.error("Failed loading "+this.skinImg.src),this.skinImg.onload=()=>{var t,e,s,i;!function(t,e){var s=!1;if(e.width!==e.height){if(e.width!==2*e.height)throw new Error("Bad skin size: "+e.width+"x"+e.height);s=!0}var i=t.getContext("2d");if(s){var a=e.width;t.width=a,t.height=a,i.clearRect(0,0,a,a),i.drawImage(e,0,0,a,a/2),w(i,a)}else t.width=e.width,t.height=e.height,i.clearRect(0,0,e.width,e.height),i.drawImage(e,0,0,t.width,t.height)}(this.skinCanvas,this.skinImg),this.detectModel&&(this.playerObject.skin.slim=(t=this.skinCanvas,e=f(t.width),s=t.getContext("2d"),(i=function(t,i,a,n){return g(s,t*e,i*e,a*e,n*e)})(50,16,2,4)||i(54,20,2,12)||i(42,48,2,4)||i(46,52,2,12))),this.skinTexture.needsUpdate=!0,this.playerObject.skin.visible=!0},this.capeImg.crossOrigin="anonymous",this.capeImg.onerror=()=>console.error("Failed loading "+this.capeImg.src),this.capeImg.onload=()=>{!function(t,e){var s=!1;if(e.width!==2*e.height){if(17*e.width!=22*e.height)throw new Error("Bad cape size: "+e.width+"x"+e.height);s=!0}var i=t.getContext("2d");if(s){var a=64*e.width/22;t.width=a,t.height=a/2}else t.width=e.width,t.height=e.height;i.clearRect(0,0,t.width,t.height),i.drawImage(e,0,0,e.width,e.height)}(this.capeCanvas,this.capeImg),this.capeTexture.needsUpdate=!0,this.playerObject.cape.visible=!0},t.skinUrl&&(this.skinUrl=t.skinUrl),t.capeUrl&&(this.capeUrl=t.capeUrl),t.width&&(this.width=t.width),t.height&&(this.height=t.height),window.requestAnimationFrame(()=>this.draw())}draw(){this.disposed||this._renderPaused||(this.animations.runAnimationLoop(this.playerObject),this.renderer.render(this.scene,this.camera),window.requestAnimationFrame(()=>this.draw()))}setSize(t,e){this.camera.aspect=t/e,this.camera.updateProjectionMatrix(),this.renderer.setSize(t,e)}dispose(){this.disposed=!0,this.domElement.removeChild(this.renderer.domElement),this.renderer.dispose(),this.skinTexture.dispose(),this.capeTexture.dispose()}get renderPaused(){return this._renderPaused}set renderPaused(t){const e=!this.disposed&&!t&&this._renderPaused;this._renderPaused=t,e&&window.requestAnimationFrame(()=>this.draw())}get skinUrl(){return this.skinImg.src}set skinUrl(t){this.skinImg.src=t}get capeUrl(){return this.capeImg.src}set capeUrl(t){this.capeImg.src=t}get width(){const t=new e.Vector2;return this.renderer.getSize(t).width}set width(t){this.setSize(t,this.height)}get height(){const t=new e.Vector2;return this.renderer.getSize(t).height}set height(t){this.setSize(this.width,t)}},t.WalkingAnimation=(t,e)=>{const s=t.skin;e*=8,s.leftLeg.rotation.x=.5*Math.sin(e),s.rightLeg.rotation.x=.5*Math.sin(e+Math.PI),s.leftArm.rotation.x=.5*Math.sin(e+Math.PI),s.rightArm.rotation.x=.5*Math.sin(e);const i=.02*Math.PI;s.leftArm.rotation.z=.03*Math.cos(e)+i,s.rightArm.rotation.z=.03*Math.cos(e+Math.PI)-i,s.head.rotation.y=.2*Math.sin(e/4),s.head.rotation.x=.1*Math.sin(e/5);const a=.06*Math.PI;t.cape.rotation.x=.06*Math.sin(e/1.5)+a},t.createOrbitControls=function(t){const s=new A(t.camera,t.renderer.domElement);return s.enablePan=!1,s.target=new e.Vector3(0,-12,0),s.minDistance=10,s.maxDistance=256,s.update(),s},t.invokeAnimation=l,Object.defineProperty(t,"__esModule",{value:!0})}));//# sourceMappingURL=skinview3d.min.js.map
|