1
- import { isCurrentFormat as condition } from '../blueprintFormat'
1
+ import { isCurrentFormat as condition , isCurrentFormat } from '../blueprintFormat'
2
2
import { PACKAGE } from '../constants'
3
+ import { roundToNth } from '../util/misc'
3
4
import { type ContextProperty , createBlockbenchMod } from '../util/moddingTools'
4
5
5
6
createBlockbenchMod (
@@ -19,3 +20,71 @@ createBlockbenchMod(
19
20
context . configs ?. delete ( )
20
21
}
21
22
)
23
+
24
+ createBlockbenchMod (
25
+ `${ PACKAGE . name } :boneInterpolationMod` ,
26
+ {
27
+ orignalInterpolate : BoneAnimator . prototype . interpolate ,
28
+ } ,
29
+ context => {
30
+ BoneAnimator . prototype . interpolate = function (
31
+ this : BoneAnimator ,
32
+ channel ,
33
+ allowExpression ,
34
+ axis
35
+ ) {
36
+ if ( ! isCurrentFormat ( ) ) {
37
+ return context . orignalInterpolate . call ( this , channel , allowExpression , axis )
38
+ }
39
+
40
+ const actualTime = this . animation . time
41
+ try {
42
+ Timeline . time = roundToNth ( this . animation . time , 20 )
43
+
44
+ let before : ArrayVector3 | false
45
+ let after : ArrayVector3 | false
46
+ let beforeTime : number
47
+ let afterTime : number
48
+
49
+ if ( Timeline . time < actualTime ) {
50
+ beforeTime = Timeline . time
51
+ before = context . orignalInterpolate . call ( this , channel , allowExpression , axis )
52
+ if ( ! before ) return false
53
+
54
+ afterTime = roundToNth ( Timeline . time + 0.05 , 20 )
55
+ Timeline . time = afterTime
56
+ after = context . orignalInterpolate . call ( this , channel , allowExpression , axis )
57
+ if ( ! after ) return false
58
+ } else {
59
+ afterTime = Timeline . time
60
+ after = context . orignalInterpolate . call ( this , channel , allowExpression , axis )
61
+ if ( ! after ) return false
62
+
63
+ beforeTime = roundToNth ( Timeline . time - 0.05 , 20 )
64
+ Timeline . time = beforeTime
65
+ before = context . orignalInterpolate . call ( this , channel , allowExpression , axis )
66
+ if ( ! before ) return false
67
+ }
68
+ const diff = ( actualTime - beforeTime ) / ( afterTime - beforeTime )
69
+
70
+ const result : ArrayVector3 = [
71
+ Math . lerp ( before [ 0 ] , after [ 0 ] , diff ) ,
72
+ Math . lerp ( before [ 1 ] , after [ 1 ] , diff ) ,
73
+ Math . lerp ( before [ 2 ] , after [ 2 ] , diff ) ,
74
+ ]
75
+ // console.log(diff)
76
+
77
+ return result
78
+
79
+ // context.orignalInterpolate.call(this, channel, allowExpression, axis)
80
+ } finally {
81
+ Timeline . time = actualTime
82
+ }
83
+ }
84
+
85
+ return context
86
+ } ,
87
+ context => {
88
+ context . orignalInterpolate = BoneAnimator . prototype . interpolate
89
+ }
90
+ )
0 commit comments