public static Edge GetEdge(Point A, Point B, IIsoSurface surface, List <Edge> edges) { Vector3 p; if (A.iso == 0) { p = A.p; } else if (B.iso == 0) { p = B.p; } else { Vector3 diff = B.p - A.p; Vector3 start = A.p; float ratio = 0.5f; p = start + (diff * ratio); float f = 0.25f; float iso; while ((iso = surface.sample(p.x, p.y, p.z)) > 0.0001) { ratio += f * Mathf.Sign(iso * A.iso); f /= 2; p = start + (diff * ratio); } } Vector3 n = surface.sampleDerivative(p.x, p.y, p.z); //Debug.DrawLine(A.p, B.p, new Color(0,0,1,0.5f), 30); return(new Edge(p, n, A, B, edges)); }
public int Draw(List <Vector3> vertices, List <Vector3> normals, List <int> triangles, IIsoSurface surface) { if (this.cells.Count < 4) { return(0); } int start = vertices.Count; int i = 0; foreach (Cell cell in cells) { i++; Vector3 p = cell.getPoint(); vertices.Add(p); normals.Add(surface.sampleDerivative(p.x, p.y, p.z)); } List <int> tris = new List <int>(); tris.Add(start); tris.Add(start + 1); tris.Add(start + 2); tris.Add(start + 1); tris.Add(start + 3); tris.Add(start + 2); /*for(int j = 0; j < tris.Count; j++) * { * triangles.Add(tris[j]); * }*/ Vector3 diff = B.p - A.p; for (int j = 0; j < tris.Count; j++) { triangles.Add(tris[j]); } for (int j = tris.Count - 1; j > -1; j--) { triangles.Add(tris[j]); } /*triangles.Add(start + 2); * triangles.Add(start + 3); * triangles.Add(start + 1); * triangles.Add(start + 3); * triangles.Add(start + 1); * triangles.Add(start);*/ return(i); }
public void DebugDraw(IIsoSurface surface) { if (this.edges.Count < 1) { return; } Vector3 p = getPoint(); Debug.DrawRay(p, surface.sampleDerivative(p.x, p.y, p.z), new Color(0, 0.4f, 0, 0.4f)); //Debug.DrawLine(Vector3.zero, p, Color.blue); }