示例#1
0
        public static TriMesh ReadFile(string fileName)
        {
            TriMesh mesh = null;

            if (fileName.EndsWith("obj"))
            {
                mesh = TriMeshIO.FromObjFile(fileName);
            }
            if (fileName.EndsWith("off"))
            {
                mesh = TriMeshIO.FromOffFile(fileName);
            }
            if (fileName.EndsWith("ply"))
            {
                mesh = TriMeshIO.FromPlyFile(fileName);
            }
            if (fileName.EndsWith("npts"))
            {
                PointsetsFile = fileName;
            }
            if (mesh != null)
            {
                TriMeshUtil.ScaleToUnit(mesh, 1.0);
                TriMeshUtil.MoveToCenter(mesh);

                TriMeshUtil.SetUpNormalVertex(mesh);
            }
            return(mesh);
        }
示例#2
0
        public void CreateSelectionFaceSave(TriMesh mesh)
        {
            List <TriMesh> meshes  = AddSelectionFace(mesh);
            string         dirName = null;

            if (ConfigShape.Instance.SaveDefaultDir)
            {
                dirName = Path.Combine(Directory.GetCurrentDirectory(), ConfigShape.Instance.SaveFileDir);
            }
            else
            {
                dirName = ConfigShape.Instance.SaveFileDir;
            }

            dirName = Path.Combine(dirName, Path.GetFileNameWithoutExtension(mesh.FileName));
            Directory.CreateDirectory(dirName);
            string filename = null;

            for (int i = 0; i < meshes.Count; i++)
            {
                filename = dirName + "/" + meshes[i].FileName + ".obj";

                TriMeshIO.WriteToObjFile(filename, meshes[i]);
            }

            filename = dirName + "/" + Path.GetFileNameWithoutExtension(mesh.FileName) + ".obj";

            TriMeshIO.WriteToObjFile(filename, mesh);
        }
示例#3
0
        public TriMesh AddSelectionVertex(TriMesh mesh, int index)
        {
            List <TriMesh> sel = new List <TriMesh>();

            for (int i = 0; i < mesh.Vertices.Count; i++)
            {
                if (mesh.Vertices[i].Traits.SelectedFlag == index)
                {
                    TriMesh selV = TriMeshIO.FromObjFile(ConfigShape.Instance.VertexFile);
                    for (int j = 0; j < selV.Vertices.Count; j++)
                    {
                        selV.Vertices[j].Traits.SelectedFlag = (byte)index;
                    }
                    TriMeshUtil.ScaleToUnit(selV, ConfigShape.Instance.Scale);
                    TriMeshUtil.TransformationMove(selV, mesh.Vertices[i].Traits.Position);
                    sel.Add(selV);
                }
            }

            TriMesh result = TriMeshUtil.Combine(sel);

            result.FileName = Path.GetFileNameWithoutExtension(mesh.FileName) + "-V-" + index.ToString();

            TriMeshUtil.SetUpVertexNormal(result, EnumNormal.AreaWeight);
            return(result);
        }
示例#4
0
        public int Run(TriMesh mesh, string param)
        {
            string file = this.FileName + ".off";

            TriMeshIO.WriteToOffFile(file, mesh);
            return(this.Run(file, param));
        }
示例#5
0
        public void OpenBigMesh()
        {
            String filename = SetUpOpenDialog();

            if (filename == null)
            {
                return;
            }

            else
            {
                if (meshLoader != null && meshLoader.IsAlive)
                {
                    meshLoader.Abort();
                }
                this.progressBar.Visible = true;
                FileInfo fileInfo = new FileInfo(filename);
                if (fileInfo.Length > 1048576)   // Open files larger than 1MB in their own thread
                {
                    meshLoader = new MeshLoader();
                    meshLoader.MeshProcessFinished += new EventHandler(meshLoader_MeshLoaded);
                    meshLoader.Load(filename);
                }
                else
                {
                    GlobalData.Instance.TriMesh = TriMeshIO.ReadFile(filename);
                    this.progressBar.Visible    = false;
                }
            }
        }
