From 69769b2c74c892b086e48e743ca94d4efcb2e1da Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sun, 8 Feb 2004 11:17:03 +0000 Subject: [PATCH] support sharing of geometry between Models --- stepmania/src/ActorUtil.cpp | 5 +- stepmania/src/Model.cpp | 94 ++++++++++++++++++++++--------- stepmania/src/Model.h | 13 ++--- stepmania/src/NoteSkinManager.cpp | 1 + 4 files changed, 76 insertions(+), 37 deletions(-) diff --git a/stepmania/src/ActorUtil.cpp b/stepmania/src/ActorUtil.cpp index fa824ab539..b1f62faaed 100644 --- a/stepmania/src/ActorUtil.cpp +++ b/stepmania/src/ActorUtil.cpp @@ -183,10 +183,11 @@ Actor* MakeActor( RageTextureID ID ) pSprite->Load( ID ); return pSprite; } - else if( sExt=="txt" ) + else if( sExt=="txt" || + sExt=="model" ) { Model* pModel = new Model; - pModel->LoadMilkshapeAscii( ID.filename ); + pModel->Load( ID.filename ); return pModel; } /* Do this last, to avoid the IsADirectory in most cases. */ diff --git a/stepmania/src/Model.cpp b/stepmania/src/Model.cpp index 86eb0efd5e..01e06f2e72 100644 --- a/stepmania/src/Model.cpp +++ b/stepmania/src/Model.cpp @@ -55,9 +55,73 @@ void Model::Clear () m_pCurAnimation = NULL; } +void Model::Load( CString sFile ) +{ + if( sFile == "" ) return; + + CString sExt = GetExtension(sFile); + sExt.MakeLower(); + if( sExt=="txt" ) + LoadMilkshapeAscii( sFile ); + else if( sExt=="model" ) + LoadFromModelFile( sFile ); +} + #define THROW RageException::Throw( "Parse at line %d: '%s'", sLine.c_str() ); -bool Model::LoadMilkshapeAscii( CString sPath ) +void Model::LoadFromModelFile( CString sPath ) +{ + Clear(); + + IniFile ini; + ini.SetPath( sPath ); + ini.ReadFile(); + + CString sDir = Dirname( sPath ); + + CString sMeshes, sMaterials, sBones; + if( !ini.GetValue( "Model", "Meshes", sMeshes ) ) + RageException::Throw( "The model file '%s' is missing the value [Model] Meshes.", sPath.c_str() ); + if( !ini.GetValue( "Model", "Materials", sMaterials ) ) + RageException::Throw( "The model file '%s' is missing the value [Model] Materials.", sPath.c_str() ); + if( !ini.GetValue( "Model", "Bones", sBones ) ) + RageException::Throw( "The model file '%s' is missing the value [Model] Bones.", sPath.c_str() ); + + LoadPieces( sDir+sMeshes, sDir+sMaterials, sDir+sBones ); +} + +void Model::LoadMilkshapeAscii( CString sPath ) +{ + LoadPieces( sPath, sPath, sPath ); +} + +void Model::LoadPieces( CString sMeshesPath, CString sMaterialsPath, CString sBomesPath ) +{ + Clear(); + + ASSERT( m_pGeometry == NULL ); + m_pGeometry = MODELMAN->LoadMilkshapeAscii( sMeshesPath ); + + LoadMaterialsFromMilkshapeAscii( sMaterialsPath ); + + LoadMilkshapeAsciiBones( DEFAULT_ANIMATION_NAME, sBomesPath ); + + // + // Setup temp vertices (if necessary) + // + bUseTempVertices = m_mapNameToAnimation[DEFAULT_ANIMATION_NAME].Bones.size() > 0; // if there are no bones, then there's no reason to use temp vertices + if( bUseTempVertices ) + { + m_vTempVerticesByMesh.resize( m_pGeometry->m_Meshes.size() ); + for (int i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++) + { + msMesh& Mesh = m_pGeometry->m_Meshes[i]; + m_vTempVerticesByMesh[i].resize( Mesh.Vertices.size() ); + } + } +} + +void Model::LoadMaterialsFromMilkshapeAscii( CString sPath ) { FixSlashesInPlace(sPath); const CString sDir = Dirname( sPath ); @@ -66,14 +130,8 @@ bool Model::LoadMilkshapeAscii( CString sPath ) if( !f.Open( sPath ) ) RageException::Throw( "Model::LoadMilkshapeAscii Could not open \"%s\": %s", sPath.c_str(), f.GetError().c_str() ); - Clear (); - CString sLine; int iLineNum = 0; - int i; - - ASSERT( m_pGeometry == NULL ); - m_pGeometry = MODELMAN->LoadMilkshapeAscii( sPath ); while( f.GetLine( sLine ) > 0 ) { @@ -211,27 +269,9 @@ bool Model::LoadMilkshapeAscii( CString sPath ) } f.Close(); - - LoadMilkshapeAsciiBones( DEFAULT_ANIMATION_NAME, sPath ); - - // - // Setup temp vertices (if necessary) - // - bUseTempVertices = m_mapNameToAnimation[DEFAULT_ANIMATION_NAME].Bones.size() > 0; // if there are no bones, then there's no reason to use temp vertices - if( bUseTempVertices ) - { - m_vTempVerticesByMesh.resize( m_pGeometry->m_Meshes.size() ); - for (i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++) - { - msMesh& Mesh = m_pGeometry->m_Meshes[i]; - m_vTempVerticesByMesh[i].resize( Mesh.Vertices.size() ); - } - } - - return true; } -bool Model::LoadMilkshapeAsciiBones( CString sAniName, CString sPath ) +void Model::LoadMilkshapeAsciiBones( CString sAniName, CString sPath ) { FixSlashesInPlace(sPath); const CString sDir = Dirname( sPath ); @@ -367,8 +407,6 @@ bool Model::LoadMilkshapeAsciiBones( CString sAniName, CString sPath ) PlayAnimation( sAniName ); } } - - return true; } void Model::DrawPrimitives() diff --git a/stepmania/src/Model.h b/stepmania/src/Model.h index 1623a6afe3..65cb6c773b 100644 --- a/stepmania/src/Model.h +++ b/stepmania/src/Model.h @@ -29,14 +29,13 @@ public: public: void Clear (); - void Load( CString sFile ) - { - if( sFile == "" ) return; - LoadMilkshapeAscii( sFile ); - }; + void Load( CString sFile ); - bool LoadMilkshapeAscii( CString sFile ); - bool LoadMilkshapeAsciiBones( CString sAniName, CString sFile ); + void LoadPieces( CString sMeshesPath, CString sMaterialsPath, CString sBomesPath ); + void LoadFromModelFile( CString sFile ); + void LoadMilkshapeAscii( CString sFile ); + void LoadMaterialsFromMilkshapeAscii( CString sPath ); + void LoadMilkshapeAsciiBones( CString sAniName, CString sPath ); void PlayAnimation( CString sAniName, float fPlayRate = 1 ); virtual void Update( float fDelta ); diff --git a/stepmania/src/NoteSkinManager.cpp b/stepmania/src/NoteSkinManager.cpp index bedccb61ff..eb95baf88d 100644 --- a/stepmania/src/NoteSkinManager.cpp +++ b/stepmania/src/NoteSkinManager.cpp @@ -271,6 +271,7 @@ CString NoteSkinManager::GetPathToFromDir( CString sDir, CString sFileName, bool GetDirListing( sDir+sFileName+"*.redir", matches, false, true ); GetDirListing( sDir+sFileName+"*.actor", matches, false, true ); + GetDirListing( sDir+sFileName+"*.model", matches, false, true ); GetDirListing( sDir+sFileName+"*.txt", matches, false, true ); GetDirListing( sDir+sFileName+"*.sprite", matches, false, true ); GetDirListing( sDir+sFileName+"*.png", matches, false, true );