Normand Briere
2019-05-02 a7277e6c6381e55761f7fa87276260fac1c94d5e
BoundaryRep.java
....@@ -15,7 +15,7 @@
1515 {
1616 this(0, 0);
1717 }
18
-
18
+
1919 void SaveSupports()
2020 {
2121 transientsupport = support;
....@@ -172,16 +172,16 @@
172172 bufV = other.bufV;
173173 bufF = other.bufF;
174174
175
- positions = (float[]) GraphreeD.clone(other.positions);
176
- normals = (float[]) GraphreeD.clone(other.normals);
177
- colors = (float[]) GraphreeD.clone(other.colors);
178
- uvmap = (float[]) GraphreeD.clone(other.uvmap);
179
- triangles = (int[]) GraphreeD.clone(other.triangles);
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);
180180
181
- indices = (int[]) GraphreeD.clone(other.indices);
181
+ indices = (int[]) GrafreeD.clone(other.indices);
182182
183
- vertices = (Vector<Vertex>) GraphreeD.clone(other.vertices);
184
- faces = (Vector<Face>) GraphreeD.clone(other.faces);
183
+ vertices = (Vector<Vertex>) GrafreeD.clone(other.vertices);
184
+ faces = (Vector<Face>) GrafreeD.clone(other.faces);
185185 }
186186 else
187187 {
....@@ -497,10 +497,10 @@
497497 return dist2;
498498 }
499499
500
- static Vertex vertextemp = new Vertex();
501
- static Vertex vertextemp2 = new Vertex();
500
+ static Vertex vertextemp = new Vertex(true);
501
+ static Vertex vertextemp2 = new Vertex(true);
502502
503
- static double SEUIL = 0.1; // 0.1 for rag doll; 0.07;
503
+ static double SEUIL = 0.1f; // 0.1 for rag doll; 0.07;
504504
505505 // Compute weight of point w/r to this
506506 float ComputeWeight(Vertex v, double[][] toRoot, int k)
....@@ -570,8 +570,10 @@
570570
571571 if (dot > distmax)
572572 dot = distmax;
573
+ //return 0; // patch for strange behavior
573574 if (dot < -distmax)
574575 dot = -distmax;
576
+ //return 0; // patch for strange behavior
575577
576578 // v3 = GetVertex(this.startvertices[subsupport] + 16);
577579 //
....@@ -609,10 +611,12 @@
609611
610612 float dist2 = (float)Distance2(v, v2, 1E10, toRoot, k);
611613
612
- if (dist2 >= 2 * SEUIL*SEUIL) // && !CameraPane.CROWD) // weightmode
614
+ double seuil = SEUIL * 2;
615
+
616
+ if (dist2 >= 2 * seuil*seuil) // && !CameraPane.CROWD) // weightmode
613617 return 0;
614618
615
- dist2 /= 2 * SEUIL*SEUIL; // multiplied by two because center of support
619
+ dist2 /= 2 * seuil*seuil; // multiplied by two because center of support
616620 // could be far from closest point
617621
618622 // dist2 = Math.pow(dist2, 2);
....@@ -786,7 +790,7 @@
786790 v.weights[k] = other.ComputeWeight(v, toRoot, k); // (float)(supportsize * normalweight * nz / Math.pow(tx*tx+ty*ty+tz*tz, 1));
787791 v.totalweight += v.weights[k];
788792
789
- if (CameraPane.CROWD)
793
+ if (Globals.CROWD)
790794 {
791795 // System.out.print("weight = " + v.weights[k]);
792796 // System.out.println("; totalweight = " + v.totalweight);
....@@ -946,7 +950,7 @@
946950
947951 int nbsupports;
948952
949
- SEUIL = 0.1; // aout 2013
953
+ // sept 2017 SEUIL = 0.1; // aout 2013
950954
951955 supports = InitConnections(other);
952956
....@@ -982,7 +986,7 @@
982986
983987 int subsupports = 0;
984988
985
- SEUIL = 0.1; // aout 2013
989
+ // sept 2017 SEUIL = 0.1; // aout 2013
986990
987991 while (subsupports == 0)
988992 {
....@@ -1006,6 +1010,26 @@
10061010
10071011 vect.set(v);
10081012 vect.sub(vect2);
1013
+
1014
+// vertextemp.x = other.averagepoints[c*3];
1015
+// vertextemp.y = other.averagepoints[c*3+1];
1016
+// vertextemp.z = other.averagepoints[c*3+2];
1017
+//
1018
+// Vertex v3 = vertextemp2;
1019
+// v3.x = other.extremepoints[c*3];
1020
+// v3.y = other.extremepoints[c*3+1];
1021
+// v3.z = other.extremepoints[c*3+2];
1022
+//
1023
+// vect3.set(v3); // "X" axis apex
1024
+// vect3.sub(vertextemp); // origin (center)
1025
+//
1026
+// double distmax = vect3.length();
1027
+//
1028
+// vect3.set(v2); // "X" axis apex
1029
+// vect3.sub(vertextemp); // origin (center)
1030
+//
1031
+// if (vect3.length() >= distmax)
1032
+// continue;
10091033
10101034 if (mindistance > vect.dot(vect))
10111035 {
....@@ -1017,7 +1041,9 @@
10171041
10181042 subsupports = v.closestsupport==-1 ? 0 : supports[v.closestsupport].Length();
10191043
1020
- SEUIL *= 2;
1044
+ // previously for "contains", now for weights.
1045
+ assert(subsupports > 0);
1046
+ //SEUIL *= 2;
10211047 }
10221048
10231049 assert(subsupports > 0);
....@@ -1492,7 +1518,7 @@
14921518 InitFaceIndices();
14931519 }
14941520
1495
- BoundaryRep rep = (BoundaryRep) GraphreeD.clone(this);
1521
+ BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
14961522 //float[] v = new float[100];
14971523
14981524 for (int loops=1; --loops>=0;)
....@@ -1522,7 +1548,7 @@
15221548 InitFaceIndices();
15231549 }
15241550
1525
- BoundaryRep rep = (BoundaryRep) GraphreeD.clone(this);
1551
+ BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
15261552 //float[] v = new float[100];
15271553
15281554 for (int loops=10; --loops>=0;)
....@@ -2163,7 +2189,7 @@
21632189 // if (slow)
21642190 // aout 2013
21652191 // sept 2013 merde...
2166
- W = 13;
2192
+ W = 3; // 13;
21672193
21682194 // POSERATE
21692195 if (CameraPane.tickcount > 0 || CameraPane.SLOWPOSE)
....@@ -2600,7 +2626,7 @@
26002626 // if (stepout && !playedonce)
26012627 // {
26022628 // // sound
2603
-// GraphreeD.wav.play();
2629
+// GrafreeD.wav.play();
26042630 // playedonce = true;
26052631 // }
26062632 //
....@@ -2635,18 +2661,18 @@
26352661 if (false) // slow && stepout && onein)
26362662 {
26372663 // sound
2638
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
2664
+ cVector eye = Globals.theRenderer.EyeCamera().location;
26392665
26402666 Vertex v = GetVertex(0);
26412667
26422668 tmp.set(v);
26432669 tmp.sub(eye);
26442670
2645
- if (CameraPane.framecount - lastsoundtime > 30) // 0.25 secs
2671
+ if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26462672 {
2647
- GraphreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
2673
+ GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
26482674
2649
- lastsoundtime = CameraPane.framecount;
2675
+ lastsoundtime = Globals.framecount;
26502676 }
26512677
26522678 stepout = false;
....@@ -3129,7 +3155,27 @@
31293155 */
31303156 }
31313157
3132
- void GenUV()
3158
+ void UnfoldUV()
3159
+ {
3160
+ for (int i = 0; i < VertexCount(); i++)
3161
+ {
3162
+ Vertex v = GetVertex(i);
3163
+
3164
+ v.x = v.s;
3165
+ v.y = v.t;
3166
+ v.z = 0;
3167
+
3168
+ v.norm.x = 0;
3169
+ v.norm.y = 0;
3170
+ v.norm.z = 1;
3171
+
3172
+ SetVertex(v, i);
3173
+ }
3174
+ }
3175
+
3176
+ float power = 2;
3177
+
3178
+ void GenUV() // float power)
31333179 {
31343180 Trim();
31353181
....@@ -3193,6 +3239,125 @@
31933239 y -= 0.5;
31943240 z -= 0.5;
31953241
3242
+ double ax = Math.abs(x);
3243
+ double ay = Math.abs(y);
3244
+ double max = ax;
3245
+ if (max < ay)
3246
+ {
3247
+ max = ay;
3248
+ }
3249
+
3250
+ if (max == 0)
3251
+ {
3252
+ uvmap[i2] = 0.5f;
3253
+ uvmap[i2+1] = 0.5f;
3254
+ continue;
3255
+ }
3256
+
3257
+ x /= max;
3258
+ y /= max;
3259
+
3260
+ double angle = Math.acos(Math.abs(z*2));
3261
+
3262
+ double k = angle / Math.PI * 2;
3263
+
3264
+ assert(k >= 0);
3265
+
3266
+ // k == 0 => uv = 0 (center)
3267
+ // k == 1 => uv = -1,1 (border)
3268
+
3269
+ if (i == 0)
3270
+ System.out.println("power = " + power);
3271
+
3272
+ double length1 = (ax+ay)/max;
3273
+ double length2 = Math.sqrt(ax*ax + ay*ay) / max;
3274
+
3275
+ double t = k;
3276
+
3277
+ t = Math.pow(t, 3);
3278
+
3279
+ // Interpolate between k/length2 (center) and k (border)
3280
+ if (length2 > 0)
3281
+ k *= (1 - t) / length2 + t;
3282
+
3283
+ double u = k*x;
3284
+ double v = k*y;
3285
+
3286
+ u /= 2;
3287
+ v /= 2;
3288
+ u += 0.5;
3289
+ v += 0.5;
3290
+
3291
+ uvmap[i2] = (float) u;
3292
+ uvmap[i2+1] = (float) v;
3293
+ }
3294
+ }
3295
+
3296
+ void GenUVold(float power)
3297
+ {
3298
+ Trim();
3299
+
3300
+ cVector boxcenter = null;
3301
+ cVector minima, maxima;
3302
+ minima = new cVector();
3303
+ maxima = new cVector();
3304
+ minima.x = minima.y = minima.z = Double.MAX_VALUE;
3305
+ maxima.x = maxima.y = maxima.z = -Double.MAX_VALUE;
3306
+ for (int i = 0; i < VertexCount(); i++)
3307
+ {
3308
+ Vertex v = GetVertex(i);
3309
+
3310
+ if (minima.x > v.x)
3311
+ {
3312
+ minima.x = v.x;
3313
+ }
3314
+ if (minima.y > v.y)
3315
+ {
3316
+ minima.y = v.y;
3317
+ }
3318
+ if (minima.z > v.z)
3319
+ {
3320
+ minima.z = v.z;
3321
+ }
3322
+
3323
+ if (maxima.x < v.x)
3324
+ {
3325
+ maxima.x = v.x;
3326
+ }
3327
+ if (maxima.y < v.y)
3328
+ {
3329
+ maxima.y = v.y;
3330
+ }
3331
+ if (maxima.z < v.z)
3332
+ {
3333
+ maxima.z = v.z;
3334
+ }
3335
+ }
3336
+
3337
+ boxcenter = new cVector((maxima.x + minima.x) / 2, (maxima.y + minima.y) / 2, (maxima.z + minima.z) / 2);
3338
+ int i2 = 0, i3 = 0;
3339
+ for (int i = 0; i < positions.length/3; i++, i3 += 3, i2 += 2)
3340
+ {
3341
+// //uvmap[i2] = (float) normals[i3]*0.5f + 0.5f; // v.x;
3342
+// //uvmap[i2 + 1] = (float) normals[i3+1]*0.5f + 0.5f; //z;
3343
+// uvmap[i2] = (float) (positions[i3] - boxcenter.x);
3344
+// uvmap[i2 + 1] = (float) (positions[i3+2] - boxcenter.z);
3345
+// uvmap[i2] = (float) Math.atan2(positions[i3+1] - boxcenter.y, positions[i3] - boxcenter.x);
3346
+// uvmap[i2 + 1] = (float)(positions[i3+2] - boxcenter.z);
3347
+ // box UV
3348
+ double x = positions[i3] - minima.x; // - Math.floor(positions[i3]);
3349
+ double y = positions[i3+1] - minima.y; // - Math.floor(positions[i3+1]);
3350
+ double z = positions[i3+2] - minima.z; // - Math.floor(positions[i3+2]);
3351
+
3352
+ // [-1/2, 1/2]
3353
+ x /= maxima.x - minima.x;
3354
+ y /= maxima.y - minima.y;
3355
+ z /= maxima.z - minima.z;
3356
+
3357
+ x -= 0.5;
3358
+ y -= 0.5;
3359
+ z -= 0.5;
3360
+
31963361 // x *= 2;
31973362 // y *= 2;
31983363 // z *= 2;
....@@ -3219,6 +3384,15 @@
32193384
32203385 z = Math.cos(angle/2);
32213386
3387
+ assert(z >= 0);
3388
+ assert(z <= 1);
3389
+
3390
+ /**/
3391
+ //z = Math.pow(z, power); //1.08f);
3392
+
3393
+ if (i == 0)
3394
+ System.out.println("power = " + power);
3395
+
32223396 // sqrt(k2*x2 + k2*z2 + y2) = length
32233397 // k2*x2 + k2*z2 = length2 - y2
32243398 // k2 = (length2 - y2) / (x2 + z2)
....@@ -3229,7 +3403,7 @@
32293403 k /= x*x + y*y;
32303404 }
32313405 else
3232
- GraphreeD.Assert(z == 1);
3406
+ GrafreeD.Assert(z == 1);
32333407
32343408 if (k < 0)
32353409 k = 0;
....@@ -3238,6 +3412,7 @@
32383412
32393413 x *= k;
32403414 y *= k;
3415
+ /**/
32413416
32423417 double max = Math.abs(x);
32433418 if (max < Math.abs(y))
....@@ -3250,10 +3425,15 @@
32503425 }
32513426
32523427 // max = Math.sqrt(max*2)/2;
3428
+// double x2 = Math.pow(Math.abs(x), 1/power);
3429
+// double y2 = Math.pow(Math.abs(y), 1/power);
3430
+// double z2 = Math.pow(Math.abs(z), 1/power);
3431
+// max = Math.pow(x2 + y2 + z2, power);
32533432
32543433 // if (!(max > 0))
3255
- assert(max > 0);
3256
-
3434
+ //assert(max > 0);
3435
+ assert(max >= 0);
3436
+
32573437 x /= max;
32583438 y /= max;
32593439 z /= max;
....@@ -3531,7 +3711,7 @@
35313711 e.printStackTrace();
35323712 }
35333713
3534
- Trim(wastrim,true,crease,wasstrip,false);
3714
+ Trim(true/*wastrim*/,true,crease,wasstrip,false);
35353715 }
35363716
35373717 void GenNormalsJME()
....@@ -3722,6 +3902,11 @@
37223902 tsa.getNormals(0, normals);
37233903 tsa.getTextureCoordinates(0, 0, uvmap);
37243904 // tsa.getColors(0, colors);
3905
+
3906
+ for (int i=colors.length; --i>=0;)
3907
+ {
3908
+ colors[i] = 1;
3909
+ }
37253910
37263911 int stripcount = tsa.getNumStrips();
37273912 triangles = new int[stripcount];
....@@ -3776,10 +3961,19 @@
37763961 for (int i = 0; i < VertexCount(); i++)
37773962 {
37783963 Vertex v = GetVertex(i);
3964
+
3965
+ vertextemp.set(v);
3966
+
37793967 //if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
37803968 {
3781
- GenerateNormal(i, v);
3782
- SetVertex(v, i);
3969
+ if (!GenerateNormal(i, vertextemp))
3970
+ continue;
3971
+
3972
+ if (v.norm.dot(vertextemp.norm) < 0)
3973
+ vertextemp.norm.mul(-1);
3974
+
3975
+ if (v.norm.dot(vertextemp.norm) < 0.9)
3976
+ SetVertex(vertextemp, i);
37833977 }
37843978 }
37853979
....@@ -3790,7 +3984,7 @@
37903984 static cVector temp2 = new cVector();
37913985 static cVector temp3 = new cVector();
37923986
3793
- void GenerateNormal(int index, Vertex v)
3987
+ boolean GenerateNormal(int index, Vertex v)
37943988 {
37953989 //System.out.println("Old normal = " + v.norm);
37963990 LA.setVector(v.norm, 0, 0, 0);
....@@ -3819,6 +4013,10 @@
38194013 LA.vecSub(p/*.pos*/, v/*.pos*/, temp1);
38204014 LA.vecSub(q/*.pos*/, v/*.pos*/, temp2);
38214015 }
4016
+ else
4017
+ {
4018
+ continue;
4019
+ }
38224020
38234021 //LA.vecNormalize(temp1);
38244022 //LA.vecNormalize(temp2);
....@@ -3829,17 +4027,25 @@
38294027 double s = temp3.length();
38304028 //double c = temp2.dot(temp1);
38314029
4030
+ if (s == 0)
4031
+ return false;
4032
+
38324033 float angle = 1; // (float) Math.atan2(s, c);
38334034 //if(angle < 0) angle = -angle;
38344035
38354036 //LA.vecNormalize(temp3);
38364037 LA.vecScale(temp3, angle / s);
38374038
4039
+// if (temp3.dot(v.norm) < 0)
4040
+// assert(temp3.dot(v.norm) >= 0);
4041
+
38384042 LA.vecAdd(temp3, v.norm, v.norm);
38394043 }
38404044
38414045 LA.vecNormalize(v.norm);
38424046 //System.out.println("New normal = " + v.norm);
4047
+
4048
+ return true;
38434049 }
38444050
38454051 double Arccos(double x)
....@@ -4233,7 +4439,7 @@
42334439 int count = VertexCount();
42344440
42354441 // mars 2014
4236
- while (step >= count)
4442
+ while (step > count)
42374443 step /= 10;
42384444
42394445 for (int i = 0; i < count; i+=step)
....@@ -4381,7 +4587,7 @@
43814587 }
43824588 }
43834589
4384
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4590
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
43854591 {
43864592 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
43874593 CameraPane.tempmat,0, CameraPane.tempmat2,0,
....@@ -4413,14 +4619,14 @@
44134619 // june 2014
44144620 // Camera parentcam = cam;
44154621 //
4416
-// if (cam == CameraPane.theRenderer.cameras[0])
4622
+// if (cam == Globals.theRenderer.cameras[0])
44174623 // {
4418
-// parentcam = CameraPane.theRenderer.cameras[1];
4624
+// parentcam = Globals.theRenderer.cameras[1];
44194625 // }
44204626 //
4421
-// if (cam == CameraPane.theRenderer.cameras[1])
4627
+// if (cam == Globals.theRenderer.cameras[1])
44224628 // {
4423
-// parentcam = CameraPane.theRenderer.cameras[0];
4629
+// parentcam = Globals.theRenderer.cameras[0];
44244630 // }
44254631
44264632 gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0);
....@@ -4846,7 +5052,7 @@
48465052 return verticesCopy;
48475053 }
48485054
4849
- void PreprocessOcclusion(CameraPane cp, double[][] transform)
5055
+ void PreprocessOcclusion(iCameraPane cp, double[][] transform)
48505056 {
48515057 if (//!trimmed ||
48525058 AOdone)
....@@ -4855,80 +5061,7 @@
48555061 return;
48565062 }
48575063
4858
- Camera keep = cp.renderCamera;
4859
- cp.renderCamera = localcamera;
4860
-
4861
- if (trimmed)
4862
- {
4863
- float[] colors = new float[positions.length / 3];
4864
-
4865
- int i3 = 0;
4866
- for (int i = 0; i < positions.length / 3; i++, i3 += 3)
4867
- {
4868
- if (normals[i3] == 0 && normals[i3+1] == 0 && normals[i3+2] == 0)
4869
- continue;
4870
-
4871
- from.set(positions[i3], positions[i3 + 1], positions[i3 + 2]);
4872
- to.set(positions[i3] + normals[i3],
4873
- positions[i3 + 1] + normals[i3 + 1],
4874
- positions[i3 + 2] + normals[i3 + 2]);
4875
- LA.xformPos(from, transform, from);
4876
- LA.xformPos(to, transform, to); // RIGID ONLY
4877
- localcamera.setAim(from, to);
4878
-
4879
- CameraPane.occlusionbuffer.display();
4880
-
4881
- if (CameraPane.DEBUG_OCCLUSION)
4882
- cp.display(); // debug
4883
-
4884
- colors[i] = cp.vertexOcclusion.r;
4885
- //colors[i3 + 1] = cp.vertexOcclusion.g;
4886
- //colors[i3 + 2] = cp.vertexOcclusion.b;
4887
-
4888
- if ((i % 1000) == 0 && i != 0)
4889
- {
4890
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
4891
- //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
4892
- System.out.println((int) (100.0 * i / (positions.length / 3)) + "% (" + i + " of " + (positions.length / 3) + ")");
4893
- }
4894
- }
4895
-
4896
- this.colors = colors;
4897
- }
4898
- else
4899
- {
4900
- for (int i = 0; i < VertexCount(); i++)
4901
- {
4902
- Vertex v = GetVertex(i);
4903
-
4904
- if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
4905
- continue;
4906
-
4907
- from.set(v.x, v.y, v.z);
4908
- to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
4909
- LA.xformPos(from, transform, from);
4910
- LA.xformPos(to, transform, to); // RIGID ONLY
4911
- localcamera.setAim(from, to);
4912
-
4913
- CameraPane.occlusionbuffer.display();
4914
-
4915
- if (CameraPane.DEBUG_OCCLUSION)
4916
- cp.display(); // debug
4917
-
4918
- v.AO = cp.vertexOcclusion.r;
4919
-
4920
- if ((i % 1000) == 0 && i != 0)
4921
- {
4922
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
4923
- //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
4924
- System.out.println((int) (100.0 * i / VertexCount()) + "% (" + i + " of " + VertexCount() + ")");
4925
- }
4926
- }
4927
- }
4928
-
4929
- System.out.println("done.");
4930
-
4931
- cp.renderCamera = keep;
5064
+ cp.PrepOcclusion(this, transform);
49325065
49335066 AOdone = true;
49345067 }
....@@ -5036,6 +5169,59 @@
50365169 }
50375170 }
50385171 colors = null;
5172
+ }
5173
+
5174
+ void CreateMesh(iHeightField hf, int x, int y)
5175
+ {
5176
+ BoundaryRep tmp = new BoundaryRep();
5177
+
5178
+ int vc = 0;
5179
+
5180
+ Vertex v = new Vertex(true);
5181
+
5182
+ for (int i=0; i<x; i++)
5183
+ {
5184
+ for (int j=0; j<y; j++)
5185
+ {
5186
+// Vertex v = tmp.GetVertex(vc++);
5187
+
5188
+ v.s = v.x = i;
5189
+ v.t = v.z = j;
5190
+ v.s /= x; v.t /= y;
5191
+ v.y = hf.f(i,j);
5192
+
5193
+ int iu = tmp.AddTableVertex(v);
5194
+
5195
+ v.s = v.x = i+1;
5196
+ v.t = v.z = j;
5197
+ v.s /= x; v.t /= y;
5198
+ v.y = hf.f(i+1,j);
5199
+
5200
+ int iv = tmp.AddTableVertex(v);
5201
+
5202
+ v.s = v.x = i+1;
5203
+ v.t = v.z = j+1;
5204
+ v.s /= x; v.t /= y;
5205
+ v.y = hf.f(i+1,j+1);
5206
+
5207
+ int iw = tmp.AddTableVertex(v);
5208
+
5209
+ v.s = v.x = i;
5210
+ v.t = v.z = j+1;
5211
+ v.s /= x; v.t /= y;
5212
+ v.y = hf.f(i,j+1);
5213
+
5214
+ int ix = tmp.AddTableVertex(v);
5215
+
5216
+ tmp.AddFace(iu,iw,iv);
5217
+ tmp.AddFace(iu,ix,iw);
5218
+ }
5219
+ }
5220
+
5221
+ Set(tmp);
5222
+
5223
+ Trim(true,false,true);
5224
+ ClearColors();
50395225 }
50405226
50415227 void Stripify()
....@@ -5297,18 +5483,10 @@
52975483 double minweight = 1E10;
52985484
52995485 nbbadfaces = 0;
5300
- for (int i=faces.size(); (i-=8)>=0;)
5486
+ for (int i=0; i<faces.size(); i+=8)
5487
+// for (int i=faces.size(); (i-=8)>=0;)
53015488 {
53025489 Face face = (Face) faces.get(i);
5303
-
5304
- //?? if (face.weight < 0)
5305
- // continue;
5306
-
5307
- double K = 1; // 0.01; // .25;
5308
-
5309
- double factor = (1-K)*face.nbiterations + K; //*face.weight;
5310
-
5311
- double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
53125490
53135491 if (!Valid(face))
53145492 {
....@@ -5327,10 +5505,21 @@
53275505 !ValidValence(face.r))
53285506 continue;
53295507
5508
+ //?? if (face.weight < 0)
5509
+ // continue;
5510
+
5511
+ double K = 1; // 0.01; // .25;
5512
+
5513
+ double factor = (1-K)*face.nbiterations + K; //*face.weight;
5514
+
5515
+ double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5516
+
53305517 if (minweight > weight)
53315518 {
53325519 minweight = weight;
53335520 chosen = i;
5521
+ if (minweight == 0)
5522
+ break;
53345523 }
53355524 }
53365525
....@@ -6170,6 +6359,7 @@
61706359
61716360 void InitWeights()
61726361 {
6362
+ new Exception().printStackTrace();
61736363 System.exit(0);
61746364 int n = 0;
61756365 int b = 0;
....@@ -7019,6 +7209,7 @@
70197209 assert(f2.contains(i));
70207210 assert(f3.contains(i));
70217211
7212
+ // when r is the "center", p is along the boundary
70227213 while (f0.r != i)
70237214 {
70247215 int t = f0.p;
....@@ -7075,59 +7266,90 @@
70757266 f0 = f3;
70767267 f3 = t;
70777268 }
7078
- atleastone = true;
70797269
7270
+ int va = f0.q;
7271
+ int vb = f0.r;
7272
+ int vc = -1;
7273
+
7274
+ Face toremove1 = null;
7275
+ Face toremove2 = null;
7276
+
7277
+ // f0 is the buffer for the first new triangle,
7278
+ // and otherf is the other upper one.
70807279 Face otherf = null;
70817280
70827281 if (f1.contains(f0.p))
70837282 {
70847283 if (f1.p == f0.p)
70857284 {
7285
+ assert(false);
70867286 f0.r = f1.q;
70877287 }
70887288 else
70897289 {
70907290 assert(f1.q == f0.p);
7091
- f0.r = f1.p;
7291
+ vc = f1.p;
70927292 }
70937293
70947294 otherf = f2;
7095
- faces.remove(f1);
7096
- faces.remove(f3);
7295
+ toremove1 = f1;
7296
+ toremove2 = f3;
70977297 }
70987298 else
70997299 if (f2.contains(f0.p))
71007300 {
71017301 if (f2.p == f0.p)
71027302 {
7303
+ assert(false);
71037304 f0.r = f2.q;
71047305 }
71057306 else
71067307 {
71077308 assert(f2.q == f0.p);
7108
- f0.r = f2.p;
7309
+ vc = f2.p;
71097310 }
71107311
71117312 otherf = f3;
7112
- faces.remove(f1);
7113
- faces.remove(f2);
7313
+ toremove1 = f1;
7314
+ toremove2 = f2;
71147315 }
71157316 if (f3.contains(f0.p))
71167317 {
71177318 if (f3.p == f0.p)
71187319 {
7320
+// assert(false);
7321
+ new Exception().printStackTrace();
71197322 f0.r = f3.q;
71207323 }
71217324 else
71227325 {
71237326 assert(f3.q == f0.p);
7124
- f0.r = f3.p;
7327
+ vc = f3.p;
71257328 }
71267329
71277330 otherf = f1;
7128
- faces.remove(f2);
7129
- faces.remove(f3);
7331
+ toremove1 = f2;
7332
+ toremove2 = f3;
71307333 }
7334
+
7335
+ vertextemp.set(vertices.get(va));
7336
+ vertextemp.sub(vertices.get(vb));
7337
+ vertextemp.normalize();
7338
+ vertextemp2.set(vertices.get(vc));
7339
+ vertextemp2.sub(vertices.get(vb));
7340
+ vertextemp2.normalize();
7341
+
7342
+ if (vertextemp.dot(vertextemp2) > -0.95)
7343
+ {
7344
+ continue;
7345
+ }
7346
+
7347
+ atleastone = true;
7348
+
7349
+ f0.r = vc;
7350
+
7351
+ faces.remove(toremove1);
7352
+ faces.remove(toremove2);
71317353
71327354 if (!f0.contains(otherf.p))
71337355 {
....@@ -7335,7 +7557,7 @@
73357557 Trim();
73367558 Untrim();
73377559
7338
- BoundaryRep tmp = new BoundaryRep(); // (BoundaryRep) GraphreeD.clone(this);
7560
+ BoundaryRep tmp = new BoundaryRep(); // (BoundaryRep) GrafreeD.clone(this);
73397561
73407562 double minx = Float.POSITIVE_INFINITY;
73417563 double maxx = Float.NEGATIVE_INFINITY;
....@@ -7373,7 +7595,7 @@
73737595 if (max < maxz - minz)
73747596 max = maxz - minz;
73757597
7376
- tmp.THRESHOLD = max/25; // 50;
7598
+ tmp.THRESHOLD = 0.5; // max/25; // 50;
73777599
73787600 tmp.faces.clear();
73797601
....@@ -7498,7 +7720,7 @@
74987720 s3 = new cVector();
74997721 }
75007722
7501
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
7723
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
75027724
75037725 try
75047726 {
....@@ -7593,7 +7815,7 @@
75937815 {
75947816 if (i++%100 == 0)
75957817 {
7596
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
7818
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
75977819 System.out.println("#faces = " + faces.size());
75987820 // if (i != 1)
75997821 // break;
....@@ -7637,7 +7859,7 @@
76377859 //Trim(true,cJME.gennormals,true,false); // doesn't work
76387860 Trim(true,false,false,false,false);
76397861
7640
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
7862
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
76417863 }
76427864
76437865 void UpdateIndices(Face face, Face minface)
....@@ -7932,6 +8154,8 @@
79328154
79338155 minface.q = minface.r = minface.p;
79348156
8157
+ int count = 0;
8158
+
79358159 for (int i=0; i<faces.size(); i++)
79368160 {
79378161 Face face = (Face) faces.get(i);
....@@ -7943,6 +8167,9 @@
79438167 TouchVertex(face.r, true); // , minface.weight);
79448168 // assert(!lock);
79458169 faces.remove(i--);
8170
+ count++;
8171
+ if (count == 4)
8172
+ break;
79468173 }
79478174 }
79488175
....@@ -8006,7 +8233,7 @@
80068233 if (!trimmed)
80078234 return;
80088235
8009
- GraphreeD.linkUV = false;
8236
+ GrafreeD.linkUV = false;
80108237
80118238 try
80128239 {
....@@ -8214,9 +8441,6 @@
82148441 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
82158442 }
82168443
8217
- static Camera localcamera = new Camera();
8218
- static cVector from = new cVector();
8219
- static cVector to = new cVector();
82208444 boolean trimmed = false;
82218445 boolean stripified = false;
82228446 transient boolean AOdone = false;
....@@ -8224,8 +8448,10 @@
82248448 /*transient*/ int maxIndexV = 0;
82258449 /*transient*/ int bufV, bufF;
82268450 // Raw version
8227
- private float[] positions;
8228
- private float[] normals;
8451
+ //private
8452
+ float[] positions;
8453
+ //private
8454
+ float[] normals;
82298455 float[] colors;
82308456 private float[] uvmap;
82318457 private int[] triangles;