Normand Briere
2018-07-01 89c1ad67bc65d24ceadfa9e95f8c5515283f1e97
Mocap.java
....@@ -26,6 +26,456 @@
2626 public class Mocap extends Object3D
2727 {
2828 static final long serialVersionUID = 7437391692559853707L;
29
+
30
+ void Fade()
31
+ {
32
+ if (currentbones == null || CameraPane.fullreset)
33
+ return;
34
+
35
+ cVector temp = new cVector();
36
+
37
+ int numframes = bvh.animation.getNumFrames();
38
+
39
+ int b;
40
+ float[] data;
41
+ Quat4d quatstart = new Quat4d();
42
+ Quat4d quatend = new Quat4d();
43
+ Quat4d quat = new Quat4d();
44
+ Matrix4d mat4d = new Matrix4d();
45
+ double[][] rot = new double[4][4];
46
+ for (b=numbones; --b>=0;) // HIP ROTATION: 0;)
47
+ {
48
+ // int hipindex = get(0)._index;
49
+
50
+// assert(get(0).get(0)._isHip);
51
+
52
+ // if (b == hipindex)
53
+ // continue;
54
+
55
+ data = bvh.animation.getBoneData(b);
56
+
57
+ int dof = 3; // data.length/numframes;
58
+
59
+ if (b == 0)
60
+ {
61
+ dof = 6;
62
+ }
63
+ // assert(dof == 3);
64
+
65
+ int boneframe3 = (b-1)*3; // dof;
66
+
67
+ // System.err.println("Bone #" + b + ": dof = " + dof);
68
+ int fadein = 45; // 120;
69
+
70
+ // if (b == hipindex)
71
+ // fadein *= 5;
72
+
73
+ if (fadein > numframes)
74
+ fadein = 0; // numframes;
75
+
76
+ for (int fi=fadein; --fi>=0;)
77
+ //for (int f=numframes; --f>=0;)
78
+ {
79
+ int f = fi + GetFirstFrame();
80
+
81
+ int f3 = f*dof;
82
+
83
+ float k = fi;
84
+
85
+ k /= fadein - 1;
86
+
87
+ if (Float.isNaN(k))
88
+ k = 1; // 0/0
89
+
90
+ k = (float) (-Math.cos(k*Math.PI));
91
+ k += 1;
92
+ k /= 2;
93
+
94
+ int start = 3;
95
+ int end = 0;
96
+
97
+ if (dof == 6)
98
+ {
99
+ start = 6;
100
+ end = 3;
101
+ }
102
+
103
+ if (b == 0)
104
+ {
105
+ for (int i=start; --i>=end;)
106
+ {
107
+ //data[f3 + i] += pos[i] - data[frame3 + i];
108
+// data[f3 + i] = k*data[f3+i] + (1-k)*
109
+// currentbones[boneframe3 + i-end];
110
+// data[f3 + i] = (float)CurveAngle(data[f3+i], currenthip[i], 1-k);
111
+ }
112
+
113
+ // TODO: translation
114
+
115
+// _t1.setIdentity();
116
+// _t2.setIdentity();
117
+// _t2.rotZ(currentbones[boneframe3 + start-1-end]);
118
+// _t1.mul(_t2);
119
+// _t2.setIdentity();
120
+// if (b == 0)
121
+// {
122
+// _t2.rotY(currentbones[boneframe3 + start-2-end]);
123
+// _t1.mul(_t2);
124
+// _t2.setIdentity();
125
+// _t2.rotX(currentbones[boneframe3 + start-3-end]);
126
+// }
127
+// else
128
+// {
129
+// _t2.rotX(currentbones[boneframe3 + start-2-end]);
130
+// _t1.mul(_t2);
131
+// _t2.setIdentity();
132
+// _t2.rotY(currentbones[boneframe3 + start-3-end]);
133
+// }
134
+// _t1.mul(_t2);
135
+// _t2.setIdentity();
136
+//
137
+// _t1.get(mat4d);
138
+//
139
+// mat4d.get(quatstart);
140
+//
141
+// _t1.setIdentity();
142
+// _t2.setIdentity();
143
+// _t2.rotZ(data[f3 + start-1]);
144
+// _t1.mul(_t2);
145
+// _t2.setIdentity();
146
+// if (b == 0)
147
+// {
148
+// _t2.rotY(data[f3 + start-2]);
149
+// _t1.mul(_t2);
150
+// _t2.setIdentity();
151
+// _t2.rotX(data[f3 + start-3]);
152
+// }
153
+// else
154
+// {
155
+// _t2.rotX(data[f3 + start-2]);
156
+// _t1.mul(_t2);
157
+// _t2.setIdentity();
158
+// _t2.rotY(data[f3 + start-3]);
159
+// }
160
+//
161
+// _t1.mul(_t2);
162
+// _t2.setIdentity();
163
+//
164
+// _t1.get(mat4d);
165
+//
166
+// mat4d.get(quatend);
167
+//
168
+// double dot = quatstart.x*quatend.x +
169
+// quatstart.y*quatend.y +
170
+// quatstart.z*quatend.z +
171
+// quatstart.w*quatend.w
172
+// ;
173
+//
174
+// if (dot < 0)
175
+// {
176
+// quatend.x *= -1;
177
+// quatend.y *= -1;
178
+// quatend.z *= -1;
179
+// quatend.w *= -1;
180
+// }
181
+//
182
+// // k = 1-k;
183
+//
184
+// quat.x = (1-k)*quatstart.x + k*quatend.x;
185
+// quat.y = (1-k)*quatstart.y + k*quatend.y;
186
+// quat.z = (1-k)*quatstart.z + k*quatend.z;
187
+// quat.w = (1-k)*quatstart.w + k*quatend.w;
188
+//
189
+// quat.normalize();
190
+//
191
+// mat4d.set(quat);
192
+//
193
+// cJ3D.SetTransform(rot, mat4d);
194
+//
195
+// matrixToEulerXYZ(rot, temp);
196
+//
197
+// data[f3 + start-1] = -(float)temp.z;
198
+//
199
+// if (b == 0)
200
+// {
201
+// data[f3 + start-2] = -(float)temp.y;
202
+// data[f3 + start-3] = -(float)temp.x;
203
+// }
204
+// else
205
+// {
206
+// data[f3 + start-2] = -(float)temp.x;
207
+// data[f3 + start-3] = -(float)temp.y;
208
+// }
209
+ }
210
+ else
211
+ {
212
+ for (int i=start; --i>=end;)
213
+ {
214
+ //data[f3 + i] += pos[i] - data[frame3 + i];
215
+// data[f3 + i] = k*data[f3+i] + (1-k)*
216
+// currentbones[boneframe3 + i-end];
217
+ data[f3 + i] = (float)CurveAngle(data[f3+i], currentbones[boneframe3 + i/*-end*/], 1-k);
218
+ }
219
+ }
220
+ }
221
+ }
222
+ }
223
+
224
+ // Updates the toParent matrix to keep the same position and orientation
225
+ // before resetting the mocap data.
226
+ void SetGlobalTransform()
227
+ {
228
+ //SetCurrentBones(frame);
229
+
230
+ cVector temp = new cVector();
231
+ cVector pos = new cVector();
232
+ cVector poship = new cVector();
233
+
234
+ double angleY = 0;
235
+ double angleYhip = 0;
236
+
237
+ Object3D hip = get(0);
238
+
239
+ if (hip.get(0).toParent == null)
240
+ {
241
+ hip.get(0).toParent = LA.newMatrix();
242
+ hip.get(0).fromParent = LA.newMatrix();
243
+ }
244
+
245
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
246
+ poship.x = matrix[3][0];
247
+ poship.y = matrix[3][1];
248
+ poship.z = matrix[3][2];
249
+
250
+ temp.x = 1;
251
+ temp.y = 0;
252
+ temp.z = 0;
253
+
254
+ LA.xformDir(temp, matrix, temp);
255
+
256
+ angleYhip = Math.atan2(-temp.z, temp.x);
257
+
258
+ LA.matIdentity(toParent);
259
+ LA.matYRotate(toParent, angleYhip);
260
+ LA.matTranslate(toParent, poship.x, poship.y, poship.z);
261
+
262
+// LA.matConcat(toParent, hip.get(0).toParent, toParent);
263
+
264
+ CameraPane.debugpoint.toParent[3][0] = poship.x;
265
+ CameraPane.debugpoint.toParent[3][1] = poship.y;
266
+ CameraPane.debugpoint.toParent[3][2] = poship.z;
267
+
268
+ LA.matInvert(toParent, fromParent);
269
+
270
+ LA.matIdentity(hip.get(0).toParent);
271
+ LA.matIdentity(hip.get(0).fromParent);
272
+
273
+// if (true)
274
+// return;
275
+
276
+ // Updates hip.get(0).toParent
277
+ setPose(hip, GetFirstFrame(), bvh.animation.getBoneData(hip._index));
278
+
279
+ // A = toParent; B = hip.get(0).toParent
280
+ // A'*B = A
281
+ // A' = A * B-1
282
+
283
+ poship.x = hip.get(0).toParent[3][0];
284
+ poship.y = hip.get(0).toParent[3][1];
285
+ poship.z = hip.get(0).toParent[3][2];
286
+
287
+ // AT*AR = A'T*BT*A'R*BR
288
+ //
289
+ LA.matInvert(hip.get(0).toParent, matrix);
290
+
291
+ //LA.matIdentity(matrix);
292
+ //LA.matTranslate(matrix, -poship.x, -poship.y, -poship.z);
293
+
294
+ LA.matConcat(toParent, matrix, toParent);
295
+
296
+// poship.x = hip.get(0).toParent[3][0];
297
+// poship.y = hip.get(0).toParent[3][1];
298
+// poship.z = hip.get(0).toParent[3][2];
299
+//
300
+// temp.x = 1;
301
+// temp.y = 0;
302
+// temp.z = 0;
303
+//
304
+// LA.xformDir(temp, hip.get(0).toParent, temp);
305
+//
306
+// angleYhip = Math.atan2(-temp.z, temp.x);
307
+
308
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
309
+ pos.x = hip.get(0).toParent[3][0];
310
+ pos.y = hip.get(0).toParent[3][1];
311
+ pos.z = hip.get(0).toParent[3][2];
312
+ LA.xformPos(new cVector(), hip.get(0).toParent, pos);
313
+ LA.xformPos(pos, toParent, pos);
314
+
315
+// temp.x = 1;
316
+// temp.y = 0;
317
+// temp.z = 0;
318
+//
319
+// LA.xformDir(temp, toParent, temp);
320
+//
321
+// angleY = Math.atan2(-temp.z, temp.x);
322
+//
323
+// LA.matIdentity(toParent);
324
+// LA.matYRotate(toParent, angleY - angleYhip);
325
+// LA.matTranslate(toParent, pos.x - poship.x, pos.y - poship.y, pos.z - poship.z);
326
+
327
+ CameraPane.debugpoint2.toParent[3][0] = pos.x;
328
+ CameraPane.debugpoint2.toParent[3][1] = pos.y;
329
+ CameraPane.debugpoint2.toParent[3][2] = pos.z;
330
+
331
+ CameraPane.debugpoint3.toParent[3][0] = poship.x;
332
+ CameraPane.debugpoint3.toParent[3][1] = poship.y;
333
+ CameraPane.debugpoint3.toParent[3][2] = poship.z;
334
+
335
+ poship.x = toParent[3][0];
336
+ poship.y = toParent[3][1];
337
+ poship.z = toParent[3][2];
338
+
339
+ CameraPane.debugpoint4.toParent[3][0] = poship.x;
340
+ CameraPane.debugpoint4.toParent[3][1] = poship.y;
341
+ CameraPane.debugpoint4.toParent[3][2] = poship.z;
342
+
343
+ LA.matInvert(toParent, fromParent);
344
+ }
345
+
346
+ void LoadData()
347
+ {
348
+ float[] thedata = bvh.animation.getBoneData(0);
349
+
350
+// thedata[0] = 0;
351
+// thedata[1] = 0;
352
+// thedata[2] = 0;
353
+// thedata[3] = 0;
354
+// thedata[4] = 0;
355
+// thedata[5] = 0;
356
+
357
+ if (true)
358
+ return;
359
+
360
+ for (int b=numbones; --b>=0;)
361
+ //int b = 0;
362
+ {
363
+ thedata = bvh.animation.getBoneData(b);
364
+
365
+ int numframes = bvh.animation.getNumFrames();
366
+
367
+ int dof = 6; // thedata.length/numframes;
368
+
369
+ if (b > 0)
370
+ dof = 3;
371
+
372
+ if (dof != thedata.length/numframes)
373
+ {
374
+ System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (thedata.length/numframes));
375
+ dof = thedata.length/numframes;
376
+ }
377
+
378
+ //for (int f=numframes; --f>=offset;)
379
+ int firstframe = GetFirstFrame();
380
+ for (int f=0; f<numframes-firstframe; f++)
381
+ {
382
+ int f3 = f*dof;
383
+
384
+ //for (int i=3/*dof*/; --i>=0;)
385
+ for (int i=dof; --i>=0;)
386
+ {
387
+ //thedata[f3 + i] += thedata[i] - thedata[offset*dof + i];
388
+ thedata[f3 + i] = thedata[f3 + firstframe*dof + i];
389
+ }
390
+ }
391
+ }
392
+ }
393
+
394
+ void ResetZero()
395
+ {
396
+ for (int b=numbones; --b>=0;)
397
+ {
398
+ float[] thedata = bvh.animation.getBoneData(b);
399
+
400
+ int numframes = bvh.animation.getNumFrames();
401
+
402
+ int dof = 6;
403
+
404
+ if (b > 0)
405
+ dof = 3;
406
+
407
+ for (int i=dof; --i>=0;)
408
+ {
409
+ thedata[i] = 0;
410
+ }
411
+ }
412
+ }
413
+
414
+ void SetCurrentBones(int frame)
415
+ {
416
+ if (frame == 0)
417
+ {
418
+ //frame = 1;
419
+ }
420
+
421
+ if (currentbones == null)
422
+ {
423
+ currentbones = new double[(numbones-1)*3];
424
+ currenthip = new double[6];
425
+ }
426
+
427
+ for (int b=numbones; --b>=1;) // HIP ROTATION: 0;)
428
+ //int b = 0;
429
+ {
430
+ float[] data = bvh.animation.getBoneData(b);
431
+
432
+ // int numframes = bvh.animation.getNumFrames();
433
+
434
+ int dof = 6; // data.length/numframes;
435
+
436
+ if (b > 0)
437
+ dof = 3;
438
+
439
+ //assert(dof == 3);
440
+
441
+ // System.err.println("Bone #" + b + ": dof = " + dof);
442
+ int theframe = // 1; // baseframe;
443
+ frame;
444
+
445
+ int frame3 = theframe*dof;
446
+ int bone3 = (b-1)*dof;
447
+
448
+ int start = 3;
449
+ int end = 0;
450
+
451
+ if (dof == 6)
452
+ {
453
+ start = 6;
454
+ //end = 3;
455
+ }
456
+
457
+ for (int i=start; --i>=end;)
458
+ {
459
+ currentbones[bone3 + i/*-end*/] = data[frame3 + i];
460
+ }
461
+ }
462
+
463
+ float[] data = bvh.animation.getBoneData(0);
464
+
465
+ int dof = 6;
466
+
467
+ int theframe = frame;
468
+
469
+ int frame3 = theframe*dof;
470
+
471
+ int start = 6;
472
+ int end = 0;
473
+
474
+ for (int i=start; --i>=end;)
475
+ {
476
+ currenthip[i] = data[frame3 + i];
477
+ }
478
+ }
29479
30480 void WriteTo(java.io.Writer writer) throws Exception
31481 {
....@@ -359,7 +809,7 @@
359809 // //GetFileRoot();
360810
361811 // sept 2014: //
362
- GraphreeD.RENDERME = 3; // patch for Merge objects
812
+ GrafreeD.RENDERME = 3; // patch for Merge objects
363813 float[] thedata = bvh.animation.getBoneData(0);
364814
365815 os.x = (float) (path.get(i).toParent[3][0]); // - thedata[frame*6]);
....@@ -705,7 +1155,7 @@
7051155 // skip first node: translation
7061156 // Object3D b = input.get(0);
7071157
708
- setPose(input, f, data.getBoneData(input._index), false); //, null);
1158
+ setPose(input, f, data.getBoneData(input._index)); //, false); //, null);
7091159 }
7101160
7111161 //mocap.figure.Bone[] children = b.getChildren();
....@@ -754,7 +1204,7 @@
7541204 //long
7551205 // june 2014 floorid = sourcenode.getFloor(floor); // , sourcenode.parent);
7561206
757
- CameraPane.debugpoints[0].name = "Floor = " + floorid;
1207
+ CameraPane.debugpoints[0].name = ""; // "Floor = " + 0; // floorid;
7581208 CameraPane.debugpoints[0].toParent[3][0] = floor.x;
7591209 CameraPane.debugpoints[0].toParent[3][1] = floor.y;
7601210 CameraPane.debugpoints[0].toParent[3][2] = floor.z;
....@@ -770,7 +1220,7 @@
7701220
7711221 this.count--; // currently drawing itself
7721222
773
- CameraPane.debugpoints[7].name = "Centroid = " + groundid; // centroid;
1223
+ CameraPane.debugpoints[7].name = ""; // Centroid = " + 0; // groundid; // centroid;
7741224 CameraPane.debugpoints[7].toParent[3][0] = centroid.x;
7751225 CameraPane.debugpoints[7].toParent[3][1] = centroid.y;
7761226 CameraPane.debugpoints[7].toParent[3][2] = centroid.z;
....@@ -795,7 +1245,7 @@
7951245
7961246 // jan 2014 sourcenode.parent.TransformToWorld(tmp);
7971247
798
- CameraPane.debugpoints[1].name = "C+";
1248
+ CameraPane.debugpoints[1].name = ""; // "C+";
7991249 CameraPane.debugpoints[1].toParent[3][0] = tmp.x;
8001250 CameraPane.debugpoints[1].toParent[3][1] = tmp.y;
8011251 CameraPane.debugpoints[1].toParent[3][2] = tmp.z;
....@@ -814,7 +1264,7 @@
8141264 tmp.z = pinz;
8151265 }
8161266
817
- CameraPane.debugpoints[2].name = "Pin";
1267
+ CameraPane.debugpoints[2].name = ""; // "Pin";
8181268 CameraPane.debugpoints[2].toParent[3][0] = tmp.x;
8191269 CameraPane.debugpoints[2].toParent[3][1] = tmp.y;
8201270 CameraPane.debugpoints[2].toParent[3][2] = tmp.z;
....@@ -822,7 +1272,7 @@
8221272 //if (sourcenode.parent.parent != null)
8231273 // jan 2014 sourcenode.parent.TransformToLocal(tmp); //, tmp);
8241274
825
- CameraPane.debugpoints[3].name = "C-";
1275
+ CameraPane.debugpoints[3].name = ""; // "C-";
8261276 CameraPane.debugpoints[3].toParent[3][0] = tmp.x;
8271277 CameraPane.debugpoints[3].toParent[3][1] = tmp.y;
8281278 CameraPane.debugpoints[3].toParent[3][2] = tmp.z;
....@@ -895,14 +1345,14 @@
8951345 // if (sourcenode.parent.parent != null)
8961346 // sourcenode.parent.parent.TransformToWorld(floor); //, floor);
8971347
898
- CameraPane.debugpoints[5].name = "F++";
1348
+ CameraPane.debugpoints[5].name = ""; // "F++";
8991349 CameraPane.debugpoints[5].toParent[3][0] = floor.x;
9001350 CameraPane.debugpoints[5].toParent[3][1] = floor.y;
9011351 CameraPane.debugpoints[5].toParent[3][2] = floor.z;
9021352
9031353 floor.y = tempg;
9041354
905
- CameraPane.debugpoints[6].name = "F+-";
1355
+ CameraPane.debugpoints[6].name = ""; // "F+-";
9061356 CameraPane.debugpoints[6].toParent[3][0] = floor.x;
9071357 CameraPane.debugpoints[6].toParent[3][1] = floor.y;
9081358 CameraPane.debugpoints[6].toParent[3][2] = floor.z;
....@@ -921,7 +1371,7 @@
9211371 //groundz += sourcenode.parent.toParent[3][2] - posz;
9221372 }
9231373
924
- boolean footcontact = CameraPane.FOOTCONTACT; // false;
1374
+ boolean footcontact = false; // CameraPane.FOOTCONTACT; // false;
9251375
9261376 if (footcontact && ground != -123456)
9271377 {
....@@ -938,6 +1388,7 @@
9381388
9391389 groundid = floorid;
9401390
1391
+ // green
9411392 CameraPane.debugpoint.toParent[3][0] = groundx;
9421393 CameraPane.debugpoint.toParent[3][1] = floor.y;
9431394 CameraPane.debugpoint.toParent[3][2] = groundz;
....@@ -998,7 +1449,7 @@
9981449
9991450 lastsoundtime = CameraPane.framecount;
10001451
1001
- GraphreeD.hassound = true;
1452
+ GrafreeD.hassound = true;
10021453 }
10031454 // else
10041455 // System.out.println("skipped");
....@@ -1016,6 +1467,7 @@
10161467 // floor.z += posz;
10171468
10181469 // System.out.println("Allo " + sourcenode);
1470
+ // purple
10191471 CameraPane.debugpoint2.toParent[3][0] = floor.x;// + posx;
10201472 CameraPane.debugpoint2.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
10211473 CameraPane.debugpoint2.toParent[3][2] = floor.z;// + posz;
....@@ -1052,7 +1504,7 @@
10521504 v0.z = groundz - floor.z;
10531505
10541506 double distance = Math.sqrt(v0.dot(v0));
1055
- double maxdist = 0.004;
1507
+ double maxdist = 0.04;
10561508
10571509 if (distance > maxdist)
10581510 {
....@@ -1078,8 +1530,27 @@
10781530 sourcenode.toParent = LA.newMatrix();
10791531 sourcenode.fromParent = LA.newMatrix();
10801532 }
1533
+
1534
+ v0.x = v0.z = 0;
1535
+
1536
+ this.get(0).TransformToWorld(v0);
1537
+
1538
+ // cyan
1539
+ CameraPane.debugpoint3.toParent[3][0] = v0.x;
1540
+ CameraPane.debugpoint3.toParent[3][1] = ground;
1541
+ CameraPane.debugpoint3.toParent[3][2] = v0.z;
1542
+
10811543 LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent);
10821544 LA.matInvert(sourcenode.toParent, sourcenode.fromParent);
1545
+
1546
+ v0.x = v0.z = 0;
1547
+
1548
+ this.get(0).TransformToWorld(v0);
1549
+
1550
+ // red
1551
+ CameraPane.debugpoint4.toParent[3][0] = v0.x;
1552
+ CameraPane.debugpoint4.toParent[3][1] = ground;
1553
+ CameraPane.debugpoint4.toParent[3][2] = v0.z;
10831554 }
10841555 }
10851556
....@@ -1199,6 +1670,7 @@
11991670 src.x = 0;
12001671 src.y = 0;
12011672 src.z = 0;
1673
+ LA.xformPos(src, get(0).get(0).toParent, src);
12021674 LA.xformPos(src, get(0).toParent, src);
12031675 LA.xformPos(src, toParent, src);
12041676 // LA.xformPos(src, rotsourcenode.toParent, src);
....@@ -1318,7 +1790,7 @@
13181790
13191791 rotsourcenode.TransformToWorld(test);
13201792
1321
- CameraPane.debugpoints[4].name = "ROT = "; // + test;
1793
+ CameraPane.debugpoints[4].name = ""; // "ROT = "; // + test;
13221794 CameraPane.debugpoints[4].toParent[3][0] = test.x;
13231795 CameraPane.debugpoints[4].toParent[3][1] = test.y;
13241796 CameraPane.debugpoints[4].toParent[3][2] = test.z;
....@@ -1542,6 +2014,7 @@
15422014 toParent = LA.newMatrix();
15432015 fromParent = LA.newMatrix();
15442016 }
2017
+
15452018 LA.matConcat(toParent, rotsourcenode.toParent, toParent);
15462019 LA.matInvert(toParent, fromParent);
15472020
....@@ -1677,7 +2150,7 @@
16772150 }
16782151
16792152 if (!smoothed)
1680
- for (int i=4; --i>=0;)
2153
+ for (int i=0; --i>=0;)
16812154 SmoothAnimData(); // much reduces shakiness
16822155
16832156 smoothed = true;
....@@ -1759,12 +2232,26 @@
17592232 if (!live) // aout 2013
17602233 return;
17612234
1762
- cVector centroid = new cVector();
1763
- cVector floor = new cVector();
1764
-
1765
- Object3D sourcenode = GetFileRoot();
2235
+ //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);
2236
+ try
2237
+ {
2238
+ SetPose(GetSkeleton(), bvh.animation, f);
2239
+ SetCurrentBones(frame);
2240
+ }
2241
+ catch (Exception e)
2242
+ {
2243
+ e.printStackTrace();
2244
+ }
17662245
1767
- boolean success; // = sourcenode.getCentroid(centroid);
2246
+ if (true)
2247
+ return;
2248
+
2249
+ cVector centroid = new cVector();
2250
+ cVector floor = new cVector();
2251
+
2252
+ Object3D sourcenode = GetFileRoot();
2253
+
2254
+ boolean success; // = sourcenode.getCentroid(centroid);
17682255 // if (!success)
17692256 // {
17702257 // //assert(success);
....@@ -1772,16 +2259,6 @@
17722259 // System.out.println("No centroid for " + sourcenode);
17732260 // }
17742261
1775
- //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);
1776
- try
1777
- {
1778
- SetPose(GetSkeleton(), bvh.animation, f);
1779
- }
1780
- catch (Exception e)
1781
- {
1782
- e.printStackTrace();
1783
- }
1784
-
17852262 if (sourcenode.parent == null && sourcenode.fileparent == null)
17862263 {
17872264 // No GFD
....@@ -1835,7 +2312,7 @@
18352312 {
18362313 SetRotation(sourcenode, new cVector(floor), new cVector(centroid));
18372314 }
1838
-
2315
+
18392316 if (setposition)
18402317 {
18412318 if (floorobject != null)
....@@ -2029,7 +2506,7 @@
20292506 * @param frame
20302507 * Frame number
20312508 */
2032
- public void setPose(Object3D bone, int frame, float[] data, boolean fade) //, Point3d offsetTrans)
2509
+ public void setPose(Object3D bone, int frame, float[] data) //, boolean fade) //, Point3d offsetTrans)
20332510 {
20342511 if (!live) // aout 2013
20352512 return;
....@@ -2037,6 +2514,33 @@
20372514 cVector temp = new cVector();
20382515 cVector temp0 = new cVector();
20392516 double pos[] = new double[3];
2517
+ double angleY = 0;
2518
+ double sinY = 0;
2519
+ double cosY = 0;
2520
+
2521
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
2522
+ {
2523
+ bone.get(0).GlobalTransformInv();
2524
+
2525
+ temp.x = bone.get(0).globalTransform[3][0];
2526
+ temp.y = bone.get(0).globalTransform[3][1];
2527
+ temp.z = bone.get(0).globalTransform[3][2];
2528
+
2529
+ pos[0] = temp.x;
2530
+ pos[1] = temp.y;
2531
+ pos[2] = temp.z;
2532
+
2533
+ temp.x = 1;
2534
+ temp.y = 0;
2535
+ temp.z = 0;
2536
+
2537
+ LA.xformDir(temp, bone.get(0).globalTransform, temp);
2538
+
2539
+ sinY = temp.z;
2540
+ cosY = temp.x;
2541
+
2542
+ angleY = Math.atan2(-sinY, cosY);
2543
+ }
20402544
20412545 // Object3D obj = get(0);
20422546 // Object3D gp = this.parent;
....@@ -2166,15 +2670,15 @@
21662670 // set rotation
21672671 //if (bone._rotationEnabled)
21682672 if (//frame > 0 &&
2169
- !bone.skipmocap &&
2170
- !bone.name.contains("head") &&
2673
+ !bone.skipmocap //&&
2674
+ //!bone.name.contains("head") &&
21712675 // !bone.name.contains("rFoot") &&
21722676 // !bone.name.contains("lFoot") &&
2173
- !bone.name.contains("Pinky") &&
2174
- !bone.name.contains("Ring") &&
2175
- !bone.name.contains("Mid") &&
2176
- !bone.name.contains("Index") &&
2177
- !bone.name.contains("Thumb")
2677
+// !bone.name.contains("Pinky") &&
2678
+// !bone.name.contains("Ring") &&
2679
+// !bone.name.contains("Mid") &&
2680
+// !bone.name.contains("Index") &&
2681
+// !bone.name.contains("Thumb")
21782682 )
21792683 {
21802684 //_rotTG.setTransform(_t1);
....@@ -2207,15 +2711,17 @@
22072711 // CROWD
22082712 //cJ3D.GetTranslation(bone, _trans0);
22092713 //_trans.add(_trans0);
2210
- _transTF.setIdentity();
2714
+ //_transTF.setIdentity();
2715
+ _transTF.set(_t1);
22112716 _transTF.setTranslation(_trans);
22122717 // System.err.println("Translate: " + _transTF);
22132718 //_transTG.setTransform(_transTF);
2214
- cJ3D.ResetTransform(bone, _transTF, true); // translation node
2719
+ cJ3D.ResetTransform(bone.get(0), _transTF, true); // translation node
2720
+ //cJ3D.ResetTransform(bone, _transTF, true); // translation node
22152721 }
22162722 }
22172723
2218
- if (bone._isRoot && firsttimeafterload && frame > 0)
2724
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
22192725 {
22202726 assert(bone == get(0));
22212727
....@@ -2231,17 +2737,17 @@
22312737 // LA.matConcat(originmatrixinv, tempmatrixinv, fromParent); // ABC * (B'*C')^-1
22322738 //
22332739
2234
- Invariants();
2235
- bone.Invariants();
2236
- bone.get(0).Invariants();
2237
- // if (origin == null)
2238
- // origin = null;
2239
- origin.Invariants();
2240
- origin0.Invariants();
2740
+ Invariants();
2741
+ bone.Invariants();
2742
+ bone.get(0).Invariants();
2743
+ // if (origin == null)
2744
+ // origin = null;
2745
+ origin.Invariants();
2746
+ origin0.Invariants();
22412747
2242
-
2243
- LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2244
- LA.matConcat(origin.toParent, tempmatrix, toParent);
2748
+
2749
+//?? LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2750
+//?? LA.matConcat(origin.toParent, tempmatrix, toParent);
22452751
22462752 // matrixToEulerXYZ(toParent, temp);
22472753 // matrixToEulerXYZ(bone.get(0).toParent, temp);
....@@ -2275,7 +2781,7 @@
22752781 //
22762782 // mat4d.get(quat);
22772783
2278
- if (true) // hip correction
2784
+ if (false) // hip correction
22792785 {
22802786 _t2.setIdentity();
22812787
....@@ -2316,13 +2822,13 @@
23162822 //????? LA.matConcat(bone.get(0).toParent, bone.toParent, tempmatrix); // B' * C'
23172823 // LA.matConcat(origin.fromParent, tempmatrix, fromParent);
23182824
2319
- LA.matInvert(toParent, fromParent);
2825
+//?? LA.matInvert(toParent, fromParent);
23202826
2321
- Invariants();
2322
- bone.Invariants();
2323
- bone.get(0).Invariants();
2324
- origin.Invariants();
2325
- origin0.Invariants();
2827
+ Invariants();
2828
+ bone.Invariants();
2829
+ bone.get(0).Invariants();
2830
+ origin.Invariants();
2831
+ origin0.Invariants();
23262832
23272833 // LA.matInvert(fromParent, tempmatrix);
23282834 //
....@@ -2343,33 +2849,39 @@
23432849 // temp.x = data[0];
23442850 // temp.y = data[1];
23452851 // temp.z = data[2];
2346
- LA.xformPos(temp, origin0.toParent, temp0);
2852
+ LA.xformPos(temp, origin0.toParent, temp0); // NU
23472853
2348
-// bone.GlobalTransformInv();
2349
-
2350
- temp0.x = bone.globalTransform[3][0];
2351
- temp0.y = bone.globalTransform[3][1];
2352
- temp0.z = bone.globalTransform[3][2];
2353
-
2854
+// bone.get(0).GlobalTransformInv();
2855
+//
2856
+// temp0.x = bone.get(0).globalTransform[3][0];
2857
+// temp0.y = bone.get(0).globalTransform[3][1];
2858
+// temp0.z = bone.get(0).globalTransform[3][2];
2859
+//
23542860 // MEGA TEST // june 2014: necessary for precision? otherwise comment works
2355
-fromParent[3][0] = 0;
2356
-fromParent[3][1] = 0;
2357
-fromParent[3][2] = 0;
2358
-LA.matInvert(fromParent, toParent);
2861
+//fromParent[3][0] = 0;
2862
+//fromParent[3][1] = 0;
2863
+//fromParent[3][2] = 0;
2864
+//LA.matInvert(fromParent, toParent);
23592865
2360
- LA.xformPos(temp0, fromParent, temp);
2866
+ LA.xformPos(temp0, fromParent, temp); // NU
23612867 //LA.xformPos(temp, bone.fromParent, temp);
23622868 // float[] data;
23632869
2364
- pos[0] = temp.x;
2365
- pos[1] = temp.y;
2366
- pos[2] = temp.z;
2870
+// pos[0] = temp.x;
2871
+// pos[1] = temp.y;
2872
+// pos[2] = temp.z;
2873
+//
2874
+// temp.x = 1;
2875
+// temp.y = 0;
2876
+// temp.z = 0;
2877
+//
2878
+// LA.xformDir(temp, bone.get(0).globalTransform, temp);
23672879
23682880 // CameraPane.selectedpoint.toParent[3][0] = temp0.x;
23692881 // CameraPane.selectedpoint.toParent[3][1] = temp0.y;
23702882 // CameraPane.selectedpoint.toParent[3][2] = temp0.z;
23712883
2372
- int numframes = bvh.animation.getNumFrames();
2884
+ int numframes = bvh.animation.getNumFrames();
23732885
23742886 int b = 0;
23752887 {
....@@ -2377,12 +2889,12 @@
23772889
23782890 int dof = 6; /// data.length/numframes;
23792891
2380
- // july 2014
2381
- if (dof != data.length/numframes)
2382
- {
2383
- System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));
2384
- dof = data.length/numframes;
2385
- }
2892
+ // july 2014
2893
+ if (dof != data.length/numframes)
2894
+ {
2895
+ System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));
2896
+ dof = data.length/numframes;
2897
+ }
23862898
23872899
23882900 int theframe = 0; // baseframe;
....@@ -2434,17 +2946,26 @@
24342946 // }
24352947 // }
24362948
2437
- data[f3 + i] += pos[i] - data[frame3 + i];
2949
+ data[f3 + i] += /*pos[i]*/ - data[frame3 + i];
24382950
24392951 // if (f < 3)
24402952 // {
24412953 // System.out.print(data[f3 + i] + " ");
24422954 // }
24432955 }
2444
-// if (f < 3)
2445
-// {
2446
-// System.out.println();
2447
-// }
2956
+
2957
+ double t1 = data[f3 + 0];
2958
+ double t2 = data[f3 + 2];
2959
+
2960
+ data[f3 + 0] = (float)(cosY*t1 - sinY*t2);
2961
+ data[f3 + 2] = (float)(sinY*t1 + cosY*t2);
2962
+
2963
+ for (int i=3/*dof*/; --i>=0;)
2964
+ {
2965
+ data[f3 + i] += pos[i];
2966
+ }
2967
+
2968
+ data[f3 + 4] += angleY - data[frame3 + 4];
24482969 }
24492970 }
24502971
....@@ -2458,186 +2979,17 @@
24582979 // temp.y = data[1];
24592980 // temp.z = data[2];
24602981
2461
- if (fade && currentbones != null && !CameraPane.fullreset)
2462
- {
2463
- Quat4d quatstart = new Quat4d();
2464
- Quat4d quatend = new Quat4d();
2465
- Quat4d quat = new Quat4d();
2466
- Matrix4d mat4d = new Matrix4d();
2467
- double[][] rot = new double[4][4];
2468
-
2469
- for (b=numbones; --b>=1;) // HIP ROTATION: 0;)
2470
- {
2471
- int hipindex = get(0)._index;
2472
-
2473
-// assert(get(0).get(0)._isHip);
2474
-
2475
- // if (b == hipindex)
2476
- // continue;
2477
-
2478
- data = bvh.animation.getBoneData(b);
2479
-
2480
- int dof = 3; // data.length/numframes;
2481
-
2482
- // assert(dof == 3);
2483
-
2484
- int boneframe3 = b*3; // dof;
2485
-
2486
- // System.err.println("Bone #" + b + ": dof = " + dof);
2487
- int fadein = 45; // 120;
2488
-
2489
- // if (b == hipindex)
2490
- // fadein *= 5;
2491
-
2492
- if (fadein > numframes)
2493
- fadein = 0; // numframes;
2494
-
2495
- for (int fi=fadein; --fi>=0;)
2496
- //for (int f=numframes; --f>=0;)
2497
- {
2498
- int f = fi + GetFirstFrame();
2499
-
2500
- int f3 = f*dof;
2501
-
2502
- float k = fi;
2503
-
2504
- k /= fadein - 1;
2505
-
2506
- if (Float.isNaN(k))
2507
- k = 1; // 0/0
2508
-
2509
- k = (float) (-Math.cos(k*Math.PI));
2510
- k += 1;
2511
- k /= 2;
2512
-
2513
- int start = 3;
2514
- int end = 0;
2515
-
2516
- if (dof == 6)
2517
- {
2518
- start = 6;
2519
- end = 3;
2520
- }
2521
-
2522
- if (b == 0)
2523
- {
2524
- _t1.setIdentity();
2525
- _t2.setIdentity();
2526
- _t2.rotZ(currentbones[boneframe3 + start-1-end]);
2527
- _t1.mul(_t2);
2528
- _t2.setIdentity();
2529
- if (b == 0)
2530
- {
2531
- _t2.rotY(currentbones[boneframe3 + start-2-end]);
2532
- _t1.mul(_t2);
2533
- _t2.setIdentity();
2534
- _t2.rotX(currentbones[boneframe3 + start-3-end]);
2535
- }
2536
- else
2537
- {
2538
- _t2.rotX(currentbones[boneframe3 + start-2-end]);
2539
- _t1.mul(_t2);
2540
- _t2.setIdentity();
2541
- _t2.rotY(currentbones[boneframe3 + start-3-end]);
2542
- }
2543
- _t1.mul(_t2);
2544
- _t2.setIdentity();
2545
-
2546
- _t1.get(mat4d);
2547
-
2548
- mat4d.get(quatstart);
2549
-
2550
- _t1.setIdentity();
2551
- _t2.setIdentity();
2552
- _t2.rotZ(data[f3 + start-1]);
2553
- _t1.mul(_t2);
2554
- _t2.setIdentity();
2555
- if (b == 0)
2556
- {
2557
- _t2.rotY(data[f3 + start-2]);
2558
- _t1.mul(_t2);
2559
- _t2.setIdentity();
2560
- _t2.rotX(data[f3 + start-3]);
2561
- }
2562
- else
2563
- {
2564
- _t2.rotX(data[f3 + start-2]);
2565
- _t1.mul(_t2);
2566
- _t2.setIdentity();
2567
- _t2.rotY(data[f3 + start-3]);
2568
- }
2569
-
2570
- _t1.mul(_t2);
2571
- _t2.setIdentity();
2572
-
2573
- _t1.get(mat4d);
2574
-
2575
- mat4d.get(quatend);
2576
-
2577
- double dot = quatstart.x*quatend.x +
2578
- quatstart.y*quatend.y +
2579
- quatstart.z*quatend.z +
2580
- quatstart.w*quatend.w
2581
- ;
2582
-
2583
- if (dot < 0)
2584
- {
2585
- quatend.x *= -1;
2586
- quatend.y *= -1;
2587
- quatend.z *= -1;
2588
- quatend.w *= -1;
2589
- }
2590
-
2591
- // k = 1-k;
2592
-
2593
- quat.x = (1-k)*quatstart.x + k*quatend.x;
2594
- quat.y = (1-k)*quatstart.y + k*quatend.y;
2595
- quat.z = (1-k)*quatstart.z + k*quatend.z;
2596
- quat.w = (1-k)*quatstart.w + k*quatend.w;
2597
-
2598
- quat.normalize();
2599
-
2600
- mat4d.set(quat);
2601
-
2602
- cJ3D.SetTransform(rot, mat4d);
2603
-
2604
- matrixToEulerXYZ(rot, temp);
2605
-
2606
- data[f3 + start-1] = -(float)temp.z;
2607
-
2608
- if (b == 0)
2609
- {
2610
- data[f3 + start-2] = -(float)temp.y;
2611
- data[f3 + start-3] = -(float)temp.x;
2612
- }
2613
- else
2614
- {
2615
- data[f3 + start-2] = -(float)temp.x;
2616
- data[f3 + start-3] = -(float)temp.y;
2617
- }
2618
- }
2619
- else
2620
- {
2621
- for (int i=start; --i>=end;)
2622
- {
2623
- //data[f3 + i] += pos[i] - data[frame3 + i];
2624
- // data[f3 + i] = k*data[f3+i] + (1-k)*
2625
- // currentbones[boneframe3 + i-end];
2626
- data[f3 + i] = (float)CurveAngle(data[f3+i], currentbones[boneframe3 + i-end], 1-k);
2627
- }
2628
- }
2629
-
2630
- }
2631
- }
2632
-
2633
- }
2982
+// if (fade && currentbones != null && !CameraPane.fullreset)
2983
+// {
2984
+// Fade();
2985
+// }
26342986 }
2635
-
2987
+
26362988 if (false) // doesn't change anything bone._isRoot)
26372989 {
26382990 // Reset orientation
26392991 _t2.setIdentity();
2640
-
2992
+
26412993 double tx = bone.toParent[3][0];
26422994 double ty = bone.toParent[3][1];
26432995 double tz = bone.toParent[3][2];
....@@ -2646,9 +2998,9 @@
26462998 temp.y = 0;
26472999 temp.z = 0;
26483000 LA.xformDir(temp, bone.toParent, temp);
2649
-
3001
+
26503002 double angle = Math.atan2(-temp.z, temp.x);
2651
-
3003
+
26523004 _t2.rotY(angle);
26533005 // _t1.setIdentity();
26543006 // _t1.rotX(temp.x);
....@@ -2661,56 +3013,21 @@
26613013 // _t1.setIdentity();
26623014 // _t1.rotZ(temp.z);
26633015 // _t2.mul(_t1);
2664
-
3016
+
26653017 cJ3D.ResetTransform(bone, _t2, false);
2666
-
3018
+
26673019 bone.toParent[3][0] = tx;
26683020 bone.toParent[3][1] = ty;
26693021 bone.toParent[3][2] = tz;
26703022 }
26713023 }
26723024
2673
- if (currentbones == null)
2674
- currentbones = new double[numbones*3];
2675
-
2676
- for (int b=numbones; --b>=1;) // 0;)
2677
- //int b = 0;
2678
- {
2679
- data = bvh.animation.getBoneData(b);
2680
-
2681
- int numframes = bvh.animation.getNumFrames();
2682
-
2683
- int dof = 6; // data.length/numframes;
2684
-
2685
- if (b > 0)
2686
- dof = 3;
2687
-
2688
- //assert(dof == 3);
2689
-
2690
- // System.err.println("Bone #" + b + ": dof = " + dof);
2691
- int theframe = // 1; // baseframe;
2692
- frame;
2693
-
2694
- int frame3 = theframe*dof;
2695
- int bone3 = b*3; // dof;
2696
-
2697
- int start = 3;
2698
- int end = 0;
2699
-
2700
- if (dof == 6)
2701
- {
2702
- start = 6;
2703
- end = 3;
2704
- }
2705
- for (int i=start; --i>=end;)
2706
- {
2707
- currentbones[bone3 + i-end] = data[frame3 + i];
2708
- }
2709
- }
3025
+ // SetCurrentBones(frame);
27103026 }
27113027 }
27123028
2713
- static int offset = 1; // 5; // 10; // 5; // 100; // skip initial "T"
3029
+ // skip initial "T"
3030
+ static int offset = 1; // 5; // 10; // 5; // 100;
27143031
27153032 void ReadBVH()
27163033 {
....@@ -2746,7 +3063,7 @@
27463063
27473064 // assert(obj.name.equals("hip"));
27483065
2749
- Object3D rot = hip.get(0);
3066
+ //Object3D rot = hip.get(0);
27503067
27513068 // assert(obj.name == null); // .equals("hip#"));
27523069
....@@ -2756,8 +3073,8 @@
27563073 hip.fromParent = LA.newMatrix();
27573074 }
27583075
2759
- hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;
2760
- hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;
3076
+ //hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;
3077
+ //hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;
27613078
27623079 if (toParent == null)
27633080 {
....@@ -2769,25 +3086,28 @@
27693086 LA.matIdentity(fromParent);
27703087 // LA.matIdentity(hip.toParent);
27713088 // LA.matIdentity(hip.fromParent);
2772
- if (rot.toParent == null)
2773
- {
2774
- // june 2014
2775
- rot.toParent = LA.newMatrix();
2776
- rot.fromParent = LA.newMatrix();
2777
- }
2778
- LA.matIdentity(rot.toParent);
2779
- LA.matIdentity(rot.fromParent);
3089
+// if (rot.toParent == null)
3090
+// {
3091
+// // june 2014
3092
+// rot.toParent = LA.newMatrix();
3093
+// rot.fromParent = LA.newMatrix();
3094
+// }
3095
+// LA.matIdentity(rot.toParent);
3096
+// LA.matIdentity(rot.fromParent);
27803097
27813098 // july 2014
27823099 goalx = goalz = 0;
27833100 targetx = targetz = 0;
27843101
2785
- SetPositionDelta(true, true, true, false);
3102
+ //SetPositionDelta(true, true, true, false);
3103
+// LoadData();
3104
+// Rewind();
27863105
27873106 baseframe = frame = 0; // T pose. No offset.
27883107
27893108 // aout 2013 endframe = 0; // june 2013
27903109
3110
+ //ResetZero();
27913111 setPose(frame);
27923112 }
27933113
....@@ -2819,7 +3139,7 @@
28193139 baseframe += step;
28203140
28213141 //frame = baseframe;
2822
- frame += step;
3142
+ //frame += step;
28233143
28243144 // if (frame != baseframe)
28253145 // {
....@@ -2833,6 +3153,7 @@
28333153 if (lastframetest == 0)
28343154 lastframetest = bvh.animation.getNumFrames();
28353155
3156
+ // WARNING: RESET DESTROYS EVERYTHING
28363157 if (baseframe >= lastframetest) // july 2013 // - GetFirstFrame())
28373158 {
28383159 System.out.println("MOCAP reset: " + this.GetFileRoot() +
....@@ -2858,7 +3179,10 @@
28583179 {
28593180 bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
28603181
2861
- SetPositionDelta(false, true, true, true);
3182
+ // SetPositionDelta(false, true, true, true);
3183
+ LoadData();
3184
+ Rewind();
3185
+ Fade();
28623186 }
28633187 catch (Exception e)
28643188 {
....@@ -2867,13 +3191,17 @@
28673191 }
28683192 }
28693193 }
3194
+
3195
+ frame = GetFirstFrame();
28703196 }
3197
+ else
3198
+ frame += step;
28713199
28723200 //SetPositionDelta(false);
28733201
2874
- if (frame >= bvh.animation.getNumFrames())
2875
- //baseframe =
2876
- frame = GetFirstFrame(); // 0; // offset; // initial point
3202
+// if (frame >= bvh.animation.getNumFrames())
3203
+// //baseframe =
3204
+// frame = GetFirstFrame(); // 0; // offset; // initial point
28773205
28783206 //System.err.println("frame = " + frame);
28793207 if (lastframe != 0)
....@@ -3171,6 +3499,8 @@
31713499 //static
31723500 transient
31733501 double[] currentbones;
3502
+ double[] currenthip;
3503
+
31743504 transient boolean inbetween;
31753505
31763506 void SetPositionDelta(boolean reset, boolean rewind, boolean load, boolean fade)
....@@ -3181,38 +3511,9 @@
31813511 //assert(dim == numframes*6);
31823512
31833513 if (load)
3184
- for (int b=numbones; --b>=0;)
3185
- //int b = 0;
3186
- {
3187
- float[] thedata = bvh.animation.getBoneData(b);
3188
-
3189
- int numframes = bvh.animation.getNumFrames();
3190
-
3191
- int dof = 6; // thedata.length/numframes;
3192
-
3193
- if (b > 0)
3194
- dof = 3;
3195
-
3196
- if (dof != thedata.length/numframes)
3197
- {
3198
- System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (thedata.length/numframes));
3199
- dof = thedata.length/numframes;
3200
- }
3201
-
3202
- //for (int f=numframes; --f>=offset;)
3203
- int firstframe = GetFirstFrame();
3204
- for (int f=0; f<numframes-firstframe; f++)
3205
- {
3206
- int f3 = f*dof;
3207
-
3208
- //for (int i=3/*dof*/; --i>=0;)
3209
- for (int i=dof; --i>=0;)
3210
- {
3211
- //thedata[f3 + i] += thedata[i] - thedata[offset*dof + i];
3212
- thedata[f3 + i] = thedata[f3 + firstframe*dof + i];
3213
- }
3214
- }
3215
- }
3514
+ {
3515
+ LoadData();
3516
+ }
32163517
32173518 // assert(thedata[0] == 0);
32183519 // assert(thedata[1] == 0);
....@@ -3222,11 +3523,11 @@
32223523 // assert(thedata[7] == 0);
32233524 // assert(thedata[8] == 0);
32243525
3225
- Object3D obj = get(0);
3526
+ Object3D hip = get(0);
32263527
32273528 // assert(obj.name.equals("hip"));
32283529
3229
- Object3D rot = obj.get(0);
3530
+ Object3D rot = hip.get(0);
32303531
32313532 // if (toParent == null)
32323533 // {
....@@ -3238,7 +3539,7 @@
32383539 // // assert(obj.name == null); // .equals("hip#"));
32393540
32403541 Invariants();
3241
- obj.Invariants();
3542
+ hip.Invariants();
32423543 rot.Invariants();
32433544
32443545 if (origin == null)
....@@ -3259,16 +3560,16 @@
32593560 fromParent = LA.newMatrix();
32603561 }
32613562
3262
- if (obj.toParent == null) // june 2014
3563
+ if (hip.toParent == null) // june 2014
32633564 {
3264
- obj.toParent = LA.newMatrix();
3265
- obj.fromParent = LA.newMatrix();
3565
+ hip.toParent = LA.newMatrix();
3566
+ hip.fromParent = LA.newMatrix();
32663567 }
32673568
3268
- LA.matConcat(toParent, obj.toParent, origin0.toParent); // AB
3569
+ LA.matConcat(toParent, hip.toParent, origin0.toParent); // AB
32693570 Object3D gp = this.parent;
32703571 this.parent = null;
3271
- obj.GlobalTransformInv();
3572
+ hip.GlobalTransformInv();
32723573 this.parent = gp;
32733574
32743575 if (rot.toParent == null)
....@@ -3291,41 +3592,41 @@
32913592 LA.matInvert(origin.toParent, origin.fromParent);
32923593
32933594 Invariants();
3294
- obj.Invariants();
3595
+ hip.Invariants();
32953596 rot.Invariants();
32963597 origin.Invariants();
32973598 origin0.Invariants();
32983599
3299
- firsttimeafterload = true;
3600
+ firsttimeafterload = false; // true;
33003601
33013602 if (rewind)
33023603 Rewind();
33033604
3304
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), fade);
3605
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); //, fade);
33053606
3306
- if (true)
3307
- return;
3607
+ if (true)
3608
+ return;
33083609
33093610 double pos[] = new double[6];
33103611
33113612 if (!reset)
33123613 {
3313
- assert(obj.tx == obj.toParent[3][0]);
3314
- assert(obj.ty == obj.toParent[3][1]);
3315
- assert(obj.tz == obj.toParent[3][2]);
3614
+ assert(hip.tx == hip.toParent[3][0]);
3615
+ assert(hip.ty == hip.toParent[3][1]);
3616
+ assert(hip.tz == hip.toParent[3][2]);
33163617
3317
- pos[0] = obj.tx; // obj.toParent[3][0];
3318
- pos[1] = obj.ty; // obj.toParent[3][1];
3319
- pos[2] = obj.tz; // obj.toParent[3][2];
3320
- pos[3] = obj.rz;
3321
- pos[4] = obj.ry;
3322
- pos[5] = obj.rx;
3618
+ pos[0] = hip.tx; // obj.toParent[3][0];
3619
+ pos[1] = hip.ty; // obj.toParent[3][1];
3620
+ pos[2] = hip.tz; // obj.toParent[3][2];
3621
+ pos[3] = hip.rz;
3622
+ pos[4] = hip.ry;
3623
+ pos[5] = hip.rx;
33233624 }
33243625
33253626 cVector temp = new cVector();
3326
- temp.x = obj.globalTransform[3][0];
3327
- temp.y = obj.globalTransform[3][1];
3328
- temp.z = obj.globalTransform[3][2];
3627
+ temp.x = hip.globalTransform[3][0];
3628
+ temp.y = hip.globalTransform[3][1];
3629
+ temp.z = hip.globalTransform[3][2];
33293630 // LA.xformPos(temp, origin0.toParent, temp);
33303631 // System.err.println("POS0 = " + temp.x + ", " + temp.y + ", " + temp.z + ";");
33313632
....@@ -3409,7 +3710,7 @@
34093710 }
34103711
34113712 // Rewind();
3412
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), true);
3713
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); // , true);
34133714 }
34143715
34153716 void Rewind()