Normand Briere
2019-05-05 623dc0fa8cbd9473830a1786f6d49fa808a09439
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[]) 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);
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[]) GrafreeD.clone(other.indices);
181
+ indices = (int[]) Grafreed.clone(other.indices);
182182
183
- vertices = (Vector<Vertex>) GrafreeD.clone(other.vertices);
184
- faces = (Vector<Face>) GrafreeD.clone(other.faces);
183
+ vertices = (Vector<Vertex>) Grafreed.clone(other.vertices);
184
+ faces = (Vector<Face>) Grafreed.clone(other.faces);
185185 }
186186 else
187187 {
....@@ -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);
....@@ -1518,7 +1518,7 @@
15181518 InitFaceIndices();
15191519 }
15201520
1521
- BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
1521
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15221522 //float[] v = new float[100];
15231523
15241524 for (int loops=1; --loops>=0;)
....@@ -1548,7 +1548,7 @@
15481548 InitFaceIndices();
15491549 }
15501550
1551
- BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this);
1551
+ BoundaryRep rep = (BoundaryRep) Grafreed.clone(this);
15521552 //float[] v = new float[100];
15531553
15541554 for (int loops=10; --loops>=0;)
....@@ -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 {
2673
- GrafreeD.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);
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)
....@@ -3255,7 +3403,7 @@
32553403 k /= x*x + y*y;
32563404 }
32573405 else
3258
- GrafreeD.Assert(z == 1);
3406
+ Grafreed.Assert(z == 1);
32593407
32603408 if (k < 0)
32613409 k = 0;
....@@ -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;
....@@ -3748,6 +3902,11 @@
37483902 tsa.getNormals(0, normals);
37493903 tsa.getTextureCoordinates(0, 0, uvmap);
37503904 // tsa.getColors(0, colors);
3905
+
3906
+ for (int i=colors.length; --i>=0;)
3907
+ {
3908
+ colors[i] = 1;
3909
+ }
37513910
37523911 int stripcount = tsa.getNumStrips();
37533912 triangles = new int[stripcount];
....@@ -4428,7 +4587,7 @@
44284587 }
44294588 }
44304589
4431
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4590
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
44324591 {
44334592 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
44344593 CameraPane.tempmat,0, CameraPane.tempmat2,0,
....@@ -4460,14 +4619,14 @@
44604619 // june 2014
44614620 // Camera parentcam = cam;
44624621 //
4463
-// if (cam == CameraPane.theRenderer.cameras[0])
4622
+// if (cam == Globals.theRenderer.cameras[0])
44644623 // {
4465
-// parentcam = CameraPane.theRenderer.cameras[1];
4624
+// parentcam = Globals.theRenderer.cameras[1];
44664625 // }
44674626 //
4468
-// if (cam == CameraPane.theRenderer.cameras[1])
4627
+// if (cam == Globals.theRenderer.cameras[1])
44694628 // {
4470
-// parentcam = CameraPane.theRenderer.cameras[0];
4629
+// parentcam = Globals.theRenderer.cameras[0];
44714630 // }
44724631
44734632 gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0);
....@@ -4893,7 +5052,7 @@
48935052 return verticesCopy;
48945053 }
48955054
4896
- void PreprocessOcclusion(CameraPane cp, double[][] transform)
5055
+ void PreprocessOcclusion(iCameraPane cp, double[][] transform)
48975056 {
48985057 if (//!trimmed ||
48995058 AOdone)
....@@ -4902,80 +5061,7 @@
49025061 return;
49035062 }
49045063
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;
5064
+ cp.PrepOcclusion(this, transform);
49795065
49805066 AOdone = true;
49815067 }
....@@ -6273,6 +6359,7 @@
62736359
62746360 void InitWeights()
62756361 {
6362
+ new Exception().printStackTrace();
62766363 System.exit(0);
62776364 int n = 0;
62786365 int b = 0;
....@@ -7230,7 +7317,8 @@
72307317 {
72317318 if (f3.p == f0.p)
72327319 {
7233
- assert(false);
7320
+// assert(false);
7321
+ new Exception().printStackTrace();
72347322 f0.r = f3.q;
72357323 }
72367324 else
....@@ -7632,7 +7720,7 @@
76327720 s3 = new cVector();
76337721 }
76347722
7635
- 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));
76367724
76377725 try
76387726 {
....@@ -7727,7 +7815,7 @@
77277815 {
77287816 if (i++%100 == 0)
77297817 {
7730
- 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));
77317819 System.out.println("#faces = " + faces.size());
77327820 // if (i != 1)
77337821 // break;
....@@ -7771,7 +7859,7 @@
77717859 //Trim(true,cJME.gennormals,true,false); // doesn't work
77727860 Trim(true,false,false,false,false);
77737861
7774
- 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));
77757863 }
77767864
77777865 void UpdateIndices(Face face, Face minface)
....@@ -8145,7 +8233,7 @@
81458233 if (!trimmed)
81468234 return;
81478235
8148
- GrafreeD.linkUV = false;
8236
+ Grafreed.linkUV = false;
81498237
81508238 try
81518239 {
....@@ -8353,9 +8441,6 @@
83538441 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
83548442 }
83558443
8356
- static Camera localcamera = new Camera();
8357
- static cVector from = new cVector();
8358
- static cVector to = new cVector();
83598444 boolean trimmed = false;
83608445 boolean stripified = false;
83618446 transient boolean AOdone = false;
....@@ -8363,8 +8448,10 @@
83638448 /*transient*/ int maxIndexV = 0;
83648449 /*transient*/ int bufV, bufF;
83658450 // Raw version
8366
- private float[] positions;
8367
- private float[] normals;
8451
+ //private
8452
+ float[] positions;
8453
+ //private
8454
+ float[] normals;
83688455 float[] colors;
83698456 private float[] uvmap;
83708457 private int[] triangles;