.. | .. |
---|
7 | 7 | |
---|
8 | 8 | class BoundaryRep implements java.io.Serializable |
---|
9 | 9 | { |
---|
10 | | - static final long serialVersionUID = -4852664309425035321L; |
---|
| 10 | + static final long serialVersionUID = // VERY old 2008 -5762968998168738314L; |
---|
| 11 | + -4852664309425035321L; |
---|
11 | 12 | |
---|
12 | 13 | transient int displaylist = 0; |
---|
13 | 14 | |
---|
.. | .. |
---|
15 | 16 | { |
---|
16 | 17 | this(0, 0); |
---|
17 | 18 | } |
---|
18 | | - |
---|
| 19 | + |
---|
19 | 20 | void SaveSupports() |
---|
20 | 21 | { |
---|
21 | 22 | transientsupport = support; |
---|
.. | .. |
---|
161 | 162 | || FaceCount() != other.FaceCount() |
---|
162 | 163 | || !(indices == null ^ other.indices != null)) // july 2014 |
---|
163 | 164 | { |
---|
| 165 | + // The meshes have different structures. |
---|
164 | 166 | //new Exception().printStackTrace(); |
---|
165 | 167 | trimmed = other.trimmed; |
---|
166 | 168 | stripified = other.stripified; |
---|
.. | .. |
---|
172 | 174 | bufV = other.bufV; |
---|
173 | 175 | bufF = other.bufF; |
---|
174 | 176 | |
---|
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); |
---|
| 177 | + positions = (float[]) Grafreed.clone(other.positions); |
---|
| 178 | + normals = (float[]) Grafreed.clone(other.normals); |
---|
| 179 | + colors = (float[]) Grafreed.clone(other.colors); |
---|
| 180 | + uvmap = (float[]) Grafreed.clone(other.uvmap); |
---|
| 181 | + triangles = (int[]) Grafreed.clone(other.triangles); |
---|
180 | 182 | |
---|
181 | | - indices = (int[]) GrafreeD.clone(other.indices); |
---|
| 183 | + indices = (int[]) Grafreed.clone(other.indices); |
---|
182 | 184 | |
---|
183 | | - vertices = (Vector<Vertex>) GrafreeD.clone(other.vertices); |
---|
184 | | - faces = (Vector<Face>) GrafreeD.clone(other.faces); |
---|
| 185 | + vertices = (Vector<Vertex>) Grafreed.clone(other.vertices); |
---|
| 186 | + faces = (Vector<Face>) Grafreed.clone(other.faces); |
---|
185 | 187 | } |
---|
186 | 188 | else |
---|
187 | 189 | { |
---|
.. | .. |
---|
239 | 241 | } |
---|
240 | 242 | } |
---|
241 | 243 | |
---|
242 | | - Support[] InitConnections(BoundaryRep other) |
---|
| 244 | + transient Support[] cachesupports = null; |
---|
| 245 | + |
---|
| 246 | + Support[] InitConnections() |
---|
243 | 247 | { |
---|
244 | | - int n = other.startvertices.length-1; |
---|
| 248 | + if (cachesupports != null) |
---|
| 249 | + { |
---|
| 250 | + return cachesupports; |
---|
| 251 | + } |
---|
| 252 | + |
---|
| 253 | + int n = this.startvertices.length-1; |
---|
245 | 254 | |
---|
246 | 255 | Support[] supports = new Support[n]; |
---|
247 | 256 | |
---|
.. | .. |
---|
253 | 262 | |
---|
254 | 263 | for (int object=1; object<=n; object++) |
---|
255 | 264 | { |
---|
256 | | - int start = other.startvertices[object-1]; |
---|
257 | | - int end = other.startvertices[object]; |
---|
| 265 | + int start = this.startvertices[object-1]; |
---|
| 266 | + int end = this.startvertices[object]; |
---|
258 | 267 | |
---|
259 | 268 | if (start == end) |
---|
260 | 269 | continue; // ?? |
---|
261 | 270 | |
---|
| 271 | + /** |
---|
| 272 | + Vertex v2 = vertextemp; |
---|
| 273 | + v2.x = averagepoints[object*3]; |
---|
| 274 | + v2.y = averagepoints[object*3+1]; |
---|
| 275 | + v2.z = averagepoints[object*3+2]; |
---|
| 276 | + |
---|
| 277 | + //v2.set(GetVertex(this.startvertices[subsupport])); |
---|
| 278 | + |
---|
| 279 | + // projected point |
---|
| 280 | + Vertex v3 = vertextemp2; |
---|
| 281 | + //GetVertex(this.startvertices[subsupport]); |
---|
| 282 | + v3.x = extremepoints[object*3]; |
---|
| 283 | + v3.y = extremepoints[object*3+1]; |
---|
| 284 | + v3.z = extremepoints[object*3+2]; |
---|
| 285 | + |
---|
| 286 | + vect3.set(v3); // "X" axis apex |
---|
| 287 | + vect3.sub(v2); // origin (center) |
---|
| 288 | + vect3.normalize(); |
---|
| 289 | + /**/ |
---|
| 290 | + |
---|
262 | 291 | int linkcount = 0; |
---|
263 | 292 | |
---|
264 | 293 | int objectinlist = -1; |
---|
| 294 | + |
---|
| 295 | + Support subsupport = supports[object-1]; |
---|
265 | 296 | |
---|
266 | 297 | for (int object2=1; object2<=n; object2++) |
---|
267 | 298 | { |
---|
268 | 299 | for (int i = start; i < end; i++) |
---|
269 | 300 | { |
---|
270 | | - Vertex v = other.GetVertex(i); |
---|
| 301 | + Vertex v = this.GetVertex(i); |
---|
271 | 302 | |
---|
272 | | - // |
---|
273 | | - if (other.Contains(v, object2)) |
---|
| 303 | + // Check if v is close enough from any vertex of the given subobject. |
---|
| 304 | + if (this.Contains(v, object2)) |
---|
274 | 305 | { |
---|
275 | | - if (linkcount == supports[object-1].links.length) |
---|
| 306 | + if (linkcount == subsupport.links.length) |
---|
276 | 307 | break; |
---|
277 | 308 | |
---|
278 | 309 | if (object2 == object) |
---|
279 | 310 | objectinlist = linkcount; |
---|
280 | 311 | |
---|
281 | | - supports[object-1].links[linkcount++] = object2; |
---|
| 312 | + subsupport.links[linkcount++] = object2; |
---|
282 | 313 | break; |
---|
283 | 314 | } |
---|
284 | 315 | } |
---|
285 | 316 | } |
---|
286 | 317 | |
---|
287 | | - supports[object-1].links[linkcount] = -1; |
---|
| 318 | + subsupport.links[linkcount] = -1; |
---|
288 | 319 | |
---|
289 | 320 | if (objectinlist == -1) |
---|
290 | 321 | assert(objectinlist != -1); |
---|
.. | .. |
---|
293 | 324 | // assert(linkcount > 1); |
---|
294 | 325 | |
---|
295 | 326 | // show main support as blue |
---|
296 | | - int first = supports[object-1].links[0]; |
---|
297 | | - supports[object-1].links[0] = supports[object-1].links[objectinlist]; |
---|
298 | | - supports[object-1].links[objectinlist] = first; |
---|
| 327 | + int first = subsupport.links[0]; |
---|
| 328 | + subsupport.links[0] = subsupport.links[objectinlist]; |
---|
| 329 | + subsupport.links[objectinlist] = first; |
---|
299 | 330 | } |
---|
300 | 331 | |
---|
301 | 332 | for (int loop = 0; --loop>=0;) |
---|
.. | .. |
---|
353 | 384 | supports = supports2; |
---|
354 | 385 | } |
---|
355 | 386 | |
---|
356 | | - return supports; |
---|
| 387 | + return cachesupports = supports; |
---|
357 | 388 | } |
---|
358 | 389 | |
---|
359 | 390 | double Distance2(Vertex v, Vertex v2, double dist2beat, double[][] toRoot, int k) |
---|
.. | .. |
---|
500 | 531 | static Vertex vertextemp = new Vertex(true); |
---|
501 | 532 | static Vertex vertextemp2 = new Vertex(true); |
---|
502 | 533 | |
---|
503 | | - static double SEUIL = 0.1f; // 0.1 for rag doll; 0.07; |
---|
| 534 | + static double SEUIL = 0.025f; // 0.1 for rag doll; 0.07; |
---|
504 | 535 | |
---|
505 | 536 | // Compute weight of point w/r to this |
---|
506 | 537 | float ComputeWeight(Vertex v, double[][] toRoot, int k) |
---|
.. | .. |
---|
598 | 629 | // ; |
---|
599 | 630 | // |
---|
600 | 631 | |
---|
601 | | - supportsize = supportsizes[subsupport]; |
---|
| 632 | + supportsize = supportminsize[subsupport]; |
---|
602 | 633 | |
---|
603 | 634 | double K = supportsize / distmax; |
---|
604 | 635 | |
---|
.. | .. |
---|
650 | 681 | // if (supportsize * fadefactor > 1) |
---|
651 | 682 | // return 1; |
---|
652 | 683 | |
---|
653 | | - return supportsize * fadefactor; |
---|
| 684 | + return //supportsize * |
---|
| 685 | + supportsize * fadefactor; |
---|
654 | 686 | } |
---|
655 | 687 | |
---|
656 | 688 | void RecomputeBasis(BoundaryRep other, double[][] toRoot, Vertex v) |
---|
657 | 689 | { |
---|
| 690 | + CameraPane.CreateSelectedPoint(); |
---|
658 | 691 | CameraPane.selectedpoint. |
---|
659 | 692 | getAverage(cStatic.point1, true); |
---|
660 | 693 | |
---|
.. | .. |
---|
790 | 823 | v.weights[k] = other.ComputeWeight(v, toRoot, k); // (float)(supportsize * normalweight * nz / Math.pow(tx*tx+ty*ty+tz*tz, 1)); |
---|
791 | 824 | v.totalweight += v.weights[k]; |
---|
792 | 825 | |
---|
793 | | - if (CameraPane.CROWD) |
---|
| 826 | + if (Globals.CROWD) |
---|
794 | 827 | { |
---|
795 | 828 | // System.out.print("weight = " + v.weights[k]); |
---|
796 | 829 | // System.out.println("; totalweight = " + v.totalweight); |
---|
.. | .. |
---|
952 | 985 | |
---|
953 | 986 | // sept 2017 SEUIL = 0.1; // aout 2013 |
---|
954 | 987 | |
---|
955 | | - supports = InitConnections(other); |
---|
| 988 | + supports = other.InitConnections(); |
---|
956 | 989 | |
---|
957 | 990 | other.supports = supports; // should be the other way around... |
---|
958 | 991 | |
---|
.. | .. |
---|
972 | 1005 | |
---|
973 | 1006 | v.closestsupport = -1; |
---|
974 | 1007 | |
---|
| 1008 | + CameraPane.CreateSelectedPoint(); |
---|
975 | 1009 | CameraPane.selectedpoint. |
---|
976 | 1010 | getAverage(cStatic.point1, true); |
---|
977 | 1011 | |
---|
.. | .. |
---|
1230 | 1264 | for (int wi = v0.weights.length; --wi>=0;) |
---|
1231 | 1265 | v[wi] = 0; |
---|
1232 | 1266 | |
---|
| 1267 | + CameraPane.CreateSelectedPoint(); |
---|
1233 | 1268 | CameraPane.selectedpoint. |
---|
1234 | 1269 | getAverage(cStatic.point1, true); |
---|
1235 | 1270 | |
---|
.. | .. |
---|
1367 | 1402 | v0.x = v0.y = v0.z = 0; |
---|
1368 | 1403 | v0.norm.x = v0.norm.y = v0.norm.z = 0; |
---|
1369 | 1404 | |
---|
| 1405 | + CameraPane.CreateSelectedPoint(); |
---|
1370 | 1406 | CameraPane.selectedpoint. |
---|
1371 | 1407 | getAverage(cStatic.point1, true); |
---|
1372 | 1408 | |
---|
.. | .. |
---|
1518 | 1554 | InitFaceIndices(); |
---|
1519 | 1555 | } |
---|
1520 | 1556 | |
---|
1521 | | - BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this); |
---|
| 1557 | + BoundaryRep rep = (BoundaryRep) Grafreed.clone(this); |
---|
1522 | 1558 | //float[] v = new float[100]; |
---|
1523 | 1559 | |
---|
1524 | 1560 | for (int loops=1; --loops>=0;) |
---|
.. | .. |
---|
1548 | 1584 | InitFaceIndices(); |
---|
1549 | 1585 | } |
---|
1550 | 1586 | |
---|
1551 | | - BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this); |
---|
| 1587 | + BoundaryRep rep = (BoundaryRep) Grafreed.clone(this); |
---|
1552 | 1588 | //float[] v = new float[100]; |
---|
1553 | 1589 | |
---|
1554 | 1590 | for (int loops=10; --loops>=0;) |
---|
.. | .. |
---|
1895 | 1931 | return; |
---|
1896 | 1932 | } |
---|
1897 | 1933 | |
---|
1898 | | - // System.exit(0); |
---|
| 1934 | + // System.exit(0); |
---|
1899 | 1935 | |
---|
1900 | 1936 | cVector vect = new cVector(); |
---|
1901 | 1937 | cVector normal = new cVector(); |
---|
.. | .. |
---|
1966 | 2002 | if (v.vertexlinks == null) |
---|
1967 | 2003 | continue; |
---|
1968 | 2004 | |
---|
1969 | | - if (v.weights != null && v.weights[j] == 0) // < 0.01 * v.totalweight) // == 0) |
---|
| 2005 | + // Warning: faster but dangerous |
---|
| 2006 | + if (v.weights != null && v.weights[j] |
---|
| 2007 | + == 0) |
---|
| 2008 | + //< 0.001 * v.totalweight) |
---|
1970 | 2009 | { |
---|
1971 | 2010 | //testweight += v.weights[j-1]; |
---|
1972 | 2011 | continue; |
---|
.. | .. |
---|
2247 | 2286 | |
---|
2248 | 2287 | transient int lastsoundtime; |
---|
2249 | 2288 | |
---|
| 2289 | + transient boolean once = false; |
---|
| 2290 | + |
---|
2250 | 2291 | void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked) |
---|
2251 | 2292 | { |
---|
2252 | 2293 | if (LA.isIdentity(toRoot)) |
---|
.. | .. |
---|
2302 | 2343 | |
---|
2303 | 2344 | if (v.totalweight == 0) |
---|
2304 | 2345 | { |
---|
2305 | | - System.err.println("v.totalweight == 0! --> " + this + " : " + other); |
---|
| 2346 | + if (!once) |
---|
| 2347 | + { |
---|
| 2348 | + System.err.println("v.totalweight == 0! --> " + this + " : " + other); |
---|
| 2349 | + once = true; |
---|
| 2350 | + } |
---|
2306 | 2351 | continue; |
---|
2307 | 2352 | } |
---|
2308 | 2353 | |
---|
.. | .. |
---|
2661 | 2706 | if (false) // slow && stepout && onein) |
---|
2662 | 2707 | { |
---|
2663 | 2708 | // sound |
---|
2664 | | - cVector eye = CameraPane.theRenderer.eyeCamera.location; |
---|
| 2709 | + cVector eye = Globals.theRenderer.EyeCamera().location; |
---|
2665 | 2710 | |
---|
2666 | 2711 | Vertex v = GetVertex(0); |
---|
2667 | 2712 | |
---|
2668 | 2713 | tmp.set(v); |
---|
2669 | 2714 | tmp.sub(eye); |
---|
2670 | 2715 | |
---|
2671 | | - if (CameraPane.framecount - lastsoundtime > 30) // 0.25 secs |
---|
| 2716 | + if (Globals.framecount - lastsoundtime > 30) // 0.25 secs |
---|
2672 | 2717 | { |
---|
2673 | | - GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1); |
---|
| 2718 | + Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1); |
---|
2674 | 2719 | |
---|
2675 | | - lastsoundtime = CameraPane.framecount; |
---|
| 2720 | + lastsoundtime = Globals.framecount; |
---|
2676 | 2721 | } |
---|
2677 | 2722 | |
---|
2678 | 2723 | stepout = false; |
---|
.. | .. |
---|
3098 | 3143 | // |
---|
3099 | 3144 | // transient VertexCompare[] vertexcompare = null; |
---|
3100 | 3145 | |
---|
| 3146 | + // Check if v0 is close enough from any vertex of the given subobject of this. |
---|
3101 | 3147 | boolean Contains(Vertex v0, int object) |
---|
3102 | 3148 | { |
---|
3103 | 3149 | int start = startvertices[object-1]; |
---|
.. | .. |
---|
3155 | 3201 | */ |
---|
3156 | 3202 | } |
---|
3157 | 3203 | |
---|
3158 | | - void GenUV() |
---|
| 3204 | + void UnfoldUV() |
---|
| 3205 | + { |
---|
| 3206 | + for (int i = 0; i < VertexCount(); i++) |
---|
| 3207 | + { |
---|
| 3208 | + Vertex v = GetVertex(i); |
---|
| 3209 | + |
---|
| 3210 | + v.x = v.s; |
---|
| 3211 | + v.y = v.t; |
---|
| 3212 | + v.z = 0; |
---|
| 3213 | + |
---|
| 3214 | + v.norm.x = 0; |
---|
| 3215 | + v.norm.y = 0; |
---|
| 3216 | + v.norm.z = 1; |
---|
| 3217 | + |
---|
| 3218 | + SetVertex(v, i); |
---|
| 3219 | + } |
---|
| 3220 | + } |
---|
| 3221 | + |
---|
| 3222 | + float power = 2; |
---|
| 3223 | + |
---|
| 3224 | + void GenUV() // float power) |
---|
3159 | 3225 | { |
---|
3160 | 3226 | Trim(); |
---|
3161 | 3227 | |
---|
.. | .. |
---|
3219 | 3285 | y -= 0.5; |
---|
3220 | 3286 | z -= 0.5; |
---|
3221 | 3287 | |
---|
| 3288 | + double ax = Math.abs(x); |
---|
| 3289 | + double ay = Math.abs(y); |
---|
| 3290 | + double max = ax; |
---|
| 3291 | + if (max < ay) |
---|
| 3292 | + { |
---|
| 3293 | + max = ay; |
---|
| 3294 | + } |
---|
| 3295 | + |
---|
| 3296 | + if (max == 0) |
---|
| 3297 | + { |
---|
| 3298 | + uvmap[i2] = 0.5f; |
---|
| 3299 | + uvmap[i2+1] = 0.5f; |
---|
| 3300 | + continue; |
---|
| 3301 | + } |
---|
| 3302 | + |
---|
| 3303 | + x /= max; |
---|
| 3304 | + y /= max; |
---|
| 3305 | + |
---|
| 3306 | + double angle = Math.acos(Math.abs(z*2)); |
---|
| 3307 | + |
---|
| 3308 | + double k = angle / Math.PI * 2; |
---|
| 3309 | + |
---|
| 3310 | + assert(k >= 0); |
---|
| 3311 | + |
---|
| 3312 | + // k == 0 => uv = 0 (center) |
---|
| 3313 | + // k == 1 => uv = -1,1 (border) |
---|
| 3314 | + |
---|
| 3315 | + if (i == 0) |
---|
| 3316 | + System.out.println("power = " + power); |
---|
| 3317 | + |
---|
| 3318 | + double length1 = (ax+ay)/max; |
---|
| 3319 | + double length2 = Math.sqrt(ax*ax + ay*ay) / max; |
---|
| 3320 | + |
---|
| 3321 | + double t = k; |
---|
| 3322 | + |
---|
| 3323 | + t = Math.pow(t, 3); |
---|
| 3324 | + |
---|
| 3325 | + // Interpolate between k/length2 (center) and k (border) |
---|
| 3326 | + if (length2 > 0) |
---|
| 3327 | + k *= (1 - t) / length2 + t; |
---|
| 3328 | + |
---|
| 3329 | + double u = k*x; |
---|
| 3330 | + double v = k*y; |
---|
| 3331 | + |
---|
| 3332 | + u /= 2; |
---|
| 3333 | + v /= 2; |
---|
| 3334 | + u += 0.5; |
---|
| 3335 | + v += 0.5; |
---|
| 3336 | + |
---|
| 3337 | + uvmap[i2] = (float) u; |
---|
| 3338 | + uvmap[i2+1] = (float) v; |
---|
| 3339 | + } |
---|
| 3340 | + } |
---|
| 3341 | + |
---|
| 3342 | + void GenUVold(float power) |
---|
| 3343 | + { |
---|
| 3344 | + Trim(); |
---|
| 3345 | + |
---|
| 3346 | + cVector boxcenter = null; |
---|
| 3347 | + cVector minima, maxima; |
---|
| 3348 | + minima = new cVector(); |
---|
| 3349 | + maxima = new cVector(); |
---|
| 3350 | + minima.x = minima.y = minima.z = Double.MAX_VALUE; |
---|
| 3351 | + maxima.x = maxima.y = maxima.z = -Double.MAX_VALUE; |
---|
| 3352 | + for (int i = 0; i < VertexCount(); i++) |
---|
| 3353 | + { |
---|
| 3354 | + Vertex v = GetVertex(i); |
---|
| 3355 | + |
---|
| 3356 | + if (minima.x > v.x) |
---|
| 3357 | + { |
---|
| 3358 | + minima.x = v.x; |
---|
| 3359 | + } |
---|
| 3360 | + if (minima.y > v.y) |
---|
| 3361 | + { |
---|
| 3362 | + minima.y = v.y; |
---|
| 3363 | + } |
---|
| 3364 | + if (minima.z > v.z) |
---|
| 3365 | + { |
---|
| 3366 | + minima.z = v.z; |
---|
| 3367 | + } |
---|
| 3368 | + |
---|
| 3369 | + if (maxima.x < v.x) |
---|
| 3370 | + { |
---|
| 3371 | + maxima.x = v.x; |
---|
| 3372 | + } |
---|
| 3373 | + if (maxima.y < v.y) |
---|
| 3374 | + { |
---|
| 3375 | + maxima.y = v.y; |
---|
| 3376 | + } |
---|
| 3377 | + if (maxima.z < v.z) |
---|
| 3378 | + { |
---|
| 3379 | + maxima.z = v.z; |
---|
| 3380 | + } |
---|
| 3381 | + } |
---|
| 3382 | + |
---|
| 3383 | + boxcenter = new cVector((maxima.x + minima.x) / 2, (maxima.y + minima.y) / 2, (maxima.z + minima.z) / 2); |
---|
| 3384 | + int i2 = 0, i3 = 0; |
---|
| 3385 | + for (int i = 0; i < positions.length/3; i++, i3 += 3, i2 += 2) |
---|
| 3386 | + { |
---|
| 3387 | +// //uvmap[i2] = (float) normals[i3]*0.5f + 0.5f; // v.x; |
---|
| 3388 | +// //uvmap[i2 + 1] = (float) normals[i3+1]*0.5f + 0.5f; //z; |
---|
| 3389 | +// uvmap[i2] = (float) (positions[i3] - boxcenter.x); |
---|
| 3390 | +// uvmap[i2 + 1] = (float) (positions[i3+2] - boxcenter.z); |
---|
| 3391 | +// uvmap[i2] = (float) Math.atan2(positions[i3+1] - boxcenter.y, positions[i3] - boxcenter.x); |
---|
| 3392 | +// uvmap[i2 + 1] = (float)(positions[i3+2] - boxcenter.z); |
---|
| 3393 | + // box UV |
---|
| 3394 | + double x = positions[i3] - minima.x; // - Math.floor(positions[i3]); |
---|
| 3395 | + double y = positions[i3+1] - minima.y; // - Math.floor(positions[i3+1]); |
---|
| 3396 | + double z = positions[i3+2] - minima.z; // - Math.floor(positions[i3+2]); |
---|
| 3397 | + |
---|
| 3398 | + // [-1/2, 1/2] |
---|
| 3399 | + x /= maxima.x - minima.x; |
---|
| 3400 | + y /= maxima.y - minima.y; |
---|
| 3401 | + z /= maxima.z - minima.z; |
---|
| 3402 | + |
---|
| 3403 | + x -= 0.5; |
---|
| 3404 | + y -= 0.5; |
---|
| 3405 | + z -= 0.5; |
---|
| 3406 | + |
---|
3222 | 3407 | // x *= 2; |
---|
3223 | 3408 | // y *= 2; |
---|
3224 | 3409 | // z *= 2; |
---|
.. | .. |
---|
3245 | 3430 | |
---|
3246 | 3431 | z = Math.cos(angle/2); |
---|
3247 | 3432 | |
---|
| 3433 | + assert(z >= 0); |
---|
| 3434 | + assert(z <= 1); |
---|
| 3435 | + |
---|
| 3436 | + /**/ |
---|
| 3437 | + //z = Math.pow(z, power); //1.08f); |
---|
| 3438 | + |
---|
| 3439 | + if (i == 0) |
---|
| 3440 | + System.out.println("power = " + power); |
---|
| 3441 | + |
---|
3248 | 3442 | // sqrt(k2*x2 + k2*z2 + y2) = length |
---|
3249 | 3443 | // k2*x2 + k2*z2 = length2 - y2 |
---|
3250 | 3444 | // k2 = (length2 - y2) / (x2 + z2) |
---|
.. | .. |
---|
3255 | 3449 | k /= x*x + y*y; |
---|
3256 | 3450 | } |
---|
3257 | 3451 | else |
---|
3258 | | - GrafreeD.Assert(z == 1); |
---|
| 3452 | + Grafreed.Assert(z == 1); |
---|
3259 | 3453 | |
---|
3260 | 3454 | if (k < 0) |
---|
3261 | 3455 | k = 0; |
---|
.. | .. |
---|
3264 | 3458 | |
---|
3265 | 3459 | x *= k; |
---|
3266 | 3460 | y *= k; |
---|
| 3461 | + /**/ |
---|
3267 | 3462 | |
---|
3268 | 3463 | double max = Math.abs(x); |
---|
3269 | 3464 | if (max < Math.abs(y)) |
---|
.. | .. |
---|
3276 | 3471 | } |
---|
3277 | 3472 | |
---|
3278 | 3473 | // max = Math.sqrt(max*2)/2; |
---|
| 3474 | +// double x2 = Math.pow(Math.abs(x), 1/power); |
---|
| 3475 | +// double y2 = Math.pow(Math.abs(y), 1/power); |
---|
| 3476 | +// double z2 = Math.pow(Math.abs(z), 1/power); |
---|
| 3477 | +// max = Math.pow(x2 + y2 + z2, power); |
---|
3279 | 3478 | |
---|
3280 | 3479 | // if (!(max > 0)) |
---|
3281 | | - assert(max > 0); |
---|
3282 | | - |
---|
| 3480 | + //assert(max > 0); |
---|
| 3481 | + assert(max >= 0); |
---|
| 3482 | + |
---|
3283 | 3483 | x /= max; |
---|
3284 | 3484 | y /= max; |
---|
3285 | 3485 | z /= max; |
---|
.. | .. |
---|
3542 | 3742 | */ |
---|
3543 | 3743 | } |
---|
3544 | 3744 | |
---|
| 3745 | + void GenerateNormals2(boolean crease) |
---|
| 3746 | + { |
---|
| 3747 | + cVector tempVector = new cVector(); |
---|
| 3748 | + |
---|
| 3749 | +// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>(); |
---|
| 3750 | +// |
---|
| 3751 | +// |
---|
| 3752 | +// for (int i=0; i<this.VertexCount(); i++) |
---|
| 3753 | +// { |
---|
| 3754 | +// Vertex v = this.GetVertex(i); |
---|
| 3755 | +// |
---|
| 3756 | +// tempVector.set(v); |
---|
| 3757 | +// |
---|
| 3758 | +// cVector n = tableBase.get(tempVector.ToFloat()); |
---|
| 3759 | +// |
---|
| 3760 | +// if (n != null) |
---|
| 3761 | +// { |
---|
| 3762 | +// continue; |
---|
| 3763 | +// } |
---|
| 3764 | +// |
---|
| 3765 | +// tableBase.put(new cVector(tempVector), new cVector(v.norm)); |
---|
| 3766 | +// } |
---|
| 3767 | + |
---|
| 3768 | + BoundaryRep tempSupport = this.support; |
---|
| 3769 | + |
---|
| 3770 | + this.support = null; |
---|
| 3771 | + |
---|
| 3772 | + BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this); |
---|
| 3773 | + |
---|
| 3774 | + this.support = tempSupport; |
---|
| 3775 | + |
---|
| 3776 | + //tempRep.Unstripify(); |
---|
| 3777 | + |
---|
| 3778 | + tempRep.GenerateNormals(crease); |
---|
| 3779 | + |
---|
| 3780 | + boolean keepnormal = Vertex.normalmode; |
---|
| 3781 | + boolean epsequal = Grafreed.epsequal; |
---|
| 3782 | + |
---|
| 3783 | + Vertex.normalmode = false; |
---|
| 3784 | + Grafreed.epsequal = false; // A bit strange |
---|
| 3785 | + |
---|
| 3786 | + // No need to have a match for vertex counts. |
---|
| 3787 | + |
---|
| 3788 | + java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>(); |
---|
| 3789 | + |
---|
| 3790 | + for (int i=0; i<tempRep.VertexCount(); i++) |
---|
| 3791 | + { |
---|
| 3792 | + Vertex v = tempRep.GetVertex(i); |
---|
| 3793 | + |
---|
| 3794 | + cVector n = table.get(tempVector.ToFloat()); |
---|
| 3795 | + |
---|
| 3796 | + if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0) |
---|
| 3797 | + { |
---|
| 3798 | + //continue; |
---|
| 3799 | + } |
---|
| 3800 | + |
---|
| 3801 | + tempVector.set(v); |
---|
| 3802 | + |
---|
| 3803 | + //cVector nBase = tableBase.get(tempVector); |
---|
| 3804 | + |
---|
| 3805 | + //if (v.norm.dot(nBase) < 0.9) |
---|
| 3806 | + //{ |
---|
| 3807 | + // continue; |
---|
| 3808 | + //} |
---|
| 3809 | + |
---|
| 3810 | + if (n != null && n.x == 1 && n.y == 0 && n.z == 0) |
---|
| 3811 | + { |
---|
| 3812 | + //continue; |
---|
| 3813 | + } |
---|
| 3814 | + |
---|
| 3815 | + if (n != null) |
---|
| 3816 | + { |
---|
| 3817 | +// if (n.dot(v.norm) < 0) |
---|
| 3818 | +// n.sub(v.norm); |
---|
| 3819 | +// else |
---|
| 3820 | +// n.add(v.norm); |
---|
| 3821 | +// |
---|
| 3822 | +// n.normalize(); |
---|
| 3823 | + continue; |
---|
| 3824 | + } |
---|
| 3825 | + |
---|
| 3826 | + table.put(new cVector(tempVector), new cVector(v.norm)); |
---|
| 3827 | + } |
---|
| 3828 | + |
---|
| 3829 | + for (int i=0; i<this.VertexCount(); i++) |
---|
| 3830 | + { |
---|
| 3831 | + Vertex v = this.GetVertex(i); |
---|
| 3832 | + |
---|
| 3833 | + tempVector.set(v); |
---|
| 3834 | + |
---|
| 3835 | + cVector n = table.get(tempVector.ToFloat()); |
---|
| 3836 | + |
---|
| 3837 | + //if (n.dot(v.norm) < 0) |
---|
| 3838 | + if (n == null) |
---|
| 3839 | + continue; |
---|
| 3840 | + |
---|
| 3841 | + if (v.norm == null) |
---|
| 3842 | + v.norm = new cVector(); |
---|
| 3843 | + |
---|
| 3844 | + LA.vecCopy(n, v.norm); |
---|
| 3845 | + |
---|
| 3846 | + this.SetVertex(v, i); |
---|
| 3847 | + } |
---|
| 3848 | + |
---|
| 3849 | + Grafreed.epsequal = epsequal; |
---|
| 3850 | + Vertex.normalmode = keepnormal; |
---|
| 3851 | + } |
---|
| 3852 | + |
---|
3545 | 3853 | void GenerateNormals(boolean crease) |
---|
3546 | 3854 | { |
---|
3547 | 3855 | boolean wastrim = trimmed; |
---|
.. | .. |
---|
3558 | 3866 | } |
---|
3559 | 3867 | |
---|
3560 | 3868 | Trim(true/*wastrim*/,true,crease,wasstrip,false); |
---|
| 3869 | + } |
---|
| 3870 | + |
---|
| 3871 | + void GenerateNormalsMesh() |
---|
| 3872 | + { |
---|
| 3873 | + if (stripified) |
---|
| 3874 | + { |
---|
| 3875 | + Unstripify(); |
---|
| 3876 | + } |
---|
| 3877 | + |
---|
| 3878 | + if (trimmed) |
---|
| 3879 | + { |
---|
| 3880 | + normals = null; |
---|
| 3881 | + } |
---|
| 3882 | + else |
---|
| 3883 | + { |
---|
| 3884 | + for (int i=VertexCount(); --i>=0;) |
---|
| 3885 | + { |
---|
| 3886 | + Vertex v = GetVertex(i); |
---|
| 3887 | + |
---|
| 3888 | + v.norm = null; |
---|
| 3889 | + } |
---|
| 3890 | + } |
---|
3561 | 3891 | } |
---|
3562 | 3892 | |
---|
3563 | 3893 | void GenNormalsJME() |
---|
.. | .. |
---|
3682 | 4012 | NormalGenerator ng; |
---|
3683 | 4013 | |
---|
3684 | 4014 | if (crease) |
---|
3685 | | - ng = new NormalGenerator(Math.PI/6); // default is 44 degrees (or Math.PI/3); // /4); |
---|
| 4015 | + ng = new NormalGenerator(Math.PI/4); // default is 44 degrees (or Math.PI/3); // /4); |
---|
3686 | 4016 | else |
---|
3687 | 4017 | ng = new NormalGenerator(Math.PI); // (Math.PI / 3); // /4); |
---|
3688 | 4018 | |
---|
.. | .. |
---|
3700 | 4030 | //System.out.println("NEW = " + positions.length); |
---|
3701 | 4031 | uvmap = new float[ta.getVertexCount() * 2]; |
---|
3702 | 4032 | |
---|
3703 | | - colors = new float[ta.getVertexCount()]; // * 3]; |
---|
3704 | | - |
---|
3705 | 4033 | ta.getCoordinates(0, positions); |
---|
3706 | 4034 | ta.getNormals(0, normals); |
---|
3707 | 4035 | // ta.getColors(0, colors); |
---|
.. | .. |
---|
3709 | 4037 | |
---|
3710 | 4038 | System.out.println("UV = " + uvmap[2] + ", " + uvmap[3] + ";"); |
---|
3711 | 4039 | |
---|
| 4040 | + colors = null; |
---|
| 4041 | +// colors = new float[ta.getVertexCount()]; // * 3]; |
---|
| 4042 | +// |
---|
| 4043 | +// for (int i=colors.length; --i>=0;) |
---|
| 4044 | +// { |
---|
| 4045 | +// colors[i] = 1; |
---|
| 4046 | +// } |
---|
| 4047 | + |
---|
3712 | 4048 | triangles = new int[ta.getVertexCount()]; |
---|
3713 | 4049 | |
---|
3714 | 4050 | for (int i = 0; i < triangles.length; i++) |
---|
3715 | 4051 | { |
---|
3716 | 4052 | triangles[i] = i; |
---|
3717 | 4053 | } |
---|
| 4054 | + |
---|
| 4055 | +// Untrim(); |
---|
| 4056 | + if (!trimmed) |
---|
| 4057 | + MergeNormals(); |
---|
3718 | 4058 | } |
---|
3719 | 4059 | } |
---|
3720 | 4060 | |
---|
.. | .. |
---|
3742 | 4082 | positions = new float[3 * ga.getVertexCount()]; |
---|
3743 | 4083 | normals = new float[3 * ga.getVertexCount()]; |
---|
3744 | 4084 | uvmap = new float[2 * ga.getVertexCount()]; |
---|
3745 | | - colors = new float[1 * ga.getVertexCount()]; |
---|
3746 | 4085 | |
---|
3747 | 4086 | tsa.getCoordinates(0, positions); |
---|
3748 | 4087 | tsa.getNormals(0, normals); |
---|
3749 | 4088 | tsa.getTextureCoordinates(0, 0, uvmap); |
---|
3750 | 4089 | // tsa.getColors(0, colors); |
---|
| 4090 | + |
---|
| 4091 | + colors = null; |
---|
| 4092 | +// colors = new float[1 * ga.getVertexCount()]; |
---|
| 4093 | +// for (int i=colors.length; --i>=0;) |
---|
| 4094 | +// { |
---|
| 4095 | +// colors[i] = 1; |
---|
| 4096 | +// } |
---|
3751 | 4097 | |
---|
3752 | 4098 | int stripcount = tsa.getNumStrips(); |
---|
3753 | 4099 | triangles = new int[stripcount]; |
---|
.. | .. |
---|
3756 | 4102 | stripified = true; |
---|
3757 | 4103 | } catch (ClassCastException e) |
---|
3758 | 4104 | { |
---|
| 4105 | + // ??? aug 2019 |
---|
3759 | 4106 | TriangleArray ta = (TriangleArray) ga; |
---|
3760 | 4107 | |
---|
3761 | 4108 | positions = new float[3 * ga.getVertexCount()]; |
---|
.. | .. |
---|
3770 | 4117 | triangles = new int[1]; |
---|
3771 | 4118 | triangles[0] = 3; |
---|
3772 | 4119 | } |
---|
| 4120 | + |
---|
| 4121 | + //Untrim(); |
---|
| 4122 | + if (!trimmed) |
---|
| 4123 | + MergeNormals(); |
---|
3773 | 4124 | } |
---|
3774 | 4125 | |
---|
3775 | 4126 | /* |
---|
.. | .. |
---|
3819 | 4170 | } |
---|
3820 | 4171 | |
---|
3821 | 4172 | Vertex.normalmode = false; |
---|
| 4173 | + } |
---|
| 4174 | + |
---|
| 4175 | + void MergeNormals() |
---|
| 4176 | + { |
---|
| 4177 | + assert(!trimmed); |
---|
| 4178 | + |
---|
| 4179 | + boolean smooth = Grafreed.smoothmode; |
---|
| 4180 | + boolean link = Grafreed.linkUV; |
---|
| 4181 | + Grafreed.smoothmode = true; |
---|
| 4182 | + Grafreed.linkUV = true; |
---|
| 4183 | + |
---|
| 4184 | + System.out.println("#Vertex = " + VertexCount()); |
---|
| 4185 | + System.out.println("#Face = " + FaceCount()); |
---|
| 4186 | + |
---|
| 4187 | + java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>(); |
---|
| 4188 | + |
---|
| 4189 | + for (int i = 0; i < VertexCount(); i++) |
---|
| 4190 | + { |
---|
| 4191 | + Vertex v = GetVertex(i); |
---|
| 4192 | + |
---|
| 4193 | + if (!table.contains(v)) |
---|
| 4194 | + { |
---|
| 4195 | + table.add(v); |
---|
| 4196 | + } |
---|
| 4197 | + } |
---|
| 4198 | + |
---|
| 4199 | + Grafreed.smoothmode = smooth; |
---|
| 4200 | + Grafreed.linkUV = link; |
---|
| 4201 | + |
---|
| 4202 | +// for (int i = 0; i < VertexCount(); i++) |
---|
| 4203 | +// { |
---|
| 4204 | +// Vertex v = GetVertex(i); |
---|
| 4205 | +// |
---|
| 4206 | +// table.add(v); |
---|
| 4207 | +// } |
---|
| 4208 | + |
---|
3822 | 4209 | } |
---|
3823 | 4210 | |
---|
3824 | 4211 | static cVector temp1 = new cVector(); |
---|
.. | .. |
---|
4428 | 4815 | } |
---|
4429 | 4816 | } |
---|
4430 | 4817 | |
---|
4431 | | - void CullVertex(javax.media.opengl.GL gl, boolean shadow) |
---|
| 4818 | + void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED) |
---|
4432 | 4819 | { |
---|
4433 | 4820 | CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z, |
---|
4434 | 4821 | CameraPane.tempmat,0, CameraPane.tempmat2,0, |
---|
.. | .. |
---|
4460 | 4847 | // june 2014 |
---|
4461 | 4848 | // Camera parentcam = cam; |
---|
4462 | 4849 | // |
---|
4463 | | -// if (cam == CameraPane.theRenderer.cameras[0]) |
---|
| 4850 | +// if (cam == Globals.theRenderer.cameras[0]) |
---|
4464 | 4851 | // { |
---|
4465 | | -// parentcam = CameraPane.theRenderer.cameras[1]; |
---|
| 4852 | +// parentcam = Globals.theRenderer.cameras[1]; |
---|
4466 | 4853 | // } |
---|
4467 | 4854 | // |
---|
4468 | | -// if (cam == CameraPane.theRenderer.cameras[1]) |
---|
| 4855 | +// if (cam == Globals.theRenderer.cameras[1]) |
---|
4469 | 4856 | // { |
---|
4470 | | -// parentcam = CameraPane.theRenderer.cameras[0]; |
---|
| 4857 | +// parentcam = Globals.theRenderer.cameras[0]; |
---|
4471 | 4858 | // } |
---|
4472 | 4859 | |
---|
4473 | 4860 | gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0); |
---|
.. | .. |
---|
4593 | 4980 | { |
---|
4594 | 4981 | i3 = positions.length-3; |
---|
4595 | 4982 | i2 = uvmap.length - 2; |
---|
4596 | | - new Exception().printStackTrace(); |
---|
| 4983 | + //new Exception().printStackTrace(); |
---|
4597 | 4984 | } |
---|
4598 | 4985 | |
---|
4599 | 4986 | v./*pos.*/x = positions[i3]; |
---|
4600 | 4987 | v./*pos.*/y = positions[i3 + 1]; |
---|
4601 | 4988 | v./*pos.*/z = positions[i3 + 2]; |
---|
4602 | 4989 | |
---|
4603 | | - v.norm.x = normals[i3]; |
---|
4604 | | - v.norm.y = normals[i3 + 1]; |
---|
4605 | | - v.norm.z = normals[i3 + 2]; |
---|
| 4990 | + if (normals == null) |
---|
| 4991 | + { |
---|
| 4992 | + v.norm.x = 0; |
---|
| 4993 | + v.norm.y = 0; |
---|
| 4994 | + v.norm.z = 0; |
---|
| 4995 | + } |
---|
| 4996 | + else |
---|
| 4997 | + { |
---|
| 4998 | + v.norm.x = normals[i3]; |
---|
| 4999 | + v.norm.y = normals[i3 + 1]; |
---|
| 5000 | + v.norm.z = normals[i3 + 2]; |
---|
| 5001 | + } |
---|
4606 | 5002 | |
---|
4607 | 5003 | v.s = uvmap[i2]; |
---|
4608 | 5004 | v.t = uvmap[i2 + 1]; |
---|
.. | .. |
---|
4893 | 5289 | return verticesCopy; |
---|
4894 | 5290 | } |
---|
4895 | 5291 | |
---|
4896 | | - void PreprocessOcclusion(CameraPane cp, double[][] transform) |
---|
| 5292 | + void PreprocessOcclusion(iCameraPane cp, double[][] transform) |
---|
4897 | 5293 | { |
---|
4898 | 5294 | if (//!trimmed || |
---|
4899 | 5295 | AOdone) |
---|
.. | .. |
---|
4902 | 5298 | return; |
---|
4903 | 5299 | } |
---|
4904 | 5300 | |
---|
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; |
---|
| 5301 | + cp.PrepOcclusion(this, transform); |
---|
4979 | 5302 | |
---|
4980 | 5303 | AOdone = true; |
---|
4981 | 5304 | } |
---|
.. | .. |
---|
5390 | 5713 | |
---|
5391 | 5714 | transient int nbbadfaces; // ?? = 1000000; |
---|
5392 | 5715 | |
---|
5393 | | - int ChooseTriangle() |
---|
| 5716 | + /* |
---|
| 5717 | + */ |
---|
| 5718 | + int ChooseTriangle(boolean firstEquilateral) |
---|
5394 | 5719 | { |
---|
5395 | 5720 | int chosen = -1; |
---|
5396 | 5721 | |
---|
5397 | 5722 | double minweight = 1E10; |
---|
5398 | 5723 | |
---|
| 5724 | + int step = 8; // ? |
---|
| 5725 | + |
---|
| 5726 | + if (firstEquilateral) |
---|
| 5727 | + step = 1; |
---|
| 5728 | + |
---|
5399 | 5729 | nbbadfaces = 0; |
---|
5400 | | - for (int i=0; i<faces.size(); i+=8) |
---|
| 5730 | + for (int i=0; i<faces.size(); i+=step) |
---|
5401 | 5731 | // for (int i=faces.size(); (i-=8)>=0;) |
---|
5402 | 5732 | { |
---|
5403 | 5733 | Face face = (Face) faces.get(i); |
---|
| 5734 | + |
---|
| 5735 | + if (face.used) |
---|
| 5736 | + continue; |
---|
5404 | 5737 | |
---|
5405 | 5738 | if (!Valid(face)) |
---|
5406 | 5739 | { |
---|
.. | .. |
---|
5410 | 5743 | |
---|
5411 | 5744 | if (Boundary(face)) |
---|
5412 | 5745 | continue; |
---|
| 5746 | + |
---|
| 5747 | +// if (Boundary(face.p)) |
---|
| 5748 | +// continue; |
---|
| 5749 | +// |
---|
| 5750 | +// if (Boundary(face.q)) |
---|
| 5751 | +// continue; |
---|
| 5752 | +// |
---|
| 5753 | +// if (Boundary(face.r)) |
---|
| 5754 | +// continue; |
---|
5413 | 5755 | |
---|
5414 | 5756 | if (!ValidValence(face)) |
---|
5415 | 5757 | continue; |
---|
.. | .. |
---|
5422 | 5764 | //?? if (face.weight < 0) |
---|
5423 | 5765 | // continue; |
---|
5424 | 5766 | |
---|
5425 | | - double K = 1; // 0.01; // .25; |
---|
5426 | | - |
---|
5427 | | - double factor = (1-K)*face.nbiterations + K; //*face.weight; |
---|
5428 | | - |
---|
5429 | | - double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor; |
---|
5430 | | - |
---|
5431 | | - if (minweight > weight) |
---|
| 5767 | + if (firstEquilateral) |
---|
5432 | 5768 | { |
---|
5433 | | - minweight = weight; |
---|
| 5769 | + if (OneFaceUsed(links.get(face.p))) |
---|
| 5770 | + continue; |
---|
| 5771 | + |
---|
| 5772 | + if (OneFaceUsed(links.get(face.q))) |
---|
| 5773 | + continue; |
---|
| 5774 | + |
---|
| 5775 | + if (OneFaceUsed(links.get(face.r))) |
---|
| 5776 | + continue; |
---|
| 5777 | + |
---|
5434 | 5778 | chosen = i; |
---|
5435 | | - if (minweight == 0) |
---|
5436 | | - break; |
---|
| 5779 | + break; |
---|
| 5780 | + } |
---|
| 5781 | + else |
---|
| 5782 | + { |
---|
| 5783 | + double K = 1; // 0.01; // .25; |
---|
| 5784 | + |
---|
| 5785 | + double factor = (1-K)*face.nbiterations + K; //*face.weight; |
---|
| 5786 | + |
---|
| 5787 | + double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor; |
---|
| 5788 | + |
---|
| 5789 | + if (minweight > weight) |
---|
| 5790 | + { |
---|
| 5791 | + minweight = weight; |
---|
| 5792 | + chosen = i; |
---|
| 5793 | + if (minweight == 0) |
---|
| 5794 | + break; |
---|
| 5795 | + } |
---|
5437 | 5796 | } |
---|
5438 | 5797 | } |
---|
5439 | 5798 | |
---|
5440 | 5799 | return chosen; |
---|
| 5800 | + } |
---|
| 5801 | + |
---|
| 5802 | + private boolean OneFaceUsed(Vector<Face> faces) |
---|
| 5803 | + { |
---|
| 5804 | + if (faces.size() != 6) |
---|
| 5805 | + return true; |
---|
| 5806 | + |
---|
| 5807 | + for (int i=0; i<6; i+=1) |
---|
| 5808 | + { |
---|
| 5809 | + if (faces.get(i).used) |
---|
| 5810 | + { |
---|
| 5811 | + return true; |
---|
| 5812 | + } |
---|
| 5813 | + } |
---|
| 5814 | + |
---|
| 5815 | + return false; |
---|
5441 | 5816 | } |
---|
5442 | 5817 | |
---|
5443 | 5818 | static boolean remove3valence = true; |
---|
.. | .. |
---|
5473 | 5848 | } |
---|
5474 | 5849 | else |
---|
5475 | 5850 | { |
---|
5476 | | - assert(links.size() == vertices.size()); |
---|
| 5851 | + // TODO Grafreed.Assert(links.size() == vertices.size()); |
---|
5477 | 5852 | |
---|
5478 | 5853 | links.setSize(vertices.size()); |
---|
5479 | 5854 | for (int i=vertices.size(); --i>=0;) |
---|
.. | .. |
---|
5481 | 5856 | // linkstouched[i] = false; |
---|
5482 | 5857 | if (links.get(i) == null) // ?? |
---|
5483 | 5858 | { |
---|
| 5859 | + new Exception().printStackTrace(); |
---|
5484 | 5860 | links.set(i, new Vector(8)); |
---|
5485 | 5861 | // linkstouched[i] = true; |
---|
5486 | 5862 | } |
---|
.. | .. |
---|
5491 | 5867 | } |
---|
5492 | 5868 | } |
---|
5493 | 5869 | |
---|
| 5870 | + boolean once = false; |
---|
| 5871 | + |
---|
5494 | 5872 | for (int i=faces.size(); --i>=0;) |
---|
5495 | 5873 | { |
---|
5496 | 5874 | Face face = (Face) faces.get(i); |
---|
.. | .. |
---|
5502 | 5880 | //if (linkstouched[face.r]) |
---|
5503 | 5881 | links.get(face.r).add(face); |
---|
5504 | 5882 | |
---|
| 5883 | + if (face.used) |
---|
| 5884 | + once = true; |
---|
| 5885 | + |
---|
5505 | 5886 | face.good = 1; |
---|
5506 | 5887 | face.boundary = -1; |
---|
5507 | 5888 | } |
---|
.. | .. |
---|
6273 | 6654 | |
---|
6274 | 6655 | void InitWeights() |
---|
6275 | 6656 | { |
---|
| 6657 | + new Exception().printStackTrace(); |
---|
6276 | 6658 | System.exit(0); |
---|
6277 | 6659 | int n = 0; |
---|
6278 | 6660 | int b = 0; |
---|
.. | .. |
---|
6866 | 7248 | return (face.boundary = 1) == 1; |
---|
6867 | 7249 | } |
---|
6868 | 7250 | |
---|
| 7251 | + // June 2019 |
---|
| 7252 | + if (true) |
---|
| 7253 | + return (face.boundary = 0) == 1; |
---|
| 7254 | + |
---|
6869 | 7255 | // reverse triangle test |
---|
6870 | 7256 | q1.set(p); |
---|
6871 | 7257 | q2.set(q); |
---|
.. | .. |
---|
7230 | 7616 | { |
---|
7231 | 7617 | if (f3.p == f0.p) |
---|
7232 | 7618 | { |
---|
7233 | | - assert(false); |
---|
| 7619 | +// assert(false); |
---|
| 7620 | + new Exception().printStackTrace(); |
---|
7234 | 7621 | f0.r = f3.q; |
---|
7235 | 7622 | } |
---|
7236 | 7623 | else |
---|
.. | .. |
---|
7314 | 7701 | //InitWeights(); |
---|
7315 | 7702 | } |
---|
7316 | 7703 | |
---|
7317 | | - int chosen = ChooseTriangle(); // Best is slow and not really better |
---|
| 7704 | + int chosen = ChooseTriangle(true); // Best is slow and not really better |
---|
7318 | 7705 | |
---|
7319 | 7706 | if (chosen == -1) |
---|
7320 | 7707 | { |
---|
.. | .. |
---|
7328 | 7715 | //remove3valence = false; |
---|
7329 | 7716 | // InitWeights(); |
---|
7330 | 7717 | |
---|
7331 | | - chosen = ChooseTriangle(); |
---|
| 7718 | + chosen = ChooseTriangle(true); |
---|
7332 | 7719 | } |
---|
7333 | 7720 | } |
---|
7334 | 7721 | |
---|
.. | .. |
---|
7604 | 7991 | |
---|
7605 | 7992 | // boolean lock; |
---|
7606 | 7993 | |
---|
7607 | | - void SplitInTwo(boolean reduction34, boolean onlyone) |
---|
| 7994 | + boolean SplitInTwo(boolean reduction34, boolean onlyone) |
---|
7608 | 7995 | { |
---|
7609 | 7996 | if (stripified) |
---|
7610 | 7997 | { |
---|
.. | .. |
---|
7632 | 8019 | s3 = new cVector(); |
---|
7633 | 8020 | } |
---|
7634 | 8021 | |
---|
7635 | | - CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
| 8022 | + Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
7636 | 8023 | |
---|
7637 | 8024 | try |
---|
7638 | 8025 | { |
---|
.. | .. |
---|
7641 | 8028 | { |
---|
7642 | 8029 | System.err.println("EXCEPTION CAUGHT"); |
---|
7643 | 8030 | e.printStackTrace(); |
---|
7644 | | - return; |
---|
| 8031 | + return false; |
---|
7645 | 8032 | } catch (Error e) |
---|
7646 | 8033 | { |
---|
7647 | 8034 | System.err.println("ERROR CAUGHT"); |
---|
7648 | 8035 | e.printStackTrace(); |
---|
7649 | | - return; |
---|
| 8036 | + return false; |
---|
7650 | 8037 | } |
---|
7651 | 8038 | |
---|
7652 | 8039 | System.out.println("# faces = " + faces.size()); |
---|
.. | .. |
---|
7656 | 8043 | { |
---|
7657 | 8044 | Face face = (Face) faces.get(i); |
---|
7658 | 8045 | |
---|
| 8046 | + face.used = false; |
---|
7659 | 8047 | face.nbiterations = 1; |
---|
7660 | 8048 | face.weight = -1; |
---|
7661 | 8049 | face.boundary = -1; |
---|
.. | .. |
---|
7707 | 8095 | nbbadfaces = faces.size(); |
---|
7708 | 8096 | //remove3valence = true; |
---|
7709 | 8097 | |
---|
| 8098 | + int count = 2; |
---|
| 8099 | + |
---|
| 8100 | + if (onlyone) |
---|
| 8101 | + count = 1; |
---|
| 8102 | + |
---|
7710 | 8103 | firstpass = true; |
---|
7711 | 8104 | |
---|
7712 | 8105 | int n = faces.size(); |
---|
.. | .. |
---|
7722 | 8115 | System.out.print('.'); |
---|
7723 | 8116 | } |
---|
7724 | 8117 | System.out.println(); |
---|
| 8118 | + boolean atleastone = false; |
---|
7725 | 8119 | int i = 0; |
---|
7726 | | - while (reduction34 || faces.size() > n/2) |
---|
| 8120 | + while (true) // reduction34 || faces.size() > n/2) |
---|
7727 | 8121 | { |
---|
7728 | 8122 | if (i++%100 == 0) |
---|
7729 | 8123 | { |
---|
7730 | | - CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
| 8124 | + Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
7731 | 8125 | System.out.println("#faces = " + faces.size()); |
---|
7732 | 8126 | // if (i != 1) |
---|
7733 | 8127 | // break; |
---|
.. | .. |
---|
7745 | 8139 | { |
---|
7746 | 8140 | if (!RemoveOneTriangle()) |
---|
7747 | 8141 | break; |
---|
| 8142 | + |
---|
| 8143 | + atleastone = true; |
---|
7748 | 8144 | } |
---|
7749 | 8145 | // if (iterationcount == 0) |
---|
7750 | 8146 | // break; |
---|
.. | .. |
---|
7755 | 8151 | break; |
---|
7756 | 8152 | } |
---|
7757 | 8153 | firstpass = false; |
---|
7758 | | - if (onlyone) |
---|
7759 | | - break; // one triangle only |
---|
| 8154 | +// if (--count<0 && !reduction34) |
---|
| 8155 | +// break; // one triangle only |
---|
7760 | 8156 | } |
---|
7761 | 8157 | |
---|
7762 | 8158 | InitLinks(false); // for further display |
---|
.. | .. |
---|
7771 | 8167 | //Trim(true,cJME.gennormals,true,false); // doesn't work |
---|
7772 | 8168 | Trim(true,false,false,false,false); |
---|
7773 | 8169 | |
---|
7774 | | - CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); |
---|
| 8170 | + Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); |
---|
| 8171 | + |
---|
| 8172 | + return atleastone; |
---|
7775 | 8173 | } |
---|
7776 | 8174 | |
---|
7777 | 8175 | void UpdateIndices(Face face, Face minface) |
---|
.. | .. |
---|
7784 | 8182 | face.p = minface.p; |
---|
7785 | 8183 | //if (leafweights) |
---|
7786 | 8184 | face.good = 0; // false; |
---|
| 8185 | + face.used = true; |
---|
7787 | 8186 | } |
---|
7788 | 8187 | if (face.q == minface.p || face.q == minface.q || face.q == minface.r) |
---|
7789 | 8188 | { |
---|
7790 | 8189 | face.q = minface.p; |
---|
7791 | 8190 | //if (leafweights) |
---|
7792 | 8191 | face.good = 0; // false; |
---|
| 8192 | + face.used = true; |
---|
7793 | 8193 | } |
---|
7794 | 8194 | if (face.r == minface.p || face.r == minface.q || face.r == minface.r) |
---|
7795 | 8195 | { |
---|
7796 | 8196 | face.r = minface.p; |
---|
7797 | 8197 | //if (leafweights) |
---|
7798 | 8198 | face.good = 0; // false; |
---|
| 8199 | + face.used = true; |
---|
7799 | 8200 | } |
---|
7800 | 8201 | |
---|
7801 | 8202 | if (face.p >/*=*/ minface.q && face.p < minface.r) |
---|
.. | .. |
---|
7855 | 8256 | if (v == 2) |
---|
7856 | 8257 | vert = minface.r; |
---|
7857 | 8258 | // Face face = (Face) faces.get(i); |
---|
7858 | | - Vector<Face> vertfaces = links.get(vert); |
---|
7859 | | - for (int i=vertfaces.size(); --i>=0;) |
---|
7860 | | - { |
---|
7861 | | - Face face = (Face) vertfaces.get(i); |
---|
7862 | | - |
---|
7863 | | - // if (face.weight == 10000) |
---|
7864 | | - // continue; |
---|
7865 | | - |
---|
7866 | | - if (face.p == minface.p || face.q == minface.p || face.r == minface.p || |
---|
7867 | | - face.p == minface.q || face.q == minface.q || face.r == minface.q || |
---|
7868 | | - face.p == minface.r || face.q == minface.r || face.r == minface.r) |
---|
| 8259 | + Vector<Face> vertfaces = links.get(vert); |
---|
| 8260 | + for (int i=vertfaces.size(); --i>=0;) |
---|
7869 | 8261 | { |
---|
7870 | | - if (!leafweights) |
---|
| 8262 | + Face face = (Face) vertfaces.get(i); |
---|
| 8263 | + |
---|
| 8264 | + // if (face.weight == 10000) |
---|
| 8265 | + // continue; |
---|
| 8266 | + |
---|
| 8267 | + if (face.p == minface.p || face.q == minface.p || face.r == minface.p || |
---|
| 8268 | + face.p == minface.q || face.q == minface.q || face.r == minface.q || |
---|
| 8269 | + face.p == minface.r || face.q == minface.r || face.r == minface.r) |
---|
7871 | 8270 | { |
---|
7872 | | -// if(minfaceweight <= 0) |
---|
7873 | | -// assert(minfaceweight > 0); |
---|
7874 | | -// |
---|
7875 | | -// //FaceWeight(face); |
---|
7876 | | -// if(face.weight < 0) |
---|
7877 | | -// assert(face.weight >= 0); |
---|
7878 | | - |
---|
7879 | | - face.weight += minfaceweight; |
---|
7880 | | - |
---|
7881 | | -// if (face.weight >= 10000) |
---|
7882 | | -// assert(face.weight < 10000); |
---|
| 8271 | + if (!leafweights) |
---|
| 8272 | + { |
---|
| 8273 | + // if(minfaceweight <= 0) |
---|
| 8274 | + // assert(minfaceweight > 0); |
---|
| 8275 | + // |
---|
| 8276 | + // //FaceWeight(face); |
---|
| 8277 | + // if(face.weight < 0) |
---|
| 8278 | + // assert(face.weight >= 0); |
---|
| 8279 | + |
---|
| 8280 | + face.weight += minfaceweight; |
---|
| 8281 | + |
---|
| 8282 | + // if (face.weight >= 10000) |
---|
| 8283 | + // assert(face.weight < 10000); |
---|
| 8284 | + } |
---|
| 8285 | + else |
---|
| 8286 | + face.weight = -1; |
---|
| 8287 | + |
---|
| 8288 | + face.nbiterations += 1; |
---|
| 8289 | + face.boundary = -1; |
---|
| 8290 | + |
---|
| 8291 | + Vertex p = (Vertex)vertices.get(face.p); |
---|
| 8292 | + Vertex q = (Vertex)vertices.get(face.q); |
---|
| 8293 | + Vertex r = (Vertex)vertices.get(face.r); |
---|
| 8294 | + |
---|
| 8295 | + p.boundary = -1; |
---|
| 8296 | + q.boundary = -1; |
---|
| 8297 | + r.boundary = -1; |
---|
7883 | 8298 | } |
---|
7884 | 8299 | else |
---|
7885 | | - face.weight = -1; |
---|
7886 | | - |
---|
7887 | | - face.nbiterations += 1; |
---|
7888 | | - face.boundary = -1; |
---|
7889 | | - |
---|
7890 | | - Vertex p = (Vertex)vertices.get(face.p); |
---|
7891 | | - Vertex q = (Vertex)vertices.get(face.q); |
---|
7892 | | - Vertex r = (Vertex)vertices.get(face.r); |
---|
7893 | | - |
---|
7894 | | - p.boundary = -1; |
---|
7895 | | - q.boundary = -1; |
---|
7896 | | - r.boundary = -1; |
---|
| 8300 | + assert(false); |
---|
7897 | 8301 | } |
---|
7898 | | - else |
---|
7899 | | - assert(false); |
---|
7900 | 8302 | } |
---|
7901 | | - } |
---|
7902 | 8303 | |
---|
7903 | 8304 | // TouchVertex(minface.p); |
---|
7904 | 8305 | // TouchVertex(minface.q); |
---|
.. | .. |
---|
8099 | 8500 | for (int i=vertfaces.size(); --i>=0;) |
---|
8100 | 8501 | { |
---|
8101 | 8502 | Face face = (Face) vertfaces.get(i); |
---|
| 8503 | + face.used = true; |
---|
8102 | 8504 | face.good = 0; // false; |
---|
8103 | 8505 | if (leafweights) |
---|
8104 | 8506 | face.weight = -1; |
---|
.. | .. |
---|
8145 | 8547 | if (!trimmed) |
---|
8146 | 8548 | return; |
---|
8147 | 8549 | |
---|
8148 | | - GrafreeD.linkUV = false; |
---|
| 8550 | + Grafreed.linkUV = false; |
---|
8149 | 8551 | |
---|
8150 | 8552 | try |
---|
8151 | 8553 | { |
---|
.. | .. |
---|
8353 | 8755 | return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices; |
---|
8354 | 8756 | } |
---|
8355 | 8757 | |
---|
8356 | | - static Camera localcamera = new Camera(); |
---|
8357 | | - static cVector from = new cVector(); |
---|
8358 | | - static cVector to = new cVector(); |
---|
8359 | 8758 | boolean trimmed = false; |
---|
8360 | 8759 | boolean stripified = false; |
---|
8361 | 8760 | transient boolean AOdone = false; |
---|
.. | .. |
---|
8363 | 8762 | /*transient*/ int maxIndexV = 0; |
---|
8364 | 8763 | /*transient*/ int bufV, bufF; |
---|
8365 | 8764 | // Raw version |
---|
8366 | | - private float[] positions; |
---|
8367 | | - private float[] normals; |
---|
| 8765 | + //private |
---|
| 8766 | + float[] positions; |
---|
| 8767 | + //private |
---|
| 8768 | + float[] normals; |
---|
8368 | 8769 | float[] colors; |
---|
8369 | 8770 | private float[] uvmap; |
---|
8370 | 8771 | private int[] triangles; |
---|
.. | .. |
---|
8378 | 8779 | int[] startvertices; |
---|
8379 | 8780 | float[] averagepoints; |
---|
8380 | 8781 | float[] extremepoints; |
---|
8381 | | - float[] supportsizes; // distance of closest point |
---|
| 8782 | + float[] supportminsize; // distance of closest point |
---|
| 8783 | + float[] supportmaxsize; // distance of fartest point |
---|
8382 | 8784 | |
---|
8383 | 8785 | transient Hashtable vertextable; |
---|
8384 | 8786 | /*transient*/ private Vertex[] verticesCopy; |
---|