@@ -125,12 +125,12 @@ export const allPartNames = posePartNames.concat(facePartNames);
125
125
// Represents a bone formed by two part keypoints.
126
126
export class Bone {
127
127
constructor ( kp0 , kp1 , skeleton , type ) {
128
+ console . log ( 'constructing...' ) ;
128
129
this . name = `${ kp0 . name } -${ kp1 . name } ` ;
129
130
this . kp0 = kp0 ;
130
131
this . kp1 = kp1 ;
131
132
this . skeleton = skeleton ;
132
133
this . type = type ;
133
- this . boneLine = new paper . default . Path ( kp0 . position , kp1 . position ) ;
134
134
this . boneColor = ColorUtils . fromStringHash ( this . name ) ;
135
135
this . boneColor . saturation += 0.5 ;
136
136
} ;
@@ -142,11 +142,12 @@ export class Bone {
142
142
let dir = this . kp1 . position . subtract ( this . kp0 . position ) . normalize ( ) ;
143
143
let n = dir . clone ( ) ;
144
144
n . angle += 90 ;
145
- let closestP = this . boneLine . getNearestPoint ( p ) ;
145
+ let closestP = MathUtils . getClosestPointOnSegment ( this . kp0 . position , this . kp1 . position , p ) ;
146
146
let v = p . subtract ( closestP ) ;
147
147
let dirProjD = v . dot ( dir ) ;
148
148
let dirProjN = v . dot ( n ) ;
149
- let anchorPerc = closestP . subtract ( this . kp0 . position ) . length / this . boneLine . length ;
149
+ let d = this . kp0 . position . subtract ( this . kp1 . position ) . length ;
150
+ let anchorPerc = closestP . subtract ( this . kp0 . position ) . length / d ;
150
151
return {
151
152
transform : new paper . default . Point ( dirProjD , dirProjN ) ,
152
153
anchorPerc : anchorPerc ,
@@ -282,7 +283,7 @@ export class Skeleton {
282
283
let leftLowerLipBottom0 = getKeyPointFromSVG ( skeletonGroup , 'leftLowerLipBottom0' ) ;
283
284
let leftLowerLipBottom1 = getKeyPointFromSVG ( skeletonGroup , 'leftLowerLipBottom1' ) ;
284
285
let lowerLipBottomMid = getKeyPointFromSVG ( skeletonGroup , 'lowerLipBottomMid' ) ;
285
-
286
+
286
287
this . bLeftShoulderRightShoulder = new Bone ( leftShoulder , rightShoulder , this , 'body' ) ;
287
288
this . bRightShoulderRightHip = new Bone ( rightShoulder , rightHip , this , 'body' ) ;
288
289
this . bLeftHipRightHip = new Bone ( leftHip , rightHip , this , 'body' ) ;
@@ -364,6 +365,7 @@ export class Skeleton {
364
365
this . bRightMouthCornerRightLowerLipBottom0 = new Bone ( rightMouthCorner , rightLowerLipBottom0 , this , 'face' ) ;
365
366
this . bRightLowerLipBottom0RightLowerLipBottom1 = new Bone ( rightLowerLipBottom0 , rightLowerLipBottom1 , this , 'face' ) ;
366
367
this . bRightLowerLipBottom1LowerLipBottomMid = new Bone ( rightLowerLipBottom1 , lowerLipBottomMid , this , 'face' ) ;
368
+ console . log ( 'Done' ) ;
367
369
368
370
this . faceBones = [
369
371
// Face
@@ -589,7 +591,9 @@ export class Skeleton {
589
591
let minDistance = Infinity ;
590
592
let boneGroup = this . boneGroups [ boneGroupKey ] ;
591
593
boneGroup . forEach ( bone => {
592
- minDistance = Math . min ( minDistance , bone . boneLine . getNearestPoint ( point ) . getDistance ( point ) ) ;
594
+ let d = MathUtils . getClosestPointOnSegment ( bone . kp0 . position , bone . kp1 . position , point )
595
+ . getDistance ( point ) ;
596
+ minDistance = Math . min ( minDistance , d ) ;
593
597
} ) ;
594
598
minDistances [ boneGroupKey ] = minDistance ;
595
599
} ) ;
0 commit comments