Normand Briere
2019-08-15 33504fc9a180903aace77613264550754fba5706
BoundaryRep.java
....@@ -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)
....@@ -500,7 +530,7 @@
500530 static Vertex vertextemp = new Vertex(true);
501531 static Vertex vertextemp2 = new Vertex(true);
502532
503
- static double SEUIL = 0.1f; // 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)
....@@ -598,7 +628,7 @@
598628 // ;
599629 //
600630
601
- supportsize = supportsizes[subsupport];
631
+ supportsize = supportminsize[subsupport];
602632
603633 double K = supportsize / distmax;
604634
....@@ -650,7 +680,8 @@
650680 // if (supportsize * fadefactor > 1)
651681 // return 1;
652682
653
- return supportsize * fadefactor;
683
+ return //supportsize *
684
+ supportsize * fadefactor;
654685 }
655686
656687 void RecomputeBasis(BoundaryRep other, double[][] toRoot, Vertex v)
....@@ -952,7 +983,7 @@
952983
953984 // sept 2017 SEUIL = 0.1; // aout 2013
954985
955
- supports = InitConnections(other);
986
+ supports = other.InitConnections();
956987
957988 other.supports = supports; // should be the other way around...
958989
....@@ -1518,7 +1549,7 @@
15181549 InitFaceIndices();
15191550 }
15201551
1521
- BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
1552
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15221553 //float[] v = new float[100];
15231554
15241555 for (int loops=1; --loops>=0;)
....@@ -1548,7 +1579,7 @@
15481579 InitFaceIndices();
15491580 }
15501581
1551
- BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
1582
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15521583 //float[] v = new float[100];
15531584
15541585 for (int loops=10; --loops>=0;)
....@@ -1895,7 +1926,7 @@
18951926 return;
18961927 }
18971928
1898
- // System.exit(0);
1929
+ // System.exit(0);
18991930
19001931 cVector vect = new cVector();
19011932 cVector normal = new cVector();
....@@ -1966,7 +1997,10 @@
19661997 if (v.vertexlinks == null)
19671998 continue;
19681999
1969
- 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)
19702004 {
19712005 //testweight += v.weights[j-1];
19722006 continue;
....@@ -2247,6 +2281,8 @@
22472281
22482282 transient int lastsoundtime;
22492283
2284
+ transient boolean once = false;
2285
+
22502286 void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked)
22512287 {
22522288 if (LA.isIdentity(toRoot))
....@@ -2302,7 +2338,11 @@
23022338
23032339 if (v.totalweight == 0)
23042340 {
2305
- 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
+ }
23062346 continue;
23072347 }
23082348
....@@ -2670,7 +2710,7 @@
26702710
26712711 if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26722712 {
2673
- 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);
26742714
26752715 lastsoundtime = Globals.framecount;
26762716 }
....@@ -3098,6 +3138,7 @@
30983138 //
30993139 // transient VertexCompare[] vertexcompare = null;
31003140
3141
+ // Check if v0 is close enough from any vertex of the given subobject of this.
31013142 boolean Contains(Vertex v0, int object)
31023143 {
31033144 int start = startvertices[object-1];
....@@ -3155,7 +3196,27 @@
31553196 */
31563197 }
31573198
3158
- 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)
31593220 {
31603221 Trim();
31613222
....@@ -3219,6 +3280,125 @@
32193280 y -= 0.5;
32203281 z -= 0.5;
32213282
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
+
32223402 // x *= 2;
32233403 // y *= 2;
32243404 // z *= 2;
....@@ -3245,6 +3425,15 @@
32453425
32463426 z = Math.cos(angle/2);
32473427
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
+
32483437 // sqrt(k2*x2 + k2*z2 + y2) = length
32493438 // k2*x2 + k2*z2 = length2 - y2
32503439 // k2 = (length2 - y2) / (x2 + z2)
....@@ -3255,7 +3444,7 @@
32553444 k /= x*x + y*y;
32563445 }
32573446 else
3258
- GrafreeD.Assert(z == 1);
3447
+ Grafreed.Assert(z == 1);
32593448
32603449 if (k < 0)
32613450 k = 0;
....@@ -3264,6 +3453,7 @@
32643453
32653454 x *= k;
32663455 y *= k;
3456
+ /**/
32673457
32683458 double max = Math.abs(x);
32693459 if (max < Math.abs(y))
....@@ -3276,10 +3466,15 @@
32763466 }
32773467
32783468 // 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);
32793473
32803474 // if (!(max > 0))
3281
- assert(max > 0);
3282
-
3475
+ //assert(max > 0);
3476
+ assert(max >= 0);
3477
+
32833478 x /= max;
32843479 y /= max;
32853480 z /= max;
....@@ -3542,6 +3737,111 @@
35423737 */
35433738 }
35443739
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
+
35453845 void GenerateNormals(boolean crease)
35463846 {
35473847 boolean wastrim = trimmed;
....@@ -3558,6 +3858,28 @@
35583858 }
35593859
35603860 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
+ }
35613883 }
35623884
35633885 void GenNormalsJME()
....@@ -3682,7 +4004,7 @@
36824004 NormalGenerator ng;
36834005
36844006 if (crease)
3685
- 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);
36864008 else
36874009 ng = new NormalGenerator(Math.PI); // (Math.PI / 3); // /4);
36884010
....@@ -3700,8 +4022,6 @@
37004022 //System.out.println("NEW = " + positions.length);
37014023 uvmap = new float[ta.getVertexCount() * 2];
37024024
3703
- colors = new float[ta.getVertexCount()]; // * 3];
3704
-
37054025 ta.getCoordinates(0, positions);
37064026 ta.getNormals(0, normals);
37074027 // ta.getColors(0, colors);
....@@ -3709,12 +4029,24 @@
37094029
37104030 System.out.println("UV = " + uvmap[2] + ", " + uvmap[3] + ";");
37114031
4032
+ colors = null;
4033
+// colors = new float[ta.getVertexCount()]; // * 3];
4034
+//
4035
+// for (int i=colors.length; --i>=0;)
4036
+// {
4037
+// colors[i] = 1;
4038
+// }
4039
+
37124040 triangles = new int[ta.getVertexCount()];
37134041
37144042 for (int i = 0; i < triangles.length; i++)
37154043 {
37164044 triangles[i] = i;
37174045 }
4046
+
4047
+// Untrim();
4048
+ if (!trimmed)
4049
+ MergeNormals();
37184050 }
37194051 }
37204052
....@@ -3742,12 +4074,18 @@
37424074 positions = new float[3 * ga.getVertexCount()];
37434075 normals = new float[3 * ga.getVertexCount()];
37444076 uvmap = new float[2 * ga.getVertexCount()];
3745
- colors = new float[1 * ga.getVertexCount()];
37464077
37474078 tsa.getCoordinates(0, positions);
37484079 tsa.getNormals(0, normals);
37494080 tsa.getTextureCoordinates(0, 0, uvmap);
37504081 // tsa.getColors(0, colors);
4082
+
4083
+ colors = null;
4084
+// colors = new float[1 * ga.getVertexCount()];
4085
+// for (int i=colors.length; --i>=0;)
4086
+// {
4087
+// colors[i] = 1;
4088
+// }
37514089
37524090 int stripcount = tsa.getNumStrips();
37534091 triangles = new int[stripcount];
....@@ -3756,6 +4094,7 @@
37564094 stripified = true;
37574095 } catch (ClassCastException e)
37584096 {
4097
+ // ??? aug 2019
37594098 TriangleArray ta = (TriangleArray) ga;
37604099
37614100 positions = new float[3 * ga.getVertexCount()];
....@@ -3770,6 +4109,10 @@
37704109 triangles = new int[1];
37714110 triangles[0] = 3;
37724111 }
4112
+
4113
+ //Untrim();
4114
+ if (!trimmed)
4115
+ MergeNormals();
37734116 }
37744117
37754118 /*
....@@ -3819,6 +4162,42 @@
38194162 }
38204163
38214164 Vertex.normalmode = false;
4165
+ }
4166
+
4167
+ void MergeNormals()
4168
+ {
4169
+ assert(!trimmed);
4170
+
4171
+ boolean smooth = Grafreed.smoothmode;
4172
+ boolean link = Grafreed.linkUV;
4173
+ Grafreed.smoothmode = true;
4174
+ Grafreed.linkUV = true;
4175
+
4176
+ System.out.println("#Vertex = " + VertexCount());
4177
+ System.out.println("#Face = " + FaceCount());
4178
+
4179
+ java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>();
4180
+
4181
+ for (int i = 0; i < VertexCount(); i++)
4182
+ {
4183
+ Vertex v = GetVertex(i);
4184
+
4185
+ if (!table.contains(v))
4186
+ {
4187
+ table.add(v);
4188
+ }
4189
+ }
4190
+
4191
+ Grafreed.smoothmode = smooth;
4192
+ Grafreed.linkUV = link;
4193
+
4194
+// for (int i = 0; i < VertexCount(); i++)
4195
+// {
4196
+// Vertex v = GetVertex(i);
4197
+//
4198
+// table.add(v);
4199
+// }
4200
+
38224201 }
38234202
38244203 static cVector temp1 = new cVector();
....@@ -4593,16 +4972,25 @@
45934972 {
45944973 i3 = positions.length-3;
45954974 i2 = uvmap.length - 2;
4596
- new Exception().printStackTrace();
4975
+ //new Exception().printStackTrace();
45974976 }
45984977
45994978 v./*pos.*/x = positions[i3];
46004979 v./*pos.*/y = positions[i3 + 1];
46014980 v./*pos.*/z = positions[i3 + 2];
46024981
4603
- v.norm.x = normals[i3];
4604
- v.norm.y = normals[i3 + 1];
4605
- v.norm.z = normals[i3 + 2];
4982
+ if (normals == null)
4983
+ {
4984
+ v.norm.x = 0;
4985
+ v.norm.y = 0;
4986
+ v.norm.z = 0;
4987
+ }
4988
+ else
4989
+ {
4990
+ v.norm.x = normals[i3];
4991
+ v.norm.y = normals[i3 + 1];
4992
+ v.norm.z = normals[i3 + 2];
4993
+ }
46064994
46074995 v.s = uvmap[i2];
46084996 v.t = uvmap[i2 + 1];
....@@ -5317,17 +5705,27 @@
53175705
53185706 transient int nbbadfaces; // ?? = 1000000;
53195707
5320
- int ChooseTriangle()
5708
+ /*
5709
+ */
5710
+ int ChooseTriangle(boolean firstEquilateral)
53215711 {
53225712 int chosen = -1;
53235713
53245714 double minweight = 1E10;
53255715
5716
+ int step = 8; // ?
5717
+
5718
+ if (firstEquilateral)
5719
+ step = 1;
5720
+
53265721 nbbadfaces = 0;
5327
- for (int i=0; i<faces.size(); i+=8)
5722
+ for (int i=0; i<faces.size(); i+=step)
53285723 // for (int i=faces.size(); (i-=8)>=0;)
53295724 {
53305725 Face face = (Face) faces.get(i);
5726
+
5727
+ if (face.used)
5728
+ continue;
53315729
53325730 if (!Valid(face))
53335731 {
....@@ -5337,6 +5735,15 @@
53375735
53385736 if (Boundary(face))
53395737 continue;
5738
+
5739
+// if (Boundary(face.p))
5740
+// continue;
5741
+//
5742
+// if (Boundary(face.q))
5743
+// continue;
5744
+//
5745
+// if (Boundary(face.r))
5746
+// continue;
53405747
53415748 if (!ValidValence(face))
53425749 continue;
....@@ -5349,22 +5756,55 @@
53495756 //?? if (face.weight < 0)
53505757 // continue;
53515758
5352
- double K = 1; // 0.01; // .25;
5353
-
5354
- double factor = (1-K)*face.nbiterations + K; //*face.weight;
5355
-
5356
- double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5357
-
5358
- if (minweight > weight)
5759
+ if (firstEquilateral)
53595760 {
5360
- minweight = weight;
5761
+ if (OneFaceUsed(links.get(face.p)))
5762
+ continue;
5763
+
5764
+ if (OneFaceUsed(links.get(face.q)))
5765
+ continue;
5766
+
5767
+ if (OneFaceUsed(links.get(face.r)))
5768
+ continue;
5769
+
53615770 chosen = i;
5362
- if (minweight == 0)
5363
- break;
5771
+ break;
5772
+ }
5773
+ else
5774
+ {
5775
+ double K = 1; // 0.01; // .25;
5776
+
5777
+ double factor = (1-K)*face.nbiterations + K; //*face.weight;
5778
+
5779
+ double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5780
+
5781
+ if (minweight > weight)
5782
+ {
5783
+ minweight = weight;
5784
+ chosen = i;
5785
+ if (minweight == 0)
5786
+ break;
5787
+ }
53645788 }
53655789 }
53665790
53675791 return chosen;
5792
+ }
5793
+
5794
+ private boolean OneFaceUsed(Vector<Face> faces)
5795
+ {
5796
+ if (faces.size() != 6)
5797
+ return true;
5798
+
5799
+ for (int i=0; i<6; i+=1)
5800
+ {
5801
+ if (faces.get(i).used)
5802
+ {
5803
+ return true;
5804
+ }
5805
+ }
5806
+
5807
+ return false;
53685808 }
53695809
53705810 static boolean remove3valence = true;
....@@ -5400,7 +5840,7 @@
54005840 }
54015841 else
54025842 {
5403
- assert(links.size() == vertices.size());
5843
+ // TODO Grafreed.Assert(links.size() == vertices.size());
54045844
54055845 links.setSize(vertices.size());
54065846 for (int i=vertices.size(); --i>=0;)
....@@ -5408,6 +5848,7 @@
54085848 // linkstouched[i] = false;
54095849 if (links.get(i) == null) // ??
54105850 {
5851
+ new Exception().printStackTrace();
54115852 links.set(i, new Vector(8));
54125853 // linkstouched[i] = true;
54135854 }
....@@ -5418,6 +5859,8 @@
54185859 }
54195860 }
54205861
5862
+ boolean once = false;
5863
+
54215864 for (int i=faces.size(); --i>=0;)
54225865 {
54235866 Face face = (Face) faces.get(i);
....@@ -5429,6 +5872,9 @@
54295872 //if (linkstouched[face.r])
54305873 links.get(face.r).add(face);
54315874
5875
+ if (face.used)
5876
+ once = true;
5877
+
54325878 face.good = 1;
54335879 face.boundary = -1;
54345880 }
....@@ -6200,6 +6646,7 @@
62006646
62016647 void InitWeights()
62026648 {
6649
+ new Exception().printStackTrace();
62036650 System.exit(0);
62046651 int n = 0;
62056652 int b = 0;
....@@ -6793,6 +7240,10 @@
67937240 return (face.boundary = 1) == 1;
67947241 }
67957242
7243
+ // June 2019
7244
+ if (true)
7245
+ return (face.boundary = 0) == 1;
7246
+
67967247 // reverse triangle test
67977248 q1.set(p);
67987249 q2.set(q);
....@@ -7242,7 +7693,7 @@
72427693 //InitWeights();
72437694 }
72447695
7245
- int chosen = ChooseTriangle(); // Best is slow and not really better
7696
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
72467697
72477698 if (chosen == -1)
72487699 {
....@@ -7256,7 +7707,7 @@
72567707 //remove3valence = false;
72577708 // InitWeights();
72587709
7259
- chosen = ChooseTriangle();
7710
+ chosen = ChooseTriangle(true);
72607711 }
72617712 }
72627713
....@@ -7532,7 +7983,7 @@
75327983
75337984 // boolean lock;
75347985
7535
- void SplitInTwo(boolean reduction34, boolean onlyone)
7986
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
75367987 {
75377988 if (stripified)
75387989 {
....@@ -7569,12 +8020,12 @@
75698020 {
75708021 System.err.println("EXCEPTION CAUGHT");
75718022 e.printStackTrace();
7572
- return;
8023
+ return false;
75738024 } catch (Error e)
75748025 {
75758026 System.err.println("ERROR CAUGHT");
75768027 e.printStackTrace();
7577
- return;
8028
+ return false;
75788029 }
75798030
75808031 System.out.println("# faces = " + faces.size());
....@@ -7584,6 +8035,7 @@
75848035 {
75858036 Face face = (Face) faces.get(i);
75868037
8038
+ face.used = false;
75878039 face.nbiterations = 1;
75888040 face.weight = -1;
75898041 face.boundary = -1;
....@@ -7635,6 +8087,11 @@
76358087 nbbadfaces = faces.size();
76368088 //remove3valence = true;
76378089
8090
+ int count = 2;
8091
+
8092
+ if (onlyone)
8093
+ count = 1;
8094
+
76388095 firstpass = true;
76398096
76408097 int n = faces.size();
....@@ -7650,8 +8107,9 @@
76508107 System.out.print('.');
76518108 }
76528109 System.out.println();
8110
+ boolean atleastone = false;
76538111 int i = 0;
7654
- while (reduction34 || faces.size() > n/2)
8112
+ while (true) // reduction34 || faces.size() > n/2)
76558113 {
76568114 if (i++%100 == 0)
76578115 {
....@@ -7673,6 +8131,8 @@
76738131 {
76748132 if (!RemoveOneTriangle())
76758133 break;
8134
+
8135
+ atleastone = true;
76768136 }
76778137 // if (iterationcount == 0)
76788138 // break;
....@@ -7683,8 +8143,8 @@
76838143 break;
76848144 }
76858145 firstpass = false;
7686
- if (onlyone)
7687
- break; // one triangle only
8146
+// if (--count<0 && !reduction34)
8147
+// break; // one triangle only
76888148 }
76898149
76908150 InitLinks(false); // for further display
....@@ -7700,6 +8160,8 @@
77008160 Trim(true,false,false,false,false);
77018161
77028162 Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8163
+
8164
+ return atleastone;
77038165 }
77048166
77058167 void UpdateIndices(Face face, Face minface)
....@@ -7712,18 +8174,21 @@
77128174 face.p = minface.p;
77138175 //if (leafweights)
77148176 face.good = 0; // false;
8177
+ face.used = true;
77158178 }
77168179 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
77178180 {
77188181 face.q = minface.p;
77198182 //if (leafweights)
77208183 face.good = 0; // false;
8184
+ face.used = true;
77218185 }
77228186 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
77238187 {
77248188 face.r = minface.p;
77258189 //if (leafweights)
77268190 face.good = 0; // false;
8191
+ face.used = true;
77278192 }
77288193
77298194 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7783,50 +8248,50 @@
77838248 if (v == 2)
77848249 vert = minface.r;
77858250 // Face face = (Face) faces.get(i);
7786
- Vector<Face> vertfaces = links.get(vert);
7787
- for (int i=vertfaces.size(); --i>=0;)
7788
- {
7789
- Face face = (Face) vertfaces.get(i);
7790
-
7791
- // if (face.weight == 10000)
7792
- // continue;
7793
-
7794
- if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
7795
- face.p == minface.q || face.q == minface.q || face.r == minface.q ||
7796
- face.p == minface.r || face.q == minface.r || face.r == minface.r)
8251
+ Vector<Face> vertfaces = links.get(vert);
8252
+ for (int i=vertfaces.size(); --i>=0;)
77978253 {
7798
- if (!leafweights)
8254
+ Face face = (Face) vertfaces.get(i);
8255
+
8256
+ // if (face.weight == 10000)
8257
+ // continue;
8258
+
8259
+ if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
8260
+ face.p == minface.q || face.q == minface.q || face.r == minface.q ||
8261
+ face.p == minface.r || face.q == minface.r || face.r == minface.r)
77998262 {
7800
-// if(minfaceweight <= 0)
7801
-// assert(minfaceweight > 0);
7802
-//
7803
-// //FaceWeight(face);
7804
-// if(face.weight < 0)
7805
-// assert(face.weight >= 0);
7806
-
7807
- face.weight += minfaceweight;
7808
-
7809
-// if (face.weight >= 10000)
7810
-// assert(face.weight < 10000);
8263
+ if (!leafweights)
8264
+ {
8265
+ // if(minfaceweight <= 0)
8266
+ // assert(minfaceweight > 0);
8267
+ //
8268
+ // //FaceWeight(face);
8269
+ // if(face.weight < 0)
8270
+ // assert(face.weight >= 0);
8271
+
8272
+ face.weight += minfaceweight;
8273
+
8274
+ // if (face.weight >= 10000)
8275
+ // assert(face.weight < 10000);
8276
+ }
8277
+ else
8278
+ face.weight = -1;
8279
+
8280
+ face.nbiterations += 1;
8281
+ face.boundary = -1;
8282
+
8283
+ Vertex p = (Vertex)vertices.get(face.p);
8284
+ Vertex q = (Vertex)vertices.get(face.q);
8285
+ Vertex r = (Vertex)vertices.get(face.r);
8286
+
8287
+ p.boundary = -1;
8288
+ q.boundary = -1;
8289
+ r.boundary = -1;
78118290 }
78128291 else
7813
- face.weight = -1;
7814
-
7815
- face.nbiterations += 1;
7816
- face.boundary = -1;
7817
-
7818
- Vertex p = (Vertex)vertices.get(face.p);
7819
- Vertex q = (Vertex)vertices.get(face.q);
7820
- Vertex r = (Vertex)vertices.get(face.r);
7821
-
7822
- p.boundary = -1;
7823
- q.boundary = -1;
7824
- r.boundary = -1;
8292
+ assert(false);
78258293 }
7826
- else
7827
- assert(false);
78288294 }
7829
- }
78308295
78318296 // TouchVertex(minface.p);
78328297 // TouchVertex(minface.q);
....@@ -8027,6 +8492,7 @@
80278492 for (int i=vertfaces.size(); --i>=0;)
80288493 {
80298494 Face face = (Face) vertfaces.get(i);
8495
+ face.used = true;
80308496 face.good = 0; // false;
80318497 if (leafweights)
80328498 face.weight = -1;
....@@ -8073,7 +8539,7 @@
80738539 if (!trimmed)
80748540 return;
80758541
8076
- GrafreeD.linkUV = false;
8542
+ Grafreed.linkUV = false;
80778543
80788544 try
80798545 {
....@@ -8305,7 +8771,8 @@
83058771 int[] startvertices;
83068772 float[] averagepoints;
83078773 float[] extremepoints;
8308
- float[] supportsizes; // distance of closest point
8774
+ float[] supportminsize; // distance of closest point
8775
+ float[] supportmaxsize; // distance of fartest point
83098776
83108777 transient Hashtable vertextable;
83118778 /*transient*/ private Vertex[] verticesCopy;