Load() public static method

Loads the specified mesh file.
Determines the path from which to load and automatically applies the file extension.
public static Load ( string fileName ) : IEnumerable
fileName string Name of the saved mesh file. Exclude path and extension.
return IEnumerable
示例#1
0
        public static void ExportRoomToWavefront()
        {
            string selectedFile = EditorUtility.OpenFilePanelWithFilters("Select Room File", MeshSaver.MeshFolderName, new string[] { "Room", "room" });

            if (string.IsNullOrEmpty(selectedFile))
            {
                return;
            }

            string             fileName = Path.GetFileNameWithoutExtension(selectedFile);
            IEnumerable <Mesh> meshes   = null;

            try
            {
                meshes = MeshSaver.Load(fileName);
            }
            catch
            {
                // Handling exceptions, and null returned by MeshSaver.Load, by checking if meshes
                // is still null below.
            }

            if (meshes == null)
            {
                EditorUtility.DisplayDialog(ExportDialogErrorTitle, "Unable to parse selected file.", "Ok");
                return;
            }

            SaveMeshesToWavefront(fileName, meshes);

            // Open the location on where the mesh was saved.
            System.Diagnostics.Process.Start(ExportDirectory);
        }
        /// <summary>
        /// Loads the SpatialMapping mesh from the specified file.
        /// </summary>
        /// <param name="fileName">The name, without path or extension, of the file to load.</param>
        public void Load(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                Debug.Log("No mesh file specified.");
                return;
            }

            Cleanup();

            List <Mesh> storedMeshes = new List <Mesh>();

            try
            {
                storedMeshes.AddRange(MeshSaver.Load(fileName));

                foreach (Mesh mesh in storedMeshes)
                {
                    GameObject surface  = AddSurfaceObject(mesh, "storedmesh-" + surfaceObjects.Count, transform);
                    Renderer   renderer = surface.GetComponent <MeshRenderer>();

                    if (SpatialMappingManager.Instance.DrawVisualMeshes == false)
                    {
                        renderer.enabled = false;
                    }

                    if (SpatialMappingManager.Instance.CastShadows == false)
                    {
                        renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                    }

                    // Reset the surface mesh collider to fit the updated mesh.
                    // Unity tribal knowledge indicates that to change the mesh assigned to a
                    // mesh collider, the mesh must first be set to null.  Presumably there
                    // is a side effect in the setter when setting the shared mesh to null.
                    MeshCollider collider = surface.GetComponent <MeshCollider>();
                    collider.sharedMesh = null;
                    collider.sharedMesh = surface.GetComponent <MeshFilter>().mesh;
                }
            }
            catch
            {
                Debug.Log("Failed to load " + fileName);
            }
        }