public static MeshNode generate_arbitrary_quad(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 center, float uvMult) { MeshNode n0 = new MeshNode(v0, v0 - center, new Vector2(1.0f * uvMult, 1.0f * uvMult)); MeshNode n1 = new MeshNode(v1, v1 - center, new Vector2(2.0f * uvMult, 1.0f * uvMult)); MeshNode n2 = new MeshNode(v2, v2 - center, new Vector2(1.0f * uvMult, 2.0f * uvMult)); MeshNode n3 = new MeshNode(v3, v3 - center, new Vector2(2.0f * uvMult, 2.0f * uvMult)); //connect square //0_____1 //|\ | //| \ | //| \ | //| \ | //| \| //2_____3 // //border edges n0.AddEdge(n1); n0.AddEdge(n2); n1.AddEdge(n3); n2.AddEdge(n3); //cross edge n0.AddEdge(n3); //return v0 as center point return(n0); }
private static void cone_recurse(MeshNode n0, MeshNode n1) { List <MeshNode> edgesCopy = new List <MeshNode>(n0.edges); n0.visited = true; n0.AddEdge(n1); for (int i = 0; i < edgesCopy.Count; i++) { if (edgesCopy[i].visited == false) { cone_recurse(edgesCopy[i], n1); } } }
// Add a point on the edge between this and n0 public MeshNode SplitEdge(MeshNode n0, Vector3 position, Vector3 normal) { MeshNode insert = new MeshNode(position, normal, new Vector2((uv.x + n0.uv.x) / 2.0f, (uv.y + n0.uv.y) / 2.0f)); //add insert in the middle insert.AddEdge(this); insert.AddEdge(n0); this.RemoveEdge(n0); //TODO check this //set insert as visited initially insert.visited = false; //now add shared edges to create new tris for (int i = 0; i < n0.edges.Count; i++) { if (this.edges.Contains(n0.edges[i]) && n0.edges[i] != insert) { insert.AddEdge(n0.edges[i]); } } return(insert); }
//TODO write this function to draw the cross values private static void cylinder_recurse(MeshNode n0, MeshNode n1, MeshNode back) { List <MeshNode> edgesCopy = new List <MeshNode>(n0.edges); List <MeshNode> edgesCopy2 = new List <MeshNode>(n1.edges); bool last_node = true; n0.visited = true; n1.visited = true; n0.AddEdge(n1); for (int i = 0; i < edgesCopy.Count; i++) { if (edgesCopy[i].visited == false) { edgesCopy[i].AddEdge(n1); cylinder_recurse(edgesCopy[i], edgesCopy2[i], back); last_node = false; } } if (last_node == true) { n1.AddEdge(back); } }
//use meshnode n0 to return the non directional graph of a cube public static MeshNode generate_cube(float x, float y, float z, float a0, float a1, float a2) { Vector3 center = new Vector3(x, y, z); //statically declare al 8 vertices //TODO figure out UV MeshNode n0 = new MeshNode( new Vector3(x - 0.5f * a0, y - 0.5f * a1, z - 0.5f * a2), new Vector3(x - 0.5f * a0 - center.x, y - 0.5f * a1 - center.y, z - 0.5f * a2 - center.z), new Vector2(0, 0)); MeshNode n1 = new MeshNode( new Vector3(x + 0.5f * a0, y - 0.5f * a1, z - 0.5f * a2), new Vector3(x + 0.5f * a0 - center.x, y - 0.5f * a1 - center.y, z - 0.5f * a2 - center.z), new Vector2(1, 0)); MeshNode n2 = new MeshNode( new Vector3(x - 0.5f * a0, y + 0.5f * a1, z - 0.5f * a2), new Vector3(x - 0.5f * a0 - center.x, y + 0.5f * a1 - center.y, z - 0.5f * a2 - center.z), new Vector2(0, 1)); MeshNode n3 = new MeshNode( new Vector3(x + 0.5f * a0, y + 0.5f * a1, z - 0.5f * a2), new Vector3(x + 0.5f * a0 - center.x, y + 0.5f * a1 - center.y, z - 0.5f * a2 - center.z), new Vector2(1, 1)); MeshNode n4 = new MeshNode( new Vector3(x - 0.5f * a0, y - 0.5f * a1, z + 0.5f * a2), new Vector3(x - 0.5f * a0 - center.x, y - 0.5f * a1 - center.y, z + 0.5f * a2 - center.z), new Vector2(0, 1)); MeshNode n5 = new MeshNode( new Vector3(x + 0.5f * a0, y - 0.5f * a1, z + 0.5f * a2), new Vector3(x + 0.5f * a0 - center.x, y - 0.5f * a1 - center.y, z + 0.5f * a2 - center.z), new Vector2(1, 1)); MeshNode n6 = new MeshNode( new Vector3(x - 0.5f * a0, y + 0.5f * a1, z + 0.5f * a2), new Vector3(x - 0.5f * a0 - center.x, y + 0.5f * a1 - center.y, z + 0.5f * a2 - center.z), new Vector2(0, 0)); MeshNode n7 = new MeshNode( new Vector3(x + 0.5f * a0, y + 0.5f * a1, z + 0.5f * a2), new Vector3(x + 0.5f * a0 - center.x, y + 0.5f * a1 - center.y, z + 0.5f * a2 - center.z), new Vector2(1, 0)); //cube vertices //4______6 //|\ |\ //| \ | \ //| \5__|__7 //0___|__2 | // \ | \ | // \ | \ | // \1_____3 //create edges all basic triangles <3 //direct n0.AddEdge(n1); n0.AddEdge(n2); n0.AddEdge(n4); n1.AddEdge(n3); n1.AddEdge(n5); n2.AddEdge(n3); n2.AddEdge(n6); n3.AddEdge(n7); n4.AddEdge(n5); n4.AddEdge(n6); n5.AddEdge(n7); n6.AddEdge(n7); //diags n0.AddEdge(n6); n1.AddEdge(n4); n2.AddEdge(n7); n3.AddEdge(n5); n5.AddEdge(n6); n1.AddEdge(n2); return(n0); }
public static MeshNode generate_square(float x, float y, float z, float width, Axis axis, Vector3 center, float uvMult) { Vector3 v0, v1, v2, v3; //center point Vector3 v4 = new Vector3(x, y, z); switch (axis) { case Axis.X_AXIS: v0 = new Vector3(x, y - 0.5f * width, z - 0.5f * width); v1 = new Vector3(x, y + 0.5f * width, z - 0.5f * width); v2 = new Vector3(x, y - 0.5f * width, z + 0.5f * width); v3 = new Vector3(x, y + 0.5f * width, z + 0.5f * width); break; case Axis.Y_AXIS: v0 = new Vector3(x - 0.5f * width, y, z - 0.5f * width); v1 = new Vector3(x + 0.5f * width, y, z - 0.5f * width); v2 = new Vector3(x - 0.5f * width, y, z + 0.5f * width); v3 = new Vector3(x + 0.5f * width, y, z + 0.5f * width); break; case Axis.Z_AXIS: v0 = new Vector3(x - 0.5f * width, y - 0.5f * width, z); v1 = new Vector3(x + 0.5f * width, y - 0.5f * width, z); v2 = new Vector3(x - 0.5f * width, y + 0.5f * width, z); v3 = new Vector3(x + 0.5f * width, y + 0.5f * width, z); break; default: v0 = new Vector3(0, 0, 0); v1 = new Vector3(0, 0, 0); v2 = new Vector3(0, 0, 0); v3 = new Vector3(0, 0, 0); break; } MeshNode n0 = new MeshNode(v0, v0 - center, new Vector2(1.0f * uvMult, 1.0f * uvMult)); MeshNode n1 = new MeshNode(v1, v1 - center, new Vector2(2.0f * uvMult, 1.0f * uvMult)); MeshNode n2 = new MeshNode(v2, v2 - center, new Vector2(1.0f * uvMult, 2.0f * uvMult)); MeshNode n3 = new MeshNode(v3, v3 - center, new Vector2(2.0f * uvMult, 2.0f * uvMult)); MeshNode n4 = new MeshNode(v4, v4 - center, new Vector2(1.5f * uvMult, 1.5f * uvMult)); //connect square //0_____1 //|\ /| //| \ / | //| 4 | //| / \ | //|/ \| //2_____3 // //border edges n0.AddEdge(n1); n0.AddEdge(n2); n1.AddEdge(n3); n2.AddEdge(n3); //cross edges n4.AddEdge(n0); n4.AddEdge(n1); n4.AddEdge(n2); n4.AddEdge(n3); //return head as center point return(n4); }