Normand Briere
2018-05-22 42107f9a01652cb2f47228d20c1148a2a22f6a63
BoundaryRep.java
....@@ -497,10 +497,10 @@
497497 return dist2;
498498 }
499499
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);
502502
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;
504504
505505 // Compute weight of point w/r to this
506506 float ComputeWeight(Vertex v, double[][] toRoot, int k)
....@@ -570,8 +570,10 @@
570570
571571 if (dot > distmax)
572572 dot = distmax;
573
+ //return 0; // patch for strange behavior
573574 if (dot < -distmax)
574575 dot = -distmax;
576
+ //return 0; // patch for strange behavior
575577
576578 // v3 = GetVertex(this.startvertices[subsupport] + 16);
577579 //
....@@ -609,10 +611,12 @@
609611
610612 float dist2 = (float)Distance2(v, v2, 1E10, toRoot, k);
611613
612
- if (dist2 >= 2 * SEUIL*SEUIL) // && !CameraPane.CROWD) // weightmode
614
+ double seuil = SEUIL * 2;
615
+
616
+ if (dist2 >= 2 * seuil*seuil) // && !CameraPane.CROWD) // weightmode
613617 return 0;
614618
615
- dist2 /= 2 * SEUIL*SEUIL; // multiplied by two because center of support
619
+ dist2 /= 2 * seuil*seuil; // multiplied by two because center of support
616620 // could be far from closest point
617621
618622 // dist2 = Math.pow(dist2, 2);
....@@ -946,7 +950,7 @@
946950
947951 int nbsupports;
948952
949
- SEUIL = 0.1; // aout 2013
953
+ // sept 2017 SEUIL = 0.1; // aout 2013
950954
951955 supports = InitConnections(other);
952956
....@@ -982,7 +986,7 @@
982986
983987 int subsupports = 0;
984988
985
- SEUIL = 0.1; // aout 2013
989
+ // sept 2017 SEUIL = 0.1; // aout 2013
986990
987991 while (subsupports == 0)
988992 {
....@@ -1006,6 +1010,26 @@
10061010
10071011 vect.set(v);
10081012 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;
10091033
10101034 if (mindistance > vect.dot(vect))
10111035 {
....@@ -1017,7 +1041,9 @@
10171041
10181042 subsupports = v.closestsupport==-1 ? 0 : supports[v.closestsupport].Length();
10191043
1020
- SEUIL *= 2;
1044
+ // previously for "contains", now for weights.
1045
+ assert(subsupports > 0);
1046
+ //SEUIL *= 2;
10211047 }
10221048
10231049 assert(subsupports > 0);
....@@ -2163,7 +2189,7 @@
21632189 // if (slow)
21642190 // aout 2013
21652191 // sept 2013 merde...
2166
- W = 13;
2192
+ W = 3; // 13;
21672193
21682194 // POSERATE
21692195 if (CameraPane.tickcount > 0 || CameraPane.SLOWPOSE)
....@@ -3776,10 +3802,19 @@
37763802 for (int i = 0; i < VertexCount(); i++)
37773803 {
37783804 Vertex v = GetVertex(i);
3805
+
3806
+ vertextemp.set(v);
3807
+
37793808 //if (v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
37803809 {
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);
37833818 }
37843819 }
37853820
....@@ -3790,7 +3825,7 @@
37903825 static cVector temp2 = new cVector();
37913826 static cVector temp3 = new cVector();
37923827
3793
- void GenerateNormal(int index, Vertex v)
3828
+ boolean GenerateNormal(int index, Vertex v)
37943829 {
37953830 //System.out.println("Old normal = " + v.norm);
37963831 LA.setVector(v.norm, 0, 0, 0);
....@@ -3819,6 +3854,10 @@
38193854 LA.vecSub(p/*.pos*/, v/*.pos*/, temp1);
38203855 LA.vecSub(q/*.pos*/, v/*.pos*/, temp2);
38213856 }
3857
+ else
3858
+ {
3859
+ continue;
3860
+ }
38223861
38233862 //LA.vecNormalize(temp1);
38243863 //LA.vecNormalize(temp2);
....@@ -3829,17 +3868,25 @@
38293868 double s = temp3.length();
38303869 //double c = temp2.dot(temp1);
38313870
3871
+ if (s == 0)
3872
+ return false;
3873
+
38323874 float angle = 1; // (float) Math.atan2(s, c);
38333875 //if(angle < 0) angle = -angle;
38343876
38353877 //LA.vecNormalize(temp3);
38363878 LA.vecScale(temp3, angle / s);
38373879
3880
+// if (temp3.dot(v.norm) < 0)
3881
+// assert(temp3.dot(v.norm) >= 0);
3882
+
38383883 LA.vecAdd(temp3, v.norm, v.norm);
38393884 }
38403885
38413886 LA.vecNormalize(v.norm);
38423887 //System.out.println("New normal = " + v.norm);
3888
+
3889
+ return true;
38433890 }
38443891
38453892 double Arccos(double x)
....@@ -4885,7 +4932,7 @@
48854932 //colors[i3 + 1] = cp.vertexOcclusion.g;
48864933 //colors[i3 + 2] = cp.vertexOcclusion.b;
48874934
4888
- if ((i % 1000) == 0 && i != 0)
4935
+ if ((i % 100) == 0 && i != 0)
48894936 {
48904937 CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
48914938 //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
....@@ -4917,7 +4964,7 @@
49174964
49184965 v.AO = cp.vertexOcclusion.r;
49194966
4920
- if ((i % 1000) == 0 && i != 0)
4967
+ if ((i % 100) == 0 && i != 0)
49214968 {
49224969 CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
49234970 //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
....@@ -4926,7 +4973,7 @@
49264973 }
49274974 }
49284975
4929
- System.out.println("done.");
4976
+ //System.out.println("done.");
49304977
49314978 cp.renderCamera = keep;
49324979
....@@ -7075,6 +7122,7 @@
70757122 assert(f2.contains(i));
70767123 assert(f3.contains(i));
70777124
7125
+ // when r is the "center", p is along the boundary
70787126 while (f0.r != i)
70797127 {
70807128 int t = f0.p;
....@@ -7131,60 +7179,91 @@
71317179 f0 = f3;
71327180 f3 = t;
71337181 }
7134
- atleastone = true;
71357182
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.
71367192 Face otherf = null;
71377193
71387194 if (f1.contains(f0.p))
71397195 {
71407196 if (f1.p == f0.p)
71417197 {
7198
+ assert(false);
71427199 f0.r = f1.q;
71437200 }
71447201 else
71457202 {
71467203 assert(f1.q == f0.p);
7147
- f0.r = f1.p;
7204
+ vc = f1.p;
71487205 }
71497206
71507207 otherf = f2;
7151
- faces.remove(f1);
7152
- faces.remove(f3);
7208
+ toremove1 = f1;
7209
+ toremove2 = f3;
71537210 }
71547211 else
71557212 if (f2.contains(f0.p))
71567213 {
71577214 if (f2.p == f0.p)
71587215 {
7216
+ assert(false);
71597217 f0.r = f2.q;
71607218 }
71617219 else
71627220 {
71637221 assert(f2.q == f0.p);
7164
- f0.r = f2.p;
7222
+ vc = f2.p;
71657223 }
71667224
71677225 otherf = f3;
7168
- faces.remove(f1);
7169
- faces.remove(f2);
7226
+ toremove1 = f1;
7227
+ toremove2 = f2;
71707228 }
71717229 if (f3.contains(f0.p))
71727230 {
71737231 if (f3.p == f0.p)
71747232 {
7233
+// assert(false);
7234
+ new Exception().printStackTrace();
71757235 f0.r = f3.q;
71767236 }
71777237 else
71787238 {
71797239 assert(f3.q == f0.p);
7180
- f0.r = f3.p;
7240
+ vc = f3.p;
71817241 }
71827242
71837243 otherf = f1;
7184
- faces.remove(f2);
7185
- faces.remove(f3);
7244
+ toremove1 = f2;
7245
+ toremove2 = f3;
71867246 }
71877247
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
+
71887267 if (!f0.contains(otherf.p))
71897268 {
71907269 otherf.r = otherf.p;