skinview3d/js/build/skinview3d.min.js

64 lines
24 KiB
JavaScript
Raw Normal View History

2018-02-11 17:01:28 +01:00
/**
* skinview3d (https://github.com/to2mbn/skinview3d)
*
* MIT License
*
2018-02-12 08:58:31 +01:00
* Copyright (c) 2014-2018 Kent Rasmussen
* Copyright (c) 2017-2018 Haowei Wen, Sean Boult and contributors
2018-02-11 17:01:28 +01:00
*
* 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.
*/
2018-07-06 09:32:14 +02:00
!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.element
/**
* @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
*/
2018-07-06 09:32:14 +02:00
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/zoo
//# sourceMappingURL=skinview3d.min.js.map