Normand Briere
2019-11-17 cb37a129d1adb403019c96e798e86e2da9667f15
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.link2master = link2master;
119
+ other.link2master = Link2Support();
104120 other.transformcount = transformcount;
105121 other.marked = marked;
106122 other.skip = skip;
....@@ -140,6 +156,7 @@
140156 projectedVertices[i] = new cVector2(); // Others
141157 }
142158 projectedVertices[0].x = 100; // bump
159
+ projectedVertices[1].y = 1000; // punchthrough. only for png
143160 }
144161
145162 void MinMax(cVector minima, cVector maxima)
....@@ -219,7 +236,7 @@
219236 return;
220237
221238 transientsupport = support;
222
- transientlink2master = link2master;
239
+ transientlink2master = Link2Support();
223240
224241 support = null;
225242 link2master = false;
....@@ -632,7 +649,10 @@
632649 transient boolean keepdontselect;
633650 boolean dontselect = false;
634651 boolean hide = false;
635
- boolean link2master = 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
+
636656 boolean marked = false; // animation node
637657 boolean skip = false; // centroid issue
638658 boolean skipmocap = false; // mocap data
....@@ -640,6 +660,9 @@
640660 boolean random = false;
641661 boolean speedup = false;
642662 boolean rewind = false;
663
+
664
+ // Option to sort triangles, e.g. for transparency.
665
+ boolean sort = false;
643666
644667 float NORMALPUSH = 0;
645668
....@@ -650,27 +673,74 @@
650673 return this;
651674 }
652675
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
+
653697 void SortBySize()
654698 {
655
- 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();
656721
657
- while (!sorted)
722
+ if (sizecompare == null || sizecompare.length != count)
658723 {
659
- sorted = true;
660
-
661
- for (int i=0; i<size()-1; i++)
724
+ sizecompare = new SizeCompare[count];
725
+
726
+ for (int k=0; k<count; k++)
662727 {
663
- Object3D obji = get(i);
664
- Object3D objj = get(i+1);
665
-
666
- if (obji.MemorySize() < objj.MemorySize())
667
- {
668
- set(i, objj);
669
- set(i+1, obji);
670
-
671
- sorted = false;
672
- }
728
+ sizecompare[k] = new SizeCompare(get(k));
673729 }
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);
674744 }
675745 }
676746
....@@ -682,7 +752,7 @@
682752 {
683753 sorted = true;
684754
685
- for (int i=0; i<size()-1; i++)
755
+ for (int i=0; i<Size()-1; i++)
686756 {
687757 Object3D obji = get(i);
688758 Object3D objj = get(i+1);
....@@ -702,34 +772,59 @@
702772
703773 int MemorySize()
704774 {
705
- 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)
706805 {
707
- try
708
- {
709
- Object3D obj = this;
806
+ return 0;
807
+ }
710808
711
- Object3D parent = obj.parent;
712
- obj.parent = null;
713
- Object3D support = obj.support;
714
- obj.support = null;
715
-
716
- java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
717
- java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(baos);
718
-
719
- out.writeObject(obj);
720
-
721
- obj.parent = parent;
722
- obj.support = support;
723
-
724
- memorysize = baos.toByteArray().length;
725
- }
726
- catch (Exception e)
727
- {
728
- e.printStackTrace();
729
- }
809
+ int memory = 0;
810
+
811
+ if (bRep != null)
812
+ {
813
+ memory = bRep.VertexCount();
730814 }
731815
732
- 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;
733828 }
734829
735830 void Slower()
....@@ -1019,7 +1114,7 @@
10191114
10201115 void Step()
10211116 {
1022
- // marde pour serialization de Texture
1117
+ // patch pour serialization de Texture
10231118 resetmaxcount();
10241119 resettransformcount();
10251120 resetstep();
....@@ -1054,7 +1149,7 @@
10541149 transformcount++;
10551150 }
10561151
1057
- int maxcount;
1152
+ int maxcount = 128;
10581153 int transformcount;
10591154 int step;
10601155
....@@ -1107,7 +1202,10 @@
11071202 if (step == 0)
11081203 step = 1;
11091204 if (maxcount == 0)
1110
- maxcount = 128; // 2048; // 4;
1205
+ {
1206
+ System.out.println("maxcount == 0");
1207
+ System.exit(0); // maxcount = 128; // 2048; // 4;
1208
+ }
11111209 // if (acceleration == 0)
11121210 // acceleration = 10;
11131211 if (delay == 0) // serial
....@@ -1133,6 +1231,8 @@
11331231 (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || !Globals.COMPUTESHADOWWHENLIVE) &&
11341232 currentframe != Globals.framecount)
11351233 {
1234
+ Globals.lighttouched = true;
1235
+
11361236 currentframe = Globals.framecount;
11371237
11381238 // System.err.println("transformcount = " + transformcount);
....@@ -1212,24 +1312,28 @@
12121312 {
12131313 // return true;
12141314
1215
- if (material == null || material.multiply)
1216
- return true;
1315
+// if (material == null || material.multiply)
1316
+// return true;
1317
+//
1318
+// if (projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
1319
+// return false;
1320
+//
1321
+// // Transparent objects are dynamic because we have to sort the triangles.
1322
+// return material.opacity > 0.99;
12171323
1218
- if (projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
1219
- return false;
1220
-
1221
- // Transparent objects are dynamic because we have to sort the triangles.
1222
- return material.opacity > 0.99;
1324
+ return !sort;
12231325 }
12241326
12251327 boolean IsOpaque()
12261328 {
12271329 // return true;
12281330
1229
- if (material == null || material.multiply)
1230
- return true;
1331
+// if (material == null || material.multiply)
1332
+// return true;
1333
+//
1334
+// return material.opacity > 0.99;
12311335
1232
- return material.opacity > 0.99;
1336
+ return !sort;
12331337 }
12341338
12351339 Object3D()
....@@ -1413,7 +1517,7 @@
14131517
14141518 blockloop = true;
14151519
1416
- other.parent = parent;
1520
+ // other.parent = parent;
14171521
14181522 //System.out.println("COPY " + this + " to " + other);
14191523 //new Exception().printStackTrace();
....@@ -1449,7 +1553,7 @@
14491553 Object3D obj = (Object3D)Children().get(i);
14501554 if (IsContainedIn(obj))
14511555 {
1452
-// assert(false); // ?!?!?!?!?!
1556
+ assert(false); // ?!?!?!?!?!
14531557 c.Children().setElementAt(c, i);
14541558 }
14551559 else
....@@ -2547,7 +2651,7 @@
25472651 return b;
25482652 }
25492653
2550
- void UpdateMaterial(cMaterial anchor, cMaterial current, boolean propagate)
2654
+ void UpdateMaterial(cMaterial anchor, cMaterial current, boolean propagate, boolean colorparallax)
25512655 {
25522656 if (blockloop)
25532657 {
....@@ -2557,7 +2661,7 @@
25572661 // super.UpdateMaterial(anchor, current, false);
25582662 if (material != null)
25592663 {
2560
- material.UpdateMaterial(anchor, current);
2664
+ material.UpdateMaterial(anchor, current, colorparallax);
25612665 }
25622666
25632667 if (!propagate)
....@@ -2571,7 +2675,7 @@
25712675 if (child == null)
25722676 continue;
25732677 blockloop = true;
2574
- child.UpdateMaterial(anchor, current, propagate);
2678
+ child.UpdateMaterial(anchor, current, propagate, false);
25752679 blockloop = false;
25762680 Children().release(i);
25772681 }
....@@ -2585,7 +2689,7 @@
25852689 if (child == null)
25862690 continue;
25872691 blockloop = true;
2588
- child.UpdateMaterial(anchor, current, propagate);
2692
+ child.UpdateMaterial(anchor, current, propagate, false);
25892693 blockloop = false;
25902694 Children().release(i);
25912695 }
....@@ -3406,7 +3510,7 @@
34063510 }
34073511 }
34083512
3409
- public void Scale(int scale)
3513
+ public void Scale(float scale)
34103514 {
34113515 Object3D obj = this;
34123516
....@@ -4040,6 +4144,7 @@
40404144
40414145 void RevertMeshes()
40424146 {
4147
+ // BLOCKLOOP
40434148 if (this instanceof cMesh)
40444149 {
40454150 ((cMesh)this).Revert();
....@@ -4070,11 +4175,6 @@
40704175 Touch();
40714176 }
40724177
4073
- ResetRecur();
4074
- }
4075
-
4076
- void ResetRecur()
4077
- {
40784178 for (int i = 0; i < size(); i++)
40794179 {
40804180 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -4097,11 +4197,6 @@
40974197 Step();
40984198 Touch();
40994199
4100
- StepRecur();
4101
- }
4102
-
4103
- void StepRecur()
4104
- {
41054200 for (int i = 0; i < size(); i++)
41064201 {
41074202 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -4288,8 +4383,8 @@
42884383 Touch();
42894384 }
42904385
4291
- transient cVector min = new cVector();
4292
- transient cVector max = new cVector();
4386
+ transient cVector min;
4387
+ transient cVector max;
42934388
42944389 void getBounds(cVector minima, cVector maxima, boolean xform)
42954390 {
....@@ -4305,7 +4400,7 @@
43054400 if (blockloop)
43064401 return;
43074402
4308
- if (min == null) // ???
4403
+ if (min == null)
43094404 {
43104405 min = new cVector();
43114406 max = new cVector();
....@@ -4346,7 +4441,7 @@
43464441
43474442 if (bRep != null)
43484443 {
4349
- bRep.getBounds(minima,maxima,this);
4444
+ bRep.getBounds(minima, maxima, xform?this:null);
43504445 }
43514446
43524447 if (false) // xform)
....@@ -5619,8 +5714,9 @@
56195714 {
56205715 }
56215716 // transient int displaylist = 0; // -1;
5622
- transient boolean touched = true;
5623
- 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
56245720
56255721 void Touch()
56265722 {
....@@ -5673,6 +5769,7 @@
56735769 {
56745770 //System.out.println("HardTouch " + this); // new Exception().printStackTrace();
56755771 //new Exception().printStackTrace();
5772
+ reset = true;
56765773 touched = true;
56775774 CameraPane.touched = true;
56785775 //if (parent != null)
....@@ -6155,7 +6252,7 @@
61556252 boolean NeedSupport()
61566253 {
61576254 return
6158
- CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && link2master && /*live &&*/ support != null
6255
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && Link2Support() && /*live &&*/ support != null
61596256 // PROBLEM with CROWD!!
61606257 && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
61616258 }
....@@ -6178,6 +6275,17 @@
61786275 return live && bRep != null;
61796276 }
61806277
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
+
61816289 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
61826290 {
61836291 Invariants(); // june 2013
....@@ -6185,6 +6293,29 @@
61856293 if (support != null)
61866294 {
61876295 // 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
+ }
61886319 }
61896320
61906321 if (display.DrawMode() == iCameraPane.SELECTION &&
....@@ -6239,8 +6370,9 @@
62396370 support = support;
62406371
62416372 boolean usecalllists = !IsDynamic() &&
6242
- IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6243
- //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);
62446376
62456377 //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass.
62466378
....@@ -6250,7 +6382,8 @@
62506382 bRep.displaylist = 0;
62516383 }
62526384 // usecalllists &= !(parent instanceof RandomNode);
6253
- // usecalllists = false;
6385
+ if (CameraPane.BOXMODE) // Too dynamic
6386
+ usecalllists = false;
62546387
62556388 if (display.DrawMode() == display.SHADOW)
62566389 //GetBRep() != null)
....@@ -6264,7 +6397,7 @@
62646397
62656398 if (!selectmode && //display.DrawMode() != display.SELECTION &&
62666399 //(touched || (bRep != null && bRep.displaylist <= 0)))
6267
- (Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE || touched && Globals.COMPUTESHADOWWHENLIVE)) // || (bRep != null && bRep.displaylist <= 0)))
6400
+ ((Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE) || touched)) // || (bRep != null && bRep.displaylist <= 0)))
62686401 {
62696402 Globals.lighttouched = true;
62706403 } // all panes...
....@@ -6293,7 +6426,9 @@
62936426 display.NewList(bRep.displaylist);
62946427 }
62956428
6429
+ compiling = true;
62966430 CallList(display, root, selected, blocked);
6431
+ compiling = false;
62976432
62986433 // compiled = true;
62996434 if (usecalllists && bRep.displaylist > 0)
....@@ -6306,8 +6441,8 @@
63066441 Globals.lighttouched = true; // all panes...
63076442 }
63086443
6309
- touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
6310
- //touched = false;
6444
+ //touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
6445
+ touched = false;
63116446
63126447 if (this instanceof Texture || this instanceof TextureNode)
63136448 {
....@@ -6346,7 +6481,7 @@
63466481 {
63476482 if (display.DrawMode() == iCameraPane.SHADOW)
63486483 {
6349
- if (!link2master // tricky to cull in shadow mode.
6484
+ if (!Link2Support() // tricky to cull in shadow mode.
63506485 && GetBRep().FrustumCull(this, null, display.LightCamera(), true))
63516486 {
63526487 //System.out.print("CULLED");
....@@ -6454,6 +6589,7 @@
64546589 boolean failedPigment = false;
64556590 boolean failedBump = false;
64566591
6592
+ CameraPane.lastObject = this;
64576593 try
64586594 {
64596595 display.BindPigmentTexture(tex, texres);
....@@ -6493,7 +6629,7 @@
64936629 }
64946630 }
64956631
6496
- assert (!(this instanceof Composite));
6632
+ // Bezier surface: assert (!(this instanceof Composite));
64976633 {
64986634 // CRASH MOCAP!! for (int i = 0; i < size(); i++)
64996635 // {
....@@ -6767,15 +6903,18 @@
67676903
67686904 void DrawNode(iCameraPane display, Object3D /*Composite*/ root, boolean selected)
67696905 {
6770
- if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
6771
- return; // no shadow for transparent objects
6772
-
6773
- if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6774
- 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
+ }
67756914
67766915 if (hide)
67776916 return;
6778
-
6917
+
67796918 if (scriptnode != null)
67806919 {
67816920 scriptnode.DrawNode(display, root, selected);
....@@ -6818,7 +6957,8 @@
68186957
68196958 //javax.media.opengl.GL gl = display.GetGL();
68206959
6821
- if (CameraPane.BOXMODE && !selected) // || CameraPane.movingcamera)
6960
+ if (CameraPane.BOXMODE && !Link2Support()) //
6961
+ //!selected) // || CameraPane.movingcamera)
68226962 {
68236963 int fc = bRep.FaceCount();
68246964 int vc = bRep.VertexCount();
....@@ -6980,7 +7120,7 @@
69807120 facescompare[k] = new FaceCompare(k);
69817121 }
69827122
6983
- center = new cVector();
7123
+ centertriangle = new cVector();
69847124 }
69857125 else
69867126 {
....@@ -7103,7 +7243,7 @@
71037243 */
71047244 }
71057245
7106
- transient cVector center;
7246
+ transient cVector centertriangle;
71077247
71087248 class FaceCompare implements Comparable
71097249 {
....@@ -7132,14 +7272,14 @@
71327272 Vertex q = bRep.GetVertex(face.q);
71337273 Vertex r = bRep.GetVertex(face.r);
71347274
7135
- center.set(p);
7136
- center.add(q);
7137
- center.add(r);
7138
- center.mul(1.0/3);
7275
+ centertriangle.set(p);
7276
+ centertriangle.add(q);
7277
+ centertriangle.add(r);
7278
+ centertriangle.mul(1.0/3);
71397279
7140
- center.sub(Globals.theRenderer.EyeCamera().location);
7280
+ centertriangle.sub(Globals.theRenderer.EyeCamera().location);
71417281
7142
- distance = center.dot(center);
7282
+ distance = centertriangle.dot(centertriangle);
71437283 }
71447284
71457285 return distance;
....@@ -8310,7 +8450,7 @@
83108450 objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
83118451 } else
83128452 {
8313
- 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) ":"") */ "";
83148454 } // + super.toString();
83158455 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
83168456
....@@ -8322,7 +8462,7 @@
83228462
83238463 public int hashCode()
83248464 {
8325
- // Fuck Vector...
8465
+ // Do not use Vector...
83268466 return System.identityHashCode(this);
83278467 }
83288468
....@@ -8562,8 +8702,8 @@
85628702 private static cVector2 qq2 = new cVector2();
85638703 private static cVector2 rr2 = new cVector2();
85648704 private static cVector2 ss2 = new cVector2();
8565
- private static cVector edge1 = new cVector();
8566
- private static cVector edge2 = new cVector();
8705
+// private static cVector edge1 = new cVector();
8706
+// private static cVector edge2 = new cVector();
85678707 //private static cVector norm = new cVector();
85688708 /*transient private*/ int hitSomething;
85698709 static final int hitCenter = 1;
....@@ -8761,7 +8901,275 @@
87618901
87628902 Touch();
87638903 }
8904
+
8905
+ static Vertex s1 = new Vertex();
8906
+ static Vertex s2 = new Vertex();
8907
+ static Vertex s3 = new Vertex();
87648908
8909
+ boolean intersectMesh(Ray ray, IntersectResult result)
8910
+ {
8911
+ boolean success = false;
8912
+
8913
+ if (bRep.stripified)
8914
+ {
8915
+ int[] strips = bRep.getRawIndices();
8916
+
8917
+ // TRIANGLE STRIP ARRAY
8918
+ if (bRep.trimmed)
8919
+ {
8920
+ float[] v = bRep.getRawVertices();
8921
+
8922
+ int count3 = 0;
8923
+
8924
+ if (v.length > 0)
8925
+ {
8926
+ for (int i = 0; i < strips.length; i++)
8927
+ {
8928
+ s1.set(v[count3], v[count3 + 1], v[count3 + 2]);
8929
+ count3 += 3;
8930
+
8931
+ s2.set(v[count3], v[count3 + 1], v[count3 + 2]);
8932
+ count3 += 3;
8933
+
8934
+ for (int j = 0; j < strips[i] - 2; j++)
8935
+ {
8936
+ s3.set(v[count3], v[count3 + 1], v[count3 + 2]);
8937
+ count3 += 3;
8938
+
8939
+ if (j%2 == 0)
8940
+ success |= intersectTriangle(ray, result, s1, s2, s3);
8941
+ else
8942
+ success |= intersectTriangle(ray, result, s1, s3, s2);
8943
+
8944
+ s1.set(s2);
8945
+ s2.set(s3);
8946
+ }
8947
+ }
8948
+ }
8949
+
8950
+ assert count3 == v.length;
8951
+ }
8952
+ else // !trimmed
8953
+ {
8954
+ int count = 0;
8955
+ for (int i = 0; i < strips.length; i++)
8956
+ {
8957
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
8958
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
8959
+
8960
+ for (int j = 0; j < strips[i] - 2; j++)
8961
+ {
8962
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
8963
+
8964
+ if (j%2 == 0)
8965
+ success |= intersectTriangle(ray, result, p, q, r);
8966
+ else
8967
+ success |= intersectTriangle(ray, result, p, r, q);
8968
+
8969
+ p = q;
8970
+ q = r;
8971
+ }
8972
+ }
8973
+ }
8974
+ } else // catch (Error e)
8975
+ {
8976
+ int facecount = bRep.FaceCount();
8977
+ for (int i = 0; i < facecount; i++)
8978
+ {
8979
+ Face face = bRep.GetFace(i);
8980
+
8981
+ Vertex p = bRep.GetVertex(face.p);
8982
+ Vertex q = bRep.GetVertex(face.q);
8983
+ Vertex r = bRep.GetVertex(face.r);
8984
+
8985
+ success |= intersectTriangle(ray, result, p, q, r);
8986
+ }
8987
+ }
8988
+
8989
+ return success;
8990
+ }
8991
+
8992
+ static cVector eye = new cVector();
8993
+ static cVector dir = new cVector();
8994
+
8995
+ transient BBox bbox = null;
8996
+
8997
+ boolean intersect(Ray ray, IntersectResult result)
8998
+ {
8999
+ double eyex = ray.eyePoint.x;
9000
+ double eyey = ray.eyePoint.y;
9001
+ double eyez = ray.eyePoint.z;
9002
+
9003
+ double dirx = ray.viewDirection.x;
9004
+ double diry = ray.viewDirection.y;
9005
+ double dirz = ray.viewDirection.z;
9006
+
9007
+ if (this.fromParent != null && !(this instanceof TextureNode))
9008
+ {
9009
+ eye.x = eyex;
9010
+ eye.y = eyey;
9011
+ eye.z = eyez;
9012
+ dir.x = dirx;
9013
+ dir.y = diry;
9014
+ dir.z = dirz;
9015
+
9016
+ LA.xformPos(eye, this.fromParent, eye);
9017
+ LA.xformDir(dir, this.fromParent, dir);
9018
+
9019
+ ray.eyePoint.x = eye.x;
9020
+ ray.eyePoint.y = eye.y;
9021
+ ray.eyePoint.z = eye.z;
9022
+
9023
+ ray.viewDirection.x = dir.x;
9024
+ ray.viewDirection.y = dir.y;
9025
+ ray.viewDirection.z = dir.z;
9026
+ }
9027
+
9028
+ boolean success = false;
9029
+
9030
+ boolean touch = false;
9031
+
9032
+ if (bRep != null && Link2Support())
9033
+ {
9034
+ if (bbox == null)
9035
+ {
9036
+ bbox = new BBox();
9037
+
9038
+ cVector min = new cVector();
9039
+ cVector max = new cVector();
9040
+
9041
+ this.getBounds(min, max, true);
9042
+
9043
+ bbox.min.x = min.x;
9044
+ bbox.min.y = min.y;
9045
+ bbox.min.z = min.z;
9046
+
9047
+ bbox.max.x = max.x;
9048
+ bbox.max.y = max.y;
9049
+ bbox.max.z = max.z;
9050
+ }
9051
+
9052
+ if (true) // NOT WORKING bbox.intersect(ray, result))
9053
+ {
9054
+ success |= intersectMesh(ray, result);
9055
+ }
9056
+ else
9057
+ {
9058
+ //this.hide = true;
9059
+ touch = true;
9060
+ }
9061
+ }
9062
+
9063
+ for (int i=0; i<size(); i++)
9064
+ {
9065
+ Object3D child = (Object3D) reserve(i);
9066
+
9067
+ if (child == null)
9068
+ continue;
9069
+
9070
+ success |= child.intersect(ray, result);
9071
+ release(i);
9072
+ }
9073
+
9074
+ ray.eyePoint.x = eyex;
9075
+ ray.eyePoint.y = eyey;
9076
+ ray.eyePoint.z = eyez;
9077
+
9078
+ ray.viewDirection.x = dirx;
9079
+ ray.viewDirection.y = diry;
9080
+ ray.viewDirection.z = dirz;
9081
+
9082
+// if (touch)
9083
+// this.Touch(); // refresh display list
9084
+
9085
+ return success;
9086
+ }
9087
+
9088
+ static Vector3d edge1 = new Vector3d();
9089
+ static Vector3d edge2 = new Vector3d();
9090
+ static Vector3d P = new Vector3d();
9091
+ static Vector3d T = new Vector3d();
9092
+ static Vector3d Q = new Vector3d();
9093
+
9094
+ private boolean intersectTriangle(Ray ray, IntersectResult result, Vertex v1, Vertex v2, Vertex v3)
9095
+ {
9096
+ if (false)
9097
+ {
9098
+ result.t = 0;
9099
+ return true;
9100
+ }
9101
+
9102
+ /*
9103
+ Fast, Minimum Storage Ray/Triangle Intersection, Moller et al.
9104
+
9105
+ Reference: http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf
9106
+ */
9107
+
9108
+ // Calculate edges of the triangle
9109
+ edge1.set(v2.x - v1.x, v2.y - v1.y, v2.z - v1.z);
9110
+ edge2.set(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z);
9111
+
9112
+ // Calculate the determinant (U parameter)
9113
+ P.cross(ray.viewDirection, edge2);
9114
+ double det = edge1.dot(P);
9115
+
9116
+ if (det > -1e-9 && det < 1e-9)
9117
+ {
9118
+ return false;
9119
+ } // Ray lies in plane of triangle
9120
+
9121
+ double invDet = 1 / det;
9122
+
9123
+ // Calculate distance from vertex1 to ray origin
9124
+ T.set(ray.eyePoint.x - v1.x, ray.eyePoint.y - v1.y, ray.eyePoint.z - v1.z);
9125
+
9126
+ double U = (T.dot(P)) * invDet; // Calculate U parameter
9127
+
9128
+ if (U < 0.f || U > 1.f)
9129
+ {
9130
+ return false;
9131
+ } // Intersection lies outside of the triangle
9132
+
9133
+ // Calculate V parameter
9134
+ Q.cross(T, edge1);
9135
+
9136
+ double V = ray.viewDirection.dot(Q) * invDet;
9137
+
9138
+ if (V < 0.f || (U + V) > 1.f)
9139
+ {
9140
+ return false;
9141
+ } // Intersection lies outside of the triangle
9142
+
9143
+ double t = edge2.dot(Q) * invDet;
9144
+
9145
+ if (t > 1e-9) // Triangle and ray intersects
9146
+ {
9147
+ //result.isIntersected = true;
9148
+ //result.id = id;
9149
+
9150
+ if (false) // isShadow)
9151
+ {
9152
+ result.t = t;
9153
+ return true;
9154
+ } else if (t < result.t)
9155
+ {
9156
+ result.object = this;
9157
+
9158
+ result.t = t;
9159
+
9160
+ //result.p.x = ray.eyePoint.x + ray.viewDirection.x * t;
9161
+ //result.p.y = ray.eyePoint.y + ray.viewDirection.y * t;
9162
+ //result.p.z = ray.eyePoint.z + ray.viewDirection.z * t;
9163
+
9164
+ result.n.cross(edge1, edge2);
9165
+ result.n.normalize();
9166
+ }
9167
+
9168
+ return true;
9169
+ }
9170
+
9171
+ return false;
9172
+ }
87659173
87669174 public int Size()
87679175 {
....@@ -8858,5 +9266,17 @@
88589266 return -1;
88599267 }
88609268 */
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
+ }
88619281 }
88629282