Normand Briere
2019-04-28 f1c718cce66e5651a0dae91375db6ebfaded1a92
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,115 @@
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
+ x /= max;
3251
+ y /= max;
3252
+
3253
+ double angle = Math.acos(Math.abs(z*2));
3254
+
3255
+ double k = angle / Math.PI * 2;
3256
+
3257
+ // k == 0 => uv = 0 (center)
3258
+ // k == 1 => uv = -1,1 (border)
3259
+
3260
+ if (i == 0)
3261
+ System.out.println("power = " + power);
3262
+
3263
+ double length1 = (ax+ay)/max;
3264
+ double length2 = Math.sqrt(ax*ax + ay*ay) / max;
3265
+
3266
+ double t = k;
3267
+
3268
+ t = Math.pow(t, 3);
3269
+
3270
+ // Interpolate between k/length2 (center) and k (border)
3271
+ k = k / length2 * (1 - t) + k * t;
3272
+
3273
+ double u = k*x;
3274
+ double v = k*y;
3275
+
3276
+ u /= 2;
3277
+ v /= 2;
3278
+ u += 0.5;
3279
+ v += 0.5;
3280
+
3281
+ uvmap[i2] = (float) u;
3282
+ uvmap[i2+1] = (float) v;
3283
+ }
3284
+ }
3285
+
3286
+ void GenUVold(float power)
3287
+ {
3288
+ Trim();
3289
+
3290
+ cVector boxcenter = null;
3291
+ cVector minima, maxima;
3292
+ minima = new cVector();
3293
+ maxima = new cVector();
3294
+ minima.x = minima.y = minima.z = Double.MAX_VALUE;
3295
+ maxima.x = maxima.y = maxima.z = -Double.MAX_VALUE;
3296
+ for (int i = 0; i < VertexCount(); i++)
3297
+ {
3298
+ Vertex v = GetVertex(i);
3299
+
3300
+ if (minima.x > v.x)
3301
+ {
3302
+ minima.x = v.x;
3303
+ }
3304
+ if (minima.y > v.y)
3305
+ {
3306
+ minima.y = v.y;
3307
+ }
3308
+ if (minima.z > v.z)
3309
+ {
3310
+ minima.z = v.z;
3311
+ }
3312
+
3313
+ if (maxima.x < v.x)
3314
+ {
3315
+ maxima.x = v.x;
3316
+ }
3317
+ if (maxima.y < v.y)
3318
+ {
3319
+ maxima.y = v.y;
3320
+ }
3321
+ if (maxima.z < v.z)
3322
+ {
3323
+ maxima.z = v.z;
3324
+ }
3325
+ }
3326
+
3327
+ boxcenter = new cVector((maxima.x + minima.x) / 2, (maxima.y + minima.y) / 2, (maxima.z + minima.z) / 2);
3328
+ int i2 = 0, i3 = 0;
3329
+ for (int i = 0; i < positions.length/3; i++, i3 += 3, i2 += 2)
3330
+ {
3331
+// //uvmap[i2] = (float) normals[i3]*0.5f + 0.5f; // v.x;
3332
+// //uvmap[i2 + 1] = (float) normals[i3+1]*0.5f + 0.5f; //z;
3333
+// uvmap[i2] = (float) (positions[i3] - boxcenter.x);
3334
+// uvmap[i2 + 1] = (float) (positions[i3+2] - boxcenter.z);
3335
+// uvmap[i2] = (float) Math.atan2(positions[i3+1] - boxcenter.y, positions[i3] - boxcenter.x);
3336
+// uvmap[i2 + 1] = (float)(positions[i3+2] - boxcenter.z);
3337
+ // box UV
3338
+ double x = positions[i3] - minima.x; // - Math.floor(positions[i3]);
3339
+ double y = positions[i3+1] - minima.y; // - Math.floor(positions[i3+1]);
3340
+ double z = positions[i3+2] - minima.z; // - Math.floor(positions[i3+2]);
3341
+
3342
+ // [-1/2, 1/2]
3343
+ x /= maxima.x - minima.x;
3344
+ y /= maxima.y - minima.y;
3345
+ z /= maxima.z - minima.z;
3346
+
3347
+ x -= 0.5;
3348
+ y -= 0.5;
3349
+ z -= 0.5;
3350
+
31963351 // x *= 2;
31973352 // y *= 2;
31983353 // z *= 2;
....@@ -3219,6 +3374,15 @@
32193374
32203375 z = Math.cos(angle/2);
32213376
3377
+ assert(z >= 0);
3378
+ assert(z <= 1);
3379
+
3380
+ /**/
3381
+ //z = Math.pow(z, power); //1.08f);
3382
+
3383
+ if (i == 0)
3384
+ System.out.println("power = " + power);
3385
+
32223386 // sqrt(k2*x2 + k2*z2 + y2) = length
32233387 // k2*x2 + k2*z2 = length2 - y2
32243388 // k2 = (length2 - y2) / (x2 + z2)
....@@ -3229,7 +3393,7 @@
32293393 k /= x*x + y*y;
32303394 }
32313395 else
3232
- GraphreeD.Assert(z == 1);
3396
+ GrafreeD.Assert(z == 1);
32333397
32343398 if (k < 0)
32353399 k = 0;
....@@ -3238,6 +3402,7 @@
32383402
32393403 x *= k;
32403404 y *= k;
3405
+ /**/
32413406
32423407 double max = Math.abs(x);
32433408 if (max < Math.abs(y))
....@@ -3250,10 +3415,15 @@
32503415 }
32513416
32523417 // max = Math.sqrt(max*2)/2;
3418
+// double x2 = Math.pow(Math.abs(x), 1/power);
3419
+// double y2 = Math.pow(Math.abs(y), 1/power);
3420
+// double z2 = Math.pow(Math.abs(z), 1/power);
3421
+// max = Math.pow(x2 + y2 + z2, power);
32533422
32543423 // if (!(max > 0))
3255
- assert(max > 0);
3256
-
3424
+ //assert(max > 0);
3425
+ assert(max >= 0);
3426
+
32573427 x /= max;
32583428 y /= max;
32593429 z /= max;
....@@ -3531,7 +3701,7 @@
35313701 e.printStackTrace();
35323702 }
35333703
3534
- Trim(wastrim,true,crease,wasstrip,false);
3704
+ Trim(true/*wastrim*/,true,crease,wasstrip,false);
35353705 }
35363706
35373707 void GenNormalsJME()
....@@ -3776,10 +3946,19 @@
37763946 for (int i = 0; i < VertexCount(); i++)
37773947 {
37783948 Vertex v = GetVertex(i);
3949
+
3950
+ vertextemp.set(v);
3951
+
37793952 //if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
37803953 {
3781
- GenerateNormal(i, v);
3782
- SetVertex(v, i);
3954
+ if (!GenerateNormal(i, vertextemp))
3955
+ continue;
3956
+
3957
+ if (v.norm.dot(vertextemp.norm) < 0)
3958
+ vertextemp.norm.mul(-1);
3959
+
3960
+ if (v.norm.dot(vertextemp.norm) < 0.9)
3961
+ SetVertex(vertextemp, i);
37833962 }
37843963 }
37853964
....@@ -3790,7 +3969,7 @@
37903969 static cVector temp2 = new cVector();
37913970 static cVector temp3 = new cVector();
37923971
3793
- void GenerateNormal(int index, Vertex v)
3972
+ boolean GenerateNormal(int index, Vertex v)
37943973 {
37953974 //System.out.println("Old normal = " + v.norm);
37963975 LA.setVector(v.norm, 0, 0, 0);
....@@ -3819,6 +3998,10 @@
38193998 LA.vecSub(p/*.pos*/, v/*.pos*/, temp1);
38203999 LA.vecSub(q/*.pos*/, v/*.pos*/, temp2);
38214000 }
4001
+ else
4002
+ {
4003
+ continue;
4004
+ }
38224005
38234006 //LA.vecNormalize(temp1);
38244007 //LA.vecNormalize(temp2);
....@@ -3829,17 +4012,25 @@
38294012 double s = temp3.length();
38304013 //double c = temp2.dot(temp1);
38314014
4015
+ if (s == 0)
4016
+ return false;
4017
+
38324018 float angle = 1; // (float) Math.atan2(s, c);
38334019 //if(angle < 0) angle = -angle;
38344020
38354021 //LA.vecNormalize(temp3);
38364022 LA.vecScale(temp3, angle / s);
38374023
4024
+// if (temp3.dot(v.norm) < 0)
4025
+// assert(temp3.dot(v.norm) >= 0);
4026
+
38384027 LA.vecAdd(temp3, v.norm, v.norm);
38394028 }
38404029
38414030 LA.vecNormalize(v.norm);
38424031 //System.out.println("New normal = " + v.norm);
4032
+
4033
+ return true;
38434034 }
38444035
38454036 double Arccos(double x)
....@@ -4233,7 +4424,7 @@
42334424 int count = VertexCount();
42344425
42354426 // mars 2014
4236
- while (step >= count)
4427
+ while (step > count)
42374428 step /= 10;
42384429
42394430 for (int i = 0; i < count; i+=step)
....@@ -4381,7 +4572,7 @@
43814572 }
43824573 }
43834574
4384
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4575
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
43854576 {
43864577 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
43874578 CameraPane.tempmat,0, CameraPane.tempmat2,0,
....@@ -4413,14 +4604,14 @@
44134604 // june 2014
44144605 // Camera parentcam = cam;
44154606 //
4416
-// if (cam == CameraPane.theRenderer.cameras[0])
4607
+// if (cam == Globals.theRenderer.cameras[0])
44174608 // {
4418
-// parentcam = CameraPane.theRenderer.cameras[1];
4609
+// parentcam = Globals.theRenderer.cameras[1];
44194610 // }
44204611 //
4421
-// if (cam == CameraPane.theRenderer.cameras[1])
4612
+// if (cam == Globals.theRenderer.cameras[1])
44224613 // {
4423
-// parentcam = CameraPane.theRenderer.cameras[0];
4614
+// parentcam = Globals.theRenderer.cameras[0];
44244615 // }
44254616
44264617 gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0);
....@@ -4846,7 +5037,7 @@
48465037 return verticesCopy;
48475038 }
48485039
4849
- void PreprocessOcclusion(CameraPane cp, double[][] transform)
5040
+ void PreprocessOcclusion(iCameraPane cp, double[][] transform)
48505041 {
48515042 if (//!trimmed ||
48525043 AOdone)
....@@ -4855,80 +5046,7 @@
48555046 return;
48565047 }
48575048
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;
5049
+ cp.PrepOcclusion(this, transform);
49325050
49335051 AOdone = true;
49345052 }
....@@ -5036,6 +5154,59 @@
50365154 }
50375155 }
50385156 colors = null;
5157
+ }
5158
+
5159
+ void CreateMesh(iHeightField hf, int x, int y)
5160
+ {
5161
+ BoundaryRep tmp = new BoundaryRep();
5162
+
5163
+ int vc = 0;
5164
+
5165
+ Vertex v = new Vertex(true);
5166
+
5167
+ for (int i=0; i<x; i++)
5168
+ {
5169
+ for (int j=0; j<y; j++)
5170
+ {
5171
+// Vertex v = tmp.GetVertex(vc++);
5172
+
5173
+ v.s = v.x = i;
5174
+ v.t = v.z = j;
5175
+ v.s /= x; v.t /= y;
5176
+ v.y = hf.f(i,j);
5177
+
5178
+ int iu = tmp.AddTableVertex(v);
5179
+
5180
+ v.s = v.x = i+1;
5181
+ v.t = v.z = j;
5182
+ v.s /= x; v.t /= y;
5183
+ v.y = hf.f(i+1,j);
5184
+
5185
+ int iv = tmp.AddTableVertex(v);
5186
+
5187
+ v.s = v.x = i+1;
5188
+ v.t = v.z = j+1;
5189
+ v.s /= x; v.t /= y;
5190
+ v.y = hf.f(i+1,j+1);
5191
+
5192
+ int iw = tmp.AddTableVertex(v);
5193
+
5194
+ v.s = v.x = i;
5195
+ v.t = v.z = j+1;
5196
+ v.s /= x; v.t /= y;
5197
+ v.y = hf.f(i,j+1);
5198
+
5199
+ int ix = tmp.AddTableVertex(v);
5200
+
5201
+ tmp.AddFace(iu,iw,iv);
5202
+ tmp.AddFace(iu,ix,iw);
5203
+ }
5204
+ }
5205
+
5206
+ Set(tmp);
5207
+
5208
+ Trim(true,false,true);
5209
+ ClearColors();
50395210 }
50405211
50415212 void Stripify()
....@@ -5297,18 +5468,10 @@
52975468 double minweight = 1E10;
52985469
52995470 nbbadfaces = 0;
5300
- for (int i=faces.size(); (i-=8)>=0;)
5471
+ for (int i=0; i<faces.size(); i+=8)
5472
+// for (int i=faces.size(); (i-=8)>=0;)
53015473 {
53025474 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;
53125475
53135476 if (!Valid(face))
53145477 {
....@@ -5327,10 +5490,21 @@
53275490 !ValidValence(face.r))
53285491 continue;
53295492
5493
+ //?? if (face.weight < 0)
5494
+ // continue;
5495
+
5496
+ double K = 1; // 0.01; // .25;
5497
+
5498
+ double factor = (1-K)*face.nbiterations + K; //*face.weight;
5499
+
5500
+ double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor;
5501
+
53305502 if (minweight > weight)
53315503 {
53325504 minweight = weight;
53335505 chosen = i;
5506
+ if (minweight == 0)
5507
+ break;
53345508 }
53355509 }
53365510
....@@ -7019,6 +7193,7 @@
70197193 assert(f2.contains(i));
70207194 assert(f3.contains(i));
70217195
7196
+ // when r is the "center", p is along the boundary
70227197 while (f0.r != i)
70237198 {
70247199 int t = f0.p;
....@@ -7075,59 +7250,90 @@
70757250 f0 = f3;
70767251 f3 = t;
70777252 }
7078
- atleastone = true;
70797253
7254
+ int va = f0.q;
7255
+ int vb = f0.r;
7256
+ int vc = -1;
7257
+
7258
+ Face toremove1 = null;
7259
+ Face toremove2 = null;
7260
+
7261
+ // f0 is the buffer for the first new triangle,
7262
+ // and otherf is the other upper one.
70807263 Face otherf = null;
70817264
70827265 if (f1.contains(f0.p))
70837266 {
70847267 if (f1.p == f0.p)
70857268 {
7269
+ assert(false);
70867270 f0.r = f1.q;
70877271 }
70887272 else
70897273 {
70907274 assert(f1.q == f0.p);
7091
- f0.r = f1.p;
7275
+ vc = f1.p;
70927276 }
70937277
70947278 otherf = f2;
7095
- faces.remove(f1);
7096
- faces.remove(f3);
7279
+ toremove1 = f1;
7280
+ toremove2 = f3;
70977281 }
70987282 else
70997283 if (f2.contains(f0.p))
71007284 {
71017285 if (f2.p == f0.p)
71027286 {
7287
+ assert(false);
71037288 f0.r = f2.q;
71047289 }
71057290 else
71067291 {
71077292 assert(f2.q == f0.p);
7108
- f0.r = f2.p;
7293
+ vc = f2.p;
71097294 }
71107295
71117296 otherf = f3;
7112
- faces.remove(f1);
7113
- faces.remove(f2);
7297
+ toremove1 = f1;
7298
+ toremove2 = f2;
71147299 }
71157300 if (f3.contains(f0.p))
71167301 {
71177302 if (f3.p == f0.p)
71187303 {
7304
+// assert(false);
7305
+ new Exception().printStackTrace();
71197306 f0.r = f3.q;
71207307 }
71217308 else
71227309 {
71237310 assert(f3.q == f0.p);
7124
- f0.r = f3.p;
7311
+ vc = f3.p;
71257312 }
71267313
71277314 otherf = f1;
7128
- faces.remove(f2);
7129
- faces.remove(f3);
7315
+ toremove1 = f2;
7316
+ toremove2 = f3;
71307317 }
7318
+
7319
+ vertextemp.set(vertices.get(va));
7320
+ vertextemp.sub(vertices.get(vb));
7321
+ vertextemp.normalize();
7322
+ vertextemp2.set(vertices.get(vc));
7323
+ vertextemp2.sub(vertices.get(vb));
7324
+ vertextemp2.normalize();
7325
+
7326
+ if (vertextemp.dot(vertextemp2) > -0.95)
7327
+ {
7328
+ continue;
7329
+ }
7330
+
7331
+ atleastone = true;
7332
+
7333
+ f0.r = vc;
7334
+
7335
+ faces.remove(toremove1);
7336
+ faces.remove(toremove2);
71317337
71327338 if (!f0.contains(otherf.p))
71337339 {
....@@ -7335,7 +7541,7 @@
73357541 Trim();
73367542 Untrim();
73377543
7338
- BoundaryRep tmp = new BoundaryRep(); // (BoundaryRep) GraphreeD.clone(this);
7544
+ BoundaryRep tmp = new BoundaryRep(); // (BoundaryRep) GrafreeD.clone(this);
73397545
73407546 double minx = Float.POSITIVE_INFINITY;
73417547 double maxx = Float.NEGATIVE_INFINITY;
....@@ -7373,7 +7579,7 @@
73737579 if (max < maxz - minz)
73747580 max = maxz - minz;
73757581
7376
- tmp.THRESHOLD = max/25; // 50;
7582
+ tmp.THRESHOLD = 0.5; // max/25; // 50;
73777583
73787584 tmp.faces.clear();
73797585
....@@ -7498,7 +7704,7 @@
74987704 s3 = new cVector();
74997705 }
75007706
7501
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
7707
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
75027708
75037709 try
75047710 {
....@@ -7593,7 +7799,7 @@
75937799 {
75947800 if (i++%100 == 0)
75957801 {
7596
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
7802
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
75977803 System.out.println("#faces = " + faces.size());
75987804 // if (i != 1)
75997805 // break;
....@@ -7637,7 +7843,7 @@
76377843 //Trim(true,cJME.gennormals,true,false); // doesn't work
76387844 Trim(true,false,false,false,false);
76397845
7640
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
7846
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
76417847 }
76427848
76437849 void UpdateIndices(Face face, Face minface)
....@@ -7932,6 +8138,8 @@
79328138
79338139 minface.q = minface.r = minface.p;
79348140
8141
+ int count = 0;
8142
+
79358143 for (int i=0; i<faces.size(); i++)
79368144 {
79378145 Face face = (Face) faces.get(i);
....@@ -7943,6 +8151,9 @@
79438151 TouchVertex(face.r, true); // , minface.weight);
79448152 // assert(!lock);
79458153 faces.remove(i--);
8154
+ count++;
8155
+ if (count == 4)
8156
+ break;
79468157 }
79478158 }
79488159
....@@ -8006,7 +8217,7 @@
80068217 if (!trimmed)
80078218 return;
80088219
8009
- GraphreeD.linkUV = false;
8220
+ GrafreeD.linkUV = false;
80108221
80118222 try
80128223 {
....@@ -8214,9 +8425,6 @@
82148425 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
82158426 }
82168427
8217
- static Camera localcamera = new Camera();
8218
- static cVector from = new cVector();
8219
- static cVector to = new cVector();
82208428 boolean trimmed = false;
82218429 boolean stripified = false;
82228430 transient boolean AOdone = false;
....@@ -8224,8 +8432,10 @@
82248432 /*transient*/ int maxIndexV = 0;
82258433 /*transient*/ int bufV, bufF;
82268434 // Raw version
8227
- private float[] positions;
8228
- private float[] normals;
8435
+ //private
8436
+ float[] positions;
8437
+ //private
8438
+ float[] normals;
82298439 float[] colors;
82308440 private float[] uvmap;
82318441 private int[] triangles;