Normand Briere
2019-06-24 c67da2e5d8655704601d6d06e8bc60aabe212253
Object3D.java
....@@ -14,11 +14,20 @@
1414 import //weka.core.
1515 matrix.Matrix;
1616
17
+import java.util.UUID;
18
+
1719 //import net.sourceforge.sizeof.SizeOf;
1820 public class Object3D extends Vector<Object3D> implements java.io.Serializable, iSendInfo //, aurelienribon.tweenengine.TweenAccessor<Object3D>
1921 {
2022 //static final long serialVersionUID = -607422624994562685L;
2123 static final long serialVersionUID = 5022536242724664900L;
24
+
25
+ private UUID uuid = UUID.randomUUID();
26
+
27
+ // TEMPORARY for mocap undo
28
+ mocap.reader.BVHReader.BVHResult bvh;
29
+ Object3D skeleton;
30
+ //
2231
2332 ScriptNode scriptnode;
2433
....@@ -100,64 +109,136 @@
100109
101110 // transient boolean reduced; // for morph reduction
102111
103
-transient com.bulletphysics.linearmath.Transform cache; // for fast merge
104
-transient com.bulletphysics.linearmath.Transform cache_1; // for fast merge
112
+ transient com.bulletphysics.linearmath.Transform cache; // for fast merge
113
+ transient com.bulletphysics.linearmath.Transform cache_1; // for fast merge
105114
106
-transient Object3D transientsupport; // for cloning
107
-transient boolean transientlink2master;
115
+ transient Object3D transientsupport; // for cloning
116
+ transient boolean transientlink2master;
108117
109
-void SaveSupports()
110
-{
111
- if (blockloop)
112
- return;
113
-
114
- transientsupport = support;
115
- transientlink2master = link2master;
116
-
117
- support = null;
118
- link2master = false;
119
-
120
- if (bRep != null)
118
+ void SaveSupports()
121119 {
122
- bRep.SaveSupports();
123
- }
124
-
125
- for (int i = 0; i < Size(); i++)
126
- {
127
- Object3D child = (Object3D) get(i);
128
- if (child == null)
129
- continue;
130
- blockloop = true;
131
- child.SaveSupports();
132
- blockloop = false;
133
- }
134
-}
120
+ if (blockloop)
121
+ return;
135122
136
-void RestoreSupports()
137
-{
138
- if (blockloop)
139
- return;
123
+ transientsupport = support;
124
+ transientlink2master = link2master;
140125
141
- support = transientsupport;
142
- link2master = transientlink2master;
143
- transientsupport = null;
144
- transientlink2master = false;
145
-
146
- if (bRep != null)
147
- {
148
- bRep.RestoreSupports();
126
+ support = null;
127
+ link2master = false;
128
+
129
+ if (bRep != null)
130
+ {
131
+ bRep.SaveSupports();
132
+ }
133
+
134
+ for (int i = 0; i < Size(); i++)
135
+ {
136
+ Object3D child = (Object3D) get(i);
137
+ if (child == null)
138
+ continue;
139
+ blockloop = true;
140
+ child.SaveSupports();
141
+ blockloop = false;
142
+ }
149143 }
150
-
151
- for (int i = 0; i < Size(); i++)
144
+
145
+ void RestoreSupports()
152146 {
153
- Object3D child = (Object3D) get(i);
154
- if (child == null)
155
- continue;
156
- blockloop = true;
157
- child.RestoreSupports();
158
- blockloop = false;
147
+ if (blockloop)
148
+ return;
149
+
150
+ support = transientsupport;
151
+ link2master = transientlink2master;
152
+ transientsupport = null;
153
+ transientlink2master = false;
154
+
155
+ if (bRep != null)
156
+ {
157
+ bRep.RestoreSupports();
158
+ }
159
+
160
+ for (int i = 0; i < Size(); i++)
161
+ {
162
+ Object3D child = (Object3D) get(i);
163
+ if (child == null)
164
+ continue;
165
+ blockloop = true;
166
+ child.RestoreSupports();
167
+ blockloop = false;
168
+ }
159169 }
160
-}
170
+
171
+ void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
172
+ {
173
+ if (hashtable.containsKey(GetUUID()))
174
+ {
175
+ Object3D o = hashtable.get(GetUUID());
176
+
177
+ Grafreed.Assert(this.bRep == o.bRep);
178
+ if (this.bRep != null)
179
+ assert(this.bRep.support == o.transientrep);
180
+
181
+ return;
182
+ }
183
+
184
+ Object3D o = new Object3D();
185
+
186
+ hashtable.put(GetUUID(), o);
187
+
188
+ for (int i=0; i<Size(); i++)
189
+ {
190
+ get(i).ExtractBigData(hashtable);
191
+ }
192
+
193
+ ExtractBigData(o);
194
+ }
195
+
196
+ void ExtractBigData(Object3D o)
197
+ {
198
+ o.bRep = this.bRep;
199
+ if (this.bRep != null)
200
+ {
201
+ o.transientrep = this.bRep.support;
202
+ o.bRep.support = null;
203
+ }
204
+
205
+ // o.support = this.support;
206
+ // o.fileparent = this.fileparent;
207
+ // if (this.bRep != null)
208
+ // o.bRep = this.bRep.support;
209
+
210
+ this.bRep = null;
211
+ // if (this.bRep != null)
212
+ // this.bRep.support = null;
213
+ // this.support = null;
214
+ // this.fileparent = null;
215
+ }
216
+
217
+ void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
218
+ {
219
+ if (!hashtable.containsKey(GetUUID()))
220
+ return;
221
+
222
+ Object3D o = hashtable.get(GetUUID());
223
+
224
+ RestoreBigData(o);
225
+
226
+ hashtable.remove(GetUUID());
227
+
228
+ for (int i=0; i<Size(); i++)
229
+ {
230
+ get(i).RestoreBigData(hashtable);
231
+ }
232
+ }
233
+
234
+ void RestoreBigData(Object3D o)
235
+ {
236
+ this.bRep = o.bRep;
237
+ if (this.bRep != null)
238
+ this.bRep.support = o.transientrep;
239
+ // this.support = o.support;
240
+ // this.fileparent = o.fileparent;
241
+ }
161242
162243 // MOCAP SUPPORT
163244 double tx,ty,tz,rx,ry,rz;
....@@ -482,12 +563,14 @@
482563 toParent = LA.newMatrix();
483564 fromParent = LA.newMatrix();
484565 }
566
+
485567 if (toParentMarked == null)
486568 {
487569 if (maxcount != 1)
488570 {
489571 new Exception().printStackTrace();
490572 }
573
+
491574 toParentMarked = LA.newMatrix();
492575 fromParentMarked = LA.newMatrix();
493576 }
....@@ -798,7 +881,7 @@
798881
799882 if (marked && Globals.isLIVE() && live &&
800883 //TEMP21aug2018
801
- (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW) &&
884
+ (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || !Globals.COMPUTESHADOWWHENLIVE) &&
802885 currentframe != Globals.framecount)
803886 {
804887 currentframe = Globals.framecount;
....@@ -810,7 +893,8 @@
810893
811894 boolean changedir = random && Math.random() < 0.01; // && !link2master;
812895
813
- if (transformcount*factor > maxcount || (step == 1 && changedir))
896
+ if (transformcount*factor >= maxcount && (rewind || random) ||
897
+ (step == 1 && changedir))
814898 {
815899 countdown = 1;
816900 delay = speedup?8:1;
....@@ -882,6 +966,7 @@
882966 if (material == null || material.multiply)
883967 return true;
884968
969
+ // Transparent objects are dynamic because we have to sort the triangles.
885970 return material.opacity > 0.99;
886971 }
887972
....@@ -2303,6 +2388,10 @@
23032388 }
23042389 */
23052390 }
2391
+ else
2392
+ {
2393
+ //((ObjEditor)editWindow).SetupUI2(null);
2394
+ }
23062395 }
23072396
23082397 void createEditWindow(GroupEditor callee, boolean newWindow) //, boolean root)
....@@ -2628,6 +2717,18 @@
26282717 //Touch();
26292718 }
26302719
2720
+ void GenNormalsMeshS()
2721
+ {
2722
+ selection.GenNormalsMesh();
2723
+// for (int i=0; i<selection.size(); i++)
2724
+// {
2725
+// Object3D selectee = (Object3D) selection.elementAt(i);
2726
+// selectee.GenNormals(crease);
2727
+// }
2728
+
2729
+ //Touch();
2730
+ }
2731
+
26312732 void ClearColorsS()
26322733 {
26332734 selection.ClearColors();
....@@ -2759,6 +2860,24 @@
27592860 if (child == null)
27602861 continue;
27612862 child.GenNormals(crease);
2863
+// Children().release(i);
2864
+ }
2865
+ blockloop = false;
2866
+ }
2867
+
2868
+ void GenNormalsMesh()
2869
+ {
2870
+ if (blockloop)
2871
+ return;
2872
+
2873
+ blockloop = true;
2874
+ GenNormalsMesh0();
2875
+ for (int i = 0; i < Children().Size(); i++)
2876
+ {
2877
+ Object3D child = (Object3D) Children().get(i); // reserve(i);
2878
+ if (child == null)
2879
+ continue;
2880
+ child.GenNormalsMesh();
27622881 // Children().release(i);
27632882 }
27642883 blockloop = false;
....@@ -2927,6 +3046,15 @@
29273046 if (bRep != null)
29283047 {
29293048 bRep.GenerateNormals(crease);
3049
+ Touch();
3050
+ }
3051
+ }
3052
+
3053
+ void GenNormalsMesh0()
3054
+ {
3055
+ if (bRep != null)
3056
+ {
3057
+ bRep.GenerateNormalsMesh();
29303058 Touch();
29313059 }
29323060 }
....@@ -3381,7 +3509,8 @@
33813509 if (blockloop)
33823510 return;
33833511
3384
- if (marked || (bRep != null && material != null)) // borderline...
3512
+ if (//marked || // does not make sense
3513
+ (bRep != null || material != null)) // borderline...
33853514 live = h;
33863515
33873516 for (int i = 0; i < Size(); i++)
....@@ -3402,7 +3531,8 @@
34023531 return;
34033532
34043533 //if (bRep != null)
3405
- if (marked || (bRep != null && material != null)) // borderline...
3534
+ if (//marked || // does not make sense
3535
+ (bRep != null || material != null)) // borderline...
34063536 link2master = h;
34073537
34083538 for (int i = 0; i < Size(); i++)
....@@ -3422,7 +3552,8 @@
34223552 if (blockloop)
34233553 return;
34243554
3425
- if (marked || (bRep != null && material != null)) // borderline...
3555
+ if (//marked || // does not make sense
3556
+ (bRep != null || material != null)) // borderline...
34263557 hide = h;
34273558
34283559 for (int i = 0; i < Size(); i++)
....@@ -3442,7 +3573,7 @@
34423573 if (blockloop)
34433574 return;
34443575
3445
- if (bRep != null && material != null) // borderline...
3576
+ if (bRep != null || material != null) // borderline...
34463577 marked = h;
34473578
34483579 for (int i = 0; i < Size(); i++)
....@@ -3452,6 +3583,46 @@
34523583 continue;
34533584 blockloop = true;
34543585 child.MarkLeaves(h);
3586
+ blockloop = false;
3587
+ // release(i);
3588
+ }
3589
+ }
3590
+
3591
+ void RewindLeaves(boolean h)
3592
+ {
3593
+ if (blockloop)
3594
+ return;
3595
+
3596
+ if (bRep != null || material != null) // borderline...
3597
+ rewind = h;
3598
+
3599
+ for (int i = 0; i < Size(); i++)
3600
+ {
3601
+ Object3D child = (Object3D) get(i); // reserve(i);
3602
+ if (child == null)
3603
+ continue;
3604
+ blockloop = true;
3605
+ child.RewindLeaves(h);
3606
+ blockloop = false;
3607
+ // release(i);
3608
+ }
3609
+ }
3610
+
3611
+ void RandomLeaves(boolean h)
3612
+ {
3613
+ if (blockloop)
3614
+ return;
3615
+
3616
+ if (bRep != null || material != null) // borderline...
3617
+ random = h;
3618
+
3619
+ for (int i = 0; i < Size(); i++)
3620
+ {
3621
+ Object3D child = (Object3D) get(i); // reserve(i);
3622
+ if (child == null)
3623
+ continue;
3624
+ blockloop = true;
3625
+ child.RandomLeaves(h);
34553626 blockloop = false;
34563627 // release(i);
34573628 }
....@@ -4225,6 +4396,55 @@
42254396 {
42264397 blockloop = true;
42274398 get(i).RepairShadow();
4399
+ blockloop = false;
4400
+ }
4401
+ }
4402
+
4403
+ void RepairSOV()
4404
+ {
4405
+ if (blockloop)
4406
+ return;
4407
+
4408
+ String texname = this.GetPigmentTexture();
4409
+
4410
+ if (texname.startsWith("sov"))
4411
+ {
4412
+ String[] s = texname.split("/");
4413
+
4414
+ String[] sname = s[1].split("Color.pn");
4415
+
4416
+ texname = sname[0];
4417
+
4418
+ if (sname.length > 1)
4419
+ {
4420
+ texname += "Color.jpg";
4421
+ }
4422
+
4423
+ this.SetPigmentTexture("sov/" + texname);
4424
+ }
4425
+
4426
+ texname = this.GetBumpTexture();
4427
+
4428
+ if (texname.startsWith("sov"))
4429
+ {
4430
+ String[] s = texname.split("/");
4431
+
4432
+ String[] sname = s[1].split("Bump.pn");
4433
+
4434
+ texname = sname[0];
4435
+
4436
+ if (sname.length > 1)
4437
+ {
4438
+ texname += "Bump.jpg";
4439
+ }
4440
+
4441
+ this.SetBumpTexture("sov/" + texname);
4442
+ }
4443
+
4444
+ for (int i=0; i<Size(); i++)
4445
+ {
4446
+ blockloop = true;
4447
+ get(i).RepairSOV();
42284448 blockloop = false;
42294449 }
42304450 }
....@@ -5371,6 +5591,43 @@
53715591 }
53725592 }
53735593
5594
+ UUID GetUUID()
5595
+ {
5596
+ if (uuid == null)
5597
+ {
5598
+ // Serial
5599
+ uuid = UUID.randomUUID();
5600
+ }
5601
+
5602
+ return uuid;
5603
+ }
5604
+
5605
+ Object3D GetObject(UUID uid)
5606
+ {
5607
+ if (blockloop)
5608
+ return null;
5609
+
5610
+ if (GetUUID().equals(uid))
5611
+ return this;
5612
+
5613
+ int nb = Size();
5614
+ for (int i = 0; i < nb; i++)
5615
+ {
5616
+ Object3D child = (Object3D) get(i);
5617
+
5618
+ if (child == null)
5619
+ continue;
5620
+
5621
+ blockloop = true;
5622
+ Object3D obj = child.GetObject(uid);
5623
+ blockloop = false;
5624
+ if (obj != null)
5625
+ return obj;
5626
+ }
5627
+
5628
+ return null;
5629
+ }
5630
+
53745631 void SetBumpTexture(String tex)
53755632 {
53765633 if (GetTextures() == null)
....@@ -5415,12 +5672,23 @@
54155672 boolean NeedSupport()
54165673 {
54175674 return
5418
- CameraPane.SUPPORT && (!CameraPane.movingcamera || !Globals.FREEZEONMOVE) && link2master && /*live &&*/ support != null
5675
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && link2master && /*live &&*/ support != null
54195676 // PROBLEM with CROWD!!
54205677 && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
54215678 }
54225679
54235680 static boolean DEBUG_SELECTION = false;
5681
+
5682
+ boolean IsLive()
5683
+ {
5684
+ if (live)
5685
+ return true;
5686
+
5687
+ if (parent == null)
5688
+ return false;
5689
+
5690
+ return parent.IsLive();
5691
+ }
54245692
54255693 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
54265694 {
....@@ -5483,7 +5751,7 @@
54835751 support = support;
54845752
54855753 //boolean usecalllists = IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5486
- boolean usecalllists = false; // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5754
+ boolean usecalllists = !IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
54875755
54885756 if (!usecalllists && bRep != null && bRep.displaylist > 0)
54895757 {
....@@ -5503,10 +5771,12 @@
55035771 boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
55045772
55055773 if (!selectmode && //display.DrawMode() != display.SELECTION &&
5506
- (touched || (bRep != null && bRep.displaylist <= 0)))
5774
+ //(touched || (bRep != null && bRep.displaylist <= 0)))
5775
+ (Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE || touched && (bRep != null && bRep.displaylist <= 0)))
55075776 {
55085777 Globals.lighttouched = true;
55095778 } // all panes...
5779
+
55105780 //if (usecalllists && display.DrawMode() != display.SELECTION && display.DrawMode() != display.SHADOW &&
55115781 if (bRep != null && usecalllists && !selectmode && // june 2013 display.DrawMode() != display.SHADOW &&
55125782 (touched || (bRep != null && bRep.displaylist <= 0)))
....@@ -5674,16 +5944,27 @@
56745944 tex = GetTextures();
56755945 }
56765946
5677
- boolean failed = false;
5947
+ boolean failedPigment = false;
5948
+ boolean failedBump = false;
56785949
56795950 try
56805951 {
5681
- display.BindTextures(tex, texres);
5952
+ display.BindPigmentTexture(tex, texres);
56825953 }
56835954 catch (Exception e)
56845955 {
56855956 System.err.println("FAILED: " + this);
5686
- failed = true;
5957
+ failedPigment = true;
5958
+ }
5959
+
5960
+ try
5961
+ {
5962
+ display.BindBumpTexture(tex, texres);
5963
+ }
5964
+ catch (Exception e)
5965
+ {
5966
+ //System.err.println("FAILED: " + this);
5967
+ failedBump = true;
56875968 }
56885969
56895970 if (!compiled)
....@@ -5706,8 +5987,11 @@
57065987 }
57075988 }
57085989
5709
- if (!failed)
5710
- display.ReleaseTextures(tex);
5990
+ if (!failedBump)
5991
+ display.ReleaseBumpTexture(tex);
5992
+
5993
+ if (!failedPigment)
5994
+ display.ReleasePigmentTexture(tex);
57115995
57125996 display.PopMaterial(this, selected);
57135997 }
....@@ -6080,6 +6364,11 @@
60806364 // dec 2012
60816365 new Exception().printStackTrace();
60826366 return;
6367
+ }
6368
+
6369
+ if (dontselect)
6370
+ {
6371
+ //bRep.GenerateNormalsMINE();
60836372 }
60846373
60856374 display.DrawGeometry(bRep, flipV, selectmode);
....@@ -6932,7 +7221,7 @@
69327221 spot.translate(32, 32);
69337222 spotw = spot.x + spot.width;
69347223 spoth = spot.y + spot.height;
6935
- info.g.setColor(Color.blue);
7224
+ info.g.setColor(Color.cyan);
69367225 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
69377226 // if (CameraPane.Xmin > spot.x)
69387227 // {
....@@ -6950,11 +7239,12 @@
69507239 // {
69517240 // CameraPane.Ymax = spoth;
69527241 // }
6953
- // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - 15);
6954
- //info.g.drawLine(spotw, spoth, spotw - 15, spoth);
7242
+ // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
7243
+ //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
69557244 spot.translate(0, -32);
6956
- info.g.setColor(Color.green);
7245
+ info.g.setColor(Color.yellow);
69577246 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7247
+ info.g.setColor(Color.green);
69587248 // if (CameraPane.Xmin > spot.x)
69597249 // {
69607250 // CameraPane.Xmin = spot.x;
....@@ -7272,19 +7562,20 @@
72727562 switch (info.pane.RenderCamera().viewCode)
72737563 {
72747564 case 3: // '\001'
7275
- if (modified)
7565
+ if (modified || opposite)
72767566 {
72777567 //LA.matScale(toParent, 1, hScale, vScale);
72787568 LA.matScale(toParent, totalScale, 1, 1);
72797569 } // vScale, 1);
72807570 else
72817571 {
7572
+ // EXCEPTION!
72827573 LA.matScale(toParent, totalScale, totalScale, totalScale);
72837574 } // vScale, 1);
72847575 break;
72857576
72867577 case 2: // '\002'
7287
- if (modified)
7578
+ if (modified || opposite)
72887579 {
72897580 //LA.matScale(toParent, hScale, 1, vScale);
72907581 LA.matScale(toParent, 1, totalScale, 1);
....@@ -7295,7 +7586,7 @@
72957586 break;
72967587
72977588 case 1: // '\003'
7298
- if (modified)
7589
+ if (modified || opposite)
72997590 {
73007591 //LA.matScale(toParent, hScale, vScale, 1);
73017592 LA.matScale(toParent, 1, 1, totalScale);
....@@ -7515,6 +7806,10 @@
75157806 editWindow = null;
75167807 } // ?
75177808 }
7809
+ else
7810
+ {
7811
+ //editWindow.closeUI();
7812
+ }
75187813 }
75197814
75207815 boolean root; // patch for edit windows
....@@ -7526,7 +7821,7 @@
75267821 /*transient*/ cVector2[] projectedVertices = new cVector2[0];
75277822
75287823 Object3D /*Composite*/ parent;
7529
- Object3D /*Composite*/ fileparent;
7824
+ Object3D /*Composite*/ fileparent; // In the case of FileObject
75307825
75317826 double[][] toParent; // dynamic matrix
75327827 double[][] fromParent;