.. | .. |
---|
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) |
---|
653 | 688 | { |
---|
| 689 | + CameraPane.CreateSelectedPoint(); |
---|
654 | 690 | CameraPane.selectedpoint. |
---|
655 | 691 | getAverage(cStatic.point1, true); |
---|
656 | 692 | |
---|
.. | .. |
---|
786 | 822 | v.weights[k] = other.ComputeWeight(v, toRoot, k); // (float)(supportsize * normalweight * nz / Math.pow(tx*tx+ty*ty+tz*tz, 1)); |
---|
787 | 823 | v.totalweight += v.weights[k]; |
---|
788 | 824 | |
---|
789 | | - if (CameraPane.CROWD) |
---|
| 825 | + if (Globals.CROWD) |
---|
790 | 826 | { |
---|
791 | 827 | // System.out.print("weight = " + v.weights[k]); |
---|
792 | 828 | // System.out.println("; totalweight = " + v.totalweight); |
---|
.. | .. |
---|
946 | 982 | |
---|
947 | 983 | int nbsupports; |
---|
948 | 984 | |
---|
949 | | - SEUIL = 0.1; // aout 2013 |
---|
| 985 | + // sept 2017 SEUIL = 0.1; // aout 2013 |
---|
950 | 986 | |
---|
951 | | - supports = InitConnections(other); |
---|
| 987 | + supports = other.InitConnections(); |
---|
952 | 988 | |
---|
953 | 989 | other.supports = supports; // should be the other way around... |
---|
954 | 990 | |
---|
.. | .. |
---|
968 | 1004 | |
---|
969 | 1005 | v.closestsupport = -1; |
---|
970 | 1006 | |
---|
| 1007 | + CameraPane.CreateSelectedPoint(); |
---|
971 | 1008 | CameraPane.selectedpoint. |
---|
972 | 1009 | getAverage(cStatic.point1, true); |
---|
973 | 1010 | |
---|
.. | .. |
---|
982 | 1019 | |
---|
983 | 1020 | int subsupports = 0; |
---|
984 | 1021 | |
---|
985 | | - SEUIL = 0.1; // aout 2013 |
---|
| 1022 | + // sept 2017 SEUIL = 0.1; // aout 2013 |
---|
986 | 1023 | |
---|
987 | 1024 | while (subsupports == 0) |
---|
988 | 1025 | { |
---|
.. | .. |
---|
1006 | 1043 | |
---|
1007 | 1044 | vect.set(v); |
---|
1008 | 1045 | vect.sub(vect2); |
---|
| 1046 | + |
---|
| 1047 | +// vertextemp.x = other.averagepoints[c*3]; |
---|
| 1048 | +// vertextemp.y = other.averagepoints[c*3+1]; |
---|
| 1049 | +// vertextemp.z = other.averagepoints[c*3+2]; |
---|
| 1050 | +// |
---|
| 1051 | +// Vertex v3 = vertextemp2; |
---|
| 1052 | +// v3.x = other.extremepoints[c*3]; |
---|
| 1053 | +// v3.y = other.extremepoints[c*3+1]; |
---|
| 1054 | +// v3.z = other.extremepoints[c*3+2]; |
---|
| 1055 | +// |
---|
| 1056 | +// vect3.set(v3); // "X" axis apex |
---|
| 1057 | +// vect3.sub(vertextemp); // origin (center) |
---|
| 1058 | +// |
---|
| 1059 | +// double distmax = vect3.length(); |
---|
| 1060 | +// |
---|
| 1061 | +// vect3.set(v2); // "X" axis apex |
---|
| 1062 | +// vect3.sub(vertextemp); // origin (center) |
---|
| 1063 | +// |
---|
| 1064 | +// if (vect3.length() >= distmax) |
---|
| 1065 | +// continue; |
---|
1009 | 1066 | |
---|
1010 | 1067 | if (mindistance > vect.dot(vect)) |
---|
1011 | 1068 | { |
---|
.. | .. |
---|
1017 | 1074 | |
---|
1018 | 1075 | subsupports = v.closestsupport==-1 ? 0 : supports[v.closestsupport].Length(); |
---|
1019 | 1076 | |
---|
1020 | | - SEUIL *= 2; |
---|
| 1077 | + // previously for "contains", now for weights. |
---|
| 1078 | + assert(subsupports > 0); |
---|
| 1079 | + //SEUIL *= 2; |
---|
1021 | 1080 | } |
---|
1022 | 1081 | |
---|
1023 | 1082 | assert(subsupports > 0); |
---|
.. | .. |
---|
1204 | 1263 | for (int wi = v0.weights.length; --wi>=0;) |
---|
1205 | 1264 | v[wi] = 0; |
---|
1206 | 1265 | |
---|
| 1266 | + CameraPane.CreateSelectedPoint(); |
---|
1207 | 1267 | CameraPane.selectedpoint. |
---|
1208 | 1268 | getAverage(cStatic.point1, true); |
---|
1209 | 1269 | |
---|
.. | .. |
---|
1341 | 1401 | v0.x = v0.y = v0.z = 0; |
---|
1342 | 1402 | v0.norm.x = v0.norm.y = v0.norm.z = 0; |
---|
1343 | 1403 | |
---|
| 1404 | + CameraPane.CreateSelectedPoint(); |
---|
1344 | 1405 | CameraPane.selectedpoint. |
---|
1345 | 1406 | getAverage(cStatic.point1, true); |
---|
1346 | 1407 | |
---|
.. | .. |
---|
1492 | 1553 | InitFaceIndices(); |
---|
1493 | 1554 | } |
---|
1494 | 1555 | |
---|
1495 | | - BoundaryRep rep = (BoundaryRep) GraphreeD.clone(this); |
---|
| 1556 | + BoundaryRep rep = (BoundaryRep) Grafreed.clone(this); |
---|
1496 | 1557 | //float[] v = new float[100]; |
---|
1497 | 1558 | |
---|
1498 | 1559 | for (int loops=1; --loops>=0;) |
---|
.. | .. |
---|
1522 | 1583 | InitFaceIndices(); |
---|
1523 | 1584 | } |
---|
1524 | 1585 | |
---|
1525 | | - BoundaryRep rep = (BoundaryRep) GraphreeD.clone(this); |
---|
| 1586 | + BoundaryRep rep = (BoundaryRep) Grafreed.clone(this); |
---|
1526 | 1587 | //float[] v = new float[100]; |
---|
1527 | 1588 | |
---|
1528 | 1589 | for (int loops=10; --loops>=0;) |
---|
.. | .. |
---|
1869 | 1930 | return; |
---|
1870 | 1931 | } |
---|
1871 | 1932 | |
---|
1872 | | - // System.exit(0); |
---|
| 1933 | + // System.exit(0); |
---|
1873 | 1934 | |
---|
1874 | 1935 | cVector vect = new cVector(); |
---|
1875 | 1936 | cVector normal = new cVector(); |
---|
.. | .. |
---|
1940 | 2001 | if (v.vertexlinks == null) |
---|
1941 | 2002 | continue; |
---|
1942 | 2003 | |
---|
1943 | | - if (v.weights != null && v.weights[j] == 0) // < 0.01 * v.totalweight) // == 0) |
---|
| 2004 | + // Warning: faster but dangerous |
---|
| 2005 | + if (v.weights != null && v.weights[j] |
---|
| 2006 | + // == 0) |
---|
| 2007 | + < 0.0001 * v.totalweight) |
---|
1944 | 2008 | { |
---|
1945 | 2009 | //testweight += v.weights[j-1]; |
---|
1946 | 2010 | continue; |
---|
.. | .. |
---|
2163 | 2227 | // if (slow) |
---|
2164 | 2228 | // aout 2013 |
---|
2165 | 2229 | // sept 2013 merde... |
---|
2166 | | - W = 13; |
---|
| 2230 | + W = 3; // 13; |
---|
2167 | 2231 | |
---|
2168 | 2232 | // POSERATE |
---|
2169 | 2233 | if (CameraPane.tickcount > 0 || CameraPane.SLOWPOSE) |
---|
.. | .. |
---|
2221 | 2285 | |
---|
2222 | 2286 | transient int lastsoundtime; |
---|
2223 | 2287 | |
---|
| 2288 | + transient boolean once = false; |
---|
| 2289 | + |
---|
2224 | 2290 | void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked) |
---|
2225 | 2291 | { |
---|
2226 | 2292 | if (LA.isIdentity(toRoot)) |
---|
.. | .. |
---|
2276 | 2342 | |
---|
2277 | 2343 | if (v.totalweight == 0) |
---|
2278 | 2344 | { |
---|
2279 | | - System.err.println("v.totalweight == 0! --> " + this + " : " + other); |
---|
| 2345 | + if (!once) |
---|
| 2346 | + { |
---|
| 2347 | + System.err.println("v.totalweight == 0! --> " + this + " : " + other); |
---|
| 2348 | + once = true; |
---|
| 2349 | + } |
---|
2280 | 2350 | continue; |
---|
2281 | 2351 | } |
---|
2282 | 2352 | |
---|
.. | .. |
---|
2600 | 2670 | // if (stepout && !playedonce) |
---|
2601 | 2671 | // { |
---|
2602 | 2672 | // // sound |
---|
2603 | | -// GraphreeD.wav.play(); |
---|
| 2673 | +// GrafreeD.wav.play(); |
---|
2604 | 2674 | // playedonce = true; |
---|
2605 | 2675 | // } |
---|
2606 | 2676 | // |
---|
.. | .. |
---|
2635 | 2705 | if (false) // slow && stepout && onein) |
---|
2636 | 2706 | { |
---|
2637 | 2707 | // sound |
---|
2638 | | - cVector eye = CameraPane.theRenderer.eyeCamera.location; |
---|
| 2708 | + cVector eye = Globals.theRenderer.EyeCamera().location; |
---|
2639 | 2709 | |
---|
2640 | 2710 | Vertex v = GetVertex(0); |
---|
2641 | 2711 | |
---|
2642 | 2712 | tmp.set(v); |
---|
2643 | 2713 | tmp.sub(eye); |
---|
2644 | 2714 | |
---|
2645 | | - if (CameraPane.framecount - lastsoundtime > 30) // 0.25 secs |
---|
| 2715 | + if (Globals.framecount - lastsoundtime > 30) // 0.25 secs |
---|
2646 | 2716 | { |
---|
2647 | | - GraphreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1); |
---|
| 2717 | + Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1); |
---|
2648 | 2718 | |
---|
2649 | | - lastsoundtime = CameraPane.framecount; |
---|
| 2719 | + lastsoundtime = Globals.framecount; |
---|
2650 | 2720 | } |
---|
2651 | 2721 | |
---|
2652 | 2722 | stepout = false; |
---|
.. | .. |
---|
3072 | 3142 | // |
---|
3073 | 3143 | // transient VertexCompare[] vertexcompare = null; |
---|
3074 | 3144 | |
---|
| 3145 | + // Check if v0 is close enough from any vertex of the given subobject of this. |
---|
3075 | 3146 | boolean Contains(Vertex v0, int object) |
---|
3076 | 3147 | { |
---|
3077 | 3148 | int start = startvertices[object-1]; |
---|
.. | .. |
---|
3129 | 3200 | */ |
---|
3130 | 3201 | } |
---|
3131 | 3202 | |
---|
3132 | | - void GenUV() |
---|
| 3203 | + void UnfoldUV() |
---|
| 3204 | + { |
---|
| 3205 | + for (int i = 0; i < VertexCount(); i++) |
---|
| 3206 | + { |
---|
| 3207 | + Vertex v = GetVertex(i); |
---|
| 3208 | + |
---|
| 3209 | + v.x = v.s; |
---|
| 3210 | + v.y = v.t; |
---|
| 3211 | + v.z = 0; |
---|
| 3212 | + |
---|
| 3213 | + v.norm.x = 0; |
---|
| 3214 | + v.norm.y = 0; |
---|
| 3215 | + v.norm.z = 1; |
---|
| 3216 | + |
---|
| 3217 | + SetVertex(v, i); |
---|
| 3218 | + } |
---|
| 3219 | + } |
---|
| 3220 | + |
---|
| 3221 | + float power = 2; |
---|
| 3222 | + |
---|
| 3223 | + void GenUV() // float power) |
---|
3133 | 3224 | { |
---|
3134 | 3225 | Trim(); |
---|
3135 | 3226 | |
---|
.. | .. |
---|
3193 | 3284 | y -= 0.5; |
---|
3194 | 3285 | z -= 0.5; |
---|
3195 | 3286 | |
---|
| 3287 | + double ax = Math.abs(x); |
---|
| 3288 | + double ay = Math.abs(y); |
---|
| 3289 | + double max = ax; |
---|
| 3290 | + if (max < ay) |
---|
| 3291 | + { |
---|
| 3292 | + max = ay; |
---|
| 3293 | + } |
---|
| 3294 | + |
---|
| 3295 | + if (max == 0) |
---|
| 3296 | + { |
---|
| 3297 | + uvmap[i2] = 0.5f; |
---|
| 3298 | + uvmap[i2+1] = 0.5f; |
---|
| 3299 | + continue; |
---|
| 3300 | + } |
---|
| 3301 | + |
---|
| 3302 | + x /= max; |
---|
| 3303 | + y /= max; |
---|
| 3304 | + |
---|
| 3305 | + double angle = Math.acos(Math.abs(z*2)); |
---|
| 3306 | + |
---|
| 3307 | + double k = angle / Math.PI * 2; |
---|
| 3308 | + |
---|
| 3309 | + assert(k >= 0); |
---|
| 3310 | + |
---|
| 3311 | + // k == 0 => uv = 0 (center) |
---|
| 3312 | + // k == 1 => uv = -1,1 (border) |
---|
| 3313 | + |
---|
| 3314 | + if (i == 0) |
---|
| 3315 | + System.out.println("power = " + power); |
---|
| 3316 | + |
---|
| 3317 | + double length1 = (ax+ay)/max; |
---|
| 3318 | + double length2 = Math.sqrt(ax*ax + ay*ay) / max; |
---|
| 3319 | + |
---|
| 3320 | + double t = k; |
---|
| 3321 | + |
---|
| 3322 | + t = Math.pow(t, 3); |
---|
| 3323 | + |
---|
| 3324 | + // Interpolate between k/length2 (center) and k (border) |
---|
| 3325 | + if (length2 > 0) |
---|
| 3326 | + k *= (1 - t) / length2 + t; |
---|
| 3327 | + |
---|
| 3328 | + double u = k*x; |
---|
| 3329 | + double v = k*y; |
---|
| 3330 | + |
---|
| 3331 | + u /= 2; |
---|
| 3332 | + v /= 2; |
---|
| 3333 | + u += 0.5; |
---|
| 3334 | + v += 0.5; |
---|
| 3335 | + |
---|
| 3336 | + uvmap[i2] = (float) u; |
---|
| 3337 | + uvmap[i2+1] = (float) v; |
---|
| 3338 | + } |
---|
| 3339 | + } |
---|
| 3340 | + |
---|
| 3341 | + void GenUVold(float power) |
---|
| 3342 | + { |
---|
| 3343 | + Trim(); |
---|
| 3344 | + |
---|
| 3345 | + cVector boxcenter = null; |
---|
| 3346 | + cVector minima, maxima; |
---|
| 3347 | + minima = new cVector(); |
---|
| 3348 | + maxima = new cVector(); |
---|
| 3349 | + minima.x = minima.y = minima.z = Double.MAX_VALUE; |
---|
| 3350 | + maxima.x = maxima.y = maxima.z = -Double.MAX_VALUE; |
---|
| 3351 | + for (int i = 0; i < VertexCount(); i++) |
---|
| 3352 | + { |
---|
| 3353 | + Vertex v = GetVertex(i); |
---|
| 3354 | + |
---|
| 3355 | + if (minima.x > v.x) |
---|
| 3356 | + { |
---|
| 3357 | + minima.x = v.x; |
---|
| 3358 | + } |
---|
| 3359 | + if (minima.y > v.y) |
---|
| 3360 | + { |
---|
| 3361 | + minima.y = v.y; |
---|
| 3362 | + } |
---|
| 3363 | + if (minima.z > v.z) |
---|
| 3364 | + { |
---|
| 3365 | + minima.z = v.z; |
---|
| 3366 | + } |
---|
| 3367 | + |
---|
| 3368 | + if (maxima.x < v.x) |
---|
| 3369 | + { |
---|
| 3370 | + maxima.x = v.x; |
---|
| 3371 | + } |
---|
| 3372 | + if (maxima.y < v.y) |
---|
| 3373 | + { |
---|
| 3374 | + maxima.y = v.y; |
---|
| 3375 | + } |
---|
| 3376 | + if (maxima.z < v.z) |
---|
| 3377 | + { |
---|
| 3378 | + maxima.z = v.z; |
---|
| 3379 | + } |
---|
| 3380 | + } |
---|
| 3381 | + |
---|
| 3382 | + boxcenter = new cVector((maxima.x + minima.x) / 2, (maxima.y + minima.y) / 2, (maxima.z + minima.z) / 2); |
---|
| 3383 | + int i2 = 0, i3 = 0; |
---|
| 3384 | + for (int i = 0; i < positions.length/3; i++, i3 += 3, i2 += 2) |
---|
| 3385 | + { |
---|
| 3386 | +// //uvmap[i2] = (float) normals[i3]*0.5f + 0.5f; // v.x; |
---|
| 3387 | +// //uvmap[i2 + 1] = (float) normals[i3+1]*0.5f + 0.5f; //z; |
---|
| 3388 | +// uvmap[i2] = (float) (positions[i3] - boxcenter.x); |
---|
| 3389 | +// uvmap[i2 + 1] = (float) (positions[i3+2] - boxcenter.z); |
---|
| 3390 | +// uvmap[i2] = (float) Math.atan2(positions[i3+1] - boxcenter.y, positions[i3] - boxcenter.x); |
---|
| 3391 | +// uvmap[i2 + 1] = (float)(positions[i3+2] - boxcenter.z); |
---|
| 3392 | + // box UV |
---|
| 3393 | + double x = positions[i3] - minima.x; // - Math.floor(positions[i3]); |
---|
| 3394 | + double y = positions[i3+1] - minima.y; // - Math.floor(positions[i3+1]); |
---|
| 3395 | + double z = positions[i3+2] - minima.z; // - Math.floor(positions[i3+2]); |
---|
| 3396 | + |
---|
| 3397 | + // [-1/2, 1/2] |
---|
| 3398 | + x /= maxima.x - minima.x; |
---|
| 3399 | + y /= maxima.y - minima.y; |
---|
| 3400 | + z /= maxima.z - minima.z; |
---|
| 3401 | + |
---|
| 3402 | + x -= 0.5; |
---|
| 3403 | + y -= 0.5; |
---|
| 3404 | + z -= 0.5; |
---|
| 3405 | + |
---|
3196 | 3406 | // x *= 2; |
---|
3197 | 3407 | // y *= 2; |
---|
3198 | 3408 | // z *= 2; |
---|
.. | .. |
---|
3219 | 3429 | |
---|
3220 | 3430 | z = Math.cos(angle/2); |
---|
3221 | 3431 | |
---|
| 3432 | + assert(z >= 0); |
---|
| 3433 | + assert(z <= 1); |
---|
| 3434 | + |
---|
| 3435 | + /**/ |
---|
| 3436 | + //z = Math.pow(z, power); //1.08f); |
---|
| 3437 | + |
---|
| 3438 | + if (i == 0) |
---|
| 3439 | + System.out.println("power = " + power); |
---|
| 3440 | + |
---|
3222 | 3441 | // sqrt(k2*x2 + k2*z2 + y2) = length |
---|
3223 | 3442 | // k2*x2 + k2*z2 = length2 - y2 |
---|
3224 | 3443 | // k2 = (length2 - y2) / (x2 + z2) |
---|
.. | .. |
---|
3229 | 3448 | k /= x*x + y*y; |
---|
3230 | 3449 | } |
---|
3231 | 3450 | else |
---|
3232 | | - GraphreeD.Assert(z == 1); |
---|
| 3451 | + Grafreed.Assert(z == 1); |
---|
3233 | 3452 | |
---|
3234 | 3453 | if (k < 0) |
---|
3235 | 3454 | k = 0; |
---|
.. | .. |
---|
3238 | 3457 | |
---|
3239 | 3458 | x *= k; |
---|
3240 | 3459 | y *= k; |
---|
| 3460 | + /**/ |
---|
3241 | 3461 | |
---|
3242 | 3462 | double max = Math.abs(x); |
---|
3243 | 3463 | if (max < Math.abs(y)) |
---|
.. | .. |
---|
3250 | 3470 | } |
---|
3251 | 3471 | |
---|
3252 | 3472 | // max = Math.sqrt(max*2)/2; |
---|
| 3473 | +// double x2 = Math.pow(Math.abs(x), 1/power); |
---|
| 3474 | +// double y2 = Math.pow(Math.abs(y), 1/power); |
---|
| 3475 | +// double z2 = Math.pow(Math.abs(z), 1/power); |
---|
| 3476 | +// max = Math.pow(x2 + y2 + z2, power); |
---|
3253 | 3477 | |
---|
3254 | 3478 | // if (!(max > 0)) |
---|
3255 | | - assert(max > 0); |
---|
3256 | | - |
---|
| 3479 | + //assert(max > 0); |
---|
| 3480 | + assert(max >= 0); |
---|
| 3481 | + |
---|
3257 | 3482 | x /= max; |
---|
3258 | 3483 | y /= max; |
---|
3259 | 3484 | z /= max; |
---|
.. | .. |
---|
3516 | 3741 | */ |
---|
3517 | 3742 | } |
---|
3518 | 3743 | |
---|
| 3744 | + void GenerateNormals2(boolean crease) |
---|
| 3745 | + { |
---|
| 3746 | + cVector tempVector = new cVector(); |
---|
| 3747 | + |
---|
| 3748 | +// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>(); |
---|
| 3749 | +// |
---|
| 3750 | +// |
---|
| 3751 | +// for (int i=0; i<this.VertexCount(); i++) |
---|
| 3752 | +// { |
---|
| 3753 | +// Vertex v = this.GetVertex(i); |
---|
| 3754 | +// |
---|
| 3755 | +// tempVector.set(v); |
---|
| 3756 | +// |
---|
| 3757 | +// cVector n = tableBase.get(tempVector.ToFloat()); |
---|
| 3758 | +// |
---|
| 3759 | +// if (n != null) |
---|
| 3760 | +// { |
---|
| 3761 | +// continue; |
---|
| 3762 | +// } |
---|
| 3763 | +// |
---|
| 3764 | +// tableBase.put(new cVector(tempVector), new cVector(v.norm)); |
---|
| 3765 | +// } |
---|
| 3766 | + |
---|
| 3767 | + BoundaryRep tempSupport = this.support; |
---|
| 3768 | + |
---|
| 3769 | + this.support = null; |
---|
| 3770 | + |
---|
| 3771 | + BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this); |
---|
| 3772 | + |
---|
| 3773 | + this.support = tempSupport; |
---|
| 3774 | + |
---|
| 3775 | + //tempRep.Unstripify(); |
---|
| 3776 | + |
---|
| 3777 | + tempRep.GenerateNormals2(crease); |
---|
| 3778 | + |
---|
| 3779 | + boolean keepnormal = Vertex.normalmode; |
---|
| 3780 | + boolean epsequal = Grafreed.epsequal; |
---|
| 3781 | + |
---|
| 3782 | + Vertex.normalmode = false; |
---|
| 3783 | + Grafreed.epsequal = false; // A bit strange |
---|
| 3784 | + |
---|
| 3785 | + // No need to have a match for vertex counts. |
---|
| 3786 | + |
---|
| 3787 | + java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>(); |
---|
| 3788 | + |
---|
| 3789 | + for (int i=0; i<tempRep.VertexCount(); i++) |
---|
| 3790 | + { |
---|
| 3791 | + Vertex v = tempRep.GetVertex(i); |
---|
| 3792 | + |
---|
| 3793 | + cVector n = table.get(tempVector.ToFloat()); |
---|
| 3794 | + |
---|
| 3795 | + if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0) |
---|
| 3796 | + { |
---|
| 3797 | + //continue; |
---|
| 3798 | + } |
---|
| 3799 | + |
---|
| 3800 | + tempVector.set(v); |
---|
| 3801 | + |
---|
| 3802 | + //cVector nBase = tableBase.get(tempVector); |
---|
| 3803 | + |
---|
| 3804 | + //if (v.norm.dot(nBase) < 0.9) |
---|
| 3805 | + //{ |
---|
| 3806 | + // continue; |
---|
| 3807 | + //} |
---|
| 3808 | + |
---|
| 3809 | + if (n != null && n.x == 1 && n.y == 0 && n.z == 0) |
---|
| 3810 | + { |
---|
| 3811 | + //continue; |
---|
| 3812 | + } |
---|
| 3813 | + |
---|
| 3814 | + if (n != null) |
---|
| 3815 | + { |
---|
| 3816 | +// if (n.dot(v.norm) < 0) |
---|
| 3817 | +// n.sub(v.norm); |
---|
| 3818 | +// else |
---|
| 3819 | +// n.add(v.norm); |
---|
| 3820 | +// |
---|
| 3821 | +// n.normalize(); |
---|
| 3822 | + continue; |
---|
| 3823 | + } |
---|
| 3824 | + |
---|
| 3825 | + table.put(new cVector(tempVector), new cVector(v.norm)); |
---|
| 3826 | + } |
---|
| 3827 | + |
---|
| 3828 | + for (int i=0; i<this.VertexCount(); i++) |
---|
| 3829 | + { |
---|
| 3830 | + Vertex v = this.GetVertex(i); |
---|
| 3831 | + |
---|
| 3832 | + tempVector.set(v); |
---|
| 3833 | + |
---|
| 3834 | + cVector n = table.get(tempVector.ToFloat()); |
---|
| 3835 | + |
---|
| 3836 | + //if (n.dot(v.norm) < 0) |
---|
| 3837 | + if (n == null) |
---|
| 3838 | + continue; |
---|
| 3839 | + |
---|
| 3840 | + LA.vecCopy(n, v.norm); |
---|
| 3841 | + |
---|
| 3842 | + this.SetVertex(v, i); |
---|
| 3843 | + } |
---|
| 3844 | + |
---|
| 3845 | + Grafreed.epsequal = epsequal; |
---|
| 3846 | + Vertex.normalmode = keepnormal; |
---|
| 3847 | + } |
---|
| 3848 | + |
---|
3519 | 3849 | void GenerateNormals(boolean crease) |
---|
3520 | 3850 | { |
---|
3521 | 3851 | boolean wastrim = trimmed; |
---|
.. | .. |
---|
3532 | 3862 | } |
---|
3533 | 3863 | |
---|
3534 | 3864 | Trim(true/*wastrim*/,true,crease,wasstrip,false); |
---|
| 3865 | + } |
---|
| 3866 | + |
---|
| 3867 | + void GenerateNormalsMesh() |
---|
| 3868 | + { |
---|
| 3869 | + if (stripified) |
---|
| 3870 | + { |
---|
| 3871 | + Unstripify(); |
---|
| 3872 | + } |
---|
| 3873 | + |
---|
| 3874 | + if (trimmed) |
---|
| 3875 | + { |
---|
| 3876 | + normals = null; |
---|
| 3877 | + } |
---|
| 3878 | + else |
---|
| 3879 | + { |
---|
| 3880 | + for (int i=VertexCount(); --i>=0;) |
---|
| 3881 | + { |
---|
| 3882 | + Vertex v = GetVertex(i); |
---|
| 3883 | + |
---|
| 3884 | + v.norm = null; |
---|
| 3885 | + } |
---|
| 3886 | + } |
---|
3535 | 3887 | } |
---|
3536 | 3888 | |
---|
3537 | 3889 | void GenNormalsJME() |
---|
.. | .. |
---|
3656 | 4008 | NormalGenerator ng; |
---|
3657 | 4009 | |
---|
3658 | 4010 | if (crease) |
---|
3659 | | - ng = new NormalGenerator(Math.PI/6); // default is 44 degrees (or Math.PI/3); // /4); |
---|
| 4011 | + ng = new NormalGenerator(Math.PI/4); // default is 44 degrees (or Math.PI/3); // /4); |
---|
3660 | 4012 | else |
---|
3661 | 4013 | ng = new NormalGenerator(Math.PI); // (Math.PI / 3); // /4); |
---|
3662 | 4014 | |
---|
.. | .. |
---|
3674 | 4026 | //System.out.println("NEW = " + positions.length); |
---|
3675 | 4027 | uvmap = new float[ta.getVertexCount() * 2]; |
---|
3676 | 4028 | |
---|
3677 | | - colors = new float[ta.getVertexCount()]; // * 3]; |
---|
3678 | | - |
---|
3679 | 4029 | ta.getCoordinates(0, positions); |
---|
3680 | 4030 | ta.getNormals(0, normals); |
---|
3681 | 4031 | // ta.getColors(0, colors); |
---|
.. | .. |
---|
3683 | 4033 | |
---|
3684 | 4034 | System.out.println("UV = " + uvmap[2] + ", " + uvmap[3] + ";"); |
---|
3685 | 4035 | |
---|
| 4036 | + colors = null; |
---|
| 4037 | +// colors = new float[ta.getVertexCount()]; // * 3]; |
---|
| 4038 | +// |
---|
| 4039 | +// for (int i=colors.length; --i>=0;) |
---|
| 4040 | +// { |
---|
| 4041 | +// colors[i] = 1; |
---|
| 4042 | +// } |
---|
| 4043 | + |
---|
3686 | 4044 | triangles = new int[ta.getVertexCount()]; |
---|
3687 | 4045 | |
---|
3688 | 4046 | for (int i = 0; i < triangles.length; i++) |
---|
3689 | 4047 | { |
---|
3690 | 4048 | triangles[i] = i; |
---|
3691 | 4049 | } |
---|
| 4050 | + |
---|
| 4051 | +// Untrim(); |
---|
| 4052 | + if (!trimmed) |
---|
| 4053 | + MergeNormals(); |
---|
3692 | 4054 | } |
---|
3693 | 4055 | } |
---|
3694 | 4056 | |
---|
.. | .. |
---|
3716 | 4078 | positions = new float[3 * ga.getVertexCount()]; |
---|
3717 | 4079 | normals = new float[3 * ga.getVertexCount()]; |
---|
3718 | 4080 | uvmap = new float[2 * ga.getVertexCount()]; |
---|
3719 | | - colors = new float[1 * ga.getVertexCount()]; |
---|
3720 | 4081 | |
---|
3721 | 4082 | tsa.getCoordinates(0, positions); |
---|
3722 | 4083 | tsa.getNormals(0, normals); |
---|
3723 | 4084 | tsa.getTextureCoordinates(0, 0, uvmap); |
---|
3724 | 4085 | // tsa.getColors(0, colors); |
---|
| 4086 | + |
---|
| 4087 | + colors = null; |
---|
| 4088 | +// colors = new float[1 * ga.getVertexCount()]; |
---|
| 4089 | +// for (int i=colors.length; --i>=0;) |
---|
| 4090 | +// { |
---|
| 4091 | +// colors[i] = 1; |
---|
| 4092 | +// } |
---|
3725 | 4093 | |
---|
3726 | 4094 | int stripcount = tsa.getNumStrips(); |
---|
3727 | 4095 | triangles = new int[stripcount]; |
---|
.. | .. |
---|
3730 | 4098 | stripified = true; |
---|
3731 | 4099 | } catch (ClassCastException e) |
---|
3732 | 4100 | { |
---|
| 4101 | + // ??? aug 2019 |
---|
3733 | 4102 | TriangleArray ta = (TriangleArray) ga; |
---|
3734 | 4103 | |
---|
3735 | 4104 | positions = new float[3 * ga.getVertexCount()]; |
---|
.. | .. |
---|
3744 | 4113 | triangles = new int[1]; |
---|
3745 | 4114 | triangles[0] = 3; |
---|
3746 | 4115 | } |
---|
| 4116 | + |
---|
| 4117 | + //Untrim(); |
---|
| 4118 | + if (!trimmed) |
---|
| 4119 | + MergeNormals(); |
---|
3747 | 4120 | } |
---|
3748 | 4121 | |
---|
3749 | 4122 | /* |
---|
.. | .. |
---|
3776 | 4149 | for (int i = 0; i < VertexCount(); i++) |
---|
3777 | 4150 | { |
---|
3778 | 4151 | Vertex v = GetVertex(i); |
---|
| 4152 | + |
---|
| 4153 | + vertextemp.set(v); |
---|
| 4154 | + |
---|
3779 | 4155 | //if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0) |
---|
3780 | 4156 | { |
---|
3781 | | - GenerateNormal(i, v); |
---|
3782 | | - SetVertex(v, i); |
---|
| 4157 | + if (!GenerateNormal(i, vertextemp)) |
---|
| 4158 | + continue; |
---|
| 4159 | + |
---|
| 4160 | + if (v.norm.dot(vertextemp.norm) < 0) |
---|
| 4161 | + vertextemp.norm.mul(-1); |
---|
| 4162 | + |
---|
| 4163 | + if (v.norm.dot(vertextemp.norm) < 0.9) |
---|
| 4164 | + SetVertex(vertextemp, i); |
---|
3783 | 4165 | } |
---|
3784 | 4166 | } |
---|
3785 | 4167 | |
---|
3786 | 4168 | Vertex.normalmode = false; |
---|
3787 | 4169 | } |
---|
3788 | 4170 | |
---|
| 4171 | + void MergeNormals() |
---|
| 4172 | + { |
---|
| 4173 | + assert(!trimmed); |
---|
| 4174 | + |
---|
| 4175 | + boolean smooth = Grafreed.smoothmode; |
---|
| 4176 | + boolean link = Grafreed.linkUV; |
---|
| 4177 | + Grafreed.smoothmode = true; |
---|
| 4178 | + Grafreed.linkUV = true; |
---|
| 4179 | + |
---|
| 4180 | + System.out.println("#Vertex = " + VertexCount()); |
---|
| 4181 | + System.out.println("#Face = " + FaceCount()); |
---|
| 4182 | + |
---|
| 4183 | + java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>(); |
---|
| 4184 | + |
---|
| 4185 | + for (int i = 0; i < VertexCount(); i++) |
---|
| 4186 | + { |
---|
| 4187 | + Vertex v = GetVertex(i); |
---|
| 4188 | + |
---|
| 4189 | + if (!table.contains(v)) |
---|
| 4190 | + { |
---|
| 4191 | + table.add(v); |
---|
| 4192 | + } |
---|
| 4193 | + } |
---|
| 4194 | + |
---|
| 4195 | + Grafreed.smoothmode = smooth; |
---|
| 4196 | + Grafreed.linkUV = link; |
---|
| 4197 | + |
---|
| 4198 | +// for (int i = 0; i < VertexCount(); i++) |
---|
| 4199 | +// { |
---|
| 4200 | +// Vertex v = GetVertex(i); |
---|
| 4201 | +// |
---|
| 4202 | +// table.add(v); |
---|
| 4203 | +// } |
---|
| 4204 | + |
---|
| 4205 | + } |
---|
| 4206 | + |
---|
3789 | 4207 | static cVector temp1 = new cVector(); |
---|
3790 | 4208 | static cVector temp2 = new cVector(); |
---|
3791 | 4209 | static cVector temp3 = new cVector(); |
---|
3792 | 4210 | |
---|
3793 | | - void GenerateNormal(int index, Vertex v) |
---|
| 4211 | + boolean GenerateNormal(int index, Vertex v) |
---|
3794 | 4212 | { |
---|
3795 | 4213 | //System.out.println("Old normal = " + v.norm); |
---|
3796 | 4214 | LA.setVector(v.norm, 0, 0, 0); |
---|
.. | .. |
---|
3819 | 4237 | LA.vecSub(p/*.pos*/, v/*.pos*/, temp1); |
---|
3820 | 4238 | LA.vecSub(q/*.pos*/, v/*.pos*/, temp2); |
---|
3821 | 4239 | } |
---|
| 4240 | + else |
---|
| 4241 | + { |
---|
| 4242 | + continue; |
---|
| 4243 | + } |
---|
3822 | 4244 | |
---|
3823 | 4245 | //LA.vecNormalize(temp1); |
---|
3824 | 4246 | //LA.vecNormalize(temp2); |
---|
.. | .. |
---|
3829 | 4251 | double s = temp3.length(); |
---|
3830 | 4252 | //double c = temp2.dot(temp1); |
---|
3831 | 4253 | |
---|
| 4254 | + if (s == 0) |
---|
| 4255 | + return false; |
---|
| 4256 | + |
---|
3832 | 4257 | float angle = 1; // (float) Math.atan2(s, c); |
---|
3833 | 4258 | //if(angle < 0) angle = -angle; |
---|
3834 | 4259 | |
---|
3835 | 4260 | //LA.vecNormalize(temp3); |
---|
3836 | 4261 | LA.vecScale(temp3, angle / s); |
---|
3837 | 4262 | |
---|
| 4263 | +// if (temp3.dot(v.norm) < 0) |
---|
| 4264 | +// assert(temp3.dot(v.norm) >= 0); |
---|
| 4265 | + |
---|
3838 | 4266 | LA.vecAdd(temp3, v.norm, v.norm); |
---|
3839 | 4267 | } |
---|
3840 | 4268 | |
---|
3841 | 4269 | LA.vecNormalize(v.norm); |
---|
3842 | 4270 | //System.out.println("New normal = " + v.norm); |
---|
| 4271 | + |
---|
| 4272 | + return true; |
---|
3843 | 4273 | } |
---|
3844 | 4274 | |
---|
3845 | 4275 | double Arccos(double x) |
---|
.. | .. |
---|
4233 | 4663 | int count = VertexCount(); |
---|
4234 | 4664 | |
---|
4235 | 4665 | // mars 2014 |
---|
4236 | | - while (step >= count) |
---|
| 4666 | + while (step > count) |
---|
4237 | 4667 | step /= 10; |
---|
4238 | 4668 | |
---|
4239 | 4669 | for (int i = 0; i < count; i+=step) |
---|
.. | .. |
---|
4381 | 4811 | } |
---|
4382 | 4812 | } |
---|
4383 | 4813 | |
---|
4384 | | - void CullVertex(javax.media.opengl.GL gl, boolean shadow) |
---|
| 4814 | + void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED) |
---|
4385 | 4815 | { |
---|
4386 | 4816 | CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z, |
---|
4387 | 4817 | CameraPane.tempmat,0, CameraPane.tempmat2,0, |
---|
.. | .. |
---|
4413 | 4843 | // june 2014 |
---|
4414 | 4844 | // Camera parentcam = cam; |
---|
4415 | 4845 | // |
---|
4416 | | -// if (cam == CameraPane.theRenderer.cameras[0]) |
---|
| 4846 | +// if (cam == Globals.theRenderer.cameras[0]) |
---|
4417 | 4847 | // { |
---|
4418 | | -// parentcam = CameraPane.theRenderer.cameras[1]; |
---|
| 4848 | +// parentcam = Globals.theRenderer.cameras[1]; |
---|
4419 | 4849 | // } |
---|
4420 | 4850 | // |
---|
4421 | | -// if (cam == CameraPane.theRenderer.cameras[1]) |
---|
| 4851 | +// if (cam == Globals.theRenderer.cameras[1]) |
---|
4422 | 4852 | // { |
---|
4423 | | -// parentcam = CameraPane.theRenderer.cameras[0]; |
---|
| 4853 | +// parentcam = Globals.theRenderer.cameras[0]; |
---|
4424 | 4854 | // } |
---|
4425 | 4855 | |
---|
4426 | 4856 | gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0); |
---|
.. | .. |
---|
4546 | 4976 | { |
---|
4547 | 4977 | i3 = positions.length-3; |
---|
4548 | 4978 | i2 = uvmap.length - 2; |
---|
4549 | | - new Exception().printStackTrace(); |
---|
| 4979 | + //new Exception().printStackTrace(); |
---|
4550 | 4980 | } |
---|
4551 | 4981 | |
---|
4552 | 4982 | v./*pos.*/x = positions[i3]; |
---|
4553 | 4983 | v./*pos.*/y = positions[i3 + 1]; |
---|
4554 | 4984 | v./*pos.*/z = positions[i3 + 2]; |
---|
4555 | 4985 | |
---|
4556 | | - v.norm.x = normals[i3]; |
---|
4557 | | - v.norm.y = normals[i3 + 1]; |
---|
4558 | | - v.norm.z = normals[i3 + 2]; |
---|
| 4986 | + if (normals == null) |
---|
| 4987 | + { |
---|
| 4988 | + v.norm.x = 0; |
---|
| 4989 | + v.norm.y = 0; |
---|
| 4990 | + v.norm.z = 0; |
---|
| 4991 | + } |
---|
| 4992 | + else |
---|
| 4993 | + { |
---|
| 4994 | + v.norm.x = normals[i3]; |
---|
| 4995 | + v.norm.y = normals[i3 + 1]; |
---|
| 4996 | + v.norm.z = normals[i3 + 2]; |
---|
| 4997 | + } |
---|
4559 | 4998 | |
---|
4560 | 4999 | v.s = uvmap[i2]; |
---|
4561 | 5000 | v.t = uvmap[i2 + 1]; |
---|
.. | .. |
---|
4846 | 5285 | return verticesCopy; |
---|
4847 | 5286 | } |
---|
4848 | 5287 | |
---|
4849 | | - void PreprocessOcclusion(CameraPane cp, double[][] transform) |
---|
| 5288 | + void PreprocessOcclusion(iCameraPane cp, double[][] transform) |
---|
4850 | 5289 | { |
---|
4851 | 5290 | if (//!trimmed || |
---|
4852 | 5291 | AOdone) |
---|
.. | .. |
---|
4855 | 5294 | return; |
---|
4856 | 5295 | } |
---|
4857 | 5296 | |
---|
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; |
---|
| 5297 | + cp.PrepOcclusion(this, transform); |
---|
4932 | 5298 | |
---|
4933 | 5299 | AOdone = true; |
---|
4934 | 5300 | } |
---|
.. | .. |
---|
5343 | 5709 | |
---|
5344 | 5710 | transient int nbbadfaces; // ?? = 1000000; |
---|
5345 | 5711 | |
---|
5346 | | - int ChooseTriangle() |
---|
| 5712 | + /* |
---|
| 5713 | + */ |
---|
| 5714 | + int ChooseTriangle(boolean firstEquilateral) |
---|
5347 | 5715 | { |
---|
5348 | 5716 | int chosen = -1; |
---|
5349 | 5717 | |
---|
5350 | 5718 | double minweight = 1E10; |
---|
5351 | 5719 | |
---|
| 5720 | + int step = 8; // ? |
---|
| 5721 | + |
---|
| 5722 | + if (firstEquilateral) |
---|
| 5723 | + step = 1; |
---|
| 5724 | + |
---|
5352 | 5725 | nbbadfaces = 0; |
---|
5353 | | - for (int i=0; i<faces.size(); i+=8) |
---|
| 5726 | + for (int i=0; i<faces.size(); i+=step) |
---|
5354 | 5727 | // for (int i=faces.size(); (i-=8)>=0;) |
---|
5355 | 5728 | { |
---|
5356 | 5729 | Face face = (Face) faces.get(i); |
---|
| 5730 | + |
---|
| 5731 | + if (face.used) |
---|
| 5732 | + continue; |
---|
5357 | 5733 | |
---|
5358 | 5734 | if (!Valid(face)) |
---|
5359 | 5735 | { |
---|
.. | .. |
---|
5363 | 5739 | |
---|
5364 | 5740 | if (Boundary(face)) |
---|
5365 | 5741 | continue; |
---|
| 5742 | + |
---|
| 5743 | +// if (Boundary(face.p)) |
---|
| 5744 | +// continue; |
---|
| 5745 | +// |
---|
| 5746 | +// if (Boundary(face.q)) |
---|
| 5747 | +// continue; |
---|
| 5748 | +// |
---|
| 5749 | +// if (Boundary(face.r)) |
---|
| 5750 | +// continue; |
---|
5366 | 5751 | |
---|
5367 | 5752 | if (!ValidValence(face)) |
---|
5368 | 5753 | continue; |
---|
.. | .. |
---|
5375 | 5760 | //?? if (face.weight < 0) |
---|
5376 | 5761 | // continue; |
---|
5377 | 5762 | |
---|
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) |
---|
| 5763 | + if (firstEquilateral) |
---|
5385 | 5764 | { |
---|
5386 | | - minweight = weight; |
---|
| 5765 | + if (OneFaceUsed(links.get(face.p))) |
---|
| 5766 | + continue; |
---|
| 5767 | + |
---|
| 5768 | + if (OneFaceUsed(links.get(face.q))) |
---|
| 5769 | + continue; |
---|
| 5770 | + |
---|
| 5771 | + if (OneFaceUsed(links.get(face.r))) |
---|
| 5772 | + continue; |
---|
| 5773 | + |
---|
5387 | 5774 | chosen = i; |
---|
5388 | | - if (minweight == 0) |
---|
5389 | | - break; |
---|
| 5775 | + break; |
---|
| 5776 | + } |
---|
| 5777 | + else |
---|
| 5778 | + { |
---|
| 5779 | + double K = 1; // 0.01; // .25; |
---|
| 5780 | + |
---|
| 5781 | + double factor = (1-K)*face.nbiterations + K; //*face.weight; |
---|
| 5782 | + |
---|
| 5783 | + double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor; |
---|
| 5784 | + |
---|
| 5785 | + if (minweight > weight) |
---|
| 5786 | + { |
---|
| 5787 | + minweight = weight; |
---|
| 5788 | + chosen = i; |
---|
| 5789 | + if (minweight == 0) |
---|
| 5790 | + break; |
---|
| 5791 | + } |
---|
5390 | 5792 | } |
---|
5391 | 5793 | } |
---|
5392 | 5794 | |
---|
5393 | 5795 | return chosen; |
---|
| 5796 | + } |
---|
| 5797 | + |
---|
| 5798 | + private boolean OneFaceUsed(Vector<Face> faces) |
---|
| 5799 | + { |
---|
| 5800 | + if (faces.size() != 6) |
---|
| 5801 | + return true; |
---|
| 5802 | + |
---|
| 5803 | + for (int i=0; i<6; i+=1) |
---|
| 5804 | + { |
---|
| 5805 | + if (faces.get(i).used) |
---|
| 5806 | + { |
---|
| 5807 | + return true; |
---|
| 5808 | + } |
---|
| 5809 | + } |
---|
| 5810 | + |
---|
| 5811 | + return false; |
---|
5394 | 5812 | } |
---|
5395 | 5813 | |
---|
5396 | 5814 | static boolean remove3valence = true; |
---|
.. | .. |
---|
5426 | 5844 | } |
---|
5427 | 5845 | else |
---|
5428 | 5846 | { |
---|
5429 | | - assert(links.size() == vertices.size()); |
---|
| 5847 | + // TODO Grafreed.Assert(links.size() == vertices.size()); |
---|
5430 | 5848 | |
---|
5431 | 5849 | links.setSize(vertices.size()); |
---|
5432 | 5850 | for (int i=vertices.size(); --i>=0;) |
---|
.. | .. |
---|
5434 | 5852 | // linkstouched[i] = false; |
---|
5435 | 5853 | if (links.get(i) == null) // ?? |
---|
5436 | 5854 | { |
---|
| 5855 | + new Exception().printStackTrace(); |
---|
5437 | 5856 | links.set(i, new Vector(8)); |
---|
5438 | 5857 | // linkstouched[i] = true; |
---|
5439 | 5858 | } |
---|
.. | .. |
---|
5444 | 5863 | } |
---|
5445 | 5864 | } |
---|
5446 | 5865 | |
---|
| 5866 | + boolean once = false; |
---|
| 5867 | + |
---|
5447 | 5868 | for (int i=faces.size(); --i>=0;) |
---|
5448 | 5869 | { |
---|
5449 | 5870 | Face face = (Face) faces.get(i); |
---|
.. | .. |
---|
5455 | 5876 | //if (linkstouched[face.r]) |
---|
5456 | 5877 | links.get(face.r).add(face); |
---|
5457 | 5878 | |
---|
| 5879 | + if (face.used) |
---|
| 5880 | + once = true; |
---|
| 5881 | + |
---|
5458 | 5882 | face.good = 1; |
---|
5459 | 5883 | face.boundary = -1; |
---|
5460 | 5884 | } |
---|
.. | .. |
---|
6226 | 6650 | |
---|
6227 | 6651 | void InitWeights() |
---|
6228 | 6652 | { |
---|
| 6653 | + new Exception().printStackTrace(); |
---|
6229 | 6654 | System.exit(0); |
---|
6230 | 6655 | int n = 0; |
---|
6231 | 6656 | int b = 0; |
---|
.. | .. |
---|
6819 | 7244 | return (face.boundary = 1) == 1; |
---|
6820 | 7245 | } |
---|
6821 | 7246 | |
---|
| 7247 | + // June 2019 |
---|
| 7248 | + if (true) |
---|
| 7249 | + return (face.boundary = 0) == 1; |
---|
| 7250 | + |
---|
6822 | 7251 | // reverse triangle test |
---|
6823 | 7252 | q1.set(p); |
---|
6824 | 7253 | q2.set(q); |
---|
.. | .. |
---|
7075 | 7504 | assert(f2.contains(i)); |
---|
7076 | 7505 | assert(f3.contains(i)); |
---|
7077 | 7506 | |
---|
| 7507 | + // when r is the "center", p is along the boundary |
---|
7078 | 7508 | while (f0.r != i) |
---|
7079 | 7509 | { |
---|
7080 | 7510 | int t = f0.p; |
---|
.. | .. |
---|
7131 | 7561 | f0 = f3; |
---|
7132 | 7562 | f3 = t; |
---|
7133 | 7563 | } |
---|
7134 | | - atleastone = true; |
---|
7135 | 7564 | |
---|
| 7565 | + int va = f0.q; |
---|
| 7566 | + int vb = f0.r; |
---|
| 7567 | + int vc = -1; |
---|
| 7568 | + |
---|
| 7569 | + Face toremove1 = null; |
---|
| 7570 | + Face toremove2 = null; |
---|
| 7571 | + |
---|
| 7572 | + // f0 is the buffer for the first new triangle, |
---|
| 7573 | + // and otherf is the other upper one. |
---|
7136 | 7574 | Face otherf = null; |
---|
7137 | 7575 | |
---|
7138 | 7576 | if (f1.contains(f0.p)) |
---|
7139 | 7577 | { |
---|
7140 | 7578 | if (f1.p == f0.p) |
---|
7141 | 7579 | { |
---|
| 7580 | + assert(false); |
---|
7142 | 7581 | f0.r = f1.q; |
---|
7143 | 7582 | } |
---|
7144 | 7583 | else |
---|
7145 | 7584 | { |
---|
7146 | 7585 | assert(f1.q == f0.p); |
---|
7147 | | - f0.r = f1.p; |
---|
| 7586 | + vc = f1.p; |
---|
7148 | 7587 | } |
---|
7149 | 7588 | |
---|
7150 | 7589 | otherf = f2; |
---|
7151 | | - faces.remove(f1); |
---|
7152 | | - faces.remove(f3); |
---|
| 7590 | + toremove1 = f1; |
---|
| 7591 | + toremove2 = f3; |
---|
7153 | 7592 | } |
---|
7154 | 7593 | else |
---|
7155 | 7594 | if (f2.contains(f0.p)) |
---|
7156 | 7595 | { |
---|
7157 | 7596 | if (f2.p == f0.p) |
---|
7158 | 7597 | { |
---|
| 7598 | + assert(false); |
---|
7159 | 7599 | f0.r = f2.q; |
---|
7160 | 7600 | } |
---|
7161 | 7601 | else |
---|
7162 | 7602 | { |
---|
7163 | 7603 | assert(f2.q == f0.p); |
---|
7164 | | - f0.r = f2.p; |
---|
| 7604 | + vc = f2.p; |
---|
7165 | 7605 | } |
---|
7166 | 7606 | |
---|
7167 | 7607 | otherf = f3; |
---|
7168 | | - faces.remove(f1); |
---|
7169 | | - faces.remove(f2); |
---|
| 7608 | + toremove1 = f1; |
---|
| 7609 | + toremove2 = f2; |
---|
7170 | 7610 | } |
---|
7171 | 7611 | if (f3.contains(f0.p)) |
---|
7172 | 7612 | { |
---|
7173 | 7613 | if (f3.p == f0.p) |
---|
7174 | 7614 | { |
---|
| 7615 | +// assert(false); |
---|
| 7616 | + new Exception().printStackTrace(); |
---|
7175 | 7617 | f0.r = f3.q; |
---|
7176 | 7618 | } |
---|
7177 | 7619 | else |
---|
7178 | 7620 | { |
---|
7179 | 7621 | assert(f3.q == f0.p); |
---|
7180 | | - f0.r = f3.p; |
---|
| 7622 | + vc = f3.p; |
---|
7181 | 7623 | } |
---|
7182 | 7624 | |
---|
7183 | 7625 | otherf = f1; |
---|
7184 | | - faces.remove(f2); |
---|
7185 | | - faces.remove(f3); |
---|
| 7626 | + toremove1 = f2; |
---|
| 7627 | + toremove2 = f3; |
---|
7186 | 7628 | } |
---|
| 7629 | + |
---|
| 7630 | + vertextemp.set(vertices.get(va)); |
---|
| 7631 | + vertextemp.sub(vertices.get(vb)); |
---|
| 7632 | + vertextemp.normalize(); |
---|
| 7633 | + vertextemp2.set(vertices.get(vc)); |
---|
| 7634 | + vertextemp2.sub(vertices.get(vb)); |
---|
| 7635 | + vertextemp2.normalize(); |
---|
| 7636 | + |
---|
| 7637 | + if (vertextemp.dot(vertextemp2) > -0.95) |
---|
| 7638 | + { |
---|
| 7639 | + continue; |
---|
| 7640 | + } |
---|
| 7641 | + |
---|
| 7642 | + atleastone = true; |
---|
| 7643 | + |
---|
| 7644 | + f0.r = vc; |
---|
| 7645 | + |
---|
| 7646 | + faces.remove(toremove1); |
---|
| 7647 | + faces.remove(toremove2); |
---|
7187 | 7648 | |
---|
7188 | 7649 | if (!f0.contains(otherf.p)) |
---|
7189 | 7650 | { |
---|
.. | .. |
---|
7236 | 7697 | //InitWeights(); |
---|
7237 | 7698 | } |
---|
7238 | 7699 | |
---|
7239 | | - int chosen = ChooseTriangle(); // Best is slow and not really better |
---|
| 7700 | + int chosen = ChooseTriangle(true); // Best is slow and not really better |
---|
7240 | 7701 | |
---|
7241 | 7702 | if (chosen == -1) |
---|
7242 | 7703 | { |
---|
.. | .. |
---|
7250 | 7711 | //remove3valence = false; |
---|
7251 | 7712 | // InitWeights(); |
---|
7252 | 7713 | |
---|
7253 | | - chosen = ChooseTriangle(); |
---|
| 7714 | + chosen = ChooseTriangle(true); |
---|
7254 | 7715 | } |
---|
7255 | 7716 | } |
---|
7256 | 7717 | |
---|
.. | .. |
---|
7391 | 7852 | Trim(); |
---|
7392 | 7853 | Untrim(); |
---|
7393 | 7854 | |
---|
7394 | | - BoundaryRep tmp = new BoundaryRep(); // (BoundaryRep) GraphreeD.clone(this); |
---|
| 7855 | + BoundaryRep tmp = new BoundaryRep(); // (BoundaryRep) GrafreeD.clone(this); |
---|
7395 | 7856 | |
---|
7396 | 7857 | double minx = Float.POSITIVE_INFINITY; |
---|
7397 | 7858 | double maxx = Float.NEGATIVE_INFINITY; |
---|
.. | .. |
---|
7526 | 7987 | |
---|
7527 | 7988 | // boolean lock; |
---|
7528 | 7989 | |
---|
7529 | | - void SplitInTwo(boolean reduction34, boolean onlyone) |
---|
| 7990 | + boolean SplitInTwo(boolean reduction34, boolean onlyone) |
---|
7530 | 7991 | { |
---|
7531 | 7992 | if (stripified) |
---|
7532 | 7993 | { |
---|
.. | .. |
---|
7554 | 8015 | s3 = new cVector(); |
---|
7555 | 8016 | } |
---|
7556 | 8017 | |
---|
7557 | | - CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
| 8018 | + Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
7558 | 8019 | |
---|
7559 | 8020 | try |
---|
7560 | 8021 | { |
---|
.. | .. |
---|
7563 | 8024 | { |
---|
7564 | 8025 | System.err.println("EXCEPTION CAUGHT"); |
---|
7565 | 8026 | e.printStackTrace(); |
---|
7566 | | - return; |
---|
| 8027 | + return false; |
---|
7567 | 8028 | } catch (Error e) |
---|
7568 | 8029 | { |
---|
7569 | 8030 | System.err.println("ERROR CAUGHT"); |
---|
7570 | 8031 | e.printStackTrace(); |
---|
7571 | | - return; |
---|
| 8032 | + return false; |
---|
7572 | 8033 | } |
---|
7573 | 8034 | |
---|
7574 | 8035 | System.out.println("# faces = " + faces.size()); |
---|
.. | .. |
---|
7578 | 8039 | { |
---|
7579 | 8040 | Face face = (Face) faces.get(i); |
---|
7580 | 8041 | |
---|
| 8042 | + face.used = false; |
---|
7581 | 8043 | face.nbiterations = 1; |
---|
7582 | 8044 | face.weight = -1; |
---|
7583 | 8045 | face.boundary = -1; |
---|
.. | .. |
---|
7629 | 8091 | nbbadfaces = faces.size(); |
---|
7630 | 8092 | //remove3valence = true; |
---|
7631 | 8093 | |
---|
| 8094 | + int count = 2; |
---|
| 8095 | + |
---|
| 8096 | + if (onlyone) |
---|
| 8097 | + count = 1; |
---|
| 8098 | + |
---|
7632 | 8099 | firstpass = true; |
---|
7633 | 8100 | |
---|
7634 | 8101 | int n = faces.size(); |
---|
.. | .. |
---|
7644 | 8111 | System.out.print('.'); |
---|
7645 | 8112 | } |
---|
7646 | 8113 | System.out.println(); |
---|
| 8114 | + boolean atleastone = false; |
---|
7647 | 8115 | int i = 0; |
---|
7648 | | - while (reduction34 || faces.size() > n/2) |
---|
| 8116 | + while (true) // reduction34 || faces.size() > n/2) |
---|
7649 | 8117 | { |
---|
7650 | 8118 | if (i++%100 == 0) |
---|
7651 | 8119 | { |
---|
7652 | | - CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
| 8120 | + Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
---|
7653 | 8121 | System.out.println("#faces = " + faces.size()); |
---|
7654 | 8122 | // if (i != 1) |
---|
7655 | 8123 | // break; |
---|
.. | .. |
---|
7667 | 8135 | { |
---|
7668 | 8136 | if (!RemoveOneTriangle()) |
---|
7669 | 8137 | break; |
---|
| 8138 | + |
---|
| 8139 | + atleastone = true; |
---|
7670 | 8140 | } |
---|
7671 | 8141 | // if (iterationcount == 0) |
---|
7672 | 8142 | // break; |
---|
.. | .. |
---|
7677 | 8147 | break; |
---|
7678 | 8148 | } |
---|
7679 | 8149 | firstpass = false; |
---|
7680 | | - if (onlyone) |
---|
7681 | | - break; // one triangle only |
---|
| 8150 | +// if (--count<0 && !reduction34) |
---|
| 8151 | +// break; // one triangle only |
---|
7682 | 8152 | } |
---|
7683 | 8153 | |
---|
7684 | 8154 | InitLinks(false); // for further display |
---|
.. | .. |
---|
7693 | 8163 | //Trim(true,cJME.gennormals,true,false); // doesn't work |
---|
7694 | 8164 | Trim(true,false,false,false,false); |
---|
7695 | 8165 | |
---|
7696 | | - CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); |
---|
| 8166 | + Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); |
---|
| 8167 | + |
---|
| 8168 | + return atleastone; |
---|
7697 | 8169 | } |
---|
7698 | 8170 | |
---|
7699 | 8171 | void UpdateIndices(Face face, Face minface) |
---|
.. | .. |
---|
7706 | 8178 | face.p = minface.p; |
---|
7707 | 8179 | //if (leafweights) |
---|
7708 | 8180 | face.good = 0; // false; |
---|
| 8181 | + face.used = true; |
---|
7709 | 8182 | } |
---|
7710 | 8183 | if (face.q == minface.p || face.q == minface.q || face.q == minface.r) |
---|
7711 | 8184 | { |
---|
7712 | 8185 | face.q = minface.p; |
---|
7713 | 8186 | //if (leafweights) |
---|
7714 | 8187 | face.good = 0; // false; |
---|
| 8188 | + face.used = true; |
---|
7715 | 8189 | } |
---|
7716 | 8190 | if (face.r == minface.p || face.r == minface.q || face.r == minface.r) |
---|
7717 | 8191 | { |
---|
7718 | 8192 | face.r = minface.p; |
---|
7719 | 8193 | //if (leafweights) |
---|
7720 | 8194 | face.good = 0; // false; |
---|
| 8195 | + face.used = true; |
---|
7721 | 8196 | } |
---|
7722 | 8197 | |
---|
7723 | 8198 | if (face.p >/*=*/ minface.q && face.p < minface.r) |
---|
.. | .. |
---|
7777 | 8252 | if (v == 2) |
---|
7778 | 8253 | vert = minface.r; |
---|
7779 | 8254 | // 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) |
---|
| 8255 | + Vector<Face> vertfaces = links.get(vert); |
---|
| 8256 | + for (int i=vertfaces.size(); --i>=0;) |
---|
7791 | 8257 | { |
---|
7792 | | - if (!leafweights) |
---|
| 8258 | + Face face = (Face) vertfaces.get(i); |
---|
| 8259 | + |
---|
| 8260 | + // if (face.weight == 10000) |
---|
| 8261 | + // continue; |
---|
| 8262 | + |
---|
| 8263 | + if (face.p == minface.p || face.q == minface.p || face.r == minface.p || |
---|
| 8264 | + face.p == minface.q || face.q == minface.q || face.r == minface.q || |
---|
| 8265 | + face.p == minface.r || face.q == minface.r || face.r == minface.r) |
---|
7793 | 8266 | { |
---|
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); |
---|
| 8267 | + if (!leafweights) |
---|
| 8268 | + { |
---|
| 8269 | + // if(minfaceweight <= 0) |
---|
| 8270 | + // assert(minfaceweight > 0); |
---|
| 8271 | + // |
---|
| 8272 | + // //FaceWeight(face); |
---|
| 8273 | + // if(face.weight < 0) |
---|
| 8274 | + // assert(face.weight >= 0); |
---|
| 8275 | + |
---|
| 8276 | + face.weight += minfaceweight; |
---|
| 8277 | + |
---|
| 8278 | + // if (face.weight >= 10000) |
---|
| 8279 | + // assert(face.weight < 10000); |
---|
| 8280 | + } |
---|
| 8281 | + else |
---|
| 8282 | + face.weight = -1; |
---|
| 8283 | + |
---|
| 8284 | + face.nbiterations += 1; |
---|
| 8285 | + face.boundary = -1; |
---|
| 8286 | + |
---|
| 8287 | + Vertex p = (Vertex)vertices.get(face.p); |
---|
| 8288 | + Vertex q = (Vertex)vertices.get(face.q); |
---|
| 8289 | + Vertex r = (Vertex)vertices.get(face.r); |
---|
| 8290 | + |
---|
| 8291 | + p.boundary = -1; |
---|
| 8292 | + q.boundary = -1; |
---|
| 8293 | + r.boundary = -1; |
---|
7805 | 8294 | } |
---|
7806 | 8295 | 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; |
---|
| 8296 | + assert(false); |
---|
7819 | 8297 | } |
---|
7820 | | - else |
---|
7821 | | - assert(false); |
---|
7822 | 8298 | } |
---|
7823 | | - } |
---|
7824 | 8299 | |
---|
7825 | 8300 | // TouchVertex(minface.p); |
---|
7826 | 8301 | // TouchVertex(minface.q); |
---|
.. | .. |
---|
8021 | 8496 | for (int i=vertfaces.size(); --i>=0;) |
---|
8022 | 8497 | { |
---|
8023 | 8498 | Face face = (Face) vertfaces.get(i); |
---|
| 8499 | + face.used = true; |
---|
8024 | 8500 | face.good = 0; // false; |
---|
8025 | 8501 | if (leafweights) |
---|
8026 | 8502 | face.weight = -1; |
---|
.. | .. |
---|
8067 | 8543 | if (!trimmed) |
---|
8068 | 8544 | return; |
---|
8069 | 8545 | |
---|
8070 | | - GraphreeD.linkUV = false; |
---|
| 8546 | + Grafreed.linkUV = false; |
---|
8071 | 8547 | |
---|
8072 | 8548 | try |
---|
8073 | 8549 | { |
---|
.. | .. |
---|
8275 | 8751 | return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices; |
---|
8276 | 8752 | } |
---|
8277 | 8753 | |
---|
8278 | | - static Camera localcamera = new Camera(); |
---|
8279 | | - static cVector from = new cVector(); |
---|
8280 | | - static cVector to = new cVector(); |
---|
8281 | 8754 | boolean trimmed = false; |
---|
8282 | 8755 | boolean stripified = false; |
---|
8283 | 8756 | transient boolean AOdone = false; |
---|
.. | .. |
---|
8285 | 8758 | /*transient*/ int maxIndexV = 0; |
---|
8286 | 8759 | /*transient*/ int bufV, bufF; |
---|
8287 | 8760 | // Raw version |
---|
8288 | | - private float[] positions; |
---|
8289 | | - private float[] normals; |
---|
| 8761 | + //private |
---|
| 8762 | + float[] positions; |
---|
| 8763 | + //private |
---|
| 8764 | + float[] normals; |
---|
8290 | 8765 | float[] colors; |
---|
8291 | 8766 | private float[] uvmap; |
---|
8292 | 8767 | private int[] triangles; |
---|
.. | .. |
---|
8300 | 8775 | int[] startvertices; |
---|
8301 | 8776 | float[] averagepoints; |
---|
8302 | 8777 | float[] extremepoints; |
---|
8303 | | - float[] supportsizes; // distance of closest point |
---|
| 8778 | + float[] supportminsize; // distance of closest point |
---|
| 8779 | + float[] supportmaxsize; // distance of fartest point |
---|
8304 | 8780 | |
---|
8305 | 8781 | transient Hashtable vertextable; |
---|
8306 | 8782 | /*transient*/ private Vertex[] verticesCopy; |
---|