Normand Briere
2019-05-13 f924d3e00db476c06f55f3d5aaef307e17575340
BoundaryRep.java
....@@ -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 {
....@@ -500,7 +500,7 @@
500500 static Vertex vertextemp = new Vertex(true);
501501 static Vertex vertextemp2 = new Vertex(true);
502502
503
- static double SEUIL = 0.1f; // 0.1 for rag doll; 0.07;
503
+ static double SEUIL = 0.05f; // 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)
....@@ -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;)
....@@ -2670,7 +2670,7 @@
26702670
26712671 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
26752675 lastsoundtime = Globals.framecount;
26762676 }
....@@ -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,
....@@ -6200,6 +6359,7 @@
62006359
62016360 void InitWeights()
62026361 {
6362
+ new Exception().printStackTrace();
62036363 System.exit(0);
62046364 int n = 0;
62056365 int b = 0;
....@@ -8073,7 +8233,7 @@
80738233 if (!trimmed)
80748234 return;
80758235
8076
- GrafreeD.linkUV = false;
8236
+ Grafreed.linkUV = false;
80778237
80788238 try
80798239 {