示例#1
0
        // 11 group
        private int makeGroup(Mesh newMesh, PRIM prim, int startIndex)
        {
            int cp = 0;

            foreach (Vertices vertices in prim.VerticesList)
            {
                if (vertices.VertexList.Count < 3)
                {
                    continue;
                }

                List <Vector4> controlPoints = new List <Vector4>();
                foreach (RVMUtility.Data.Vertex v in vertices.VertexList)
                {
                    Vector4 vector = this.CalcMatrix(prim, v.X, v.Y, v.Z);
                    controlPoints.Add(vector);
                }

                newMesh.ControlPoints.AddRange(controlPoints);
                PolygonBuilder builder = new PolygonBuilder(newMesh);
                builder.Begin();
                for (int i = 0; i < controlPoints.Count; i++)
                {
                    builder.AddVertex(startIndex + i + cp);
                }
                builder.End();
                cp += controlPoints.Count;
            }

            return(cp);
        }
示例#2
0
        public static Mesh CreateMesh()
        {
            // Initialize control points
            Vector4[] controlPoints = new Vector4[] {
                new Vector4(-5.0, 0.0, 5.0, 1.0),
                new Vector4(5.0, 0.0, 5.0, 1.0),
                new Vector4(5.0, 10.0, 5.0, 1.0),
                new Vector4(-5.0, 10.0, 5.0, 1.0),
                new Vector4(-5.0, 0.0, -5.0, 1.0),
                new Vector4(5.0, 0.0, -5.0, 1.0),
                new Vector4(5.0, 10.0, -5.0, 1.0),
                new Vector4(-5.0, 10.0, -5.0, 1.0)
            };
            // Initialize mesh object
            Mesh mesh = new Mesh();

            // Add control points to the mesh
            mesh.ControlPoints.AddRange(controlPoints);

            // Indices of the vertices per each polygon
            int[] indices = new int[] {
                0, 1, 2, 3, // front face (Z+)
                1, 5, 6, 2, // right side (X+)
                5, 4, 7, 6, // back face (Z-)
                4, 0, 3, 7, // left side (X-)
                0, 4, 5, 1, // bottom face (Y-)
                3, 2, 6, 7  // top face (Y+)
            };

            int            vertexId = 0;
            PolygonBuilder builder  = new PolygonBuilder(mesh);

            for (int face = 0; face < 6; face++)
            {
                // Start defining a new polygon
                builder.Begin();
                for (int v = 0; v < 4; v++)
                {
                    // The indice of vertice per each polygon
                    builder.AddVertex(indices[vertexId++]);
                }
                // Finished one polygon
                builder.End();
            }

            return(mesh);
        }
示例#3
0
        public static Mesh CreateMesh()
        {
            // Initialize control points
            Vector4[] controlPoints = new Vector4[]{
            new Vector4( -5.0, 0.0, 5.0, 1.0),
            new Vector4( 5.0, 0.0, 5.0, 1.0),
            new Vector4( 5.0, 10.0, 5.0, 1.0),
            new Vector4( -5.0, 10.0, 5.0, 1.0),
            new Vector4( -5.0, 0.0, -5.0, 1.0),
            new Vector4( 5.0, 0.0, -5.0, 1.0),
            new Vector4( 5.0, 10.0, -5.0, 1.0),
            new Vector4( -5.0, 10.0, -5.0, 1.0)
            };
            // Initialize mesh object
            Mesh mesh = new Mesh();

            // Add control points to the mesh
            mesh.ControlPoints.AddRange(controlPoints);

            // Indices of the vertices per each polygon
            int[] indices = new int[]{
            0,1,2,3, // front face (Z+)
            1,5,6,2, // right side (X+)
            5,4,7,6, // back face (Z-)
            4,0,3,7, // left side (X-)
            0,4,5,1, // bottom face (Y-)
            3,2,6,7 // top face (Y+)
            };

            int vertexId = 0;
            PolygonBuilder builder = new PolygonBuilder(mesh);
            for (int face = 0; face < 6; face++)
            {
                // Start defining a new polygon
                builder.Begin();
                for (int v = 0; v < 4; v++)
                    // The indice of vertice per each polygon
                    builder.AddVertex(indices[vertexId++]);
                // Finished one polygon
                builder.End();
            }

            return mesh;
        }
