Normand Briere
2019-11-17 cb37a129d1adb403019c96e798e86e2da9667f15
Mocap.java
....@@ -26,6 +26,577 @@
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.CreateSelectedPoint();
265
+
266
+ CameraPane.debugpointG.toParent[3][0] = poship.x;
267
+ CameraPane.debugpointG.toParent[3][1] = poship.y;
268
+ CameraPane.debugpointG.toParent[3][2] = poship.z;
269
+
270
+ LA.matInvert(toParent, fromParent);
271
+
272
+ LA.matIdentity(hip.get(0).toParent);
273
+ LA.matIdentity(hip.get(0).fromParent);
274
+
275
+// if (true)
276
+// return;
277
+
278
+ // Updates hip.get(0).toParent
279
+ setPose(hip, GetFirstFrame(), bvh.animation.getBoneData(hip._index));
280
+
281
+ // A = toParent; B = hip.get(0).toParent
282
+ // A'*B = A
283
+ // A' = A * B-1
284
+
285
+ poship.x = hip.get(0).toParent[3][0];
286
+ poship.y = hip.get(0).toParent[3][1];
287
+ poship.z = hip.get(0).toParent[3][2];
288
+
289
+ temp.x = 1;
290
+ temp.y = 0;
291
+ temp.z = 0;
292
+
293
+ LA.xformDir(temp, hip.get(0).toParent, temp);
294
+
295
+ angleYhip = Math.atan2(-temp.z, temp.x);
296
+
297
+ LA.matIdentity(matrix);
298
+ LA.matYRotate(matrix, angleYhip);
299
+ LA.matTranslate(matrix, poship.x, poship.y, poship.z);
300
+
301
+ //LA.matInvert(hip.get(0).toParent, matrix);
302
+ LA.matInvert(matrix, matrix);
303
+
304
+ //LA.matIdentity(matrix);
305
+ //LA.matTranslate(matrix, -poship.x, -poship.y, -poship.z);
306
+
307
+ LA.matConcat(toParent, matrix, toParent);
308
+
309
+
310
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
311
+ pos.x = hip.get(0).toParent[3][0];
312
+ pos.y = hip.get(0).toParent[3][1];
313
+ pos.z = hip.get(0).toParent[3][2];
314
+ LA.xformPos(new cVector(), hip.get(0).toParent, pos);
315
+ LA.xformPos(pos, toParent, pos);
316
+
317
+// temp.x = 1;
318
+// temp.y = 0;
319
+// temp.z = 0;
320
+//
321
+// LA.xformDir(temp, toParent, temp);
322
+//
323
+// angleY = Math.atan2(-temp.z, temp.x);
324
+//
325
+// LA.matIdentity(toParent);
326
+// LA.matYRotate(toParent, angleY - angleYhip);
327
+// LA.matTranslate(toParent, pos.x - poship.x, pos.y - poship.y, pos.z - poship.z);
328
+
329
+ CameraPane.debugpointP.toParent[3][0] = pos.x;
330
+ CameraPane.debugpointP.toParent[3][1] = pos.y;
331
+ CameraPane.debugpointP.toParent[3][2] = pos.z;
332
+
333
+ CameraPane.debugpointC.toParent[3][0] = poship.x;
334
+ CameraPane.debugpointC.toParent[3][1] = poship.y;
335
+ CameraPane.debugpointC.toParent[3][2] = poship.z;
336
+
337
+ poship.x = toParent[3][0];
338
+ poship.y = toParent[3][1];
339
+ poship.z = toParent[3][2];
340
+
341
+ CameraPane.debugpointR.toParent[3][0] = poship.x;
342
+ CameraPane.debugpointR.toParent[3][1] = poship.y;
343
+ CameraPane.debugpointR.toParent[3][2] = poship.z;
344
+
345
+ LA.matInvert(toParent, fromParent);
346
+ }
347
+
348
+ void LoadData()
349
+ {
350
+ float[] thedata = bvh.animation.getBoneData(0);
351
+
352
+// thedata[0] = 0;
353
+// thedata[1] = 0;
354
+// thedata[2] = 0;
355
+// thedata[3] = 0;
356
+// thedata[4] = 0;
357
+// thedata[5] = 0;
358
+
359
+ if (true)
360
+ return;
361
+
362
+ for (int b=numbones; --b>=0;)
363
+ //int b = 0;
364
+ {
365
+ thedata = bvh.animation.getBoneData(b);
366
+
367
+ int numframes = bvh.animation.getNumFrames();
368
+
369
+ int dof = 6; // thedata.length/numframes;
370
+
371
+ if (b > 0)
372
+ dof = 3;
373
+
374
+ if (dof != thedata.length/numframes)
375
+ {
376
+ System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (thedata.length/numframes));
377
+ dof = thedata.length/numframes;
378
+ }
379
+
380
+ //for (int f=numframes; --f>=offset;)
381
+ int firstframe = GetFirstFrame();
382
+ for (int f=0; f<numframes-firstframe; f++)
383
+ {
384
+ int f3 = f*dof;
385
+
386
+ //for (int i=3/*dof*/; --i>=0;)
387
+ for (int i=dof; --i>=0;)
388
+ {
389
+ //thedata[f3 + i] += thedata[i] - thedata[offset*dof + i];
390
+ thedata[f3 + i] = thedata[f3 + firstframe*dof + i];
391
+ }
392
+ }
393
+ }
394
+ }
395
+
396
+ void ResetZero()
397
+ {
398
+ for (int b=numbones; --b>=0;)
399
+ {
400
+ float[] thedata = bvh.animation.getBoneData(b);
401
+
402
+ int numframes = bvh.animation.getNumFrames();
403
+
404
+ int dof = 6;
405
+
406
+ if (b > 0)
407
+ dof = 3;
408
+
409
+ for (int i=dof; --i>=0;)
410
+ {
411
+ thedata[i] = 0;
412
+ }
413
+ }
414
+ }
415
+
416
+ void SetCurrentBones(int frame)
417
+ {
418
+ if (frame == 0)
419
+ {
420
+ //frame = 1;
421
+ }
422
+
423
+ if (currentbones == null)
424
+ {
425
+ currentbones = new double[(numbones-1)*3];
426
+ currenthip = new double[6];
427
+ }
428
+
429
+ for (int b=numbones; --b>=1;) // HIP ROTATION: 0;)
430
+ //int b = 0;
431
+ {
432
+ float[] data = bvh.animation.getBoneData(b);
433
+
434
+ // int numframes = bvh.animation.getNumFrames();
435
+
436
+ int dof = 6; // data.length/numframes;
437
+
438
+ if (b > 0)
439
+ dof = 3;
440
+
441
+ //assert(dof == 3);
442
+
443
+ // System.err.println("Bone #" + b + ": dof = " + dof);
444
+ int theframe = // 1; // baseframe;
445
+ frame;
446
+
447
+ int frame3 = theframe*dof;
448
+ int bone3 = (b-1)*dof;
449
+
450
+ int start = 3;
451
+ int end = 0;
452
+
453
+ if (dof == 6)
454
+ {
455
+ start = 6;
456
+ //end = 3;
457
+ }
458
+
459
+ for (int i=start; --i>=end;)
460
+ {
461
+ currentbones[bone3 + i/*-end*/] = data[frame3 + i];
462
+ }
463
+ }
464
+
465
+ float[] data = bvh.animation.getBoneData(0);
466
+
467
+ int dof = 6;
468
+
469
+ int theframe = frame;
470
+
471
+ int frame3 = theframe*dof;
472
+
473
+ int start = 6;
474
+ int end = 0;
475
+
476
+ for (int i=start; --i>=end;)
477
+ {
478
+ currenthip[i] = data[frame3 + i];
479
+ }
480
+ }
481
+
482
+ static cVector centroid = new cVector();
483
+ static cVector mocaporigin = new cVector();
484
+
485
+ void SetHipOrientation()
486
+ {
487
+ Object3D hip = get(0);
488
+
489
+ if (toParent == null)
490
+ {
491
+ toParent = LA.newMatrix();
492
+ fromParent = LA.newMatrix();
493
+ }
494
+
495
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
496
+
497
+ mocaporigin.x = matrix[3][0];
498
+ mocaporigin.y = matrix[3][1];
499
+ mocaporigin.z = matrix[3][2];
500
+
501
+ centroid.x = matrix[3][0];
502
+ centroid.y = matrix[3][1];
503
+ centroid.z = matrix[3][2];
504
+// this.getCentroid(centroid, true);
505
+
506
+ CameraPane.CreateSelectedPoint();
507
+ CameraPane.debugpointG.name = "";
508
+ CameraPane.debugpointG.toParent[3][0] = mocaporigin.x;
509
+ CameraPane.debugpointG.toParent[3][1] = mocaporigin.y;
510
+ CameraPane.debugpointG.toParent[3][2] = mocaporigin.z;
511
+
512
+ CameraPane.debugpointP.name = "";
513
+ CameraPane.debugpointP.toParent[3][0] = centroid.x;
514
+ CameraPane.debugpointP.toParent[3][1] = centroid.y;
515
+ CameraPane.debugpointP.toParent[3][2] = centroid.z;
516
+
517
+ cVector goal = GetGoal(centroid);
518
+ if (goal != null)
519
+ {
520
+ System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
521
+
522
+ goalposx = goal.x;
523
+ goalposz = goal.z;
524
+ targetdirx = targetdirz = 0;
525
+ }
526
+
527
+ if (goalposx == 0 && goalposz == 0)
528
+ {
529
+ // No target
530
+ if (ScriptNode.speaker != null)
531
+ {
532
+ Object3D sourcenode = GetFileRoot();
533
+ Object3D speakernode = ScriptNode.speaker.GetFileRoot();
534
+
535
+ //System.err.println("speaker is " + speakernode + "; last was " + ScriptNode.lastspeaker);
536
+
537
+ Object3D speaker = ScriptNode.speaker;
538
+
539
+ if (speakernode == sourcenode)
540
+ {
541
+ if (ScriptNode.lastspeaker != null)
542
+ {
543
+ speakernode = ScriptNode.lastspeaker.GetFileRoot();
544
+ speaker = ScriptNode.lastspeaker;
545
+ }
546
+ else
547
+ return;
548
+ }
549
+
550
+ cVector dst = new cVector();
551
+
552
+ boolean success = speakernode.getCentroid(dst); // , true);
553
+
554
+ if (!success)
555
+ new Exception().printStackTrace();
556
+
557
+ //speakernode.parent.TransformToWorld(dst);
558
+ //sourcenode.parent.TransformToLocal(dst);
559
+ this.parent.TransformToLocal(dst);
560
+
561
+ goalposx = dst.x;
562
+ goalposz = dst.z;
563
+ }
564
+ else
565
+ return;
566
+ }
567
+
568
+ cVector temp = new cVector();
569
+
570
+ temp.x = 1;
571
+ temp.y = 0;
572
+ temp.z = 0;
573
+
574
+ LA.xformDir(temp, matrix, temp);
575
+
576
+ double angleYhip = Math.atan2(-temp.z, temp.x);
577
+
578
+ double angleYtarget = Math.atan2(goalposx - centroid.x, goalposz - centroid.z);
579
+
580
+ LA.matIdentity(matrix);
581
+ LA.matTranslate(matrix, -centroid.x, -centroid.y, -centroid.z);
582
+ double angle = CurveAngle(0, angleYtarget - angleYhip, 0.1f);
583
+ LA.matYRotate(matrix, angle);
584
+ LA.matTranslate(matrix, centroid.x, centroid.y, centroid.z);
585
+
586
+ LA.matConcat(matrix, toParent, toParent);
587
+
588
+ LA.matInvert(toParent, fromParent);
589
+
590
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
591
+
592
+ centroid.x = matrix[3][0];
593
+ centroid.y = matrix[3][1];
594
+ centroid.z = matrix[3][2];
595
+
596
+ double dist = LA.distance(centroid, mocaporigin);
597
+
598
+ CheckForAction(centroid);
599
+ }
29600
30601 void WriteTo(java.io.Writer writer) throws Exception
31602 {
....@@ -76,6 +647,24 @@
76647 // transient // aout 2013
77648 Object3D skeleton;
78649
650
+ void ExtractBigData(Object3D o)
651
+ {
652
+ super.ExtractBigData(o);
653
+
654
+ o.savebvh = this.bvh;
655
+ o.saveskeleton = this.skeleton;
656
+ this.bvh = null;
657
+ this.skeleton = null;
658
+ }
659
+
660
+ void RestoreBigData(Object3D o)
661
+ {
662
+ super.RestoreBigData(o);
663
+
664
+ this.bvh = o.savebvh;
665
+ this.skeleton = o.saveskeleton;
666
+ }
667
+
79668 boolean smoothed;
80669
81670 //boolean touched;
....@@ -99,11 +688,11 @@
99688 double pinx;
100689 double pinz;
101690
102
- double targetx;
103
- double targetz;
691
+ double targetdirx;
692
+ double targetdirz;
104693
105
- double goalx;
106
- double goalz;
694
+ double goalposx = 0; // -20;
695
+ double goalposz = 0; // -10;
107696
108697 boolean followpath;
109698
....@@ -174,7 +763,7 @@
174763 scriptactions.clear();
175764 }
176765
177
- static double EPSACTION = 0.1; // 0.075; // 0.1;
766
+ static double EPSACTION = 0.1; // 0.075; // 0.1;Came
178767
179768 void AddFromTo(cVector from, cVector to)
180769 {
....@@ -359,7 +948,7 @@
359948 // //GetFileRoot();
360949
361950 // sept 2014: //
362
- GraphreeD.RENDERME = 3; // patch for Merge objects
951
+ Grafreed.RENDERME = 3; // patch for Merge objects
363952 float[] thedata = bvh.animation.getBoneData(0);
364953
365954 os.x = (float) (path.get(i).toParent[3][0]); // - thedata[frame*6]);
....@@ -409,7 +998,7 @@
409998
410999 get(0).link2master = path.size() > 1; // hip orientation
4111000
412
- if (get(0).link2master)
1001
+ if (get(0).Link2Support())
4131002 {
4141003 rotateonce = 2;
4151004 }
....@@ -460,6 +1049,8 @@
4601049 testvect.set(from);
4611050 testvect.sub(fromto.from);
4621051
1052
+ testvect.y = 0; // PATCH
1053
+
4631054 int factor = 1;
4641055
4651056 //if (CameraPane.FAST)
....@@ -501,6 +1092,8 @@
5011092
5021093 testvect.set(from);
5031094 testvect.sub(fromto.from);
1095
+
1096
+ testvect.y = 0; // PATCH
5041097
5051098 int factor = 1;
5061099
....@@ -705,7 +1298,7 @@
7051298 // skip first node: translation
7061299 // Object3D b = input.get(0);
7071300
708
- setPose(input, f, data.getBoneData(input._index), false); //, null);
1301
+ setPose(input, f, data.getBoneData(input._index)); //, false); //, null);
7091302 }
7101303
7111304 //mocap.figure.Bone[] children = b.getChildren();
....@@ -736,6 +1329,7 @@
7361329
7371330 void SetPosition(Object3D sourcenode, cVector floor, long floorid, cVector centroid)
7381331 {
1332
+ assert(false);
7391333 //assert(CameraPane.drawMode == CameraPane.SHADOW);
7401334
7411335 Object3D transformnode = new Object3D();
....@@ -833,7 +1427,7 @@
8331427 double w = 0.00015;
8341428
8351429 //if (!sourcenode.link2master) // strong pin on floor
836
- if (parent.link2master) // strong pin on floor
1430
+ if (parent.Link2Support()) // strong pin on floor
8371431 {
8381432 w = 0.005; // .001;
8391433 }
....@@ -921,7 +1515,7 @@
9211515 //groundz += sourcenode.parent.toParent[3][2] - posz;
9221516 }
9231517
924
- boolean footcontact = CameraPane.FOOTCONTACT; // false;
1518
+ boolean footcontact = false; // CameraPane.FOOTCONTACT; // false;
9251519
9261520 if (footcontact && ground != -123456)
9271521 {
....@@ -938,9 +1532,10 @@
9381532
9391533 groundid = floorid;
9401534
941
- CameraPane.debugpoint.toParent[3][0] = groundx;
942
- CameraPane.debugpoint.toParent[3][1] = floor.y;
943
- CameraPane.debugpoint.toParent[3][2] = groundz;
1535
+ // green
1536
+ CameraPane.debugpointG.toParent[3][0] = groundx;
1537
+ CameraPane.debugpointG.toParent[3][1] = floor.y;
1538
+ CameraPane.debugpointG.toParent[3][2] = groundz;
9441539
9451540 if (true) // slow && stepout && onein)
9461541 {
....@@ -951,7 +1546,7 @@
9511546 // mywave = currentwave++;
9521547 // }
9531548 // sound
954
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
1549
+ cVector eye = Globals.theRenderer.EyeCamera().location;
9551550
9561551 // if (sourcenode.parent.parent != null)
9571552 // sourcenode.parent.parent.TransformToWorld(floor, tmp);
....@@ -996,9 +1591,9 @@
9961591 //GraphreeD.
9971592 wav.play(volume * usedvolume); //, mywave);
9981593
999
- lastsoundtime = CameraPane.framecount;
1594
+ lastsoundtime = Globals.framecount;
10001595
1001
- GraphreeD.hassound = true;
1596
+ Grafreed.hassound = true;
10021597 }
10031598 // else
10041599 // System.out.println("skipped");
....@@ -1016,9 +1611,10 @@
10161611 // floor.z += posz;
10171612
10181613 // System.out.println("Allo " + sourcenode);
1019
- CameraPane.debugpoint2.toParent[3][0] = floor.x;// + posx;
1020
- CameraPane.debugpoint2.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1021
- CameraPane.debugpoint2.toParent[3][2] = floor.z;// + posz;
1614
+ // purple
1615
+ CameraPane.debugpointP.toParent[3][0] = floor.x;// + posx;
1616
+ CameraPane.debugpointP.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1617
+ CameraPane.debugpointP.toParent[3][2] = floor.z;// + posz;
10221618
10231619
10241620 if (false) // dist2 > 0.1)
....@@ -1045,14 +1641,14 @@
10451641 // sourcenode.parent.toParent[3][1] = ground - floor.y;
10461642 // sourcenode.parent.toParent[3][2] += groundz - floor.z;
10471643 // sourcenode.parent.toParent[3][1] = K * (ground - floor.y) + (1 - K) * oldposy;
1048
- if (footcontact && (sourcenode.parent != null && !sourcenode.parent.link2master)) // strong pin on floor
1644
+ if (footcontact && (sourcenode.parent != null && !sourcenode.parent.Link2Support())) // strong pin on floor
10491645 {
10501646 v0.x = groundx - floor.x;
10511647 v0.y = 0; // groundx - floor.x;
10521648 v0.z = groundz - floor.z;
10531649
10541650 double distance = Math.sqrt(v0.dot(v0));
1055
- double maxdist = 0.004;
1651
+ double maxdist = 0.04;
10561652
10571653 if (distance > maxdist)
10581654 {
....@@ -1078,8 +1674,27 @@
10781674 sourcenode.toParent = LA.newMatrix();
10791675 sourcenode.fromParent = LA.newMatrix();
10801676 }
1677
+
1678
+ v0.x = v0.z = 0;
1679
+
1680
+ this.get(0).TransformToWorld(v0);
1681
+
1682
+ // cyan
1683
+ CameraPane.debugpointC.toParent[3][0] = v0.x;
1684
+ CameraPane.debugpointC.toParent[3][1] = ground;
1685
+ CameraPane.debugpointC.toParent[3][2] = v0.z;
1686
+
10811687 LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent);
10821688 LA.matInvert(sourcenode.toParent, sourcenode.fromParent);
1689
+
1690
+ v0.x = v0.z = 0;
1691
+
1692
+ this.get(0).TransformToWorld(v0);
1693
+
1694
+ // red
1695
+ CameraPane.debugpointR.toParent[3][0] = v0.x;
1696
+ CameraPane.debugpointR.toParent[3][1] = ground;
1697
+ CameraPane.debugpointR.toParent[3][2] = v0.z;
10831698 }
10841699 }
10851700
....@@ -1119,11 +1734,11 @@
11191734
11201735 if (goal != null)
11211736 {
1122
- System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")");
1737
+ System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
11231738 //sourcenode.parent.parent.Dump();
1124
- goalx = goal.x;
1125
- goalz = goal.z;
1126
- targetx = targetz = 0;
1739
+ goalposx = goal.x;
1740
+ goalposz = goal.z;
1741
+ targetdirx = targetdirz = 0;
11271742
11281743 followpath = true;
11291744 }
....@@ -1174,16 +1789,16 @@
11741789 // }
11751790 if (false) // !uselast)
11761791 {
1177
- CameraPane.debugpoint.toParent[3][0] = dst.x;
1178
- CameraPane.debugpoint.toParent[3][1] = dst.y;
1179
- CameraPane.debugpoint.toParent[3][2] = dst.z;
1792
+ CameraPane.debugpointG.toParent[3][0] = dst.x;
1793
+ CameraPane.debugpointG.toParent[3][1] = dst.y;
1794
+ CameraPane.debugpointG.toParent[3][2] = dst.z;
11801795 }
11811796 }
11821797
1183
- if (goalx != 0 || goalz != 0) // TODO
1798
+ if (goalposx != 0 || goalposz != 0) // TODO
11841799 {
11851800 // overwrite speaker orientation
1186
- dst.set(goalx,0,goalz);
1801
+ dst.set(goalposx,0,goalposz);
11871802 if (sourcenode.parent != null) // july 2014
11881803 sourcenode.parent.
11891804 TransformToLocal(dst);
....@@ -1199,6 +1814,7 @@
11991814 src.x = 0;
12001815 src.y = 0;
12011816 src.z = 0;
1817
+ LA.xformPos(src, get(0).get(0).toParent, src);
12021818 LA.xformPos(src, get(0).toParent, src);
12031819 LA.xformPos(src, toParent, src);
12041820 // LA.xformPos(src, rotsourcenode.toParent, src);
....@@ -1234,26 +1850,26 @@
12341850 // mars 2014
12351851 if (false) // goalx != 0 || goalz != 0)
12361852 {
1237
- targetx = dst.x - src.x;
1238
- targetz = dst.z - src.z;
1853
+ targetdirx = dst.x - src.x;
1854
+ targetdirz = dst.z - src.z;
12391855
1240
- if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1)
1856
+ if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1)
12411857 {
12421858 // far enough from goal. keep the goal position.
1243
- targetx = 0;
1244
- targetz = 0;
1859
+ targetdirx = 0;
1860
+ targetdirz = 0;
12451861 }
12461862 else
12471863 {
12481864 // too close to goal. switch to target direction instead.
1249
- goalx = 0;
1250
- goalz = 0;
1865
+ goalposx = 0;
1866
+ goalposz = 0;
12511867 }
12521868 }
12531869
12541870 //sourcenode.getCentroid(src, true);
12551871
1256
- if (speakernode == sourcenode && goalx == 0 && goalz == 0)
1872
+ if (speakernode == sourcenode && goalposx == 0 && goalposz == 0)
12571873 {
12581874 if (ScriptNode.lastspeaker != null)
12591875 new Exception().printStackTrace();
....@@ -1262,13 +1878,13 @@
12621878
12631879 // LA.xformPos(src, fromParent, src);
12641880
1265
- if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalx != 0 || goalz != 0) && targetx == 0 && targetz == 0)
1881
+ if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalposx != 0 || goalposz != 0) && targetdirx == 0 && targetdirz == 0)
12661882 dst.sub(src);
12671883 else
12681884 // vector mode
12691885 {
1270
- dst.x = targetx;
1271
- dst.z = targetz;
1886
+ dst.x = targetdirx;
1887
+ dst.z = targetdirz;
12721888
12731889 // TEST TARGET
12741890 // dst.x = CameraPane.selectedpoint.toParent[3][0];
....@@ -1390,7 +2006,7 @@
13902006 // if (sourcenode.link2master)
13912007 // if (goalx != 0 || goalz != 0)
13922008 // K = 0.02; // .0625;
1393
- if (parent.link2master) // strong pin on floor
2009
+ if (parent.Link2Support()) // strong pin on floor
13942010 {
13952011 K = 0.05; // 0.02;
13962012 }
....@@ -1542,6 +2158,7 @@
15422158 toParent = LA.newMatrix();
15432159 fromParent = LA.newMatrix();
15442160 }
2161
+
15452162 LA.matConcat(toParent, rotsourcenode.toParent, toParent);
15462163 LA.matInvert(toParent, fromParent);
15472164
....@@ -1677,7 +2294,7 @@
16772294 }
16782295
16792296 if (!smoothed)
1680
- for (int i=4; --i>=0;)
2297
+ for (int i=10; --i>=0;)
16812298 SmoothAnimData(); // much reduces shakiness
16822299
16832300 smoothed = true;
....@@ -1715,9 +2332,16 @@
17152332 toVector.x = LA.cos(to);
17162333 toVector.y = LA.sin(to);
17172334
2335
+ double fromA = Math.atan2(fromVector.y, fromVector.x);
2336
+ double toA = Math.atan2(toVector.y, toVector.x);
2337
+
17182338 Vector2d currentVector = Slerp(fromVector, toVector, step);
17192339
1720
- return Math.atan2(currentVector.y, currentVector.x);
2340
+ double angle = Math.atan2(currentVector.y, currentVector.x);
2341
+
2342
+ double angle2 = (1-step) * fromA + step * toA;
2343
+
2344
+ return angle;
17212345 }
17222346
17232347 public static Vector2d Slerp(Vector2d from, Vector2d to, double step)
....@@ -1759,12 +2383,28 @@
17592383 if (!live) // aout 2013
17602384 return;
17612385
1762
- cVector centroid = new cVector();
1763
- cVector floor = new cVector();
1764
-
1765
- Object3D sourcenode = GetFileRoot();
2386
+ //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);
2387
+ try
2388
+ {
2389
+ SetPose(GetSkeleton(), bvh.animation, f);
2390
+ SetCurrentBones(frame);
2391
+ }
2392
+ catch (Exception e)
2393
+ {
2394
+ e.printStackTrace();
2395
+ }
17662396
1767
- boolean success; // = sourcenode.getCentroid(centroid);
2397
+ SetHipOrientation();
2398
+
2399
+ if (true)
2400
+ return;
2401
+
2402
+ cVector centroid = new cVector();
2403
+ cVector floor = new cVector();
2404
+
2405
+ Object3D sourcenode = GetFileRoot();
2406
+
2407
+ boolean success; // = sourcenode.getCentroid(centroid);
17682408 // if (!success)
17692409 // {
17702410 // //assert(success);
....@@ -1772,16 +2412,6 @@
17722412 // System.out.println("No centroid for " + sourcenode);
17732413 // }
17742414
1775
- //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);
1776
- try
1777
- {
1778
- SetPose(GetSkeleton(), bvh.animation, f);
1779
- }
1780
- catch (Exception e)
1781
- {
1782
- e.printStackTrace();
1783
- }
1784
-
17852415 if (sourcenode.parent == null && sourcenode.fileparent == null)
17862416 {
17872417 // No GFD
....@@ -1793,9 +2423,9 @@
17932423 // SetBreakPoint(get(0).toParent[0], 0);
17942424 // }
17952425
1796
- boolean setrotation = get(0).link2master && !firsttimeafterload && frame > 0;
2426
+ boolean setrotation = get(0).Link2Support() && !firsttimeafterload && frame > 0;
17972427 boolean setposition = sourcenode != null && // sourcenode.parent != null && // july 2014
1798
- sourcenode./*parent.*/link2master && !firsttimeafterload && frame > 0;
2428
+ sourcenode./*parent.*/Link2Support() && !firsttimeafterload && frame > 0;
17992429
18002430 // cVector centroid = new cVector();
18012431 // cVector floor = new cVector();
....@@ -1835,7 +2465,7 @@
18352465 {
18362466 SetRotation(sourcenode, new cVector(floor), new cVector(centroid));
18372467 }
1838
-
2468
+
18392469 if (setposition)
18402470 {
18412471 if (floorobject != null)
....@@ -2029,7 +2659,7 @@
20292659 * @param frame
20302660 * Frame number
20312661 */
2032
- public void setPose(Object3D bone, int frame, float[] data, boolean fade) //, Point3d offsetTrans)
2662
+ public void setPose(Object3D bone, int frame, float[] data) //, boolean fade) //, Point3d offsetTrans)
20332663 {
20342664 if (!live) // aout 2013
20352665 return;
....@@ -2037,6 +2667,33 @@
20372667 cVector temp = new cVector();
20382668 cVector temp0 = new cVector();
20392669 double pos[] = new double[3];
2670
+ double angleY = 0;
2671
+ double sinY = 0;
2672
+ double cosY = 0;
2673
+
2674
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
2675
+ {
2676
+ bone.get(0).GlobalTransformInv();
2677
+
2678
+ temp.x = bone.get(0).globalTransform[3][0];
2679
+ temp.y = bone.get(0).globalTransform[3][1];
2680
+ temp.z = bone.get(0).globalTransform[3][2];
2681
+
2682
+ pos[0] = temp.x;
2683
+ pos[1] = temp.y;
2684
+ pos[2] = temp.z;
2685
+
2686
+ temp.x = 1;
2687
+ temp.y = 0;
2688
+ temp.z = 0;
2689
+
2690
+ LA.xformDir(temp, bone.get(0).globalTransform, temp);
2691
+
2692
+ sinY = temp.z;
2693
+ cosY = temp.x;
2694
+
2695
+ angleY = Math.atan2(-sinY, cosY);
2696
+ }
20402697
20412698 // Object3D obj = get(0);
20422699 // Object3D gp = this.parent;
....@@ -2168,13 +2825,14 @@
21682825 if (//frame > 0 &&
21692826 !bone.skipmocap &&
21702827 !bone.name.contains("head") &&
2828
+ !bone.name.contains("Head") // &&
21712829 // !bone.name.contains("rFoot") &&
21722830 // !bone.name.contains("lFoot") &&
2173
- !bone.name.contains("Pinky") &&
2174
- !bone.name.contains("Ring") &&
2175
- !bone.name.contains("Mid") &&
2176
- !bone.name.contains("Index") &&
2177
- !bone.name.contains("Thumb")
2831
+// !bone.name.contains("Pinky") &&
2832
+// !bone.name.contains("Ring") &&
2833
+// !bone.name.contains("Mid") &&
2834
+// !bone.name.contains("Index") &&
2835
+// !bone.name.contains("Thumb")
21782836 )
21792837 {
21802838 //_rotTG.setTransform(_t1);
....@@ -2200,22 +2858,24 @@
22002858
22012859 // set translation
22022860 // (currently only possible for root bone! see mocapdata.com data)
2203
- if (bone._isRoot && link2master) // && !GetFileRoot().link2master)
2861
+ if (bone._isRoot && Link2Support()) // && !GetFileRoot().link2master)
22042862 {
22052863 if (hasTranslation) // && _translationEnabled)
22062864 {
22072865 // CROWD
22082866 //cJ3D.GetTranslation(bone, _trans0);
22092867 //_trans.add(_trans0);
2210
- _transTF.setIdentity();
2868
+ //_transTF.setIdentity();
2869
+ _transTF.set(_t1);
22112870 _transTF.setTranslation(_trans);
22122871 // System.err.println("Translate: " + _transTF);
22132872 //_transTG.setTransform(_transTF);
2214
- cJ3D.ResetTransform(bone, _transTF, true); // translation node
2873
+ cJ3D.ResetTransform(bone.get(0), _transTF, true); // translation node
2874
+ //cJ3D.ResetTransform(bone, _transTF, true); // translation node
22152875 }
22162876 }
22172877
2218
- if (bone._isRoot && firsttimeafterload && frame > 0)
2878
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
22192879 {
22202880 assert(bone == get(0));
22212881
....@@ -2231,17 +2891,17 @@
22312891 // LA.matConcat(originmatrixinv, tempmatrixinv, fromParent); // ABC * (B'*C')^-1
22322892 //
22332893
2234
- Invariants();
2235
- bone.Invariants();
2236
- bone.get(0).Invariants();
2237
- // if (origin == null)
2238
- // origin = null;
2239
- origin.Invariants();
2240
- origin0.Invariants();
2894
+ Invariants();
2895
+ bone.Invariants();
2896
+ bone.get(0).Invariants();
2897
+ // if (origin == null)
2898
+ // origin = null;
2899
+ origin.Invariants();
2900
+ origin0.Invariants();
22412901
2242
-
2243
- LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2244
- LA.matConcat(origin.toParent, tempmatrix, toParent);
2902
+
2903
+//?? LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2904
+//?? LA.matConcat(origin.toParent, tempmatrix, toParent);
22452905
22462906 // matrixToEulerXYZ(toParent, temp);
22472907 // matrixToEulerXYZ(bone.get(0).toParent, temp);
....@@ -2275,7 +2935,7 @@
22752935 //
22762936 // mat4d.get(quat);
22772937
2278
- if (true) // hip correction
2938
+ if (false) // hip correction
22792939 {
22802940 _t2.setIdentity();
22812941
....@@ -2316,13 +2976,13 @@
23162976 //????? LA.matConcat(bone.get(0).toParent, bone.toParent, tempmatrix); // B' * C'
23172977 // LA.matConcat(origin.fromParent, tempmatrix, fromParent);
23182978
2319
- LA.matInvert(toParent, fromParent);
2979
+//?? LA.matInvert(toParent, fromParent);
23202980
2321
- Invariants();
2322
- bone.Invariants();
2323
- bone.get(0).Invariants();
2324
- origin.Invariants();
2325
- origin0.Invariants();
2981
+ Invariants();
2982
+ bone.Invariants();
2983
+ bone.get(0).Invariants();
2984
+ origin.Invariants();
2985
+ origin0.Invariants();
23262986
23272987 // LA.matInvert(fromParent, tempmatrix);
23282988 //
....@@ -2343,33 +3003,39 @@
23433003 // temp.x = data[0];
23443004 // temp.y = data[1];
23453005 // temp.z = data[2];
2346
- LA.xformPos(temp, origin0.toParent, temp0);
3006
+ LA.xformPos(temp, origin0.toParent, temp0); // NU
23473007
2348
-// bone.GlobalTransformInv();
2349
-
2350
- temp0.x = bone.globalTransform[3][0];
2351
- temp0.y = bone.globalTransform[3][1];
2352
- temp0.z = bone.globalTransform[3][2];
2353
-
3008
+// bone.get(0).GlobalTransformInv();
3009
+//
3010
+// temp0.x = bone.get(0).globalTransform[3][0];
3011
+// temp0.y = bone.get(0).globalTransform[3][1];
3012
+// temp0.z = bone.get(0).globalTransform[3][2];
3013
+//
23543014 // MEGA TEST // june 2014: necessary for precision? otherwise comment works
2355
-fromParent[3][0] = 0;
2356
-fromParent[3][1] = 0;
2357
-fromParent[3][2] = 0;
2358
-LA.matInvert(fromParent, toParent);
3015
+//fromParent[3][0] = 0;
3016
+//fromParent[3][1] = 0;
3017
+//fromParent[3][2] = 0;
3018
+//LA.matInvert(fromParent, toParent);
23593019
2360
- LA.xformPos(temp0, fromParent, temp);
3020
+ LA.xformPos(temp0, fromParent, temp); // NU
23613021 //LA.xformPos(temp, bone.fromParent, temp);
23623022 // float[] data;
23633023
2364
- pos[0] = temp.x;
2365
- pos[1] = temp.y;
2366
- pos[2] = temp.z;
3024
+// pos[0] = temp.x;
3025
+// pos[1] = temp.y;
3026
+// pos[2] = temp.z;
3027
+//
3028
+// temp.x = 1;
3029
+// temp.y = 0;
3030
+// temp.z = 0;
3031
+//
3032
+// LA.xformDir(temp, bone.get(0).globalTransform, temp);
23673033
23683034 // CameraPane.selectedpoint.toParent[3][0] = temp0.x;
23693035 // CameraPane.selectedpoint.toParent[3][1] = temp0.y;
23703036 // CameraPane.selectedpoint.toParent[3][2] = temp0.z;
23713037
2372
- int numframes = bvh.animation.getNumFrames();
3038
+ int numframes = bvh.animation.getNumFrames();
23733039
23743040 int b = 0;
23753041 {
....@@ -2377,12 +3043,12 @@
23773043
23783044 int dof = 6; /// data.length/numframes;
23793045
2380
- // july 2014
2381
- if (dof != data.length/numframes)
2382
- {
2383
- System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));
2384
- dof = data.length/numframes;
2385
- }
3046
+ // july 2014
3047
+ if (dof != data.length/numframes)
3048
+ {
3049
+ System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));
3050
+ dof = data.length/numframes;
3051
+ }
23863052
23873053
23883054 int theframe = 0; // baseframe;
....@@ -2434,17 +3100,26 @@
24343100 // }
24353101 // }
24363102
2437
- data[f3 + i] += pos[i] - data[frame3 + i];
3103
+ data[f3 + i] += /*pos[i]*/ - data[frame3 + i];
24383104
24393105 // if (f < 3)
24403106 // {
24413107 // System.out.print(data[f3 + i] + " ");
24423108 // }
24433109 }
2444
-// if (f < 3)
2445
-// {
2446
-// System.out.println();
2447
-// }
3110
+
3111
+ double t1 = data[f3 + 0];
3112
+ double t2 = data[f3 + 2];
3113
+
3114
+ data[f3 + 0] = (float)(cosY*t1 - sinY*t2);
3115
+ data[f3 + 2] = (float)(sinY*t1 + cosY*t2);
3116
+
3117
+ for (int i=3/*dof*/; --i>=0;)
3118
+ {
3119
+ data[f3 + i] += pos[i];
3120
+ }
3121
+
3122
+ data[f3 + 4] += angleY - data[frame3 + 4];
24483123 }
24493124 }
24503125
....@@ -2458,186 +3133,17 @@
24583133 // temp.y = data[1];
24593134 // temp.z = data[2];
24603135
2461
- if (fade && currentbones != null && !CameraPane.fullreset)
2462
- {
2463
- Quat4d quatstart = new Quat4d();
2464
- Quat4d quatend = new Quat4d();
2465
- Quat4d quat = new Quat4d();
2466
- Matrix4d mat4d = new Matrix4d();
2467
- double[][] rot = new double[4][4];
2468
-
2469
- for (b=numbones; --b>=1;) // HIP ROTATION: 0;)
2470
- {
2471
- int hipindex = get(0)._index;
2472
-
2473
-// assert(get(0).get(0)._isHip);
2474
-
2475
- // if (b == hipindex)
2476
- // continue;
2477
-
2478
- data = bvh.animation.getBoneData(b);
2479
-
2480
- int dof = 3; // data.length/numframes;
2481
-
2482
- // assert(dof == 3);
2483
-
2484
- int boneframe3 = b*3; // dof;
2485
-
2486
- // System.err.println("Bone #" + b + ": dof = " + dof);
2487
- int fadein = 45; // 120;
2488
-
2489
- // if (b == hipindex)
2490
- // fadein *= 5;
2491
-
2492
- if (fadein > numframes)
2493
- fadein = 0; // numframes;
2494
-
2495
- for (int fi=fadein; --fi>=0;)
2496
- //for (int f=numframes; --f>=0;)
2497
- {
2498
- int f = fi + GetFirstFrame();
2499
-
2500
- int f3 = f*dof;
2501
-
2502
- float k = fi;
2503
-
2504
- k /= fadein - 1;
2505
-
2506
- if (Float.isNaN(k))
2507
- k = 1; // 0/0
2508
-
2509
- k = (float) (-Math.cos(k*Math.PI));
2510
- k += 1;
2511
- k /= 2;
2512
-
2513
- int start = 3;
2514
- int end = 0;
2515
-
2516
- if (dof == 6)
2517
- {
2518
- start = 6;
2519
- end = 3;
2520
- }
2521
-
2522
- if (b == 0)
2523
- {
2524
- _t1.setIdentity();
2525
- _t2.setIdentity();
2526
- _t2.rotZ(currentbones[boneframe3 + start-1-end]);
2527
- _t1.mul(_t2);
2528
- _t2.setIdentity();
2529
- if (b == 0)
2530
- {
2531
- _t2.rotY(currentbones[boneframe3 + start-2-end]);
2532
- _t1.mul(_t2);
2533
- _t2.setIdentity();
2534
- _t2.rotX(currentbones[boneframe3 + start-3-end]);
2535
- }
2536
- else
2537
- {
2538
- _t2.rotX(currentbones[boneframe3 + start-2-end]);
2539
- _t1.mul(_t2);
2540
- _t2.setIdentity();
2541
- _t2.rotY(currentbones[boneframe3 + start-3-end]);
2542
- }
2543
- _t1.mul(_t2);
2544
- _t2.setIdentity();
2545
-
2546
- _t1.get(mat4d);
2547
-
2548
- mat4d.get(quatstart);
2549
-
2550
- _t1.setIdentity();
2551
- _t2.setIdentity();
2552
- _t2.rotZ(data[f3 + start-1]);
2553
- _t1.mul(_t2);
2554
- _t2.setIdentity();
2555
- if (b == 0)
2556
- {
2557
- _t2.rotY(data[f3 + start-2]);
2558
- _t1.mul(_t2);
2559
- _t2.setIdentity();
2560
- _t2.rotX(data[f3 + start-3]);
2561
- }
2562
- else
2563
- {
2564
- _t2.rotX(data[f3 + start-2]);
2565
- _t1.mul(_t2);
2566
- _t2.setIdentity();
2567
- _t2.rotY(data[f3 + start-3]);
2568
- }
2569
-
2570
- _t1.mul(_t2);
2571
- _t2.setIdentity();
2572
-
2573
- _t1.get(mat4d);
2574
-
2575
- mat4d.get(quatend);
2576
-
2577
- double dot = quatstart.x*quatend.x +
2578
- quatstart.y*quatend.y +
2579
- quatstart.z*quatend.z +
2580
- quatstart.w*quatend.w
2581
- ;
2582
-
2583
- if (dot < 0)
2584
- {
2585
- quatend.x *= -1;
2586
- quatend.y *= -1;
2587
- quatend.z *= -1;
2588
- quatend.w *= -1;
2589
- }
2590
-
2591
- // k = 1-k;
2592
-
2593
- quat.x = (1-k)*quatstart.x + k*quatend.x;
2594
- quat.y = (1-k)*quatstart.y + k*quatend.y;
2595
- quat.z = (1-k)*quatstart.z + k*quatend.z;
2596
- quat.w = (1-k)*quatstart.w + k*quatend.w;
2597
-
2598
- quat.normalize();
2599
-
2600
- mat4d.set(quat);
2601
-
2602
- cJ3D.SetTransform(rot, mat4d);
2603
-
2604
- matrixToEulerXYZ(rot, temp);
2605
-
2606
- data[f3 + start-1] = -(float)temp.z;
2607
-
2608
- if (b == 0)
2609
- {
2610
- data[f3 + start-2] = -(float)temp.y;
2611
- data[f3 + start-3] = -(float)temp.x;
2612
- }
2613
- else
2614
- {
2615
- data[f3 + start-2] = -(float)temp.x;
2616
- data[f3 + start-3] = -(float)temp.y;
2617
- }
2618
- }
2619
- else
2620
- {
2621
- for (int i=start; --i>=end;)
2622
- {
2623
- //data[f3 + i] += pos[i] - data[frame3 + i];
2624
- // data[f3 + i] = k*data[f3+i] + (1-k)*
2625
- // currentbones[boneframe3 + i-end];
2626
- data[f3 + i] = (float)CurveAngle(data[f3+i], currentbones[boneframe3 + i-end], 1-k);
2627
- }
2628
- }
2629
-
2630
- }
2631
- }
2632
-
2633
- }
3136
+// if (fade && currentbones != null && !CameraPane.fullreset)
3137
+// {
3138
+// Fade();
3139
+// }
26343140 }
2635
-
3141
+
26363142 if (false) // doesn't change anything bone._isRoot)
26373143 {
26383144 // Reset orientation
26393145 _t2.setIdentity();
2640
-
3146
+
26413147 double tx = bone.toParent[3][0];
26423148 double ty = bone.toParent[3][1];
26433149 double tz = bone.toParent[3][2];
....@@ -2646,9 +3152,9 @@
26463152 temp.y = 0;
26473153 temp.z = 0;
26483154 LA.xformDir(temp, bone.toParent, temp);
2649
-
3155
+
26503156 double angle = Math.atan2(-temp.z, temp.x);
2651
-
3157
+
26523158 _t2.rotY(angle);
26533159 // _t1.setIdentity();
26543160 // _t1.rotX(temp.x);
....@@ -2661,56 +3167,21 @@
26613167 // _t1.setIdentity();
26623168 // _t1.rotZ(temp.z);
26633169 // _t2.mul(_t1);
2664
-
3170
+
26653171 cJ3D.ResetTransform(bone, _t2, false);
2666
-
3172
+
26673173 bone.toParent[3][0] = tx;
26683174 bone.toParent[3][1] = ty;
26693175 bone.toParent[3][2] = tz;
26703176 }
26713177 }
26723178
2673
- if (currentbones == null)
2674
- currentbones = new double[numbones*3];
2675
-
2676
- for (int b=numbones; --b>=1;) // 0;)
2677
- //int b = 0;
2678
- {
2679
- data = bvh.animation.getBoneData(b);
2680
-
2681
- int numframes = bvh.animation.getNumFrames();
2682
-
2683
- int dof = 6; // data.length/numframes;
2684
-
2685
- if (b > 0)
2686
- dof = 3;
2687
-
2688
- //assert(dof == 3);
2689
-
2690
- // System.err.println("Bone #" + b + ": dof = " + dof);
2691
- int theframe = // 1; // baseframe;
2692
- frame;
2693
-
2694
- int frame3 = theframe*dof;
2695
- int bone3 = b*3; // dof;
2696
-
2697
- int start = 3;
2698
- int end = 0;
2699
-
2700
- if (dof == 6)
2701
- {
2702
- start = 6;
2703
- end = 3;
2704
- }
2705
- for (int i=start; --i>=end;)
2706
- {
2707
- currentbones[bone3 + i-end] = data[frame3 + i];
2708
- }
2709
- }
3179
+ // SetCurrentBones(frame);
27103180 }
27113181 }
27123182
2713
- static int offset = 1; // 5; // 10; // 5; // 100; // skip initial "T"
3183
+ // skip initial "T"
3184
+ static int offset = 1; // 5; // 10; // 5; // 100;
27143185
27153186 void ReadBVH()
27163187 {
....@@ -2739,14 +3210,14 @@
27393210
27403211 void Reset()
27413212 {
2742
- if (fullname != null)
2743
- ReadBVH();
3213
+// if (fullname != null)
3214
+// ReadBVH();
27443215
27453216 Object3D hip = get(0);
27463217
27473218 // assert(obj.name.equals("hip"));
27483219
2749
- Object3D rot = hip.get(0);
3220
+ //Object3D rot = hip.get(0);
27503221
27513222 // assert(obj.name == null); // .equals("hip#"));
27523223
....@@ -2756,8 +3227,8 @@
27563227 hip.fromParent = LA.newMatrix();
27573228 }
27583229
2759
- hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;
2760
- hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;
3230
+ //hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;
3231
+ //hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;
27613232
27623233 if (toParent == null)
27633234 {
....@@ -2769,26 +3240,29 @@
27693240 LA.matIdentity(fromParent);
27703241 // LA.matIdentity(hip.toParent);
27713242 // LA.matIdentity(hip.fromParent);
2772
- if (rot.toParent == null)
2773
- {
2774
- // june 2014
2775
- rot.toParent = LA.newMatrix();
2776
- rot.fromParent = LA.newMatrix();
2777
- }
2778
- LA.matIdentity(rot.toParent);
2779
- LA.matIdentity(rot.fromParent);
3243
+// if (rot.toParent == null)
3244
+// {
3245
+// // june 2014
3246
+// rot.toParent = LA.newMatrix();
3247
+// rot.fromParent = LA.newMatrix();
3248
+// }
3249
+// LA.matIdentity(rot.toParent);
3250
+// LA.matIdentity(rot.fromParent);
27803251
27813252 // july 2014
2782
- goalx = goalz = 0;
2783
- targetx = targetz = 0;
3253
+// goalx = goalz = 0;
3254
+ targetdirx = targetdirz = 0;
27843255
2785
- SetPositionDelta(true, true, true, false);
3256
+ //SetPositionDelta(true, true, true, false);
3257
+// LoadData();
3258
+// Rewind();
27863259
27873260 baseframe = frame = 0; // T pose. No offset.
27883261
27893262 // aout 2013 endframe = 0; // june 2013
27903263
2791
- setPose(frame);
3264
+ ResetZero();
3265
+ //setPose(frame);
27923266 }
27933267
27943268 static int mocapsupport = 0;
....@@ -2806,12 +3280,13 @@
28063280
28073281 int step = 1;
28083282
3283
+ // patch for running hare
28093284 if (speedup) // fev 2014
28103285 step *= 2; // 4;
28113286 if (rewind) // mars 2014
28123287 step *= 4;
28133288
2814
- if (CameraPane.FAST) // && !CameraPane.HOLD)
3289
+ //if (CameraPane.FAST) // && !CameraPane.HOLD)
28153290 step *= CameraPane.STEP;
28163291
28173292 //System.err.println("Step Mocap frame # " + frame);
....@@ -2819,7 +3294,7 @@
28193294 baseframe += step;
28203295
28213296 //frame = baseframe;
2822
- frame += step;
3297
+ //frame += step;
28233298
28243299 // if (frame != baseframe)
28253300 // {
....@@ -2833,6 +3308,7 @@
28333308 if (lastframetest == 0)
28343309 lastframetest = bvh.animation.getNumFrames();
28353310
3311
+ // WARNING: RESET DESTROYS EVERYTHING
28363312 if (baseframe >= lastframetest) // july 2013 // - GetFirstFrame())
28373313 {
28383314 System.out.println("MOCAP reset: " + this.GetFileRoot() +
....@@ -2842,7 +3318,7 @@
28423318 "; fullname = " + fullname);
28433319
28443320 //int delta = frame - baseframe;
2845
- if (CameraPane.CROWD)
3321
+ if (Globals.CROWD)
28463322 {
28473323 baseframe = GetFirstFrame(); // 0 initial point
28483324 }
....@@ -2851,29 +3327,53 @@
28513327 // SetPositionDelta(false, true, false); // ?? false);
28523328 {
28533329 if (support == null)
2854
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
2855
- else
28563330 {
2857
- try
3331
+ if (bvh == null && new File(fullname).exists())
3332
+ ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3333
+ else
28583334 {
2859
- bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
2860
-
2861
- SetPositionDelta(false, true, true, true);
2862
- }
2863
- catch (Exception e)
2864
- {
2865
- e.printStackTrace();
2866
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3335
+ SetGlobalTransform();
3336
+ Rewind();
3337
+ Fade();
28673338 }
28683339 }
3340
+ else
3341
+ {
3342
+// try
3343
+// {
3344
+ bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
3345
+
3346
+ // SetPositionDelta(false, true, true, true);
3347
+ LoadData();
3348
+ Rewind();
3349
+ Fade();
3350
+// }
3351
+// catch (Exception e)
3352
+// {
3353
+// System.err.println("An error occured while loading data. Use fallback by loading the file.");
3354
+// //e.printStackTrace();
3355
+// try
3356
+// {
3357
+// ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3358
+// }
3359
+// catch (Exception e2)
3360
+// {
3361
+// System.err.println("Motion file not found: " + fullname);
3362
+// }
3363
+// }
3364
+ }
28693365 }
3366
+
3367
+ frame = GetFirstFrame();
28703368 }
3369
+ else
3370
+ frame += step;
28713371
28723372 //SetPositionDelta(false);
28733373
2874
- if (frame >= bvh.animation.getNumFrames())
2875
- //baseframe =
2876
- frame = GetFirstFrame(); // 0; // offset; // initial point
3374
+// if (frame >= bvh.animation.getNumFrames())
3375
+// //baseframe =
3376
+// frame = GetFirstFrame(); // 0; // offset; // initial point
28773377
28783378 //System.err.println("frame = " + frame);
28793379 if (lastframe != 0)
....@@ -3042,6 +3542,7 @@
30423542 // filters out bad input data
30433543 void FilterAnimData()
30443544 {
3545
+ new Exception().printStackTrace();
30453546 System.exit(0);
30463547
30473548 float[] data; // = bvh.animation.getBoneData(0);
....@@ -3171,6 +3672,8 @@
31713672 //static
31723673 transient
31733674 double[] currentbones;
3675
+ double[] currenthip;
3676
+
31743677 transient boolean inbetween;
31753678
31763679 void SetPositionDelta(boolean reset, boolean rewind, boolean load, boolean fade)
....@@ -3181,38 +3684,9 @@
31813684 //assert(dim == numframes*6);
31823685
31833686 if (load)
3184
- for (int b=numbones; --b>=0;)
3185
- //int b = 0;
3186
- {
3187
- float[] thedata = bvh.animation.getBoneData(b);
3188
-
3189
- int numframes = bvh.animation.getNumFrames();
3190
-
3191
- int dof = 6; // thedata.length/numframes;
3192
-
3193
- if (b > 0)
3194
- dof = 3;
3195
-
3196
- if (dof != thedata.length/numframes)
3197
- {
3198
- System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (thedata.length/numframes));
3199
- dof = thedata.length/numframes;
3200
- }
3201
-
3202
- //for (int f=numframes; --f>=offset;)
3203
- int firstframe = GetFirstFrame();
3204
- for (int f=0; f<numframes-firstframe; f++)
3205
- {
3206
- int f3 = f*dof;
3207
-
3208
- //for (int i=3/*dof*/; --i>=0;)
3209
- for (int i=dof; --i>=0;)
3210
- {
3211
- //thedata[f3 + i] += thedata[i] - thedata[offset*dof + i];
3212
- thedata[f3 + i] = thedata[f3 + firstframe*dof + i];
3213
- }
3214
- }
3215
- }
3687
+ {
3688
+ LoadData();
3689
+ }
32163690
32173691 // assert(thedata[0] == 0);
32183692 // assert(thedata[1] == 0);
....@@ -3222,11 +3696,11 @@
32223696 // assert(thedata[7] == 0);
32233697 // assert(thedata[8] == 0);
32243698
3225
- Object3D obj = get(0);
3699
+ Object3D hip = get(0);
32263700
32273701 // assert(obj.name.equals("hip"));
32283702
3229
- Object3D rot = obj.get(0);
3703
+ Object3D rot = hip.get(0);
32303704
32313705 // if (toParent == null)
32323706 // {
....@@ -3238,7 +3712,7 @@
32383712 // // assert(obj.name == null); // .equals("hip#"));
32393713
32403714 Invariants();
3241
- obj.Invariants();
3715
+ hip.Invariants();
32423716 rot.Invariants();
32433717
32443718 if (origin == null)
....@@ -3259,16 +3733,16 @@
32593733 fromParent = LA.newMatrix();
32603734 }
32613735
3262
- if (obj.toParent == null) // june 2014
3736
+ if (hip.toParent == null) // june 2014
32633737 {
3264
- obj.toParent = LA.newMatrix();
3265
- obj.fromParent = LA.newMatrix();
3738
+ hip.toParent = LA.newMatrix();
3739
+ hip.fromParent = LA.newMatrix();
32663740 }
32673741
3268
- LA.matConcat(toParent, obj.toParent, origin0.toParent); // AB
3742
+ LA.matConcat(toParent, hip.toParent, origin0.toParent); // AB
32693743 Object3D gp = this.parent;
32703744 this.parent = null;
3271
- obj.GlobalTransformInv();
3745
+ hip.GlobalTransformInv();
32723746 this.parent = gp;
32733747
32743748 if (rot.toParent == null)
....@@ -3291,41 +3765,41 @@
32913765 LA.matInvert(origin.toParent, origin.fromParent);
32923766
32933767 Invariants();
3294
- obj.Invariants();
3768
+ hip.Invariants();
32953769 rot.Invariants();
32963770 origin.Invariants();
32973771 origin0.Invariants();
32983772
3299
- firsttimeafterload = true;
3773
+ firsttimeafterload = false; // true;
33003774
33013775 if (rewind)
33023776 Rewind();
33033777
3304
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), fade);
3778
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); //, fade);
33053779
3306
- if (true)
3307
- return;
3780
+ if (true)
3781
+ return;
33083782
33093783 double pos[] = new double[6];
33103784
33113785 if (!reset)
33123786 {
3313
- assert(obj.tx == obj.toParent[3][0]);
3314
- assert(obj.ty == obj.toParent[3][1]);
3315
- assert(obj.tz == obj.toParent[3][2]);
3787
+ assert(hip.tx == hip.toParent[3][0]);
3788
+ assert(hip.ty == hip.toParent[3][1]);
3789
+ assert(hip.tz == hip.toParent[3][2]);
33163790
3317
- pos[0] = obj.tx; // obj.toParent[3][0];
3318
- pos[1] = obj.ty; // obj.toParent[3][1];
3319
- pos[2] = obj.tz; // obj.toParent[3][2];
3320
- pos[3] = obj.rz;
3321
- pos[4] = obj.ry;
3322
- pos[5] = obj.rx;
3791
+ pos[0] = hip.tx; // obj.toParent[3][0];
3792
+ pos[1] = hip.ty; // obj.toParent[3][1];
3793
+ pos[2] = hip.tz; // obj.toParent[3][2];
3794
+ pos[3] = hip.rz;
3795
+ pos[4] = hip.ry;
3796
+ pos[5] = hip.rx;
33233797 }
33243798
33253799 cVector temp = new cVector();
3326
- temp.x = obj.globalTransform[3][0];
3327
- temp.y = obj.globalTransform[3][1];
3328
- temp.z = obj.globalTransform[3][2];
3800
+ temp.x = hip.globalTransform[3][0];
3801
+ temp.y = hip.globalTransform[3][1];
3802
+ temp.z = hip.globalTransform[3][2];
33293803 // LA.xformPos(temp, origin0.toParent, temp);
33303804 // System.err.println("POS0 = " + temp.x + ", " + temp.y + ", " + temp.z + ";");
33313805
....@@ -3409,7 +3883,7 @@
34093883 }
34103884
34113885 // Rewind();
3412
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), true);
3886
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); // , true);
34133887 }
34143888
34153889 void Rewind()
....@@ -3426,7 +3900,7 @@
34263900
34273901 transient boolean restarted; // CROWD issue?
34283902
3429
- void drawSelf(CameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
3903
+ void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
34303904 {
34313905 //System.err.println("drawSelf Mocap frame # " + frame);
34323906 //System.err.println("drawSelf Mocap baseframe # " + baseframe);
....@@ -3443,17 +3917,24 @@
34433917 // if (firstframe)
34443918 // return;
34453919
3446
- if (!restarted && /*display.restartframe &&*/
3447
- display.isLIVE() && live && display.drawMode == display.SHADOW) // FUCK
3920
+ if (//!restarted && /*display.restartframe &&*/
3921
+ Globals.isLIVE() && live && (display.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || !Globals.COMPUTESHADOWWHENLIVE))
34483922 {
34493923 //display.restartframe = false;
34503924 restarted = true;
3925
+ //System.err.println("restarted = true");
34513926 Step();
3927
+
3928
+ Globals.lighttouched = true;
34523929 }
34533930 else
34543931 {
3455
- if (display.isLIVE() && live && display.drawMode != display.SHADOW)
3932
+ //System.err.println("restarted");
3933
+ if (Globals.isLIVE() && live && display.DrawMode() != iCameraPane.SHADOW)
3934
+ {
34563935 restarted = false;
3936
+ //System.err.println("restarted = false");
3937
+ }
34573938 }
34583939
34593940 super.drawSelf(display, root, selected, blocked);
....@@ -3513,6 +3994,11 @@
35133994 // GetObject().release(i);
35143995 }
35153996
3997
+ boolean HasBigData()
3998
+ {
3999
+ return skeleton != null;
4000
+ }
4001
+
35164002 public Object3D get(int i)
35174003 {
35184004 if (i != 0)