Exemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        string path     = @"D:\max.off";
        string savepath = @"D:\max2.off";

        List <Vector3> listVertex  = new List <Vector3>();
        List <int>     listIndices = new List <int>();
        List <int>     listEdges   = new List <int>();

        OFFReader.ReadFile(path, out listVertex, out listIndices);
        OFFReader.WriteFile(savepath, listVertex, listIndices, listEdges);


        gameObject.AddComponent <MeshFilter>();          // Creation d'un composant MeshFilter qui peut ensuite être visualisé
        gameObject.AddComponent <MeshRenderer>();
        gameObject.GetComponent <MeshRenderer>().material = mat;

        Mesh msh = new Mesh();

        msh.vertices  = listVertex.ToArray();
        msh.triangles = listIndices.ToArray();

        count = new Counter(msh);

        gameObject.GetComponent <MeshFilter>().mesh = msh;
    }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a new Model, compute the low resolution representation, calculate the mapping from the low to the high
        /// resolution representation, initialize the simulator and start the simualtion update timer
        /// </summary>
        private void Open3DFile(string fileName)
        {
            List <Double3>  posListH;
            List <Triangle> triListH;

            OFFReader.Read(fileName, out posListH, out triListH);


            Double3 min, max;

            Graphics3D.Extensions.MinMax(posListH, out min, out max);

            //Scale such that model fits into unit bounding box
            Double3 center  = 0.5 * (min + max);
            Double3 size    = max - min;
            double  scaling = 1.0 / Math.Max(size.X, Math.Max(size.Y, size.Z));

            for (int i = 0; i < posListH.Count; ++i)
            {
                posListH[i] = scaling * (posListH[i] - center);
            }


            PairContract    c = new PairContract();
            List <Double3>  posList;
            List <Triangle> triList;

            c.Simplify(posListH, triListH, 1000, false, out posList, out triList);


            Channel <Double3> nor = MeshBuilder.CreateNormals(posList, triList);

            _lowResToHighResMapper = new LowResToHighResMapper(posList, nor, triList, posListH);
            _sim = new RigidSimulator(posList, triList);

            _pos = new Channel <Double3>(posList);
            _geo = new PhongPNTriangleGeometry(new Channel <Triangle>(triList),
                                               new NamedChannel(Channel.Position, _pos), new NamedChannel(Channel.Normal, nor));


            _posHighRes = new Channel <Double3>(posListH);
            Channel <Double3> norH = MeshBuilder.CreateNormals(posListH, triListH);

            _geoHighRes = new PhongPNTriangleGeometry(new Channel <Triangle>(triListH),
                                                      new NamedChannel(Channel.Position, _posHighRes), new NamedChannel(Channel.Normal, norH));

            _geo.Color        = new Double3(0.7, 0.5, 0);
            _geoHighRes.Color = new Double3(0.7, 0.5, 0);

            //_gl.SceneGraph.Add(geo);
            _gl.SceneGraph.Add(_geoHighRes);
            _gl.InputHandler.Fit();

            tmr.Start();

            // TODO: The result with a separate thread was not staisfactory
            //Thread t = new Thread(UpdateSimThread);
            //t.Start();
        }
Exemplo n.º 3
0
    // Start is called before the first frame update
    void Start()
    {
        string path = @"D:\bunny.off";

        OFFReader.ReadFile(path, out List <Vector3> listVertex, out List <int> listIndices);
        originalMesh           = new Mesh();
        originalMesh.vertices  = listVertex.ToArray();
        originalMesh.triangles = listIndices.ToArray();

        gameObject.AddComponent <MeshFilter>().mesh = originalMesh;
        gameObject.AddComponent <MeshRenderer>();
        gameObject.GetComponent <MeshRenderer>().material = material;

        grid = new Grid();
    }
Exemplo n.º 4
0
        public static void TestHalfEdgeMesh(string path)
        {
            Console.WriteLine("---- TestHalfEdgeMesh() called ----");

            OFFMeshData data;
            OFFResult   result = OFFReader.ReadMeshFromFile(path, out data);

            Debug.WriteLine("OFFReader result: " + result + "\n");


            HE_Mesh mesh = new HE_Mesh(data.vertices, data.faces);

            Debug.WriteLine(mesh);

            HE_MeshTopology top = new HE_MeshTopology(mesh);

            top.computeVertexAdjacency();
            top.computeFaceAdjacency();
            top.computeEdgeAdjacency();
            //Debug.WriteLine(top.TopologyDictToString(top.FaceVertex));

            Debug.WriteLine("isMesh? triangular: " + mesh.isTriangularMesh() + " quad: " + mesh.isQuadMesh() + " ngon: " + mesh.isNgonMesh());

            OFFResult result2 = OFFWritter.WriteMeshToFile(mesh, "/Users/alan/Desktop/AR_GeometryLibrary/AR_TerminalApp/meshes/cubeOut.off");

            Debug.WriteLine(result.ToString());

            mesh.Faces[0].HalfEdge.Vertex.UserValues.Add("set1", 3);
            mesh.Faces[0].HalfEdge.Next.Vertex.UserValues.Add("set1", 4);
            mesh.Faces[0].HalfEdge.Next.Next.Vertex.UserValues.Add("set1", 3);


            Line levelLine;

            AR_Lib.Curve.LevelSets.getFaceLevel("set1", 3.5, mesh.Faces[0], out levelLine);

            Console.WriteLine("---- TestHalfEdgeMesh() ended ----");
        }