.. | .. |
---|
161 | 161 | || FaceCount() != other.FaceCount() |
---|
162 | 162 | || !(indices == null ^ other.indices != null)) // july 2014 |
---|
163 | 163 | { |
---|
| 164 | + // The meshes have different structures. |
---|
164 | 165 | //new Exception().printStackTrace(); |
---|
165 | 166 | trimmed = other.trimmed; |
---|
166 | 167 | stripified = other.stripified; |
---|
.. | .. |
---|
172 | 173 | bufV = other.bufV; |
---|
173 | 174 | bufF = other.bufF; |
---|
174 | 175 | |
---|
175 | | - positions = (float[]) GrafreeD.clone(other.positions); |
---|
176 | | - normals = (float[]) GrafreeD.clone(other.normals); |
---|
177 | | - colors = (float[]) GrafreeD.clone(other.colors); |
---|
178 | | - uvmap = (float[]) GrafreeD.clone(other.uvmap); |
---|
179 | | - triangles = (int[]) GrafreeD.clone(other.triangles); |
---|
| 176 | + positions = (float[]) Grafreed.clone(other.positions); |
---|
| 177 | + normals = (float[]) Grafreed.clone(other.normals); |
---|
| 178 | + colors = (float[]) Grafreed.clone(other.colors); |
---|
| 179 | + uvmap = (float[]) Grafreed.clone(other.uvmap); |
---|
| 180 | + triangles = (int[]) Grafreed.clone(other.triangles); |
---|
180 | 181 | |
---|
181 | | - indices = (int[]) GrafreeD.clone(other.indices); |
---|
| 182 | + indices = (int[]) Grafreed.clone(other.indices); |
---|
182 | 183 | |
---|
183 | | - vertices = (Vector<Vertex>) GrafreeD.clone(other.vertices); |
---|
184 | | - faces = (Vector<Face>) GrafreeD.clone(other.faces); |
---|
| 184 | + vertices = (Vector<Vertex>) Grafreed.clone(other.vertices); |
---|
| 185 | + faces = (Vector<Face>) Grafreed.clone(other.faces); |
---|
185 | 186 | } |
---|
186 | 187 | else |
---|
187 | 188 | { |
---|
.. | .. |
---|
239 | 240 | } |
---|
240 | 241 | } |
---|
241 | 242 | |
---|
242 | | - Support[] InitConnections(BoundaryRep other) |
---|
| 243 | + transient Support[] cachesupports = null; |
---|
| 244 | + |
---|
| 245 | + Support[] InitConnections() |
---|
243 | 246 | { |
---|
244 | | - int n = other.startvertices.length-1; |
---|
| 247 | + if (cachesupports != null) |
---|
| 248 | + { |
---|
| 249 | + return cachesupports; |
---|
| 250 | + } |
---|
| 251 | + |
---|
| 252 | + int n = this.startvertices.length-1; |
---|
245 | 253 | |
---|
246 | 254 | Support[] supports = new Support[n]; |
---|
247 | 255 | |
---|
.. | .. |
---|
253 | 261 | |
---|
254 | 262 | for (int object=1; object<=n; object++) |
---|
255 | 263 | { |
---|
256 | | - int start = other.startvertices[object-1]; |
---|
257 | | - int end = other.startvertices[object]; |
---|
| 264 | + int start = this.startvertices[object-1]; |
---|
| 265 | + int end = this.startvertices[object]; |
---|
258 | 266 | |
---|
259 | 267 | if (start == end) |
---|
260 | 268 | continue; // ?? |
---|
261 | 269 | |
---|
| 270 | + /** |
---|
| 271 | + Vertex v2 = vertextemp; |
---|
| 272 | + v2.x = averagepoints[object*3]; |
---|
| 273 | + v2.y = averagepoints[object*3+1]; |
---|
| 274 | + v2.z = averagepoints[object*3+2]; |
---|
| 275 | + |
---|
| 276 | + //v2.set(GetVertex(this.startvertices[subsupport])); |
---|
| 277 | + |
---|
| 278 | + // projected point |
---|
| 279 | + Vertex v3 = vertextemp2; |
---|
| 280 | + //GetVertex(this.startvertices[subsupport]); |
---|
| 281 | + v3.x = extremepoints[object*3]; |
---|
| 282 | + v3.y = extremepoints[object*3+1]; |
---|
| 283 | + v3.z = extremepoints[object*3+2]; |
---|
| 284 | + |
---|
| 285 | + vect3.set(v3); // "X" axis apex |
---|
| 286 | + vect3.sub(v2); // origin (center) |
---|
| 287 | + vect3.normalize(); |
---|
| 288 | + /**/ |
---|
| 289 | + |
---|
262 | 290 | int linkcount = 0; |
---|
263 | 291 | |
---|
264 | 292 | int objectinlist = -1; |
---|
| 293 | + |
---|
| 294 | + Support subsupport = supports[object-1]; |
---|
265 | 295 | |
---|
266 | 296 | for (int object2=1; object2<=n; object2++) |
---|
267 | 297 | { |
---|
268 | 298 | for (int i = start; i < end; i++) |
---|
269 | 299 | { |
---|
270 | | - Vertex v = other.GetVertex(i); |
---|
| 300 | + Vertex v = this.GetVertex(i); |
---|
271 | 301 | |
---|
272 | | - // |
---|
273 | | - if (other.Contains(v, object2)) |
---|
| 302 | + // Check if v is close enough from any vertex of the given subobject. |
---|
| 303 | + if (this.Contains(v, object2)) |
---|
274 | 304 | { |
---|
275 | | - if (linkcount == supports[object-1].links.length) |
---|
| 305 | + if (linkcount == subsupport.links.length) |
---|
276 | 306 | break; |
---|
277 | 307 | |
---|
278 | 308 | if (object2 == object) |
---|
279 | 309 | objectinlist = linkcount; |
---|
280 | 310 | |
---|
281 | | - supports[object-1].links[linkcount++] = object2; |
---|
| 311 | + subsupport.links[linkcount++] = object2; |
---|
282 | 312 | break; |
---|
283 | 313 | } |
---|
284 | 314 | } |
---|
285 | 315 | } |
---|
286 | 316 | |
---|
287 | | - supports[object-1].links[linkcount] = -1; |
---|
| 317 | + subsupport.links[linkcount] = -1; |
---|
288 | 318 | |
---|
289 | 319 | if (objectinlist == -1) |
---|
290 | 320 | assert(objectinlist != -1); |
---|
.. | .. |
---|
293 | 323 | // assert(linkcount > 1); |
---|
294 | 324 | |
---|
295 | 325 | // show main support as blue |
---|
296 | | - int first = supports[object-1].links[0]; |
---|
297 | | - supports[object-1].links[0] = supports[object-1].links[objectinlist]; |
---|
298 | | - supports[object-1].links[objectinlist] = first; |
---|
| 326 | + int first = subsupport.links[0]; |
---|
| 327 | + subsupport.links[0] = subsupport.links[objectinlist]; |
---|
| 328 | + subsupport.links[objectinlist] = first; |
---|
299 | 329 | } |
---|
300 | 330 | |
---|
301 | 331 | for (int loop = 0; --loop>=0;) |
---|
.. | .. |
---|
353 | 383 | supports = supports2; |
---|
354 | 384 | } |
---|
355 | 385 | |
---|
356 | | - return supports; |
---|
| 386 | + return cachesupports = supports; |
---|
357 | 387 | } |
---|
358 | 388 | |
---|
359 | 389 | double Distance2(Vertex v, Vertex v2, double dist2beat, double[][] toRoot, int k) |
---|
.. | .. |
---|
500 | 530 | static Vertex vertextemp = new Vertex(true); |
---|
501 | 531 | static Vertex vertextemp2 = new Vertex(true); |
---|
502 | 532 | |
---|
503 | | - static double SEUIL = 0.1f; // 0.1 for rag doll; 0.07; |
---|
| 533 | + static double SEUIL = 0.05f; // 0.1 for rag doll; 0.07; |
---|
504 | 534 | |
---|
505 | 535 | // Compute weight of point w/r to this |
---|
506 | 536 | float ComputeWeight(Vertex v, double[][] toRoot, int k) |
---|
.. | .. |
---|
598 | 628 | // ; |
---|
599 | 629 | // |
---|
600 | 630 | |
---|
601 | | - supportsize = supportsizes[subsupport]; |
---|
| 631 | + supportsize = supportminsize[subsupport]; |
---|
602 | 632 | |
---|
603 | 633 | double K = supportsize / distmax; |
---|
604 | 634 | |
---|
.. | .. |
---|
650 | 680 | // if (supportsize * fadefactor > 1) |
---|
651 | 681 | // return 1; |
---|
652 | 682 | |
---|
653 | | - return supportsize * fadefactor; |
---|
| 683 | + return //supportsize * |
---|
| 684 | + supportsize * fadefactor; |
---|
654 | 685 | } |
---|
655 | 686 | |
---|
656 | 687 | void RecomputeBasis(BoundaryRep other, double[][] toRoot, Vertex v) |
---|
.. | .. |
---|
952 | 983 | |
---|
953 | 984 | // sept 2017 SEUIL = 0.1; // aout 2013 |
---|
954 | 985 | |
---|
955 | | - supports = InitConnections(other); |
---|
| 986 | + supports = other.InitConnections(); |
---|
956 | 987 | |
---|
957 | 988 | other.supports = supports; // should be the other way around... |
---|
958 | 989 | |
---|
.. | .. |
---|
1518 | 1549 | InitFaceIndices(); |
---|
1519 | 1550 | } |
---|
1520 | 1551 | |
---|
1521 | | - BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this); |
---|
| 1552 | + BoundaryRep rep = (BoundaryRep) Grafreed.clone(this); |
---|
1522 | 1553 | //float[] v = new float[100]; |
---|
1523 | 1554 | |
---|
1524 | 1555 | for (int loops=1; --loops>=0;) |
---|
.. | .. |
---|
1548 | 1579 | InitFaceIndices(); |
---|
1549 | 1580 | } |
---|
1550 | 1581 | |
---|
1551 | | - BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this); |
---|
| 1582 | + BoundaryRep rep = (BoundaryRep) Grafreed.clone(this); |
---|
1552 | 1583 | //float[] v = new float[100]; |
---|
1553 | 1584 | |
---|
1554 | 1585 | for (int loops=10; --loops>=0;) |
---|
.. | .. |
---|
1895 | 1926 | return; |
---|
1896 | 1927 | } |
---|
1897 | 1928 | |
---|
1898 | | - // System.exit(0); |
---|
| 1929 | + // System.exit(0); |
---|
1899 | 1930 | |
---|
1900 | 1931 | cVector vect = new cVector(); |
---|
1901 | 1932 | cVector normal = new cVector(); |
---|
.. | .. |
---|
1966 | 1997 | if (v.vertexlinks == null) |
---|
1967 | 1998 | continue; |
---|
1968 | 1999 | |
---|
1969 | | - if (v.weights != null && v.weights[j] == 0) // < 0.01 * v.totalweight) // == 0) |
---|
| 2000 | + // Warning: a bit faster but dangerous |
---|
| 2001 | + if (v.weights != null && v.weights[j] == 0) |
---|
| 2002 | + // < 0.001 * v.totalweight) |
---|
1970 | 2003 | { |
---|
1971 | 2004 | //testweight += v.weights[j-1]; |
---|
1972 | 2005 | continue; |
---|
.. | .. |
---|
2247 | 2280 | |
---|
2248 | 2281 | transient int lastsoundtime; |
---|
2249 | 2282 | |
---|
| 2283 | + transient boolean once = false; |
---|
| 2284 | + |
---|
2250 | 2285 | void setMasterThis0(BoundaryRep other, double[][] toRoot, boolean smooth, boolean marked) |
---|
2251 | 2286 | { |
---|
2252 | 2287 | if (LA.isIdentity(toRoot)) |
---|
.. | .. |
---|
2302 | 2337 | |
---|
2303 | 2338 | if (v.totalweight == 0) |
---|
2304 | 2339 | { |
---|
2305 | | - System.err.println("v.totalweight == 0! --> " + this + " : " + other); |
---|
| 2340 | + if (!once) |
---|
| 2341 | + { |
---|
| 2342 | + System.err.println("v.totalweight == 0! --> " + this + " : " + other); |
---|
| 2343 | + once = true; |
---|
| 2344 | + } |
---|
2306 | 2345 | continue; |
---|
2307 | 2346 | } |
---|
2308 | 2347 | |
---|
.. | .. |
---|
2670 | 2709 | |
---|
2671 | 2710 | if (Globals.framecount - lastsoundtime > 30) // 0.25 secs |
---|
2672 | 2711 | { |
---|
2673 | | - GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1); |
---|
| 2712 | + Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1); |
---|
2674 | 2713 | |
---|
2675 | 2714 | lastsoundtime = Globals.framecount; |
---|
2676 | 2715 | } |
---|
.. | .. |
---|
3098 | 3137 | // |
---|
3099 | 3138 | // transient VertexCompare[] vertexcompare = null; |
---|
3100 | 3139 | |
---|
| 3140 | + // Check if v0 is close enough from any vertex of the given subobject of this. |
---|
3101 | 3141 | boolean Contains(Vertex v0, int object) |
---|
3102 | 3142 | { |
---|
3103 | 3143 | int start = startvertices[object-1]; |
---|
.. | .. |
---|
3403 | 3443 | k /= x*x + y*y; |
---|
3404 | 3444 | } |
---|
3405 | 3445 | else |
---|
3406 | | - GrafreeD.Assert(z == 1); |
---|
| 3446 | + Grafreed.Assert(z == 1); |
---|
3407 | 3447 | |
---|
3408 | 3448 | if (k < 0) |
---|
3409 | 3449 | k = 0; |
---|
.. | .. |
---|
3696 | 3736 | */ |
---|
3697 | 3737 | } |
---|
3698 | 3738 | |
---|
| 3739 | + void GenerateNormals2(boolean crease) |
---|
| 3740 | + { |
---|
| 3741 | + cVector tempVector = new cVector(); |
---|
| 3742 | + |
---|
| 3743 | +// java.util.HashMap<cVector, cVector> tableBase = new java.util.HashMap<cVector, cVector>(); |
---|
| 3744 | +// |
---|
| 3745 | +// |
---|
| 3746 | +// for (int i=0; i<this.VertexCount(); i++) |
---|
| 3747 | +// { |
---|
| 3748 | +// Vertex v = this.GetVertex(i); |
---|
| 3749 | +// |
---|
| 3750 | +// tempVector.set(v); |
---|
| 3751 | +// |
---|
| 3752 | +// cVector n = tableBase.get(tempVector.ToFloat()); |
---|
| 3753 | +// |
---|
| 3754 | +// if (n != null) |
---|
| 3755 | +// { |
---|
| 3756 | +// continue; |
---|
| 3757 | +// } |
---|
| 3758 | +// |
---|
| 3759 | +// tableBase.put(new cVector(tempVector), new cVector(v.norm)); |
---|
| 3760 | +// } |
---|
| 3761 | + |
---|
| 3762 | + BoundaryRep tempSupport = this.support; |
---|
| 3763 | + |
---|
| 3764 | + this.support = null; |
---|
| 3765 | + |
---|
| 3766 | + BoundaryRep tempRep = (BoundaryRep)Grafreed.clone(this); |
---|
| 3767 | + |
---|
| 3768 | + this.support = tempSupport; |
---|
| 3769 | + |
---|
| 3770 | + //tempRep.Unstripify(); |
---|
| 3771 | + |
---|
| 3772 | + tempRep.GenerateNormals2(crease); |
---|
| 3773 | + |
---|
| 3774 | + boolean keepnormal = Vertex.normalmode; |
---|
| 3775 | + boolean epsequal = Grafreed.epsequal; |
---|
| 3776 | + |
---|
| 3777 | + Vertex.normalmode = false; |
---|
| 3778 | + Grafreed.epsequal = false; // A bit strange |
---|
| 3779 | + |
---|
| 3780 | + // No need to have a match for vertex counts. |
---|
| 3781 | + |
---|
| 3782 | + java.util.HashMap<cVector, cVector> table = new java.util.HashMap<cVector, cVector>(); |
---|
| 3783 | + |
---|
| 3784 | + for (int i=0; i<tempRep.VertexCount(); i++) |
---|
| 3785 | + { |
---|
| 3786 | + Vertex v = tempRep.GetVertex(i); |
---|
| 3787 | + |
---|
| 3788 | + cVector n = table.get(tempVector.ToFloat()); |
---|
| 3789 | + |
---|
| 3790 | + if (v.norm.x == 1 && v.norm.y == 0 && v.norm.z == 0) |
---|
| 3791 | + { |
---|
| 3792 | + //continue; |
---|
| 3793 | + } |
---|
| 3794 | + |
---|
| 3795 | + tempVector.set(v); |
---|
| 3796 | + |
---|
| 3797 | + //cVector nBase = tableBase.get(tempVector); |
---|
| 3798 | + |
---|
| 3799 | + //if (v.norm.dot(nBase) < 0.9) |
---|
| 3800 | + //{ |
---|
| 3801 | + // continue; |
---|
| 3802 | + //} |
---|
| 3803 | + |
---|
| 3804 | + if (n != null && n.x == 1 && n.y == 0 && n.z == 0) |
---|
| 3805 | + { |
---|
| 3806 | + //continue; |
---|
| 3807 | + } |
---|
| 3808 | + |
---|
| 3809 | + if (n != null) |
---|
| 3810 | + { |
---|
| 3811 | +// if (n.dot(v.norm) < 0) |
---|
| 3812 | +// n.sub(v.norm); |
---|
| 3813 | +// else |
---|
| 3814 | +// n.add(v.norm); |
---|
| 3815 | +// |
---|
| 3816 | +// n.normalize(); |
---|
| 3817 | + continue; |
---|
| 3818 | + } |
---|
| 3819 | + |
---|
| 3820 | + table.put(new cVector(tempVector), new cVector(v.norm)); |
---|
| 3821 | + } |
---|
| 3822 | + |
---|
| 3823 | + for (int i=0; i<this.VertexCount(); i++) |
---|
| 3824 | + { |
---|
| 3825 | + Vertex v = this.GetVertex(i); |
---|
| 3826 | + |
---|
| 3827 | + tempVector.set(v); |
---|
| 3828 | + |
---|
| 3829 | + cVector n = table.get(tempVector.ToFloat()); |
---|
| 3830 | + |
---|
| 3831 | + //if (n.dot(v.norm) < 0) |
---|
| 3832 | + if (n == null) |
---|
| 3833 | + continue; |
---|
| 3834 | + |
---|
| 3835 | + LA.vecCopy(n, v.norm); |
---|
| 3836 | + |
---|
| 3837 | + this.SetVertex(v, i); |
---|
| 3838 | + } |
---|
| 3839 | + |
---|
| 3840 | + Grafreed.epsequal = epsequal; |
---|
| 3841 | + Vertex.normalmode = keepnormal; |
---|
| 3842 | + } |
---|
| 3843 | + |
---|
3699 | 3844 | void GenerateNormals(boolean crease) |
---|
3700 | 3845 | { |
---|
3701 | 3846 | boolean wastrim = trimmed; |
---|
.. | .. |
---|
3712 | 3857 | } |
---|
3713 | 3858 | |
---|
3714 | 3859 | Trim(true/*wastrim*/,true,crease,wasstrip,false); |
---|
| 3860 | + } |
---|
| 3861 | + |
---|
| 3862 | + void GenerateNormalsMesh() |
---|
| 3863 | + { |
---|
| 3864 | + if (stripified) |
---|
| 3865 | + { |
---|
| 3866 | + Unstripify(); |
---|
| 3867 | + } |
---|
| 3868 | + |
---|
| 3869 | + if (trimmed) |
---|
| 3870 | + { |
---|
| 3871 | + normals = null; |
---|
| 3872 | + } |
---|
| 3873 | + else |
---|
| 3874 | + { |
---|
| 3875 | + for (int i=VertexCount(); --i>=0;) |
---|
| 3876 | + { |
---|
| 3877 | + Vertex v = GetVertex(i); |
---|
| 3878 | + |
---|
| 3879 | + v.norm = null; |
---|
| 3880 | + } |
---|
| 3881 | + } |
---|
3715 | 3882 | } |
---|
3716 | 3883 | |
---|
3717 | 3884 | void GenNormalsJME() |
---|
.. | .. |
---|
3836 | 4003 | NormalGenerator ng; |
---|
3837 | 4004 | |
---|
3838 | 4005 | if (crease) |
---|
3839 | | - ng = new NormalGenerator(Math.PI/6); // default is 44 degrees (or Math.PI/3); // /4); |
---|
| 4006 | + ng = new NormalGenerator(Math.PI/4); // default is 44 degrees (or Math.PI/3); // /4); |
---|
3840 | 4007 | else |
---|
3841 | 4008 | ng = new NormalGenerator(Math.PI); // (Math.PI / 3); // /4); |
---|
3842 | 4009 | |
---|
.. | .. |
---|
3869 | 4036 | { |
---|
3870 | 4037 | triangles[i] = i; |
---|
3871 | 4038 | } |
---|
| 4039 | + |
---|
| 4040 | +// Untrim(); |
---|
| 4041 | + if (!trimmed) |
---|
| 4042 | + MergeNormals(); |
---|
3872 | 4043 | } |
---|
3873 | 4044 | } |
---|
3874 | 4045 | |
---|
.. | .. |
---|
3902 | 4073 | tsa.getNormals(0, normals); |
---|
3903 | 4074 | tsa.getTextureCoordinates(0, 0, uvmap); |
---|
3904 | 4075 | // tsa.getColors(0, colors); |
---|
| 4076 | + |
---|
| 4077 | + for (int i=colors.length; --i>=0;) |
---|
| 4078 | + { |
---|
| 4079 | + colors[i] = 1; |
---|
| 4080 | + } |
---|
3905 | 4081 | |
---|
3906 | 4082 | int stripcount = tsa.getNumStrips(); |
---|
3907 | 4083 | triangles = new int[stripcount]; |
---|
.. | .. |
---|
3924 | 4100 | triangles = new int[1]; |
---|
3925 | 4101 | triangles[0] = 3; |
---|
3926 | 4102 | } |
---|
| 4103 | + |
---|
| 4104 | + //Untrim(); |
---|
| 4105 | + if (!trimmed) |
---|
| 4106 | + MergeNormals(); |
---|
3927 | 4107 | } |
---|
3928 | 4108 | |
---|
3929 | 4109 | /* |
---|
.. | .. |
---|
3973 | 4153 | } |
---|
3974 | 4154 | |
---|
3975 | 4155 | Vertex.normalmode = false; |
---|
| 4156 | + } |
---|
| 4157 | + |
---|
| 4158 | + void MergeNormals() |
---|
| 4159 | + { |
---|
| 4160 | + assert(!trimmed); |
---|
| 4161 | + |
---|
| 4162 | + boolean smooth = Grafreed.smoothmode; |
---|
| 4163 | + boolean link = Grafreed.linkUV; |
---|
| 4164 | + Grafreed.smoothmode = true; |
---|
| 4165 | + Grafreed.linkUV = true; |
---|
| 4166 | + |
---|
| 4167 | + System.out.println("#Vertex = " + VertexCount()); |
---|
| 4168 | + System.out.println("#Face = " + FaceCount()); |
---|
| 4169 | + |
---|
| 4170 | + java.util.HashSet<Vertex> table = new java.util.HashSet<Vertex>(); |
---|
| 4171 | + |
---|
| 4172 | + for (int i = 0; i < VertexCount(); i++) |
---|
| 4173 | + { |
---|
| 4174 | + Vertex v = GetVertex(i); |
---|
| 4175 | + |
---|
| 4176 | + if (!table.contains(v)) |
---|
| 4177 | + { |
---|
| 4178 | + table.add(v); |
---|
| 4179 | + } |
---|
| 4180 | + } |
---|
| 4181 | + |
---|
| 4182 | + Grafreed.smoothmode = smooth; |
---|
| 4183 | + Grafreed.linkUV = link; |
---|
| 4184 | + |
---|
| 4185 | +// for (int i = 0; i < VertexCount(); i++) |
---|
| 4186 | +// { |
---|
| 4187 | +// Vertex v = GetVertex(i); |
---|
| 4188 | +// |
---|
| 4189 | +// table.add(v); |
---|
| 4190 | +// } |
---|
| 4191 | + |
---|
3976 | 4192 | } |
---|
3977 | 4193 | |
---|
3978 | 4194 | static cVector temp1 = new cVector(); |
---|
.. | .. |
---|
4747 | 4963 | { |
---|
4748 | 4964 | i3 = positions.length-3; |
---|
4749 | 4965 | i2 = uvmap.length - 2; |
---|
4750 | | - new Exception().printStackTrace(); |
---|
| 4966 | + //new Exception().printStackTrace(); |
---|
4751 | 4967 | } |
---|
4752 | 4968 | |
---|
4753 | 4969 | v./*pos.*/x = positions[i3]; |
---|
4754 | 4970 | v./*pos.*/y = positions[i3 + 1]; |
---|
4755 | 4971 | v./*pos.*/z = positions[i3 + 2]; |
---|
4756 | 4972 | |
---|
4757 | | - v.norm.x = normals[i3]; |
---|
4758 | | - v.norm.y = normals[i3 + 1]; |
---|
4759 | | - v.norm.z = normals[i3 + 2]; |
---|
| 4973 | + if (normals == null) |
---|
| 4974 | + { |
---|
| 4975 | + v.norm.x = 0; |
---|
| 4976 | + v.norm.y = 0; |
---|
| 4977 | + v.norm.z = 0; |
---|
| 4978 | + } |
---|
| 4979 | + else |
---|
| 4980 | + { |
---|
| 4981 | + v.norm.x = normals[i3]; |
---|
| 4982 | + v.norm.y = normals[i3 + 1]; |
---|
| 4983 | + v.norm.z = normals[i3 + 2]; |
---|
| 4984 | + } |
---|
4760 | 4985 | |
---|
4761 | 4986 | v.s = uvmap[i2]; |
---|
4762 | 4987 | v.t = uvmap[i2 + 1]; |
---|
.. | .. |
---|
5471 | 5696 | |
---|
5472 | 5697 | transient int nbbadfaces; // ?? = 1000000; |
---|
5473 | 5698 | |
---|
5474 | | - int ChooseTriangle() |
---|
| 5699 | + /* |
---|
| 5700 | + */ |
---|
| 5701 | + int ChooseTriangle(boolean firstEquilateral) |
---|
5475 | 5702 | { |
---|
5476 | 5703 | int chosen = -1; |
---|
5477 | 5704 | |
---|
5478 | 5705 | double minweight = 1E10; |
---|
5479 | 5706 | |
---|
| 5707 | + int step = 8; // ? |
---|
| 5708 | + |
---|
| 5709 | + if (firstEquilateral) |
---|
| 5710 | + step = 1; |
---|
| 5711 | + |
---|
5480 | 5712 | nbbadfaces = 0; |
---|
5481 | | - for (int i=0; i<faces.size(); i+=8) |
---|
| 5713 | + for (int i=0; i<faces.size(); i+=step) |
---|
5482 | 5714 | // for (int i=faces.size(); (i-=8)>=0;) |
---|
5483 | 5715 | { |
---|
5484 | 5716 | Face face = (Face) faces.get(i); |
---|
| 5717 | + |
---|
| 5718 | + if (face.used) |
---|
| 5719 | + continue; |
---|
5485 | 5720 | |
---|
5486 | 5721 | if (!Valid(face)) |
---|
5487 | 5722 | { |
---|
.. | .. |
---|
5491 | 5726 | |
---|
5492 | 5727 | if (Boundary(face)) |
---|
5493 | 5728 | continue; |
---|
| 5729 | + |
---|
| 5730 | +// if (Boundary(face.p)) |
---|
| 5731 | +// continue; |
---|
| 5732 | +// |
---|
| 5733 | +// if (Boundary(face.q)) |
---|
| 5734 | +// continue; |
---|
| 5735 | +// |
---|
| 5736 | +// if (Boundary(face.r)) |
---|
| 5737 | +// continue; |
---|
5494 | 5738 | |
---|
5495 | 5739 | if (!ValidValence(face)) |
---|
5496 | 5740 | continue; |
---|
.. | .. |
---|
5503 | 5747 | //?? if (face.weight < 0) |
---|
5504 | 5748 | // continue; |
---|
5505 | 5749 | |
---|
5506 | | - double K = 1; // 0.01; // .25; |
---|
5507 | | - |
---|
5508 | | - double factor = (1-K)*face.nbiterations + K; //*face.weight; |
---|
5509 | | - |
---|
5510 | | - double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor; |
---|
5511 | | - |
---|
5512 | | - if (minweight > weight) |
---|
| 5750 | + if (firstEquilateral) |
---|
5513 | 5751 | { |
---|
5514 | | - minweight = weight; |
---|
| 5752 | + if (OneFaceUsed(links.get(face.p))) |
---|
| 5753 | + continue; |
---|
| 5754 | + |
---|
| 5755 | + if (OneFaceUsed(links.get(face.q))) |
---|
| 5756 | + continue; |
---|
| 5757 | + |
---|
| 5758 | + if (OneFaceUsed(links.get(face.r))) |
---|
| 5759 | + continue; |
---|
| 5760 | + |
---|
5515 | 5761 | chosen = i; |
---|
5516 | | - if (minweight == 0) |
---|
5517 | | - break; |
---|
| 5762 | + break; |
---|
| 5763 | + } |
---|
| 5764 | + else |
---|
| 5765 | + { |
---|
| 5766 | + double K = 1; // 0.01; // .25; |
---|
| 5767 | + |
---|
| 5768 | + double factor = (1-K)*face.nbiterations + K; //*face.weight; |
---|
| 5769 | + |
---|
| 5770 | + double weight = FaceWeight(face); // *Math.pow(PerimeterMax(face),0.25)*factor; |
---|
| 5771 | + |
---|
| 5772 | + if (minweight > weight) |
---|
| 5773 | + { |
---|
| 5774 | + minweight = weight; |
---|
| 5775 | + chosen = i; |
---|
| 5776 | + if (minweight == 0) |
---|
| 5777 | + break; |
---|
| 5778 | + } |
---|
5518 | 5779 | } |
---|
5519 | 5780 | } |
---|
5520 | 5781 | |
---|
5521 | 5782 | return chosen; |
---|
| 5783 | + } |
---|
| 5784 | + |
---|
| 5785 | + private boolean OneFaceUsed(Vector<Face> faces) |
---|
| 5786 | + { |
---|
| 5787 | + if (faces.size() != 6) |
---|
| 5788 | + return true; |
---|
| 5789 | + |
---|
| 5790 | + for (int i=0; i<6; i+=1) |
---|
| 5791 | + { |
---|
| 5792 | + if (faces.get(i).used) |
---|
| 5793 | + { |
---|
| 5794 | + return true; |
---|
| 5795 | + } |
---|
| 5796 | + } |
---|
| 5797 | + |
---|
| 5798 | + return false; |
---|
5522 | 5799 | } |
---|
5523 | 5800 | |
---|
5524 | 5801 | static boolean remove3valence = true; |
---|
.. | .. |
---|
5554 | 5831 | } |
---|
5555 | 5832 | else |
---|
5556 | 5833 | { |
---|
5557 | | - assert(links.size() == vertices.size()); |
---|
| 5834 | + // TODO Grafreed.Assert(links.size() == vertices.size()); |
---|
5558 | 5835 | |
---|
5559 | 5836 | links.setSize(vertices.size()); |
---|
5560 | 5837 | for (int i=vertices.size(); --i>=0;) |
---|
.. | .. |
---|
5562 | 5839 | // linkstouched[i] = false; |
---|
5563 | 5840 | if (links.get(i) == null) // ?? |
---|
5564 | 5841 | { |
---|
| 5842 | + new Exception().printStackTrace(); |
---|
5565 | 5843 | links.set(i, new Vector(8)); |
---|
5566 | 5844 | // linkstouched[i] = true; |
---|
5567 | 5845 | } |
---|
.. | .. |
---|
5572 | 5850 | } |
---|
5573 | 5851 | } |
---|
5574 | 5852 | |
---|
| 5853 | + boolean once = false; |
---|
| 5854 | + |
---|
5575 | 5855 | for (int i=faces.size(); --i>=0;) |
---|
5576 | 5856 | { |
---|
5577 | 5857 | Face face = (Face) faces.get(i); |
---|
.. | .. |
---|
5583 | 5863 | //if (linkstouched[face.r]) |
---|
5584 | 5864 | links.get(face.r).add(face); |
---|
5585 | 5865 | |
---|
| 5866 | + if (face.used) |
---|
| 5867 | + once = true; |
---|
| 5868 | + |
---|
5586 | 5869 | face.good = 1; |
---|
5587 | 5870 | face.boundary = -1; |
---|
5588 | 5871 | } |
---|
.. | .. |
---|
6354 | 6637 | |
---|
6355 | 6638 | void InitWeights() |
---|
6356 | 6639 | { |
---|
| 6640 | + new Exception().printStackTrace(); |
---|
6357 | 6641 | System.exit(0); |
---|
6358 | 6642 | int n = 0; |
---|
6359 | 6643 | int b = 0; |
---|
.. | .. |
---|
6947 | 7231 | return (face.boundary = 1) == 1; |
---|
6948 | 7232 | } |
---|
6949 | 7233 | |
---|
| 7234 | + // June 2019 |
---|
| 7235 | + if (true) |
---|
| 7236 | + return (face.boundary = 0) == 1; |
---|
| 7237 | + |
---|
6950 | 7238 | // reverse triangle test |
---|
6951 | 7239 | q1.set(p); |
---|
6952 | 7240 | q2.set(q); |
---|
.. | .. |
---|
7396 | 7684 | //InitWeights(); |
---|
7397 | 7685 | } |
---|
7398 | 7686 | |
---|
7399 | | - int chosen = ChooseTriangle(); // Best is slow and not really better |
---|
| 7687 | + int chosen = ChooseTriangle(true); // Best is slow and not really better |
---|
7400 | 7688 | |
---|
7401 | 7689 | if (chosen == -1) |
---|
7402 | 7690 | { |
---|
.. | .. |
---|
7410 | 7698 | //remove3valence = false; |
---|
7411 | 7699 | // InitWeights(); |
---|
7412 | 7700 | |
---|
7413 | | - chosen = ChooseTriangle(); |
---|
| 7701 | + chosen = ChooseTriangle(true); |
---|
7414 | 7702 | } |
---|
7415 | 7703 | } |
---|
7416 | 7704 | |
---|
.. | .. |
---|
7686 | 7974 | |
---|
7687 | 7975 | // boolean lock; |
---|
7688 | 7976 | |
---|
7689 | | - void SplitInTwo(boolean reduction34, boolean onlyone) |
---|
| 7977 | + boolean SplitInTwo(boolean reduction34, boolean onlyone) |
---|
7690 | 7978 | { |
---|
7691 | 7979 | if (stripified) |
---|
7692 | 7980 | { |
---|
.. | .. |
---|
7723 | 8011 | { |
---|
7724 | 8012 | System.err.println("EXCEPTION CAUGHT"); |
---|
7725 | 8013 | e.printStackTrace(); |
---|
7726 | | - return; |
---|
| 8014 | + return false; |
---|
7727 | 8015 | } catch (Error e) |
---|
7728 | 8016 | { |
---|
7729 | 8017 | System.err.println("ERROR CAUGHT"); |
---|
7730 | 8018 | e.printStackTrace(); |
---|
7731 | | - return; |
---|
| 8019 | + return false; |
---|
7732 | 8020 | } |
---|
7733 | 8021 | |
---|
7734 | 8022 | System.out.println("# faces = " + faces.size()); |
---|
.. | .. |
---|
7738 | 8026 | { |
---|
7739 | 8027 | Face face = (Face) faces.get(i); |
---|
7740 | 8028 | |
---|
| 8029 | + face.used = false; |
---|
7741 | 8030 | face.nbiterations = 1; |
---|
7742 | 8031 | face.weight = -1; |
---|
7743 | 8032 | face.boundary = -1; |
---|
.. | .. |
---|
7789 | 8078 | nbbadfaces = faces.size(); |
---|
7790 | 8079 | //remove3valence = true; |
---|
7791 | 8080 | |
---|
| 8081 | + int count = 2; |
---|
| 8082 | + |
---|
| 8083 | + if (onlyone) |
---|
| 8084 | + count = 1; |
---|
| 8085 | + |
---|
7792 | 8086 | firstpass = true; |
---|
7793 | 8087 | |
---|
7794 | 8088 | int n = faces.size(); |
---|
.. | .. |
---|
7804 | 8098 | System.out.print('.'); |
---|
7805 | 8099 | } |
---|
7806 | 8100 | System.out.println(); |
---|
| 8101 | + boolean atleastone = false; |
---|
7807 | 8102 | int i = 0; |
---|
7808 | | - while (reduction34 || faces.size() > n/2) |
---|
| 8103 | + while (true) // reduction34 || faces.size() > n/2) |
---|
7809 | 8104 | { |
---|
7810 | 8105 | if (i++%100 == 0) |
---|
7811 | 8106 | { |
---|
.. | .. |
---|
7827 | 8122 | { |
---|
7828 | 8123 | if (!RemoveOneTriangle()) |
---|
7829 | 8124 | break; |
---|
| 8125 | + |
---|
| 8126 | + atleastone = true; |
---|
7830 | 8127 | } |
---|
7831 | 8128 | // if (iterationcount == 0) |
---|
7832 | 8129 | // break; |
---|
.. | .. |
---|
7837 | 8134 | break; |
---|
7838 | 8135 | } |
---|
7839 | 8136 | firstpass = false; |
---|
7840 | | - if (onlyone) |
---|
7841 | | - break; // one triangle only |
---|
| 8137 | +// if (--count<0 && !reduction34) |
---|
| 8138 | +// break; // one triangle only |
---|
7842 | 8139 | } |
---|
7843 | 8140 | |
---|
7844 | 8141 | InitLinks(false); // for further display |
---|
.. | .. |
---|
7854 | 8151 | Trim(true,false,false,false,false); |
---|
7855 | 8152 | |
---|
7856 | 8153 | Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); |
---|
| 8154 | + |
---|
| 8155 | + return atleastone; |
---|
7857 | 8156 | } |
---|
7858 | 8157 | |
---|
7859 | 8158 | void UpdateIndices(Face face, Face minface) |
---|
.. | .. |
---|
7866 | 8165 | face.p = minface.p; |
---|
7867 | 8166 | //if (leafweights) |
---|
7868 | 8167 | face.good = 0; // false; |
---|
| 8168 | + face.used = true; |
---|
7869 | 8169 | } |
---|
7870 | 8170 | if (face.q == minface.p || face.q == minface.q || face.q == minface.r) |
---|
7871 | 8171 | { |
---|
7872 | 8172 | face.q = minface.p; |
---|
7873 | 8173 | //if (leafweights) |
---|
7874 | 8174 | face.good = 0; // false; |
---|
| 8175 | + face.used = true; |
---|
7875 | 8176 | } |
---|
7876 | 8177 | if (face.r == minface.p || face.r == minface.q || face.r == minface.r) |
---|
7877 | 8178 | { |
---|
7878 | 8179 | face.r = minface.p; |
---|
7879 | 8180 | //if (leafweights) |
---|
7880 | 8181 | face.good = 0; // false; |
---|
| 8182 | + face.used = true; |
---|
7881 | 8183 | } |
---|
7882 | 8184 | |
---|
7883 | 8185 | if (face.p >/*=*/ minface.q && face.p < minface.r) |
---|
.. | .. |
---|
7937 | 8239 | if (v == 2) |
---|
7938 | 8240 | vert = minface.r; |
---|
7939 | 8241 | // Face face = (Face) faces.get(i); |
---|
7940 | | - Vector<Face> vertfaces = links.get(vert); |
---|
7941 | | - for (int i=vertfaces.size(); --i>=0;) |
---|
7942 | | - { |
---|
7943 | | - Face face = (Face) vertfaces.get(i); |
---|
7944 | | - |
---|
7945 | | - // if (face.weight == 10000) |
---|
7946 | | - // continue; |
---|
7947 | | - |
---|
7948 | | - if (face.p == minface.p || face.q == minface.p || face.r == minface.p || |
---|
7949 | | - face.p == minface.q || face.q == minface.q || face.r == minface.q || |
---|
7950 | | - face.p == minface.r || face.q == minface.r || face.r == minface.r) |
---|
| 8242 | + Vector<Face> vertfaces = links.get(vert); |
---|
| 8243 | + for (int i=vertfaces.size(); --i>=0;) |
---|
7951 | 8244 | { |
---|
7952 | | - if (!leafweights) |
---|
| 8245 | + Face face = (Face) vertfaces.get(i); |
---|
| 8246 | + |
---|
| 8247 | + // if (face.weight == 10000) |
---|
| 8248 | + // continue; |
---|
| 8249 | + |
---|
| 8250 | + if (face.p == minface.p || face.q == minface.p || face.r == minface.p || |
---|
| 8251 | + face.p == minface.q || face.q == minface.q || face.r == minface.q || |
---|
| 8252 | + face.p == minface.r || face.q == minface.r || face.r == minface.r) |
---|
7953 | 8253 | { |
---|
7954 | | -// if(minfaceweight <= 0) |
---|
7955 | | -// assert(minfaceweight > 0); |
---|
7956 | | -// |
---|
7957 | | -// //FaceWeight(face); |
---|
7958 | | -// if(face.weight < 0) |
---|
7959 | | -// assert(face.weight >= 0); |
---|
7960 | | - |
---|
7961 | | - face.weight += minfaceweight; |
---|
7962 | | - |
---|
7963 | | -// if (face.weight >= 10000) |
---|
7964 | | -// assert(face.weight < 10000); |
---|
| 8254 | + if (!leafweights) |
---|
| 8255 | + { |
---|
| 8256 | + // if(minfaceweight <= 0) |
---|
| 8257 | + // assert(minfaceweight > 0); |
---|
| 8258 | + // |
---|
| 8259 | + // //FaceWeight(face); |
---|
| 8260 | + // if(face.weight < 0) |
---|
| 8261 | + // assert(face.weight >= 0); |
---|
| 8262 | + |
---|
| 8263 | + face.weight += minfaceweight; |
---|
| 8264 | + |
---|
| 8265 | + // if (face.weight >= 10000) |
---|
| 8266 | + // assert(face.weight < 10000); |
---|
| 8267 | + } |
---|
| 8268 | + else |
---|
| 8269 | + face.weight = -1; |
---|
| 8270 | + |
---|
| 8271 | + face.nbiterations += 1; |
---|
| 8272 | + face.boundary = -1; |
---|
| 8273 | + |
---|
| 8274 | + Vertex p = (Vertex)vertices.get(face.p); |
---|
| 8275 | + Vertex q = (Vertex)vertices.get(face.q); |
---|
| 8276 | + Vertex r = (Vertex)vertices.get(face.r); |
---|
| 8277 | + |
---|
| 8278 | + p.boundary = -1; |
---|
| 8279 | + q.boundary = -1; |
---|
| 8280 | + r.boundary = -1; |
---|
7965 | 8281 | } |
---|
7966 | 8282 | else |
---|
7967 | | - face.weight = -1; |
---|
7968 | | - |
---|
7969 | | - face.nbiterations += 1; |
---|
7970 | | - face.boundary = -1; |
---|
7971 | | - |
---|
7972 | | - Vertex p = (Vertex)vertices.get(face.p); |
---|
7973 | | - Vertex q = (Vertex)vertices.get(face.q); |
---|
7974 | | - Vertex r = (Vertex)vertices.get(face.r); |
---|
7975 | | - |
---|
7976 | | - p.boundary = -1; |
---|
7977 | | - q.boundary = -1; |
---|
7978 | | - r.boundary = -1; |
---|
| 8283 | + assert(false); |
---|
7979 | 8284 | } |
---|
7980 | | - else |
---|
7981 | | - assert(false); |
---|
7982 | 8285 | } |
---|
7983 | | - } |
---|
7984 | 8286 | |
---|
7985 | 8287 | // TouchVertex(minface.p); |
---|
7986 | 8288 | // TouchVertex(minface.q); |
---|
.. | .. |
---|
8181 | 8483 | for (int i=vertfaces.size(); --i>=0;) |
---|
8182 | 8484 | { |
---|
8183 | 8485 | Face face = (Face) vertfaces.get(i); |
---|
| 8486 | + face.used = true; |
---|
8184 | 8487 | face.good = 0; // false; |
---|
8185 | 8488 | if (leafweights) |
---|
8186 | 8489 | face.weight = -1; |
---|
.. | .. |
---|
8227 | 8530 | if (!trimmed) |
---|
8228 | 8531 | return; |
---|
8229 | 8532 | |
---|
8230 | | - GrafreeD.linkUV = false; |
---|
| 8533 | + Grafreed.linkUV = false; |
---|
8231 | 8534 | |
---|
8232 | 8535 | try |
---|
8233 | 8536 | { |
---|
.. | .. |
---|
8459 | 8762 | int[] startvertices; |
---|
8460 | 8763 | float[] averagepoints; |
---|
8461 | 8764 | float[] extremepoints; |
---|
8462 | | - float[] supportsizes; // distance of closest point |
---|
| 8765 | + float[] supportminsize; // distance of closest point |
---|
| 8766 | + float[] supportmaxsize; // distance of fartest point |
---|
8463 | 8767 | |
---|
8464 | 8768 | transient Hashtable vertextable; |
---|
8465 | 8769 | /*transient*/ private Vertex[] verticesCopy; |
---|