Normand Briere
2019-08-06 b3ae4e889872ca0b9ca76f1d17b2f0b961226729
BoundaryRep.java
....@@ -15,7 +15,7 @@
1515 {
1616 this(0, 0);
1717 }
18
-
18
+
1919 void SaveSupports()
2020 {
2121 transientsupport = support;
....@@ -161,6 +161,7 @@
161161 || FaceCount() != other.FaceCount()
162162 || !(indices == null ^ other.indices != null)) // july 2014
163163 {
164
+ // The meshes have different structures.
164165 //new Exception().printStackTrace();
165166 trimmed = other.trimmed;
166167 stripified = other.stripified;
....@@ -172,16 +173,16 @@
172173 bufV = other.bufV;
173174 bufF = other.bufF;
174175
175
- positions = (float[]) GrafreeD.clone(other.positions);
176
- normals = (float[]) GrafreeD.clone(other.normals);
177
- colors = (float[]) GrafreeD.clone(other.colors);
178
- uvmap = (float[]) GrafreeD.clone(other.uvmap);
179
- triangles = (int[]) GrafreeD.clone(other.triangles);
176
+ positions = (float[]) Grafreed.clone(other.positions);
177
+ normals = (float[]) Grafreed.clone(other.normals);
178
+ colors = (float[]) Grafreed.clone(other.colors);
179
+ uvmap = (float[]) Grafreed.clone(other.uvmap);
180
+ triangles = (int[]) Grafreed.clone(other.triangles);
180181
181
- indices = (int[]) GrafreeD.clone(other.indices);
182
+ indices = (int[]) Grafreed.clone(other.indices);
182183
183
- vertices = (Vector<Vertex>) GrafreeD.clone(other.vertices);
184
- faces = (Vector<Face>) GrafreeD.clone(other.faces);
184
+ vertices = (Vector<Vertex>) Grafreed.clone(other.vertices);
185
+ faces = (Vector<Face>) Grafreed.clone(other.faces);
185186 }
186187 else
187188 {
....@@ -239,9 +240,16 @@
239240 }
240241 }
241242
242
- Support[] InitConnections(BoundaryRep other)
243
+ transient Support[] cachesupports = null;
244
+
245
+ Support[] InitConnections()
243246 {
244
- int n = other.startvertices.length-1;
247
+ if (cachesupports != null)
248
+ {
249
+ return cachesupports;
250
+ }
251
+
252
+ int n = this.startvertices.length-1;
245253
246254 Support[] supports = new Support[n];
247255
....@@ -253,38 +261,60 @@
253261
254262 for (int object=1; object<=n; object++)
255263 {
256
- int start = other.startvertices[object-1];
257
- int end = other.startvertices[object];
264
+ int start = this.startvertices[object-1];
265
+ int end = this.startvertices[object];
258266
259267 if (start == end)
260268 continue; // ??
261269
270
+ /**
271
+ Vertex v2 = vertextemp;
272
+ v2.x = averagepoints[object*3];
273
+ v2.y = averagepoints[object*3+1];
274
+ v2.z = averagepoints[object*3+2];
275
+
276
+ //v2.set(GetVertex(this.startvertices[subsupport]));
277
+
278
+ // projected point
279
+ Vertex v3 = vertextemp2;
280
+ //GetVertex(this.startvertices[subsupport]);
281
+ v3.x = extremepoints[object*3];
282
+ v3.y = extremepoints[object*3+1];
283
+ v3.z = extremepoints[object*3+2];
284
+
285
+ vect3.set(v3); // "X" axis apex
286
+ vect3.sub(v2); // origin (center)
287
+ vect3.normalize();
288
+ /**/
289
+
262290 int linkcount = 0;
263291
264292 int objectinlist = -1;
293
+
294
+ Support subsupport = supports[object-1];
265295
266296 for (int object2=1; object2<=n; object2++)
267297 {
268298 for (int i = start; i < end; i++)
269299 {
270
- Vertex v = other.GetVertex(i);
300
+ Vertex v = this.GetVertex(i);
271301
272
- //
273
- if (other.Contains(v, object2))
302
+ // Check if v is close enough from any vertex of the given subobject.
303
+ if (this.Contains(v, object2))
274304 {
275
- if (linkcount == supports[object-1].links.length)
305
+ if (linkcount == subsupport.links.length)
276306 break;
277307
278308 if (object2 == object)
279309 objectinlist = linkcount;
280310
281
- supports[object-1].links[linkcount++] = object2;
311
+ subsupport.links[linkcount++] = object2;
282312 break;
283313 }
284314 }
285315 }
286316
287
- supports[object-1].links[linkcount] = -1;
317
+ subsupport.links[linkcount] = -1;
288318
289319 if (objectinlist == -1)
290320 assert(objectinlist != -1);
....@@ -293,9 +323,9 @@
293323 // assert(linkcount > 1);
294324
295325 // show main support as blue
296
- int first = supports[object-1].links[0];
297
- supports[object-1].links[0] = supports[object-1].links[objectinlist];
298
- supports[object-1].links[objectinlist] = first;
326
+ int first = subsupport.links[0];
327
+ subsupport.links[0] = subsupport.links[objectinlist];
328
+ subsupport.links[objectinlist] = first;
299329 }
300330
301331 for (int loop = 0; --loop>=0;)
....@@ -353,7 +383,7 @@
353383 supports = supports2;
354384 }
355385
356
- return supports;
386
+ return cachesupports = supports;
357387 }
358388
359389 double Distance2(Vertex v, Vertex v2, double dist2beat, double[][] toRoot, int k)
....@@ -497,10 +527,10 @@
497527 return dist2;
498528 }
499529
500
- static Vertex vertextemp = new Vertex();
501
- static Vertex vertextemp2 = new Vertex();
530
+ static Vertex vertextemp = new Vertex(true);
531
+ static Vertex vertextemp2 = new Vertex(true);
502532
503
- static double SEUIL = 0.1; // 0.1 for rag doll; 0.07;
533
+ static double SEUIL = 0.05f; // 0.1 for rag doll; 0.07;
504534
505535 // Compute weight of point w/r to this
506536 float ComputeWeight(Vertex v, double[][] toRoot, int k)
....@@ -570,8 +600,10 @@
570600
571601 if (dot > distmax)
572602 dot = distmax;
603
+ //return 0; // patch for strange behavior
573604 if (dot < -distmax)
574605 dot = -distmax;
606
+ //return 0; // patch for strange behavior
575607
576608 // v3 = GetVertex(this.startvertices[subsupport] + 16);
577609 //
....@@ -596,7 +628,7 @@
596628 // ;
597629 //
598630
599
- supportsize = supportsizes[subsupport];
631
+ supportsize = supportminsize[subsupport];
600632
601633 double K = supportsize / distmax;
602634
....@@ -609,10 +641,12 @@
609641
610642 float dist2 = (float)Distance2(v, v2, 1E10, toRoot, k);
611643
612
- if (dist2 >= 2 * SEUIL*SEUIL) // && !CameraPane.CROWD) // weightmode
644
+ double seuil = SEUIL * 2;
645
+
646
+ if (dist2 >= 2 * seuil*seuil) // && !CameraPane.CROWD) // weightmode
613647 return 0;
614648
615
- dist2 /= 2 * SEUIL*SEUIL; // multiplied by two because center of support
649
+ dist2 /= 2 * seuil*seuil; // multiplied by two because center of support
616650 // could be far from closest point
617651
618652 // dist2 = Math.pow(dist2, 2);
....@@ -646,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) GrafreeD.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) GrafreeD.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,10 @@
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]
2002
+ // == 0)
2003
+ < 0.001 * v.totalweight)
19442004 {
19452005 //testweight += v.weights[j-1];
19462006 continue;
....@@ -2221,6 +2281,8 @@
22212281
22222282 transient int lastsoundtime;
22232283
2284
+ transient boolean once = false;
2285
+
22242286 void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked)
22252287 {
22262288 if (LA.isIdentity(toRoot))
....@@ -2276,7 +2338,11 @@
22762338
22772339 if (v.totalweight == 0)
22782340 {
2279
- System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2341
+ if (!once)
2342
+ {
2343
+ System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2344
+ once = true;
2345
+ }
22802346 continue;
22812347 }
22822348
....@@ -2635,18 +2701,18 @@
26352701 if (false) // slow && stepout && onein)
26362702 {
26372703 // sound
2638
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
2704
+ cVector eye = Globals.theRenderer.EyeCamera().location;
26392705
26402706 Vertex v = GetVertex(0);
26412707
26422708 tmp.set(v);
26432709 tmp.sub(eye);
26442710
2645
- if (CameraPane.framecount - lastsoundtime > 30) // 0.25 secs
2711
+ if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26462712 {
2647
- GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
2713
+ Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
26482714
2649
- lastsoundtime = CameraPane.framecount;
2715
+ lastsoundtime = Globals.framecount;
26502716 }
26512717
26522718 stepout = false;
....@@ -3072,6 +3138,7 @@
30723138 //
30733139 // transient VertexCompare[] vertexcompare = null;
30743140
3141
+ // Check if v0 is close enough from any vertex of the given subobject of this.
30753142 boolean Contains(Vertex v0, int object)
30763143 {
30773144 int start = startvertices[object-1];
....@@ -3129,7 +3196,27 @@
31293196 */
31303197 }
31313198
3132
- void GenUV()
3199
+ void UnfoldUV()
3200
+ {
3201
+ for (int i = 0; i < VertexCount(); i++)
3202
+ {
3203
+ Vertex v = GetVertex(i);
3204
+
3205
+ v.x = v.s;
3206
+ v.y = v.t;
3207
+ v.z = 0;
3208
+
3209
+ v.norm.x = 0;
3210
+ v.norm.y = 0;
3211
+ v.norm.z = 1;
3212
+
3213
+ SetVertex(v, i);
3214
+ }
3215
+ }
3216
+
3217
+ float power = 2;
3218
+
3219
+ void GenUV() // float power)
31333220 {
31343221 Trim();
31353222
....@@ -3193,6 +3280,125 @@
31933280 y -= 0.5;
31943281 z -= 0.5;
31953282
3283
+ double ax = Math.abs(x);
3284
+ double ay = Math.abs(y);
3285
+ double max = ax;
3286
+ if (max < ay)
3287
+ {
3288
+ max = ay;
3289
+ }
3290
+
3291
+ if (max == 0)
3292
+ {
3293
+ uvmap[i2] = 0.5f;
3294
+ uvmap[i2+1] = 0.5f;
3295
+ continue;
3296
+ }
3297
+
3298
+ x /= max;
3299
+ y /= max;
3300
+
3301
+ double angle = Math.acos(Math.abs(z*2));
3302
+
3303
+ double k = angle / Math.PI * 2;
3304
+
3305
+ assert(k >= 0);
3306
+
3307
+ // k == 0 => uv = 0 (center)
3308
+ // k == 1 => uv = -1,1 (border)
3309
+
3310
+ if (i == 0)
3311
+ System.out.println("power = " + power);
3312
+
3313
+ double length1 = (ax+ay)/max;
3314
+ double length2 = Math.sqrt(ax*ax + ay*ay) / max;
3315
+
3316
+ double t = k;
3317
+
3318
+ t = Math.pow(t, 3);
3319
+
3320
+ // Interpolate between k/length2 (center) and k (border)
3321
+ if (length2 > 0)
3322
+ k *= (1 - t) / length2 + t;
3323
+
3324
+ double u = k*x;
3325
+ double v = k*y;
3326
+
3327
+ u /= 2;
3328
+ v /= 2;
3329
+ u += 0.5;
3330
+ v += 0.5;
3331
+
3332
+ uvmap[i2] = (float) u;
3333
+ uvmap[i2+1] = (float) v;
3334
+ }
3335
+ }
3336
+
3337
+ void GenUVold(float power)
3338
+ {
3339
+ Trim();
3340
+
3341
+ cVector boxcenter = null;
3342
+ cVector minima, maxima;
3343
+ minima = new cVector();
3344
+ maxima = new cVector();
3345
+ minima.x = minima.y = minima.z = Double.MAX_VALUE;
3346
+ maxima.x = maxima.y = maxima.z = -Double.MAX_VALUE;
3347
+ for (int i = 0; i < VertexCount(); i++)
3348
+ {
3349
+ Vertex v = GetVertex(i);
3350
+
3351
+ if (minima.x > v.x)
3352
+ {
3353
+ minima.x = v.x;
3354
+ }
3355
+ if (minima.y > v.y)
3356
+ {
3357
+ minima.y = v.y;
3358
+ }
3359
+ if (minima.z > v.z)
3360
+ {
3361
+ minima.z = v.z;
3362
+ }
3363
+
3364
+ if (maxima.x < v.x)
3365
+ {
3366
+ maxima.x = v.x;
3367
+ }
3368
+ if (maxima.y < v.y)
3369
+ {
3370
+ maxima.y = v.y;
3371
+ }
3372
+ if (maxima.z < v.z)
3373
+ {
3374
+ maxima.z = v.z;
3375
+ }
3376
+ }
3377
+
3378
+ boxcenter = new cVector((maxima.x + minima.x) / 2, (maxima.y + minima.y) / 2, (maxima.z + minima.z) / 2);
3379
+ int i2 = 0, i3 = 0;
3380
+ for (int i = 0; i < positions.length/3; i++, i3 += 3, i2 += 2)
3381
+ {
3382
+// //uvmap[i2] = (float) normals[i3]*0.5f + 0.5f; // v.x;
3383
+// //uvmap[i2 + 1] = (float) normals[i3+1]*0.5f + 0.5f; //z;
3384
+// uvmap[i2] = (float) (positions[i3] - boxcenter.x);
3385
+// uvmap[i2 + 1] = (float) (positions[i3+2] - boxcenter.z);
3386
+// uvmap[i2] = (float) Math.atan2(positions[i3+1] - boxcenter.y, positions[i3] - boxcenter.x);
3387
+// uvmap[i2 + 1] = (float)(positions[i3+2] - boxcenter.z);
3388
+ // box UV
3389
+ double x = positions[i3] - minima.x; // - Math.floor(positions[i3]);
3390
+ double y = positions[i3+1] - minima.y; // - Math.floor(positions[i3+1]);
3391
+ double z = positions[i3+2] - minima.z; // - Math.floor(positions[i3+2]);
3392
+
3393
+ // [-1/2, 1/2]
3394
+ x /= maxima.x - minima.x;
3395
+ y /= maxima.y - minima.y;
3396
+ z /= maxima.z - minima.z;
3397
+
3398
+ x -= 0.5;
3399
+ y -= 0.5;
3400
+ z -= 0.5;
3401
+
31963402 // x *= 2;
31973403 // y *= 2;
31983404 // z *= 2;
....@@ -3219,6 +3425,15 @@
32193425
32203426 z = Math.cos(angle/2);
32213427
3428
+ assert(z >= 0);
3429
+ assert(z <= 1);
3430
+
3431
+ /**/
3432
+ //z = Math.pow(z, power); //1.08f);
3433
+
3434
+ if (i == 0)
3435
+ System.out.println("power = " + power);
3436
+
32223437 // sqrt(k2*x2 + k2*z2 + y2) = length
32233438 // k2*x2 + k2*z2 = length2 - y2
32243439 // k2 = (length2 - y2) / (x2 + z2)
....@@ -3229,7 +3444,7 @@
32293444 k /= x*x + y*y;
32303445 }
32313446 else
3232
- GrafreeD.Assert(z == 1);
3447
+ Grafreed.Assert(z == 1);
32333448
32343449 if (k < 0)
32353450 k = 0;
....@@ -3238,6 +3453,7 @@
32383453
32393454 x *= k;
32403455 y *= k;
3456
+ /**/
32413457
32423458 double max = Math.abs(x);
32433459 if (max < Math.abs(y))
....@@ -3250,10 +3466,15 @@
32503466 }
32513467
32523468 // max = Math.sqrt(max*2)/2;
3469
+// double x2 = Math.pow(Math.abs(x), 1/power);
3470
+// double y2 = Math.pow(Math.abs(y), 1/power);
3471
+// double z2 = Math.pow(Math.abs(z), 1/power);
3472
+// max = Math.pow(x2 + y2 + z2, power);
32533473
32543474 // if (!(max > 0))
3255
- assert(max > 0);
3256
-
3475
+ //assert(max > 0);
3476
+ assert(max >= 0);
3477
+
32573478 x /= max;
32583479 y /= max;
32593480 z /= max;
....@@ -3516,6 +3737,111 @@
35163737 */
35173738 }
35183739
3740
+ void GenerateNormals2(boolean crease)
3741
+ {
3742
+ cVector tempVector = new cVector();
3743
+
3744
+// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>();
3745
+//
3746
+//
3747
+// for (int i=0; i<this.VertexCount(); i++)
3748
+// {
3749
+// Vertex v = this.GetVertex(i);
3750
+//
3751
+// tempVector.set(v);
3752
+//
3753
+// cVector n = tableBase.get(tempVector.ToFloat());
3754
+//
3755
+// if (n != null)
3756
+// {
3757
+// continue;
3758
+// }
3759
+//
3760
+// tableBase.put(new cVector(tempVector), new cVector(v.norm));
3761
+// }
3762
+
3763
+ BoundaryRep tempSupport = this.support;
3764
+
3765
+ this.support = null;
3766
+
3767
+ BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this);
3768
+
3769
+ this.support = tempSupport;
3770
+
3771
+ //tempRep.Unstripify();
3772
+
3773
+ tempRep.GenerateNormals2(crease);
3774
+
3775
+ boolean keepnormal = Vertex.normalmode;
3776
+ boolean epsequal = Grafreed.epsequal;
3777
+
3778
+ Vertex.normalmode = false;
3779
+ Grafreed.epsequal = false; // A bit strange
3780
+
3781
+ // No need to have a match for vertex counts.
3782
+
3783
+ java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>();
3784
+
3785
+ for (int i=0; i<tempRep.VertexCount(); i++)
3786
+ {
3787
+ Vertex v = tempRep.GetVertex(i);
3788
+
3789
+ cVector n = table.get(tempVector.ToFloat());
3790
+
3791
+ if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0)
3792
+ {
3793
+ //continue;
3794
+ }
3795
+
3796
+ tempVector.set(v);
3797
+
3798
+ //cVector nBase = tableBase.get(tempVector);
3799
+
3800
+ //if (v.norm.dot(nBase) < 0.9)
3801
+ //{
3802
+ // continue;
3803
+ //}
3804
+
3805
+ if (n != null && n.x == 1 && n.y == 0 && n.z == 0)
3806
+ {
3807
+ //continue;
3808
+ }
3809
+
3810
+ if (n != null)
3811
+ {
3812
+// if (n.dot(v.norm) < 0)
3813
+// n.sub(v.norm);
3814
+// else
3815
+// n.add(v.norm);
3816
+//
3817
+// n.normalize();
3818
+ continue;
3819
+ }
3820
+
3821
+ table.put(new cVector(tempVector), new cVector(v.norm));
3822
+ }
3823
+
3824
+ for (int i=0; i<this.VertexCount(); i++)
3825
+ {
3826
+ Vertex v = this.GetVertex(i);
3827
+
3828
+ tempVector.set(v);
3829
+
3830
+ cVector n = table.get(tempVector.ToFloat());
3831
+
3832
+ //if (n.dot(v.norm) < 0)
3833
+ if (n == null)
3834
+ continue;
3835
+
3836
+ LA.vecCopy(n, v.norm);
3837
+
3838
+ this.SetVertex(v, i);
3839
+ }
3840
+
3841
+ Grafreed.epsequal = epsequal;
3842
+ Vertex.normalmode = keepnormal;
3843
+ }
3844
+
35193845 void GenerateNormals(boolean crease)
35203846 {
35213847 boolean wastrim = trimmed;
....@@ -3532,6 +3858,28 @@
35323858 }
35333859
35343860 Trim(true/*wastrim*/,true,crease,wasstrip,false);
3861
+ }
3862
+
3863
+ void GenerateNormalsMesh()
3864
+ {
3865
+ if (stripified)
3866
+ {
3867
+ Unstripify();
3868
+ }
3869
+
3870
+ if (trimmed)
3871
+ {
3872
+ normals = null;
3873
+ }
3874
+ else
3875
+ {
3876
+ for (int i=VertexCount(); --i>=0;)
3877
+ {
3878
+ Vertex v = GetVertex(i);
3879
+
3880
+ v.norm = null;
3881
+ }
3882
+ }
35353883 }
35363884
35373885 void GenNormalsJME()
....@@ -3656,7 +4004,7 @@
36564004 NormalGenerator ng;
36574005
36584006 if (crease)
3659
- ng = new NormalGenerator(Math.PI/6); // default is 44 degrees (or Math.PI/3); // /4);
4007
+ ng = new NormalGenerator(Math.PI/4); // default is 44 degrees (or Math.PI/3); // /4);
36604008 else
36614009 ng = new NormalGenerator(Math.PI); // (Math.PI / 3); // /4);
36624010
....@@ -3689,6 +4037,10 @@
36894037 {
36904038 triangles[i] = i;
36914039 }
4040
+
4041
+// Untrim();
4042
+ if (!trimmed)
4043
+ MergeNormals();
36924044 }
36934045 }
36944046
....@@ -3722,6 +4074,11 @@
37224074 tsa.getNormals(0, normals);
37234075 tsa.getTextureCoordinates(0, 0, uvmap);
37244076 // tsa.getColors(0, colors);
4077
+
4078
+ for (int i=colors.length; --i>=0;)
4079
+ {
4080
+ colors[i] = 1;
4081
+ }
37254082
37264083 int stripcount = tsa.getNumStrips();
37274084 triangles = new int[stripcount];
....@@ -3744,6 +4101,10 @@
37444101 triangles = new int[1];
37454102 triangles[0] = 3;
37464103 }
4104
+
4105
+ //Untrim();
4106
+ if (!trimmed)
4107
+ MergeNormals();
37474108 }
37484109
37494110 /*
....@@ -3776,21 +4137,66 @@
37764137 for (int i = 0; i < VertexCount(); i++)
37774138 {
37784139 Vertex v = GetVertex(i);
4140
+
4141
+ vertextemp.set(v);
4142
+
37794143 //if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
37804144 {
3781
- GenerateNormal(i, v);
3782
- SetVertex(v, i);
4145
+ if (!GenerateNormal(i, vertextemp))
4146
+ continue;
4147
+
4148
+ if (v.norm.dot(vertextemp.norm) < 0)
4149
+ vertextemp.norm.mul(-1);
4150
+
4151
+ if (v.norm.dot(vertextemp.norm) < 0.9)
4152
+ SetVertex(vertextemp, i);
37834153 }
37844154 }
37854155
37864156 Vertex.normalmode = false;
37874157 }
37884158
4159
+ void MergeNormals()
4160
+ {
4161
+ assert(!trimmed);
4162
+
4163
+ boolean smooth = Grafreed.smoothmode;
4164
+ boolean link = Grafreed.linkUV;
4165
+ Grafreed.smoothmode = true;
4166
+ Grafreed.linkUV = true;
4167
+
4168
+ System.out.println("#Vertex = " + VertexCount());
4169
+ System.out.println("#Face = " + FaceCount());
4170
+
4171
+ java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>();
4172
+
4173
+ for (int i = 0; i < VertexCount(); i++)
4174
+ {
4175
+ Vertex v = GetVertex(i);
4176
+
4177
+ if (!table.contains(v))
4178
+ {
4179
+ table.add(v);
4180
+ }
4181
+ }
4182
+
4183
+ Grafreed.smoothmode = smooth;
4184
+ Grafreed.linkUV = link;
4185
+
4186
+// for (int i = 0; i < VertexCount(); i++)
4187
+// {
4188
+// Vertex v = GetVertex(i);
4189
+//
4190
+// table.add(v);
4191
+// }
4192
+
4193
+ }
4194
+
37894195 static cVector temp1 = new cVector();
37904196 static cVector temp2 = new cVector();
37914197 static cVector temp3 = new cVector();
37924198
3793
- void GenerateNormal(int index, Vertex v)
4199
+ boolean GenerateNormal(int index, Vertex v)
37944200 {
37954201 //System.out.println("Old normal = " + v.norm);
37964202 LA.setVector(v.norm, 0, 0, 0);
....@@ -3819,6 +4225,10 @@
38194225 LA.vecSub(p/*.pos*/, v/*.pos*/, temp1);
38204226 LA.vecSub(q/*.pos*/, v/*.pos*/, temp2);
38214227 }
4228
+ else
4229
+ {
4230
+ continue;
4231
+ }
38224232
38234233 //LA.vecNormalize(temp1);
38244234 //LA.vecNormalize(temp2);
....@@ -3829,17 +4239,25 @@
38294239 double s = temp3.length();
38304240 //double c = temp2.dot(temp1);
38314241
4242
+ if (s == 0)
4243
+ return false;
4244
+
38324245 float angle = 1; // (float) Math.atan2(s, c);
38334246 //if(angle < 0) angle = -angle;
38344247
38354248 //LA.vecNormalize(temp3);
38364249 LA.vecScale(temp3, angle / s);
38374250
4251
+// if (temp3.dot(v.norm) < 0)
4252
+// assert(temp3.dot(v.norm) >= 0);
4253
+
38384254 LA.vecAdd(temp3, v.norm, v.norm);
38394255 }
38404256
38414257 LA.vecNormalize(v.norm);
38424258 //System.out.println("New normal = " + v.norm);
4259
+
4260
+ return true;
38434261 }
38444262
38454263 double Arccos(double x)
....@@ -4381,7 +4799,7 @@
43814799 }
43824800 }
43834801
4384
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4802
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
43854803 {
43864804 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
43874805 CameraPane.tempmat,0, CameraPane.tempmat2,0,
....@@ -4413,14 +4831,14 @@
44134831 // june 2014
44144832 // Camera parentcam = cam;
44154833 //
4416
-// if (cam == CameraPane.theRenderer.cameras[0])
4834
+// if (cam == Globals.theRenderer.cameras[0])
44174835 // {
4418
-// parentcam = CameraPane.theRenderer.cameras[1];
4836
+// parentcam = Globals.theRenderer.cameras[1];
44194837 // }
44204838 //
4421
-// if (cam == CameraPane.theRenderer.cameras[1])
4839
+// if (cam == Globals.theRenderer.cameras[1])
44224840 // {
4423
-// parentcam = CameraPane.theRenderer.cameras[0];
4841
+// parentcam = Globals.theRenderer.cameras[0];
44244842 // }
44254843
44264844 gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0);
....@@ -4546,16 +4964,25 @@
45464964 {
45474965 i3 = positions.length-3;
45484966 i2 = uvmap.length - 2;
4549
- new Exception().printStackTrace();
4967
+ //new Exception().printStackTrace();
45504968 }
45514969
45524970 v./*pos.*/x = positions[i3];
45534971 v./*pos.*/y = positions[i3 + 1];
45544972 v./*pos.*/z = positions[i3 + 2];
45554973
4556
- v.norm.x = normals[i3];
4557
- v.norm.y = normals[i3 + 1];
4558
- v.norm.z = normals[i3 + 2];
4974
+ if (normals == null)
4975
+ {
4976
+ v.norm.x = 0;
4977
+ v.norm.y = 0;
4978
+ v.norm.z = 0;
4979
+ }
4980
+ else
4981
+ {
4982
+ v.norm.x = normals[i3];
4983
+ v.norm.y = normals[i3 + 1];
4984
+ v.norm.z = normals[i3 + 2];
4985
+ }
45594986
45604987 v.s = uvmap[i2];
45614988 v.t = uvmap[i2 + 1];
....@@ -4846,7 +5273,7 @@
48465273 return verticesCopy;
48475274 }
48485275
4849
- void PreprocessOcclusion(CameraPane cp, double[][] transform)
5276
+ void PreprocessOcclusion(iCameraPane cp, double[][] transform)
48505277 {
48515278 if (//!trimmed ||
48525279 AOdone)
....@@ -4855,80 +5282,7 @@
48555282 return;
48565283 }
48575284
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;
5285
+ cp.PrepOcclusion(this, transform);
49325286
49335287 AOdone = true;
49345288 }
....@@ -5343,17 +5697,27 @@
53435697
53445698 transient int nbbadfaces; // ?? = 1000000;
53455699
5346
- int ChooseTriangle()
5700
+ /*
5701
+ */
5702
+ int ChooseTriangle(boolean firstEquilateral)
53475703 {
53485704 int chosen = -1;
53495705
53505706 double minweight = 1E10;
53515707
5708
+ int step = 8; // ?
5709
+
5710
+ if (firstEquilateral)
5711
+ step = 1;
5712
+
53525713 nbbadfaces = 0;
5353
- for (int i=0; i<faces.size(); i+=8)
5714
+ for (int i=0; i<faces.size(); i+=step)
53545715 // for (int i=faces.size(); (i-=8)>=0;)
53555716 {
53565717 Face face = (Face) faces.get(i);
5718
+
5719
+ if (face.used)
5720
+ continue;
53575721
53585722 if (!Valid(face))
53595723 {
....@@ -5363,6 +5727,15 @@
53635727
53645728 if (Boundary(face))
53655729 continue;
5730
+
5731
+// if (Boundary(face.p))
5732
+// continue;
5733
+//
5734
+// if (Boundary(face.q))
5735
+// continue;
5736
+//
5737
+// if (Boundary(face.r))
5738
+// continue;
53665739
53675740 if (!ValidValence(face))
53685741 continue;
....@@ -5375,22 +5748,55 @@
53755748 //?? if (face.weight < 0)
53765749 // continue;
53775750
5378
- double K = 1; // 0.01; // .25;
5379
-
5380
- double factor = (1-K)*face.nbiterations + K; //*face.weight;
5381
-
5382
- double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5383
-
5384
- if (minweight > weight)
5751
+ if (firstEquilateral)
53855752 {
5386
- minweight = weight;
5753
+ if (OneFaceUsed(links.get(face.p)))
5754
+ continue;
5755
+
5756
+ if (OneFaceUsed(links.get(face.q)))
5757
+ continue;
5758
+
5759
+ if (OneFaceUsed(links.get(face.r)))
5760
+ continue;
5761
+
53875762 chosen = i;
5388
- if (minweight == 0)
5389
- break;
5763
+ break;
5764
+ }
5765
+ else
5766
+ {
5767
+ double K = 1; // 0.01; // .25;
5768
+
5769
+ double factor = (1-K)*face.nbiterations + K; //*face.weight;
5770
+
5771
+ double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5772
+
5773
+ if (minweight > weight)
5774
+ {
5775
+ minweight = weight;
5776
+ chosen = i;
5777
+ if (minweight == 0)
5778
+ break;
5779
+ }
53905780 }
53915781 }
53925782
53935783 return chosen;
5784
+ }
5785
+
5786
+ private boolean OneFaceUsed(Vector<Face> faces)
5787
+ {
5788
+ if (faces.size() != 6)
5789
+ return true;
5790
+
5791
+ for (int i=0; i<6; i+=1)
5792
+ {
5793
+ if (faces.get(i).used)
5794
+ {
5795
+ return true;
5796
+ }
5797
+ }
5798
+
5799
+ return false;
53945800 }
53955801
53965802 static boolean remove3valence = true;
....@@ -5426,7 +5832,7 @@
54265832 }
54275833 else
54285834 {
5429
- assert(links.size() == vertices.size());
5835
+ // TODO Grafreed.Assert(links.size() == vertices.size());
54305836
54315837 links.setSize(vertices.size());
54325838 for (int i=vertices.size(); --i>=0;)
....@@ -5434,6 +5840,7 @@
54345840 // linkstouched[i] = false;
54355841 if (links.get(i) == null) // ??
54365842 {
5843
+ new Exception().printStackTrace();
54375844 links.set(i, new Vector(8));
54385845 // linkstouched[i] = true;
54395846 }
....@@ -5444,6 +5851,8 @@
54445851 }
54455852 }
54465853
5854
+ boolean once = false;
5855
+
54475856 for (int i=faces.size(); --i>=0;)
54485857 {
54495858 Face face = (Face) faces.get(i);
....@@ -5455,6 +5864,9 @@
54555864 //if (linkstouched[face.r])
54565865 links.get(face.r).add(face);
54575866
5867
+ if (face.used)
5868
+ once = true;
5869
+
54585870 face.good = 1;
54595871 face.boundary = -1;
54605872 }
....@@ -6226,6 +6638,7 @@
62266638
62276639 void InitWeights()
62286640 {
6641
+ new Exception().printStackTrace();
62296642 System.exit(0);
62306643 int n = 0;
62316644 int b = 0;
....@@ -6819,6 +7232,10 @@
68197232 return (face.boundary = 1) == 1;
68207233 }
68217234
7235
+ // June 2019
7236
+ if (true)
7237
+ return (face.boundary = 0) == 1;
7238
+
68227239 // reverse triangle test
68237240 q1.set(p);
68247241 q2.set(q);
....@@ -7075,6 +7492,7 @@
70757492 assert(f2.contains(i));
70767493 assert(f3.contains(i));
70777494
7495
+ // when r is the "center", p is along the boundary
70787496 while (f0.r != i)
70797497 {
70807498 int t = f0.p;
....@@ -7131,59 +7549,90 @@
71317549 f0 = f3;
71327550 f3 = t;
71337551 }
7134
- atleastone = true;
71357552
7553
+ int va = f0.q;
7554
+ int vb = f0.r;
7555
+ int vc = -1;
7556
+
7557
+ Face toremove1 = null;
7558
+ Face toremove2 = null;
7559
+
7560
+ // f0 is the buffer for the first new triangle,
7561
+ // and otherf is the other upper one.
71367562 Face otherf = null;
71377563
71387564 if (f1.contains(f0.p))
71397565 {
71407566 if (f1.p == f0.p)
71417567 {
7568
+ assert(false);
71427569 f0.r = f1.q;
71437570 }
71447571 else
71457572 {
71467573 assert(f1.q == f0.p);
7147
- f0.r = f1.p;
7574
+ vc = f1.p;
71487575 }
71497576
71507577 otherf = f2;
7151
- faces.remove(f1);
7152
- faces.remove(f3);
7578
+ toremove1 = f1;
7579
+ toremove2 = f3;
71537580 }
71547581 else
71557582 if (f2.contains(f0.p))
71567583 {
71577584 if (f2.p == f0.p)
71587585 {
7586
+ assert(false);
71597587 f0.r = f2.q;
71607588 }
71617589 else
71627590 {
71637591 assert(f2.q == f0.p);
7164
- f0.r = f2.p;
7592
+ vc = f2.p;
71657593 }
71667594
71677595 otherf = f3;
7168
- faces.remove(f1);
7169
- faces.remove(f2);
7596
+ toremove1 = f1;
7597
+ toremove2 = f2;
71707598 }
71717599 if (f3.contains(f0.p))
71727600 {
71737601 if (f3.p == f0.p)
71747602 {
7603
+// assert(false);
7604
+ new Exception().printStackTrace();
71757605 f0.r = f3.q;
71767606 }
71777607 else
71787608 {
71797609 assert(f3.q == f0.p);
7180
- f0.r = f3.p;
7610
+ vc = f3.p;
71817611 }
71827612
71837613 otherf = f1;
7184
- faces.remove(f2);
7185
- faces.remove(f3);
7614
+ toremove1 = f2;
7615
+ toremove2 = f3;
71867616 }
7617
+
7618
+ vertextemp.set(vertices.get(va));
7619
+ vertextemp.sub(vertices.get(vb));
7620
+ vertextemp.normalize();
7621
+ vertextemp2.set(vertices.get(vc));
7622
+ vertextemp2.sub(vertices.get(vb));
7623
+ vertextemp2.normalize();
7624
+
7625
+ if (vertextemp.dot(vertextemp2) > -0.95)
7626
+ {
7627
+ continue;
7628
+ }
7629
+
7630
+ atleastone = true;
7631
+
7632
+ f0.r = vc;
7633
+
7634
+ faces.remove(toremove1);
7635
+ faces.remove(toremove2);
71877636
71887637 if (!f0.contains(otherf.p))
71897638 {
....@@ -7236,7 +7685,7 @@
72367685 //InitWeights();
72377686 }
72387687
7239
- int chosen = ChooseTriangle(); // Best is slow and not really better
7688
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
72407689
72417690 if (chosen == -1)
72427691 {
....@@ -7250,7 +7699,7 @@
72507699 //remove3valence = false;
72517700 // InitWeights();
72527701
7253
- chosen = ChooseTriangle();
7702
+ chosen = ChooseTriangle(true);
72547703 }
72557704 }
72567705
....@@ -7526,7 +7975,7 @@
75267975
75277976 // boolean lock;
75287977
7529
- void SplitInTwo(boolean reduction34, boolean onlyone)
7978
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
75307979 {
75317980 if (stripified)
75327981 {
....@@ -7554,7 +8003,7 @@
75548003 s3 = new cVector();
75558004 }
75568005
7557
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
8006
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
75588007
75598008 try
75608009 {
....@@ -7563,12 +8012,12 @@
75638012 {
75648013 System.err.println("EXCEPTION CAUGHT");
75658014 e.printStackTrace();
7566
- return;
8015
+ return false;
75678016 } catch (Error e)
75688017 {
75698018 System.err.println("ERROR CAUGHT");
75708019 e.printStackTrace();
7571
- return;
8020
+ return false;
75728021 }
75738022
75748023 System.out.println("# faces = " + faces.size());
....@@ -7578,6 +8027,7 @@
75788027 {
75798028 Face face = (Face) faces.get(i);
75808029
8030
+ face.used = false;
75818031 face.nbiterations = 1;
75828032 face.weight = -1;
75838033 face.boundary = -1;
....@@ -7629,6 +8079,11 @@
76298079 nbbadfaces = faces.size();
76308080 //remove3valence = true;
76318081
8082
+ int count = 2;
8083
+
8084
+ if (onlyone)
8085
+ count = 1;
8086
+
76328087 firstpass = true;
76338088
76348089 int n = faces.size();
....@@ -7644,12 +8099,13 @@
76448099 System.out.print('.');
76458100 }
76468101 System.out.println();
8102
+ boolean atleastone = false;
76478103 int i = 0;
7648
- while (reduction34 || faces.size() > n/2)
8104
+ while (true) // reduction34 || faces.size() > n/2)
76498105 {
76508106 if (i++%100 == 0)
76518107 {
7652
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
8108
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
76538109 System.out.println("#faces = " + faces.size());
76548110 // if (i != 1)
76558111 // break;
....@@ -7667,6 +8123,8 @@
76678123 {
76688124 if (!RemoveOneTriangle())
76698125 break;
8126
+
8127
+ atleastone = true;
76708128 }
76718129 // if (iterationcount == 0)
76728130 // break;
....@@ -7677,8 +8135,8 @@
76778135 break;
76788136 }
76798137 firstpass = false;
7680
- if (onlyone)
7681
- break; // one triangle only
8138
+// if (--count<0 && !reduction34)
8139
+// break; // one triangle only
76828140 }
76838141
76848142 InitLinks(false); // for further display
....@@ -7693,7 +8151,9 @@
76938151 //Trim(true,cJME.gennormals,true,false); // doesn't work
76948152 Trim(true,false,false,false,false);
76958153
7696
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8154
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8155
+
8156
+ return atleastone;
76978157 }
76988158
76998159 void UpdateIndices(Face face, Face minface)
....@@ -7706,18 +8166,21 @@
77068166 face.p = minface.p;
77078167 //if (leafweights)
77088168 face.good = 0; // false;
8169
+ face.used = true;
77098170 }
77108171 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
77118172 {
77128173 face.q = minface.p;
77138174 //if (leafweights)
77148175 face.good = 0; // false;
8176
+ face.used = true;
77158177 }
77168178 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
77178179 {
77188180 face.r = minface.p;
77198181 //if (leafweights)
77208182 face.good = 0; // false;
8183
+ face.used = true;
77218184 }
77228185
77238186 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7777,50 +8240,50 @@
77778240 if (v == 2)
77788241 vert = minface.r;
77798242 // Face face = (Face) faces.get(i);
7780
- Vector<Face> vertfaces = links.get(vert);
7781
- for (int i=vertfaces.size(); --i>=0;)
7782
- {
7783
- Face face = (Face) vertfaces.get(i);
7784
-
7785
- // if (face.weight == 10000)
7786
- // continue;
7787
-
7788
- if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
7789
- face.p == minface.q || face.q == minface.q || face.r == minface.q ||
7790
- face.p == minface.r || face.q == minface.r || face.r == minface.r)
8243
+ Vector<Face> vertfaces = links.get(vert);
8244
+ for (int i=vertfaces.size(); --i>=0;)
77918245 {
7792
- if (!leafweights)
8246
+ Face face = (Face) vertfaces.get(i);
8247
+
8248
+ // if (face.weight == 10000)
8249
+ // continue;
8250
+
8251
+ if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
8252
+ face.p == minface.q || face.q == minface.q || face.r == minface.q ||
8253
+ face.p == minface.r || face.q == minface.r || face.r == minface.r)
77938254 {
7794
-// if(minfaceweight <= 0)
7795
-// assert(minfaceweight > 0);
7796
-//
7797
-// //FaceWeight(face);
7798
-// if(face.weight < 0)
7799
-// assert(face.weight >= 0);
7800
-
7801
- face.weight += minfaceweight;
7802
-
7803
-// if (face.weight >= 10000)
7804
-// assert(face.weight < 10000);
8255
+ if (!leafweights)
8256
+ {
8257
+ // if(minfaceweight <= 0)
8258
+ // assert(minfaceweight > 0);
8259
+ //
8260
+ // //FaceWeight(face);
8261
+ // if(face.weight < 0)
8262
+ // assert(face.weight >= 0);
8263
+
8264
+ face.weight += minfaceweight;
8265
+
8266
+ // if (face.weight >= 10000)
8267
+ // assert(face.weight < 10000);
8268
+ }
8269
+ else
8270
+ face.weight = -1;
8271
+
8272
+ face.nbiterations += 1;
8273
+ face.boundary = -1;
8274
+
8275
+ Vertex p = (Vertex)vertices.get(face.p);
8276
+ Vertex q = (Vertex)vertices.get(face.q);
8277
+ Vertex r = (Vertex)vertices.get(face.r);
8278
+
8279
+ p.boundary = -1;
8280
+ q.boundary = -1;
8281
+ r.boundary = -1;
78058282 }
78068283 else
7807
- face.weight = -1;
7808
-
7809
- face.nbiterations += 1;
7810
- face.boundary = -1;
7811
-
7812
- Vertex p = (Vertex)vertices.get(face.p);
7813
- Vertex q = (Vertex)vertices.get(face.q);
7814
- Vertex r = (Vertex)vertices.get(face.r);
7815
-
7816
- p.boundary = -1;
7817
- q.boundary = -1;
7818
- r.boundary = -1;
8284
+ assert(false);
78198285 }
7820
- else
7821
- assert(false);
78228286 }
7823
- }
78248287
78258288 // TouchVertex(minface.p);
78268289 // TouchVertex(minface.q);
....@@ -8021,6 +8484,7 @@
80218484 for (int i=vertfaces.size(); --i>=0;)
80228485 {
80238486 Face face = (Face) vertfaces.get(i);
8487
+ face.used = true;
80248488 face.good = 0; // false;
80258489 if (leafweights)
80268490 face.weight = -1;
....@@ -8067,7 +8531,7 @@
80678531 if (!trimmed)
80688532 return;
80698533
8070
- GrafreeD.linkUV = false;
8534
+ Grafreed.linkUV = false;
80718535
80728536 try
80738537 {
....@@ -8275,9 +8739,6 @@
82758739 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
82768740 }
82778741
8278
- static Camera localcamera = new Camera();
8279
- static cVector from = new cVector();
8280
- static cVector to = new cVector();
82818742 boolean trimmed = false;
82828743 boolean stripified = false;
82838744 transient boolean AOdone = false;
....@@ -8285,8 +8746,10 @@
82858746 /*transient*/ int maxIndexV = 0;
82868747 /*transient*/ int bufV, bufF;
82878748 // Raw version
8288
- private float[] positions;
8289
- private float[] normals;
8749
+ //private
8750
+ float[] positions;
8751
+ //private
8752
+ float[] normals;
82908753 float[] colors;
82918754 private float[] uvmap;
82928755 private int[] triangles;
....@@ -8300,7 +8763,8 @@
83008763 int[] startvertices;
83018764 float[] averagepoints;
83028765 float[] extremepoints;
8303
- float[] supportsizes; // distance of closest point
8766
+ float[] supportminsize; // distance of closest point
8767
+ float[] supportmaxsize; // distance of fartest point
83048768
83058769 transient Hashtable vertextable;
83068770 /*transient*/ private Vertex[] verticesCopy;