2019-12-16 03:04:31 +08:00
( function ( h , l ) { "object" === typeof exports && "undefined" !== typeof module ? l ( exports ) : "function" === typeof define && define . amd ? define ( [ "exports" ] , l ) : l ( h . FIK = { } ) } ) ( this , function ( h ) { function l ( a , b ) { this . x = a || 0 ; this . y = b || 0 } function f ( a , b , c ) { this . x = a || 0 ; this . y = b || 0 ; this . z = c || 0 } function y ( ) { this . elements = [ 1 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 1 ] ; 0 < arguments . length && console . error ( "M3: the constructor no longer reads arguments. use .set() instead." ) } function u ( a , b , c , d ) { this . _x = a || 0 ; this . _y = b || 0 ; this . _z = c || 0 ; this . _w = void 0 !== d ? d : 1 } function v ( ) { this . rotor =
q ; this . min = - q ; this . max = q ; this . freeHinge = ! 0 ; this . rotationAxisUV = new f ; this . referenceAxisUV = new f ; this . type = 10 } function r ( a , b , c , d , e ) { this . joint = new v ; this . start = new f ; this . end = new f ; this . boneConnectionPoint = 21 ; this . length = 0 ; this . color = e || 16777215 ; this . name = "" ; this . init ( a , b , c , d ) } function z ( a ) { this . tmpTarget = new f ; this . tmpMtx = new y ; this . bones = [ ] ; this . name = "" ; this . color = a || 16777215 ; this . solveDistanceThreshold = 1 ; this . minIterationChange = . 01 ; this . maxIteration = 20 ; this . precision = . 001 ; this . numBones = this . chainLength =
0 ; this . baseLocation = new f ; this . fixedBaseMode = ! 0 ; this . baseboneConstraintType = 1 ; this . baseboneConstraintUV = new f ; this . baseboneRelativeConstraintUV = new f ; this . baseboneRelativeReferenceConstraintUV = new f ; this . lastTargetLocation = new f ( Infinity , Infinity , Infinity ) ; this . lastBaseLocation = new f ( Infinity , Infinity , Infinity ) ; this . currentSolveDistance = Infinity ; this . connectedBoneNumber = this . connectedChainNumber = - 1 ; this . boneConnectionPoint = 21 ; this . isFullForward = ! 1 ; this . embeddedTarget = new f ; this . useEmbeddedTarget =
! 1 } function B ( a ) { this . fixedBaseMode = ! 0 ; this . chains = [ ] ; this . meshChains = [ ] ; this . targets = [ ] ; this . numChains = 0 ; this . scene = a ; this . tmpMtx = new FIK . M3 ; this . isWithMesh = ! 1 } function w ( a , b , c ) { this . coordinateSystem = c || 11 ; this . min = void 0 !== a ? - a * n : - q ; this . max = void 0 !== b ? b * n : q } function x ( a , b , c , d , e , g , k ) { this . start = new l ; this . end = new l ; this . length = d || 0 ; this . joint = new w ( e , g ) ; this . globalConstraintUV = new l ( 1 , 0 ) ; this . boneConnectionPoint = 21 ; this . color = k || null ; this . name = "" ; this . setStartLocation ( a ) ; b ? ( this . setEndLocation ( b ) ,
0 === this . length && ( this . length = this . getLength ( ) ) ) : c && this . setEndLocation ( this . start . plus ( c . normalised ( ) . multiplyScalar ( this . length ) ) ) } function A ( a ) { this . tmpTarget = new l ; this . bones = [ ] ; this . name = "" ; this . solveDistanceThreshold = 1 ; this . minIterationChange = . 01 ; this . maxIteration = 15 ; this . precision = . 001 ; this . numBones = this . chainLength = 0 ; this . baseLocation = new l ; this . fixedBaseMode = ! 0 ; this . baseboneConstraintType = 1 ; this . baseboneConstraintUV = new l ; this . baseboneRelativeConstraintUV = new l ; this . lastTargetLocation = new l ( Infinity ,
Infinity ) ; this . lastBaseLocation = new l ( Infinity , Infinity ) ; this . boneConnectionPoint = 21 ; this . currentSolveDistance = Infinity ; this . connectedBoneNumber = this . connectedChainNumber = - 1 ; this . color = a || 16777215 ; this . embeddedTarget = new l ; this . useEmbeddedTarget = ! 1 } function C ( a ) { this . fixedBaseMode = ! 0 ; this . chains = [ ] ; this . meshChains = [ ] ; this . targets = [ ] ; this . numChains = 0 ; this . scene = a ; this . isWithMesh = ! 1 } function D ( ) { this . goal = this . target = this . endBones = this . startBones = null ; this . swivelAngle = 0 ; this . iteration = 40 ; this . thresholds =
{ position : . 1 , rotation : . 1 } ; this . chain = this . solver = null } function E ( ) { this . goal = this . target = this . endBones = this . startBones = null ; this . swivelAngle = 0 ; this . iteration = 40 ; this . thresholds = { position : . 1 , rotation : . 1 } ; this . chain = this . solver = null } void 0 === Number . EPSILON && ( Number . EPSILON = Math . pow ( 2 , - 52 ) ) ; void 0 === Math . sign && ( Math . sign = function ( a ) { return 0 > a ? - 1 : 0 < a ? 1 : + a } ) ; void 0 === Function . prototype . name && Object . defineProperty ( Function . prototype , "name" , { get : function ( ) { return this . toString ( ) . match ( /^\s*function\s*([^\(\s]*)/ ) [ 1 ] } } ) ;
void 0 === Object . assign && function ( ) { Object . assign = function ( a ) { if ( void 0 === a || null === a ) throw new TypeError ( "Cannot convert undefined or null to object" ) ; for ( var b = Object ( a ) , c = 1 ; c < arguments . length ; c ++ ) { var d = arguments [ c ] ; if ( void 0 !== d && null !== d ) for ( var e in d ) Object . prototype . hasOwnProperty . call ( d , e ) && ( b [ e ] = d [ e ] ) } return b } } ( ) ; var p = { error : function ( a ) { console . error ( a ) } } , m = { toRad : Math . PI / 180 , toDeg : 180 / Math . PI , pi90 : . 5 * Math . PI , findAngle : function ( a , b ) { var c = a . end . minus ( b . end ) . lengthSq ( ) , d = a . end . minus ( a . start ) . lengthSq ( ) ,
e = b . end . minus ( a . start ) . lengthSq ( ) ; c = ( c + d - e ) / Math . sqrt ( 4 * c * d ) ; c = - 1 >= c ? Math . PI : 1 <= c ? 0 : Math . acos ( c ) ; return 0 <= a . end . x * b . end . y - a . end . y * b . end . x ? c : - c } , clamp : function ( a , b , c ) { a = a < b ? b : a ; return a > c ? c : a } , lerp : function ( a , b , c ) { return ( 1 - c ) * a + c * b } , rand : function ( a , b ) { return a + Math . random ( ) * ( b - a ) } , randInt : function ( a , b ) { return a + Math . floor ( Math . random ( ) * ( b - a + 1 ) ) } , nearEquals : function ( a , b , c ) { return Math . abs ( a - b ) <= c ? ! 0 : ! 1 } , perpendicular : function ( a , b ) { return m . nearEquals ( a . dot ( b ) , 0 , . 01 ) ? ! 0 : ! 1 } , genPerpendicularVectorQuick : function ( a ) { var b =
a . clone ( ) ; return . 99 > Math . abs ( a . y ) ? b . set ( - a . z , 0 , a . x ) . normalize ( ) : b . set ( 0 , a . z , - a . y ) . normalize ( ) } , genPerpendicularVectorFrisvad : function ( a ) { var b = a . clone ( ) ; if ( - . 9999999 > a . z ) return b . set ( 0 , - 1 , 0 ) ; var c = 1 / ( 1 + a . z ) ; return b . set ( 1 - a . x * a . x * c , - a . x * a . y * c , - a . x ) . normalize ( ) } , rotateXDegs : function ( a , b ) { return a . clone ( ) . rotate ( b * m . toRad , "X" ) } , rotateYDegs : function ( a , b ) { return a . clone ( ) . rotate ( b * m . toRad , "Y" ) } , rotateZDegs : function ( a , b ) { return a . clone ( ) . rotate ( b * m . toRad , "Z" ) } , withinManhattanDistance : function ( a , b , c ) { return Math . abs ( b . x -
a . x ) > c || Math . abs ( b . y - a . y ) > c || Math . abs ( b . z - a . z ) > c ? ! 1 : ! 0 } , manhattanDistanceBetween : function ( a , b ) { return Math . abs ( b . x - a . x ) + Math . abs ( b . x - a . x ) + Math . abs ( b . x - a . x ) } , distanceBetween : function ( a , b ) { var c = b . x - a . x , d = b . y - a . y ; a = void 0 !== a . z ? b . z - a . z : 0 ; return Math . sqrt ( c * c + d * d + a * a ) } , rotateDegs : function ( a , b ) { return a . clone ( ) . rotate ( b * m . toRad ) } , validateDirectionUV : function ( a ) { 0 > a . length ( ) && p . error ( "vector direction unit vector cannot be zero." ) } , validateLength : function ( a ) { 0 > a && p . error ( "Length must be a greater than or equal to zero." ) } } ;
Object . assign ( l . prototype , { isVector2 : ! 0 , set : function ( a , b ) { this . x = a || 0 ; this . y = b || 0 ; return this } , distanceTo : function ( a ) { return Math . sqrt ( this . distanceToSquared ( a ) ) } , distanceToSquared : function ( a ) { var b = this . x - a . x ; a = this . y - a . y ; return b * b + a * a } , multiplyScalar : function ( a ) { this . x *= a ; this . y *= a ; return this } , divideScalar : function ( a ) { return this . multiplyScalar ( 1 / a ) } , length : function ( ) { return Math . sqrt ( this . x * this . x + this . y * this . y ) } , normalize : function ( ) { return this . divideScalar ( this . length ( ) || 1 ) } , normalised : function ( ) { return ( new l ( this . x ,
this . y ) ) . normalize ( ) } , lengthSq : function ( ) { return this . x * this . x + this . y * this . y } , add : function ( a ) { this . x += a . x ; this . y += a . y ; return this } , plus : function ( a ) { return new l ( this . x + a . x , this . y + a . y ) } , min : function ( a ) { this . x -= a . x ; this . y -= a . y ; return this } , minus : function ( a ) { return new l ( this . x - a . x , this . y - a . y ) } , divideBy : function ( a ) { return ( new l ( this . x , this . y ) ) . divideScalar ( a ) } , times : function ( a ) { return a . isVector2 ? new l ( this . x * a . x , this . y * a . y ) : new l ( this . x * a , this . y * a , this . z * a ) } , dot : function ( a , b ) { return this . x * a . x + this . y *
a . y } , negate : function ( ) { this . x = - this . x ; this . y = - this . y ; return this } , negated : function ( ) { return new l ( - this . x , - this . y ) } , clone : function ( ) { return new l ( this . x , this . y ) } , copy : function ( a ) { this . x = a . x ; this . y = a . y ; return this } , cross : function ( a ) { return this . x * a . y - this . y * a . x } , sign : function ( a ) { return 0 <= this . cross ( a ) ? 1 : - 1 } , approximatelyEquals : function ( a , b ) { if ( 0 > b ) return ! 1 ; var c = Math . abs ( this . y - a . y ) ; return Math . abs ( this . x - a . x ) < b && c < b } , rotate : function ( a ) { var b = Math . cos ( a ) ; a = Math . sin ( a ) ; var c = this . x * a + this . y * b ; this . x =
this . x * b - this . y * a ; this . y = c ; return this } , angleTo : function ( a ) { a = this . dot ( a ) / Math . sqrt ( this . lengthSq ( ) * a . lengthSq ( ) ) ; return - 1 >= a ? Math . PI : 1 <= a ? 0 : Math . acos ( a ) } , getSignedAngle : function ( a ) { var b = this . angleTo ( a ) ; return 1 === this . sign ( a ) ? b : - b } , constrainedUV : function ( a , b , c ) { var d = a . getSignedAngle ( this ) ; d > c && this . copy ( a ) . rotate ( c ) ; d < b && this . copy ( a ) . rotate ( b ) ; return this } } ) ; Object . assign ( f . prototype , { isVector3 : ! 0 , set : function ( a , b , c ) { this . x = a || 0 ; this . y = b || 0 ; this . z = c || 0 ; return this } , distanceTo : function ( a ) { return Math . sqrt ( this . distanceToSquared ( a ) ) } ,
distanceToSquared : function ( a ) { var b = this . x - a . x , c = this . y - a . y ; a = this . z - a . z ; return b * b + c * c + a * a } , abs : function ( ) { return new f ( 0 > this . x ? - this . x : this . x , 0 > this . y ? - this . y : this . y , 0 > this . z ? - this . z : this . z ) } , dot : function ( a ) { return this . x * a . x + this . y * a . y + this . z * a . z } , length : function ( ) { return Math . sqrt ( this . x * this . x + this . y * this . y + this . z * this . z ) } , lengthSq : function ( ) { return this . x * this . x + this . y * this . y + this . z * this . z } , normalize : function ( ) { return this . divideScalar ( this . length ( ) || 1 ) } , normalised : function ( ) { return ( new f ( this . x ,
this . y , this . z ) ) . normalize ( ) } , add : function ( a ) { this . x += a . x ; this . y += a . y ; this . z += a . z ; return this } , min : function ( a ) { this . x -= a . x ; this . y -= a . y ; this . z -= a . z ; return this } , plus : function ( a ) { return new f ( this . x + a . x , this . y + a . y , this . z + a . z ) } , minus : function ( a ) { return new f ( this . x - a . x , this . y - a . y , this . z - a . z ) } , divideBy : function ( a ) { return new f ( this . x / a , this . y / a , this . z / a ) } , multiply : function ( a ) { return new f ( this . x * a , this . y * a , this . z * a ) } , multiplyScalar : function ( a ) { this . x *= a ; this . y *= a ; this . z *= a ; return this } , divideScalar : function ( a ) { return this . multiplyScalar ( 1 /
a ) } , cross : function ( a ) { return new f ( this . y * a . z - this . z * a . y , this . z * a . x - this . x * a . z , this . x * a . y - this . y * a . x ) } , crossVectors : function ( a , b ) { var c = a . x , d = a . y ; a = a . z ; var e = b . x , g = b . y ; b = b . z ; this . x = d * b - a * g ; this . y = a * e - c * b ; this . z = c * g - d * e ; return this } , negate : function ( ) { this . x = - this . x ; this . y = - this . y ; this . z = - this . z ; return this } , negated : function ( ) { return new f ( - this . x , - this . y , - this . z ) } , clone : function ( ) { return new f ( this . x , this . y , this . z ) } , copy : function ( a ) { this . x = a . x ; this . y = a . y ; this . z = a . z ; return this } , approximatelyEquals : function ( a ,
b ) { if ( 0 > b ) return ! 1 ; var c = Math . abs ( this . y - a . y ) , d = Math . abs ( this . z - a . z ) ; return Math . abs ( this . x - a . x ) < b && c < b && d < b } , zero : function ( ) { this . z = this . y = this . x = 0 ; return this } , rotate : function ( a , b ) { var c = Math . cos ( a ) ; a = Math . sin ( a ) ; switch ( b ) { case "X" : var d = this . x ; var e = this . y * c - this . z * a ; var g = this . y * a + this . z * c ; break ; case "Y" : d = this . z * a + this . x * c ; e = this . y ; g = this . z * c - this . x * a ; break ; case "Z" : d = this . x * c - this . y * a , e = this . x * a + this . y * c , g = this . z } this . x = d ; this . y = e ; this . z = g ; return this } , projectOnVector : function ( a ) { var b = a . dot ( this ) /
a . lengthSq ( ) ; return this . copy ( a ) . multiplyScalar ( b ) } , projectOnPlane : function ( ) { var a = new f ; return function ( b ) { a . copy ( this ) . projectOnVector ( b . normalised ( ) ) ; return this . min ( a ) . normalize ( ) } } ( ) , applyM3 : function ( a ) { var b = this . x , c = this . y , d = this . z ; a = a . elements ; this . x = a [ 0 ] * b + a [ 1 ] * c + a [ 2 ] * d ; this . y = a [ 3 ] * b + a [ 4 ] * c + a [ 5 ] * d ; this . z = a [ 6 ] * b + a [ 7 ] * c + a [ 8 ] * d ; return this . normalize ( ) } , applyMatrix3 : function ( a ) { var b = this . x , c = this . y , d = this . z ; a = a . elements ; this . x = a [ 0 ] * b + a [ 3 ] * c + a [ 6 ] * d ; this . y = a [ 1 ] * b + a [ 4 ] * c + a [ 7 ] * d ; this . z = a [ 2 ] * b +
a [ 5 ] * c + a [ 8 ] * d ; return this } , applyQuaternion : function ( a ) { var b = this . x , c = this . y , d = this . z , e = a . x , g = a . y , k = a . z ; a = a . w ; var h = a * b + g * d - k * c , t = a * c + k * b - e * d , f = a * d + e * c - g * b ; b = - e * b - g * c - k * d ; this . x = h * a + b * - e + t * - k - f * - g ; this . y = t * a + b * - g + f * - e - h * - k ; this . z = f * a + b * - k + h * - g - t * - e ; return this } , sign : function ( a , b ) { return 0 <= this . cross ( a ) . dot ( b ) ? 1 : - 1 } , angleTo : function ( a ) { a = this . dot ( a ) / Math . sqrt ( this . lengthSq ( ) * a . lengthSq ( ) ) ; return - 1 >= a ? Math . PI : 1 <= a ? 0 : Math . acos ( a ) } , getSignedAngle : function ( a , b ) { var c = this . angleTo ( a ) ; return 1 === this . sign ( a ,
b ) ? c : - c } , constrainedUV : function ( a , b , c , d , e ) { var g = a . getSignedAngle ( this , b ) ; g > e && this . copy ( c . rotateAboutAxis ( a , e , b ) ) ; g < d && this . copy ( c . rotateAboutAxis ( a , d , b ) ) ; return this } , limitAngle : function ( a , b , c ) { if ( a . angleTo ( this ) > c ) { var d = a . normalised ( ) . cross ( this ) . normalize ( ) ; this . copy ( b . rotateAboutAxis ( a , c , d ) ) } return this } } ) ; Object . assign ( y . prototype , { isMatrix3 : ! 0 , set : function ( a , b , c , d , e , g , k , h , t ) { var f = this . elements ; f [ 0 ] = a ; f [ 1 ] = d ; f [ 2 ] = k ; f [ 3 ] = b ; f [ 4 ] = e ; f [ 5 ] = h ; f [ 6 ] = c ; f [ 7 ] = g ; f [ 8 ] = t ; return this } , identity : function ( ) { this . set ( 1 ,
0 , 0 , 0 , 1 , 0 , 0 , 0 , 1 ) ; return this } , setV3 : function ( a , b , c ) { var d = this . elements ; d [ 0 ] = a . x ; d [ 3 ] = a . y ; d [ 6 ] = a . z ; d [ 1 ] = b . x ; d [ 4 ] = b . y ; d [ 7 ] = b . z ; d [ 2 ] = c . x ; d [ 5 ] = c . y ; d [ 8 ] = c . z ; return this } , transpose : function ( ) { var a = this . elements ; var b = a [ 1 ] ; a [ 1 ] = a [ 3 ] ; a [ 3 ] = b ; b = a [ 2 ] ; a [ 2 ] = a [ 6 ] ; a [ 6 ] = b ; b = a [ 5 ] ; a [ 5 ] = a [ 7 ] ; a [ 7 ] = b ; return this } , createRotationMatrix : function ( a ) { var b = new f ( 1 , 0 , 0 ) , c = new f ( 0 , 1 , 0 ) ; if ( - . 9999999 > a . z ) b . set ( 1 , 0 , 0 ) , c . set ( 0 , 1 , 0 ) ; else { var d = 1 / ( 1 + a . z ) , e = - a . x * a . y * d ; b . set ( 1 - a . x * a . x * d , e , - a . x ) . normalize ( ) ; c . set ( e , 1 - a . y * a . y * d , - a . y ) . normalize ( ) } return this . setV3 ( b ,
c , a ) } , rotateAboutAxis : function ( a , b , c ) { var d = Math . sin ( b ) ; b = Math . cos ( b ) ; var e = 1 - b , g = c . x * c . y * e , k = c . x * c . z * e , h = c . y * c . z * e , f = this . elements ; f [ 0 ] = c . x * c . x * e + b ; f [ 3 ] = g + c . z * d ; f [ 6 ] = k - c . y * d ; f [ 1 ] = g - c . z * d ; f [ 4 ] = c . y * c . y * e + b ; f [ 7 ] = h + c . x * d ; f [ 2 ] = k + c . y * d ; f [ 5 ] = h - c . x * d ; f [ 8 ] = c . z * c . z * e + b ; return a . clone ( ) . applyM3 ( this ) } } ) ; Object . assign ( u , { slerp : function ( a , b , c , d ) { return c . copy ( a ) . slerp ( b , d ) } } ) ; Object . defineProperties ( u . prototype , { x : { get : function ( ) { return this . _x } , set : function ( a ) { this . _x = a ; this . onChangeCallback ( ) } } , y : { get : function ( ) { return this . _y } ,
set : function ( a ) { this . _y = a ; this . onChangeCallback ( ) } } , z : { get : function ( ) { return this . _z } , set : function ( a ) { this . _z = a ; this . onChangeCallback ( ) } } , w : { get : function ( ) { return this . _w } , set : function ( a ) { this . _w = a ; this . onChangeCallback ( ) } } } ) ; Object . assign ( u . prototype , { set : function ( a , b , c , d ) { this . _x = a ; this . _y = b ; this . _z = c ; this . _w = d ; this . onChangeCallback ( ) ; return this } , clone : function ( ) { return new this . constructor ( this . _x , this . _y , this . _z , this . _w ) } , setFromAxisAngle : function ( a , b ) { b /= 2 ; var c = Math . sin ( b ) ; this . _x = a . x * c ; this . _y =
a . y * c ; this . _z = a . z * c ; this . _w = Math . cos ( b ) ; this . onChangeCallback ( ) ; return this } , copy : function ( a ) { this . _x = a . x ; this . _y = a . y ; this . _z = a . z ; this . _w = a . w ; this . onChangeCallback ( ) ; return this } , setFromRotationMatrix : function ( a ) { var b = a . elements , c = b [ 0 ] ; a = b [ 4 ] ; var d = b [ 8 ] , e = b [ 1 ] , g = b [ 5 ] , k = b [ 9 ] , f = b [ 2 ] , h = b [ 6 ] ; b = b [ 10 ] ; var l = c + g + b ; 0 < l ? ( c = . 5 / Math . sqrt ( l + 1 ) , this . _w = . 25 / c , this . _x = ( h - k ) * c , this . _y = ( d - f ) * c , this . _z = ( e - a ) * c ) : c > g && c > b ? ( c = 2 * Math . sqrt ( 1 + c - g - b ) , this . _w = ( h - k ) / c , this . _x = . 25 * c , this . _y = ( a + e ) / c , this . _z = ( d + f ) / c ) : g > b ? ( c =
2 * Math . sqrt ( 1 + g - c - b ) , this . _w = ( d - f ) / c , this . _x = ( a + e ) / c , this . _y = . 25 * c , this . _z = ( k + h ) / c ) : ( c = 2 * Math . sqrt ( 1 + b - c - g ) , this . _w = ( e - a ) / c , this . _x = ( d + f ) / c , this . _y = ( k + h ) / c , this . _z = . 25 * c ) ; this . onChangeCallback ( ) ; return this } , setFromUnitVectors : function ( ) { var a = new f , b ; return function ( c , d ) { void 0 === a && ( a = new f ) ; b = c . dot ( d ) + 1 ; 1E-6 > b ? ( b = 0 , Math . abs ( c . x ) > Math . abs ( c . z ) ? a . set ( - c . y , c . x , 0 ) : a . set ( 0 , - c . z , c . y ) ) : a . crossVectors ( c , d ) ; this . _x = a . x ; this . _y = a . y ; this . _z = a . z ; this . _w = b ; return this . normalize ( ) } } ( ) , inverse : function ( ) { return this . conjugate ( ) } ,
conjugate : function ( ) { this . _x *= - 1 ; this . _y *= - 1 ; this . _z *= - 1 ; this . onChangeCallback ( ) ; return this } , dot : function ( a ) { return this . _x * a . _x + this . _y * a . _y + this . _z * a . _z + this . _w * a . _w } , lengthSq : function ( ) { return this . _x * this . _x + this . _y * this . _y + this . _z * this . _z + this . _w * this . _w } , length : function ( ) { return Math . sqrt ( this . _x * this . _x + this . _y * this . _y + this . _z * this . _z + this . _w * this . _w ) } , normalize : function ( ) { var a = this . length ( ) ; 0 === a ? ( this . _z = this . _y = this . _x = 0 , this . _w = 1 ) : ( a = 1 / a , this . _x *= a , this . _y *= a , this . _z *= a , this . _w *= a ) ; this . onChangeCallback ( ) ;
return this } , multiply : function ( a , b ) { return void 0 !== b ? ( console . warn ( "THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead." ) , this . multiplyQuaternions ( a , b ) ) : this . multiplyQuaternions ( this , a ) } , premultiply : function ( a ) { return this . multiplyQuaternions ( a , this ) } , multiplyQuaternions : function ( a , b ) { var c = a . _x , d = a . _y , e = a . _z ; a = a . _w ; var g = b . _x , k = b . _y , f = b . _z ; b = b . _w ; this . _x = c * b + a * g + d * f - e * k ; this . _y = d * b + a * k + e * g - c * f ; this . _z = e * b + a * f + c * k - d * g ; this . _w = a * b - c * g - d * k - e * f ; this . onChangeCallback ( ) ;
return this } , onChangeCallback : function ( ) { } } ) ; var q = Math . PI , n = Math . PI / 180 , G = 180 / Math . PI , H = new f ( 1 , 0 , 0 ) , I = new f ( 0 , 1 , 0 ) , J = new f ( 0 , 0 , 1 ) , K = new f ( - 1 , 0 , 0 ) , L = new f ( 0 , - 1 , 0 ) , M = new f ( 0 , 0 , - 1 ) , F = new l ( 0 , 1 ) , N = new l ( 0 , - 1 ) , O = new l ( - 1 , 0 ) , P = new l ( 1 , 0 ) ; Object . assign ( v . prototype , { isJoint3D : ! 0 , clone : function ( ) { var a = new v ; a . type = this . type ; a . rotor = this . rotor ; a . max = this . max ; a . min = this . min ; a . freeHinge = this . freeHinge ; a . rotationAxisUV . copy ( this . rotationAxisUV ) ; a . referenceAxisUV . copy ( this . referenceAxisUV ) ; return a } , testAngle : function ( ) { this . freeHinge =
this . max === q && this . min === - q ? ! 0 : ! 1 } , validateAngle : function ( a ) { a = 0 > a ? 0 : a ; return 180 < a ? 180 : a } , setAsBallJoint : function ( a ) { this . rotor = this . validateAngle ( a ) * n ; this . type = 10 } , setHinge : function ( a , b , c , d , e ) { this . type = a ; 0 > c && ( c *= - 1 ) ; this . min = - this . validateAngle ( c ) * n ; this . max = this . validateAngle ( d ) * n ; this . testAngle ( ) ; this . rotationAxisUV . copy ( b ) . normalize ( ) ; this . referenceAxisUV . copy ( e ) . normalize ( ) } , getHingeReferenceAxis : function ( ) { return this . referenceAxisUV } , getHingeRotationAxis : function ( ) { return this . rotationAxisUV } ,
setBallJointConstraintDegs : function ( a ) { this . rotor = this . validateAngle ( a ) * n } , setHingeClockwise : function ( a ) { 0 > a && ( a *= - 1 ) ; this . min = - this . validateAngle ( a ) * n ; this . testAngle ( ) } , setHingeAnticlockwise : function ( a ) { this . max = this . validateAngle ( a ) * n ; this . testAngle ( ) } } ) ; Object . assign ( r . prototype , { isBone3D : ! 0 , init : function ( a , b , c , d ) { this . setStartLocation ( a ) ; b ? ( this . setEndLocation ( b ) , this . length = this . getLength ( ) ) : ( this . setLength ( d ) , this . setEndLocation ( this . start . plus ( c . normalised ( ) . multiplyScalar ( d ) ) ) ) } , clone : function ( ) { var a =
new r ( this . start , this . end ) ; a . joint = this . joint . clone ( ) ; return a } , setColor : function ( a ) { this . color = a } , setBoneConnectionPoint : function ( a ) { this . boneConnectionPoint = a } , setHingeClockwise : function ( a ) { this . joint . setHingeClockwise ( a ) } , setHingeAnticlockwise : function ( a ) { this . joint . setHingeAnticlockwise ( a ) } , setBallJointConstraintDegs : function ( a ) { this . joint . setBallJointConstraintDegs ( a ) } , setStartLocation : function ( a ) { this . start . copy ( a ) } , setEndLocation : function ( a ) { this . end . copy ( a ) } , setLength : function ( a ) { 0 < a && ( this . length =
a ) } , setJoint : function ( a ) { this . joint = a } , getBoneConnectionPoint : function ( ) { return this . boneConnectionPoint } , getDirectionUV : function ( ) { return this . end . minus ( this . start ) . normalize ( ) } , getLength : function ( ) { return this . start . distanceTo ( this . end ) } } ) ; Object . assign ( z . prototype , { isChain3D : ! 0 , clone : function ( ) { var a = new z ; a . solveDistanceThreshold = this . solveDistanceThreshold ; a . minIterationChange = this . minIterationChange ; a . maxIteration = this . maxIteration ; a . precision = this . precision ; a . bones = this . cloneBones ( ) ; a . baseLocation . copy ( this . baseLocation ) ;
a . lastTargetLocation . copy ( this . lastTargetLocation ) ; a . lastBaseLocation . copy ( this . lastBaseLocation ) ; 1 !== this . baseboneConstraintType && ( a . baseboneConstraintUV . copy ( this . baseboneConstraintUV ) , a . baseboneRelativeConstraintUV . copy ( this . baseboneRelativeConstraintUV ) ) ; a . fixedBaseMode = this . fixedBaseMode ; a . chainLength = this . chainLength ; a . numBones = this . numBones ; a . currentSolveDistance = this . currentSolveDistance ; a . boneConnectionPoint = this . boneConnectionPoint ; a . connectedChainNumber = this . connectedChainNumber ; a . connectedBoneNumber =
this . connectedBoneNumber ; a . baseboneConstraintType = this . baseboneConstraintType ; a . color = this . color ; a . embeddedTarget = this . embeddedTarget . clone ( ) ; a . useEmbeddedTarget = this . useEmbeddedTarget ; return a } , clear : function ( ) { for ( var a = this . numBones ; a -- ; ) this . removeBone ( a ) ; this . numBones = 0 } , addBone : function ( a ) { a . setColor ( this . color ) ; this . bones . push ( a ) ; this . numBones ++ ; 1 === this . numBones && ( this . baseLocation . copy ( a . start ) , this . baseboneConstraintUV . copy ( a . getDirectionUV ( ) ) ) ; this . updateChainLength ( ) } , removeBone : function ( a ) { a <
this . numBones && ( this . bones . splice ( a , 1 ) , this . numBones -- , this . updateChainLength ( ) ) } , addConsecutiveBone : function ( a , b ) { 0 < this . numBones && this . addBone ( new r ( this . bones [ this . numBones - 1 ] . end , void 0 , a . normalised ( ) , b ) ) } , addConsecutiveFreelyRotatingHingedBone : function ( a , b , c , d ) { this . addConsecutiveHingedBone ( a , b , c , d , 180 , 180 , m . genPerpendicularVectorQuick ( d ) ) } , addConsecutiveHingedBone : function ( a , b , c , d , e , g , k ) { 0 !== this . numBones && ( a = a . normalised ( ) , d = d . normalised ( ) , b = new r ( this . bones [ this . numBones - 1 ] . end , void 0 , a , b ,
this . color ) , b . joint . setHinge ( "global" === ( c || "global" ) ? 12 : 11 , d , e , g , k ) , this . addBone ( b ) ) } , addConsecutiveRotorConstrainedBone : function ( a , b , c ) { 0 !== this . numBones && ( a = a . normalised ( ) , a = new r ( this . bones [ this . numBones - 1 ] . end , void 0 , a , b ) , a . joint . setAsBallJoint ( c ) , this . addBone ( a ) ) } , getBoneConnectionPoint : function ( ) { return this . boneConnectionPoint } , getConnectedBoneNumber : function ( ) { return this . connectedBoneNumber } , getConnectedChainNumber : function ( ) { return this . connectedChainNumber } , getBaseboneConstraintType : function ( ) { return this . baseboneConstraintType } ,
getBaseboneConstraintUV : function ( ) { if ( 1 !== this . baseboneConstraintType ) return this . baseboneConstraintUV } , getBaseLocation : function ( ) { return this . bones [ 0 ] . start } , getEffectorLocation : function ( ) { return this . bones [ this . numBones - 1 ] . end } , getLastTargetLocation : function ( ) { return this . lastTargetLocation } , getLiveChainLength : function ( ) { for ( var a = 0 , b = this . numBones ; b -- ; ) a += this . bones [ b ] . getLength ( ) ; return a } , getBaseboneRelativeReferenceConstraintUV : function ( ) { return this . baseboneRelativeReferenceConstraintUV } , setConnectedBoneNumber : function ( a ) { this . connectedBoneNumber =
a } , setConnectedChainNumber : function ( a ) { this . connectedChainNumber = a } , setBoneConnectionPoint : function ( a ) { this . boneConnectionPoint = a } , setColor : function ( a ) { this . color = a ; for ( a = this . numBones ; a -- ; ) this . bones [ a ] . setColor ( this . color ) } , setBaseboneRelativeConstraintUV : function ( a ) { this . baseboneRelativeConstraintUV = a . normalised ( ) } , setBaseboneRelativeReferenceConstraintUV : function ( a ) { this . baseboneRelativeReferenceConstraintUV = a . normalised ( ) } , setBaseboneConstraintUV : function ( a ) { this . baseboneConstraintUV = a . normalised ( ) } ,
setRotorBaseboneConstraint : function ( a , b , c ) { 0 === this . numBones ? p . error ( "Chain must contain a basebone before we can specify the basebone constraint type." ) : 0 < b . length ( ) ? ( this . baseboneConstraintType = "global" === ( a || "global" ) ? 2 : 4 , this . baseboneConstraintUV = b . normalised ( ) , this . baseboneRelativeConstraintUV . copy ( this . baseboneConstraintUV ) , this . bones [ 0 ] . joint . setAsBallJoint ( c ) ) : p . error ( "Constraint axis cannot be zero." ) } , setHingeBaseboneConstraint : function ( a , b , c , d , e ) { 0 === this . numBones ? p . error ( "Chain must contain a basebone before we can specify the basebone constraint type." ) :
0 >= b . length ( ) ? p . error ( "Hinge rotation axis cannot be zero." ) : 0 >= e . length ( ) ? p . error ( "Hinge reference axis cannot be zero." ) : m . perpendicular ( b , e ) ? ( a = a || "global" , this . baseboneConstraintType = "global" === a ? 3 : 5 , this . baseboneConstraintUV = b . normalised ( ) , this . bones [ 0 ] . joint . setHinge ( "global" === a ? 12 : 11 , b , c , d , e ) ) : p . error ( "The hinge reference axis must be in the plane of the hinge rotation axis, that is, they must be perpendicular." ) } , setFreelyRotatingGlobalHingedBasebone : function ( a ) { this . setHingeBaseboneConstraint ( "global" ,
a , 180 , 180 , m . genPerpendicularVectorQuick ( a ) ) } , setGlobalHingedBasebone : function ( a , b , c , d ) { this . setHingeBaseboneConstraint ( "global" , a , b , c , d ) } , setFreelyRotatingLocalHingedBasebone : function ( a ) { this . setHingeBaseboneConstraint ( "local" , a , 180 , 180 , m . genPerpendicularVectorQuick ( a ) ) } , setLocalHingedBasebone : function ( a , b , c , d ) { this . setHingeBaseboneConstraint ( "local" , a , b , c , d ) } , setBaseLocation : function ( a ) { this . baseLocation . copy ( a ) } , setFixedBaseMode : function ( a ) { if ( a || - 1 === this . connectedChainNumber ) if ( 2 !== this . baseboneConstraintType ||
a ) this . fixedBaseMode = a } , setMaxIterationAttempts : function ( a ) { 1 > a || ( this . maxIteration = a ) } , setMinIterationChange : function ( a ) { 0 > a || ( this . minIterationChange = a ) } , setSolveDistanceThreshold : function ( a ) { 0 > a || ( this . solveDistanceThreshold = a ) } , solveForEmbeddedTarget : function ( ) { if ( this . useEmbeddedTarget ) return this . solveForTarget ( this . embeddedTarget ) } , resetTarget : function ( ) { this . lastBaseLocation = new f ( Infinity , Infinity , Infinity ) ; this . currentSolveDistance = Infinity } , solveForTarget : function ( a ) { this . tmpTarget . set ( a . x ,
a . y , a . z ) ; a = this . precision ; var b = this . lastBaseLocation . approximatelyEquals ( this . baseLocation , a ) ; if ( this . lastTargetLocation . approximatelyEquals ( this . tmpTarget , a ) && b ) return this . currentSolveDistance ; a = null ; b ? ( b = this . bones [ this . numBones - 1 ] . end . distanceTo ( this . tmpTarget ) , a = this . cloneBones ( ) ) : b = Infinity ; for ( var c = [ ] , d = Infinity , e = Infinity , g , k = this . maxIteration ; k -- ; ) { g = this . solveIK ( this . tmpTarget ) ; if ( g < d ) { if ( d = g , c = this . cloneBones ( ) , g <= this . solveDistanceThreshold ) break } else if ( Math . abs ( g - e ) < this . minIterationChange ) break ;
e = g } d < b ? ( this . currentSolveDistance = d , this . bones = c ) : ( this . currentSolveDistance = b , this . bones = a ) ; this . lastBaseLocation . copy ( this . baseLocation ) ; this . lastTargetLocation . copy ( this . tmpTarget ) ; return this . currentSolveDistance } , solveIK : function ( a ) { if ( 0 !== this . numBones ) { for ( var b , c , d , e , g , k , f = this . tmpMtx , h = this . numBones ; h -- ; ) { b = this . bones [ h ] ; c = b . length ; d = b . joint ; e = d . type ; if ( h !== this . numBones - 1 ) { g = this . bones [ h + 1 ] ; k = g . getDirectionUV ( ) . negate ( ) ; g = b . getDirectionUV ( ) . negate ( ) ; switch ( e ) { case 10 : g . limitAngle ( k , f , d . rotor ) ;
break ; case 12 : e = d . getHingeRotationAxis ( ) ; g . projectOnPlane ( e ) ; break ; case 11 : 0 < h ? ( f . createRotationMatrix ( this . bones [ h - 1 ] . getDirectionUV ( ) ) , e = d . getHingeRotationAxis ( ) . clone ( ) . applyM3 ( f ) ) : e = this . baseboneRelativeConstraintUV , g . projectOnPlane ( e ) } c = b . end . plus ( g . multiplyScalar ( c ) ) } else { b . setEndLocation ( a ) ; g = b . getDirectionUV ( ) . negated ( ) ; switch ( e ) { case 12 : e = d . getHingeRotationAxis ( ) ; g . projectOnPlane ( e ) ; break ; case 11 : f . createRotationMatrix ( this . bones [ h - 1 ] . getDirectionUV ( ) ) , e = d . getHingeRotationAxis ( ) . clone ( ) . applyM3 ( f ) ,
g . projectOnPlane ( e ) } c = a . plus ( g . multiplyScalar ( c ) ) } b . setStartLocation ( c ) ; 0 < h && this . bones [ h - 1 ] . setEndLocation ( c ) } for ( h = 0 ; h < this . numBones ; h ++ ) if ( b = this . bones [ h ] , c = b . length , d = b . joint , e = d . type , 0 !== h ) { g = b . getDirectionUV ( ) ; k = this . bones [ h - 1 ] . getDirectionUV ( ) ; switch ( e ) { case 10 : g . limitAngle ( k , f , d . rotor ) ; break ; case 12 : e = d . getHingeRotationAxis ( ) ; k = d . getHingeReferenceAxis ( ) ; g . projectOnPlane ( e ) ; d . freeHinge || g . constrainedUV ( k , e , f , d . min , d . max ) ; break ; case 11 : f . createRotationMatrix ( k ) , e = d . getHingeRotationAxis ( ) . clone ( ) . applyM3 ( f ) ,
k = d . getHingeReferenceAxis ( ) . clone ( ) . applyM3 ( f ) , g . projectOnPlane ( e ) , d . freeHinge || g . constrainedUV ( k , e , f , d . min , d . max ) } c = b . start . plus ( g . multiplyScalar ( c ) ) ; b . setEndLocation ( c ) ; h < this . numBones - 1 && this . bones [ h + 1 ] . setStartLocation ( c ) } else { this . fixedBaseMode ? b . setStartLocation ( this . baseLocation ) : b . setStartLocation ( b . end . minus ( b . getDirectionUV ( ) . multiplyScalar ( c ) ) ) ; g = b . getDirectionUV ( ) ; switch ( this . baseboneConstraintType ) { case 2 : g . limitAngle ( this . baseboneConstraintUV , f , d . rotor ) ; break ; case 4 : g . limitAngle ( this . baseboneRelativeConstraintUV ,
f , d . rotor ) ; break ; case 3 : e = d . getHingeRotationAxis ( ) ; k = d . getHingeReferenceAxis ( ) ; g . projectOnPlane ( e ) ; d . freeHinge || g . constrainedUV ( k , e , f , d . min , d . max ) ; break ; case 5 : e = this . baseboneRelativeConstraintUV , k = this . baseboneRelativeReferenceConstraintUV , g . projectOnPlane ( e ) , d . freeHinge || g . constrainedUV ( k , e , f , d . min , d . max ) } c = b . start . plus ( g . multiplyScalar ( c ) ) ; b . setEndLocation ( c ) ; 1 < this . numBones && this . bones [ 1 ] . setStartLocation ( c ) } this . lastTargetLocation . copy ( a ) ; return this . bones [ this . numBones - 1 ] . end . distanceTo ( a ) } } ,
updateChainLength : function ( ) { this . chainLength = 0 ; for ( var a = this . numBones ; a -- ; ) this . chainLength += this . bones [ a ] . length } , cloneBones : function ( ) { for ( var a = [ ] , b = 0 , c = this . bones . length ; b < c ; b ++ ) a . push ( this . bones [ b ] . clone ( ) ) ; return a } } ) ; Object . assign ( B . prototype , { update : function ( ) { for ( var a , b , c , d , e = 0 ; e < this . numChains ; e ++ ) { a = this . chains [ e ] ; b = this . targets [ e ] ; c = a . getConnectedChainNumber ( ) ; if ( - 1 !== c ) switch ( d = this . chains [ c ] . bones [ a . getConnectedBoneNumber ( ) ] , a . setBaseLocation ( 20 === a . getBoneConnectionPoint ( ) ? d . start :
d . end ) , c = a . getBaseboneConstraintType ( ) , c ) { case 4 : case 5 : this . tmpMtx . createRotationMatrix ( d . getDirectionUV ( ) ) , d = a . getBaseboneConstraintUV ( ) . clone ( ) . applyM3 ( this . tmpMtx ) , a . setBaseboneRelativeConstraintUV ( d ) , 5 === c && a . setBaseboneRelativeReferenceConstraintUV ( a . bones [ 0 ] . joint . getHingeReferenceAxis ( ) . clone ( ) . applyM3 ( this . tmpMtx ) ) } a . useEmbeddedTarget ? a . solveForEmbeddedTarget ( ) : a . solveForTarget ( b ) ; if ( this . isWithMesh ) for ( b = this . meshChains [ e ] , d = 0 ; d < a . numBones ; d ++ ) c = a . bones [ d ] , b [ d ] . position . copy ( c . start ) , b [ d ] . lookAt ( c . end ) } } ,
clear : function ( ) { this . clearAllBoneMesh ( ) ; var a ; for ( a = this . numChains ; a -- ; ) this . remove ( a ) ; this . chains = [ ] ; this . meshChains = [ ] ; this . targets = [ ] } , add : function ( a , b , c ) { this . chains . push ( a ) ; this . targets . push ( b ) ; this . numChains ++ ; c && this . addChainMeshs ( a ) } , remove : function ( a ) { this . chains [ a ] . clear ( ) ; this . chains . splice ( a , 1 ) ; this . meshChains . splice ( a , 1 ) ; this . targets . splice ( a , 1 ) ; this . numChains -- } , setFixedBaseMode : function ( a ) { this . fixedBaseMode = a ; a = this . numChains ; for ( var b ; a -- ; ) b = this . chains [ a ] . getConnectedChainNumber ( ) ,
- 1 === b && this . chains [ a ] . setFixedBaseMode ( this . fixedBaseMode ) } , getNumChains : function ( ) { return this . numChains } , getChain : function ( a ) { return this . chains [ a ] } , connectChain : function ( a , b , c , d , e , g , f ) { if ( ! ( b > this . numChains || c > this . chains [ b ] . numBones ) ) { a = a . clone ( ) ; void 0 !== f && a . setColor ( f ) ; a . setBoneConnectionPoint ( "end" === d ? 21 : 20 ) ; a . setConnectedChainNumber ( b ) ; a . setConnectedBoneNumber ( c ) ; b = "end" === d ? this . chains [ b ] . bones [ c ] . end : this . chains [ b ] . bones [ c ] . start ; a . setBaseLocation ( b ) ; a . setFixedBaseMode ( ! 0 ) ; for ( c = 0 ; c <
2020-10-13 04:48:28 +08:00
a . numBones ; c ++ ) a . bones [ c ] . start . add ( b ) , a . bones [ c ] . end . add ( b ) ; this . add ( a , e , g ) } } , addChainMeshs : function ( a , b ) { this . isWithMesh = ! 0 ; b = [ ] ; for ( var c = a . bones . length , d = 0 ; d < c ; d ++ ) b . push ( this . addBoneMesh ( a . bones [ d ] , d - 1 , b , a ) ) ; this . meshChains . push ( b ) } , addBoneMesh : function ( a , b , c , d ) { var e = a . length , g = a . color , f = new THREE . CylinderBufferGeometry ( 1 , . 5 , e , 4 ) ; f . applyMatrix4 ( ( new THREE . Matrix4 ) . makeRotationX ( . 5 * - Math . PI ) ) ; f . applyMatrix4 ( ( new THREE . Matrix4 ) . makeTranslation ( 0 , 0 , . 5 * e ) ) ; var h = new THREE . MeshStandardMaterial ( { color : g ,
wireframe : ! 1 , shadowSide : ! 1 } ) , l = new THREE . MeshBasicMaterial ( { wireframe : ! 0 } ) , m = null ; e = a . joint . type ; switch ( e ) { case 10 : l . color . setHex ( 16737792 ) ; if ( a . joint . rotor === Math . PI ) break ; a = new THREE . CylinderBufferGeometry ( 0 , 2 , 2 , 6 , 1 , ! 0 ) ; a . applyMatrix4 ( ( new THREE . Matrix4 ) . makeRotationX ( . 5 * - Math . PI ) ) ; a . applyMatrix4 ( ( new THREE . Matrix4 ) . makeTranslation ( 0 , 0 , 1 ) ) ; m = new THREE . Mesh ( a , l ) ; break ; case 12 : g = a . joint . getHingeRotationAxis ( ) ; var n = a . joint . min ; a = a . joint . max ; m = 2 ; l . color . setHex ( 16776960 ) ; a = new THREE . CircleBufferGeometry ( m ,
12 , n , - n + a ) ; 1 === g . z && a . applyMatrix4 ( ( new THREE . Matrix4 ) . makeRotationX ( . 5 * - Math . PI ) ) ; 1 === g . y && ( a . applyMatrix4 ( ( new THREE . Matrix4 ) . makeRotationY ( . 5 * - Math . PI ) ) , a . applyMatrix4 ( ( new THREE . Matrix4 ) . makeRotationX ( . 5 * - Math . PI ) ) ) ; 1 === g . x && a . applyMatrix4 ( ( new THREE . Matrix4 ) . makeRotationY ( . 5 * Math . PI ) ) ; m = new THREE . Mesh ( a , l ) ; break ; case 11 : g = a . joint . getHingeRotationAxis ( ) , m = 2 , n = a . joint . min , a = a . joint . max , l . color . setHex ( 65535 ) , a = new THREE . CircleBufferGeometry ( m , 12 , n , - n + a ) , a . applyMatrix4 ( ( new THREE . Matrix4 ) . makeRotationX ( . 5 *
- Math . PI ) ) , 1 === g . z && ( a . applyMatrix4 ( ( new THREE . Matrix4 ) . makeRotationY ( . 5 * - Math . PI ) ) , a . applyMatrix4 ( ( new THREE . Matrix4 ) . makeRotationX ( . 5 * Math . PI ) ) ) , 1 === g . x && a . applyMatrix4 ( ( new THREE . Matrix4 ) . makeRotationZ ( . 5 * - Math . PI ) ) , 1 === g . y && ( a . applyMatrix4 ( ( new THREE . Matrix4 ) . makeRotationX ( . 5 * Math . PI ) ) , a . applyMatrix4 ( ( new THREE . Matrix4 ) . makeRotationY ( . 5 * Math . PI ) ) ) , m = new THREE . Mesh ( a , l ) } g = new THREE . AxesHelper ( 1.5 ) ; f = new THREE . Mesh ( f , h ) ; f . add ( g ) ; this . scene . add ( f ) ; f . castShadow = ! 0 ; f . receiveShadow = ! 0 ; - 1 !== b ? null !== m && ( 12 !==
2019-12-16 03:04:31 +08:00
e ? ( m . position . z = d . bones [ b ] . length , c [ b ] . add ( m ) ) : f . add ( m ) ) : null !== m && f . add ( m ) ; return f } , clearAllBoneMesh : function ( ) { if ( this . isWithMesh ) { var a , b ; for ( a = this . meshChains . length ; a -- ; ) { for ( b = this . meshChains [ a ] . length ; b -- ; ) { var c = this . meshChains [ a ] [ b ] ; this . scene . remove ( c ) ; c . geometry . dispose ( ) ; c . material . dispose ( ) } this . meshChains [ a ] = [ ] } this . meshChains = [ ] } } } ) ; Object . assign ( w . prototype , { isJoint2D : ! 0 , clone : function ( ) { var a = new w ; a . coordinateSystem = this . coordinateSystem ; a . max = this . max ; a . min = this . min ; return a } ,
validateAngle : function ( a ) { a = 0 > a ? 0 : a ; return 180 < a ? 180 : a } , set : function ( a ) { this . max = a . max ; this . min = a . min ; this . coordinateSystem = a . coordinateSystem } , setClockwiseConstraintDegs : function ( a ) { this . min = - ( this . validateAngle ( a ) * n ) } , setAnticlockwiseConstraintDegs : function ( a ) { this . max = this . validateAngle ( a ) * n } , setConstraintCoordinateSystem : function ( a ) { this . coordinateSystem = a } , getConstraintCoordinateSystem : function ( ) { return this . coordinateSystem } } ) ; Object . assign ( x . prototype , { isBone2D : ! 0 , clone : function ( ) { var a = new x ( this . start ,
this . end ) ; a . length = this . length ; a . globalConstraintUV = this . globalConstraintUV ; a . boneConnectionPoint = this . boneConnectionPoint ; a . joint = this . joint . clone ( ) ; a . color = this . color ; a . name = this . name ; return a } , setName : function ( a ) { this . name = a } , setColor : function ( a ) { this . color = a } , setBoneConnectionPoint : function ( a ) { this . boneConnectionPoint = a } , setStartLocation : function ( a ) { this . start . copy ( a ) } , setEndLocation : function ( a ) { this . end . copy ( a ) } , setLength : function ( a ) { 0 < a && ( this . length = a ) } , setGlobalConstraintUV : function ( a ) { this . globalConstraintUV =
a } , setJoint : function ( a ) { this . joint = a } , setClockwiseConstraintDegs : function ( a ) { this . joint . setClockwiseConstraintDegs ( a ) } , setAnticlockwiseConstraintDegs : function ( a ) { this . joint . setAnticlockwiseConstraintDegs ( a ) } , setJointConstraintCoordinateSystem : function ( a ) { this . joint . setConstraintCoordinateSystem ( a ) } , getGlobalConstraintUV : function ( ) { return this . globalConstraintUV } , getBoneConnectionPoint : function ( ) { return this . boneConnectionPoint } , getDirectionUV : function ( ) { return this . end . minus ( this . start ) . normalize ( ) } ,
getLength : function ( ) { return this . start . distanceTo ( this . end ) } } ) ; Object . assign ( A . prototype , { isChain2D : ! 0 , clone : function ( ) { var a = new A ; a . solveDistanceThreshold = this . solveDistanceThreshold ; a . minIterationChange = this . minIterationChange ; a . maxIteration = this . maxIteration ; a . precision = this . precision ; a . bones = this . cloneBones ( ) ; a . baseLocation . copy ( this . baseLocation ) ; a . lastTargetLocation . copy ( this . lastTargetLocation ) ; a . lastBaseLocation . copy ( this . lastBaseLocation ) ; 1 !== this . baseboneConstraintType && ( a . baseboneConstraintUV . copy ( this . baseboneConstraintUV ) ,
a . baseboneRelativeConstraintUV . copy ( this . baseboneRelativeConstraintUV ) ) ; a . fixedBaseMode = this . fixedBaseMode ; a . chainLength = this . chainLength ; a . numBones = this . numBones ; a . currentSolveDistance = this . currentSolveDistance ; a . boneConnectionPoint = this . boneConnectionPoint ; a . connectedChainNumber = this . connectedChainNumber ; a . connectedBoneNumber = this . connectedBoneNumber ; a . baseboneConstraintType = this . baseboneConstraintType ; a . color = this . color ; a . embeddedTarget = this . embeddedTarget . clone ( ) ; a . useEmbeddedTarget = this . useEmbeddedTarget ;
return a } , clear : function ( ) { for ( var a = this . numBones ; a -- ; ) this . removeBone ( a ) } , addBone : function ( a ) { null === a . color && a . setColor ( this . color ) ; this . bones . push ( a ) ; 0 === this . numBones && ( this . baseLocation . copy ( a . start ) , this . baseboneConstraintUV . copy ( a . getDirectionUV ( ) ) ) ; this . numBones ++ ; this . updateChainLength ( ) } , removeBone : function ( a ) { a < this . numBones && ( this . bones . splice ( a , 1 ) , this . numBones -- , this . updateChainLength ( ) ) } , addConsecutiveBone : function ( a , b , c , d , e ) { if ( 0 === this . numBones ) p . error ( "Chain is empty ! need first bone" ) ;
else if ( a . isBone2D ) { b = a . getDirectionUV ( ) ; m . validateDirectionUV ( b ) ; c = a . length ; m . validateLength ( c ) ; var g = this . bones [ this . numBones - 1 ] . end ; a . setStartLocation ( g ) ; a . setEndLocation ( g . plus ( b . multiplyScalar ( c ) ) ) ; this . addBone ( a ) } else a . isVector2 && ( e = e || this . color , m . validateDirectionUV ( a ) , m . validateLength ( b ) , g = this . bones [ this . numBones - 1 ] . end , this . addBone ( new x ( g , null , a . normalised ( ) , b , c , d , e ) ) ) } , getBoneConnectionPoint : function ( ) { return this . boneConnectionPoint } , getConnectedBoneNumber : function ( ) { return this . connectedBoneNumber } ,
getConnectedChainNumber : function ( ) { return this . connectedChainNumber } , getEmbeddedTarget : function ( ) { return this . embeddedTarget } , getBaseboneConstraintType : function ( ) { return this . baseboneConstraintType } , getBaseboneConstraintUV : function ( ) { if ( 1 !== this . baseboneConstraintType ) return this . baseboneConstraintUV } , getBaseLocation : function ( ) { return this . bones [ 0 ] . start } , getEffectorLocation : function ( ) { return this . bones [ this . numBones - 1 ] . end } , getLastTargetLocation : function ( ) { return this . lastTargetLocation } , getLiveChainLength : function ( ) { for ( var a =
0 , b = this . numBones ; b -- ; ) a += this . bones [ b ] . getLength ( ) ; return a } , setColor : function ( a ) { this . color = a ; for ( a = this . numBones ; a -- ; ) this . bones [ a ] . setColor ( this . color ) } , setBaseboneRelativeConstraintUV : function ( a ) { this . baseboneRelativeConstraintUV = a } , setConnectedBoneNumber : function ( a ) { this . connectedBoneNumber = a } , setConnectedChainNumber : function ( a ) { this . connectedChainNumber = a } , setBoneConnectionPoint : function ( a ) { this . boneConnectionPoint = a } , setBaseboneConstraintUV : function ( a ) { m . validateDirectionUV ( a ) ; this . baseboneConstraintUV . copy ( a . normalised ( ) ) } ,
setBaseLocation : function ( a ) { this . baseLocation . copy ( a ) } , setBaseboneConstraintType : function ( a ) { this . baseboneConstraintType = a } , setFixedBaseMode : function ( a ) { if ( a || - 1 === this . connectedChainNumber ) if ( 6 !== this . baseboneConstraintType || a ) this . fixedBaseMode = a } , setMaxIterationAttempts : function ( a ) { 1 > a || ( this . maxIteration = a ) } , setMinIterationChange : function ( a ) { 0 > a || ( this . minIterationChange = a ) } , setSolveDistanceThreshold : function ( a ) { 0 > a || ( this . solveDistanceThreshold = a ) } , solveForEmbeddedTarget : function ( ) { if ( this . useEmbeddedTarget ) return this . solveForTarget ( this . embeddedTarget ) } ,
resetTarget : function ( ) { this . lastBaseLocation = new l ( Infinity , Infinity ) ; this . currentSolveDistance = Infinity } , solveForTarget : function ( a ) { this . tmpTarget . set ( a . x , a . y ) ; a = this . precision ; var b = this . lastBaseLocation . approximatelyEquals ( this . baseLocation , a ) ; if ( this . lastTargetLocation . approximatelyEquals ( this . tmpTarget , a ) && b ) return this . currentSolveDistance ; a = null ; b ? ( b = this . bones [ this . numBones - 1 ] . end . distanceTo ( this . tmpTarget ) , a = this . cloneBones ( ) ) : b = Infinity ; for ( var c = [ ] , d = Infinity , e = Infinity , g , f = this . maxIteration ; f -- ; ) { g =
this . solveIK ( this . tmpTarget ) ; if ( g < d ) { if ( d = g , c = this . cloneBones ( ) , g <= this . solveDistanceThreshold ) break } else if ( Math . abs ( g - e ) < this . minIterationChange ) break ; e = g } d < b ? ( this . currentSolveDistance = d , this . bones = c ) : ( this . currentSolveDistance = b , this . bones = a ) ; this . lastBaseLocation . copy ( this . baseLocation ) ; this . lastTargetLocation . copy ( this . tmpTarget ) ; return this . currentSolveDistance } , solveIK : function ( a ) { if ( 0 !== this . numBones ) { for ( var b , c , d , e , g , f = this . numBones ; f -- ; ) b = this . bones [ f ] , c = b . length , f !== this . numBones - 1 ? ( d =
this . bones [ f + 1 ] , e = b . getDirectionUV ( ) . negate ( ) , g = 11 === b . joint . coordinateSystem ? d . getDirectionUV ( ) . negate ( ) : b . getGlobalConstraintUV ( ) . negated ( ) , e . constrainedUV ( g , d . joint . min , d . joint . max ) ) : ( b . setEndLocation ( a ) , e = b . getDirectionUV ( ) . negate ( ) , 0 < f ? ( g = 11 === b . joint . coordinateSystem ? this . bones [ f - 1 ] . getDirectionUV ( ) . negate ( ) : b . getGlobalConstraintUV ( ) . negated ( ) , e . constrainedUV ( g , b . joint . min , b . joint . max ) ) : 11 !== b . joint . coordinateSystem && ( g = b . getGlobalConstraintUV ( ) . negated ( ) , e . constrainedUV ( g , b . joint . min , b . joint . max ) ) ) ,
d = b . end . plus ( e . multiplyScalar ( c ) ) , b . setStartLocation ( d ) , 0 < f && this . bones [ f - 1 ] . setEndLocation ( d ) ; for ( f = 0 ; f < this . numBones ; f ++ ) b = this . bones [ f ] , c = b . length , 0 !== f ? ( e = b . getDirectionUV ( ) , g = 11 === b . joint . coordinateSystem ? this . bones [ f - 1 ] . getDirectionUV ( ) : b . getGlobalConstraintUV ( ) , e . constrainedUV ( g , b . joint . min , b . joint . max ) , c = b . start . plus ( e . multiplyScalar ( c ) ) , b . setEndLocation ( c ) , f < this . numBones - 1 && this . bones [ f + 1 ] . setStartLocation ( c ) ) : ( this . fixedBaseMode ? b . setStartLocation ( this . baseLocation ) : ( d = b . end . minus ( b . getDirectionUV ( ) . multiplyScalar ( c ) ) ,
b . setStartLocation ( d ) ) , e = b . getDirectionUV ( ) , 1 === this . baseboneConstraintType ? ( c = b . start . plus ( e . multiplyScalar ( c ) ) , b . setEndLocation ( c ) , 1 < this . numBones && this . bones [ 1 ] . setStartLocation ( c ) ) : ( g = 8 === this . baseboneConstraintType ? this . baseboneRelativeConstraintUV : this . baseboneConstraintUV , e . constrainedUV ( g , b . joint . min , b . joint . max ) , c = b . start . plus ( e . multiplyScalar ( c ) ) , b . setEndLocation ( c ) , f < this . numBones - 1 && this . bones [ f + 1 ] . setStartLocation ( c ) ) ) ; this . lastTargetLocation . copy ( a ) ; return this . bones [ this . numBones - 1 ] . end . distanceTo ( a ) } } ,
updateChainLength : function ( ) { this . chainLength = 0 ; for ( var a = this . numBones ; a -- ; ) this . chainLength += this . bones [ a ] . length } , cloneBones : function ( ) { for ( var a = [ ] , b = 0 , c = this . bones . length ; b < c ; b ++ ) a . push ( this . bones [ b ] . clone ( ) ) ; return a } } ) ; Object . assign ( C . prototype , { isStructure2D : ! 0 , update : function ( ) { for ( var a , b , c , d = new THREE . Vector3 , e , f = 0 ; f < this . numChains ; f ++ ) if ( a = this . chains [ f ] , b = this . targets [ f ] , e = a . getConnectedChainNumber ( ) , c = a . getBaseboneConstraintType ( ) , - 1 !== e && 6 !== c && ( e = this . chains [ e ] . bones [ a . getConnectedBoneNumber ( ) ] ,
a . setBaseLocation ( 20 === a . getBoneConnectionPoint ( ) ? e . start : e . end ) , e = e . getDirectionUV ( ) , 7 === c ? a . setBaseboneConstraintUV ( e ) : 8 === c && ( c = F . getSignedAngle ( e ) , c = a . getBaseboneConstraintUV ( ) . clone ( ) . rotate ( c ) , a . setBaseboneRelativeConstraintUV ( c ) ) ) , a . useEmbeddedTarget ? a . solveForEmbeddedTarget ( ) : a . solveForTarget ( b ) , this . isWithMesh ) for ( b = this . meshChains [ f ] , e = 0 ; e < a . numBones ; e ++ ) c = a . bones [ e ] , b [ e ] . position . set ( c . start . x , c . start . y , 0 ) , b [ e ] . lookAt ( d . set ( c . end . x , c . end . y , 0 ) ) } , setFixedBaseMode : function ( a ) { this . fixedBaseMode =
a ; a = this . numChains ; for ( var b ; a -- ; ) b = this . chains [ a ] . getConnectedChainNumber ( ) , - 1 === b && this . chains [ a ] . setFixedBaseMode ( this . fixedBaseMode ) } , clear : function ( ) { this . clearAllBoneMesh ( ) ; var a ; for ( a = this . numChains ; a -- ; ) this . remove ( a ) ; this . chains = [ ] ; this . meshChains = [ ] ; this . targets = [ ] } , add : function ( a , b , c ) { this . chains . push ( a ) ; this . targets . push ( b ) ; this . numChains ++ ; c && this . addChainMeshs ( a ) } , remove : function ( a ) { this . chains [ a ] . clear ( ) ; this . chains . splice ( a , 1 ) ; this . meshChains . splice ( a , 1 ) ; this . targets . splice ( a , 1 ) ; this . numChains -- } ,
getNumChains : function ( ) { return this . numChains } , getChain : function ( a ) { return this . chains [ a ] } , connectChain : function ( a , b , c , d , e , f , h ) { d = d || "end" ; if ( b > this . numChains ) p . error ( "Chain not existe !" ) ; else if ( c > this . chains [ b ] . numBones ) p . error ( "Bone not existe !" ) ; else { a = a . clone ( ) ; a . setBoneConnectionPoint ( "end" === d ? 21 : 20 ) ; a . setConnectedChainNumber ( b ) ; a . setConnectedBoneNumber ( c ) ; b = "end" === d ? this . chains [ b ] . bones [ c ] . end : this . chains [ b ] . bones [ c ] . start ; a . setBaseLocation ( b ) ; a . setFixedBaseMode ( ! 0 ) ; for ( c = 0 ; c < a . numBones ; c ++ ) a . bones [ c ] . start . add ( b ) ,
2020-10-13 04:48:28 +08:00
a . bones [ c ] . end . add ( b ) ; this . add ( a , e , f ) } } , addChainMeshs : function ( a , b ) { this . isWithMesh = ! 0 ; b = [ ] ; for ( var c = a . bones . length , d = 0 ; d < c ; d ++ ) b . push ( this . addBoneMesh ( a . bones [ d ] ) ) ; this . meshChains . push ( b ) } , addBoneMesh : function ( a ) { var b = a . length , c = a . color ; a = new THREE . CylinderBufferGeometry ( 1 , . 5 , b , 4 ) ; a . applyMatrix4 ( ( new THREE . Matrix4 ) . makeRotationX ( - m . pi90 ) ) ; a . applyMatrix4 ( ( new THREE . Matrix4 ) . makeTranslation ( 0 , 0 , . 5 * b ) ) ; b = new THREE . MeshStandardMaterial ( { color : c , wireframe : ! 1 , shadowSide : ! 1 } ) ; new THREE . MeshBasicMaterial ( { wireframe : ! 0 } ) ;
2019-12-16 03:04:31 +08:00
b = new THREE . Mesh ( a , b ) ; b . castShadow = ! 0 ; b . receiveShadow = ! 0 ; this . scene . add ( b ) ; return b } , clearAllBoneMesh : function ( ) { if ( this . isWithMesh ) { var a , b ; for ( a = this . meshChains . length ; a -- ; ) { for ( b = this . meshChains [ a ] . length ; b -- ; ) { var c = this . meshChains [ a ] [ b ] ; this . scene . remove ( c ) ; c . geometry . dispose ( ) ; c . material . dispose ( ) } this . meshChains [ a ] = [ ] } this . meshChains = [ ] } } } ) ; Object . assign ( D . prototype , { isIKSolver : ! 0 } ) ; Object . assign ( E . prototype , { isIKSolver : ! 0 } ) ; h . _Math = m ; h . V2 = l ; h . V3 = f ; h . M3 = y ; h . Q = u ; h . Joint3D = v ; h . Bone3D = r ; h . Chain3D =
z ; h . Structure3D = B ; h . Joint2D = w ; h . Bone2D = x ; h . Chain2D = A ; h . Structure2D = C ; h . IKSolver = D ; h . HISolver = E ; h . REVISION = "1.3.3" ; h . PRECISION = . 001 ; h . PRECISION _DEG = . 01 ; h . MAX _VALUE = Infinity ; h . PI = q ; h . TORAD = n ; h . TODEG = G ; h . NONE = 1 ; h . GLOBAL _ROTOR = 2 ; h . GLOBAL _HINGE = 3 ; h . LOCAL _ROTOR = 4 ; h . LOCAL _HINGE = 5 ; h . GLOBAL _ABSOLUTE = 6 ; h . LOCAL _RELATIVE = 7 ; h . LOCAL _ABSOLUTE = 8 ; h . J _BALL = 10 ; h . J _LOCAL = 11 ; h . J _GLOBAL = 12 ; h . START = 20 ; h . END = 21 ; h . X _AXE = H ; h . Y _AXE = I ; h . Z _AXE = J ; h . X _NEG = K ; h . Y _NEG = L ; h . Z _NEG = M ; h . UP = F ; h . DOWN = N ; h . LEFT = O ; h . RIGHT = P ; Object . defineProperty ( h ,
"__esModule" , { value : ! 0 } ) } ) ;