Normand Briere
2019-05-01 25cef97465f0bfa8959663754e9243006324c81c
BoundaryRep.java
....@@ -15,7 +15,7 @@
1515 {
1616 this(0, 0);
1717 }
18
-
18
+
1919 void SaveSupports()
2020 {
2121 transientsupport = support;
....@@ -790,7 +790,7 @@
790790 v.weights[k] = other.ComputeWeight(v, toRoot, k); // (float)(supportsize * normalweight * nz / Math.pow(tx*tx+ty*ty+tz*tz, 1));
791791 v.totalweight += v.weights[k];
792792
793
- if (CameraPane.CROWD)
793
+ if (Globals.CROWD)
794794 {
795795 // System.out.print("weight = " + v.weights[k]);
796796 // System.out.println("; totalweight = " + v.totalweight);
....@@ -2661,18 +2661,18 @@
26612661 if (false) // slow && stepout && onein)
26622662 {
26632663 // sound
2664
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
2664
+ cVector eye = Globals.theRenderer.EyeCamera().location;
26652665
26662666 Vertex v = GetVertex(0);
26672667
26682668 tmp.set(v);
26692669 tmp.sub(eye);
26702670
2671
- if (CameraPane.framecount - lastsoundtime > 30) // 0.25 secs
2671
+ if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26722672 {
26732673 GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
26742674
2675
- lastsoundtime = CameraPane.framecount;
2675
+ lastsoundtime = Globals.framecount;
26762676 }
26772677
26782678 stepout = false;
....@@ -3155,7 +3155,27 @@
31553155 */
31563156 }
31573157
3158
- 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)
31593179 {
31603180 Trim();
31613181
....@@ -3219,6 +3239,125 @@
32193239 y -= 0.5;
32203240 z -= 0.5;
32213241
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
+
32223361 // x *= 2;
32233362 // y *= 2;
32243363 // z *= 2;
....@@ -3245,6 +3384,15 @@
32453384
32463385 z = Math.cos(angle/2);
32473386
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
+
32483396 // sqrt(k2*x2 + k2*z2 + y2) = length
32493397 // k2*x2 + k2*z2 = length2 - y2
32503398 // k2 = (length2 - y2) / (x2 + z2)
....@@ -3264,6 +3412,7 @@
32643412
32653413 x *= k;
32663414 y *= k;
3415
+ /**/
32673416
32683417 double max = Math.abs(x);
32693418 if (max < Math.abs(y))
....@@ -3276,10 +3425,15 @@
32763425 }
32773426
32783427 // 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);
32793432
32803433 // if (!(max > 0))
3281
- assert(max > 0);
3282
-
3434
+ //assert(max > 0);
3435
+ assert(max >= 0);
3436
+
32833437 x /= max;
32843438 y /= max;
32853439 z /= max;
....@@ -4428,7 +4582,7 @@
44284582 }
44294583 }
44304584
4431
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4585
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
44324586 {
44334587 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
44344588 CameraPane.tempmat,0, CameraPane.tempmat2,0,
....@@ -4460,14 +4614,14 @@
44604614 // june 2014
44614615 // Camera parentcam = cam;
44624616 //
4463
-// if (cam == CameraPane.theRenderer.cameras[0])
4617
+// if (cam == Globals.theRenderer.cameras[0])
44644618 // {
4465
-// parentcam = CameraPane.theRenderer.cameras[1];
4619
+// parentcam = Globals.theRenderer.cameras[1];
44664620 // }
44674621 //
4468
-// if (cam == CameraPane.theRenderer.cameras[1])
4622
+// if (cam == Globals.theRenderer.cameras[1])
44694623 // {
4470
-// parentcam = CameraPane.theRenderer.cameras[0];
4624
+// parentcam = Globals.theRenderer.cameras[0];
44714625 // }
44724626
44734627 gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0);
....@@ -4893,7 +5047,7 @@
48935047 return verticesCopy;
48945048 }
48955049
4896
- void PreprocessOcclusion(CameraPane cp, double[][] transform)
5050
+ void PreprocessOcclusion(iCameraPane cp, double[][] transform)
48975051 {
48985052 if (//!trimmed ||
48995053 AOdone)
....@@ -4902,80 +5056,7 @@
49025056 return;
49035057 }
49045058
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 % 1000) == 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.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 % 1000) == 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;
5059
+ cp.PrepOcclusion(this, transform);
49795060
49805061 AOdone = true;
49815062 }
....@@ -6273,6 +6354,7 @@
62736354
62746355 void InitWeights()
62756356 {
6357
+ new Exception().printStackTrace();
62766358 System.exit(0);
62776359 int n = 0;
62786360 int b = 0;
....@@ -7230,7 +7312,8 @@
72307312 {
72317313 if (f3.p == f0.p)
72327314 {
7233
- assert(false);
7315
+// assert(false);
7316
+ new Exception().printStackTrace();
72347317 f0.r = f3.q;
72357318 }
72367319 else
....@@ -7632,7 +7715,7 @@
76327715 s3 = new cVector();
76337716 }
76347717
7635
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
7718
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
76367719
76377720 try
76387721 {
....@@ -7727,7 +7810,7 @@
77277810 {
77287811 if (i++%100 == 0)
77297812 {
7730
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
7813
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
77317814 System.out.println("#faces = " + faces.size());
77327815 // if (i != 1)
77337816 // break;
....@@ -7771,7 +7854,7 @@
77717854 //Trim(true,cJME.gennormals,true,false); // doesn't work
77727855 Trim(true,false,false,false,false);
77737856
7774
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
7857
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
77757858 }
77767859
77777860 void UpdateIndices(Face face, Face minface)
....@@ -8353,9 +8436,6 @@
83538436 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
83548437 }
83558438
8356
- static Camera localcamera = new Camera();
8357
- static cVector from = new cVector();
8358
- static cVector to = new cVector();
83598439 boolean trimmed = false;
83608440 boolean stripified = false;
83618441 transient boolean AOdone = false;
....@@ -8363,8 +8443,10 @@
83638443 /*transient*/ int maxIndexV = 0;
83648444 /*transient*/ int bufV, bufF;
83658445 // Raw version
8366
- private float[] positions;
8367
- private float[] normals;
8446
+ //private
8447
+ float[] positions;
8448
+ //private
8449
+ float[] normals;
83688450 float[] colors;
83698451 private float[] uvmap;
83708452 private int[] triangles;