示例#4
0
        public static Mesh CreateMeshUsingPolygonBuilder()
        {
            // ExStart:CreateMeshUsingPolygonBuilder
            Vector4[] controlPoints = DefineControlPoints();

            // Initialize mesh object
            Mesh mesh = new Mesh();

            // Add control points to the mesh
            mesh.ControlPoints.AddRange(controlPoints);

            // Indices of the vertices per each polygon
            int[] indices = new int[]
            {
                0, 1, 2, 3, // Front face (Z+)
                1, 5, 6, 2, // Right side (X+)
                5, 4, 7, 6, // Back face (Z-)
                4, 0, 3, 7, // Left side (X-)
                0, 4, 5, 1, // Bottom face (Y-)
                3, 2, 6, 7  // Top face (Y+)
            };

            int            vertexId = 0;
            PolygonBuilder builder  = new PolygonBuilder(mesh);

            for (int face = 0; face < 6; face++)
            {
                // Start defining a new polygon
                builder.Begin();
                for (int v = 0; v < 4; v++)
                {
                    // The indice of vertice per each polygon
                    builder.AddVertex(indices[vertexId++]);
                }
                // Finished one polygon
                builder.End();
            }

            // ExEnd:CreateMeshUsingPolygonBuilder
            return(mesh);
        }
示例#5
0
        public static Mesh CreateMeshUsingPolygonBuilder()
        {
            // ExStart:CreateMeshUsingPolygonBuilder           
            Vector4[] controlPoints = DefineControlPoints();
            
            // Initialize mesh object
            Mesh mesh = new Mesh();

            // Add control points to the mesh
            mesh.ControlPoints.AddRange(controlPoints);
            
            // Indices of the vertices per each polygon
            int[] indices = new int[]
            {
                0,1,2,3, // Front face (Z+)
                1,5,6,2, // Right side (X+)
                5,4,7,6, // Back face (Z-)
                4,0,3,7, // Left side (X-)
                0,4,5,1, // Bottom face (Y-)
                3,2,6,7 // Top face (Y+)
            };

            int vertexId = 0;
            PolygonBuilder builder = new PolygonBuilder(mesh);
            for (int face = 0; face < 6; face++)
            {
                // Start defining a new polygon
                builder.Begin();
                for (int v = 0; v < 4; v++)
                    // The indice of vertice per each polygon
                    builder.AddVertex(indices[vertexId++]);
                // Finished one polygon
                builder.End();
            }

            // ExEnd:CreateMeshUsingPolygonBuilder
            return mesh;
        }
示例#6
0
        // 9 sphere
        private int makeSphere(Mesh newMesh, PRIM prim, int startIndex)
        {
            double radius = prim.Length[0, 0];

            double sliceCount = 8;
            double stackCount = 6;

            double phiStep   = Math.PI / stackCount;
            double thetaStep = 2.0 * Math.PI / sliceCount;

            List <Vector4> controlPoints = new List <Vector4>();

            for (int i = 0; i < stackCount + 1; i++)
            {
                double phi = i * phiStep;

                for (int j = 0; j < sliceCount; j++)
                {
                    double theta = j * thetaStep;
                    double x     = radius * Math.Sin(phi) * Math.Cos(theta);
                    double y     = radius * Math.Cos(phi);
                    double z     = radius * Math.Sin(phi) * Math.Sin(theta);

                    Vector4 v = this.CalcMatrix(prim, x, y, z);
                    controlPoints.Add(v);

                    if (i == 0 || i == stackCount)
                    {
                        break;
                    }
                }
            }


            newMesh.ControlPoints.AddRange(controlPoints);
            PolygonBuilder builder = new PolygonBuilder(newMesh);
            int            sc      = (int)sliceCount;

            for (int i = 0; i < sc - 1; i++)
            {
                builder.Begin();
                builder.AddVertex(startIndex + 0);
                builder.AddVertex(startIndex + i + 2);
                builder.AddVertex(startIndex + i + 1);
                builder.End();
            }
            builder.Begin();
            builder.AddVertex(startIndex + 0);
            builder.AddVertex(startIndex + 1);
            builder.AddVertex(startIndex + sc);
            builder.End();


            for (int i = 0; i < stackCount - 2; i++)
            {
                for (int j = 0; j < sc - 1; j++)
                {
                    builder.Begin();
                    builder.AddVertex(startIndex + (i * sc) + j + 1);
                    builder.AddVertex(startIndex + (i * sc) + j + 2);
                    builder.AddVertex(startIndex + (i * sc) + j + sc + 2);
                    builder.AddVertex(startIndex + (i * sc) + j + sc + 1);
                    builder.End();
                }

                builder.Begin();
                builder.AddVertex(startIndex + (i * sc) + 1);
                builder.AddVertex(startIndex + (i * sc) + sc + 1);
                builder.AddVertex(startIndex + (i * sc) + sc + sc);
                builder.AddVertex(startIndex + (i * sc) + sc);
                builder.End();
            }

            return(controlPoints.Count);
        }
