示例#1
0
        public Face4 clone()
        {
            Face4 face = new Face4(a, b, c, d);

            face.normal   = new Vector3(this.normal);
            face.color    = Color.FromArgb(this.color.ToArgb());
            face.centroid = new Vector3(this.centroid);

            int i, il;

            for (i = 0, il = this.vertexNormals.Count; i < il; i++)
            {
                face.vertexNormals.Add(new Vector3(this.vertexNormals[i]));
            }
            for (i = 0, il = this.vertexColors.Count; i < il; i++)
            {
                face.vertexColors.Add(Color.FromArgb(this.vertexColors[i].ToArgb()));
            }
            for (i = 0, il = this.vertexTangents.Count; i < il; i++)
            {
                face.vertexTangents.Add(new Vector3(this.vertexTangents[i]));
            }

            return(face);
        }
示例#2
0
        public void buildPlane(char u, char v, int udir, int vdir, int width, int height, int depth, int materialindex)
        {
            int  ix, iy;
            char w     = 'c';
            int  gridX = scope.widthSegment;
            int  gridY = scope.heightSegment;

            width_half  = width / 2;
            height_half = height / 2;
            int offSet = scope.vertices.Count;

            if ((u.Equals('x') && v.Equals('y')) || (u.Equals('y') && v.Equals('x')))
            {
                w = 'z';
            }
            else if ((u.Equals('x') && v.Equals('z')) || (u.Equals('z') && v.Equals('x')))
            {
                w     = 'y';
                gridY = scope.depthSegment;
            }
            else if ((u.Equals('z') && v.Equals('y')) || (u.Equals('y') && v.Equals('z')))
            {
                w     = 'x';
                gridY = scope.depthSegment;
            }

            int     gridX1                   = gridX + 1;
            int     gridY1                   = gridY + 1;
            int     segment_width            = width / gridX;
            int     segment_height           = height / gridY;
            Vector3 normal                   = new Vector3();
            Dictionary <char, int> normaldic = new Dictionary <char, int> ();

            normaldic [w] = depth > 0 ? 1 : -1;
            normaldic [u] = 0;
            normaldic [v] = 0;

            normal.X = normaldic ['x'];
            normal.Y = normaldic ['y'];
            normal.Z = normaldic ['z'];


            for (iy = 0; iy < gridY1; iy++)
            {
                for (ix = 0; ix < gridX1; ix++)
                {
                    Vector3 vector = new Vector3();
                    Dictionary <char, int> vectordic = new Dictionary <char, int> ();
                    vectordic [u] = (ix * segment_width - width_half) * udir;
                    vectordic [v] = (iy * segment_height - height_half) * vdir;
                    vectordic [w] = depth;

                    vector.X = vectordic ['x'];
                    vector.Y = vectordic ['y'];
                    vector.Z = vectordic ['z'];

                    scope.vertices.Add(vector);
                }
            }


            for (iy = 0; iy < gridY; iy++)
            {
                for (ix = 0; ix < gridX; ix++)
                {
                    int a = ix + gridX1 * iy;
                    int b = ix + gridX1 * (iy + 1);
                    int c = (ix + 1) + gridX1 * (iy + 1);
                    int d = (ix + 1) + gridX1 * iy;

                    Face4 face = new Face4(a + offSet, b + offSet, c + offSet, d + offSet);
                    face.normal = new Vector3(normal);
                    face.vertexNormals.Add(new Vector3(normal));
                    face.vertexNormals.Add(new Vector3(normal));
                    face.vertexNormals.Add(new Vector3(normal));
                    face.vertexNormals.Add(new Vector3(normal));
                    face.materialIndex = materialindex;

                    scope.faces.Add(face);

                    scope.faceVertexUvs.Add(new List <List <Vector2> >());
                    scope.faceVertexUvs[0].Add(new List <Vector2>());
                    scope.faceVertexUvs[0][0].Add(new Vector2(ix / gridX, 1 - iy / gridY));
                    scope.faceVertexUvs[0][0].Add(new Vector2(ix / gridX, 1 - (iy + 1) / gridY));
                    scope.faceVertexUvs[0][0].Add(new Vector2((ix + 1) / gridX, 1 - (iy + 1) / gridY));
                    scope.faceVertexUvs[0][0].Add(new Vector2((ix + 1) / gridX, 1 - iy / gridY));
                }
            }

            this.computeCentroids();
            this.mergeVertices();
        }