Normand Briere
2019-06-26 89b25e7cc97f6fe221dfd41c4d463500f8a31bc1
Mocap.java
....@@ -26,6 +26,575 @@
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.debugpointG.toParent[3][0] = poship.x;
265
+ CameraPane.debugpointG.toParent[3][1] = poship.y;
266
+ CameraPane.debugpointG.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
+ temp.x = 1;
288
+ temp.y = 0;
289
+ temp.z = 0;
290
+
291
+ LA.xformDir(temp, hip.get(0).toParent, temp);
292
+
293
+ angleYhip = Math.atan2(-temp.z, temp.x);
294
+
295
+ LA.matIdentity(matrix);
296
+ LA.matYRotate(matrix, angleYhip);
297
+ LA.matTranslate(matrix, poship.x, poship.y, poship.z);
298
+
299
+ //LA.matInvert(hip.get(0).toParent, matrix);
300
+ LA.matInvert(matrix, matrix);
301
+
302
+ //LA.matIdentity(matrix);
303
+ //LA.matTranslate(matrix, -poship.x, -poship.y, -poship.z);
304
+
305
+ LA.matConcat(toParent, matrix, toParent);
306
+
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.debugpointP.toParent[3][0] = pos.x;
328
+ CameraPane.debugpointP.toParent[3][1] = pos.y;
329
+ CameraPane.debugpointP.toParent[3][2] = pos.z;
330
+
331
+ CameraPane.debugpointC.toParent[3][0] = poship.x;
332
+ CameraPane.debugpointC.toParent[3][1] = poship.y;
333
+ CameraPane.debugpointC.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.debugpointR.toParent[3][0] = poship.x;
340
+ CameraPane.debugpointR.toParent[3][1] = poship.y;
341
+ CameraPane.debugpointR.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
+ }
479
+
480
+ static cVector centroid = new cVector();
481
+ static cVector mocaporigin = new cVector();
482
+
483
+ void SetHipOrientation()
484
+ {
485
+ Object3D hip = get(0);
486
+
487
+ if (toParent == null)
488
+ {
489
+ toParent = LA.newMatrix();
490
+ fromParent = LA.newMatrix();
491
+ }
492
+
493
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
494
+
495
+ mocaporigin.x = matrix[3][0];
496
+ mocaporigin.y = matrix[3][1];
497
+ mocaporigin.z = matrix[3][2];
498
+
499
+ centroid.x = matrix[3][0];
500
+ centroid.y = matrix[3][1];
501
+ centroid.z = matrix[3][2];
502
+// this.getCentroid(centroid, true);
503
+
504
+ CameraPane.CreateSelectedPoint();
505
+ CameraPane.debugpointG.name = "";
506
+ CameraPane.debugpointG.toParent[3][0] = mocaporigin.x;
507
+ CameraPane.debugpointG.toParent[3][1] = mocaporigin.y;
508
+ CameraPane.debugpointG.toParent[3][2] = mocaporigin.z;
509
+
510
+ CameraPane.debugpointP.name = "";
511
+ CameraPane.debugpointP.toParent[3][0] = centroid.x;
512
+ CameraPane.debugpointP.toParent[3][1] = centroid.y;
513
+ CameraPane.debugpointP.toParent[3][2] = centroid.z;
514
+
515
+ cVector goal = GetGoal(centroid);
516
+ if (goal != null)
517
+ {
518
+ System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
519
+
520
+ goalposx = goal.x;
521
+ goalposz = goal.z;
522
+ targetdirx = targetdirz = 0;
523
+ }
524
+
525
+ if (goalposx == 0 && goalposz == 0)
526
+ {
527
+ // No target
528
+ if (ScriptNode.speaker != null)
529
+ {
530
+ Object3D sourcenode = GetFileRoot();
531
+ Object3D speakernode = ScriptNode.speaker.GetFileRoot();
532
+
533
+ //System.err.println("speaker is " + speakernode + "; last was " + ScriptNode.lastspeaker);
534
+
535
+ Object3D speaker = ScriptNode.speaker;
536
+
537
+ if (speakernode == sourcenode)
538
+ {
539
+ if (ScriptNode.lastspeaker != null)
540
+ {
541
+ speakernode = ScriptNode.lastspeaker.GetFileRoot();
542
+ speaker = ScriptNode.lastspeaker;
543
+ }
544
+ else
545
+ return;
546
+ }
547
+
548
+ cVector dst = new cVector();
549
+
550
+ boolean success = speakernode.getCentroid(dst); // , true);
551
+
552
+ if (!success)
553
+ new Exception().printStackTrace();
554
+
555
+ //speakernode.parent.TransformToWorld(dst);
556
+ //sourcenode.parent.TransformToLocal(dst);
557
+ this.parent.TransformToLocal(dst);
558
+
559
+ goalposx = dst.x;
560
+ goalposz = dst.z;
561
+ }
562
+ else
563
+ return;
564
+ }
565
+
566
+ cVector temp = new cVector();
567
+
568
+ temp.x = 1;
569
+ temp.y = 0;
570
+ temp.z = 0;
571
+
572
+ LA.xformDir(temp, matrix, temp);
573
+
574
+ double angleYhip = Math.atan2(-temp.z, temp.x);
575
+
576
+ double angleYtarget = Math.atan2(goalposx - centroid.x, goalposz - centroid.z);
577
+
578
+ LA.matIdentity(matrix);
579
+ LA.matTranslate(matrix, -centroid.x, -centroid.y, -centroid.z);
580
+ double angle = CurveAngle(0, angleYtarget - angleYhip, 0.1f);
581
+ LA.matYRotate(matrix, angle);
582
+ LA.matTranslate(matrix, centroid.x, centroid.y, centroid.z);
583
+
584
+ LA.matConcat(matrix, toParent, toParent);
585
+
586
+ LA.matInvert(toParent, fromParent);
587
+
588
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
589
+
590
+ centroid.x = matrix[3][0];
591
+ centroid.y = matrix[3][1];
592
+ centroid.z = matrix[3][2];
593
+
594
+ double dist = LA.distance(centroid, mocaporigin);
595
+
596
+ CheckForAction(centroid);
597
+ }
29598
30599 void WriteTo(java.io.Writer writer) throws Exception
31600 {
....@@ -76,6 +645,24 @@
76645 // transient // aout 2013
77646 Object3D skeleton;
78647
648
+ void ExtractBigData(Object3D o)
649
+ {
650
+ super.ExtractBigData(o);
651
+
652
+ o.bvh = this.bvh;
653
+ o.skeleton = this.skeleton;
654
+ this.bvh = null;
655
+ this.skeleton = null;
656
+ }
657
+
658
+ void RestoreBigData(Object3D o)
659
+ {
660
+ super.RestoreBigData(o);
661
+
662
+ this.bvh = o.bvh;
663
+ this.skeleton = o.skeleton;
664
+ }
665
+
79666 boolean smoothed;
80667
81668 //boolean touched;
....@@ -99,11 +686,11 @@
99686 double pinx;
100687 double pinz;
101688
102
- double targetx;
103
- double targetz;
689
+ double targetdirx;
690
+ double targetdirz;
104691
105
- double goalx;
106
- double goalz;
692
+ double goalposx = 0; // -20;
693
+ double goalposz = 0; // -10;
107694
108695 boolean followpath;
109696
....@@ -174,7 +761,7 @@
174761 scriptactions.clear();
175762 }
176763
177
- static double EPSACTION = 0.1; // 0.075; // 0.1;
764
+ static double EPSACTION = 0.1; // 0.075; // 0.1;Came
178765
179766 void AddFromTo(cVector from, cVector to)
180767 {
....@@ -359,7 +946,7 @@
359946 // //GetFileRoot();
360947
361948 // sept 2014: //
362
- GrafreeD.RENDERME = 3; // patch for Merge objects
949
+ Grafreed.RENDERME = 3; // patch for Merge objects
363950 float[] thedata = bvh.animation.getBoneData(0);
364951
365952 os.x = (float) (path.get(i).toParent[3][0]); // - thedata[frame*6]);
....@@ -460,6 +1047,8 @@
4601047 testvect.set(from);
4611048 testvect.sub(fromto.from);
4621049
1050
+ testvect.y = 0; // PATCH
1051
+
4631052 int factor = 1;
4641053
4651054 //if (CameraPane.FAST)
....@@ -501,6 +1090,8 @@
5011090
5021091 testvect.set(from);
5031092 testvect.sub(fromto.from);
1093
+
1094
+ testvect.y = 0; // PATCH
5041095
5051096 int factor = 1;
5061097
....@@ -705,7 +1296,7 @@
7051296 // skip first node: translation
7061297 // Object3D b = input.get(0);
7071298
708
- setPose(input, f, data.getBoneData(input._index), false); //, null);
1299
+ setPose(input, f, data.getBoneData(input._index)); //, false); //, null);
7091300 }
7101301
7111302 //mocap.figure.Bone[] children = b.getChildren();
....@@ -736,6 +1327,7 @@
7361327
7371328 void SetPosition(Object3D sourcenode, cVector floor, long floorid, cVector centroid)
7381329 {
1330
+ assert(false);
7391331 //assert(CameraPane.drawMode == CameraPane.SHADOW);
7401332
7411333 Object3D transformnode = new Object3D();
....@@ -921,7 +1513,7 @@
9211513 //groundz += sourcenode.parent.toParent[3][2] - posz;
9221514 }
9231515
924
- boolean footcontact = CameraPane.FOOTCONTACT; // false;
1516
+ boolean footcontact = false; // CameraPane.FOOTCONTACT; // false;
9251517
9261518 if (footcontact && ground != -123456)
9271519 {
....@@ -939,9 +1531,9 @@
9391531 groundid = floorid;
9401532
9411533 // green
942
- CameraPane.debugpoint.toParent[3][0] = groundx;
943
- CameraPane.debugpoint.toParent[3][1] = floor.y;
944
- CameraPane.debugpoint.toParent[3][2] = groundz;
1534
+ CameraPane.debugpointG.toParent[3][0] = groundx;
1535
+ CameraPane.debugpointG.toParent[3][1] = floor.y;
1536
+ CameraPane.debugpointG.toParent[3][2] = groundz;
9451537
9461538 if (true) // slow && stepout && onein)
9471539 {
....@@ -952,7 +1544,7 @@
9521544 // mywave = currentwave++;
9531545 // }
9541546 // sound
955
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
1547
+ cVector eye = Globals.theRenderer.EyeCamera().location;
9561548
9571549 // if (sourcenode.parent.parent != null)
9581550 // sourcenode.parent.parent.TransformToWorld(floor, tmp);
....@@ -997,9 +1589,9 @@
9971589 //GraphreeD.
9981590 wav.play(volume * usedvolume); //, mywave);
9991591
1000
- lastsoundtime = CameraPane.framecount;
1592
+ lastsoundtime = Globals.framecount;
10011593
1002
- GrafreeD.hassound = true;
1594
+ Grafreed.hassound = true;
10031595 }
10041596 // else
10051597 // System.out.println("skipped");
....@@ -1018,9 +1610,9 @@
10181610
10191611 // System.out.println("Allo " + sourcenode);
10201612 // purple
1021
- CameraPane.debugpoint2.toParent[3][0] = floor.x;// + posx;
1022
- CameraPane.debugpoint2.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1023
- CameraPane.debugpoint2.toParent[3][2] = floor.z;// + posz;
1613
+ CameraPane.debugpointP.toParent[3][0] = floor.x;// + posx;
1614
+ CameraPane.debugpointP.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1615
+ CameraPane.debugpointP.toParent[3][2] = floor.z;// + posz;
10241616
10251617
10261618 if (false) // dist2 > 0.1)
....@@ -1086,9 +1678,9 @@
10861678 this.get(0).TransformToWorld(v0);
10871679
10881680 // cyan
1089
- CameraPane.debugpoint3.toParent[3][0] = v0.x;
1090
- CameraPane.debugpoint3.toParent[3][1] = ground;
1091
- CameraPane.debugpoint3.toParent[3][2] = v0.z;
1681
+ CameraPane.debugpointC.toParent[3][0] = v0.x;
1682
+ CameraPane.debugpointC.toParent[3][1] = ground;
1683
+ CameraPane.debugpointC.toParent[3][2] = v0.z;
10921684
10931685 LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent);
10941686 LA.matInvert(sourcenode.toParent, sourcenode.fromParent);
....@@ -1098,9 +1690,9 @@
10981690 this.get(0).TransformToWorld(v0);
10991691
11001692 // red
1101
- CameraPane.debugpoint4.toParent[3][0] = v0.x;
1102
- CameraPane.debugpoint4.toParent[3][1] = ground;
1103
- CameraPane.debugpoint4.toParent[3][2] = v0.z;
1693
+ CameraPane.debugpointR.toParent[3][0] = v0.x;
1694
+ CameraPane.debugpointR.toParent[3][1] = ground;
1695
+ CameraPane.debugpointR.toParent[3][2] = v0.z;
11041696 }
11051697 }
11061698
....@@ -1140,11 +1732,11 @@
11401732
11411733 if (goal != null)
11421734 {
1143
- System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")");
1735
+ System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
11441736 //sourcenode.parent.parent.Dump();
1145
- goalx = goal.x;
1146
- goalz = goal.z;
1147
- targetx = targetz = 0;
1737
+ goalposx = goal.x;
1738
+ goalposz = goal.z;
1739
+ targetdirx = targetdirz = 0;
11481740
11491741 followpath = true;
11501742 }
....@@ -1195,16 +1787,16 @@
11951787 // }
11961788 if (false) // !uselast)
11971789 {
1198
- CameraPane.debugpoint.toParent[3][0] = dst.x;
1199
- CameraPane.debugpoint.toParent[3][1] = dst.y;
1200
- CameraPane.debugpoint.toParent[3][2] = dst.z;
1790
+ CameraPane.debugpointG.toParent[3][0] = dst.x;
1791
+ CameraPane.debugpointG.toParent[3][1] = dst.y;
1792
+ CameraPane.debugpointG.toParent[3][2] = dst.z;
12011793 }
12021794 }
12031795
1204
- if (goalx != 0 || goalz != 0) // TODO
1796
+ if (goalposx != 0 || goalposz != 0) // TODO
12051797 {
12061798 // overwrite speaker orientation
1207
- dst.set(goalx,0,goalz);
1799
+ dst.set(goalposx,0,goalposz);
12081800 if (sourcenode.parent != null) // july 2014
12091801 sourcenode.parent.
12101802 TransformToLocal(dst);
....@@ -1220,6 +1812,7 @@
12201812 src.x = 0;
12211813 src.y = 0;
12221814 src.z = 0;
1815
+ LA.xformPos(src, get(0).get(0).toParent, src);
12231816 LA.xformPos(src, get(0).toParent, src);
12241817 LA.xformPos(src, toParent, src);
12251818 // LA.xformPos(src, rotsourcenode.toParent, src);
....@@ -1255,26 +1848,26 @@
12551848 // mars 2014
12561849 if (false) // goalx != 0 || goalz != 0)
12571850 {
1258
- targetx = dst.x - src.x;
1259
- targetz = dst.z - src.z;
1851
+ targetdirx = dst.x - src.x;
1852
+ targetdirz = dst.z - src.z;
12601853
1261
- if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1)
1854
+ if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1)
12621855 {
12631856 // far enough from goal. keep the goal position.
1264
- targetx = 0;
1265
- targetz = 0;
1857
+ targetdirx = 0;
1858
+ targetdirz = 0;
12661859 }
12671860 else
12681861 {
12691862 // too close to goal. switch to target direction instead.
1270
- goalx = 0;
1271
- goalz = 0;
1863
+ goalposx = 0;
1864
+ goalposz = 0;
12721865 }
12731866 }
12741867
12751868 //sourcenode.getCentroid(src, true);
12761869
1277
- if (speakernode == sourcenode && goalx == 0 && goalz == 0)
1870
+ if (speakernode == sourcenode && goalposx == 0 && goalposz == 0)
12781871 {
12791872 if (ScriptNode.lastspeaker != null)
12801873 new Exception().printStackTrace();
....@@ -1283,13 +1876,13 @@
12831876
12841877 // LA.xformPos(src, fromParent, src);
12851878
1286
- if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalx != 0 || goalz != 0) && targetx == 0 && targetz == 0)
1879
+ if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalposx != 0 || goalposz != 0) && targetdirx == 0 && targetdirz == 0)
12871880 dst.sub(src);
12881881 else
12891882 // vector mode
12901883 {
1291
- dst.x = targetx;
1292
- dst.z = targetz;
1884
+ dst.x = targetdirx;
1885
+ dst.z = targetdirz;
12931886
12941887 // TEST TARGET
12951888 // dst.x = CameraPane.selectedpoint.toParent[3][0];
....@@ -1563,6 +2156,7 @@
15632156 toParent = LA.newMatrix();
15642157 fromParent = LA.newMatrix();
15652158 }
2159
+
15662160 LA.matConcat(toParent, rotsourcenode.toParent, toParent);
15672161 LA.matInvert(toParent, fromParent);
15682162
....@@ -1698,7 +2292,7 @@
16982292 }
16992293
17002294 if (!smoothed)
1701
- for (int i=4; --i>=0;)
2295
+ for (int i=10; --i>=0;)
17022296 SmoothAnimData(); // much reduces shakiness
17032297
17042298 smoothed = true;
....@@ -1736,9 +2330,16 @@
17362330 toVector.x = LA.cos(to);
17372331 toVector.y = LA.sin(to);
17382332
2333
+ double fromA = Math.atan2(fromVector.y, fromVector.x);
2334
+ double toA = Math.atan2(toVector.y, toVector.x);
2335
+
17392336 Vector2d currentVector = Slerp(fromVector, toVector, step);
17402337
1741
- return Math.atan2(currentVector.y, currentVector.x);
2338
+ double angle = Math.atan2(currentVector.y, currentVector.x);
2339
+
2340
+ double angle2 = (1-step) * fromA + step * toA;
2341
+
2342
+ return angle;
17422343 }
17432344
17442345 public static Vector2d Slerp(Vector2d from, Vector2d to, double step)
....@@ -1780,12 +2381,28 @@
17802381 if (!live) // aout 2013
17812382 return;
17822383
1783
- cVector centroid = new cVector();
1784
- cVector floor = new cVector();
1785
-
1786
- Object3D sourcenode = GetFileRoot();
2384
+ //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);
2385
+ try
2386
+ {
2387
+ SetPose(GetSkeleton(), bvh.animation, f);
2388
+ SetCurrentBones(frame);
2389
+ }
2390
+ catch (Exception e)
2391
+ {
2392
+ e.printStackTrace();
2393
+ }
17872394
1788
- boolean success; // = sourcenode.getCentroid(centroid);
2395
+ SetHipOrientation();
2396
+
2397
+ if (true)
2398
+ return;
2399
+
2400
+ cVector centroid = new cVector();
2401
+ cVector floor = new cVector();
2402
+
2403
+ Object3D sourcenode = GetFileRoot();
2404
+
2405
+ boolean success; // = sourcenode.getCentroid(centroid);
17892406 // if (!success)
17902407 // {
17912408 // //assert(success);
....@@ -1793,16 +2410,6 @@
17932410 // System.out.println("No centroid for " + sourcenode);
17942411 // }
17952412
1796
- //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);
1797
- try
1798
- {
1799
- SetPose(GetSkeleton(), bvh.animation, f);
1800
- }
1801
- catch (Exception e)
1802
- {
1803
- e.printStackTrace();
1804
- }
1805
-
18062413 if (sourcenode.parent == null && sourcenode.fileparent == null)
18072414 {
18082415 // No GFD
....@@ -2050,7 +2657,7 @@
20502657 * @param frame
20512658 * Frame number
20522659 */
2053
- public void setPose(Object3D bone, int frame, float[] data, boolean fade) //, Point3d offsetTrans)
2660
+ public void setPose(Object3D bone, int frame, float[] data) //, boolean fade) //, Point3d offsetTrans)
20542661 {
20552662 if (!live) // aout 2013
20562663 return;
....@@ -2058,6 +2665,33 @@
20582665 cVector temp = new cVector();
20592666 cVector temp0 = new cVector();
20602667 double pos[] = new double[3];
2668
+ double angleY = 0;
2669
+ double sinY = 0;
2670
+ double cosY = 0;
2671
+
2672
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
2673
+ {
2674
+ bone.get(0).GlobalTransformInv();
2675
+
2676
+ temp.x = bone.get(0).globalTransform[3][0];
2677
+ temp.y = bone.get(0).globalTransform[3][1];
2678
+ temp.z = bone.get(0).globalTransform[3][2];
2679
+
2680
+ pos[0] = temp.x;
2681
+ pos[1] = temp.y;
2682
+ pos[2] = temp.z;
2683
+
2684
+ temp.x = 1;
2685
+ temp.y = 0;
2686
+ temp.z = 0;
2687
+
2688
+ LA.xformDir(temp, bone.get(0).globalTransform, temp);
2689
+
2690
+ sinY = temp.z;
2691
+ cosY = temp.x;
2692
+
2693
+ angleY = Math.atan2(-sinY, cosY);
2694
+ }
20612695
20622696 // Object3D obj = get(0);
20632697 // Object3D gp = this.parent;
....@@ -2189,13 +2823,14 @@
21892823 if (//frame > 0 &&
21902824 !bone.skipmocap &&
21912825 !bone.name.contains("head") &&
2826
+ !bone.name.contains("Head") // &&
21922827 // !bone.name.contains("rFoot") &&
21932828 // !bone.name.contains("lFoot") &&
2194
- !bone.name.contains("Pinky") &&
2195
- !bone.name.contains("Ring") &&
2196
- !bone.name.contains("Mid") &&
2197
- !bone.name.contains("Index") &&
2198
- !bone.name.contains("Thumb")
2829
+// !bone.name.contains("Pinky") &&
2830
+// !bone.name.contains("Ring") &&
2831
+// !bone.name.contains("Mid") &&
2832
+// !bone.name.contains("Index") &&
2833
+// !bone.name.contains("Thumb")
21992834 )
22002835 {
22012836 //_rotTG.setTransform(_t1);
....@@ -2228,15 +2863,17 @@
22282863 // CROWD
22292864 //cJ3D.GetTranslation(bone, _trans0);
22302865 //_trans.add(_trans0);
2231
- _transTF.setIdentity();
2866
+ //_transTF.setIdentity();
2867
+ _transTF.set(_t1);
22322868 _transTF.setTranslation(_trans);
22332869 // System.err.println("Translate: " + _transTF);
22342870 //_transTG.setTransform(_transTF);
2235
- cJ3D.ResetTransform(bone, _transTF, true); // translation node
2871
+ cJ3D.ResetTransform(bone.get(0), _transTF, true); // translation node
2872
+ //cJ3D.ResetTransform(bone, _transTF, true); // translation node
22362873 }
22372874 }
22382875
2239
- if (bone._isRoot && firsttimeafterload && frame > 0)
2876
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
22402877 {
22412878 assert(bone == get(0));
22422879
....@@ -2252,17 +2889,17 @@
22522889 // LA.matConcat(originmatrixinv, tempmatrixinv, fromParent); // ABC * (B'*C')^-1
22532890 //
22542891
2255
- Invariants();
2256
- bone.Invariants();
2257
- bone.get(0).Invariants();
2258
- // if (origin == null)
2259
- // origin = null;
2260
- origin.Invariants();
2261
- origin0.Invariants();
2892
+ Invariants();
2893
+ bone.Invariants();
2894
+ bone.get(0).Invariants();
2895
+ // if (origin == null)
2896
+ // origin = null;
2897
+ origin.Invariants();
2898
+ origin0.Invariants();
22622899
2263
-
2264
- LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2265
- LA.matConcat(origin.toParent, tempmatrix, toParent);
2900
+
2901
+//?? LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2902
+//?? LA.matConcat(origin.toParent, tempmatrix, toParent);
22662903
22672904 // matrixToEulerXYZ(toParent, temp);
22682905 // matrixToEulerXYZ(bone.get(0).toParent, temp);
....@@ -2296,7 +2933,7 @@
22962933 //
22972934 // mat4d.get(quat);
22982935
2299
- if (true) // hip correction
2936
+ if (false) // hip correction
23002937 {
23012938 _t2.setIdentity();
23022939
....@@ -2337,13 +2974,13 @@
23372974 //????? LA.matConcat(bone.get(0).toParent, bone.toParent, tempmatrix); // B' * C'
23382975 // LA.matConcat(origin.fromParent, tempmatrix, fromParent);
23392976
2340
- LA.matInvert(toParent, fromParent);
2977
+//?? LA.matInvert(toParent, fromParent);
23412978
2342
- Invariants();
2343
- bone.Invariants();
2344
- bone.get(0).Invariants();
2345
- origin.Invariants();
2346
- origin0.Invariants();
2979
+ Invariants();
2980
+ bone.Invariants();
2981
+ bone.get(0).Invariants();
2982
+ origin.Invariants();
2983
+ origin0.Invariants();
23472984
23482985 // LA.matInvert(fromParent, tempmatrix);
23492986 //
....@@ -2364,33 +3001,39 @@
23643001 // temp.x = data[0];
23653002 // temp.y = data[1];
23663003 // temp.z = data[2];
2367
- LA.xformPos(temp, origin0.toParent, temp0);
3004
+ LA.xformPos(temp, origin0.toParent, temp0); // NU
23683005
2369
-// bone.GlobalTransformInv();
2370
-
2371
- temp0.x = bone.globalTransform[3][0];
2372
- temp0.y = bone.globalTransform[3][1];
2373
- temp0.z = bone.globalTransform[3][2];
2374
-
3006
+// bone.get(0).GlobalTransformInv();
3007
+//
3008
+// temp0.x = bone.get(0).globalTransform[3][0];
3009
+// temp0.y = bone.get(0).globalTransform[3][1];
3010
+// temp0.z = bone.get(0).globalTransform[3][2];
3011
+//
23753012 // MEGA TEST // june 2014: necessary for precision? otherwise comment works
2376
-fromParent[3][0] = 0;
2377
-fromParent[3][1] = 0;
2378
-fromParent[3][2] = 0;
2379
-LA.matInvert(fromParent, toParent);
3013
+//fromParent[3][0] = 0;
3014
+//fromParent[3][1] = 0;
3015
+//fromParent[3][2] = 0;
3016
+//LA.matInvert(fromParent, toParent);
23803017
2381
- LA.xformPos(temp0, fromParent, temp);
3018
+ LA.xformPos(temp0, fromParent, temp); // NU
23823019 //LA.xformPos(temp, bone.fromParent, temp);
23833020 // float[] data;
23843021
2385
- pos[0] = temp.x;
2386
- pos[1] = temp.y;
2387
- pos[2] = temp.z;
3022
+// pos[0] = temp.x;
3023
+// pos[1] = temp.y;
3024
+// pos[2] = temp.z;
3025
+//
3026
+// temp.x = 1;
3027
+// temp.y = 0;
3028
+// temp.z = 0;
3029
+//
3030
+// LA.xformDir(temp, bone.get(0).globalTransform, temp);
23883031
23893032 // CameraPane.selectedpoint.toParent[3][0] = temp0.x;
23903033 // CameraPane.selectedpoint.toParent[3][1] = temp0.y;
23913034 // CameraPane.selectedpoint.toParent[3][2] = temp0.z;
23923035
2393
- int numframes = bvh.animation.getNumFrames();
3036
+ int numframes = bvh.animation.getNumFrames();
23943037
23953038 int b = 0;
23963039 {
....@@ -2398,12 +3041,12 @@
23983041
23993042 int dof = 6; /// data.length/numframes;
24003043
2401
- // july 2014
2402
- if (dof != data.length/numframes)
2403
- {
2404
- System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));
2405
- dof = data.length/numframes;
2406
- }
3044
+ // july 2014
3045
+ if (dof != data.length/numframes)
3046
+ {
3047
+ System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));
3048
+ dof = data.length/numframes;
3049
+ }
24073050
24083051
24093052 int theframe = 0; // baseframe;
....@@ -2455,17 +3098,26 @@
24553098 // }
24563099 // }
24573100
2458
- data[f3 + i] += pos[i] - data[frame3 + i];
3101
+ data[f3 + i] += /*pos[i]*/ - data[frame3 + i];
24593102
24603103 // if (f < 3)
24613104 // {
24623105 // System.out.print(data[f3 + i] + " ");
24633106 // }
24643107 }
2465
-// if (f < 3)
2466
-// {
2467
-// System.out.println();
2468
-// }
3108
+
3109
+ double t1 = data[f3 + 0];
3110
+ double t2 = data[f3 + 2];
3111
+
3112
+ data[f3 + 0] = (float)(cosY*t1 - sinY*t2);
3113
+ data[f3 + 2] = (float)(sinY*t1 + cosY*t2);
3114
+
3115
+ for (int i=3/*dof*/; --i>=0;)
3116
+ {
3117
+ data[f3 + i] += pos[i];
3118
+ }
3119
+
3120
+ data[f3 + 4] += angleY - data[frame3 + 4];
24693121 }
24703122 }
24713123
....@@ -2479,186 +3131,17 @@
24793131 // temp.y = data[1];
24803132 // temp.z = data[2];
24813133
2482
- if (fade && currentbones != null && !CameraPane.fullreset)
2483
- {
2484
- Quat4d quatstart = new Quat4d();
2485
- Quat4d quatend = new Quat4d();
2486
- Quat4d quat = new Quat4d();
2487
- Matrix4d mat4d = new Matrix4d();
2488
- double[][] rot = new double[4][4];
2489
-
2490
- for (b=numbones; --b>=1;) // HIP ROTATION: 0;)
2491
- {
2492
- int hipindex = get(0)._index;
2493
-
2494
-// assert(get(0).get(0)._isHip);
2495
-
2496
- // if (b == hipindex)
2497
- // continue;
2498
-
2499
- data = bvh.animation.getBoneData(b);
2500
-
2501
- int dof = 3; // data.length/numframes;
2502
-
2503
- // assert(dof == 3);
2504
-
2505
- int boneframe3 = b*3; // dof;
2506
-
2507
- // System.err.println("Bone #" + b + ": dof = " + dof);
2508
- int fadein = 45; // 120;
2509
-
2510
- // if (b == hipindex)
2511
- // fadein *= 5;
2512
-
2513
- if (fadein > numframes)
2514
- fadein = 0; // numframes;
2515
-
2516
- for (int fi=fadein; --fi>=0;)
2517
- //for (int f=numframes; --f>=0;)
2518
- {
2519
- int f = fi + GetFirstFrame();
2520
-
2521
- int f3 = f*dof;
2522
-
2523
- float k = fi;
2524
-
2525
- k /= fadein - 1;
2526
-
2527
- if (Float.isNaN(k))
2528
- k = 1; // 0/0
2529
-
2530
- k = (float) (-Math.cos(k*Math.PI));
2531
- k += 1;
2532
- k /= 2;
2533
-
2534
- int start = 3;
2535
- int end = 0;
2536
-
2537
- if (dof == 6)
2538
- {
2539
- start = 6;
2540
- end = 3;
2541
- }
2542
-
2543
- if (b == 0)
2544
- {
2545
- _t1.setIdentity();
2546
- _t2.setIdentity();
2547
- _t2.rotZ(currentbones[boneframe3 + start-1-end]);
2548
- _t1.mul(_t2);
2549
- _t2.setIdentity();
2550
- if (b == 0)
2551
- {
2552
- _t2.rotY(currentbones[boneframe3 + start-2-end]);
2553
- _t1.mul(_t2);
2554
- _t2.setIdentity();
2555
- _t2.rotX(currentbones[boneframe3 + start-3-end]);
2556
- }
2557
- else
2558
- {
2559
- _t2.rotX(currentbones[boneframe3 + start-2-end]);
2560
- _t1.mul(_t2);
2561
- _t2.setIdentity();
2562
- _t2.rotY(currentbones[boneframe3 + start-3-end]);
2563
- }
2564
- _t1.mul(_t2);
2565
- _t2.setIdentity();
2566
-
2567
- _t1.get(mat4d);
2568
-
2569
- mat4d.get(quatstart);
2570
-
2571
- _t1.setIdentity();
2572
- _t2.setIdentity();
2573
- _t2.rotZ(data[f3 + start-1]);
2574
- _t1.mul(_t2);
2575
- _t2.setIdentity();
2576
- if (b == 0)
2577
- {
2578
- _t2.rotY(data[f3 + start-2]);
2579
- _t1.mul(_t2);
2580
- _t2.setIdentity();
2581
- _t2.rotX(data[f3 + start-3]);
2582
- }
2583
- else
2584
- {
2585
- _t2.rotX(data[f3 + start-2]);
2586
- _t1.mul(_t2);
2587
- _t2.setIdentity();
2588
- _t2.rotY(data[f3 + start-3]);
2589
- }
2590
-
2591
- _t1.mul(_t2);
2592
- _t2.setIdentity();
2593
-
2594
- _t1.get(mat4d);
2595
-
2596
- mat4d.get(quatend);
2597
-
2598
- double dot = quatstart.x*quatend.x +
2599
- quatstart.y*quatend.y +
2600
- quatstart.z*quatend.z +
2601
- quatstart.w*quatend.w
2602
- ;
2603
-
2604
- if (dot < 0)
2605
- {
2606
- quatend.x *= -1;
2607
- quatend.y *= -1;
2608
- quatend.z *= -1;
2609
- quatend.w *= -1;
2610
- }
2611
-
2612
- // k = 1-k;
2613
-
2614
- quat.x = (1-k)*quatstart.x + k*quatend.x;
2615
- quat.y = (1-k)*quatstart.y + k*quatend.y;
2616
- quat.z = (1-k)*quatstart.z + k*quatend.z;
2617
- quat.w = (1-k)*quatstart.w + k*quatend.w;
2618
-
2619
- quat.normalize();
2620
-
2621
- mat4d.set(quat);
2622
-
2623
- cJ3D.SetTransform(rot, mat4d);
2624
-
2625
- matrixToEulerXYZ(rot, temp);
2626
-
2627
- data[f3 + start-1] = -(float)temp.z;
2628
-
2629
- if (b == 0)
2630
- {
2631
- data[f3 + start-2] = -(float)temp.y;
2632
- data[f3 + start-3] = -(float)temp.x;
2633
- }
2634
- else
2635
- {
2636
- data[f3 + start-2] = -(float)temp.x;
2637
- data[f3 + start-3] = -(float)temp.y;
2638
- }
2639
- }
2640
- else
2641
- {
2642
- for (int i=start; --i>=end;)
2643
- {
2644
- //data[f3 + i] += pos[i] - data[frame3 + i];
2645
- // data[f3 + i] = k*data[f3+i] + (1-k)*
2646
- // currentbones[boneframe3 + i-end];
2647
- data[f3 + i] = (float)CurveAngle(data[f3+i], currentbones[boneframe3 + i-end], 1-k);
2648
- }
2649
- }
2650
-
2651
- }
2652
- }
2653
-
2654
- }
3134
+// if (fade && currentbones != null && !CameraPane.fullreset)
3135
+// {
3136
+// Fade();
3137
+// }
26553138 }
2656
-
3139
+
26573140 if (false) // doesn't change anything bone._isRoot)
26583141 {
26593142 // Reset orientation
26603143 _t2.setIdentity();
2661
-
3144
+
26623145 double tx = bone.toParent[3][0];
26633146 double ty = bone.toParent[3][1];
26643147 double tz = bone.toParent[3][2];
....@@ -2667,9 +3150,9 @@
26673150 temp.y = 0;
26683151 temp.z = 0;
26693152 LA.xformDir(temp, bone.toParent, temp);
2670
-
3153
+
26713154 double angle = Math.atan2(-temp.z, temp.x);
2672
-
3155
+
26733156 _t2.rotY(angle);
26743157 // _t1.setIdentity();
26753158 // _t1.rotX(temp.x);
....@@ -2682,56 +3165,21 @@
26823165 // _t1.setIdentity();
26833166 // _t1.rotZ(temp.z);
26843167 // _t2.mul(_t1);
2685
-
3168
+
26863169 cJ3D.ResetTransform(bone, _t2, false);
2687
-
3170
+
26883171 bone.toParent[3][0] = tx;
26893172 bone.toParent[3][1] = ty;
26903173 bone.toParent[3][2] = tz;
26913174 }
26923175 }
26933176
2694
- if (currentbones == null)
2695
- currentbones = new double[numbones*3];
2696
-
2697
- for (int b=numbones; --b>=1;) // 0;)
2698
- //int b = 0;
2699
- {
2700
- data = bvh.animation.getBoneData(b);
2701
-
2702
- int numframes = bvh.animation.getNumFrames();
2703
-
2704
- int dof = 6; // data.length/numframes;
2705
-
2706
- if (b > 0)
2707
- dof = 3;
2708
-
2709
- //assert(dof == 3);
2710
-
2711
- // System.err.println("Bone #" + b + ": dof = " + dof);
2712
- int theframe = // 1; // baseframe;
2713
- frame;
2714
-
2715
- int frame3 = theframe*dof;
2716
- int bone3 = b*3; // dof;
2717
-
2718
- int start = 3;
2719
- int end = 0;
2720
-
2721
- if (dof == 6)
2722
- {
2723
- start = 6;
2724
- end = 3;
2725
- }
2726
- for (int i=start; --i>=end;)
2727
- {
2728
- currentbones[bone3 + i-end] = data[frame3 + i];
2729
- }
2730
- }
3177
+ // SetCurrentBones(frame);
27313178 }
27323179 }
27333180
2734
- static int offset = 1; // 5; // 10; // 5; // 100; // skip initial "T"
3181
+ // skip initial "T"
3182
+ static int offset = 1; // 5; // 10; // 5; // 100;
27353183
27363184 void ReadBVH()
27373185 {
....@@ -2760,14 +3208,14 @@
27603208
27613209 void Reset()
27623210 {
2763
- if (fullname != null)
2764
- ReadBVH();
3211
+// if (fullname != null)
3212
+// ReadBVH();
27653213
27663214 Object3D hip = get(0);
27673215
27683216 // assert(obj.name.equals("hip"));
27693217
2770
- Object3D rot = hip.get(0);
3218
+ //Object3D rot = hip.get(0);
27713219
27723220 // assert(obj.name == null); // .equals("hip#"));
27733221
....@@ -2777,8 +3225,8 @@
27773225 hip.fromParent = LA.newMatrix();
27783226 }
27793227
2780
- hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;
2781
- hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;
3228
+ //hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;
3229
+ //hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;
27823230
27833231 if (toParent == null)
27843232 {
....@@ -2790,26 +3238,29 @@
27903238 LA.matIdentity(fromParent);
27913239 // LA.matIdentity(hip.toParent);
27923240 // LA.matIdentity(hip.fromParent);
2793
- if (rot.toParent == null)
2794
- {
2795
- // june 2014
2796
- rot.toParent = LA.newMatrix();
2797
- rot.fromParent = LA.newMatrix();
2798
- }
2799
- LA.matIdentity(rot.toParent);
2800
- LA.matIdentity(rot.fromParent);
3241
+// if (rot.toParent == null)
3242
+// {
3243
+// // june 2014
3244
+// rot.toParent = LA.newMatrix();
3245
+// rot.fromParent = LA.newMatrix();
3246
+// }
3247
+// LA.matIdentity(rot.toParent);
3248
+// LA.matIdentity(rot.fromParent);
28013249
28023250 // july 2014
2803
- goalx = goalz = 0;
2804
- targetx = targetz = 0;
3251
+// goalx = goalz = 0;
3252
+ targetdirx = targetdirz = 0;
28053253
2806
- SetPositionDelta(true, true, true, false);
3254
+ //SetPositionDelta(true, true, true, false);
3255
+// LoadData();
3256
+// Rewind();
28073257
28083258 baseframe = frame = 0; // T pose. No offset.
28093259
28103260 // aout 2013 endframe = 0; // june 2013
28113261
2812
- setPose(frame);
3262
+ ResetZero();
3263
+ //setPose(frame);
28133264 }
28143265
28153266 static int mocapsupport = 0;
....@@ -2827,12 +3278,13 @@
28273278
28283279 int step = 1;
28293280
3281
+ // patch for running hare
28303282 if (speedup) // fev 2014
28313283 step *= 2; // 4;
28323284 if (rewind) // mars 2014
28333285 step *= 4;
28343286
2835
- if (CameraPane.FAST) // && !CameraPane.HOLD)
3287
+ //if (CameraPane.FAST) // && !CameraPane.HOLD)
28363288 step *= CameraPane.STEP;
28373289
28383290 //System.err.println("Step Mocap frame # " + frame);
....@@ -2840,7 +3292,7 @@
28403292 baseframe += step;
28413293
28423294 //frame = baseframe;
2843
- frame += step;
3295
+ //frame += step;
28443296
28453297 // if (frame != baseframe)
28463298 // {
....@@ -2864,7 +3316,7 @@
28643316 "; fullname = " + fullname);
28653317
28663318 //int delta = frame - baseframe;
2867
- if (CameraPane.CROWD)
3319
+ if (Globals.CROWD)
28683320 {
28693321 baseframe = GetFirstFrame(); // 0 initial point
28703322 }
....@@ -2873,29 +3325,53 @@
28733325 // SetPositionDelta(false, true, false); // ?? false);
28743326 {
28753327 if (support == null)
2876
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
2877
- else
28783328 {
2879
- try
3329
+ if (bvh == null && new File(fullname).exists())
3330
+ ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3331
+ else
28803332 {
2881
- bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
2882
-
2883
- SetPositionDelta(false, true, true, true);
2884
- }
2885
- catch (Exception e)
2886
- {
2887
- e.printStackTrace();
2888
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3333
+ SetGlobalTransform();
3334
+ Rewind();
3335
+ Fade();
28893336 }
28903337 }
3338
+ else
3339
+ {
3340
+// try
3341
+// {
3342
+ bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
3343
+
3344
+ // SetPositionDelta(false, true, true, true);
3345
+ LoadData();
3346
+ Rewind();
3347
+ Fade();
3348
+// }
3349
+// catch (Exception e)
3350
+// {
3351
+// System.err.println("An error occured while loading data. Use fallback by loading the file.");
3352
+// //e.printStackTrace();
3353
+// try
3354
+// {
3355
+// ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3356
+// }
3357
+// catch (Exception e2)
3358
+// {
3359
+// System.err.println("Motion file not found: " + fullname);
3360
+// }
3361
+// }
3362
+ }
28913363 }
3364
+
3365
+ frame = GetFirstFrame();
28923366 }
3367
+ else
3368
+ frame += step;
28933369
28943370 //SetPositionDelta(false);
28953371
2896
- if (frame >= bvh.animation.getNumFrames())
2897
- //baseframe =
2898
- frame = GetFirstFrame(); // 0; // offset; // initial point
3372
+// if (frame >= bvh.animation.getNumFrames())
3373
+// //baseframe =
3374
+// frame = GetFirstFrame(); // 0; // offset; // initial point
28993375
29003376 //System.err.println("frame = " + frame);
29013377 if (lastframe != 0)
....@@ -3064,6 +3540,7 @@
30643540 // filters out bad input data
30653541 void FilterAnimData()
30663542 {
3543
+ new Exception().printStackTrace();
30673544 System.exit(0);
30683545
30693546 float[] data; // = bvh.animation.getBoneData(0);
....@@ -3193,6 +3670,8 @@
31933670 //static
31943671 transient
31953672 double[] currentbones;
3673
+ double[] currenthip;
3674
+
31963675 transient boolean inbetween;
31973676
31983677 void SetPositionDelta(boolean reset, boolean rewind, boolean load, boolean fade)
....@@ -3203,38 +3682,9 @@
32033682 //assert(dim == numframes*6);
32043683
32053684 if (load)
3206
- for (int b=numbones; --b>=0;)
3207
- //int b = 0;
3208
- {
3209
- float[] thedata = bvh.animation.getBoneData(b);
3210
-
3211
- int numframes = bvh.animation.getNumFrames();
3212
-
3213
- int dof = 6; // thedata.length/numframes;
3214
-
3215
- if (b > 0)
3216
- dof = 3;
3217
-
3218
- if (dof != thedata.length/numframes)
3219
- {
3220
- System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (thedata.length/numframes));
3221
- dof = thedata.length/numframes;
3222
- }
3223
-
3224
- //for (int f=numframes; --f>=offset;)
3225
- int firstframe = GetFirstFrame();
3226
- for (int f=0; f<numframes-firstframe; f++)
3227
- {
3228
- int f3 = f*dof;
3229
-
3230
- //for (int i=3/*dof*/; --i>=0;)
3231
- for (int i=dof; --i>=0;)
3232
- {
3233
- //thedata[f3 + i] += thedata[i] - thedata[offset*dof + i];
3234
- thedata[f3 + i] = thedata[f3 + firstframe*dof + i];
3235
- }
3236
- }
3237
- }
3685
+ {
3686
+ LoadData();
3687
+ }
32383688
32393689 // assert(thedata[0] == 0);
32403690 // assert(thedata[1] == 0);
....@@ -3244,11 +3694,11 @@
32443694 // assert(thedata[7] == 0);
32453695 // assert(thedata[8] == 0);
32463696
3247
- Object3D obj = get(0);
3697
+ Object3D hip = get(0);
32483698
32493699 // assert(obj.name.equals("hip"));
32503700
3251
- Object3D rot = obj.get(0);
3701
+ Object3D rot = hip.get(0);
32523702
32533703 // if (toParent == null)
32543704 // {
....@@ -3260,7 +3710,7 @@
32603710 // // assert(obj.name == null); // .equals("hip#"));
32613711
32623712 Invariants();
3263
- obj.Invariants();
3713
+ hip.Invariants();
32643714 rot.Invariants();
32653715
32663716 if (origin == null)
....@@ -3281,16 +3731,16 @@
32813731 fromParent = LA.newMatrix();
32823732 }
32833733
3284
- if (obj.toParent == null) // june 2014
3734
+ if (hip.toParent == null) // june 2014
32853735 {
3286
- obj.toParent = LA.newMatrix();
3287
- obj.fromParent = LA.newMatrix();
3736
+ hip.toParent = LA.newMatrix();
3737
+ hip.fromParent = LA.newMatrix();
32883738 }
32893739
3290
- LA.matConcat(toParent, obj.toParent, origin0.toParent); // AB
3740
+ LA.matConcat(toParent, hip.toParent, origin0.toParent); // AB
32913741 Object3D gp = this.parent;
32923742 this.parent = null;
3293
- obj.GlobalTransformInv();
3743
+ hip.GlobalTransformInv();
32943744 this.parent = gp;
32953745
32963746 if (rot.toParent == null)
....@@ -3313,41 +3763,41 @@
33133763 LA.matInvert(origin.toParent, origin.fromParent);
33143764
33153765 Invariants();
3316
- obj.Invariants();
3766
+ hip.Invariants();
33173767 rot.Invariants();
33183768 origin.Invariants();
33193769 origin0.Invariants();
33203770
3321
- firsttimeafterload = true;
3771
+ firsttimeafterload = false; // true;
33223772
33233773 if (rewind)
33243774 Rewind();
33253775
3326
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), fade);
3776
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); //, fade);
33273777
3328
- if (true)
3329
- return;
3778
+ if (true)
3779
+ return;
33303780
33313781 double pos[] = new double[6];
33323782
33333783 if (!reset)
33343784 {
3335
- assert(obj.tx == obj.toParent[3][0]);
3336
- assert(obj.ty == obj.toParent[3][1]);
3337
- assert(obj.tz == obj.toParent[3][2]);
3785
+ assert(hip.tx == hip.toParent[3][0]);
3786
+ assert(hip.ty == hip.toParent[3][1]);
3787
+ assert(hip.tz == hip.toParent[3][2]);
33383788
3339
- pos[0] = obj.tx; // obj.toParent[3][0];
3340
- pos[1] = obj.ty; // obj.toParent[3][1];
3341
- pos[2] = obj.tz; // obj.toParent[3][2];
3342
- pos[3] = obj.rz;
3343
- pos[4] = obj.ry;
3344
- pos[5] = obj.rx;
3789
+ pos[0] = hip.tx; // obj.toParent[3][0];
3790
+ pos[1] = hip.ty; // obj.toParent[3][1];
3791
+ pos[2] = hip.tz; // obj.toParent[3][2];
3792
+ pos[3] = hip.rz;
3793
+ pos[4] = hip.ry;
3794
+ pos[5] = hip.rx;
33453795 }
33463796
33473797 cVector temp = new cVector();
3348
- temp.x = obj.globalTransform[3][0];
3349
- temp.y = obj.globalTransform[3][1];
3350
- temp.z = obj.globalTransform[3][2];
3798
+ temp.x = hip.globalTransform[3][0];
3799
+ temp.y = hip.globalTransform[3][1];
3800
+ temp.z = hip.globalTransform[3][2];
33513801 // LA.xformPos(temp, origin0.toParent, temp);
33523802 // System.err.println("POS0 = " + temp.x + ", " + temp.y + ", " + temp.z + ";");
33533803
....@@ -3431,7 +3881,7 @@
34313881 }
34323882
34333883 // Rewind();
3434
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), true);
3884
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); // , true);
34353885 }
34363886
34373887 void Rewind()
....@@ -3448,7 +3898,7 @@
34483898
34493899 transient boolean restarted; // CROWD issue?
34503900
3451
- void drawSelf(CameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
3901
+ void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
34523902 {
34533903 //System.err.println("drawSelf Mocap frame # " + frame);
34543904 //System.err.println("drawSelf Mocap baseframe # " + baseframe);
....@@ -3465,17 +3915,22 @@
34653915 // if (firstframe)
34663916 // return;
34673917
3468
- if (!restarted && /*display.restartframe &&*/
3469
- display.isLIVE() && live && display.drawMode == display.SHADOW) // FUCK
3918
+ if (//!restarted && /*display.restartframe &&*/
3919
+ Globals.isLIVE() && live && (display.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || !Globals.COMPUTESHADOWWHENLIVE))
34703920 {
34713921 //display.restartframe = false;
34723922 restarted = true;
3923
+ //System.err.println("restarted = true");
34733924 Step();
34743925 }
34753926 else
34763927 {
3477
- if (display.isLIVE() && live && display.drawMode != display.SHADOW)
3928
+ //System.err.println("restarted");
3929
+ if (Globals.isLIVE() && live && display.DrawMode() != iCameraPane.SHADOW)
3930
+ {
34783931 restarted = false;
3932
+ //System.err.println("restarted = false");
3933
+ }
34793934 }
34803935
34813936 super.drawSelf(display, root, selected, blocked);