示例#6
0
        public static void Init(TriMesh mesh)
        {
            nv = mesh.Vertices.Count;
            TriMeshIO.WriteToObjFile(FileName, mesh);

            FromObjFile(mesh.FileName);
        }
示例#7
0
        public void Init(TriMesh mesh)
        {
            string file = "rtsc.obj";

            TriMeshIO.WriteToObjFile(file, mesh);
            this.rtsc = new Rtsc(file);
            this.rtsc.InitTriMesh();
        }
示例#8
0
 TransparentDemo()
 {
     this.mesh = TriMeshIO.ReadFile("cube.obj");
     foreach (var item in this.mesh.Vertices)
     {
         item.Traits.Position.z /= 3;
     }
 }
示例#9
0
        public void RunAsync(TriMesh mesh, string param)
        {
            //string file = IOHuiZhao.Instance.GetPath()+"/"+ this.FileName + ".off";

            string file = this.FileName + ".off";

            TriMeshIO.WriteToOffFile(file, mesh);
            this.RunAsync(file, param);
        }
示例#10
0
        private void DoAfter()
        {
            this.MeshView.Items[0].SubItems[2].Text = this.Mesh.Vertices.Count.ToString();
            this.MeshView.Items[1].SubItems[2].Text = this.Mesh.Edges.Count.ToString();
            this.MeshView.Items[2].SubItems[2].Text = this.Mesh.Faces.Count.ToString();

            string file = @"AutoAfter.obj";

            TriMeshIO.WriteToObjFile(file, Mesh);
        }
示例#11
0
        public void Subdivision()
        {
            /*        /\                  /\
             *       /  \                /__\
             *      /    \              /\  /\
             *     /      \            /__\/__\
             *    /        \          /\  /\  /\
             *   /__________\        /__\/__\/__\
             *
             *   为了让每个顶点周围都有它专属的一圈价为6的点,把每个三角形拆成9个
             */
            TriMesh copy = TriMeshIO.Clone(this.mesh);

            this.mesh.Clear();

            TriMesh.Vertex[] faceMap = new HalfEdgeMesh.Vertex[copy.Faces.Count];
            TriMesh.Vertex[] hfMap   = new HalfEdgeMesh.Vertex[copy.HalfEdges.Count];

            foreach (var v in copy.Vertices)
            {
                this.mesh.Vertices.Add(new VertexTraits(v.Traits.Position));
            }

            foreach (var face in copy.Faces)
            {
                faceMap[face.Index] = this.mesh.Vertices.Add(new VertexTraits(TriMeshUtil.GetMidPoint(face)));
            }

            foreach (var hf in copy.HalfEdges)
            {
                Vector3D pos = hf.FromVertex.Traits.Position * 2 / 3 + hf.ToVertex.Traits.Position * 1 / 3;
                hfMap[hf.Index] = this.mesh.Vertices.Add(new VertexTraits(pos));
            }

            foreach (var face in copy.Faces)
            {
                foreach (var hf in face.Halfedges)
                {
                    this.mesh.Faces.AddTriangles(faceMap[face.Index], hfMap[hf.Index], hfMap[hf.Opposite.Index]);
                    this.mesh.Faces.AddTriangles(faceMap[face.Index], hfMap[hf.Opposite.Index], hfMap[hf.Next.Index]);
                }
            }

            foreach (var v in copy.Vertices)
            {
                foreach (var hf in v.HalfEdges)
                {
                    if (hf.Face != null)
                    {
                        this.mesh.Faces.AddTriangles(this.mesh.Vertices[v.Index], hfMap[hf.Index], hfMap[hf.Previous.Opposite.Index]);
                    }
                }
            }
        }
示例#12
0
 StencilDemo()
 {
     this.cube = TriMeshIO.ReadFile("cube.obj");
     foreach (var v in this.cube.Vertices)
     {
         Vector3D p = v.Traits.Position;
         v.Traits.Position = new Vector3D(p.x * 2, p.y * 0.01, p.z * 2);
     }
     this.sphere = TriMeshIO.ReadFile("sphere.obj");
     this.bunny  = TriMeshIO.ReadFile("bunny.obj");
 }
