Normand Briere
2019-06-17 e36047725ce3217618d4e5807ac7c8769b9e3598
BoundaryRep.java
....@@ -15,7 +15,7 @@
1515 {
1616 this(0, 0);
1717 }
18
-
18
+
1919 void SaveSupports()
2020 {
2121 transientsupport = support;
....@@ -161,6 +161,7 @@
161161 || FaceCount() != other.FaceCount()
162162 || !(indices == null ^ other.indices != null)) // july 2014
163163 {
164
+ // The meshes have different structures.
164165 //new Exception().printStackTrace();
165166 trimmed = other.trimmed;
166167 stripified = other.stripified;
....@@ -172,16 +173,16 @@
172173 bufV = other.bufV;
173174 bufF = other.bufF;
174175
175
- positions = (float[]) GrafreeD.clone(other.positions);
176
- normals = (float[]) GrafreeD.clone(other.normals);
177
- colors = (float[]) GrafreeD.clone(other.colors);
178
- uvmap = (float[]) GrafreeD.clone(other.uvmap);
179
- triangles = (int[]) GrafreeD.clone(other.triangles);
176
+ positions = (float[]) Grafreed.clone(other.positions);
177
+ normals = (float[]) Grafreed.clone(other.normals);
178
+ colors = (float[]) Grafreed.clone(other.colors);
179
+ uvmap = (float[]) Grafreed.clone(other.uvmap);
180
+ triangles = (int[]) Grafreed.clone(other.triangles);
180181
181
- indices = (int[]) GrafreeD.clone(other.indices);
182
+ indices = (int[]) Grafreed.clone(other.indices);
182183
183
- vertices = (Vector<Vertex>) GrafreeD.clone(other.vertices);
184
- faces = (Vector<Face>) GrafreeD.clone(other.faces);
184
+ vertices = (Vector<Vertex>) Grafreed.clone(other.vertices);
185
+ faces = (Vector<Face>) Grafreed.clone(other.faces);
185186 }
186187 else
187188 {
....@@ -239,9 +240,16 @@
239240 }
240241 }
241242
242
- Support[] InitConnections(BoundaryRep other)
243
+ transient Support[] cachesupports = null;
244
+
245
+ Support[] InitConnections()
243246 {
244
- int n = other.startvertices.length-1;
247
+ if (cachesupports != null)
248
+ {
249
+ return cachesupports;
250
+ }
251
+
252
+ int n = this.startvertices.length-1;
245253
246254 Support[] supports = new Support[n];
247255
....@@ -253,38 +261,60 @@
253261
254262 for (int object=1; object<=n; object++)
255263 {
256
- int start = other.startvertices[object-1];
257
- int end = other.startvertices[object];
264
+ int start = this.startvertices[object-1];
265
+ int end = this.startvertices[object];
258266
259267 if (start == end)
260268 continue; // ??
261269
270
+ /**
271
+ Vertex v2 = vertextemp;
272
+ v2.x = averagepoints[object*3];
273
+ v2.y = averagepoints[object*3+1];
274
+ v2.z = averagepoints[object*3+2];
275
+
276
+ //v2.set(GetVertex(this.startvertices[subsupport]));
277
+
278
+ // projected point
279
+ Vertex v3 = vertextemp2;
280
+ //GetVertex(this.startvertices[subsupport]);
281
+ v3.x = extremepoints[object*3];
282
+ v3.y = extremepoints[object*3+1];
283
+ v3.z = extremepoints[object*3+2];
284
+
285
+ vect3.set(v3); // "X" axis apex
286
+ vect3.sub(v2); // origin (center)
287
+ vect3.normalize();
288
+ /**/
289
+
262290 int linkcount = 0;
263291
264292 int objectinlist = -1;
293
+
294
+ Support subsupport = supports[object-1];
265295
266296 for (int object2=1; object2<=n; object2++)
267297 {
268298 for (int i = start; i < end; i++)
269299 {
270
- Vertex v = other.GetVertex(i);
300
+ Vertex v = this.GetVertex(i);
271301
272
- //
273
- if (other.Contains(v, object2))
302
+ // Check if v is close enough from any vertex of the given subobject.
303
+ if (this.Contains(v, object2))
274304 {
275
- if (linkcount == supports[object-1].links.length)
305
+ if (linkcount == subsupport.links.length)
276306 break;
277307
278308 if (object2 == object)
279309 objectinlist = linkcount;
280310
281
- supports[object-1].links[linkcount++] = object2;
311
+ subsupport.links[linkcount++] = object2;
282312 break;
283313 }
284314 }
285315 }
286316
287
- supports[object-1].links[linkcount] = -1;
317
+ subsupport.links[linkcount] = -1;
288318
289319 if (objectinlist == -1)
290320 assert(objectinlist != -1);
....@@ -293,9 +323,9 @@
293323 // assert(linkcount > 1);
294324
295325 // show main support as blue
296
- int first = supports[object-1].links[0];
297
- supports[object-1].links[0] = supports[object-1].links[objectinlist];
298
- supports[object-1].links[objectinlist] = first;
326
+ int first = subsupport.links[0];
327
+ subsupport.links[0] = subsupport.links[objectinlist];
328
+ subsupport.links[objectinlist] = first;
299329 }
300330
301331 for (int loop = 0; --loop>=0;)
....@@ -353,7 +383,7 @@
353383 supports = supports2;
354384 }
355385
356
- return supports;
386
+ return cachesupports = supports;
357387 }
358388
359389 double Distance2(Vertex v, Vertex v2, double dist2beat, double[][] toRoot, int k)
....@@ -500,7 +530,7 @@
500530 static Vertex vertextemp = new Vertex(true);
501531 static Vertex vertextemp2 = new Vertex(true);
502532
503
- static double SEUIL = 0.1f; // 0.1 for rag doll; 0.07;
533
+ static double SEUIL = 0.05f; // 0.1 for rag doll; 0.07;
504534
505535 // Compute weight of point w/r to this
506536 float ComputeWeight(Vertex v, double[][] toRoot, int k)
....@@ -598,7 +628,7 @@
598628 // ;
599629 //
600630
601
- supportsize = supportsizes[subsupport];
631
+ supportsize = supportminsize[subsupport];
602632
603633 double K = supportsize / distmax;
604634
....@@ -650,7 +680,8 @@
650680 // if (supportsize * fadefactor > 1)
651681 // return 1;
652682
653
- return supportsize * fadefactor;
683
+ return //supportsize *
684
+ supportsize * fadefactor;
654685 }
655686
656687 void RecomputeBasis(BoundaryRep other, double[][] toRoot, Vertex v)
....@@ -790,7 +821,7 @@
790821 v.weights[k] = other.ComputeWeight(v, toRoot, k); // (float)(supportsize * normalweight * nz / Math.pow(tx*tx+ty*ty+tz*tz, 1));
791822 v.totalweight += v.weights[k];
792823
793
- if (CameraPane.CROWD)
824
+ if (Globals.CROWD)
794825 {
795826 // System.out.print("weight = " + v.weights[k]);
796827 // System.out.println("; totalweight = " + v.totalweight);
....@@ -952,7 +983,7 @@
952983
953984 // sept 2017 SEUIL = 0.1; // aout 2013
954985
955
- supports = InitConnections(other);
986
+ supports = other.InitConnections();
956987
957988 other.supports = supports; // should be the other way around...
958989
....@@ -1518,7 +1549,7 @@
15181549 InitFaceIndices();
15191550 }
15201551
1521
- BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
1552
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15221553 //float[] v = new float[100];
15231554
15241555 for (int loops=1; --loops>=0;)
....@@ -1548,7 +1579,7 @@
15481579 InitFaceIndices();
15491580 }
15501581
1551
- BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
1582
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15521583 //float[] v = new float[100];
15531584
15541585 for (int loops=10; --loops>=0;)
....@@ -1895,7 +1926,7 @@
18951926 return;
18961927 }
18971928
1898
- // System.exit(0);
1929
+ // System.exit(0);
18991930
19001931 cVector vect = new cVector();
19011932 cVector normal = new cVector();
....@@ -1966,7 +1997,7 @@
19661997 if (v.vertexlinks == null)
19671998 continue;
19681999
1969
- if (v.weights != null && v.weights[j] == 0) // < 0.01 * v.totalweight) // == 0)
2000
+ if (v.weights != null && v.weights[j] < 0.001 * v.totalweight) // == 0)
19702001 {
19712002 //testweight += v.weights[j-1];
19722003 continue;
....@@ -2247,6 +2278,8 @@
22472278
22482279 transient int lastsoundtime;
22492280
2281
+ transient boolean once = false;
2282
+
22502283 void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked)
22512284 {
22522285 if (LA.isIdentity(toRoot))
....@@ -2302,7 +2335,11 @@
23022335
23032336 if (v.totalweight == 0)
23042337 {
2305
- System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2338
+ if (!once)
2339
+ {
2340
+ System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2341
+ once = true;
2342
+ }
23062343 continue;
23072344 }
23082345
....@@ -2661,18 +2698,18 @@
26612698 if (false) // slow && stepout && onein)
26622699 {
26632700 // sound
2664
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
2701
+ cVector eye = Globals.theRenderer.EyeCamera().location;
26652702
26662703 Vertex v = GetVertex(0);
26672704
26682705 tmp.set(v);
26692706 tmp.sub(eye);
26702707
2671
- if (CameraPane.framecount - lastsoundtime > 30) // 0.25 secs
2708
+ if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26722709 {
2673
- GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
2710
+ Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
26742711
2675
- lastsoundtime = CameraPane.framecount;
2712
+ lastsoundtime = Globals.framecount;
26762713 }
26772714
26782715 stepout = false;
....@@ -3098,6 +3135,7 @@
30983135 //
30993136 // transient VertexCompare[] vertexcompare = null;
31003137
3138
+ // Check if v0 is close enough from any vertex of the given subobject of this.
31013139 boolean Contains(Vertex v0, int object)
31023140 {
31033141 int start = startvertices[object-1];
....@@ -3155,7 +3193,27 @@
31553193 */
31563194 }
31573195
3158
- void GenUV()
3196
+ void UnfoldUV()
3197
+ {
3198
+ for (int i = 0; i < VertexCount(); i++)
3199
+ {
3200
+ Vertex v = GetVertex(i);
3201
+
3202
+ v.x = v.s;
3203
+ v.y = v.t;
3204
+ v.z = 0;
3205
+
3206
+ v.norm.x = 0;
3207
+ v.norm.y = 0;
3208
+ v.norm.z = 1;
3209
+
3210
+ SetVertex(v, i);
3211
+ }
3212
+ }
3213
+
3214
+ float power = 2;
3215
+
3216
+ void GenUV() // float power)
31593217 {
31603218 Trim();
31613219
....@@ -3219,6 +3277,125 @@
32193277 y -= 0.5;
32203278 z -= 0.5;
32213279
3280
+ double ax = Math.abs(x);
3281
+ double ay = Math.abs(y);
3282
+ double max = ax;
3283
+ if (max < ay)
3284
+ {
3285
+ max = ay;
3286
+ }
3287
+
3288
+ if (max == 0)
3289
+ {
3290
+ uvmap[i2] = 0.5f;
3291
+ uvmap[i2+1] = 0.5f;
3292
+ continue;
3293
+ }
3294
+
3295
+ x /= max;
3296
+ y /= max;
3297
+
3298
+ double angle = Math.acos(Math.abs(z*2));
3299
+
3300
+ double k = angle / Math.PI * 2;
3301
+
3302
+ assert(k >= 0);
3303
+
3304
+ // k == 0 => uv = 0 (center)
3305
+ // k == 1 => uv = -1,1 (border)
3306
+
3307
+ if (i == 0)
3308
+ System.out.println("power = " + power);
3309
+
3310
+ double length1 = (ax+ay)/max;
3311
+ double length2 = Math.sqrt(ax*ax + ay*ay) / max;
3312
+
3313
+ double t = k;
3314
+
3315
+ t = Math.pow(t, 3);
3316
+
3317
+ // Interpolate between k/length2 (center) and k (border)
3318
+ if (length2 > 0)
3319
+ k *= (1 - t) / length2 + t;
3320
+
3321
+ double u = k*x;
3322
+ double v = k*y;
3323
+
3324
+ u /= 2;
3325
+ v /= 2;
3326
+ u += 0.5;
3327
+ v += 0.5;
3328
+
3329
+ uvmap[i2] = (float) u;
3330
+ uvmap[i2+1] = (float) v;
3331
+ }
3332
+ }
3333
+
3334
+ void GenUVold(float power)
3335
+ {
3336
+ Trim();
3337
+
3338
+ cVector boxcenter = null;
3339
+ cVector minima, maxima;
3340
+ minima = new cVector();
3341
+ maxima = new cVector();
3342
+ minima.x = minima.y = minima.z = Double.MAX_VALUE;
3343
+ maxima.x = maxima.y = maxima.z = -Double.MAX_VALUE;
3344
+ for (int i = 0; i < VertexCount(); i++)
3345
+ {
3346
+ Vertex v = GetVertex(i);
3347
+
3348
+ if (minima.x > v.x)
3349
+ {
3350
+ minima.x = v.x;
3351
+ }
3352
+ if (minima.y > v.y)
3353
+ {
3354
+ minima.y = v.y;
3355
+ }
3356
+ if (minima.z > v.z)
3357
+ {
3358
+ minima.z = v.z;
3359
+ }
3360
+
3361
+ if (maxima.x < v.x)
3362
+ {
3363
+ maxima.x = v.x;
3364
+ }
3365
+ if (maxima.y < v.y)
3366
+ {
3367
+ maxima.y = v.y;
3368
+ }
3369
+ if (maxima.z < v.z)
3370
+ {
3371
+ maxima.z = v.z;
3372
+ }
3373
+ }
3374
+
3375
+ boxcenter = new cVector((maxima.x + minima.x) / 2, (maxima.y + minima.y) / 2, (maxima.z + minima.z) / 2);
3376
+ int i2 = 0, i3 = 0;
3377
+ for (int i = 0; i < positions.length/3; i++, i3 += 3, i2 += 2)
3378
+ {
3379
+// //uvmap[i2] = (float) normals[i3]*0.5f + 0.5f; // v.x;
3380
+// //uvmap[i2 + 1] = (float) normals[i3+1]*0.5f + 0.5f; //z;
3381
+// uvmap[i2] = (float) (positions[i3] - boxcenter.x);
3382
+// uvmap[i2 + 1] = (float) (positions[i3+2] - boxcenter.z);
3383
+// uvmap[i2] = (float) Math.atan2(positions[i3+1] - boxcenter.y, positions[i3] - boxcenter.x);
3384
+// uvmap[i2 + 1] = (float)(positions[i3+2] - boxcenter.z);
3385
+ // box UV
3386
+ double x = positions[i3] - minima.x; // - Math.floor(positions[i3]);
3387
+ double y = positions[i3+1] - minima.y; // - Math.floor(positions[i3+1]);
3388
+ double z = positions[i3+2] - minima.z; // - Math.floor(positions[i3+2]);
3389
+
3390
+ // [-1/2, 1/2]
3391
+ x /= maxima.x - minima.x;
3392
+ y /= maxima.y - minima.y;
3393
+ z /= maxima.z - minima.z;
3394
+
3395
+ x -= 0.5;
3396
+ y -= 0.5;
3397
+ z -= 0.5;
3398
+
32223399 // x *= 2;
32233400 // y *= 2;
32243401 // z *= 2;
....@@ -3245,6 +3422,15 @@
32453422
32463423 z = Math.cos(angle/2);
32473424
3425
+ assert(z >= 0);
3426
+ assert(z <= 1);
3427
+
3428
+ /**/
3429
+ //z = Math.pow(z, power); //1.08f);
3430
+
3431
+ if (i == 0)
3432
+ System.out.println("power = " + power);
3433
+
32483434 // sqrt(k2*x2 + k2*z2 + y2) = length
32493435 // k2*x2 + k2*z2 = length2 - y2
32503436 // k2 = (length2 - y2) / (x2 + z2)
....@@ -3255,7 +3441,7 @@
32553441 k /= x*x + y*y;
32563442 }
32573443 else
3258
- GrafreeD.Assert(z == 1);
3444
+ Grafreed.Assert(z == 1);
32593445
32603446 if (k < 0)
32613447 k = 0;
....@@ -3264,6 +3450,7 @@
32643450
32653451 x *= k;
32663452 y *= k;
3453
+ /**/
32673454
32683455 double max = Math.abs(x);
32693456 if (max < Math.abs(y))
....@@ -3276,10 +3463,15 @@
32763463 }
32773464
32783465 // max = Math.sqrt(max*2)/2;
3466
+// double x2 = Math.pow(Math.abs(x), 1/power);
3467
+// double y2 = Math.pow(Math.abs(y), 1/power);
3468
+// double z2 = Math.pow(Math.abs(z), 1/power);
3469
+// max = Math.pow(x2 + y2 + z2, power);
32793470
32803471 // if (!(max > 0))
3281
- assert(max > 0);
3282
-
3472
+ //assert(max > 0);
3473
+ assert(max >= 0);
3474
+
32833475 x /= max;
32843476 y /= max;
32853477 z /= max;
....@@ -3542,6 +3734,111 @@
35423734 */
35433735 }
35443736
3737
+ void GenerateNormals2(boolean crease)
3738
+ {
3739
+ cVector tempVector = new cVector();
3740
+
3741
+// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>();
3742
+//
3743
+//
3744
+// for (int i=0; i<this.VertexCount(); i++)
3745
+// {
3746
+// Vertex v = this.GetVertex(i);
3747
+//
3748
+// tempVector.set(v);
3749
+//
3750
+// cVector n = tableBase.get(tempVector.ToFloat());
3751
+//
3752
+// if (n != null)
3753
+// {
3754
+// continue;
3755
+// }
3756
+//
3757
+// tableBase.put(new cVector(tempVector), new cVector(v.norm));
3758
+// }
3759
+
3760
+ BoundaryRep tempSupport = this.support;
3761
+
3762
+ this.support = null;
3763
+
3764
+ BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this);
3765
+
3766
+ this.support = tempSupport;
3767
+
3768
+ //tempRep.Unstripify();
3769
+
3770
+ tempRep.GenerateNormals2(crease);
3771
+
3772
+ boolean keepnormal = Vertex.normalmode;
3773
+ boolean epsequal = Grafreed.epsequal;
3774
+
3775
+ Vertex.normalmode = false;
3776
+ Grafreed.epsequal = false; // A bit strange
3777
+
3778
+ // No need to have a match for vertex counts.
3779
+
3780
+ java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>();
3781
+
3782
+ for (int i=0; i<tempRep.VertexCount(); i++)
3783
+ {
3784
+ Vertex v = tempRep.GetVertex(i);
3785
+
3786
+ cVector n = table.get(tempVector.ToFloat());
3787
+
3788
+ if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0)
3789
+ {
3790
+ //continue;
3791
+ }
3792
+
3793
+ tempVector.set(v);
3794
+
3795
+ //cVector nBase = tableBase.get(tempVector);
3796
+
3797
+ //if (v.norm.dot(nBase) < 0.9)
3798
+ //{
3799
+ // continue;
3800
+ //}
3801
+
3802
+ if (n != null && n.x == 1 && n.y == 0 && n.z == 0)
3803
+ {
3804
+ //continue;
3805
+ }
3806
+
3807
+ if (n != null)
3808
+ {
3809
+// if (n.dot(v.norm) < 0)
3810
+// n.sub(v.norm);
3811
+// else
3812
+// n.add(v.norm);
3813
+//
3814
+// n.normalize();
3815
+ continue;
3816
+ }
3817
+
3818
+ table.put(new cVector(tempVector), new cVector(v.norm));
3819
+ }
3820
+
3821
+ for (int i=0; i<this.VertexCount(); i++)
3822
+ {
3823
+ Vertex v = this.GetVertex(i);
3824
+
3825
+ tempVector.set(v);
3826
+
3827
+ cVector n = table.get(tempVector.ToFloat());
3828
+
3829
+ //if (n.dot(v.norm) < 0)
3830
+ if (n == null)
3831
+ continue;
3832
+
3833
+ LA.vecCopy(n, v.norm);
3834
+
3835
+ this.SetVertex(v, i);
3836
+ }
3837
+
3838
+ Grafreed.epsequal = epsequal;
3839
+ Vertex.normalmode = keepnormal;
3840
+ }
3841
+
35453842 void GenerateNormals(boolean crease)
35463843 {
35473844 boolean wastrim = trimmed;
....@@ -3558,6 +3855,28 @@
35583855 }
35593856
35603857 Trim(true/*wastrim*/,true,crease,wasstrip,false);
3858
+ }
3859
+
3860
+ void GenerateNormalsMesh()
3861
+ {
3862
+ if (stripified)
3863
+ {
3864
+ Unstripify();
3865
+ }
3866
+
3867
+ if (trimmed)
3868
+ {
3869
+ normals = null;
3870
+ }
3871
+ else
3872
+ {
3873
+ for (int i=VertexCount(); --i>=0;)
3874
+ {
3875
+ Vertex v = GetVertex(i);
3876
+
3877
+ v.norm = null;
3878
+ }
3879
+ }
35613880 }
35623881
35633882 void GenNormalsJME()
....@@ -3715,6 +4034,10 @@
37154034 {
37164035 triangles[i] = i;
37174036 }
4037
+
4038
+// Untrim();
4039
+ if (!trimmed)
4040
+ MergeNormals();
37184041 }
37194042 }
37204043
....@@ -3748,6 +4071,11 @@
37484071 tsa.getNormals(0, normals);
37494072 tsa.getTextureCoordinates(0, 0, uvmap);
37504073 // tsa.getColors(0, colors);
4074
+
4075
+ for (int i=colors.length; --i>=0;)
4076
+ {
4077
+ colors[i] = 1;
4078
+ }
37514079
37524080 int stripcount = tsa.getNumStrips();
37534081 triangles = new int[stripcount];
....@@ -3770,6 +4098,10 @@
37704098 triangles = new int[1];
37714099 triangles[0] = 3;
37724100 }
4101
+
4102
+ //Untrim();
4103
+ if (!trimmed)
4104
+ MergeNormals();
37734105 }
37744106
37754107 /*
....@@ -3819,6 +4151,40 @@
38194151 }
38204152
38214153 Vertex.normalmode = false;
4154
+ }
4155
+
4156
+ void MergeNormals()
4157
+ {
4158
+ boolean smooth = Grafreed.smoothmode;
4159
+ boolean link = Grafreed.linkUV;
4160
+ Grafreed.smoothmode = true;
4161
+ Grafreed.linkUV = true;
4162
+
4163
+ System.out.println("#Vertex = " + VertexCount());
4164
+ System.out.println("#Face = " + FaceCount());
4165
+
4166
+ java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>();
4167
+
4168
+ for (int i = 0; i < VertexCount(); i++)
4169
+ {
4170
+ Vertex v = GetVertex(i);
4171
+
4172
+ if (!table.contains(v))
4173
+ {
4174
+ table.add(v);
4175
+ }
4176
+ }
4177
+
4178
+ Grafreed.smoothmode = smooth;
4179
+ Grafreed.linkUV = link;
4180
+
4181
+// for (int i = 0; i < VertexCount(); i++)
4182
+// {
4183
+// Vertex v = GetVertex(i);
4184
+//
4185
+// table.add(v);
4186
+// }
4187
+
38224188 }
38234189
38244190 static cVector temp1 = new cVector();
....@@ -4428,7 +4794,7 @@
44284794 }
44294795 }
44304796
4431
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4797
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
44324798 {
44334799 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
44344800 CameraPane.tempmat,0, CameraPane.tempmat2,0,
....@@ -4460,14 +4826,14 @@
44604826 // june 2014
44614827 // Camera parentcam = cam;
44624828 //
4463
-// if (cam == CameraPane.theRenderer.cameras[0])
4829
+// if (cam == Globals.theRenderer.cameras[0])
44644830 // {
4465
-// parentcam = CameraPane.theRenderer.cameras[1];
4831
+// parentcam = Globals.theRenderer.cameras[1];
44664832 // }
44674833 //
4468
-// if (cam == CameraPane.theRenderer.cameras[1])
4834
+// if (cam == Globals.theRenderer.cameras[1])
44694835 // {
4470
-// parentcam = CameraPane.theRenderer.cameras[0];
4836
+// parentcam = Globals.theRenderer.cameras[0];
44714837 // }
44724838
44734839 gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0);
....@@ -4593,16 +4959,25 @@
45934959 {
45944960 i3 = positions.length-3;
45954961 i2 = uvmap.length - 2;
4596
- new Exception().printStackTrace();
4962
+ //new Exception().printStackTrace();
45974963 }
45984964
45994965 v./*pos.*/x = positions[i3];
46004966 v./*pos.*/y = positions[i3 + 1];
46014967 v./*pos.*/z = positions[i3 + 2];
46024968
4603
- v.norm.x = normals[i3];
4604
- v.norm.y = normals[i3 + 1];
4605
- v.norm.z = normals[i3 + 2];
4969
+ if (normals == null)
4970
+ {
4971
+ v.norm.x = 0;
4972
+ v.norm.y = 0;
4973
+ v.norm.z = 0;
4974
+ }
4975
+ else
4976
+ {
4977
+ v.norm.x = normals[i3];
4978
+ v.norm.y = normals[i3 + 1];
4979
+ v.norm.z = normals[i3 + 2];
4980
+ }
46064981
46074982 v.s = uvmap[i2];
46084983 v.t = uvmap[i2 + 1];
....@@ -4893,7 +5268,7 @@
48935268 return verticesCopy;
48945269 }
48955270
4896
- void PreprocessOcclusion(CameraPane cp, double[][] transform)
5271
+ void PreprocessOcclusion(iCameraPane cp, double[][] transform)
48975272 {
48985273 if (//!trimmed ||
48995274 AOdone)
....@@ -4902,80 +5277,7 @@
49025277 return;
49035278 }
49045279
4905
- Camera keep = cp.renderCamera;
4906
- cp.renderCamera = localcamera;
4907
-
4908
- if (trimmed)
4909
- {
4910
- float[] colors = new float[positions.length / 3];
4911
-
4912
- int i3 = 0;
4913
- for (int i = 0; i < positions.length / 3; i++, i3 += 3)
4914
- {
4915
- if (normals[i3] == 0 && normals[i3+1] == 0 && normals[i3+2] == 0)
4916
- continue;
4917
-
4918
- from.set(positions[i3], positions[i3 + 1], positions[i3 + 2]);
4919
- to.set(positions[i3] + normals[i3],
4920
- positions[i3 + 1] + normals[i3 + 1],
4921
- positions[i3 + 2] + normals[i3 + 2]);
4922
- LA.xformPos(from, transform, from);
4923
- LA.xformPos(to, transform, to); // RIGID ONLY
4924
- localcamera.setAim(from, to);
4925
-
4926
- CameraPane.occlusionbuffer.display();
4927
-
4928
- if (CameraPane.DEBUG_OCCLUSION)
4929
- cp.display(); // debug
4930
-
4931
- colors[i] = cp.vertexOcclusion.r;
4932
- //colors[i3 + 1] = cp.vertexOcclusion.g;
4933
- //colors[i3 + 2] = cp.vertexOcclusion.b;
4934
-
4935
- if ((i % 100) == 0 && i != 0)
4936
- {
4937
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
4938
- //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
4939
- System.out.println((int) (100.0 * i / (positions.length / 3)) + "% (" + i + " of " + (positions.length / 3) + ")");
4940
- }
4941
- }
4942
-
4943
- this.colors = colors;
4944
- }
4945
- else
4946
- {
4947
- for (int i = 0; i < VertexCount(); i++)
4948
- {
4949
- Vertex v = GetVertex(i);
4950
-
4951
- if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
4952
- continue;
4953
-
4954
- from.set(v.x, v.y, v.z);
4955
- to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
4956
- LA.xformPos(from, transform, from);
4957
- LA.xformPos(to, transform, to); // RIGID ONLY
4958
- localcamera.setAim(from, to);
4959
-
4960
- CameraPane.occlusionbuffer.display();
4961
-
4962
- if (CameraPane.DEBUG_OCCLUSION)
4963
- cp.display(); // debug
4964
-
4965
- v.AO = cp.vertexOcclusion.r;
4966
-
4967
- if ((i % 100) == 0 && i != 0)
4968
- {
4969
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
4970
- //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
4971
- System.out.println((int) (100.0 * i / VertexCount()) + "% (" + i + " of " + VertexCount() + ")");
4972
- }
4973
- }
4974
- }
4975
-
4976
- //System.out.println("done.");
4977
-
4978
- cp.renderCamera = keep;
5280
+ cp.PrepOcclusion(this, transform);
49795281
49805282 AOdone = true;
49815283 }
....@@ -5390,17 +5692,27 @@
53905692
53915693 transient int nbbadfaces; // ?? = 1000000;
53925694
5393
- int ChooseTriangle()
5695
+ /*
5696
+ */
5697
+ int ChooseTriangle(boolean firstEquilateral)
53945698 {
53955699 int chosen = -1;
53965700
53975701 double minweight = 1E10;
53985702
5703
+ int step = 8; // ?
5704
+
5705
+ if (firstEquilateral)
5706
+ step = 1;
5707
+
53995708 nbbadfaces = 0;
5400
- for (int i=0; i<faces.size(); i+=8)
5709
+ for (int i=0; i<faces.size(); i+=step)
54015710 // for (int i=faces.size(); (i-=8)>=0;)
54025711 {
54035712 Face face = (Face) faces.get(i);
5713
+
5714
+ if (face.used)
5715
+ continue;
54045716
54055717 if (!Valid(face))
54065718 {
....@@ -5410,6 +5722,15 @@
54105722
54115723 if (Boundary(face))
54125724 continue;
5725
+
5726
+// if (Boundary(face.p))
5727
+// continue;
5728
+//
5729
+// if (Boundary(face.q))
5730
+// continue;
5731
+//
5732
+// if (Boundary(face.r))
5733
+// continue;
54135734
54145735 if (!ValidValence(face))
54155736 continue;
....@@ -5422,22 +5743,55 @@
54225743 //?? if (face.weight < 0)
54235744 // continue;
54245745
5425
- double K = 1; // 0.01; // .25;
5426
-
5427
- double factor = (1-K)*face.nbiterations + K; //*face.weight;
5428
-
5429
- double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5430
-
5431
- if (minweight > weight)
5746
+ if (firstEquilateral)
54325747 {
5433
- minweight = weight;
5748
+ if (OneFaceUsed(links.get(face.p)))
5749
+ continue;
5750
+
5751
+ if (OneFaceUsed(links.get(face.q)))
5752
+ continue;
5753
+
5754
+ if (OneFaceUsed(links.get(face.r)))
5755
+ continue;
5756
+
54345757 chosen = i;
5435
- if (minweight == 0)
5436
- break;
5758
+ break;
5759
+ }
5760
+ else
5761
+ {
5762
+ double K = 1; // 0.01; // .25;
5763
+
5764
+ double factor = (1-K)*face.nbiterations + K; //*face.weight;
5765
+
5766
+ double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5767
+
5768
+ if (minweight > weight)
5769
+ {
5770
+ minweight = weight;
5771
+ chosen = i;
5772
+ if (minweight == 0)
5773
+ break;
5774
+ }
54375775 }
54385776 }
54395777
54405778 return chosen;
5779
+ }
5780
+
5781
+ private boolean OneFaceUsed(Vector<Face> faces)
5782
+ {
5783
+ if (faces.size() != 6)
5784
+ return true;
5785
+
5786
+ for (int i=0; i<6; i+=1)
5787
+ {
5788
+ if (faces.get(i).used)
5789
+ {
5790
+ return true;
5791
+ }
5792
+ }
5793
+
5794
+ return false;
54415795 }
54425796
54435797 static boolean remove3valence = true;
....@@ -5473,7 +5827,7 @@
54735827 }
54745828 else
54755829 {
5476
- assert(links.size() == vertices.size());
5830
+ // TODO Grafreed.Assert(links.size() == vertices.size());
54775831
54785832 links.setSize(vertices.size());
54795833 for (int i=vertices.size(); --i>=0;)
....@@ -5481,6 +5835,7 @@
54815835 // linkstouched[i] = false;
54825836 if (links.get(i) == null) // ??
54835837 {
5838
+ new Exception().printStackTrace();
54845839 links.set(i, new Vector(8));
54855840 // linkstouched[i] = true;
54865841 }
....@@ -5491,6 +5846,8 @@
54915846 }
54925847 }
54935848
5849
+ boolean once = false;
5850
+
54945851 for (int i=faces.size(); --i>=0;)
54955852 {
54965853 Face face = (Face) faces.get(i);
....@@ -5502,6 +5859,9 @@
55025859 //if (linkstouched[face.r])
55035860 links.get(face.r).add(face);
55045861
5862
+ if (face.used)
5863
+ once = true;
5864
+
55055865 face.good = 1;
55065866 face.boundary = -1;
55075867 }
....@@ -6273,6 +6633,7 @@
62736633
62746634 void InitWeights()
62756635 {
6636
+ new Exception().printStackTrace();
62766637 System.exit(0);
62776638 int n = 0;
62786639 int b = 0;
....@@ -6866,6 +7227,10 @@
68667227 return (face.boundary = 1) == 1;
68677228 }
68687229
7230
+ // June 2019
7231
+ if (true)
7232
+ return (face.boundary = 0) == 1;
7233
+
68697234 // reverse triangle test
68707235 q1.set(p);
68717236 q2.set(q);
....@@ -7315,7 +7680,7 @@
73157680 //InitWeights();
73167681 }
73177682
7318
- int chosen = ChooseTriangle(); // Best is slow and not really better
7683
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
73197684
73207685 if (chosen == -1)
73217686 {
....@@ -7329,7 +7694,7 @@
73297694 //remove3valence = false;
73307695 // InitWeights();
73317696
7332
- chosen = ChooseTriangle();
7697
+ chosen = ChooseTriangle(true);
73337698 }
73347699 }
73357700
....@@ -7605,7 +7970,7 @@
76057970
76067971 // boolean lock;
76077972
7608
- void SplitInTwo(boolean reduction34, boolean onlyone)
7973
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
76097974 {
76107975 if (stripified)
76117976 {
....@@ -7633,7 +7998,7 @@
76337998 s3 = new cVector();
76347999 }
76358000
7636
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
8001
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
76378002
76388003 try
76398004 {
....@@ -7642,12 +8007,12 @@
76428007 {
76438008 System.err.println("EXCEPTION CAUGHT");
76448009 e.printStackTrace();
7645
- return;
8010
+ return false;
76468011 } catch (Error e)
76478012 {
76488013 System.err.println("ERROR CAUGHT");
76498014 e.printStackTrace();
7650
- return;
8015
+ return false;
76518016 }
76528017
76538018 System.out.println("# faces = " + faces.size());
....@@ -7657,6 +8022,7 @@
76578022 {
76588023 Face face = (Face) faces.get(i);
76598024
8025
+ face.used = false;
76608026 face.nbiterations = 1;
76618027 face.weight = -1;
76628028 face.boundary = -1;
....@@ -7708,6 +8074,11 @@
77088074 nbbadfaces = faces.size();
77098075 //remove3valence = true;
77108076
8077
+ int count = 2;
8078
+
8079
+ if (onlyone)
8080
+ count = 1;
8081
+
77118082 firstpass = true;
77128083
77138084 int n = faces.size();
....@@ -7723,12 +8094,13 @@
77238094 System.out.print('.');
77248095 }
77258096 System.out.println();
8097
+ boolean atleastone = false;
77268098 int i = 0;
7727
- while (reduction34 || faces.size() > n/2)
8099
+ while (true) // reduction34 || faces.size() > n/2)
77288100 {
77298101 if (i++%100 == 0)
77308102 {
7731
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
8103
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
77328104 System.out.println("#faces = " + faces.size());
77338105 // if (i != 1)
77348106 // break;
....@@ -7746,6 +8118,8 @@
77468118 {
77478119 if (!RemoveOneTriangle())
77488120 break;
8121
+
8122
+ atleastone = true;
77498123 }
77508124 // if (iterationcount == 0)
77518125 // break;
....@@ -7756,8 +8130,8 @@
77568130 break;
77578131 }
77588132 firstpass = false;
7759
- if (onlyone)
7760
- break; // one triangle only
8133
+// if (--count<0 && !reduction34)
8134
+// break; // one triangle only
77618135 }
77628136
77638137 InitLinks(false); // for further display
....@@ -7772,7 +8146,9 @@
77728146 //Trim(true,cJME.gennormals,true,false); // doesn't work
77738147 Trim(true,false,false,false,false);
77748148
7775
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8149
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8150
+
8151
+ return atleastone;
77768152 }
77778153
77788154 void UpdateIndices(Face face, Face minface)
....@@ -7785,18 +8161,21 @@
77858161 face.p = minface.p;
77868162 //if (leafweights)
77878163 face.good = 0; // false;
8164
+ face.used = true;
77888165 }
77898166 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
77908167 {
77918168 face.q = minface.p;
77928169 //if (leafweights)
77938170 face.good = 0; // false;
8171
+ face.used = true;
77948172 }
77958173 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
77968174 {
77978175 face.r = minface.p;
77988176 //if (leafweights)
77998177 face.good = 0; // false;
8178
+ face.used = true;
78008179 }
78018180
78028181 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7856,50 +8235,50 @@
78568235 if (v == 2)
78578236 vert = minface.r;
78588237 // Face face = (Face) faces.get(i);
7859
- Vector<Face> vertfaces = links.get(vert);
7860
- for (int i=vertfaces.size(); --i>=0;)
7861
- {
7862
- Face face = (Face) vertfaces.get(i);
7863
-
7864
- // if (face.weight == 10000)
7865
- // continue;
7866
-
7867
- if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
7868
- face.p == minface.q || face.q == minface.q || face.r == minface.q ||
7869
- face.p == minface.r || face.q == minface.r || face.r == minface.r)
8238
+ Vector<Face> vertfaces = links.get(vert);
8239
+ for (int i=vertfaces.size(); --i>=0;)
78708240 {
7871
- if (!leafweights)
8241
+ Face face = (Face) vertfaces.get(i);
8242
+
8243
+ // if (face.weight == 10000)
8244
+ // continue;
8245
+
8246
+ if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
8247
+ face.p == minface.q || face.q == minface.q || face.r == minface.q ||
8248
+ face.p == minface.r || face.q == minface.r || face.r == minface.r)
78728249 {
7873
-// if(minfaceweight <= 0)
7874
-// assert(minfaceweight > 0);
7875
-//
7876
-// //FaceWeight(face);
7877
-// if(face.weight < 0)
7878
-// assert(face.weight >= 0);
7879
-
7880
- face.weight += minfaceweight;
7881
-
7882
-// if (face.weight >= 10000)
7883
-// assert(face.weight < 10000);
8250
+ if (!leafweights)
8251
+ {
8252
+ // if(minfaceweight <= 0)
8253
+ // assert(minfaceweight > 0);
8254
+ //
8255
+ // //FaceWeight(face);
8256
+ // if(face.weight < 0)
8257
+ // assert(face.weight >= 0);
8258
+
8259
+ face.weight += minfaceweight;
8260
+
8261
+ // if (face.weight >= 10000)
8262
+ // assert(face.weight < 10000);
8263
+ }
8264
+ else
8265
+ face.weight = -1;
8266
+
8267
+ face.nbiterations += 1;
8268
+ face.boundary = -1;
8269
+
8270
+ Vertex p = (Vertex)vertices.get(face.p);
8271
+ Vertex q = (Vertex)vertices.get(face.q);
8272
+ Vertex r = (Vertex)vertices.get(face.r);
8273
+
8274
+ p.boundary = -1;
8275
+ q.boundary = -1;
8276
+ r.boundary = -1;
78848277 }
78858278 else
7886
- face.weight = -1;
7887
-
7888
- face.nbiterations += 1;
7889
- face.boundary = -1;
7890
-
7891
- Vertex p = (Vertex)vertices.get(face.p);
7892
- Vertex q = (Vertex)vertices.get(face.q);
7893
- Vertex r = (Vertex)vertices.get(face.r);
7894
-
7895
- p.boundary = -1;
7896
- q.boundary = -1;
7897
- r.boundary = -1;
8279
+ assert(false);
78988280 }
7899
- else
7900
- assert(false);
79018281 }
7902
- }
79038282
79048283 // TouchVertex(minface.p);
79058284 // TouchVertex(minface.q);
....@@ -8100,6 +8479,7 @@
81008479 for (int i=vertfaces.size(); --i>=0;)
81018480 {
81028481 Face face = (Face) vertfaces.get(i);
8482
+ face.used = true;
81038483 face.good = 0; // false;
81048484 if (leafweights)
81058485 face.weight = -1;
....@@ -8146,7 +8526,7 @@
81468526 if (!trimmed)
81478527 return;
81488528
8149
- GrafreeD.linkUV = false;
8529
+ Grafreed.linkUV = false;
81508530
81518531 try
81528532 {
....@@ -8354,9 +8734,6 @@
83548734 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
83558735 }
83568736
8357
- static Camera localcamera = new Camera();
8358
- static cVector from = new cVector();
8359
- static cVector to = new cVector();
83608737 boolean trimmed = false;
83618738 boolean stripified = false;
83628739 transient boolean AOdone = false;
....@@ -8364,8 +8741,10 @@
83648741 /*transient*/ int maxIndexV = 0;
83658742 /*transient*/ int bufV, bufF;
83668743 // Raw version
8367
- private float[] positions;
8368
- private float[] normals;
8744
+ //private
8745
+ float[] positions;
8746
+ //private
8747
+ float[] normals;
83698748 float[] colors;
83708749 private float[] uvmap;
83718750 private int[] triangles;
....@@ -8379,7 +8758,8 @@
83798758 int[] startvertices;
83808759 float[] averagepoints;
83818760 float[] extremepoints;
8382
- float[] supportsizes; // distance of closest point
8761
+ float[] supportminsize; // distance of closest point
8762
+ float[] supportmaxsize; // distance of fartest point
83838763
83848764 transient Hashtable vertextable;
83858765 /*transient*/ private Vertex[] verticesCopy;