convert mesh and bone names to CString
add MergeMeshes
This commit is contained in:
@@ -87,7 +87,7 @@ void Model::LoadPieces( CString sMeshesPath, CString sMaterialsPath, CString sBo
|
|||||||
|
|
||||||
if( pMesh->nMaterialIndex >= (int) m_Materials.size() )
|
if( pMesh->nMaterialIndex >= (int) m_Materials.size() )
|
||||||
RageException::Throw( "Model \"%s\" mesh \"%s\" references material index %i, but there are only %i materials",
|
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 ) )
|
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][1] = pBone->Position[1];
|
||||||
m_vpBones[i].mRelative.m[3][2] = pBone->Position[2];
|
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 )
|
if( nParentBone != -1 )
|
||||||
{
|
{
|
||||||
RageMatrixMultiply( &m_vpBones[i].mAbsolute, &m_vpBones[nParentBone].mAbsolute, &m_vpBones[i].mRelative );
|
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 );
|
RageMatrixMultiply( &vpBones[i].mRelativeFinal, &vpBones[i].mRelative, &m );
|
||||||
|
|
||||||
int nParentBone = pAnimation->FindBoneByName( pBone->szParentName );
|
int nParentBone = pAnimation->FindBoneByName( pBone->sParentName );
|
||||||
if( nParentBone == -1 )
|
if( nParentBone == -1 )
|
||||||
vpBones[i].mFinal = vpBones[i].mRelativeFinal;
|
vpBones[i].mFinal = vpBones[i].mRelativeFinal;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
#include "RageDisplay.h"
|
#include "RageDisplay.h"
|
||||||
#include "Foreach.h"
|
#include "Foreach.h"
|
||||||
|
|
||||||
|
#define MS_MAX_NAME 32
|
||||||
|
|
||||||
AnimatedTexture::AnimatedTexture()
|
AnimatedTexture::AnimatedTexture()
|
||||||
{
|
{
|
||||||
m_iCurState = 0;
|
m_iCurState = 0;
|
||||||
@@ -204,7 +206,6 @@ RageVector2 AnimatedTexture::GetTextureTranslate()
|
|||||||
|
|
||||||
msMesh::msMesh()
|
msMesh::msMesh()
|
||||||
{
|
{
|
||||||
ZERO( szName );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
msMesh::~msMesh()
|
msMesh::~msMesh()
|
||||||
@@ -255,7 +256,7 @@ bool msAnimation::LoadMilkshapeAsciiBones( CString sAniName, CString sPath )
|
|||||||
THROW;
|
THROW;
|
||||||
if (sscanf (sLine, "\"%[^\"]\"", szName) != 1)
|
if (sscanf (sLine, "\"%[^\"]\"", szName) != 1)
|
||||||
THROW;
|
THROW;
|
||||||
strcpy( Bone.szName, szName );
|
Bone.sName = szName;
|
||||||
|
|
||||||
// parent
|
// parent
|
||||||
if( f.GetLine( sLine ) <= 0 )
|
if( f.GetLine( sLine ) <= 0 )
|
||||||
@@ -263,7 +264,7 @@ bool msAnimation::LoadMilkshapeAsciiBones( CString sAniName, CString sPath )
|
|||||||
strcpy (szName, "");
|
strcpy (szName, "");
|
||||||
sscanf (sLine, "\"%[^\"]\"", szName);
|
sscanf (sLine, "\"%[^\"]\"", szName);
|
||||||
|
|
||||||
strcpy( Bone.szParentName, szName );
|
Bone.sParentName = szName;
|
||||||
|
|
||||||
// flags, position, rotation
|
// flags, position, rotation
|
||||||
RageVector3 Position, Rotation;
|
RageVector3 Position, Rotation;
|
||||||
|
|||||||
+16
-18
@@ -3,8 +3,6 @@
|
|||||||
#ifndef MODEL_TYPES_H
|
#ifndef MODEL_TYPES_H
|
||||||
#define MODEL_TYPES_H
|
#define MODEL_TYPES_H
|
||||||
|
|
||||||
#define MS_MAX_NAME 32
|
|
||||||
|
|
||||||
#include "RageTypes.h"
|
#include "RageTypes.h"
|
||||||
|
|
||||||
struct msTriangle
|
struct msTriangle
|
||||||
@@ -18,8 +16,8 @@ struct msMesh
|
|||||||
msMesh();
|
msMesh();
|
||||||
~msMesh();
|
~msMesh();
|
||||||
|
|
||||||
char szName[MS_MAX_NAME];
|
CString sName;
|
||||||
char nMaterialIndex;
|
char nMaterialIndex;
|
||||||
|
|
||||||
vector<RageModelVertex> Vertices;
|
vector<RageModelVertex> Vertices;
|
||||||
|
|
||||||
@@ -116,37 +114,37 @@ struct msRotationKey
|
|||||||
|
|
||||||
struct msBone
|
struct msBone
|
||||||
{
|
{
|
||||||
int nFlags;
|
int nFlags;
|
||||||
char szName[MS_MAX_NAME];
|
CString sName;
|
||||||
char szParentName[MS_MAX_NAME];
|
CString sParentName;
|
||||||
RageVector3 Position;
|
RageVector3 Position;
|
||||||
RageVector3 Rotation;
|
RageVector3 Rotation;
|
||||||
|
|
||||||
vector<msPositionKey> PositionKeys;
|
vector<msPositionKey> PositionKeys;
|
||||||
|
|
||||||
int nNumRotationKeys;
|
int nNumRotationKeys;
|
||||||
int nNumAllocedRotationKeys;
|
int nNumAllocedRotationKeys;
|
||||||
vector<msRotationKey> RotationKeys;
|
vector<msRotationKey> RotationKeys;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct msAnimation
|
struct msAnimation
|
||||||
{
|
{
|
||||||
vector<msBone> Bones;
|
vector<msBone> Bones;
|
||||||
|
|
||||||
int FindBoneByName( const char* szName ) const
|
int FindBoneByName( const CString &sName ) const
|
||||||
{
|
{
|
||||||
for( unsigned i=0; i<Bones.size(); i++ )
|
for( unsigned i=0; i<Bones.size(); i++ )
|
||||||
if( strcmp(Bones[i].szName, szName)==0 )
|
if( Bones[i].sName == sName )
|
||||||
return i;
|
return i;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoadMilkshapeAsciiBones( CString sAniName, CString sPath );
|
bool LoadMilkshapeAsciiBones( CString sAniName, CString sPath );
|
||||||
|
|
||||||
int nTotalFrames;
|
int nTotalFrames;
|
||||||
|
|
||||||
RageVector3 Position;
|
RageVector3 Position;
|
||||||
RageVector3 Rotation;
|
RageVector3 Rotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct myBone_t
|
struct myBone_t
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include "RageDisplay.h"
|
#include "RageDisplay.h"
|
||||||
#include "IniFile.h"
|
#include "IniFile.h"
|
||||||
|
|
||||||
|
#define MS_MAX_NAME 32
|
||||||
|
|
||||||
RageModelGeometry::RageModelGeometry ()
|
RageModelGeometry::RageModelGeometry ()
|
||||||
{
|
{
|
||||||
m_iRefCount = 1;
|
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
|
bool RageModelGeometry::HasAnyPerVertexBones() const
|
||||||
{
|
{
|
||||||
for( unsigned i = 0; i < m_Meshes.size(); ++i )
|
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 )
|
if( sscanf (sLine, "\"%[^\"]\" %d %d",szName, &nFlags, &nIndex) != 3 )
|
||||||
THROW;
|
THROW;
|
||||||
|
|
||||||
strcpy( mesh.szName, szName );
|
mesh.sName = szName;
|
||||||
// mesh.nFlags = nFlags;
|
// mesh.nFlags = nFlags;
|
||||||
mesh.nMaterialIndex = (uint8_t) nIndex;
|
mesh.nMaterialIndex = (uint8_t) nIndex;
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public:
|
|||||||
|
|
||||||
void LoadMilkshapeAscii( const CString& sMilkshapeAsciiFile, bool bNeedsNormals );
|
void LoadMilkshapeAscii( const CString& sMilkshapeAsciiFile, bool bNeedsNormals );
|
||||||
void OptimizeBones();
|
void OptimizeBones();
|
||||||
|
void MergeMeshes( int iFromIndex, int iToIndex );
|
||||||
bool HasAnyPerVertexBones() const;
|
bool HasAnyPerVertexBones() const;
|
||||||
|
|
||||||
int m_iRefCount;
|
int m_iRefCount;
|
||||||
|
|||||||
Reference in New Issue
Block a user