Normand Briere
2019-07-27 1af7d3700724834e40ad8636bc9a56cdc3b19b15
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)
....@@ -790,7 +821,7 @@
790821 v.weights[k] = other.ComputeWeight(v, toRoot, k); // (float)(supportsize * normalweight * nz / Math.pow(tx*tx+ty*ty+tz*tz, 1));
791822 v.totalweight += v.weights[k];
792823
793
- if (CameraPane.CROWD)
824
+ if (Globals.CROWD)
794825 {
795826 // System.out.print("weight = " + v.weights[k]);
796827 // System.out.println("; totalweight = " + v.totalweight);
....@@ -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,9 @@
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] == 0)
2002
+ // < 0.001 * v.totalweight)
19702003 {
19712004 //testweight += v.weights[j-1];
19722005 continue;
....@@ -2247,6 +2280,8 @@
22472280
22482281 transient int lastsoundtime;
22492282
2283
+ transient boolean once = false;
2284
+
22502285 void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked)
22512286 {
22522287 if (LA.isIdentity(toRoot))
....@@ -2302,7 +2337,11 @@
23022337
23032338 if (v.totalweight == 0)
23042339 {
2305
- System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2340
+ if (!once)
2341
+ {
2342
+ System.err.println("v.totalweight == 0! --> " + this + " : " + other);
2343
+ once = true;
2344
+ }
23062345 continue;
23072346 }
23082347
....@@ -2661,18 +2700,18 @@
26612700 if (false) // slow && stepout && onein)
26622701 {
26632702 // sound
2664
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
2703
+ cVector eye = Globals.theRenderer.EyeCamera().location;
26652704
26662705 Vertex v = GetVertex(0);
26672706
26682707 tmp.set(v);
26692708 tmp.sub(eye);
26702709
2671
- if (CameraPane.framecount - lastsoundtime > 30) // 0.25 secs
2710
+ if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26722711 {
2673
- GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
2712
+ Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
26742713
2675
- lastsoundtime = CameraPane.framecount;
2714
+ lastsoundtime = Globals.framecount;
26762715 }
26772716
26782717 stepout = false;
....@@ -3098,6 +3137,7 @@
30983137 //
30993138 // transient VertexCompare[] vertexcompare = null;
31003139
3140
+ // Check if v0 is close enough from any vertex of the given subobject of this.
31013141 boolean Contains(Vertex v0, int object)
31023142 {
31033143 int start = startvertices[object-1];
....@@ -3155,7 +3195,27 @@
31553195 */
31563196 }
31573197
3158
- void GenUV()
3198
+ void UnfoldUV()
3199
+ {
3200
+ for (int i = 0; i < VertexCount(); i++)
3201
+ {
3202
+ Vertex v = GetVertex(i);
3203
+
3204
+ v.x = v.s;
3205
+ v.y = v.t;
3206
+ v.z = 0;
3207
+
3208
+ v.norm.x = 0;
3209
+ v.norm.y = 0;
3210
+ v.norm.z = 1;
3211
+
3212
+ SetVertex(v, i);
3213
+ }
3214
+ }
3215
+
3216
+ float power = 2;
3217
+
3218
+ void GenUV() // float power)
31593219 {
31603220 Trim();
31613221
....@@ -3219,6 +3279,125 @@
32193279 y -= 0.5;
32203280 z -= 0.5;
32213281
3282
+ double ax = Math.abs(x);
3283
+ double ay = Math.abs(y);
3284
+ double max = ax;
3285
+ if (max < ay)
3286
+ {
3287
+ max = ay;
3288
+ }
3289
+
3290
+ if (max == 0)
3291
+ {
3292
+ uvmap[i2] = 0.5f;
3293
+ uvmap[i2+1] = 0.5f;
3294
+ continue;
3295
+ }
3296
+
3297
+ x /= max;
3298
+ y /= max;
3299
+
3300
+ double angle = Math.acos(Math.abs(z*2));
3301
+
3302
+ double k = angle / Math.PI * 2;
3303
+
3304
+ assert(k >= 0);
3305
+
3306
+ // k == 0 => uv = 0 (center)
3307
+ // k == 1 => uv = -1,1 (border)
3308
+
3309
+ if (i == 0)
3310
+ System.out.println("power = " + power);
3311
+
3312
+ double length1 = (ax+ay)/max;
3313
+ double length2 = Math.sqrt(ax*ax + ay*ay) / max;
3314
+
3315
+ double t = k;
3316
+
3317
+ t = Math.pow(t, 3);
3318
+
3319
+ // Interpolate between k/length2 (center) and k (border)
3320
+ if (length2 > 0)
3321
+ k *= (1 - t) / length2 + t;
3322
+
3323
+ double u = k*x;
3324
+ double v = k*y;
3325
+
3326
+ u /= 2;
3327
+ v /= 2;
3328
+ u += 0.5;
3329
+ v += 0.5;
3330
+
3331
+ uvmap[i2] = (float) u;
3332
+ uvmap[i2+1] = (float) v;
3333
+ }
3334
+ }
3335
+
3336
+ void GenUVold(float power)
3337
+ {
3338
+ Trim();
3339
+
3340
+ cVector boxcenter = null;
3341
+ cVector minima, maxima;
3342
+ minima = new cVector();
3343
+ maxima = new cVector();
3344
+ minima.x = minima.y = minima.z = Double.MAX_VALUE;
3345
+ maxima.x = maxima.y = maxima.z = -Double.MAX_VALUE;
3346
+ for (int i = 0; i < VertexCount(); i++)
3347
+ {
3348
+ Vertex v = GetVertex(i);
3349
+
3350
+ if (minima.x > v.x)
3351
+ {
3352
+ minima.x = v.x;
3353
+ }
3354
+ if (minima.y > v.y)
3355
+ {
3356
+ minima.y = v.y;
3357
+ }
3358
+ if (minima.z > v.z)
3359
+ {
3360
+ minima.z = v.z;
3361
+ }
3362
+
3363
+ if (maxima.x < v.x)
3364
+ {
3365
+ maxima.x = v.x;
3366
+ }
3367
+ if (maxima.y < v.y)
3368
+ {
3369
+ maxima.y = v.y;
3370
+ }
3371
+ if (maxima.z < v.z)
3372
+ {
3373
+ maxima.z = v.z;
3374
+ }
3375
+ }
3376
+
3377
+ boxcenter = new cVector((maxima.x + minima.x) / 2, (maxima.y + minima.y) / 2, (maxima.z + minima.z) / 2);
3378
+ int i2 = 0, i3 = 0;
3379
+ for (int i = 0; i < positions.length/3; i++, i3 += 3, i2 += 2)
3380
+ {
3381
+// //uvmap[i2] = (float) normals[i3]*0.5f + 0.5f; // v.x;
3382
+// //uvmap[i2 + 1] = (float) normals[i3+1]*0.5f + 0.5f; //z;
3383
+// uvmap[i2] = (float) (positions[i3] - boxcenter.x);
3384
+// uvmap[i2 + 1] = (float) (positions[i3+2] - boxcenter.z);
3385
+// uvmap[i2] = (float) Math.atan2(positions[i3+1] - boxcenter.y, positions[i3] - boxcenter.x);
3386
+// uvmap[i2 + 1] = (float)(positions[i3+2] - boxcenter.z);
3387
+ // box UV
3388
+ double x = positions[i3] - minima.x; // - Math.floor(positions[i3]);
3389
+ double y = positions[i3+1] - minima.y; // - Math.floor(positions[i3+1]);
3390
+ double z = positions[i3+2] - minima.z; // - Math.floor(positions[i3+2]);
3391
+
3392
+ // [-1/2, 1/2]
3393
+ x /= maxima.x - minima.x;
3394
+ y /= maxima.y - minima.y;
3395
+ z /= maxima.z - minima.z;
3396
+
3397
+ x -= 0.5;
3398
+ y -= 0.5;
3399
+ z -= 0.5;
3400
+
32223401 // x *= 2;
32233402 // y *= 2;
32243403 // z *= 2;
....@@ -3245,6 +3424,15 @@
32453424
32463425 z = Math.cos(angle/2);
32473426
3427
+ assert(z >= 0);
3428
+ assert(z <= 1);
3429
+
3430
+ /**/
3431
+ //z = Math.pow(z, power); //1.08f);
3432
+
3433
+ if (i == 0)
3434
+ System.out.println("power = " + power);
3435
+
32483436 // sqrt(k2*x2 + k2*z2 + y2) = length
32493437 // k2*x2 + k2*z2 = length2 - y2
32503438 // k2 = (length2 - y2) / (x2 + z2)
....@@ -3255,7 +3443,7 @@
32553443 k /= x*x + y*y;
32563444 }
32573445 else
3258
- GrafreeD.Assert(z == 1);
3446
+ Grafreed.Assert(z == 1);
32593447
32603448 if (k < 0)
32613449 k = 0;
....@@ -3264,6 +3452,7 @@
32643452
32653453 x *= k;
32663454 y *= k;
3455
+ /**/
32673456
32683457 double max = Math.abs(x);
32693458 if (max < Math.abs(y))
....@@ -3276,10 +3465,15 @@
32763465 }
32773466
32783467 // max = Math.sqrt(max*2)/2;
3468
+// double x2 = Math.pow(Math.abs(x), 1/power);
3469
+// double y2 = Math.pow(Math.abs(y), 1/power);
3470
+// double z2 = Math.pow(Math.abs(z), 1/power);
3471
+// max = Math.pow(x2 + y2 + z2, power);
32793472
32803473 // if (!(max > 0))
3281
- assert(max > 0);
3282
-
3474
+ //assert(max > 0);
3475
+ assert(max >= 0);
3476
+
32833477 x /= max;
32843478 y /= max;
32853479 z /= max;
....@@ -3542,6 +3736,111 @@
35423736 */
35433737 }
35443738
3739
+ void GenerateNormals2(boolean crease)
3740
+ {
3741
+ cVector tempVector = new cVector();
3742
+
3743
+// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>();
3744
+//
3745
+//
3746
+// for (int i=0; i<this.VertexCount(); i++)
3747
+// {
3748
+// Vertex v = this.GetVertex(i);
3749
+//
3750
+// tempVector.set(v);
3751
+//
3752
+// cVector n = tableBase.get(tempVector.ToFloat());
3753
+//
3754
+// if (n != null)
3755
+// {
3756
+// continue;
3757
+// }
3758
+//
3759
+// tableBase.put(new cVector(tempVector), new cVector(v.norm));
3760
+// }
3761
+
3762
+ BoundaryRep tempSupport = this.support;
3763
+
3764
+ this.support = null;
3765
+
3766
+ BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this);
3767
+
3768
+ this.support = tempSupport;
3769
+
3770
+ //tempRep.Unstripify();
3771
+
3772
+ tempRep.GenerateNormals2(crease);
3773
+
3774
+ boolean keepnormal = Vertex.normalmode;
3775
+ boolean epsequal = Grafreed.epsequal;
3776
+
3777
+ Vertex.normalmode = false;
3778
+ Grafreed.epsequal = false; // A bit strange
3779
+
3780
+ // No need to have a match for vertex counts.
3781
+
3782
+ java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>();
3783
+
3784
+ for (int i=0; i<tempRep.VertexCount(); i++)
3785
+ {
3786
+ Vertex v = tempRep.GetVertex(i);
3787
+
3788
+ cVector n = table.get(tempVector.ToFloat());
3789
+
3790
+ if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0)
3791
+ {
3792
+ //continue;
3793
+ }
3794
+
3795
+ tempVector.set(v);
3796
+
3797
+ //cVector nBase = tableBase.get(tempVector);
3798
+
3799
+ //if (v.norm.dot(nBase) < 0.9)
3800
+ //{
3801
+ // continue;
3802
+ //}
3803
+
3804
+ if (n != null && n.x == 1 && n.y == 0 && n.z == 0)
3805
+ {
3806
+ //continue;
3807
+ }
3808
+
3809
+ if (n != null)
3810
+ {
3811
+// if (n.dot(v.norm) < 0)
3812
+// n.sub(v.norm);
3813
+// else
3814
+// n.add(v.norm);
3815
+//
3816
+// n.normalize();
3817
+ continue;
3818
+ }
3819
+
3820
+ table.put(new cVector(tempVector), new cVector(v.norm));
3821
+ }
3822
+
3823
+ for (int i=0; i<this.VertexCount(); i++)
3824
+ {
3825
+ Vertex v = this.GetVertex(i);
3826
+
3827
+ tempVector.set(v);
3828
+
3829
+ cVector n = table.get(tempVector.ToFloat());
3830
+
3831
+ //if (n.dot(v.norm) < 0)
3832
+ if (n == null)
3833
+ continue;
3834
+
3835
+ LA.vecCopy(n, v.norm);
3836
+
3837
+ this.SetVertex(v, i);
3838
+ }
3839
+
3840
+ Grafreed.epsequal = epsequal;
3841
+ Vertex.normalmode = keepnormal;
3842
+ }
3843
+
35453844 void GenerateNormals(boolean crease)
35463845 {
35473846 boolean wastrim = trimmed;
....@@ -3558,6 +3857,28 @@
35583857 }
35593858
35603859 Trim(true/*wastrim*/,true,crease,wasstrip,false);
3860
+ }
3861
+
3862
+ void GenerateNormalsMesh()
3863
+ {
3864
+ if (stripified)
3865
+ {
3866
+ Unstripify();
3867
+ }
3868
+
3869
+ if (trimmed)
3870
+ {
3871
+ normals = null;
3872
+ }
3873
+ else
3874
+ {
3875
+ for (int i=VertexCount(); --i>=0;)
3876
+ {
3877
+ Vertex v = GetVertex(i);
3878
+
3879
+ v.norm = null;
3880
+ }
3881
+ }
35613882 }
35623883
35633884 void GenNormalsJME()
....@@ -3682,7 +4003,7 @@
36824003 NormalGenerator ng;
36834004
36844005 if (crease)
3685
- ng = new NormalGenerator(Math.PI/6); // default is 44 degrees (or Math.PI/3); // /4);
4006
+ ng = new NormalGenerator(Math.PI/4); // default is 44 degrees (or Math.PI/3); // /4);
36864007 else
36874008 ng = new NormalGenerator(Math.PI); // (Math.PI / 3); // /4);
36884009
....@@ -3715,6 +4036,10 @@
37154036 {
37164037 triangles[i] = i;
37174038 }
4039
+
4040
+// Untrim();
4041
+ if (!trimmed)
4042
+ MergeNormals();
37184043 }
37194044 }
37204045
....@@ -3748,6 +4073,11 @@
37484073 tsa.getNormals(0, normals);
37494074 tsa.getTextureCoordinates(0, 0, uvmap);
37504075 // tsa.getColors(0, colors);
4076
+
4077
+ for (int i=colors.length; --i>=0;)
4078
+ {
4079
+ colors[i] = 1;
4080
+ }
37514081
37524082 int stripcount = tsa.getNumStrips();
37534083 triangles = new int[stripcount];
....@@ -3770,6 +4100,10 @@
37704100 triangles = new int[1];
37714101 triangles[0] = 3;
37724102 }
4103
+
4104
+ //Untrim();
4105
+ if (!trimmed)
4106
+ MergeNormals();
37734107 }
37744108
37754109 /*
....@@ -3819,6 +4153,42 @@
38194153 }
38204154
38214155 Vertex.normalmode = false;
4156
+ }
4157
+
4158
+ void MergeNormals()
4159
+ {
4160
+ assert(!trimmed);
4161
+
4162
+ boolean smooth = Grafreed.smoothmode;
4163
+ boolean link = Grafreed.linkUV;
4164
+ Grafreed.smoothmode = true;
4165
+ Grafreed.linkUV = true;
4166
+
4167
+ System.out.println("#Vertex = " + VertexCount());
4168
+ System.out.println("#Face = " + FaceCount());
4169
+
4170
+ java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>();
4171
+
4172
+ for (int i = 0; i < VertexCount(); i++)
4173
+ {
4174
+ Vertex v = GetVertex(i);
4175
+
4176
+ if (!table.contains(v))
4177
+ {
4178
+ table.add(v);
4179
+ }
4180
+ }
4181
+
4182
+ Grafreed.smoothmode = smooth;
4183
+ Grafreed.linkUV = link;
4184
+
4185
+// for (int i = 0; i < VertexCount(); i++)
4186
+// {
4187
+// Vertex v = GetVertex(i);
4188
+//
4189
+// table.add(v);
4190
+// }
4191
+
38224192 }
38234193
38244194 static cVector temp1 = new cVector();
....@@ -4428,7 +4798,7 @@
44284798 }
44294799 }
44304800
4431
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4801
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
44324802 {
44334803 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
44344804 CameraPane.tempmat,0, CameraPane.tempmat2,0,
....@@ -4460,14 +4830,14 @@
44604830 // june 2014
44614831 // Camera parentcam = cam;
44624832 //
4463
-// if (cam == CameraPane.theRenderer.cameras[0])
4833
+// if (cam == Globals.theRenderer.cameras[0])
44644834 // {
4465
-// parentcam = CameraPane.theRenderer.cameras[1];
4835
+// parentcam = Globals.theRenderer.cameras[1];
44664836 // }
44674837 //
4468
-// if (cam == CameraPane.theRenderer.cameras[1])
4838
+// if (cam == Globals.theRenderer.cameras[1])
44694839 // {
4470
-// parentcam = CameraPane.theRenderer.cameras[0];
4840
+// parentcam = Globals.theRenderer.cameras[0];
44714841 // }
44724842
44734843 gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0);
....@@ -4593,16 +4963,25 @@
45934963 {
45944964 i3 = positions.length-3;
45954965 i2 = uvmap.length - 2;
4596
- new Exception().printStackTrace();
4966
+ //new Exception().printStackTrace();
45974967 }
45984968
45994969 v./*pos.*/x = positions[i3];
46004970 v./*pos.*/y = positions[i3 + 1];
46014971 v./*pos.*/z = positions[i3 + 2];
46024972
4603
- v.norm.x = normals[i3];
4604
- v.norm.y = normals[i3 + 1];
4605
- v.norm.z = normals[i3 + 2];
4973
+ if (normals == null)
4974
+ {
4975
+ v.norm.x = 0;
4976
+ v.norm.y = 0;
4977
+ v.norm.z = 0;
4978
+ }
4979
+ else
4980
+ {
4981
+ v.norm.x = normals[i3];
4982
+ v.norm.y = normals[i3 + 1];
4983
+ v.norm.z = normals[i3 + 2];
4984
+ }
46064985
46074986 v.s = uvmap[i2];
46084987 v.t = uvmap[i2 + 1];
....@@ -4893,7 +5272,7 @@
48935272 return verticesCopy;
48945273 }
48955274
4896
- void PreprocessOcclusion(CameraPane cp, double[][] transform)
5275
+ void PreprocessOcclusion(iCameraPane cp, double[][] transform)
48975276 {
48985277 if (//!trimmed ||
48995278 AOdone)
....@@ -4902,80 +5281,7 @@
49025281 return;
49035282 }
49045283
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;
5284
+ cp.PrepOcclusion(this, transform);
49795285
49805286 AOdone = true;
49815287 }
....@@ -5390,17 +5696,27 @@
53905696
53915697 transient int nbbadfaces; // ?? = 1000000;
53925698
5393
- int ChooseTriangle()
5699
+ /*
5700
+ */
5701
+ int ChooseTriangle(boolean firstEquilateral)
53945702 {
53955703 int chosen = -1;
53965704
53975705 double minweight = 1E10;
53985706
5707
+ int step = 8; // ?
5708
+
5709
+ if (firstEquilateral)
5710
+ step = 1;
5711
+
53995712 nbbadfaces = 0;
5400
- for (int i=0; i<faces.size(); i+=8)
5713
+ for (int i=0; i<faces.size(); i+=step)
54015714 // for (int i=faces.size(); (i-=8)>=0;)
54025715 {
54035716 Face face = (Face) faces.get(i);
5717
+
5718
+ if (face.used)
5719
+ continue;
54045720
54055721 if (!Valid(face))
54065722 {
....@@ -5410,6 +5726,15 @@
54105726
54115727 if (Boundary(face))
54125728 continue;
5729
+
5730
+// if (Boundary(face.p))
5731
+// continue;
5732
+//
5733
+// if (Boundary(face.q))
5734
+// continue;
5735
+//
5736
+// if (Boundary(face.r))
5737
+// continue;
54135738
54145739 if (!ValidValence(face))
54155740 continue;
....@@ -5422,22 +5747,55 @@
54225747 //?? if (face.weight < 0)
54235748 // continue;
54245749
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)
5750
+ if (firstEquilateral)
54325751 {
5433
- minweight = weight;
5752
+ if (OneFaceUsed(links.get(face.p)))
5753
+ continue;
5754
+
5755
+ if (OneFaceUsed(links.get(face.q)))
5756
+ continue;
5757
+
5758
+ if (OneFaceUsed(links.get(face.r)))
5759
+ continue;
5760
+
54345761 chosen = i;
5435
- if (minweight == 0)
5436
- break;
5762
+ break;
5763
+ }
5764
+ else
5765
+ {
5766
+ double K = 1; // 0.01; // .25;
5767
+
5768
+ double factor = (1-K)*face.nbiterations + K; //*face.weight;
5769
+
5770
+ double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5771
+
5772
+ if (minweight > weight)
5773
+ {
5774
+ minweight = weight;
5775
+ chosen = i;
5776
+ if (minweight == 0)
5777
+ break;
5778
+ }
54375779 }
54385780 }
54395781
54405782 return chosen;
5783
+ }
5784
+
5785
+ private boolean OneFaceUsed(Vector<Face> faces)
5786
+ {
5787
+ if (faces.size() != 6)
5788
+ return true;
5789
+
5790
+ for (int i=0; i<6; i+=1)
5791
+ {
5792
+ if (faces.get(i).used)
5793
+ {
5794
+ return true;
5795
+ }
5796
+ }
5797
+
5798
+ return false;
54415799 }
54425800
54435801 static boolean remove3valence = true;
....@@ -5473,7 +5831,7 @@
54735831 }
54745832 else
54755833 {
5476
- assert(links.size() == vertices.size());
5834
+ // TODO Grafreed.Assert(links.size() == vertices.size());
54775835
54785836 links.setSize(vertices.size());
54795837 for (int i=vertices.size(); --i>=0;)
....@@ -5481,6 +5839,7 @@
54815839 // linkstouched[i] = false;
54825840 if (links.get(i) == null) // ??
54835841 {
5842
+ new Exception().printStackTrace();
54845843 links.set(i, new Vector(8));
54855844 // linkstouched[i] = true;
54865845 }
....@@ -5491,6 +5850,8 @@
54915850 }
54925851 }
54935852
5853
+ boolean once = false;
5854
+
54945855 for (int i=faces.size(); --i>=0;)
54955856 {
54965857 Face face = (Face) faces.get(i);
....@@ -5502,6 +5863,9 @@
55025863 //if (linkstouched[face.r])
55035864 links.get(face.r).add(face);
55045865
5866
+ if (face.used)
5867
+ once = true;
5868
+
55055869 face.good = 1;
55065870 face.boundary = -1;
55075871 }
....@@ -6273,6 +6637,7 @@
62736637
62746638 void InitWeights()
62756639 {
6640
+ new Exception().printStackTrace();
62766641 System.exit(0);
62776642 int n = 0;
62786643 int b = 0;
....@@ -6866,6 +7231,10 @@
68667231 return (face.boundary = 1) == 1;
68677232 }
68687233
7234
+ // June 2019
7235
+ if (true)
7236
+ return (face.boundary = 0) == 1;
7237
+
68697238 // reverse triangle test
68707239 q1.set(p);
68717240 q2.set(q);
....@@ -7315,7 +7684,7 @@
73157684 //InitWeights();
73167685 }
73177686
7318
- int chosen = ChooseTriangle(); // Best is slow and not really better
7687
+ int chosen = ChooseTriangle(true); // Best is slow and not really better
73197688
73207689 if (chosen == -1)
73217690 {
....@@ -7329,7 +7698,7 @@
73297698 //remove3valence = false;
73307699 // InitWeights();
73317700
7332
- chosen = ChooseTriangle();
7701
+ chosen = ChooseTriangle(true);
73337702 }
73347703 }
73357704
....@@ -7605,7 +7974,7 @@
76057974
76067975 // boolean lock;
76077976
7608
- void SplitInTwo(boolean reduction34, boolean onlyone)
7977
+ boolean SplitInTwo(boolean reduction34, boolean onlyone)
76097978 {
76107979 if (stripified)
76117980 {
....@@ -7633,7 +8002,7 @@
76338002 s3 = new cVector();
76348003 }
76358004
7636
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
8005
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
76378006
76388007 try
76398008 {
....@@ -7642,12 +8011,12 @@
76428011 {
76438012 System.err.println("EXCEPTION CAUGHT");
76448013 e.printStackTrace();
7645
- return;
8014
+ return false;
76468015 } catch (Error e)
76478016 {
76488017 System.err.println("ERROR CAUGHT");
76498018 e.printStackTrace();
7650
- return;
8019
+ return false;
76518020 }
76528021
76538022 System.out.println("# faces = " + faces.size());
....@@ -7657,6 +8026,7 @@
76578026 {
76588027 Face face = (Face) faces.get(i);
76598028
8029
+ face.used = false;
76608030 face.nbiterations = 1;
76618031 face.weight = -1;
76628032 face.boundary = -1;
....@@ -7708,6 +8078,11 @@
77088078 nbbadfaces = faces.size();
77098079 //remove3valence = true;
77108080
8081
+ int count = 2;
8082
+
8083
+ if (onlyone)
8084
+ count = 1;
8085
+
77118086 firstpass = true;
77128087
77138088 int n = faces.size();
....@@ -7723,12 +8098,13 @@
77238098 System.out.print('.');
77248099 }
77258100 System.out.println();
8101
+ boolean atleastone = false;
77268102 int i = 0;
7727
- while (reduction34 || faces.size() > n/2)
8103
+ while (true) // reduction34 || faces.size() > n/2)
77288104 {
77298105 if (i++%100 == 0)
77308106 {
7731
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
8107
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
77328108 System.out.println("#faces = " + faces.size());
77338109 // if (i != 1)
77348110 // break;
....@@ -7746,6 +8122,8 @@
77468122 {
77478123 if (!RemoveOneTriangle())
77488124 break;
8125
+
8126
+ atleastone = true;
77498127 }
77508128 // if (iterationcount == 0)
77518129 // break;
....@@ -7756,8 +8134,8 @@
77568134 break;
77578135 }
77588136 firstpass = false;
7759
- if (onlyone)
7760
- break; // one triangle only
8137
+// if (--count<0 && !reduction34)
8138
+// break; // one triangle only
77618139 }
77628140
77638141 InitLinks(false); // for further display
....@@ -7772,7 +8150,9 @@
77728150 //Trim(true,cJME.gennormals,true,false); // doesn't work
77738151 Trim(true,false,false,false,false);
77748152
7775
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8153
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
8154
+
8155
+ return atleastone;
77768156 }
77778157
77788158 void UpdateIndices(Face face, Face minface)
....@@ -7785,18 +8165,21 @@
77858165 face.p = minface.p;
77868166 //if (leafweights)
77878167 face.good = 0; // false;
8168
+ face.used = true;
77888169 }
77898170 if (face.q == minface.p || face.q == minface.q || face.q == minface.r)
77908171 {
77918172 face.q = minface.p;
77928173 //if (leafweights)
77938174 face.good = 0; // false;
8175
+ face.used = true;
77948176 }
77958177 if (face.r == minface.p || face.r == minface.q || face.r == minface.r)
77968178 {
77978179 face.r = minface.p;
77988180 //if (leafweights)
77998181 face.good = 0; // false;
8182
+ face.used = true;
78008183 }
78018184
78028185 if (face.p >/*=*/ minface.q && face.p < minface.r)
....@@ -7856,50 +8239,50 @@
78568239 if (v == 2)
78578240 vert = minface.r;
78588241 // 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)
8242
+ Vector<Face> vertfaces = links.get(vert);
8243
+ for (int i=vertfaces.size(); --i>=0;)
78708244 {
7871
- if (!leafweights)
8245
+ Face face = (Face) vertfaces.get(i);
8246
+
8247
+ // if (face.weight == 10000)
8248
+ // continue;
8249
+
8250
+ if (face.p == minface.p || face.q == minface.p || face.r == minface.p ||
8251
+ face.p == minface.q || face.q == minface.q || face.r == minface.q ||
8252
+ face.p == minface.r || face.q == minface.r || face.r == minface.r)
78728253 {
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);
8254
+ if (!leafweights)
8255
+ {
8256
+ // if(minfaceweight <= 0)
8257
+ // assert(minfaceweight > 0);
8258
+ //
8259
+ // //FaceWeight(face);
8260
+ // if(face.weight < 0)
8261
+ // assert(face.weight >= 0);
8262
+
8263
+ face.weight += minfaceweight;
8264
+
8265
+ // if (face.weight >= 10000)
8266
+ // assert(face.weight < 10000);
8267
+ }
8268
+ else
8269
+ face.weight = -1;
8270
+
8271
+ face.nbiterations += 1;
8272
+ face.boundary = -1;
8273
+
8274
+ Vertex p = (Vertex)vertices.get(face.p);
8275
+ Vertex q = (Vertex)vertices.get(face.q);
8276
+ Vertex r = (Vertex)vertices.get(face.r);
8277
+
8278
+ p.boundary = -1;
8279
+ q.boundary = -1;
8280
+ r.boundary = -1;
78848281 }
78858282 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;
8283
+ assert(false);
78988284 }
7899
- else
7900
- assert(false);
79018285 }
7902
- }
79038286
79048287 // TouchVertex(minface.p);
79058288 // TouchVertex(minface.q);
....@@ -8100,6 +8483,7 @@
81008483 for (int i=vertfaces.size(); --i>=0;)
81018484 {
81028485 Face face = (Face) vertfaces.get(i);
8486
+ face.used = true;
81038487 face.good = 0; // false;
81048488 if (leafweights)
81058489 face.weight = -1;
....@@ -8146,7 +8530,7 @@
81468530 if (!trimmed)
81478531 return;
81488532
8149
- GrafreeD.linkUV = false;
8533
+ Grafreed.linkUV = false;
81508534
81518535 try
81528536 {
....@@ -8354,9 +8738,6 @@
83548738 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
83558739 }
83568740
8357
- static Camera localcamera = new Camera();
8358
- static cVector from = new cVector();
8359
- static cVector to = new cVector();
83608741 boolean trimmed = false;
83618742 boolean stripified = false;
83628743 transient boolean AOdone = false;
....@@ -8364,8 +8745,10 @@
83648745 /*transient*/ int maxIndexV = 0;
83658746 /*transient*/ int bufV, bufF;
83668747 // Raw version
8367
- private float[] positions;
8368
- private float[] normals;
8748
+ //private
8749
+ float[] positions;
8750
+ //private
8751
+ float[] normals;
83698752 float[] colors;
83708753 private float[] uvmap;
83718754 private int[] triangles;
....@@ -8379,7 +8762,8 @@
83798762 int[] startvertices;
83808763 float[] averagepoints;
83818764 float[] extremepoints;
8382
- float[] supportsizes; // distance of closest point
8765
+ float[] supportminsize; // distance of closest point
8766
+ float[] supportmaxsize; // distance of fartest point
83838767
83848768 transient Hashtable vertextable;
83858769 /*transient*/ private Vertex[] verticesCopy;