Normand Briere
2019-04-23 ec9d13e42c9c8674739acefb0769a9273a1048c9
BoundaryRep.java
....@@ -15,7 +15,7 @@
1515 {
1616 this(0, 0);
1717 }
18
-
18
+
1919 void SaveSupports()
2020 {
2121 transientsupport = support;
....@@ -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);
....@@ -786,7 +790,7 @@
786790 v.weights[k] = other.ComputeWeight(v, toRoot, k); // (float)(supportsize * normalweight * nz / Math.pow(tx*tx+ty*ty+tz*tz, 1));
787791 v.totalweight += v.weights[k];
788792
789
- if (CameraPane.CROWD)
793
+ if (Globals.CROWD)
790794 {
791795 // System.out.print("weight = " + v.weights[k]);
792796 // System.out.println("; totalweight = " + v.totalweight);
....@@ -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);
....@@ -2635,18 +2661,18 @@
26352661 if (false) // slow && stepout && onein)
26362662 {
26372663 // sound
2638
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
2664
+ cVector eye = Globals.theRenderer.EyeCamera().location;
26392665
26402666 Vertex v = GetVertex(0);
26412667
26422668 tmp.set(v);
26432669 tmp.sub(eye);
26442670
2645
- if (CameraPane.framecount - lastsoundtime > 30) // 0.25 secs
2671
+ if (Globals.framecount - lastsoundtime > 30) // 0.25 secs
26462672 {
26472673 GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1);
26482674
2649
- lastsoundtime = CameraPane.framecount;
2675
+ lastsoundtime = Globals.framecount;
26502676 }
26512677
26522678 stepout = false;
....@@ -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)
....@@ -4381,7 +4428,7 @@
43814428 }
43824429 }
43834430
4384
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4431
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
43854432 {
43864433 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
43874434 CameraPane.tempmat,0, CameraPane.tempmat2,0,
....@@ -4413,14 +4460,14 @@
44134460 // june 2014
44144461 // Camera parentcam = cam;
44154462 //
4416
-// if (cam == CameraPane.theRenderer.cameras[0])
4463
+// if (cam == Globals.theRenderer.cameras[0])
44174464 // {
4418
-// parentcam = CameraPane.theRenderer.cameras[1];
4465
+// parentcam = Globals.theRenderer.cameras[1];
44194466 // }
44204467 //
4421
-// if (cam == CameraPane.theRenderer.cameras[1])
4468
+// if (cam == Globals.theRenderer.cameras[1])
44224469 // {
4423
-// parentcam = CameraPane.theRenderer.cameras[0];
4470
+// parentcam = Globals.theRenderer.cameras[0];
44244471 // }
44254472
44264473 gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, CameraPane.tempmat, 0);
....@@ -4846,7 +4893,7 @@
48464893 return verticesCopy;
48474894 }
48484895
4849
- void PreprocessOcclusion(CameraPane cp, double[][] transform)
4896
+ void PreprocessOcclusion(iCameraPane cp, double[][] transform)
48504897 {
48514898 if (//!trimmed ||
48524899 AOdone)
....@@ -4855,80 +4902,7 @@
48554902 return;
48564903 }
48574904
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;
4905
+ cp.PrepOcclusion(this, transform);
49324906
49334907 AOdone = true;
49344908 }
....@@ -7075,6 +7049,7 @@
70757049 assert(f2.contains(i));
70767050 assert(f3.contains(i));
70777051
7052
+ // when r is the "center", p is along the boundary
70787053 while (f0.r != i)
70797054 {
70807055 int t = f0.p;
....@@ -7131,59 +7106,90 @@
71317106 f0 = f3;
71327107 f3 = t;
71337108 }
7134
- atleastone = true;
71357109
7110
+ int va = f0.q;
7111
+ int vb = f0.r;
7112
+ int vc = -1;
7113
+
7114
+ Face toremove1 = null;
7115
+ Face toremove2 = null;
7116
+
7117
+ // f0 is the buffer for the first new triangle,
7118
+ // and otherf is the other upper one.
71367119 Face otherf = null;
71377120
71387121 if (f1.contains(f0.p))
71397122 {
71407123 if (f1.p == f0.p)
71417124 {
7125
+ assert(false);
71427126 f0.r = f1.q;
71437127 }
71447128 else
71457129 {
71467130 assert(f1.q == f0.p);
7147
- f0.r = f1.p;
7131
+ vc = f1.p;
71487132 }
71497133
71507134 otherf = f2;
7151
- faces.remove(f1);
7152
- faces.remove(f3);
7135
+ toremove1 = f1;
7136
+ toremove2 = f3;
71537137 }
71547138 else
71557139 if (f2.contains(f0.p))
71567140 {
71577141 if (f2.p == f0.p)
71587142 {
7143
+ assert(false);
71597144 f0.r = f2.q;
71607145 }
71617146 else
71627147 {
71637148 assert(f2.q == f0.p);
7164
- f0.r = f2.p;
7149
+ vc = f2.p;
71657150 }
71667151
71677152 otherf = f3;
7168
- faces.remove(f1);
7169
- faces.remove(f2);
7153
+ toremove1 = f1;
7154
+ toremove2 = f2;
71707155 }
71717156 if (f3.contains(f0.p))
71727157 {
71737158 if (f3.p == f0.p)
71747159 {
7160
+// assert(false);
7161
+ new Exception().printStackTrace();
71757162 f0.r = f3.q;
71767163 }
71777164 else
71787165 {
71797166 assert(f3.q == f0.p);
7180
- f0.r = f3.p;
7167
+ vc = f3.p;
71817168 }
71827169
71837170 otherf = f1;
7184
- faces.remove(f2);
7185
- faces.remove(f3);
7171
+ toremove1 = f2;
7172
+ toremove2 = f3;
71867173 }
7174
+
7175
+ vertextemp.set(vertices.get(va));
7176
+ vertextemp.sub(vertices.get(vb));
7177
+ vertextemp.normalize();
7178
+ vertextemp2.set(vertices.get(vc));
7179
+ vertextemp2.sub(vertices.get(vb));
7180
+ vertextemp2.normalize();
7181
+
7182
+ if (vertextemp.dot(vertextemp2) > -0.95)
7183
+ {
7184
+ continue;
7185
+ }
7186
+
7187
+ atleastone = true;
7188
+
7189
+ f0.r = vc;
7190
+
7191
+ faces.remove(toremove1);
7192
+ faces.remove(toremove2);
71877193
71887194 if (!f0.contains(otherf.p))
71897195 {
....@@ -7554,7 +7560,7 @@
75547560 s3 = new cVector();
75557561 }
75567562
7557
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
7563
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
75587564
75597565 try
75607566 {
....@@ -7649,7 +7655,7 @@
76497655 {
76507656 if (i++%100 == 0)
76517657 {
7652
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
7658
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
76537659 System.out.println("#faces = " + faces.size());
76547660 // if (i != 1)
76557661 // break;
....@@ -7693,7 +7699,7 @@
76937699 //Trim(true,cJME.gennormals,true,false); // doesn't work
76947700 Trim(true,false,false,false,false);
76957701
7696
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
7702
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
76977703 }
76987704
76997705 void UpdateIndices(Face face, Face minface)
....@@ -8275,9 +8281,6 @@
82758281 return "trim = " + trimmed + "; stripped = " + stripified + "; colors = " + colors + "; faces = " + (faces!=null?faces.size():null) + "; triangles = " + (triangles!=null?triangles.length:null) + "; indices = " + indices;
82768282 }
82778283
8278
- static Camera localcamera = new Camera();
8279
- static cVector from = new cVector();
8280
- static cVector to = new cVector();
82818284 boolean trimmed = false;
82828285 boolean stripified = false;
82838286 transient boolean AOdone = false;
....@@ -8285,8 +8288,10 @@
82858288 /*transient*/ int maxIndexV = 0;
82868289 /*transient*/ int bufV, bufF;
82878290 // Raw version
8288
- private float[] positions;
8289
- private float[] normals;
8291
+ //private
8292
+ float[] positions;
8293
+ //private
8294
+ float[] normals;
82908295 float[] colors;
82918296 private float[] uvmap;
82928297 private int[] triangles;