Normand Briere
2019-08-26 6266c8a4b2485b29a7d5bcb217460d7aad3e1c4a
Object3D.java
....@@ -36,8 +36,23 @@
3636 Object3D versionlist[];
3737 int versionindex = -1;
3838
39
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable; // = new java.util.Hashtable<java.util.UUID, Object3D>();
40
+
3941 ScriptNode scriptnode;
4042
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
+
4156 void InitOthers()
4257 {
4358 if (projectedVertices == null || projectedVertices.length <= 2)
....@@ -269,6 +284,50 @@
269284 //
270285 // return null;
271286 // }
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;
330
+ }
272331
273332 void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
274333 {
....@@ -522,11 +581,11 @@
522581 }
523582 }
524583
525
- int memorysize;
584
+ transient int memorysize; // needs to be transient, dunno why
526585
527586 int MemorySize()
528587 {
529
- if (true) // memorysize == 0)
588
+ if (memorysize == 0)
530589 {
531590 try
532591 {
....@@ -641,7 +700,7 @@
641700 {
642701 if (maxcount != 1)
643702 {
644
- new Exception().printStackTrace();
703
+ //new Exception().printStackTrace();
645704 }
646705
647706 toParentMarked = LA.newMatrix();
....@@ -2323,11 +2382,6 @@
23232382
23242383 InitOthers();
23252384
2326
- if (this instanceof Camera)
2327
- {
2328
- material.shift = 90;
2329
- }
2330
-
23312385 material.multiply = multiply;
23322386
23332387 if (multiply)
....@@ -2468,7 +2522,11 @@
24682522 else
24692523 {
24702524 //((ObjEditor)editWindow).SetupUI2(null);
2471
- ((ObjEditor)objectUI).pinButton.setSelected(pinned);
2525
+ if (objectUI != null)
2526
+ ((ObjEditor)objectUI).pinButton.setSelected(pinned);
2527
+ else
2528
+ //new Exception().printStackTrace();
2529
+ System.err.println("objectUI is null");
24722530 }
24732531 }
24742532
....@@ -3219,6 +3277,93 @@
32193277 blockloop = false;
32203278 }
32213279
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
+
32223367 void TransformChildren()
32233368 {
32243369 if (toParent != null)
....@@ -3572,15 +3717,47 @@
35723717
35733718 void ClearMaterials()
35743719 {
3720
+ if (blockloop)
3721
+ return;
3722
+
3723
+ blockloop = true;
3724
+
35753725 ClearMaterial();
3576
- for (int i = 0; i < size(); i++)
3726
+ for (int i = 0; i < Size(); i++)
35773727 {
3578
- Object3D child = (Object3D) reserve(i);
3728
+ Object3D child = (Object3D) get(i);
35793729 if (child == null)
35803730 continue;
35813731 child.ClearMaterials();
3582
- release(i);
35833732 }
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;
35843761 }
35853762
35863763 void FlipV(boolean flip)
....@@ -5570,6 +5747,11 @@
55705747 if (fullname == null)
55715748 return "";
55725749
5750
+ if (fullname.pigment != null)
5751
+ {
5752
+ return fullname.pigment;
5753
+ }
5754
+
55735755 // System.out.println("Fullname = " + fullname);
55745756
55755757 // Does not work on Windows due to C:
....@@ -5582,7 +5764,7 @@
55825764
55835765 if (split.length == 0)
55845766 {
5585
- return "";
5767
+ return fullname.pigment = "";
55865768 }
55875769
55885770 if (split.length <= 2)
....@@ -5590,22 +5772,27 @@
55905772 if (fullname.name.endsWith(":"))
55915773 {
55925774 // Windows
5593
- return fullname.name.substring(0, fullname.name.length()-1);
5775
+ return fullname.pigment = fullname.name.substring(0, fullname.name.length()-1);
55945776 }
55955777
5596
- return split[0];
5778
+ return fullname.pigment = split[0];
55975779 }
55985780
55995781 // Windows
56005782 assert(split.length == 4);
56015783
5602
- return split[0] + ":" + split[1];
5784
+ return fullname.pigment = split[0] + ":" + split[1];
56035785 }
56045786
56055787 static String GetBump(cTexture fullname)
56065788 {
56075789 if (fullname == null)
56085790 return "";
5791
+
5792
+ if (fullname.bump != null)
5793
+ {
5794
+ return fullname.bump;
5795
+ }
56095796
56105797 // System.out.println("Fullname = " + fullname);
56115798 // Does not work on Windows due to C:
....@@ -5617,12 +5804,12 @@
56175804
56185805 if (split.length == 0)
56195806 {
5620
- return "";
5807
+ return fullname.bump = "";
56215808 }
56225809
56235810 if (split.length == 1)
56245811 {
5625
- return "";
5812
+ return fullname.bump = "";
56265813 }
56275814
56285815 if (split.length == 2)
....@@ -5630,16 +5817,16 @@
56305817 if (fullname.name.endsWith(":"))
56315818 {
56325819 // Windows
5633
- return "";
5820
+ return fullname.bump = "";
56345821 }
56355822
5636
- return split[1];
5823
+ return fullname.bump = split[1];
56375824 }
56385825
56395826 // Windows
56405827 assert(split.length == 4);
56415828
5642
- return split[2] + ":" + split[3];
5829
+ return fullname.bump = split[2] + ":" + split[3];
56435830 }
56445831
56455832 String GetPigmentTexture()
....@@ -5722,6 +5909,9 @@
57225909 texname = "";
57235910
57245911 GetTextures().name = texname + ":" + GetBump(GetTextures());
5912
+
5913
+ GetTextures().pigment = null;
5914
+
57255915 Touch();
57265916 }
57275917
....@@ -5794,6 +5984,8 @@
57945984 texname = "";
57955985
57965986 GetTextures().name = Object3D.GetPigment(GetTextures()) + ":" + texname;
5987
+
5988
+ GetTextures().bump = null;
57975989
57985990 Touch();
57995991 }
....@@ -5877,6 +6069,11 @@
58776069 return parent.IsLive();
58786070 }
58796071
6072
+ boolean IsDynamic()
6073
+ {
6074
+ return live && bRep != null;
6075
+ }
6076
+
58806077 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
58816078 {
58826079 Invariants(); // june 2013
....@@ -5937,7 +6134,8 @@
59376134 if (support != null)
59386135 support = support;
59396136
5940
- boolean usecalllists = !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);
59416139 //boolean usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
59426140
59436141 //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass.
....@@ -7398,7 +7596,7 @@
73987596 boundary.y = spot.y - 30;
73997597 boundary.width = spot.width + 60;
74007598 boundary.height = spot.height + 60;
7401
- clickInfo.g.setColor(Color.red);
7599
+ clickInfo.g.setColor(Color.white);
74027600 int spotw = spot.x + spot.width;
74037601 int spoth = spot.y + spot.height;
74047602 clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
....@@ -7418,7 +7616,29 @@
74187616 // {
74197617 // CameraPane.Ymax = spoth;
74207618 // }
7421
- 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);
74227642 spotw = spot.x + spot.width;
74237643 spoth = spot.y + spot.height;
74247644 clickInfo.g.setColor(Color.cyan);
....@@ -7439,28 +7659,7 @@
74397659 // {
74407660 // CameraPane.Ymax = spoth;
74417661 // }
7442
- // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
7443
- //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
7444
- spot.translate(0, -32);
7445
- clickInfo.g.setColor(Color.yellow);
7446
- clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
74477662 clickInfo.g.setColor(Color.green);
7448
-// if (CameraPane.Xmin > spot.x)
7449
-// {
7450
-// CameraPane.Xmin = spot.x;
7451
-// }
7452
-// if (CameraPane.Xmax < spotw)
7453
-// {
7454
-// CameraPane.Xmax = spotw;
7455
-// }
7456
-// if (CameraPane.Ymin > spot.y)
7457
-// {
7458
-// CameraPane.Ymin = spot.y;
7459
-// }
7460
-// if (CameraPane.Ymax < spoth)
7461
-// {
7462
-// CameraPane.Ymax = spoth;
7463
-// }
74647663 clickInfo.g.drawArc(boundary.x + clickInfo.DX, boundary.y + clickInfo.DY,
74657664 (int)(boundary.width * clickInfo.W), (int)(boundary.height * clickInfo.W), 0, 360);
74667665 //info.g.drawArc(spot.x, spotw, spot.width/2, boundary.height/2, 0, 360);
....@@ -7519,12 +7718,14 @@
75197718 retval = true;
75207719 }
75217720 spot.translate(0, 32);
7721
+ spot.translate(32, 0);
7722
+ spot.translate(0, 32);
75227723 if (spot.contains(clickInfo.x, clickInfo.y))
75237724 {
75247725 hitSomething = hitScale;
75257726
75267727 double scale = 0.005f * clickInfo.camera.Distance();
7527
- double hScale = (double) (clickInfo.x - centerPt.x) / 32;
7728
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
75287729 double sign = 1;
75297730 if (hScale < 0)
75307731 {
....@@ -7536,7 +7737,7 @@
75367737 //hScale = 0.01;
75377738 }
75387739
7539
- double vScale = (double) (clickInfo.y - centerPt.y) / 32;
7740
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
75407741 sign = 1;
75417742 if (vScale < 0)
75427743 {
....@@ -7616,7 +7817,9 @@
76167817
76177818 scale *= 0.05f * Globals.theRenderer.RenderCamera().Distance();
76187819
7619
- if (modified || opposite)
7820
+ // Modified could snap
7821
+ if (//modified ||
7822
+ opposite)
76207823 {
76217824 //assert(false);
76227825 /*
....@@ -7710,7 +7913,7 @@
77107913
77117914 if (modified)
77127915 {
7713
- // Rotate 90 degrees
7916
+ // Rotate 45 degrees
77147917 angle /= (Math.PI / 4);
77157918 angle = Math.floor(angle + 0.5);
77167919 angle *= (Math.PI / 4);
....@@ -7751,7 +7954,7 @@
77517954 break;
77527955
77537956 case hitScale: // scale
7754
- double hScale = (double) (clickInfo.x - centerPt.x) / 32;
7957
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
77557958 double sign = 1;
77567959 if (hScale < 0)
77577960 {
....@@ -7763,7 +7966,7 @@
77637966 //hScale = 0.01;
77647967 }
77657968
7766
- double vScale = (double) (clickInfo.y - centerPt.y) / 32;
7969
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
77677970 sign = 1;
77687971 if (vScale < 0)
77697972 {
....@@ -7796,21 +7999,27 @@
77967999 case 3: // '\001'
77978000 if (modified || opposite)
77988001 {
8002
+ if (modified) // && opposite)
8003
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8004
+ else
77998005 //LA.matScale(toParent, 1, hScale, vScale);
7800
- LA.matScale(toParent, totalScale, 1, 1);
8006
+ LA.matScale(toParent, totalScale, 1, 1);
78018007 } // vScale, 1);
78028008 else
78038009 {
78048010 // EXCEPTION!
7805
- LA.matScale(toParent, totalScale, totalScale, totalScale);
8011
+ LA.matScale(toParent, 1, totalScale, totalScale);
78068012 } // vScale, 1);
78078013 break;
78088014
78098015 case 2: // '\002'
78108016 if (modified || opposite)
78118017 {
7812
- //LA.matScale(toParent, hScale, 1, vScale);
7813
- 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);
78148023 } else
78158024 {
78168025 LA.matScale(toParent, totalScale, 1, totalScale);
....@@ -7820,8 +8029,11 @@
78208029 case 1: // '\003'
78218030 if (modified || opposite)
78228031 {
7823
- //LA.matScale(toParent, hScale, vScale, 1);
7824
- 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);
78258037 } else
78268038 {
78278039 LA.matScale(toParent, totalScale, totalScale, 1);
....@@ -7969,10 +8181,10 @@
79698181 } // + super.toString();
79708182 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
79718183
7972
- if (!Globals.ADVANCED)
7973
- return objname;
8184
+// if (!Globals.ADVANCED)
8185
+// return objname;
79748186
7975
- return objname + " " + System.identityHashCode(this);
8187
+ return objname + " " + System.identityHashCode(this); // + GetUUID()
79768188 }
79778189
79788190 public int hashCode()