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
....@@ -797,7 +855,7 @@
797855
798856 if (marked && Globals.isLIVE() && live &&
799857 //TEMP21aug2018
800
- Globals.DrawMode() == iCameraPane.SHADOW &&
858
+ (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW) &&
801859 currentframe != Globals.framecount)
802860 {
803861 currentframe = Globals.framecount;
....@@ -912,6 +970,11 @@
912970 fromParent = null; // LA.newMatrix();
913971 bRep = null; // new BoundaryRep();
914972
973
+ if (oname != null && oname.equals("LeftHand"))
974
+ {
975
+ name = oname;
976
+ }
977
+
915978 /*
916979 float hue = (float)Math.random();
917980 Color col;
....@@ -954,7 +1017,7 @@
9541017
9551018 public Object clone()
9561019 {
957
- return GrafreeD.clone(this);
1020
+ return Grafreed.clone(this);
9581021 }
9591022
9601023 Object3D copyExpand()
....@@ -1470,7 +1533,7 @@
14701533 BoundaryRep.SEUIL = other.material.cameralight;
14711534
14721535 // Set default to 0.1
1473
- BoundaryRep.SEUIL /= 2;
1536
+ BoundaryRep.SEUIL /= 4; // 2;
14741537 System.out.println("SEUIL = " + BoundaryRep.SEUIL);
14751538 }
14761539
....@@ -1729,7 +1792,7 @@
17291792 Object3D o = new Object3D((clone?"Ge:":"Li:") + this.name);
17301793 o.bRep = transientrep;
17311794 if (clone)
1732
- o.bRep = (BoundaryRep) GrafreeD.clone(transientrep);
1795
+ o.bRep = (BoundaryRep) Grafreed.clone(transientrep);
17331796 o.CreateMaterial();
17341797 o.SetAttributes(this, -1);
17351798 //parent
....@@ -1742,7 +1805,7 @@
17421805 Object3D o = new Object3D((clone?"Ge:":"Li:") + this.name);
17431806 o.bRep = bRep;
17441807 if (clone)
1745
- o.bRep = (BoundaryRep) GrafreeD.clone(bRep);
1808
+ o.bRep = (BoundaryRep) Grafreed.clone(bRep);
17461809 o.CreateMaterial();
17471810 //o.overwriteThis(this, -1);
17481811 o.SetAttributes(this, -1);
....@@ -1829,12 +1892,15 @@
18291892 if (obj.name == null)
18301893 continue; // can't be a null one
18311894
1895
+ // Try perfect match first.
18321896 if (n.equals(obj.name))
18331897 {
18341898 theobj = obj;
18351899 count++;
18361900 }
18371901 }
1902
+
1903
+ // not needed: n = n.split(":")[0]; // Poser generates a count
18381904
18391905 if (count != 1)
18401906 for (int i=Size(); --i>=0;)
....@@ -2983,6 +3049,33 @@
29833049 blockloop = false;
29843050 }
29853051
3052
+ void TransformChildren()
3053
+ {
3054
+ if (toParent != null)
3055
+ {
3056
+ for (int i=Size(); --i>=0;)
3057
+ {
3058
+ Object3D v = get(i);
3059
+
3060
+ if (v.toParent == null)
3061
+ {
3062
+ v.toParent = LA.newMatrix();
3063
+ v.fromParent = LA.newMatrix();
3064
+ }
3065
+
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);
3070
+ }
3071
+
3072
+ toParent = null; // LA.matIdentity(toParent);
3073
+ fromParent = null; // LA.matIdentity(fromParent);
3074
+
3075
+ Touch();
3076
+ }
3077
+ }
3078
+
29863079 void TransformGeometry()
29873080 {
29883081 Object3D obj = this;
....@@ -3204,9 +3297,11 @@
32043297
32053298 BoundaryRep sup = bRep.support;
32063299 bRep.support = null;
3207
- BoundaryRep temprep = (BoundaryRep) GrafreeD.clone(bRep);
3300
+ BoundaryRep temprep = (BoundaryRep) Grafreed.clone(bRep);
32083301 // bRep.SplitInTwo(onlyone); // thread...
3209
- temprep.SplitInTwo(reduction34, onlyone);
3302
+
3303
+ while(temprep.SplitInTwo(reduction34, onlyone));
3304
+
32103305 bRep = temprep;
32113306 bRep.support = sup;
32123307 Touch();
....@@ -3728,7 +3823,7 @@
37283823 if (child == null)
37293824 continue;
37303825
3731
- if (GrafreeD.RENDERME > 0)
3826
+ if (Grafreed.RENDERME > 0)
37323827 {
37333828 if (child instanceof Merge)
37343829 ((Merge)child).renderme();
....@@ -3879,7 +3974,7 @@
38793974 if (child == null)
38803975 continue;
38813976
3882
- if (GrafreeD.RENDERME > 0)
3977
+ if (Grafreed.RENDERME > 0)
38833978 {
38843979 if (child instanceof Merge)
38853980 ((Merge)child).renderme();
....@@ -4074,7 +4169,7 @@
40744169 if (child == null)
40754170 continue;
40764171
4077
- if (GrafreeD.RENDERME > 0)
4172
+ if (Grafreed.RENDERME > 0)
40784173 {
40794174 if (child instanceof Merge)
40804175 ((Merge)child).renderme();
....@@ -4681,7 +4776,7 @@
46814776
46824777 cTreePath SelectLeaf(int indexcount, boolean deselect)
46834778 {
4684
- if (hide)
4779
+ if (hide || dontselect)
46854780 return null;
46864781
46874782 if (count <= 0)
....@@ -4707,7 +4802,7 @@
47074802
47084803 cTreePath Select(int indexcount, boolean deselect)
47094804 {
4710
- if (hide)
4805
+ if (hide || dontselect)
47114806 return null;
47124807
47134808 if (count <= 0)
....@@ -5333,6 +5428,43 @@
53335428 }
53345429 }
53355430
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
+
53365468 void SetBumpTexture(String tex)
53375469 {
53385470 if (GetTextures() == null)
....@@ -5377,9 +5509,9 @@
53775509 boolean NeedSupport()
53785510 {
53795511 return
5380
- CameraPane.SUPPORT && !CameraPane.movingcamera && link2master && /*live &&*/ support != null
5512
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || !Globals.FREEZEONMOVE) && link2master && /*live &&*/ support != null
53815513 // PROBLEM with CROWD!!
5382
- && (Globals.DrawMode() == iCameraPane.SHADOW || Globals.CROWD);
5514
+ && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
53835515 }
53845516
53855517 static boolean DEBUG_SELECTION = false;
....@@ -5394,7 +5526,7 @@
53945526 }
53955527
53965528 if (display.DrawMode() == iCameraPane.SELECTION &&
5397
- hide)
5529
+ (hide || dontselect))
53985530 return;
53995531
54005532 if (name != null && name.contains("sclera"))
....@@ -5636,7 +5768,17 @@
56365768 tex = GetTextures();
56375769 }
56385770
5639
- 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
+ }
56405782
56415783 if (!compiled)
56425784 {
....@@ -5658,7 +5800,8 @@
56585800 }
56595801 }
56605802
5661
- display.ReleaseTextures(tex);
5803
+ if (!failed)
5804
+ display.ReleaseTextures(tex);
56625805
56635806 display.PopMaterial(this, selected);
56645807 }
....@@ -5787,6 +5930,9 @@
57875930
57885931 void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
57895932 {
5933
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
5934
+ return;
5935
+
57905936 if (hide)
57915937 return;
57925938 // shadow optimisation
....@@ -5911,6 +6057,9 @@
59116057 {
59126058 if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
59136059 return; // no shadow for transparent objects
6060
+
6061
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6062
+ return;
59146063
59156064 if (hide)
59166065 return;
....@@ -6895,8 +7044,8 @@
68957044 // {
68967045 // CameraPane.Ymax = spoth;
68977046 // }
6898
- info.g.drawLine(spotw, spoth, spotw, spoth - 15);
6899
- 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);
69007049 spot.translate(0, -32);
69017050 info.g.setColor(Color.green);
69027051 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
....@@ -6951,7 +7100,7 @@
69517100 startX = info.x;
69527101 startY = info.y;
69537102
6954
- hitSomething = 0;
7103
+ hitSomething = -1;
69557104 cVector origin = new cVector();
69567105 //LA.xformPos(origin, toParent, origin);
69577106 Rectangle spot = new Rectangle();
....@@ -7027,6 +7176,7 @@
70277176 //System.out.println("hitSomething = " + hitSomething);
70287177
70297178 double scale = 0.005f * info.camera.Distance();
7179
+
70307180 cVector xlate = new cVector();
70317181 //cVector xlate2 = new cVector();
70327182 switch (hitSomething)
....@@ -7175,24 +7325,27 @@
71757325
71767326 case hitScale: // scale
71777327 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);
71787334 if (hScale < 0.01)
71797335 {
7180
- hScale = 0.01;
7336
+ //hScale = 0.01;
71817337 }
7182
- hScale = Math.pow(hScale, scale * 50);
7183
- if (hScale < 0.01)
7184
- {
7185
- hScale = 0.01;
7186
- }
7338
+
71877339 double vScale = (double) (info.y - centerPt.y) / 32;
7188
- if (vScale < 0.01)
7340
+ sign = 1;
7341
+ if (vScale < 0)
71897342 {
7190
- vScale = 0.01;
7343
+ sign = -1;
71917344 }
7192
- vScale = Math.pow(vScale, scale * 50);
7345
+ vScale = sign*Math.pow(sign*vScale, scale * 50);
71937346 if (vScale < 0.01)
71947347 {
7195
- vScale = 0.01;
7348
+ //vScale = 0.01;
71967349 }
71977350 LA.matCopy(startMat, toParent);
71987351 /**/
....@@ -7203,17 +7356,24 @@
72037356 }
72047357 /**/
72057358
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
+
72067366 switch (info.pane.RenderCamera().viewCode)
72077367 {
72087368 case 3: // '\001'
72097369 if (modified)
72107370 {
72117371 //LA.matScale(toParent, 1, hScale, vScale);
7212
- LA.matScale(toParent, vScale, 1, 1);
7372
+ LA.matScale(toParent, totalScale, 1, 1);
72137373 } // vScale, 1);
72147374 else
72157375 {
7216
- LA.matScale(toParent, vScale, vScale, vScale);
7376
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
72177377 } // vScale, 1);
72187378 break;
72197379
....@@ -7221,10 +7381,10 @@
72217381 if (modified)
72227382 {
72237383 //LA.matScale(toParent, hScale, 1, vScale);
7224
- LA.matScale(toParent, 1, vScale, 1);
7384
+ LA.matScale(toParent, 1, totalScale, 1);
72257385 } else
72267386 {
7227
- LA.matScale(toParent, vScale, 1, vScale);
7387
+ LA.matScale(toParent, totalScale, 1, totalScale);
72287388 }
72297389 break;
72307390
....@@ -7232,10 +7392,10 @@
72327392 if (modified)
72337393 {
72347394 //LA.matScale(toParent, hScale, vScale, 1);
7235
- LA.matScale(toParent, 1, 1, vScale);
7395
+ LA.matScale(toParent, 1, 1, totalScale);
72367396 } else
72377397 {
7238
- LA.matScale(toParent, vScale, vScale, 1);
7398
+ LA.matScale(toParent, totalScale, totalScale, 1);
72397399 }
72407400 break;
72417401 }
....@@ -7368,14 +7528,22 @@
73687528 //return super.toString() + " (id=" + list + ")" + " (brep=" + bRep + ")";
73697529 //return name + " (id=" + list + ")" + " (brep=" + bRep + ") " + super.toString();
73707530 //return name + " (#tri = " + (bRep==null?0:bRep.VertexCount()) + ") " + super.toString();
7531
+
7532
+ String objname;
7533
+
73717534 if (false) //parent != null)
73727535 {
7373
- return name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
7536
+ objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
73747537 } else
73757538 {
7376
- return GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count /*- 1*/) + ") ")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ +System.identityHashCode(this);
7539
+ objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count - 1) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
73777540 } // + super.toString();
73787541 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
7542
+
7543
+ if (!Globals.ADVANCED)
7544
+ return objname;
7545
+
7546
+ return objname + " " + System.identityHashCode(this);
73797547 }
73807548
73817549 public int hashCode()
....@@ -7452,7 +7620,7 @@
74527620 /*transient*/ cVector2[] projectedVertices = new cVector2[0];
74537621
74547622 Object3D /*Composite*/ parent;
7455
- Object3D /*Composite*/ fileparent;
7623
+ Object3D /*Composite*/ fileparent; // In the case of FileObject
74567624
74577625 double[][] toParent; // dynamic matrix
74587626 double[][] fromParent;
....@@ -7567,7 +7735,7 @@
75677735 {
75687736 assert(bRep != null);
75697737 if (!(support instanceof GenericJoint)) // support.bRep != null)
7570
- GrafreeD.Assert(support.bRep == bRep.support);
7738
+ Grafreed.Assert(support.bRep == bRep.support);
75717739 }
75727740 else
75737741 {
....@@ -7616,9 +7784,9 @@
76167784 private static cVector edge2 = new cVector();
76177785 //private static cVector norm = new cVector();
76187786 /*transient private*/ int hitSomething;
7619
- private static final int hitCenter = 1;
7620
- private static final int hitScale = 2;
7621
- private static final int hitRotate = 3;
7787
+ static final int hitCenter = 1;
7788
+ static final int hitScale = 2;
7789
+ static final int hitRotate = 3;
76227790 /*transient*/ /*private*/ int viewCode; // Now used for transparency cache flag
76237791 /*transient*/ private Point centerPt;
76247792 /*transient*/ private int startX;