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

Exports a mesh to the file specified.
public ExportMesh ( Axiom.Core.Mesh mesh, string fileName ) : void
mesh Axiom.Core.Mesh Reference to the mesh to export.
fileName string The destination filename.
Результат void
Пример #1
0
 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 );
 }
Пример #2
0
        private static void SetupManualLodLevels( string srcDir, string dstDir, string name,
                                                 List<LodEntry> lodEntries )
        {
            string dir = string.Empty;
            string path = string.Empty;
            SplitPath( ref dir, ref path, name );
            if( srcDir == string.Empty )
                srcDir = dir;
            if( dstDir == string.Empty )
                dstDir = dir;
            name = path;
            // get the resource data from MeshManager
            string extension = Path.GetExtension( name ).ToLower();

            Mesh mesh = ReadMesh( srcDir, dstDir, name );
            if( mesh.LodLevelCount > 1 )
            {
                log.Warn( "Mesh already contains level of detail information" );
                mesh.RemoveLodLevels();
            }
            List<MeshLodUsage> manualLodList = new List<MeshLodUsage>();
            foreach( LodEntry lodEntry in lodEntries )
            {
                Mesh lodMesh = ReadMesh( dstDir, dstDir, lodEntry.meshFile );
                MeshLodUsage lodUsage = new MeshLodUsage();
                lodUsage.fromSquaredDepth = lodEntry.distance * lodEntry.distance;
                lodUsage.manualMesh = lodMesh;
                lodUsage.manualName = lodMesh.Name;
                manualLodList.Add( lodUsage );
            }
            mesh.AddManualLodEntries( manualLodList );

            MeshSerializer meshWriter = new MeshSerializer();
            meshWriter.ExportMesh( mesh, dstDir + name );
        }
Пример #3
0
        private static void ConvertFile( string srcDir, string dstDir, string name,
                                        Matrix4 transform, bool build_tangents,
                                        bool extract_collision_volumes, bool optimize_mesh,
                                        string skeleton_file )
        {
            if( String.IsNullOrEmpty( name ) )
            {
                // TODO: It would be better to catch this while parsing command args, but
                // that's a bit too hairy for now. This will at least inform the user.
                throw new ArgumentException( "No file named for conversion" );
            }

            string dir = string.Empty;
            string path = string.Empty;
            SplitPath( ref dir, ref path, name );
            if( srcDir == string.Empty )
                srcDir = dir;
            if( dstDir == string.Empty )
                dstDir = dir;
            name = path;
            // get the resource data from MeshManager
            string extension = Path.GetExtension( name ).ToLower();

            string baseFile = Path.GetFileNameWithoutExtension( name );
            if( baseFile.EndsWith( ".mesh" ) )
                baseFile = baseFile.Substring( 0, baseFile.Length - 5 );

            string baseSkeletonName = null;
            if( skeleton_file != null )
                baseSkeletonName = Path.GetFileName( skeleton_file );

            // mesh loading stats
            int before, after;

            // get the tick count before loading the mesh
            before = Environment.TickCount;

            string materialScript = null;
            Mesh mesh = ReadMesh( ref materialScript, transform, srcDir, dstDir, name );
            if( optimize_mesh )
                mesh = MeshUtility.CopyMesh( mesh );

            // 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", mesh.Name, (after - before) );

            // Build tangent vectors
            if( build_tangents )
            {
                log.Info( "Building tangent vectors from uv map" );
                MeshHelper.BuildTangentVectors( mesh );
            }

            if( extract_collision_volumes )
            {
                log.InfoFormat( "Extracting collision volumes from '{0}'", mesh.Name );
                CVExtractor.ExtractCollisionShapes( mesh, dstDir + baseFile );
            }

            //// prepare the mesh for a shadow volume?
            //if (MeshManager.Instance.PrepareAllMeshesForShadowVolumes) {
            //    if (edgeListsBuilt || autoBuildEdgeLists) {
            //        PrepareForShadowVolume();
            //    }
            //    if (!edgeListsBuilt && autoBuildEdgeLists) {
            //        BuildEdgeList();
            //    }
            //}

            // Allow them to override the skeleton reference of the mesh
            if( baseSkeletonName != null )
                mesh.SkeletonName = baseSkeletonName;

            string meshFile = baseFile + ".mesh";
            MeshSerializer meshWriter = new MeshSerializer();
            meshWriter.ExportMesh( mesh, dstDir + meshFile );

            // If it was a .dae file, we will need to export the material and skeleton as well
            if( extension != ".dae" && extension != ".kmz" )
                return;

            if( materialScript != null )
            {
                string materialFile = baseFile + ".material";
                Stream materialData = new FileStream( dstDir + materialFile, FileMode.Create );
                StreamWriter materialWriter = new StreamWriter( materialData );
                materialWriter.Write( materialScript );
                materialWriter.Close();
            }

            if( mesh.Skeleton == null )
                return;
            #if USE_XML
            string skelFile = baseFile + ".skeleton.xml";
            Stream skelData = new FileStream(dstDir + skelFile, FileMode.Create);
            OgreXmlSkeletonWriter skelWriter = new OgreXmlSkeletonWriter(skelData);
            skelWriter.Export(mesh.Skeleton);
            skelData.Close();
            #else
            // DEBUG
            foreach( AttachmentPoint socket in mesh.Skeleton.AttachmentPoints )
            {
                log.InfoFormat( "Created attachment point with parent {0}", socket.ParentBone );
                log.InfoFormat( "  Relative Position: {0}", socket.Position );
                log.InfoFormat( "  Relative Up: {0}", socket.Orientation * Vector3.UnitZ );
                Bone bone = mesh.Skeleton.GetBone( socket.ParentBone );
                Vector3 derivedPos = bone.DerivedPosition + socket.Position;
                Vector3 derivedUp = socket.Orientation * bone.DerivedOrientation * Vector3.UnitZ;
                log.InfoFormat( "  Absolute Position: {0}", derivedPos );
                log.InfoFormat( "  Absolute Up: {0}", derivedUp );
            }

            string skelFile = baseFile + ".skeleton";
            OgreSkeletonSerializer skelWriter = new OgreSkeletonSerializer();
            skelWriter.ExportSkeleton( mesh.Skeleton, dstDir + skelFile );
            #endif
        }
