.. | .. |
---|
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) |
---|
.. | .. |
---|
790 | 821 | v.weights[k] = other.ComputeWeight(v, toRoot, k); // (float)(supportsize * normalweight * nz / Math.pow(tx*tx+ty*ty+tz*tz, 1)); |
---|
791 | 822 | v.totalweight += v.weights[k]; |
---|
792 | 823 | |
---|
793 | | - if (CameraPane.CROWD) |
---|
| 824 | + if (Globals.CROWD) |
---|
794 | 825 | { |
---|
795 | 826 | // System.out.print("weight = " + v.weights[k]); |
---|
796 | 827 | // System.out.println("; totalweight = " + v.totalweight); |
---|
.. | .. |
---|
952 | 983 | |
---|
953 | 984 | // sept 2017 SEUIL = 0.1; // aout 2013 |
---|
954 | 985 | |
---|
955 | | - supports = InitConnections(other); |
---|
| 986 | + supports = other.InitConnections(); |
---|
956 | 987 | |
---|
957 | 988 | other.supports = supports; // should be the other way around... |
---|
958 | 989 | |
---|
.. | .. |
---|
1518 | 1549 | InitFaceIndices(); |
---|
1519 | 1550 | } |
---|
1520 | 1551 | |
---|
1521 | | - BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this); |
---|
| 1552 | + BoundaryRep rep = (BoundaryRep) Grafreed.clone(this); |
---|
1522 | 1553 | //float[] v = new float[100]; |
---|
1523 | 1554 | |
---|
1524 | 1555 | for (int loops=1; --loops>=0;) |
---|
.. | .. |
---|
1548 | 1579 | InitFaceIndices(); |
---|
1549 | 1580 | } |
---|
1550 | 1581 | |
---|
1551 | | - BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this); |
---|
| 1582 | + BoundaryRep rep = (BoundaryRep) Grafreed.clone(this); |
---|
1552 | 1583 | //float[] v = new float[100]; |
---|
1553 | 1584 | |
---|
1554 | 1585 | for (int loops=10; --loops>=0;) |
---|
.. | .. |
---|
1895 | 1926 | return; |
---|
1896 | 1927 | } |
---|
1897 | 1928 | |
---|
1898 | | - // System.exit(0); |
---|
| 1929 | + // System.exit(0); |
---|
1899 | 1930 | |
---|
1900 | 1931 | cVector vect = new cVector(); |
---|
1901 | 1932 | cVector normal = new cVector(); |
---|
.. | .. |
---|
1966 | 1997 | if (v.vertexlinks == null) |
---|
1967 | 1998 | continue; |
---|
1968 | 1999 | |
---|
1969 | | - if (v.weights != null && v.weights[j] == 0) // < 0.01 * v.totalweight) // == 0) |
---|
| 2000 | + if (v.weights != null && v.weights[j] < 0.001 * v.totalweight) // == 0) |
---|
1970 | 2001 | { |
---|
1971 | 2002 | //testweight += v.weights[j-1]; |
---|
1972 | 2003 | continue; |
---|
.. | .. |
---|
2247 | 2278 | |
---|
2248 | 2279 | transient int lastsoundtime; |
---|
2249 | 2280 | |
---|
| 2281 | + transient boolean once = false; |
---|
| 2282 | + |
---|
2250 | 2283 | void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked) |
---|
2251 | 2284 | { |
---|
2252 | 2285 | if (LA.isIdentity(toRoot)) |
---|
.. | .. |
---|
2302 | 2335 | |
---|
2303 | 2336 | if (v.totalweight == 0) |
---|
2304 | 2337 | { |
---|
2305 | | - System.err.println("v.totalweight == 0! --> " + this + " : " + other); |
---|
| 2338 | + if (!once) |
---|
| 2339 | + { |
---|
| 2340 | + System.err.println("v.totalweight == 0! --> " + this + " : " + other); |
---|
| 2341 | + once = true; |
---|
| 2342 | + } |
---|
2306 | 2343 | continue; |
---|
2307 | 2344 | } |
---|
2308 | 2345 | |
---|
.. | .. |
---|
2661 | 2698 | if (false) // slow && stepout && onein) |
---|
2662 | 2699 | { |
---|
2663 | 2700 | // sound |
---|
2664 | | - cVector eye = CameraPane.theRenderer.eyeCamera.location; |
---|
| 2701 | + cVector eye = Globals.theRenderer.EyeCamera().location; |
---|
2665 | 2702 | |
---|
2666 | 2703 | Vertex v = GetVertex(0); |
---|
2667 | 2704 | |
---|
2668 | 2705 | tmp.set(v); |
---|
2669 | 2706 | tmp.sub(eye); |
---|
2670 | 2707 | |
---|
2671 | | - if (CameraPane.framecount - lastsoundtime > 30) // 0.25 secs |
---|
| 2708 | + if (Globals.framecount - lastsoundtime > 30) // 0.25 secs |
---|
2672 | 2709 | { |
---|
2673 | | - GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1); |
---|
| 2710 | + Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1); |
---|
2674 | 2711 | |
---|
2675 | | - lastsoundtime = CameraPane.framecount; |
---|
| 2712 | + lastsoundtime = Globals.framecount; |
---|
2676 | 2713 | } |
---|
2677 | 2714 | |
---|
2678 | 2715 | stepout = false; |
---|
.. | .. |
---|
3098 | 3135 | // |
---|
3099 | 3136 | // transient VertexCompare[] vertexcompare = null; |
---|
3100 | 3137 | |
---|
| 3138 | + // Check if v0 is close enough from any vertex of the given subobject of this. |
---|
3101 | 3139 | boolean Contains(Vertex v0, int object) |
---|
3102 | 3140 | { |
---|
3103 | 3141 | int start = startvertices[object-1]; |
---|
.. | .. |
---|
3155 | 3193 | */ |
---|
3156 | 3194 | } |
---|
3157 | 3195 | |
---|
3158 | | - void GenUV() |
---|
| 3196 | + void UnfoldUV() |
---|
| 3197 | + { |
---|
| 3198 | + for (int i = 0; i < VertexCount(); i++) |
---|
| 3199 | + { |
---|
| 3200 | + Vertex v = GetVertex(i); |
---|
| 3201 | + |
---|
| 3202 | + v.x = v.s; |
---|
| 3203 | + v.y = v.t; |
---|
| 3204 | + v.z = 0; |
---|
| 3205 | + |
---|
| 3206 | + v.norm.x = 0; |
---|
| 3207 | + v.norm.y = 0; |
---|
| 3208 | + v.norm.z = 1; |
---|
| 3209 | + |
---|
| 3210 | + SetVertex(v, i); |
---|
| 3211 | + } |
---|
| 3212 | + } |
---|
| 3213 | + |
---|
| 3214 | + float power = 2; |
---|
| 3215 | + |
---|
| 3216 | + void GenUV() // float power) |
---|
3159 | 3217 | { |
---|
3160 | 3218 | Trim(); |
---|
3161 | 3219 | |
---|
.. | .. |
---|
3219 | 3277 | y -= 0.5; |
---|
3220 | 3278 | z -= 0.5; |
---|
3221 | 3279 | |
---|
| 3280 | + double ax = Math.abs(x); |
---|
| 3281 | + double ay = Math.abs(y); |
---|
| 3282 | + double max = ax; |
---|
| 3283 | + if (max < ay) |
---|
| 3284 | + { |
---|
| 3285 | + max = ay; |
---|
| 3286 | + } |
---|
| 3287 | + |
---|
| 3288 | + if (max == 0) |
---|
| 3289 | + { |
---|
| 3290 | + uvmap[i2] = 0.5f; |
---|
| 3291 | + uvmap[i2+1] = 0.5f; |
---|
| 3292 | + continue; |
---|
| 3293 | + } |
---|
| 3294 | + |
---|
| 3295 | + x /= max; |
---|
| 3296 | + y /= max; |
---|
| 3297 | + |
---|
| 3298 | + double angle = Math.acos(Math.abs(z*2)); |
---|
| 3299 | + |
---|
| 3300 | + double k = angle / Math.PI * 2; |
---|
| 3301 | + |
---|
| 3302 | + assert(k >= 0); |
---|
| 3303 | + |
---|
| 3304 | + // k == 0 => uv = 0 (center) |
---|
| 3305 | + // k == 1 => uv = -1,1 (border) |
---|
| 3306 | + |
---|
| 3307 | + if (i == 0) |
---|
| 3308 | + System.out.println("power = " + power); |
---|
| 3309 | + |
---|
| 3310 | + double length1 = (ax+ay)/max; |
---|
| 3311 | + double length2 = Math.sqrt(ax*ax + ay*ay) / max; |
---|
| 3312 | + |
---|
| 3313 | + double t = k; |
---|
| 3314 | + |
---|
| 3315 | + t = Math.pow(t, 3); |
---|
| 3316 | + |
---|
| 3317 | + // Interpolate between k/length2 (center) and k (border) |
---|
| 3318 | + if (length2 > 0) |
---|
| 3319 | + k *= (1 - t) / length2 + t; |
---|
| 3320 | + |
---|
| 3321 | + double u = k*x; |
---|
| 3322 | + double v = k*y; |
---|
| 3323 | + |
---|
| 3324 | + u /= 2; |
---|
| 3325 | + v /= 2; |
---|
| 3326 | + u += 0.5; |
---|
| 3327 | + v += 0.5; |
---|
| 3328 | + |
---|
| 3329 | + uvmap[i2] = (float) u; |
---|
| 3330 | + uvmap[i2+1] = (float) v; |
---|
| 3331 | + } |
---|
| 3332 | + } |
---|
| 3333 | + |
---|
| 3334 | + void GenUVold(float power) |
---|
| 3335 | + { |
---|
| 3336 | + Trim(); |
---|
| 3337 | + |
---|
| 3338 | + cVector boxcenter = null; |
---|
| 3339 | + cVector minima, maxima; |
---|
| 3340 | + minima = new cVector(); |
---|
| 3341 | + maxima = new cVector(); |
---|
| 3342 | + minima.x = minima.y = minima.z = Double.MAX_VALUE; |
---|
| 3343 | + maxima.x = maxima.y = maxima.z = -Double.MAX_VALUE; |
---|
| 3344 | + for (int i = 0; i < VertexCount(); i++) |
---|
| 3345 | + { |
---|
| 3346 | + Vertex v = GetVertex(i); |
---|
| 3347 | + |
---|
| 3348 | + if (minima.x > v.x) |
---|
| 3349 | + { |
---|
| 3350 | + minima.x = v.x; |
---|
| 3351 | + } |
---|
| 3352 | + if (minima.y > v.y) |
---|
| 3353 | + { |
---|
| 3354 | + minima.y = v.y; |
---|
| 3355 | + } |
---|
| 3356 | + if (minima.z > v.z) |
---|
| 3357 | + { |
---|
| 3358 | + minima.z = v.z; |
---|
| 3359 | + } |
---|
| 3360 | + |
---|
| 3361 | + if (maxima.x < v.x) |
---|
| 3362 | + { |
---|
| 3363 | + maxima.x = v.x; |
---|
| 3364 | + } |
---|
| 3365 | + if (maxima.y < v.y) |
---|
| 3366 | + { |
---|
| 3367 | + maxima.y = v.y; |
---|
| 3368 | + } |
---|
| 3369 | + if (maxima.z < v.z) |
---|
| 3370 | + { |
---|
| 3371 | + maxima.z = v.z; |
---|
| 3372 | + } |
---|
| 3373 | + } |
---|
| 3374 | + |
---|
| 3375 | + boxcenter = new cVector((maxima.x + minima.x) / 2, (maxima.y + minima.y) / 2, (maxima.z + minima.z) / 2); |
---|
| 3376 | + int i2 = 0, i3 = 0; |
---|
| 3377 | + for (int i = 0; i < positions.length/3; i++, i3 += 3, i2 += 2) |
---|
| 3378 | + { |
---|
| 3379 | +// //uvmap[i2] = (float) normals[i3]*0.5f + 0.5f; // v.x; |
---|
| 3380 | +// //uvmap[i2 + 1] = (float) normals[i3+1]*0.5f + 0.5f; //z; |
---|
| 3381 | +// uvmap[i2] = (float) (positions[i3] - boxcenter.x); |
---|
| 3382 | +// uvmap[i2 + 1] = (float) (positions[i3+2] - boxcenter.z); |
---|
| 3383 | +// uvmap[i2] = (float) Math.atan2(positions[i3+1] - boxcenter.y, positions[i3] - boxcenter.x); |
---|
| 3384 | +// uvmap[i2 + 1] = (float)(positions[i3+2] - boxcenter.z); |
---|
| 3385 | + // box UV |
---|
| 3386 | + double x = positions[i3] - minima.x; // - Math.floor(positions[i3]); |
---|
| 3387 | + double y = positions[i3+1] - minima.y; // - Math.floor(positions[i3+1]); |
---|
| 3388 | + double z = positions[i3+2] - minima.z; // - Math.floor(positions[i3+2]); |
---|
| 3389 | + |
---|
| 3390 | + // [-1/2, 1/2] |
---|
| 3391 | + x /= maxima.x - minima.x; |
---|
| 3392 | + y /= maxima.y - minima.y; |
---|
| 3393 | + z /= maxima.z - minima.z; |
---|
| 3394 | + |
---|
| 3395 | + x -= 0.5; |
---|
| 3396 | + y -= 0.5; |
---|
| 3397 | + z -= 0.5; |
---|
| 3398 | + |
---|
3222 | 3399 | // x *= 2; |
---|
3223 | 3400 | // y *= 2; |
---|
3224 | 3401 | // z *= 2; |
---|
.. | .. |
---|
3245 | 3422 | |
---|
3246 | 3423 | z = Math.cos(angle/2); |
---|
3247 | 3424 | |
---|
| 3425 | + assert(z >= 0); |
---|
| 3426 | + assert(z <= 1); |
---|
| 3427 | + |
---|
| 3428 | + /**/ |
---|
| 3429 | + //z = Math.pow(z, power); //1.08f); |
---|
| 3430 | + |
---|
| 3431 | + if (i == 0) |
---|
| 3432 | + System.out.println("power = " + power); |
---|
| 3433 | + |
---|
3248 | 3434 | // sqrt(k2*x2 + k2*z2 + y2) = length |
---|
3249 | 3435 | // k2*x2 + k2*z2 = length2 - y2 |
---|
3250 | 3436 | // k2 = (length2 - y2) / (x2 + z2) |
---|
.. | .. |
---|
3255 | 3441 | k /= x*x + y*y; |
---|
3256 | 3442 | } |
---|
3257 | 3443 | else |
---|
3258 | | - GrafreeD.Assert(z == 1); |
---|
| 3444 | + Grafreed.Assert(z == 1); |
---|
3259 | 3445 | |
---|
3260 | 3446 | if (k < 0) |
---|
3261 | 3447 | k = 0; |
---|
.. | .. |
---|
3264 | 3450 | |
---|
3265 | 3451 | x *= k; |
---|
3266 | 3452 | y *= k; |
---|
| 3453 | + /**/ |
---|
3267 | 3454 | |
---|
3268 | 3455 | double max = Math.abs(x); |
---|
3269 | 3456 | if (max < Math.abs(y)) |
---|
.. | .. |
---|
3276 | 3463 | } |
---|
3277 | 3464 | |
---|
3278 | 3465 | // max = Math.sqrt(max*2)/2; |
---|
| 3466 | +// double x2 = Math.pow(Math.abs(x), 1/power); |
---|
| 3467 | +// double y2 = Math.pow(Math.abs(y), 1/power); |
---|
| 3468 | +// double z2 = Math.pow(Math.abs(z), 1/power); |
---|
| 3469 | +// max = Math.pow(x2 + y2 + z2, power); |
---|
3279 | 3470 | |
---|
3280 | 3471 | // if (!(max > 0)) |
---|
3281 | | - assert(max > 0); |
---|
3282 | | - |
---|
| 3472 | + //assert(max > 0); |
---|
| 3473 | + assert(max >= 0); |
---|
| 3474 | + |
---|
3283 | 3475 | x /= max; |
---|
3284 | 3476 | y /= max; |
---|
3285 | 3477 | z /= max; |
---|
.. | .. |
---|
3542 | 3734 | */ |
---|
3543 | 3735 | } |
---|
3544 | 3736 | |
---|
| 3737 | + void GenerateNormals2(boolean crease) |
---|
| 3738 | + { |
---|
| 3739 | + cVector tempVector = new cVector(); |
---|
| 3740 | + |
---|
| 3741 | +// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>(); |
---|
| 3742 | +// |
---|
| 3743 | +// |
---|
| 3744 | +// for (int i=0; i<this.VertexCount(); i++) |
---|
| 3745 | +// { |
---|
| 3746 | +// Vertex v = this.GetVertex(i); |
---|
| 3747 | +// |
---|
| 3748 | +// tempVector.set(v); |
---|
| 3749 | +// |
---|
| 3750 | +// cVector n = tableBase.get(tempVector.ToFloat()); |
---|
| 3751 | +// |
---|
| 3752 | +// if (n != null) |
---|
| 3753 | +// { |
---|
| 3754 | +// continue; |
---|
| 3755 | +// } |
---|
| 3756 | +// |
---|
| 3757 | +// tableBase.put(new cVector(tempVector), new cVector(v.norm)); |
---|
| 3758 | +// } |
---|
| 3759 | + |
---|
| 3760 | + BoundaryRep tempSupport = this.support; |
---|
| 3761 | + |
---|
| 3762 | + this.support = null; |
---|
| 3763 | + |
---|
| 3764 | + BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this); |
---|
| 3765 | + |
---|
| 3766 | + this.support = tempSupport; |
---|
| 3767 | + |
---|
| 3768 | + //tempRep.Unstripify(); |
---|
| 3769 | + |
---|
| 3770 | + tempRep.GenerateNormals2(crease); |
---|
| 3771 | + |
---|
| 3772 | + boolean keepnormal = Vertex.normalmode; |
---|
| 3773 | + boolean epsequal = Grafreed.epsequal; |
---|
| 3774 | + |
---|
| 3775 | + Vertex.normalmode = false; |
---|
| 3776 | + Grafreed.epsequal = false; // A bit strange |
---|
| 3777 | + |
---|
| 3778 | + // No need to have a match for vertex counts. |
---|
| 3779 | + |
---|
| 3780 | + java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>(); |
---|
| 3781 | + |
---|
| 3782 | + for (int i=0; i<tempRep.VertexCount(); i++) |
---|
| 3783 | + { |
---|
| 3784 | + Vertex v = tempRep.GetVertex(i); |
---|
| 3785 | + |
---|
| 3786 | + cVector n = table.get(tempVector.ToFloat()); |
---|
| 3787 | + |
---|
| 3788 | + if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0) |
---|
| 3789 | + { |
---|
| 3790 | + //continue; |
---|
| 3791 | + } |
---|
| 3792 | + |
---|
| 3793 | + tempVector.set(v); |
---|
| 3794 | + |
---|
| 3795 | + //cVector nBase = tableBase.get(tempVector); |
---|
| 3796 | + |
---|
| 3797 | + //if (v.norm.dot(nBase) < 0.9) |
---|
| 3798 | + //{ |
---|
| 3799 | + // continue; |
---|
| 3800 | + //} |
---|
| 3801 | + |
---|
| 3802 | + if (n != null && n.x == 1 && n.y == 0 && n.z == 0) |
---|
| 3803 | + { |
---|
| 3804 | + //continue; |
---|
| 3805 | + } |
---|
| 3806 | + |
---|
| 3807 | + if (n != null) |
---|
| 3808 | + { |
---|
| 3809 | +// if (n.dot(v.norm) < 0) |
---|
| 3810 | +// n.sub(v.norm); |
---|
| 3811 | +// else |
---|
| 3812 | +// n.add(v.norm); |
---|
| 3813 | +// |
---|
| 3814 | +// n.normalize(); |
---|
| 3815 | + continue; |
---|
| 3816 | + } |
---|
| 3817 | + |
---|
| 3818 | + table.put(new cVector(tempVector), new cVector(v.norm)); |
---|
| 3819 | + } |
---|
| 3820 | + |
---|
| 3821 | + for (int i=0; i<this.VertexCount(); i++) |
---|
| 3822 | + { |
---|
| 3823 | + Vertex v = this.GetVertex(i); |
---|
| 3824 | + |
---|
| 3825 | + tempVector.set(v); |
---|
| 3826 | + |
---|
| 3827 | + cVector n = table.get(tempVector.ToFloat()); |
---|
| 3828 | + |
---|
| 3829 | + //if (n.dot(v.norm) < 0) |
---|
| 3830 | + if (n == null) |
---|
| 3831 | + continue; |
---|
| 3832 | + |
---|
| 3833 | + LA.vecCopy(n, v.norm); |
---|
| 3834 | + |
---|
| 3835 | + this.SetVertex(v, i); |
---|
| 3836 | + } |
---|
| 3837 | + |
---|
| 3838 | + Grafreed.epsequal = epsequal; |
---|
| 3839 | + Vertex.normalmode = keepnormal; |
---|
| 3840 | + } |
---|
| 3841 | + |
---|
3545 | 3842 | void GenerateNormals(boolean crease) |
---|
3546 | 3843 | { |
---|
3547 | 3844 | boolean wastrim = trimmed; |
---|
.. | .. |
---|
3715 | 4012 | { |
---|
3716 | 4013 | triangles[i] = i; |
---|
3717 | 4014 | } |
---|
| 4015 | + |
---|
| 4016 | + Untrim(); |
---|
| 4017 | + MergeNormals(); |
---|
3718 | 4018 | } |
---|
3719 | 4019 | } |
---|
3720 | 4020 | |
---|
.. | .. |
---|
3748 | 4048 | tsa.getNormals(0, normals); |
---|
3749 | 4049 | tsa.getTextureCoordinates(0, 0, uvmap); |
---|
3750 | 4050 | // tsa.getColors(0, colors); |
---|
| 4051 | + |
---|
| 4052 | + for (int i=colors.length; --i>=0;) |
---|
| 4053 | + { |
---|
| 4054 | + colors[i] = 1; |
---|
| 4055 | + } |
---|
3751 | 4056 | |
---|
3752 | 4057 | int stripcount = tsa.getNumStrips(); |
---|
3753 | 4058 | triangles = new int[stripcount]; |
---|
.. | .. |
---|
3770 | 4075 | triangles = new int[1]; |
---|
3771 | 4076 | triangles[0] = 3; |
---|
3772 | 4077 | } |
---|
| 4078 | + |
---|
| 4079 | + Untrim(); |
---|
| 4080 | + MergeNormals(); |
---|
3773 | 4081 | } |
---|
3774 | 4082 | |
---|
3775 | 4083 | /* |
---|
.. | .. |
---|
3819 | 4127 | } |
---|
3820 | 4128 | |
---|
3821 | 4129 | Vertex.normalmode = false; |
---|
| 4130 | + } |
---|
| 4131 | + |
---|
| 4132 | + void MergeNormals() |
---|
| 4133 | + { |
---|
| 4134 | + boolean smooth = Grafreed.smoothmode; |
---|
| 4135 | + boolean link = Grafreed.linkUV; |
---|
| 4136 | + Grafreed.smoothmode = true; |
---|
| 4137 | + Grafreed.linkUV = true; |
---|
| 4138 | + |
---|
| 4139 | + System.out.println("#Vertex = " + VertexCount()); |
---|
| 4140 | + System.out.println("#Face = " + FaceCount()); |
---|
| 4141 | + |
---|
| 4142 | + java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>(); |
---|
| 4143 | + |
---|
| 4144 | + for (int i = 0; i < VertexCount(); i++) |
---|
| 4145 | + { |
---|
| 4146 | + Vertex v = GetVertex(i); |
---|
| 4147 | + |
---|
| 4148 | + if (!table.contains(v)) |
---|
| 4149 | + { |
---|
| 4150 | + table.add(v); |
---|
| 4151 | + } |
---|
| 4152 | + } |
---|
| 4153 | + |
---|
| 4154 | + Grafreed.smoothmode = smooth; |
---|
| 4155 | + Grafreed.linkUV = link; |
---|
| 4156 | + |
---|
| 4157 | +// for (int i = 0; i < VertexCount(); i++) |
---|
| 4158 | +// { |
---|
| 4159 | +// Vertex v = GetVertex(i); |
---|
| 4160 | +// |
---|
| 4161 | +// table.add(v); |
---|
| 4162 | +// } |
---|
| 4163 | + |
---|
3822 | 4164 | } |
---|
3823 | 4165 | |
---|
3824 | 4166 | static cVector temp1 = new cVector(); |
---|
.. | .. |
---|
4428 | 4770 | } |
---|
4429 | 4771 | } |
---|
4430 | 4772 | |
---|
4431 | | - void CullVertex(javax.media.opengl.GL gl, boolean shadow) |
---|
| 4773 | + void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED) |
---|
4432 | 4774 | { |
---|
4433 | 4775 | CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z, |
---|
4434 | 4776 | CameraPane.tempmat,0, CameraPane.tempmat2,0, |
---|
.. | .. |
---|
4460 | 4802 | // june 2014 |
---|
4461 | 4803 | // Camera parentcam = cam; |
---|
4462 | 4804 | // |
---|
4463 | | -// if (cam == CameraPane.theRenderer.cameras[0]) |
---|
| 4805 | +// if (cam == Globals.theRenderer.cameras[0]) |
---|
4464 | 4806 | // { |
---|
4465 | | -// parentcam = CameraPane.theRenderer.cameras[1]; |
---|
| 4807 | +// parentcam = Globals.theRenderer.cameras[1]; |
---|
4466 | 4808 | // } |
---|
4467 | 4809 | // |
---|
4468 | | -// if (cam == CameraPane.theRenderer.cameras[1]) |
---|
| 4810 | +// if (cam == Globals.theRenderer.cameras[1]) |
---|
4469 | 4811 | // { |
---|
4470 | | -// parentcam = CameraPane.theRenderer.cameras[0]; |
---|
| 4812 | +// parentcam = Globals.theRenderer.cameras[0]; |
---|
4471 | 4813 | // } |
---|
4472 | 4814 | |
---|
4473 | 4815 | gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0); |
---|
.. | .. |
---|
4593 | 4935 | { |
---|
4594 | 4936 | i3 = positions.length-3; |
---|
4595 | 4937 | i2 = uvmap.length - 2; |
---|
4596 | | - new Exception().printStackTrace(); |
---|
| 4938 | + //new Exception().printStackTrace(); |
---|
4597 | 4939 | } |
---|
4598 | 4940 | |
---|
4599 | 4941 | v./*pos.*/x = positions[i3]; |
---|
.. | .. |
---|
4893 | 5235 | return verticesCopy; |
---|
4894 | 5236 | } |
---|
4895 | 5237 | |
---|
4896 | | - void PreprocessOcclusion(CameraPane cp, double[][] transform) |
---|
| 5238 | + void PreprocessOcclusion(iCameraPane cp, double[][] transform) |
---|
4897 | 5239 | { |
---|
4898 | 5240 | if (//!trimmed || |
---|
4899 | 5241 | AOdone) |
---|
.. | .. |
---|
4902 | 5244 | return; |
---|
4903 | 5245 | } |
---|
4904 | 5246 | |
---|
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; |
---|
| 5247 | + cp.PrepOcclusion(this, transform); |
---|
4979 | 5248 | |
---|
4980 | 5249 | AOdone = true; |
---|
4981 | 5250 | } |
---|
.. | .. |
---|
5390 | 5659 | |
---|
5391 | 5660 | transient int nbbadfaces; // ?? = 1000000; |
---|
5392 | 5661 | |
---|
5393 | | - int ChooseTriangle() |
---|
| 5662 | + /* |
---|
| 5663 | + */ |
---|
| 5664 | + int ChooseTriangle(boolean firstEquilateral) |
---|
5394 | 5665 | { |
---|
5395 | 5666 | int chosen = -1; |
---|
5396 | 5667 | |
---|
5397 | 5668 | double minweight = 1E10; |
---|
5398 | 5669 | |
---|
| 5670 | + int step = 8; // ? |
---|
| 5671 | + |
---|
| 5672 | + if (firstEquilateral) |
---|
| 5673 | + step = 1; |
---|
| 5674 | + |
---|
5399 | 5675 | nbbadfaces = 0; |
---|
5400 | | - for (int i=0; i<faces.size(); i+=8) |
---|
| 5676 | + for (int i=0; i<faces.size(); i+=step) |
---|
5401 | 5677 | // for (int i=faces.size(); (i-=8)>=0;) |
---|
5402 | 5678 | { |
---|
5403 | 5679 | Face face = (Face) faces.get(i); |
---|
| 5680 | + |
---|
| 5681 | + if (face.used) |
---|
| 5682 | + continue; |
---|
5404 | 5683 | |
---|
5405 | 5684 | if (!Valid(face)) |
---|
5406 | 5685 | { |
---|
.. | .. |
---|
5410 | 5689 | |
---|
5411 | 5690 | if (Boundary(face)) |
---|
5412 | 5691 | continue; |
---|
| 5692 | + |
---|
| 5693 | +// if (Boundary(face.p)) |
---|
| 5694 | +// continue; |
---|
| 5695 | +// |
---|
| 5696 | +// if (Boundary(face.q)) |
---|
| 5697 | +// continue; |
---|
| 5698 | +// |
---|
| 5699 | +// if (Boundary(face.r)) |
---|
| 5700 | +// continue; |
---|
5413 | 5701 | |
---|
5414 | 5702 | if (!ValidValence(face)) |
---|
5415 | 5703 | continue; |
---|
.. | .. |
---|
5422 | 5710 | //?? if (face.weight < 0) |
---|
5423 | 5711 | // continue; |
---|
5424 | 5712 | |
---|
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) |
---|
| 5713 | + if (firstEquilateral) |
---|
5432 | 5714 | { |
---|
5433 | | - minweight = weight; |
---|
| 5715 | + if (OneFaceUsed(links.get(face.p))) |
---|
| 5716 | + continue; |
---|
| 5717 | + |
---|
| 5718 | + if (OneFaceUsed(links.get(face.q))) |
---|
| 5719 | + continue; |
---|
| 5720 | + |
---|
| 5721 | + if (OneFaceUsed(links.get(face.r))) |
---|
| 5722 | + continue; |
---|
| 5723 | + |
---|
5434 | 5724 | chosen = i; |
---|
5435 | | - if (minweight == 0) |
---|
5436 | | - break; |
---|
| 5725 | + break; |
---|
| 5726 | + } |
---|
| 5727 | + else |
---|
| 5728 | + { |
---|
| 5729 | + double K = 1; // 0.01; // .25; |
---|
| 5730 | + |
---|
| 5731 | + double factor = (1-K)*face.nbiterations + K; //*face.weight; |
---|
| 5732 | + |
---|
| 5733 | + double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor; |
---|
| 5734 | + |
---|
| 5735 | + if (minweight > weight) |
---|
| 5736 | + { |
---|
| 5737 | + minweight = weight; |
---|
| 5738 | + chosen = i; |
---|
| 5739 | + if (minweight == 0) |
---|
| 5740 | + break; |
---|
| 5741 | + } |
---|
5437 | 5742 | } |
---|
5438 | 5743 | } |
---|
5439 | 5744 | |
---|
5440 | 5745 | return chosen; |
---|
| 5746 | + } |
---|
| 5747 | + |
---|
| 5748 | + private boolean OneFaceUsed(Vector<Face> faces) |
---|
| 5749 | + { |
---|
| 5750 | + if (faces.size() != 6) |
---|
| 5751 | + return true; |
---|
| 5752 | + |
---|
| 5753 | + for (int i=0; i<6; i+=1) |
---|
| 5754 | + { |
---|
| 5755 | + if (faces.get(i).used) |
---|
| 5756 | + { |
---|
| 5757 | + return true; |
---|
| 5758 | + } |
---|
| 5759 | + } |
---|
| 5760 | + |
---|
| 5761 | + return false; |
---|
5441 | 5762 | } |
---|
5442 | 5763 | |
---|
5443 | 5764 | static boolean remove3valence = true; |
---|
.. | .. |
---|
5473 | 5794 | } |
---|
5474 | 5795 | else |
---|
5475 | 5796 | { |
---|
5476 | | - assert(links.size() == vertices.size()); |
---|
| 5797 | + // TODO Grafreed.Assert(links.size() == vertices.size()); |
---|
5477 | 5798 | |
---|
5478 | 5799 | links.setSize(vertices.size()); |
---|
5479 | 5800 | for (int i=vertices.size(); --i>=0;) |
---|
.. | .. |
---|
5481 | 5802 | // linkstouched[i] = false; |
---|
5482 | 5803 | if (links.get(i) == null) // ?? |
---|
5483 | 5804 | { |
---|
| 5805 | + new Exception().printStackTrace(); |
---|
5484 | 5806 | links.set(i, new Vector(8)); |
---|
5485 | 5807 | // linkstouched[i] = true; |
---|
5486 | 5808 | } |
---|
.. | .. |
---|
5491 | 5813 | } |
---|
5492 | 5814 | } |
---|
5493 | 5815 | |
---|
| 5816 | + boolean once = false; |
---|
| 5817 | + |
---|
5494 | 5818 | for (int i=faces.size(); --i>=0;) |
---|
5495 | 5819 | { |
---|
5496 | 5820 | Face face = (Face) faces.get(i); |
---|
.. | .. |
---|
5502 | 5826 | //if (linkstouched[face.r]) |
---|
5503 | 5827 | links.get(face.r).add(face); |
---|
5504 | 5828 | |
---|
| 5829 | + if (face.used) |
---|
| 5830 | + once = true; |
---|
| 5831 | + |
---|
5505 | 5832 | face.good = 1; |
---|
5506 | 5833 | face.boundary = -1; |
---|
5507 | 5834 | } |
---|
.. | .. |
---|
6273 | 6600 | |
---|
6274 | 6601 | void InitWeights() |
---|
6275 | 6602 | { |
---|
| 6603 | + new Exception().printStackTrace(); |
---|
6276 | 6604 | System.exit(0); |
---|
6277 | 6605 | int n = 0; |
---|
6278 | 6606 | int b = 0; |
---|
.. | .. |
---|
6866 | 7194 | return (face.boundary = 1) == 1; |
---|
6867 | 7195 | } |
---|
6868 | 7196 | |
---|
| 7197 | + // June 2019 |
---|
| 7198 | + if (true) |
---|
| 7199 | + return (face.boundary = 0) == 1; |
---|
| 7200 | + |
---|
6869 | 7201 | // reverse triangle test |
---|
6870 | 7202 | q1.set(p); |
---|
6871 | 7203 | q2.set(q); |
---|
.. | .. |
---|
7230 | 7562 | { |
---|
7231 | 7563 | if (f3.p == f0.p) |
---|
7232 | 7564 | { |
---|
7233 | | - assert(false); |
---|
| 7565 | +// assert(false); |
---|
| 7566 | + new Exception().printStackTrace(); |
---|
7234 | 7567 | f0.r = f3.q; |
---|
7235 | 7568 | } |
---|
7236 | 7569 | else |
---|
.. | .. |
---|
7314 | 7647 | //InitWeights(); |
---|
7315 | 7648 | } |
---|
7316 | 7649 | |
---|
7317 | | - int chosen = ChooseTriangle(); // Best is slow and not really better |
---|
| 7650 | + int chosen = ChooseTriangle(true); // Best is slow and not really better |
---|
7318 | 7651 | |
---|
7319 | 7652 | if (chosen == -1) |
---|
7320 | 7653 | { |
---|
.. | .. |
---|
7328 | 7661 | //remove3valence = false; |
---|
7329 | 7662 | // InitWeights(); |
---|
7330 | 7663 | |
---|
7331 | | - chosen = ChooseTriangle(); |
---|
| 7664 | + chosen = ChooseTriangle(true); |
---|
7332 | 7665 | } |
---|
7333 | 7666 | } |
---|
7334 | 7667 | |
---|
.. | .. |
---|
7604 | 7937 | |
---|
7605 | 7938 | // boolean lock; |
---|
7606 | 7939 | |
---|
7607 | | - void SplitInTwo(boolean reduction34, boolean onlyone) |
---|
| 7940 | + boolean SplitInTwo(boolean reduction34, boolean onlyone) |
---|
7608 | 7941 | { |
---|
7609 | 7942 | if (stripified) |
---|
7610 | 7943 | { |
---|
.. | .. |
---|
7632 | 7965 | s3 = new cVector(); |
---|
7633 | 7966 | } |
---|
7634 | 7967 | |
---|
7635 | | - CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
| 7968 | + Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
7636 | 7969 | |
---|
7637 | 7970 | try |
---|
7638 | 7971 | { |
---|
.. | .. |
---|
7641 | 7974 | { |
---|
7642 | 7975 | System.err.println("EXCEPTION CAUGHT"); |
---|
7643 | 7976 | e.printStackTrace(); |
---|
7644 | | - return; |
---|
| 7977 | + return false; |
---|
7645 | 7978 | } catch (Error e) |
---|
7646 | 7979 | { |
---|
7647 | 7980 | System.err.println("ERROR CAUGHT"); |
---|
7648 | 7981 | e.printStackTrace(); |
---|
7649 | | - return; |
---|
| 7982 | + return false; |
---|
7650 | 7983 | } |
---|
7651 | 7984 | |
---|
7652 | 7985 | System.out.println("# faces = " + faces.size()); |
---|
.. | .. |
---|
7656 | 7989 | { |
---|
7657 | 7990 | Face face = (Face) faces.get(i); |
---|
7658 | 7991 | |
---|
| 7992 | + face.used = false; |
---|
7659 | 7993 | face.nbiterations = 1; |
---|
7660 | 7994 | face.weight = -1; |
---|
7661 | 7995 | face.boundary = -1; |
---|
.. | .. |
---|
7707 | 8041 | nbbadfaces = faces.size(); |
---|
7708 | 8042 | //remove3valence = true; |
---|
7709 | 8043 | |
---|
| 8044 | + int count = 2; |
---|
| 8045 | + |
---|
| 8046 | + if (onlyone) |
---|
| 8047 | + count = 1; |
---|
| 8048 | + |
---|
7710 | 8049 | firstpass = true; |
---|
7711 | 8050 | |
---|
7712 | 8051 | int n = faces.size(); |
---|
.. | .. |
---|
7722 | 8061 | System.out.print('.'); |
---|
7723 | 8062 | } |
---|
7724 | 8063 | System.out.println(); |
---|
| 8064 | + boolean atleastone = false; |
---|
7725 | 8065 | int i = 0; |
---|
7726 | | - while (reduction34 || faces.size() > n/2) |
---|
| 8066 | + while (true) // reduction34 || faces.size() > n/2) |
---|
7727 | 8067 | { |
---|
7728 | 8068 | if (i++%100 == 0) |
---|
7729 | 8069 | { |
---|
7730 | | - CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
| 8070 | + Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
7731 | 8071 | System.out.println("#faces = " + faces.size()); |
---|
7732 | 8072 | // if (i != 1) |
---|
7733 | 8073 | // break; |
---|
.. | .. |
---|
7745 | 8085 | { |
---|
7746 | 8086 | if (!RemoveOneTriangle()) |
---|
7747 | 8087 | break; |
---|
| 8088 | + |
---|
| 8089 | + atleastone = true; |
---|
7748 | 8090 | } |
---|
7749 | 8091 | // if (iterationcount == 0) |
---|
7750 | 8092 | // break; |
---|
.. | .. |
---|
7755 | 8097 | break; |
---|
7756 | 8098 | } |
---|
7757 | 8099 | firstpass = false; |
---|
7758 | | - if (onlyone) |
---|
7759 | | - break; // one triangle only |
---|
| 8100 | +// if (--count<0 && !reduction34) |
---|
| 8101 | +// break; // one triangle only |
---|
7760 | 8102 | } |
---|
7761 | 8103 | |
---|
7762 | 8104 | InitLinks(false); // for further display |
---|
.. | .. |
---|
7771 | 8113 | //Trim(true,cJME.gennormals,true,false); // doesn't work |
---|
7772 | 8114 | Trim(true,false,false,false,false); |
---|
7773 | 8115 | |
---|
7774 | | - CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); |
---|
| 8116 | + Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); |
---|
| 8117 | + |
---|
| 8118 | + return atleastone; |
---|
7775 | 8119 | } |
---|
7776 | 8120 | |
---|
7777 | 8121 | void UpdateIndices(Face face, Face minface) |
---|
.. | .. |
---|
7784 | 8128 | face.p = minface.p; |
---|
7785 | 8129 | //if (leafweights) |
---|
7786 | 8130 | face.good = 0; // false; |
---|
| 8131 | + face.used = true; |
---|
7787 | 8132 | } |
---|
7788 | 8133 | if (face.q == minface.p || face.q == minface.q || face.q == minface.r) |
---|
7789 | 8134 | { |
---|
7790 | 8135 | face.q = minface.p; |
---|
7791 | 8136 | //if (leafweights) |
---|
7792 | 8137 | face.good = 0; // false; |
---|
| 8138 | + face.used = true; |
---|
7793 | 8139 | } |
---|
7794 | 8140 | if (face.r == minface.p || face.r == minface.q || face.r == minface.r) |
---|
7795 | 8141 | { |
---|
7796 | 8142 | face.r = minface.p; |
---|
7797 | 8143 | //if (leafweights) |
---|
7798 | 8144 | face.good = 0; // false; |
---|
| 8145 | + face.used = true; |
---|
7799 | 8146 | } |
---|
7800 | 8147 | |
---|
7801 | 8148 | if (face.p >/*=*/ minface.q && face.p < minface.r) |
---|
.. | .. |
---|
7855 | 8202 | if (v == 2) |
---|
7856 | 8203 | vert = minface.r; |
---|
7857 | 8204 | // 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) |
---|
| 8205 | + Vector<Face> vertfaces = links.get(vert); |
---|
| 8206 | + for (int i=vertfaces.size(); --i>=0;) |
---|
7869 | 8207 | { |
---|
7870 | | - if (!leafweights) |
---|
| 8208 | + Face face = (Face) vertfaces.get(i); |
---|
| 8209 | + |
---|
| 8210 | + // if (face.weight == 10000) |
---|
| 8211 | + // continue; |
---|
| 8212 | + |
---|
| 8213 | + if (face.p == minface.p || face.q == minface.p || face.r == minface.p || |
---|
| 8214 | + face.p == minface.q || face.q == minface.q || face.r == minface.q || |
---|
| 8215 | + face.p == minface.r || face.q == minface.r || face.r == minface.r) |
---|
7871 | 8216 | { |
---|
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); |
---|
| 8217 | + if (!leafweights) |
---|
| 8218 | + { |
---|
| 8219 | + // if(minfaceweight <= 0) |
---|
| 8220 | + // assert(minfaceweight > 0); |
---|
| 8221 | + // |
---|
| 8222 | + // //FaceWeight(face); |
---|
| 8223 | + // if(face.weight < 0) |
---|
| 8224 | + // assert(face.weight >= 0); |
---|
| 8225 | + |
---|
| 8226 | + face.weight += minfaceweight; |
---|
| 8227 | + |
---|
| 8228 | + // if (face.weight >= 10000) |
---|
| 8229 | + // assert(face.weight < 10000); |
---|
| 8230 | + } |
---|
| 8231 | + else |
---|
| 8232 | + face.weight = -1; |
---|
| 8233 | + |
---|
| 8234 | + face.nbiterations += 1; |
---|
| 8235 | + face.boundary = -1; |
---|
| 8236 | + |
---|
| 8237 | + Vertex p = (Vertex)vertices.get(face.p); |
---|
| 8238 | + Vertex q = (Vertex)vertices.get(face.q); |
---|
| 8239 | + Vertex r = (Vertex)vertices.get(face.r); |
---|
| 8240 | + |
---|
| 8241 | + p.boundary = -1; |
---|
| 8242 | + q.boundary = -1; |
---|
| 8243 | + r.boundary = -1; |
---|
7883 | 8244 | } |
---|
7884 | 8245 | 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; |
---|
| 8246 | + assert(false); |
---|
7897 | 8247 | } |
---|
7898 | | - else |
---|
7899 | | - assert(false); |
---|
7900 | 8248 | } |
---|
7901 | | - } |
---|
7902 | 8249 | |
---|
7903 | 8250 | // TouchVertex(minface.p); |
---|
7904 | 8251 | // TouchVertex(minface.q); |
---|
.. | .. |
---|
8099 | 8446 | for (int i=vertfaces.size(); --i>=0;) |
---|
8100 | 8447 | { |
---|
8101 | 8448 | Face face = (Face) vertfaces.get(i); |
---|
| 8449 | + face.used = true; |
---|
8102 | 8450 | face.good = 0; // false; |
---|
8103 | 8451 | if (leafweights) |
---|
8104 | 8452 | face.weight = -1; |
---|
.. | .. |
---|
8145 | 8493 | if (!trimmed) |
---|
8146 | 8494 | return; |
---|
8147 | 8495 | |
---|
8148 | | - GrafreeD.linkUV = false; |
---|
| 8496 | + Grafreed.linkUV = false; |
---|
8149 | 8497 | |
---|
8150 | 8498 | try |
---|
8151 | 8499 | { |
---|
.. | .. |
---|
8353 | 8701 | return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices; |
---|
8354 | 8702 | } |
---|
8355 | 8703 | |
---|
8356 | | - static Camera localcamera = new Camera(); |
---|
8357 | | - static cVector from = new cVector(); |
---|
8358 | | - static cVector to = new cVector(); |
---|
8359 | 8704 | boolean trimmed = false; |
---|
8360 | 8705 | boolean stripified = false; |
---|
8361 | 8706 | transient boolean AOdone = false; |
---|
.. | .. |
---|
8363 | 8708 | /*transient*/ int maxIndexV = 0; |
---|
8364 | 8709 | /*transient*/ int bufV, bufF; |
---|
8365 | 8710 | // Raw version |
---|
8366 | | - private float[] positions; |
---|
8367 | | - private float[] normals; |
---|
| 8711 | + //private |
---|
| 8712 | + float[] positions; |
---|
| 8713 | + //private |
---|
| 8714 | + float[] normals; |
---|
8368 | 8715 | float[] colors; |
---|
8369 | 8716 | private float[] uvmap; |
---|
8370 | 8717 | private int[] triangles; |
---|
.. | .. |
---|
8378 | 8725 | int[] startvertices; |
---|
8379 | 8726 | float[] averagepoints; |
---|
8380 | 8727 | float[] extremepoints; |
---|
8381 | | - float[] supportsizes; // distance of closest point |
---|
| 8728 | + float[] supportminsize; // distance of closest point |
---|
| 8729 | + float[] supportmaxsize; // distance of fartest point |
---|
8382 | 8730 | |
---|
8383 | 8731 | transient Hashtable vertextable; |
---|
8384 | 8732 | /*transient*/ private Vertex[] verticesCopy; |
---|