Normand Briere
2019-06-11 d0dc7ff35d71919d503ae35592478b173cf3cfd3
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,59 @@
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
+ return;
170
+
171
+ Object3D o = new Object3D();
172
+ o.bRep = this.bRep;
173
+ if (this.bRep != null)
174
+ {
175
+ o.transientrep = this.bRep.support;
176
+ o.bRep.support = null;
177
+ }
178
+
179
+// o.support = this.support;
180
+// o.fileparent = this.fileparent;
181
+// if (this.bRep != null)
182
+// o.bRep = this.bRep.support;
183
+
184
+ hashtable.put(GetUUID(), o);
185
+
186
+ this.bRep = null;
187
+// if (this.bRep != null)
188
+// this.bRep.support = null;
189
+// this.support = null;
190
+// this.fileparent = null;
191
+
192
+ for (int i=0; i<Size(); i++)
193
+ {
194
+ get(i).ExtractBigData(hashtable);
195
+ }
196
+}
197
+
198
+void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
199
+{
200
+ if (!hashtable.containsKey(GetUUID()))
201
+ return;
202
+
203
+ Object3D o = hashtable.get(GetUUID());
204
+
205
+ this.bRep = o.bRep;
206
+ if (this.bRep != null)
207
+ this.bRep.support = o.transientrep;
208
+// this.support = o.support;
209
+// this.fileparent = o.fileparent;
210
+
211
+ hashtable.remove(GetUUID());
212
+
213
+ for (int i=0; i<Size(); i++)
214
+ {
215
+ get(i).RestoreBigData(hashtable);
159216 }
160217 }
161218
....@@ -300,6 +357,7 @@
300357 }
301358
302359 boolean live = false;
360
+ boolean dontselect = false;
303361 boolean hide = false;
304362 boolean link2master = false; // performs reset support/master at each frame
305363 boolean marked = false; // animation node
....@@ -774,7 +832,7 @@
774832 if (step == 0)
775833 step = 1;
776834 if (maxcount == 0)
777
- maxcount = 2048; // 4;
835
+ maxcount = 128; // 2048; // 4;
778836 // if (acceleration == 0)
779837 // acceleration = 10;
780838 if (delay == 0) // serial
....@@ -1834,12 +1892,15 @@
18341892 if (obj.name == null)
18351893 continue; // can't be a null one
18361894
1895
+ // Try perfect match first.
18371896 if (n.equals(obj.name))
18381897 {
18391898 theobj = obj;
18401899 count++;
18411900 }
18421901 }
1902
+
1903
+ // not needed: n = n.split(":")[0]; // Poser generates a count
18431904
18441905 if (count != 1)
18451906 for (int i=Size(); --i>=0;)
....@@ -3002,8 +3063,10 @@
30023063 v.fromParent = LA.newMatrix();
30033064 }
30043065
3005
- LA.matConcat(v.toParent, toParent, v.toParent);
3006
- LA.matConcat(fromParent, v.fromParent, v.fromParent);
3066
+// LA.matConcat(v.toParent, toParent, v.toParent);
3067
+// LA.matConcat(fromParent, v.fromParent, v.fromParent);
3068
+ LA.matConcat(toParent, v.toParent, v.toParent);
3069
+ LA.matConcat(v.fromParent, fromParent, v.fromParent);
30073070 }
30083071
30093072 toParent = null; // LA.matIdentity(toParent);
....@@ -3236,7 +3299,9 @@
32363299 bRep.support = null;
32373300 BoundaryRep temprep = (BoundaryRep) Grafreed.clone(bRep);
32383301 // bRep.SplitInTwo(onlyone); // thread...
3239
- temprep.SplitInTwo(reduction34, onlyone);
3302
+
3303
+ while(temprep.SplitInTwo(reduction34, onlyone));
3304
+
32403305 bRep = temprep;
32413306 bRep.support = sup;
32423307 Touch();
....@@ -4711,7 +4776,7 @@
47114776
47124777 cTreePath SelectLeaf(int indexcount, boolean deselect)
47134778 {
4714
- if (hide)
4779
+ if (hide || dontselect)
47154780 return null;
47164781
47174782 if (count <= 0)
....@@ -4737,7 +4802,7 @@
47374802
47384803 cTreePath Select(int indexcount, boolean deselect)
47394804 {
4740
- if (hide)
4805
+ if (hide || dontselect)
47414806 return null;
47424807
47434808 if (count <= 0)
....@@ -5363,6 +5428,43 @@
53635428 }
53645429 }
53655430
5431
+ UUID GetUUID()
5432
+ {
5433
+ if (uuid == null)
5434
+ {
5435
+ // Serial
5436
+ uuid = UUID.randomUUID();
5437
+ }
5438
+
5439
+ return uuid;
5440
+ }
5441
+
5442
+ Object3D GetObject(UUID uid)
5443
+ {
5444
+ if (blockloop)
5445
+ return null;
5446
+
5447
+ if (GetUUID().equals(uid))
5448
+ return this;
5449
+
5450
+ int nb = Size();
5451
+ for (int i = 0; i < nb; i++)
5452
+ {
5453
+ Object3D child = (Object3D) get(i);
5454
+
5455
+ if (child == null)
5456
+ continue;
5457
+
5458
+ blockloop = true;
5459
+ Object3D obj = child.GetObject(uid);
5460
+ blockloop = false;
5461
+ if (obj != null)
5462
+ return obj;
5463
+ }
5464
+
5465
+ return null;
5466
+ }
5467
+
53665468 void SetBumpTexture(String tex)
53675469 {
53685470 if (GetTextures() == null)
....@@ -5407,7 +5509,7 @@
54075509 boolean NeedSupport()
54085510 {
54095511 return
5410
- CameraPane.SUPPORT && !CameraPane.movingcamera && link2master && /*live &&*/ support != null
5512
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || !Globals.FREEZEONMOVE) && link2master && /*live &&*/ support != null
54115513 // PROBLEM with CROWD!!
54125514 && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
54135515 }
....@@ -5424,7 +5526,7 @@
54245526 }
54255527
54265528 if (display.DrawMode() == iCameraPane.SELECTION &&
5427
- hide)
5529
+ (hide || dontselect))
54285530 return;
54295531
54305532 if (name != null && name.contains("sclera"))
....@@ -5666,7 +5768,17 @@
56665768 tex = GetTextures();
56675769 }
56685770
5669
- display.BindTextures(tex, texres);
5771
+ boolean failed = false;
5772
+
5773
+ try
5774
+ {
5775
+ display.BindTextures(tex, texres);
5776
+ }
5777
+ catch (Exception e)
5778
+ {
5779
+ System.err.println("FAILED: " + this);
5780
+ failed = true;
5781
+ }
56705782
56715783 if (!compiled)
56725784 {
....@@ -5688,7 +5800,8 @@
56885800 }
56895801 }
56905802
5691
- display.ReleaseTextures(tex);
5803
+ if (!failed)
5804
+ display.ReleaseTextures(tex);
56925805
56935806 display.PopMaterial(this, selected);
56945807 }
....@@ -5817,6 +5930,9 @@
58175930
58185931 void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
58195932 {
5933
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
5934
+ return;
5935
+
58205936 if (hide)
58215937 return;
58225938 // shadow optimisation
....@@ -5941,6 +6057,9 @@
59416057 {
59426058 if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
59436059 return; // no shadow for transparent objects
6060
+
6061
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6062
+ return;
59446063
59456064 if (hide)
59466065 return;
....@@ -6925,8 +7044,8 @@
69257044 // {
69267045 // CameraPane.Ymax = spoth;
69277046 // }
6928
- info.g.drawLine(spotw, spoth, spotw, spoth - 15);
6929
- info.g.drawLine(spotw, spoth, spotw - 15, spoth);
7047
+ // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - 15);
7048
+ //info.g.drawLine(spotw, spoth, spotw - 15, spoth);
69307049 spot.translate(0, -32);
69317050 info.g.setColor(Color.green);
69327051 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
....@@ -6981,7 +7100,7 @@
69817100 startX = info.x;
69827101 startY = info.y;
69837102
6984
- hitSomething = 0;
7103
+ hitSomething = -1;
69857104 cVector origin = new cVector();
69867105 //LA.xformPos(origin, toParent, origin);
69877106 Rectangle spot = new Rectangle();
....@@ -7057,6 +7176,7 @@
70577176 //System.out.println("hitSomething = " + hitSomething);
70587177
70597178 double scale = 0.005f * info.camera.Distance();
7179
+
70607180 cVector xlate = new cVector();
70617181 //cVector xlate2 = new cVector();
70627182 switch (hitSomething)
....@@ -7205,24 +7325,27 @@
72057325
72067326 case hitScale: // scale
72077327 double hScale = (double) (info.x - centerPt.x) / 32;
7328
+ double sign = 1;
7329
+ if (hScale < 0)
7330
+ {
7331
+ sign = -1;
7332
+ }
7333
+ hScale = sign*Math.pow(sign*hScale, scale * 50);
72087334 if (hScale < 0.01)
72097335 {
7210
- hScale = 0.01;
7336
+ //hScale = 0.01;
72117337 }
7212
- hScale = Math.pow(hScale, scale * 50);
7213
- if (hScale < 0.01)
7214
- {
7215
- hScale = 0.01;
7216
- }
7338
+
72177339 double vScale = (double) (info.y - centerPt.y) / 32;
7218
- if (vScale < 0.01)
7340
+ sign = 1;
7341
+ if (vScale < 0)
72197342 {
7220
- vScale = 0.01;
7343
+ sign = -1;
72217344 }
7222
- vScale = Math.pow(vScale, scale * 50);
7345
+ vScale = sign*Math.pow(sign*vScale, scale * 50);
72237346 if (vScale < 0.01)
72247347 {
7225
- vScale = 0.01;
7348
+ //vScale = 0.01;
72267349 }
72277350 LA.matCopy(startMat, toParent);
72287351 /**/
....@@ -7233,17 +7356,24 @@
72337356 }
72347357 /**/
72357358
7359
+ double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2);
7360
+
7361
+ if (totalScale < 0.01)
7362
+ {
7363
+ totalScale = 0.01;
7364
+ }
7365
+
72367366 switch (info.pane.RenderCamera().viewCode)
72377367 {
72387368 case 3: // '\001'
72397369 if (modified)
72407370 {
72417371 //LA.matScale(toParent, 1, hScale, vScale);
7242
- LA.matScale(toParent, vScale, 1, 1);
7372
+ LA.matScale(toParent, totalScale, 1, 1);
72437373 } // vScale, 1);
72447374 else
72457375 {
7246
- LA.matScale(toParent, vScale, vScale, vScale);
7376
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
72477377 } // vScale, 1);
72487378 break;
72497379
....@@ -7251,10 +7381,10 @@
72517381 if (modified)
72527382 {
72537383 //LA.matScale(toParent, hScale, 1, vScale);
7254
- LA.matScale(toParent, 1, vScale, 1);
7384
+ LA.matScale(toParent, 1, totalScale, 1);
72557385 } else
72567386 {
7257
- LA.matScale(toParent, vScale, 1, vScale);
7387
+ LA.matScale(toParent, totalScale, 1, totalScale);
72587388 }
72597389 break;
72607390
....@@ -7262,10 +7392,10 @@
72627392 if (modified)
72637393 {
72647394 //LA.matScale(toParent, hScale, vScale, 1);
7265
- LA.matScale(toParent, 1, 1, vScale);
7395
+ LA.matScale(toParent, 1, 1, totalScale);
72667396 } else
72677397 {
7268
- LA.matScale(toParent, vScale, vScale, 1);
7398
+ LA.matScale(toParent, totalScale, totalScale, 1);
72697399 }
72707400 break;
72717401 }
....@@ -7406,7 +7536,7 @@
74067536 objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
74077537 } else
74087538 {
7409
- objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count /*- 1*/) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
7539
+ objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count - 1) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
74107540 } // + super.toString();
74117541 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
74127542
....@@ -7490,7 +7620,7 @@
74907620 /*transient*/ cVector2[] projectedVertices = new cVector2[0];
74917621
74927622 Object3D /*Composite*/ parent;
7493
- Object3D /*Composite*/ fileparent;
7623
+ Object3D /*Composite*/ fileparent; // In the case of FileObject
74947624
74957625 double[][] toParent; // dynamic matrix
74967626 double[][] fromParent;
....@@ -7654,9 +7784,9 @@
76547784 private static cVector edge2 = new cVector();
76557785 //private static cVector norm = new cVector();
76567786 /*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;
7787
+ static final int hitCenter = 1;
7788
+ static final int hitScale = 2;
7789
+ static final int hitRotate = 3;
76607790 /*transient*/ /*private*/ int viewCode; // Now used for transparency cache flag
76617791 /*transient*/ private Point centerPt;
76627792 /*transient*/ private int startX;