Normand Briere
2019-06-25 ecff440ceef3ad352aa64cedbb913107ec4863a5
Object3D.java
....@@ -24,6 +24,11 @@
2424
2525 private UUID uuid = UUID.randomUUID();
2626
27
+ // TEMPORARY for mocap undo
28
+ mocap.reader.BVHReader.BVHResult bvh;
29
+ Object3D skeleton;
30
+ //
31
+
2732 ScriptNode scriptnode;
2833
2934 void InitOthers()
....@@ -104,64 +109,143 @@
104109
105110 // transient boolean reduced; // for morph reduction
106111
107
-transient com.bulletphysics.linearmath.Transform cache; // for fast merge
108
-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
109114
110
-transient Object3D transientsupport; // for cloning
111
-transient boolean transientlink2master;
115
+ transient Object3D transientsupport; // for cloning
116
+ transient boolean transientlink2master;
112117
113
-void SaveSupports()
114
-{
115
- if (blockloop)
116
- return;
117
-
118
- transientsupport = support;
119
- transientlink2master = link2master;
120
-
121
- support = null;
122
- link2master = false;
123
-
124
- if (bRep != null)
118
+ void SaveSupports()
125119 {
126
- bRep.SaveSupports();
120
+ if (blockloop)
121
+ return;
122
+
123
+ transientsupport = support;
124
+ transientlink2master = link2master;
125
+
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
+ }
127143 }
128
-
129
- for (int i = 0; i < Size(); i++)
144
+
145
+ void RestoreSupports()
130146 {
131
- Object3D child = (Object3D) get(i);
132
- if (child == null)
133
- continue;
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
+ }
169
+ }
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("copy of " + this.name);
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
+ if (blockloop)
223
+ return;
224
+
134225 blockloop = true;
135
- child.SaveSupports();
226
+
227
+ Object3D o = hashtable.get(GetUUID());
228
+
229
+ RestoreBigData(o);
230
+
231
+ //hashtable.remove(GetUUID());
232
+
233
+ for (int i=0; i<Size(); i++)
234
+ {
235
+ get(i).RestoreBigData(hashtable);
236
+ }
237
+
136238 blockloop = false;
137239 }
138
-}
139240
140
-void RestoreSupports()
141
-{
142
- if (blockloop)
143
- return;
144
-
145
- support = transientsupport;
146
- link2master = transientlink2master;
147
- transientsupport = null;
148
- transientlink2master = false;
149
-
150
- if (bRep != null)
241
+ void RestoreBigData(Object3D o)
151242 {
152
- bRep.RestoreSupports();
243
+ this.bRep = o.bRep;
244
+ if (this.bRep != null)
245
+ this.bRep.support = o.transientrep;
246
+ // this.support = o.support;
247
+ // this.fileparent = o.fileparent;
153248 }
154
-
155
- for (int i = 0; i < Size(); i++)
156
- {
157
- Object3D child = (Object3D) get(i);
158
- if (child == null)
159
- continue;
160
- blockloop = true;
161
- child.RestoreSupports();
162
- blockloop = false;
163
- }
164
-}
165249
166250 // MOCAP SUPPORT
167251 double tx,ty,tz,rx,ry,rz;
....@@ -486,12 +570,14 @@
486570 toParent = LA.newMatrix();
487571 fromParent = LA.newMatrix();
488572 }
573
+
489574 if (toParentMarked == null)
490575 {
491576 if (maxcount != 1)
492577 {
493578 new Exception().printStackTrace();
494579 }
580
+
495581 toParentMarked = LA.newMatrix();
496582 fromParentMarked = LA.newMatrix();
497583 }
....@@ -802,7 +888,7 @@
802888
803889 if (marked && Globals.isLIVE() && live &&
804890 //TEMP21aug2018
805
- (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW) &&
891
+ (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || !Globals.COMPUTESHADOWWHENLIVE) &&
806892 currentframe != Globals.framecount)
807893 {
808894 currentframe = Globals.framecount;
....@@ -814,7 +900,8 @@
814900
815901 boolean changedir = random && Math.random() < 0.01; // && !link2master;
816902
817
- if (transformcount*factor > maxcount || (step == 1 && changedir))
903
+ if (transformcount*factor >= maxcount && (rewind || random) ||
904
+ (step == 1 && changedir))
818905 {
819906 countdown = 1;
820907 delay = speedup?8:1;
....@@ -886,6 +973,7 @@
886973 if (material == null || material.multiply)
887974 return true;
888975
976
+ // Transparent objects are dynamic because we have to sort the triangles.
889977 return material.opacity > 0.99;
890978 }
891979
....@@ -2307,6 +2395,10 @@
23072395 }
23082396 */
23092397 }
2398
+ else
2399
+ {
2400
+ //((ObjEditor)editWindow).SetupUI2(null);
2401
+ }
23102402 }
23112403
23122404 void createEditWindow(GroupEditor callee, boolean newWindow) //, boolean root)
....@@ -2348,6 +2440,14 @@
23482440 {
23492441 editWindow.refreshContents();
23502442 }
2443
+ else
2444
+ {
2445
+ if (manipWindow != null)
2446
+ {
2447
+ manipWindow.refreshContents();
2448
+ }
2449
+ }
2450
+
23512451 //if (parent != null)
23522452 //parent.refreshEditWindow();
23532453 }
....@@ -2632,6 +2732,18 @@
26322732 //Touch();
26332733 }
26342734
2735
+ void GenNormalsMeshS()
2736
+ {
2737
+ selection.GenNormalsMesh();
2738
+// for (int i=0; i<selection.size(); i++)
2739
+// {
2740
+// Object3D selectee = (Object3D) selection.elementAt(i);
2741
+// selectee.GenNormals(crease);
2742
+// }
2743
+
2744
+ //Touch();
2745
+ }
2746
+
26352747 void ClearColorsS()
26362748 {
26372749 selection.ClearColors();
....@@ -2763,6 +2875,24 @@
27632875 if (child == null)
27642876 continue;
27652877 child.GenNormals(crease);
2878
+// Children().release(i);
2879
+ }
2880
+ blockloop = false;
2881
+ }
2882
+
2883
+ void GenNormalsMesh()
2884
+ {
2885
+ if (blockloop)
2886
+ return;
2887
+
2888
+ blockloop = true;
2889
+ GenNormalsMesh0();
2890
+ for (int i = 0; i < Children().Size(); i++)
2891
+ {
2892
+ Object3D child = (Object3D) Children().get(i); // reserve(i);
2893
+ if (child == null)
2894
+ continue;
2895
+ child.GenNormalsMesh();
27662896 // Children().release(i);
27672897 }
27682898 blockloop = false;
....@@ -2931,6 +3061,15 @@
29313061 if (bRep != null)
29323062 {
29333063 bRep.GenerateNormals(crease);
3064
+ Touch();
3065
+ }
3066
+ }
3067
+
3068
+ void GenNormalsMesh0()
3069
+ {
3070
+ if (bRep != null)
3071
+ {
3072
+ bRep.GenerateNormalsMesh();
29343073 Touch();
29353074 }
29363075 }
....@@ -3385,7 +3524,8 @@
33853524 if (blockloop)
33863525 return;
33873526
3388
- if (marked || (bRep != null && material != null)) // borderline...
3527
+ if (//marked || // does not make sense
3528
+ (bRep != null || material != null)) // borderline...
33893529 live = h;
33903530
33913531 for (int i = 0; i < Size(); i++)
....@@ -3406,7 +3546,8 @@
34063546 return;
34073547
34083548 //if (bRep != null)
3409
- if (marked || (bRep != null && material != null)) // borderline...
3549
+ if (//marked || // does not make sense
3550
+ (bRep != null || material != null)) // borderline...
34103551 link2master = h;
34113552
34123553 for (int i = 0; i < Size(); i++)
....@@ -3426,7 +3567,8 @@
34263567 if (blockloop)
34273568 return;
34283569
3429
- if (marked || (bRep != null && material != null)) // borderline...
3570
+ if (//marked || // does not make sense
3571
+ (bRep != null || material != null)) // borderline...
34303572 hide = h;
34313573
34323574 for (int i = 0; i < Size(); i++)
....@@ -3446,7 +3588,7 @@
34463588 if (blockloop)
34473589 return;
34483590
3449
- if (bRep != null && material != null) // borderline...
3591
+ if (bRep != null || material != null) // borderline...
34503592 marked = h;
34513593
34523594 for (int i = 0; i < Size(); i++)
....@@ -3456,6 +3598,46 @@
34563598 continue;
34573599 blockloop = true;
34583600 child.MarkLeaves(h);
3601
+ blockloop = false;
3602
+ // release(i);
3603
+ }
3604
+ }
3605
+
3606
+ void RewindLeaves(boolean h)
3607
+ {
3608
+ if (blockloop)
3609
+ return;
3610
+
3611
+ if (bRep != null || material != null) // borderline...
3612
+ rewind = h;
3613
+
3614
+ for (int i = 0; i < Size(); i++)
3615
+ {
3616
+ Object3D child = (Object3D) get(i); // reserve(i);
3617
+ if (child == null)
3618
+ continue;
3619
+ blockloop = true;
3620
+ child.RewindLeaves(h);
3621
+ blockloop = false;
3622
+ // release(i);
3623
+ }
3624
+ }
3625
+
3626
+ void RandomLeaves(boolean h)
3627
+ {
3628
+ if (blockloop)
3629
+ return;
3630
+
3631
+ if (bRep != null || material != null) // borderline...
3632
+ random = h;
3633
+
3634
+ for (int i = 0; i < Size(); i++)
3635
+ {
3636
+ Object3D child = (Object3D) get(i); // reserve(i);
3637
+ if (child == null)
3638
+ continue;
3639
+ blockloop = true;
3640
+ child.RandomLeaves(h);
34593641 blockloop = false;
34603642 // release(i);
34613643 }
....@@ -4233,6 +4415,55 @@
42334415 }
42344416 }
42354417
4418
+ void RepairSOV()
4419
+ {
4420
+ if (blockloop)
4421
+ return;
4422
+
4423
+ String texname = this.GetPigmentTexture();
4424
+
4425
+ if (texname.startsWith("sov"))
4426
+ {
4427
+ String[] s = texname.split("/");
4428
+
4429
+ String[] sname = s[1].split("Color.pn");
4430
+
4431
+ texname = sname[0];
4432
+
4433
+ if (sname.length > 1)
4434
+ {
4435
+ texname += "Color.jpg";
4436
+ }
4437
+
4438
+ this.SetPigmentTexture("sov/" + texname);
4439
+ }
4440
+
4441
+ texname = this.GetBumpTexture();
4442
+
4443
+ if (texname.startsWith("sov"))
4444
+ {
4445
+ String[] s = texname.split("/");
4446
+
4447
+ String[] sname = s[1].split("Bump.pn");
4448
+
4449
+ texname = sname[0];
4450
+
4451
+ if (sname.length > 1)
4452
+ {
4453
+ texname += "Bump.jpg";
4454
+ }
4455
+
4456
+ this.SetBumpTexture("sov/" + texname);
4457
+ }
4458
+
4459
+ for (int i=0; i<Size(); i++)
4460
+ {
4461
+ blockloop = true;
4462
+ get(i).RepairSOV();
4463
+ blockloop = false;
4464
+ }
4465
+ }
4466
+
42364467 void RepairTexture()
42374468 {
42384469 if (this instanceof FileObject || blockloop)
....@@ -4747,6 +4978,14 @@
47474978 }
47484979 }
47494980
4981
+ ObjEditor GetWindow()
4982
+ {
4983
+ if (editWindow != null)
4984
+ return editWindow;
4985
+
4986
+ return manipWindow;
4987
+ }
4988
+
47504989 cTreePath Select(int indexcount, boolean deselect)
47514990 {
47524991 if (hide || dontselect)
....@@ -4783,10 +5022,11 @@
47835022 if (leaf != null)
47845023 {
47855024 cTreePath tp = new cTreePath(this, leaf);
4786
- if (editWindow != null)
5025
+ ObjEditor window = GetWindow();
5026
+ if (window != null)
47875027 {
47885028 //System.out.println("editWindow = " + editWindow + " vs " + this);
4789
- editWindow.Select(tp, deselect, true);
5029
+ window.Select(tp, deselect, true);
47905030 }
47915031
47925032 return tp;
....@@ -4812,9 +5052,10 @@
48125052 if (leaf != null)
48135053 {
48145054 cTreePath tp = new cTreePath(this, leaf);
4815
- if (editWindow != null)
5055
+ ObjEditor window = GetWindow();
5056
+ if (window != null)
48165057 {
4817
- editWindow.Select(tp, deselect, true);
5058
+ window.Select(tp, deselect, true);
48185059 }
48195060
48205061 return tp;
....@@ -5456,12 +5697,23 @@
54565697 boolean NeedSupport()
54575698 {
54585699 return
5459
- CameraPane.SUPPORT && (!CameraPane.movingcamera || !Globals.FREEZEONMOVE) && link2master && /*live &&*/ support != null
5700
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && link2master && /*live &&*/ support != null
54605701 // PROBLEM with CROWD!!
54615702 && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
54625703 }
54635704
54645705 static boolean DEBUG_SELECTION = false;
5706
+
5707
+ boolean IsLive()
5708
+ {
5709
+ if (live)
5710
+ return true;
5711
+
5712
+ if (parent == null)
5713
+ return false;
5714
+
5715
+ return parent.IsLive();
5716
+ }
54655717
54665718 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
54675719 {
....@@ -5524,7 +5776,7 @@
55245776 support = support;
55255777
55265778 //boolean usecalllists = IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5527
- boolean usecalllists = false; // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5779
+ boolean usecalllists = !IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
55285780
55295781 if (!usecalllists && bRep != null && bRep.displaylist > 0)
55305782 {
....@@ -5544,10 +5796,12 @@
55445796 boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
55455797
55465798 if (!selectmode && //display.DrawMode() != display.SELECTION &&
5547
- (touched || (bRep != null && bRep.displaylist <= 0)))
5799
+ //(touched || (bRep != null && bRep.displaylist <= 0)))
5800
+ (Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE || touched || (bRep != null && bRep.displaylist <= 0)))
55485801 {
55495802 Globals.lighttouched = true;
55505803 } // all panes...
5804
+
55515805 //if (usecalllists && display.DrawMode() != display.SELECTION && display.DrawMode() != display.SHADOW &&
55525806 if (bRep != null && usecalllists && !selectmode && // june 2013 display.DrawMode() != display.SHADOW &&
55535807 (touched || (bRep != null && bRep.displaylist <= 0)))
....@@ -5715,16 +5969,27 @@
57155969 tex = GetTextures();
57165970 }
57175971
5718
- boolean failed = false;
5972
+ boolean failedPigment = false;
5973
+ boolean failedBump = false;
57195974
57205975 try
57215976 {
5722
- display.BindTextures(tex, texres);
5977
+ display.BindPigmentTexture(tex, texres);
57235978 }
57245979 catch (Exception e)
57255980 {
57265981 System.err.println("FAILED: " + this);
5727
- failed = true;
5982
+ failedPigment = true;
5983
+ }
5984
+
5985
+ try
5986
+ {
5987
+ display.BindBumpTexture(tex, texres);
5988
+ }
5989
+ catch (Exception e)
5990
+ {
5991
+ //System.err.println("FAILED: " + this);
5992
+ failedBump = true;
57285993 }
57295994
57305995 if (!compiled)
....@@ -5747,8 +6012,11 @@
57476012 }
57486013 }
57496014
5750
- if (!failed)
5751
- display.ReleaseTextures(tex);
6015
+ if (!failedBump)
6016
+ display.ReleaseBumpTexture(tex);
6017
+
6018
+ if (!failedPigment)
6019
+ display.ReleasePigmentTexture(tex);
57526020
57536021 display.PopMaterial(this, selected);
57546022 }
....@@ -6121,6 +6389,11 @@
61216389 // dec 2012
61226390 new Exception().printStackTrace();
61236391 return;
6392
+ }
6393
+
6394
+ if (dontselect)
6395
+ {
6396
+ //bRep.GenerateNormalsMINE();
61246397 }
61256398
61266399 display.DrawGeometry(bRep, flipV, selectmode);
....@@ -6973,7 +7246,7 @@
69737246 spot.translate(32, 32);
69747247 spotw = spot.x + spot.width;
69757248 spoth = spot.y + spot.height;
6976
- info.g.setColor(Color.blue);
7249
+ info.g.setColor(Color.cyan);
69777250 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
69787251 // if (CameraPane.Xmin > spot.x)
69797252 // {
....@@ -6991,11 +7264,12 @@
69917264 // {
69927265 // CameraPane.Ymax = spoth;
69937266 // }
6994
- // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - 15);
6995
- //info.g.drawLine(spotw, spoth, spotw - 15, spoth);
7267
+ // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
7268
+ //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
69967269 spot.translate(0, -32);
6997
- info.g.setColor(Color.green);
7270
+ info.g.setColor(Color.yellow);
69987271 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7272
+ info.g.setColor(Color.green);
69997273 // if (CameraPane.Xmin > spot.x)
70007274 // {
70017275 // CameraPane.Xmin = spot.x;
....@@ -7313,19 +7587,20 @@
73137587 switch (info.pane.RenderCamera().viewCode)
73147588 {
73157589 case 3: // '\001'
7316
- if (modified)
7590
+ if (modified || opposite)
73177591 {
73187592 //LA.matScale(toParent, 1, hScale, vScale);
73197593 LA.matScale(toParent, totalScale, 1, 1);
73207594 } // vScale, 1);
73217595 else
73227596 {
7597
+ // EXCEPTION!
73237598 LA.matScale(toParent, totalScale, totalScale, totalScale);
73247599 } // vScale, 1);
73257600 break;
73267601
73277602 case 2: // '\002'
7328
- if (modified)
7603
+ if (modified || opposite)
73297604 {
73307605 //LA.matScale(toParent, hScale, 1, vScale);
73317606 LA.matScale(toParent, 1, totalScale, 1);
....@@ -7336,7 +7611,7 @@
73367611 break;
73377612
73387613 case 1: // '\003'
7339
- if (modified)
7614
+ if (modified || opposite)
73407615 {
73417616 //LA.matScale(toParent, hScale, vScale, 1);
73427617 LA.matScale(toParent, 1, 1, totalScale);
....@@ -7556,6 +7831,10 @@
75567831 editWindow = null;
75577832 } // ?
75587833 }
7834
+ else
7835
+ {
7836
+ //editWindow.closeUI();
7837
+ }
75597838 }
75607839
75617840 boolean root; // patch for edit windows
....@@ -7567,7 +7846,7 @@
75677846 /*transient*/ cVector2[] projectedVertices = new cVector2[0];
75687847
75697848 Object3D /*Composite*/ parent;
7570
- Object3D /*Composite*/ fileparent;
7849
+ Object3D /*Composite*/ fileparent; // In the case of FileObject
75717850
75727851 double[][] toParent; // dynamic matrix
75737852 double[][] fromParent;
....@@ -7713,6 +7992,8 @@
77137992 }
77147993
77157994 transient ObjEditor editWindow;
7995
+ transient ObjEditor manipWindow;
7996
+
77167997 transient ObjectUI objectUI;
77177998 public static int povDepth = 0;
77187999 private static cVector tbMin = new cVector();