示例#13
0
        private static TriMesh LoadOffFile(string fileName)
        {
            TriMesh mesh = null;

            using (Stream stream = File.OpenRead(fileName))
            {
                mesh = TriMeshIO.LoadOffStream(stream);
            }
            mesh.FileName = fileName;
            return(mesh);
        }
示例#14
0
        //TriMesh bunny;

        ShadowDemo()
        {
            //this.cube = TriMeshIO.ReadFile("cube.obj");
            //foreach (var v in this.cube.Vertices)
            //{
            //    Vector3D p = v.Traits.Position;
            //    v.Traits.Position = new Vector3D(p.x, p.y, p.z);
            //}
            this.sphere = TriMeshIO.ReadFile("sphere.obj");
            TriMeshUtil.ScaleToUnit(this.sphere, 0.1);
            //this.bunny = TriMeshIO.ReadFile("bunny.obj");
            //TriMeshUtil.ScaleToUnit(this.bunny, 0.3);
        }
示例#15
0
        public void SaveSelection()
        {
            string filename = SetUpSaveDialog();

            if (filename == null)
            {
                return;
            }

            else
            {
                TriMeshIO.WriteSelection(filename, GlobalData.Instance.TriMesh);
            }
        }
示例#16
0
        public void SaveMeshWithTexture()
        {
            string filename = SetUpSaveDialog();

            if (filename == null)
            {
                return;
            }

            else
            {
                TriMeshIO.WriteToObjFileWithTexture(filename, GlobalData.Instance.TriMesh);
            }
        }
示例#17
0
        static TriMesh CreateSphere()
        {
            TriMesh sphere = TriMeshIO.ReadFile("sphere.obj");

            TriMeshUtil.ScaleToUnit(sphere, 0.4);
            TriMeshUtil.MoveToCenter(sphere);
            Vector3D move = new Vector3D(-0.2, -0.1, -0.1);

            foreach (var v in sphere.Vertices)
            {
                v.Traits.Position -= move;
            }
            TriMeshUtil.SetUpNormalVertex(sphere);
            return(sphere);
        }
示例#18
0
        static TriMesh CreateCube()
        {
            TriMesh cube = TriMeshIO.ReadFile("cube.obj");

            TriMeshUtil.ScaleToUnit(cube, 0.2);
            TriMeshUtil.MoveToCenter(cube);
            Vector3D move = new Vector3D(0.2, 0.1, -0.3);

            foreach (var v in cube.Vertices)
            {
                v.Traits.Position -= move;
            }
            TriMeshUtil.SetUpNormalVertex(cube);
            return(cube);
        }
示例#19
0
        public void OpenManiFoldFileTwo()
        {
            String filename = SetUpOpenDialog();

            if (filename == null)
            {
                return;
            }

            else
            {
                GlobalData.Instance.MeshTwo = TriMeshIO.ReadFile(filename);
            }

            GlobalData.Instance.OnChanged(EventArgs.Empty);
        }
示例#20
0
 private void Run()
 {
     try
     {
         mesh = TriMeshIO.ReadFile(file);
         lock (mesh)
         {
             //mesh.ComputeAllTraits();
         }
         MeshProcessFinished(this, EventArgs.Empty);
     }
     catch (ThreadAbortException)
     {
         Thread.ResetAbort();
         mesh = null;
     }
 }
示例#21
0
        public void AddOneMore()
        {
            String filename = SetUpOpenDialog();

            if (filename == null)
            {
                return;
            }

            else
            {
                GlobalData.Instance.AllMeshes.Add(TriMeshIO.ReadFile(filename));

                GlobalData.Instance.TriMesh = GlobalData.Instance.AllMeshes[GlobalData.Instance.AllMeshes.Count - 1];
            }

            GlobalData.Instance.OnChanged(EventArgs.Empty);
        }
