Normand Briere
2019-06-09 8558ae86e65457c512a26339d3660d79eee16ae6
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;)
....@@ -2300,6 +2313,7 @@
23002313 {
23012314 if (newWindow)
23022315 {
2316
+ new Exception().printStackTrace();
23032317 System.exit(0);
23042318 if (parent != null)
23052319 {
....@@ -2476,13 +2490,13 @@
24762490 return retval;
24772491 }
24782492
2479
- void doEditDrag(ClickInfo info)
2493
+ void doEditDrag(ClickInfo info, boolean opposite)
24802494 {
24812495 switch (doSomething)
24822496 {
24832497 case 1: // '\001'
24842498 //super.
2485
- doEditDrag0(info);
2499
+ doEditDrag0(info, opposite);
24862500 break;
24872501
24882502 case 2: // '\002'
....@@ -2495,11 +2509,11 @@
24952509 {
24962510 //sel.hitSomething = childToDrag.hitSomething;
24972511 //childToDrag.doEditDrag(info);
2498
- sel.doEditDrag(info);
2512
+ sel.doEditDrag(info, opposite);
24992513 } else
25002514 {
25012515 //super.
2502
- doEditDrag0(info);
2516
+ doEditDrag0(info, opposite);
25032517 }
25042518 }
25052519 break;
....@@ -2982,6 +2996,33 @@
29822996 blockloop = false;
29832997 }
29842998
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
+
29853026 void TransformGeometry()
29863027 {
29873028 Object3D obj = this;
....@@ -3203,9 +3244,11 @@
32033244
32043245 BoundaryRep sup = bRep.support;
32053246 bRep.support = null;
3206
- BoundaryRep temprep = (BoundaryRep) GrafreeD.clone(bRep);
3247
+ BoundaryRep temprep = (BoundaryRep) Grafreed.clone(bRep);
32073248 // bRep.SplitInTwo(onlyone); // thread...
3208
- temprep.SplitInTwo(reduction34, onlyone);
3249
+
3250
+ while(temprep.SplitInTwo(reduction34, onlyone));
3251
+
32093252 bRep = temprep;
32103253 bRep.support = sup;
32113254 Touch();
....@@ -3727,7 +3770,7 @@
37273770 if (child == null)
37283771 continue;
37293772
3730
- if (GrafreeD.RENDERME > 0)
3773
+ if (Grafreed.RENDERME > 0)
37313774 {
37323775 if (child instanceof Merge)
37333776 ((Merge)child).renderme();
....@@ -3878,7 +3921,7 @@
38783921 if (child == null)
38793922 continue;
38803923
3881
- if (GrafreeD.RENDERME > 0)
3924
+ if (Grafreed.RENDERME > 0)
38823925 {
38833926 if (child instanceof Merge)
38843927 ((Merge)child).renderme();
....@@ -4073,7 +4116,7 @@
40734116 if (child == null)
40744117 continue;
40754118
4076
- if (GrafreeD.RENDERME > 0)
4119
+ if (Grafreed.RENDERME > 0)
40774120 {
40784121 if (child instanceof Merge)
40794122 ((Merge)child).renderme();
....@@ -4680,7 +4723,7 @@
46804723
46814724 cTreePath SelectLeaf(int indexcount, boolean deselect)
46824725 {
4683
- if (hide)
4726
+ if (hide || dontselect)
46844727 return null;
46854728
46864729 if (count <= 0)
....@@ -4706,7 +4749,7 @@
47064749
47074750 cTreePath Select(int indexcount, boolean deselect)
47084751 {
4709
- if (hide)
4752
+ if (hide || dontselect)
47104753 return null;
47114754
47124755 if (count <= 0)
....@@ -5158,10 +5201,34 @@
51585201
51595202 // System.out.println("Fullname = " + fullname);
51605203
5161
- if (fullname.name.indexOf(":") == -1)
5162
- return fullname.name;
5204
+ // Does not work on Windows due to C:
5205
+// if (fullname.name.indexOf(":") == -1)
5206
+// return fullname.name;
5207
+//
5208
+// return fullname.name.substring(0,fullname.name.indexOf(":"));
51635209
5164
- return fullname.name.substring(0,fullname.name.indexOf(":"));
5210
+ String[] split = fullname.name.split(":");
5211
+
5212
+ if (split.length == 0)
5213
+ {
5214
+ return "";
5215
+ }
5216
+
5217
+ if (split.length <= 2)
5218
+ {
5219
+ if (fullname.name.endsWith(":"))
5220
+ {
5221
+ // Windows
5222
+ return fullname.name.substring(0, fullname.name.length()-1);
5223
+ }
5224
+
5225
+ return split[0];
5226
+ }
5227
+
5228
+ // Windows
5229
+ assert(split.length == 4);
5230
+
5231
+ return split[0] + ":" + split[1];
51655232 }
51665233
51675234 static String GetBump(cTexture fullname)
....@@ -5170,10 +5237,38 @@
51705237 return "";
51715238
51725239 // System.out.println("Fullname = " + fullname);
5173
- if (fullname.name.indexOf(":") == -1)
5174
- return "";
5175
-
5176
- return fullname.name.substring(fullname.name.indexOf(":")+1,fullname.name.length());
5240
+ // Does not work on Windows due to C:
5241
+// if (fullname.name.indexOf(":") == -1)
5242
+// return "";
5243
+//
5244
+// return fullname.name.substring(fullname.name.indexOf(":")+1,fullname.name.length());
5245
+ String[] split = fullname.name.split(":");
5246
+
5247
+ if (split.length == 0)
5248
+ {
5249
+ return "";
5250
+ }
5251
+
5252
+ if (split.length == 1)
5253
+ {
5254
+ return "";
5255
+ }
5256
+
5257
+ if (split.length == 2)
5258
+ {
5259
+ if (fullname.name.endsWith(":"))
5260
+ {
5261
+ // Windows
5262
+ return "";
5263
+ }
5264
+
5265
+ return split[1];
5266
+ }
5267
+
5268
+ // Windows
5269
+ assert(split.length == 4);
5270
+
5271
+ return split[2] + ":" + split[3];
51775272 }
51785273
51795274 String GetPigmentTexture()
....@@ -5247,7 +5342,7 @@
52475342 System.out.print("; textures = " + textures);
52485343 System.out.println("; usedtextures = " + usedtextures);
52495344
5250
- if (GetTextures() == null)
5345
+ if (GetTextures() == null) // What is that??
52515346 GetTextures().name = ":";
52525347
52535348 String texname = tex;
....@@ -5278,6 +5373,43 @@
52785373 child.ResetPigmentTexture();
52795374 blockloop = false;
52805375 }
5376
+ }
5377
+
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;
52815413 }
52825414
52835415 void SetBumpTexture(String tex)
....@@ -5324,9 +5456,9 @@
53245456 boolean NeedSupport()
53255457 {
53265458 return
5327
- CameraPane.SUPPORT && !CameraPane.movingcamera && link2master && /*live &&*/ support != null
5459
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || !Globals.FREEZEONMOVE) && link2master && /*live &&*/ support != null
53285460 // PROBLEM with CROWD!!
5329
- && (Globals.DrawMode() == iCameraPane.SHADOW || Globals.CROWD);
5461
+ && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
53305462 }
53315463
53325464 static boolean DEBUG_SELECTION = false;
....@@ -5341,7 +5473,7 @@
53415473 }
53425474
53435475 if (display.DrawMode() == iCameraPane.SELECTION &&
5344
- hide)
5476
+ (hide || dontselect))
53455477 return;
53465478
53475479 if (name != null && name.contains("sclera"))
....@@ -5583,7 +5715,17 @@
55835715 tex = GetTextures();
55845716 }
55855717
5586
- 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
+ }
55875729
55885730 if (!compiled)
55895731 {
....@@ -5605,7 +5747,8 @@
56055747 }
56065748 }
56075749
5608
- display.ReleaseTextures(tex);
5750
+ if (!failed)
5751
+ display.ReleaseTextures(tex);
56095752
56105753 display.PopMaterial(this, selected);
56115754 }
....@@ -5734,6 +5877,9 @@
57345877
57355878 void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
57365879 {
5880
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
5881
+ return;
5882
+
57375883 if (hide)
57385884 return;
57395885 // shadow optimisation
....@@ -5858,6 +6004,9 @@
58586004 {
58596005 if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
58606006 return; // no shadow for transparent objects
6007
+
6008
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6009
+ return;
58616010
58626011 if (hide)
58636012 return;
....@@ -6842,8 +6991,8 @@
68426991 // {
68436992 // CameraPane.Ymax = spoth;
68446993 // }
6845
- info.g.drawLine(spotw, spoth, spotw, spoth - 15);
6846
- 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);
68476996 spot.translate(0, -32);
68486997 info.g.setColor(Color.green);
68496998 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
....@@ -6898,7 +7047,7 @@
68987047 startX = info.x;
68997048 startY = info.y;
69007049
6901
- hitSomething = 0;
7050
+ hitSomething = -1;
69027051 cVector origin = new cVector();
69037052 //LA.xformPos(origin, toParent, origin);
69047053 Rectangle spot = new Rectangle();
....@@ -6931,7 +7080,7 @@
69317080 }
69327081
69337082 //System.out.println("info.modifiers = " + info.modifiers);
6934
- modified = (info.modifiers & CameraPane.META) != 0;
7083
+ modified = (info.modifiers & CameraPane.SHIFT) != 0; // Was META
69357084 //System.out.println("modified = " + modified);
69367085 //new Exception().printStackTrace();
69377086 //viewCode = info.pane.renderCamera.viewCode;
....@@ -6959,7 +7108,7 @@
69597108 return true;
69607109 }
69617110
6962
- void doEditDrag0(ClickInfo info)
7111
+ void doEditDrag0(ClickInfo info, boolean opposite)
69637112 {
69647113 if (hitSomething == 0)
69657114 {
....@@ -6974,6 +7123,7 @@
69747123 //System.out.println("hitSomething = " + hitSomething);
69757124
69767125 double scale = 0.005f * info.camera.Distance();
7126
+
69777127 cVector xlate = new cVector();
69787128 //cVector xlate2 = new cVector();
69797129 switch (hitSomething)
....@@ -6986,7 +7136,7 @@
69867136
69877137 scale *= 0.05f * Globals.theRenderer.RenderCamera().Distance();
69887138
6989
- if (modified)
7139
+ if (modified || opposite)
69907140 {
69917141 //assert(false);
69927142 /*
....@@ -7080,6 +7230,7 @@
70807230
70817231 if (modified)
70827232 {
7233
+ // Rotate 90 degrees
70837234 angle /= (Math.PI / 4);
70847235 angle = Math.floor(angle + 0.5);
70857236 angle *= (Math.PI / 4);
....@@ -7121,24 +7272,27 @@
71217272
71227273 case hitScale: // scale
71237274 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);
71247281 if (hScale < 0.01)
71257282 {
7126
- hScale = 0.01;
7283
+ //hScale = 0.01;
71277284 }
7128
- hScale = Math.pow(hScale, scale * 50);
7129
- if (hScale < 0.01)
7130
- {
7131
- hScale = 0.01;
7132
- }
7285
+
71337286 double vScale = (double) (info.y - centerPt.y) / 32;
7134
- if (vScale < 0.01)
7287
+ sign = 1;
7288
+ if (vScale < 0)
71357289 {
7136
- vScale = 0.01;
7290
+ sign = -1;
71377291 }
7138
- vScale = Math.pow(vScale, scale * 50);
7292
+ vScale = sign*Math.pow(sign*vScale, scale * 50);
71397293 if (vScale < 0.01)
71407294 {
7141
- vScale = 0.01;
7295
+ //vScale = 0.01;
71427296 }
71437297 LA.matCopy(startMat, toParent);
71447298 /**/
....@@ -7149,17 +7303,24 @@
71497303 }
71507304 /**/
71517305
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
+
71527313 switch (info.pane.RenderCamera().viewCode)
71537314 {
71547315 case 3: // '\001'
71557316 if (modified)
71567317 {
71577318 //LA.matScale(toParent, 1, hScale, vScale);
7158
- LA.matScale(toParent, vScale, 1, 1);
7319
+ LA.matScale(toParent, totalScale, 1, 1);
71597320 } // vScale, 1);
71607321 else
71617322 {
7162
- LA.matScale(toParent, vScale, vScale, vScale);
7323
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
71637324 } // vScale, 1);
71647325 break;
71657326
....@@ -7167,10 +7328,10 @@
71677328 if (modified)
71687329 {
71697330 //LA.matScale(toParent, hScale, 1, vScale);
7170
- LA.matScale(toParent, 1, vScale, 1);
7331
+ LA.matScale(toParent, 1, totalScale, 1);
71717332 } else
71727333 {
7173
- LA.matScale(toParent, vScale, 1, vScale);
7334
+ LA.matScale(toParent, totalScale, 1, totalScale);
71747335 }
71757336 break;
71767337
....@@ -7178,10 +7339,10 @@
71787339 if (modified)
71797340 {
71807341 //LA.matScale(toParent, hScale, vScale, 1);
7181
- LA.matScale(toParent, 1, 1, vScale);
7342
+ LA.matScale(toParent, 1, 1, totalScale);
71827343 } else
71837344 {
7184
- LA.matScale(toParent, vScale, vScale, 1);
7345
+ LA.matScale(toParent, totalScale, totalScale, 1);
71857346 }
71867347 break;
71877348 }
....@@ -7314,14 +7475,22 @@
73147475 //return super.toString() + " (id=" + list + ")" + " (brep=" + bRep + ")";
73157476 //return name + " (id=" + list + ")" + " (brep=" + bRep + ") " + super.toString();
73167477 //return name + " (#tri = " + (bRep==null?0:bRep.VertexCount()) + ") " + super.toString();
7478
+
7479
+ String objname;
7480
+
73177481 if (false) //parent != null)
73187482 {
7319
- return name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
7483
+ objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
73207484 } else
73217485 {
7322
- 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) ":"") */ "";
73237487 } // + super.toString();
73247488 //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);
73257494 }
73267495
73277496 public int hashCode()
....@@ -7377,6 +7546,7 @@
73777546 objectUI.closeUI();
73787547 if (editWindow != null)
73797548 {
7549
+ editWindow.ctrlPanel.FlushUI();
73807550 editWindow.refreshContents();
73817551 } // ? new
73827552 objectUI = null;
....@@ -7512,7 +7682,7 @@
75127682 {
75137683 assert(bRep != null);
75147684 if (!(support instanceof GenericJoint)) // support.bRep != null)
7515
- GrafreeD.Assert(support.bRep == bRep.support);
7685
+ Grafreed.Assert(support.bRep == bRep.support);
75167686 }
75177687 else
75187688 {
....@@ -7561,9 +7731,9 @@
75617731 private static cVector edge2 = new cVector();
75627732 //private static cVector norm = new cVector();
75637733 /*transient private*/ int hitSomething;
7564
- private static final int hitCenter = 1;
7565
- private static final int hitScale = 2;
7566
- private static final int hitRotate = 3;
7734
+ static final int hitCenter = 1;
7735
+ static final int hitScale = 2;
7736
+ static final int hitRotate = 3;
75677737 /*transient*/ /*private*/ int viewCode; // Now used for transparency cache flag
75687738 /*transient*/ private Point centerPt;
75697739 /*transient*/ private int startX;