Normand Briere
2019-11-21 ddb10cb84dddfeef1ef9946f2e13cef3c93e6cc4
Object3D.java
....@@ -41,8 +41,24 @@
4141
4242 java.util.Hashtable<java.util.UUID, Object3D> versiontable; // = new java.util.Hashtable<java.util.UUID, Object3D>();
4343
44
+ transient int tabIndex; // Tabs can change between sessions.
45
+
4446 ScriptNode scriptnode;
4547
48
+ void GetOrigin(cVector o)
49
+ {
50
+ o.x = this.toParent[3][0];
51
+ o.y = this.toParent[3][1];
52
+ o.z = this.toParent[3][2];
53
+ }
54
+
55
+ void SetOrigin(cVector o)
56
+ {
57
+ this.toParent[3][0] = o.x;
58
+ this.toParent[3][1] = o.y;
59
+ this.toParent[3][2] = o.z;
60
+ }
61
+
4662 void deepCopyNode(Object3D other)
4763 {
4864 other.skyboxname = skyboxname;
....@@ -100,7 +116,7 @@
100116 other.softtouched = softtouched;
101117
102118 other.random = random;
103
- other.link2support = link2support;
119
+ other.link2master = Link2Support();
104120 other.transformcount = transformcount;
105121 other.marked = marked;
106122 other.skip = skip;
....@@ -220,10 +236,10 @@
220236 return;
221237
222238 transientsupport = support;
223
- transientlink2master = link2support;
239
+ transientlink2master = Link2Support();
224240
225241 support = null;
226
- link2support = false;
242
+ link2master = false;
227243
228244 if (bRep != null)
229245 {
....@@ -247,7 +263,7 @@
247263 return;
248264
249265 support = transientsupport;
250
- link2support = transientlink2master;
266
+ link2master = transientlink2master;
251267 transientsupport = null;
252268 transientlink2master = false;
253269
....@@ -633,7 +649,10 @@
633649 transient boolean keepdontselect;
634650 boolean dontselect = false;
635651 boolean hide = false;
636
- boolean link2support = false; // performs reset support/master at each frame
652
+
653
+ boolean link2master = false; // performs reset support/master at each frame (cannot rename due to serialization)
654
+ boolean link2support = false; // (cannot rename due to serialization)
655
+
637656 boolean marked = false; // animation node
638657 boolean skip = false; // centroid issue
639658 boolean skipmocap = false; // mocap data
....@@ -654,27 +673,74 @@
654673 return this;
655674 }
656675
676
+ class SizeCompare implements Comparable
677
+ {
678
+ int size;
679
+ Object3D child;
680
+
681
+ SizeCompare(Object3D c)
682
+ {
683
+ child = c;
684
+ size = c.MemorySize();
685
+ }
686
+
687
+ public int compareTo(Object o)
688
+ {
689
+ SizeCompare comp = (SizeCompare) o;
690
+
691
+ return comp.size < size ? 1 : -1;
692
+ }
693
+ }
694
+
695
+ transient SizeCompare[] sizecompare = null;
696
+
657697 void SortBySize()
658698 {
659
- boolean sorted = false;
699
+// boolean sorted = false;
700
+//
701
+// while (!sorted)
702
+// {
703
+// sorted = true;
704
+//
705
+// for (int i=0; i<Size()-1; i++)
706
+// {
707
+// Object3D obji = get(i);
708
+// Object3D objj = get(i+1);
709
+//
710
+// if (obji.MemorySize() < objj.MemorySize())
711
+// {
712
+// set(i, objj);
713
+// set(i+1, obji);
714
+//
715
+// sorted = false;
716
+// }
717
+// }
718
+// }
719
+
720
+ int count = Size();
660721
661
- while (!sorted)
722
+ if (sizecompare == null || sizecompare.length != count)
662723 {
663
- sorted = true;
664
-
665
- for (int i=0; i<Size()-1; i++)
724
+ sizecompare = new SizeCompare[count];
725
+
726
+ for (int k=0; k<count; k++)
666727 {
667
- Object3D obji = get(i);
668
- Object3D objj = get(i+1);
669
-
670
- if (obji.MemorySize() < objj.MemorySize())
671
- {
672
- set(i, objj);
673
- set(i+1, obji);
674
-
675
- sorted = false;
676
- }
728
+ sizecompare[k] = new SizeCompare(get(k));
677729 }
730
+ }
731
+ else
732
+ {
733
+ for (int k=0; k<count; k++)
734
+ {
735
+ sizecompare[k].size = get(k).MemorySize();
736
+ }
737
+ }
738
+
739
+ java.util.Arrays.sort(sizecompare);
740
+
741
+ for (int i=0; i<count; i++)
742
+ {
743
+ set(i, sizecompare[i].child);
678744 }
679745 }
680746
....@@ -706,34 +772,59 @@
706772
707773 int MemorySize()
708774 {
709
- if (memorysize == 0)
775
+// if (memorysize == 0)
776
+// {
777
+// try
778
+// {
779
+// Object3D obj = this;
780
+//
781
+// Object3D parent = obj.parent;
782
+// obj.parent = null;
783
+// Object3D support = obj.support;
784
+// obj.support = null;
785
+//
786
+// java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
787
+// java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(baos);
788
+//
789
+// out.writeObject(obj);
790
+//
791
+// obj.parent = parent;
792
+// obj.support = support;
793
+//
794
+// memorysize = baos.toByteArray().length;
795
+// }
796
+// catch (Exception e)
797
+// {
798
+// e.printStackTrace();
799
+// }
800
+// }
801
+//
802
+// return memorysize;
803
+
804
+ if (blockloop)
710805 {
711
- try
712
- {
713
- Object3D obj = this;
806
+ return 0;
807
+ }
714808
715
- Object3D parent = obj.parent;
716
- obj.parent = null;
717
- Object3D support = obj.support;
718
- obj.support = null;
719
-
720
- java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
721
- java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(baos);
722
-
723
- out.writeObject(obj);
724
-
725
- obj.parent = parent;
726
- obj.support = support;
727
-
728
- memorysize = baos.toByteArray().length;
729
- }
730
- catch (Exception e)
731
- {
732
- e.printStackTrace();
733
- }
809
+ int memory = 0;
810
+
811
+ if (bRep != null)
812
+ {
813
+ memory = bRep.VertexCount();
734814 }
735815
736
- return memorysize;
816
+ blockloop = true;
817
+
818
+ for (int i = 0; i < Size(); i++)
819
+ {
820
+ Object3D obj = (Object3D) Children().get(i);
821
+
822
+ memory += obj.MemorySize();
823
+ }
824
+
825
+ blockloop = false;
826
+
827
+ return memory;
737828 }
738829
739830 void Slower()
....@@ -1023,7 +1114,7 @@
10231114
10241115 void Step()
10251116 {
1026
- // marde pour serialization de Texture
1117
+ // patch pour serialization de Texture
10271118 resetmaxcount();
10281119 resettransformcount();
10291120 resetstep();
....@@ -1058,7 +1149,7 @@
10581149 transformcount++;
10591150 }
10601151
1061
- int maxcount;
1152
+ int maxcount = 128;
10621153 int transformcount;
10631154 int step;
10641155
....@@ -1111,7 +1202,10 @@
11111202 if (step == 0)
11121203 step = 1;
11131204 if (maxcount == 0)
1114
- maxcount = 128; // 2048; // 4;
1205
+ {
1206
+ System.out.println("maxcount == 0");
1207
+ System.exit(0); // maxcount = 128; // 2048; // 4;
1208
+ }
11151209 // if (acceleration == 0)
11161210 // acceleration = 10;
11171211 if (delay == 0) // serial
....@@ -1137,6 +1231,8 @@
11371231 (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || !Globals.COMPUTESHADOWWHENLIVE) &&
11381232 currentframe != Globals.framecount)
11391233 {
1234
+ Globals.lighttouched = true;
1235
+
11401236 currentframe = Globals.framecount;
11411237
11421238 // System.err.println("transformcount = " + transformcount);
....@@ -1421,7 +1517,7 @@
14211517
14221518 blockloop = true;
14231519
1424
- other.parent = parent;
1520
+ // other.parent = parent;
14251521
14261522 //System.out.println("COPY " + this + " to " + other);
14271523 //new Exception().printStackTrace();
....@@ -1457,7 +1553,7 @@
14571553 Object3D obj = (Object3D)Children().get(i);
14581554 if (IsContainedIn(obj))
14591555 {
1460
-// assert(false); // ?!?!?!?!?!
1556
+ assert(false); // ?!?!?!?!?!
14611557 c.Children().setElementAt(c, i);
14621558 }
14631559 else
....@@ -2202,7 +2298,7 @@
22022298 {
22032299 support = other;
22042300
2205
- link2support = support != null;
2301
+ link2master = support != null;
22062302
22072303 if (support != null && bRep.trimmed)
22082304 {
....@@ -2555,7 +2651,7 @@
25552651 return b;
25562652 }
25572653
2558
- void UpdateMaterial(cMaterial anchor, cMaterial current, boolean propagate)
2654
+ void UpdateMaterial(cMaterial anchor, cMaterial current, boolean propagate, boolean colorparallax)
25592655 {
25602656 if (blockloop)
25612657 {
....@@ -2565,7 +2661,7 @@
25652661 // super.UpdateMaterial(anchor, current, false);
25662662 if (material != null)
25672663 {
2568
- material.UpdateMaterial(anchor, current);
2664
+ material.UpdateMaterial(anchor, current, colorparallax);
25692665 }
25702666
25712667 if (!propagate)
....@@ -2579,7 +2675,7 @@
25792675 if (child == null)
25802676 continue;
25812677 blockloop = true;
2582
- child.UpdateMaterial(anchor, current, propagate);
2678
+ child.UpdateMaterial(anchor, current, propagate, false);
25832679 blockloop = false;
25842680 Children().release(i);
25852681 }
....@@ -2593,7 +2689,7 @@
25932689 if (child == null)
25942690 continue;
25952691 blockloop = true;
2596
- child.UpdateMaterial(anchor, current, propagate);
2692
+ child.UpdateMaterial(anchor, current, propagate, false);
25972693 blockloop = false;
25982694 Children().release(i);
25992695 }
....@@ -3414,7 +3510,7 @@
34143510 }
34153511 }
34163512
3417
- public void Scale(int scale)
3513
+ public void Scale(float scale)
34183514 {
34193515 Object3D obj = this;
34203516
....@@ -3921,7 +4017,7 @@
39214017 //if (bRep != null)
39224018 if (//marked || // does not make sense
39234019 (bRep != null || material != null)) // borderline...
3924
- link2support = h;
4020
+ link2master = h;
39254021
39264022 for (int i = 0; i < Size(); i++)
39274023 {
....@@ -4101,11 +4197,6 @@
41014197 Step();
41024198 Touch();
41034199
4104
- StepRecur();
4105
- }
4106
-
4107
- void StepRecur()
4108
- {
41094200 for (int i = 0; i < size(); i++)
41104201 {
41114202 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -5623,8 +5714,9 @@
56235714 {
56245715 }
56255716 // transient int displaylist = 0; // -1;
5626
- transient boolean touched = true;
5627
- transient boolean softtouched = true;
5717
+ transient boolean reset = false; // Recalculate
5718
+ transient boolean touched = true; // call list only
5719
+ transient boolean softtouched = true; // aucune idee
56285720
56295721 void Touch()
56305722 {
....@@ -5677,6 +5769,7 @@
56775769 {
56785770 //System.out.println("HardTouch " + this); // new Exception().printStackTrace();
56795771 //new Exception().printStackTrace();
5772
+ reset = true;
56805773 touched = true;
56815774 CameraPane.touched = true;
56825775 //if (parent != null)
....@@ -6159,7 +6252,7 @@
61596252 boolean NeedSupport()
61606253 {
61616254 return
6162
- CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && link2support && /*live &&*/ support != null
6255
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && Link2Support() && /*live &&*/ support != null
61636256 // PROBLEM with CROWD!!
61646257 && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
61656258 }
....@@ -6182,6 +6275,17 @@
61826275 return live && bRep != null;
61836276 }
61846277
6278
+ boolean Link2Support()
6279
+ {
6280
+ return link2master || link2support;
6281
+ }
6282
+
6283
+ static cVector minima = new cVector();
6284
+ static cVector maxima = new cVector();
6285
+ static javax.vecmath.Point3d center = new javax.vecmath.Point3d();
6286
+
6287
+ boolean compiling;
6288
+
61856289 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
61866290 {
61876291 Invariants(); // june 2013
....@@ -6189,6 +6293,29 @@
61896293 if (support != null)
61906294 {
61916295 // System.err.println("Draw " + this + " Frame # " + ((Mocap)((Merge)support).object).frame);
6296
+ }
6297
+
6298
+ if (false) // live && Link2Support() && support == null && !this.marked) // project on ground
6299
+ {
6300
+ getBounds(minima, maxima, true);
6301
+ center.x = (minima.x + maxima.x) / 2;
6302
+ center.y = 10000; // (minima.y + maxima.y) / 2;
6303
+ center.z = (minima.z + maxima.z) / 2;
6304
+
6305
+ Ray ray = new Ray(center, new Vector3d(0,-1,0));
6306
+
6307
+ IntersectResult res = new IntersectResult();
6308
+ res.t = Double.POSITIVE_INFINITY;
6309
+
6310
+ if (Grafreed.grafreed.universe.intersect(ray, res))
6311
+ {
6312
+ double resx = ray.eyePoint.x + ray.viewDirection.x * res.t;
6313
+ double resy = ray.eyePoint.y + ray.viewDirection.y * res.t;
6314
+ double resz = ray.eyePoint.z + ray.viewDirection.z * res.t;
6315
+
6316
+ LA.matTranslate(toParent, 0, resy - minima.y, 0);
6317
+ LA.matInvert(toParent, fromParent);
6318
+ }
61926319 }
61936320
61946321 if (display.DrawMode() == iCameraPane.SELECTION &&
....@@ -6243,8 +6370,9 @@
62436370 support = support;
62446371
62456372 boolean usecalllists = !IsDynamic() &&
6246
- IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2support); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6247
- //boolean usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6373
+ IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !Link2Support()); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6374
+
6375
+ //usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
62486376
62496377 //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass.
62506378
....@@ -6254,7 +6382,8 @@
62546382 bRep.displaylist = 0;
62556383 }
62566384 // usecalllists &= !(parent instanceof RandomNode);
6257
- // usecalllists = false;
6385
+ if (CameraPane.BOXMODE) // Too dynamic
6386
+ usecalllists = false;
62586387
62596388 if (display.DrawMode() == display.SHADOW)
62606389 //GetBRep() != null)
....@@ -6268,7 +6397,7 @@
62686397
62696398 if (!selectmode && //display.DrawMode() != display.SELECTION &&
62706399 //(touched || (bRep != null && bRep.displaylist <= 0)))
6271
- (Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE || touched && Globals.COMPUTESHADOWWHENLIVE)) // || (bRep != null && bRep.displaylist <= 0)))
6400
+ ((Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE) || touched)) // || (bRep != null && bRep.displaylist <= 0)))
62726401 {
62736402 Globals.lighttouched = true;
62746403 } // all panes...
....@@ -6297,7 +6426,9 @@
62976426 display.NewList(bRep.displaylist);
62986427 }
62996428
6429
+ compiling = true;
63006430 CallList(display, root, selected, blocked);
6431
+ compiling = false;
63016432
63026433 // compiled = true;
63036434 if (usecalllists && bRep.displaylist > 0)
....@@ -6350,7 +6481,7 @@
63506481 {
63516482 if (display.DrawMode() == iCameraPane.SHADOW)
63526483 {
6353
- if (!link2support // tricky to cull in shadow mode.
6484
+ if (!Link2Support() // tricky to cull in shadow mode.
63546485 && GetBRep().FrustumCull(this, null, display.LightCamera(), true))
63556486 {
63566487 //System.out.print("CULLED");
....@@ -6498,7 +6629,7 @@
64986629 }
64996630 }
65006631
6501
- assert (!(this instanceof Composite));
6632
+ // Bezier surface: assert (!(this instanceof Composite));
65026633 {
65036634 // CRASH MOCAP!! for (int i = 0; i < size(); i++)
65046635 // {
....@@ -6772,15 +6903,18 @@
67726903
67736904 void DrawNode(iCameraPane display, Object3D /*Composite*/ root, boolean selected)
67746905 {
6775
- if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
6776
- return; // no shadow for transparent objects
6777
-
6778
- if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6779
- return;
6906
+ if (!compiling)
6907
+ {
6908
+ if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
6909
+ return; // no shadow for transparent objects
6910
+
6911
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6912
+ return;
6913
+ }
67806914
67816915 if (hide)
67826916 return;
6783
-
6917
+
67846918 if (scriptnode != null)
67856919 {
67866920 scriptnode.DrawNode(display, root, selected);
....@@ -6823,7 +6957,8 @@
68236957
68246958 //javax.media.opengl.GL gl = display.GetGL();
68256959
6826
- if (CameraPane.BOXMODE && !selected) // || CameraPane.movingcamera)
6960
+ if (CameraPane.BOXMODE && !Link2Support()) //
6961
+ //!selected) // || CameraPane.movingcamera)
68276962 {
68286963 int fc = bRep.FaceCount();
68296964 int vc = bRep.VertexCount();
....@@ -6985,7 +7120,7 @@
69857120 facescompare[k] = new FaceCompare(k);
69867121 }
69877122
6988
- center = new cVector();
7123
+ centertriangle = new cVector();
69897124 }
69907125 else
69917126 {
....@@ -7108,7 +7243,7 @@
71087243 */
71097244 }
71107245
7111
- transient cVector center;
7246
+ transient cVector centertriangle;
71127247
71137248 class FaceCompare implements Comparable
71147249 {
....@@ -7137,14 +7272,14 @@
71377272 Vertex q = bRep.GetVertex(face.q);
71387273 Vertex r = bRep.GetVertex(face.r);
71397274
7140
- center.set(p);
7141
- center.add(q);
7142
- center.add(r);
7143
- center.mul(1.0/3);
7275
+ centertriangle.set(p);
7276
+ centertriangle.add(q);
7277
+ centertriangle.add(r);
7278
+ centertriangle.mul(1.0/3);
71447279
7145
- center.sub(Globals.theRenderer.EyeCamera().location);
7280
+ centertriangle.sub(Globals.theRenderer.EyeCamera().location);
71467281
7147
- distance = center.dot(center);
7282
+ distance = centertriangle.dot(centertriangle);
71487283 }
71497284
71507285 return distance;
....@@ -8315,7 +8450,7 @@
83158450 objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
83168451 } else
83178452 {
8318
- objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count - 1) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
8453
+ objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + ((bRep==null)?(count - 1):bRep.VertexCount()) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
83198454 } // + super.toString();
83208455 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
83218456
....@@ -8327,7 +8462,7 @@
83278462
83288463 public int hashCode()
83298464 {
8330
- // Fuck Vector...
8465
+ // Do not use Vector...
83318466 return System.identityHashCode(this);
83328467 }
83338468
....@@ -8869,7 +9004,7 @@
88699004 double diry = ray.viewDirection.y;
88709005 double dirz = ray.viewDirection.z;
88719006
8872
- if (this.fromParent != null)
9007
+ if (this.fromParent != null && !(this instanceof TextureNode))
88739008 {
88749009 eye.x = eyex;
88759010 eye.y = eyey;
....@@ -8894,7 +9029,7 @@
88949029
88959030 boolean touch = false;
88969031
8897
- if (bRep != null)
9032
+ if (bRep != null && Link2Support())
88989033 {
88999034 if (bbox == null)
89009035 {
....@@ -8903,7 +9038,7 @@
89039038 cVector min = new cVector();
89049039 cVector max = new cVector();
89059040
8906
- this.getBounds(min, max, false);
9041
+ this.getBounds(min, max, true);
89079042
89089043 bbox.min.x = min.x;
89099044 bbox.min.y = min.y;
....@@ -8914,7 +9049,7 @@
89149049 bbox.max.z = max.z;
89159050 }
89169051
8917
- if (bbox.intersect(ray, result))
9052
+ if (true) // NOT WORKING bbox.intersect(ray, result))
89189053 {
89199054 success |= intersectMesh(ray, result);
89209055 }
....@@ -8958,6 +9093,12 @@
89589093
89599094 private boolean intersectTriangle(Ray ray, IntersectResult result, Vertex v1, Vertex v2, Vertex v3)
89609095 {
9096
+ if (false)
9097
+ {
9098
+ result.t = 0;
9099
+ return true;
9100
+ }
9101
+
89619102 /*
89629103 Fast, Minimum Storage Ray/Triangle Intersection, Moller et al.
89639104
....@@ -9125,5 +9266,17 @@
91259266 return -1;
91269267 }
91279268 */
9269
+
9270
+ void Translate(double x, double y, double z)
9271
+ {
9272
+ if (toParent == null)
9273
+ {
9274
+ toParent = LA.newMatrix();
9275
+ fromParent = LA.newMatrix();
9276
+ }
9277
+
9278
+ LA.matTranslate(toParent, x, y, z);
9279
+ LA.matTranslateInv(fromParent, -x, -y, -z);
9280
+ }
91289281 }
91299282