This materials database is a collection of materials that reference textures and parameters for each material
Esempio n. 1
0
        /// <summary>
        /// Converts a FBX file into a temp scene representation (which may already contain meshes and materials, don't care)
        /// </summary>
        /// <param name="_FileName">The name of the FBX file to load</param>
        /// <param name="_Scene">The cirrus scene into which we should store the data</param>
        /// <param name="_ScaleFactor">The scale factor to apply to the entire scene
        /// By default, internal MAX units can be considered as centimeters so if you create a scene whose dimensions of a one meter box are 100x100x100, you
        /// will want to use a scale factor of 0.01.
        /// FBX offers the possibility of scaling but does a shitty job at it as it doesn't even rescale other dimensions like near/far clips or ranges for lights
        ///  and camera, which plain sucks.</param>
        /// <param name="_Materials">An optional materials database containing informations about materials required by the scene</param>
        public void     Load(FileInfo _FileName, FBX.Scene.Scene _Scene, float _ScaleFactor, MaterialsDatabase _Materials)
        {
            if (_FileName == null)
            {
                throw new Exception("Invalid file name!");
            }
            if (!_FileName.Exists)
            {
                throw new Exception("Scene file \"" + _FileName + "\" does not exist!");
            }
            if (_Scene == null)
            {
                throw new Exception("Invalid Scene to load into!");
            }

            m_Scene = _Scene;
            m_TempMesh2FinalMesh.Clear();
            m_ScaleFactor       = _ScaleFactor;
            m_MaterialsDatabase = _Materials;

            FBXImporter.Scene FBXScene = null;
            try
            {
                FBXScene = new FBXImporter.Scene();
                FBXScene.Load(_FileName.FullName);

                // Process materials
                ProcessMaterials(FBXScene.Materials);

                // Process the scene nodes
                RecurseProcessNode(FBXScene.RootNode, null);

                // Attach camera & light targets
                PostProcessNodes(m_Scene.RootNode);

                // Build actual optimized and consolidated meshes
                BuildConsolidatedMeshes();

                // Propagate state once so Local2World matrices are up to date
                m_Scene.RootNode.PropagateState();
            }
            catch (Exception _e)
            {
                throw new Exception("An error occurred while importing the FBX file \"" + _FileName + "\"!", _e);
            }
            finally
            {
                FBXScene.Dispose();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Converts a FBX file into a temp scene representation (which may already contain meshes and materials, don't care)
        /// </summary>
        /// <param name="_FileName">The name of the FBX file to load</param>
        /// <param name="_Scene">The cirrus scene into which we should store the data</param>
        /// <param name="_ScaleFactor">The scale factor to apply to the entire scene
        /// By default, internal MAX units can be considered as centimeters so if you create a scene whose dimensions of a one meter box are 100x100x100, you
        /// will want to use a scale factor of 0.01.
        /// FBX offers the possibility of scaling but does a shitty job at it as it doesn't even rescale other dimensions like near/far clips or ranges for lights
        ///  and camera, which plain sucks.</param>
        /// <param name="_Materials">An optional materials database containing informations about materials required by the scene</param>
        public void Load( FileInfo _FileName, FBX.Scene.Scene _Scene, float _ScaleFactor, MaterialsDatabase _Materials )
        {
            if ( _FileName == null )
                throw new Exception( "Invalid file name!" );
            if ( !_FileName.Exists )
                throw new Exception( "Scene file \"" + _FileName + "\" does not exist!" );
            if ( _Scene == null )
                throw new Exception( "Invalid Scene to load into!" );

            m_Scene = _Scene;
            m_TempMesh2FinalMesh.Clear();
            m_ScaleFactor = _ScaleFactor;
            m_MaterialsDatabase = _Materials;

            FBXImporter.Scene	FBXScene = null;
            try
            {
                FBXScene = new FBXImporter.Scene();
                FBXScene.Load( _FileName.FullName );

                // Process materials
                ProcessMaterials( FBXScene.Materials );

                // Process the scene nodes
                RecurseProcessNode( FBXScene.RootNode, null );

                // Attach camera & light targets
                PostProcessNodes( m_Scene.RootNode );

                // Build actual optimized and consolidated meshes
                BuildConsolidatedMeshes();

                // Propagate state once so Local2World matrices are up to date
                m_Scene.RootNode.PropagateState();
            }
            catch ( Exception _e )
            {
                throw new Exception( "An error occurred while importing the FBX file \"" + _FileName + "\"!", _e );
            }
            finally
            {
                FBXScene.Dispose();
            }
        }