示例#22
0
        public void SaveMesh()
        {
            string filename = SetUpSaveDialog();

            if (filename == null)
            {
                return;
            }

            else
            {
                string ext = Path.GetExtension(filename);
                if (ext == ".obj")
                {
                    TriMeshIO.WriteToObjFile(filename, GlobalData.Instance.TriMesh);
                }

                if (ext == ".ply")
                {
                    TriMeshIO.WriteToPlyFile(filename, GlobalData.Instance.TriMesh);
                }
            }
        }
示例#23
0
        public TriMesh AddSelectionEdge(TriMesh mesh, int index)
        {
            List <TriMesh> sel = new List <TriMesh>();

            for (int i = 0; i < mesh.Edges.Count; i++)
            {
                if (mesh.Edges[i].Traits.SelectedFlag == index)
                {
                    TriMesh selV = TriMeshIO.FromObjFile(ConfigShape.Instance.EdgeFile);
                    TriMeshUtil.ScaleToUnit(selV, 1);
                    TriMeshUtil.ScaleToUnit(selV, ConfigShape.Instance.Scale);
                    Vector3D direction = mesh.Edges[i].Vertex1.Traits.Position - mesh.Edges[i].Vertex0.Traits.Position;
                    Vector3D loc       = (mesh.Edges[i].Vertex1.Traits.Position + mesh.Edges[i].Vertex0.Traits.Position) / 2;

                    Matrix4D scale = TriMeshUtil.ComputeMatrixScale(direction.Length() / ConfigShape.Instance.Scale, 1d, 1d);


                    //  TriMeshUtil.TransformationRotation(selV, direction);

                    TriMeshUtil.TransformationScale(selV, scale);
                    TriMeshUtil.TransformRoatationV(selV, direction, Vector3D.UnitX);
                    //TriMeshUtil.TransformRotationX(selV, direction.x);
                    //TriMeshUtil.TransformRotationY(selV, direction.y);
                    //TriMeshUtil.TransformRotationZ(selV, direction.z);
                    TriMeshUtil.TransformationMove(selV, loc);
                    sel.Add(selV);
                }
            }

            TriMesh result = TriMeshUtil.Combine(sel);

            result.FileName = Path.GetFileNameWithoutExtension(mesh.FileName) + "-E-" + index.ToString();

            TriMeshUtil.SetUpVertexNormal(result, EnumNormal.AreaWeight);
            return(result);
        }
示例#24
0
        public void RunBasic(EnumMayaBasic type)
        {
            string para = ConfigMaya.Instance.SelectAll;

            switch (type)
            {
            case EnumMayaBasic.Info:
                MGlobal.displayInfo("Hello World\n");
                break;

            case EnumMayaBasic.FirstSelect:
                MayaBridge.Instance.ShowMeshInfo();
                break;

            case EnumMayaBasic.ToTrimesh:
                MayaBridge.Instance.ConvertToTriMesh();
                break;


            case EnumMayaBasic.SelectVertice:
                MayaBridge.Instance.GetVerticeSelected();
                break;

            case EnumMayaBasic.HookUp:
                MayaBridge.Instance.HookUp();
                break;

            case EnumMayaBasic.Create:
                MayaBridge.Instance.HookUpCreate();
                break;

            case EnumMayaBasic.Delete:
                TriMeshIO.Copy(GlobalData.Instance.TriMesh);
                break;
            }
        }
示例#25
0
        public static TriMesh FromOffStream(Stream stream)
        {
            TriMesh m = TriMeshIO.LoadOffStream(stream);

            return(m);
        }
示例#26
0
 TeapotDemo()
 {
     this.mesh = TriMeshIO.ReadFile("teapot.obj");
     TriMeshUtil.SetUpNormalVertex(this.mesh);
 }
示例#27
0
        public static TriMesh FromOffFile(string fileName)
        {
            TriMesh m = TriMeshIO.LoadOffFile(fileName);

            return(m);
        }