skinview3d
Advanced tools
Comparing version 1.1.0-alpha.4 to 1.1.0
@@ -703,3 +703,3 @@ /** | ||
this.animation = options.animation || null; | ||
this.detectModel = options.animation !== false; // true by default | ||
this.detectModel = options.detectModel !== false; // true by default | ||
this.animationPaused = false; | ||
@@ -706,0 +706,0 @@ this.animationTime = 0; |
@@ -28,3 +28,3 @@ /** | ||
!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.animation,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){ | ||
!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){ | ||
/** | ||
@@ -31,0 +31,0 @@ * @preserve |
@@ -28,3 +28,3 @@ /** | ||
import { Vector2, Group, BoxGeometry, Mesh, Texture, NearestFilter, MeshBasicMaterial, FrontSide, DoubleSide, Scene, PerspectiveCamera, WebGLRenderer, Vector3, MOUSE, Quaternion, Spherical, OrthographicCamera, EventDispatcher } from 'three'; | ||
import { Vector2, Group, BoxGeometry, Mesh, Vector3, MOUSE, Quaternion, Spherical, PerspectiveCamera, OrthographicCamera, EventDispatcher, Texture, NearestFilter, MeshBasicMaterial, FrontSide, DoubleSide, Scene, WebGLRenderer } from 'three'; | ||
@@ -700,3 +700,3 @@ var classCallCheck = function (instance, Constructor) { | ||
this.animation = options.animation || null; | ||
this.detectModel = options.animation !== false; // true by default | ||
this.detectModel = options.detectModel !== false; // true by default | ||
this.animationPaused = false; | ||
@@ -703,0 +703,0 @@ this.animationTime = 0; |
{ | ||
"name": "skinview3d", | ||
"version": "1.1.0-alpha.4", | ||
"version": "1.1.0", | ||
"description": "Three.js powered Minecraft skin viewer", | ||
@@ -10,3 +10,3 @@ "module": "build/skinview3d.module.js", | ||
"build": "rollup -c tools/rollup.module.js && rollup -c tools/rollup.browser.js && rollup -c tools/rollup.browser.min.js", | ||
"prepare": "npm test && rm -rf build && npm run build", | ||
"prepare": "npm test && rimraf build && npm run build", | ||
"test": "karma start && npm run lint", | ||
@@ -39,6 +39,6 @@ "lint": "eslint src/** tools/** && tslint -c tslint.json types/**.ts", | ||
"dependencies": { | ||
"three": "^0.94.0" | ||
"three": "^0.95.0" | ||
}, | ||
"devDependencies": { | ||
"@types/three": "^0.92.12", | ||
"@types/three": "^0.92.17", | ||
"babel-cli": "^6.26.0", | ||
@@ -48,22 +48,23 @@ "babel-plugin-external-helpers": "^6.22.0", | ||
"chai": "^4.1.2", | ||
"eslint": "^5.0.1", | ||
"karma": "^2.0.4", | ||
"eslint": "^5.4.0", | ||
"karma": "^3.0.0", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-mocha": "^1.3.0", | ||
"karma-webpack": "^3.0.0", | ||
"local-web-server": "^2.5.4", | ||
"local-web-server": "^2.6.0", | ||
"mocha": "^5.2.0", | ||
"npm-run-all": "^4.1.2", | ||
"puppeteer": "^1.5.0", | ||
"rollup": "^0.62.0", | ||
"rollup-plugin-babel": "^3.0.4", | ||
"npm-run-all": "^4.1.3", | ||
"puppeteer": "^1.7.0", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.64.1", | ||
"rollup-plugin-babel": "^3.0.7", | ||
"rollup-plugin-license": "^0.7.0", | ||
"rollup-plugin-node-resolve": "^3.3.0", | ||
"rollup-plugin-uglify": "^4.0.0", | ||
"tslint": "^5.10.0", | ||
"typescript": "^2.8.3", | ||
"tslint": "^5.11.0", | ||
"typescript": "^3.0.1", | ||
"uglify-es": "^3.3.10", | ||
"url-loader": "^1.0.1", | ||
"webpack": "^4.15.1" | ||
"url-loader": "^1.1.1", | ||
"webpack": "^4.16.5" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
417612
1
25
+ Addedthree@0.95.0(transitive)
- Removedthree@0.94.0(transitive)
Updatedthree@^0.95.0