Beispiel #1
0
        public bool Save(string fileName)
        {
            if (Context == null || Context.OccluderMesh == null)
            {
                Logger.DisplayError("No occluder found!  Please Open a mesh and then (Build > Voxelize) to generate an occluder before saving.");
                return(false);
            }

            string fileExt = Path.GetExtension(fileName);

            try
            {
                IExporter exporter = IOFactory.ExporterFactory(fileName);
                exporter.Save(fileName, Context.OccluderMesh.Vertices, Context.OccluderMesh.Indicies);
            }
            catch (System.Exception)
            {
                Logger.DisplayError("Unable to save the file");
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public bool Open(string meshFile, WindingOrder order)
        {
            if (Context != null)
            {
                Context.Dispose();
                Context = null;
            }

            Context = new VoxelizationContext();

            try
            {
                IImporter importer = IOFactory.ImporterFactory(meshFile);
                Context.CurrentMeshFile = meshFile;
                Context.CurrentMesh     = importer.Load(meshFile);
            }
            catch (IOException)
            {
                Logger.DisplayError("Unable to open the file: " + meshFile);
                return(false);
            }

            Context.Octree = new VoxelizingOctree(Input.OctreeLevels);
            Context.Octree.GenerateOctree(Context.CurrentMesh);

            Vector4[] orignalVertices = new Vector4[Context.CurrentMesh.Vertices.Length];
            for (int i = 0; i < orignalVertices.Length; i++)
            {
                orignalVertices[i] = new Vector4(Context.CurrentMesh.Vertices[i], 1);
            }

            int[] originalIndicies = new int[Context.CurrentMesh.Tris.Length * 3];

            if (order == WindingOrder.CounterClockwise)
            {
                for (int i = 0; i < Context.CurrentMesh.Tris.Length; i++)
                {
                    Tri t     = Context.CurrentMesh.Tris[i];
                    int index = i * 3;
                    originalIndicies[index + 0] = t.P1.Vertex;
                    originalIndicies[index + 1] = t.P2.Vertex;
                    originalIndicies[index + 2] = t.P3.Vertex;
                }
            }
            else if (order == WindingOrder.Clockwise)
            {
                for (int i = 0; i < Context.CurrentMesh.Tris.Length; i++)
                {
                    Tri t     = Context.CurrentMesh.Tris[i];
                    int index = i * 3;
                    originalIndicies[index + 0] = t.P1.Vertex;
                    originalIndicies[index + 2] = t.P2.Vertex;
                    originalIndicies[index + 1] = t.P3.Vertex;
                }
            }

            if (Context.OriginalMesh != null)
            {
                Context.OriginalMesh.Dispose();
                Context.OriginalMesh = null;
            }

            Mesh mesh = new Mesh();

            mesh.Indicies = originalIndicies;
            mesh.Vertices = orignalVertices;

            Context.OriginalMesh = new RenderableMesh(mesh, true);

            return(true);
        }