Normand Briere
2019-09-02 21ac57b36a9e3b909853c7d64ac29b7ad72490a3
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)
....@@ -497,10 +527,10 @@
497527 return dist2;
498528 }
499529
500
- static Vertex vertextemp = new Vertex();
501
- static Vertex vertextemp2 = new Vertex();
530
+ static Vertex vertextemp = new Vertex(true);
531
+ static Vertex vertextemp2 = new Vertex(true);
502532
503
- static double SEUIL = 0.1; // 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)
....@@ -570,8 +600,10 @@
570600
571601 if (dot > distmax)
572602 dot = distmax;
603
+ //return 0; // patch for strange behavior
573604 if (dot < -distmax)
574605 dot = -distmax;
606
+ //return 0; // patch for strange behavior
575607
576608 // v3 = GetVertex(this.startvertices[subsupport] + 16);
577609 //
....@@ -596,7 +628,7 @@
596628 // ;
597629 //
598630
599
- supportsize = supportsizes[subsupport];
631
+ supportsize = supportminsize[subsupport];
600632
601633 double K = supportsize / distmax;
602634
....@@ -609,10 +641,12 @@
609641
610642 float dist2 = (float)Distance2(v, v2, 1E10, toRoot, k);
611643
612
- if (dist2 >= 2 * SEUIL*SEUIL) // && !CameraPane.CROWD) // weightmode
644
+ double seuil = SEUIL * 2;
645
+
646
+ if (dist2 >= 2 * seuil*seuil) // && !CameraPane.CROWD) // weightmode
613647 return 0;
614648
615
- dist2 /= 2 * SEUIL*SEUIL; // multiplied by two because center of support
649
+ dist2 /= 2 * seuil*seuil; // multiplied by two because center of support
616650 // could be far from closest point
617651
618652 // dist2 = Math.pow(dist2, 2);
....@@ -646,11 +680,13 @@
646680 // if (supportsize * fadefactor > 1)
647681 // return 1;
648682
649
- return supportsize * fadefactor;
683
+ return //supportsize *
684
+ supportsize * fadefactor;
650685 }
651686
652687 void RecomputeBasis(BoundaryRep other, double[][] toRoot, Vertex v)
653688 {
689
+ CameraPane.CreateSelectedPoint();
654690 CameraPane.selectedpoint.
655691 getAverage(cStatic.point1, true);
656692
....@@ -786,7 +822,7 @@
786822 v.weights[k] = other.ComputeWeight(v, toRoot, k); // (float)(supportsize * normalweight * nz / Math.pow(tx*tx+ty*ty+tz*tz, 1));
787823 v.totalweight += v.weights[k];
788824
789
- if (CameraPane.CROWD)
825
+ if (Globals.CROWD)
790826 {
791827 // System.out.print("weight = " + v.weights[k]);
792828 // System.out.println("; totalweight = " + v.totalweight);
....@@ -946,9 +982,9 @@
946982
947983 int nbsupports;
948984
949
- SEUIL = 0.1; // aout 2013
985
+ // sept 2017 SEUIL = 0.1; // aout 2013
950986
951
- supports = InitConnections(other);
987
+ supports = other.InitConnections();
952988
953989 other.supports = supports; // should be the other way around...
954990
....@@ -968,6 +1004,7 @@
9681004
9691005 v.closestsupport = -1;
9701006
1007
+ CameraPane.CreateSelectedPoint();
9711008 CameraPane.selectedpoint.
9721009 getAverage(cStatic.point1, true);
9731010
....@@ -982,7 +1019,7 @@
9821019
9831020 int subsupports = 0;
9841021
985
- SEUIL = 0.1; // aout 2013
1022
+ // sept 2017 SEUIL = 0.1; // aout 2013
9861023
9871024 while (subsupports == 0)
9881025 {
....@@ -1006,6 +1043,26 @@
10061043
10071044 vect.set(v);
10081045 vect.sub(vect2);
1046
+
1047
+// vertextemp.x = other.averagepoints[c*3];
1048
+// vertextemp.y = other.averagepoints[c*3+1];
1049
+// vertextemp.z = other.averagepoints[c*3+2];
1050
+//
1051
+// Vertex v3 = vertextemp2;
1052
+// v3.x = other.extremepoints[c*3];
1053
+// v3.y = other.extremepoints[c*3+1];
1054
+// v3.z = other.extremepoints[c*3+2];
1055
+//
1056
+// vect3.set(v3); // "X" axis apex
1057
+// vect3.sub(vertextemp); // origin (center)
1058
+//
1059
+// double distmax = vect3.length();
1060
+//
1061
+// vect3.set(v2); // "X" axis apex
1062
+// vect3.sub(vertextemp); // origin (center)
1063
+//
1064
+// if (vect3.length() >= distmax)
1065
+// continue;
10091066
10101067 if (mindistance > vect.dot(vect))
10111068 {
....@@ -1017,7 +1074,9 @@
10171074
10181075 subsupports = v.closestsupport==-1 ? 0 : supports[v.closestsupport].Length();
10191076
1020
- SEUIL *= 2;
1077
+ // previously for "contains", now for weights.
1078
+ assert(subsupports > 0);
1079
+ //SEUIL *= 2;
10211080 }
10221081
10231082 assert(subsupports > 0);
....@@ -1204,6 +1263,7 @@
12041263 for (int wi = v0.weights.length; --wi>=0;)
12051264 v[wi] = 0;
12061265
1266
+ CameraPane.CreateSelectedPoint();
12071267 CameraPane.selectedpoint.
12081268 getAverage(cStatic.point1, true);
12091269
....@@ -1341,6 +1401,7 @@
13411401 v0.x = v0.y = v0.z = 0;
13421402 v0.norm.x = v0.norm.y = v0.norm.z = 0;
13431403
1404
+ CameraPane.CreateSelectedPoint();
13441405 CameraPane.selectedpoint.
13451406 getAverage(cStatic.point1, true);
13461407
....@@ -1492,7 +1553,7 @@
14921553 InitFaceIndices();
14931554 }
14941555
1495
- BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
1556
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
14961557 //float[] v = new float[100];
14971558
14981559 for (int loops=1; --loops>=0;)
....@@ -1522,7 +1583,7 @@
15221583 InitFaceIndices();
15231584 }
15241585
1525
- BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
1586
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15261587 //float[] v = new float[100];
15271588
15281589 for (int loops=10; --loops>=0;)
....@@ -1869,7 +1930,7 @@
18691930 return;
18701931 }
18711932
1872
- // System.exit(0);
1933
+ // System.exit(0);
18731934
18741935 cVector vect = new cVector();
18751936 cVector normal = new cVector();
....@@ -1940,7 +2001,10 @@
19402001 if (v.vertexlinks == null)
19412002 continue;
19422003
1943
- if (v.weights != null && v.weights[j] == 0) // < 0.01 * v.totalweight) // == 0)
2004
+ // Warning: faster but dangerous
2005
+ if (v.weights != null && v.weights[j]
2006
+ // == 0)
2007
+ < 0.0001 * v.totalweight)
19442008 {
19452009 //testweight += v.weights[j-1];
19462010 continue;
....@@ -2221,6 +2285,8 @@
22212285
22222286 transient int lastsoundtime;
22232287
2288
+ transient boolean once = false;
2289
+
22242290 void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked)
22252291 {
22262292 if (LA.isIdentity(toRoot))
....@@ -2276,7 +2342,11 @@
22762342
22772343 if (v.totalweight == 0)
22782344 {
2279
- System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2345
+ if (!once)
2346
+ {
2347
+ System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2348
+ once = true;
2349
+ }
22802350 continue;
22812351 }
22822352
....@@ -2635,18 +2705,18 @@
26352705 if (false) // slow && stepout && onein)
26362706 {
26372707 // sound
2638
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
2708
+ cVector eye = Globals.theRenderer.EyeCamera().location;
26392709
26402710 Vertex v = GetVertex(0);
26412711
26422712 tmp.set(v);
26432713 tmp.sub(eye);
26442714
2645
- if (CameraPane.framecount - lastsoundtime > 30) // 0.25 secs
2715
+ if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26462716 {
2647
- GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
2717
+ Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
26482718
2649
- lastsoundtime = CameraPane.framecount;
2719
+ lastsoundtime = Globals.framecount;
26502720 }
26512721
26522722 stepout = false;
....@@ -3072,6 +3142,7 @@
30723142 //
30733143 // transient VertexCompare[] vertexcompare = null;
30743144
3145
+ // Check if v0 is close enough from any vertex of the given subobject of this.
30753146 boolean Contains(Vertex v0, int object)
30763147 {
30773148 int start = startvertices[object-1];
....@@ -3129,7 +3200,27 @@
31293200 */
31303201 }
31313202
3132
- void GenUV()
3203
+ void UnfoldUV()
3204
+ {
3205
+ for (int i = 0; i < VertexCount(); i++)
3206
+ {
3207
+ Vertex v = GetVertex(i);
3208
+
3209
+ v.x = v.s;
3210
+ v.y = v.t;
3211
+ v.z = 0;
3212
+
3213
+ v.norm.x = 0;
3214
+ v.norm.y = 0;
3215
+ v.norm.z = 1;
3216
+
3217
+ SetVertex(v, i);
3218
+ }
3219
+ }
3220
+
3221
+ float power = 2;
3222
+
3223
+ void GenUV() // float power)
31333224 {
31343225 Trim();
31353226
....@@ -3193,6 +3284,125 @@
31933284 y -= 0.5;
31943285 z -= 0.5;
31953286
3287
+ double ax = Math.abs(x);
3288
+ double ay = Math.abs(y);
3289
+ double max = ax;
3290
+ if (max < ay)
3291
+ {
3292
+ max = ay;
3293
+ }
3294
+
3295
+ if (max == 0)
3296
+ {
3297
+ uvmap[i2] = 0.5f;
3298
+ uvmap[i2+1] = 0.5f;
3299
+ continue;
3300
+ }
3301
+
3302
+ x /= max;
3303
+ y /= max;
3304
+
3305
+ double angle = Math.acos(Math.abs(z*2));
3306
+
3307
+ double k = angle / Math.PI * 2;
3308
+
3309
+ assert(k >= 0);
3310
+
3311
+ // k == 0 => uv = 0 (center)
3312
+ // k == 1 => uv = -1,1 (border)
3313
+
3314
+ if (i == 0)
3315
+ System.out.println("power = " + power);
3316
+
3317
+ double length1 = (ax+ay)/max;
3318
+ double length2 = Math.sqrt(ax*ax + ay*ay) / max;
3319
+
3320
+ double t = k;
3321
+
3322
+ t = Math.pow(t, 3);
3323
+
3324
+ // Interpolate between k/length2 (center) and k (border)
3325
+ if (length2 > 0)
3326
+ k *= (1 - t) / length2 + t;
3327
+
3328
+ double u = k*x;
3329
+ double v = k*y;
3330
+
3331
+ u /= 2;
3332
+ v /= 2;
3333
+ u += 0.5;
3334
+ v += 0.5;
3335
+
3336
+ uvmap[i2] = (float) u;
3337
+ uvmap[i2+1] = (float) v;
3338
+ }
3339
+ }
3340
+
3341
+ void GenUVold(float power)
3342
+ {
3343
+ Trim();
3344
+
3345
+ cVector boxcenter = null;
3346
+ cVector minima, maxima;
3347
+ minima = new cVector();
3348
+ maxima = new cVector();
3349
+ minima.x = minima.y = minima.z = Double.MAX_VALUE;
3350
+ maxima.x = maxima.y = maxima.z = -Double.MAX_VALUE;
3351
+ for (int i = 0; i < VertexCount(); i++)
3352
+ {
3353
+ Vertex v = GetVertex(i);
3354
+
3355
+ if (minima.x > v.x)
3356
+ {
3357
+ minima.x = v.x;
3358
+ }
3359
+ if (minima.y > v.y)
3360
+ {
3361
+ minima.y = v.y;
3362
+ }
3363
+ if (minima.z > v.z)
3364
+ {
3365
+ minima.z = v.z;
3366
+ }
3367
+
3368
+ if (maxima.x < v.x)
3369
+ {
3370
+ maxima.x = v.x;
3371
+ }
3372
+ if (maxima.y < v.y)
3373
+ {
3374
+ maxima.y = v.y;
3375
+ }
3376
+ if (maxima.z < v.z)
3377
+ {
3378
+ maxima.z = v.z;
3379
+ }
3380
+ }
3381
+
3382
+ boxcenter = new cVector((maxima.x + minima.x) / 2, (maxima.y + minima.y) / 2, (maxima.z + minima.z) / 2);
3383
+ int i2 = 0, i3 = 0;
3384
+ for (int i = 0; i < positions.length/3; i++, i3 += 3, i2 += 2)
3385
+ {
3386
+// //uvmap[i2] = (float) normals[i3]*0.5f + 0.5f; // v.x;
3387
+// //uvmap[i2 + 1] = (float) normals[i3+1]*0.5f + 0.5f; //z;
3388
+// uvmap[i2] = (float) (positions[i3] - boxcenter.x);
3389
+// uvmap[i2 + 1] = (float) (positions[i3+2] - boxcenter.z);
3390
+// uvmap[i2] = (float) Math.atan2(positions[i3+1] - boxcenter.y, positions[i3] - boxcenter.x);
3391
+// uvmap[i2 + 1] = (float)(positions[i3+2] - boxcenter.z);
3392
+ // box UV
3393
+ double x = positions[i3] - minima.x; // - Math.floor(positions[i3]);
3394
+ double y = positions[i3+1] - minima.y; // - Math.floor(positions[i3+1]);
3395
+ double z = positions[i3+2] - minima.z; // - Math.floor(positions[i3+2]);
3396
+
3397
+ // [-1/2, 1/2]
3398
+ x /= maxima.x - minima.x;
3399
+ y /= maxima.y - minima.y;
3400
+ z /= maxima.z - minima.z;
3401
+
3402
+ x -= 0.5;
3403
+ y -= 0.5;
3404
+ z -= 0.5;
3405
+
31963406 // x *= 2;
31973407 // y *= 2;
31983408 // z *= 2;
....@@ -3219,6 +3429,15 @@
32193429
32203430 z = Math.cos(angle/2);
32213431
3432
+ assert(z >= 0);
3433
+ assert(z <= 1);
3434
+
3435
+ /**/
3436
+ //z = Math.pow(z, power); //1.08f);
3437
+
3438
+ if (i == 0)
3439
+ System.out.println("power = " + power);
3440
+
32223441 // sqrt(k2*x2 + k2*z2 + y2) = length
32233442 // k2*x2 + k2*z2 = length2 - y2
32243443 // k2 = (length2 - y2) / (x2 + z2)
....@@ -3229,7 +3448,7 @@
32293448 k /= x*x + y*y;
32303449 }
32313450 else
3232
- GrafreeD.Assert(z == 1);
3451
+ Grafreed.Assert(z == 1);
32333452
32343453 if (k < 0)
32353454 k = 0;
....@@ -3238,6 +3457,7 @@
32383457
32393458 x *= k;
32403459 y *= k;
3460
+ /**/
32413461
32423462 double max = Math.abs(x);
32433463 if (max < Math.abs(y))
....@@ -3250,10 +3470,15 @@
32503470 }
32513471
32523472 // max = Math.sqrt(max*2)/2;
3473
+// double x2 = Math.pow(Math.abs(x), 1/power);
3474
+// double y2 = Math.pow(Math.abs(y), 1/power);
3475
+// double z2 = Math.pow(Math.abs(z), 1/power);
3476
+// max = Math.pow(x2 + y2 + z2, power);
32533477
32543478 // if (!(max > 0))
3255
- assert(max > 0);
3256
-
3479
+ //assert(max > 0);
3480
+ assert(max >= 0);
3481
+
32573482 x /= max;
32583483 y /= max;
32593484 z /= max;
....@@ -3516,6 +3741,111 @@
35163741 */
35173742 }
35183743
3744
+ void GenerateNormals2(boolean crease)
3745
+ {
3746
+ cVector tempVector = new cVector();
3747
+
3748
+// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>();
3749
+//
3750
+//
3751
+// for (int i=0; i<this.VertexCount(); i++)
3752
+// {
3753
+// Vertex v = this.GetVertex(i);
3754
+//
3755
+// tempVector.set(v);
3756
+//
3757
+// cVector n = tableBase.get(tempVector.ToFloat());
3758
+//
3759
+// if (n != null)
3760
+// {
3761
+// continue;
3762
+// }
3763
+//
3764
+// tableBase.put(new cVector(tempVector), new cVector(v.norm));
3765
+// }
3766
+
3767
+ BoundaryRep tempSupport = this.support;
3768
+
3769
+ this.support = null;
3770
+
3771
+ BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this);
3772
+
3773
+ this.support = tempSupport;
3774
+
3775
+ //tempRep.Unstripify();
3776
+
3777
+ tempRep.GenerateNormals2(crease);
3778
+
3779
+ boolean keepnormal = Vertex.normalmode;
3780
+ boolean epsequal = Grafreed.epsequal;
3781
+
3782
+ Vertex.normalmode = false;
3783
+ Grafreed.epsequal = false; // A bit strange
3784
+
3785
+ // No need to have a match for vertex counts.
3786
+
3787
+ java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>();
3788
+
3789
+ for (int i=0; i<tempRep.VertexCount(); i++)
3790
+ {
3791
+ Vertex v = tempRep.GetVertex(i);
3792
+
3793
+ cVector n = table.get(tempVector.ToFloat());
3794
+
3795
+ if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0)
3796
+ {
3797
+ //continue;
3798
+ }
3799
+
3800
+ tempVector.set(v);
3801
+
3802
+ //cVector nBase = tableBase.get(tempVector);
3803
+
3804
+ //if (v.norm.dot(nBase) < 0.9)
3805
+ //{
3806
+ // continue;
3807
+ //}
3808
+
3809
+ if (n != null && n.x == 1 && n.y == 0 && n.z == 0)
3810
+ {
3811
+ //continue;
3812
+ }
3813
+
3814
+ if (n != null)
3815
+ {
3816
+// if (n.dot(v.norm) < 0)
3817
+// n.sub(v.norm);
3818
+// else
3819
+// n.add(v.norm);
3820
+//
3821
+// n.normalize();
3822
+ continue;
3823
+ }
3824
+
3825
+ table.put(new cVector(tempVector), new cVector(v.norm));
3826
+ }
3827
+
3828
+ for (int i=0; i<this.VertexCount(); i++)
3829
+ {
3830
+ Vertex v = this.GetVertex(i);
3831
+
3832
+ tempVector.set(v);
3833
+
3834
+ cVector n = table.get(tempVector.ToFloat());
3835
+
3836
+ //if (n.dot(v.norm) < 0)
3837
+ if (n == null)
3838
+ continue;
3839
+
3840
+ LA.vecCopy(n, v.norm);
3841
+
3842
+ this.SetVertex(v, i);
3843
+ }
3844
+
3845
+ Grafreed.epsequal = epsequal;
3846
+ Vertex.normalmode = keepnormal;
3847
+ }
3848
+
35193849 void GenerateNormals(boolean crease)
35203850 {
35213851 boolean wastrim = trimmed;
....@@ -3532,6 +3862,28 @@
35323862 }
35333863
35343864 Trim(true/*wastrim*/,true,crease,wasstrip,false);
3865
+ }
3866
+
3867
+ void GenerateNormalsMesh()
3868
+ {
3869
+ if (stripified)
3870
+ {
3871
+ Unstripify();
3872
+ }
3873
+
3874
+ if (trimmed)
3875
+ {
3876
+ normals = null;
3877
+ }
3878
+ else
3879
+ {
3880
+ for (int i=VertexCount(); --i>=0;)
3881
+ {
3882
+ Vertex v = GetVertex(i);
3883
+
3884
+ v.norm = null;
3885
+ }
3886
+ }
35353887 }
35363888
35373889 void GenNormalsJME()
....@@ -3656,7 +4008,7 @@
36564008 NormalGenerator ng;
36574009
36584010 if (crease)
3659
- ng = new NormalGenerator(Math.PI/6); // default is 44 degrees (or Math.PI/3); // /4);
4011
+ ng = new NormalGenerator(Math.PI/4); // default is 44 degrees (or Math.PI/3); // /4);
36604012 else
36614013 ng = new NormalGenerator(Math.PI); // (Math.PI / 3); // /4);
36624014
....@@ -3674,8 +4026,6 @@
36744026 //System.out.println("NEW = " + positions.length);
36754027 uvmap = new float[ta.getVertexCount() * 2];
36764028
3677
- colors = new float[ta.getVertexCount()]; // * 3];
3678
-
36794029 ta.getCoordinates(0, positions);
36804030 ta.getNormals(0, normals);
36814031 // ta.getColors(0, colors);
....@@ -3683,12 +4033,24 @@
36834033
36844034 System.out.println("UV = " + uvmap[2] + ", " + uvmap[3] + ";");
36854035
4036
+ colors = null;
4037
+// colors = new float[ta.getVertexCount()]; // * 3];
4038
+//
4039
+// for (int i=colors.length; --i>=0;)
4040
+// {
4041
+// colors[i] = 1;
4042
+// }
4043
+
36864044 triangles = new int[ta.getVertexCount()];
36874045
36884046 for (int i = 0; i < triangles.length; i++)
36894047 {
36904048 triangles[i] = i;
36914049 }
4050
+
4051
+// Untrim();
4052
+ if (!trimmed)
4053
+ MergeNormals();
36924054 }
36934055 }
36944056
....@@ -3716,12 +4078,18 @@
37164078 positions = new float[3 * ga.getVertexCount()];
37174079 normals = new float[3 * ga.getVertexCount()];
37184080 uvmap = new float[2 * ga.getVertexCount()];
3719
- colors = new float[1 * ga.getVertexCount()];
37204081
37214082 tsa.getCoordinates(0, positions);
37224083 tsa.getNormals(0, normals);
37234084 tsa.getTextureCoordinates(0, 0, uvmap);
37244085 // tsa.getColors(0, colors);
4086
+
4087
+ colors = null;
4088
+// colors = new float[1 * ga.getVertexCount()];
4089
+// for (int i=colors.length; --i>=0;)
4090
+// {
4091
+// colors[i] = 1;
4092
+// }
37254093
37264094 int stripcount = tsa.getNumStrips();
37274095 triangles = new int[stripcount];
....@@ -3730,6 +4098,7 @@
37304098 stripified = true;
37314099 } catch (ClassCastException e)
37324100 {
4101
+ // ??? aug 2019
37334102 TriangleArray ta = (TriangleArray) ga;
37344103
37354104 positions = new float[3 * ga.getVertexCount()];
....@@ -3744,6 +4113,10 @@
37444113 triangles = new int[1];
37454114 triangles[0] = 3;
37464115 }
4116
+
4117
+ //Untrim();
4118
+ if (!trimmed)
4119
+ MergeNormals();
37474120 }
37484121
37494122 /*
....@@ -3776,21 +4149,66 @@
37764149 for (int i = 0; i < VertexCount(); i++)
37774150 {
37784151 Vertex v = GetVertex(i);
4152
+
4153
+ vertextemp.set(v);
4154
+
37794155 //if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
37804156 {
3781
- GenerateNormal(i, v);
3782
- SetVertex(v, i);
4157
+ if (!GenerateNormal(i, vertextemp))
4158
+ continue;
4159
+
4160
+ if (v.norm.dot(vertextemp.norm) < 0)
4161
+ vertextemp.norm.mul(-1);
4162
+
4163
+ if (v.norm.dot(vertextemp.norm) < 0.9)
4164
+ SetVertex(vertextemp, i);
37834165 }
37844166 }
37854167
37864168 Vertex.normalmode = false;
37874169 }
37884170
4171
+ void MergeNormals()
4172
+ {
4173
+ assert(!trimmed);
4174
+
4175
+ boolean smooth = Grafreed.smoothmode;
4176
+ boolean link = Grafreed.linkUV;
4177
+ Grafreed.smoothmode = true;
4178
+ Grafreed.linkUV = true;
4179
+
4180
+ System.out.println("#Vertex = " + VertexCount());
4181
+ System.out.println("#Face = " + FaceCount());
4182
+
4183
+ java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>();
4184
+
4185
+ for (int i = 0; i < VertexCount(); i++)
4186
+ {
4187
+ Vertex v = GetVertex(i);
4188
+
4189
+ if (!table.contains(v))
4190
+ {
4191
+ table.add(v);
4192
+ }
4193
+ }
4194
+
4195
+ Grafreed.smoothmode = smooth;
4196
+ Grafreed.linkUV = link;
4197
+
4198
+// for (int i = 0; i < VertexCount(); i++)
4199
+// {
4200
+// Vertex v = GetVertex(i);
4201
+//
4202
+// table.add(v);
4203
+// }
4204
+
4205
+ }
4206
+
37894207 static cVector temp1 = new cVector();
37904208 static cVector temp2 = new cVector();
37914209 static cVector temp3 = new cVector();
37924210
3793
- void GenerateNormal(int index, Vertex v)
4211
+ boolean GenerateNormal(int index, Vertex v)
37944212 {
37954213 //System.out.println("Old normal = " + v.norm);
37964214 LA.setVector(v.norm, 0, 0, 0);
....@@ -3819,6 +4237,10 @@
38194237 LA.vecSub(p/*.pos*/, v/*.pos*/, temp1);
38204238 LA.vecSub(q/*.pos*/, v/*.pos*/, temp2);
38214239 }
4240
+ else
4241
+ {
4242
+ continue;
4243
+ }
38224244
38234245 //LA.vecNormalize(temp1);
38244246 //LA.vecNormalize(temp2);
....@@ -3829,17 +4251,25 @@
38294251 double s = temp3.length();
38304252 //double c = temp2.dot(temp1);
38314253
4254
+ if (s == 0)
4255
+ return false;
4256
+
38324257 float angle = 1; // (float) Math.atan2(s, c);
38334258 //if(angle < 0) angle = -angle;
38344259
38354260 //LA.vecNormalize(temp3);
38364261 LA.vecScale(temp3, angle / s);
38374262
4263
+// if (temp3.dot(v.norm) < 0)
4264
+// assert(temp3.dot(v.norm) >= 0);
4265
+
38384266 LA.vecAdd(temp3, v.norm, v.norm);
38394267 }
38404268
38414269 LA.vecNormalize(v.norm);
38424270 //System.out.println("New normal = " + v.norm);
4271
+
4272
+ return true;
38434273 }
38444274
38454275 double Arccos(double x)
....@@ -4381,7 +4811,7 @@
43814811 }
43824812 }
43834813
4384
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4814
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
43854815 {
43864816 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
43874817 CameraPane.tempmat,0, CameraPane.tempmat2,0,
....@@ -4413,14 +4843,14 @@
44134843 // june 2014
44144844 // Camera parentcam = cam;
44154845 //
4416
-// if (cam == CameraPane.theRenderer.cameras[0])
4846
+// if (cam == Globals.theRenderer.cameras[0])
44174847 // {
4418
-// parentcam = CameraPane.theRenderer.cameras[1];
4848
+// parentcam = Globals.theRenderer.cameras[1];
44194849 // }
44204850 //
4421
-// if (cam == CameraPane.theRenderer.cameras[1])
4851
+// if (cam == Globals.theRenderer.cameras[1])
44224852 // {
4423
-// parentcam = CameraPane.theRenderer.cameras[0];
4853
+// parentcam = Globals.theRenderer.cameras[0];
44244854 // }
44254855
44264856 gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0);
....@@ -4546,16 +4976,25 @@
45464976 {
45474977 i3 = positions.length-3;
45484978 i2 = uvmap.length - 2;
4549
- new Exception().printStackTrace();
4979
+ //new Exception().printStackTrace();
45504980 }
45514981
45524982 v./*pos.*/x = positions[i3];
45534983 v./*pos.*/y = positions[i3 + 1];
45544984 v./*pos.*/z = positions[i3 + 2];
45554985
4556
- v.norm.x = normals[i3];
4557
- v.norm.y = normals[i3 + 1];
4558
- v.norm.z = normals[i3 + 2];
4986
+ if (normals == null)
4987
+ {
4988
+ v.norm.x = 0;
4989
+ v.norm.y = 0;
4990
+ v.norm.z = 0;
4991
+ }
4992
+ else
4993
+ {
4994
+ v.norm.x = normals[i3];
4995
+ v.norm.y = normals[i3 + 1];
4996
+ v.norm.z = normals[i3 + 2];
4997
+ }
45594998
45604999 v.s = uvmap[i2];
45615000 v.t = uvmap[i2 + 1];
....@@ -4846,7 +5285,7 @@
48465285 return verticesCopy;
48475286 }
48485287
4849
- void PreprocessOcclusion(CameraPane cp, double[][] transform)
5288
+ void PreprocessOcclusion(iCameraPane cp, double[][] transform)
48505289 {
48515290 if (//!trimmed ||
48525291 AOdone)
....@@ -4855,80 +5294,7 @@
48555294 return;
48565295 }
48575296
4858
- Camera keep = cp.renderCamera;
4859
- cp.renderCamera = localcamera;
4860
-
4861
- if (trimmed)
4862
- {
4863
- float[] colors = new float[positions.length / 3];
4864
-
4865
- int i3 = 0;
4866
- for (int i = 0; i < positions.length / 3; i++, i3 += 3)
4867
- {
4868
- if (normals[i3] == 0 && normals[i3+1] == 0 && normals[i3+2] == 0)
4869
- continue;
4870
-
4871
- from.set(positions[i3], positions[i3 + 1], positions[i3 + 2]);
4872
- to.set(positions[i3] + normals[i3],
4873
- positions[i3 + 1] + normals[i3 + 1],
4874
- positions[i3 + 2] + normals[i3 + 2]);
4875
- LA.xformPos(from, transform, from);
4876
- LA.xformPos(to, transform, to); // RIGID ONLY
4877
- localcamera.setAim(from, to);
4878
-
4879
- CameraPane.occlusionbuffer.display();
4880
-
4881
- if (CameraPane.DEBUG_OCCLUSION)
4882
- cp.display(); // debug
4883
-
4884
- colors[i] = cp.vertexOcclusion.r;
4885
- //colors[i3 + 1] = cp.vertexOcclusion.g;
4886
- //colors[i3 + 2] = cp.vertexOcclusion.b;
4887
-
4888
- if ((i % 1000) == 0 && i != 0)
4889
- {
4890
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
4891
- //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
4892
- System.out.println((int) (100.0 * i / (positions.length / 3)) + "% (" + i + " of " + (positions.length / 3) + ")");
4893
- }
4894
- }
4895
-
4896
- this.colors = colors;
4897
- }
4898
- else
4899
- {
4900
- for (int i = 0; i < VertexCount(); i++)
4901
- {
4902
- Vertex v = GetVertex(i);
4903
-
4904
- if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
4905
- continue;
4906
-
4907
- from.set(v.x, v.y, v.z);
4908
- to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
4909
- LA.xformPos(from, transform, from);
4910
- LA.xformPos(to, transform, to); // RIGID ONLY
4911
- localcamera.setAim(from, to);
4912
-
4913
- CameraPane.occlusionbuffer.display();
4914
-
4915
- if (CameraPane.DEBUG_OCCLUSION)
4916
- cp.display(); // debug
4917
-
4918
- v.AO = cp.vertexOcclusion.r;
4919
-
4920
- if ((i % 1000) == 0 && i != 0)
4921
- {
4922
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
4923
- //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
4924
- System.out.println((int) (100.0 * i / VertexCount()) + "% (" + i + " of " + VertexCount() + ")");
4925
- }
4926
- }
4927
- }
4928
-
4929
- System.out.println("done.");
4930
-
4931
- cp.renderCamera = keep;
5297
+ cp.PrepOcclusion(this, transform);
49325298
49335299 AOdone = true;
49345300 }
....@@ -5343,17 +5709,27 @@
53435709
53445710 transient int nbbadfaces; // ?? = 1000000;
53455711
5346
- int ChooseTriangle()
5712
+ /*
5713
+ */
5714
+ int ChooseTriangle(boolean firstEquilateral)
53475715 {
53485716 int chosen = -1;
53495717
53505718 double minweight = 1E10;
53515719
5720
+ int step = 8; // ?
5721
+
5722
+ if (firstEquilateral)
5723
+ step = 1;
5724
+
53525725 nbbadfaces = 0;
5353
- for (int i=0; i<faces.size(); i+=8)
5726
+ for (int i=0; i<faces.size(); i+=step)
53545727 // for (int i=faces.size(); (i-=8)>=0;)
53555728 {
53565729 Face face = (Face) faces.get(i);
5730
+
5731
+ if (face.used)
5732
+ continue;
53575733
53585734 if (!Valid(face))
53595735 {
....@@ -5363,6 +5739,15 @@
53635739
53645740 if (Boundary(face))
53655741 continue;
5742
+
5743
+// if (Boundary(face.p))
5744
+// continue;
5745
+//
5746
+// if (Boundary(face.q))
5747
+// continue;
5748
+//
5749
+// if (Boundary(face.r))
5750
+// continue;
53665751
53675752 if (!ValidValence(face))
53685753 continue;
....@@ -5375,22 +5760,55 @@
53755760 //?? if (face.weight < 0)
53765761 // continue;
53775762
5378
- double K = 1; // 0.01; // .25;
5379
-
5380
- double factor = (1-K)*face.nbiterations + K; //*face.weight;
5381
-
5382
- double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5383
-
5384
- if (minweight > weight)
5763
+ if (firstEquilateral)
53855764 {
5386
- minweight = weight;
5765
+ if (OneFaceUsed(links.get(face.p)))
5766
+ continue;
5767
+
5768
+ if (OneFaceUsed(links.get(face.q)))
5769
+ continue;
5770
+
5771
+ if (OneFaceUsed(links.get(face.r)))
5772
+ continue;
5773
+
53875774 chosen = i;
5388
- if (minweight == 0)
5389
- break;
5775
+ break;
5776
+ }
5777
+ else
5778
+ {
5779
+ double K = 1; // 0.01; // .25;
5780
+
5781
+ double factor = (1-K)*face.nbiterations + K; //*face.weight;
5782
+
5783
+ double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5784
+
5785
+ if (minweight > weight)
5786
+ {
5787
+ minweight = weight;
5788
+ chosen = i;
5789
+ if (minweight == 0)
5790
+ break;
5791
+ }
53905792 }
53915793 }
53925794
53935795 return chosen;
5796
+ }
5797
+
5798
+ private boolean OneFaceUsed(Vector<Face> faces)
5799
+ {
5800
+ if (faces.size() != 6)
5801
+ return true;
5802
+
5803
+ for (int i=0; i<6; i+=1)
5804
+ {
5805
+ if (faces.get(i).used)
5806
+ {
5807
+ return true;
5808
+ }
5809
+ }
5810
+
5811
+ return false;
53945812 }
53955813
53965814 static boolean remove3valence = true;
....@@ -5426,7 +5844,7 @@
54265844 }
54275845 else
54285846 {
5429
- assert(links.size() == vertices.size());
5847
+ // TODO Grafreed.Assert(links.size() == vertices.size());
54305848
54315849 links.setSize(vertices.size());
54325850 for (int i=vertices.size(); --i>=0;)
....@@ -5434,6 +5852,7 @@
54345852 // linkstouched[i] = false;
54355853 if (links.get(i) == null) // ??
54365854 {
5855
+ new Exception().printStackTrace();
54375856 links.set(i, new Vector(8));
54385857 // linkstouched[i] = true;
54395858 }
....@@ -5444,6 +5863,8 @@
54445863 }
54455864 }
54465865
5866
+ boolean once = false;
5867
+
54475868 for (int i=faces.size(); --i>=0;)
54485869 {
54495870 Face face = (Face) faces.get(i);
....@@ -5455,6 +5876,9 @@
54555876 //if (linkstouched[face.r])
54565877 links.get(face.r).add(face);
54575878
5879
+ if (face.used)
5880
+ once = true;
5881
+
54585882 face.good = 1;
54595883 face.boundary = -1;
54605884 }
....@@ -6226,6 +6650,7 @@
62266650
62276651 void InitWeights()
62286652 {
6653
+ new Exception().printStackTrace();
62296654 System.exit(0);
62306655 int n = 0;
62316656 int b = 0;
....@@ -6819,6 +7244,10 @@
68197244 return (face.boundary = 1) == 1;
68207245 }
68217246
7247
+ // June 2019
7248
+ if (true)
7249
+ return (face.boundary = 0) == 1;
7250
+
68227251 // reverse triangle test
68237252 q1.set(p);
68247253 q2.set(q);
....@@ -7075,6 +7504,7 @@
70757504 assert(f2.contains(i));
70767505 assert(f3.contains(i));
70777506
7507
+ // when r is the "center", p is along the boundary
70787508 while (f0.r != i)
70797509 {
70807510 int t = f0.p;
....@@ -7131,59 +7561,90 @@
71317561 f0 = f3;
71327562 f3 = t;
71337563 }
7134
- atleastone = true;
71357564
7565
+ int va = f0.q;
7566
+ int vb = f0.r;
7567
+ int vc = -1;
7568
+
7569
+ Face toremove1 = null;
7570
+ Face toremove2 = null;
7571
+
7572
+ // f0 is the buffer for the first new triangle,
7573
+ // and otherf is the other upper one.
71367574 Face otherf = null;
71377575
71387576 if (f1.contains(f0.p))
71397577 {
71407578 if (f1.p == f0.p)
71417579 {
7580
+ assert(false);
71427581 f0.r = f1.q;
71437582 }
71447583 else
71457584 {
71467585 assert(f1.q == f0.p);
7147
- f0.r = f1.p;
7586
+ vc = f1.p;
71487587 }
71497588
71507589 otherf = f2;
7151
- faces.remove(f1);
7152
- faces.remove(f3);
7590
+ toremove1 = f1;
7591
+ toremove2 = f3;
71537592 }
71547593 else
71557594 if (f2.contains(f0.p))
71567595 {
71577596 if (f2.p == f0.p)
71587597 {
7598
+ assert(false);
71597599 f0.r = f2.q;
71607600 }
71617601 else
71627602 {
71637603 assert(f2.q == f0.p);
7164
- f0.r = f2.p;
7604
+ vc = f2.p;
71657605 }
71667606
71677607 otherf = f3;
7168
- faces.remove(f1);
7169
- faces.remove(f2);
7608
+ toremove1 = f1;
7609
+ toremove2 = f2;
71707610 }
71717611 if (f3.contains(f0.p))
71727612 {
71737613 if (f3.p == f0.p)
71747614 {
7615
+// assert(false);
7616
+ new Exception().printStackTrace();
71757617 f0.r = f3.q;
71767618 }
71777619 else
71787620 {
71797621 assert(f3.q == f0.p);
7180
- f0.r = f3.p;
7622
+ vc = f3.p;
71817623 }
71827624
71837625 otherf = f1;
7184
- faces.remove(f2);
7185
- faces.remove(f3);
7626
+ toremove1 = f2;
7627
+ toremove2 = f3;
71867628 }
7629
+
7630
+ vertextemp.set(vertices.get(va));
7631
+ vertextemp.sub(vertices.get(vb));
7632
+ vertextemp.normalize();
7633
+ vertextemp2.set(vertices.get(vc));
7634
+ vertextemp2.sub(vertices.get(vb));
7635
+ vertextemp2.normalize();
7636
+
7637
+ if (vertextemp.dot(vertextemp2) > -0.95)
7638
+ {
7639
+ continue;
7640
+ }
7641
+
7642
+ atleastone = true;
7643
+
7644
+ f0.r = vc;
7645
+
7646
+ faces.remove(toremove1);
7647
+ faces.remove(toremove2);
71877648
71887649 if (!f0.contains(otherf.p))
71897650 {
....@@ -7236,7 +7697,7 @@
72367697 //InitWeights();
72377698 }
72387699
7239
- int chosen = ChooseTriangle(); // Best is slow and not really better
7700
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
72407701
72417702 if (chosen == -1)
72427703 {
....@@ -7250,7 +7711,7 @@
72507711 //remove3valence = false;
72517712 // InitWeights();
72527713
7253
- chosen = ChooseTriangle();
7714
+ chosen = ChooseTriangle(true);
72547715 }
72557716 }
72567717
....@@ -7526,7 +7987,7 @@
75267987
75277988 // boolean lock;
75287989
7529
- void SplitInTwo(boolean reduction34, boolean onlyone)
7990
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
75307991 {
75317992 if (stripified)
75327993 {
....@@ -7554,7 +8015,7 @@
75548015 s3 = new cVector();
75558016 }
75568017
7557
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
8018
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
75588019
75598020 try
75608021 {
....@@ -7563,12 +8024,12 @@
75638024 {
75648025 System.err.println("EXCEPTION CAUGHT");
75658026 e.printStackTrace();
7566
- return;
8027
+ return false;
75678028 } catch (Error e)
75688029 {
75698030 System.err.println("ERROR CAUGHT");
75708031 e.printStackTrace();
7571
- return;
8032
+ return false;
75728033 }
75738034
75748035 System.out.println("# faces = " + faces.size());
....@@ -7578,6 +8039,7 @@
75788039 {
75798040 Face face = (Face) faces.get(i);
75808041
8042
+ face.used = false;
75818043 face.nbiterations = 1;
75828044 face.weight = -1;
75838045 face.boundary = -1;
....@@ -7629,6 +8091,11 @@
76298091 nbbadfaces = faces.size();
76308092 //remove3valence = true;
76318093
8094
+ int count = 2;
8095
+
8096
+ if (onlyone)
8097
+ count = 1;
8098
+
76328099 firstpass = true;
76338100
76348101 int n = faces.size();
....@@ -7644,12 +8111,13 @@
76448111 System.out.print('.');
76458112 }
76468113 System.out.println();
8114
+ boolean atleastone = false;
76478115 int i = 0;
7648
- while (reduction34 || faces.size() > n/2)
8116
+ while (true) // reduction34 || faces.size() > n/2)
76498117 {
76508118 if (i++%100 == 0)
76518119 {
7652
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
8120
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
76538121 System.out.println("#faces = " + faces.size());
76548122 // if (i != 1)
76558123 // break;
....@@ -7667,6 +8135,8 @@
76678135 {
76688136 if (!RemoveOneTriangle())
76698137 break;
8138
+
8139
+ atleastone = true;
76708140 }
76718141 // if (iterationcount == 0)
76728142 // break;
....@@ -7677,8 +8147,8 @@
76778147 break;
76788148 }
76798149 firstpass = false;
7680
- if (onlyone)
7681
- break; // one triangle only
8150
+// if (--count<0 && !reduction34)
8151
+// break; // one triangle only
76828152 }
76838153
76848154 InitLinks(false); // for further display
....@@ -7693,7 +8163,9 @@
76938163 //Trim(true,cJME.gennormals,true,false); // doesn't work
76948164 Trim(true,false,false,false,false);
76958165
7696
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8166
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8167
+
8168
+ return atleastone;
76978169 }
76988170
76998171 void UpdateIndices(Face face, Face minface)
....@@ -7706,18 +8178,21 @@
77068178 face.p = minface.p;
77078179 //if (leafweights)
77088180 face.good = 0; // false;
8181
+ face.used = true;
77098182 }
77108183 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
77118184 {
77128185 face.q = minface.p;
77138186 //if (leafweights)
77148187 face.good = 0; // false;
8188
+ face.used = true;
77158189 }
77168190 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
77178191 {
77188192 face.r = minface.p;
77198193 //if (leafweights)
77208194 face.good = 0; // false;
8195
+ face.used = true;
77218196 }
77228197
77238198 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7777,50 +8252,50 @@
77778252 if (v == 2)
77788253 vert = minface.r;
77798254 // Face face = (Face) faces.get(i);
7780
- Vector<Face> vertfaces = links.get(vert);
7781
- for (int i=vertfaces.size(); --i>=0;)
7782
- {
7783
- Face face = (Face) vertfaces.get(i);
7784
-
7785
- // if (face.weight == 10000)
7786
- // continue;
7787
-
7788
- if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
7789
- face.p == minface.q || face.q == minface.q || face.r == minface.q ||
7790
- face.p == minface.r || face.q == minface.r || face.r == minface.r)
8255
+ Vector<Face> vertfaces = links.get(vert);
8256
+ for (int i=vertfaces.size(); --i>=0;)
77918257 {
7792
- if (!leafweights)
8258
+ Face face = (Face) vertfaces.get(i);
8259
+
8260
+ // if (face.weight == 10000)
8261
+ // continue;
8262
+
8263
+ if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
8264
+ face.p == minface.q || face.q == minface.q || face.r == minface.q ||
8265
+ face.p == minface.r || face.q == minface.r || face.r == minface.r)
77938266 {
7794
-// if(minfaceweight <= 0)
7795
-// assert(minfaceweight > 0);
7796
-//
7797
-// //FaceWeight(face);
7798
-// if(face.weight < 0)
7799
-// assert(face.weight >= 0);
7800
-
7801
- face.weight += minfaceweight;
7802
-
7803
-// if (face.weight >= 10000)
7804
-// assert(face.weight < 10000);
8267
+ if (!leafweights)
8268
+ {
8269
+ // if(minfaceweight <= 0)
8270
+ // assert(minfaceweight > 0);
8271
+ //
8272
+ // //FaceWeight(face);
8273
+ // if(face.weight < 0)
8274
+ // assert(face.weight >= 0);
8275
+
8276
+ face.weight += minfaceweight;
8277
+
8278
+ // if (face.weight >= 10000)
8279
+ // assert(face.weight < 10000);
8280
+ }
8281
+ else
8282
+ face.weight = -1;
8283
+
8284
+ face.nbiterations += 1;
8285
+ face.boundary = -1;
8286
+
8287
+ Vertex p = (Vertex)vertices.get(face.p);
8288
+ Vertex q = (Vertex)vertices.get(face.q);
8289
+ Vertex r = (Vertex)vertices.get(face.r);
8290
+
8291
+ p.boundary = -1;
8292
+ q.boundary = -1;
8293
+ r.boundary = -1;
78058294 }
78068295 else
7807
- face.weight = -1;
7808
-
7809
- face.nbiterations += 1;
7810
- face.boundary = -1;
7811
-
7812
- Vertex p = (Vertex)vertices.get(face.p);
7813
- Vertex q = (Vertex)vertices.get(face.q);
7814
- Vertex r = (Vertex)vertices.get(face.r);
7815
-
7816
- p.boundary = -1;
7817
- q.boundary = -1;
7818
- r.boundary = -1;
8296
+ assert(false);
78198297 }
7820
- else
7821
- assert(false);
78228298 }
7823
- }
78248299
78258300 // TouchVertex(minface.p);
78268301 // TouchVertex(minface.q);
....@@ -8021,6 +8496,7 @@
80218496 for (int i=vertfaces.size(); --i>=0;)
80228497 {
80238498 Face face = (Face) vertfaces.get(i);
8499
+ face.used = true;
80248500 face.good = 0; // false;
80258501 if (leafweights)
80268502 face.weight = -1;
....@@ -8067,7 +8543,7 @@
80678543 if (!trimmed)
80688544 return;
80698545
8070
- GrafreeD.linkUV = false;
8546
+ Grafreed.linkUV = false;
80718547
80728548 try
80738549 {
....@@ -8275,9 +8751,6 @@
82758751 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
82768752 }
82778753
8278
- static Camera localcamera = new Camera();
8279
- static cVector from = new cVector();
8280
- static cVector to = new cVector();
82818754 boolean trimmed = false;
82828755 boolean stripified = false;
82838756 transient boolean AOdone = false;
....@@ -8285,8 +8758,10 @@
82858758 /*transient*/ int maxIndexV = 0;
82868759 /*transient*/ int bufV, bufF;
82878760 // Raw version
8288
- private float[] positions;
8289
- private float[] normals;
8761
+ //private
8762
+ float[] positions;
8763
+ //private
8764
+ float[] normals;
82908765 float[] colors;
82918766 private float[] uvmap;
82928767 private int[] triangles;
....@@ -8300,7 +8775,8 @@
83008775 int[] startvertices;
83018776 float[] averagepoints;
83028777 float[] extremepoints;
8303
- float[] supportsizes; // distance of closest point
8778
+ float[] supportminsize; // distance of closest point
8779
+ float[] supportmaxsize; // distance of fartest point
83048780
83058781 transient Hashtable vertextable;
83068782 /*transient*/ private Vertex[] verticesCopy;