.. | .. |
---|
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) |
---|
.. | .. |
---|
497 | 527 | return dist2; |
---|
498 | 528 | } |
---|
499 | 529 | |
---|
500 | | - static Vertex vertextemp = new Vertex(); |
---|
501 | | - static Vertex vertextemp2 = new Vertex(); |
---|
| 530 | + static Vertex vertextemp = new Vertex(true); |
---|
| 531 | + static Vertex vertextemp2 = new Vertex(true); |
---|
502 | 532 | |
---|
503 | | - static double SEUIL = 0.1; // 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) |
---|
.. | .. |
---|
570 | 600 | |
---|
571 | 601 | if (dot > distmax) |
---|
572 | 602 | dot = distmax; |
---|
| 603 | + //return 0; // patch for strange behavior |
---|
573 | 604 | if (dot < -distmax) |
---|
574 | 605 | dot = -distmax; |
---|
| 606 | + //return 0; // patch for strange behavior |
---|
575 | 607 | |
---|
576 | 608 | // v3 = GetVertex(this.startvertices[subsupport] + 16); |
---|
577 | 609 | // |
---|
.. | .. |
---|
596 | 628 | // ; |
---|
597 | 629 | // |
---|
598 | 630 | |
---|
599 | | - supportsize = supportsizes[subsupport]; |
---|
| 631 | + supportsize = supportminsize[subsupport]; |
---|
600 | 632 | |
---|
601 | 633 | double K = supportsize / distmax; |
---|
602 | 634 | |
---|
.. | .. |
---|
609 | 641 | |
---|
610 | 642 | float dist2 = (float)Distance2(v, v2, 1E10, toRoot, k); |
---|
611 | 643 | |
---|
612 | | - if (dist2 >= 2 * SEUIL*SEUIL) // && !CameraPane.CROWD) // weightmode |
---|
| 644 | + double seuil = SEUIL * 2; |
---|
| 645 | + |
---|
| 646 | + if (dist2 >= 2 * seuil*seuil) // && !CameraPane.CROWD) // weightmode |
---|
613 | 647 | return 0; |
---|
614 | 648 | |
---|
615 | | - dist2 /= 2 * SEUIL*SEUIL; // multiplied by two because center of support |
---|
| 649 | + dist2 /= 2 * seuil*seuil; // multiplied by two because center of support |
---|
616 | 650 | // could be far from closest point |
---|
617 | 651 | |
---|
618 | 652 | // dist2 = Math.pow(dist2, 2); |
---|
.. | .. |
---|
646 | 680 | // if (supportsize * fadefactor > 1) |
---|
647 | 681 | // return 1; |
---|
648 | 682 | |
---|
649 | | - return supportsize * fadefactor; |
---|
| 683 | + return //supportsize * |
---|
| 684 | + supportsize * fadefactor; |
---|
650 | 685 | } |
---|
651 | 686 | |
---|
652 | 687 | void RecomputeBasis(BoundaryRep other, double[][] toRoot, Vertex v) |
---|
.. | .. |
---|
786 | 821 | v.weights[k] = other.ComputeWeight(v, toRoot, k); // (float)(supportsize * normalweight * nz / Math.pow(tx*tx+ty*ty+tz*tz, 1)); |
---|
787 | 822 | v.totalweight += v.weights[k]; |
---|
788 | 823 | |
---|
789 | | - if (CameraPane.CROWD) |
---|
| 824 | + if (Globals.CROWD) |
---|
790 | 825 | { |
---|
791 | 826 | // System.out.print("weight = " + v.weights[k]); |
---|
792 | 827 | // System.out.println("; totalweight = " + v.totalweight); |
---|
.. | .. |
---|
946 | 981 | |
---|
947 | 982 | int nbsupports; |
---|
948 | 983 | |
---|
949 | | - SEUIL = 0.1; // aout 2013 |
---|
| 984 | + // sept 2017 SEUIL = 0.1; // aout 2013 |
---|
950 | 985 | |
---|
951 | | - supports = InitConnections(other); |
---|
| 986 | + supports = other.InitConnections(); |
---|
952 | 987 | |
---|
953 | 988 | other.supports = supports; // should be the other way around... |
---|
954 | 989 | |
---|
.. | .. |
---|
982 | 1017 | |
---|
983 | 1018 | int subsupports = 0; |
---|
984 | 1019 | |
---|
985 | | - SEUIL = 0.1; // aout 2013 |
---|
| 1020 | + // sept 2017 SEUIL = 0.1; // aout 2013 |
---|
986 | 1021 | |
---|
987 | 1022 | while (subsupports == 0) |
---|
988 | 1023 | { |
---|
.. | .. |
---|
1006 | 1041 | |
---|
1007 | 1042 | vect.set(v); |
---|
1008 | 1043 | vect.sub(vect2); |
---|
| 1044 | + |
---|
| 1045 | +// vertextemp.x = other.averagepoints[c*3]; |
---|
| 1046 | +// vertextemp.y = other.averagepoints[c*3+1]; |
---|
| 1047 | +// vertextemp.z = other.averagepoints[c*3+2]; |
---|
| 1048 | +// |
---|
| 1049 | +// Vertex v3 = vertextemp2; |
---|
| 1050 | +// v3.x = other.extremepoints[c*3]; |
---|
| 1051 | +// v3.y = other.extremepoints[c*3+1]; |
---|
| 1052 | +// v3.z = other.extremepoints[c*3+2]; |
---|
| 1053 | +// |
---|
| 1054 | +// vect3.set(v3); // "X" axis apex |
---|
| 1055 | +// vect3.sub(vertextemp); // origin (center) |
---|
| 1056 | +// |
---|
| 1057 | +// double distmax = vect3.length(); |
---|
| 1058 | +// |
---|
| 1059 | +// vect3.set(v2); // "X" axis apex |
---|
| 1060 | +// vect3.sub(vertextemp); // origin (center) |
---|
| 1061 | +// |
---|
| 1062 | +// if (vect3.length() >= distmax) |
---|
| 1063 | +// continue; |
---|
1009 | 1064 | |
---|
1010 | 1065 | if (mindistance > vect.dot(vect)) |
---|
1011 | 1066 | { |
---|
.. | .. |
---|
1017 | 1072 | |
---|
1018 | 1073 | subsupports = v.closestsupport==-1 ? 0 : supports[v.closestsupport].Length(); |
---|
1019 | 1074 | |
---|
1020 | | - SEUIL *= 2; |
---|
| 1075 | + // previously for "contains", now for weights. |
---|
| 1076 | + assert(subsupports > 0); |
---|
| 1077 | + //SEUIL *= 2; |
---|
1021 | 1078 | } |
---|
1022 | 1079 | |
---|
1023 | 1080 | assert(subsupports > 0); |
---|
.. | .. |
---|
1492 | 1549 | InitFaceIndices(); |
---|
1493 | 1550 | } |
---|
1494 | 1551 | |
---|
1495 | | - BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this); |
---|
| 1552 | + BoundaryRep rep = (BoundaryRep) Grafreed.clone(this); |
---|
1496 | 1553 | //float[] v = new float[100]; |
---|
1497 | 1554 | |
---|
1498 | 1555 | for (int loops=1; --loops>=0;) |
---|
.. | .. |
---|
1522 | 1579 | InitFaceIndices(); |
---|
1523 | 1580 | } |
---|
1524 | 1581 | |
---|
1525 | | - BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this); |
---|
| 1582 | + BoundaryRep rep = (BoundaryRep) Grafreed.clone(this); |
---|
1526 | 1583 | //float[] v = new float[100]; |
---|
1527 | 1584 | |
---|
1528 | 1585 | for (int loops=10; --loops>=0;) |
---|
.. | .. |
---|
1869 | 1926 | return; |
---|
1870 | 1927 | } |
---|
1871 | 1928 | |
---|
1872 | | - // System.exit(0); |
---|
| 1929 | + // System.exit(0); |
---|
1873 | 1930 | |
---|
1874 | 1931 | cVector vect = new cVector(); |
---|
1875 | 1932 | cVector normal = new cVector(); |
---|
.. | .. |
---|
1940 | 1997 | if (v.vertexlinks == null) |
---|
1941 | 1998 | continue; |
---|
1942 | 1999 | |
---|
1943 | | - if (v.weights != null && v.weights[j] == 0) // < 0.01 * v.totalweight) // == 0) |
---|
| 2000 | + // Warning: a bit faster but dangerous |
---|
| 2001 | + if (v.weights != null && v.weights[j] == 0) |
---|
| 2002 | + // < 0.001 * v.totalweight) |
---|
1944 | 2003 | { |
---|
1945 | 2004 | //testweight += v.weights[j-1]; |
---|
1946 | 2005 | continue; |
---|
.. | .. |
---|
2221 | 2280 | |
---|
2222 | 2281 | transient int lastsoundtime; |
---|
2223 | 2282 | |
---|
| 2283 | + transient boolean once = false; |
---|
| 2284 | + |
---|
2224 | 2285 | void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked) |
---|
2225 | 2286 | { |
---|
2226 | 2287 | if (LA.isIdentity(toRoot)) |
---|
.. | .. |
---|
2276 | 2337 | |
---|
2277 | 2338 | if (v.totalweight == 0) |
---|
2278 | 2339 | { |
---|
2279 | | - System.err.println("v.totalweight == 0! --> " + this + " : " + other); |
---|
| 2340 | + if (!once) |
---|
| 2341 | + { |
---|
| 2342 | + System.err.println("v.totalweight == 0! --> " + this + " : " + other); |
---|
| 2343 | + once = true; |
---|
| 2344 | + } |
---|
2280 | 2345 | continue; |
---|
2281 | 2346 | } |
---|
2282 | 2347 | |
---|
.. | .. |
---|
2635 | 2700 | if (false) // slow && stepout && onein) |
---|
2636 | 2701 | { |
---|
2637 | 2702 | // sound |
---|
2638 | | - cVector eye = CameraPane.theRenderer.eyeCamera.location; |
---|
| 2703 | + cVector eye = Globals.theRenderer.EyeCamera().location; |
---|
2639 | 2704 | |
---|
2640 | 2705 | Vertex v = GetVertex(0); |
---|
2641 | 2706 | |
---|
2642 | 2707 | tmp.set(v); |
---|
2643 | 2708 | tmp.sub(eye); |
---|
2644 | 2709 | |
---|
2645 | | - if (CameraPane.framecount - lastsoundtime > 30) // 0.25 secs |
---|
| 2710 | + if (Globals.framecount - lastsoundtime > 30) // 0.25 secs |
---|
2646 | 2711 | { |
---|
2647 | | - GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1); |
---|
| 2712 | + Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1); |
---|
2648 | 2713 | |
---|
2649 | | - lastsoundtime = CameraPane.framecount; |
---|
| 2714 | + lastsoundtime = Globals.framecount; |
---|
2650 | 2715 | } |
---|
2651 | 2716 | |
---|
2652 | 2717 | stepout = false; |
---|
.. | .. |
---|
3072 | 3137 | // |
---|
3073 | 3138 | // transient VertexCompare[] vertexcompare = null; |
---|
3074 | 3139 | |
---|
| 3140 | + // Check if v0 is close enough from any vertex of the given subobject of this. |
---|
3075 | 3141 | boolean Contains(Vertex v0, int object) |
---|
3076 | 3142 | { |
---|
3077 | 3143 | int start = startvertices[object-1]; |
---|
.. | .. |
---|
3129 | 3195 | */ |
---|
3130 | 3196 | } |
---|
3131 | 3197 | |
---|
3132 | | - void GenUV() |
---|
| 3198 | + void UnfoldUV() |
---|
| 3199 | + { |
---|
| 3200 | + for (int i = 0; i < VertexCount(); i++) |
---|
| 3201 | + { |
---|
| 3202 | + Vertex v = GetVertex(i); |
---|
| 3203 | + |
---|
| 3204 | + v.x = v.s; |
---|
| 3205 | + v.y = v.t; |
---|
| 3206 | + v.z = 0; |
---|
| 3207 | + |
---|
| 3208 | + v.norm.x = 0; |
---|
| 3209 | + v.norm.y = 0; |
---|
| 3210 | + v.norm.z = 1; |
---|
| 3211 | + |
---|
| 3212 | + SetVertex(v, i); |
---|
| 3213 | + } |
---|
| 3214 | + } |
---|
| 3215 | + |
---|
| 3216 | + float power = 2; |
---|
| 3217 | + |
---|
| 3218 | + void GenUV() // float power) |
---|
3133 | 3219 | { |
---|
3134 | 3220 | Trim(); |
---|
3135 | 3221 | |
---|
.. | .. |
---|
3193 | 3279 | y -= 0.5; |
---|
3194 | 3280 | z -= 0.5; |
---|
3195 | 3281 | |
---|
| 3282 | + double ax = Math.abs(x); |
---|
| 3283 | + double ay = Math.abs(y); |
---|
| 3284 | + double max = ax; |
---|
| 3285 | + if (max < ay) |
---|
| 3286 | + { |
---|
| 3287 | + max = ay; |
---|
| 3288 | + } |
---|
| 3289 | + |
---|
| 3290 | + if (max == 0) |
---|
| 3291 | + { |
---|
| 3292 | + uvmap[i2] = 0.5f; |
---|
| 3293 | + uvmap[i2+1] = 0.5f; |
---|
| 3294 | + continue; |
---|
| 3295 | + } |
---|
| 3296 | + |
---|
| 3297 | + x /= max; |
---|
| 3298 | + y /= max; |
---|
| 3299 | + |
---|
| 3300 | + double angle = Math.acos(Math.abs(z*2)); |
---|
| 3301 | + |
---|
| 3302 | + double k = angle / Math.PI * 2; |
---|
| 3303 | + |
---|
| 3304 | + assert(k >= 0); |
---|
| 3305 | + |
---|
| 3306 | + // k == 0 => uv = 0 (center) |
---|
| 3307 | + // k == 1 => uv = -1,1 (border) |
---|
| 3308 | + |
---|
| 3309 | + if (i == 0) |
---|
| 3310 | + System.out.println("power = " + power); |
---|
| 3311 | + |
---|
| 3312 | + double length1 = (ax+ay)/max; |
---|
| 3313 | + double length2 = Math.sqrt(ax*ax + ay*ay) / max; |
---|
| 3314 | + |
---|
| 3315 | + double t = k; |
---|
| 3316 | + |
---|
| 3317 | + t = Math.pow(t, 3); |
---|
| 3318 | + |
---|
| 3319 | + // Interpolate between k/length2 (center) and k (border) |
---|
| 3320 | + if (length2 > 0) |
---|
| 3321 | + k *= (1 - t) / length2 + t; |
---|
| 3322 | + |
---|
| 3323 | + double u = k*x; |
---|
| 3324 | + double v = k*y; |
---|
| 3325 | + |
---|
| 3326 | + u /= 2; |
---|
| 3327 | + v /= 2; |
---|
| 3328 | + u += 0.5; |
---|
| 3329 | + v += 0.5; |
---|
| 3330 | + |
---|
| 3331 | + uvmap[i2] = (float) u; |
---|
| 3332 | + uvmap[i2+1] = (float) v; |
---|
| 3333 | + } |
---|
| 3334 | + } |
---|
| 3335 | + |
---|
| 3336 | + void GenUVold(float power) |
---|
| 3337 | + { |
---|
| 3338 | + Trim(); |
---|
| 3339 | + |
---|
| 3340 | + cVector boxcenter = null; |
---|
| 3341 | + cVector minima, maxima; |
---|
| 3342 | + minima = new cVector(); |
---|
| 3343 | + maxima = new cVector(); |
---|
| 3344 | + minima.x = minima.y = minima.z = Double.MAX_VALUE; |
---|
| 3345 | + maxima.x = maxima.y = maxima.z = -Double.MAX_VALUE; |
---|
| 3346 | + for (int i = 0; i < VertexCount(); i++) |
---|
| 3347 | + { |
---|
| 3348 | + Vertex v = GetVertex(i); |
---|
| 3349 | + |
---|
| 3350 | + if (minima.x > v.x) |
---|
| 3351 | + { |
---|
| 3352 | + minima.x = v.x; |
---|
| 3353 | + } |
---|
| 3354 | + if (minima.y > v.y) |
---|
| 3355 | + { |
---|
| 3356 | + minima.y = v.y; |
---|
| 3357 | + } |
---|
| 3358 | + if (minima.z > v.z) |
---|
| 3359 | + { |
---|
| 3360 | + minima.z = v.z; |
---|
| 3361 | + } |
---|
| 3362 | + |
---|
| 3363 | + if (maxima.x < v.x) |
---|
| 3364 | + { |
---|
| 3365 | + maxima.x = v.x; |
---|
| 3366 | + } |
---|
| 3367 | + if (maxima.y < v.y) |
---|
| 3368 | + { |
---|
| 3369 | + maxima.y = v.y; |
---|
| 3370 | + } |
---|
| 3371 | + if (maxima.z < v.z) |
---|
| 3372 | + { |
---|
| 3373 | + maxima.z = v.z; |
---|
| 3374 | + } |
---|
| 3375 | + } |
---|
| 3376 | + |
---|
| 3377 | + boxcenter = new cVector((maxima.x + minima.x) / 2, (maxima.y + minima.y) / 2, (maxima.z + minima.z) / 2); |
---|
| 3378 | + int i2 = 0, i3 = 0; |
---|
| 3379 | + for (int i = 0; i < positions.length/3; i++, i3 += 3, i2 += 2) |
---|
| 3380 | + { |
---|
| 3381 | +// //uvmap[i2] = (float) normals[i3]*0.5f + 0.5f; // v.x; |
---|
| 3382 | +// //uvmap[i2 + 1] = (float) normals[i3+1]*0.5f + 0.5f; //z; |
---|
| 3383 | +// uvmap[i2] = (float) (positions[i3] - boxcenter.x); |
---|
| 3384 | +// uvmap[i2 + 1] = (float) (positions[i3+2] - boxcenter.z); |
---|
| 3385 | +// uvmap[i2] = (float) Math.atan2(positions[i3+1] - boxcenter.y, positions[i3] - boxcenter.x); |
---|
| 3386 | +// uvmap[i2 + 1] = (float)(positions[i3+2] - boxcenter.z); |
---|
| 3387 | + // box UV |
---|
| 3388 | + double x = positions[i3] - minima.x; // - Math.floor(positions[i3]); |
---|
| 3389 | + double y = positions[i3+1] - minima.y; // - Math.floor(positions[i3+1]); |
---|
| 3390 | + double z = positions[i3+2] - minima.z; // - Math.floor(positions[i3+2]); |
---|
| 3391 | + |
---|
| 3392 | + // [-1/2, 1/2] |
---|
| 3393 | + x /= maxima.x - minima.x; |
---|
| 3394 | + y /= maxima.y - minima.y; |
---|
| 3395 | + z /= maxima.z - minima.z; |
---|
| 3396 | + |
---|
| 3397 | + x -= 0.5; |
---|
| 3398 | + y -= 0.5; |
---|
| 3399 | + z -= 0.5; |
---|
| 3400 | + |
---|
3196 | 3401 | // x *= 2; |
---|
3197 | 3402 | // y *= 2; |
---|
3198 | 3403 | // z *= 2; |
---|
.. | .. |
---|
3219 | 3424 | |
---|
3220 | 3425 | z = Math.cos(angle/2); |
---|
3221 | 3426 | |
---|
| 3427 | + assert(z >= 0); |
---|
| 3428 | + assert(z <= 1); |
---|
| 3429 | + |
---|
| 3430 | + /**/ |
---|
| 3431 | + //z = Math.pow(z, power); //1.08f); |
---|
| 3432 | + |
---|
| 3433 | + if (i == 0) |
---|
| 3434 | + System.out.println("power = " + power); |
---|
| 3435 | + |
---|
3222 | 3436 | // sqrt(k2*x2 + k2*z2 + y2) = length |
---|
3223 | 3437 | // k2*x2 + k2*z2 = length2 - y2 |
---|
3224 | 3438 | // k2 = (length2 - y2) / (x2 + z2) |
---|
.. | .. |
---|
3229 | 3443 | k /= x*x + y*y; |
---|
3230 | 3444 | } |
---|
3231 | 3445 | else |
---|
3232 | | - GrafreeD.Assert(z == 1); |
---|
| 3446 | + Grafreed.Assert(z == 1); |
---|
3233 | 3447 | |
---|
3234 | 3448 | if (k < 0) |
---|
3235 | 3449 | k = 0; |
---|
.. | .. |
---|
3238 | 3452 | |
---|
3239 | 3453 | x *= k; |
---|
3240 | 3454 | y *= k; |
---|
| 3455 | + /**/ |
---|
3241 | 3456 | |
---|
3242 | 3457 | double max = Math.abs(x); |
---|
3243 | 3458 | if (max < Math.abs(y)) |
---|
.. | .. |
---|
3250 | 3465 | } |
---|
3251 | 3466 | |
---|
3252 | 3467 | // max = Math.sqrt(max*2)/2; |
---|
| 3468 | +// double x2 = Math.pow(Math.abs(x), 1/power); |
---|
| 3469 | +// double y2 = Math.pow(Math.abs(y), 1/power); |
---|
| 3470 | +// double z2 = Math.pow(Math.abs(z), 1/power); |
---|
| 3471 | +// max = Math.pow(x2 + y2 + z2, power); |
---|
3253 | 3472 | |
---|
3254 | 3473 | // if (!(max > 0)) |
---|
3255 | | - assert(max > 0); |
---|
3256 | | - |
---|
| 3474 | + //assert(max > 0); |
---|
| 3475 | + assert(max >= 0); |
---|
| 3476 | + |
---|
3257 | 3477 | x /= max; |
---|
3258 | 3478 | y /= max; |
---|
3259 | 3479 | z /= max; |
---|
.. | .. |
---|
3516 | 3736 | */ |
---|
3517 | 3737 | } |
---|
3518 | 3738 | |
---|
| 3739 | + void GenerateNormals2(boolean crease) |
---|
| 3740 | + { |
---|
| 3741 | + cVector tempVector = new cVector(); |
---|
| 3742 | + |
---|
| 3743 | +// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>(); |
---|
| 3744 | +// |
---|
| 3745 | +// |
---|
| 3746 | +// for (int i=0; i<this.VertexCount(); i++) |
---|
| 3747 | +// { |
---|
| 3748 | +// Vertex v = this.GetVertex(i); |
---|
| 3749 | +// |
---|
| 3750 | +// tempVector.set(v); |
---|
| 3751 | +// |
---|
| 3752 | +// cVector n = tableBase.get(tempVector.ToFloat()); |
---|
| 3753 | +// |
---|
| 3754 | +// if (n != null) |
---|
| 3755 | +// { |
---|
| 3756 | +// continue; |
---|
| 3757 | +// } |
---|
| 3758 | +// |
---|
| 3759 | +// tableBase.put(new cVector(tempVector), new cVector(v.norm)); |
---|
| 3760 | +// } |
---|
| 3761 | + |
---|
| 3762 | + BoundaryRep tempSupport = this.support; |
---|
| 3763 | + |
---|
| 3764 | + this.support = null; |
---|
| 3765 | + |
---|
| 3766 | + BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this); |
---|
| 3767 | + |
---|
| 3768 | + this.support = tempSupport; |
---|
| 3769 | + |
---|
| 3770 | + //tempRep.Unstripify(); |
---|
| 3771 | + |
---|
| 3772 | + tempRep.GenerateNormals2(crease); |
---|
| 3773 | + |
---|
| 3774 | + boolean keepnormal = Vertex.normalmode; |
---|
| 3775 | + boolean epsequal = Grafreed.epsequal; |
---|
| 3776 | + |
---|
| 3777 | + Vertex.normalmode = false; |
---|
| 3778 | + Grafreed.epsequal = false; // A bit strange |
---|
| 3779 | + |
---|
| 3780 | + // No need to have a match for vertex counts. |
---|
| 3781 | + |
---|
| 3782 | + java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>(); |
---|
| 3783 | + |
---|
| 3784 | + for (int i=0; i<tempRep.VertexCount(); i++) |
---|
| 3785 | + { |
---|
| 3786 | + Vertex v = tempRep.GetVertex(i); |
---|
| 3787 | + |
---|
| 3788 | + cVector n = table.get(tempVector.ToFloat()); |
---|
| 3789 | + |
---|
| 3790 | + if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0) |
---|
| 3791 | + { |
---|
| 3792 | + //continue; |
---|
| 3793 | + } |
---|
| 3794 | + |
---|
| 3795 | + tempVector.set(v); |
---|
| 3796 | + |
---|
| 3797 | + //cVector nBase = tableBase.get(tempVector); |
---|
| 3798 | + |
---|
| 3799 | + //if (v.norm.dot(nBase) < 0.9) |
---|
| 3800 | + //{ |
---|
| 3801 | + // continue; |
---|
| 3802 | + //} |
---|
| 3803 | + |
---|
| 3804 | + if (n != null && n.x == 1 && n.y == 0 && n.z == 0) |
---|
| 3805 | + { |
---|
| 3806 | + //continue; |
---|
| 3807 | + } |
---|
| 3808 | + |
---|
| 3809 | + if (n != null) |
---|
| 3810 | + { |
---|
| 3811 | +// if (n.dot(v.norm) < 0) |
---|
| 3812 | +// n.sub(v.norm); |
---|
| 3813 | +// else |
---|
| 3814 | +// n.add(v.norm); |
---|
| 3815 | +// |
---|
| 3816 | +// n.normalize(); |
---|
| 3817 | + continue; |
---|
| 3818 | + } |
---|
| 3819 | + |
---|
| 3820 | + table.put(new cVector(tempVector), new cVector(v.norm)); |
---|
| 3821 | + } |
---|
| 3822 | + |
---|
| 3823 | + for (int i=0; i<this.VertexCount(); i++) |
---|
| 3824 | + { |
---|
| 3825 | + Vertex v = this.GetVertex(i); |
---|
| 3826 | + |
---|
| 3827 | + tempVector.set(v); |
---|
| 3828 | + |
---|
| 3829 | + cVector n = table.get(tempVector.ToFloat()); |
---|
| 3830 | + |
---|
| 3831 | + //if (n.dot(v.norm) < 0) |
---|
| 3832 | + if (n == null) |
---|
| 3833 | + continue; |
---|
| 3834 | + |
---|
| 3835 | + LA.vecCopy(n, v.norm); |
---|
| 3836 | + |
---|
| 3837 | + this.SetVertex(v, i); |
---|
| 3838 | + } |
---|
| 3839 | + |
---|
| 3840 | + Grafreed.epsequal = epsequal; |
---|
| 3841 | + Vertex.normalmode = keepnormal; |
---|
| 3842 | + } |
---|
| 3843 | + |
---|
3519 | 3844 | void GenerateNormals(boolean crease) |
---|
3520 | 3845 | { |
---|
3521 | 3846 | boolean wastrim = trimmed; |
---|
.. | .. |
---|
3532 | 3857 | } |
---|
3533 | 3858 | |
---|
3534 | 3859 | Trim(true/*wastrim*/,true,crease,wasstrip,false); |
---|
| 3860 | + } |
---|
| 3861 | + |
---|
| 3862 | + void GenerateNormalsMesh() |
---|
| 3863 | + { |
---|
| 3864 | + if (stripified) |
---|
| 3865 | + { |
---|
| 3866 | + Unstripify(); |
---|
| 3867 | + } |
---|
| 3868 | + |
---|
| 3869 | + if (trimmed) |
---|
| 3870 | + { |
---|
| 3871 | + normals = null; |
---|
| 3872 | + } |
---|
| 3873 | + else |
---|
| 3874 | + { |
---|
| 3875 | + for (int i=VertexCount(); --i>=0;) |
---|
| 3876 | + { |
---|
| 3877 | + Vertex v = GetVertex(i); |
---|
| 3878 | + |
---|
| 3879 | + v.norm = null; |
---|
| 3880 | + } |
---|
| 3881 | + } |
---|
3535 | 3882 | } |
---|
3536 | 3883 | |
---|
3537 | 3884 | void GenNormalsJME() |
---|
.. | .. |
---|
3656 | 4003 | NormalGenerator ng; |
---|
3657 | 4004 | |
---|
3658 | 4005 | if (crease) |
---|
3659 | | - ng = new NormalGenerator(Math.PI/6); // default is 44 degrees (or Math.PI/3); // /4); |
---|
| 4006 | + ng = new NormalGenerator(Math.PI/4); // default is 44 degrees (or Math.PI/3); // /4); |
---|
3660 | 4007 | else |
---|
3661 | 4008 | ng = new NormalGenerator(Math.PI); // (Math.PI / 3); // /4); |
---|
3662 | 4009 | |
---|
.. | .. |
---|
3689 | 4036 | { |
---|
3690 | 4037 | triangles[i] = i; |
---|
3691 | 4038 | } |
---|
| 4039 | + |
---|
| 4040 | +// Untrim(); |
---|
| 4041 | + if (!trimmed) |
---|
| 4042 | + MergeNormals(); |
---|
3692 | 4043 | } |
---|
3693 | 4044 | } |
---|
3694 | 4045 | |
---|
.. | .. |
---|
3722 | 4073 | tsa.getNormals(0, normals); |
---|
3723 | 4074 | tsa.getTextureCoordinates(0, 0, uvmap); |
---|
3724 | 4075 | // tsa.getColors(0, colors); |
---|
| 4076 | + |
---|
| 4077 | + for (int i=colors.length; --i>=0;) |
---|
| 4078 | + { |
---|
| 4079 | + colors[i] = 1; |
---|
| 4080 | + } |
---|
3725 | 4081 | |
---|
3726 | 4082 | int stripcount = tsa.getNumStrips(); |
---|
3727 | 4083 | triangles = new int[stripcount]; |
---|
.. | .. |
---|
3744 | 4100 | triangles = new int[1]; |
---|
3745 | 4101 | triangles[0] = 3; |
---|
3746 | 4102 | } |
---|
| 4103 | + |
---|
| 4104 | + //Untrim(); |
---|
| 4105 | + if (!trimmed) |
---|
| 4106 | + MergeNormals(); |
---|
3747 | 4107 | } |
---|
3748 | 4108 | |
---|
3749 | 4109 | /* |
---|
.. | .. |
---|
3776 | 4136 | for (int i = 0; i < VertexCount(); i++) |
---|
3777 | 4137 | { |
---|
3778 | 4138 | Vertex v = GetVertex(i); |
---|
| 4139 | + |
---|
| 4140 | + vertextemp.set(v); |
---|
| 4141 | + |
---|
3779 | 4142 | //if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0) |
---|
3780 | 4143 | { |
---|
3781 | | - GenerateNormal(i, v); |
---|
3782 | | - SetVertex(v, i); |
---|
| 4144 | + if (!GenerateNormal(i, vertextemp)) |
---|
| 4145 | + continue; |
---|
| 4146 | + |
---|
| 4147 | + if (v.norm.dot(vertextemp.norm) < 0) |
---|
| 4148 | + vertextemp.norm.mul(-1); |
---|
| 4149 | + |
---|
| 4150 | + if (v.norm.dot(vertextemp.norm) < 0.9) |
---|
| 4151 | + SetVertex(vertextemp, i); |
---|
3783 | 4152 | } |
---|
3784 | 4153 | } |
---|
3785 | 4154 | |
---|
3786 | 4155 | Vertex.normalmode = false; |
---|
3787 | 4156 | } |
---|
3788 | 4157 | |
---|
| 4158 | + void MergeNormals() |
---|
| 4159 | + { |
---|
| 4160 | + assert(!trimmed); |
---|
| 4161 | + |
---|
| 4162 | + boolean smooth = Grafreed.smoothmode; |
---|
| 4163 | + boolean link = Grafreed.linkUV; |
---|
| 4164 | + Grafreed.smoothmode = true; |
---|
| 4165 | + Grafreed.linkUV = true; |
---|
| 4166 | + |
---|
| 4167 | + System.out.println("#Vertex = " + VertexCount()); |
---|
| 4168 | + System.out.println("#Face = " + FaceCount()); |
---|
| 4169 | + |
---|
| 4170 | + java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>(); |
---|
| 4171 | + |
---|
| 4172 | + for (int i = 0; i < VertexCount(); i++) |
---|
| 4173 | + { |
---|
| 4174 | + Vertex v = GetVertex(i); |
---|
| 4175 | + |
---|
| 4176 | + if (!table.contains(v)) |
---|
| 4177 | + { |
---|
| 4178 | + table.add(v); |
---|
| 4179 | + } |
---|
| 4180 | + } |
---|
| 4181 | + |
---|
| 4182 | + Grafreed.smoothmode = smooth; |
---|
| 4183 | + Grafreed.linkUV = link; |
---|
| 4184 | + |
---|
| 4185 | +// for (int i = 0; i < VertexCount(); i++) |
---|
| 4186 | +// { |
---|
| 4187 | +// Vertex v = GetVertex(i); |
---|
| 4188 | +// |
---|
| 4189 | +// table.add(v); |
---|
| 4190 | +// } |
---|
| 4191 | + |
---|
| 4192 | + } |
---|
| 4193 | + |
---|
3789 | 4194 | static cVector temp1 = new cVector(); |
---|
3790 | 4195 | static cVector temp2 = new cVector(); |
---|
3791 | 4196 | static cVector temp3 = new cVector(); |
---|
3792 | 4197 | |
---|
3793 | | - void GenerateNormal(int index, Vertex v) |
---|
| 4198 | + boolean GenerateNormal(int index, Vertex v) |
---|
3794 | 4199 | { |
---|
3795 | 4200 | //System.out.println("Old normal = " + v.norm); |
---|
3796 | 4201 | LA.setVector(v.norm, 0, 0, 0); |
---|
.. | .. |
---|
3819 | 4224 | LA.vecSub(p/*.pos*/, v/*.pos*/, temp1); |
---|
3820 | 4225 | LA.vecSub(q/*.pos*/, v/*.pos*/, temp2); |
---|
3821 | 4226 | } |
---|
| 4227 | + else |
---|
| 4228 | + { |
---|
| 4229 | + continue; |
---|
| 4230 | + } |
---|
3822 | 4231 | |
---|
3823 | 4232 | //LA.vecNormalize(temp1); |
---|
3824 | 4233 | //LA.vecNormalize(temp2); |
---|
.. | .. |
---|
3829 | 4238 | double s = temp3.length(); |
---|
3830 | 4239 | //double c = temp2.dot(temp1); |
---|
3831 | 4240 | |
---|
| 4241 | + if (s == 0) |
---|
| 4242 | + return false; |
---|
| 4243 | + |
---|
3832 | 4244 | float angle = 1; // (float) Math.atan2(s, c); |
---|
3833 | 4245 | //if(angle < 0) angle = -angle; |
---|
3834 | 4246 | |
---|
3835 | 4247 | //LA.vecNormalize(temp3); |
---|
3836 | 4248 | LA.vecScale(temp3, angle / s); |
---|
3837 | 4249 | |
---|
| 4250 | +// if (temp3.dot(v.norm) < 0) |
---|
| 4251 | +// assert(temp3.dot(v.norm) >= 0); |
---|
| 4252 | + |
---|
3838 | 4253 | LA.vecAdd(temp3, v.norm, v.norm); |
---|
3839 | 4254 | } |
---|
3840 | 4255 | |
---|
3841 | 4256 | LA.vecNormalize(v.norm); |
---|
3842 | 4257 | //System.out.println("New normal = " + v.norm); |
---|
| 4258 | + |
---|
| 4259 | + return true; |
---|
3843 | 4260 | } |
---|
3844 | 4261 | |
---|
3845 | 4262 | double Arccos(double x) |
---|
.. | .. |
---|
4381 | 4798 | } |
---|
4382 | 4799 | } |
---|
4383 | 4800 | |
---|
4384 | | - void CullVertex(javax.media.opengl.GL gl, boolean shadow) |
---|
| 4801 | + void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED) |
---|
4385 | 4802 | { |
---|
4386 | 4803 | CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z, |
---|
4387 | 4804 | CameraPane.tempmat,0, CameraPane.tempmat2,0, |
---|
.. | .. |
---|
4413 | 4830 | // june 2014 |
---|
4414 | 4831 | // Camera parentcam = cam; |
---|
4415 | 4832 | // |
---|
4416 | | -// if (cam == CameraPane.theRenderer.cameras[0]) |
---|
| 4833 | +// if (cam == Globals.theRenderer.cameras[0]) |
---|
4417 | 4834 | // { |
---|
4418 | | -// parentcam = CameraPane.theRenderer.cameras[1]; |
---|
| 4835 | +// parentcam = Globals.theRenderer.cameras[1]; |
---|
4419 | 4836 | // } |
---|
4420 | 4837 | // |
---|
4421 | | -// if (cam == CameraPane.theRenderer.cameras[1]) |
---|
| 4838 | +// if (cam == Globals.theRenderer.cameras[1]) |
---|
4422 | 4839 | // { |
---|
4423 | | -// parentcam = CameraPane.theRenderer.cameras[0]; |
---|
| 4840 | +// parentcam = Globals.theRenderer.cameras[0]; |
---|
4424 | 4841 | // } |
---|
4425 | 4842 | |
---|
4426 | 4843 | gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0); |
---|
.. | .. |
---|
4546 | 4963 | { |
---|
4547 | 4964 | i3 = positions.length-3; |
---|
4548 | 4965 | i2 = uvmap.length - 2; |
---|
4549 | | - new Exception().printStackTrace(); |
---|
| 4966 | + //new Exception().printStackTrace(); |
---|
4550 | 4967 | } |
---|
4551 | 4968 | |
---|
4552 | 4969 | v./*pos.*/x = positions[i3]; |
---|
4553 | 4970 | v./*pos.*/y = positions[i3 + 1]; |
---|
4554 | 4971 | v./*pos.*/z = positions[i3 + 2]; |
---|
4555 | 4972 | |
---|
4556 | | - v.norm.x = normals[i3]; |
---|
4557 | | - v.norm.y = normals[i3 + 1]; |
---|
4558 | | - v.norm.z = normals[i3 + 2]; |
---|
| 4973 | + if (normals == null) |
---|
| 4974 | + { |
---|
| 4975 | + v.norm.x = 0; |
---|
| 4976 | + v.norm.y = 0; |
---|
| 4977 | + v.norm.z = 0; |
---|
| 4978 | + } |
---|
| 4979 | + else |
---|
| 4980 | + { |
---|
| 4981 | + v.norm.x = normals[i3]; |
---|
| 4982 | + v.norm.y = normals[i3 + 1]; |
---|
| 4983 | + v.norm.z = normals[i3 + 2]; |
---|
| 4984 | + } |
---|
4559 | 4985 | |
---|
4560 | 4986 | v.s = uvmap[i2]; |
---|
4561 | 4987 | v.t = uvmap[i2 + 1]; |
---|
.. | .. |
---|
4846 | 5272 | return verticesCopy; |
---|
4847 | 5273 | } |
---|
4848 | 5274 | |
---|
4849 | | - void PreprocessOcclusion(CameraPane cp, double[][] transform) |
---|
| 5275 | + void PreprocessOcclusion(iCameraPane cp, double[][] transform) |
---|
4850 | 5276 | { |
---|
4851 | 5277 | if (//!trimmed || |
---|
4852 | 5278 | AOdone) |
---|
.. | .. |
---|
4855 | 5281 | return; |
---|
4856 | 5282 | } |
---|
4857 | 5283 | |
---|
4858 | | - Camera keep = cp.renderCamera; |
---|
4859 | | - cp.renderCamera = localcamera; |
---|
4860 | | - |
---|
4861 | | - if (trimmed) |
---|
4862 | | - { |
---|
4863 | | - float[] colors = new float[positions.length / 3]; |
---|
4864 | | - |
---|
4865 | | - int i3 = 0; |
---|
4866 | | - for (int i = 0; i < positions.length / 3; i++, i3 += 3) |
---|
4867 | | - { |
---|
4868 | | - if (normals[i3] == 0 && normals[i3+1] == 0 && normals[i3+2] == 0) |
---|
4869 | | - continue; |
---|
4870 | | - |
---|
4871 | | - from.set(positions[i3], positions[i3 + 1], positions[i3 + 2]); |
---|
4872 | | - to.set(positions[i3] + normals[i3], |
---|
4873 | | - positions[i3 + 1] + normals[i3 + 1], |
---|
4874 | | - positions[i3 + 2] + normals[i3 + 2]); |
---|
4875 | | - LA.xformPos(from, transform, from); |
---|
4876 | | - LA.xformPos(to, transform, to); // RIGID ONLY |
---|
4877 | | - localcamera.setAim(from, to); |
---|
4878 | | - |
---|
4879 | | - CameraPane.occlusionbuffer.display(); |
---|
4880 | | - |
---|
4881 | | - if (CameraPane.DEBUG_OCCLUSION) |
---|
4882 | | - cp.display(); // debug |
---|
4883 | | - |
---|
4884 | | - colors[i] = cp.vertexOcclusion.r; |
---|
4885 | | - //colors[i3 + 1] = cp.vertexOcclusion.g; |
---|
4886 | | - //colors[i3 + 2] = cp.vertexOcclusion.b; |
---|
4887 | | - |
---|
4888 | | - if ((i % 1000) == 0 && i != 0) |
---|
4889 | | - { |
---|
4890 | | - CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
4891 | | - //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done"); |
---|
4892 | | - System.out.println((int) (100.0 * i / (positions.length / 3)) + "% (" + i + " of " + (positions.length / 3) + ")"); |
---|
4893 | | - } |
---|
4894 | | - } |
---|
4895 | | - |
---|
4896 | | - this.colors = colors; |
---|
4897 | | - } |
---|
4898 | | - else |
---|
4899 | | - { |
---|
4900 | | - for (int i = 0; i < VertexCount(); i++) |
---|
4901 | | - { |
---|
4902 | | - Vertex v = GetVertex(i); |
---|
4903 | | - |
---|
4904 | | - if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0) |
---|
4905 | | - continue; |
---|
4906 | | - |
---|
4907 | | - from.set(v.x, v.y, v.z); |
---|
4908 | | - to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z); |
---|
4909 | | - LA.xformPos(from, transform, from); |
---|
4910 | | - LA.xformPos(to, transform, to); // RIGID ONLY |
---|
4911 | | - localcamera.setAim(from, to); |
---|
4912 | | - |
---|
4913 | | - CameraPane.occlusionbuffer.display(); |
---|
4914 | | - |
---|
4915 | | - if (CameraPane.DEBUG_OCCLUSION) |
---|
4916 | | - cp.display(); // debug |
---|
4917 | | - |
---|
4918 | | - v.AO = cp.vertexOcclusion.r; |
---|
4919 | | - |
---|
4920 | | - if ((i % 1000) == 0 && i != 0) |
---|
4921 | | - { |
---|
4922 | | - CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
4923 | | - //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done"); |
---|
4924 | | - System.out.println((int) (100.0 * i / VertexCount()) + "% (" + i + " of " + VertexCount() + ")"); |
---|
4925 | | - } |
---|
4926 | | - } |
---|
4927 | | - } |
---|
4928 | | - |
---|
4929 | | - System.out.println("done."); |
---|
4930 | | - |
---|
4931 | | - cp.renderCamera = keep; |
---|
| 5284 | + cp.PrepOcclusion(this, transform); |
---|
4932 | 5285 | |
---|
4933 | 5286 | AOdone = true; |
---|
4934 | 5287 | } |
---|
.. | .. |
---|
5343 | 5696 | |
---|
5344 | 5697 | transient int nbbadfaces; // ?? = 1000000; |
---|
5345 | 5698 | |
---|
5346 | | - int ChooseTriangle() |
---|
| 5699 | + /* |
---|
| 5700 | + */ |
---|
| 5701 | + int ChooseTriangle(boolean firstEquilateral) |
---|
5347 | 5702 | { |
---|
5348 | 5703 | int chosen = -1; |
---|
5349 | 5704 | |
---|
5350 | 5705 | double minweight = 1E10; |
---|
5351 | 5706 | |
---|
| 5707 | + int step = 8; // ? |
---|
| 5708 | + |
---|
| 5709 | + if (firstEquilateral) |
---|
| 5710 | + step = 1; |
---|
| 5711 | + |
---|
5352 | 5712 | nbbadfaces = 0; |
---|
5353 | | - for (int i=0; i<faces.size(); i+=8) |
---|
| 5713 | + for (int i=0; i<faces.size(); i+=step) |
---|
5354 | 5714 | // for (int i=faces.size(); (i-=8)>=0;) |
---|
5355 | 5715 | { |
---|
5356 | 5716 | Face face = (Face) faces.get(i); |
---|
| 5717 | + |
---|
| 5718 | + if (face.used) |
---|
| 5719 | + continue; |
---|
5357 | 5720 | |
---|
5358 | 5721 | if (!Valid(face)) |
---|
5359 | 5722 | { |
---|
.. | .. |
---|
5363 | 5726 | |
---|
5364 | 5727 | if (Boundary(face)) |
---|
5365 | 5728 | continue; |
---|
| 5729 | + |
---|
| 5730 | +// if (Boundary(face.p)) |
---|
| 5731 | +// continue; |
---|
| 5732 | +// |
---|
| 5733 | +// if (Boundary(face.q)) |
---|
| 5734 | +// continue; |
---|
| 5735 | +// |
---|
| 5736 | +// if (Boundary(face.r)) |
---|
| 5737 | +// continue; |
---|
5366 | 5738 | |
---|
5367 | 5739 | if (!ValidValence(face)) |
---|
5368 | 5740 | continue; |
---|
.. | .. |
---|
5375 | 5747 | //?? if (face.weight < 0) |
---|
5376 | 5748 | // continue; |
---|
5377 | 5749 | |
---|
5378 | | - double K = 1; // 0.01; // .25; |
---|
5379 | | - |
---|
5380 | | - double factor = (1-K)*face.nbiterations + K; //*face.weight; |
---|
5381 | | - |
---|
5382 | | - double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor; |
---|
5383 | | - |
---|
5384 | | - if (minweight > weight) |
---|
| 5750 | + if (firstEquilateral) |
---|
5385 | 5751 | { |
---|
5386 | | - minweight = weight; |
---|
| 5752 | + if (OneFaceUsed(links.get(face.p))) |
---|
| 5753 | + continue; |
---|
| 5754 | + |
---|
| 5755 | + if (OneFaceUsed(links.get(face.q))) |
---|
| 5756 | + continue; |
---|
| 5757 | + |
---|
| 5758 | + if (OneFaceUsed(links.get(face.r))) |
---|
| 5759 | + continue; |
---|
| 5760 | + |
---|
5387 | 5761 | chosen = i; |
---|
5388 | | - if (minweight == 0) |
---|
5389 | | - break; |
---|
| 5762 | + break; |
---|
| 5763 | + } |
---|
| 5764 | + else |
---|
| 5765 | + { |
---|
| 5766 | + double K = 1; // 0.01; // .25; |
---|
| 5767 | + |
---|
| 5768 | + double factor = (1-K)*face.nbiterations + K; //*face.weight; |
---|
| 5769 | + |
---|
| 5770 | + double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor; |
---|
| 5771 | + |
---|
| 5772 | + if (minweight > weight) |
---|
| 5773 | + { |
---|
| 5774 | + minweight = weight; |
---|
| 5775 | + chosen = i; |
---|
| 5776 | + if (minweight == 0) |
---|
| 5777 | + break; |
---|
| 5778 | + } |
---|
5390 | 5779 | } |
---|
5391 | 5780 | } |
---|
5392 | 5781 | |
---|
5393 | 5782 | return chosen; |
---|
| 5783 | + } |
---|
| 5784 | + |
---|
| 5785 | + private boolean OneFaceUsed(Vector<Face> faces) |
---|
| 5786 | + { |
---|
| 5787 | + if (faces.size() != 6) |
---|
| 5788 | + return true; |
---|
| 5789 | + |
---|
| 5790 | + for (int i=0; i<6; i+=1) |
---|
| 5791 | + { |
---|
| 5792 | + if (faces.get(i).used) |
---|
| 5793 | + { |
---|
| 5794 | + return true; |
---|
| 5795 | + } |
---|
| 5796 | + } |
---|
| 5797 | + |
---|
| 5798 | + return false; |
---|
5394 | 5799 | } |
---|
5395 | 5800 | |
---|
5396 | 5801 | static boolean remove3valence = true; |
---|
.. | .. |
---|
5426 | 5831 | } |
---|
5427 | 5832 | else |
---|
5428 | 5833 | { |
---|
5429 | | - assert(links.size() == vertices.size()); |
---|
| 5834 | + // TODO Grafreed.Assert(links.size() == vertices.size()); |
---|
5430 | 5835 | |
---|
5431 | 5836 | links.setSize(vertices.size()); |
---|
5432 | 5837 | for (int i=vertices.size(); --i>=0;) |
---|
.. | .. |
---|
5434 | 5839 | // linkstouched[i] = false; |
---|
5435 | 5840 | if (links.get(i) == null) // ?? |
---|
5436 | 5841 | { |
---|
| 5842 | + new Exception().printStackTrace(); |
---|
5437 | 5843 | links.set(i, new Vector(8)); |
---|
5438 | 5844 | // linkstouched[i] = true; |
---|
5439 | 5845 | } |
---|
.. | .. |
---|
5444 | 5850 | } |
---|
5445 | 5851 | } |
---|
5446 | 5852 | |
---|
| 5853 | + boolean once = false; |
---|
| 5854 | + |
---|
5447 | 5855 | for (int i=faces.size(); --i>=0;) |
---|
5448 | 5856 | { |
---|
5449 | 5857 | Face face = (Face) faces.get(i); |
---|
.. | .. |
---|
5455 | 5863 | //if (linkstouched[face.r]) |
---|
5456 | 5864 | links.get(face.r).add(face); |
---|
5457 | 5865 | |
---|
| 5866 | + if (face.used) |
---|
| 5867 | + once = true; |
---|
| 5868 | + |
---|
5458 | 5869 | face.good = 1; |
---|
5459 | 5870 | face.boundary = -1; |
---|
5460 | 5871 | } |
---|
.. | .. |
---|
6226 | 6637 | |
---|
6227 | 6638 | void InitWeights() |
---|
6228 | 6639 | { |
---|
| 6640 | + new Exception().printStackTrace(); |
---|
6229 | 6641 | System.exit(0); |
---|
6230 | 6642 | int n = 0; |
---|
6231 | 6643 | int b = 0; |
---|
.. | .. |
---|
6819 | 7231 | return (face.boundary = 1) == 1; |
---|
6820 | 7232 | } |
---|
6821 | 7233 | |
---|
| 7234 | + // June 2019 |
---|
| 7235 | + if (true) |
---|
| 7236 | + return (face.boundary = 0) == 1; |
---|
| 7237 | + |
---|
6822 | 7238 | // reverse triangle test |
---|
6823 | 7239 | q1.set(p); |
---|
6824 | 7240 | q2.set(q); |
---|
.. | .. |
---|
7075 | 7491 | assert(f2.contains(i)); |
---|
7076 | 7492 | assert(f3.contains(i)); |
---|
7077 | 7493 | |
---|
| 7494 | + // when r is the "center", p is along the boundary |
---|
7078 | 7495 | while (f0.r != i) |
---|
7079 | 7496 | { |
---|
7080 | 7497 | int t = f0.p; |
---|
.. | .. |
---|
7131 | 7548 | f0 = f3; |
---|
7132 | 7549 | f3 = t; |
---|
7133 | 7550 | } |
---|
7134 | | - atleastone = true; |
---|
7135 | 7551 | |
---|
| 7552 | + int va = f0.q; |
---|
| 7553 | + int vb = f0.r; |
---|
| 7554 | + int vc = -1; |
---|
| 7555 | + |
---|
| 7556 | + Face toremove1 = null; |
---|
| 7557 | + Face toremove2 = null; |
---|
| 7558 | + |
---|
| 7559 | + // f0 is the buffer for the first new triangle, |
---|
| 7560 | + // and otherf is the other upper one. |
---|
7136 | 7561 | Face otherf = null; |
---|
7137 | 7562 | |
---|
7138 | 7563 | if (f1.contains(f0.p)) |
---|
7139 | 7564 | { |
---|
7140 | 7565 | if (f1.p == f0.p) |
---|
7141 | 7566 | { |
---|
| 7567 | + assert(false); |
---|
7142 | 7568 | f0.r = f1.q; |
---|
7143 | 7569 | } |
---|
7144 | 7570 | else |
---|
7145 | 7571 | { |
---|
7146 | 7572 | assert(f1.q == f0.p); |
---|
7147 | | - f0.r = f1.p; |
---|
| 7573 | + vc = f1.p; |
---|
7148 | 7574 | } |
---|
7149 | 7575 | |
---|
7150 | 7576 | otherf = f2; |
---|
7151 | | - faces.remove(f1); |
---|
7152 | | - faces.remove(f3); |
---|
| 7577 | + toremove1 = f1; |
---|
| 7578 | + toremove2 = f3; |
---|
7153 | 7579 | } |
---|
7154 | 7580 | else |
---|
7155 | 7581 | if (f2.contains(f0.p)) |
---|
7156 | 7582 | { |
---|
7157 | 7583 | if (f2.p == f0.p) |
---|
7158 | 7584 | { |
---|
| 7585 | + assert(false); |
---|
7159 | 7586 | f0.r = f2.q; |
---|
7160 | 7587 | } |
---|
7161 | 7588 | else |
---|
7162 | 7589 | { |
---|
7163 | 7590 | assert(f2.q == f0.p); |
---|
7164 | | - f0.r = f2.p; |
---|
| 7591 | + vc = f2.p; |
---|
7165 | 7592 | } |
---|
7166 | 7593 | |
---|
7167 | 7594 | otherf = f3; |
---|
7168 | | - faces.remove(f1); |
---|
7169 | | - faces.remove(f2); |
---|
| 7595 | + toremove1 = f1; |
---|
| 7596 | + toremove2 = f2; |
---|
7170 | 7597 | } |
---|
7171 | 7598 | if (f3.contains(f0.p)) |
---|
7172 | 7599 | { |
---|
7173 | 7600 | if (f3.p == f0.p) |
---|
7174 | 7601 | { |
---|
| 7602 | +// assert(false); |
---|
| 7603 | + new Exception().printStackTrace(); |
---|
7175 | 7604 | f0.r = f3.q; |
---|
7176 | 7605 | } |
---|
7177 | 7606 | else |
---|
7178 | 7607 | { |
---|
7179 | 7608 | assert(f3.q == f0.p); |
---|
7180 | | - f0.r = f3.p; |
---|
| 7609 | + vc = f3.p; |
---|
7181 | 7610 | } |
---|
7182 | 7611 | |
---|
7183 | 7612 | otherf = f1; |
---|
7184 | | - faces.remove(f2); |
---|
7185 | | - faces.remove(f3); |
---|
| 7613 | + toremove1 = f2; |
---|
| 7614 | + toremove2 = f3; |
---|
7186 | 7615 | } |
---|
| 7616 | + |
---|
| 7617 | + vertextemp.set(vertices.get(va)); |
---|
| 7618 | + vertextemp.sub(vertices.get(vb)); |
---|
| 7619 | + vertextemp.normalize(); |
---|
| 7620 | + vertextemp2.set(vertices.get(vc)); |
---|
| 7621 | + vertextemp2.sub(vertices.get(vb)); |
---|
| 7622 | + vertextemp2.normalize(); |
---|
| 7623 | + |
---|
| 7624 | + if (vertextemp.dot(vertextemp2) > -0.95) |
---|
| 7625 | + { |
---|
| 7626 | + continue; |
---|
| 7627 | + } |
---|
| 7628 | + |
---|
| 7629 | + atleastone = true; |
---|
| 7630 | + |
---|
| 7631 | + f0.r = vc; |
---|
| 7632 | + |
---|
| 7633 | + faces.remove(toremove1); |
---|
| 7634 | + faces.remove(toremove2); |
---|
7187 | 7635 | |
---|
7188 | 7636 | if (!f0.contains(otherf.p)) |
---|
7189 | 7637 | { |
---|
.. | .. |
---|
7236 | 7684 | //InitWeights(); |
---|
7237 | 7685 | } |
---|
7238 | 7686 | |
---|
7239 | | - int chosen = ChooseTriangle(); // Best is slow and not really better |
---|
| 7687 | + int chosen = ChooseTriangle(true); // Best is slow and not really better |
---|
7240 | 7688 | |
---|
7241 | 7689 | if (chosen == -1) |
---|
7242 | 7690 | { |
---|
.. | .. |
---|
7250 | 7698 | //remove3valence = false; |
---|
7251 | 7699 | // InitWeights(); |
---|
7252 | 7700 | |
---|
7253 | | - chosen = ChooseTriangle(); |
---|
| 7701 | + chosen = ChooseTriangle(true); |
---|
7254 | 7702 | } |
---|
7255 | 7703 | } |
---|
7256 | 7704 | |
---|
.. | .. |
---|
7526 | 7974 | |
---|
7527 | 7975 | // boolean lock; |
---|
7528 | 7976 | |
---|
7529 | | - void SplitInTwo(boolean reduction34, boolean onlyone) |
---|
| 7977 | + boolean SplitInTwo(boolean reduction34, boolean onlyone) |
---|
7530 | 7978 | { |
---|
7531 | 7979 | if (stripified) |
---|
7532 | 7980 | { |
---|
.. | .. |
---|
7554 | 8002 | s3 = new cVector(); |
---|
7555 | 8003 | } |
---|
7556 | 8004 | |
---|
7557 | | - CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
| 8005 | + Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
7558 | 8006 | |
---|
7559 | 8007 | try |
---|
7560 | 8008 | { |
---|
.. | .. |
---|
7563 | 8011 | { |
---|
7564 | 8012 | System.err.println("EXCEPTION CAUGHT"); |
---|
7565 | 8013 | e.printStackTrace(); |
---|
7566 | | - return; |
---|
| 8014 | + return false; |
---|
7567 | 8015 | } catch (Error e) |
---|
7568 | 8016 | { |
---|
7569 | 8017 | System.err.println("ERROR CAUGHT"); |
---|
7570 | 8018 | e.printStackTrace(); |
---|
7571 | | - return; |
---|
| 8019 | + return false; |
---|
7572 | 8020 | } |
---|
7573 | 8021 | |
---|
7574 | 8022 | System.out.println("# faces = " + faces.size()); |
---|
.. | .. |
---|
7578 | 8026 | { |
---|
7579 | 8027 | Face face = (Face) faces.get(i); |
---|
7580 | 8028 | |
---|
| 8029 | + face.used = false; |
---|
7581 | 8030 | face.nbiterations = 1; |
---|
7582 | 8031 | face.weight = -1; |
---|
7583 | 8032 | face.boundary = -1; |
---|
.. | .. |
---|
7629 | 8078 | nbbadfaces = faces.size(); |
---|
7630 | 8079 | //remove3valence = true; |
---|
7631 | 8080 | |
---|
| 8081 | + int count = 2; |
---|
| 8082 | + |
---|
| 8083 | + if (onlyone) |
---|
| 8084 | + count = 1; |
---|
| 8085 | + |
---|
7632 | 8086 | firstpass = true; |
---|
7633 | 8087 | |
---|
7634 | 8088 | int n = faces.size(); |
---|
.. | .. |
---|
7644 | 8098 | System.out.print('.'); |
---|
7645 | 8099 | } |
---|
7646 | 8100 | System.out.println(); |
---|
| 8101 | + boolean atleastone = false; |
---|
7647 | 8102 | int i = 0; |
---|
7648 | | - while (reduction34 || faces.size() > n/2) |
---|
| 8103 | + while (true) // reduction34 || faces.size() > n/2) |
---|
7649 | 8104 | { |
---|
7650 | 8105 | if (i++%100 == 0) |
---|
7651 | 8106 | { |
---|
7652 | | - CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
| 8107 | + Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
7653 | 8108 | System.out.println("#faces = " + faces.size()); |
---|
7654 | 8109 | // if (i != 1) |
---|
7655 | 8110 | // break; |
---|
.. | .. |
---|
7667 | 8122 | { |
---|
7668 | 8123 | if (!RemoveOneTriangle()) |
---|
7669 | 8124 | break; |
---|
| 8125 | + |
---|
| 8126 | + atleastone = true; |
---|
7670 | 8127 | } |
---|
7671 | 8128 | // if (iterationcount == 0) |
---|
7672 | 8129 | // break; |
---|
.. | .. |
---|
7677 | 8134 | break; |
---|
7678 | 8135 | } |
---|
7679 | 8136 | firstpass = false; |
---|
7680 | | - if (onlyone) |
---|
7681 | | - break; // one triangle only |
---|
| 8137 | +// if (--count<0 && !reduction34) |
---|
| 8138 | +// break; // one triangle only |
---|
7682 | 8139 | } |
---|
7683 | 8140 | |
---|
7684 | 8141 | InitLinks(false); // for further display |
---|
.. | .. |
---|
7693 | 8150 | //Trim(true,cJME.gennormals,true,false); // doesn't work |
---|
7694 | 8151 | Trim(true,false,false,false,false); |
---|
7695 | 8152 | |
---|
7696 | | - CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); |
---|
| 8153 | + Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); |
---|
| 8154 | + |
---|
| 8155 | + return atleastone; |
---|
7697 | 8156 | } |
---|
7698 | 8157 | |
---|
7699 | 8158 | void UpdateIndices(Face face, Face minface) |
---|
.. | .. |
---|
7706 | 8165 | face.p = minface.p; |
---|
7707 | 8166 | //if (leafweights) |
---|
7708 | 8167 | face.good = 0; // false; |
---|
| 8168 | + face.used = true; |
---|
7709 | 8169 | } |
---|
7710 | 8170 | if (face.q == minface.p || face.q == minface.q || face.q == minface.r) |
---|
7711 | 8171 | { |
---|
7712 | 8172 | face.q = minface.p; |
---|
7713 | 8173 | //if (leafweights) |
---|
7714 | 8174 | face.good = 0; // false; |
---|
| 8175 | + face.used = true; |
---|
7715 | 8176 | } |
---|
7716 | 8177 | if (face.r == minface.p || face.r == minface.q || face.r == minface.r) |
---|
7717 | 8178 | { |
---|
7718 | 8179 | face.r = minface.p; |
---|
7719 | 8180 | //if (leafweights) |
---|
7720 | 8181 | face.good = 0; // false; |
---|
| 8182 | + face.used = true; |
---|
7721 | 8183 | } |
---|
7722 | 8184 | |
---|
7723 | 8185 | if (face.p >/*=*/ minface.q && face.p < minface.r) |
---|
.. | .. |
---|
7777 | 8239 | if (v == 2) |
---|
7778 | 8240 | vert = minface.r; |
---|
7779 | 8241 | // Face face = (Face) faces.get(i); |
---|
7780 | | - Vector<Face> vertfaces = links.get(vert); |
---|
7781 | | - for (int i=vertfaces.size(); --i>=0;) |
---|
7782 | | - { |
---|
7783 | | - Face face = (Face) vertfaces.get(i); |
---|
7784 | | - |
---|
7785 | | - // if (face.weight == 10000) |
---|
7786 | | - // continue; |
---|
7787 | | - |
---|
7788 | | - if (face.p == minface.p || face.q == minface.p || face.r == minface.p || |
---|
7789 | | - face.p == minface.q || face.q == minface.q || face.r == minface.q || |
---|
7790 | | - face.p == minface.r || face.q == minface.r || face.r == minface.r) |
---|
| 8242 | + Vector<Face> vertfaces = links.get(vert); |
---|
| 8243 | + for (int i=vertfaces.size(); --i>=0;) |
---|
7791 | 8244 | { |
---|
7792 | | - if (!leafweights) |
---|
| 8245 | + Face face = (Face) vertfaces.get(i); |
---|
| 8246 | + |
---|
| 8247 | + // if (face.weight == 10000) |
---|
| 8248 | + // continue; |
---|
| 8249 | + |
---|
| 8250 | + if (face.p == minface.p || face.q == minface.p || face.r == minface.p || |
---|
| 8251 | + face.p == minface.q || face.q == minface.q || face.r == minface.q || |
---|
| 8252 | + face.p == minface.r || face.q == minface.r || face.r == minface.r) |
---|
7793 | 8253 | { |
---|
7794 | | -// if(minfaceweight <= 0) |
---|
7795 | | -// assert(minfaceweight > 0); |
---|
7796 | | -// |
---|
7797 | | -// //FaceWeight(face); |
---|
7798 | | -// if(face.weight < 0) |
---|
7799 | | -// assert(face.weight >= 0); |
---|
7800 | | - |
---|
7801 | | - face.weight += minfaceweight; |
---|
7802 | | - |
---|
7803 | | -// if (face.weight >= 10000) |
---|
7804 | | -// assert(face.weight < 10000); |
---|
| 8254 | + if (!leafweights) |
---|
| 8255 | + { |
---|
| 8256 | + // if(minfaceweight <= 0) |
---|
| 8257 | + // assert(minfaceweight > 0); |
---|
| 8258 | + // |
---|
| 8259 | + // //FaceWeight(face); |
---|
| 8260 | + // if(face.weight < 0) |
---|
| 8261 | + // assert(face.weight >= 0); |
---|
| 8262 | + |
---|
| 8263 | + face.weight += minfaceweight; |
---|
| 8264 | + |
---|
| 8265 | + // if (face.weight >= 10000) |
---|
| 8266 | + // assert(face.weight < 10000); |
---|
| 8267 | + } |
---|
| 8268 | + else |
---|
| 8269 | + face.weight = -1; |
---|
| 8270 | + |
---|
| 8271 | + face.nbiterations += 1; |
---|
| 8272 | + face.boundary = -1; |
---|
| 8273 | + |
---|
| 8274 | + Vertex p = (Vertex)vertices.get(face.p); |
---|
| 8275 | + Vertex q = (Vertex)vertices.get(face.q); |
---|
| 8276 | + Vertex r = (Vertex)vertices.get(face.r); |
---|
| 8277 | + |
---|
| 8278 | + p.boundary = -1; |
---|
| 8279 | + q.boundary = -1; |
---|
| 8280 | + r.boundary = -1; |
---|
7805 | 8281 | } |
---|
7806 | 8282 | else |
---|
7807 | | - face.weight = -1; |
---|
7808 | | - |
---|
7809 | | - face.nbiterations += 1; |
---|
7810 | | - face.boundary = -1; |
---|
7811 | | - |
---|
7812 | | - Vertex p = (Vertex)vertices.get(face.p); |
---|
7813 | | - Vertex q = (Vertex)vertices.get(face.q); |
---|
7814 | | - Vertex r = (Vertex)vertices.get(face.r); |
---|
7815 | | - |
---|
7816 | | - p.boundary = -1; |
---|
7817 | | - q.boundary = -1; |
---|
7818 | | - r.boundary = -1; |
---|
| 8283 | + assert(false); |
---|
7819 | 8284 | } |
---|
7820 | | - else |
---|
7821 | | - assert(false); |
---|
7822 | 8285 | } |
---|
7823 | | - } |
---|
7824 | 8286 | |
---|
7825 | 8287 | // TouchVertex(minface.p); |
---|
7826 | 8288 | // TouchVertex(minface.q); |
---|
.. | .. |
---|
8021 | 8483 | for (int i=vertfaces.size(); --i>=0;) |
---|
8022 | 8484 | { |
---|
8023 | 8485 | Face face = (Face) vertfaces.get(i); |
---|
| 8486 | + face.used = true; |
---|
8024 | 8487 | face.good = 0; // false; |
---|
8025 | 8488 | if (leafweights) |
---|
8026 | 8489 | face.weight = -1; |
---|
.. | .. |
---|
8067 | 8530 | if (!trimmed) |
---|
8068 | 8531 | return; |
---|
8069 | 8532 | |
---|
8070 | | - GrafreeD.linkUV = false; |
---|
| 8533 | + Grafreed.linkUV = false; |
---|
8071 | 8534 | |
---|
8072 | 8535 | try |
---|
8073 | 8536 | { |
---|
.. | .. |
---|
8275 | 8738 | return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices; |
---|
8276 | 8739 | } |
---|
8277 | 8740 | |
---|
8278 | | - static Camera localcamera = new Camera(); |
---|
8279 | | - static cVector from = new cVector(); |
---|
8280 | | - static cVector to = new cVector(); |
---|
8281 | 8741 | boolean trimmed = false; |
---|
8282 | 8742 | boolean stripified = false; |
---|
8283 | 8743 | transient boolean AOdone = false; |
---|
.. | .. |
---|
8285 | 8745 | /*transient*/ int maxIndexV = 0; |
---|
8286 | 8746 | /*transient*/ int bufV, bufF; |
---|
8287 | 8747 | // Raw version |
---|
8288 | | - private float[] positions; |
---|
8289 | | - private float[] normals; |
---|
| 8748 | + //private |
---|
| 8749 | + float[] positions; |
---|
| 8750 | + //private |
---|
| 8751 | + float[] normals; |
---|
8290 | 8752 | float[] colors; |
---|
8291 | 8753 | private float[] uvmap; |
---|
8292 | 8754 | private int[] triangles; |
---|
.. | .. |
---|
8300 | 8762 | int[] startvertices; |
---|
8301 | 8763 | float[] averagepoints; |
---|
8302 | 8764 | float[] extremepoints; |
---|
8303 | | - float[] supportsizes; // distance of closest point |
---|
| 8765 | + float[] supportminsize; // distance of closest point |
---|
| 8766 | + float[] supportmaxsize; // distance of fartest point |
---|
8304 | 8767 | |
---|
8305 | 8768 | transient Hashtable vertextable; |
---|
8306 | 8769 | /*transient*/ private Vertex[] verticesCopy; |
---|