-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlendCharacterGui.js
executable file
·207 lines (130 loc) · 4.21 KB
/
BlendCharacterGui.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/**
* @author Michael Guerrero / http://realitymeltdown.com
*/
function BlendCharacterGui( animations ) {
var controls = {
gui: null,
"Show Model": true,
"Show Skeleton": false,
"Time Scale": 1.0,
"Step Size": 0.016,
"Crossfade Time": 3.5,
"idle": 0.33,
"walk": 0.33,
"run": 0.33
};
var animations = animations;
this.showModel = function() {
return controls[ 'Show Model' ];
};
this.showSkeleton = function() {
return controls[ 'Show Skeleton' ];
};
this.getTimeScale = function() {
return controls[ 'Time Scale' ];
};
this.update = function() {
controls[ 'idle' ] = animations[ 'idle' ].weight;
controls[ 'walk' ] = animations[ 'walk' ].weight;
controls[ 'run' ] = animations[ 'run' ].weight;
};
var init = function() {
controls.gui = new dat.GUI();
var settings = controls.gui.addFolder( 'Settings' );
var playback = controls.gui.addFolder( 'Playback' );
var blending = controls.gui.addFolder( 'Blend Tuning' );
settings.add( controls, "Show Model" ).onChange( controls.showModelChanged );
settings.add( controls, "Show Skeleton" ).onChange( controls.showSkeletonChanged );
settings.add( controls, "Time Scale", 0, 1, 0.01 );
settings.add( controls, "Step Size", 0.01, 0.1, 0.01 );
settings.add( controls, "Crossfade Time", 0.1, 6.0, 0.05 );
// These controls execute functions
playback.add( controls, "start" );
playback.add( controls, "pause" );
playback.add( controls, "step" );
playback.add( controls, "idle to walk" );
playback.add( controls, "walk to run" );
playback.add( controls, "warp walk to run" );
blending.add( controls, "idle", 0, 1, 0.01 ).listen().onChange( controls.weight );
blending.add( controls, "walk", 0, 1, 0.01 ).listen().onChange( controls.weight );
blending.add( controls, "run", 0, 1, 0.01 ).listen().onChange( controls.weight );
settings.open();
playback.open();
blending.open();
};
var getAnimationData = function() {
return {
detail: {
anims: [ "idle", "walk", "run" ],
weights: [ controls[ 'idle' ],
controls[ 'walk' ],
controls[ 'run' ] ]
}
};
};
controls.start = function() {
var startEvent = new CustomEvent( 'start-animation', getAnimationData() );
window.dispatchEvent( startEvent );
};
controls.stop = function() {
var stopEvent = new CustomEvent( 'stop-animation' );
window.dispatchEvent( stopEvent );
};
controls.pause = function() {
var pauseEvent = new CustomEvent( 'pause-animation' );
window.dispatchEvent( pauseEvent );
};
controls.step = function() {
var stepData = { detail: { stepSize: controls[ 'Step Size' ] } };
window.dispatchEvent( new CustomEvent( 'step-animation', stepData ) );
};
controls.weight = function() {
// renormalize
var sum = controls[ 'idle' ] + controls[ 'walk' ] + controls[ 'run' ];
controls[ 'idle' ] /= sum;
controls[ 'walk' ] /= sum;
controls[ 'run' ] /= sum;
var weightEvent = new CustomEvent( 'weight-animation', getAnimationData() );
window.dispatchEvent( weightEvent );
};
controls.crossfade = function( from, to ) {
var fadeData = getAnimationData();
fadeData.detail.from = from;
fadeData.detail.to = to;
fadeData.detail.time = controls[ "Crossfade Time" ];
window.dispatchEvent( new CustomEvent( 'crossfade', fadeData ) );
};
controls.warp = function( from, to ) {
var warpData = getAnimationData();
warpData.detail.from = 'walk';
warpData.detail.to = 'run';
warpData.detail.time = controls[ "Crossfade Time" ];
window.dispatchEvent( new CustomEvent( 'warp', warpData ) );
};
controls[ 'idle to walk' ] = function() {
controls.crossfade( 'idle', 'walk' );
};
controls[ 'walk to run' ] = function() {
controls.crossfade( 'walk', 'run' );
};
controls[ 'warp walk to run' ] = function() {
controls.warp( 'walk', 'run' );
};
controls.showSkeletonChanged = function() {
var data = {
detail: {
shouldShow: controls[ 'Show Skeleton' ]
}
};
window.dispatchEvent( new CustomEvent( 'toggle-show-skeleton', data ) );
};
controls.showModelChanged = function() {
var data = {
detail: {
shouldShow: controls[ 'Show Model' ]
}
};
window.dispatchEvent( new CustomEvent( 'toggle-show-model', data ) );
};
init.call( this );
}