/// <summary> /// Do Loop subdivision of the input control triangle mesh. /// </summary> /// <param name="scene">Input scene (must not be changed).</param> /// <param name="epsilon">Reference error toleration (size of undivided triangle).</param> /// <param name="normals">Generate normals? (optional)</param> /// <param name="colors">Generate colors? (optional)</param> /// <param name="txtcoord">Generate texture coordinates? (optional)</param> /// <param name="time">Current time for animation (optional)</param> /// <param name="param">Optional additional parameters.</param> /// <returns>Number of generated points.</returns> public int Subdivide(SceneBrep scene, float epsilon, bool normals, bool colors, bool txtcoord, float time, string param) { result = scene.Clone(); // !!!{{ TODO: put your Loop subdivision code here // pilot: do one (trivial) division int triangles = result.Triangles; int tr; for (tr = 0; tr < triangles; tr++) { int A, B, C; result.GetTriangleVertices(tr, out A, out B, out C); Vector3 vA = result.GetVertex(A); Vector3 vB = result.GetVertex(B); Vector3 vC = result.GetVertex(C); Vector3 vA2 = (vB + vC) * 0.5f; Vector3 vB2 = (vA + vC) * 0.5f; Vector3 vC2 = (vA + vB) * 0.5f; int A2 = result.AddVertex(vA2); int B2 = result.AddVertex(vB2); int C2 = result.AddVertex(vC2); result.AddTriangle(B2, C2, A2); result.AddTriangle(B2, A2, C); result.AddTriangle(C2, B, A2); result.SetTriangleVertices(tr, A, C2, B2); } //result.BuildCornerTable(); return(result.Vertices); // !!!}} }