Normand Briere
2019-07-25 f2b6a33fdf84a06b958f9cb9d667a2eff3063d8b
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,8 @@
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] == 0) // < 0.001 * v.totalweight)
19702002 {
19712003 //testweight += v.weights[j-1];
19722004 continue;
....@@ -2247,6 +2279,8 @@
22472279
22482280 transient int lastsoundtime;
22492281
2282
+ transient boolean once = false;
2283
+
22502284 void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked)
22512285 {
22522286 if (LA.isIdentity(toRoot))
....@@ -2302,7 +2336,11 @@
23022336
23032337 if (v.totalweight == 0)
23042338 {
2305
- 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
+ }
23062344 continue;
23072345 }
23082346
....@@ -2670,7 +2708,7 @@
26702708
26712709 if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26722710 {
2673
- GrafreeD.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);
26742712
26752713 lastsoundtime = Globals.framecount;
26762714 }
....@@ -3098,6 +3136,7 @@
30983136 //
30993137 // transient VertexCompare[] vertexcompare = null;
31003138
3139
+ // Check if v0 is close enough from any vertex of the given subobject of this.
31013140 boolean Contains(Vertex v0, int object)
31023141 {
31033142 int start = startvertices[object-1];
....@@ -3155,7 +3194,27 @@
31553194 */
31563195 }
31573196
3158
- 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)
31593218 {
31603219 Trim();
31613220
....@@ -3219,6 +3278,125 @@
32193278 y -= 0.5;
32203279 z -= 0.5;
32213280
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
+
32223400 // x *= 2;
32233401 // y *= 2;
32243402 // z *= 2;
....@@ -3245,6 +3423,15 @@
32453423
32463424 z = Math.cos(angle/2);
32473425
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
+
32483435 // sqrt(k2*x2 + k2*z2 + y2) = length
32493436 // k2*x2 + k2*z2 = length2 - y2
32503437 // k2 = (length2 - y2) / (x2 + z2)
....@@ -3255,7 +3442,7 @@
32553442 k /= x*x + y*y;
32563443 }
32573444 else
3258
- GrafreeD.Assert(z == 1);
3445
+ Grafreed.Assert(z == 1);
32593446
32603447 if (k < 0)
32613448 k = 0;
....@@ -3264,6 +3451,7 @@
32643451
32653452 x *= k;
32663453 y *= k;
3454
+ /**/
32673455
32683456 double max = Math.abs(x);
32693457 if (max < Math.abs(y))
....@@ -3276,10 +3464,15 @@
32763464 }
32773465
32783466 // 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);
32793471
32803472 // if (!(max > 0))
3281
- assert(max > 0);
3282
-
3473
+ //assert(max > 0);
3474
+ assert(max >= 0);
3475
+
32833476 x /= max;
32843477 y /= max;
32853478 z /= max;
....@@ -3542,6 +3735,111 @@
35423735 */
35433736 }
35443737
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
+
35453843 void GenerateNormals(boolean crease)
35463844 {
35473845 boolean wastrim = trimmed;
....@@ -3558,6 +3856,28 @@
35583856 }
35593857
35603858 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
+ }
35613881 }
35623882
35633883 void GenNormalsJME()
....@@ -3682,7 +4002,7 @@
36824002 NormalGenerator ng;
36834003
36844004 if (crease)
3685
- 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);
36864006 else
36874007 ng = new NormalGenerator(Math.PI); // (Math.PI / 3); // /4);
36884008
....@@ -3715,6 +4035,10 @@
37154035 {
37164036 triangles[i] = i;
37174037 }
4038
+
4039
+// Untrim();
4040
+ if (!trimmed)
4041
+ MergeNormals();
37184042 }
37194043 }
37204044
....@@ -3748,6 +4072,11 @@
37484072 tsa.getNormals(0, normals);
37494073 tsa.getTextureCoordinates(0, 0, uvmap);
37504074 // tsa.getColors(0, colors);
4075
+
4076
+ for (int i=colors.length; --i>=0;)
4077
+ {
4078
+ colors[i] = 1;
4079
+ }
37514080
37524081 int stripcount = tsa.getNumStrips();
37534082 triangles = new int[stripcount];
....@@ -3770,6 +4099,10 @@
37704099 triangles = new int[1];
37714100 triangles[0] = 3;
37724101 }
4102
+
4103
+ //Untrim();
4104
+ if (!trimmed)
4105
+ MergeNormals();
37734106 }
37744107
37754108 /*
....@@ -3819,6 +4152,42 @@
38194152 }
38204153
38214154 Vertex.normalmode = false;
4155
+ }
4156
+
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
+
38224191 }
38234192
38244193 static cVector temp1 = new cVector();
....@@ -4428,7 +4797,7 @@
44284797 }
44294798 }
44304799
4431
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4800
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
44324801 {
44334802 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
44344803 CameraPane.tempmat,0, CameraPane.tempmat2,0,
....@@ -4593,16 +4962,25 @@
45934962 {
45944963 i3 = positions.length-3;
45954964 i2 = uvmap.length - 2;
4596
- new Exception().printStackTrace();
4965
+ //new Exception().printStackTrace();
45974966 }
45984967
45994968 v./*pos.*/x = positions[i3];
46004969 v./*pos.*/y = positions[i3 + 1];
46014970 v./*pos.*/z = positions[i3 + 2];
46024971
4603
- v.norm.x = normals[i3];
4604
- v.norm.y = normals[i3 + 1];
4605
- 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
+ }
46064984
46074985 v.s = uvmap[i2];
46084986 v.t = uvmap[i2 + 1];
....@@ -5317,17 +5695,27 @@
53175695
53185696 transient int nbbadfaces; // ?? = 1000000;
53195697
5320
- int ChooseTriangle()
5698
+ /*
5699
+ */
5700
+ int ChooseTriangle(boolean firstEquilateral)
53215701 {
53225702 int chosen = -1;
53235703
53245704 double minweight = 1E10;
53255705
5706
+ int step = 8; // ?
5707
+
5708
+ if (firstEquilateral)
5709
+ step = 1;
5710
+
53265711 nbbadfaces = 0;
5327
- for (int i=0; i<faces.size(); i+=8)
5712
+ for (int i=0; i<faces.size(); i+=step)
53285713 // for (int i=faces.size(); (i-=8)>=0;)
53295714 {
53305715 Face face = (Face) faces.get(i);
5716
+
5717
+ if (face.used)
5718
+ continue;
53315719
53325720 if (!Valid(face))
53335721 {
....@@ -5337,6 +5725,15 @@
53375725
53385726 if (Boundary(face))
53395727 continue;
5728
+
5729
+// if (Boundary(face.p))
5730
+// continue;
5731
+//
5732
+// if (Boundary(face.q))
5733
+// continue;
5734
+//
5735
+// if (Boundary(face.r))
5736
+// continue;
53405737
53415738 if (!ValidValence(face))
53425739 continue;
....@@ -5349,22 +5746,55 @@
53495746 //?? if (face.weight < 0)
53505747 // continue;
53515748
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)
5749
+ if (firstEquilateral)
53595750 {
5360
- 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
+
53615760 chosen = i;
5362
- if (minweight == 0)
5363
- break;
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
+ }
53645778 }
53655779 }
53665780
53675781 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;
53685798 }
53695799
53705800 static boolean remove3valence = true;
....@@ -5400,7 +5830,7 @@
54005830 }
54015831 else
54025832 {
5403
- assert(links.size() == vertices.size());
5833
+ // TODO Grafreed.Assert(links.size() == vertices.size());
54045834
54055835 links.setSize(vertices.size());
54065836 for (int i=vertices.size(); --i>=0;)
....@@ -5408,6 +5838,7 @@
54085838 // linkstouched[i] = false;
54095839 if (links.get(i) == null) // ??
54105840 {
5841
+ new Exception().printStackTrace();
54115842 links.set(i, new Vector(8));
54125843 // linkstouched[i] = true;
54135844 }
....@@ -5418,6 +5849,8 @@
54185849 }
54195850 }
54205851
5852
+ boolean once = false;
5853
+
54215854 for (int i=faces.size(); --i>=0;)
54225855 {
54235856 Face face = (Face) faces.get(i);
....@@ -5429,6 +5862,9 @@
54295862 //if (linkstouched[face.r])
54305863 links.get(face.r).add(face);
54315864
5865
+ if (face.used)
5866
+ once = true;
5867
+
54325868 face.good = 1;
54335869 face.boundary = -1;
54345870 }
....@@ -6200,6 +6636,7 @@
62006636
62016637 void InitWeights()
62026638 {
6639
+ new Exception().printStackTrace();
62036640 System.exit(0);
62046641 int n = 0;
62056642 int b = 0;
....@@ -6793,6 +7230,10 @@
67937230 return (face.boundary = 1) == 1;
67947231 }
67957232
7233
+ // June 2019
7234
+ if (true)
7235
+ return (face.boundary = 0) == 1;
7236
+
67967237 // reverse triangle test
67977238 q1.set(p);
67987239 q2.set(q);
....@@ -7242,7 +7683,7 @@
72427683 //InitWeights();
72437684 }
72447685
7245
- int chosen = ChooseTriangle(); // Best is slow and not really better
7686
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
72467687
72477688 if (chosen == -1)
72487689 {
....@@ -7256,7 +7697,7 @@
72567697 //remove3valence = false;
72577698 // InitWeights();
72587699
7259
- chosen = ChooseTriangle();
7700
+ chosen = ChooseTriangle(true);
72607701 }
72617702 }
72627703
....@@ -7532,7 +7973,7 @@
75327973
75337974 // boolean lock;
75347975
7535
- void SplitInTwo(boolean reduction34, boolean onlyone)
7976
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
75367977 {
75377978 if (stripified)
75387979 {
....@@ -7569,12 +8010,12 @@
75698010 {
75708011 System.err.println("EXCEPTION CAUGHT");
75718012 e.printStackTrace();
7572
- return;
8013
+ return false;
75738014 } catch (Error e)
75748015 {
75758016 System.err.println("ERROR CAUGHT");
75768017 e.printStackTrace();
7577
- return;
8018
+ return false;
75788019 }
75798020
75808021 System.out.println("# faces = " + faces.size());
....@@ -7584,6 +8025,7 @@
75848025 {
75858026 Face face = (Face) faces.get(i);
75868027
8028
+ face.used = false;
75878029 face.nbiterations = 1;
75888030 face.weight = -1;
75898031 face.boundary = -1;
....@@ -7635,6 +8077,11 @@
76358077 nbbadfaces = faces.size();
76368078 //remove3valence = true;
76378079
8080
+ int count = 2;
8081
+
8082
+ if (onlyone)
8083
+ count = 1;
8084
+
76388085 firstpass = true;
76398086
76408087 int n = faces.size();
....@@ -7650,8 +8097,9 @@
76508097 System.out.print('.');
76518098 }
76528099 System.out.println();
8100
+ boolean atleastone = false;
76538101 int i = 0;
7654
- while (reduction34 || faces.size() > n/2)
8102
+ while (true) // reduction34 || faces.size() > n/2)
76558103 {
76568104 if (i++%100 == 0)
76578105 {
....@@ -7673,6 +8121,8 @@
76738121 {
76748122 if (!RemoveOneTriangle())
76758123 break;
8124
+
8125
+ atleastone = true;
76768126 }
76778127 // if (iterationcount == 0)
76788128 // break;
....@@ -7683,8 +8133,8 @@
76838133 break;
76848134 }
76858135 firstpass = false;
7686
- if (onlyone)
7687
- break; // one triangle only
8136
+// if (--count<0 && !reduction34)
8137
+// break; // one triangle only
76888138 }
76898139
76908140 InitLinks(false); // for further display
....@@ -7700,6 +8150,8 @@
77008150 Trim(true,false,false,false,false);
77018151
77028152 Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8153
+
8154
+ return atleastone;
77038155 }
77048156
77058157 void UpdateIndices(Face face, Face minface)
....@@ -7712,18 +8164,21 @@
77128164 face.p = minface.p;
77138165 //if (leafweights)
77148166 face.good = 0; // false;
8167
+ face.used = true;
77158168 }
77168169 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
77178170 {
77188171 face.q = minface.p;
77198172 //if (leafweights)
77208173 face.good = 0; // false;
8174
+ face.used = true;
77218175 }
77228176 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
77238177 {
77248178 face.r = minface.p;
77258179 //if (leafweights)
77268180 face.good = 0; // false;
8181
+ face.used = true;
77278182 }
77288183
77298184 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7783,50 +8238,50 @@
77838238 if (v == 2)
77848239 vert = minface.r;
77858240 // 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)
8241
+ Vector<Face> vertfaces = links.get(vert);
8242
+ for (int i=vertfaces.size(); --i>=0;)
77978243 {
7798
- 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)
77998252 {
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);
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;
78118280 }
78128281 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;
8282
+ assert(false);
78258283 }
7826
- else
7827
- assert(false);
78288284 }
7829
- }
78308285
78318286 // TouchVertex(minface.p);
78328287 // TouchVertex(minface.q);
....@@ -8027,6 +8482,7 @@
80278482 for (int i=vertfaces.size(); --i>=0;)
80288483 {
80298484 Face face = (Face) vertfaces.get(i);
8485
+ face.used = true;
80308486 face.good = 0; // false;
80318487 if (leafweights)
80328488 face.weight = -1;
....@@ -8073,7 +8529,7 @@
80738529 if (!trimmed)
80748530 return;
80758531
8076
- GrafreeD.linkUV = false;
8532
+ Grafreed.linkUV = false;
80778533
80788534 try
80798535 {
....@@ -8305,7 +8761,8 @@
83058761 int[] startvertices;
83068762 float[] averagepoints;
83078763 float[] extremepoints;
8308
- float[] supportsizes; // distance of closest point
8764
+ float[] supportminsize; // distance of closest point
8765
+ float[] supportmaxsize; // distance of fartest point
83098766
83108767 transient Hashtable vertextable;
83118768 /*transient*/ private Vertex[] verticesCopy;