convert mesh and bone names to CString

add MergeMeshes
This commit is contained in:
Chris Danford
2005-10-21 05:23:50 +00:00
parent 37a136a4b8
commit 9455ee6d54
5 changed files with 45 additions and 25 deletions
+3 -3
View File
@@ -87,7 +87,7 @@ void Model::LoadPieces( CString sMeshesPath, CString sMaterialsPath, CString sBo
if( pMesh->nMaterialIndex >= (int) m_Materials.size() )
RageException::Throw( "Model \"%s\" mesh \"%s\" references material index %i, but there are only %i materials",
sMeshesPath.c_str(), pMesh->szName, pMesh->nMaterialIndex, m_Materials.size() );
sMeshesPath.c_str(), pMesh->sName.c_str(), pMesh->nMaterialIndex, m_Materials.size() );
}
if( LoadMilkshapeAsciiBones( DEFAULT_ANIMATION_NAME, sBonesPath ) )
@@ -531,7 +531,7 @@ void Model::PlayAnimation( CString sAniName, float fPlayRate )
m_vpBones[i].mRelative.m[3][1] = pBone->Position[1];
m_vpBones[i].mRelative.m[3][2] = pBone->Position[2];
int nParentBone = m_pCurAnimation->FindBoneByName( pBone->szParentName );
int nParentBone = m_pCurAnimation->FindBoneByName( pBone->sParentName );
if( nParentBone != -1 )
{
RageMatrixMultiply( &m_vpBones[i].mAbsolute, &m_vpBones[nParentBone].mAbsolute, &m_vpBones[i].mRelative );
@@ -690,7 +690,7 @@ void Model::SetBones( const msAnimation* pAnimation, float fFrame, vector<myBone
RageMatrixMultiply( &vpBones[i].mRelativeFinal, &vpBones[i].mRelative, &m );
int nParentBone = pAnimation->FindBoneByName( pBone->szParentName );
int nParentBone = pAnimation->FindBoneByName( pBone->sParentName );
if( nParentBone == -1 )
vpBones[i].mFinal = vpBones[i].mRelativeFinal;
else
+4 -3
View File
@@ -10,6 +10,8 @@
#include "RageDisplay.h"
#include "Foreach.h"
#define MS_MAX_NAME 32
AnimatedTexture::AnimatedTexture()
{
m_iCurState = 0;
@@ -204,7 +206,6 @@ RageVector2 AnimatedTexture::GetTextureTranslate()
msMesh::msMesh()
{
ZERO( szName );
}
msMesh::~msMesh()
@@ -255,7 +256,7 @@ bool msAnimation::LoadMilkshapeAsciiBones( CString sAniName, CString sPath )
THROW;
if (sscanf (sLine, "\"%[^\"]\"", szName) != 1)
THROW;
strcpy( Bone.szName, szName );
Bone.sName = szName;
// parent
if( f.GetLine( sLine ) <= 0 )
@@ -263,7 +264,7 @@ bool msAnimation::LoadMilkshapeAsciiBones( CString sAniName, CString sPath )
strcpy (szName, "");
sscanf (sLine, "\"%[^\"]\"", szName);
strcpy( Bone.szParentName, szName );
Bone.sParentName = szName;
// flags, position, rotation
RageVector3 Position, Rotation;
+16 -18
View File
@@ -3,8 +3,6 @@
#ifndef MODEL_TYPES_H
#define MODEL_TYPES_H
#define MS_MAX_NAME 32
#include "RageTypes.h"
struct msTriangle
@@ -18,8 +16,8 @@ struct msMesh
msMesh();
~msMesh();
char szName[MS_MAX_NAME];
char nMaterialIndex;
CString sName;
char nMaterialIndex;
vector<RageModelVertex> Vertices;
@@ -116,37 +114,37 @@ struct msRotationKey
struct msBone
{
int nFlags;
char szName[MS_MAX_NAME];
char szParentName[MS_MAX_NAME];
RageVector3 Position;
RageVector3 Rotation;
int nFlags;
CString sName;
CString sParentName;
RageVector3 Position;
RageVector3 Rotation;
vector<msPositionKey> PositionKeys;
vector<msPositionKey> PositionKeys;
int nNumRotationKeys;
int nNumAllocedRotationKeys;
vector<msRotationKey> RotationKeys;
int nNumRotationKeys;
int nNumAllocedRotationKeys;
vector<msRotationKey> RotationKeys;
};
struct msAnimation
{
vector<msBone> Bones;
int FindBoneByName( const char* szName ) const
int FindBoneByName( const CString &sName ) const
{
for( unsigned i=0; i<Bones.size(); i++ )
if( strcmp(Bones[i].szName, szName)==0 )
if( Bones[i].sName == sName )
return i;
return -1;
}
bool LoadMilkshapeAsciiBones( CString sAniName, CString sPath );
int nTotalFrames;
int nTotalFrames;
RageVector3 Position;
RageVector3 Rotation;
RageVector3 Position;
RageVector3 Rotation;
};
struct myBone_t
+21 -1
View File
@@ -6,6 +6,8 @@
#include "RageDisplay.h"
#include "IniFile.h"
#define MS_MAX_NAME 32
RageModelGeometry::RageModelGeometry ()
{
m_iRefCount = 1;
@@ -53,6 +55,24 @@ void RageModelGeometry::OptimizeBones()
}
}
void RageModelGeometry::MergeMeshes( int iFromIndex, int iToIndex )
{
msMesh& meshFrom = m_Meshes[ iFromIndex ];
msMesh& meshTo = m_Meshes[ iToIndex ];
int iShiftTriangleVertexIndicesBy = meshTo.Vertices.size();
int iStartShiftingTriangleAtIndex = meshTo.Triangles.size();
meshTo.Vertices.insert( meshTo.Vertices.end(), meshFrom.Vertices.end(), meshFrom.Vertices.end() );
meshTo.Triangles.insert( meshTo.Triangles.end(), meshFrom.Triangles.end(), meshFrom.Triangles.end() );
for( unsigned i=iStartShiftingTriangleAtIndex; i<meshTo.Triangles.size(); i++ )
{
for( int j=0; j<3; j++ )
meshTo.Triangles[i].nVertexIndices[j] += iShiftTriangleVertexIndicesBy;
}
}
bool RageModelGeometry::HasAnyPerVertexBones() const
{
for( unsigned i = 0; i < m_Meshes.size(); ++i )
@@ -123,7 +143,7 @@ void RageModelGeometry::LoadMilkshapeAscii( const CString& _sPath, bool bNeedsNo
if( sscanf (sLine, "\"%[^\"]\" %d %d",szName, &nFlags, &nIndex) != 3 )
THROW;
strcpy( mesh.szName, szName );
mesh.sName = szName;
// mesh.nFlags = nFlags;
mesh.nMaterialIndex = (uint8_t) nIndex;
+1
View File
@@ -17,6 +17,7 @@ public:
void LoadMilkshapeAscii( const CString& sMilkshapeAsciiFile, bool bNeedsNormals );
void OptimizeBones();
void MergeMeshes( int iFromIndex, int iToIndex );
bool HasAnyPerVertexBones() const;
int m_iRefCount;