Normand Briere
2019-06-16 372b7fd481a476cd659713a4a01bf28bf6760cbe
Mocap.java
....@@ -26,6 +26,574 @@
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.debugpointG.name = "";
505
+ CameraPane.debugpointG.toParent[3][0] = mocaporigin.x;
506
+ CameraPane.debugpointG.toParent[3][1] = mocaporigin.y;
507
+ CameraPane.debugpointG.toParent[3][2] = mocaporigin.z;
508
+
509
+ CameraPane.debugpointP.name = "";
510
+ CameraPane.debugpointP.toParent[3][0] = centroid.x;
511
+ CameraPane.debugpointP.toParent[3][1] = centroid.y;
512
+ CameraPane.debugpointP.toParent[3][2] = centroid.z;
513
+
514
+ cVector goal = GetGoal(centroid);
515
+ if (goal != null)
516
+ {
517
+ System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
518
+
519
+ goalposx = goal.x;
520
+ goalposz = goal.z;
521
+ targetdirx = targetdirz = 0;
522
+ }
523
+
524
+ if (goalposx == 0 && goalposz == 0)
525
+ {
526
+ // No target
527
+ if (ScriptNode.speaker != null)
528
+ {
529
+ Object3D sourcenode = GetFileRoot();
530
+ Object3D speakernode = ScriptNode.speaker.GetFileRoot();
531
+
532
+ //System.err.println("speaker is " + speakernode + "; last was " + ScriptNode.lastspeaker);
533
+
534
+ Object3D speaker = ScriptNode.speaker;
535
+
536
+ if (speakernode == sourcenode)
537
+ {
538
+ if (ScriptNode.lastspeaker != null)
539
+ {
540
+ speakernode = ScriptNode.lastspeaker.GetFileRoot();
541
+ speaker = ScriptNode.lastspeaker;
542
+ }
543
+ else
544
+ return;
545
+ }
546
+
547
+ cVector dst = new cVector();
548
+
549
+ boolean success = speakernode.getCentroid(dst); // , true);
550
+
551
+ if (!success)
552
+ new Exception().printStackTrace();
553
+
554
+ //speakernode.parent.TransformToWorld(dst);
555
+ //sourcenode.parent.TransformToLocal(dst);
556
+ this.parent.TransformToLocal(dst);
557
+
558
+ goalposx = dst.x;
559
+ goalposz = dst.z;
560
+ }
561
+ else
562
+ return;
563
+ }
564
+
565
+ cVector temp = new cVector();
566
+
567
+ temp.x = 1;
568
+ temp.y = 0;
569
+ temp.z = 0;
570
+
571
+ LA.xformDir(temp, matrix, temp);
572
+
573
+ double angleYhip = Math.atan2(-temp.z, temp.x);
574
+
575
+ double angleYtarget = Math.atan2(goalposx - centroid.x, goalposz - centroid.z);
576
+
577
+ LA.matIdentity(matrix);
578
+ LA.matTranslate(matrix, -centroid.x, -centroid.y, -centroid.z);
579
+ double angle = CurveAngle(0, angleYtarget - angleYhip, 0.1f);
580
+ LA.matYRotate(matrix, angle);
581
+ LA.matTranslate(matrix, centroid.x, centroid.y, centroid.z);
582
+
583
+ LA.matConcat(matrix, toParent, toParent);
584
+
585
+ LA.matInvert(toParent, fromParent);
586
+
587
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
588
+
589
+ centroid.x = matrix[3][0];
590
+ centroid.y = matrix[3][1];
591
+ centroid.z = matrix[3][2];
592
+
593
+ double dist = LA.distance(centroid, mocaporigin);
594
+
595
+ CheckForAction(centroid);
596
+ }
29597
30598 void WriteTo(java.io.Writer writer) throws Exception
31599 {
....@@ -76,6 +644,24 @@
76644 // transient // aout 2013
77645 Object3D skeleton;
78646
647
+ void ExtractBigData(Object3D o)
648
+ {
649
+ super.ExtractBigData(o);
650
+
651
+ o.bvh = this.bvh;
652
+ o.skeleton = this.skeleton;
653
+ this.bvh = null;
654
+ this.skeleton = null;
655
+ }
656
+
657
+ void RestoreBigData(Object3D o)
658
+ {
659
+ super.RestoreBigData(o);
660
+
661
+ this.bvh = o.bvh;
662
+ this.skeleton = o.skeleton;
663
+ }
664
+
79665 boolean smoothed;
80666
81667 //boolean touched;
....@@ -99,11 +685,11 @@
99685 double pinx;
100686 double pinz;
101687
102
- double targetx;
103
- double targetz;
688
+ double targetdirx;
689
+ double targetdirz;
104690
105
- double goalx;
106
- double goalz;
691
+ double goalposx = 0; // -20;
692
+ double goalposz = 0; // -10;
107693
108694 boolean followpath;
109695
....@@ -174,7 +760,7 @@
174760 scriptactions.clear();
175761 }
176762
177
- static double EPSACTION = 0.1; // 0.075; // 0.1;
763
+ static double EPSACTION = 0.1; // 0.075; // 0.1;Came
178764
179765 void AddFromTo(cVector from, cVector to)
180766 {
....@@ -359,7 +945,7 @@
359945 // //GetFileRoot();
360946
361947 // sept 2014: //
362
- GrafreeD.RENDERME = 3; // patch for Merge objects
948
+ Grafreed.RENDERME = 3; // patch for Merge objects
363949 float[] thedata = bvh.animation.getBoneData(0);
364950
365951 os.x = (float) (path.get(i).toParent[3][0]); // - thedata[frame*6]);
....@@ -460,6 +1046,8 @@
4601046 testvect.set(from);
4611047 testvect.sub(fromto.from);
4621048
1049
+ testvect.y = 0; // PATCH
1050
+
4631051 int factor = 1;
4641052
4651053 //if (CameraPane.FAST)
....@@ -501,6 +1089,8 @@
5011089
5021090 testvect.set(from);
5031091 testvect.sub(fromto.from);
1092
+
1093
+ testvect.y = 0; // PATCH
5041094
5051095 int factor = 1;
5061096
....@@ -705,7 +1295,7 @@
7051295 // skip first node: translation
7061296 // Object3D b = input.get(0);
7071297
708
- setPose(input, f, data.getBoneData(input._index), false); //, null);
1298
+ setPose(input, f, data.getBoneData(input._index)); //, false); //, null);
7091299 }
7101300
7111301 //mocap.figure.Bone[] children = b.getChildren();
....@@ -736,6 +1326,7 @@
7361326
7371327 void SetPosition(Object3D sourcenode, cVector floor, long floorid, cVector centroid)
7381328 {
1329
+ assert(false);
7391330 //assert(CameraPane.drawMode == CameraPane.SHADOW);
7401331
7411332 Object3D transformnode = new Object3D();
....@@ -921,7 +1512,7 @@
9211512 //groundz += sourcenode.parent.toParent[3][2] - posz;
9221513 }
9231514
924
- boolean footcontact = CameraPane.FOOTCONTACT; // false;
1515
+ boolean footcontact = false; // CameraPane.FOOTCONTACT; // false;
9251516
9261517 if (footcontact && ground != -123456)
9271518 {
....@@ -939,9 +1530,9 @@
9391530 groundid = floorid;
9401531
9411532 // green
942
- CameraPane.debugpoint.toParent[3][0] = groundx;
943
- CameraPane.debugpoint.toParent[3][1] = floor.y;
944
- CameraPane.debugpoint.toParent[3][2] = groundz;
1533
+ CameraPane.debugpointG.toParent[3][0] = groundx;
1534
+ CameraPane.debugpointG.toParent[3][1] = floor.y;
1535
+ CameraPane.debugpointG.toParent[3][2] = groundz;
9451536
9461537 if (true) // slow && stepout && onein)
9471538 {
....@@ -952,7 +1543,7 @@
9521543 // mywave = currentwave++;
9531544 // }
9541545 // sound
955
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
1546
+ cVector eye = Globals.theRenderer.EyeCamera().location;
9561547
9571548 // if (sourcenode.parent.parent != null)
9581549 // sourcenode.parent.parent.TransformToWorld(floor, tmp);
....@@ -997,9 +1588,9 @@
9971588 //GraphreeD.
9981589 wav.play(volume * usedvolume); //, mywave);
9991590
1000
- lastsoundtime = CameraPane.framecount;
1591
+ lastsoundtime = Globals.framecount;
10011592
1002
- GrafreeD.hassound = true;
1593
+ Grafreed.hassound = true;
10031594 }
10041595 // else
10051596 // System.out.println("skipped");
....@@ -1018,9 +1609,9 @@
10181609
10191610 // System.out.println("Allo " + sourcenode);
10201611 // 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;
1612
+ CameraPane.debugpointP.toParent[3][0] = floor.x;// + posx;
1613
+ CameraPane.debugpointP.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1614
+ CameraPane.debugpointP.toParent[3][2] = floor.z;// + posz;
10241615
10251616
10261617 if (false) // dist2 > 0.1)
....@@ -1086,9 +1677,9 @@
10861677 this.get(0).TransformToWorld(v0);
10871678
10881679 // cyan
1089
- CameraPane.debugpoint3.toParent[3][0] = v0.x;
1090
- CameraPane.debugpoint3.toParent[3][1] = ground;
1091
- CameraPane.debugpoint3.toParent[3][2] = v0.z;
1680
+ CameraPane.debugpointC.toParent[3][0] = v0.x;
1681
+ CameraPane.debugpointC.toParent[3][1] = ground;
1682
+ CameraPane.debugpointC.toParent[3][2] = v0.z;
10921683
10931684 LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent);
10941685 LA.matInvert(sourcenode.toParent, sourcenode.fromParent);
....@@ -1098,9 +1689,9 @@
10981689 this.get(0).TransformToWorld(v0);
10991690
11001691 // red
1101
- CameraPane.debugpoint4.toParent[3][0] = v0.x;
1102
- CameraPane.debugpoint4.toParent[3][1] = ground;
1103
- CameraPane.debugpoint4.toParent[3][2] = v0.z;
1692
+ CameraPane.debugpointR.toParent[3][0] = v0.x;
1693
+ CameraPane.debugpointR.toParent[3][1] = ground;
1694
+ CameraPane.debugpointR.toParent[3][2] = v0.z;
11041695 }
11051696 }
11061697
....@@ -1140,11 +1731,11 @@
11401731
11411732 if (goal != null)
11421733 {
1143
- System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")");
1734
+ System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
11441735 //sourcenode.parent.parent.Dump();
1145
- goalx = goal.x;
1146
- goalz = goal.z;
1147
- targetx = targetz = 0;
1736
+ goalposx = goal.x;
1737
+ goalposz = goal.z;
1738
+ targetdirx = targetdirz = 0;
11481739
11491740 followpath = true;
11501741 }
....@@ -1195,16 +1786,16 @@
11951786 // }
11961787 if (false) // !uselast)
11971788 {
1198
- CameraPane.debugpoint.toParent[3][0] = dst.x;
1199
- CameraPane.debugpoint.toParent[3][1] = dst.y;
1200
- CameraPane.debugpoint.toParent[3][2] = dst.z;
1789
+ CameraPane.debugpointG.toParent[3][0] = dst.x;
1790
+ CameraPane.debugpointG.toParent[3][1] = dst.y;
1791
+ CameraPane.debugpointG.toParent[3][2] = dst.z;
12011792 }
12021793 }
12031794
1204
- if (goalx != 0 || goalz != 0) // TODO
1795
+ if (goalposx != 0 || goalposz != 0) // TODO
12051796 {
12061797 // overwrite speaker orientation
1207
- dst.set(goalx,0,goalz);
1798
+ dst.set(goalposx,0,goalposz);
12081799 if (sourcenode.parent != null) // july 2014
12091800 sourcenode.parent.
12101801 TransformToLocal(dst);
....@@ -1220,6 +1811,7 @@
12201811 src.x = 0;
12211812 src.y = 0;
12221813 src.z = 0;
1814
+ LA.xformPos(src, get(0).get(0).toParent, src);
12231815 LA.xformPos(src, get(0).toParent, src);
12241816 LA.xformPos(src, toParent, src);
12251817 // LA.xformPos(src, rotsourcenode.toParent, src);
....@@ -1255,26 +1847,26 @@
12551847 // mars 2014
12561848 if (false) // goalx != 0 || goalz != 0)
12571849 {
1258
- targetx = dst.x - src.x;
1259
- targetz = dst.z - src.z;
1850
+ targetdirx = dst.x - src.x;
1851
+ targetdirz = dst.z - src.z;
12601852
1261
- if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1)
1853
+ if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1)
12621854 {
12631855 // far enough from goal. keep the goal position.
1264
- targetx = 0;
1265
- targetz = 0;
1856
+ targetdirx = 0;
1857
+ targetdirz = 0;
12661858 }
12671859 else
12681860 {
12691861 // too close to goal. switch to target direction instead.
1270
- goalx = 0;
1271
- goalz = 0;
1862
+ goalposx = 0;
1863
+ goalposz = 0;
12721864 }
12731865 }
12741866
12751867 //sourcenode.getCentroid(src, true);
12761868
1277
- if (speakernode == sourcenode && goalx == 0 && goalz == 0)
1869
+ if (speakernode == sourcenode && goalposx == 0 && goalposz == 0)
12781870 {
12791871 if (ScriptNode.lastspeaker != null)
12801872 new Exception().printStackTrace();
....@@ -1283,13 +1875,13 @@
12831875
12841876 // LA.xformPos(src, fromParent, src);
12851877
1286
- if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalx != 0 || goalz != 0) && targetx == 0 && targetz == 0)
1878
+ if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalposx != 0 || goalposz != 0) && targetdirx == 0 && targetdirz == 0)
12871879 dst.sub(src);
12881880 else
12891881 // vector mode
12901882 {
1291
- dst.x = targetx;
1292
- dst.z = targetz;
1883
+ dst.x = targetdirx;
1884
+ dst.z = targetdirz;
12931885
12941886 // TEST TARGET
12951887 // dst.x = CameraPane.selectedpoint.toParent[3][0];
....@@ -1563,6 +2155,7 @@
15632155 toParent = LA.newMatrix();
15642156 fromParent = LA.newMatrix();
15652157 }
2158
+
15662159 LA.matConcat(toParent, rotsourcenode.toParent, toParent);
15672160 LA.matInvert(toParent, fromParent);
15682161
....@@ -1698,7 +2291,7 @@
16982291 }
16992292
17002293 if (!smoothed)
1701
- for (int i=4; --i>=0;)
2294
+ for (int i=10; --i>=0;)
17022295 SmoothAnimData(); // much reduces shakiness
17032296
17042297 smoothed = true;
....@@ -1736,9 +2329,16 @@
17362329 toVector.x = LA.cos(to);
17372330 toVector.y = LA.sin(to);
17382331
2332
+ double fromA = Math.atan2(fromVector.y, fromVector.x);
2333
+ double toA = Math.atan2(toVector.y, toVector.x);
2334
+
17392335 Vector2d currentVector = Slerp(fromVector, toVector, step);
17402336
1741
- return Math.atan2(currentVector.y, currentVector.x);
2337
+ double angle = Math.atan2(currentVector.y, currentVector.x);
2338
+
2339
+ double angle2 = (1-step) * fromA + step * toA;
2340
+
2341
+ return angle;
17422342 }
17432343
17442344 public static Vector2d Slerp(Vector2d from, Vector2d to, double step)
....@@ -1780,12 +2380,28 @@
17802380 if (!live) // aout 2013
17812381 return;
17822382
1783
- cVector centroid = new cVector();
1784
- cVector floor = new cVector();
1785
-
1786
- Object3D sourcenode = GetFileRoot();
2383
+ //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);
2384
+ try
2385
+ {
2386
+ SetPose(GetSkeleton(), bvh.animation, f);
2387
+ SetCurrentBones(frame);
2388
+ }
2389
+ catch (Exception e)
2390
+ {
2391
+ e.printStackTrace();
2392
+ }
17872393
1788
- boolean success; // = sourcenode.getCentroid(centroid);
2394
+ SetHipOrientation();
2395
+
2396
+ if (true)
2397
+ return;
2398
+
2399
+ cVector centroid = new cVector();
2400
+ cVector floor = new cVector();
2401
+
2402
+ Object3D sourcenode = GetFileRoot();
2403
+
2404
+ boolean success; // = sourcenode.getCentroid(centroid);
17892405 // if (!success)
17902406 // {
17912407 // //assert(success);
....@@ -1793,16 +2409,6 @@
17932409 // System.out.println("No centroid for " + sourcenode);
17942410 // }
17952411
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
-
18062412 if (sourcenode.parent == null && sourcenode.fileparent == null)
18072413 {
18082414 // No GFD
....@@ -2050,7 +2656,7 @@
20502656 * @param frame
20512657 * Frame number
20522658 */
2053
- public void setPose(Object3D bone, int frame, float[] data, boolean fade) //, Point3d offsetTrans)
2659
+ public void setPose(Object3D bone, int frame, float[] data) //, boolean fade) //, Point3d offsetTrans)
20542660 {
20552661 if (!live) // aout 2013
20562662 return;
....@@ -2058,6 +2664,33 @@
20582664 cVector temp = new cVector();
20592665 cVector temp0 = new cVector();
20602666 double pos[] = new double[3];
2667
+ double angleY = 0;
2668
+ double sinY = 0;
2669
+ double cosY = 0;
2670
+
2671
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
2672
+ {
2673
+ bone.get(0).GlobalTransformInv();
2674
+
2675
+ temp.x = bone.get(0).globalTransform[3][0];
2676
+ temp.y = bone.get(0).globalTransform[3][1];
2677
+ temp.z = bone.get(0).globalTransform[3][2];
2678
+
2679
+ pos[0] = temp.x;
2680
+ pos[1] = temp.y;
2681
+ pos[2] = temp.z;
2682
+
2683
+ temp.x = 1;
2684
+ temp.y = 0;
2685
+ temp.z = 0;
2686
+
2687
+ LA.xformDir(temp, bone.get(0).globalTransform, temp);
2688
+
2689
+ sinY = temp.z;
2690
+ cosY = temp.x;
2691
+
2692
+ angleY = Math.atan2(-sinY, cosY);
2693
+ }
20612694
20622695 // Object3D obj = get(0);
20632696 // Object3D gp = this.parent;
....@@ -2189,13 +2822,14 @@
21892822 if (//frame > 0 &&
21902823 !bone.skipmocap &&
21912824 !bone.name.contains("head") &&
2825
+ !bone.name.contains("Head") // &&
21922826 // !bone.name.contains("rFoot") &&
21932827 // !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")
2828
+// !bone.name.contains("Pinky") &&
2829
+// !bone.name.contains("Ring") &&
2830
+// !bone.name.contains("Mid") &&
2831
+// !bone.name.contains("Index") &&
2832
+// !bone.name.contains("Thumb")
21992833 )
22002834 {
22012835 //_rotTG.setTransform(_t1);
....@@ -2228,15 +2862,17 @@
22282862 // CROWD
22292863 //cJ3D.GetTranslation(bone, _trans0);
22302864 //_trans.add(_trans0);
2231
- _transTF.setIdentity();
2865
+ //_transTF.setIdentity();
2866
+ _transTF.set(_t1);
22322867 _transTF.setTranslation(_trans);
22332868 // System.err.println("Translate: " + _transTF);
22342869 //_transTG.setTransform(_transTF);
2235
- cJ3D.ResetTransform(bone, _transTF, true); // translation node
2870
+ cJ3D.ResetTransform(bone.get(0), _transTF, true); // translation node
2871
+ //cJ3D.ResetTransform(bone, _transTF, true); // translation node
22362872 }
22372873 }
22382874
2239
- if (bone._isRoot && firsttimeafterload && frame > 0)
2875
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
22402876 {
22412877 assert(bone == get(0));
22422878
....@@ -2252,17 +2888,17 @@
22522888 // LA.matConcat(originmatrixinv, tempmatrixinv, fromParent); // ABC * (B'*C')^-1
22532889 //
22542890
2255
- Invariants();
2256
- bone.Invariants();
2257
- bone.get(0).Invariants();
2258
- // if (origin == null)
2259
- // origin = null;
2260
- origin.Invariants();
2261
- origin0.Invariants();
2891
+ Invariants();
2892
+ bone.Invariants();
2893
+ bone.get(0).Invariants();
2894
+ // if (origin == null)
2895
+ // origin = null;
2896
+ origin.Invariants();
2897
+ origin0.Invariants();
22622898
2263
-
2264
- LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2265
- LA.matConcat(origin.toParent, tempmatrix, toParent);
2899
+
2900
+//?? LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2901
+//?? LA.matConcat(origin.toParent, tempmatrix, toParent);
22662902
22672903 // matrixToEulerXYZ(toParent, temp);
22682904 // matrixToEulerXYZ(bone.get(0).toParent, temp);
....@@ -2296,7 +2932,7 @@
22962932 //
22972933 // mat4d.get(quat);
22982934
2299
- if (true) // hip correction
2935
+ if (false) // hip correction
23002936 {
23012937 _t2.setIdentity();
23022938
....@@ -2337,13 +2973,13 @@
23372973 //????? LA.matConcat(bone.get(0).toParent, bone.toParent, tempmatrix); // B' * C'
23382974 // LA.matConcat(origin.fromParent, tempmatrix, fromParent);
23392975
2340
- LA.matInvert(toParent, fromParent);
2976
+//?? LA.matInvert(toParent, fromParent);
23412977
2342
- Invariants();
2343
- bone.Invariants();
2344
- bone.get(0).Invariants();
2345
- origin.Invariants();
2346
- origin0.Invariants();
2978
+ Invariants();
2979
+ bone.Invariants();
2980
+ bone.get(0).Invariants();
2981
+ origin.Invariants();
2982
+ origin0.Invariants();
23472983
23482984 // LA.matInvert(fromParent, tempmatrix);
23492985 //
....@@ -2364,33 +3000,39 @@
23643000 // temp.x = data[0];
23653001 // temp.y = data[1];
23663002 // temp.z = data[2];
2367
- LA.xformPos(temp, origin0.toParent, temp0);
3003
+ LA.xformPos(temp, origin0.toParent, temp0); // NU
23683004
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
-
3005
+// bone.get(0).GlobalTransformInv();
3006
+//
3007
+// temp0.x = bone.get(0).globalTransform[3][0];
3008
+// temp0.y = bone.get(0).globalTransform[3][1];
3009
+// temp0.z = bone.get(0).globalTransform[3][2];
3010
+//
23753011 // 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);
3012
+//fromParent[3][0] = 0;
3013
+//fromParent[3][1] = 0;
3014
+//fromParent[3][2] = 0;
3015
+//LA.matInvert(fromParent, toParent);
23803016
2381
- LA.xformPos(temp0, fromParent, temp);
3017
+ LA.xformPos(temp0, fromParent, temp); // NU
23823018 //LA.xformPos(temp, bone.fromParent, temp);
23833019 // float[] data;
23843020
2385
- pos[0] = temp.x;
2386
- pos[1] = temp.y;
2387
- pos[2] = temp.z;
3021
+// pos[0] = temp.x;
3022
+// pos[1] = temp.y;
3023
+// pos[2] = temp.z;
3024
+//
3025
+// temp.x = 1;
3026
+// temp.y = 0;
3027
+// temp.z = 0;
3028
+//
3029
+// LA.xformDir(temp, bone.get(0).globalTransform, temp);
23883030
23893031 // CameraPane.selectedpoint.toParent[3][0] = temp0.x;
23903032 // CameraPane.selectedpoint.toParent[3][1] = temp0.y;
23913033 // CameraPane.selectedpoint.toParent[3][2] = temp0.z;
23923034
2393
- int numframes = bvh.animation.getNumFrames();
3035
+ int numframes = bvh.animation.getNumFrames();
23943036
23953037 int b = 0;
23963038 {
....@@ -2398,12 +3040,12 @@
23983040
23993041 int dof = 6; /// data.length/numframes;
24003042
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
- }
3043
+ // july 2014
3044
+ if (dof != data.length/numframes)
3045
+ {
3046
+ System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));
3047
+ dof = data.length/numframes;
3048
+ }
24073049
24083050
24093051 int theframe = 0; // baseframe;
....@@ -2455,17 +3097,26 @@
24553097 // }
24563098 // }
24573099
2458
- data[f3 + i] += pos[i] - data[frame3 + i];
3100
+ data[f3 + i] += /*pos[i]*/ - data[frame3 + i];
24593101
24603102 // if (f < 3)
24613103 // {
24623104 // System.out.print(data[f3 + i] + " ");
24633105 // }
24643106 }
2465
-// if (f < 3)
2466
-// {
2467
-// System.out.println();
2468
-// }
3107
+
3108
+ double t1 = data[f3 + 0];
3109
+ double t2 = data[f3 + 2];
3110
+
3111
+ data[f3 + 0] = (float)(cosY*t1 - sinY*t2);
3112
+ data[f3 + 2] = (float)(sinY*t1 + cosY*t2);
3113
+
3114
+ for (int i=3/*dof*/; --i>=0;)
3115
+ {
3116
+ data[f3 + i] += pos[i];
3117
+ }
3118
+
3119
+ data[f3 + 4] += angleY - data[frame3 + 4];
24693120 }
24703121 }
24713122
....@@ -2479,186 +3130,17 @@
24793130 // temp.y = data[1];
24803131 // temp.z = data[2];
24813132
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
- }
3133
+// if (fade && currentbones != null && !CameraPane.fullreset)
3134
+// {
3135
+// Fade();
3136
+// }
26553137 }
2656
-
3138
+
26573139 if (false) // doesn't change anything bone._isRoot)
26583140 {
26593141 // Reset orientation
26603142 _t2.setIdentity();
2661
-
3143
+
26623144 double tx = bone.toParent[3][0];
26633145 double ty = bone.toParent[3][1];
26643146 double tz = bone.toParent[3][2];
....@@ -2667,9 +3149,9 @@
26673149 temp.y = 0;
26683150 temp.z = 0;
26693151 LA.xformDir(temp, bone.toParent, temp);
2670
-
3152
+
26713153 double angle = Math.atan2(-temp.z, temp.x);
2672
-
3154
+
26733155 _t2.rotY(angle);
26743156 // _t1.setIdentity();
26753157 // _t1.rotX(temp.x);
....@@ -2682,56 +3164,21 @@
26823164 // _t1.setIdentity();
26833165 // _t1.rotZ(temp.z);
26843166 // _t2.mul(_t1);
2685
-
3167
+
26863168 cJ3D.ResetTransform(bone, _t2, false);
2687
-
3169
+
26883170 bone.toParent[3][0] = tx;
26893171 bone.toParent[3][1] = ty;
26903172 bone.toParent[3][2] = tz;
26913173 }
26923174 }
26933175
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
- }
3176
+ // SetCurrentBones(frame);
27313177 }
27323178 }
27333179
2734
- static int offset = 1; // 5; // 10; // 5; // 100; // skip initial "T"
3180
+ // skip initial "T"
3181
+ static int offset = 1; // 5; // 10; // 5; // 100;
27353182
27363183 void ReadBVH()
27373184 {
....@@ -2760,14 +3207,14 @@
27603207
27613208 void Reset()
27623209 {
2763
- if (fullname != null)
2764
- ReadBVH();
3210
+// if (fullname != null)
3211
+// ReadBVH();
27653212
27663213 Object3D hip = get(0);
27673214
27683215 // assert(obj.name.equals("hip"));
27693216
2770
- Object3D rot = hip.get(0);
3217
+ //Object3D rot = hip.get(0);
27713218
27723219 // assert(obj.name == null); // .equals("hip#"));
27733220
....@@ -2777,8 +3224,8 @@
27773224 hip.fromParent = LA.newMatrix();
27783225 }
27793226
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;
3227
+ //hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;
3228
+ //hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;
27823229
27833230 if (toParent == null)
27843231 {
....@@ -2790,26 +3237,29 @@
27903237 LA.matIdentity(fromParent);
27913238 // LA.matIdentity(hip.toParent);
27923239 // 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);
3240
+// if (rot.toParent == null)
3241
+// {
3242
+// // june 2014
3243
+// rot.toParent = LA.newMatrix();
3244
+// rot.fromParent = LA.newMatrix();
3245
+// }
3246
+// LA.matIdentity(rot.toParent);
3247
+// LA.matIdentity(rot.fromParent);
28013248
28023249 // july 2014
2803
- goalx = goalz = 0;
2804
- targetx = targetz = 0;
3250
+// goalx = goalz = 0;
3251
+ targetdirx = targetdirz = 0;
28053252
2806
- SetPositionDelta(true, true, true, false);
3253
+ //SetPositionDelta(true, true, true, false);
3254
+// LoadData();
3255
+// Rewind();
28073256
28083257 baseframe = frame = 0; // T pose. No offset.
28093258
28103259 // aout 2013 endframe = 0; // june 2013
28113260
2812
- setPose(frame);
3261
+ ResetZero();
3262
+ //setPose(frame);
28133263 }
28143264
28153265 static int mocapsupport = 0;
....@@ -2827,12 +3277,13 @@
28273277
28283278 int step = 1;
28293279
3280
+ // patch for running hare
28303281 if (speedup) // fev 2014
28313282 step *= 2; // 4;
28323283 if (rewind) // mars 2014
28333284 step *= 4;
28343285
2835
- if (CameraPane.FAST) // && !CameraPane.HOLD)
3286
+ //if (CameraPane.FAST) // && !CameraPane.HOLD)
28363287 step *= CameraPane.STEP;
28373288
28383289 //System.err.println("Step Mocap frame # " + frame);
....@@ -2840,7 +3291,7 @@
28403291 baseframe += step;
28413292
28423293 //frame = baseframe;
2843
- frame += step;
3294
+ //frame += step;
28443295
28453296 // if (frame != baseframe)
28463297 // {
....@@ -2864,7 +3315,7 @@
28643315 "; fullname = " + fullname);
28653316
28663317 //int delta = frame - baseframe;
2867
- if (CameraPane.CROWD)
3318
+ if (Globals.CROWD)
28683319 {
28693320 baseframe = GetFirstFrame(); // 0 initial point
28703321 }
....@@ -2873,29 +3324,53 @@
28733324 // SetPositionDelta(false, true, false); // ?? false);
28743325 {
28753326 if (support == null)
2876
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
2877
- else
28783327 {
2879
- try
3328
+ if (bvh == null && new File(fullname).exists())
3329
+ ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3330
+ else
28803331 {
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);
3332
+ SetGlobalTransform();
3333
+ Rewind();
3334
+ Fade();
28893335 }
28903336 }
3337
+ else
3338
+ {
3339
+// try
3340
+// {
3341
+ bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
3342
+
3343
+ // SetPositionDelta(false, true, true, true);
3344
+ LoadData();
3345
+ Rewind();
3346
+ Fade();
3347
+// }
3348
+// catch (Exception e)
3349
+// {
3350
+// System.err.println("An error occured while loading data. Use fallback by loading the file.");
3351
+// //e.printStackTrace();
3352
+// try
3353
+// {
3354
+// ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3355
+// }
3356
+// catch (Exception e2)
3357
+// {
3358
+// System.err.println("Motion file not found: " + fullname);
3359
+// }
3360
+// }
3361
+ }
28913362 }
3363
+
3364
+ frame = GetFirstFrame();
28923365 }
3366
+ else
3367
+ frame += step;
28933368
28943369 //SetPositionDelta(false);
28953370
2896
- if (frame >= bvh.animation.getNumFrames())
2897
- //baseframe =
2898
- frame = GetFirstFrame(); // 0; // offset; // initial point
3371
+// if (frame >= bvh.animation.getNumFrames())
3372
+// //baseframe =
3373
+// frame = GetFirstFrame(); // 0; // offset; // initial point
28993374
29003375 //System.err.println("frame = " + frame);
29013376 if (lastframe != 0)
....@@ -3064,6 +3539,7 @@
30643539 // filters out bad input data
30653540 void FilterAnimData()
30663541 {
3542
+ new Exception().printStackTrace();
30673543 System.exit(0);
30683544
30693545 float[] data; // = bvh.animation.getBoneData(0);
....@@ -3193,6 +3669,8 @@
31933669 //static
31943670 transient
31953671 double[] currentbones;
3672
+ double[] currenthip;
3673
+
31963674 transient boolean inbetween;
31973675
31983676 void SetPositionDelta(boolean reset, boolean rewind, boolean load, boolean fade)
....@@ -3203,38 +3681,9 @@
32033681 //assert(dim == numframes*6);
32043682
32053683 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
- }
3684
+ {
3685
+ LoadData();
3686
+ }
32383687
32393688 // assert(thedata[0] == 0);
32403689 // assert(thedata[1] == 0);
....@@ -3244,11 +3693,11 @@
32443693 // assert(thedata[7] == 0);
32453694 // assert(thedata[8] == 0);
32463695
3247
- Object3D obj = get(0);
3696
+ Object3D hip = get(0);
32483697
32493698 // assert(obj.name.equals("hip"));
32503699
3251
- Object3D rot = obj.get(0);
3700
+ Object3D rot = hip.get(0);
32523701
32533702 // if (toParent == null)
32543703 // {
....@@ -3260,7 +3709,7 @@
32603709 // // assert(obj.name == null); // .equals("hip#"));
32613710
32623711 Invariants();
3263
- obj.Invariants();
3712
+ hip.Invariants();
32643713 rot.Invariants();
32653714
32663715 if (origin == null)
....@@ -3281,16 +3730,16 @@
32813730 fromParent = LA.newMatrix();
32823731 }
32833732
3284
- if (obj.toParent == null) // june 2014
3733
+ if (hip.toParent == null) // june 2014
32853734 {
3286
- obj.toParent = LA.newMatrix();
3287
- obj.fromParent = LA.newMatrix();
3735
+ hip.toParent = LA.newMatrix();
3736
+ hip.fromParent = LA.newMatrix();
32883737 }
32893738
3290
- LA.matConcat(toParent, obj.toParent, origin0.toParent); // AB
3739
+ LA.matConcat(toParent, hip.toParent, origin0.toParent); // AB
32913740 Object3D gp = this.parent;
32923741 this.parent = null;
3293
- obj.GlobalTransformInv();
3742
+ hip.GlobalTransformInv();
32943743 this.parent = gp;
32953744
32963745 if (rot.toParent == null)
....@@ -3313,41 +3762,41 @@
33133762 LA.matInvert(origin.toParent, origin.fromParent);
33143763
33153764 Invariants();
3316
- obj.Invariants();
3765
+ hip.Invariants();
33173766 rot.Invariants();
33183767 origin.Invariants();
33193768 origin0.Invariants();
33203769
3321
- firsttimeafterload = true;
3770
+ firsttimeafterload = false; // true;
33223771
33233772 if (rewind)
33243773 Rewind();
33253774
3326
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), fade);
3775
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); //, fade);
33273776
3328
- if (true)
3329
- return;
3777
+ if (true)
3778
+ return;
33303779
33313780 double pos[] = new double[6];
33323781
33333782 if (!reset)
33343783 {
3335
- assert(obj.tx == obj.toParent[3][0]);
3336
- assert(obj.ty == obj.toParent[3][1]);
3337
- assert(obj.tz == obj.toParent[3][2]);
3784
+ assert(hip.tx == hip.toParent[3][0]);
3785
+ assert(hip.ty == hip.toParent[3][1]);
3786
+ assert(hip.tz == hip.toParent[3][2]);
33383787
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;
3788
+ pos[0] = hip.tx; // obj.toParent[3][0];
3789
+ pos[1] = hip.ty; // obj.toParent[3][1];
3790
+ pos[2] = hip.tz; // obj.toParent[3][2];
3791
+ pos[3] = hip.rz;
3792
+ pos[4] = hip.ry;
3793
+ pos[5] = hip.rx;
33453794 }
33463795
33473796 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];
3797
+ temp.x = hip.globalTransform[3][0];
3798
+ temp.y = hip.globalTransform[3][1];
3799
+ temp.z = hip.globalTransform[3][2];
33513800 // LA.xformPos(temp, origin0.toParent, temp);
33523801 // System.err.println("POS0 = " + temp.x + ", " + temp.y + ", " + temp.z + ";");
33533802
....@@ -3431,7 +3880,7 @@
34313880 }
34323881
34333882 // Rewind();
3434
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), true);
3883
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); // , true);
34353884 }
34363885
34373886 void Rewind()
....@@ -3448,7 +3897,7 @@
34483897
34493898 transient boolean restarted; // CROWD issue?
34503899
3451
- void drawSelf(CameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
3900
+ void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
34523901 {
34533902 //System.err.println("drawSelf Mocap frame # " + frame);
34543903 //System.err.println("drawSelf Mocap baseframe # " + baseframe);
....@@ -3465,17 +3914,22 @@
34653914 // if (firstframe)
34663915 // return;
34673916
3468
- if (!restarted && /*display.restartframe &&*/
3469
- display.isLIVE() && live && display.drawMode == display.SHADOW) // FUCK
3917
+ if (//!restarted && /*display.restartframe &&*/
3918
+ Globals.isLIVE() && live && (display.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW))
34703919 {
34713920 //display.restartframe = false;
34723921 restarted = true;
3922
+ //System.err.println("restarted = true");
34733923 Step();
34743924 }
34753925 else
34763926 {
3477
- if (display.isLIVE() && live && display.drawMode != display.SHADOW)
3927
+ //System.err.println("restarted");
3928
+ if (Globals.isLIVE() && live && display.DrawMode() != iCameraPane.SHADOW)
3929
+ {
34783930 restarted = false;
3931
+ //System.err.println("restarted = false");
3932
+ }
34793933 }
34803934
34813935 super.drawSelf(display, root, selected, blocked);