Normand Briere
2019-06-11 4113164b3be1e50251ac40d6fd65660f0a6c2e63
Object3D.java
....@@ -14,11 +14,15 @@
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();
2226
2327 ScriptNode scriptnode;
2428
....@@ -156,6 +160,67 @@
156160 blockloop = true;
157161 child.RestoreSupports();
158162 blockloop = false;
163
+ }
164
+}
165
+
166
+void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
167
+{
168
+ if (hashtable.containsKey(GetUUID()))
169
+ {
170
+ Object3D o = hashtable.get(GetUUID());
171
+
172
+ assert(this.bRep == o.bRep);
173
+ if (this.bRep != null)
174
+ assert(this.bRep.support == o.transientrep);
175
+
176
+ return;
177
+ }
178
+
179
+ Object3D o = new Object3D();
180
+ o.bRep = this.bRep;
181
+ if (this.bRep != null)
182
+ {
183
+ o.transientrep = this.bRep.support;
184
+ o.bRep.support = null;
185
+ }
186
+
187
+// o.support = this.support;
188
+// o.fileparent = this.fileparent;
189
+// if (this.bRep != null)
190
+// o.bRep = this.bRep.support;
191
+
192
+ hashtable.put(GetUUID(), o);
193
+
194
+ this.bRep = null;
195
+// if (this.bRep != null)
196
+// this.bRep.support = null;
197
+// this.support = null;
198
+// this.fileparent = null;
199
+
200
+ for (int i=0; i<Size(); i++)
201
+ {
202
+ get(i).ExtractBigData(hashtable);
203
+ }
204
+}
205
+
206
+void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
207
+{
208
+ if (!hashtable.containsKey(GetUUID()))
209
+ return;
210
+
211
+ Object3D o = hashtable.get(GetUUID());
212
+
213
+ this.bRep = o.bRep;
214
+ if (this.bRep != null)
215
+ this.bRep.support = o.transientrep;
216
+// this.support = o.support;
217
+// this.fileparent = o.fileparent;
218
+
219
+ hashtable.remove(GetUUID());
220
+
221
+ for (int i=0; i<Size(); i++)
222
+ {
223
+ get(i).RestoreBigData(hashtable);
159224 }
160225 }
161226
....@@ -300,6 +365,7 @@
300365 }
301366
302367 boolean live = false;
368
+ boolean dontselect = false;
303369 boolean hide = false;
304370 boolean link2master = false; // performs reset support/master at each frame
305371 boolean marked = false; // animation node
....@@ -774,7 +840,7 @@
774840 if (step == 0)
775841 step = 1;
776842 if (maxcount == 0)
777
- maxcount = 2048; // 4;
843
+ maxcount = 128; // 2048; // 4;
778844 // if (acceleration == 0)
779845 // acceleration = 10;
780846 if (delay == 0) // serial
....@@ -1834,12 +1900,15 @@
18341900 if (obj.name == null)
18351901 continue; // can't be a null one
18361902
1903
+ // Try perfect match first.
18371904 if (n.equals(obj.name))
18381905 {
18391906 theobj = obj;
18401907 count++;
18411908 }
18421909 }
1910
+
1911
+ // not needed: n = n.split(":")[0]; // Poser generates a count
18431912
18441913 if (count != 1)
18451914 for (int i=Size(); --i>=0;)
....@@ -3002,8 +3071,10 @@
30023071 v.fromParent = LA.newMatrix();
30033072 }
30043073
3005
- LA.matConcat(v.toParent, toParent, v.toParent);
3006
- LA.matConcat(fromParent, v.fromParent, v.fromParent);
3074
+// LA.matConcat(v.toParent, toParent, v.toParent);
3075
+// LA.matConcat(fromParent, v.fromParent, v.fromParent);
3076
+ LA.matConcat(toParent, v.toParent, v.toParent);
3077
+ LA.matConcat(v.fromParent, fromParent, v.fromParent);
30073078 }
30083079
30093080 toParent = null; // LA.matIdentity(toParent);
....@@ -3236,7 +3307,9 @@
32363307 bRep.support = null;
32373308 BoundaryRep temprep = (BoundaryRep) Grafreed.clone(bRep);
32383309 // bRep.SplitInTwo(onlyone); // thread...
3239
- temprep.SplitInTwo(reduction34, onlyone);
3310
+
3311
+ while(temprep.SplitInTwo(reduction34, onlyone));
3312
+
32403313 bRep = temprep;
32413314 bRep.support = sup;
32423315 Touch();
....@@ -4711,7 +4784,7 @@
47114784
47124785 cTreePath SelectLeaf(int indexcount, boolean deselect)
47134786 {
4714
- if (hide)
4787
+ if (hide || dontselect)
47154788 return null;
47164789
47174790 if (count <= 0)
....@@ -4737,7 +4810,7 @@
47374810
47384811 cTreePath Select(int indexcount, boolean deselect)
47394812 {
4740
- if (hide)
4813
+ if (hide || dontselect)
47414814 return null;
47424815
47434816 if (count <= 0)
....@@ -5363,6 +5436,43 @@
53635436 }
53645437 }
53655438
5439
+ UUID GetUUID()
5440
+ {
5441
+ if (uuid == null)
5442
+ {
5443
+ // Serial
5444
+ uuid = UUID.randomUUID();
5445
+ }
5446
+
5447
+ return uuid;
5448
+ }
5449
+
5450
+ Object3D GetObject(UUID uid)
5451
+ {
5452
+ if (blockloop)
5453
+ return null;
5454
+
5455
+ if (GetUUID().equals(uid))
5456
+ return this;
5457
+
5458
+ int nb = Size();
5459
+ for (int i = 0; i < nb; i++)
5460
+ {
5461
+ Object3D child = (Object3D) get(i);
5462
+
5463
+ if (child == null)
5464
+ continue;
5465
+
5466
+ blockloop = true;
5467
+ Object3D obj = child.GetObject(uid);
5468
+ blockloop = false;
5469
+ if (obj != null)
5470
+ return obj;
5471
+ }
5472
+
5473
+ return null;
5474
+ }
5475
+
53665476 void SetBumpTexture(String tex)
53675477 {
53685478 if (GetTextures() == null)
....@@ -5407,7 +5517,7 @@
54075517 boolean NeedSupport()
54085518 {
54095519 return
5410
- CameraPane.SUPPORT && !CameraPane.movingcamera && link2master && /*live &&*/ support != null
5520
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || !Globals.FREEZEONMOVE) && link2master && /*live &&*/ support != null
54115521 // PROBLEM with CROWD!!
54125522 && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
54135523 }
....@@ -5424,7 +5534,7 @@
54245534 }
54255535
54265536 if (display.DrawMode() == iCameraPane.SELECTION &&
5427
- hide)
5537
+ (hide || dontselect))
54285538 return;
54295539
54305540 if (name != null && name.contains("sclera"))
....@@ -5666,7 +5776,17 @@
56665776 tex = GetTextures();
56675777 }
56685778
5669
- display.BindTextures(tex, texres);
5779
+ boolean failed = false;
5780
+
5781
+ try
5782
+ {
5783
+ display.BindTextures(tex, texres);
5784
+ }
5785
+ catch (Exception e)
5786
+ {
5787
+ System.err.println("FAILED: " + this);
5788
+ failed = true;
5789
+ }
56705790
56715791 if (!compiled)
56725792 {
....@@ -5688,7 +5808,8 @@
56885808 }
56895809 }
56905810
5691
- display.ReleaseTextures(tex);
5811
+ if (!failed)
5812
+ display.ReleaseTextures(tex);
56925813
56935814 display.PopMaterial(this, selected);
56945815 }
....@@ -5817,6 +5938,9 @@
58175938
58185939 void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
58195940 {
5941
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
5942
+ return;
5943
+
58205944 if (hide)
58215945 return;
58225946 // shadow optimisation
....@@ -5941,6 +6065,9 @@
59416065 {
59426066 if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
59436067 return; // no shadow for transparent objects
6068
+
6069
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6070
+ return;
59446071
59456072 if (hide)
59466073 return;
....@@ -6925,8 +7052,8 @@
69257052 // {
69267053 // CameraPane.Ymax = spoth;
69277054 // }
6928
- info.g.drawLine(spotw, spoth, spotw, spoth - 15);
6929
- info.g.drawLine(spotw, spoth, spotw - 15, spoth);
7055
+ // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - 15);
7056
+ //info.g.drawLine(spotw, spoth, spotw - 15, spoth);
69307057 spot.translate(0, -32);
69317058 info.g.setColor(Color.green);
69327059 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
....@@ -6981,7 +7108,7 @@
69817108 startX = info.x;
69827109 startY = info.y;
69837110
6984
- hitSomething = 0;
7111
+ hitSomething = -1;
69857112 cVector origin = new cVector();
69867113 //LA.xformPos(origin, toParent, origin);
69877114 Rectangle spot = new Rectangle();
....@@ -7057,6 +7184,7 @@
70577184 //System.out.println("hitSomething = " + hitSomething);
70587185
70597186 double scale = 0.005f * info.camera.Distance();
7187
+
70607188 cVector xlate = new cVector();
70617189 //cVector xlate2 = new cVector();
70627190 switch (hitSomething)
....@@ -7205,24 +7333,27 @@
72057333
72067334 case hitScale: // scale
72077335 double hScale = (double) (info.x - centerPt.x) / 32;
7336
+ double sign = 1;
7337
+ if (hScale < 0)
7338
+ {
7339
+ sign = -1;
7340
+ }
7341
+ hScale = sign*Math.pow(sign*hScale, scale * 50);
72087342 if (hScale < 0.01)
72097343 {
7210
- hScale = 0.01;
7344
+ //hScale = 0.01;
72117345 }
7212
- hScale = Math.pow(hScale, scale * 50);
7213
- if (hScale < 0.01)
7214
- {
7215
- hScale = 0.01;
7216
- }
7346
+
72177347 double vScale = (double) (info.y - centerPt.y) / 32;
7218
- if (vScale < 0.01)
7348
+ sign = 1;
7349
+ if (vScale < 0)
72197350 {
7220
- vScale = 0.01;
7351
+ sign = -1;
72217352 }
7222
- vScale = Math.pow(vScale, scale * 50);
7353
+ vScale = sign*Math.pow(sign*vScale, scale * 50);
72237354 if (vScale < 0.01)
72247355 {
7225
- vScale = 0.01;
7356
+ //vScale = 0.01;
72267357 }
72277358 LA.matCopy(startMat, toParent);
72287359 /**/
....@@ -7233,17 +7364,24 @@
72337364 }
72347365 /**/
72357366
7367
+ double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2);
7368
+
7369
+ if (totalScale < 0.01)
7370
+ {
7371
+ totalScale = 0.01;
7372
+ }
7373
+
72367374 switch (info.pane.RenderCamera().viewCode)
72377375 {
72387376 case 3: // '\001'
72397377 if (modified)
72407378 {
72417379 //LA.matScale(toParent, 1, hScale, vScale);
7242
- LA.matScale(toParent, vScale, 1, 1);
7380
+ LA.matScale(toParent, totalScale, 1, 1);
72437381 } // vScale, 1);
72447382 else
72457383 {
7246
- LA.matScale(toParent, vScale, vScale, vScale);
7384
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
72477385 } // vScale, 1);
72487386 break;
72497387
....@@ -7251,10 +7389,10 @@
72517389 if (modified)
72527390 {
72537391 //LA.matScale(toParent, hScale, 1, vScale);
7254
- LA.matScale(toParent, 1, vScale, 1);
7392
+ LA.matScale(toParent, 1, totalScale, 1);
72557393 } else
72567394 {
7257
- LA.matScale(toParent, vScale, 1, vScale);
7395
+ LA.matScale(toParent, totalScale, 1, totalScale);
72587396 }
72597397 break;
72607398
....@@ -7262,10 +7400,10 @@
72627400 if (modified)
72637401 {
72647402 //LA.matScale(toParent, hScale, vScale, 1);
7265
- LA.matScale(toParent, 1, 1, vScale);
7403
+ LA.matScale(toParent, 1, 1, totalScale);
72667404 } else
72677405 {
7268
- LA.matScale(toParent, vScale, vScale, 1);
7406
+ LA.matScale(toParent, totalScale, totalScale, 1);
72697407 }
72707408 break;
72717409 }
....@@ -7406,7 +7544,7 @@
74067544 objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
74077545 } else
74087546 {
7409
- objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count /*- 1*/) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
7547
+ objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count - 1) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
74107548 } // + super.toString();
74117549 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
74127550
....@@ -7490,7 +7628,7 @@
74907628 /*transient*/ cVector2[] projectedVertices = new cVector2[0];
74917629
74927630 Object3D /*Composite*/ parent;
7493
- Object3D /*Composite*/ fileparent;
7631
+ Object3D /*Composite*/ fileparent; // In the case of FileObject
74947632
74957633 double[][] toParent; // dynamic matrix
74967634 double[][] fromParent;
....@@ -7654,9 +7792,9 @@
76547792 private static cVector edge2 = new cVector();
76557793 //private static cVector norm = new cVector();
76567794 /*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;
7795
+ static final int hitCenter = 1;
7796
+ static final int hitScale = 2;
7797
+ static final int hitRotate = 3;
76607798 /*transient*/ /*private*/ int viewCode; // Now used for transparency cache flag
76617799 /*transient*/ private Point centerPt;
76627800 /*transient*/ private int startX;