| .. | .. |
|---|
| 497 | 497 | return dist2; |
|---|
| 498 | 498 | } |
|---|
| 499 | 499 | |
|---|
| 500 | | - static Vertex vertextemp = new Vertex(); |
|---|
| 501 | | - static Vertex vertextemp2 = new Vertex(); |
|---|
| 500 | + static Vertex vertextemp = new Vertex(true); |
|---|
| 501 | + static Vertex vertextemp2 = new Vertex(true); |
|---|
| 502 | 502 | |
|---|
| 503 | | - static double SEUIL = 0.1; // 0.1 for rag doll; 0.07; |
|---|
| 503 | + static double SEUIL = 0.1f; // 0.1 for rag doll; 0.07; |
|---|
| 504 | 504 | |
|---|
| 505 | 505 | // Compute weight of point w/r to this |
|---|
| 506 | 506 | float ComputeWeight(Vertex v, double[][] toRoot, int k) |
|---|
| .. | .. |
|---|
| 570 | 570 | |
|---|
| 571 | 571 | if (dot > distmax) |
|---|
| 572 | 572 | dot = distmax; |
|---|
| 573 | + //return 0; // patch for strange behavior |
|---|
| 573 | 574 | if (dot < -distmax) |
|---|
| 574 | 575 | dot = -distmax; |
|---|
| 576 | + //return 0; // patch for strange behavior |
|---|
| 575 | 577 | |
|---|
| 576 | 578 | // v3 = GetVertex(this.startvertices[subsupport] + 16); |
|---|
| 577 | 579 | // |
|---|
| .. | .. |
|---|
| 609 | 611 | |
|---|
| 610 | 612 | float dist2 = (float)Distance2(v, v2, 1E10, toRoot, k); |
|---|
| 611 | 613 | |
|---|
| 612 | | - if (dist2 >= 2 * SEUIL*SEUIL) // && !CameraPane.CROWD) // weightmode |
|---|
| 614 | + double seuil = SEUIL * 2; |
|---|
| 615 | + |
|---|
| 616 | + if (dist2 >= 2 * seuil*seuil) // && !CameraPane.CROWD) // weightmode |
|---|
| 613 | 617 | return 0; |
|---|
| 614 | 618 | |
|---|
| 615 | | - dist2 /= 2 * SEUIL*SEUIL; // multiplied by two because center of support |
|---|
| 619 | + dist2 /= 2 * seuil*seuil; // multiplied by two because center of support |
|---|
| 616 | 620 | // could be far from closest point |
|---|
| 617 | 621 | |
|---|
| 618 | 622 | // dist2 = Math.pow(dist2, 2); |
|---|
| .. | .. |
|---|
| 946 | 950 | |
|---|
| 947 | 951 | int nbsupports; |
|---|
| 948 | 952 | |
|---|
| 949 | | - SEUIL = 0.1; // aout 2013 |
|---|
| 953 | + // sept 2017 SEUIL = 0.1; // aout 2013 |
|---|
| 950 | 954 | |
|---|
| 951 | 955 | supports = InitConnections(other); |
|---|
| 952 | 956 | |
|---|
| .. | .. |
|---|
| 982 | 986 | |
|---|
| 983 | 987 | int subsupports = 0; |
|---|
| 984 | 988 | |
|---|
| 985 | | - SEUIL = 0.1; // aout 2013 |
|---|
| 989 | + // sept 2017 SEUIL = 0.1; // aout 2013 |
|---|
| 986 | 990 | |
|---|
| 987 | 991 | while (subsupports == 0) |
|---|
| 988 | 992 | { |
|---|
| .. | .. |
|---|
| 1006 | 1010 | |
|---|
| 1007 | 1011 | vect.set(v); |
|---|
| 1008 | 1012 | vect.sub(vect2); |
|---|
| 1013 | + |
|---|
| 1014 | +// vertextemp.x = other.averagepoints[c*3]; |
|---|
| 1015 | +// vertextemp.y = other.averagepoints[c*3+1]; |
|---|
| 1016 | +// vertextemp.z = other.averagepoints[c*3+2]; |
|---|
| 1017 | +// |
|---|
| 1018 | +// Vertex v3 = vertextemp2; |
|---|
| 1019 | +// v3.x = other.extremepoints[c*3]; |
|---|
| 1020 | +// v3.y = other.extremepoints[c*3+1]; |
|---|
| 1021 | +// v3.z = other.extremepoints[c*3+2]; |
|---|
| 1022 | +// |
|---|
| 1023 | +// vect3.set(v3); // "X" axis apex |
|---|
| 1024 | +// vect3.sub(vertextemp); // origin (center) |
|---|
| 1025 | +// |
|---|
| 1026 | +// double distmax = vect3.length(); |
|---|
| 1027 | +// |
|---|
| 1028 | +// vect3.set(v2); // "X" axis apex |
|---|
| 1029 | +// vect3.sub(vertextemp); // origin (center) |
|---|
| 1030 | +// |
|---|
| 1031 | +// if (vect3.length() >= distmax) |
|---|
| 1032 | +// continue; |
|---|
| 1009 | 1033 | |
|---|
| 1010 | 1034 | if (mindistance > vect.dot(vect)) |
|---|
| 1011 | 1035 | { |
|---|
| .. | .. |
|---|
| 1017 | 1041 | |
|---|
| 1018 | 1042 | subsupports = v.closestsupport==-1 ? 0 : supports[v.closestsupport].Length(); |
|---|
| 1019 | 1043 | |
|---|
| 1020 | | - SEUIL *= 2; |
|---|
| 1044 | + // previously for "contains", now for weights. |
|---|
| 1045 | + assert(subsupports > 0); |
|---|
| 1046 | + //SEUIL *= 2; |
|---|
| 1021 | 1047 | } |
|---|
| 1022 | 1048 | |
|---|
| 1023 | 1049 | assert(subsupports > 0); |
|---|
| .. | .. |
|---|
| 2163 | 2189 | // if (slow) |
|---|
| 2164 | 2190 | // aout 2013 |
|---|
| 2165 | 2191 | // sept 2013 merde... |
|---|
| 2166 | | - W = 13; |
|---|
| 2192 | + W = 3; // 13; |
|---|
| 2167 | 2193 | |
|---|
| 2168 | 2194 | // POSERATE |
|---|
| 2169 | 2195 | if (CameraPane.tickcount > 0 || CameraPane.SLOWPOSE) |
|---|
| .. | .. |
|---|
| 3776 | 3802 | for (int i = 0; i < VertexCount(); i++) |
|---|
| 3777 | 3803 | { |
|---|
| 3778 | 3804 | Vertex v = GetVertex(i); |
|---|
| 3805 | + |
|---|
| 3806 | + vertextemp.set(v); |
|---|
| 3807 | + |
|---|
| 3779 | 3808 | //if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0) |
|---|
| 3780 | 3809 | { |
|---|
| 3781 | | - GenerateNormal(i, v); |
|---|
| 3782 | | - SetVertex(v, i); |
|---|
| 3810 | + if (!GenerateNormal(i, vertextemp)) |
|---|
| 3811 | + continue; |
|---|
| 3812 | + |
|---|
| 3813 | + if (v.norm.dot(vertextemp.norm) < 0) |
|---|
| 3814 | + vertextemp.norm.mul(-1); |
|---|
| 3815 | + |
|---|
| 3816 | + if (v.norm.dot(vertextemp.norm) < 0.9) |
|---|
| 3817 | + SetVertex(vertextemp, i); |
|---|
| 3783 | 3818 | } |
|---|
| 3784 | 3819 | } |
|---|
| 3785 | 3820 | |
|---|
| .. | .. |
|---|
| 3790 | 3825 | static cVector temp2 = new cVector(); |
|---|
| 3791 | 3826 | static cVector temp3 = new cVector(); |
|---|
| 3792 | 3827 | |
|---|
| 3793 | | - void GenerateNormal(int index, Vertex v) |
|---|
| 3828 | + boolean GenerateNormal(int index, Vertex v) |
|---|
| 3794 | 3829 | { |
|---|
| 3795 | 3830 | //System.out.println("Old normal = " + v.norm); |
|---|
| 3796 | 3831 | LA.setVector(v.norm, 0, 0, 0); |
|---|
| .. | .. |
|---|
| 3819 | 3854 | LA.vecSub(p/*.pos*/, v/*.pos*/, temp1); |
|---|
| 3820 | 3855 | LA.vecSub(q/*.pos*/, v/*.pos*/, temp2); |
|---|
| 3821 | 3856 | } |
|---|
| 3857 | + else |
|---|
| 3858 | + { |
|---|
| 3859 | + continue; |
|---|
| 3860 | + } |
|---|
| 3822 | 3861 | |
|---|
| 3823 | 3862 | //LA.vecNormalize(temp1); |
|---|
| 3824 | 3863 | //LA.vecNormalize(temp2); |
|---|
| .. | .. |
|---|
| 3829 | 3868 | double s = temp3.length(); |
|---|
| 3830 | 3869 | //double c = temp2.dot(temp1); |
|---|
| 3831 | 3870 | |
|---|
| 3871 | + if (s == 0) |
|---|
| 3872 | + return false; |
|---|
| 3873 | + |
|---|
| 3832 | 3874 | float angle = 1; // (float) Math.atan2(s, c); |
|---|
| 3833 | 3875 | //if(angle < 0) angle = -angle; |
|---|
| 3834 | 3876 | |
|---|
| 3835 | 3877 | //LA.vecNormalize(temp3); |
|---|
| 3836 | 3878 | LA.vecScale(temp3, angle / s); |
|---|
| 3837 | 3879 | |
|---|
| 3880 | +// if (temp3.dot(v.norm) < 0) |
|---|
| 3881 | +// assert(temp3.dot(v.norm) >= 0); |
|---|
| 3882 | + |
|---|
| 3838 | 3883 | LA.vecAdd(temp3, v.norm, v.norm); |
|---|
| 3839 | 3884 | } |
|---|
| 3840 | 3885 | |
|---|
| 3841 | 3886 | LA.vecNormalize(v.norm); |
|---|
| 3842 | 3887 | //System.out.println("New normal = " + v.norm); |
|---|
| 3888 | + |
|---|
| 3889 | + return true; |
|---|
| 3843 | 3890 | } |
|---|
| 3844 | 3891 | |
|---|
| 3845 | 3892 | double Arccos(double x) |
|---|
| .. | .. |
|---|
| 4885 | 4932 | //colors[i3 + 1] = cp.vertexOcclusion.g; |
|---|
| 4886 | 4933 | //colors[i3 + 2] = cp.vertexOcclusion.b; |
|---|
| 4887 | 4934 | |
|---|
| 4888 | | - if ((i % 1000) == 0 && i != 0) |
|---|
| 4935 | + if ((i % 100) == 0 && i != 0) |
|---|
| 4889 | 4936 | { |
|---|
| 4890 | 4937 | CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
|---|
| 4891 | 4938 | //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done"); |
|---|
| .. | .. |
|---|
| 4917 | 4964 | |
|---|
| 4918 | 4965 | v.AO = cp.vertexOcclusion.r; |
|---|
| 4919 | 4966 | |
|---|
| 4920 | | - if ((i % 1000) == 0 && i != 0) |
|---|
| 4967 | + if ((i % 100) == 0 && i != 0) |
|---|
| 4921 | 4968 | { |
|---|
| 4922 | 4969 | CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); |
|---|
| 4923 | 4970 | //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done"); |
|---|
| .. | .. |
|---|
| 4926 | 4973 | } |
|---|
| 4927 | 4974 | } |
|---|
| 4928 | 4975 | |
|---|
| 4929 | | - System.out.println("done."); |
|---|
| 4976 | + //System.out.println("done."); |
|---|
| 4930 | 4977 | |
|---|
| 4931 | 4978 | cp.renderCamera = keep; |
|---|
| 4932 | 4979 | |
|---|
| .. | .. |
|---|
| 7075 | 7122 | assert(f2.contains(i)); |
|---|
| 7076 | 7123 | assert(f3.contains(i)); |
|---|
| 7077 | 7124 | |
|---|
| 7125 | + // when r is the "center", p is along the boundary |
|---|
| 7078 | 7126 | while (f0.r != i) |
|---|
| 7079 | 7127 | { |
|---|
| 7080 | 7128 | int t = f0.p; |
|---|
| .. | .. |
|---|
| 7131 | 7179 | f0 = f3; |
|---|
| 7132 | 7180 | f3 = t; |
|---|
| 7133 | 7181 | } |
|---|
| 7134 | | - atleastone = true; |
|---|
| 7135 | 7182 | |
|---|
| 7183 | + int va = f0.q; |
|---|
| 7184 | + int vb = f0.r; |
|---|
| 7185 | + int vc = -1; |
|---|
| 7186 | + |
|---|
| 7187 | + Face toremove1 = null; |
|---|
| 7188 | + Face toremove2 = null; |
|---|
| 7189 | + |
|---|
| 7190 | + // f0 is the buffer for the first new triangle, |
|---|
| 7191 | + // and otherf is the other upper one. |
|---|
| 7136 | 7192 | Face otherf = null; |
|---|
| 7137 | 7193 | |
|---|
| 7138 | 7194 | if (f1.contains(f0.p)) |
|---|
| 7139 | 7195 | { |
|---|
| 7140 | 7196 | if (f1.p == f0.p) |
|---|
| 7141 | 7197 | { |
|---|
| 7198 | + assert(false); |
|---|
| 7142 | 7199 | f0.r = f1.q; |
|---|
| 7143 | 7200 | } |
|---|
| 7144 | 7201 | else |
|---|
| 7145 | 7202 | { |
|---|
| 7146 | 7203 | assert(f1.q == f0.p); |
|---|
| 7147 | | - f0.r = f1.p; |
|---|
| 7204 | + vc = f1.p; |
|---|
| 7148 | 7205 | } |
|---|
| 7149 | 7206 | |
|---|
| 7150 | 7207 | otherf = f2; |
|---|
| 7151 | | - faces.remove(f1); |
|---|
| 7152 | | - faces.remove(f3); |
|---|
| 7208 | + toremove1 = f1; |
|---|
| 7209 | + toremove2 = f3; |
|---|
| 7153 | 7210 | } |
|---|
| 7154 | 7211 | else |
|---|
| 7155 | 7212 | if (f2.contains(f0.p)) |
|---|
| 7156 | 7213 | { |
|---|
| 7157 | 7214 | if (f2.p == f0.p) |
|---|
| 7158 | 7215 | { |
|---|
| 7216 | + assert(false); |
|---|
| 7159 | 7217 | f0.r = f2.q; |
|---|
| 7160 | 7218 | } |
|---|
| 7161 | 7219 | else |
|---|
| 7162 | 7220 | { |
|---|
| 7163 | 7221 | assert(f2.q == f0.p); |
|---|
| 7164 | | - f0.r = f2.p; |
|---|
| 7222 | + vc = f2.p; |
|---|
| 7165 | 7223 | } |
|---|
| 7166 | 7224 | |
|---|
| 7167 | 7225 | otherf = f3; |
|---|
| 7168 | | - faces.remove(f1); |
|---|
| 7169 | | - faces.remove(f2); |
|---|
| 7226 | + toremove1 = f1; |
|---|
| 7227 | + toremove2 = f2; |
|---|
| 7170 | 7228 | } |
|---|
| 7171 | 7229 | if (f3.contains(f0.p)) |
|---|
| 7172 | 7230 | { |
|---|
| 7173 | 7231 | if (f3.p == f0.p) |
|---|
| 7174 | 7232 | { |
|---|
| 7233 | +// assert(false); |
|---|
| 7234 | + new Exception().printStackTrace(); |
|---|
| 7175 | 7235 | f0.r = f3.q; |
|---|
| 7176 | 7236 | } |
|---|
| 7177 | 7237 | else |
|---|
| 7178 | 7238 | { |
|---|
| 7179 | 7239 | assert(f3.q == f0.p); |
|---|
| 7180 | | - f0.r = f3.p; |
|---|
| 7240 | + vc = f3.p; |
|---|
| 7181 | 7241 | } |
|---|
| 7182 | 7242 | |
|---|
| 7183 | 7243 | otherf = f1; |
|---|
| 7184 | | - faces.remove(f2); |
|---|
| 7185 | | - faces.remove(f3); |
|---|
| 7244 | + toremove1 = f2; |
|---|
| 7245 | + toremove2 = f3; |
|---|
| 7186 | 7246 | } |
|---|
| 7187 | 7247 | |
|---|
| 7248 | + vertextemp.set(vertices.get(va)); |
|---|
| 7249 | + vertextemp.sub(vertices.get(vb)); |
|---|
| 7250 | + vertextemp.normalize(); |
|---|
| 7251 | + vertextemp2.set(vertices.get(vc)); |
|---|
| 7252 | + vertextemp2.sub(vertices.get(vb)); |
|---|
| 7253 | + vertextemp2.normalize(); |
|---|
| 7254 | + |
|---|
| 7255 | + if (vertextemp.dot(vertextemp2) > -0.95) |
|---|
| 7256 | + { |
|---|
| 7257 | + continue; |
|---|
| 7258 | + } |
|---|
| 7259 | + |
|---|
| 7260 | + atleastone = true; |
|---|
| 7261 | + |
|---|
| 7262 | + f0.r = vc; |
|---|
| 7263 | + |
|---|
| 7264 | + faces.remove(toremove1); |
|---|
| 7265 | + faces.remove(toremove2); |
|---|
| 7266 | + |
|---|
| 7188 | 7267 | if (!f0.contains(otherf.p)) |
|---|
| 7189 | 7268 | { |
|---|
| 7190 | 7269 | otherf.r = otherf.p; |
|---|