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;
....@@ -657,27 +673,74 @@
657673 return this;
658674 }
659675
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
+
660697 void SortBySize()
661698 {
662
- 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();
663721
664
- while (!sorted)
722
+ if (sizecompare == null || sizecompare.length != count)
665723 {
666
- sorted = true;
667
-
668
- for (int i=0; i<Size()-1; i++)
724
+ sizecompare = new SizeCompare[count];
725
+
726
+ for (int k=0; k<count; k++)
669727 {
670
- Object3D obji = get(i);
671
- Object3D objj = get(i+1);
672
-
673
- if (obji.MemorySize() < objj.MemorySize())
674
- {
675
- set(i, objj);
676
- set(i+1, obji);
677
-
678
- sorted = false;
679
- }
728
+ sizecompare[k] = new SizeCompare(get(k));
680729 }
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);
681744 }
682745 }
683746
....@@ -709,34 +772,59 @@
709772
710773 int MemorySize()
711774 {
712
- 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)
713805 {
714
- try
715
- {
716
- Object3D obj = this;
806
+ return 0;
807
+ }
717808
718
- Object3D parent = obj.parent;
719
- obj.parent = null;
720
- Object3D support = obj.support;
721
- obj.support = null;
722
-
723
- java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
724
- java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(baos);
725
-
726
- out.writeObject(obj);
727
-
728
- obj.parent = parent;
729
- obj.support = support;
730
-
731
- memorysize = baos.toByteArray().length;
732
- }
733
- catch (Exception e)
734
- {
735
- e.printStackTrace();
736
- }
809
+ int memory = 0;
810
+
811
+ if (bRep != null)
812
+ {
813
+ memory = bRep.VertexCount();
737814 }
738815
739
- 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;
740828 }
741829
742830 void Slower()
....@@ -1061,7 +1149,7 @@
10611149 transformcount++;
10621150 }
10631151
1064
- int maxcount;
1152
+ int maxcount = 128;
10651153 int transformcount;
10661154 int step;
10671155
....@@ -1114,7 +1202,10 @@
11141202 if (step == 0)
11151203 step = 1;
11161204 if (maxcount == 0)
1117
- maxcount = 128; // 2048; // 4;
1205
+ {
1206
+ System.out.println("maxcount == 0");
1207
+ System.exit(0); // maxcount = 128; // 2048; // 4;
1208
+ }
11181209 // if (acceleration == 0)
11191210 // acceleration = 10;
11201211 if (delay == 0) // serial
....@@ -1140,6 +1231,8 @@
11401231 (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || !Globals.COMPUTESHADOWWHENLIVE) &&
11411232 currentframe != Globals.framecount)
11421233 {
1234
+ Globals.lighttouched = true;
1235
+
11431236 currentframe = Globals.framecount;
11441237
11451238 // System.err.println("transformcount = " + transformcount);
....@@ -1424,7 +1517,7 @@
14241517
14251518 blockloop = true;
14261519
1427
- other.parent = parent;
1520
+ // other.parent = parent;
14281521
14291522 //System.out.println("COPY " + this + " to " + other);
14301523 //new Exception().printStackTrace();
....@@ -1460,7 +1553,7 @@
14601553 Object3D obj = (Object3D)Children().get(i);
14611554 if (IsContainedIn(obj))
14621555 {
1463
-// assert(false); // ?!?!?!?!?!
1556
+ assert(false); // ?!?!?!?!?!
14641557 c.Children().setElementAt(c, i);
14651558 }
14661559 else
....@@ -2558,7 +2651,7 @@
25582651 return b;
25592652 }
25602653
2561
- void UpdateMaterial(cMaterial anchor, cMaterial current, boolean propagate)
2654
+ void UpdateMaterial(cMaterial anchor, cMaterial current, boolean propagate, boolean colorparallax)
25622655 {
25632656 if (blockloop)
25642657 {
....@@ -2568,7 +2661,7 @@
25682661 // super.UpdateMaterial(anchor, current, false);
25692662 if (material != null)
25702663 {
2571
- material.UpdateMaterial(anchor, current);
2664
+ material.UpdateMaterial(anchor, current, colorparallax);
25722665 }
25732666
25742667 if (!propagate)
....@@ -2582,7 +2675,7 @@
25822675 if (child == null)
25832676 continue;
25842677 blockloop = true;
2585
- child.UpdateMaterial(anchor, current, propagate);
2678
+ child.UpdateMaterial(anchor, current, propagate, false);
25862679 blockloop = false;
25872680 Children().release(i);
25882681 }
....@@ -2596,7 +2689,7 @@
25962689 if (child == null)
25972690 continue;
25982691 blockloop = true;
2599
- child.UpdateMaterial(anchor, current, propagate);
2692
+ child.UpdateMaterial(anchor, current, propagate, false);
26002693 blockloop = false;
26012694 Children().release(i);
26022695 }
....@@ -3417,7 +3510,7 @@
34173510 }
34183511 }
34193512
3420
- public void Scale(int scale)
3513
+ public void Scale(float scale)
34213514 {
34223515 Object3D obj = this;
34233516
....@@ -5621,8 +5714,9 @@
56215714 {
56225715 }
56235716 // transient int displaylist = 0; // -1;
5624
- transient boolean touched = true;
5625
- 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
56265720
56275721 void Touch()
56285722 {
....@@ -5675,6 +5769,7 @@
56755769 {
56765770 //System.out.println("HardTouch " + this); // new Exception().printStackTrace();
56775771 //new Exception().printStackTrace();
5772
+ reset = true;
56785773 touched = true;
56795774 CameraPane.touched = true;
56805775 //if (parent != null)
....@@ -6189,6 +6284,8 @@
61896284 static cVector maxima = new cVector();
61906285 static javax.vecmath.Point3d center = new javax.vecmath.Point3d();
61916286
6287
+ boolean compiling;
6288
+
61926289 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
61936290 {
61946291 Invariants(); // june 2013
....@@ -6198,7 +6295,7 @@
61986295 // System.err.println("Draw " + this + " Frame # " + ((Mocap)((Merge)support).object).frame);
61996296 }
62006297
6201
- if (live && Link2Support() && support == null && !this.marked) // project on ground
6298
+ if (false) // live && Link2Support() && support == null && !this.marked) // project on ground
62026299 {
62036300 getBounds(minima, maxima, true);
62046301 center.x = (minima.x + maxima.x) / 2;
....@@ -6274,7 +6371,8 @@
62746371
62756372 boolean usecalllists = !IsDynamic() &&
62766373 IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !Link2Support()); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6277
- //boolean usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(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);
62786376
62796377 //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass.
62806378
....@@ -6299,7 +6397,7 @@
62996397
63006398 if (!selectmode && //display.DrawMode() != display.SELECTION &&
63016399 //(touched || (bRep != null && bRep.displaylist <= 0)))
6302
- (Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE || touched && Globals.COMPUTESHADOWWHENLIVE)) // || (bRep != null && bRep.displaylist <= 0)))
6400
+ ((Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE) || touched)) // || (bRep != null && bRep.displaylist <= 0)))
63036401 {
63046402 Globals.lighttouched = true;
63056403 } // all panes...
....@@ -6328,7 +6426,9 @@
63286426 display.NewList(bRep.displaylist);
63296427 }
63306428
6429
+ compiling = true;
63316430 CallList(display, root, selected, blocked);
6431
+ compiling = false;
63326432
63336433 // compiled = true;
63346434 if (usecalllists && bRep.displaylist > 0)
....@@ -6529,7 +6629,7 @@
65296629 }
65306630 }
65316631
6532
- assert (!(this instanceof Composite));
6632
+ // Bezier surface: assert (!(this instanceof Composite));
65336633 {
65346634 // CRASH MOCAP!! for (int i = 0; i < size(); i++)
65356635 // {
....@@ -6803,15 +6903,18 @@
68036903
68046904 void DrawNode(iCameraPane display, Object3D /*Composite*/ root, boolean selected)
68056905 {
6806
- if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
6807
- return; // no shadow for transparent objects
6808
-
6809
- if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6810
- 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
+ }
68116914
68126915 if (hide)
68136916 return;
6814
-
6917
+
68156918 if (scriptnode != null)
68166919 {
68176920 scriptnode.DrawNode(display, root, selected);
....@@ -6854,7 +6957,8 @@
68546957
68556958 //javax.media.opengl.GL gl = display.GetGL();
68566959
6857
- if (CameraPane.BOXMODE && !Link2Support()) //selected) // || CameraPane.movingcamera)
6960
+ if (CameraPane.BOXMODE && !Link2Support()) //
6961
+ //!selected) // || CameraPane.movingcamera)
68586962 {
68596963 int fc = bRep.FaceCount();
68606964 int vc = bRep.VertexCount();
....@@ -8346,7 +8450,7 @@
83468450 objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
83478451 } else
83488452 {
8349
- 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) ":"") */ "";
83508454 } // + super.toString();
83518455 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
83528456
....@@ -9162,5 +9266,17 @@
91629266 return -1;
91639267 }
91649268 */
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
+ }
91659281 }
91669282