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;
....@@ -2906,7 +2920,8 @@
29062920 {
29072921 if (bRep != null)
29082922 {
2909
- bRep.GenUV();
2923
+ bRep.GenUV(); //1);
2924
+ //bRep.UnfoldUV();
29102925 Touch();
29112926 }
29122927 }
....@@ -2981,6 +2996,33 @@
29812996 blockloop = false;
29822997 }
29832998
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
+
29843026 void TransformGeometry()
29853027 {
29863028 Object3D obj = this;
....@@ -3202,9 +3244,11 @@
32023244
32033245 BoundaryRep sup = bRep.support;
32043246 bRep.support = null;
3205
- BoundaryRep temprep = (BoundaryRep) GrafreeD.clone(bRep);
3247
+ BoundaryRep temprep = (BoundaryRep) Grafreed.clone(bRep);
32063248 // bRep.SplitInTwo(onlyone); // thread...
3207
- temprep.SplitInTwo(reduction34, onlyone);
3249
+
3250
+ while(temprep.SplitInTwo(reduction34, onlyone));
3251
+
32083252 bRep = temprep;
32093253 bRep.support = sup;
32103254 Touch();
....@@ -3726,7 +3770,7 @@
37263770 if (child == null)
37273771 continue;
37283772
3729
- if (GrafreeD.RENDERME > 0)
3773
+ if (Grafreed.RENDERME > 0)
37303774 {
37313775 if (child instanceof Merge)
37323776 ((Merge)child).renderme();
....@@ -3877,7 +3921,7 @@
38773921 if (child == null)
38783922 continue;
38793923
3880
- if (GrafreeD.RENDERME > 0)
3924
+ if (Grafreed.RENDERME > 0)
38813925 {
38823926 if (child instanceof Merge)
38833927 ((Merge)child).renderme();
....@@ -4072,7 +4116,7 @@
40724116 if (child == null)
40734117 continue;
40744118
4075
- if (GrafreeD.RENDERME > 0)
4119
+ if (Grafreed.RENDERME > 0)
40764120 {
40774121 if (child instanceof Merge)
40784122 ((Merge)child).renderme();
....@@ -4679,7 +4723,7 @@
46794723
46804724 cTreePath SelectLeaf(int indexcount, boolean deselect)
46814725 {
4682
- if (hide)
4726
+ if (hide || dontselect)
46834727 return null;
46844728
46854729 if (count <= 0)
....@@ -4705,7 +4749,7 @@
47054749
47064750 cTreePath Select(int indexcount, boolean deselect)
47074751 {
4708
- if (hide)
4752
+ if (hide || dontselect)
47094753 return null;
47104754
47114755 if (count <= 0)
....@@ -5157,10 +5201,34 @@
51575201
51585202 // System.out.println("Fullname = " + fullname);
51595203
5160
- if (fullname.name.indexOf(":") == -1)
5161
- 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(":"));
51625209
5163
- 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];
51645232 }
51655233
51665234 static String GetBump(cTexture fullname)
....@@ -5169,10 +5237,38 @@
51695237 return "";
51705238
51715239 // System.out.println("Fullname = " + fullname);
5172
- if (fullname.name.indexOf(":") == -1)
5173
- return "";
5174
-
5175
- 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];
51765272 }
51775273
51785274 String GetPigmentTexture()
....@@ -5246,7 +5342,7 @@
52465342 System.out.print("; textures = " + textures);
52475343 System.out.println("; usedtextures = " + usedtextures);
52485344
5249
- if (GetTextures() == null)
5345
+ if (GetTextures() == null) // What is that??
52505346 GetTextures().name = ":";
52515347
52525348 String texname = tex;
....@@ -5277,6 +5373,43 @@
52775373 child.ResetPigmentTexture();
52785374 blockloop = false;
52795375 }
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;
52805413 }
52815414
52825415 void SetBumpTexture(String tex)
....@@ -5323,9 +5456,9 @@
53235456 boolean NeedSupport()
53245457 {
53255458 return
5326
- CameraPane.SUPPORT && !CameraPane.movingcamera && link2master && /*live &&*/ support != null
5459
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || !Globals.FREEZEONMOVE) && link2master && /*live &&*/ support != null
53275460 // PROBLEM with CROWD!!
5328
- && (Globals.DrawMode() == iCameraPane.SHADOW || Globals.CROWD);
5461
+ && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
53295462 }
53305463
53315464 static boolean DEBUG_SELECTION = false;
....@@ -5340,7 +5473,7 @@
53405473 }
53415474
53425475 if (display.DrawMode() == iCameraPane.SELECTION &&
5343
- hide)
5476
+ (hide || dontselect))
53445477 return;
53455478
53465479 if (name != null && name.contains("sclera"))
....@@ -5582,7 +5715,17 @@
55825715 tex = GetTextures();
55835716 }
55845717
5585
- 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
+ }
55865729
55875730 if (!compiled)
55885731 {
....@@ -5604,7 +5747,8 @@
56045747 }
56055748 }
56065749
5607
- display.ReleaseTextures(tex);
5750
+ if (!failed)
5751
+ display.ReleaseTextures(tex);
56085752
56095753 display.PopMaterial(this, selected);
56105754 }
....@@ -5733,6 +5877,9 @@
57335877
57345878 void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
57355879 {
5880
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
5881
+ return;
5882
+
57365883 if (hide)
57375884 return;
57385885 // shadow optimisation
....@@ -5858,6 +6005,9 @@
58586005 if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
58596006 return; // no shadow for transparent objects
58606007
6008
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6009
+ return;
6010
+
58616011 if (hide)
58626012 return;
58636013
....@@ -5898,6 +6048,7 @@
58986048 return;
58996049 }
59006050
6051
+ //bRep.GenUV(1/material.diffuseness);
59016052 // bRep.lock = true;
59026053
59036054 //javax.media.opengl.GL gl = display.GetGL();
....@@ -6840,8 +6991,8 @@
68406991 // {
68416992 // CameraPane.Ymax = spoth;
68426993 // }
6843
- info.g.drawLine(spotw, spoth, spotw, spoth - 15);
6844
- 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);
68456996 spot.translate(0, -32);
68466997 info.g.setColor(Color.green);
68476998 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
....@@ -6896,7 +7047,7 @@
68967047 startX = info.x;
68977048 startY = info.y;
68987049
6899
- hitSomething = 0;
7050
+ hitSomething = -1;
69007051 cVector origin = new cVector();
69017052 //LA.xformPos(origin, toParent, origin);
69027053 Rectangle spot = new Rectangle();
....@@ -6929,7 +7080,7 @@
69297080 }
69307081
69317082 //System.out.println("info.modifiers = " + info.modifiers);
6932
- modified = (info.modifiers & CameraPane.META) != 0;
7083
+ modified = (info.modifiers & CameraPane.SHIFT) != 0; // Was META
69337084 //System.out.println("modified = " + modified);
69347085 //new Exception().printStackTrace();
69357086 //viewCode = info.pane.renderCamera.viewCode;
....@@ -6957,7 +7108,7 @@
69577108 return true;
69587109 }
69597110
6960
- void doEditDrag0(ClickInfo info)
7111
+ void doEditDrag0(ClickInfo info, boolean opposite)
69617112 {
69627113 if (hitSomething == 0)
69637114 {
....@@ -6972,6 +7123,7 @@
69727123 //System.out.println("hitSomething = " + hitSomething);
69737124
69747125 double scale = 0.005f * info.camera.Distance();
7126
+
69757127 cVector xlate = new cVector();
69767128 //cVector xlate2 = new cVector();
69777129 switch (hitSomething)
....@@ -6984,7 +7136,7 @@
69847136
69857137 scale *= 0.05f * Globals.theRenderer.RenderCamera().Distance();
69867138
6987
- if (modified)
7139
+ if (modified || opposite)
69887140 {
69897141 //assert(false);
69907142 /*
....@@ -7078,6 +7230,7 @@
70787230
70797231 if (modified)
70807232 {
7233
+ // Rotate 90 degrees
70817234 angle /= (Math.PI / 4);
70827235 angle = Math.floor(angle + 0.5);
70837236 angle *= (Math.PI / 4);
....@@ -7119,24 +7272,27 @@
71197272
71207273 case hitScale: // scale
71217274 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);
71227281 if (hScale < 0.01)
71237282 {
7124
- hScale = 0.01;
7283
+ //hScale = 0.01;
71257284 }
7126
- hScale = Math.pow(hScale, scale * 50);
7127
- if (hScale < 0.01)
7128
- {
7129
- hScale = 0.01;
7130
- }
7285
+
71317286 double vScale = (double) (info.y - centerPt.y) / 32;
7132
- if (vScale < 0.01)
7287
+ sign = 1;
7288
+ if (vScale < 0)
71337289 {
7134
- vScale = 0.01;
7290
+ sign = -1;
71357291 }
7136
- vScale = Math.pow(vScale, scale * 50);
7292
+ vScale = sign*Math.pow(sign*vScale, scale * 50);
71377293 if (vScale < 0.01)
71387294 {
7139
- vScale = 0.01;
7295
+ //vScale = 0.01;
71407296 }
71417297 LA.matCopy(startMat, toParent);
71427298 /**/
....@@ -7147,17 +7303,24 @@
71477303 }
71487304 /**/
71497305
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
+
71507313 switch (info.pane.RenderCamera().viewCode)
71517314 {
71527315 case 3: // '\001'
71537316 if (modified)
71547317 {
71557318 //LA.matScale(toParent, 1, hScale, vScale);
7156
- LA.matScale(toParent, vScale, 1, 1);
7319
+ LA.matScale(toParent, totalScale, 1, 1);
71577320 } // vScale, 1);
71587321 else
71597322 {
7160
- LA.matScale(toParent, vScale, vScale, vScale);
7323
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
71617324 } // vScale, 1);
71627325 break;
71637326
....@@ -7165,10 +7328,10 @@
71657328 if (modified)
71667329 {
71677330 //LA.matScale(toParent, hScale, 1, vScale);
7168
- LA.matScale(toParent, 1, vScale, 1);
7331
+ LA.matScale(toParent, 1, totalScale, 1);
71697332 } else
71707333 {
7171
- LA.matScale(toParent, vScale, 1, vScale);
7334
+ LA.matScale(toParent, totalScale, 1, totalScale);
71727335 }
71737336 break;
71747337
....@@ -7176,10 +7339,10 @@
71767339 if (modified)
71777340 {
71787341 //LA.matScale(toParent, hScale, vScale, 1);
7179
- LA.matScale(toParent, 1, 1, vScale);
7342
+ LA.matScale(toParent, 1, 1, totalScale);
71807343 } else
71817344 {
7182
- LA.matScale(toParent, vScale, vScale, 1);
7345
+ LA.matScale(toParent, totalScale, totalScale, 1);
71837346 }
71847347 break;
71857348 }
....@@ -7312,14 +7475,22 @@
73127475 //return super.toString() + " (id=" + list + ")" + " (brep=" + bRep + ")";
73137476 //return name + " (id=" + list + ")" + " (brep=" + bRep + ") " + super.toString();
73147477 //return name + " (#tri = " + (bRep==null?0:bRep.VertexCount()) + ") " + super.toString();
7478
+
7479
+ String objname;
7480
+
73157481 if (false) //parent != null)
73167482 {
7317
- return name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
7483
+ objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
73187484 } else
73197485 {
7320
- 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) ":"") */ "";
73217487 } // + super.toString();
73227488 //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);
73237494 }
73247495
73257496 public int hashCode()
....@@ -7375,6 +7546,7 @@
73757546 objectUI.closeUI();
73767547 if (editWindow != null)
73777548 {
7549
+ editWindow.ctrlPanel.FlushUI();
73787550 editWindow.refreshContents();
73797551 } // ? new
73807552 objectUI = null;
....@@ -7510,7 +7682,7 @@
75107682 {
75117683 assert(bRep != null);
75127684 if (!(support instanceof GenericJoint)) // support.bRep != null)
7513
- GrafreeD.Assert(support.bRep == bRep.support);
7685
+ Grafreed.Assert(support.bRep == bRep.support);
75147686 }
75157687 else
75167688 {
....@@ -7559,9 +7731,9 @@
75597731 private static cVector edge2 = new cVector();
75607732 //private static cVector norm = new cVector();
75617733 /*transient private*/ int hitSomething;
7562
- private static final int hitCenter = 1;
7563
- private static final int hitScale = 2;
7564
- private static final int hitRotate = 3;
7734
+ static final int hitCenter = 1;
7735
+ static final int hitScale = 2;
7736
+ static final int hitRotate = 3;
75657737 /*transient*/ /*private*/ int viewCode; // Now used for transparency cache flag
75667738 /*transient*/ private Point centerPt;
75677739 /*transient*/ private int startX;