Axiom.Serialization.MeshSerializer.ImportMesh C# (CSharp) Метод

ImportMesh() публичный Метод

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.
Результат void
		public void ImportMesh( Stream stream, Mesh mesh )
		{
			BinaryReader reader = new BinaryReader( stream );

			// read the header ID
			ushort headerID = ReadUShort( reader );

			if ( headerID != (ushort)MeshChunkID.Header )
			{
				throw new AxiomException( "File header not found." );
			}

			// read version
			string fileVersion = ReadString( reader );

			// set jump back to the start of the reader
			Seek( reader, 0, SeekOrigin.Begin );

			// barf if there specified version is not supported
			if ( !implementations.ContainsKey( fileVersion ) )
			{
				throw new AxiomException( "Cannot find serializer implementation for version '{0}'.", fileVersion );
			}

			LogManager.Instance.Write( "Mesh: Loading '{0}'...", mesh.Name );

			// call implementation
			MeshSerializerImpl serializer = (MeshSerializerImpl)implementations[ fileVersion ];
			serializer.ImportMesh( stream, mesh );

			// warn on old version of mesh
			if ( fileVersion != currentVersion )
			{
				LogManager.Instance.Write( "WARNING: {0} is an older format ({1}); you should upgrade it as soon as possible using the OgreMeshUpdate tool.", mesh.Name, fileVersion );
			}
		}

Usage Example

        /// <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();
        }
All Usage Examples Of Axiom.Serialization.MeshSerializer::ImportMesh