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[]) 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);
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[]) GraphreeD.clone(other.indices);
182
+ indices = (int[]) Grafreed.clone(other.indices);
182183
183
- vertices = (Vector<Vertex>) GraphreeD.clone(other.vertices);
184
- faces = (Vector<Face>) GraphreeD.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) GraphreeD.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) GraphreeD.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;
....@@ -2163,7 +2227,7 @@
21632227 // if (slow)
21642228 // aout 2013
21652229 // sept 2013 merde...
2166
- W = 13;
2230
+ W = 3; // 13;
21672231
21682232 // POSERATE
21692233 if (CameraPane.tickcount > 0 || CameraPane.SLOWPOSE)
....@@ -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
....@@ -2600,7 +2670,7 @@
26002670 // if (stepout && !playedonce)
26012671 // {
26022672 // // sound
2603
-// GraphreeD.wav.play();
2673
+// GrafreeD.wav.play();
26042674 // playedonce = true;
26052675 // }
26062676 //
....@@ -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
- GraphreeD.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
- GraphreeD.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;
....@@ -3531,7 +3861,29 @@
35313861 e.printStackTrace();
35323862 }
35333863
3534
- Trim(wastrim,true,crease,wasstrip,false);
3864
+ 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)
....@@ -4233,7 +4663,7 @@
42334663 int count = VertexCount();
42344664
42354665 // mars 2014
4236
- while (step >= count)
4666
+ while (step > count)
42374667 step /= 10;
42384668
42394669 for (int i = 0; i < count; i+=step)
....@@ -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 }
....@@ -5036,6 +5402,59 @@
50365402 }
50375403 }
50385404 colors = null;
5405
+ }
5406
+
5407
+ void CreateMesh(iHeightField hf, int x, int y)
5408
+ {
5409
+ BoundaryRep tmp = new BoundaryRep();
5410
+
5411
+ int vc = 0;
5412
+
5413
+ Vertex v = new Vertex(true);
5414
+
5415
+ for (int i=0; i<x; i++)
5416
+ {
5417
+ for (int j=0; j<y; j++)
5418
+ {
5419
+// Vertex v = tmp.GetVertex(vc++);
5420
+
5421
+ v.s = v.x = i;
5422
+ v.t = v.z = j;
5423
+ v.s /= x; v.t /= y;
5424
+ v.y = hf.f(i,j);
5425
+
5426
+ int iu = tmp.AddTableVertex(v);
5427
+
5428
+ v.s = v.x = i+1;
5429
+ v.t = v.z = j;
5430
+ v.s /= x; v.t /= y;
5431
+ v.y = hf.f(i+1,j);
5432
+
5433
+ int iv = tmp.AddTableVertex(v);
5434
+
5435
+ v.s = v.x = i+1;
5436
+ v.t = v.z = j+1;
5437
+ v.s /= x; v.t /= y;
5438
+ v.y = hf.f(i+1,j+1);
5439
+
5440
+ int iw = tmp.AddTableVertex(v);
5441
+
5442
+ v.s = v.x = i;
5443
+ v.t = v.z = j+1;
5444
+ v.s /= x; v.t /= y;
5445
+ v.y = hf.f(i,j+1);
5446
+
5447
+ int ix = tmp.AddTableVertex(v);
5448
+
5449
+ tmp.AddFace(iu,iw,iv);
5450
+ tmp.AddFace(iu,ix,iw);
5451
+ }
5452
+ }
5453
+
5454
+ Set(tmp);
5455
+
5456
+ Trim(true,false,true);
5457
+ ClearColors();
50395458 }
50405459
50415460 void Stripify()
....@@ -5290,25 +5709,27 @@
52905709
52915710 transient int nbbadfaces; // ?? = 1000000;
52925711
5293
- int ChooseTriangle()
5712
+ /*
5713
+ */
5714
+ int ChooseTriangle(boolean firstEquilateral)
52945715 {
52955716 int chosen = -1;
52965717
52975718 double minweight = 1E10;
52985719
5720
+ int step = 8; // ?
5721
+
5722
+ if (firstEquilateral)
5723
+ step = 1;
5724
+
52995725 nbbadfaces = 0;
5300
- for (int i=faces.size(); (i-=8)>=0;)
5726
+ for (int i=0; i<faces.size(); i+=step)
5727
+// for (int i=faces.size(); (i-=8)>=0;)
53015728 {
53025729 Face face = (Face) faces.get(i);
53035730
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;
5731
+ if (face.used)
5732
+ continue;
53125733
53135734 if (!Valid(face))
53145735 {
....@@ -5319,6 +5740,15 @@
53195740 if (Boundary(face))
53205741 continue;
53215742
5743
+// if (Boundary(face.p))
5744
+// continue;
5745
+//
5746
+// if (Boundary(face.q))
5747
+// continue;
5748
+//
5749
+// if (Boundary(face.r))
5750
+// continue;
5751
+
53225752 if (!ValidValence(face))
53235753 continue;
53245754
....@@ -5327,14 +5757,58 @@
53275757 !ValidValence(face.r))
53285758 continue;
53295759
5330
- if (minweight > weight)
5760
+ //?? if (face.weight < 0)
5761
+ // continue;
5762
+
5763
+ if (firstEquilateral)
53315764 {
5332
- 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
+
53335774 chosen = i;
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
+ }
53345792 }
53355793 }
53365794
53375795 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;
53385812 }
53395813
53405814 static boolean remove3valence = true;
....@@ -5370,7 +5844,7 @@
53705844 }
53715845 else
53725846 {
5373
- assert(links.size() == vertices.size());
5847
+ // TODO Grafreed.Assert(links.size() == vertices.size());
53745848
53755849 links.setSize(vertices.size());
53765850 for (int i=vertices.size(); --i>=0;)
....@@ -5378,6 +5852,7 @@
53785852 // linkstouched[i] = false;
53795853 if (links.get(i) == null) // ??
53805854 {
5855
+ new Exception().printStackTrace();
53815856 links.set(i, new Vector(8));
53825857 // linkstouched[i] = true;
53835858 }
....@@ -5388,6 +5863,8 @@
53885863 }
53895864 }
53905865
5866
+ boolean once = false;
5867
+
53915868 for (int i=faces.size(); --i>=0;)
53925869 {
53935870 Face face = (Face) faces.get(i);
....@@ -5399,6 +5876,9 @@
53995876 //if (linkstouched[face.r])
54005877 links.get(face.r).add(face);
54015878
5879
+ if (face.used)
5880
+ once = true;
5881
+
54025882 face.good = 1;
54035883 face.boundary = -1;
54045884 }
....@@ -6170,6 +6650,7 @@
61706650
61716651 void InitWeights()
61726652 {
6653
+ new Exception().printStackTrace();
61736654 System.exit(0);
61746655 int n = 0;
61756656 int b = 0;
....@@ -6763,6 +7244,10 @@
67637244 return (face.boundary = 1) == 1;
67647245 }
67657246
7247
+ // June 2019
7248
+ if (true)
7249
+ return (face.boundary = 0) == 1;
7250
+
67667251 // reverse triangle test
67677252 q1.set(p);
67687253 q2.set(q);
....@@ -7019,6 +7504,7 @@
70197504 assert(f2.contains(i));
70207505 assert(f3.contains(i));
70217506
7507
+ // when r is the "center", p is along the boundary
70227508 while (f0.r != i)
70237509 {
70247510 int t = f0.p;
....@@ -7075,59 +7561,90 @@
70757561 f0 = f3;
70767562 f3 = t;
70777563 }
7078
- atleastone = true;
70797564
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.
70807574 Face otherf = null;
70817575
70827576 if (f1.contains(f0.p))
70837577 {
70847578 if (f1.p == f0.p)
70857579 {
7580
+ assert(false);
70867581 f0.r = f1.q;
70877582 }
70887583 else
70897584 {
70907585 assert(f1.q == f0.p);
7091
- f0.r = f1.p;
7586
+ vc = f1.p;
70927587 }
70937588
70947589 otherf = f2;
7095
- faces.remove(f1);
7096
- faces.remove(f3);
7590
+ toremove1 = f1;
7591
+ toremove2 = f3;
70977592 }
70987593 else
70997594 if (f2.contains(f0.p))
71007595 {
71017596 if (f2.p == f0.p)
71027597 {
7598
+ assert(false);
71037599 f0.r = f2.q;
71047600 }
71057601 else
71067602 {
71077603 assert(f2.q == f0.p);
7108
- f0.r = f2.p;
7604
+ vc = f2.p;
71097605 }
71107606
71117607 otherf = f3;
7112
- faces.remove(f1);
7113
- faces.remove(f2);
7608
+ toremove1 = f1;
7609
+ toremove2 = f2;
71147610 }
71157611 if (f3.contains(f0.p))
71167612 {
71177613 if (f3.p == f0.p)
71187614 {
7615
+// assert(false);
7616
+ new Exception().printStackTrace();
71197617 f0.r = f3.q;
71207618 }
71217619 else
71227620 {
71237621 assert(f3.q == f0.p);
7124
- f0.r = f3.p;
7622
+ vc = f3.p;
71257623 }
71267624
71277625 otherf = f1;
7128
- faces.remove(f2);
7129
- faces.remove(f3);
7626
+ toremove1 = f2;
7627
+ toremove2 = f3;
71307628 }
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);
71317648
71327649 if (!f0.contains(otherf.p))
71337650 {
....@@ -7180,7 +7697,7 @@
71807697 //InitWeights();
71817698 }
71827699
7183
- int chosen = ChooseTriangle(); // Best is slow and not really better
7700
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
71847701
71857702 if (chosen == -1)
71867703 {
....@@ -7194,7 +7711,7 @@
71947711 //remove3valence = false;
71957712 // InitWeights();
71967713
7197
- chosen = ChooseTriangle();
7714
+ chosen = ChooseTriangle(true);
71987715 }
71997716 }
72007717
....@@ -7335,7 +7852,7 @@
73357852 Trim();
73367853 Untrim();
73377854
7338
- BoundaryRep tmp = new BoundaryRep(); // (BoundaryRep) GraphreeD.clone(this);
7855
+ BoundaryRep tmp = new BoundaryRep(); // (BoundaryRep) GrafreeD.clone(this);
73397856
73407857 double minx = Float.POSITIVE_INFINITY;
73417858 double maxx = Float.NEGATIVE_INFINITY;
....@@ -7373,7 +7890,7 @@
73737890 if (max < maxz - minz)
73747891 max = maxz - minz;
73757892
7376
- tmp.THRESHOLD = max/25; // 50;
7893
+ tmp.THRESHOLD = 0.5; // max/25; // 50;
73777894
73787895 tmp.faces.clear();
73797896
....@@ -7470,7 +7987,7 @@
74707987
74717988 // boolean lock;
74727989
7473
- void SplitInTwo(boolean reduction34, boolean onlyone)
7990
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
74747991 {
74757992 if (stripified)
74767993 {
....@@ -7498,7 +8015,7 @@
74988015 s3 = new cVector();
74998016 }
75008017
7501
- 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));
75028019
75038020 try
75048021 {
....@@ -7507,12 +8024,12 @@
75078024 {
75088025 System.err.println("EXCEPTION CAUGHT");
75098026 e.printStackTrace();
7510
- return;
8027
+ return false;
75118028 } catch (Error e)
75128029 {
75138030 System.err.println("ERROR CAUGHT");
75148031 e.printStackTrace();
7515
- return;
8032
+ return false;
75168033 }
75178034
75188035 System.out.println("# faces = " + faces.size());
....@@ -7522,6 +8039,7 @@
75228039 {
75238040 Face face = (Face) faces.get(i);
75248041
8042
+ face.used = false;
75258043 face.nbiterations = 1;
75268044 face.weight = -1;
75278045 face.boundary = -1;
....@@ -7573,6 +8091,11 @@
75738091 nbbadfaces = faces.size();
75748092 //remove3valence = true;
75758093
8094
+ int count = 2;
8095
+
8096
+ if (onlyone)
8097
+ count = 1;
8098
+
75768099 firstpass = true;
75778100
75788101 int n = faces.size();
....@@ -7588,12 +8111,13 @@
75888111 System.out.print('.');
75898112 }
75908113 System.out.println();
8114
+ boolean atleastone = false;
75918115 int i = 0;
7592
- while (reduction34 || faces.size() > n/2)
8116
+ while (true) // reduction34 || faces.size() > n/2)
75938117 {
75948118 if (i++%100 == 0)
75958119 {
7596
- 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));
75978121 System.out.println("#faces = " + faces.size());
75988122 // if (i != 1)
75998123 // break;
....@@ -7611,6 +8135,8 @@
76118135 {
76128136 if (!RemoveOneTriangle())
76138137 break;
8138
+
8139
+ atleastone = true;
76148140 }
76158141 // if (iterationcount == 0)
76168142 // break;
....@@ -7621,8 +8147,8 @@
76218147 break;
76228148 }
76238149 firstpass = false;
7624
- if (onlyone)
7625
- break; // one triangle only
8150
+// if (--count<0 && !reduction34)
8151
+// break; // one triangle only
76268152 }
76278153
76288154 InitLinks(false); // for further display
....@@ -7637,7 +8163,9 @@
76378163 //Trim(true,cJME.gennormals,true,false); // doesn't work
76388164 Trim(true,false,false,false,false);
76398165
7640
- 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;
76418169 }
76428170
76438171 void UpdateIndices(Face face, Face minface)
....@@ -7650,18 +8178,21 @@
76508178 face.p = minface.p;
76518179 //if (leafweights)
76528180 face.good = 0; // false;
8181
+ face.used = true;
76538182 }
76548183 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
76558184 {
76568185 face.q = minface.p;
76578186 //if (leafweights)
76588187 face.good = 0; // false;
8188
+ face.used = true;
76598189 }
76608190 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
76618191 {
76628192 face.r = minface.p;
76638193 //if (leafweights)
76648194 face.good = 0; // false;
8195
+ face.used = true;
76658196 }
76668197
76678198 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7721,50 +8252,50 @@
77218252 if (v == 2)
77228253 vert = minface.r;
77238254 // 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)
8255
+ Vector<Face> vertfaces = links.get(vert);
8256
+ for (int i=vertfaces.size(); --i>=0;)
77358257 {
7736
- 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)
77378266 {
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);
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;
77498294 }
77508295 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;
8296
+ assert(false);
77638297 }
7764
- else
7765
- assert(false);
77668298 }
7767
- }
77688299
77698300 // TouchVertex(minface.p);
77708301 // TouchVertex(minface.q);
....@@ -7932,6 +8463,8 @@
79328463
79338464 minface.q = minface.r = minface.p;
79348465
8466
+ int count = 0;
8467
+
79358468 for (int i=0; i<faces.size(); i++)
79368469 {
79378470 Face face = (Face) faces.get(i);
....@@ -7943,6 +8476,9 @@
79438476 TouchVertex(face.r, true); // , minface.weight);
79448477 // assert(!lock);
79458478 faces.remove(i--);
8479
+ count++;
8480
+ if (count == 4)
8481
+ break;
79468482 }
79478483 }
79488484
....@@ -7960,6 +8496,7 @@
79608496 for (int i=vertfaces.size(); --i>=0;)
79618497 {
79628498 Face face = (Face) vertfaces.get(i);
8499
+ face.used = true;
79638500 face.good = 0; // false;
79648501 if (leafweights)
79658502 face.weight = -1;
....@@ -8006,7 +8543,7 @@
80068543 if (!trimmed)
80078544 return;
80088545
8009
- GraphreeD.linkUV = false;
8546
+ Grafreed.linkUV = false;
80108547
80118548 try
80128549 {
....@@ -8214,9 +8751,6 @@
82148751 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
82158752 }
82168753
8217
- static Camera localcamera = new Camera();
8218
- static cVector from = new cVector();
8219
- static cVector to = new cVector();
82208754 boolean trimmed = false;
82218755 boolean stripified = false;
82228756 transient boolean AOdone = false;
....@@ -8224,8 +8758,10 @@
82248758 /*transient*/ int maxIndexV = 0;
82258759 /*transient*/ int bufV, bufF;
82268760 // Raw version
8227
- private float[] positions;
8228
- private float[] normals;
8761
+ //private
8762
+ float[] positions;
8763
+ //private
8764
+ float[] normals;
82298765 float[] colors;
82308766 private float[] uvmap;
82318767 private int[] triangles;
....@@ -8239,7 +8775,8 @@
82398775 int[] startvertices;
82408776 float[] averagepoints;
82418777 float[] extremepoints;
8242
- float[] supportsizes; // distance of closest point
8778
+ float[] supportminsize; // distance of closest point
8779
+ float[] supportmaxsize; // distance of fartest point
82438780
82448781 transient Hashtable vertextable;
82458782 /*transient*/ private Vertex[] verticesCopy;