private static Mesh ReadMesh(Matrix4 transform, string srcDir, string meshFile) { Stream meshData = new FileStream(srcDir + meshFile, FileMode.Open); Mesh mesh = new Mesh(meshFile); if (meshFile.EndsWith(".mesh", StringComparison.CurrentCultureIgnoreCase)) { MeshSerializer meshReader = new MeshSerializer(); meshReader.ImportMesh(meshData, mesh); } else if (meshFile.EndsWith(".mesh.xml", StringComparison.CurrentCultureIgnoreCase)) { OgreXmlMeshReader meshReader = new OgreXmlMeshReader(meshData); meshReader.Import(mesh); } else if (meshFile.EndsWith(".dae", StringComparison.CurrentCultureIgnoreCase)) { string extension = Path.GetExtension(meshFile); string baseFile = Path.GetFileNameWithoutExtension(meshFile); string basename = meshFile.Substring(0, meshFile.Length - extension.Length); ColladaMeshReader meshReader = new ColladaMeshReader(meshData, baseFile); // import the .dae file meshReader.Import(transform, mesh, null, "idle", basename); // materialScript = meshReader.MaterialScript; } else { meshData.Close(); string extension = Path.GetExtension(meshFile); throw new AxiomException("Unsupported mesh format '{0}'", extension); } meshData.Close(); return mesh; }
/// <summary> /// Loads the mesh data. /// </summary> protected override void LoadImpl() { // meshLoadMeter.Enter(); // load this bad boy if it is not to be manually defined if (!isManual) { // get the resource data from MeshManager Stream data = MeshManager.Instance.FindResourceData(name); string extension = Path.GetExtension(name); // mesh loading stats int before, after; // get the tick count before loading the mesh before = Environment.TickCount; if (extension == ".mesh") { // instantiate a mesh reader and pass in the stream data MeshSerializer meshReader = new MeshSerializer(); // import the .mesh file meshReader.ImportMesh(data, this); } else if (extension == ".xml") { OgreXmlMeshReader meshReader = new OgreXmlMeshReader(data); // import the .xml file meshReader.Import(this); } else if (extension == ".dae") { ColladaMeshReader meshReader = new ColladaMeshReader(data, "tmp"); // import the .dae file meshReader.Import(this); } else { data.Close(); throw new AxiomException("Unsupported mesh format '{0}'", extension); } // get the tick count after loading the mesh after = Environment.TickCount; // record the time elapsed while loading the mesh log.InfoFormat("Mesh: Loaded '{0}', took {1}ms", this.name, (after - before)); // close the stream (we don't need to leave it open here) data.Close(); } // prepare the mesh for a shadow volume? if (MeshManager.Instance.PrepareAllMeshesForShadowVolumes) { if (edgeListsBuilt || autoBuildEdgeLists) { PrepareForShadowVolume(); } if (!edgeListsBuilt && autoBuildEdgeLists) { BuildEdgeList(); } } // meshLoadMeter.Exit(); }
/// <summary> /// Loads the mesh data. /// </summary> protected override void LoadImpl() { // meshLoadMeter.Enter(); // load this bad boy if it is not to be manually defined if (!isManual) { // get the resource data from MeshManager Stream data = MeshManager.Instance.FindResourceData(name); string extension = Path.GetExtension(name); // mesh loading stats int before, after; // get the tick count before loading the mesh before = Environment.TickCount; if (extension == ".mesh") { // instantiate a mesh reader and pass in the stream data MeshSerializer meshReader = new MeshSerializer(); // import the .mesh file meshReader.ImportMesh(data, this); } else if (extension == ".xml") { OgreXmlMeshReader meshReader = new OgreXmlMeshReader(data); // import the .xml file meshReader.Import(this); } else if (extension == ".dae") { ColladaMeshReader meshReader = new ColladaMeshReader(data, "tmp"); // import the .dae file meshReader.Import(this); } else { data.Close(); throw new AxiomException("Unsupported mesh format '{0}'", extension); } // get the tick count after loading the mesh after = Environment.TickCount; // record the time elapsed while loading the mesh log.InfoFormat("Mesh: Loaded '{0}', took {1}ms", this.name, (after - before)); // close the stream (we don't need to leave it open here) data.Close(); } // prepare the mesh for a shadow volume? if (MeshManager.Instance.PrepareAllMeshesForShadowVolumes) { if (edgeListsBuilt || autoBuildEdgeLists) { PrepareForShadowVolume(); } if (!edgeListsBuilt && autoBuildEdgeLists) { BuildEdgeList(); } } // meshLoadMeter.Exit(); }