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;
....@@ -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,115 @@
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
+ 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
+
32223351 // x *= 2;
32233352 // y *= 2;
32243353 // z *= 2;
....@@ -3245,6 +3374,15 @@
32453374
32463375 z = Math.cos(angle/2);
32473376
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
+
32483386 // sqrt(k2*x2 + k2*z2 + y2) = length
32493387 // k2*x2 + k2*z2 = length2 - y2
32503388 // k2 = (length2 - y2) / (x2 + z2)
....@@ -3264,6 +3402,7 @@
32643402
32653403 x *= k;
32663404 y *= k;
3405
+ /**/
32673406
32683407 double max = Math.abs(x);
32693408 if (max < Math.abs(y))
....@@ -3276,10 +3415,15 @@
32763415 }
32773416
32783417 // 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);
32793422
32803423 // if (!(max > 0))
3281
- assert(max > 0);
3282
-
3424
+ //assert(max > 0);
3425
+ assert(max >= 0);
3426
+
32833427 x /= max;
32843428 y /= max;
32853429 z /= max;
....@@ -4428,7 +4572,7 @@
44284572 }
44294573 }
44304574
4431
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4575
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
44324576 {
44334577 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
44344578 CameraPane.tempmat,0, CameraPane.tempmat2,0,
....@@ -4460,14 +4604,14 @@
44604604 // june 2014
44614605 // Camera parentcam = cam;
44624606 //
4463
-// if (cam == CameraPane.theRenderer.cameras[0])
4607
+// if (cam == Globals.theRenderer.cameras[0])
44644608 // {
4465
-// parentcam = CameraPane.theRenderer.cameras[1];
4609
+// parentcam = Globals.theRenderer.cameras[1];
44664610 // }
44674611 //
4468
-// if (cam == CameraPane.theRenderer.cameras[1])
4612
+// if (cam == Globals.theRenderer.cameras[1])
44694613 // {
4470
-// parentcam = CameraPane.theRenderer.cameras[0];
4614
+// parentcam = Globals.theRenderer.cameras[0];
44714615 // }
44724616
44734617 gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0);
....@@ -4893,7 +5037,7 @@
48935037 return verticesCopy;
48945038 }
48955039
4896
- void PreprocessOcclusion(CameraPane cp, double[][] transform)
5040
+ void PreprocessOcclusion(iCameraPane cp, double[][] transform)
48975041 {
48985042 if (//!trimmed ||
48995043 AOdone)
....@@ -4902,80 +5046,7 @@
49025046 return;
49035047 }
49045048
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;
5049
+ cp.PrepOcclusion(this, transform);
49795050
49805051 AOdone = true;
49815052 }
....@@ -7633,7 +7704,7 @@
76337704 s3 = new cVector();
76347705 }
76357706
7636
- 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));
76377708
76387709 try
76397710 {
....@@ -7728,7 +7799,7 @@
77287799 {
77297800 if (i++%100 == 0)
77307801 {
7731
- 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));
77327803 System.out.println("#faces = " + faces.size());
77337804 // if (i != 1)
77347805 // break;
....@@ -7772,7 +7843,7 @@
77727843 //Trim(true,cJME.gennormals,true,false); // doesn't work
77737844 Trim(true,false,false,false,false);
77747845
7775
- 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));
77767847 }
77777848
77787849 void UpdateIndices(Face face, Face minface)
....@@ -8354,9 +8425,6 @@
83548425 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
83558426 }
83568427
8357
- static Camera localcamera = new Camera();
8358
- static cVector from = new cVector();
8359
- static cVector to = new cVector();
83608428 boolean trimmed = false;
83618429 boolean stripified = false;
83628430 transient boolean AOdone = false;
....@@ -8364,8 +8432,10 @@
83648432 /*transient*/ int maxIndexV = 0;
83658433 /*transient*/ int bufV, bufF;
83668434 // Raw version
8367
- private float[] positions;
8368
- private float[] normals;
8435
+ //private
8436
+ float[] positions;
8437
+ //private
8438
+ float[] normals;
83698439 float[] colors;
83708440 private float[] uvmap;
83718441 private int[] triangles;