.. | .. |
---|
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[]) GraphreeD.clone(other.positions); |
---|
176 | | - normals = (float[]) GraphreeD.clone(other.normals); |
---|
177 | | - colors = (float[]) GraphreeD.clone(other.colors); |
---|
178 | | - uvmap = (float[]) GraphreeD.clone(other.uvmap); |
---|
179 | | - triangles = (int[]) GraphreeD.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[]) GraphreeD.clone(other.indices); |
---|
| 182 | + indices = (int[]) Grafreed.clone(other.indices); |
---|
182 | 183 | |
---|
183 | | - vertices = (Vector<Vertex>) GraphreeD.clone(other.vertices); |
---|
184 | | - faces = (Vector<Face>) GraphreeD.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) GraphreeD.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) GraphreeD.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 | + if (v.weights != null && v.weights[j] < 0.001 * v.totalweight) // == 0) |
---|
1944 | 2001 | { |
---|
1945 | 2002 | //testweight += v.weights[j-1]; |
---|
1946 | 2003 | continue; |
---|
.. | .. |
---|
2163 | 2220 | // if (slow) |
---|
2164 | 2221 | // aout 2013 |
---|
2165 | 2222 | // sept 2013 merde... |
---|
2166 | | - W = 13; |
---|
| 2223 | + W = 3; // 13; |
---|
2167 | 2224 | |
---|
2168 | 2225 | // POSERATE |
---|
2169 | 2226 | if (CameraPane.tickcount > 0 || CameraPane.SLOWPOSE) |
---|
.. | .. |
---|
2221 | 2278 | |
---|
2222 | 2279 | transient int lastsoundtime; |
---|
2223 | 2280 | |
---|
| 2281 | + transient boolean once = false; |
---|
| 2282 | + |
---|
2224 | 2283 | void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked) |
---|
2225 | 2284 | { |
---|
2226 | 2285 | if (LA.isIdentity(toRoot)) |
---|
.. | .. |
---|
2276 | 2335 | |
---|
2277 | 2336 | if (v.totalweight == 0) |
---|
2278 | 2337 | { |
---|
2279 | | - 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 | + } |
---|
2280 | 2343 | continue; |
---|
2281 | 2344 | } |
---|
2282 | 2345 | |
---|
.. | .. |
---|
2600 | 2663 | // if (stepout && !playedonce) |
---|
2601 | 2664 | // { |
---|
2602 | 2665 | // // sound |
---|
2603 | | -// GraphreeD.wav.play(); |
---|
| 2666 | +// GrafreeD.wav.play(); |
---|
2604 | 2667 | // playedonce = true; |
---|
2605 | 2668 | // } |
---|
2606 | 2669 | // |
---|
.. | .. |
---|
2635 | 2698 | if (false) // slow && stepout && onein) |
---|
2636 | 2699 | { |
---|
2637 | 2700 | // sound |
---|
2638 | | - cVector eye = CameraPane.theRenderer.eyeCamera.location; |
---|
| 2701 | + cVector eye = Globals.theRenderer.EyeCamera().location; |
---|
2639 | 2702 | |
---|
2640 | 2703 | Vertex v = GetVertex(0); |
---|
2641 | 2704 | |
---|
2642 | 2705 | tmp.set(v); |
---|
2643 | 2706 | tmp.sub(eye); |
---|
2644 | 2707 | |
---|
2645 | | - if (CameraPane.framecount - lastsoundtime > 30) // 0.25 secs |
---|
| 2708 | + if (Globals.framecount - lastsoundtime > 30) // 0.25 secs |
---|
2646 | 2709 | { |
---|
2647 | | - GraphreeD.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); |
---|
2648 | 2711 | |
---|
2649 | | - lastsoundtime = CameraPane.framecount; |
---|
| 2712 | + lastsoundtime = Globals.framecount; |
---|
2650 | 2713 | } |
---|
2651 | 2714 | |
---|
2652 | 2715 | stepout = false; |
---|
.. | .. |
---|
3072 | 3135 | // |
---|
3073 | 3136 | // transient VertexCompare[] vertexcompare = null; |
---|
3074 | 3137 | |
---|
| 3138 | + // Check if v0 is close enough from any vertex of the given subobject of this. |
---|
3075 | 3139 | boolean Contains(Vertex v0, int object) |
---|
3076 | 3140 | { |
---|
3077 | 3141 | int start = startvertices[object-1]; |
---|
.. | .. |
---|
3129 | 3193 | */ |
---|
3130 | 3194 | } |
---|
3131 | 3195 | |
---|
3132 | | - 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) |
---|
3133 | 3217 | { |
---|
3134 | 3218 | Trim(); |
---|
3135 | 3219 | |
---|
.. | .. |
---|
3193 | 3277 | y -= 0.5; |
---|
3194 | 3278 | z -= 0.5; |
---|
3195 | 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 | + |
---|
3196 | 3399 | // x *= 2; |
---|
3197 | 3400 | // y *= 2; |
---|
3198 | 3401 | // z *= 2; |
---|
.. | .. |
---|
3219 | 3422 | |
---|
3220 | 3423 | z = Math.cos(angle/2); |
---|
3221 | 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 | + |
---|
3222 | 3434 | // sqrt(k2*x2 + k2*z2 + y2) = length |
---|
3223 | 3435 | // k2*x2 + k2*z2 = length2 - y2 |
---|
3224 | 3436 | // k2 = (length2 - y2) / (x2 + z2) |
---|
.. | .. |
---|
3229 | 3441 | k /= x*x + y*y; |
---|
3230 | 3442 | } |
---|
3231 | 3443 | else |
---|
3232 | | - GraphreeD.Assert(z == 1); |
---|
| 3444 | + Grafreed.Assert(z == 1); |
---|
3233 | 3445 | |
---|
3234 | 3446 | if (k < 0) |
---|
3235 | 3447 | k = 0; |
---|
.. | .. |
---|
3238 | 3450 | |
---|
3239 | 3451 | x *= k; |
---|
3240 | 3452 | y *= k; |
---|
| 3453 | + /**/ |
---|
3241 | 3454 | |
---|
3242 | 3455 | double max = Math.abs(x); |
---|
3243 | 3456 | if (max < Math.abs(y)) |
---|
.. | .. |
---|
3250 | 3463 | } |
---|
3251 | 3464 | |
---|
3252 | 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); |
---|
3253 | 3470 | |
---|
3254 | 3471 | // if (!(max > 0)) |
---|
3255 | | - assert(max > 0); |
---|
3256 | | - |
---|
| 3472 | + //assert(max > 0); |
---|
| 3473 | + assert(max >= 0); |
---|
| 3474 | + |
---|
3257 | 3475 | x /= max; |
---|
3258 | 3476 | y /= max; |
---|
3259 | 3477 | z /= max; |
---|
.. | .. |
---|
3516 | 3734 | */ |
---|
3517 | 3735 | } |
---|
3518 | 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 | + |
---|
3519 | 3842 | void GenerateNormals(boolean crease) |
---|
3520 | 3843 | { |
---|
3521 | 3844 | boolean wastrim = trimmed; |
---|
.. | .. |
---|
3531 | 3854 | e.printStackTrace(); |
---|
3532 | 3855 | } |
---|
3533 | 3856 | |
---|
3534 | | - Trim(wastrim,true,crease,wasstrip,false); |
---|
| 3857 | + Trim(true/*wastrim*/,true,crease,wasstrip,false); |
---|
3535 | 3858 | } |
---|
3536 | 3859 | |
---|
3537 | 3860 | void GenNormalsJME() |
---|
.. | .. |
---|
3689 | 4012 | { |
---|
3690 | 4013 | triangles[i] = i; |
---|
3691 | 4014 | } |
---|
| 4015 | + |
---|
| 4016 | + Untrim(); |
---|
| 4017 | + MergeNormals(); |
---|
3692 | 4018 | } |
---|
3693 | 4019 | } |
---|
3694 | 4020 | |
---|
.. | .. |
---|
3722 | 4048 | tsa.getNormals(0, normals); |
---|
3723 | 4049 | tsa.getTextureCoordinates(0, 0, uvmap); |
---|
3724 | 4050 | // tsa.getColors(0, colors); |
---|
| 4051 | + |
---|
| 4052 | + for (int i=colors.length; --i>=0;) |
---|
| 4053 | + { |
---|
| 4054 | + colors[i] = 1; |
---|
| 4055 | + } |
---|
3725 | 4056 | |
---|
3726 | 4057 | int stripcount = tsa.getNumStrips(); |
---|
3727 | 4058 | triangles = new int[stripcount]; |
---|
.. | .. |
---|
3744 | 4075 | triangles = new int[1]; |
---|
3745 | 4076 | triangles[0] = 3; |
---|
3746 | 4077 | } |
---|
| 4078 | + |
---|
| 4079 | + Untrim(); |
---|
| 4080 | + MergeNormals(); |
---|
3747 | 4081 | } |
---|
3748 | 4082 | |
---|
3749 | 4083 | /* |
---|
.. | .. |
---|
3776 | 4110 | for (int i = 0; i < VertexCount(); i++) |
---|
3777 | 4111 | { |
---|
3778 | 4112 | Vertex v = GetVertex(i); |
---|
| 4113 | + |
---|
| 4114 | + vertextemp.set(v); |
---|
| 4115 | + |
---|
3779 | 4116 | //if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0) |
---|
3780 | 4117 | { |
---|
3781 | | - GenerateNormal(i, v); |
---|
3782 | | - SetVertex(v, i); |
---|
| 4118 | + if (!GenerateNormal(i, vertextemp)) |
---|
| 4119 | + continue; |
---|
| 4120 | + |
---|
| 4121 | + if (v.norm.dot(vertextemp.norm) < 0) |
---|
| 4122 | + vertextemp.norm.mul(-1); |
---|
| 4123 | + |
---|
| 4124 | + if (v.norm.dot(vertextemp.norm) < 0.9) |
---|
| 4125 | + SetVertex(vertextemp, i); |
---|
3783 | 4126 | } |
---|
3784 | 4127 | } |
---|
3785 | 4128 | |
---|
3786 | 4129 | Vertex.normalmode = false; |
---|
3787 | 4130 | } |
---|
3788 | 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 | + |
---|
| 4164 | + } |
---|
| 4165 | + |
---|
3789 | 4166 | static cVector temp1 = new cVector(); |
---|
3790 | 4167 | static cVector temp2 = new cVector(); |
---|
3791 | 4168 | static cVector temp3 = new cVector(); |
---|
3792 | 4169 | |
---|
3793 | | - void GenerateNormal(int index, Vertex v) |
---|
| 4170 | + boolean GenerateNormal(int index, Vertex v) |
---|
3794 | 4171 | { |
---|
3795 | 4172 | //System.out.println("Old normal = " + v.norm); |
---|
3796 | 4173 | LA.setVector(v.norm, 0, 0, 0); |
---|
.. | .. |
---|
3819 | 4196 | LA.vecSub(p/*.pos*/, v/*.pos*/, temp1); |
---|
3820 | 4197 | LA.vecSub(q/*.pos*/, v/*.pos*/, temp2); |
---|
3821 | 4198 | } |
---|
| 4199 | + else |
---|
| 4200 | + { |
---|
| 4201 | + continue; |
---|
| 4202 | + } |
---|
3822 | 4203 | |
---|
3823 | 4204 | //LA.vecNormalize(temp1); |
---|
3824 | 4205 | //LA.vecNormalize(temp2); |
---|
.. | .. |
---|
3829 | 4210 | double s = temp3.length(); |
---|
3830 | 4211 | //double c = temp2.dot(temp1); |
---|
3831 | 4212 | |
---|
| 4213 | + if (s == 0) |
---|
| 4214 | + return false; |
---|
| 4215 | + |
---|
3832 | 4216 | float angle = 1; // (float) Math.atan2(s, c); |
---|
3833 | 4217 | //if(angle < 0) angle = -angle; |
---|
3834 | 4218 | |
---|
3835 | 4219 | //LA.vecNormalize(temp3); |
---|
3836 | 4220 | LA.vecScale(temp3, angle / s); |
---|
3837 | 4221 | |
---|
| 4222 | +// if (temp3.dot(v.norm) < 0) |
---|
| 4223 | +// assert(temp3.dot(v.norm) >= 0); |
---|
| 4224 | + |
---|
3838 | 4225 | LA.vecAdd(temp3, v.norm, v.norm); |
---|
3839 | 4226 | } |
---|
3840 | 4227 | |
---|
3841 | 4228 | LA.vecNormalize(v.norm); |
---|
3842 | 4229 | //System.out.println("New normal = " + v.norm); |
---|
| 4230 | + |
---|
| 4231 | + return true; |
---|
3843 | 4232 | } |
---|
3844 | 4233 | |
---|
3845 | 4234 | double Arccos(double x) |
---|
.. | .. |
---|
4233 | 4622 | int count = VertexCount(); |
---|
4234 | 4623 | |
---|
4235 | 4624 | // mars 2014 |
---|
4236 | | - while (step >= count) |
---|
| 4625 | + while (step > count) |
---|
4237 | 4626 | step /= 10; |
---|
4238 | 4627 | |
---|
4239 | 4628 | for (int i = 0; i < count; i+=step) |
---|
.. | .. |
---|
4381 | 4770 | } |
---|
4382 | 4771 | } |
---|
4383 | 4772 | |
---|
4384 | | - void CullVertex(javax.media.opengl.GL gl, boolean shadow) |
---|
| 4773 | + void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED) |
---|
4385 | 4774 | { |
---|
4386 | 4775 | CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z, |
---|
4387 | 4776 | CameraPane.tempmat,0, CameraPane.tempmat2,0, |
---|
.. | .. |
---|
4413 | 4802 | // june 2014 |
---|
4414 | 4803 | // Camera parentcam = cam; |
---|
4415 | 4804 | // |
---|
4416 | | -// if (cam == CameraPane.theRenderer.cameras[0]) |
---|
| 4805 | +// if (cam == Globals.theRenderer.cameras[0]) |
---|
4417 | 4806 | // { |
---|
4418 | | -// parentcam = CameraPane.theRenderer.cameras[1]; |
---|
| 4807 | +// parentcam = Globals.theRenderer.cameras[1]; |
---|
4419 | 4808 | // } |
---|
4420 | 4809 | // |
---|
4421 | | -// if (cam == CameraPane.theRenderer.cameras[1]) |
---|
| 4810 | +// if (cam == Globals.theRenderer.cameras[1]) |
---|
4422 | 4811 | // { |
---|
4423 | | -// parentcam = CameraPane.theRenderer.cameras[0]; |
---|
| 4812 | +// parentcam = Globals.theRenderer.cameras[0]; |
---|
4424 | 4813 | // } |
---|
4425 | 4814 | |
---|
4426 | 4815 | gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0); |
---|
.. | .. |
---|
4546 | 4935 | { |
---|
4547 | 4936 | i3 = positions.length-3; |
---|
4548 | 4937 | i2 = uvmap.length - 2; |
---|
4549 | | - new Exception().printStackTrace(); |
---|
| 4938 | + //new Exception().printStackTrace(); |
---|
4550 | 4939 | } |
---|
4551 | 4940 | |
---|
4552 | 4941 | v./*pos.*/x = positions[i3]; |
---|
.. | .. |
---|
4846 | 5235 | return verticesCopy; |
---|
4847 | 5236 | } |
---|
4848 | 5237 | |
---|
4849 | | - void PreprocessOcclusion(CameraPane cp, double[][] transform) |
---|
| 5238 | + void PreprocessOcclusion(iCameraPane cp, double[][] transform) |
---|
4850 | 5239 | { |
---|
4851 | 5240 | if (//!trimmed || |
---|
4852 | 5241 | AOdone) |
---|
.. | .. |
---|
4855 | 5244 | return; |
---|
4856 | 5245 | } |
---|
4857 | 5246 | |
---|
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; |
---|
| 5247 | + cp.PrepOcclusion(this, transform); |
---|
4932 | 5248 | |
---|
4933 | 5249 | AOdone = true; |
---|
4934 | 5250 | } |
---|
.. | .. |
---|
5036 | 5352 | } |
---|
5037 | 5353 | } |
---|
5038 | 5354 | colors = null; |
---|
| 5355 | + } |
---|
| 5356 | + |
---|
| 5357 | + void CreateMesh(iHeightField hf, int x, int y) |
---|
| 5358 | + { |
---|
| 5359 | + BoundaryRep tmp = new BoundaryRep(); |
---|
| 5360 | + |
---|
| 5361 | + int vc = 0; |
---|
| 5362 | + |
---|
| 5363 | + Vertex v = new Vertex(true); |
---|
| 5364 | + |
---|
| 5365 | + for (int i=0; i<x; i++) |
---|
| 5366 | + { |
---|
| 5367 | + for (int j=0; j<y; j++) |
---|
| 5368 | + { |
---|
| 5369 | +// Vertex v = tmp.GetVertex(vc++); |
---|
| 5370 | + |
---|
| 5371 | + v.s = v.x = i; |
---|
| 5372 | + v.t = v.z = j; |
---|
| 5373 | + v.s /= x; v.t /= y; |
---|
| 5374 | + v.y = hf.f(i,j); |
---|
| 5375 | + |
---|
| 5376 | + int iu = tmp.AddTableVertex(v); |
---|
| 5377 | + |
---|
| 5378 | + v.s = v.x = i+1; |
---|
| 5379 | + v.t = v.z = j; |
---|
| 5380 | + v.s /= x; v.t /= y; |
---|
| 5381 | + v.y = hf.f(i+1,j); |
---|
| 5382 | + |
---|
| 5383 | + int iv = tmp.AddTableVertex(v); |
---|
| 5384 | + |
---|
| 5385 | + v.s = v.x = i+1; |
---|
| 5386 | + v.t = v.z = j+1; |
---|
| 5387 | + v.s /= x; v.t /= y; |
---|
| 5388 | + v.y = hf.f(i+1,j+1); |
---|
| 5389 | + |
---|
| 5390 | + int iw = tmp.AddTableVertex(v); |
---|
| 5391 | + |
---|
| 5392 | + v.s = v.x = i; |
---|
| 5393 | + v.t = v.z = j+1; |
---|
| 5394 | + v.s /= x; v.t /= y; |
---|
| 5395 | + v.y = hf.f(i,j+1); |
---|
| 5396 | + |
---|
| 5397 | + int ix = tmp.AddTableVertex(v); |
---|
| 5398 | + |
---|
| 5399 | + tmp.AddFace(iu,iw,iv); |
---|
| 5400 | + tmp.AddFace(iu,ix,iw); |
---|
| 5401 | + } |
---|
| 5402 | + } |
---|
| 5403 | + |
---|
| 5404 | + Set(tmp); |
---|
| 5405 | + |
---|
| 5406 | + Trim(true,false,true); |
---|
| 5407 | + ClearColors(); |
---|
5039 | 5408 | } |
---|
5040 | 5409 | |
---|
5041 | 5410 | void Stripify() |
---|
.. | .. |
---|
5290 | 5659 | |
---|
5291 | 5660 | transient int nbbadfaces; // ?? = 1000000; |
---|
5292 | 5661 | |
---|
5293 | | - int ChooseTriangle() |
---|
| 5662 | + /* |
---|
| 5663 | + */ |
---|
| 5664 | + int ChooseTriangle(boolean firstEquilateral) |
---|
5294 | 5665 | { |
---|
5295 | 5666 | int chosen = -1; |
---|
5296 | 5667 | |
---|
5297 | 5668 | double minweight = 1E10; |
---|
5298 | 5669 | |
---|
| 5670 | + int step = 8; // ? |
---|
| 5671 | + |
---|
| 5672 | + if (firstEquilateral) |
---|
| 5673 | + step = 1; |
---|
| 5674 | + |
---|
5299 | 5675 | nbbadfaces = 0; |
---|
5300 | | - for (int i=faces.size(); (i-=8)>=0;) |
---|
| 5676 | + for (int i=0; i<faces.size(); i+=step) |
---|
| 5677 | +// for (int i=faces.size(); (i-=8)>=0;) |
---|
5301 | 5678 | { |
---|
5302 | 5679 | Face face = (Face) faces.get(i); |
---|
5303 | 5680 | |
---|
5304 | | - //?? if (face.weight < 0) |
---|
5305 | | - // continue; |
---|
5306 | | - |
---|
5307 | | - double K = 1; // 0.01; // .25; |
---|
5308 | | - |
---|
5309 | | - double factor = (1-K)*face.nbiterations + K; //*face.weight; |
---|
5310 | | - |
---|
5311 | | - double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor; |
---|
| 5681 | + if (face.used) |
---|
| 5682 | + continue; |
---|
5312 | 5683 | |
---|
5313 | 5684 | if (!Valid(face)) |
---|
5314 | 5685 | { |
---|
.. | .. |
---|
5319 | 5690 | if (Boundary(face)) |
---|
5320 | 5691 | continue; |
---|
5321 | 5692 | |
---|
| 5693 | +// if (Boundary(face.p)) |
---|
| 5694 | +// continue; |
---|
| 5695 | +// |
---|
| 5696 | +// if (Boundary(face.q)) |
---|
| 5697 | +// continue; |
---|
| 5698 | +// |
---|
| 5699 | +// if (Boundary(face.r)) |
---|
| 5700 | +// continue; |
---|
| 5701 | + |
---|
5322 | 5702 | if (!ValidValence(face)) |
---|
5323 | 5703 | continue; |
---|
5324 | 5704 | |
---|
.. | .. |
---|
5327 | 5707 | !ValidValence(face.r)) |
---|
5328 | 5708 | continue; |
---|
5329 | 5709 | |
---|
5330 | | - if (minweight > weight) |
---|
| 5710 | + //?? if (face.weight < 0) |
---|
| 5711 | + // continue; |
---|
| 5712 | + |
---|
| 5713 | + if (firstEquilateral) |
---|
5331 | 5714 | { |
---|
5332 | | - 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 | + |
---|
5333 | 5724 | chosen = i; |
---|
| 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 | + } |
---|
5334 | 5742 | } |
---|
5335 | 5743 | } |
---|
5336 | 5744 | |
---|
5337 | 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; |
---|
5338 | 5762 | } |
---|
5339 | 5763 | |
---|
5340 | 5764 | static boolean remove3valence = true; |
---|
.. | .. |
---|
5370 | 5794 | } |
---|
5371 | 5795 | else |
---|
5372 | 5796 | { |
---|
5373 | | - assert(links.size() == vertices.size()); |
---|
| 5797 | + // TODO Grafreed.Assert(links.size() == vertices.size()); |
---|
5374 | 5798 | |
---|
5375 | 5799 | links.setSize(vertices.size()); |
---|
5376 | 5800 | for (int i=vertices.size(); --i>=0;) |
---|
.. | .. |
---|
5378 | 5802 | // linkstouched[i] = false; |
---|
5379 | 5803 | if (links.get(i) == null) // ?? |
---|
5380 | 5804 | { |
---|
| 5805 | + new Exception().printStackTrace(); |
---|
5381 | 5806 | links.set(i, new Vector(8)); |
---|
5382 | 5807 | // linkstouched[i] = true; |
---|
5383 | 5808 | } |
---|
.. | .. |
---|
5388 | 5813 | } |
---|
5389 | 5814 | } |
---|
5390 | 5815 | |
---|
| 5816 | + boolean once = false; |
---|
| 5817 | + |
---|
5391 | 5818 | for (int i=faces.size(); --i>=0;) |
---|
5392 | 5819 | { |
---|
5393 | 5820 | Face face = (Face) faces.get(i); |
---|
.. | .. |
---|
5399 | 5826 | //if (linkstouched[face.r]) |
---|
5400 | 5827 | links.get(face.r).add(face); |
---|
5401 | 5828 | |
---|
| 5829 | + if (face.used) |
---|
| 5830 | + once = true; |
---|
| 5831 | + |
---|
5402 | 5832 | face.good = 1; |
---|
5403 | 5833 | face.boundary = -1; |
---|
5404 | 5834 | } |
---|
.. | .. |
---|
6170 | 6600 | |
---|
6171 | 6601 | void InitWeights() |
---|
6172 | 6602 | { |
---|
| 6603 | + new Exception().printStackTrace(); |
---|
6173 | 6604 | System.exit(0); |
---|
6174 | 6605 | int n = 0; |
---|
6175 | 6606 | int b = 0; |
---|
.. | .. |
---|
6763 | 7194 | return (face.boundary = 1) == 1; |
---|
6764 | 7195 | } |
---|
6765 | 7196 | |
---|
| 7197 | + // June 2019 |
---|
| 7198 | + if (true) |
---|
| 7199 | + return (face.boundary = 0) == 1; |
---|
| 7200 | + |
---|
6766 | 7201 | // reverse triangle test |
---|
6767 | 7202 | q1.set(p); |
---|
6768 | 7203 | q2.set(q); |
---|
.. | .. |
---|
7019 | 7454 | assert(f2.contains(i)); |
---|
7020 | 7455 | assert(f3.contains(i)); |
---|
7021 | 7456 | |
---|
| 7457 | + // when r is the "center", p is along the boundary |
---|
7022 | 7458 | while (f0.r != i) |
---|
7023 | 7459 | { |
---|
7024 | 7460 | int t = f0.p; |
---|
.. | .. |
---|
7075 | 7511 | f0 = f3; |
---|
7076 | 7512 | f3 = t; |
---|
7077 | 7513 | } |
---|
7078 | | - atleastone = true; |
---|
7079 | 7514 | |
---|
| 7515 | + int va = f0.q; |
---|
| 7516 | + int vb = f0.r; |
---|
| 7517 | + int vc = -1; |
---|
| 7518 | + |
---|
| 7519 | + Face toremove1 = null; |
---|
| 7520 | + Face toremove2 = null; |
---|
| 7521 | + |
---|
| 7522 | + // f0 is the buffer for the first new triangle, |
---|
| 7523 | + // and otherf is the other upper one. |
---|
7080 | 7524 | Face otherf = null; |
---|
7081 | 7525 | |
---|
7082 | 7526 | if (f1.contains(f0.p)) |
---|
7083 | 7527 | { |
---|
7084 | 7528 | if (f1.p == f0.p) |
---|
7085 | 7529 | { |
---|
| 7530 | + assert(false); |
---|
7086 | 7531 | f0.r = f1.q; |
---|
7087 | 7532 | } |
---|
7088 | 7533 | else |
---|
7089 | 7534 | { |
---|
7090 | 7535 | assert(f1.q == f0.p); |
---|
7091 | | - f0.r = f1.p; |
---|
| 7536 | + vc = f1.p; |
---|
7092 | 7537 | } |
---|
7093 | 7538 | |
---|
7094 | 7539 | otherf = f2; |
---|
7095 | | - faces.remove(f1); |
---|
7096 | | - faces.remove(f3); |
---|
| 7540 | + toremove1 = f1; |
---|
| 7541 | + toremove2 = f3; |
---|
7097 | 7542 | } |
---|
7098 | 7543 | else |
---|
7099 | 7544 | if (f2.contains(f0.p)) |
---|
7100 | 7545 | { |
---|
7101 | 7546 | if (f2.p == f0.p) |
---|
7102 | 7547 | { |
---|
| 7548 | + assert(false); |
---|
7103 | 7549 | f0.r = f2.q; |
---|
7104 | 7550 | } |
---|
7105 | 7551 | else |
---|
7106 | 7552 | { |
---|
7107 | 7553 | assert(f2.q == f0.p); |
---|
7108 | | - f0.r = f2.p; |
---|
| 7554 | + vc = f2.p; |
---|
7109 | 7555 | } |
---|
7110 | 7556 | |
---|
7111 | 7557 | otherf = f3; |
---|
7112 | | - faces.remove(f1); |
---|
7113 | | - faces.remove(f2); |
---|
| 7558 | + toremove1 = f1; |
---|
| 7559 | + toremove2 = f2; |
---|
7114 | 7560 | } |
---|
7115 | 7561 | if (f3.contains(f0.p)) |
---|
7116 | 7562 | { |
---|
7117 | 7563 | if (f3.p == f0.p) |
---|
7118 | 7564 | { |
---|
| 7565 | +// assert(false); |
---|
| 7566 | + new Exception().printStackTrace(); |
---|
7119 | 7567 | f0.r = f3.q; |
---|
7120 | 7568 | } |
---|
7121 | 7569 | else |
---|
7122 | 7570 | { |
---|
7123 | 7571 | assert(f3.q == f0.p); |
---|
7124 | | - f0.r = f3.p; |
---|
| 7572 | + vc = f3.p; |
---|
7125 | 7573 | } |
---|
7126 | 7574 | |
---|
7127 | 7575 | otherf = f1; |
---|
7128 | | - faces.remove(f2); |
---|
7129 | | - faces.remove(f3); |
---|
| 7576 | + toremove1 = f2; |
---|
| 7577 | + toremove2 = f3; |
---|
7130 | 7578 | } |
---|
| 7579 | + |
---|
| 7580 | + vertextemp.set(vertices.get(va)); |
---|
| 7581 | + vertextemp.sub(vertices.get(vb)); |
---|
| 7582 | + vertextemp.normalize(); |
---|
| 7583 | + vertextemp2.set(vertices.get(vc)); |
---|
| 7584 | + vertextemp2.sub(vertices.get(vb)); |
---|
| 7585 | + vertextemp2.normalize(); |
---|
| 7586 | + |
---|
| 7587 | + if (vertextemp.dot(vertextemp2) > -0.95) |
---|
| 7588 | + { |
---|
| 7589 | + continue; |
---|
| 7590 | + } |
---|
| 7591 | + |
---|
| 7592 | + atleastone = true; |
---|
| 7593 | + |
---|
| 7594 | + f0.r = vc; |
---|
| 7595 | + |
---|
| 7596 | + faces.remove(toremove1); |
---|
| 7597 | + faces.remove(toremove2); |
---|
7131 | 7598 | |
---|
7132 | 7599 | if (!f0.contains(otherf.p)) |
---|
7133 | 7600 | { |
---|
.. | .. |
---|
7180 | 7647 | //InitWeights(); |
---|
7181 | 7648 | } |
---|
7182 | 7649 | |
---|
7183 | | - int chosen = ChooseTriangle(); // Best is slow and not really better |
---|
| 7650 | + int chosen = ChooseTriangle(true); // Best is slow and not really better |
---|
7184 | 7651 | |
---|
7185 | 7652 | if (chosen == -1) |
---|
7186 | 7653 | { |
---|
.. | .. |
---|
7194 | 7661 | //remove3valence = false; |
---|
7195 | 7662 | // InitWeights(); |
---|
7196 | 7663 | |
---|
7197 | | - chosen = ChooseTriangle(); |
---|
| 7664 | + chosen = ChooseTriangle(true); |
---|
7198 | 7665 | } |
---|
7199 | 7666 | } |
---|
7200 | 7667 | |
---|
.. | .. |
---|
7335 | 7802 | Trim(); |
---|
7336 | 7803 | Untrim(); |
---|
7337 | 7804 | |
---|
7338 | | - BoundaryRep tmp = new BoundaryRep(); // (BoundaryRep) GraphreeD.clone(this); |
---|
| 7805 | + BoundaryRep tmp = new BoundaryRep(); // (BoundaryRep) GrafreeD.clone(this); |
---|
7339 | 7806 | |
---|
7340 | 7807 | double minx = Float.POSITIVE_INFINITY; |
---|
7341 | 7808 | double maxx = Float.NEGATIVE_INFINITY; |
---|
.. | .. |
---|
7373 | 7840 | if (max < maxz - minz) |
---|
7374 | 7841 | max = maxz - minz; |
---|
7375 | 7842 | |
---|
7376 | | - tmp.THRESHOLD = max/25; // 50; |
---|
| 7843 | + tmp.THRESHOLD = 0.5; // max/25; // 50; |
---|
7377 | 7844 | |
---|
7378 | 7845 | tmp.faces.clear(); |
---|
7379 | 7846 | |
---|
.. | .. |
---|
7470 | 7937 | |
---|
7471 | 7938 | // boolean lock; |
---|
7472 | 7939 | |
---|
7473 | | - void SplitInTwo(boolean reduction34, boolean onlyone) |
---|
| 7940 | + boolean SplitInTwo(boolean reduction34, boolean onlyone) |
---|
7474 | 7941 | { |
---|
7475 | 7942 | if (stripified) |
---|
7476 | 7943 | { |
---|
.. | .. |
---|
7498 | 7965 | s3 = new cVector(); |
---|
7499 | 7966 | } |
---|
7500 | 7967 | |
---|
7501 | | - 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)); |
---|
7502 | 7969 | |
---|
7503 | 7970 | try |
---|
7504 | 7971 | { |
---|
.. | .. |
---|
7507 | 7974 | { |
---|
7508 | 7975 | System.err.println("EXCEPTION CAUGHT"); |
---|
7509 | 7976 | e.printStackTrace(); |
---|
7510 | | - return; |
---|
| 7977 | + return false; |
---|
7511 | 7978 | } catch (Error e) |
---|
7512 | 7979 | { |
---|
7513 | 7980 | System.err.println("ERROR CAUGHT"); |
---|
7514 | 7981 | e.printStackTrace(); |
---|
7515 | | - return; |
---|
| 7982 | + return false; |
---|
7516 | 7983 | } |
---|
7517 | 7984 | |
---|
7518 | 7985 | System.out.println("# faces = " + faces.size()); |
---|
.. | .. |
---|
7522 | 7989 | { |
---|
7523 | 7990 | Face face = (Face) faces.get(i); |
---|
7524 | 7991 | |
---|
| 7992 | + face.used = false; |
---|
7525 | 7993 | face.nbiterations = 1; |
---|
7526 | 7994 | face.weight = -1; |
---|
7527 | 7995 | face.boundary = -1; |
---|
.. | .. |
---|
7573 | 8041 | nbbadfaces = faces.size(); |
---|
7574 | 8042 | //remove3valence = true; |
---|
7575 | 8043 | |
---|
| 8044 | + int count = 2; |
---|
| 8045 | + |
---|
| 8046 | + if (onlyone) |
---|
| 8047 | + count = 1; |
---|
| 8048 | + |
---|
7576 | 8049 | firstpass = true; |
---|
7577 | 8050 | |
---|
7578 | 8051 | int n = faces.size(); |
---|
.. | .. |
---|
7588 | 8061 | System.out.print('.'); |
---|
7589 | 8062 | } |
---|
7590 | 8063 | System.out.println(); |
---|
| 8064 | + boolean atleastone = false; |
---|
7591 | 8065 | int i = 0; |
---|
7592 | | - while (reduction34 || faces.size() > n/2) |
---|
| 8066 | + while (true) // reduction34 || faces.size() > n/2) |
---|
7593 | 8067 | { |
---|
7594 | 8068 | if (i++%100 == 0) |
---|
7595 | 8069 | { |
---|
7596 | | - 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)); |
---|
7597 | 8071 | System.out.println("#faces = " + faces.size()); |
---|
7598 | 8072 | // if (i != 1) |
---|
7599 | 8073 | // break; |
---|
.. | .. |
---|
7611 | 8085 | { |
---|
7612 | 8086 | if (!RemoveOneTriangle()) |
---|
7613 | 8087 | break; |
---|
| 8088 | + |
---|
| 8089 | + atleastone = true; |
---|
7614 | 8090 | } |
---|
7615 | 8091 | // if (iterationcount == 0) |
---|
7616 | 8092 | // break; |
---|
.. | .. |
---|
7621 | 8097 | break; |
---|
7622 | 8098 | } |
---|
7623 | 8099 | firstpass = false; |
---|
7624 | | - if (onlyone) |
---|
7625 | | - break; // one triangle only |
---|
| 8100 | +// if (--count<0 && !reduction34) |
---|
| 8101 | +// break; // one triangle only |
---|
7626 | 8102 | } |
---|
7627 | 8103 | |
---|
7628 | 8104 | InitLinks(false); // for further display |
---|
.. | .. |
---|
7637 | 8113 | //Trim(true,cJME.gennormals,true,false); // doesn't work |
---|
7638 | 8114 | Trim(true,false,false,false,false); |
---|
7639 | 8115 | |
---|
7640 | | - 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; |
---|
7641 | 8119 | } |
---|
7642 | 8120 | |
---|
7643 | 8121 | void UpdateIndices(Face face, Face minface) |
---|
.. | .. |
---|
7650 | 8128 | face.p = minface.p; |
---|
7651 | 8129 | //if (leafweights) |
---|
7652 | 8130 | face.good = 0; // false; |
---|
| 8131 | + face.used = true; |
---|
7653 | 8132 | } |
---|
7654 | 8133 | if (face.q == minface.p || face.q == minface.q || face.q == minface.r) |
---|
7655 | 8134 | { |
---|
7656 | 8135 | face.q = minface.p; |
---|
7657 | 8136 | //if (leafweights) |
---|
7658 | 8137 | face.good = 0; // false; |
---|
| 8138 | + face.used = true; |
---|
7659 | 8139 | } |
---|
7660 | 8140 | if (face.r == minface.p || face.r == minface.q || face.r == minface.r) |
---|
7661 | 8141 | { |
---|
7662 | 8142 | face.r = minface.p; |
---|
7663 | 8143 | //if (leafweights) |
---|
7664 | 8144 | face.good = 0; // false; |
---|
| 8145 | + face.used = true; |
---|
7665 | 8146 | } |
---|
7666 | 8147 | |
---|
7667 | 8148 | if (face.p >/*=*/ minface.q && face.p < minface.r) |
---|
.. | .. |
---|
7721 | 8202 | if (v == 2) |
---|
7722 | 8203 | vert = minface.r; |
---|
7723 | 8204 | // Face face = (Face) faces.get(i); |
---|
7724 | | - Vector<Face> vertfaces = links.get(vert); |
---|
7725 | | - for (int i=vertfaces.size(); --i>=0;) |
---|
7726 | | - { |
---|
7727 | | - Face face = (Face) vertfaces.get(i); |
---|
7728 | | - |
---|
7729 | | - // if (face.weight == 10000) |
---|
7730 | | - // continue; |
---|
7731 | | - |
---|
7732 | | - if (face.p == minface.p || face.q == minface.p || face.r == minface.p || |
---|
7733 | | - face.p == minface.q || face.q == minface.q || face.r == minface.q || |
---|
7734 | | - 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;) |
---|
7735 | 8207 | { |
---|
7736 | | - 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) |
---|
7737 | 8216 | { |
---|
7738 | | -// if(minfaceweight <= 0) |
---|
7739 | | -// assert(minfaceweight > 0); |
---|
7740 | | -// |
---|
7741 | | -// //FaceWeight(face); |
---|
7742 | | -// if(face.weight < 0) |
---|
7743 | | -// assert(face.weight >= 0); |
---|
7744 | | - |
---|
7745 | | - face.weight += minfaceweight; |
---|
7746 | | - |
---|
7747 | | -// if (face.weight >= 10000) |
---|
7748 | | -// 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; |
---|
7749 | 8244 | } |
---|
7750 | 8245 | else |
---|
7751 | | - face.weight = -1; |
---|
7752 | | - |
---|
7753 | | - face.nbiterations += 1; |
---|
7754 | | - face.boundary = -1; |
---|
7755 | | - |
---|
7756 | | - Vertex p = (Vertex)vertices.get(face.p); |
---|
7757 | | - Vertex q = (Vertex)vertices.get(face.q); |
---|
7758 | | - Vertex r = (Vertex)vertices.get(face.r); |
---|
7759 | | - |
---|
7760 | | - p.boundary = -1; |
---|
7761 | | - q.boundary = -1; |
---|
7762 | | - r.boundary = -1; |
---|
| 8246 | + assert(false); |
---|
7763 | 8247 | } |
---|
7764 | | - else |
---|
7765 | | - assert(false); |
---|
7766 | 8248 | } |
---|
7767 | | - } |
---|
7768 | 8249 | |
---|
7769 | 8250 | // TouchVertex(minface.p); |
---|
7770 | 8251 | // TouchVertex(minface.q); |
---|
.. | .. |
---|
7932 | 8413 | |
---|
7933 | 8414 | minface.q = minface.r = minface.p; |
---|
7934 | 8415 | |
---|
| 8416 | + int count = 0; |
---|
| 8417 | + |
---|
7935 | 8418 | for (int i=0; i<faces.size(); i++) |
---|
7936 | 8419 | { |
---|
7937 | 8420 | Face face = (Face) faces.get(i); |
---|
.. | .. |
---|
7943 | 8426 | TouchVertex(face.r, true); // , minface.weight); |
---|
7944 | 8427 | // assert(!lock); |
---|
7945 | 8428 | faces.remove(i--); |
---|
| 8429 | + count++; |
---|
| 8430 | + if (count == 4) |
---|
| 8431 | + break; |
---|
7946 | 8432 | } |
---|
7947 | 8433 | } |
---|
7948 | 8434 | |
---|
.. | .. |
---|
7960 | 8446 | for (int i=vertfaces.size(); --i>=0;) |
---|
7961 | 8447 | { |
---|
7962 | 8448 | Face face = (Face) vertfaces.get(i); |
---|
| 8449 | + face.used = true; |
---|
7963 | 8450 | face.good = 0; // false; |
---|
7964 | 8451 | if (leafweights) |
---|
7965 | 8452 | face.weight = -1; |
---|
.. | .. |
---|
8006 | 8493 | if (!trimmed) |
---|
8007 | 8494 | return; |
---|
8008 | 8495 | |
---|
8009 | | - GraphreeD.linkUV = false; |
---|
| 8496 | + Grafreed.linkUV = false; |
---|
8010 | 8497 | |
---|
8011 | 8498 | try |
---|
8012 | 8499 | { |
---|
.. | .. |
---|
8214 | 8701 | return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices; |
---|
8215 | 8702 | } |
---|
8216 | 8703 | |
---|
8217 | | - static Camera localcamera = new Camera(); |
---|
8218 | | - static cVector from = new cVector(); |
---|
8219 | | - static cVector to = new cVector(); |
---|
8220 | 8704 | boolean trimmed = false; |
---|
8221 | 8705 | boolean stripified = false; |
---|
8222 | 8706 | transient boolean AOdone = false; |
---|
.. | .. |
---|
8224 | 8708 | /*transient*/ int maxIndexV = 0; |
---|
8225 | 8709 | /*transient*/ int bufV, bufF; |
---|
8226 | 8710 | // Raw version |
---|
8227 | | - private float[] positions; |
---|
8228 | | - private float[] normals; |
---|
| 8711 | + //private |
---|
| 8712 | + float[] positions; |
---|
| 8713 | + //private |
---|
| 8714 | + float[] normals; |
---|
8229 | 8715 | float[] colors; |
---|
8230 | 8716 | private float[] uvmap; |
---|
8231 | 8717 | private int[] triangles; |
---|
.. | .. |
---|
8239 | 8725 | int[] startvertices; |
---|
8240 | 8726 | float[] averagepoints; |
---|
8241 | 8727 | float[] extremepoints; |
---|
8242 | | - float[] supportsizes; // distance of closest point |
---|
| 8728 | + float[] supportminsize; // distance of closest point |
---|
| 8729 | + float[] supportmaxsize; // distance of fartest point |
---|
8243 | 8730 | |
---|
8244 | 8731 | transient Hashtable vertextable; |
---|
8245 | 8732 | /*transient*/ private Vertex[] verticesCopy; |
---|