Normand Briere
2019-06-17 13e9febe94aaeebad9c97f6d3e2aa4d73b2495c8
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;
....@@ -300,6 +381,7 @@
300381 }
301382
302383 boolean live = false;
384
+ boolean dontselect = false;
303385 boolean hide = false;
304386 boolean link2master = false; // performs reset support/master at each frame
305387 boolean marked = false; // animation node
....@@ -481,12 +563,14 @@
481563 toParent = LA.newMatrix();
482564 fromParent = LA.newMatrix();
483565 }
566
+
484567 if (toParentMarked == null)
485568 {
486569 if (maxcount != 1)
487570 {
488571 new Exception().printStackTrace();
489572 }
573
+
490574 toParentMarked = LA.newMatrix();
491575 fromParentMarked = LA.newMatrix();
492576 }
....@@ -774,7 +858,7 @@
774858 if (step == 0)
775859 step = 1;
776860 if (maxcount == 0)
777
- maxcount = 2048; // 4;
861
+ maxcount = 128; // 2048; // 4;
778862 // if (acceleration == 0)
779863 // acceleration = 10;
780864 if (delay == 0) // serial
....@@ -1834,12 +1918,15 @@
18341918 if (obj.name == null)
18351919 continue; // can't be a null one
18361920
1921
+ // Try perfect match first.
18371922 if (n.equals(obj.name))
18381923 {
18391924 theobj = obj;
18401925 count++;
18411926 }
18421927 }
1928
+
1929
+ // not needed: n = n.split(":")[0]; // Poser generates a count
18431930
18441931 if (count != 1)
18451932 for (int i=Size(); --i>=0;)
....@@ -2624,6 +2711,18 @@
26242711 //Touch();
26252712 }
26262713
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
+
26272726 void ClearColorsS()
26282727 {
26292728 selection.ClearColors();
....@@ -2755,6 +2854,24 @@
27552854 if (child == null)
27562855 continue;
27572856 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();
27582875 // Children().release(i);
27592876 }
27602877 blockloop = false;
....@@ -2927,6 +3044,15 @@
29273044 }
29283045 }
29293046
3047
+ void GenNormalsMesh0()
3048
+ {
3049
+ if (bRep != null)
3050
+ {
3051
+ bRep.GenerateNormalsMesh();
3052
+ Touch();
3053
+ }
3054
+ }
3055
+
29303056 void GenNormalsMINE0()
29313057 {
29323058 if (bRep != null)
....@@ -3002,8 +3128,10 @@
30023128 v.fromParent = LA.newMatrix();
30033129 }
30043130
3005
- LA.matConcat(v.toParent, toParent, v.toParent);
3006
- LA.matConcat(fromParent, v.fromParent, v.fromParent);
3131
+// LA.matConcat(v.toParent, toParent, v.toParent);
3132
+// LA.matConcat(fromParent, v.fromParent, v.fromParent);
3133
+ LA.matConcat(toParent, v.toParent, v.toParent);
3134
+ LA.matConcat(v.fromParent, fromParent, v.fromParent);
30073135 }
30083136
30093137 toParent = null; // LA.matIdentity(toParent);
....@@ -3236,7 +3364,9 @@
32363364 bRep.support = null;
32373365 BoundaryRep temprep = (BoundaryRep) Grafreed.clone(bRep);
32383366 // bRep.SplitInTwo(onlyone); // thread...
3239
- temprep.SplitInTwo(reduction34, onlyone);
3367
+
3368
+ while(temprep.SplitInTwo(reduction34, onlyone));
3369
+
32403370 bRep = temprep;
32413371 bRep.support = sup;
32423372 Touch();
....@@ -4711,7 +4841,7 @@
47114841
47124842 cTreePath SelectLeaf(int indexcount, boolean deselect)
47134843 {
4714
- if (hide)
4844
+ if (hide || dontselect)
47154845 return null;
47164846
47174847 if (count <= 0)
....@@ -4737,7 +4867,7 @@
47374867
47384868 cTreePath Select(int indexcount, boolean deselect)
47394869 {
4740
- if (hide)
4870
+ if (hide || dontselect)
47414871 return null;
47424872
47434873 if (count <= 0)
....@@ -5363,6 +5493,43 @@
53635493 }
53645494 }
53655495
5496
+ UUID GetUUID()
5497
+ {
5498
+ if (uuid == null)
5499
+ {
5500
+ // Serial
5501
+ uuid = UUID.randomUUID();
5502
+ }
5503
+
5504
+ return uuid;
5505
+ }
5506
+
5507
+ Object3D GetObject(UUID uid)
5508
+ {
5509
+ if (blockloop)
5510
+ return null;
5511
+
5512
+ if (GetUUID().equals(uid))
5513
+ return this;
5514
+
5515
+ int nb = Size();
5516
+ for (int i = 0; i < nb; i++)
5517
+ {
5518
+ Object3D child = (Object3D) get(i);
5519
+
5520
+ if (child == null)
5521
+ continue;
5522
+
5523
+ blockloop = true;
5524
+ Object3D obj = child.GetObject(uid);
5525
+ blockloop = false;
5526
+ if (obj != null)
5527
+ return obj;
5528
+ }
5529
+
5530
+ return null;
5531
+ }
5532
+
53665533 void SetBumpTexture(String tex)
53675534 {
53685535 if (GetTextures() == null)
....@@ -5407,12 +5574,23 @@
54075574 boolean NeedSupport()
54085575 {
54095576 return
5410
- CameraPane.SUPPORT && !CameraPane.movingcamera && link2master && /*live &&*/ support != null
5577
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && link2master && /*live &&*/ support != null
54115578 // PROBLEM with CROWD!!
54125579 && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
54135580 }
54145581
54155582 static boolean DEBUG_SELECTION = false;
5583
+
5584
+ boolean IsLive()
5585
+ {
5586
+ if (live)
5587
+ return true;
5588
+
5589
+ if (parent == null)
5590
+ return false;
5591
+
5592
+ return parent.IsLive();
5593
+ }
54165594
54175595 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
54185596 {
....@@ -5424,7 +5602,7 @@
54245602 }
54255603
54265604 if (display.DrawMode() == iCameraPane.SELECTION &&
5427
- hide)
5605
+ (hide || dontselect))
54285606 return;
54295607
54305608 if (name != null && name.contains("sclera"))
....@@ -5475,7 +5653,7 @@
54755653 support = support;
54765654
54775655 //boolean usecalllists = IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5478
- boolean usecalllists = false; // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5656
+ boolean usecalllists = IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
54795657
54805658 if (!usecalllists && bRep != null && bRep.displaylist > 0)
54815659 {
....@@ -5495,10 +5673,12 @@
54955673 boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
54965674
54975675 if (!selectmode && //display.DrawMode() != display.SELECTION &&
5498
- (touched || (bRep != null && bRep.displaylist <= 0)))
5676
+ //(touched || (bRep != null && bRep.displaylist <= 0)))
5677
+ (Globals.isLIVE() || touched && (bRep != null && bRep.displaylist <= 0)))
54995678 {
55005679 Globals.lighttouched = true;
55015680 } // all panes...
5681
+
55025682 //if (usecalllists && display.DrawMode() != display.SELECTION && display.DrawMode() != display.SHADOW &&
55035683 if (bRep != null && usecalllists && !selectmode && // june 2013 display.DrawMode() != display.SHADOW &&
55045684 (touched || (bRep != null && bRep.displaylist <= 0)))
....@@ -5666,7 +5846,17 @@
56665846 tex = GetTextures();
56675847 }
56685848
5669
- display.BindTextures(tex, texres);
5849
+ boolean failed = false;
5850
+
5851
+ try
5852
+ {
5853
+ display.BindTextures(tex, texres);
5854
+ }
5855
+ catch (Exception e)
5856
+ {
5857
+ System.err.println("FAILED: " + this);
5858
+ failed = true;
5859
+ }
56705860
56715861 if (!compiled)
56725862 {
....@@ -5688,7 +5878,8 @@
56885878 }
56895879 }
56905880
5691
- display.ReleaseTextures(tex);
5881
+ if (!failed)
5882
+ display.ReleaseTextures(tex);
56925883
56935884 display.PopMaterial(this, selected);
56945885 }
....@@ -5817,6 +6008,9 @@
58176008
58186009 void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
58196010 {
6011
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6012
+ return;
6013
+
58206014 if (hide)
58216015 return;
58226016 // shadow optimisation
....@@ -5941,6 +6135,9 @@
59416135 {
59426136 if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
59436137 return; // no shadow for transparent objects
6138
+
6139
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6140
+ return;
59446141
59456142 if (hide)
59466143 return;
....@@ -6907,7 +7104,7 @@
69077104 spot.translate(32, 32);
69087105 spotw = spot.x + spot.width;
69097106 spoth = spot.y + spot.height;
6910
- info.g.setColor(Color.blue);
7107
+ info.g.setColor(Color.cyan);
69117108 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
69127109 // if (CameraPane.Xmin > spot.x)
69137110 // {
....@@ -6925,11 +7122,12 @@
69257122 // {
69267123 // CameraPane.Ymax = spoth;
69277124 // }
6928
- info.g.drawLine(spotw, spoth, spotw, spoth - 15);
6929
- info.g.drawLine(spotw, spoth, spotw - 15, spoth);
7125
+ // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
7126
+ //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
69307127 spot.translate(0, -32);
6931
- info.g.setColor(Color.green);
7128
+ info.g.setColor(Color.yellow);
69327129 info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7130
+ info.g.setColor(Color.green);
69337131 // if (CameraPane.Xmin > spot.x)
69347132 // {
69357133 // CameraPane.Xmin = spot.x;
....@@ -6981,7 +7179,7 @@
69817179 startX = info.x;
69827180 startY = info.y;
69837181
6984
- hitSomething = 0;
7182
+ hitSomething = -1;
69857183 cVector origin = new cVector();
69867184 //LA.xformPos(origin, toParent, origin);
69877185 Rectangle spot = new Rectangle();
....@@ -7057,6 +7255,7 @@
70577255 //System.out.println("hitSomething = " + hitSomething);
70587256
70597257 double scale = 0.005f * info.camera.Distance();
7258
+
70607259 cVector xlate = new cVector();
70617260 //cVector xlate2 = new cVector();
70627261 switch (hitSomething)
....@@ -7205,24 +7404,27 @@
72057404
72067405 case hitScale: // scale
72077406 double hScale = (double) (info.x - centerPt.x) / 32;
7407
+ double sign = 1;
7408
+ if (hScale < 0)
7409
+ {
7410
+ sign = -1;
7411
+ }
7412
+ hScale = sign*Math.pow(sign*hScale, scale * 50);
72087413 if (hScale < 0.01)
72097414 {
7210
- hScale = 0.01;
7415
+ //hScale = 0.01;
72117416 }
7212
- hScale = Math.pow(hScale, scale * 50);
7213
- if (hScale < 0.01)
7214
- {
7215
- hScale = 0.01;
7216
- }
7417
+
72177418 double vScale = (double) (info.y - centerPt.y) / 32;
7218
- if (vScale < 0.01)
7419
+ sign = 1;
7420
+ if (vScale < 0)
72197421 {
7220
- vScale = 0.01;
7422
+ sign = -1;
72217423 }
7222
- vScale = Math.pow(vScale, scale * 50);
7424
+ vScale = sign*Math.pow(sign*vScale, scale * 50);
72237425 if (vScale < 0.01)
72247426 {
7225
- vScale = 0.01;
7427
+ //vScale = 0.01;
72267428 }
72277429 LA.matCopy(startMat, toParent);
72287430 /**/
....@@ -7233,39 +7435,46 @@
72337435 }
72347436 /**/
72357437
7438
+ double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2);
7439
+
7440
+ if (totalScale < 0.01)
7441
+ {
7442
+ totalScale = 0.01;
7443
+ }
7444
+
72367445 switch (info.pane.RenderCamera().viewCode)
72377446 {
72387447 case 3: // '\001'
7239
- if (modified)
7448
+ if (modified || opposite)
72407449 {
72417450 //LA.matScale(toParent, 1, hScale, vScale);
7242
- LA.matScale(toParent, vScale, 1, 1);
7451
+ LA.matScale(toParent, totalScale, 1, 1);
72437452 } // vScale, 1);
72447453 else
72457454 {
7246
- LA.matScale(toParent, vScale, vScale, vScale);
7455
+ LA.matScale(toParent, 1, totalScale, totalScale);
72477456 } // vScale, 1);
72487457 break;
72497458
72507459 case 2: // '\002'
7251
- if (modified)
7460
+ if (modified || opposite)
72527461 {
72537462 //LA.matScale(toParent, hScale, 1, vScale);
7254
- LA.matScale(toParent, 1, vScale, 1);
7463
+ LA.matScale(toParent, 1, totalScale, 1);
72557464 } else
72567465 {
7257
- LA.matScale(toParent, vScale, 1, vScale);
7466
+ LA.matScale(toParent, totalScale, 1, totalScale);
72587467 }
72597468 break;
72607469
72617470 case 1: // '\003'
7262
- if (modified)
7471
+ if (modified || opposite)
72637472 {
72647473 //LA.matScale(toParent, hScale, vScale, 1);
7265
- LA.matScale(toParent, 1, 1, vScale);
7474
+ LA.matScale(toParent, 1, 1, totalScale);
72667475 } else
72677476 {
7268
- LA.matScale(toParent, vScale, vScale, 1);
7477
+ LA.matScale(toParent, totalScale, totalScale, 1);
72697478 }
72707479 break;
72717480 }
....@@ -7406,7 +7615,7 @@
74067615 objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
74077616 } else
74087617 {
7409
- objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count /*- 1*/) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
7618
+ objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count - 1) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
74107619 } // + super.toString();
74117620 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
74127621
....@@ -7490,7 +7699,7 @@
74907699 /*transient*/ cVector2[] projectedVertices = new cVector2[0];
74917700
74927701 Object3D /*Composite*/ parent;
7493
- Object3D /*Composite*/ fileparent;
7702
+ Object3D /*Composite*/ fileparent; // In the case of FileObject
74947703
74957704 double[][] toParent; // dynamic matrix
74967705 double[][] fromParent;
....@@ -7654,9 +7863,9 @@
76547863 private static cVector edge2 = new cVector();
76557864 //private static cVector norm = new cVector();
76567865 /*transient private*/ int hitSomething;
7657
- private static final int hitCenter = 1;
7658
- private static final int hitScale = 2;
7659
- private static final int hitRotate = 3;
7866
+ static final int hitCenter = 1;
7867
+ static final int hitScale = 2;
7868
+ static final int hitRotate = 3;
76607869 /*transient*/ /*private*/ int viewCode; // Now used for transparency cache flag
76617870 /*transient*/ private Point centerPt;
76627871 /*transient*/ private int startX;