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