Normand Briere
2019-09-18 f9325048496d7cdbcad233f8a6b84c88e79adcc2
BoundaryRep.java
....@@ -7,7 +7,8 @@
77
88 class BoundaryRep implements java.io.Serializable
99 {
10
- static final long serialVersionUID = -4852664309425035321L;
10
+ static final long serialVersionUID = // VERY old 2008 -5762968998168738314L;
11
+ -4852664309425035321L;
1112
1213 transient int displaylist = 0;
1314
....@@ -15,7 +16,7 @@
1516 {
1617 this(0, 0);
1718 }
18
-
19
+
1920 void SaveSupports()
2021 {
2122 transientsupport = support;
....@@ -161,6 +162,7 @@
161162 || FaceCount() != other.FaceCount()
162163 || !(indices == null ^ other.indices != null)) // july 2014
163164 {
165
+ // The meshes have different structures.
164166 //new Exception().printStackTrace();
165167 trimmed = other.trimmed;
166168 stripified = other.stripified;
....@@ -172,16 +174,16 @@
172174 bufV = other.bufV;
173175 bufF = other.bufF;
174176
175
- positions = (float[]) GraphreeD.clone(other.positions);
176
- normals = (float[]) GraphreeD.clone(other.normals);
177
- colors = (float[]) GraphreeD.clone(other.colors);
178
- uvmap = (float[]) GraphreeD.clone(other.uvmap);
179
- triangles = (int[]) GraphreeD.clone(other.triangles);
177
+ positions = (float[]) Grafreed.clone(other.positions);
178
+ normals = (float[]) Grafreed.clone(other.normals);
179
+ colors = (float[]) Grafreed.clone(other.colors);
180
+ uvmap = (float[]) Grafreed.clone(other.uvmap);
181
+ triangles = (int[]) Grafreed.clone(other.triangles);
180182
181
- indices = (int[]) GraphreeD.clone(other.indices);
183
+ indices = (int[]) Grafreed.clone(other.indices);
182184
183
- vertices = (Vector<Vertex>) GraphreeD.clone(other.vertices);
184
- faces = (Vector<Face>) GraphreeD.clone(other.faces);
185
+ vertices = (Vector<Vertex>) Grafreed.clone(other.vertices);
186
+ faces = (Vector<Face>) Grafreed.clone(other.faces);
185187 }
186188 else
187189 {
....@@ -239,9 +241,16 @@
239241 }
240242 }
241243
242
- Support[] InitConnections(BoundaryRep other)
244
+ transient Support[] cachesupports = null;
245
+
246
+ Support[] InitConnections()
243247 {
244
- int n = other.startvertices.length-1;
248
+ if (cachesupports != null)
249
+ {
250
+ return cachesupports;
251
+ }
252
+
253
+ int n = this.startvertices.length-1;
245254
246255 Support[] supports = new Support[n];
247256
....@@ -253,38 +262,60 @@
253262
254263 for (int object=1; object<=n; object++)
255264 {
256
- int start = other.startvertices[object-1];
257
- int end = other.startvertices[object];
265
+ int start = this.startvertices[object-1];
266
+ int end = this.startvertices[object];
258267
259268 if (start == end)
260269 continue; // ??
261270
271
+ /**
272
+ Vertex v2 = vertextemp;
273
+ v2.x = averagepoints[object*3];
274
+ v2.y = averagepoints[object*3+1];
275
+ v2.z = averagepoints[object*3+2];
276
+
277
+ //v2.set(GetVertex(this.startvertices[subsupport]));
278
+
279
+ // projected point
280
+ Vertex v3 = vertextemp2;
281
+ //GetVertex(this.startvertices[subsupport]);
282
+ v3.x = extremepoints[object*3];
283
+ v3.y = extremepoints[object*3+1];
284
+ v3.z = extremepoints[object*3+2];
285
+
286
+ vect3.set(v3); // "X" axis apex
287
+ vect3.sub(v2); // origin (center)
288
+ vect3.normalize();
289
+ /**/
290
+
262291 int linkcount = 0;
263292
264293 int objectinlist = -1;
294
+
295
+ Support subsupport = supports[object-1];
265296
266297 for (int object2=1; object2<=n; object2++)
267298 {
268299 for (int i = start; i < end; i++)
269300 {
270
- Vertex v = other.GetVertex(i);
301
+ Vertex v = this.GetVertex(i);
271302
272
- //
273
- if (other.Contains(v, object2))
303
+ // Check if v is close enough from any vertex of the given subobject.
304
+ if (this.Contains(v, object2))
274305 {
275
- if (linkcount == supports[object-1].links.length)
306
+ if (linkcount == subsupport.links.length)
276307 break;
277308
278309 if (object2 == object)
279310 objectinlist = linkcount;
280311
281
- supports[object-1].links[linkcount++] = object2;
312
+ subsupport.links[linkcount++] = object2;
282313 break;
283314 }
284315 }
285316 }
286317
287
- supports[object-1].links[linkcount] = -1;
318
+ subsupport.links[linkcount] = -1;
288319
289320 if (objectinlist == -1)
290321 assert(objectinlist != -1);
....@@ -293,9 +324,9 @@
293324 // assert(linkcount > 1);
294325
295326 // 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;
327
+ int first = subsupport.links[0];
328
+ subsupport.links[0] = subsupport.links[objectinlist];
329
+ subsupport.links[objectinlist] = first;
299330 }
300331
301332 for (int loop = 0; --loop>=0;)
....@@ -353,7 +384,7 @@
353384 supports = supports2;
354385 }
355386
356
- return supports;
387
+ return cachesupports = supports;
357388 }
358389
359390 double Distance2(Vertex v, Vertex v2, double dist2beat, double[][] toRoot, int k)
....@@ -497,10 +528,10 @@
497528 return dist2;
498529 }
499530
500
- static Vertex vertextemp = new Vertex();
501
- static Vertex vertextemp2 = new Vertex();
531
+ static Vertex vertextemp = new Vertex(true);
532
+ static Vertex vertextemp2 = new Vertex(true);
502533
503
- static double SEUIL = 0.1; // 0.1 for rag doll; 0.07;
534
+ static double SEUIL = 0.025f; // 0.1 for rag doll; 0.07;
504535
505536 // Compute weight of point w/r to this
506537 float ComputeWeight(Vertex v, double[][] toRoot, int k)
....@@ -570,8 +601,10 @@
570601
571602 if (dot > distmax)
572603 dot = distmax;
604
+ //return 0; // patch for strange behavior
573605 if (dot < -distmax)
574606 dot = -distmax;
607
+ //return 0; // patch for strange behavior
575608
576609 // v3 = GetVertex(this.startvertices[subsupport] + 16);
577610 //
....@@ -596,7 +629,7 @@
596629 // ;
597630 //
598631
599
- supportsize = supportsizes[subsupport];
632
+ supportsize = supportminsize[subsupport];
600633
601634 double K = supportsize / distmax;
602635
....@@ -609,10 +642,12 @@
609642
610643 float dist2 = (float)Distance2(v, v2, 1E10, toRoot, k);
611644
612
- if (dist2 >= 2 * SEUIL*SEUIL) // && !CameraPane.CROWD) // weightmode
645
+ double seuil = SEUIL * 2;
646
+
647
+ if (dist2 >= 2 * seuil*seuil) // && !CameraPane.CROWD) // weightmode
613648 return 0;
614649
615
- dist2 /= 2 * SEUIL*SEUIL; // multiplied by two because center of support
650
+ dist2 /= 2 * seuil*seuil; // multiplied by two because center of support
616651 // could be far from closest point
617652
618653 // dist2 = Math.pow(dist2, 2);
....@@ -646,11 +681,13 @@
646681 // if (supportsize * fadefactor > 1)
647682 // return 1;
648683
649
- return supportsize * fadefactor;
684
+ return //supportsize *
685
+ supportsize * fadefactor;
650686 }
651687
652688 void RecomputeBasis(BoundaryRep other, double[][] toRoot, Vertex v)
653689 {
690
+ CameraPane.CreateSelectedPoint();
654691 CameraPane.selectedpoint.
655692 getAverage(cStatic.point1, true);
656693
....@@ -786,7 +823,7 @@
786823 v.weights[k] = other.ComputeWeight(v, toRoot, k); // (float)(supportsize * normalweight * nz / Math.pow(tx*tx+ty*ty+tz*tz, 1));
787824 v.totalweight += v.weights[k];
788825
789
- if (CameraPane.CROWD)
826
+ if (Globals.CROWD)
790827 {
791828 // System.out.print("weight = " + v.weights[k]);
792829 // System.out.println("; totalweight = " + v.totalweight);
....@@ -946,9 +983,9 @@
946983
947984 int nbsupports;
948985
949
- SEUIL = 0.1; // aout 2013
986
+ // sept 2017 SEUIL = 0.1; // aout 2013
950987
951
- supports = InitConnections(other);
988
+ supports = other.InitConnections();
952989
953990 other.supports = supports; // should be the other way around...
954991
....@@ -968,6 +1005,7 @@
9681005
9691006 v.closestsupport = -1;
9701007
1008
+ CameraPane.CreateSelectedPoint();
9711009 CameraPane.selectedpoint.
9721010 getAverage(cStatic.point1, true);
9731011
....@@ -982,7 +1020,7 @@
9821020
9831021 int subsupports = 0;
9841022
985
- SEUIL = 0.1; // aout 2013
1023
+ // sept 2017 SEUIL = 0.1; // aout 2013
9861024
9871025 while (subsupports == 0)
9881026 {
....@@ -1006,6 +1044,26 @@
10061044
10071045 vect.set(v);
10081046 vect.sub(vect2);
1047
+
1048
+// vertextemp.x = other.averagepoints[c*3];
1049
+// vertextemp.y = other.averagepoints[c*3+1];
1050
+// vertextemp.z = other.averagepoints[c*3+2];
1051
+//
1052
+// Vertex v3 = vertextemp2;
1053
+// v3.x = other.extremepoints[c*3];
1054
+// v3.y = other.extremepoints[c*3+1];
1055
+// v3.z = other.extremepoints[c*3+2];
1056
+//
1057
+// vect3.set(v3); // "X" axis apex
1058
+// vect3.sub(vertextemp); // origin (center)
1059
+//
1060
+// double distmax = vect3.length();
1061
+//
1062
+// vect3.set(v2); // "X" axis apex
1063
+// vect3.sub(vertextemp); // origin (center)
1064
+//
1065
+// if (vect3.length() >= distmax)
1066
+// continue;
10091067
10101068 if (mindistance > vect.dot(vect))
10111069 {
....@@ -1017,7 +1075,9 @@
10171075
10181076 subsupports = v.closestsupport==-1 ? 0 : supports[v.closestsupport].Length();
10191077
1020
- SEUIL *= 2;
1078
+ // previously for "contains", now for weights.
1079
+ assert(subsupports > 0);
1080
+ //SEUIL *= 2;
10211081 }
10221082
10231083 assert(subsupports > 0);
....@@ -1204,6 +1264,7 @@
12041264 for (int wi = v0.weights.length; --wi>=0;)
12051265 v[wi] = 0;
12061266
1267
+ CameraPane.CreateSelectedPoint();
12071268 CameraPane.selectedpoint.
12081269 getAverage(cStatic.point1, true);
12091270
....@@ -1341,6 +1402,7 @@
13411402 v0.x = v0.y = v0.z = 0;
13421403 v0.norm.x = v0.norm.y = v0.norm.z = 0;
13431404
1405
+ CameraPane.CreateSelectedPoint();
13441406 CameraPane.selectedpoint.
13451407 getAverage(cStatic.point1, true);
13461408
....@@ -1492,7 +1554,7 @@
14921554 InitFaceIndices();
14931555 }
14941556
1495
- BoundaryRep rep = (BoundaryRep) GraphreeD.clone(this);
1557
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
14961558 //float[] v = new float[100];
14971559
14981560 for (int loops=1; --loops>=0;)
....@@ -1522,7 +1584,7 @@
15221584 InitFaceIndices();
15231585 }
15241586
1525
- BoundaryRep rep = (BoundaryRep) GraphreeD.clone(this);
1587
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15261588 //float[] v = new float[100];
15271589
15281590 for (int loops=10; --loops>=0;)
....@@ -1869,7 +1931,7 @@
18691931 return;
18701932 }
18711933
1872
- // System.exit(0);
1934
+ // System.exit(0);
18731935
18741936 cVector vect = new cVector();
18751937 cVector normal = new cVector();
....@@ -1940,7 +2002,10 @@
19402002 if (v.vertexlinks == null)
19412003 continue;
19422004
1943
- if (v.weights != null && v.weights[j] == 0) // < 0.01 * v.totalweight) // == 0)
2005
+ // Warning: faster but dangerous
2006
+ if (v.weights != null && v.weights[j]
2007
+ == 0)
2008
+ //< 0.001 * v.totalweight)
19442009 {
19452010 //testweight += v.weights[j-1];
19462011 continue;
....@@ -2163,7 +2228,7 @@
21632228 // if (slow)
21642229 // aout 2013
21652230 // sept 2013 merde...
2166
- W = 13;
2231
+ W = 3; // 13;
21672232
21682233 // POSERATE
21692234 if (CameraPane.tickcount > 0 || CameraPane.SLOWPOSE)
....@@ -2221,6 +2286,8 @@
22212286
22222287 transient int lastsoundtime;
22232288
2289
+ transient boolean once = false;
2290
+
22242291 void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked)
22252292 {
22262293 if (LA.isIdentity(toRoot))
....@@ -2276,7 +2343,11 @@
22762343
22772344 if (v.totalweight == 0)
22782345 {
2279
- System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2346
+ if (!once)
2347
+ {
2348
+ System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2349
+ once = true;
2350
+ }
22802351 continue;
22812352 }
22822353
....@@ -2600,7 +2671,7 @@
26002671 // if (stepout && !playedonce)
26012672 // {
26022673 // // sound
2603
-// GraphreeD.wav.play();
2674
+// GrafreeD.wav.play();
26042675 // playedonce = true;
26052676 // }
26062677 //
....@@ -2635,18 +2706,18 @@
26352706 if (false) // slow && stepout && onein)
26362707 {
26372708 // sound
2638
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
2709
+ cVector eye = Globals.theRenderer.EyeCamera().location;
26392710
26402711 Vertex v = GetVertex(0);
26412712
26422713 tmp.set(v);
26432714 tmp.sub(eye);
26442715
2645
- if (CameraPane.framecount - lastsoundtime > 30) // 0.25 secs
2716
+ if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26462717 {
2647
- GraphreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
2718
+ Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
26482719
2649
- lastsoundtime = CameraPane.framecount;
2720
+ lastsoundtime = Globals.framecount;
26502721 }
26512722
26522723 stepout = false;
....@@ -3072,6 +3143,7 @@
30723143 //
30733144 // transient VertexCompare[] vertexcompare = null;
30743145
3146
+ // Check if v0 is close enough from any vertex of the given subobject of this.
30753147 boolean Contains(Vertex v0, int object)
30763148 {
30773149 int start = startvertices[object-1];
....@@ -3129,7 +3201,27 @@
31293201 */
31303202 }
31313203
3132
- void GenUV()
3204
+ void UnfoldUV()
3205
+ {
3206
+ for (int i = 0; i < VertexCount(); i++)
3207
+ {
3208
+ Vertex v = GetVertex(i);
3209
+
3210
+ v.x = v.s;
3211
+ v.y = v.t;
3212
+ v.z = 0;
3213
+
3214
+ v.norm.x = 0;
3215
+ v.norm.y = 0;
3216
+ v.norm.z = 1;
3217
+
3218
+ SetVertex(v, i);
3219
+ }
3220
+ }
3221
+
3222
+ float power = 2;
3223
+
3224
+ void GenUV() // float power)
31333225 {
31343226 Trim();
31353227
....@@ -3193,6 +3285,125 @@
31933285 y -= 0.5;
31943286 z -= 0.5;
31953287
3288
+ double ax = Math.abs(x);
3289
+ double ay = Math.abs(y);
3290
+ double max = ax;
3291
+ if (max < ay)
3292
+ {
3293
+ max = ay;
3294
+ }
3295
+
3296
+ if (max == 0)
3297
+ {
3298
+ uvmap[i2] = 0.5f;
3299
+ uvmap[i2+1] = 0.5f;
3300
+ continue;
3301
+ }
3302
+
3303
+ x /= max;
3304
+ y /= max;
3305
+
3306
+ double angle = Math.acos(Math.abs(z*2));
3307
+
3308
+ double k = angle / Math.PI * 2;
3309
+
3310
+ assert(k >= 0);
3311
+
3312
+ // k == 0 => uv = 0 (center)
3313
+ // k == 1 => uv = -1,1 (border)
3314
+
3315
+ if (i == 0)
3316
+ System.out.println("power = " + power);
3317
+
3318
+ double length1 = (ax+ay)/max;
3319
+ double length2 = Math.sqrt(ax*ax + ay*ay) / max;
3320
+
3321
+ double t = k;
3322
+
3323
+ t = Math.pow(t, 3);
3324
+
3325
+ // Interpolate between k/length2 (center) and k (border)
3326
+ if (length2 > 0)
3327
+ k *= (1 - t) / length2 + t;
3328
+
3329
+ double u = k*x;
3330
+ double v = k*y;
3331
+
3332
+ u /= 2;
3333
+ v /= 2;
3334
+ u += 0.5;
3335
+ v += 0.5;
3336
+
3337
+ uvmap[i2] = (float) u;
3338
+ uvmap[i2+1] = (float) v;
3339
+ }
3340
+ }
3341
+
3342
+ void GenUVold(float power)
3343
+ {
3344
+ Trim();
3345
+
3346
+ cVector boxcenter = null;
3347
+ cVector minima, maxima;
3348
+ minima = new cVector();
3349
+ maxima = new cVector();
3350
+ minima.x = minima.y = minima.z = Double.MAX_VALUE;
3351
+ maxima.x = maxima.y = maxima.z = -Double.MAX_VALUE;
3352
+ for (int i = 0; i < VertexCount(); i++)
3353
+ {
3354
+ Vertex v = GetVertex(i);
3355
+
3356
+ if (minima.x > v.x)
3357
+ {
3358
+ minima.x = v.x;
3359
+ }
3360
+ if (minima.y > v.y)
3361
+ {
3362
+ minima.y = v.y;
3363
+ }
3364
+ if (minima.z > v.z)
3365
+ {
3366
+ minima.z = v.z;
3367
+ }
3368
+
3369
+ if (maxima.x < v.x)
3370
+ {
3371
+ maxima.x = v.x;
3372
+ }
3373
+ if (maxima.y < v.y)
3374
+ {
3375
+ maxima.y = v.y;
3376
+ }
3377
+ if (maxima.z < v.z)
3378
+ {
3379
+ maxima.z = v.z;
3380
+ }
3381
+ }
3382
+
3383
+ boxcenter = new cVector((maxima.x + minima.x) / 2, (maxima.y + minima.y) / 2, (maxima.z + minima.z) / 2);
3384
+ int i2 = 0, i3 = 0;
3385
+ for (int i = 0; i < positions.length/3; i++, i3 += 3, i2 += 2)
3386
+ {
3387
+// //uvmap[i2] = (float) normals[i3]*0.5f + 0.5f; // v.x;
3388
+// //uvmap[i2 + 1] = (float) normals[i3+1]*0.5f + 0.5f; //z;
3389
+// uvmap[i2] = (float) (positions[i3] - boxcenter.x);
3390
+// uvmap[i2 + 1] = (float) (positions[i3+2] - boxcenter.z);
3391
+// uvmap[i2] = (float) Math.atan2(positions[i3+1] - boxcenter.y, positions[i3] - boxcenter.x);
3392
+// uvmap[i2 + 1] = (float)(positions[i3+2] - boxcenter.z);
3393
+ // box UV
3394
+ double x = positions[i3] - minima.x; // - Math.floor(positions[i3]);
3395
+ double y = positions[i3+1] - minima.y; // - Math.floor(positions[i3+1]);
3396
+ double z = positions[i3+2] - minima.z; // - Math.floor(positions[i3+2]);
3397
+
3398
+ // [-1/2, 1/2]
3399
+ x /= maxima.x - minima.x;
3400
+ y /= maxima.y - minima.y;
3401
+ z /= maxima.z - minima.z;
3402
+
3403
+ x -= 0.5;
3404
+ y -= 0.5;
3405
+ z -= 0.5;
3406
+
31963407 // x *= 2;
31973408 // y *= 2;
31983409 // z *= 2;
....@@ -3219,6 +3430,15 @@
32193430
32203431 z = Math.cos(angle/2);
32213432
3433
+ assert(z >= 0);
3434
+ assert(z <= 1);
3435
+
3436
+ /**/
3437
+ //z = Math.pow(z, power); //1.08f);
3438
+
3439
+ if (i == 0)
3440
+ System.out.println("power = " + power);
3441
+
32223442 // sqrt(k2*x2 + k2*z2 + y2) = length
32233443 // k2*x2 + k2*z2 = length2 - y2
32243444 // k2 = (length2 - y2) / (x2 + z2)
....@@ -3229,7 +3449,7 @@
32293449 k /= x*x + y*y;
32303450 }
32313451 else
3232
- GraphreeD.Assert(z == 1);
3452
+ Grafreed.Assert(z == 1);
32333453
32343454 if (k < 0)
32353455 k = 0;
....@@ -3238,6 +3458,7 @@
32383458
32393459 x *= k;
32403460 y *= k;
3461
+ /**/
32413462
32423463 double max = Math.abs(x);
32433464 if (max < Math.abs(y))
....@@ -3250,10 +3471,15 @@
32503471 }
32513472
32523473 // max = Math.sqrt(max*2)/2;
3474
+// double x2 = Math.pow(Math.abs(x), 1/power);
3475
+// double y2 = Math.pow(Math.abs(y), 1/power);
3476
+// double z2 = Math.pow(Math.abs(z), 1/power);
3477
+// max = Math.pow(x2 + y2 + z2, power);
32533478
32543479 // if (!(max > 0))
3255
- assert(max > 0);
3256
-
3480
+ //assert(max > 0);
3481
+ assert(max >= 0);
3482
+
32573483 x /= max;
32583484 y /= max;
32593485 z /= max;
....@@ -3516,6 +3742,114 @@
35163742 */
35173743 }
35183744
3745
+ void GenerateNormals2(boolean crease)
3746
+ {
3747
+ cVector tempVector = new cVector();
3748
+
3749
+// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>();
3750
+//
3751
+//
3752
+// for (int i=0; i<this.VertexCount(); i++)
3753
+// {
3754
+// Vertex v = this.GetVertex(i);
3755
+//
3756
+// tempVector.set(v);
3757
+//
3758
+// cVector n = tableBase.get(tempVector.ToFloat());
3759
+//
3760
+// if (n != null)
3761
+// {
3762
+// continue;
3763
+// }
3764
+//
3765
+// tableBase.put(new cVector(tempVector), new cVector(v.norm));
3766
+// }
3767
+
3768
+ BoundaryRep tempSupport = this.support;
3769
+
3770
+ this.support = null;
3771
+
3772
+ BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this);
3773
+
3774
+ this.support = tempSupport;
3775
+
3776
+ //tempRep.Unstripify();
3777
+
3778
+ tempRep.GenerateNormals(crease);
3779
+
3780
+ boolean keepnormal = Vertex.normalmode;
3781
+ boolean epsequal = Grafreed.epsequal;
3782
+
3783
+ Vertex.normalmode = false;
3784
+ Grafreed.epsequal = false; // A bit strange
3785
+
3786
+ // No need to have a match for vertex counts.
3787
+
3788
+ java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>();
3789
+
3790
+ for (int i=0; i<tempRep.VertexCount(); i++)
3791
+ {
3792
+ Vertex v = tempRep.GetVertex(i);
3793
+
3794
+ cVector n = table.get(tempVector.ToFloat());
3795
+
3796
+ if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0)
3797
+ {
3798
+ //continue;
3799
+ }
3800
+
3801
+ tempVector.set(v);
3802
+
3803
+ //cVector nBase = tableBase.get(tempVector);
3804
+
3805
+ //if (v.norm.dot(nBase) < 0.9)
3806
+ //{
3807
+ // continue;
3808
+ //}
3809
+
3810
+ if (n != null && n.x == 1 && n.y == 0 && n.z == 0)
3811
+ {
3812
+ //continue;
3813
+ }
3814
+
3815
+ if (n != null)
3816
+ {
3817
+// if (n.dot(v.norm) < 0)
3818
+// n.sub(v.norm);
3819
+// else
3820
+// n.add(v.norm);
3821
+//
3822
+// n.normalize();
3823
+ continue;
3824
+ }
3825
+
3826
+ table.put(new cVector(tempVector), new cVector(v.norm));
3827
+ }
3828
+
3829
+ for (int i=0; i<this.VertexCount(); i++)
3830
+ {
3831
+ Vertex v = this.GetVertex(i);
3832
+
3833
+ tempVector.set(v);
3834
+
3835
+ cVector n = table.get(tempVector.ToFloat());
3836
+
3837
+ //if (n.dot(v.norm) < 0)
3838
+ if (n == null)
3839
+ continue;
3840
+
3841
+ if (v.norm == null)
3842
+ v.norm = new cVector();
3843
+
3844
+ LA.vecCopy(n, v.norm);
3845
+
3846
+ this.SetVertex(v, i);
3847
+ }
3848
+
3849
+ Grafreed.epsequal = epsequal;
3850
+ Vertex.normalmode = keepnormal;
3851
+ }
3852
+
35193853 void GenerateNormals(boolean crease)
35203854 {
35213855 boolean wastrim = trimmed;
....@@ -3531,7 +3865,29 @@
35313865 e.printStackTrace();
35323866 }
35333867
3534
- Trim(wastrim,true,crease,wasstrip,false);
3868
+ Trim(true/*wastrim*/,true,crease,wasstrip,false);
3869
+ }
3870
+
3871
+ void GenerateNormalsMesh()
3872
+ {
3873
+ if (stripified)
3874
+ {
3875
+ Unstripify();
3876
+ }
3877
+
3878
+ if (trimmed)
3879
+ {
3880
+ normals = null;
3881
+ }
3882
+ else
3883
+ {
3884
+ for (int i=VertexCount(); --i>=0;)
3885
+ {
3886
+ Vertex v = GetVertex(i);
3887
+
3888
+ v.norm = null;
3889
+ }
3890
+ }
35353891 }
35363892
35373893 void GenNormalsJME()
....@@ -3656,7 +4012,7 @@
36564012 NormalGenerator ng;
36574013
36584014 if (crease)
3659
- ng = new NormalGenerator(Math.PI/6); // default is 44 degrees (or Math.PI/3); // /4);
4015
+ ng = new NormalGenerator(Math.PI/4); // default is 44 degrees (or Math.PI/3); // /4);
36604016 else
36614017 ng = new NormalGenerator(Math.PI); // (Math.PI / 3); // /4);
36624018
....@@ -3674,8 +4030,6 @@
36744030 //System.out.println("NEW = " + positions.length);
36754031 uvmap = new float[ta.getVertexCount() * 2];
36764032
3677
- colors = new float[ta.getVertexCount()]; // * 3];
3678
-
36794033 ta.getCoordinates(0, positions);
36804034 ta.getNormals(0, normals);
36814035 // ta.getColors(0, colors);
....@@ -3683,12 +4037,24 @@
36834037
36844038 System.out.println("UV = " + uvmap[2] + ", " + uvmap[3] + ";");
36854039
4040
+ colors = null;
4041
+// colors = new float[ta.getVertexCount()]; // * 3];
4042
+//
4043
+// for (int i=colors.length; --i>=0;)
4044
+// {
4045
+// colors[i] = 1;
4046
+// }
4047
+
36864048 triangles = new int[ta.getVertexCount()];
36874049
36884050 for (int i = 0; i < triangles.length; i++)
36894051 {
36904052 triangles[i] = i;
36914053 }
4054
+
4055
+// Untrim();
4056
+ if (!trimmed)
4057
+ MergeNormals();
36924058 }
36934059 }
36944060
....@@ -3716,12 +4082,18 @@
37164082 positions = new float[3 * ga.getVertexCount()];
37174083 normals = new float[3 * ga.getVertexCount()];
37184084 uvmap = new float[2 * ga.getVertexCount()];
3719
- colors = new float[1 * ga.getVertexCount()];
37204085
37214086 tsa.getCoordinates(0, positions);
37224087 tsa.getNormals(0, normals);
37234088 tsa.getTextureCoordinates(0, 0, uvmap);
37244089 // tsa.getColors(0, colors);
4090
+
4091
+ colors = null;
4092
+// colors = new float[1 * ga.getVertexCount()];
4093
+// for (int i=colors.length; --i>=0;)
4094
+// {
4095
+// colors[i] = 1;
4096
+// }
37254097
37264098 int stripcount = tsa.getNumStrips();
37274099 triangles = new int[stripcount];
....@@ -3730,6 +4102,7 @@
37304102 stripified = true;
37314103 } catch (ClassCastException e)
37324104 {
4105
+ // ??? aug 2019
37334106 TriangleArray ta = (TriangleArray) ga;
37344107
37354108 positions = new float[3 * ga.getVertexCount()];
....@@ -3744,6 +4117,10 @@
37444117 triangles = new int[1];
37454118 triangles[0] = 3;
37464119 }
4120
+
4121
+ //Untrim();
4122
+ if (!trimmed)
4123
+ MergeNormals();
37474124 }
37484125
37494126 /*
....@@ -3776,21 +4153,66 @@
37764153 for (int i = 0; i < VertexCount(); i++)
37774154 {
37784155 Vertex v = GetVertex(i);
4156
+
4157
+ vertextemp.set(v);
4158
+
37794159 //if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
37804160 {
3781
- GenerateNormal(i, v);
3782
- SetVertex(v, i);
4161
+ if (!GenerateNormal(i, vertextemp))
4162
+ continue;
4163
+
4164
+ if (v.norm.dot(vertextemp.norm) < 0)
4165
+ vertextemp.norm.mul(-1);
4166
+
4167
+ if (v.norm.dot(vertextemp.norm) < 0.9)
4168
+ SetVertex(vertextemp, i);
37834169 }
37844170 }
37854171
37864172 Vertex.normalmode = false;
37874173 }
37884174
4175
+ void MergeNormals()
4176
+ {
4177
+ assert(!trimmed);
4178
+
4179
+ boolean smooth = Grafreed.smoothmode;
4180
+ boolean link = Grafreed.linkUV;
4181
+ Grafreed.smoothmode = true;
4182
+ Grafreed.linkUV = true;
4183
+
4184
+ System.out.println("#Vertex = " + VertexCount());
4185
+ System.out.println("#Face = " + FaceCount());
4186
+
4187
+ java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>();
4188
+
4189
+ for (int i = 0; i < VertexCount(); i++)
4190
+ {
4191
+ Vertex v = GetVertex(i);
4192
+
4193
+ if (!table.contains(v))
4194
+ {
4195
+ table.add(v);
4196
+ }
4197
+ }
4198
+
4199
+ Grafreed.smoothmode = smooth;
4200
+ Grafreed.linkUV = link;
4201
+
4202
+// for (int i = 0; i < VertexCount(); i++)
4203
+// {
4204
+// Vertex v = GetVertex(i);
4205
+//
4206
+// table.add(v);
4207
+// }
4208
+
4209
+ }
4210
+
37894211 static cVector temp1 = new cVector();
37904212 static cVector temp2 = new cVector();
37914213 static cVector temp3 = new cVector();
37924214
3793
- void GenerateNormal(int index, Vertex v)
4215
+ boolean GenerateNormal(int index, Vertex v)
37944216 {
37954217 //System.out.println("Old normal = " + v.norm);
37964218 LA.setVector(v.norm, 0, 0, 0);
....@@ -3819,6 +4241,10 @@
38194241 LA.vecSub(p/*.pos*/, v/*.pos*/, temp1);
38204242 LA.vecSub(q/*.pos*/, v/*.pos*/, temp2);
38214243 }
4244
+ else
4245
+ {
4246
+ continue;
4247
+ }
38224248
38234249 //LA.vecNormalize(temp1);
38244250 //LA.vecNormalize(temp2);
....@@ -3829,17 +4255,25 @@
38294255 double s = temp3.length();
38304256 //double c = temp2.dot(temp1);
38314257
4258
+ if (s == 0)
4259
+ return false;
4260
+
38324261 float angle = 1; // (float) Math.atan2(s, c);
38334262 //if(angle < 0) angle = -angle;
38344263
38354264 //LA.vecNormalize(temp3);
38364265 LA.vecScale(temp3, angle / s);
38374266
4267
+// if (temp3.dot(v.norm) < 0)
4268
+// assert(temp3.dot(v.norm) >= 0);
4269
+
38384270 LA.vecAdd(temp3, v.norm, v.norm);
38394271 }
38404272
38414273 LA.vecNormalize(v.norm);
38424274 //System.out.println("New normal = " + v.norm);
4275
+
4276
+ return true;
38434277 }
38444278
38454279 double Arccos(double x)
....@@ -4233,7 +4667,7 @@
42334667 int count = VertexCount();
42344668
42354669 // mars 2014
4236
- while (step >= count)
4670
+ while (step > count)
42374671 step /= 10;
42384672
42394673 for (int i = 0; i < count; i+=step)
....@@ -4381,7 +4815,7 @@
43814815 }
43824816 }
43834817
4384
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4818
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
43854819 {
43864820 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
43874821 CameraPane.tempmat,0, CameraPane.tempmat2,0,
....@@ -4413,14 +4847,14 @@
44134847 // june 2014
44144848 // Camera parentcam = cam;
44154849 //
4416
-// if (cam == CameraPane.theRenderer.cameras[0])
4850
+// if (cam == Globals.theRenderer.cameras[0])
44174851 // {
4418
-// parentcam = CameraPane.theRenderer.cameras[1];
4852
+// parentcam = Globals.theRenderer.cameras[1];
44194853 // }
44204854 //
4421
-// if (cam == CameraPane.theRenderer.cameras[1])
4855
+// if (cam == Globals.theRenderer.cameras[1])
44224856 // {
4423
-// parentcam = CameraPane.theRenderer.cameras[0];
4857
+// parentcam = Globals.theRenderer.cameras[0];
44244858 // }
44254859
44264860 gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0);
....@@ -4546,16 +4980,25 @@
45464980 {
45474981 i3 = positions.length-3;
45484982 i2 = uvmap.length - 2;
4549
- new Exception().printStackTrace();
4983
+ //new Exception().printStackTrace();
45504984 }
45514985
45524986 v./*pos.*/x = positions[i3];
45534987 v./*pos.*/y = positions[i3 + 1];
45544988 v./*pos.*/z = positions[i3 + 2];
45554989
4556
- v.norm.x = normals[i3];
4557
- v.norm.y = normals[i3 + 1];
4558
- v.norm.z = normals[i3 + 2];
4990
+ if (normals == null)
4991
+ {
4992
+ v.norm.x = 0;
4993
+ v.norm.y = 0;
4994
+ v.norm.z = 0;
4995
+ }
4996
+ else
4997
+ {
4998
+ v.norm.x = normals[i3];
4999
+ v.norm.y = normals[i3 + 1];
5000
+ v.norm.z = normals[i3 + 2];
5001
+ }
45595002
45605003 v.s = uvmap[i2];
45615004 v.t = uvmap[i2 + 1];
....@@ -4846,7 +5289,7 @@
48465289 return verticesCopy;
48475290 }
48485291
4849
- void PreprocessOcclusion(CameraPane cp, double[][] transform)
5292
+ void PreprocessOcclusion(iCameraPane cp, double[][] transform)
48505293 {
48515294 if (//!trimmed ||
48525295 AOdone)
....@@ -4855,80 +5298,7 @@
48555298 return;
48565299 }
48575300
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;
5301
+ cp.PrepOcclusion(this, transform);
49325302
49335303 AOdone = true;
49345304 }
....@@ -5036,6 +5406,59 @@
50365406 }
50375407 }
50385408 colors = null;
5409
+ }
5410
+
5411
+ void CreateMesh(iHeightField hf, int x, int y)
5412
+ {
5413
+ BoundaryRep tmp = new BoundaryRep();
5414
+
5415
+ int vc = 0;
5416
+
5417
+ Vertex v = new Vertex(true);
5418
+
5419
+ for (int i=0; i<x; i++)
5420
+ {
5421
+ for (int j=0; j<y; j++)
5422
+ {
5423
+// Vertex v = tmp.GetVertex(vc++);
5424
+
5425
+ v.s = v.x = i;
5426
+ v.t = v.z = j;
5427
+ v.s /= x; v.t /= y;
5428
+ v.y = hf.f(i,j);
5429
+
5430
+ int iu = tmp.AddTableVertex(v);
5431
+
5432
+ v.s = v.x = i+1;
5433
+ v.t = v.z = j;
5434
+ v.s /= x; v.t /= y;
5435
+ v.y = hf.f(i+1,j);
5436
+
5437
+ int iv = tmp.AddTableVertex(v);
5438
+
5439
+ v.s = v.x = i+1;
5440
+ v.t = v.z = j+1;
5441
+ v.s /= x; v.t /= y;
5442
+ v.y = hf.f(i+1,j+1);
5443
+
5444
+ int iw = tmp.AddTableVertex(v);
5445
+
5446
+ v.s = v.x = i;
5447
+ v.t = v.z = j+1;
5448
+ v.s /= x; v.t /= y;
5449
+ v.y = hf.f(i,j+1);
5450
+
5451
+ int ix = tmp.AddTableVertex(v);
5452
+
5453
+ tmp.AddFace(iu,iw,iv);
5454
+ tmp.AddFace(iu,ix,iw);
5455
+ }
5456
+ }
5457
+
5458
+ Set(tmp);
5459
+
5460
+ Trim(true,false,true);
5461
+ ClearColors();
50395462 }
50405463
50415464 void Stripify()
....@@ -5290,25 +5713,27 @@
52905713
52915714 transient int nbbadfaces; // ?? = 1000000;
52925715
5293
- int ChooseTriangle()
5716
+ /*
5717
+ */
5718
+ int ChooseTriangle(boolean firstEquilateral)
52945719 {
52955720 int chosen = -1;
52965721
52975722 double minweight = 1E10;
52985723
5724
+ int step = 8; // ?
5725
+
5726
+ if (firstEquilateral)
5727
+ step = 1;
5728
+
52995729 nbbadfaces = 0;
5300
- for (int i=faces.size(); (i-=8)>=0;)
5730
+ for (int i=0; i<faces.size(); i+=step)
5731
+// for (int i=faces.size(); (i-=8)>=0;)
53015732 {
53025733 Face face = (Face) faces.get(i);
53035734
5304
- //?? if (face.weight < 0)
5305
- // continue;
5306
-
5307
- double K = 1; // 0.01; // .25;
5308
-
5309
- double factor = (1-K)*face.nbiterations + K; //*face.weight;
5310
-
5311
- double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5735
+ if (face.used)
5736
+ continue;
53125737
53135738 if (!Valid(face))
53145739 {
....@@ -5319,6 +5744,15 @@
53195744 if (Boundary(face))
53205745 continue;
53215746
5747
+// if (Boundary(face.p))
5748
+// continue;
5749
+//
5750
+// if (Boundary(face.q))
5751
+// continue;
5752
+//
5753
+// if (Boundary(face.r))
5754
+// continue;
5755
+
53225756 if (!ValidValence(face))
53235757 continue;
53245758
....@@ -5327,14 +5761,58 @@
53275761 !ValidValence(face.r))
53285762 continue;
53295763
5330
- if (minweight > weight)
5764
+ //?? if (face.weight < 0)
5765
+ // continue;
5766
+
5767
+ if (firstEquilateral)
53315768 {
5332
- minweight = weight;
5769
+ if (OneFaceUsed(links.get(face.p)))
5770
+ continue;
5771
+
5772
+ if (OneFaceUsed(links.get(face.q)))
5773
+ continue;
5774
+
5775
+ if (OneFaceUsed(links.get(face.r)))
5776
+ continue;
5777
+
53335778 chosen = i;
5779
+ break;
5780
+ }
5781
+ else
5782
+ {
5783
+ double K = 1; // 0.01; // .25;
5784
+
5785
+ double factor = (1-K)*face.nbiterations + K; //*face.weight;
5786
+
5787
+ double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5788
+
5789
+ if (minweight > weight)
5790
+ {
5791
+ minweight = weight;
5792
+ chosen = i;
5793
+ if (minweight == 0)
5794
+ break;
5795
+ }
53345796 }
53355797 }
53365798
53375799 return chosen;
5800
+ }
5801
+
5802
+ private boolean OneFaceUsed(Vector<Face> faces)
5803
+ {
5804
+ if (faces.size() != 6)
5805
+ return true;
5806
+
5807
+ for (int i=0; i<6; i+=1)
5808
+ {
5809
+ if (faces.get(i).used)
5810
+ {
5811
+ return true;
5812
+ }
5813
+ }
5814
+
5815
+ return false;
53385816 }
53395817
53405818 static boolean remove3valence = true;
....@@ -5370,7 +5848,7 @@
53705848 }
53715849 else
53725850 {
5373
- assert(links.size() == vertices.size());
5851
+ // TODO Grafreed.Assert(links.size() == vertices.size());
53745852
53755853 links.setSize(vertices.size());
53765854 for (int i=vertices.size(); --i>=0;)
....@@ -5378,6 +5856,7 @@
53785856 // linkstouched[i] = false;
53795857 if (links.get(i) == null) // ??
53805858 {
5859
+ new Exception().printStackTrace();
53815860 links.set(i, new Vector(8));
53825861 // linkstouched[i] = true;
53835862 }
....@@ -5388,6 +5867,8 @@
53885867 }
53895868 }
53905869
5870
+ boolean once = false;
5871
+
53915872 for (int i=faces.size(); --i>=0;)
53925873 {
53935874 Face face = (Face) faces.get(i);
....@@ -5399,6 +5880,9 @@
53995880 //if (linkstouched[face.r])
54005881 links.get(face.r).add(face);
54015882
5883
+ if (face.used)
5884
+ once = true;
5885
+
54025886 face.good = 1;
54035887 face.boundary = -1;
54045888 }
....@@ -6170,6 +6654,7 @@
61706654
61716655 void InitWeights()
61726656 {
6657
+ new Exception().printStackTrace();
61736658 System.exit(0);
61746659 int n = 0;
61756660 int b = 0;
....@@ -6763,6 +7248,10 @@
67637248 return (face.boundary = 1) == 1;
67647249 }
67657250
7251
+ // June 2019
7252
+ if (true)
7253
+ return (face.boundary = 0) == 1;
7254
+
67667255 // reverse triangle test
67677256 q1.set(p);
67687257 q2.set(q);
....@@ -7019,6 +7508,7 @@
70197508 assert(f2.contains(i));
70207509 assert(f3.contains(i));
70217510
7511
+ // when r is the "center", p is along the boundary
70227512 while (f0.r != i)
70237513 {
70247514 int t = f0.p;
....@@ -7075,59 +7565,90 @@
70757565 f0 = f3;
70767566 f3 = t;
70777567 }
7078
- atleastone = true;
70797568
7569
+ int va = f0.q;
7570
+ int vb = f0.r;
7571
+ int vc = -1;
7572
+
7573
+ Face toremove1 = null;
7574
+ Face toremove2 = null;
7575
+
7576
+ // f0 is the buffer for the first new triangle,
7577
+ // and otherf is the other upper one.
70807578 Face otherf = null;
70817579
70827580 if (f1.contains(f0.p))
70837581 {
70847582 if (f1.p == f0.p)
70857583 {
7584
+ assert(false);
70867585 f0.r = f1.q;
70877586 }
70887587 else
70897588 {
70907589 assert(f1.q == f0.p);
7091
- f0.r = f1.p;
7590
+ vc = f1.p;
70927591 }
70937592
70947593 otherf = f2;
7095
- faces.remove(f1);
7096
- faces.remove(f3);
7594
+ toremove1 = f1;
7595
+ toremove2 = f3;
70977596 }
70987597 else
70997598 if (f2.contains(f0.p))
71007599 {
71017600 if (f2.p == f0.p)
71027601 {
7602
+ assert(false);
71037603 f0.r = f2.q;
71047604 }
71057605 else
71067606 {
71077607 assert(f2.q == f0.p);
7108
- f0.r = f2.p;
7608
+ vc = f2.p;
71097609 }
71107610
71117611 otherf = f3;
7112
- faces.remove(f1);
7113
- faces.remove(f2);
7612
+ toremove1 = f1;
7613
+ toremove2 = f2;
71147614 }
71157615 if (f3.contains(f0.p))
71167616 {
71177617 if (f3.p == f0.p)
71187618 {
7619
+// assert(false);
7620
+ new Exception().printStackTrace();
71197621 f0.r = f3.q;
71207622 }
71217623 else
71227624 {
71237625 assert(f3.q == f0.p);
7124
- f0.r = f3.p;
7626
+ vc = f3.p;
71257627 }
71267628
71277629 otherf = f1;
7128
- faces.remove(f2);
7129
- faces.remove(f3);
7630
+ toremove1 = f2;
7631
+ toremove2 = f3;
71307632 }
7633
+
7634
+ vertextemp.set(vertices.get(va));
7635
+ vertextemp.sub(vertices.get(vb));
7636
+ vertextemp.normalize();
7637
+ vertextemp2.set(vertices.get(vc));
7638
+ vertextemp2.sub(vertices.get(vb));
7639
+ vertextemp2.normalize();
7640
+
7641
+ if (vertextemp.dot(vertextemp2) > -0.95)
7642
+ {
7643
+ continue;
7644
+ }
7645
+
7646
+ atleastone = true;
7647
+
7648
+ f0.r = vc;
7649
+
7650
+ faces.remove(toremove1);
7651
+ faces.remove(toremove2);
71317652
71327653 if (!f0.contains(otherf.p))
71337654 {
....@@ -7180,7 +7701,7 @@
71807701 //InitWeights();
71817702 }
71827703
7183
- int chosen = ChooseTriangle(); // Best is slow and not really better
7704
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
71847705
71857706 if (chosen == -1)
71867707 {
....@@ -7194,7 +7715,7 @@
71947715 //remove3valence = false;
71957716 // InitWeights();
71967717
7197
- chosen = ChooseTriangle();
7718
+ chosen = ChooseTriangle(true);
71987719 }
71997720 }
72007721
....@@ -7335,7 +7856,7 @@
73357856 Trim();
73367857 Untrim();
73377858
7338
- BoundaryRep tmp = new BoundaryRep(); // (BoundaryRep) GraphreeD.clone(this);
7859
+ BoundaryRep tmp = new BoundaryRep(); // (BoundaryRep) GrafreeD.clone(this);
73397860
73407861 double minx = Float.POSITIVE_INFINITY;
73417862 double maxx = Float.NEGATIVE_INFINITY;
....@@ -7373,7 +7894,7 @@
73737894 if (max < maxz - minz)
73747895 max = maxz - minz;
73757896
7376
- tmp.THRESHOLD = max/25; // 50;
7897
+ tmp.THRESHOLD = 0.5; // max/25; // 50;
73777898
73787899 tmp.faces.clear();
73797900
....@@ -7470,7 +7991,7 @@
74707991
74717992 // boolean lock;
74727993
7473
- void SplitInTwo(boolean reduction34, boolean onlyone)
7994
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
74747995 {
74757996 if (stripified)
74767997 {
....@@ -7498,7 +8019,7 @@
74988019 s3 = new cVector();
74998020 }
75008021
7501
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
8022
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
75028023
75038024 try
75048025 {
....@@ -7507,12 +8028,12 @@
75078028 {
75088029 System.err.println("EXCEPTION CAUGHT");
75098030 e.printStackTrace();
7510
- return;
8031
+ return false;
75118032 } catch (Error e)
75128033 {
75138034 System.err.println("ERROR CAUGHT");
75148035 e.printStackTrace();
7515
- return;
8036
+ return false;
75168037 }
75178038
75188039 System.out.println("# faces = " + faces.size());
....@@ -7522,6 +8043,7 @@
75228043 {
75238044 Face face = (Face) faces.get(i);
75248045
8046
+ face.used = false;
75258047 face.nbiterations = 1;
75268048 face.weight = -1;
75278049 face.boundary = -1;
....@@ -7573,6 +8095,11 @@
75738095 nbbadfaces = faces.size();
75748096 //remove3valence = true;
75758097
8098
+ int count = 2;
8099
+
8100
+ if (onlyone)
8101
+ count = 1;
8102
+
75768103 firstpass = true;
75778104
75788105 int n = faces.size();
....@@ -7588,12 +8115,13 @@
75888115 System.out.print('.');
75898116 }
75908117 System.out.println();
8118
+ boolean atleastone = false;
75918119 int i = 0;
7592
- while (reduction34 || faces.size() > n/2)
8120
+ while (true) // reduction34 || faces.size() > n/2)
75938121 {
75948122 if (i++%100 == 0)
75958123 {
7596
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
8124
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
75978125 System.out.println("#faces = " + faces.size());
75988126 // if (i != 1)
75998127 // break;
....@@ -7611,6 +8139,8 @@
76118139 {
76128140 if (!RemoveOneTriangle())
76138141 break;
8142
+
8143
+ atleastone = true;
76148144 }
76158145 // if (iterationcount == 0)
76168146 // break;
....@@ -7621,8 +8151,8 @@
76218151 break;
76228152 }
76238153 firstpass = false;
7624
- if (onlyone)
7625
- break; // one triangle only
8154
+// if (--count<0 && !reduction34)
8155
+// break; // one triangle only
76268156 }
76278157
76288158 InitLinks(false); // for further display
....@@ -7637,7 +8167,9 @@
76378167 //Trim(true,cJME.gennormals,true,false); // doesn't work
76388168 Trim(true,false,false,false,false);
76398169
7640
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8170
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8171
+
8172
+ return atleastone;
76418173 }
76428174
76438175 void UpdateIndices(Face face, Face minface)
....@@ -7650,18 +8182,21 @@
76508182 face.p = minface.p;
76518183 //if (leafweights)
76528184 face.good = 0; // false;
8185
+ face.used = true;
76538186 }
76548187 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
76558188 {
76568189 face.q = minface.p;
76578190 //if (leafweights)
76588191 face.good = 0; // false;
8192
+ face.used = true;
76598193 }
76608194 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
76618195 {
76628196 face.r = minface.p;
76638197 //if (leafweights)
76648198 face.good = 0; // false;
8199
+ face.used = true;
76658200 }
76668201
76678202 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7721,50 +8256,50 @@
77218256 if (v == 2)
77228257 vert = minface.r;
77238258 // Face face = (Face) faces.get(i);
7724
- Vector<Face> vertfaces = links.get(vert);
7725
- for (int i=vertfaces.size(); --i>=0;)
7726
- {
7727
- Face face = (Face) vertfaces.get(i);
7728
-
7729
- // if (face.weight == 10000)
7730
- // continue;
7731
-
7732
- if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
7733
- face.p == minface.q || face.q == minface.q || face.r == minface.q ||
7734
- face.p == minface.r || face.q == minface.r || face.r == minface.r)
8259
+ Vector<Face> vertfaces = links.get(vert);
8260
+ for (int i=vertfaces.size(); --i>=0;)
77358261 {
7736
- if (!leafweights)
8262
+ Face face = (Face) vertfaces.get(i);
8263
+
8264
+ // if (face.weight == 10000)
8265
+ // continue;
8266
+
8267
+ if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
8268
+ face.p == minface.q || face.q == minface.q || face.r == minface.q ||
8269
+ face.p == minface.r || face.q == minface.r || face.r == minface.r)
77378270 {
7738
-// if(minfaceweight <= 0)
7739
-// assert(minfaceweight > 0);
7740
-//
7741
-// //FaceWeight(face);
7742
-// if(face.weight < 0)
7743
-// assert(face.weight >= 0);
7744
-
7745
- face.weight += minfaceweight;
7746
-
7747
-// if (face.weight >= 10000)
7748
-// assert(face.weight < 10000);
8271
+ if (!leafweights)
8272
+ {
8273
+ // if(minfaceweight <= 0)
8274
+ // assert(minfaceweight > 0);
8275
+ //
8276
+ // //FaceWeight(face);
8277
+ // if(face.weight < 0)
8278
+ // assert(face.weight >= 0);
8279
+
8280
+ face.weight += minfaceweight;
8281
+
8282
+ // if (face.weight >= 10000)
8283
+ // assert(face.weight < 10000);
8284
+ }
8285
+ else
8286
+ face.weight = -1;
8287
+
8288
+ face.nbiterations += 1;
8289
+ face.boundary = -1;
8290
+
8291
+ Vertex p = (Vertex)vertices.get(face.p);
8292
+ Vertex q = (Vertex)vertices.get(face.q);
8293
+ Vertex r = (Vertex)vertices.get(face.r);
8294
+
8295
+ p.boundary = -1;
8296
+ q.boundary = -1;
8297
+ r.boundary = -1;
77498298 }
77508299 else
7751
- face.weight = -1;
7752
-
7753
- face.nbiterations += 1;
7754
- face.boundary = -1;
7755
-
7756
- Vertex p = (Vertex)vertices.get(face.p);
7757
- Vertex q = (Vertex)vertices.get(face.q);
7758
- Vertex r = (Vertex)vertices.get(face.r);
7759
-
7760
- p.boundary = -1;
7761
- q.boundary = -1;
7762
- r.boundary = -1;
8300
+ assert(false);
77638301 }
7764
- else
7765
- assert(false);
77668302 }
7767
- }
77688303
77698304 // TouchVertex(minface.p);
77708305 // TouchVertex(minface.q);
....@@ -7932,6 +8467,8 @@
79328467
79338468 minface.q = minface.r = minface.p;
79348469
8470
+ int count = 0;
8471
+
79358472 for (int i=0; i<faces.size(); i++)
79368473 {
79378474 Face face = (Face) faces.get(i);
....@@ -7943,6 +8480,9 @@
79438480 TouchVertex(face.r, true); // , minface.weight);
79448481 // assert(!lock);
79458482 faces.remove(i--);
8483
+ count++;
8484
+ if (count == 4)
8485
+ break;
79468486 }
79478487 }
79488488
....@@ -7960,6 +8500,7 @@
79608500 for (int i=vertfaces.size(); --i>=0;)
79618501 {
79628502 Face face = (Face) vertfaces.get(i);
8503
+ face.used = true;
79638504 face.good = 0; // false;
79648505 if (leafweights)
79658506 face.weight = -1;
....@@ -8006,7 +8547,7 @@
80068547 if (!trimmed)
80078548 return;
80088549
8009
- GraphreeD.linkUV = false;
8550
+ Grafreed.linkUV = false;
80108551
80118552 try
80128553 {
....@@ -8214,9 +8755,6 @@
82148755 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
82158756 }
82168757
8217
- static Camera localcamera = new Camera();
8218
- static cVector from = new cVector();
8219
- static cVector to = new cVector();
82208758 boolean trimmed = false;
82218759 boolean stripified = false;
82228760 transient boolean AOdone = false;
....@@ -8224,8 +8762,10 @@
82248762 /*transient*/ int maxIndexV = 0;
82258763 /*transient*/ int bufV, bufF;
82268764 // Raw version
8227
- private float[] positions;
8228
- private float[] normals;
8765
+ //private
8766
+ float[] positions;
8767
+ //private
8768
+ float[] normals;
82298769 float[] colors;
82308770 private float[] uvmap;
82318771 private int[] triangles;
....@@ -8239,7 +8779,8 @@
82398779 int[] startvertices;
82408780 float[] averagepoints;
82418781 float[] extremepoints;
8242
- float[] supportsizes; // distance of closest point
8782
+ float[] supportminsize; // distance of closest point
8783
+ float[] supportmaxsize; // distance of fartest point
82438784
82448785 transient Hashtable vertextable;
82458786 /*transient*/ private Vertex[] verticesCopy;