Normand Briere
2019-07-24 f555e2cacc4470c5b2217a14d40d2b39c4a57ba2
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,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
....@@ -2661,7 +2699,7 @@
26612699 if (false) // slow && stepout && onein)
26622700 {
26632701 // sound
2664
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
2702
+ cVector eye = Globals.theRenderer.EyeCamera().location;
26652703
26662704 Vertex v = GetVertex(0);
26672705
....@@ -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,
....@@ -4460,14 +4829,14 @@
44604829 // june 2014
44614830 // Camera parentcam = cam;
44624831 //
4463
-// if (cam == CameraPane.theRenderer.cameras[0])
4832
+// if (cam == Globals.theRenderer.cameras[0])
44644833 // {
4465
-// parentcam = CameraPane.theRenderer.cameras[1];
4834
+// parentcam = Globals.theRenderer.cameras[1];
44664835 // }
44674836 //
4468
-// if (cam == CameraPane.theRenderer.cameras[1])
4837
+// if (cam == Globals.theRenderer.cameras[1])
44694838 // {
4470
-// parentcam = CameraPane.theRenderer.cameras[0];
4839
+// parentcam = Globals.theRenderer.cameras[0];
44714840 // }
44724841
44734842 gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 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];
....@@ -4893,7 +5271,7 @@
48935271 return verticesCopy;
48945272 }
48955273
4896
- void PreprocessOcclusion(CameraPane cp, double[][] transform)
5274
+ void PreprocessOcclusion(iCameraPane cp, double[][] transform)
48975275 {
48985276 if (//!trimmed ||
48995277 AOdone)
....@@ -4902,80 +5280,7 @@
49025280 return;
49035281 }
49045282
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;
5283
+ cp.PrepOcclusion(this, transform);
49795284
49805285 AOdone = true;
49815286 }
....@@ -5390,17 +5695,27 @@
53905695
53915696 transient int nbbadfaces; // ?? = 1000000;
53925697
5393
- int ChooseTriangle()
5698
+ /*
5699
+ */
5700
+ int ChooseTriangle(boolean firstEquilateral)
53945701 {
53955702 int chosen = -1;
53965703
53975704 double minweight = 1E10;
53985705
5706
+ int step = 8; // ?
5707
+
5708
+ if (firstEquilateral)
5709
+ step = 1;
5710
+
53995711 nbbadfaces = 0;
5400
- for (int i=0; i<faces.size(); i+=8)
5712
+ for (int i=0; i<faces.size(); i+=step)
54015713 // for (int i=faces.size(); (i-=8)>=0;)
54025714 {
54035715 Face face = (Face) faces.get(i);
5716
+
5717
+ if (face.used)
5718
+ continue;
54045719
54055720 if (!Valid(face))
54065721 {
....@@ -5410,6 +5725,15 @@
54105725
54115726 if (Boundary(face))
54125727 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;
54135737
54145738 if (!ValidValence(face))
54155739 continue;
....@@ -5422,22 +5746,55 @@
54225746 //?? if (face.weight < 0)
54235747 // continue;
54245748
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)
5749
+ if (firstEquilateral)
54325750 {
5433
- 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
+
54345760 chosen = i;
5435
- if (minweight == 0)
5436
- 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
+ }
54375778 }
54385779 }
54395780
54405781 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;
54415798 }
54425799
54435800 static boolean remove3valence = true;
....@@ -5473,7 +5830,7 @@
54735830 }
54745831 else
54755832 {
5476
- assert(links.size() == vertices.size());
5833
+ // TODO Grafreed.Assert(links.size() == vertices.size());
54775834
54785835 links.setSize(vertices.size());
54795836 for (int i=vertices.size(); --i>=0;)
....@@ -5481,6 +5838,7 @@
54815838 // linkstouched[i] = false;
54825839 if (links.get(i) == null) // ??
54835840 {
5841
+ new Exception().printStackTrace();
54845842 links.set(i, new Vector(8));
54855843 // linkstouched[i] = true;
54865844 }
....@@ -5491,6 +5849,8 @@
54915849 }
54925850 }
54935851
5852
+ boolean once = false;
5853
+
54945854 for (int i=faces.size(); --i>=0;)
54955855 {
54965856 Face face = (Face) faces.get(i);
....@@ -5502,6 +5862,9 @@
55025862 //if (linkstouched[face.r])
55035863 links.get(face.r).add(face);
55045864
5865
+ if (face.used)
5866
+ once = true;
5867
+
55055868 face.good = 1;
55065869 face.boundary = -1;
55075870 }
....@@ -6273,6 +6636,7 @@
62736636
62746637 void InitWeights()
62756638 {
6639
+ new Exception().printStackTrace();
62766640 System.exit(0);
62776641 int n = 0;
62786642 int b = 0;
....@@ -6866,6 +7230,10 @@
68667230 return (face.boundary = 1) == 1;
68677231 }
68687232
7233
+ // June 2019
7234
+ if (true)
7235
+ return (face.boundary = 0) == 1;
7236
+
68697237 // reverse triangle test
68707238 q1.set(p);
68717239 q2.set(q);
....@@ -7315,7 +7683,7 @@
73157683 //InitWeights();
73167684 }
73177685
7318
- int chosen = ChooseTriangle(); // Best is slow and not really better
7686
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
73197687
73207688 if (chosen == -1)
73217689 {
....@@ -7329,7 +7697,7 @@
73297697 //remove3valence = false;
73307698 // InitWeights();
73317699
7332
- chosen = ChooseTriangle();
7700
+ chosen = ChooseTriangle(true);
73337701 }
73347702 }
73357703
....@@ -7605,7 +7973,7 @@
76057973
76067974 // boolean lock;
76077975
7608
- void SplitInTwo(boolean reduction34, boolean onlyone)
7976
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
76097977 {
76107978 if (stripified)
76117979 {
....@@ -7633,7 +8001,7 @@
76338001 s3 = new cVector();
76348002 }
76358003
7636
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
8004
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
76378005
76388006 try
76398007 {
....@@ -7642,12 +8010,12 @@
76428010 {
76438011 System.err.println("EXCEPTION CAUGHT");
76448012 e.printStackTrace();
7645
- return;
8013
+ return false;
76468014 } catch (Error e)
76478015 {
76488016 System.err.println("ERROR CAUGHT");
76498017 e.printStackTrace();
7650
- return;
8018
+ return false;
76518019 }
76528020
76538021 System.out.println("# faces = " + faces.size());
....@@ -7657,6 +8025,7 @@
76578025 {
76588026 Face face = (Face) faces.get(i);
76598027
8028
+ face.used = false;
76608029 face.nbiterations = 1;
76618030 face.weight = -1;
76628031 face.boundary = -1;
....@@ -7708,6 +8077,11 @@
77088077 nbbadfaces = faces.size();
77098078 //remove3valence = true;
77108079
8080
+ int count = 2;
8081
+
8082
+ if (onlyone)
8083
+ count = 1;
8084
+
77118085 firstpass = true;
77128086
77138087 int n = faces.size();
....@@ -7723,12 +8097,13 @@
77238097 System.out.print('.');
77248098 }
77258099 System.out.println();
8100
+ boolean atleastone = false;
77268101 int i = 0;
7727
- while (reduction34 || faces.size() > n/2)
8102
+ while (true) // reduction34 || faces.size() > n/2)
77288103 {
77298104 if (i++%100 == 0)
77308105 {
7731
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
8106
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
77328107 System.out.println("#faces = " + faces.size());
77338108 // if (i != 1)
77348109 // break;
....@@ -7746,6 +8121,8 @@
77468121 {
77478122 if (!RemoveOneTriangle())
77488123 break;
8124
+
8125
+ atleastone = true;
77498126 }
77508127 // if (iterationcount == 0)
77518128 // break;
....@@ -7756,8 +8133,8 @@
77568133 break;
77578134 }
77588135 firstpass = false;
7759
- if (onlyone)
7760
- break; // one triangle only
8136
+// if (--count<0 && !reduction34)
8137
+// break; // one triangle only
77618138 }
77628139
77638140 InitLinks(false); // for further display
....@@ -7772,7 +8149,9 @@
77728149 //Trim(true,cJME.gennormals,true,false); // doesn't work
77738150 Trim(true,false,false,false,false);
77748151
7775
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8152
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8153
+
8154
+ return atleastone;
77768155 }
77778156
77788157 void UpdateIndices(Face face, Face minface)
....@@ -7785,18 +8164,21 @@
77858164 face.p = minface.p;
77868165 //if (leafweights)
77878166 face.good = 0; // false;
8167
+ face.used = true;
77888168 }
77898169 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
77908170 {
77918171 face.q = minface.p;
77928172 //if (leafweights)
77938173 face.good = 0; // false;
8174
+ face.used = true;
77948175 }
77958176 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
77968177 {
77978178 face.r = minface.p;
77988179 //if (leafweights)
77998180 face.good = 0; // false;
8181
+ face.used = true;
78008182 }
78018183
78028184 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7856,50 +8238,50 @@
78568238 if (v == 2)
78578239 vert = minface.r;
78588240 // 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)
8241
+ Vector<Face> vertfaces = links.get(vert);
8242
+ for (int i=vertfaces.size(); --i>=0;)
78708243 {
7871
- 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)
78728252 {
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);
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;
78848280 }
78858281 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;
8282
+ assert(false);
78988283 }
7899
- else
7900
- assert(false);
79018284 }
7902
- }
79038285
79048286 // TouchVertex(minface.p);
79058287 // TouchVertex(minface.q);
....@@ -8100,6 +8482,7 @@
81008482 for (int i=vertfaces.size(); --i>=0;)
81018483 {
81028484 Face face = (Face) vertfaces.get(i);
8485
+ face.used = true;
81038486 face.good = 0; // false;
81048487 if (leafweights)
81058488 face.weight = -1;
....@@ -8146,7 +8529,7 @@
81468529 if (!trimmed)
81478530 return;
81488531
8149
- GrafreeD.linkUV = false;
8532
+ Grafreed.linkUV = false;
81508533
81518534 try
81528535 {
....@@ -8354,9 +8737,6 @@
83548737 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
83558738 }
83568739
8357
- static Camera localcamera = new Camera();
8358
- static cVector from = new cVector();
8359
- static cVector to = new cVector();
83608740 boolean trimmed = false;
83618741 boolean stripified = false;
83628742 transient boolean AOdone = false;
....@@ -8364,8 +8744,10 @@
83648744 /*transient*/ int maxIndexV = 0;
83658745 /*transient*/ int bufV, bufF;
83668746 // Raw version
8367
- private float[] positions;
8368
- private float[] normals;
8747
+ //private
8748
+ float[] positions;
8749
+ //private
8750
+ float[] normals;
83698751 float[] colors;
83708752 private float[] uvmap;
83718753 private int[] triangles;
....@@ -8379,7 +8761,8 @@
83798761 int[] startvertices;
83808762 float[] averagepoints;
83818763 float[] extremepoints;
8382
- float[] supportsizes; // distance of closest point
8764
+ float[] supportminsize; // distance of closest point
8765
+ float[] supportmaxsize; // distance of fartest point
83838766
83848767 transient Hashtable vertextable;
83858768 /*transient*/ private Vertex[] verticesCopy;