Normand Briere
2019-08-26 6266c8a4b2485b29a7d5bcb217460d7aad3e1c4a
Object3D.java
....@@ -22,6 +22,7 @@
2222 //static final long serialVersionUID = -607422624994562685L;
2323 static final long serialVersionUID = 5022536242724664900L;
2424
25
+ // Use GetUUID for backward compatibility with null.
2526 private UUID uuid = UUID.randomUUID();
2627
2728 // TEMPORARY for mocap undo. No need to be transient.
....@@ -32,11 +33,26 @@
3233 String skyboxname;
3334 String skyboxext;
3435
35
- byte[] versions[];
36
+ Object3D versionlist[];
3637 int versionindex = -1;
3738
39
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable; // = new java.util.Hashtable<java.util.UUID, Object3D>();
40
+
3841 ScriptNode scriptnode;
3942
43
+ int VersionCount()
44
+ {
45
+ int count = 0;
46
+
47
+ for (int i = versionlist.length; --i >= 0;)
48
+ {
49
+ if (versionlist[i] != null)
50
+ count++;
51
+ }
52
+
53
+ return count;
54
+ }
55
+
4056 void InitOthers()
4157 {
4258 if (projectedVertices == null || projectedVertices.length <= 2)
....@@ -222,7 +238,7 @@
222238 // o.bRep.support = null;
223239 // }
224240 o.selection = this.selection;
225
- o.versions = this.versions;
241
+ o.versionlist = this.versionlist;
226242 o.versionindex = this.versionindex;
227243
228244 if (this.support != null)
....@@ -244,6 +260,73 @@
244260 // this.bRep.support = null;
245261 // this.support = null;
246262 // this.fileparent = null;
263
+ }
264
+
265
+// Object3D GetObject(java.util.UUID uuid)
266
+// {
267
+// if (this.uuid.equals(uuid))
268
+// return this;
269
+//
270
+// if (blockloop)
271
+// return null;
272
+//
273
+// blockloop = true;
274
+//
275
+// for (int i=0; i<Size(); i++)
276
+// {
277
+// Object3D o = get(i).GetObject(uuid);
278
+//
279
+// if (o != null)
280
+// return o;
281
+// }
282
+//
283
+// blockloop = false;
284
+//
285
+// return null;
286
+// }
287
+
288
+ transient boolean tag;
289
+
290
+ void TagObjects(Object3D o, boolean tag)
291
+ {
292
+ if (blockloop)
293
+ return;
294
+
295
+ o.tag = tag;
296
+
297
+ if (o == this)
298
+ return;
299
+
300
+ blockloop = true;
301
+
302
+ for (int i=0; i<Size(); i++)
303
+ {
304
+ get(i).TagObjects(o, tag);
305
+ }
306
+
307
+ blockloop = false;
308
+ }
309
+
310
+ boolean HasTags()
311
+ {
312
+ if (blockloop)
313
+ return false;
314
+
315
+ blockloop = true;
316
+
317
+ boolean hasTags = false;
318
+
319
+ for (int i=0; i<Size(); i++)
320
+ {
321
+ hasTags |= get(i).tag || get(i).HasTags();
322
+
323
+ if (hasTags)
324
+ break;
325
+ }
326
+
327
+ blockloop = false;
328
+
329
+ return hasTags;
247330 }
248331
249332 void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
....@@ -280,7 +363,7 @@
280363
281364 this.selection = o.selection;
282365
283
- this.versions = o.versions;
366
+ this.versionlist = o.versionlist;
284367 this.versionindex = o.versionindex;
285368 // July 2019 if (this.bRep != null)
286369 // this.bRep.support = o.transientrep;
....@@ -498,11 +581,11 @@
498581 }
499582 }
500583
501
- int memorysize;
584
+ transient int memorysize; // needs to be transient, dunno why
502585
503586 int MemorySize()
504587 {
505
- if (true) // memorysize == 0)
588
+ if (memorysize == 0)
506589 {
507590 try
508591 {
....@@ -617,7 +700,7 @@
617700 {
618701 if (maxcount != 1)
619702 {
620
- new Exception().printStackTrace();
703
+ //new Exception().printStackTrace();
621704 }
622705
623706 toParentMarked = LA.newMatrix();
....@@ -1014,6 +1097,9 @@
10141097
10151098 if (material == null || material.multiply)
10161099 return true;
1100
+
1101
+ if (projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
1102
+ return false;
10171103
10181104 // Transparent objects are dynamic because we have to sort the triangles.
10191105 return material.opacity > 0.99;
....@@ -2296,11 +2382,6 @@
22962382
22972383 InitOthers();
22982384
2299
- if (this instanceof Camera)
2300
- {
2301
- material.shift = 90;
2302
- }
2303
-
23042385 material.multiply = multiply;
23052386
23062387 if (multiply)
....@@ -2441,6 +2522,11 @@
24412522 else
24422523 {
24432524 //((ObjEditor)editWindow).SetupUI2(null);
2525
+ if (objectUI != null)
2526
+ ((ObjEditor)objectUI).pinButton.setSelected(pinned);
2527
+ else
2528
+ //new Exception().printStackTrace();
2529
+ System.err.println("objectUI is null");
24442530 }
24452531 }
24462532
....@@ -3191,6 +3277,93 @@
31913277 blockloop = false;
31923278 }
31933279
3280
+ public void ResetTransform(int mask)
3281
+ {
3282
+ Object3D obj = this;
3283
+
3284
+ if (mask == -1)
3285
+ {
3286
+ if (obj instanceof Camera) // jan 2014
3287
+ {
3288
+ LA.matIdentity(obj.toParent);
3289
+ LA.matIdentity(obj.fromParent);
3290
+ }
3291
+ else
3292
+ {
3293
+ obj.toParent = null; // jan 2014 LA.matIdentity(obj.toParent);
3294
+ obj.fromParent = null; // LA.matIdentity(obj.fromParent);
3295
+ }
3296
+ return;
3297
+ }
3298
+
3299
+ if ((mask&2) != 0) // Scale/rotation
3300
+ {
3301
+ obj.toParent[0][0] = obj.toParent[1][1] = obj.toParent[2][2] = 1;
3302
+ obj.toParent[0][1] = obj.toParent[1][0] = obj.toParent[2][0] = 0;
3303
+ obj.toParent[0][2] = obj.toParent[1][2] = obj.toParent[2][1] = 0;
3304
+ obj.fromParent[0][0] = obj.fromParent[1][1] = obj.fromParent[2][2] = 1;
3305
+ obj.fromParent[0][1] = obj.fromParent[1][0] = obj.fromParent[2][0] = 0;
3306
+ obj.fromParent[0][2] = obj.fromParent[1][2] = obj.fromParent[2][1] = 0;
3307
+ }
3308
+ if ((mask&1) != 0) // Translation
3309
+ {
3310
+ if (obj.toParent != null)
3311
+ {
3312
+ obj.toParent[3][0] = obj.toParent[3][1] = obj.toParent[3][2] = 0;
3313
+ obj.fromParent[3][0] = obj.fromParent[3][1] = obj.fromParent[3][2] = 0;
3314
+ }
3315
+ }
3316
+ }
3317
+
3318
+ public void TextureRatioTransform(int axis)
3319
+ {
3320
+ cTexture tex = GetTextures();
3321
+
3322
+ com.sun.opengl.util.texture.TextureData texturedata = null;
3323
+
3324
+ try
3325
+ {
3326
+ texturedata = Globals.theRenderer.GetTextureData(tex, false, texres);
3327
+ }
3328
+ catch (Exception e)
3329
+ {
3330
+ System.err.println("FAIL TextureRatio: " + this);
3331
+ }
3332
+
3333
+ LA.matIdentity(Object3D.mat);
3334
+ Object3D.mat[axis][axis] = (double)texturedata.getWidth() / texturedata.getHeight();
3335
+
3336
+ if (toParent == null)
3337
+ {
3338
+ toParent = LA.newMatrix();
3339
+ fromParent = LA.newMatrix();
3340
+ }
3341
+
3342
+ ResetTransform(2);
3343
+
3344
+ LA.matConcat(Object3D.mat, fromParent, fromParent);
3345
+ LA.matInvert(fromParent, toParent);
3346
+ }
3347
+
3348
+ void TextureRatio(int axis)
3349
+ {
3350
+ if (blockloop)
3351
+ return;
3352
+
3353
+ blockloop = true;
3354
+
3355
+ TextureRatioTransform(axis);
3356
+
3357
+ for (int i=Size(); --i>=0;)
3358
+ {
3359
+ Object3D v = get(i);
3360
+
3361
+ v.TextureRatio(axis);
3362
+ }
3363
+
3364
+ blockloop = false;
3365
+ }
3366
+
31943367 void TransformChildren()
31953368 {
31963369 if (toParent != null)
....@@ -3544,15 +3717,47 @@
35443717
35453718 void ClearMaterials()
35463719 {
3720
+ if (blockloop)
3721
+ return;
3722
+
3723
+ blockloop = true;
3724
+
35473725 ClearMaterial();
3548
- for (int i = 0; i < size(); i++)
3726
+ for (int i = 0; i < Size(); i++)
35493727 {
3550
- Object3D child = (Object3D) reserve(i);
3728
+ Object3D child = (Object3D) get(i);
35513729 if (child == null)
35523730 continue;
35533731 child.ClearMaterials();
3554
- release(i);
35553732 }
3733
+
3734
+ blockloop = false;
3735
+ }
3736
+
3737
+ void ClearVersionList()
3738
+ {
3739
+ this.versionlist = null;
3740
+ this.versionindex = -1;
3741
+ this.versiontable = null;
3742
+ }
3743
+
3744
+ void ClearVersions()
3745
+ {
3746
+ if (blockloop)
3747
+ return;
3748
+
3749
+ blockloop = true;
3750
+
3751
+ ClearVersionList();
3752
+ for (int i = 0; i < Size(); i++)
3753
+ {
3754
+ Object3D child = (Object3D) get(i);
3755
+ if (child == null)
3756
+ continue;
3757
+ child.ClearVersions();
3758
+ }
3759
+
3760
+ blockloop = false;
35563761 }
35573762
35583763 void FlipV(boolean flip)
....@@ -5542,6 +5747,11 @@
55425747 if (fullname == null)
55435748 return "";
55445749
5750
+ if (fullname.pigment != null)
5751
+ {
5752
+ return fullname.pigment;
5753
+ }
5754
+
55455755 // System.out.println("Fullname = " + fullname);
55465756
55475757 // Does not work on Windows due to C:
....@@ -5554,7 +5764,7 @@
55545764
55555765 if (split.length == 0)
55565766 {
5557
- return "";
5767
+ return fullname.pigment = "";
55585768 }
55595769
55605770 if (split.length <= 2)
....@@ -5562,22 +5772,27 @@
55625772 if (fullname.name.endsWith(":"))
55635773 {
55645774 // Windows
5565
- return fullname.name.substring(0, fullname.name.length()-1);
5775
+ return fullname.pigment = fullname.name.substring(0, fullname.name.length()-1);
55665776 }
55675777
5568
- return split[0];
5778
+ return fullname.pigment = split[0];
55695779 }
55705780
55715781 // Windows
55725782 assert(split.length == 4);
55735783
5574
- return split[0] + ":" + split[1];
5784
+ return fullname.pigment = split[0] + ":" + split[1];
55755785 }
55765786
55775787 static String GetBump(cTexture fullname)
55785788 {
55795789 if (fullname == null)
55805790 return "";
5791
+
5792
+ if (fullname.bump != null)
5793
+ {
5794
+ return fullname.bump;
5795
+ }
55815796
55825797 // System.out.println("Fullname = " + fullname);
55835798 // Does not work on Windows due to C:
....@@ -5589,12 +5804,12 @@
55895804
55905805 if (split.length == 0)
55915806 {
5592
- return "";
5807
+ return fullname.bump = "";
55935808 }
55945809
55955810 if (split.length == 1)
55965811 {
5597
- return "";
5812
+ return fullname.bump = "";
55985813 }
55995814
56005815 if (split.length == 2)
....@@ -5602,16 +5817,16 @@
56025817 if (fullname.name.endsWith(":"))
56035818 {
56045819 // Windows
5605
- return "";
5820
+ return fullname.bump = "";
56065821 }
56075822
5608
- return split[1];
5823
+ return fullname.bump = split[1];
56095824 }
56105825
56115826 // Windows
56125827 assert(split.length == 4);
56135828
5614
- return split[2] + ":" + split[3];
5829
+ return fullname.bump = split[2] + ":" + split[3];
56155830 }
56165831
56175832 String GetPigmentTexture()
....@@ -5694,6 +5909,9 @@
56945909 texname = "";
56955910
56965911 GetTextures().name = texname + ":" + GetBump(GetTextures());
5912
+
5913
+ GetTextures().pigment = null;
5914
+
56975915 Touch();
56985916 }
56995917
....@@ -5766,6 +5984,8 @@
57665984 texname = "";
57675985
57685986 GetTextures().name = Object3D.GetPigment(GetTextures()) + ":" + texname;
5987
+
5988
+ GetTextures().bump = null;
57695989
57705990 Touch();
57715991 }
....@@ -5849,6 +6069,11 @@
58496069 return parent.IsLive();
58506070 }
58516071
6072
+ boolean IsDynamic()
6073
+ {
6074
+ return live && bRep != null;
6075
+ }
6076
+
58526077 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
58536078 {
58546079 Invariants(); // june 2013
....@@ -5909,8 +6134,11 @@
59096134 if (support != null)
59106135 support = support;
59116136
5912
- //boolean usecalllists = IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5913
- boolean usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6137
+ boolean usecalllists = !IsDynamic() &&
6138
+ IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6139
+ //boolean usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6140
+
6141
+ //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass.
59146142
59156143 if (!usecalllists && bRep != null && bRep.displaylist > 0)
59166144 {
....@@ -5920,8 +6148,9 @@
59206148 // usecalllists &= !(parent instanceof RandomNode);
59216149 // usecalllists = false;
59226150
5923
- if (GetBRep() != null)
5924
- usecalllists = usecalllists;
6151
+ if (display.DrawMode() == display.SHADOW)
6152
+ //GetBRep() != null)
6153
+ usecalllists = !!usecalllists;
59256154 //System.out.println("draw " + this);
59266155 //new Exception().printStackTrace();
59276156
....@@ -5943,7 +6172,7 @@
59436172 if (!(this instanceof Composite))
59446173 touched = false;
59456174 //if (displaylist == -1 && usecalllists)
5946
- if ((bRep != null && bRep.displaylist <= 0) && usecalllists) // june 2013
6175
+ if (bRep.displaylist <= 0 && usecalllists) // && display.DrawMode() == display.DEFAULT) // june 2013
59476176 {
59486177 bRep.displaylist = display.GenList();
59496178 assert(bRep.displaylist != 0);
....@@ -5954,7 +6183,7 @@
59546183
59556184 //System.out.println("\tnew list " + list);
59566185 //gl.glDrawBuffer(gl.GL_NONE);
5957
- if (usecalllists)
6186
+ if (usecalllists && bRep.displaylist > 0)
59586187 {
59596188 // System.err.println("new list " + bRep.displaylist + " for " + this);
59606189 display.NewList(bRep.displaylist);
....@@ -5963,7 +6192,7 @@
59636192 CallList(display, root, selected, blocked);
59646193
59656194 // compiled = true;
5966
- if (usecalllists)
6195
+ if (usecalllists && bRep.displaylist > 0)
59676196 {
59686197 // System.err.println("end list " + bRep.displaylist + " for " + this);
59696198 display.EndList();
....@@ -7367,7 +7596,7 @@
73677596 boundary.y = spot.y - 30;
73687597 boundary.width = spot.width + 60;
73697598 boundary.height = spot.height + 60;
7370
- clickInfo.g.setColor(Color.red);
7599
+ clickInfo.g.setColor(Color.white);
73717600 int spotw = spot.x + spot.width;
73727601 int spoth = spot.y + spot.height;
73737602 clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
....@@ -7387,7 +7616,29 @@
73877616 // {
73887617 // CameraPane.Ymax = spoth;
73897618 // }
7390
- spot.translate(32, 32);
7619
+// if (CameraPane.Xmin > spot.x)
7620
+// {
7621
+// CameraPane.Xmin = spot.x;
7622
+// }
7623
+// if (CameraPane.Xmax < spotw)
7624
+// {
7625
+// CameraPane.Xmax = spotw;
7626
+// }
7627
+// if (CameraPane.Ymin > spot.y)
7628
+// {
7629
+// CameraPane.Ymin = spot.y;
7630
+// }
7631
+// if (CameraPane.Ymax < spoth)
7632
+// {
7633
+// CameraPane.Ymax = spoth;
7634
+// }
7635
+ // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
7636
+ //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
7637
+ spot.translate(32, 0);
7638
+ clickInfo.g.setColor(Color.yellow);
7639
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7640
+
7641
+ spot.translate(32, 64);
73917642 spotw = spot.x + spot.width;
73927643 spoth = spot.y + spot.height;
73937644 clickInfo.g.setColor(Color.cyan);
....@@ -7408,28 +7659,7 @@
74087659 // {
74097660 // CameraPane.Ymax = spoth;
74107661 // }
7411
- // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
7412
- //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
7413
- spot.translate(0, -32);
7414
- clickInfo.g.setColor(Color.yellow);
7415
- clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
74167662 clickInfo.g.setColor(Color.green);
7417
-// if (CameraPane.Xmin > spot.x)
7418
-// {
7419
-// CameraPane.Xmin = spot.x;
7420
-// }
7421
-// if (CameraPane.Xmax < spotw)
7422
-// {
7423
-// CameraPane.Xmax = spotw;
7424
-// }
7425
-// if (CameraPane.Ymin > spot.y)
7426
-// {
7427
-// CameraPane.Ymin = spot.y;
7428
-// }
7429
-// if (CameraPane.Ymax < spoth)
7430
-// {
7431
-// CameraPane.Ymax = spoth;
7432
-// }
74337663 clickInfo.g.drawArc(boundary.x + clickInfo.DX, boundary.y + clickInfo.DY,
74347664 (int)(boundary.width * clickInfo.W), (int)(boundary.height * clickInfo.W), 0, 360);
74357665 //info.g.drawArc(spot.x, spotw, spot.width/2, boundary.height/2, 0, 360);
....@@ -7488,12 +7718,14 @@
74887718 retval = true;
74897719 }
74907720 spot.translate(0, 32);
7721
+ spot.translate(32, 0);
7722
+ spot.translate(0, 32);
74917723 if (spot.contains(clickInfo.x, clickInfo.y))
74927724 {
74937725 hitSomething = hitScale;
74947726
74957727 double scale = 0.005f * clickInfo.camera.Distance();
7496
- double hScale = (double) (clickInfo.x /*- centerPt.x*/) / 32;
7728
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
74977729 double sign = 1;
74987730 if (hScale < 0)
74997731 {
....@@ -7505,7 +7737,7 @@
75057737 //hScale = 0.01;
75067738 }
75077739
7508
- double vScale = (double) (clickInfo.y /*- centerPt.y*/) / 32;
7740
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
75097741 sign = 1;
75107742 if (vScale < 0)
75117743 {
....@@ -7585,7 +7817,9 @@
75857817
75867818 scale *= 0.05f * Globals.theRenderer.RenderCamera().Distance();
75877819
7588
- if (modified || opposite)
7820
+ // Modified could snap
7821
+ if (//modified ||
7822
+ opposite)
75897823 {
75907824 //assert(false);
75917825 /*
....@@ -7679,7 +7913,7 @@
76797913
76807914 if (modified)
76817915 {
7682
- // Rotate 90 degrees
7916
+ // Rotate 45 degrees
76837917 angle /= (Math.PI / 4);
76847918 angle = Math.floor(angle + 0.5);
76857919 angle *= (Math.PI / 4);
....@@ -7720,7 +7954,7 @@
77207954 break;
77217955
77227956 case hitScale: // scale
7723
- double hScale = (double) (clickInfo.x /*- centerPt.x*/) / 32;
7957
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
77247958 double sign = 1;
77257959 if (hScale < 0)
77267960 {
....@@ -7732,7 +7966,7 @@
77327966 //hScale = 0.01;
77337967 }
77347968
7735
- double vScale = (double) (clickInfo.y /*- centerPt.y*/) / 32;
7969
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
77367970 sign = 1;
77377971 if (vScale < 0)
77387972 {
....@@ -7765,21 +7999,27 @@
77657999 case 3: // '\001'
77668000 if (modified || opposite)
77678001 {
8002
+ if (modified) // && opposite)
8003
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8004
+ else
77688005 //LA.matScale(toParent, 1, hScale, vScale);
7769
- LA.matScale(toParent, totalScale, 1, 1);
8006
+ LA.matScale(toParent, totalScale, 1, 1);
77708007 } // vScale, 1);
77718008 else
77728009 {
77738010 // EXCEPTION!
7774
- LA.matScale(toParent, totalScale, totalScale, totalScale);
8011
+ LA.matScale(toParent, 1, totalScale, totalScale);
77758012 } // vScale, 1);
77768013 break;
77778014
77788015 case 2: // '\002'
77798016 if (modified || opposite)
77808017 {
7781
- //LA.matScale(toParent, hScale, 1, vScale);
7782
- LA.matScale(toParent, 1, totalScale, 1);
8018
+ if (modified) // && opposite)
8019
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8020
+ else
8021
+ //LA.matScale(toParent, hScale, 1, vScale);
8022
+ LA.matScale(toParent, 1, totalScale, 1);
77838023 } else
77848024 {
77858025 LA.matScale(toParent, totalScale, 1, totalScale);
....@@ -7789,8 +8029,11 @@
77898029 case 1: // '\003'
77908030 if (modified || opposite)
77918031 {
7792
- //LA.matScale(toParent, hScale, vScale, 1);
7793
- LA.matScale(toParent, 1, 1, totalScale);
8032
+ if (modified) // && opposite)
8033
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8034
+ else
8035
+ //LA.matScale(toParent, hScale, vScale, 1);
8036
+ LA.matScale(toParent, 1, 1, totalScale);
77948037 } else
77958038 {
77968039 LA.matScale(toParent, totalScale, totalScale, 1);
....@@ -7938,10 +8181,10 @@
79388181 } // + super.toString();
79398182 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
79408183
7941
- if (!Globals.ADVANCED)
7942
- return objname;
8184
+// if (!Globals.ADVANCED)
8185
+// return objname;
79438186
7944
- return objname + " " + System.identityHashCode(this);
8187
+ return objname + " " + System.identityHashCode(this); // + GetUUID()
79458188 }
79468189
79478190 public int hashCode()