Normand Briere
2019-10-20 49d9c15d375942997692f7fccfb697665d0cb59e
Object3D.java
....@@ -45,6 +45,20 @@
4545
4646 ScriptNode scriptnode;
4747
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
+
4862 void deepCopyNode(Object3D other)
4963 {
5064 other.skyboxname = skyboxname;
....@@ -659,27 +673,74 @@
659673 return this;
660674 }
661675
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
+
662697 void SortBySize()
663698 {
664
- 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();
665721
666
- while (!sorted)
722
+ if (sizecompare == null || sizecompare.length != count)
667723 {
668
- sorted = true;
669
-
670
- for (int i=0; i<Size()-1; i++)
724
+ sizecompare = new SizeCompare[count];
725
+
726
+ for (int k=0; k<count; k++)
671727 {
672
- Object3D obji = get(i);
673
- Object3D objj = get(i+1);
674
-
675
- if (obji.MemorySize() < objj.MemorySize())
676
- {
677
- set(i, objj);
678
- set(i+1, obji);
679
-
680
- sorted = false;
681
- }
728
+ sizecompare[k] = new SizeCompare(get(k));
682729 }
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);
683744 }
684745 }
685746
....@@ -711,34 +772,59 @@
711772
712773 int MemorySize()
713774 {
714
- 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)
715805 {
716
- try
717
- {
718
- Object3D obj = this;
806
+ return 0;
807
+ }
719808
720
- Object3D parent = obj.parent;
721
- obj.parent = null;
722
- Object3D support = obj.support;
723
- obj.support = null;
724
-
725
- java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
726
- java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(baos);
727
-
728
- out.writeObject(obj);
729
-
730
- obj.parent = parent;
731
- obj.support = support;
732
-
733
- memorysize = baos.toByteArray().length;
734
- }
735
- catch (Exception e)
736
- {
737
- e.printStackTrace();
738
- }
809
+ int memory = 0;
810
+
811
+ if (bRep != null)
812
+ {
813
+ memory = bRep.VertexCount();
739814 }
740815
741
- 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;
742828 }
743829
744830 void Slower()
....@@ -6193,6 +6279,8 @@
61936279 static cVector maxima = new cVector();
61946280 static javax.vecmath.Point3d center = new javax.vecmath.Point3d();
61956281
6282
+ boolean compiling;
6283
+
61966284 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
61976285 {
61986286 Invariants(); // june 2013
....@@ -6278,7 +6366,8 @@
62786366
62796367 boolean usecalllists = !IsDynamic() &&
62806368 IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !Link2Support()); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6281
- //boolean usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6369
+
6370
+ //usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
62826371
62836372 //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass.
62846373
....@@ -6332,7 +6421,9 @@
63326421 display.NewList(bRep.displaylist);
63336422 }
63346423
6424
+ compiling = true;
63356425 CallList(display, root, selected, blocked);
6426
+ compiling = false;
63366427
63376428 // compiled = true;
63386429 if (usecalllists && bRep.displaylist > 0)
....@@ -6807,14 +6898,17 @@
68076898
68086899 void DrawNode(iCameraPane display, Object3D /*Composite*/ root, boolean selected)
68096900 {
6810
- if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
6811
- return; // no shadow for transparent objects
6812
-
6813
- if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6814
- return;
6815
-
6816
- if (hide)
6817
- return;
6901
+ if (!compiling)
6902
+ {
6903
+ if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
6904
+ return; // no shadow for transparent objects
6905
+
6906
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6907
+ return;
6908
+
6909
+ if (hide)
6910
+ return;
6911
+ }
68186912
68196913 if (scriptnode != null)
68206914 {
....@@ -8351,7 +8445,7 @@
83518445 objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
83528446 } else
83538447 {
8354
- objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count - 1) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
8448
+ objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + ((bRep==null)?(count - 1):bRep.VertexCount()) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
83558449 } // + super.toString();
83568450 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
83578451