Пример #4
0
        private static void GenerateLodLevels( string srcDir, string dstDir, string name,
                                              int lodlevels, float loddist, float lodpercent )
        {
            string dir = string.Empty;
            string path = string.Empty;
            SplitPath( ref dir, ref path, name );
            if( srcDir == string.Empty )
                srcDir = dir;
            if( dstDir == string.Empty )
                dstDir = dir;
            name = path;
            // get the resource data from MeshManager
            string extension = Path.GetExtension( name ).ToLower();
            string materialScript = null;

            Mesh mesh = ReadMesh( ref materialScript, Matrix4.Identity, srcDir, dstDir, name );
            if( mesh.LodLevelCount > 1 )
            {
                log.Warn( "Mesh already contains level of detail information" );
                mesh.RemoveLodLevels();
            }
            List<float> lodDistanceList = new List<float>();
            for( int i = 0; i < lodlevels; ++i )
                lodDistanceList.Add( loddist * (i + 1) );
            mesh.GenerateLodLevels( lodDistanceList, ProgressiveMesh.VertexReductionQuota.Proportional, lodpercent );

            MeshSerializer meshWriter = new MeshSerializer();
            meshWriter.ExportMesh( mesh, dstDir + name );
        }
Пример #5
0
 /// <summary>
 ///   Loads up a mesh and the associated skeleton, and uses the 
 ///   skeleton to create a joint mesh.
 /// </summary>
 /// <param name="dstDir"></param>
 /// <param name="name"></param>
 private static void BuildSkeletonMesh( string dstDir, string name )
 {
     Mesh mesh = MeshManager.Instance.CreateBoneMesh( name );
     string meshFile = name + ".mesh";
     MeshSerializer meshWriter = new MeshSerializer();
     meshWriter.ExportMesh( mesh, dstDir + meshFile );
 }