Normand Briere
2019-06-16 372b7fd481a476cd659713a4a01bf28bf6760cbe
Mocap.java
....@@ -261,9 +261,9 @@
261261
262262 // LA.matConcat(toParent, hip.get(0).toParent, toParent);
263263
264
- CameraPane.debugpoint.toParent[3][0] = poship.x;
265
- CameraPane.debugpoint.toParent[3][1] = poship.y;
266
- CameraPane.debugpoint.toParent[3][2] = poship.z;
264
+ CameraPane.debugpointG.toParent[3][0] = poship.x;
265
+ CameraPane.debugpointG.toParent[3][1] = poship.y;
266
+ CameraPane.debugpointG.toParent[3][2] = poship.z;
267267
268268 LA.matInvert(toParent, fromParent);
269269
....@@ -324,21 +324,21 @@
324324 // LA.matYRotate(toParent, angleY - angleYhip);
325325 // LA.matTranslate(toParent, pos.x - poship.x, pos.y - poship.y, pos.z - poship.z);
326326
327
- CameraPane.debugpoint2.toParent[3][0] = pos.x;
328
- CameraPane.debugpoint2.toParent[3][1] = pos.y;
329
- CameraPane.debugpoint2.toParent[3][2] = pos.z;
327
+ CameraPane.debugpointP.toParent[3][0] = pos.x;
328
+ CameraPane.debugpointP.toParent[3][1] = pos.y;
329
+ CameraPane.debugpointP.toParent[3][2] = pos.z;
330330
331
- CameraPane.debugpoint3.toParent[3][0] = poship.x;
332
- CameraPane.debugpoint3.toParent[3][1] = poship.y;
333
- CameraPane.debugpoint3.toParent[3][2] = poship.z;
331
+ CameraPane.debugpointC.toParent[3][0] = poship.x;
332
+ CameraPane.debugpointC.toParent[3][1] = poship.y;
333
+ CameraPane.debugpointC.toParent[3][2] = poship.z;
334334
335335 poship.x = toParent[3][0];
336336 poship.y = toParent[3][1];
337337 poship.z = toParent[3][2];
338338
339
- CameraPane.debugpoint4.toParent[3][0] = poship.x;
340
- CameraPane.debugpoint4.toParent[3][1] = poship.y;
341
- CameraPane.debugpoint4.toParent[3][2] = poship.z;
339
+ CameraPane.debugpointR.toParent[3][0] = poship.x;
340
+ CameraPane.debugpointR.toParent[3][1] = poship.y;
341
+ CameraPane.debugpointR.toParent[3][2] = poship.z;
342342
343343 LA.matInvert(toParent, fromParent);
344344 }
....@@ -477,29 +477,51 @@
477477 }
478478 }
479479
480
+ static cVector centroid = new cVector();
481
+ static cVector mocaporigin = new cVector();
482
+
480483 void SetHipOrientation()
481484 {
482485 Object3D hip = get(0);
483486
487
+ if (toParent == null)
488
+ {
489
+ toParent = LA.newMatrix();
490
+ fromParent = LA.newMatrix();
491
+ }
492
+
484493 LA.matConcat(toParent, hip.get(0).toParent, matrix);
485494
486
- cVector centroid = new cVector();
495
+ mocaporigin.x = matrix[3][0];
496
+ mocaporigin.y = matrix[3][1];
497
+ mocaporigin.z = matrix[3][2];
498
+
487499 centroid.x = matrix[3][0];
488500 centroid.y = matrix[3][1];
489501 centroid.z = matrix[3][2];
490
- this.getCentroid(centroid, true);
502
+// this.getCentroid(centroid, true);
503
+
504
+ CameraPane.debugpointG.name = "";
505
+ CameraPane.debugpointG.toParent[3][0] = mocaporigin.x;
506
+ CameraPane.debugpointG.toParent[3][1] = mocaporigin.y;
507
+ CameraPane.debugpointG.toParent[3][2] = mocaporigin.z;
508
+
509
+ CameraPane.debugpointP.name = "";
510
+ CameraPane.debugpointP.toParent[3][0] = centroid.x;
511
+ CameraPane.debugpointP.toParent[3][1] = centroid.y;
512
+ CameraPane.debugpointP.toParent[3][2] = centroid.z;
491513
492514 cVector goal = GetGoal(centroid);
493515 if (goal != null)
494516 {
495
- System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalx + ", " + goalz + ")");
517
+ System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
496518
497
- goalx = goal.x;
498
- goalz = goal.z;
499
- targetx = targetz = 0;
519
+ goalposx = goal.x;
520
+ goalposz = goal.z;
521
+ targetdirx = targetdirz = 0;
500522 }
501523
502
- if (goalx == 0 && goalz == 0)
524
+ if (goalposx == 0 && goalposz == 0)
503525 {
504526 // No target
505527 if (ScriptNode.speaker != null)
....@@ -533,8 +555,8 @@
533555 //sourcenode.parent.TransformToLocal(dst);
534556 this.parent.TransformToLocal(dst);
535557
536
- goalx = dst.x;
537
- goalz = dst.z;
558
+ goalposx = dst.x;
559
+ goalposz = dst.z;
538560 }
539561 else
540562 return;
....@@ -550,17 +572,25 @@
550572
551573 double angleYhip = Math.atan2(-temp.z, temp.x);
552574
553
- double angleYtarget = Math.atan2(goalx - centroid.x, goalz - centroid.z);
575
+ double angleYtarget = Math.atan2(goalposx - centroid.x, goalposz - centroid.z);
554576
555577 LA.matIdentity(matrix);
556578 LA.matTranslate(matrix, -centroid.x, -centroid.y, -centroid.z);
557
- double angle = CurveAngle(0, angleYtarget - angleYhip, 1); // 0.1f);
579
+ double angle = CurveAngle(0, angleYtarget - angleYhip, 0.1f);
558580 LA.matYRotate(matrix, angle);
559581 LA.matTranslate(matrix, centroid.x, centroid.y, centroid.z);
560582
561583 LA.matConcat(matrix, toParent, toParent);
562584
563585 LA.matInvert(toParent, fromParent);
586
+
587
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
588
+
589
+ centroid.x = matrix[3][0];
590
+ centroid.y = matrix[3][1];
591
+ centroid.z = matrix[3][2];
592
+
593
+ double dist = LA.distance(centroid, mocaporigin);
564594
565595 CheckForAction(centroid);
566596 }
....@@ -614,6 +644,24 @@
614644 // transient // aout 2013
615645 Object3D skeleton;
616646
647
+ void ExtractBigData(Object3D o)
648
+ {
649
+ super.ExtractBigData(o);
650
+
651
+ o.bvh = this.bvh;
652
+ o.skeleton = this.skeleton;
653
+ this.bvh = null;
654
+ this.skeleton = null;
655
+ }
656
+
657
+ void RestoreBigData(Object3D o)
658
+ {
659
+ super.RestoreBigData(o);
660
+
661
+ this.bvh = o.bvh;
662
+ this.skeleton = o.skeleton;
663
+ }
664
+
617665 boolean smoothed;
618666
619667 //boolean touched;
....@@ -637,11 +685,11 @@
637685 double pinx;
638686 double pinz;
639687
640
- double targetx;
641
- double targetz;
688
+ double targetdirx;
689
+ double targetdirz;
642690
643
- double goalx = -20;
644
- double goalz = -10;
691
+ double goalposx = 0; // -20;
692
+ double goalposz = 0; // -10;
645693
646694 boolean followpath;
647695
....@@ -712,7 +760,7 @@
712760 scriptactions.clear();
713761 }
714762
715
- static double EPSACTION = 0.1; // 0.075; // 0.1;
763
+ static double EPSACTION = 0.1; // 0.075; // 0.1;Came
716764
717765 void AddFromTo(cVector from, cVector to)
718766 {
....@@ -897,7 +945,7 @@
897945 // //GetFileRoot();
898946
899947 // sept 2014: //
900
- GrafreeD.RENDERME = 3; // patch for Merge objects
948
+ Grafreed.RENDERME = 3; // patch for Merge objects
901949 float[] thedata = bvh.animation.getBoneData(0);
902950
903951 os.x = (float) (path.get(i).toParent[3][0]); // - thedata[frame*6]);
....@@ -1278,6 +1326,7 @@
12781326
12791327 void SetPosition(Object3D sourcenode, cVector floor, long floorid, cVector centroid)
12801328 {
1329
+ assert(false);
12811330 //assert(CameraPane.drawMode == CameraPane.SHADOW);
12821331
12831332 Object3D transformnode = new Object3D();
....@@ -1481,9 +1530,9 @@
14811530 groundid = floorid;
14821531
14831532 // green
1484
- CameraPane.debugpoint.toParent[3][0] = groundx;
1485
- CameraPane.debugpoint.toParent[3][1] = floor.y;
1486
- CameraPane.debugpoint.toParent[3][2] = groundz;
1533
+ CameraPane.debugpointG.toParent[3][0] = groundx;
1534
+ CameraPane.debugpointG.toParent[3][1] = floor.y;
1535
+ CameraPane.debugpointG.toParent[3][2] = groundz;
14871536
14881537 if (true) // slow && stepout && onein)
14891538 {
....@@ -1494,7 +1543,7 @@
14941543 // mywave = currentwave++;
14951544 // }
14961545 // sound
1497
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
1546
+ cVector eye = Globals.theRenderer.EyeCamera().location;
14981547
14991548 // if (sourcenode.parent.parent != null)
15001549 // sourcenode.parent.parent.TransformToWorld(floor, tmp);
....@@ -1539,9 +1588,9 @@
15391588 //GraphreeD.
15401589 wav.play(volume * usedvolume); //, mywave);
15411590
1542
- lastsoundtime = CameraPane.framecount;
1591
+ lastsoundtime = Globals.framecount;
15431592
1544
- GrafreeD.hassound = true;
1593
+ Grafreed.hassound = true;
15451594 }
15461595 // else
15471596 // System.out.println("skipped");
....@@ -1560,9 +1609,9 @@
15601609
15611610 // System.out.println("Allo " + sourcenode);
15621611 // purple
1563
- CameraPane.debugpoint2.toParent[3][0] = floor.x;// + posx;
1564
- CameraPane.debugpoint2.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1565
- CameraPane.debugpoint2.toParent[3][2] = floor.z;// + posz;
1612
+ CameraPane.debugpointP.toParent[3][0] = floor.x;// + posx;
1613
+ CameraPane.debugpointP.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1614
+ CameraPane.debugpointP.toParent[3][2] = floor.z;// + posz;
15661615
15671616
15681617 if (false) // dist2 > 0.1)
....@@ -1628,9 +1677,9 @@
16281677 this.get(0).TransformToWorld(v0);
16291678
16301679 // cyan
1631
- CameraPane.debugpoint3.toParent[3][0] = v0.x;
1632
- CameraPane.debugpoint3.toParent[3][1] = ground;
1633
- CameraPane.debugpoint3.toParent[3][2] = v0.z;
1680
+ CameraPane.debugpointC.toParent[3][0] = v0.x;
1681
+ CameraPane.debugpointC.toParent[3][1] = ground;
1682
+ CameraPane.debugpointC.toParent[3][2] = v0.z;
16341683
16351684 LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent);
16361685 LA.matInvert(sourcenode.toParent, sourcenode.fromParent);
....@@ -1640,9 +1689,9 @@
16401689 this.get(0).TransformToWorld(v0);
16411690
16421691 // red
1643
- CameraPane.debugpoint4.toParent[3][0] = v0.x;
1644
- CameraPane.debugpoint4.toParent[3][1] = ground;
1645
- CameraPane.debugpoint4.toParent[3][2] = v0.z;
1692
+ CameraPane.debugpointR.toParent[3][0] = v0.x;
1693
+ CameraPane.debugpointR.toParent[3][1] = ground;
1694
+ CameraPane.debugpointR.toParent[3][2] = v0.z;
16461695 }
16471696 }
16481697
....@@ -1682,11 +1731,11 @@
16821731
16831732 if (goal != null)
16841733 {
1685
- System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")");
1734
+ System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
16861735 //sourcenode.parent.parent.Dump();
1687
- goalx = goal.x;
1688
- goalz = goal.z;
1689
- targetx = targetz = 0;
1736
+ goalposx = goal.x;
1737
+ goalposz = goal.z;
1738
+ targetdirx = targetdirz = 0;
16901739
16911740 followpath = true;
16921741 }
....@@ -1737,16 +1786,16 @@
17371786 // }
17381787 if (false) // !uselast)
17391788 {
1740
- CameraPane.debugpoint.toParent[3][0] = dst.x;
1741
- CameraPane.debugpoint.toParent[3][1] = dst.y;
1742
- CameraPane.debugpoint.toParent[3][2] = dst.z;
1789
+ CameraPane.debugpointG.toParent[3][0] = dst.x;
1790
+ CameraPane.debugpointG.toParent[3][1] = dst.y;
1791
+ CameraPane.debugpointG.toParent[3][2] = dst.z;
17431792 }
17441793 }
17451794
1746
- if (goalx != 0 || goalz != 0) // TODO
1795
+ if (goalposx != 0 || goalposz != 0) // TODO
17471796 {
17481797 // overwrite speaker orientation
1749
- dst.set(goalx,0,goalz);
1798
+ dst.set(goalposx,0,goalposz);
17501799 if (sourcenode.parent != null) // july 2014
17511800 sourcenode.parent.
17521801 TransformToLocal(dst);
....@@ -1798,26 +1847,26 @@
17981847 // mars 2014
17991848 if (false) // goalx != 0 || goalz != 0)
18001849 {
1801
- targetx = dst.x - src.x;
1802
- targetz = dst.z - src.z;
1850
+ targetdirx = dst.x - src.x;
1851
+ targetdirz = dst.z - src.z;
18031852
1804
- if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1)
1853
+ if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1)
18051854 {
18061855 // far enough from goal. keep the goal position.
1807
- targetx = 0;
1808
- targetz = 0;
1856
+ targetdirx = 0;
1857
+ targetdirz = 0;
18091858 }
18101859 else
18111860 {
18121861 // too close to goal. switch to target direction instead.
1813
- goalx = 0;
1814
- goalz = 0;
1862
+ goalposx = 0;
1863
+ goalposz = 0;
18151864 }
18161865 }
18171866
18181867 //sourcenode.getCentroid(src, true);
18191868
1820
- if (speakernode == sourcenode && goalx == 0 && goalz == 0)
1869
+ if (speakernode == sourcenode && goalposx == 0 && goalposz == 0)
18211870 {
18221871 if (ScriptNode.lastspeaker != null)
18231872 new Exception().printStackTrace();
....@@ -1826,13 +1875,13 @@
18261875
18271876 // LA.xformPos(src, fromParent, src);
18281877
1829
- if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalx != 0 || goalz != 0) && targetx == 0 && targetz == 0)
1878
+ if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalposx != 0 || goalposz != 0) && targetdirx == 0 && targetdirz == 0)
18301879 dst.sub(src);
18311880 else
18321881 // vector mode
18331882 {
1834
- dst.x = targetx;
1835
- dst.z = targetz;
1883
+ dst.x = targetdirx;
1884
+ dst.z = targetdirz;
18361885
18371886 // TEST TARGET
18381887 // dst.x = CameraPane.selectedpoint.toParent[3][0];
....@@ -2242,7 +2291,7 @@
22422291 }
22432292
22442293 if (!smoothed)
2245
- for (int i=0; --i>=0;)
2294
+ for (int i=10; --i>=0;)
22462295 SmoothAnimData(); // much reduces shakiness
22472296
22482297 smoothed = true;
....@@ -2280,9 +2329,16 @@
22802329 toVector.x = LA.cos(to);
22812330 toVector.y = LA.sin(to);
22822331
2332
+ double fromA = Math.atan2(fromVector.y, fromVector.x);
2333
+ double toA = Math.atan2(toVector.y, toVector.x);
2334
+
22832335 Vector2d currentVector = Slerp(fromVector, toVector, step);
22842336
2285
- return Math.atan2(currentVector.y, currentVector.x);
2337
+ double angle = Math.atan2(currentVector.y, currentVector.x);
2338
+
2339
+ double angle2 = (1-step) * fromA + step * toA;
2340
+
2341
+ return angle;
22862342 }
22872343
22882344 public static Vector2d Slerp(Vector2d from, Vector2d to, double step)
....@@ -2765,7 +2821,8 @@
27652821 //if (bone._rotationEnabled)
27662822 if (//frame > 0 &&
27672823 !bone.skipmocap &&
2768
- !bone.name.contains("head") // &&
2824
+ !bone.name.contains("head") &&
2825
+ !bone.name.contains("Head") // &&
27692826 // !bone.name.contains("rFoot") &&
27702827 // !bone.name.contains("lFoot") &&
27712828 // !bone.name.contains("Pinky") &&
....@@ -3191,7 +3248,7 @@
31913248
31923249 // july 2014
31933250 // goalx = goalz = 0;
3194
- targetx = targetz = 0;
3251
+ targetdirx = targetdirz = 0;
31953252
31963253 //SetPositionDelta(true, true, true, false);
31973254 // LoadData();
....@@ -3201,8 +3258,8 @@
32013258
32023259 // aout 2013 endframe = 0; // june 2013
32033260
3204
- //ResetZero();
3205
- setPose(frame);
3261
+ ResetZero();
3262
+ //setPose(frame);
32063263 }
32073264
32083265 static int mocapsupport = 0;
....@@ -3220,12 +3277,13 @@
32203277
32213278 int step = 1;
32223279
3280
+ // patch for running hare
32233281 if (speedup) // fev 2014
32243282 step *= 2; // 4;
32253283 if (rewind) // mars 2014
32263284 step *= 4;
32273285
3228
- if (CameraPane.FAST) // && !CameraPane.HOLD)
3286
+ //if (CameraPane.FAST) // && !CameraPane.HOLD)
32293287 step *= CameraPane.STEP;
32303288
32313289 //System.err.println("Step Mocap frame # " + frame);
....@@ -3257,7 +3315,7 @@
32573315 "; fullname = " + fullname);
32583316
32593317 //int delta = frame - baseframe;
3260
- if (CameraPane.CROWD)
3318
+ if (Globals.CROWD)
32613319 {
32623320 baseframe = GetFirstFrame(); // 0 initial point
32633321 }
....@@ -3266,23 +3324,40 @@
32663324 // SetPositionDelta(false, true, false); // ?? false);
32673325 {
32683326 if (support == null)
3269
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3327
+ {
3328
+ if (bvh == null && new File(fullname).exists())
3329
+ ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3330
+ else
3331
+ {
3332
+ SetGlobalTransform();
3333
+ Rewind();
3334
+ Fade();
3335
+ }
3336
+ }
32703337 else
32713338 {
3272
- try
3273
- {
3339
+// try
3340
+// {
32743341 bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
32753342
32763343 // SetPositionDelta(false, true, true, true);
32773344 LoadData();
32783345 Rewind();
32793346 Fade();
3280
- }
3281
- catch (Exception e)
3282
- {
3283
- e.printStackTrace();
3284
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3285
- }
3347
+// }
3348
+// catch (Exception e)
3349
+// {
3350
+// System.err.println("An error occured while loading data. Use fallback by loading the file.");
3351
+// //e.printStackTrace();
3352
+// try
3353
+// {
3354
+// ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3355
+// }
3356
+// catch (Exception e2)
3357
+// {
3358
+// System.err.println("Motion file not found: " + fullname);
3359
+// }
3360
+// }
32863361 }
32873362 }
32883363
....@@ -3464,6 +3539,7 @@
34643539 // filters out bad input data
34653540 void FilterAnimData()
34663541 {
3542
+ new Exception().printStackTrace();
34673543 System.exit(0);
34683544
34693545 float[] data; // = bvh.animation.getBoneData(0);
....@@ -3821,7 +3897,7 @@
38213897
38223898 transient boolean restarted; // CROWD issue?
38233899
3824
- void drawSelf(CameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
3900
+ void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
38253901 {
38263902 //System.err.println("drawSelf Mocap frame # " + frame);
38273903 //System.err.println("drawSelf Mocap baseframe # " + baseframe);
....@@ -3838,17 +3914,22 @@
38383914 // if (firstframe)
38393915 // return;
38403916
3841
- if (!restarted && /*display.restartframe &&*/
3842
- display.isLIVE() && live && display.drawMode == display.SHADOW) // FUCK
3917
+ if (//!restarted && /*display.restartframe &&*/
3918
+ Globals.isLIVE() && live && (display.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW))
38433919 {
38443920 //display.restartframe = false;
38453921 restarted = true;
3922
+ //System.err.println("restarted = true");
38463923 Step();
38473924 }
38483925 else
38493926 {
3850
- if (display.isLIVE() && live && display.drawMode != display.SHADOW)
3927
+ //System.err.println("restarted");
3928
+ if (Globals.isLIVE() && live && display.DrawMode() != iCameraPane.SHADOW)
3929
+ {
38513930 restarted = false;
3931
+ //System.err.println("restarted = false");
3932
+ }
38523933 }
38533934
38543935 super.drawSelf(display, root, selected, blocked);