Normand Briere
2019-06-17 e36047725ce3217618d4e5807ac7c8769b9e3598
Object3D.java
....@@ -14,11 +14,20 @@
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();
26
+
27
+ // TEMPORARY for mocap undo
28
+ mocap.reader.BVHReader.BVHResult bvh;
29
+ Object3D skeleton;
30
+ //
2231
2332 ScriptNode scriptnode;
2433
....@@ -100,64 +109,136 @@
100109
101110 // transient boolean reduced; // for morph reduction
102111
103
-transient com.bulletphysics.linearmath.Transform cache; // for fast merge
104
-transient com.bulletphysics.linearmath.Transform cache_1; // for fast merge
112
+ transient com.bulletphysics.linearmath.Transform cache; // for fast merge
113
+ transient com.bulletphysics.linearmath.Transform cache_1; // for fast merge
105114
106
-transient Object3D transientsupport; // for cloning
107
-transient boolean transientlink2master;
115
+ transient Object3D transientsupport; // for cloning
116
+ transient boolean transientlink2master;
108117
109
-void SaveSupports()
110
-{
111
- if (blockloop)
112
- return;
113
-
114
- transientsupport = support;
115
- transientlink2master = link2master;
116
-
117
- support = null;
118
- link2master = false;
119
-
120
- if (bRep != null)
118
+ void SaveSupports()
121119 {
122
- bRep.SaveSupports();
123
- }
124
-
125
- for (int i = 0; i < Size(); i++)
126
- {
127
- Object3D child = (Object3D) get(i);
128
- if (child == null)
129
- continue;
130
- blockloop = true;
131
- child.SaveSupports();
132
- blockloop = false;
133
- }
134
-}
120
+ if (blockloop)
121
+ return;
135122
136
-void RestoreSupports()
137
-{
138
- if (blockloop)
139
- return;
123
+ transientsupport = support;
124
+ transientlink2master = link2master;
140125
141
- support = transientsupport;
142
- link2master = transientlink2master;
143
- transientsupport = null;
144
- transientlink2master = false;
145
-
146
- if (bRep != null)
147
- {
148
- bRep.RestoreSupports();
126
+ support = null;
127
+ link2master = false;
128
+
129
+ if (bRep != null)
130
+ {
131
+ bRep.SaveSupports();
132
+ }
133
+
134
+ for (int i = 0; i < Size(); i++)
135
+ {
136
+ Object3D child = (Object3D) get(i);
137
+ if (child == null)
138
+ continue;
139
+ blockloop = true;
140
+ child.SaveSupports();
141
+ blockloop = false;
142
+ }
149143 }
150
-
151
- for (int i = 0; i < Size(); i++)
144
+
145
+ void RestoreSupports()
152146 {
153
- Object3D child = (Object3D) get(i);
154
- if (child == null)
155
- continue;
156
- blockloop = true;
157
- child.RestoreSupports();
158
- blockloop = false;
147
+ if (blockloop)
148
+ return;
149
+
150
+ support = transientsupport;
151
+ link2master = transientlink2master;
152
+ transientsupport = null;
153
+ transientlink2master = false;
154
+
155
+ if (bRep != null)
156
+ {
157
+ bRep.RestoreSupports();
158
+ }
159
+
160
+ for (int i = 0; i < Size(); i++)
161
+ {
162
+ Object3D child = (Object3D) get(i);
163
+ if (child == null)
164
+ continue;
165
+ blockloop = true;
166
+ child.RestoreSupports();
167
+ blockloop = false;
168
+ }
159169 }
160
-}
170
+
171
+ void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
172
+ {
173
+ if (hashtable.containsKey(GetUUID()))
174
+ {
175
+ Object3D o = hashtable.get(GetUUID());
176
+
177
+ Grafreed.Assert(this.bRep == o.bRep);
178
+ if (this.bRep != null)
179
+ assert(this.bRep.support == o.transientrep);
180
+
181
+ return;
182
+ }
183
+
184
+ Object3D o = new Object3D();
185
+
186
+ hashtable.put(GetUUID(), o);
187
+
188
+ for (int i=0; i<Size(); i++)
189
+ {
190
+ get(i).ExtractBigData(hashtable);
191
+ }
192
+
193
+ ExtractBigData(o);
194
+ }
195
+
196
+ void ExtractBigData(Object3D o)
197
+ {
198
+ o.bRep = this.bRep;
199
+ if (this.bRep != null)
200
+ {
201
+ o.transientrep = this.bRep.support;
202
+ o.bRep.support = null;
203
+ }
204
+
205
+ // o.support = this.support;
206
+ // o.fileparent = this.fileparent;
207
+ // if (this.bRep != null)
208
+ // o.bRep = this.bRep.support;
209
+
210
+ this.bRep = null;
211
+ // if (this.bRep != null)
212
+ // this.bRep.support = null;
213
+ // this.support = null;
214
+ // this.fileparent = null;
215
+ }
216
+
217
+ void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
218
+ {
219
+ if (!hashtable.containsKey(GetUUID()))
220
+ return;
221
+
222
+ Object3D o = hashtable.get(GetUUID());
223
+
224
+ RestoreBigData(o);
225
+
226
+ hashtable.remove(GetUUID());
227
+
228
+ for (int i=0; i<Size(); i++)
229
+ {
230
+ get(i).RestoreBigData(hashtable);
231
+ }
232
+ }
233
+
234
+ void RestoreBigData(Object3D o)
235
+ {
236
+ this.bRep = o.bRep;
237
+ if (this.bRep != null)
238
+ this.bRep.support = o.transientrep;
239
+ // this.support = o.support;
240
+ // this.fileparent = o.fileparent;
241
+ }
161242
162243 // MOCAP SUPPORT
163244 double tx,ty,tz,rx,ry,rz;
....@@ -482,12 +563,14 @@
482563 toParent = LA.newMatrix();
483564 fromParent = LA.newMatrix();
484565 }
566
+
485567 if (toParentMarked == null)
486568 {
487569 if (maxcount != 1)
488570 {
489571 new Exception().printStackTrace();
490572 }
573
+
491574 toParentMarked = LA.newMatrix();
492575 fromParentMarked = LA.newMatrix();
493576 }
....@@ -775,7 +858,7 @@
775858 if (step == 0)
776859 step = 1;
777860 if (maxcount == 0)
778
- maxcount = 2048; // 4;
861
+ maxcount = 128; // 2048; // 4;
779862 // if (acceleration == 0)
780863 // acceleration = 10;
781864 if (delay == 0) // serial
....@@ -2628,6 +2711,18 @@
26282711 //Touch();
26292712 }
26302713
2714
+ void GenNormalsMeshS()
2715
+ {
2716
+ selection.GenNormalsMesh();
2717
+// for (int i=0; i<selection.size(); i++)
2718
+// {
2719
+// Object3D selectee = (Object3D) selection.elementAt(i);
2720
+// selectee.GenNormals(crease);
2721
+// }
2722
+
2723
+ //Touch();
2724
+ }
2725
+
26312726 void ClearColorsS()
26322727 {
26332728 selection.ClearColors();
....@@ -2759,6 +2854,24 @@
27592854 if (child == null)
27602855 continue;
27612856 child.GenNormals(crease);
2857
+// Children().release(i);
2858
+ }
2859
+ blockloop = false;
2860
+ }
2861
+
2862
+ void GenNormalsMesh()
2863
+ {
2864
+ if (blockloop)
2865
+ return;
2866
+
2867
+ blockloop = true;
2868
+ GenNormalsMesh0();
2869
+ for (int i = 0; i < Children().Size(); i++)
2870
+ {
2871
+ Object3D child = (Object3D) Children().get(i); // reserve(i);
2872
+ if (child == null)
2873
+ continue;
2874
+ child.GenNormalsMesh();
27622875 // Children().release(i);
27632876 }
27642877 blockloop = false;
....@@ -2927,6 +3040,15 @@
29273040 if (bRep != null)
29283041 {
29293042 bRep.GenerateNormals(crease);
3043
+ Touch();
3044
+ }
3045
+ }
3046
+
3047
+ void GenNormalsMesh0()
3048
+ {
3049
+ if (bRep != null)
3050
+ {
3051
+ bRep.GenerateNormalsMesh();
29303052 Touch();
29313053 }
29323054 }
....@@ -4229,6 +4351,55 @@
42294351 }
42304352 }
42314353
4354
+ void RepairSOV()
4355
+ {
4356
+ if (blockloop)
4357
+ return;
4358
+
4359
+ String texname = this.GetPigmentTexture();
4360
+
4361
+ if (texname.startsWith("sov"))
4362
+ {
4363
+ String[] s = texname.split("/");
4364
+
4365
+ String[] sname = s[1].split("Color.pn");
4366
+
4367
+ texname = sname[0];
4368
+
4369
+ if (sname.length > 1)
4370
+ {
4371
+ texname += "Color.jpg";
4372
+ }
4373
+
4374
+ this.SetPigmentTexture("sov/" + texname);
4375
+ }
4376
+
4377
+ texname = this.GetBumpTexture();
4378
+
4379
+ if (texname.startsWith("sov"))
4380
+ {
4381
+ String[] s = texname.split("/");
4382
+
4383
+ String[] sname = s[1].split("Bump.pn");
4384
+
4385
+ texname = sname[0];
4386
+
4387
+ if (sname.length > 1)
4388
+ {
4389
+ texname += "Bump.jpg";
4390
+ }
4391
+
4392
+ this.SetBumpTexture("sov/" + texname);
4393
+ }
4394
+
4395
+ for (int i=0; i<Size(); i++)
4396
+ {
4397
+ blockloop = true;
4398
+ get(i).RepairSOV();
4399
+ blockloop = false;
4400
+ }
4401
+ }
4402
+
42324403 void RepairTexture()
42334404 {
42344405 if (this instanceof FileObject || blockloop)
....@@ -5371,6 +5542,43 @@
53715542 }
53725543 }
53735544
5545
+ UUID GetUUID()
5546
+ {
5547
+ if (uuid == null)
5548
+ {
5549
+ // Serial
5550
+ uuid = UUID.randomUUID();
5551
+ }
5552
+
5553
+ return uuid;
5554
+ }
5555
+
5556
+ Object3D GetObject(UUID uid)
5557
+ {
5558
+ if (blockloop)
5559
+ return null;
5560
+
5561
+ if (GetUUID().equals(uid))
5562
+ return this;
5563
+
5564
+ int nb = Size();
5565
+ for (int i = 0; i < nb; i++)
5566
+ {
5567
+ Object3D child = (Object3D) get(i);
5568
+
5569
+ if (child == null)
5570
+ continue;
5571
+
5572
+ blockloop = true;
5573
+ Object3D obj = child.GetObject(uid);
5574
+ blockloop = false;
5575
+ if (obj != null)
5576
+ return obj;
5577
+ }
5578
+
5579
+ return null;
5580
+ }
5581
+
53745582 void SetBumpTexture(String tex)
53755583 {
53765584 if (GetTextures() == null)
....@@ -5415,12 +5623,23 @@
54155623 boolean NeedSupport()
54165624 {
54175625 return
5418
- CameraPane.SUPPORT && (!CameraPane.movingcamera || !Globals.FREEZEONMOVE) && link2master && /*live &&*/ support != null
5626
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && link2master && /*live &&*/ support != null
54195627 // PROBLEM with CROWD!!
54205628 && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
54215629 }
54225630
54235631 static boolean DEBUG_SELECTION = false;
5632
+
5633
+ boolean IsLive()
5634
+ {
5635
+ if (live)
5636
+ return true;
5637
+
5638
+ if (parent == null)
5639
+ return false;
5640
+
5641
+ return parent.IsLive();
5642
+ }
54245643
54255644 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
54265645 {
....@@ -5483,7 +5702,7 @@
54835702 support = support;
54845703
54855704 //boolean usecalllists = IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5486
- boolean usecalllists = false; // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5705
+ boolean usecalllists = IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
54875706
54885707 if (!usecalllists && bRep != null && bRep.displaylist > 0)
54895708 {
....@@ -5503,10 +5722,12 @@
55035722 boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
55045723
55055724 if (!selectmode && //display.DrawMode() != display.SELECTION &&
5506
- (touched || (bRep != null && bRep.displaylist <= 0)))
5725
+ //(touched || (bRep != null && bRep.displaylist <= 0)))
5726
+ (Globals.isLIVE() || touched && (bRep != null && bRep.displaylist <= 0)))
55075727 {
55085728 Globals.lighttouched = true;
55095729 } // all panes...
5730
+
55105731 //if (usecalllists && display.DrawMode() != display.SELECTION && display.DrawMode() != display.SHADOW &&
55115732 if (bRep != null && usecalllists && !selectmode && // june 2013 display.DrawMode() != display.SHADOW &&
55125733 (touched || (bRep != null && bRep.displaylist <= 0)))
....@@ -5674,16 +5895,27 @@
56745895 tex = GetTextures();
56755896 }
56765897
5677
- boolean failed = false;
5898
+ boolean failedPigment = false;
5899
+ boolean failedBump = false;
56785900
56795901 try
56805902 {
5681
- display.BindTextures(tex, texres);
5903
+ display.BindPigmentTexture(tex, texres);
56825904 }
56835905 catch (Exception e)
56845906 {
56855907 System.err.println("FAILED: " + this);
5686
- failed = true;
5908
+ failedPigment = true;
5909
+ }
5910
+
5911
+ try
5912
+ {
5913
+ display.BindBumpTexture(tex, texres);
5914
+ }
5915
+ catch (Exception e)
5916
+ {
5917
+ //System.err.println("FAILED: " + this);
5918
+ failedBump = true;
56875919 }
56885920
56895921 if (!compiled)
....@@ -5706,8 +5938,11 @@
57065938 }
57075939 }
57085940
5709
- if (!failed)
5710
- display.ReleaseTextures(tex);
5941
+ if (!failedBump)
5942
+ display.ReleaseBumpTexture(tex);
5943
+
5944
+ if (!failedPigment)
5945
+ display.ReleasePigmentTexture(tex);
57115946
57125947 display.PopMaterial(this, selected);
57135948 }
....@@ -6932,7 +7167,7 @@
69327167 spot.translate(32, 32);
69337168 spotw = spot.x + spot.width;
69347169 spoth = spot.y + spot.height;
6935
- info.g.setColor(Color.blue);
7170
+ info.g.setColor(Color.cyan);
69367171 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
69377172 // if (CameraPane.Xmin > spot.x)
69387173 // {
....@@ -6950,11 +7185,12 @@
69507185 // {
69517186 // CameraPane.Ymax = spoth;
69527187 // }
6953
- info.g.drawLine(spotw, spoth, spotw, spoth - 15);
6954
- info.g.drawLine(spotw, spoth, spotw - 15, spoth);
7188
+ // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
7189
+ //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
69557190 spot.translate(0, -32);
6956
- info.g.setColor(Color.green);
7191
+ info.g.setColor(Color.yellow);
69577192 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7193
+ info.g.setColor(Color.green);
69587194 // if (CameraPane.Xmin > spot.x)
69597195 // {
69607196 // CameraPane.Xmin = spot.x;
....@@ -7006,7 +7242,7 @@
70067242 startX = info.x;
70077243 startY = info.y;
70087244
7009
- hitSomething = 0;
7245
+ hitSomething = -1;
70107246 cVector origin = new cVector();
70117247 //LA.xformPos(origin, toParent, origin);
70127248 Rectangle spot = new Rectangle();
....@@ -7082,6 +7318,7 @@
70827318 //System.out.println("hitSomething = " + hitSomething);
70837319
70847320 double scale = 0.005f * info.camera.Distance();
7321
+
70857322 cVector xlate = new cVector();
70867323 //cVector xlate2 = new cVector();
70877324 switch (hitSomething)
....@@ -7230,24 +7467,27 @@
72307467
72317468 case hitScale: // scale
72327469 double hScale = (double) (info.x - centerPt.x) / 32;
7470
+ double sign = 1;
7471
+ if (hScale < 0)
7472
+ {
7473
+ sign = -1;
7474
+ }
7475
+ hScale = sign*Math.pow(sign*hScale, scale * 50);
72337476 if (hScale < 0.01)
72347477 {
7235
- hScale = 0.01;
7478
+ //hScale = 0.01;
72367479 }
7237
- hScale = Math.pow(hScale, scale * 50);
7238
- if (hScale < 0.01)
7239
- {
7240
- hScale = 0.01;
7241
- }
7480
+
72427481 double vScale = (double) (info.y - centerPt.y) / 32;
7243
- if (vScale < 0.01)
7482
+ sign = 1;
7483
+ if (vScale < 0)
72447484 {
7245
- vScale = 0.01;
7485
+ sign = -1;
72467486 }
7247
- vScale = Math.pow(vScale, scale * 50);
7487
+ vScale = sign*Math.pow(sign*vScale, scale * 50);
72487488 if (vScale < 0.01)
72497489 {
7250
- vScale = 0.01;
7490
+ //vScale = 0.01;
72517491 }
72527492 LA.matCopy(startMat, toParent);
72537493 /**/
....@@ -7258,39 +7498,47 @@
72587498 }
72597499 /**/
72607500
7501
+ double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2);
7502
+
7503
+ if (totalScale < 0.01)
7504
+ {
7505
+ totalScale = 0.01;
7506
+ }
7507
+
72617508 switch (info.pane.RenderCamera().viewCode)
72627509 {
72637510 case 3: // '\001'
7264
- if (modified)
7511
+ if (modified || opposite)
72657512 {
72667513 //LA.matScale(toParent, 1, hScale, vScale);
7267
- LA.matScale(toParent, vScale, 1, 1);
7514
+ LA.matScale(toParent, totalScale, 1, 1);
72687515 } // vScale, 1);
72697516 else
72707517 {
7271
- LA.matScale(toParent, vScale, vScale, vScale);
7518
+ // EXCEPTION!
7519
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
72727520 } // vScale, 1);
72737521 break;
72747522
72757523 case 2: // '\002'
7276
- if (modified)
7524
+ if (modified || opposite)
72777525 {
72787526 //LA.matScale(toParent, hScale, 1, vScale);
7279
- LA.matScale(toParent, 1, vScale, 1);
7527
+ LA.matScale(toParent, 1, totalScale, 1);
72807528 } else
72817529 {
7282
- LA.matScale(toParent, vScale, 1, vScale);
7530
+ LA.matScale(toParent, totalScale, 1, totalScale);
72837531 }
72847532 break;
72857533
72867534 case 1: // '\003'
7287
- if (modified)
7535
+ if (modified || opposite)
72887536 {
72897537 //LA.matScale(toParent, hScale, vScale, 1);
7290
- LA.matScale(toParent, 1, 1, vScale);
7538
+ LA.matScale(toParent, 1, 1, totalScale);
72917539 } else
72927540 {
7293
- LA.matScale(toParent, vScale, vScale, 1);
7541
+ LA.matScale(toParent, totalScale, totalScale, 1);
72947542 }
72957543 break;
72967544 }
....@@ -7431,7 +7679,7 @@
74317679 objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
74327680 } else
74337681 {
7434
- objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count /*- 1*/) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
7682
+ objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count - 1) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
74357683 } // + super.toString();
74367684 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
74377685
....@@ -7515,7 +7763,7 @@
75157763 /*transient*/ cVector2[] projectedVertices = new cVector2[0];
75167764
75177765 Object3D /*Composite*/ parent;
7518
- Object3D /*Composite*/ fileparent;
7766
+ Object3D /*Composite*/ fileparent; // In the case of FileObject
75197767
75207768 double[][] toParent; // dynamic matrix
75217769 double[][] fromParent;
....@@ -7679,9 +7927,9 @@
76797927 private static cVector edge2 = new cVector();
76807928 //private static cVector norm = new cVector();
76817929 /*transient private*/ int hitSomething;
7682
- private static final int hitCenter = 1;
7683
- private static final int hitScale = 2;
7684
- private static final int hitRotate = 3;
7930
+ static final int hitCenter = 1;
7931
+ static final int hitScale = 2;
7932
+ static final int hitRotate = 3;
76857933 /*transient*/ /*private*/ int viewCode; // Now used for transparency cache flag
76867934 /*transient*/ private Point centerPt;
76877935 /*transient*/ private int startX;