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;)
....@@ -2477,13 +2490,13 @@
24772490 return retval;
24782491 }
24792492
2480
- void doEditDrag(ClickInfo info)
2493
+ void doEditDrag(ClickInfo info, boolean opposite)
24812494 {
24822495 switch (doSomething)
24832496 {
24842497 case 1: // '\001'
24852498 //super.
2486
- doEditDrag0(info);
2499
+ doEditDrag0(info, opposite);
24872500 break;
24882501
24892502 case 2: // '\002'
....@@ -2496,11 +2509,11 @@
24962509 {
24972510 //sel.hitSomething = childToDrag.hitSomething;
24982511 //childToDrag.doEditDrag(info);
2499
- sel.doEditDrag(info);
2512
+ sel.doEditDrag(info, opposite);
25002513 } else
25012514 {
25022515 //super.
2503
- doEditDrag0(info);
2516
+ doEditDrag0(info, opposite);
25042517 }
25052518 }
25062519 break;
....@@ -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)
....@@ -5159,10 +5201,34 @@
51595201
51605202 // System.out.println("Fullname = " + fullname);
51615203
5162
- if (fullname.name.indexOf(":") == -1)
5163
- 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(":"));
51645209
5165
- 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];
51665232 }
51675233
51685234 static String GetBump(cTexture fullname)
....@@ -5171,10 +5237,38 @@
51715237 return "";
51725238
51735239 // System.out.println("Fullname = " + fullname);
5174
- if (fullname.name.indexOf(":") == -1)
5175
- return "";
5176
-
5177
- 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];
51785272 }
51795273
51805274 String GetPigmentTexture()
....@@ -5248,7 +5342,7 @@
52485342 System.out.print("; textures = " + textures);
52495343 System.out.println("; usedtextures = " + usedtextures);
52505344
5251
- if (GetTextures() == null)
5345
+ if (GetTextures() == null) // What is that??
52525346 GetTextures().name = ":";
52535347
52545348 String texname = tex;
....@@ -5279,6 +5373,43 @@
52795373 child.ResetPigmentTexture();
52805374 blockloop = false;
52815375 }
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;
52825413 }
52835414
52845415 void SetBumpTexture(String tex)
....@@ -5325,9 +5456,9 @@
53255456 boolean NeedSupport()
53265457 {
53275458 return
5328
- CameraPane.SUPPORT && !CameraPane.movingcamera && link2master && /*live &&*/ support != null
5459
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || !Globals.FREEZEONMOVE) && link2master && /*live &&*/ support != null
53295460 // PROBLEM with CROWD!!
5330
- && (Globals.DrawMode() == iCameraPane.SHADOW || Globals.CROWD);
5461
+ && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
53315462 }
53325463
53335464 static boolean DEBUG_SELECTION = false;
....@@ -5342,7 +5473,7 @@
53425473 }
53435474
53445475 if (display.DrawMode() == iCameraPane.SELECTION &&
5345
- hide)
5476
+ (hide || dontselect))
53465477 return;
53475478
53485479 if (name != null && name.contains("sclera"))
....@@ -5584,7 +5715,17 @@
55845715 tex = GetTextures();
55855716 }
55865717
5587
- 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
+ }
55885729
55895730 if (!compiled)
55905731 {
....@@ -5606,7 +5747,8 @@
56065747 }
56075748 }
56085749
5609
- display.ReleaseTextures(tex);
5750
+ if (!failed)
5751
+ display.ReleaseTextures(tex);
56105752
56115753 display.PopMaterial(this, selected);
56125754 }
....@@ -5735,6 +5877,9 @@
57355877
57365878 void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
57375879 {
5880
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
5881
+ return;
5882
+
57385883 if (hide)
57395884 return;
57405885 // shadow optimisation
....@@ -5859,6 +6004,9 @@
58596004 {
58606005 if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
58616006 return; // no shadow for transparent objects
6007
+
6008
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6009
+ return;
58626010
58636011 if (hide)
58646012 return;
....@@ -6843,8 +6991,8 @@
68436991 // {
68446992 // CameraPane.Ymax = spoth;
68456993 // }
6846
- info.g.drawLine(spotw, spoth, spotw, spoth - 15);
6847
- 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);
68486996 spot.translate(0, -32);
68496997 info.g.setColor(Color.green);
68506998 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
....@@ -6899,7 +7047,7 @@
68997047 startX = info.x;
69007048 startY = info.y;
69017049
6902
- hitSomething = 0;
7050
+ hitSomething = -1;
69037051 cVector origin = new cVector();
69047052 //LA.xformPos(origin, toParent, origin);
69057053 Rectangle spot = new Rectangle();
....@@ -6932,7 +7080,7 @@
69327080 }
69337081
69347082 //System.out.println("info.modifiers = " + info.modifiers);
6935
- modified = (info.modifiers & CameraPane.META) != 0;
7083
+ modified = (info.modifiers & CameraPane.SHIFT) != 0; // Was META
69367084 //System.out.println("modified = " + modified);
69377085 //new Exception().printStackTrace();
69387086 //viewCode = info.pane.renderCamera.viewCode;
....@@ -6960,7 +7108,7 @@
69607108 return true;
69617109 }
69627110
6963
- void doEditDrag0(ClickInfo info)
7111
+ void doEditDrag0(ClickInfo info, boolean opposite)
69647112 {
69657113 if (hitSomething == 0)
69667114 {
....@@ -6975,6 +7123,7 @@
69757123 //System.out.println("hitSomething = " + hitSomething);
69767124
69777125 double scale = 0.005f * info.camera.Distance();
7126
+
69787127 cVector xlate = new cVector();
69797128 //cVector xlate2 = new cVector();
69807129 switch (hitSomething)
....@@ -6987,7 +7136,7 @@
69877136
69887137 scale *= 0.05f * Globals.theRenderer.RenderCamera().Distance();
69897138
6990
- if (modified)
7139
+ if (modified || opposite)
69917140 {
69927141 //assert(false);
69937142 /*
....@@ -7081,6 +7230,7 @@
70817230
70827231 if (modified)
70837232 {
7233
+ // Rotate 90 degrees
70847234 angle /= (Math.PI / 4);
70857235 angle = Math.floor(angle + 0.5);
70867236 angle *= (Math.PI / 4);
....@@ -7122,24 +7272,27 @@
71227272
71237273 case hitScale: // scale
71247274 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);
71257281 if (hScale < 0.01)
71267282 {
7127
- hScale = 0.01;
7283
+ //hScale = 0.01;
71287284 }
7129
- hScale = Math.pow(hScale, scale * 50);
7130
- if (hScale < 0.01)
7131
- {
7132
- hScale = 0.01;
7133
- }
7285
+
71347286 double vScale = (double) (info.y - centerPt.y) / 32;
7135
- if (vScale < 0.01)
7287
+ sign = 1;
7288
+ if (vScale < 0)
71367289 {
7137
- vScale = 0.01;
7290
+ sign = -1;
71387291 }
7139
- vScale = Math.pow(vScale, scale * 50);
7292
+ vScale = sign*Math.pow(sign*vScale, scale * 50);
71407293 if (vScale < 0.01)
71417294 {
7142
- vScale = 0.01;
7295
+ //vScale = 0.01;
71437296 }
71447297 LA.matCopy(startMat, toParent);
71457298 /**/
....@@ -7150,17 +7303,24 @@
71507303 }
71517304 /**/
71527305
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
+
71537313 switch (info.pane.RenderCamera().viewCode)
71547314 {
71557315 case 3: // '\001'
71567316 if (modified)
71577317 {
71587318 //LA.matScale(toParent, 1, hScale, vScale);
7159
- LA.matScale(toParent, vScale, 1, 1);
7319
+ LA.matScale(toParent, totalScale, 1, 1);
71607320 } // vScale, 1);
71617321 else
71627322 {
7163
- LA.matScale(toParent, vScale, vScale, vScale);
7323
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
71647324 } // vScale, 1);
71657325 break;
71667326
....@@ -7168,10 +7328,10 @@
71687328 if (modified)
71697329 {
71707330 //LA.matScale(toParent, hScale, 1, vScale);
7171
- LA.matScale(toParent, 1, vScale, 1);
7331
+ LA.matScale(toParent, 1, totalScale, 1);
71727332 } else
71737333 {
7174
- LA.matScale(toParent, vScale, 1, vScale);
7334
+ LA.matScale(toParent, totalScale, 1, totalScale);
71757335 }
71767336 break;
71777337
....@@ -7179,10 +7339,10 @@
71797339 if (modified)
71807340 {
71817341 //LA.matScale(toParent, hScale, vScale, 1);
7182
- LA.matScale(toParent, 1, 1, vScale);
7342
+ LA.matScale(toParent, 1, 1, totalScale);
71837343 } else
71847344 {
7185
- LA.matScale(toParent, vScale, vScale, 1);
7345
+ LA.matScale(toParent, totalScale, totalScale, 1);
71867346 }
71877347 break;
71887348 }
....@@ -7315,14 +7475,22 @@
73157475 //return super.toString() + " (id=" + list + ")" + " (brep=" + bRep + ")";
73167476 //return name + " (id=" + list + ")" + " (brep=" + bRep + ") " + super.toString();
73177477 //return name + " (#tri = " + (bRep==null?0:bRep.VertexCount()) + ") " + super.toString();
7478
+
7479
+ String objname;
7480
+
73187481 if (false) //parent != null)
73197482 {
7320
- return name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
7483
+ objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
73217484 } else
73227485 {
7323
- 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) ":"") */ "";
73247487 } // + super.toString();
73257488 //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);
73267494 }
73277495
73287496 public int hashCode()
....@@ -7514,7 +7682,7 @@
75147682 {
75157683 assert(bRep != null);
75167684 if (!(support instanceof GenericJoint)) // support.bRep != null)
7517
- GrafreeD.Assert(support.bRep == bRep.support);
7685
+ Grafreed.Assert(support.bRep == bRep.support);
75187686 }
75197687 else
75207688 {
....@@ -7563,9 +7731,9 @@
75637731 private static cVector edge2 = new cVector();
75647732 //private static cVector norm = new cVector();
75657733 /*transient private*/ int hitSomething;
7566
- private static final int hitCenter = 1;
7567
- private static final int hitScale = 2;
7568
- private static final int hitRotate = 3;
7734
+ static final int hitCenter = 1;
7735
+ static final int hitScale = 2;
7736
+ static final int hitRotate = 3;
75697737 /*transient*/ /*private*/ int viewCode; // Now used for transparency cache flag
75707738 /*transient*/ private Point centerPt;
75717739 /*transient*/ private int startX;