Normand Briere
2019-04-29 8c837a9e50c29e66bdf5bd7ea2fd15b1a7d5d598
BoundaryRep.java
....@@ -15,7 +15,7 @@
1515 {
1616 this(0, 0);
1717 }
18
-
18
+
1919 void SaveSupports()
2020 {
2121 transientsupport = support;
....@@ -2661,7 +2661,7 @@
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
....@@ -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 % 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;
5059
+ cp.PrepOcclusion(this, transform);
49795060
49805061 AOdone = true;
49815062 }
....@@ -7633,7 +7714,7 @@
76337714 s3 = new cVector();
76347715 }
76357716
7636
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
7717
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
76377718
76387719 try
76397720 {
....@@ -7728,7 +7809,7 @@
77287809 {
77297810 if (i++%100 == 0)
77307811 {
7731
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
7812
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
77327813 System.out.println("#faces = " + faces.size());
77337814 // if (i != 1)
77347815 // break;
....@@ -7772,7 +7853,7 @@
77727853 //Trim(true,cJME.gennormals,true,false); // doesn't work
77737854 Trim(true,false,false,false,false);
77747855
7775
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
7856
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
77767857 }
77777858
77787859 void UpdateIndices(Face face, Face minface)
....@@ -8354,9 +8435,6 @@
83548435 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
83558436 }
83568437
8357
- static Camera localcamera = new Camera();
8358
- static cVector from = new cVector();
8359
- static cVector to = new cVector();
83608438 boolean trimmed = false;
83618439 boolean stripified = false;
83628440 transient boolean AOdone = false;
....@@ -8364,8 +8442,10 @@
83648442 /*transient*/ int maxIndexV = 0;
83658443 /*transient*/ int bufV, bufF;
83668444 // Raw version
8367
- private float[] positions;
8368
- private float[] normals;
8445
+ //private
8446
+ float[] positions;
8447
+ //private
8448
+ float[] normals;
83698449 float[] colors;
83708450 private float[] uvmap;
83718451 private int[] triangles;