Normand Briere
2019-06-11 5e6a6f3319f0c4c687fe71952ac9ecc17792b83a
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
....@@ -300,6 +304,7 @@
300304 }
301305
302306 boolean live = false;
307
+ boolean dontselect = false;
303308 boolean hide = false;
304309 boolean link2master = false; // performs reset support/master at each frame
305310 boolean marked = false; // animation node
....@@ -774,7 +779,7 @@
774779 if (step == 0)
775780 step = 1;
776781 if (maxcount == 0)
777
- maxcount = 2048; // 4;
782
+ maxcount = 128; // 2048; // 4;
778783 // if (acceleration == 0)
779784 // acceleration = 10;
780785 if (delay == 0) // serial
....@@ -797,7 +802,7 @@
797802
798803 if (marked && Globals.isLIVE() && live &&
799804 //TEMP21aug2018
800
- Globals.DrawMode() == iCameraPane.SHADOW &&
805
+ (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW) &&
801806 currentframe != Globals.framecount)
802807 {
803808 currentframe = Globals.framecount;
....@@ -912,6 +917,11 @@
912917 fromParent = null; // LA.newMatrix();
913918 bRep = null; // new BoundaryRep();
914919
920
+ if (oname != null && oname.equals("LeftHand"))
921
+ {
922
+ name = oname;
923
+ }
924
+
915925 /*
916926 float hue = (float)Math.random();
917927 Color col;
....@@ -954,7 +964,7 @@
954964
955965 public Object clone()
956966 {
957
- return GrafreeD.clone(this);
967
+ return Grafreed.clone(this);
958968 }
959969
960970 Object3D copyExpand()
....@@ -1470,7 +1480,7 @@
14701480 BoundaryRep.SEUIL = other.material.cameralight;
14711481
14721482 // Set default to 0.1
1473
- BoundaryRep.SEUIL /= 2;
1483
+ BoundaryRep.SEUIL /= 4; // 2;
14741484 System.out.println("SEUIL = " + BoundaryRep.SEUIL);
14751485 }
14761486
....@@ -1729,7 +1739,7 @@
17291739 Object3D o = new Object3D((clone?"Ge:":"Li:") + this.name);
17301740 o.bRep = transientrep;
17311741 if (clone)
1732
- o.bRep = (BoundaryRep) GrafreeD.clone(transientrep);
1742
+ o.bRep = (BoundaryRep) Grafreed.clone(transientrep);
17331743 o.CreateMaterial();
17341744 o.SetAttributes(this, -1);
17351745 //parent
....@@ -1742,7 +1752,7 @@
17421752 Object3D o = new Object3D((clone?"Ge:":"Li:") + this.name);
17431753 o.bRep = bRep;
17441754 if (clone)
1745
- o.bRep = (BoundaryRep) GrafreeD.clone(bRep);
1755
+ o.bRep = (BoundaryRep) Grafreed.clone(bRep);
17461756 o.CreateMaterial();
17471757 //o.overwriteThis(this, -1);
17481758 o.SetAttributes(this, -1);
....@@ -1829,12 +1839,15 @@
18291839 if (obj.name == null)
18301840 continue; // can't be a null one
18311841
1842
+ // Try perfect match first.
18321843 if (n.equals(obj.name))
18331844 {
18341845 theobj = obj;
18351846 count++;
18361847 }
18371848 }
1849
+
1850
+ // not needed: n = n.split(":")[0]; // Poser generates a count
18381851
18391852 if (count != 1)
18401853 for (int i=Size(); --i>=0;)
....@@ -2983,6 +2996,33 @@
29832996 blockloop = false;
29842997 }
29852998
2999
+ void TransformChildren()
3000
+ {
3001
+ if (toParent != null)
3002
+ {
3003
+ for (int i=Size(); --i>=0;)
3004
+ {
3005
+ Object3D v = get(i);
3006
+
3007
+ if (v.toParent == null)
3008
+ {
3009
+ v.toParent = LA.newMatrix();
3010
+ v.fromParent = LA.newMatrix();
3011
+ }
3012
+
3013
+// LA.matConcat(v.toParent, toParent, v.toParent);
3014
+// LA.matConcat(fromParent, v.fromParent, v.fromParent);
3015
+ LA.matConcat(toParent, v.toParent, v.toParent);
3016
+ LA.matConcat(v.fromParent, fromParent, v.fromParent);
3017
+ }
3018
+
3019
+ toParent = null; // LA.matIdentity(toParent);
3020
+ fromParent = null; // LA.matIdentity(fromParent);
3021
+
3022
+ Touch();
3023
+ }
3024
+ }
3025
+
29863026 void TransformGeometry()
29873027 {
29883028 Object3D obj = this;
....@@ -3204,9 +3244,11 @@
32043244
32053245 BoundaryRep sup = bRep.support;
32063246 bRep.support = null;
3207
- BoundaryRep temprep = (BoundaryRep) GrafreeD.clone(bRep);
3247
+ BoundaryRep temprep = (BoundaryRep) Grafreed.clone(bRep);
32083248 // bRep.SplitInTwo(onlyone); // thread...
3209
- temprep.SplitInTwo(reduction34, onlyone);
3249
+
3250
+ while(temprep.SplitInTwo(reduction34, onlyone));
3251
+
32103252 bRep = temprep;
32113253 bRep.support = sup;
32123254 Touch();
....@@ -3728,7 +3770,7 @@
37283770 if (child == null)
37293771 continue;
37303772
3731
- if (GrafreeD.RENDERME > 0)
3773
+ if (Grafreed.RENDERME > 0)
37323774 {
37333775 if (child instanceof Merge)
37343776 ((Merge)child).renderme();
....@@ -3879,7 +3921,7 @@
38793921 if (child == null)
38803922 continue;
38813923
3882
- if (GrafreeD.RENDERME > 0)
3924
+ if (Grafreed.RENDERME > 0)
38833925 {
38843926 if (child instanceof Merge)
38853927 ((Merge)child).renderme();
....@@ -4074,7 +4116,7 @@
40744116 if (child == null)
40754117 continue;
40764118
4077
- if (GrafreeD.RENDERME > 0)
4119
+ if (Grafreed.RENDERME > 0)
40784120 {
40794121 if (child instanceof Merge)
40804122 ((Merge)child).renderme();
....@@ -4681,7 +4723,7 @@
46814723
46824724 cTreePath SelectLeaf(int indexcount, boolean deselect)
46834725 {
4684
- if (hide)
4726
+ if (hide || dontselect)
46854727 return null;
46864728
46874729 if (count <= 0)
....@@ -4707,7 +4749,7 @@
47074749
47084750 cTreePath Select(int indexcount, boolean deselect)
47094751 {
4710
- if (hide)
4752
+ if (hide || dontselect)
47114753 return null;
47124754
47134755 if (count <= 0)
....@@ -5333,6 +5375,43 @@
53335375 }
53345376 }
53355377
5378
+ UUID GetUUID()
5379
+ {
5380
+ if (uuid == null)
5381
+ {
5382
+ // Serial
5383
+ uuid = UUID.randomUUID();
5384
+ }
5385
+
5386
+ return uuid;
5387
+ }
5388
+
5389
+ Object3D GetObject(UUID uid)
5390
+ {
5391
+ if (blockloop)
5392
+ return null;
5393
+
5394
+ if (GetUUID().equals(uid))
5395
+ return this;
5396
+
5397
+ int nb = Size();
5398
+ for (int i = 0; i < nb; i++)
5399
+ {
5400
+ Object3D child = (Object3D) get(i);
5401
+
5402
+ if (child == null)
5403
+ continue;
5404
+
5405
+ blockloop = true;
5406
+ Object3D obj = child.GetObject(uid);
5407
+ blockloop = false;
5408
+ if (obj != null)
5409
+ return obj;
5410
+ }
5411
+
5412
+ return null;
5413
+ }
5414
+
53365415 void SetBumpTexture(String tex)
53375416 {
53385417 if (GetTextures() == null)
....@@ -5377,9 +5456,9 @@
53775456 boolean NeedSupport()
53785457 {
53795458 return
5380
- CameraPane.SUPPORT && !CameraPane.movingcamera && link2master && /*live &&*/ support != null
5459
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || !Globals.FREEZEONMOVE) && link2master && /*live &&*/ support != null
53815460 // PROBLEM with CROWD!!
5382
- && (Globals.DrawMode() == iCameraPane.SHADOW || Globals.CROWD);
5461
+ && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
53835462 }
53845463
53855464 static boolean DEBUG_SELECTION = false;
....@@ -5394,7 +5473,7 @@
53945473 }
53955474
53965475 if (display.DrawMode() == iCameraPane.SELECTION &&
5397
- hide)
5476
+ (hide || dontselect))
53985477 return;
53995478
54005479 if (name != null && name.contains("sclera"))
....@@ -5636,7 +5715,17 @@
56365715 tex = GetTextures();
56375716 }
56385717
5639
- display.BindTextures(tex, texres);
5718
+ boolean failed = false;
5719
+
5720
+ try
5721
+ {
5722
+ display.BindTextures(tex, texres);
5723
+ }
5724
+ catch (Exception e)
5725
+ {
5726
+ System.err.println("FAILED: " + this);
5727
+ failed = true;
5728
+ }
56405729
56415730 if (!compiled)
56425731 {
....@@ -5658,7 +5747,8 @@
56585747 }
56595748 }
56605749
5661
- display.ReleaseTextures(tex);
5750
+ if (!failed)
5751
+ display.ReleaseTextures(tex);
56625752
56635753 display.PopMaterial(this, selected);
56645754 }
....@@ -5787,6 +5877,9 @@
57875877
57885878 void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
57895879 {
5880
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
5881
+ return;
5882
+
57905883 if (hide)
57915884 return;
57925885 // shadow optimisation
....@@ -5911,6 +6004,9 @@
59116004 {
59126005 if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
59136006 return; // no shadow for transparent objects
6007
+
6008
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6009
+ return;
59146010
59156011 if (hide)
59166012 return;
....@@ -6895,8 +6991,8 @@
68956991 // {
68966992 // CameraPane.Ymax = spoth;
68976993 // }
6898
- info.g.drawLine(spotw, spoth, spotw, spoth - 15);
6899
- info.g.drawLine(spotw, spoth, spotw - 15, spoth);
6994
+ // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - 15);
6995
+ //info.g.drawLine(spotw, spoth, spotw - 15, spoth);
69006996 spot.translate(0, -32);
69016997 info.g.setColor(Color.green);
69026998 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
....@@ -6951,7 +7047,7 @@
69517047 startX = info.x;
69527048 startY = info.y;
69537049
6954
- hitSomething = 0;
7050
+ hitSomething = -1;
69557051 cVector origin = new cVector();
69567052 //LA.xformPos(origin, toParent, origin);
69577053 Rectangle spot = new Rectangle();
....@@ -7027,6 +7123,7 @@
70277123 //System.out.println("hitSomething = " + hitSomething);
70287124
70297125 double scale = 0.005f * info.camera.Distance();
7126
+
70307127 cVector xlate = new cVector();
70317128 //cVector xlate2 = new cVector();
70327129 switch (hitSomething)
....@@ -7175,24 +7272,27 @@
71757272
71767273 case hitScale: // scale
71777274 double hScale = (double) (info.x - centerPt.x) / 32;
7275
+ double sign = 1;
7276
+ if (hScale < 0)
7277
+ {
7278
+ sign = -1;
7279
+ }
7280
+ hScale = sign*Math.pow(sign*hScale, scale * 50);
71787281 if (hScale < 0.01)
71797282 {
7180
- hScale = 0.01;
7283
+ //hScale = 0.01;
71817284 }
7182
- hScale = Math.pow(hScale, scale * 50);
7183
- if (hScale < 0.01)
7184
- {
7185
- hScale = 0.01;
7186
- }
7285
+
71877286 double vScale = (double) (info.y - centerPt.y) / 32;
7188
- if (vScale < 0.01)
7287
+ sign = 1;
7288
+ if (vScale < 0)
71897289 {
7190
- vScale = 0.01;
7290
+ sign = -1;
71917291 }
7192
- vScale = Math.pow(vScale, scale * 50);
7292
+ vScale = sign*Math.pow(sign*vScale, scale * 50);
71937293 if (vScale < 0.01)
71947294 {
7195
- vScale = 0.01;
7295
+ //vScale = 0.01;
71967296 }
71977297 LA.matCopy(startMat, toParent);
71987298 /**/
....@@ -7203,17 +7303,24 @@
72037303 }
72047304 /**/
72057305
7306
+ double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2);
7307
+
7308
+ if (totalScale < 0.01)
7309
+ {
7310
+ totalScale = 0.01;
7311
+ }
7312
+
72067313 switch (info.pane.RenderCamera().viewCode)
72077314 {
72087315 case 3: // '\001'
72097316 if (modified)
72107317 {
72117318 //LA.matScale(toParent, 1, hScale, vScale);
7212
- LA.matScale(toParent, vScale, 1, 1);
7319
+ LA.matScale(toParent, totalScale, 1, 1);
72137320 } // vScale, 1);
72147321 else
72157322 {
7216
- LA.matScale(toParent, vScale, vScale, vScale);
7323
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
72177324 } // vScale, 1);
72187325 break;
72197326
....@@ -7221,10 +7328,10 @@
72217328 if (modified)
72227329 {
72237330 //LA.matScale(toParent, hScale, 1, vScale);
7224
- LA.matScale(toParent, 1, vScale, 1);
7331
+ LA.matScale(toParent, 1, totalScale, 1);
72257332 } else
72267333 {
7227
- LA.matScale(toParent, vScale, 1, vScale);
7334
+ LA.matScale(toParent, totalScale, 1, totalScale);
72287335 }
72297336 break;
72307337
....@@ -7232,10 +7339,10 @@
72327339 if (modified)
72337340 {
72347341 //LA.matScale(toParent, hScale, vScale, 1);
7235
- LA.matScale(toParent, 1, 1, vScale);
7342
+ LA.matScale(toParent, 1, 1, totalScale);
72367343 } else
72377344 {
7238
- LA.matScale(toParent, vScale, vScale, 1);
7345
+ LA.matScale(toParent, totalScale, totalScale, 1);
72397346 }
72407347 break;
72417348 }
....@@ -7368,14 +7475,22 @@
73687475 //return super.toString() + " (id=" + list + ")" + " (brep=" + bRep + ")";
73697476 //return name + " (id=" + list + ")" + " (brep=" + bRep + ") " + super.toString();
73707477 //return name + " (#tri = " + (bRep==null?0:bRep.VertexCount()) + ") " + super.toString();
7478
+
7479
+ String objname;
7480
+
73717481 if (false) //parent != null)
73727482 {
7373
- return name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
7483
+ objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
73747484 } else
73757485 {
7376
- return GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count /*- 1*/) + ") ")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ +System.identityHashCode(this);
7486
+ objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count - 1) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
73777487 } // + super.toString();
73787488 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
7489
+
7490
+ if (!Globals.ADVANCED)
7491
+ return objname;
7492
+
7493
+ return objname + " " + System.identityHashCode(this);
73797494 }
73807495
73817496 public int hashCode()
....@@ -7567,7 +7682,7 @@
75677682 {
75687683 assert(bRep != null);
75697684 if (!(support instanceof GenericJoint)) // support.bRep != null)
7570
- GrafreeD.Assert(support.bRep == bRep.support);
7685
+ Grafreed.Assert(support.bRep == bRep.support);
75717686 }
75727687 else
75737688 {
....@@ -7616,9 +7731,9 @@
76167731 private static cVector edge2 = new cVector();
76177732 //private static cVector norm = new cVector();
76187733 /*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;
7734
+ static final int hitCenter = 1;
7735
+ static final int hitScale = 2;
7736
+ static final int hitRotate = 3;
76227737 /*transient*/ /*private*/ int viewCode; // Now used for transparency cache flag
76237738 /*transient*/ private Point centerPt;
76247739 /*transient*/ private int startX;