예제 #1
0
        /// <summary>
        /// Loads an OBJ file from a stream.
        /// </summary>
        /// <param name="stream">A stream with OBJ file data.</param>
        private static TriMesh LoadObjStream(Stream stream)
        {
            TriMesh mesh = new TriMesh();

            mesh.Traits.HasFaceVertexNormals  = true;
            mesh.Traits.HasTextureCoordinates = true;

            StreamReader          sr    = new StreamReader(stream);
            ObjFileProcessorState state = new ObjFileProcessorState();
            string line;

            while ((line = sr.ReadLine()) != null)
            {
                ProcessObjLine(mesh, line, state);
            }

            if (state.VertexTextureCoords.Count == mesh.Vertices.Count)
            {
                for (int i = 0; i < mesh.Vertices.Count; i++)
                {
                    mesh.Vertices[i].Traits.UV = state.VertexTextureCoords[i];
                }
            }
            mesh.TrimExcess();
            return(mesh);
        }
예제 #2
0
        public static TriMesh Clone(TriMesh mesh)
        {
            TriMesh newMesh = new TriMesh();
            for (int i = 0; i < mesh.Vertices.Count; i++)
            {
                VertexTraits traits = new VertexTraits(mesh.Vertices[i].Traits.Position.x,
                                                       mesh.Vertices[i].Traits.Position.y,
                                                       mesh.Vertices[i].Traits.Position.z);
                newMesh.Vertices.Add(traits);
            }

            TriMesh.Vertex[] faceVetices = new TriMesh.Vertex[3];
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                int faceVertexIndex1 = mesh.Faces[i].GetVertex(0).Index;
                int faceVertexIndex2 = mesh.Faces[i].GetVertex(1).Index;
                int faceVertexIndex3 = mesh.Faces[i].GetVertex(2).Index;

                faceVetices[0] = newMesh.Vertices[faceVertexIndex1];
                faceVetices[1] = newMesh.Vertices[faceVertexIndex2];
                faceVetices[2] = newMesh.Vertices[faceVertexIndex3];
                newMesh.Faces.AddTriangles(faceVetices);
            }
            newMesh.TrimExcess();
            return newMesh;
        }
예제 #3
0
        public static TriMesh Clone(TriMesh mesh)
        {
            TriMesh newMesh = new TriMesh();

            for (int i = 0; i < mesh.Vertices.Count; i++)
            {
                VertexTraits traits = new VertexTraits(mesh.Vertices[i].Traits.Position.x,
                                                       mesh.Vertices[i].Traits.Position.y,
                                                       mesh.Vertices[i].Traits.Position.z);
                newMesh.Vertices.Add(traits);
            }

            TriMesh.Vertex[] faceVetices = new TriMesh.Vertex[3];
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                int faceVertexIndex1 = mesh.Faces[i].GetVertex(0).Index;
                int faceVertexIndex2 = mesh.Faces[i].GetVertex(1).Index;
                int faceVertexIndex3 = mesh.Faces[i].GetVertex(2).Index;

                faceVetices[0] = newMesh.Vertices[faceVertexIndex1];
                faceVetices[1] = newMesh.Vertices[faceVertexIndex2];
                faceVetices[2] = newMesh.Vertices[faceVertexIndex3];
                newMesh.Faces.AddTriangles(faceVetices);
            }
            newMesh.TrimExcess();
            return(newMesh);
        }
예제 #4
0
        private static TriMesh LoadPlyStream(Stream stream)
        {
            TriMesh mesh = new TriMesh();
            mesh.Traits.HasFaceVertexNormals = true;
            mesh.Traits.HasTextureCoordinates = true;

            StreamReader sr = new StreamReader(stream);
            PlyFileProcessorState state = new PlyFileProcessorState();
            string line;
            while ((line = sr.ReadLine()) != null)
            {
                ProcessPlyLine(mesh, line, state);
            }

            mesh.TrimExcess();
            return mesh;
        }
예제 #5
0
        private static TriMesh LoadGuStream(Stream stream)
        {
            TriMesh mesh = new TriMesh();

            mesh.Traits.HasFaceVertexNormals  = true;
            mesh.Traits.HasTextureCoordinates = true;

            StreamReader          sr    = new StreamReader(stream);
            PlyFileProcessorState state = new PlyFileProcessorState();
            string line;

            while ((line = sr.ReadLine()) != null)
            {
                ProcessGuLine(mesh, line, state);
            }

            mesh.TrimExcess();
            return(mesh);
        }
