Normand Briere
2019-06-13 4629090fafbef256abd0686a85ee12042d658868
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
+ 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;
....@@ -300,6 +381,7 @@
300381 }
301382
302383 boolean live = false;
384
+ boolean dontselect = false;
303385 boolean hide = false;
304386 boolean link2master = false; // performs reset support/master at each frame
305387 boolean marked = false; // animation node
....@@ -774,7 +856,7 @@
774856 if (step == 0)
775857 step = 1;
776858 if (maxcount == 0)
777
- maxcount = 2048; // 4;
859
+ maxcount = 128; // 2048; // 4;
778860 // if (acceleration == 0)
779861 // acceleration = 10;
780862 if (delay == 0) // serial
....@@ -1834,12 +1916,15 @@
18341916 if (obj.name == null)
18351917 continue; // can't be a null one
18361918
1919
+ // Try perfect match first.
18371920 if (n.equals(obj.name))
18381921 {
18391922 theobj = obj;
18401923 count++;
18411924 }
18421925 }
1926
+
1927
+ // not needed: n = n.split(":")[0]; // Poser generates a count
18431928
18441929 if (count != 1)
18451930 for (int i=Size(); --i>=0;)
....@@ -2624,6 +2709,18 @@
26242709 //Touch();
26252710 }
26262711
2712
+ void GenNormalsMeshS()
2713
+ {
2714
+ selection.GenNormalsMesh();
2715
+// for (int i=0; i<selection.size(); i++)
2716
+// {
2717
+// Object3D selectee = (Object3D) selection.elementAt(i);
2718
+// selectee.GenNormals(crease);
2719
+// }
2720
+
2721
+ //Touch();
2722
+ }
2723
+
26272724 void ClearColorsS()
26282725 {
26292726 selection.ClearColors();
....@@ -2755,6 +2852,24 @@
27552852 if (child == null)
27562853 continue;
27572854 child.GenNormals(crease);
2855
+// Children().release(i);
2856
+ }
2857
+ blockloop = false;
2858
+ }
2859
+
2860
+ void GenNormalsMesh()
2861
+ {
2862
+ if (blockloop)
2863
+ return;
2864
+
2865
+ blockloop = true;
2866
+ GenNormalsMesh0();
2867
+ for (int i = 0; i < Children().Size(); i++)
2868
+ {
2869
+ Object3D child = (Object3D) Children().get(i); // reserve(i);
2870
+ if (child == null)
2871
+ continue;
2872
+ child.GenNormalsMesh();
27582873 // Children().release(i);
27592874 }
27602875 blockloop = false;
....@@ -2927,6 +3042,15 @@
29273042 }
29283043 }
29293044
3045
+ void GenNormalsMesh0()
3046
+ {
3047
+ if (bRep != null)
3048
+ {
3049
+ bRep.GenerateNormalsMesh();
3050
+ Touch();
3051
+ }
3052
+ }
3053
+
29303054 void GenNormalsMINE0()
29313055 {
29323056 if (bRep != null)
....@@ -3002,8 +3126,10 @@
30023126 v.fromParent = LA.newMatrix();
30033127 }
30043128
3005
- LA.matConcat(v.toParent, toParent, v.toParent);
3006
- LA.matConcat(fromParent, v.fromParent, v.fromParent);
3129
+// LA.matConcat(v.toParent, toParent, v.toParent);
3130
+// LA.matConcat(fromParent, v.fromParent, v.fromParent);
3131
+ LA.matConcat(toParent, v.toParent, v.toParent);
3132
+ LA.matConcat(v.fromParent, fromParent, v.fromParent);
30073133 }
30083134
30093135 toParent = null; // LA.matIdentity(toParent);
....@@ -3236,7 +3362,9 @@
32363362 bRep.support = null;
32373363 BoundaryRep temprep = (BoundaryRep) Grafreed.clone(bRep);
32383364 // bRep.SplitInTwo(onlyone); // thread...
3239
- temprep.SplitInTwo(reduction34, onlyone);
3365
+
3366
+ while(temprep.SplitInTwo(reduction34, onlyone));
3367
+
32403368 bRep = temprep;
32413369 bRep.support = sup;
32423370 Touch();
....@@ -4711,7 +4839,7 @@
47114839
47124840 cTreePath SelectLeaf(int indexcount, boolean deselect)
47134841 {
4714
- if (hide)
4842
+ if (hide || dontselect)
47154843 return null;
47164844
47174845 if (count <= 0)
....@@ -4737,7 +4865,7 @@
47374865
47384866 cTreePath Select(int indexcount, boolean deselect)
47394867 {
4740
- if (hide)
4868
+ if (hide || dontselect)
47414869 return null;
47424870
47434871 if (count <= 0)
....@@ -5363,6 +5491,43 @@
53635491 }
53645492 }
53655493
5494
+ UUID GetUUID()
5495
+ {
5496
+ if (uuid == null)
5497
+ {
5498
+ // Serial
5499
+ uuid = UUID.randomUUID();
5500
+ }
5501
+
5502
+ return uuid;
5503
+ }
5504
+
5505
+ Object3D GetObject(UUID uid)
5506
+ {
5507
+ if (blockloop)
5508
+ return null;
5509
+
5510
+ if (GetUUID().equals(uid))
5511
+ return this;
5512
+
5513
+ int nb = Size();
5514
+ for (int i = 0; i < nb; i++)
5515
+ {
5516
+ Object3D child = (Object3D) get(i);
5517
+
5518
+ if (child == null)
5519
+ continue;
5520
+
5521
+ blockloop = true;
5522
+ Object3D obj = child.GetObject(uid);
5523
+ blockloop = false;
5524
+ if (obj != null)
5525
+ return obj;
5526
+ }
5527
+
5528
+ return null;
5529
+ }
5530
+
53665531 void SetBumpTexture(String tex)
53675532 {
53685533 if (GetTextures() == null)
....@@ -5407,7 +5572,7 @@
54075572 boolean NeedSupport()
54085573 {
54095574 return
5410
- CameraPane.SUPPORT && !CameraPane.movingcamera && link2master && /*live &&*/ support != null
5575
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || !Globals.FREEZEONMOVE) && link2master && /*live &&*/ support != null
54115576 // PROBLEM with CROWD!!
54125577 && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
54135578 }
....@@ -5424,7 +5589,7 @@
54245589 }
54255590
54265591 if (display.DrawMode() == iCameraPane.SELECTION &&
5427
- hide)
5592
+ (hide || dontselect))
54285593 return;
54295594
54305595 if (name != null && name.contains("sclera"))
....@@ -5666,7 +5831,17 @@
56665831 tex = GetTextures();
56675832 }
56685833
5669
- display.BindTextures(tex, texres);
5834
+ boolean failed = false;
5835
+
5836
+ try
5837
+ {
5838
+ display.BindTextures(tex, texres);
5839
+ }
5840
+ catch (Exception e)
5841
+ {
5842
+ System.err.println("FAILED: " + this);
5843
+ failed = true;
5844
+ }
56705845
56715846 if (!compiled)
56725847 {
....@@ -5688,7 +5863,8 @@
56885863 }
56895864 }
56905865
5691
- display.ReleaseTextures(tex);
5866
+ if (!failed)
5867
+ display.ReleaseTextures(tex);
56925868
56935869 display.PopMaterial(this, selected);
56945870 }
....@@ -5817,6 +5993,9 @@
58175993
58185994 void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
58195995 {
5996
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
5997
+ return;
5998
+
58205999 if (hide)
58216000 return;
58226001 // shadow optimisation
....@@ -5941,6 +6120,9 @@
59416120 {
59426121 if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
59436122 return; // no shadow for transparent objects
6123
+
6124
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6125
+ return;
59446126
59456127 if (hide)
59466128 return;
....@@ -6925,8 +7107,8 @@
69257107 // {
69267108 // CameraPane.Ymax = spoth;
69277109 // }
6928
- info.g.drawLine(spotw, spoth, spotw, spoth - 15);
6929
- info.g.drawLine(spotw, spoth, spotw - 15, spoth);
7110
+ // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - 15);
7111
+ //info.g.drawLine(spotw, spoth, spotw - 15, spoth);
69307112 spot.translate(0, -32);
69317113 info.g.setColor(Color.green);
69327114 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
....@@ -6981,7 +7163,7 @@
69817163 startX = info.x;
69827164 startY = info.y;
69837165
6984
- hitSomething = 0;
7166
+ hitSomething = -1;
69857167 cVector origin = new cVector();
69867168 //LA.xformPos(origin, toParent, origin);
69877169 Rectangle spot = new Rectangle();
....@@ -7057,6 +7239,7 @@
70577239 //System.out.println("hitSomething = " + hitSomething);
70587240
70597241 double scale = 0.005f * info.camera.Distance();
7242
+
70607243 cVector xlate = new cVector();
70617244 //cVector xlate2 = new cVector();
70627245 switch (hitSomething)
....@@ -7205,24 +7388,27 @@
72057388
72067389 case hitScale: // scale
72077390 double hScale = (double) (info.x - centerPt.x) / 32;
7391
+ double sign = 1;
7392
+ if (hScale < 0)
7393
+ {
7394
+ sign = -1;
7395
+ }
7396
+ hScale = sign*Math.pow(sign*hScale, scale * 50);
72087397 if (hScale < 0.01)
72097398 {
7210
- hScale = 0.01;
7399
+ //hScale = 0.01;
72117400 }
7212
- hScale = Math.pow(hScale, scale * 50);
7213
- if (hScale < 0.01)
7214
- {
7215
- hScale = 0.01;
7216
- }
7401
+
72177402 double vScale = (double) (info.y - centerPt.y) / 32;
7218
- if (vScale < 0.01)
7403
+ sign = 1;
7404
+ if (vScale < 0)
72197405 {
7220
- vScale = 0.01;
7406
+ sign = -1;
72217407 }
7222
- vScale = Math.pow(vScale, scale * 50);
7408
+ vScale = sign*Math.pow(sign*vScale, scale * 50);
72237409 if (vScale < 0.01)
72247410 {
7225
- vScale = 0.01;
7411
+ //vScale = 0.01;
72267412 }
72277413 LA.matCopy(startMat, toParent);
72287414 /**/
....@@ -7233,17 +7419,24 @@
72337419 }
72347420 /**/
72357421
7422
+ double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2);
7423
+
7424
+ if (totalScale < 0.01)
7425
+ {
7426
+ totalScale = 0.01;
7427
+ }
7428
+
72367429 switch (info.pane.RenderCamera().viewCode)
72377430 {
72387431 case 3: // '\001'
72397432 if (modified)
72407433 {
72417434 //LA.matScale(toParent, 1, hScale, vScale);
7242
- LA.matScale(toParent, vScale, 1, 1);
7435
+ LA.matScale(toParent, totalScale, 1, 1);
72437436 } // vScale, 1);
72447437 else
72457438 {
7246
- LA.matScale(toParent, vScale, vScale, vScale);
7439
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
72477440 } // vScale, 1);
72487441 break;
72497442
....@@ -7251,10 +7444,10 @@
72517444 if (modified)
72527445 {
72537446 //LA.matScale(toParent, hScale, 1, vScale);
7254
- LA.matScale(toParent, 1, vScale, 1);
7447
+ LA.matScale(toParent, 1, totalScale, 1);
72557448 } else
72567449 {
7257
- LA.matScale(toParent, vScale, 1, vScale);
7450
+ LA.matScale(toParent, totalScale, 1, totalScale);
72587451 }
72597452 break;
72607453
....@@ -7262,10 +7455,10 @@
72627455 if (modified)
72637456 {
72647457 //LA.matScale(toParent, hScale, vScale, 1);
7265
- LA.matScale(toParent, 1, 1, vScale);
7458
+ LA.matScale(toParent, 1, 1, totalScale);
72667459 } else
72677460 {
7268
- LA.matScale(toParent, vScale, vScale, 1);
7461
+ LA.matScale(toParent, totalScale, totalScale, 1);
72697462 }
72707463 break;
72717464 }
....@@ -7406,7 +7599,7 @@
74067599 objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
74077600 } else
74087601 {
7409
- objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count /*- 1*/) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
7602
+ objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count - 1) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
74107603 } // + super.toString();
74117604 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
74127605
....@@ -7490,7 +7683,7 @@
74907683 /*transient*/ cVector2[] projectedVertices = new cVector2[0];
74917684
74927685 Object3D /*Composite*/ parent;
7493
- Object3D /*Composite*/ fileparent;
7686
+ Object3D /*Composite*/ fileparent; // In the case of FileObject
74947687
74957688 double[][] toParent; // dynamic matrix
74967689 double[][] fromParent;
....@@ -7654,9 +7847,9 @@
76547847 private static cVector edge2 = new cVector();
76557848 //private static cVector norm = new cVector();
76567849 /*transient private*/ int hitSomething;
7657
- private static final int hitCenter = 1;
7658
- private static final int hitScale = 2;
7659
- private static final int hitRotate = 3;
7850
+ static final int hitCenter = 1;
7851
+ static final int hitScale = 2;
7852
+ static final int hitRotate = 3;
76607853 /*transient*/ /*private*/ int viewCode; // Now used for transparency cache flag
76617854 /*transient*/ private Point centerPt;
76627855 /*transient*/ private int startX;