示例#7
0
        // 7, 8 cylinder
        private int makeCylinder(Mesh newMesh, PRIM prim, int startIndex)
        {
            double radiusTop    = 0;
            double radiusBottom = radiusTop;
            double height       = 0;

            if (prim.Type == 7)
            {
                radiusBottom = prim.Length[0, 0];
                radiusTop    = prim.Length[0, 1];
                height       = prim.Length[0, 2];
            }
            else if (prim.Type == 8)
            {
                radiusBottom = prim.Length[0, 0];
                radiusTop    = prim.Length[0, 0];
                height       = prim.Length[0, 1];
            }

            int    sliceCount  = 8;
            int    stackCount  = 1;
            int    ringCount   = stackCount + 1;
            double stackHeight = height / stackCount;
            double radiusStep  = (radiusTop - radiusBottom) / stackCount;

            List <Vector4> controlPoints = new List <Vector4>();

            for (int i = 0; i < ringCount; i++)
            {
                double z      = (-0.5f * height) + (i * stackHeight);
                double r      = radiusBottom + (i * radiusStep);
                double dTheta = (2.0f * Math.PI) / sliceCount;

                for (int j = 0; j < sliceCount; j++)
                {
                    double c = Math.Cos(j * dTheta);
                    double s = Math.Sin(j * dTheta);

                    Vector4 v = this.CalcMatrix(prim, r * c, r * s, z);
                    controlPoints.Add(v);
                }
            }


            newMesh.ControlPoints.AddRange(controlPoints);
            PolygonBuilder builder = new PolygonBuilder(newMesh);

            for (int i = 0; i < sliceCount - 1; i++)
            {
                builder.Begin();
                builder.AddVertex(startIndex + i);
                builder.AddVertex(startIndex + i + 1);
                builder.AddVertex(startIndex + i + sliceCount + 1);
                builder.AddVertex(startIndex + i + sliceCount);
                builder.End();
            }

            builder.Begin();
            builder.AddVertex(startIndex + 0);
            builder.AddVertex(startIndex + sliceCount);
            builder.AddVertex(startIndex + sliceCount + sliceCount - 1);
            builder.AddVertex(startIndex + sliceCount - 1);
            builder.End();


            if (prim.Type == 8)
            {
                builder.Begin();
                for (int i = 0; i < sliceCount; i++)
                {
                    builder.AddVertex(startIndex + sliceCount - 1 - i);
                }
                builder.End();

                builder.Begin();
                for (int i = 0; i < sliceCount; i++)
                {
                    builder.AddVertex(startIndex + sliceCount + i);
                }
                builder.End();
            }

            return(controlPoints.Count);
        }
示例#8
0
        // 2
        private int makeBox(Mesh newMesh, PRIM prim, int startIndex)
        {
            double xlen = prim.Length[0, 0] / 2;
            double ylen = prim.Length[0, 1] / 2;
            double zlen = prim.Length[0, 2] / 2;

            //Console.WriteLine(string.Format("{0} {1} {2} {3}", xtlen, xblen, ylen, zlen));

            Vector4 v1 = this.CalcMatrix(prim, xlen, ylen, zlen);
            Vector4 v2 = this.CalcMatrix(prim, xlen * -1, ylen, zlen);
            Vector4 v3 = this.CalcMatrix(prim, xlen * -1, ylen * -1, zlen);
            Vector4 v4 = this.CalcMatrix(prim, xlen, ylen * -1, zlen);

            Vector4 v5 = this.CalcMatrix(prim, xlen, ylen, zlen * -1);
            Vector4 v6 = this.CalcMatrix(prim, xlen * -1, ylen, zlen * -1);
            Vector4 v7 = this.CalcMatrix(prim, xlen * -1, ylen * -1, zlen * -1);
            Vector4 v8 = this.CalcMatrix(prim, xlen, ylen * -1, zlen * -1);


            List <Vector4> controlPoints = new List <Vector4>();

            controlPoints.Add(v1);
            controlPoints.Add(v2);
            controlPoints.Add(v3);
            controlPoints.Add(v4);
            controlPoints.Add(v5);
            controlPoints.Add(v6);
            controlPoints.Add(v7);
            controlPoints.Add(v8);


            newMesh.ControlPoints.AddRange(controlPoints);
            PolygonBuilder builder = new PolygonBuilder(newMesh);

            builder.Begin();
            for (int i = 0; i < 4; i++)
            {
                builder.AddVertex(startIndex + i);
            }
            builder.End();

            builder.Begin();
            for (int i = 0; i < 4; i++)
            {
                builder.AddVertex(startIndex + i + 4);
            }
            builder.End();


            for (int i = 0; i < 3; i++)
            {
                builder.Begin();
                builder.AddVertex(startIndex + i);
                builder.AddVertex(startIndex + i + 4);
                builder.AddVertex(startIndex + i + 5);
                builder.AddVertex(startIndex + i + 1);
                builder.End();
            }

            builder.Begin();
            builder.AddVertex(startIndex + 3);
            builder.AddVertex(startIndex + 7);
            builder.AddVertex(startIndex + 4);
            builder.AddVertex(startIndex + 0);
            builder.End();

            return(controlPoints.Count);
        }