예제 #6
0
        private static TriMesh LoadOffStream(Stream stream)
        {
            TriMesh mesh = new TriMesh();
            mesh.Traits.HasFaceVertexNormals = true;
            mesh.Traits.HasTextureCoordinates = true;

            StreamReader sr = new StreamReader(stream);
            OffFileProcessorState state = new OffFileProcessorState();
            string line;
            bool ignoreFirstThreeNum = true;


            while ((line = sr.ReadLine()) != null)
            {
                ProcessOffLine(mesh, line, state, ref ignoreFirstThreeNum);
            }

            mesh.TrimExcess();
            return mesh;
        }
예제 #7
0
        private static TriMesh LoadOffStream(Stream stream)
        {
            TriMesh mesh = new TriMesh();

            mesh.Traits.HasFaceVertexNormals  = true;
            mesh.Traits.HasTextureCoordinates = true;

            StreamReader          sr    = new StreamReader(stream);
            OffFileProcessorState state = new OffFileProcessorState();
            string line;
            bool   ignoreFirstThreeNum = true;


            while ((line = sr.ReadLine()) != null)
            {
                ProcessOffLine(mesh, line, state, ref ignoreFirstThreeNum);
            }

            mesh.TrimExcess();
            return(mesh);
        }
예제 #8
0
        /// <summary>
        /// Loads an OBJ file from a stream.
        /// </summary>
        /// <param name="stream">A stream with OBJ file data.</param>
        private static TriMesh LoadObjStream(Stream stream)
        {
            TriMesh mesh = new TriMesh();
            mesh.Traits.HasFaceVertexNormals = true;
            mesh.Traits.HasTextureCoordinates = true;

            StreamReader sr = new StreamReader(stream);
            ObjFileProcessorState state = new ObjFileProcessorState();
            string line;

            while ((line = sr.ReadLine()) != null)
            {

                ProcessObjLine(mesh, line, state);

            }

            if (state.VertexTextureCoords.Count == mesh.Vertices.Count)
            {
                for (int i = 0; i < mesh.Vertices.Count; i++)
                {
                    mesh.Vertices[i].Traits.UV = state.VertexTextureCoords[i];
                }
            }
            mesh.TrimExcess();
            return mesh;
        }
예제 #9
0
        public static TriMesh BulidSphere()//建立球星Trimesh
        {
            TriMesh sphere = new TriMesh();

            sphere.Vertices.Add(new VertexTraits(-0.9972, 19.7347, -0.3015));
            sphere.Vertices.Add(new VertexTraits(-0.9972, 13.8535, -15.6699));
            sphere.Vertices.Add(new VertexTraits(-14.3067, 13.8535, -7.98572));
            sphere.Vertices.Add(new VertexTraits(-14.3067, 13.8535, 7.3828));
            sphere.Vertices.Add(new VertexTraits(-0.9972, 13.8535, 15.0670));
            sphere.Vertices.Add(new VertexTraits(12.3122, 13.8535, 7.3828));
            sphere.Vertices.Add(new VertexTraits(12.3122, 13.8535, -7.9857));
            sphere.Vertices.Add(new VertexTraits(-0.9972, -3.8925, -15.6699));
            sphere.Vertices.Add(new VertexTraits(-14.3067, -3.8925, -7.9857));
            sphere.Vertices.Add(new VertexTraits(-14.3067, -3.8925, 7.3828));
            sphere.Vertices.Add(new VertexTraits(-0.9972, -3.8925, 15.0670));
            sphere.Vertices.Add(new VertexTraits(12.3122, -3.8925, 7.3828));
            sphere.Vertices.Add(new VertexTraits(12.3122, -3.8925, -7.9857));
            sphere.Vertices.Add(new VertexTraits(-0.9972, -9.7738, -0.3015));


            BulidSphereFace(0, 1, 2,sphere);
            BulidSphereFace(0, 2, 3,sphere);
            BulidSphereFace(0, 3, 4, sphere);
            BulidSphereFace(0, 4, 5, sphere);
            BulidSphereFace(0, 5, 6, sphere);
            BulidSphereFace(0, 6, 1, sphere);
            BulidSphereFace(1, 7, 8, sphere);
            BulidSphereFace(1, 8, 2, sphere);
            BulidSphereFace(2, 8, 9, sphere);
            BulidSphereFace(2, 9, 3, sphere);
            BulidSphereFace(3, 9, 10, sphere);
            BulidSphereFace(3, 10, 4, sphere);
            BulidSphereFace(4, 10, 11, sphere);
            BulidSphereFace(4, 11, 5, sphere);
            BulidSphereFace(5, 11, 12, sphere);
            BulidSphereFace(5, 12, 6, sphere);
            BulidSphereFace(6, 12, 7, sphere);
            BulidSphereFace(6, 7, 1, sphere);
            BulidSphereFace(13, 8, 7, sphere);
            BulidSphereFace(13, 9, 8, sphere);
            BulidSphereFace(13, 10, 9, sphere);
            BulidSphereFace(13, 11, 10, sphere);
            BulidSphereFace(13, 12, 11, sphere);
            BulidSphereFace(13, 7, 12, sphere);

            sphere.TrimExcess();

            Matrix4D m = new Matrix4D();
            m[0, 0] = 0.003; m[1, 1] = 0.003; m[2, 2] = 0.003;
            Vector4D v = new Vector4D();
            for (int i = 0; i < sphere.Vertices.Count; i++)//对整个球进行缩放
            {
                v.x = sphere.Vertices[i].Traits.Position.x;
                v.y = sphere.Vertices[i].Traits.Position.y;
                v.z = sphere.Vertices[i].Traits.Position.z;
                v.w = 1;
                v *= m;
                sphere.Vertices[i].Traits.Position.x = v.x;
                sphere.Vertices[i].Traits.Position.y = v.y;
                sphere.Vertices[i].Traits.Position.z = v.z;
             }
            return sphere;

        }
