Normand Briere
2019-07-24 ebd16116fc612bf14e2469ba27dd7ee54918eabb
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,7 +680,8 @@
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)
....@@ -786,7 +821,7 @@
786821 v.weights[k] = other.ComputeWeight(v, toRoot, k); // (float)(supportsize * normalweight * nz / Math.pow(tx*tx+ty*ty+tz*tz, 1));
787822 v.totalweight += v.weights[k];
788823
789
- if (CameraPane.CROWD)
824
+ if (Globals.CROWD)
790825 {
791826 // System.out.print("weight = " + v.weights[k]);
792827 // System.out.println("; totalweight = " + v.totalweight);
....@@ -946,9 +981,9 @@
946981
947982 int nbsupports;
948983
949
- SEUIL = 0.1; // aout 2013
984
+ // sept 2017 SEUIL = 0.1; // aout 2013
950985
951
- supports = InitConnections(other);
986
+ supports = other.InitConnections();
952987
953988 other.supports = supports; // should be the other way around...
954989
....@@ -982,7 +1017,7 @@
9821017
9831018 int subsupports = 0;
9841019
985
- SEUIL = 0.1; // aout 2013
1020
+ // sept 2017 SEUIL = 0.1; // aout 2013
9861021
9871022 while (subsupports == 0)
9881023 {
....@@ -1006,6 +1041,26 @@
10061041
10071042 vect.set(v);
10081043 vect.sub(vect2);
1044
+
1045
+// vertextemp.x = other.averagepoints[c*3];
1046
+// vertextemp.y = other.averagepoints[c*3+1];
1047
+// vertextemp.z = other.averagepoints[c*3+2];
1048
+//
1049
+// Vertex v3 = vertextemp2;
1050
+// v3.x = other.extremepoints[c*3];
1051
+// v3.y = other.extremepoints[c*3+1];
1052
+// v3.z = other.extremepoints[c*3+2];
1053
+//
1054
+// vect3.set(v3); // "X" axis apex
1055
+// vect3.sub(vertextemp); // origin (center)
1056
+//
1057
+// double distmax = vect3.length();
1058
+//
1059
+// vect3.set(v2); // "X" axis apex
1060
+// vect3.sub(vertextemp); // origin (center)
1061
+//
1062
+// if (vect3.length() >= distmax)
1063
+// continue;
10091064
10101065 if (mindistance > vect.dot(vect))
10111066 {
....@@ -1017,7 +1072,9 @@
10171072
10181073 subsupports = v.closestsupport==-1 ? 0 : supports[v.closestsupport].Length();
10191074
1020
- SEUIL *= 2;
1075
+ // previously for "contains", now for weights.
1076
+ assert(subsupports > 0);
1077
+ //SEUIL *= 2;
10211078 }
10221079
10231080 assert(subsupports > 0);
....@@ -1492,7 +1549,7 @@
14921549 InitFaceIndices();
14931550 }
14941551
1495
- BoundaryRep rep = (BoundaryRep) GraphreeD.clone(this);
1552
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
14961553 //float[] v = new float[100];
14971554
14981555 for (int loops=1; --loops>=0;)
....@@ -1522,7 +1579,7 @@
15221579 InitFaceIndices();
15231580 }
15241581
1525
- BoundaryRep rep = (BoundaryRep) GraphreeD.clone(this);
1582
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15261583 //float[] v = new float[100];
15271584
15281585 for (int loops=10; --loops>=0;)
....@@ -1869,7 +1926,7 @@
18691926 return;
18701927 }
18711928
1872
- // System.exit(0);
1929
+ // System.exit(0);
18731930
18741931 cVector vect = new cVector();
18751932 cVector normal = new cVector();
....@@ -1940,7 +1997,8 @@
19401997 if (v.vertexlinks == null)
19411998 continue;
19421999
1943
- if (v.weights != null && v.weights[j] == 0) // < 0.01 * v.totalweight) // == 0)
2000
+ // Warning: faster but dangerous
2001
+ if (v.weights != null && v.weights[j] == 0) // < 0.001 * v.totalweight)
19442002 {
19452003 //testweight += v.weights[j-1];
19462004 continue;
....@@ -2163,7 +2221,7 @@
21632221 // if (slow)
21642222 // aout 2013
21652223 // sept 2013 merde...
2166
- W = 13;
2224
+ W = 3; // 13;
21672225
21682226 // POSERATE
21692227 if (CameraPane.tickcount > 0 || CameraPane.SLOWPOSE)
....@@ -2221,6 +2279,8 @@
22212279
22222280 transient int lastsoundtime;
22232281
2282
+ transient boolean once = false;
2283
+
22242284 void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked)
22252285 {
22262286 if (LA.isIdentity(toRoot))
....@@ -2276,7 +2336,11 @@
22762336
22772337 if (v.totalweight == 0)
22782338 {
2279
- System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2339
+ if (!once)
2340
+ {
2341
+ System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2342
+ once = true;
2343
+ }
22802344 continue;
22812345 }
22822346
....@@ -2600,7 +2664,7 @@
26002664 // if (stepout && !playedonce)
26012665 // {
26022666 // // sound
2603
-// GraphreeD.wav.play();
2667
+// GrafreeD.wav.play();
26042668 // playedonce = true;
26052669 // }
26062670 //
....@@ -2635,18 +2699,18 @@
26352699 if (false) // slow && stepout && onein)
26362700 {
26372701 // sound
2638
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
2702
+ cVector eye = Globals.theRenderer.EyeCamera().location;
26392703
26402704 Vertex v = GetVertex(0);
26412705
26422706 tmp.set(v);
26432707 tmp.sub(eye);
26442708
2645
- if (CameraPane.framecount - lastsoundtime > 30) // 0.25 secs
2709
+ if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26462710 {
2647
- GraphreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
2711
+ Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
26482712
2649
- lastsoundtime = CameraPane.framecount;
2713
+ lastsoundtime = Globals.framecount;
26502714 }
26512715
26522716 stepout = false;
....@@ -3072,6 +3136,7 @@
30723136 //
30733137 // transient VertexCompare[] vertexcompare = null;
30743138
3139
+ // Check if v0 is close enough from any vertex of the given subobject of this.
30753140 boolean Contains(Vertex v0, int object)
30763141 {
30773142 int start = startvertices[object-1];
....@@ -3129,7 +3194,27 @@
31293194 */
31303195 }
31313196
3132
- void GenUV()
3197
+ void UnfoldUV()
3198
+ {
3199
+ for (int i = 0; i < VertexCount(); i++)
3200
+ {
3201
+ Vertex v = GetVertex(i);
3202
+
3203
+ v.x = v.s;
3204
+ v.y = v.t;
3205
+ v.z = 0;
3206
+
3207
+ v.norm.x = 0;
3208
+ v.norm.y = 0;
3209
+ v.norm.z = 1;
3210
+
3211
+ SetVertex(v, i);
3212
+ }
3213
+ }
3214
+
3215
+ float power = 2;
3216
+
3217
+ void GenUV() // float power)
31333218 {
31343219 Trim();
31353220
....@@ -3193,6 +3278,125 @@
31933278 y -= 0.5;
31943279 z -= 0.5;
31953280
3281
+ double ax = Math.abs(x);
3282
+ double ay = Math.abs(y);
3283
+ double max = ax;
3284
+ if (max < ay)
3285
+ {
3286
+ max = ay;
3287
+ }
3288
+
3289
+ if (max == 0)
3290
+ {
3291
+ uvmap[i2] = 0.5f;
3292
+ uvmap[i2+1] = 0.5f;
3293
+ continue;
3294
+ }
3295
+
3296
+ x /= max;
3297
+ y /= max;
3298
+
3299
+ double angle = Math.acos(Math.abs(z*2));
3300
+
3301
+ double k = angle / Math.PI * 2;
3302
+
3303
+ assert(k >= 0);
3304
+
3305
+ // k == 0 => uv = 0 (center)
3306
+ // k == 1 => uv = -1,1 (border)
3307
+
3308
+ if (i == 0)
3309
+ System.out.println("power = " + power);
3310
+
3311
+ double length1 = (ax+ay)/max;
3312
+ double length2 = Math.sqrt(ax*ax + ay*ay) / max;
3313
+
3314
+ double t = k;
3315
+
3316
+ t = Math.pow(t, 3);
3317
+
3318
+ // Interpolate between k/length2 (center) and k (border)
3319
+ if (length2 > 0)
3320
+ k *= (1 - t) / length2 + t;
3321
+
3322
+ double u = k*x;
3323
+ double v = k*y;
3324
+
3325
+ u /= 2;
3326
+ v /= 2;
3327
+ u += 0.5;
3328
+ v += 0.5;
3329
+
3330
+ uvmap[i2] = (float) u;
3331
+ uvmap[i2+1] = (float) v;
3332
+ }
3333
+ }
3334
+
3335
+ void GenUVold(float power)
3336
+ {
3337
+ Trim();
3338
+
3339
+ cVector boxcenter = null;
3340
+ cVector minima, maxima;
3341
+ minima = new cVector();
3342
+ maxima = new cVector();
3343
+ minima.x = minima.y = minima.z = Double.MAX_VALUE;
3344
+ maxima.x = maxima.y = maxima.z = -Double.MAX_VALUE;
3345
+ for (int i = 0; i < VertexCount(); i++)
3346
+ {
3347
+ Vertex v = GetVertex(i);
3348
+
3349
+ if (minima.x > v.x)
3350
+ {
3351
+ minima.x = v.x;
3352
+ }
3353
+ if (minima.y > v.y)
3354
+ {
3355
+ minima.y = v.y;
3356
+ }
3357
+ if (minima.z > v.z)
3358
+ {
3359
+ minima.z = v.z;
3360
+ }
3361
+
3362
+ if (maxima.x < v.x)
3363
+ {
3364
+ maxima.x = v.x;
3365
+ }
3366
+ if (maxima.y < v.y)
3367
+ {
3368
+ maxima.y = v.y;
3369
+ }
3370
+ if (maxima.z < v.z)
3371
+ {
3372
+ maxima.z = v.z;
3373
+ }
3374
+ }
3375
+
3376
+ boxcenter = new cVector((maxima.x + minima.x) / 2, (maxima.y + minima.y) / 2, (maxima.z + minima.z) / 2);
3377
+ int i2 = 0, i3 = 0;
3378
+ for (int i = 0; i < positions.length/3; i++, i3 += 3, i2 += 2)
3379
+ {
3380
+// //uvmap[i2] = (float) normals[i3]*0.5f + 0.5f; // v.x;
3381
+// //uvmap[i2 + 1] = (float) normals[i3+1]*0.5f + 0.5f; //z;
3382
+// uvmap[i2] = (float) (positions[i3] - boxcenter.x);
3383
+// uvmap[i2 + 1] = (float) (positions[i3+2] - boxcenter.z);
3384
+// uvmap[i2] = (float) Math.atan2(positions[i3+1] - boxcenter.y, positions[i3] - boxcenter.x);
3385
+// uvmap[i2 + 1] = (float)(positions[i3+2] - boxcenter.z);
3386
+ // box UV
3387
+ double x = positions[i3] - minima.x; // - Math.floor(positions[i3]);
3388
+ double y = positions[i3+1] - minima.y; // - Math.floor(positions[i3+1]);
3389
+ double z = positions[i3+2] - minima.z; // - Math.floor(positions[i3+2]);
3390
+
3391
+ // [-1/2, 1/2]
3392
+ x /= maxima.x - minima.x;
3393
+ y /= maxima.y - minima.y;
3394
+ z /= maxima.z - minima.z;
3395
+
3396
+ x -= 0.5;
3397
+ y -= 0.5;
3398
+ z -= 0.5;
3399
+
31963400 // x *= 2;
31973401 // y *= 2;
31983402 // z *= 2;
....@@ -3219,6 +3423,15 @@
32193423
32203424 z = Math.cos(angle/2);
32213425
3426
+ assert(z >= 0);
3427
+ assert(z <= 1);
3428
+
3429
+ /**/
3430
+ //z = Math.pow(z, power); //1.08f);
3431
+
3432
+ if (i == 0)
3433
+ System.out.println("power = " + power);
3434
+
32223435 // sqrt(k2*x2 + k2*z2 + y2) = length
32233436 // k2*x2 + k2*z2 = length2 - y2
32243437 // k2 = (length2 - y2) / (x2 + z2)
....@@ -3229,7 +3442,7 @@
32293442 k /= x*x + y*y;
32303443 }
32313444 else
3232
- GraphreeD.Assert(z == 1);
3445
+ Grafreed.Assert(z == 1);
32333446
32343447 if (k < 0)
32353448 k = 0;
....@@ -3238,6 +3451,7 @@
32383451
32393452 x *= k;
32403453 y *= k;
3454
+ /**/
32413455
32423456 double max = Math.abs(x);
32433457 if (max < Math.abs(y))
....@@ -3250,10 +3464,15 @@
32503464 }
32513465
32523466 // max = Math.sqrt(max*2)/2;
3467
+// double x2 = Math.pow(Math.abs(x), 1/power);
3468
+// double y2 = Math.pow(Math.abs(y), 1/power);
3469
+// double z2 = Math.pow(Math.abs(z), 1/power);
3470
+// max = Math.pow(x2 + y2 + z2, power);
32533471
32543472 // if (!(max > 0))
3255
- assert(max > 0);
3256
-
3473
+ //assert(max > 0);
3474
+ assert(max >= 0);
3475
+
32573476 x /= max;
32583477 y /= max;
32593478 z /= max;
....@@ -3516,6 +3735,111 @@
35163735 */
35173736 }
35183737
3738
+ void GenerateNormals2(boolean crease)
3739
+ {
3740
+ cVector tempVector = new cVector();
3741
+
3742
+// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>();
3743
+//
3744
+//
3745
+// for (int i=0; i<this.VertexCount(); i++)
3746
+// {
3747
+// Vertex v = this.GetVertex(i);
3748
+//
3749
+// tempVector.set(v);
3750
+//
3751
+// cVector n = tableBase.get(tempVector.ToFloat());
3752
+//
3753
+// if (n != null)
3754
+// {
3755
+// continue;
3756
+// }
3757
+//
3758
+// tableBase.put(new cVector(tempVector), new cVector(v.norm));
3759
+// }
3760
+
3761
+ BoundaryRep tempSupport = this.support;
3762
+
3763
+ this.support = null;
3764
+
3765
+ BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this);
3766
+
3767
+ this.support = tempSupport;
3768
+
3769
+ //tempRep.Unstripify();
3770
+
3771
+ tempRep.GenerateNormals2(crease);
3772
+
3773
+ boolean keepnormal = Vertex.normalmode;
3774
+ boolean epsequal = Grafreed.epsequal;
3775
+
3776
+ Vertex.normalmode = false;
3777
+ Grafreed.epsequal = false; // A bit strange
3778
+
3779
+ // No need to have a match for vertex counts.
3780
+
3781
+ java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>();
3782
+
3783
+ for (int i=0; i<tempRep.VertexCount(); i++)
3784
+ {
3785
+ Vertex v = tempRep.GetVertex(i);
3786
+
3787
+ cVector n = table.get(tempVector.ToFloat());
3788
+
3789
+ if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0)
3790
+ {
3791
+ //continue;
3792
+ }
3793
+
3794
+ tempVector.set(v);
3795
+
3796
+ //cVector nBase = tableBase.get(tempVector);
3797
+
3798
+ //if (v.norm.dot(nBase) < 0.9)
3799
+ //{
3800
+ // continue;
3801
+ //}
3802
+
3803
+ if (n != null && n.x == 1 && n.y == 0 && n.z == 0)
3804
+ {
3805
+ //continue;
3806
+ }
3807
+
3808
+ if (n != null)
3809
+ {
3810
+// if (n.dot(v.norm) < 0)
3811
+// n.sub(v.norm);
3812
+// else
3813
+// n.add(v.norm);
3814
+//
3815
+// n.normalize();
3816
+ continue;
3817
+ }
3818
+
3819
+ table.put(new cVector(tempVector), new cVector(v.norm));
3820
+ }
3821
+
3822
+ for (int i=0; i<this.VertexCount(); i++)
3823
+ {
3824
+ Vertex v = this.GetVertex(i);
3825
+
3826
+ tempVector.set(v);
3827
+
3828
+ cVector n = table.get(tempVector.ToFloat());
3829
+
3830
+ //if (n.dot(v.norm) < 0)
3831
+ if (n == null)
3832
+ continue;
3833
+
3834
+ LA.vecCopy(n, v.norm);
3835
+
3836
+ this.SetVertex(v, i);
3837
+ }
3838
+
3839
+ Grafreed.epsequal = epsequal;
3840
+ Vertex.normalmode = keepnormal;
3841
+ }
3842
+
35193843 void GenerateNormals(boolean crease)
35203844 {
35213845 boolean wastrim = trimmed;
....@@ -3531,7 +3855,29 @@
35313855 e.printStackTrace();
35323856 }
35333857
3534
- Trim(wastrim,true,crease,wasstrip,false);
3858
+ Trim(true/*wastrim*/,true,crease,wasstrip,false);
3859
+ }
3860
+
3861
+ void GenerateNormalsMesh()
3862
+ {
3863
+ if (stripified)
3864
+ {
3865
+ Unstripify();
3866
+ }
3867
+
3868
+ if (trimmed)
3869
+ {
3870
+ normals = null;
3871
+ }
3872
+ else
3873
+ {
3874
+ for (int i=VertexCount(); --i>=0;)
3875
+ {
3876
+ Vertex v = GetVertex(i);
3877
+
3878
+ v.norm = null;
3879
+ }
3880
+ }
35353881 }
35363882
35373883 void GenNormalsJME()
....@@ -3656,7 +4002,7 @@
36564002 NormalGenerator ng;
36574003
36584004 if (crease)
3659
- ng = new NormalGenerator(Math.PI/6); // default is 44 degrees (or Math.PI/3); // /4);
4005
+ ng = new NormalGenerator(Math.PI/4); // default is 44 degrees (or Math.PI/3); // /4);
36604006 else
36614007 ng = new NormalGenerator(Math.PI); // (Math.PI / 3); // /4);
36624008
....@@ -3689,6 +4035,10 @@
36894035 {
36904036 triangles[i] = i;
36914037 }
4038
+
4039
+// Untrim();
4040
+ if (!trimmed)
4041
+ MergeNormals();
36924042 }
36934043 }
36944044
....@@ -3722,6 +4072,11 @@
37224072 tsa.getNormals(0, normals);
37234073 tsa.getTextureCoordinates(0, 0, uvmap);
37244074 // tsa.getColors(0, colors);
4075
+
4076
+ for (int i=colors.length; --i>=0;)
4077
+ {
4078
+ colors[i] = 1;
4079
+ }
37254080
37264081 int stripcount = tsa.getNumStrips();
37274082 triangles = new int[stripcount];
....@@ -3744,6 +4099,10 @@
37444099 triangles = new int[1];
37454100 triangles[0] = 3;
37464101 }
4102
+
4103
+ //Untrim();
4104
+ if (!trimmed)
4105
+ MergeNormals();
37474106 }
37484107
37494108 /*
....@@ -3776,21 +4135,66 @@
37764135 for (int i = 0; i < VertexCount(); i++)
37774136 {
37784137 Vertex v = GetVertex(i);
4138
+
4139
+ vertextemp.set(v);
4140
+
37794141 //if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
37804142 {
3781
- GenerateNormal(i, v);
3782
- SetVertex(v, i);
4143
+ if (!GenerateNormal(i, vertextemp))
4144
+ continue;
4145
+
4146
+ if (v.norm.dot(vertextemp.norm) < 0)
4147
+ vertextemp.norm.mul(-1);
4148
+
4149
+ if (v.norm.dot(vertextemp.norm) < 0.9)
4150
+ SetVertex(vertextemp, i);
37834151 }
37844152 }
37854153
37864154 Vertex.normalmode = false;
37874155 }
37884156
4157
+ void MergeNormals()
4158
+ {
4159
+ assert(!trimmed);
4160
+
4161
+ boolean smooth = Grafreed.smoothmode;
4162
+ boolean link = Grafreed.linkUV;
4163
+ Grafreed.smoothmode = true;
4164
+ Grafreed.linkUV = true;
4165
+
4166
+ System.out.println("#Vertex = " + VertexCount());
4167
+ System.out.println("#Face = " + FaceCount());
4168
+
4169
+ java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>();
4170
+
4171
+ for (int i = 0; i < VertexCount(); i++)
4172
+ {
4173
+ Vertex v = GetVertex(i);
4174
+
4175
+ if (!table.contains(v))
4176
+ {
4177
+ table.add(v);
4178
+ }
4179
+ }
4180
+
4181
+ Grafreed.smoothmode = smooth;
4182
+ Grafreed.linkUV = link;
4183
+
4184
+// for (int i = 0; i < VertexCount(); i++)
4185
+// {
4186
+// Vertex v = GetVertex(i);
4187
+//
4188
+// table.add(v);
4189
+// }
4190
+
4191
+ }
4192
+
37894193 static cVector temp1 = new cVector();
37904194 static cVector temp2 = new cVector();
37914195 static cVector temp3 = new cVector();
37924196
3793
- void GenerateNormal(int index, Vertex v)
4197
+ boolean GenerateNormal(int index, Vertex v)
37944198 {
37954199 //System.out.println("Old normal = " + v.norm);
37964200 LA.setVector(v.norm, 0, 0, 0);
....@@ -3819,6 +4223,10 @@
38194223 LA.vecSub(p/*.pos*/, v/*.pos*/, temp1);
38204224 LA.vecSub(q/*.pos*/, v/*.pos*/, temp2);
38214225 }
4226
+ else
4227
+ {
4228
+ continue;
4229
+ }
38224230
38234231 //LA.vecNormalize(temp1);
38244232 //LA.vecNormalize(temp2);
....@@ -3829,17 +4237,25 @@
38294237 double s = temp3.length();
38304238 //double c = temp2.dot(temp1);
38314239
4240
+ if (s == 0)
4241
+ return false;
4242
+
38324243 float angle = 1; // (float) Math.atan2(s, c);
38334244 //if(angle < 0) angle = -angle;
38344245
38354246 //LA.vecNormalize(temp3);
38364247 LA.vecScale(temp3, angle / s);
38374248
4249
+// if (temp3.dot(v.norm) < 0)
4250
+// assert(temp3.dot(v.norm) >= 0);
4251
+
38384252 LA.vecAdd(temp3, v.norm, v.norm);
38394253 }
38404254
38414255 LA.vecNormalize(v.norm);
38424256 //System.out.println("New normal = " + v.norm);
4257
+
4258
+ return true;
38434259 }
38444260
38454261 double Arccos(double x)
....@@ -4233,7 +4649,7 @@
42334649 int count = VertexCount();
42344650
42354651 // mars 2014
4236
- while (step >= count)
4652
+ while (step > count)
42374653 step /= 10;
42384654
42394655 for (int i = 0; i < count; i+=step)
....@@ -4381,7 +4797,7 @@
43814797 }
43824798 }
43834799
4384
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4800
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
43854801 {
43864802 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
43874803 CameraPane.tempmat,0, CameraPane.tempmat2,0,
....@@ -4413,14 +4829,14 @@
44134829 // june 2014
44144830 // Camera parentcam = cam;
44154831 //
4416
-// if (cam == CameraPane.theRenderer.cameras[0])
4832
+// if (cam == Globals.theRenderer.cameras[0])
44174833 // {
4418
-// parentcam = CameraPane.theRenderer.cameras[1];
4834
+// parentcam = Globals.theRenderer.cameras[1];
44194835 // }
44204836 //
4421
-// if (cam == CameraPane.theRenderer.cameras[1])
4837
+// if (cam == Globals.theRenderer.cameras[1])
44224838 // {
4423
-// parentcam = CameraPane.theRenderer.cameras[0];
4839
+// parentcam = Globals.theRenderer.cameras[0];
44244840 // }
44254841
44264842 gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0);
....@@ -4546,16 +4962,25 @@
45464962 {
45474963 i3 = positions.length-3;
45484964 i2 = uvmap.length - 2;
4549
- new Exception().printStackTrace();
4965
+ //new Exception().printStackTrace();
45504966 }
45514967
45524968 v./*pos.*/x = positions[i3];
45534969 v./*pos.*/y = positions[i3 + 1];
45544970 v./*pos.*/z = positions[i3 + 2];
45554971
4556
- v.norm.x = normals[i3];
4557
- v.norm.y = normals[i3 + 1];
4558
- v.norm.z = normals[i3 + 2];
4972
+ if (normals == null)
4973
+ {
4974
+ v.norm.x = 0;
4975
+ v.norm.y = 0;
4976
+ v.norm.z = 0;
4977
+ }
4978
+ else
4979
+ {
4980
+ v.norm.x = normals[i3];
4981
+ v.norm.y = normals[i3 + 1];
4982
+ v.norm.z = normals[i3 + 2];
4983
+ }
45594984
45604985 v.s = uvmap[i2];
45614986 v.t = uvmap[i2 + 1];
....@@ -4846,7 +5271,7 @@
48465271 return verticesCopy;
48475272 }
48485273
4849
- void PreprocessOcclusion(CameraPane cp, double[][] transform)
5274
+ void PreprocessOcclusion(iCameraPane cp, double[][] transform)
48505275 {
48515276 if (//!trimmed ||
48525277 AOdone)
....@@ -4855,80 +5280,7 @@
48555280 return;
48565281 }
48575282
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;
5283
+ cp.PrepOcclusion(this, transform);
49325284
49335285 AOdone = true;
49345286 }
....@@ -5036,6 +5388,59 @@
50365388 }
50375389 }
50385390 colors = null;
5391
+ }
5392
+
5393
+ void CreateMesh(iHeightField hf, int x, int y)
5394
+ {
5395
+ BoundaryRep tmp = new BoundaryRep();
5396
+
5397
+ int vc = 0;
5398
+
5399
+ Vertex v = new Vertex(true);
5400
+
5401
+ for (int i=0; i<x; i++)
5402
+ {
5403
+ for (int j=0; j<y; j++)
5404
+ {
5405
+// Vertex v = tmp.GetVertex(vc++);
5406
+
5407
+ v.s = v.x = i;
5408
+ v.t = v.z = j;
5409
+ v.s /= x; v.t /= y;
5410
+ v.y = hf.f(i,j);
5411
+
5412
+ int iu = tmp.AddTableVertex(v);
5413
+
5414
+ v.s = v.x = i+1;
5415
+ v.t = v.z = j;
5416
+ v.s /= x; v.t /= y;
5417
+ v.y = hf.f(i+1,j);
5418
+
5419
+ int iv = tmp.AddTableVertex(v);
5420
+
5421
+ v.s = v.x = i+1;
5422
+ v.t = v.z = j+1;
5423
+ v.s /= x; v.t /= y;
5424
+ v.y = hf.f(i+1,j+1);
5425
+
5426
+ int iw = tmp.AddTableVertex(v);
5427
+
5428
+ v.s = v.x = i;
5429
+ v.t = v.z = j+1;
5430
+ v.s /= x; v.t /= y;
5431
+ v.y = hf.f(i,j+1);
5432
+
5433
+ int ix = tmp.AddTableVertex(v);
5434
+
5435
+ tmp.AddFace(iu,iw,iv);
5436
+ tmp.AddFace(iu,ix,iw);
5437
+ }
5438
+ }
5439
+
5440
+ Set(tmp);
5441
+
5442
+ Trim(true,false,true);
5443
+ ClearColors();
50395444 }
50405445
50415446 void Stripify()
....@@ -5290,25 +5695,27 @@
52905695
52915696 transient int nbbadfaces; // ?? = 1000000;
52925697
5293
- int ChooseTriangle()
5698
+ /*
5699
+ */
5700
+ int ChooseTriangle(boolean firstEquilateral)
52945701 {
52955702 int chosen = -1;
52965703
52975704 double minweight = 1E10;
52985705
5706
+ int step = 8; // ?
5707
+
5708
+ if (firstEquilateral)
5709
+ step = 1;
5710
+
52995711 nbbadfaces = 0;
5300
- for (int i=faces.size(); (i-=8)>=0;)
5712
+ for (int i=0; i<faces.size(); i+=step)
5713
+// for (int i=faces.size(); (i-=8)>=0;)
53015714 {
53025715 Face face = (Face) faces.get(i);
53035716
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;
5717
+ if (face.used)
5718
+ continue;
53125719
53135720 if (!Valid(face))
53145721 {
....@@ -5319,6 +5726,15 @@
53195726 if (Boundary(face))
53205727 continue;
53215728
5729
+// if (Boundary(face.p))
5730
+// continue;
5731
+//
5732
+// if (Boundary(face.q))
5733
+// continue;
5734
+//
5735
+// if (Boundary(face.r))
5736
+// continue;
5737
+
53225738 if (!ValidValence(face))
53235739 continue;
53245740
....@@ -5327,14 +5743,58 @@
53275743 !ValidValence(face.r))
53285744 continue;
53295745
5330
- if (minweight > weight)
5746
+ //?? if (face.weight < 0)
5747
+ // continue;
5748
+
5749
+ if (firstEquilateral)
53315750 {
5332
- minweight = weight;
5751
+ if (OneFaceUsed(links.get(face.p)))
5752
+ continue;
5753
+
5754
+ if (OneFaceUsed(links.get(face.q)))
5755
+ continue;
5756
+
5757
+ if (OneFaceUsed(links.get(face.r)))
5758
+ continue;
5759
+
53335760 chosen = i;
5761
+ break;
5762
+ }
5763
+ else
5764
+ {
5765
+ double K = 1; // 0.01; // .25;
5766
+
5767
+ double factor = (1-K)*face.nbiterations + K; //*face.weight;
5768
+
5769
+ double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5770
+
5771
+ if (minweight > weight)
5772
+ {
5773
+ minweight = weight;
5774
+ chosen = i;
5775
+ if (minweight == 0)
5776
+ break;
5777
+ }
53345778 }
53355779 }
53365780
53375781 return chosen;
5782
+ }
5783
+
5784
+ private boolean OneFaceUsed(Vector<Face> faces)
5785
+ {
5786
+ if (faces.size() != 6)
5787
+ return true;
5788
+
5789
+ for (int i=0; i<6; i+=1)
5790
+ {
5791
+ if (faces.get(i).used)
5792
+ {
5793
+ return true;
5794
+ }
5795
+ }
5796
+
5797
+ return false;
53385798 }
53395799
53405800 static boolean remove3valence = true;
....@@ -5370,7 +5830,7 @@
53705830 }
53715831 else
53725832 {
5373
- assert(links.size() == vertices.size());
5833
+ // TODO Grafreed.Assert(links.size() == vertices.size());
53745834
53755835 links.setSize(vertices.size());
53765836 for (int i=vertices.size(); --i>=0;)
....@@ -5378,6 +5838,7 @@
53785838 // linkstouched[i] = false;
53795839 if (links.get(i) == null) // ??
53805840 {
5841
+ new Exception().printStackTrace();
53815842 links.set(i, new Vector(8));
53825843 // linkstouched[i] = true;
53835844 }
....@@ -5388,6 +5849,8 @@
53885849 }
53895850 }
53905851
5852
+ boolean once = false;
5853
+
53915854 for (int i=faces.size(); --i>=0;)
53925855 {
53935856 Face face = (Face) faces.get(i);
....@@ -5399,6 +5862,9 @@
53995862 //if (linkstouched[face.r])
54005863 links.get(face.r).add(face);
54015864
5865
+ if (face.used)
5866
+ once = true;
5867
+
54025868 face.good = 1;
54035869 face.boundary = -1;
54045870 }
....@@ -6170,6 +6636,7 @@
61706636
61716637 void InitWeights()
61726638 {
6639
+ new Exception().printStackTrace();
61736640 System.exit(0);
61746641 int n = 0;
61756642 int b = 0;
....@@ -6763,6 +7230,10 @@
67637230 return (face.boundary = 1) == 1;
67647231 }
67657232
7233
+ // June 2019
7234
+ if (true)
7235
+ return (face.boundary = 0) == 1;
7236
+
67667237 // reverse triangle test
67677238 q1.set(p);
67687239 q2.set(q);
....@@ -7019,6 +7490,7 @@
70197490 assert(f2.contains(i));
70207491 assert(f3.contains(i));
70217492
7493
+ // when r is the "center", p is along the boundary
70227494 while (f0.r != i)
70237495 {
70247496 int t = f0.p;
....@@ -7075,59 +7547,90 @@
70757547 f0 = f3;
70767548 f3 = t;
70777549 }
7078
- atleastone = true;
70797550
7551
+ int va = f0.q;
7552
+ int vb = f0.r;
7553
+ int vc = -1;
7554
+
7555
+ Face toremove1 = null;
7556
+ Face toremove2 = null;
7557
+
7558
+ // f0 is the buffer for the first new triangle,
7559
+ // and otherf is the other upper one.
70807560 Face otherf = null;
70817561
70827562 if (f1.contains(f0.p))
70837563 {
70847564 if (f1.p == f0.p)
70857565 {
7566
+ assert(false);
70867567 f0.r = f1.q;
70877568 }
70887569 else
70897570 {
70907571 assert(f1.q == f0.p);
7091
- f0.r = f1.p;
7572
+ vc = f1.p;
70927573 }
70937574
70947575 otherf = f2;
7095
- faces.remove(f1);
7096
- faces.remove(f3);
7576
+ toremove1 = f1;
7577
+ toremove2 = f3;
70977578 }
70987579 else
70997580 if (f2.contains(f0.p))
71007581 {
71017582 if (f2.p == f0.p)
71027583 {
7584
+ assert(false);
71037585 f0.r = f2.q;
71047586 }
71057587 else
71067588 {
71077589 assert(f2.q == f0.p);
7108
- f0.r = f2.p;
7590
+ vc = f2.p;
71097591 }
71107592
71117593 otherf = f3;
7112
- faces.remove(f1);
7113
- faces.remove(f2);
7594
+ toremove1 = f1;
7595
+ toremove2 = f2;
71147596 }
71157597 if (f3.contains(f0.p))
71167598 {
71177599 if (f3.p == f0.p)
71187600 {
7601
+// assert(false);
7602
+ new Exception().printStackTrace();
71197603 f0.r = f3.q;
71207604 }
71217605 else
71227606 {
71237607 assert(f3.q == f0.p);
7124
- f0.r = f3.p;
7608
+ vc = f3.p;
71257609 }
71267610
71277611 otherf = f1;
7128
- faces.remove(f2);
7129
- faces.remove(f3);
7612
+ toremove1 = f2;
7613
+ toremove2 = f3;
71307614 }
7615
+
7616
+ vertextemp.set(vertices.get(va));
7617
+ vertextemp.sub(vertices.get(vb));
7618
+ vertextemp.normalize();
7619
+ vertextemp2.set(vertices.get(vc));
7620
+ vertextemp2.sub(vertices.get(vb));
7621
+ vertextemp2.normalize();
7622
+
7623
+ if (vertextemp.dot(vertextemp2) > -0.95)
7624
+ {
7625
+ continue;
7626
+ }
7627
+
7628
+ atleastone = true;
7629
+
7630
+ f0.r = vc;
7631
+
7632
+ faces.remove(toremove1);
7633
+ faces.remove(toremove2);
71317634
71327635 if (!f0.contains(otherf.p))
71337636 {
....@@ -7180,7 +7683,7 @@
71807683 //InitWeights();
71817684 }
71827685
7183
- int chosen = ChooseTriangle(); // Best is slow and not really better
7686
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
71847687
71857688 if (chosen == -1)
71867689 {
....@@ -7194,7 +7697,7 @@
71947697 //remove3valence = false;
71957698 // InitWeights();
71967699
7197
- chosen = ChooseTriangle();
7700
+ chosen = ChooseTriangle(true);
71987701 }
71997702 }
72007703
....@@ -7335,7 +7838,7 @@
73357838 Trim();
73367839 Untrim();
73377840
7338
- BoundaryRep tmp = new BoundaryRep(); // (BoundaryRep) GraphreeD.clone(this);
7841
+ BoundaryRep tmp = new BoundaryRep(); // (BoundaryRep) GrafreeD.clone(this);
73397842
73407843 double minx = Float.POSITIVE_INFINITY;
73417844 double maxx = Float.NEGATIVE_INFINITY;
....@@ -7373,7 +7876,7 @@
73737876 if (max < maxz - minz)
73747877 max = maxz - minz;
73757878
7376
- tmp.THRESHOLD = max/25; // 50;
7879
+ tmp.THRESHOLD = 0.5; // max/25; // 50;
73777880
73787881 tmp.faces.clear();
73797882
....@@ -7470,7 +7973,7 @@
74707973
74717974 // boolean lock;
74727975
7473
- void SplitInTwo(boolean reduction34, boolean onlyone)
7976
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
74747977 {
74757978 if (stripified)
74767979 {
....@@ -7498,7 +8001,7 @@
74988001 s3 = new cVector();
74998002 }
75008003
7501
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
8004
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
75028005
75038006 try
75048007 {
....@@ -7507,12 +8010,12 @@
75078010 {
75088011 System.err.println("EXCEPTION CAUGHT");
75098012 e.printStackTrace();
7510
- return;
8013
+ return false;
75118014 } catch (Error e)
75128015 {
75138016 System.err.println("ERROR CAUGHT");
75148017 e.printStackTrace();
7515
- return;
8018
+ return false;
75168019 }
75178020
75188021 System.out.println("# faces = " + faces.size());
....@@ -7522,6 +8025,7 @@
75228025 {
75238026 Face face = (Face) faces.get(i);
75248027
8028
+ face.used = false;
75258029 face.nbiterations = 1;
75268030 face.weight = -1;
75278031 face.boundary = -1;
....@@ -7573,6 +8077,11 @@
75738077 nbbadfaces = faces.size();
75748078 //remove3valence = true;
75758079
8080
+ int count = 2;
8081
+
8082
+ if (onlyone)
8083
+ count = 1;
8084
+
75768085 firstpass = true;
75778086
75788087 int n = faces.size();
....@@ -7588,12 +8097,13 @@
75888097 System.out.print('.');
75898098 }
75908099 System.out.println();
8100
+ boolean atleastone = false;
75918101 int i = 0;
7592
- while (reduction34 || faces.size() > n/2)
8102
+ while (true) // reduction34 || faces.size() > n/2)
75938103 {
75948104 if (i++%100 == 0)
75958105 {
7596
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
8106
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
75978107 System.out.println("#faces = " + faces.size());
75988108 // if (i != 1)
75998109 // break;
....@@ -7611,6 +8121,8 @@
76118121 {
76128122 if (!RemoveOneTriangle())
76138123 break;
8124
+
8125
+ atleastone = true;
76148126 }
76158127 // if (iterationcount == 0)
76168128 // break;
....@@ -7621,8 +8133,8 @@
76218133 break;
76228134 }
76238135 firstpass = false;
7624
- if (onlyone)
7625
- break; // one triangle only
8136
+// if (--count<0 && !reduction34)
8137
+// break; // one triangle only
76268138 }
76278139
76288140 InitLinks(false); // for further display
....@@ -7637,7 +8149,9 @@
76378149 //Trim(true,cJME.gennormals,true,false); // doesn't work
76388150 Trim(true,false,false,false,false);
76398151
7640
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8152
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8153
+
8154
+ return atleastone;
76418155 }
76428156
76438157 void UpdateIndices(Face face, Face minface)
....@@ -7650,18 +8164,21 @@
76508164 face.p = minface.p;
76518165 //if (leafweights)
76528166 face.good = 0; // false;
8167
+ face.used = true;
76538168 }
76548169 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
76558170 {
76568171 face.q = minface.p;
76578172 //if (leafweights)
76588173 face.good = 0; // false;
8174
+ face.used = true;
76598175 }
76608176 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
76618177 {
76628178 face.r = minface.p;
76638179 //if (leafweights)
76648180 face.good = 0; // false;
8181
+ face.used = true;
76658182 }
76668183
76678184 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7721,50 +8238,50 @@
77218238 if (v == 2)
77228239 vert = minface.r;
77238240 // 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)
8241
+ Vector<Face> vertfaces = links.get(vert);
8242
+ for (int i=vertfaces.size(); --i>=0;)
77358243 {
7736
- if (!leafweights)
8244
+ Face face = (Face) vertfaces.get(i);
8245
+
8246
+ // if (face.weight == 10000)
8247
+ // continue;
8248
+
8249
+ if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
8250
+ face.p == minface.q || face.q == minface.q || face.r == minface.q ||
8251
+ face.p == minface.r || face.q == minface.r || face.r == minface.r)
77378252 {
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);
8253
+ if (!leafweights)
8254
+ {
8255
+ // if(minfaceweight <= 0)
8256
+ // assert(minfaceweight > 0);
8257
+ //
8258
+ // //FaceWeight(face);
8259
+ // if(face.weight < 0)
8260
+ // assert(face.weight >= 0);
8261
+
8262
+ face.weight += minfaceweight;
8263
+
8264
+ // if (face.weight >= 10000)
8265
+ // assert(face.weight < 10000);
8266
+ }
8267
+ else
8268
+ face.weight = -1;
8269
+
8270
+ face.nbiterations += 1;
8271
+ face.boundary = -1;
8272
+
8273
+ Vertex p = (Vertex)vertices.get(face.p);
8274
+ Vertex q = (Vertex)vertices.get(face.q);
8275
+ Vertex r = (Vertex)vertices.get(face.r);
8276
+
8277
+ p.boundary = -1;
8278
+ q.boundary = -1;
8279
+ r.boundary = -1;
77498280 }
77508281 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;
8282
+ assert(false);
77638283 }
7764
- else
7765
- assert(false);
77668284 }
7767
- }
77688285
77698286 // TouchVertex(minface.p);
77708287 // TouchVertex(minface.q);
....@@ -7932,6 +8449,8 @@
79328449
79338450 minface.q = minface.r = minface.p;
79348451
8452
+ int count = 0;
8453
+
79358454 for (int i=0; i<faces.size(); i++)
79368455 {
79378456 Face face = (Face) faces.get(i);
....@@ -7943,6 +8462,9 @@
79438462 TouchVertex(face.r, true); // , minface.weight);
79448463 // assert(!lock);
79458464 faces.remove(i--);
8465
+ count++;
8466
+ if (count == 4)
8467
+ break;
79468468 }
79478469 }
79488470
....@@ -7960,6 +8482,7 @@
79608482 for (int i=vertfaces.size(); --i>=0;)
79618483 {
79628484 Face face = (Face) vertfaces.get(i);
8485
+ face.used = true;
79638486 face.good = 0; // false;
79648487 if (leafweights)
79658488 face.weight = -1;
....@@ -8006,7 +8529,7 @@
80068529 if (!trimmed)
80078530 return;
80088531
8009
- GraphreeD.linkUV = false;
8532
+ Grafreed.linkUV = false;
80108533
80118534 try
80128535 {
....@@ -8214,9 +8737,6 @@
82148737 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
82158738 }
82168739
8217
- static Camera localcamera = new Camera();
8218
- static cVector from = new cVector();
8219
- static cVector to = new cVector();
82208740 boolean trimmed = false;
82218741 boolean stripified = false;
82228742 transient boolean AOdone = false;
....@@ -8224,8 +8744,10 @@
82248744 /*transient*/ int maxIndexV = 0;
82258745 /*transient*/ int bufV, bufF;
82268746 // Raw version
8227
- private float[] positions;
8228
- private float[] normals;
8747
+ //private
8748
+ float[] positions;
8749
+ //private
8750
+ float[] normals;
82298751 float[] colors;
82308752 private float[] uvmap;
82318753 private int[] triangles;
....@@ -8239,7 +8761,8 @@
82398761 int[] startvertices;
82408762 float[] averagepoints;
82418763 float[] extremepoints;
8242
- float[] supportsizes; // distance of closest point
8764
+ float[] supportminsize; // distance of closest point
8765
+ float[] supportmaxsize; // distance of fartest point
82438766
82448767 transient Hashtable vertextable;
82458768 /*transient*/ private Vertex[] verticesCopy;