ImportMesh() public method

Imports mesh data from a .mesh file.
public ImportMesh ( Stream stream, Axiom.Core.Mesh mesh ) : void
stream Stream The stream holding the .mesh data. Must be initialised (pos at the start of the buffer).
mesh Axiom.Core.Mesh Reference to the Mesh object which will receive the data. Should be blank already.
return void
        /// <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();
        }
Beispiel #2
0
		//public override void Preload()
		//{
		//    //if (isPreloaded) {
		//    //    return;
		//    //}

		//    // load this bad boy if it is not to be manually defined
		//    if ( !isManuallyDefined )
		//    {
		//        MeshSerializer serializer = new MeshSerializer();

		//        // get the resource data from MeshManager
		//        Stream data = MeshManager.Instance.FindResourceData( name );

		//        string extension = Path.GetExtension( name );

		//        if ( extension != ".mesh" )
		//        {
		//            data.Close();

		//            throw new AxiomException( "Unsupported mesh format '{0}'", extension );
		//        }

		//        // fetch the .mesh dependency info
		//        serializer.GetDependencyInfo( data, this );

		//        // close the stream (we don't need to leave it open here)
		//        data.Close();
		//    }

		//}

		/// <summary>
		///		Loads the mesh data.
		/// </summary>
		protected override void load()
		{
			// unload this first if it is already loaded
			if ( IsLoaded )
			{
				Unload();
			}

			// I should eventually call Preload here, and then use
			// the preloaded data to make future loads faster, but
			// I haven't finished the Preload stuff yet.
			// Preload();

			// load this bad boy if it is not to be manually defined
			if ( !IsManuallyLoaded )
			{
				var serializer = new MeshSerializer();

				// get the resource data from MeshManager
				var data = ResourceGroupManager.Instance.OpenResource( Name, Group, true, this );

				var extension = Path.GetExtension( Name );

				if ( extension != ".mesh" )
				{
					data.Close();

					throw new AxiomException( "Unsupported mesh format '{0}'", extension );
				}

				// import the .mesh file
				serializer.ImportMesh( data, this );

				// 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 ( this._edgeListsBuilt || this._autoBuildEdgeLists )
				{
					PrepareForShadowVolume();
				}
				if ( !this._edgeListsBuilt && this._autoBuildEdgeLists )
				{
					BuildEdgeList();
				}
			}

			// The loading process accesses lod usages directly, so
			// transformation of user values must occur after loading is complete.

			// Transform user lod values
			foreach ( var mlu in this.meshLodUsageList )
			{
				mlu.Value = this._lodStrategy.TransformUserValue( mlu.UserValue );
			}

			// meshLoadMeter.Exit();
		}
 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;
 }
 private static void Test( string srcDir, string dstDir, string name )
 {
     MeshSerializer meshReader = new MeshSerializer();
     Stream data = new FileStream( srcDir + name, FileMode.Open );
     // import the .mesh file
     Mesh mesh = new Mesh( "testmesh" );
     meshReader.ImportMesh( data, mesh );
     meshReader.ExportMesh( mesh, dstDir + name );
 }