예제 #10
0
        public static TriMesh BulidSphere()//建立球星Trimesh
        {
            TriMesh sphere = new TriMesh();

            sphere.Vertices.Add(new VertexTraits(-0.9972, 19.7347, -0.3015));
            sphere.Vertices.Add(new VertexTraits(-0.9972, 13.8535, -15.6699));
            sphere.Vertices.Add(new VertexTraits(-14.3067, 13.8535, -7.98572));
            sphere.Vertices.Add(new VertexTraits(-14.3067, 13.8535, 7.3828));
            sphere.Vertices.Add(new VertexTraits(-0.9972, 13.8535, 15.0670));
            sphere.Vertices.Add(new VertexTraits(12.3122, 13.8535, 7.3828));
            sphere.Vertices.Add(new VertexTraits(12.3122, 13.8535, -7.9857));
            sphere.Vertices.Add(new VertexTraits(-0.9972, -3.8925, -15.6699));
            sphere.Vertices.Add(new VertexTraits(-14.3067, -3.8925, -7.9857));
            sphere.Vertices.Add(new VertexTraits(-14.3067, -3.8925, 7.3828));
            sphere.Vertices.Add(new VertexTraits(-0.9972, -3.8925, 15.0670));
            sphere.Vertices.Add(new VertexTraits(12.3122, -3.8925, 7.3828));
            sphere.Vertices.Add(new VertexTraits(12.3122, -3.8925, -7.9857));
            sphere.Vertices.Add(new VertexTraits(-0.9972, -9.7738, -0.3015));


            BulidSphereFace(0, 1, 2, sphere);
            BulidSphereFace(0, 2, 3, sphere);
            BulidSphereFace(0, 3, 4, sphere);
            BulidSphereFace(0, 4, 5, sphere);
            BulidSphereFace(0, 5, 6, sphere);
            BulidSphereFace(0, 6, 1, sphere);
            BulidSphereFace(1, 7, 8, sphere);
            BulidSphereFace(1, 8, 2, sphere);
            BulidSphereFace(2, 8, 9, sphere);
            BulidSphereFace(2, 9, 3, sphere);
            BulidSphereFace(3, 9, 10, sphere);
            BulidSphereFace(3, 10, 4, sphere);
            BulidSphereFace(4, 10, 11, sphere);
            BulidSphereFace(4, 11, 5, sphere);
            BulidSphereFace(5, 11, 12, sphere);
            BulidSphereFace(5, 12, 6, sphere);
            BulidSphereFace(6, 12, 7, sphere);
            BulidSphereFace(6, 7, 1, sphere);
            BulidSphereFace(13, 8, 7, sphere);
            BulidSphereFace(13, 9, 8, sphere);
            BulidSphereFace(13, 10, 9, sphere);
            BulidSphereFace(13, 11, 10, sphere);
            BulidSphereFace(13, 12, 11, sphere);
            BulidSphereFace(13, 7, 12, sphere);

            sphere.TrimExcess();

            Matrix4D m = new Matrix4D();

            m[0, 0] = 0.003; m[1, 1] = 0.003; m[2, 2] = 0.003;
            Vector4D v = new Vector4D();

            for (int i = 0; i < sphere.Vertices.Count; i++)//对整个球进行缩放
            {
                v.x = sphere.Vertices[i].Traits.Position.x;
                v.y = sphere.Vertices[i].Traits.Position.y;
                v.z = sphere.Vertices[i].Traits.Position.z;
                v.w = 1;
                v  *= m;
                sphere.Vertices[i].Traits.Position.x = v.x;
                sphere.Vertices[i].Traits.Position.y = v.y;
                sphere.Vertices[i].Traits.Position.z = v.z;
            }
            return(sphere);
        }