/// <summary> /// Construct a new Brep solid (preferebaly closed = regular one). /// </summary> /// <param name="scene">B-rep scene to be modified</param> /// <param name="m">Transform matrix (object-space to world-space)</param> /// <param name="param">Shape parameters if needed</param> /// <returns>Number of generated faces (0 in case of failure)</returns> public int AddMesh(SceneBrep scene, Matrix4 m, string param) { parseParams(param); scene.Reserve(10000000); curve = Curve.createCurve(level); firstCircle(curve.current_vertices[0], curve.current_vertices[1], scene, m); int count = 0; for (int i = 1; i < curve.current_vertices.Length - 1; i++) { if (isBent(curve.current_vertices[i - 1], curve.current_vertices[i], curve.current_vertices[i + 1])) { count += createBentPipe(scene, m, curve.current_vertices[i - 1], curve.current_vertices[i], curve.current_vertices[i + 1]); } else { Vector3 dif = curve.current_vertices[i] - curve.current_vertices[i - 1]; for (int j = 0; j < cdetail; j++) { last_circle[j] = last_circle[j] + dif; } } } int l = curve.current_vertices.Length; count += lastCircle(curve.current_vertices[l - 2], curve.current_vertices[l - 1], scene, m); return(count); }
/// <summary> /// Construct a new Brep solid (preferebaly closed = regular one). /// </summary> /// <param name="scene">B-rep scene to be modified</param> /// <param name="m">Transform matrix (object-space to world-space)</param> /// <param name="param">Shape parameters if needed</param> /// <returns>Number of generated faces (0 in case of failure)</returns> public int AddMesh(SceneBrep scene, Matrix4 m, string param) { // !!!{{ TODO: put your Mesh-construction code here // if there will be large number of new vertices, reserve space for them to save time: scene.Reserve(4); return(CreateTetrahedron(scene, m, Vector3.Zero, 1.0f)); // !!!}} }
/// <summary> /// Construct a new Brep solid (preferebaly closed = regular one). /// </summary> /// <param name="scene">B-rep scene to be modified</param> /// <param name="m">Transform matrix (object-space to world-space)</param> /// <param name="param">Shape parameters if needed</param> /// <returns>Number of generated faces (0 in case of failure)</returns> public int AddMesh(SceneBrep scene, Matrix4 m, string param) { parseParams(param); scene.Reserve(10000000); Curve c = new Curve(xFreq, yFreq, zFreq, thickness, vertexFreq, circEdgeSize); c.GenerateThingsForScene(m); c.RenderSceneSimpleTube(scene); // c.RenderSceneJustCurve(scene); return(c.GeneratedFaces); }
/// <summary> /// Construct a new Brep solid (preferebaly closed = regular one). /// </summary> /// <param name="scene">B-rep scene to be modified</param> /// <param name="m">Transform matrix (object-space to world-space)</param> /// <param name="param">Shape parameters if needed</param> /// <returns>Number of generated faces (0 in case of failure)</returns> public int AddMesh(SceneBrep scene, Matrix4 m, string param) { // {{ TODO: put your Mesh-construction code here parseParams(param); // If there will be large number of new vertices, reserve space for them to save time. scene.Reserve(segments + 1); double t = 0.0; double dt = maxT / segments; double s = 0.0; // for both texture coordinate & color ramp double ds = 1.0 / segments; int vPrev = 0; Vector3 A; for (int i = 0; i <= segments; i++) { // New vertex's coordinates. A.X = (float)(radius * Math.Cos(kx * t + dx)); A.Y = (float)(radius * Math.Cos(ky * t + dy)); A.Z = (float)(radius * Math.Cos(kz * t + dz)); // New vertex. int v = scene.AddVertex(Vector3.TransformPosition(A, m)); // Vertex attributes. scene.SetTxtCoord(v, new Vector2((float)s, (float)s)); System.Drawing.Color c = Raster.Draw.ColorRamp(0.5 * (s + 1.0)); scene.SetColor(v, new Vector3(c.R / 255.0f, c.G / 255.0f, c.B / 255.0f)); // New line? if (i > 0) { scene.AddLine(vPrev, v); } // Next vertex. t += dt; s += ds; vPrev = v; } // Thick line (for rendering). scene.LineWidth = 3.0f; return(segments); // }} }
private int drawTetrahedron(SceneBrep scene, Matrix4 m, string param) { segments = 4; scene.Reserve(segments + (int)Math.Pow(4, depthParam) + 1); /*c.Line(0, 0, 0, c.Height); * c.Line(0, c.Height, c.Width, c.Height / 2); * c.Line(c.Width, c.Height / 2, 0, 0); */ Vector3 A, B, C, D; int one, two, three, four; //float a = 1.0f; A.X = 0; A.Y = 0; A.Z = 0; one = scene.AddVertex(Vector3.TransformPosition(A, m)); B.X = 1.0f; B.Y = 1.0f; B.Z = 0; two = scene.AddVertex(Vector3.TransformPosition(B, m)); C.X = 0; C.Y = 1.0f; C.Z = 1.0f; three = scene.AddVertex(Vector3.TransformPosition(C, m)); D.X = 1.0f; D.Y = 0; D.Z = 1.0f; four = scene.AddVertex(Vector3.TransformPosition(D, m)); scene.AddLine(one, two); scene.AddLine(two, three); scene.AddLine(three, one); scene.AddLine(four, one); scene.AddLine(four, two); scene.AddLine(four, three); drawTetrahedronRecursive(depthParam, scene, m, param, A, B, C, D); return(segments + (int)Math.Pow(4, depthParam) + 1); }
/// <summary> /// Construct a new Brep solid (preferebaly closed = regular one). /// </summary> /// <param name="scene">B-rep scene to be modified</param> /// <param name="m">Transform matrix (object-space to world-space)</param> /// <param name="param">Shape parameters if needed</param> /// <returns>Number of generated faces (0 in case of failure)</returns> public int AddMesh(SceneBrep scene, Matrix4 m, string param) { parseParams(param); int elements = 6 + (depth > 0 ? 8 * (int)Math.Pow(3, depth - 1) : 0) + (center ? 1 : 0); scene.Reserve(elements); int middle = scene.AddVertex(Vector3.TransformPosition(new Vector3(0, 0, 0), m)); GenerateBaseVertices(); GenerateSubVertices(); // Generate int positions { Queue <Vertex> currentVertices = new Queue <Vertex>(baseVertices); while (currentVertices.Count > 0) { Vertex currentVertex = currentVertices.Dequeue(); currentVertex.Position = scene.AddVertex(Vector3.TransformPosition(currentVertex.Vector3, m)); for (int i = 0; i < currentVertex.SubVertices.Count; i++) { currentVertices.Enqueue(currentVertex.SubVertices[i]); } } } if (neighbors) { Queue <Vertex> currentVertices = new Queue <Vertex>(baseVertices); while (currentVertices.Count > 0) { Vertex currentVertex = currentVertices.Dequeue(); for (int i = 0; i < currentVertex.Neighbors.Count; i++) { scene.AddLine(currentVertex.Position, currentVertex.Neighbors[i].Position); } for (int i = 0; i < currentVertex.SubVertices.Count; i++) { currentVertices.Enqueue(currentVertex.SubVertices[i]); } } } if (center) { Queue <Vertex> currentVertices = new Queue <Vertex>(baseVertices); while (currentVertices.Count > 0) { Vertex currentVertex = currentVertices.Dequeue(); scene.AddLine(currentVertex.Position, middle); for (int i = 0; i < currentVertex.SubVertices.Count; i++) { currentVertices.Enqueue(currentVertex.SubVertices[i]); } } } scene.LineWidth = 3.0f; return(elements); }