diff --git a/stepmania/src/Model.cpp b/stepmania/src/Model.cpp index 878e1f5ae2..11d84f3702 100644 --- a/stepmania/src/Model.cpp +++ b/stepmania/src/Model.cpp @@ -94,11 +94,13 @@ void Model::LoadPieces( CString sMeshesPath, CString sMaterialsPath, CString sBo { Clear(); - ASSERT( m_pGeometry == NULL ); - m_pGeometry = MODELMAN->LoadMilkshapeAscii( sMeshesPath ); - + // TRICKY: Load materials before geometry so we can figure out whether the materials require normals. + LoadMaterialsFromMilkshapeAscii( sMaterialsPath ); + ASSERT( m_pGeometry == NULL ); + m_pGeometry = MODELMAN->LoadMilkshapeAscii( sMeshesPath, this->MaterialsNeedNormals() ); + if( LoadMilkshapeAsciiBones( DEFAULT_ANIMATION_NAME, sBonesPath ) ) PlayAnimation( DEFAULT_ANIMATION_NAME ); @@ -110,7 +112,7 @@ void Model::LoadPieces( CString sMeshesPath, CString sMaterialsPath, CString sBo { m_vTempMeshes = m_pGeometry->m_Meshes; m_pTempGeometry = DISPLAY->CreateCompiledGeometry(); - m_pTempGeometry->Set( m_vTempMeshes ); + m_pTempGeometry->Set( m_vTempMeshes, this->MaterialsNeedNormals() ); } } @@ -762,6 +764,16 @@ void Model::HandleCommand( const Command &command ) EndHandleArgs; } +bool Model::MaterialsNeedNormals() const +{ + FOREACH_CONST( msMaterial, m_Materials, m ) + { + if( m->NeedsNormals() ) + return true; + } + return false; +} + /* * (c) 2003-2004 Chris Danford * All rights reserved. diff --git a/stepmania/src/Model.h b/stepmania/src/Model.h index c586ae70c9..b4f5f398ff 100644 --- a/stepmania/src/Model.h +++ b/stepmania/src/Model.h @@ -43,6 +43,8 @@ public: void SetDefaultAnimation( CString sAnimation, float fPlayRate = 1 ); bool m_bRevertToDefaultAnimation; + bool MaterialsNeedNormals() const; + virtual void HandleCommand( const Command &command ); private: diff --git a/stepmania/src/ModelManager.cpp b/stepmania/src/ModelManager.cpp index 3eb72f1c45..530e07875f 100644 --- a/stepmania/src/ModelManager.cpp +++ b/stepmania/src/ModelManager.cpp @@ -26,7 +26,7 @@ ModelManager::~ModelManager() } } -RageModelGeometry* ModelManager::LoadMilkshapeAscii( CString sFile ) +RageModelGeometry* ModelManager::LoadMilkshapeAscii( const CString& sFile, bool bNeedNormals ) { std::map::iterator p = m_mapFileToModel.find(sFile); if(p != m_mapFileToModel.end()) @@ -38,7 +38,7 @@ RageModelGeometry* ModelManager::LoadMilkshapeAscii( CString sFile ) } RageModelGeometry* pModel = new RageModelGeometry; - pModel->LoadMilkshapeAscii( sFile ); + pModel->LoadMilkshapeAscii( sFile, bNeedNormals ); m_mapFileToModel[sFile] = pModel; return pModel; @@ -75,12 +75,13 @@ void ModelManager::UnloadModel( RageModelGeometry *m ) ASSERT(0); // we tried to delete a texture that wasn't loaded. } -bool ModelManager::SetPrefs( ModelManagerPrefs prefs ) +bool ModelManager::SetPrefs( const ModelManagerPrefs& prefs ) { m_Prefs = prefs; return false; } + /* * (c) 2003-2004 Chris Danford * All rights reserved. diff --git a/stepmania/src/ModelManager.h b/stepmania/src/ModelManager.h index 37eb416254..223ae81dcb 100644 --- a/stepmania/src/ModelManager.h +++ b/stepmania/src/ModelManager.h @@ -32,12 +32,12 @@ public: ModelManager(); ~ModelManager(); - RageModelGeometry* LoadMilkshapeAscii( CString sFile ); + RageModelGeometry* LoadMilkshapeAscii( const CString& sFile, bool bNeedNormals ); void UnloadModel( RageModelGeometry *m ); // void ReloadAll(); - bool SetPrefs( ModelManagerPrefs prefs ); - ModelManagerPrefs GetPrefs() { return m_Prefs; } + bool SetPrefs( const ModelManagerPrefs& prefs ); // returns true if needs display to be reset + const ModelManagerPrefs& GetPrefs() { return m_Prefs; } protected: diff --git a/stepmania/src/ModelTypes.h b/stepmania/src/ModelTypes.h index ae6b18d211..789bd666e0 100644 --- a/stepmania/src/ModelTypes.h +++ b/stepmania/src/ModelTypes.h @@ -57,6 +57,8 @@ public: float m_fTexVelocityY; BlendMode m_BlendMode; + bool NeedsNormals() const { return m_bSphereMapped; } + private: int m_iCurState; @@ -83,6 +85,8 @@ struct msMaterial AnimatedTexture diffuse; AnimatedTexture alpha; + + bool NeedsNormals() const { return diffuse.NeedsNormals() || alpha.NeedsNormals() ; } }; struct msPositionKey diff --git a/stepmania/src/RageDisplay.h b/stepmania/src/RageDisplay.h index 22a07e4383..7f830772ae 100644 --- a/stepmania/src/RageDisplay.h +++ b/stepmania/src/RageDisplay.h @@ -17,10 +17,15 @@ const int MAX_TEXTURE_UNITS = 2; class RageCompiledGeometry { public: - virtual ~RageCompiledGeometry() { } - - void Set( const vector &vMeshes ) + virtual ~RageCompiledGeometry() { + m_bNeedsNormals = false; + } + + void Set( const vector &vMeshes, bool bNeedsNormals ) + { + m_bNeedsNormals = bNeedsNormals; + size_t totalVerts = 0; size_t totalTriangles = 0; @@ -50,7 +55,7 @@ public: virtual void Allocate( const vector &vMeshes ) = 0; // allocate space virtual void Change( const vector &vMeshes ) = 0; // new data must be the same size as was passed to Set() virtual void Draw( int iMeshIndex ) const = 0; - + protected: size_t GetTotalVertices() { if( m_vMeshInfo.empty() ) return 0; return m_vMeshInfo.back().iVertexStart + m_vMeshInfo.back().iVertexCount; } size_t GetTotalTriangles() { if( m_vMeshInfo.empty() ) return 0; return m_vMeshInfo.back().iTriangleStart + m_vMeshInfo.back().iTriangleCount; } @@ -63,6 +68,7 @@ protected: int iTriangleCount; }; vector m_vMeshInfo; + bool m_bNeedsNormals; }; class RageDisplay diff --git a/stepmania/src/RageModelGeometry.cpp b/stepmania/src/RageModelGeometry.cpp index 6918094bca..70944505fe 100644 --- a/stepmania/src/RageModelGeometry.cpp +++ b/stepmania/src/RageModelGeometry.cpp @@ -68,8 +68,9 @@ bool RageModelGeometry::HasAnyPerVertexBones() const #define THROW RageException::Throw( "Parse error in \"%s\" at line %d: '%s'", sPath.c_str(), iLineNum, sLine.c_str() ); -void RageModelGeometry::LoadMilkshapeAscii( CString sPath ) +void RageModelGeometry::LoadMilkshapeAscii( const CString& _sPath, bool bNeedsNormals ) { + CString sPath = _sPath; FixSlashesInPlace(sPath); const CString sDir = Dirname( sPath ); @@ -264,7 +265,7 @@ void RageModelGeometry::LoadMilkshapeAscii( CString sPath ) OptimizeBones(); // send the finalized vertices to the graphics card - m_pCompiledGeometry->Set( m_Meshes ); + m_pCompiledGeometry->Set( m_Meshes, bNeedsNormals ); f.Close(); } diff --git a/stepmania/src/RageModelGeometry.h b/stepmania/src/RageModelGeometry.h index 365fac01a5..387e2fb1e6 100644 --- a/stepmania/src/RageModelGeometry.h +++ b/stepmania/src/RageModelGeometry.h @@ -17,8 +17,7 @@ public: RageModelGeometry (); virtual ~RageModelGeometry (); -public: - void LoadMilkshapeAscii( CString sMilkshapeAsciiFile ); + void LoadMilkshapeAscii( const CString& sMilkshapeAsciiFile, bool bNeedsNormals ); void OptimizeBones(); bool HasAnyPerVertexBones() const;