Normand Briere
2019-08-01 29d5516687020263d3ae0454ce81879a3a450af0
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)
....@@ -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: a bit 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
....@@ -2661,7 +2701,7 @@
26612701 if (false) // slow && stepout && onein)
26622702 {
26632703 // sound
2664
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
2704
+ cVector eye = Globals.theRenderer.EyeCamera().location;
26652705
26662706 Vertex v = GetVertex(0);
26672707
....@@ -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
....@@ -3715,6 +4037,10 @@
37154037 {
37164038 triangles[i] = i;
37174039 }
4040
+
4041
+// Untrim();
4042
+ if (!trimmed)
4043
+ MergeNormals();
37184044 }
37194045 }
37204046
....@@ -3748,6 +4074,11 @@
37484074 tsa.getNormals(0, normals);
37494075 tsa.getTextureCoordinates(0, 0, uvmap);
37504076 // tsa.getColors(0, colors);
4077
+
4078
+ for (int i=colors.length; --i>=0;)
4079
+ {
4080
+ colors[i] = 1;
4081
+ }
37514082
37524083 int stripcount = tsa.getNumStrips();
37534084 triangles = new int[stripcount];
....@@ -3770,6 +4101,10 @@
37704101 triangles = new int[1];
37714102 triangles[0] = 3;
37724103 }
4104
+
4105
+ //Untrim();
4106
+ if (!trimmed)
4107
+ MergeNormals();
37734108 }
37744109
37754110 /*
....@@ -3819,6 +4154,42 @@
38194154 }
38204155
38214156 Vertex.normalmode = false;
4157
+ }
4158
+
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
+
38224193 }
38234194
38244195 static cVector temp1 = new cVector();
....@@ -4428,7 +4799,7 @@
44284799 }
44294800 }
44304801
4431
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4802
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
44324803 {
44334804 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
44344805 CameraPane.tempmat,0, CameraPane.tempmat2,0,
....@@ -4460,14 +4831,14 @@
44604831 // june 2014
44614832 // Camera parentcam = cam;
44624833 //
4463
-// if (cam == CameraPane.theRenderer.cameras[0])
4834
+// if (cam == Globals.theRenderer.cameras[0])
44644835 // {
4465
-// parentcam = CameraPane.theRenderer.cameras[1];
4836
+// parentcam = Globals.theRenderer.cameras[1];
44664837 // }
44674838 //
4468
-// if (cam == CameraPane.theRenderer.cameras[1])
4839
+// if (cam == Globals.theRenderer.cameras[1])
44694840 // {
4470
-// parentcam = CameraPane.theRenderer.cameras[0];
4841
+// parentcam = Globals.theRenderer.cameras[0];
44714842 // }
44724843
44734844 gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0);
....@@ -4593,16 +4964,25 @@
45934964 {
45944965 i3 = positions.length-3;
45954966 i2 = uvmap.length - 2;
4596
- new Exception().printStackTrace();
4967
+ //new Exception().printStackTrace();
45974968 }
45984969
45994970 v./*pos.*/x = positions[i3];
46004971 v./*pos.*/y = positions[i3 + 1];
46014972 v./*pos.*/z = positions[i3 + 2];
46024973
4603
- v.norm.x = normals[i3];
4604
- v.norm.y = normals[i3 + 1];
4605
- 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
+ }
46064986
46074987 v.s = uvmap[i2];
46084988 v.t = uvmap[i2 + 1];
....@@ -4893,7 +5273,7 @@
48935273 return verticesCopy;
48945274 }
48955275
4896
- void PreprocessOcclusion(CameraPane cp, double[][] transform)
5276
+ void PreprocessOcclusion(iCameraPane cp, double[][] transform)
48975277 {
48985278 if (//!trimmed ||
48995279 AOdone)
....@@ -4902,80 +5282,7 @@
49025282 return;
49035283 }
49045284
4905
- Camera keep = cp.renderCamera;
4906
- cp.renderCamera = localcamera;
4907
-
4908
- if (trimmed)
4909
- {
4910
- float[] colors = new float[positions.length / 3];
4911
-
4912
- int i3 = 0;
4913
- for (int i = 0; i < positions.length / 3; i++, i3 += 3)
4914
- {
4915
- if (normals[i3] == 0 && normals[i3+1] == 0 && normals[i3+2] == 0)
4916
- continue;
4917
-
4918
- from.set(positions[i3], positions[i3 + 1], positions[i3 + 2]);
4919
- to.set(positions[i3] + normals[i3],
4920
- positions[i3 + 1] + normals[i3 + 1],
4921
- positions[i3 + 2] + normals[i3 + 2]);
4922
- LA.xformPos(from, transform, from);
4923
- LA.xformPos(to, transform, to); // RIGID ONLY
4924
- localcamera.setAim(from, to);
4925
-
4926
- CameraPane.occlusionbuffer.display();
4927
-
4928
- if (CameraPane.DEBUG_OCCLUSION)
4929
- cp.display(); // debug
4930
-
4931
- colors[i] = cp.vertexOcclusion.r;
4932
- //colors[i3 + 1] = cp.vertexOcclusion.g;
4933
- //colors[i3 + 2] = cp.vertexOcclusion.b;
4934
-
4935
- if ((i % 100) == 0 && i != 0)
4936
- {
4937
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
4938
- //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
4939
- System.out.println((int) (100.0 * i / (positions.length / 3)) + "% (" + i + " of " + (positions.length / 3) + ")");
4940
- }
4941
- }
4942
-
4943
- this.colors = colors;
4944
- }
4945
- else
4946
- {
4947
- for (int i = 0; i < VertexCount(); i++)
4948
- {
4949
- Vertex v = GetVertex(i);
4950
-
4951
- if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
4952
- continue;
4953
-
4954
- from.set(v.x, v.y, v.z);
4955
- to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
4956
- LA.xformPos(from, transform, from);
4957
- LA.xformPos(to, transform, to); // RIGID ONLY
4958
- localcamera.setAim(from, to);
4959
-
4960
- CameraPane.occlusionbuffer.display();
4961
-
4962
- if (CameraPane.DEBUG_OCCLUSION)
4963
- cp.display(); // debug
4964
-
4965
- v.AO = cp.vertexOcclusion.r;
4966
-
4967
- if ((i % 100) == 0 && i != 0)
4968
- {
4969
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
4970
- //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
4971
- System.out.println((int) (100.0 * i / VertexCount()) + "% (" + i + " of " + VertexCount() + ")");
4972
- }
4973
- }
4974
- }
4975
-
4976
- //System.out.println("done.");
4977
-
4978
- cp.renderCamera = keep;
5285
+ cp.PrepOcclusion(this, transform);
49795286
49805287 AOdone = true;
49815288 }
....@@ -5390,17 +5697,27 @@
53905697
53915698 transient int nbbadfaces; // ?? = 1000000;
53925699
5393
- int ChooseTriangle()
5700
+ /*
5701
+ */
5702
+ int ChooseTriangle(boolean firstEquilateral)
53945703 {
53955704 int chosen = -1;
53965705
53975706 double minweight = 1E10;
53985707
5708
+ int step = 8; // ?
5709
+
5710
+ if (firstEquilateral)
5711
+ step = 1;
5712
+
53995713 nbbadfaces = 0;
5400
- for (int i=0; i<faces.size(); i+=8)
5714
+ for (int i=0; i<faces.size(); i+=step)
54015715 // for (int i=faces.size(); (i-=8)>=0;)
54025716 {
54035717 Face face = (Face) faces.get(i);
5718
+
5719
+ if (face.used)
5720
+ continue;
54045721
54055722 if (!Valid(face))
54065723 {
....@@ -5410,6 +5727,15 @@
54105727
54115728 if (Boundary(face))
54125729 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;
54135739
54145740 if (!ValidValence(face))
54155741 continue;
....@@ -5422,22 +5748,55 @@
54225748 //?? if (face.weight < 0)
54235749 // continue;
54245750
5425
- double K = 1; // 0.01; // .25;
5426
-
5427
- double factor = (1-K)*face.nbiterations + K; //*face.weight;
5428
-
5429
- double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5430
-
5431
- if (minweight > weight)
5751
+ if (firstEquilateral)
54325752 {
5433
- 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
+
54345762 chosen = i;
5435
- if (minweight == 0)
5436
- 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
+ }
54375780 }
54385781 }
54395782
54405783 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;
54415800 }
54425801
54435802 static boolean remove3valence = true;
....@@ -5473,7 +5832,7 @@
54735832 }
54745833 else
54755834 {
5476
- assert(links.size() == vertices.size());
5835
+ // TODO Grafreed.Assert(links.size() == vertices.size());
54775836
54785837 links.setSize(vertices.size());
54795838 for (int i=vertices.size(); --i>=0;)
....@@ -5481,6 +5840,7 @@
54815840 // linkstouched[i] = false;
54825841 if (links.get(i) == null) // ??
54835842 {
5843
+ new Exception().printStackTrace();
54845844 links.set(i, new Vector(8));
54855845 // linkstouched[i] = true;
54865846 }
....@@ -5491,6 +5851,8 @@
54915851 }
54925852 }
54935853
5854
+ boolean once = false;
5855
+
54945856 for (int i=faces.size(); --i>=0;)
54955857 {
54965858 Face face = (Face) faces.get(i);
....@@ -5502,6 +5864,9 @@
55025864 //if (linkstouched[face.r])
55035865 links.get(face.r).add(face);
55045866
5867
+ if (face.used)
5868
+ once = true;
5869
+
55055870 face.good = 1;
55065871 face.boundary = -1;
55075872 }
....@@ -6273,6 +6638,7 @@
62736638
62746639 void InitWeights()
62756640 {
6641
+ new Exception().printStackTrace();
62766642 System.exit(0);
62776643 int n = 0;
62786644 int b = 0;
....@@ -6866,6 +7232,10 @@
68667232 return (face.boundary = 1) == 1;
68677233 }
68687234
7235
+ // June 2019
7236
+ if (true)
7237
+ return (face.boundary = 0) == 1;
7238
+
68697239 // reverse triangle test
68707240 q1.set(p);
68717241 q2.set(q);
....@@ -7315,7 +7685,7 @@
73157685 //InitWeights();
73167686 }
73177687
7318
- int chosen = ChooseTriangle(); // Best is slow and not really better
7688
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
73197689
73207690 if (chosen == -1)
73217691 {
....@@ -7329,7 +7699,7 @@
73297699 //remove3valence = false;
73307700 // InitWeights();
73317701
7332
- chosen = ChooseTriangle();
7702
+ chosen = ChooseTriangle(true);
73337703 }
73347704 }
73357705
....@@ -7605,7 +7975,7 @@
76057975
76067976 // boolean lock;
76077977
7608
- void SplitInTwo(boolean reduction34, boolean onlyone)
7978
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
76097979 {
76107980 if (stripified)
76117981 {
....@@ -7633,7 +8003,7 @@
76338003 s3 = new cVector();
76348004 }
76358005
7636
- 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));
76378007
76388008 try
76398009 {
....@@ -7642,12 +8012,12 @@
76428012 {
76438013 System.err.println("EXCEPTION CAUGHT");
76448014 e.printStackTrace();
7645
- return;
8015
+ return false;
76468016 } catch (Error e)
76478017 {
76488018 System.err.println("ERROR CAUGHT");
76498019 e.printStackTrace();
7650
- return;
8020
+ return false;
76518021 }
76528022
76538023 System.out.println("# faces = " + faces.size());
....@@ -7657,6 +8027,7 @@
76578027 {
76588028 Face face = (Face) faces.get(i);
76598029
8030
+ face.used = false;
76608031 face.nbiterations = 1;
76618032 face.weight = -1;
76628033 face.boundary = -1;
....@@ -7708,6 +8079,11 @@
77088079 nbbadfaces = faces.size();
77098080 //remove3valence = true;
77108081
8082
+ int count = 2;
8083
+
8084
+ if (onlyone)
8085
+ count = 1;
8086
+
77118087 firstpass = true;
77128088
77138089 int n = faces.size();
....@@ -7723,12 +8099,13 @@
77238099 System.out.print('.');
77248100 }
77258101 System.out.println();
8102
+ boolean atleastone = false;
77268103 int i = 0;
7727
- while (reduction34 || faces.size() > n/2)
8104
+ while (true) // reduction34 || faces.size() > n/2)
77288105 {
77298106 if (i++%100 == 0)
77308107 {
7731
- 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));
77328109 System.out.println("#faces = " + faces.size());
77338110 // if (i != 1)
77348111 // break;
....@@ -7746,6 +8123,8 @@
77468123 {
77478124 if (!RemoveOneTriangle())
77488125 break;
8126
+
8127
+ atleastone = true;
77498128 }
77508129 // if (iterationcount == 0)
77518130 // break;
....@@ -7756,8 +8135,8 @@
77568135 break;
77578136 }
77588137 firstpass = false;
7759
- if (onlyone)
7760
- break; // one triangle only
8138
+// if (--count<0 && !reduction34)
8139
+// break; // one triangle only
77618140 }
77628141
77638142 InitLinks(false); // for further display
....@@ -7772,7 +8151,9 @@
77728151 //Trim(true,cJME.gennormals,true,false); // doesn't work
77738152 Trim(true,false,false,false,false);
77748153
7775
- 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;
77768157 }
77778158
77788159 void UpdateIndices(Face face, Face minface)
....@@ -7785,18 +8166,21 @@
77858166 face.p = minface.p;
77868167 //if (leafweights)
77878168 face.good = 0; // false;
8169
+ face.used = true;
77888170 }
77898171 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
77908172 {
77918173 face.q = minface.p;
77928174 //if (leafweights)
77938175 face.good = 0; // false;
8176
+ face.used = true;
77948177 }
77958178 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
77968179 {
77978180 face.r = minface.p;
77988181 //if (leafweights)
77998182 face.good = 0; // false;
8183
+ face.used = true;
78008184 }
78018185
78028186 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7856,50 +8240,50 @@
78568240 if (v == 2)
78578241 vert = minface.r;
78588242 // Face face = (Face) faces.get(i);
7859
- Vector<Face> vertfaces = links.get(vert);
7860
- for (int i=vertfaces.size(); --i>=0;)
7861
- {
7862
- Face face = (Face) vertfaces.get(i);
7863
-
7864
- // if (face.weight == 10000)
7865
- // continue;
7866
-
7867
- if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
7868
- face.p == minface.q || face.q == minface.q || face.r == minface.q ||
7869
- 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;)
78708245 {
7871
- 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)
78728254 {
7873
-// if(minfaceweight <= 0)
7874
-// assert(minfaceweight > 0);
7875
-//
7876
-// //FaceWeight(face);
7877
-// if(face.weight < 0)
7878
-// assert(face.weight >= 0);
7879
-
7880
- face.weight += minfaceweight;
7881
-
7882
-// if (face.weight >= 10000)
7883
-// 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;
78848282 }
78858283 else
7886
- face.weight = -1;
7887
-
7888
- face.nbiterations += 1;
7889
- face.boundary = -1;
7890
-
7891
- Vertex p = (Vertex)vertices.get(face.p);
7892
- Vertex q = (Vertex)vertices.get(face.q);
7893
- Vertex r = (Vertex)vertices.get(face.r);
7894
-
7895
- p.boundary = -1;
7896
- q.boundary = -1;
7897
- r.boundary = -1;
8284
+ assert(false);
78988285 }
7899
- else
7900
- assert(false);
79018286 }
7902
- }
79038287
79048288 // TouchVertex(minface.p);
79058289 // TouchVertex(minface.q);
....@@ -8100,6 +8484,7 @@
81008484 for (int i=vertfaces.size(); --i>=0;)
81018485 {
81028486 Face face = (Face) vertfaces.get(i);
8487
+ face.used = true;
81038488 face.good = 0; // false;
81048489 if (leafweights)
81058490 face.weight = -1;
....@@ -8146,7 +8531,7 @@
81468531 if (!trimmed)
81478532 return;
81488533
8149
- GrafreeD.linkUV = false;
8534
+ Grafreed.linkUV = false;
81508535
81518536 try
81528537 {
....@@ -8354,9 +8739,6 @@
83548739 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
83558740 }
83568741
8357
- static Camera localcamera = new Camera();
8358
- static cVector from = new cVector();
8359
- static cVector to = new cVector();
83608742 boolean trimmed = false;
83618743 boolean stripified = false;
83628744 transient boolean AOdone = false;
....@@ -8364,8 +8746,10 @@
83648746 /*transient*/ int maxIndexV = 0;
83658747 /*transient*/ int bufV, bufF;
83668748 // Raw version
8367
- private float[] positions;
8368
- private float[] normals;
8749
+ //private
8750
+ float[] positions;
8751
+ //private
8752
+ float[] normals;
83698753 float[] colors;
83708754 private float[] uvmap;
83718755 private int[] triangles;
....@@ -8379,7 +8763,8 @@
83798763 int[] startvertices;
83808764 float[] averagepoints;
83818765 float[] extremepoints;
8382
- float[] supportsizes; // distance of closest point
8766
+ float[] supportminsize; // distance of closest point
8767
+ float[] supportmaxsize; // distance of fartest point
83838768
83848769 transient Hashtable vertextable;
83858770 /*transient*/ private Vertex[] verticesCopy;