Normand Briere
2019-10-06 ce660a4b6ba367bd162dd2cff26d02c80a34c912
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
- GrafreeD.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 {
....@@ -939,9 +1533,9 @@
9391533 groundid = floorid;
9401534
9411535 // green
942
- CameraPane.debugpoint.toParent[3][0] = groundx;
943
- CameraPane.debugpoint.toParent[3][1] = floor.y;
944
- CameraPane.debugpoint.toParent[3][2] = groundz;
1536
+ CameraPane.debugpointG.toParent[3][0] = groundx;
1537
+ CameraPane.debugpointG.toParent[3][1] = floor.y;
1538
+ CameraPane.debugpointG.toParent[3][2] = groundz;
9451539
9461540 if (true) // slow && stepout && onein)
9471541 {
....@@ -952,7 +1546,7 @@
9521546 // mywave = currentwave++;
9531547 // }
9541548 // sound
955
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
1549
+ cVector eye = Globals.theRenderer.EyeCamera().location;
9561550
9571551 // if (sourcenode.parent.parent != null)
9581552 // sourcenode.parent.parent.TransformToWorld(floor, tmp);
....@@ -997,9 +1591,9 @@
9971591 //GraphreeD.
9981592 wav.play(volume * usedvolume); //, mywave);
9991593
1000
- lastsoundtime = CameraPane.framecount;
1594
+ lastsoundtime = Globals.framecount;
10011595
1002
- GrafreeD.hassound = true;
1596
+ Grafreed.hassound = true;
10031597 }
10041598 // else
10051599 // System.out.println("skipped");
....@@ -1018,9 +1612,9 @@
10181612
10191613 // System.out.println("Allo " + sourcenode);
10201614 // 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;
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;
10241618
10251619
10261620 if (false) // dist2 > 0.1)
....@@ -1047,7 +1641,7 @@
10471641 // sourcenode.parent.toParent[3][1] = ground - floor.y;
10481642 // sourcenode.parent.toParent[3][2] += groundz - floor.z;
10491643 // sourcenode.parent.toParent[3][1] = K * (ground - floor.y) + (1 - K) * oldposy;
1050
- 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
10511645 {
10521646 v0.x = groundx - floor.x;
10531647 v0.y = 0; // groundx - floor.x;
....@@ -1086,9 +1680,9 @@
10861680 this.get(0).TransformToWorld(v0);
10871681
10881682 // cyan
1089
- CameraPane.debugpoint3.toParent[3][0] = v0.x;
1090
- CameraPane.debugpoint3.toParent[3][1] = ground;
1091
- CameraPane.debugpoint3.toParent[3][2] = v0.z;
1683
+ CameraPane.debugpointC.toParent[3][0] = v0.x;
1684
+ CameraPane.debugpointC.toParent[3][1] = ground;
1685
+ CameraPane.debugpointC.toParent[3][2] = v0.z;
10921686
10931687 LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent);
10941688 LA.matInvert(sourcenode.toParent, sourcenode.fromParent);
....@@ -1098,9 +1692,9 @@
10981692 this.get(0).TransformToWorld(v0);
10991693
11001694 // red
1101
- CameraPane.debugpoint4.toParent[3][0] = v0.x;
1102
- CameraPane.debugpoint4.toParent[3][1] = ground;
1103
- CameraPane.debugpoint4.toParent[3][2] = v0.z;
1695
+ CameraPane.debugpointR.toParent[3][0] = v0.x;
1696
+ CameraPane.debugpointR.toParent[3][1] = ground;
1697
+ CameraPane.debugpointR.toParent[3][2] = v0.z;
11041698 }
11051699 }
11061700
....@@ -1140,11 +1734,11 @@
11401734
11411735 if (goal != null)
11421736 {
1143
- System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")");
1737
+ System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
11441738 //sourcenode.parent.parent.Dump();
1145
- goalx = goal.x;
1146
- goalz = goal.z;
1147
- targetx = targetz = 0;
1739
+ goalposx = goal.x;
1740
+ goalposz = goal.z;
1741
+ targetdirx = targetdirz = 0;
11481742
11491743 followpath = true;
11501744 }
....@@ -1195,16 +1789,16 @@
11951789 // }
11961790 if (false) // !uselast)
11971791 {
1198
- CameraPane.debugpoint.toParent[3][0] = dst.x;
1199
- CameraPane.debugpoint.toParent[3][1] = dst.y;
1200
- 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;
12011795 }
12021796 }
12031797
1204
- if (goalx != 0 || goalz != 0) // TODO
1798
+ if (goalposx != 0 || goalposz != 0) // TODO
12051799 {
12061800 // overwrite speaker orientation
1207
- dst.set(goalx,0,goalz);
1801
+ dst.set(goalposx,0,goalposz);
12081802 if (sourcenode.parent != null) // july 2014
12091803 sourcenode.parent.
12101804 TransformToLocal(dst);
....@@ -1220,6 +1814,7 @@
12201814 src.x = 0;
12211815 src.y = 0;
12221816 src.z = 0;
1817
+ LA.xformPos(src, get(0).get(0).toParent, src);
12231818 LA.xformPos(src, get(0).toParent, src);
12241819 LA.xformPos(src, toParent, src);
12251820 // LA.xformPos(src, rotsourcenode.toParent, src);
....@@ -1255,26 +1850,26 @@
12551850 // mars 2014
12561851 if (false) // goalx != 0 || goalz != 0)
12571852 {
1258
- targetx = dst.x - src.x;
1259
- targetz = dst.z - src.z;
1853
+ targetdirx = dst.x - src.x;
1854
+ targetdirz = dst.z - src.z;
12601855
1261
- if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1)
1856
+ if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1)
12621857 {
12631858 // far enough from goal. keep the goal position.
1264
- targetx = 0;
1265
- targetz = 0;
1859
+ targetdirx = 0;
1860
+ targetdirz = 0;
12661861 }
12671862 else
12681863 {
12691864 // too close to goal. switch to target direction instead.
1270
- goalx = 0;
1271
- goalz = 0;
1865
+ goalposx = 0;
1866
+ goalposz = 0;
12721867 }
12731868 }
12741869
12751870 //sourcenode.getCentroid(src, true);
12761871
1277
- if (speakernode == sourcenode && goalx == 0 && goalz == 0)
1872
+ if (speakernode == sourcenode && goalposx == 0 && goalposz == 0)
12781873 {
12791874 if (ScriptNode.lastspeaker != null)
12801875 new Exception().printStackTrace();
....@@ -1283,13 +1878,13 @@
12831878
12841879 // LA.xformPos(src, fromParent, src);
12851880
1286
- 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)
12871882 dst.sub(src);
12881883 else
12891884 // vector mode
12901885 {
1291
- dst.x = targetx;
1292
- dst.z = targetz;
1886
+ dst.x = targetdirx;
1887
+ dst.z = targetdirz;
12931888
12941889 // TEST TARGET
12951890 // dst.x = CameraPane.selectedpoint.toParent[3][0];
....@@ -1411,7 +2006,7 @@
14112006 // if (sourcenode.link2master)
14122007 // if (goalx != 0 || goalz != 0)
14132008 // K = 0.02; // .0625;
1414
- if (parent.link2master) // strong pin on floor
2009
+ if (parent.Link2Support()) // strong pin on floor
14152010 {
14162011 K = 0.05; // 0.02;
14172012 }
....@@ -1563,6 +2158,7 @@
15632158 toParent = LA.newMatrix();
15642159 fromParent = LA.newMatrix();
15652160 }
2161
+
15662162 LA.matConcat(toParent, rotsourcenode.toParent, toParent);
15672163 LA.matInvert(toParent, fromParent);
15682164
....@@ -1698,7 +2294,7 @@
16982294 }
16992295
17002296 if (!smoothed)
1701
- for (int i=4; --i>=0;)
2297
+ for (int i=10; --i>=0;)
17022298 SmoothAnimData(); // much reduces shakiness
17032299
17042300 smoothed = true;
....@@ -1736,9 +2332,16 @@
17362332 toVector.x = LA.cos(to);
17372333 toVector.y = LA.sin(to);
17382334
2335
+ double fromA = Math.atan2(fromVector.y, fromVector.x);
2336
+ double toA = Math.atan2(toVector.y, toVector.x);
2337
+
17392338 Vector2d currentVector = Slerp(fromVector, toVector, step);
17402339
1741
- 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;
17422345 }
17432346
17442347 public static Vector2d Slerp(Vector2d from, Vector2d to, double step)
....@@ -1780,12 +2383,28 @@
17802383 if (!live) // aout 2013
17812384 return;
17822385
1783
- cVector centroid = new cVector();
1784
- cVector floor = new cVector();
1785
-
1786
- 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
+ }
17872396
1788
- 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);
17892408 // if (!success)
17902409 // {
17912410 // //assert(success);
....@@ -1793,16 +2412,6 @@
17932412 // System.out.println("No centroid for " + sourcenode);
17942413 // }
17952414
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
-
18062415 if (sourcenode.parent == null && sourcenode.fileparent == null)
18072416 {
18082417 // No GFD
....@@ -1814,9 +2423,9 @@
18142423 // SetBreakPoint(get(0).toParent[0], 0);
18152424 // }
18162425
1817
- boolean setrotation = get(0).link2master && !firsttimeafterload && frame > 0;
2426
+ boolean setrotation = get(0).Link2Support() && !firsttimeafterload && frame > 0;
18182427 boolean setposition = sourcenode != null && // sourcenode.parent != null && // july 2014
1819
- sourcenode./*parent.*/link2master && !firsttimeafterload && frame > 0;
2428
+ sourcenode./*parent.*/Link2Support() && !firsttimeafterload && frame > 0;
18202429
18212430 // cVector centroid = new cVector();
18222431 // cVector floor = new cVector();
....@@ -2050,7 +2659,7 @@
20502659 * @param frame
20512660 * Frame number
20522661 */
2053
- 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)
20542663 {
20552664 if (!live) // aout 2013
20562665 return;
....@@ -2058,6 +2667,33 @@
20582667 cVector temp = new cVector();
20592668 cVector temp0 = new cVector();
20602669 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
+ }
20612697
20622698 // Object3D obj = get(0);
20632699 // Object3D gp = this.parent;
....@@ -2189,13 +2825,14 @@
21892825 if (//frame > 0 &&
21902826 !bone.skipmocap &&
21912827 !bone.name.contains("head") &&
2828
+ !bone.name.contains("Head") // &&
21922829 // !bone.name.contains("rFoot") &&
21932830 // !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")
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")
21992836 )
22002837 {
22012838 //_rotTG.setTransform(_t1);
....@@ -2221,22 +2858,24 @@
22212858
22222859 // set translation
22232860 // (currently only possible for root bone! see mocapdata.com data)
2224
- if (bone._isRoot && link2master) // && !GetFileRoot().link2master)
2861
+ if (bone._isRoot && Link2Support()) // && !GetFileRoot().link2master)
22252862 {
22262863 if (hasTranslation) // && _translationEnabled)
22272864 {
22282865 // CROWD
22292866 //cJ3D.GetTranslation(bone, _trans0);
22302867 //_trans.add(_trans0);
2231
- _transTF.setIdentity();
2868
+ //_transTF.setIdentity();
2869
+ _transTF.set(_t1);
22322870 _transTF.setTranslation(_trans);
22332871 // System.err.println("Translate: " + _transTF);
22342872 //_transTG.setTransform(_transTF);
2235
- 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
22362875 }
22372876 }
22382877
2239
- if (bone._isRoot && firsttimeafterload && frame > 0)
2878
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
22402879 {
22412880 assert(bone == get(0));
22422881
....@@ -2252,17 +2891,17 @@
22522891 // LA.matConcat(originmatrixinv, tempmatrixinv, fromParent); // ABC * (B'*C')^-1
22532892 //
22542893
2255
- Invariants();
2256
- bone.Invariants();
2257
- bone.get(0).Invariants();
2258
- // if (origin == null)
2259
- // origin = null;
2260
- origin.Invariants();
2261
- 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();
22622901
2263
-
2264
- LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2265
- 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);
22662905
22672906 // matrixToEulerXYZ(toParent, temp);
22682907 // matrixToEulerXYZ(bone.get(0).toParent, temp);
....@@ -2296,7 +2935,7 @@
22962935 //
22972936 // mat4d.get(quat);
22982937
2299
- if (true) // hip correction
2938
+ if (false) // hip correction
23002939 {
23012940 _t2.setIdentity();
23022941
....@@ -2337,13 +2976,13 @@
23372976 //????? LA.matConcat(bone.get(0).toParent, bone.toParent, tempmatrix); // B' * C'
23382977 // LA.matConcat(origin.fromParent, tempmatrix, fromParent);
23392978
2340
- LA.matInvert(toParent, fromParent);
2979
+//?? LA.matInvert(toParent, fromParent);
23412980
2342
- Invariants();
2343
- bone.Invariants();
2344
- bone.get(0).Invariants();
2345
- origin.Invariants();
2346
- origin0.Invariants();
2981
+ Invariants();
2982
+ bone.Invariants();
2983
+ bone.get(0).Invariants();
2984
+ origin.Invariants();
2985
+ origin0.Invariants();
23472986
23482987 // LA.matInvert(fromParent, tempmatrix);
23492988 //
....@@ -2364,33 +3003,39 @@
23643003 // temp.x = data[0];
23653004 // temp.y = data[1];
23663005 // temp.z = data[2];
2367
- LA.xformPos(temp, origin0.toParent, temp0);
3006
+ LA.xformPos(temp, origin0.toParent, temp0); // NU
23683007
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
-
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
+//
23753014 // 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);
3015
+//fromParent[3][0] = 0;
3016
+//fromParent[3][1] = 0;
3017
+//fromParent[3][2] = 0;
3018
+//LA.matInvert(fromParent, toParent);
23803019
2381
- LA.xformPos(temp0, fromParent, temp);
3020
+ LA.xformPos(temp0, fromParent, temp); // NU
23823021 //LA.xformPos(temp, bone.fromParent, temp);
23833022 // float[] data;
23843023
2385
- pos[0] = temp.x;
2386
- pos[1] = temp.y;
2387
- 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);
23883033
23893034 // CameraPane.selectedpoint.toParent[3][0] = temp0.x;
23903035 // CameraPane.selectedpoint.toParent[3][1] = temp0.y;
23913036 // CameraPane.selectedpoint.toParent[3][2] = temp0.z;
23923037
2393
- int numframes = bvh.animation.getNumFrames();
3038
+ int numframes = bvh.animation.getNumFrames();
23943039
23953040 int b = 0;
23963041 {
....@@ -2398,12 +3043,12 @@
23983043
23993044 int dof = 6; /// data.length/numframes;
24003045
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
- }
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
+ }
24073052
24083053
24093054 int theframe = 0; // baseframe;
....@@ -2455,17 +3100,26 @@
24553100 // }
24563101 // }
24573102
2458
- data[f3 + i] += pos[i] - data[frame3 + i];
3103
+ data[f3 + i] += /*pos[i]*/ - data[frame3 + i];
24593104
24603105 // if (f < 3)
24613106 // {
24623107 // System.out.print(data[f3 + i] + " ");
24633108 // }
24643109 }
2465
-// if (f < 3)
2466
-// {
2467
-// System.out.println();
2468
-// }
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];
24693123 }
24703124 }
24713125
....@@ -2479,186 +3133,17 @@
24793133 // temp.y = data[1];
24803134 // temp.z = data[2];
24813135
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
- }
3136
+// if (fade && currentbones != null && !CameraPane.fullreset)
3137
+// {
3138
+// Fade();
3139
+// }
26553140 }
2656
-
3141
+
26573142 if (false) // doesn't change anything bone._isRoot)
26583143 {
26593144 // Reset orientation
26603145 _t2.setIdentity();
2661
-
3146
+
26623147 double tx = bone.toParent[3][0];
26633148 double ty = bone.toParent[3][1];
26643149 double tz = bone.toParent[3][2];
....@@ -2667,9 +3152,9 @@
26673152 temp.y = 0;
26683153 temp.z = 0;
26693154 LA.xformDir(temp, bone.toParent, temp);
2670
-
3155
+
26713156 double angle = Math.atan2(-temp.z, temp.x);
2672
-
3157
+
26733158 _t2.rotY(angle);
26743159 // _t1.setIdentity();
26753160 // _t1.rotX(temp.x);
....@@ -2682,56 +3167,21 @@
26823167 // _t1.setIdentity();
26833168 // _t1.rotZ(temp.z);
26843169 // _t2.mul(_t1);
2685
-
3170
+
26863171 cJ3D.ResetTransform(bone, _t2, false);
2687
-
3172
+
26883173 bone.toParent[3][0] = tx;
26893174 bone.toParent[3][1] = ty;
26903175 bone.toParent[3][2] = tz;
26913176 }
26923177 }
26933178
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
- }
3179
+ // SetCurrentBones(frame);
27313180 }
27323181 }
27333182
2734
- static int offset = 1; // 5; // 10; // 5; // 100; // skip initial "T"
3183
+ // skip initial "T"
3184
+ static int offset = 1; // 5; // 10; // 5; // 100;
27353185
27363186 void ReadBVH()
27373187 {
....@@ -2760,14 +3210,14 @@
27603210
27613211 void Reset()
27623212 {
2763
- if (fullname != null)
2764
- ReadBVH();
3213
+// if (fullname != null)
3214
+// ReadBVH();
27653215
27663216 Object3D hip = get(0);
27673217
27683218 // assert(obj.name.equals("hip"));
27693219
2770
- Object3D rot = hip.get(0);
3220
+ //Object3D rot = hip.get(0);
27713221
27723222 // assert(obj.name == null); // .equals("hip#"));
27733223
....@@ -2777,8 +3227,8 @@
27773227 hip.fromParent = LA.newMatrix();
27783228 }
27793229
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;
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;
27823232
27833233 if (toParent == null)
27843234 {
....@@ -2790,26 +3240,29 @@
27903240 LA.matIdentity(fromParent);
27913241 // LA.matIdentity(hip.toParent);
27923242 // 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);
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);
28013251
28023252 // july 2014
2803
- goalx = goalz = 0;
2804
- targetx = targetz = 0;
3253
+// goalx = goalz = 0;
3254
+ targetdirx = targetdirz = 0;
28053255
2806
- SetPositionDelta(true, true, true, false);
3256
+ //SetPositionDelta(true, true, true, false);
3257
+// LoadData();
3258
+// Rewind();
28073259
28083260 baseframe = frame = 0; // T pose. No offset.
28093261
28103262 // aout 2013 endframe = 0; // june 2013
28113263
2812
- setPose(frame);
3264
+ ResetZero();
3265
+ //setPose(frame);
28133266 }
28143267
28153268 static int mocapsupport = 0;
....@@ -2827,12 +3280,13 @@
28273280
28283281 int step = 1;
28293282
3283
+ // patch for running hare
28303284 if (speedup) // fev 2014
28313285 step *= 2; // 4;
28323286 if (rewind) // mars 2014
28333287 step *= 4;
28343288
2835
- if (CameraPane.FAST) // && !CameraPane.HOLD)
3289
+ //if (CameraPane.FAST) // && !CameraPane.HOLD)
28363290 step *= CameraPane.STEP;
28373291
28383292 //System.err.println("Step Mocap frame # " + frame);
....@@ -2840,7 +3294,7 @@
28403294 baseframe += step;
28413295
28423296 //frame = baseframe;
2843
- frame += step;
3297
+ //frame += step;
28443298
28453299 // if (frame != baseframe)
28463300 // {
....@@ -2854,6 +3308,7 @@
28543308 if (lastframetest == 0)
28553309 lastframetest = bvh.animation.getNumFrames();
28563310
3311
+ // WARNING: RESET DESTROYS EVERYTHING
28573312 if (baseframe >= lastframetest) // july 2013 // - GetFirstFrame())
28583313 {
28593314 System.out.println("MOCAP reset: " + this.GetFileRoot() +
....@@ -2863,7 +3318,7 @@
28633318 "; fullname = " + fullname);
28643319
28653320 //int delta = frame - baseframe;
2866
- if (CameraPane.CROWD)
3321
+ if (Globals.CROWD)
28673322 {
28683323 baseframe = GetFirstFrame(); // 0 initial point
28693324 }
....@@ -2872,29 +3327,53 @@
28723327 // SetPositionDelta(false, true, false); // ?? false);
28733328 {
28743329 if (support == null)
2875
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
2876
- else
28773330 {
2878
- try
3331
+ if (bvh == null && new File(fullname).exists())
3332
+ ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3333
+ else
28793334 {
2880
- bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
2881
-
2882
- SetPositionDelta(false, true, true, true);
2883
- }
2884
- catch (Exception e)
2885
- {
2886
- e.printStackTrace();
2887
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3335
+ SetGlobalTransform();
3336
+ Rewind();
3337
+ Fade();
28883338 }
28893339 }
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
+ }
28903365 }
3366
+
3367
+ frame = GetFirstFrame();
28913368 }
3369
+ else
3370
+ frame += step;
28923371
28933372 //SetPositionDelta(false);
28943373
2895
- if (frame >= bvh.animation.getNumFrames())
2896
- //baseframe =
2897
- frame = GetFirstFrame(); // 0; // offset; // initial point
3374
+// if (frame >= bvh.animation.getNumFrames())
3375
+// //baseframe =
3376
+// frame = GetFirstFrame(); // 0; // offset; // initial point
28983377
28993378 //System.err.println("frame = " + frame);
29003379 if (lastframe != 0)
....@@ -3063,6 +3542,7 @@
30633542 // filters out bad input data
30643543 void FilterAnimData()
30653544 {
3545
+ new Exception().printStackTrace();
30663546 System.exit(0);
30673547
30683548 float[] data; // = bvh.animation.getBoneData(0);
....@@ -3192,6 +3672,8 @@
31923672 //static
31933673 transient
31943674 double[] currentbones;
3675
+ double[] currenthip;
3676
+
31953677 transient boolean inbetween;
31963678
31973679 void SetPositionDelta(boolean reset, boolean rewind, boolean load, boolean fade)
....@@ -3202,38 +3684,9 @@
32023684 //assert(dim == numframes*6);
32033685
32043686 if (load)
3205
- for (int b=numbones; --b>=0;)
3206
- //int b = 0;
3207
- {
3208
- float[] thedata = bvh.animation.getBoneData(b);
3209
-
3210
- int numframes = bvh.animation.getNumFrames();
3211
-
3212
- int dof = 6; // thedata.length/numframes;
3213
-
3214
- if (b > 0)
3215
- dof = 3;
3216
-
3217
- if (dof != thedata.length/numframes)
3218
- {
3219
- System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (thedata.length/numframes));
3220
- dof = thedata.length/numframes;
3221
- }
3222
-
3223
- //for (int f=numframes; --f>=offset;)
3224
- int firstframe = GetFirstFrame();
3225
- for (int f=0; f<numframes-firstframe; f++)
3226
- {
3227
- int f3 = f*dof;
3228
-
3229
- //for (int i=3/*dof*/; --i>=0;)
3230
- for (int i=dof; --i>=0;)
3231
- {
3232
- //thedata[f3 + i] += thedata[i] - thedata[offset*dof + i];
3233
- thedata[f3 + i] = thedata[f3 + firstframe*dof + i];
3234
- }
3235
- }
3236
- }
3687
+ {
3688
+ LoadData();
3689
+ }
32373690
32383691 // assert(thedata[0] == 0);
32393692 // assert(thedata[1] == 0);
....@@ -3243,11 +3696,11 @@
32433696 // assert(thedata[7] == 0);
32443697 // assert(thedata[8] == 0);
32453698
3246
- Object3D obj = get(0);
3699
+ Object3D hip = get(0);
32473700
32483701 // assert(obj.name.equals("hip"));
32493702
3250
- Object3D rot = obj.get(0);
3703
+ Object3D rot = hip.get(0);
32513704
32523705 // if (toParent == null)
32533706 // {
....@@ -3259,7 +3712,7 @@
32593712 // // assert(obj.name == null); // .equals("hip#"));
32603713
32613714 Invariants();
3262
- obj.Invariants();
3715
+ hip.Invariants();
32633716 rot.Invariants();
32643717
32653718 if (origin == null)
....@@ -3280,16 +3733,16 @@
32803733 fromParent = LA.newMatrix();
32813734 }
32823735
3283
- if (obj.toParent == null) // june 2014
3736
+ if (hip.toParent == null) // june 2014
32843737 {
3285
- obj.toParent = LA.newMatrix();
3286
- obj.fromParent = LA.newMatrix();
3738
+ hip.toParent = LA.newMatrix();
3739
+ hip.fromParent = LA.newMatrix();
32873740 }
32883741
3289
- LA.matConcat(toParent, obj.toParent, origin0.toParent); // AB
3742
+ LA.matConcat(toParent, hip.toParent, origin0.toParent); // AB
32903743 Object3D gp = this.parent;
32913744 this.parent = null;
3292
- obj.GlobalTransformInv();
3745
+ hip.GlobalTransformInv();
32933746 this.parent = gp;
32943747
32953748 if (rot.toParent == null)
....@@ -3312,41 +3765,41 @@
33123765 LA.matInvert(origin.toParent, origin.fromParent);
33133766
33143767 Invariants();
3315
- obj.Invariants();
3768
+ hip.Invariants();
33163769 rot.Invariants();
33173770 origin.Invariants();
33183771 origin0.Invariants();
33193772
3320
- firsttimeafterload = true;
3773
+ firsttimeafterload = false; // true;
33213774
33223775 if (rewind)
33233776 Rewind();
33243777
3325
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), fade);
3778
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); //, fade);
33263779
3327
- if (true)
3328
- return;
3780
+ if (true)
3781
+ return;
33293782
33303783 double pos[] = new double[6];
33313784
33323785 if (!reset)
33333786 {
3334
- assert(obj.tx == obj.toParent[3][0]);
3335
- assert(obj.ty == obj.toParent[3][1]);
3336
- 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]);
33373790
3338
- pos[0] = obj.tx; // obj.toParent[3][0];
3339
- pos[1] = obj.ty; // obj.toParent[3][1];
3340
- pos[2] = obj.tz; // obj.toParent[3][2];
3341
- pos[3] = obj.rz;
3342
- pos[4] = obj.ry;
3343
- 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;
33443797 }
33453798
33463799 cVector temp = new cVector();
3347
- temp.x = obj.globalTransform[3][0];
3348
- temp.y = obj.globalTransform[3][1];
3349
- 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];
33503803 // LA.xformPos(temp, origin0.toParent, temp);
33513804 // System.err.println("POS0 = " + temp.x + ", " + temp.y + ", " + temp.z + ";");
33523805
....@@ -3430,7 +3883,7 @@
34303883 }
34313884
34323885 // Rewind();
3433
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), true);
3886
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); // , true);
34343887 }
34353888
34363889 void Rewind()
....@@ -3447,7 +3900,7 @@
34473900
34483901 transient boolean restarted; // CROWD issue?
34493902
3450
- void drawSelf(CameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
3903
+ void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
34513904 {
34523905 //System.err.println("drawSelf Mocap frame # " + frame);
34533906 //System.err.println("drawSelf Mocap baseframe # " + baseframe);
....@@ -3464,17 +3917,24 @@
34643917 // if (firstframe)
34653918 // return;
34663919
3467
- if (!restarted && /*display.restartframe &&*/
3468
- 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))
34693922 {
34703923 //display.restartframe = false;
34713924 restarted = true;
3925
+ //System.err.println("restarted = true");
34723926 Step();
3927
+
3928
+ Globals.lighttouched = true;
34733929 }
34743930 else
34753931 {
3476
- if (display.isLIVE() && live && display.drawMode != display.SHADOW)
3932
+ //System.err.println("restarted");
3933
+ if (Globals.isLIVE() && live && display.DrawMode() != iCameraPane.SHADOW)
3934
+ {
34773935 restarted = false;
3936
+ //System.err.println("restarted = false");
3937
+ }
34783938 }
34793939
34803940 super.drawSelf(display, root, selected, blocked);
....@@ -3534,6 +3994,11 @@
35343994 // GetObject().release(i);
35353995 }
35363996
3997
+ boolean HasBigData()
3998
+ {
3999
+ return skeleton != null;
4000
+ }
4001
+
35374002 public Object3D get(int i)
35384003 {
35394004 if (i != 0)