29 #include "../idlib/precompiled.h"
35 static const char *MD5_SnapshotName =
"_MD5_Snapshot_";
44 static int c_numVerts = 0;
45 static int c_numWeights = 0;
46 static int c_numWeightJoints = 0;
127 parser.
Error(
"Invalid size: %s", token.
c_str() );
131 firstWeightForVertex.
SetNum( count );
132 numWeightsForVertex.
SetNum( count );
142 firstWeightForVertex[
i ] = parser.
ParseInt();
143 numWeightsForVertex[
i ] = parser.
ParseInt();
145 if ( !numWeightsForVertex[ i ] ) {
146 parser.
Error(
"Vertex without any joint weights." );
150 if ( numWeightsForVertex[ i ] + firstWeightForVertex[ i ] > maxweight ) {
151 maxweight = numWeightsForVertex[
i ] + firstWeightForVertex[
i ];
161 parser.
Error(
"Invalid size: %d", count );
166 for( i = 0; i <
count; i++ ) {
170 tris[ i * 3 + 0 ] = parser.
ParseInt();
171 tris[ i * 3 + 1 ] = parser.
ParseInt();
172 tris[ i * 3 + 2 ] = parser.
ParseInt();
181 parser.
Error(
"Invalid size: %d", count );
184 if ( maxweight > count ) {
185 parser.
Warning(
"Vertices reference out of range weights in model (%d of %d weights).", maxweight, count );
188 tempWeights.
SetNum( count );
190 for( i = 0; i <
count; i++ ) {
195 if ( ( jointnum < 0 ) || ( jointnum >= numJoints ) ) {
196 parser.
Error(
"Joint Index out of range(%d): %d", numJoints, jointnum );
199 tempWeights[
i ].joint = jointnum;
200 tempWeights[
i ].jointWeight = parser.
ParseFloat();
212 num = firstWeightForVertex[
i];
213 for( j = 0; j < numWeightsForVertex[
i]; j++, num++, count++ ) {
222 numWeightsForVertex.
Clear();
223 firstWeightForVertex.
Clear();
371 int i, bestJoint, vertNum, weightVertNum;
388 for( i = 0; weightVertNum < vertNum; i++ ) {
460 parser.
Error(
"Invalid parent for joint '%s'", joint->
name.
c_str() );
470 defaultPose->
q.
w = defaultPose->
q.
CalcW();
516 parser.
Error(
"Invalid version %d. Should be version %d\n", version,
MD5_VERSION );
532 poseMat3 = (
idJointMat * )_alloca16( num *
sizeof( *poseMat3 ) );
538 parser.
Error(
"Invalid size: %d", num );
550 for( i = 0; i <
joints.
Num(); i++, joint++, pose++ ) {
554 if ( joint->parent ) {
555 parentNum = joint->parent -
joints.
Ptr();
557 pose->
t = ( poseMat3[
i ].
ToVec3() - poseMat3[ parentNum ].
ToVec3() ) * poseMat3[ parentNum ].ToMat3().Transpose();
591 int totalWeights = 0;
658 common->
Error(
"idRenderModelMD5::Bounds: called without entity" );
686 for( i = 0; i <
num; i++, joint++, md5Joint++ ) {
687 pos = ent->
origin + joint->ToVec3() * ent->
axis;
710 for( i = 0; i <
num; i++, joint++ ) {
711 pos = ent->
origin + joint->ToVec3() * ent->
axis;
738 common->
Printf(
"idRenderModelMD5::InstantiateDynamicModel: NULL joints on renderEntity for '%s'\n",
Name() );
742 common->
Printf(
"idRenderModelMD5::InstantiateDynamicModel: renderEntity has different number of joints than model for '%s'\n",
Name() );
750 assert( dynamic_cast<idRenderModelStatic *>(cachedModel) !=
NULL );
755 staticModel->
InitEmpty( MD5_SnapshotName );
768 staticModel->
InitEmpty( MD5_SnapshotName );
791 surf = &staticModel->
surfaces[surfaceNum];
798 surf = &staticModel->
surfaces.Alloc();
859 for( i = 0; i <
joints.
Num(); i++, joint++ ) {
874 if ( ( handle < 0 ) || ( handle >=
joints.
Num() ) ) {
875 return "<invalid joint>";
878 return joints[ handle ].name;
891 common->
Error(
"idRenderModelMD5::NearestJoint: surfaceNum > meshes.Num()" );
943 total =
sizeof( *this );
948 total +=
joints[
i].name.DynamicMemoryUsed();
static void RemoveOverlaySurfacesFromModel(idRenderModel *baseModel)
bool SurfaceCastsShadow(void) const
int CheckTokenString(const char *string)
virtual const char * Name() const
struct deformInfo_s * deformInfo
virtual void List() const
deformInfo_t * R_BuildDeformInfo(int numVerts, const idDrawVert *verts, int numIndexes, const int *indexes, bool useUnsmoothedTangents)
bool AddBounds(const idBounds &a)
bool FindSurfaceWithId(int id, int &surfaceNum)
idMat3 ToMat3(void) const
idList< modelSurface_t > surfaces
void TransformScaledVerts(idDrawVert *verts, const idJointMat *joints, float scale)
void CalculateBounds(const idJointMat *joints)
assert(prefInfo.fullscreenBtn)
virtual const idMD5Joint * GetJoints(void) const
const float * ToFloatPtr(void) const
float GetFloat(void) const
void SetNum(int newnum, bool resize=true)
idMat3 ToMat3(void) const
const float * ToFloatPtr(void) const
virtual int ReadFile(const char *relativePath, void **buffer, ID_TIME_T *timestamp=NULL)=0
GLenum GLenum GLenum GLenum GLenum scale
idMat3 Transpose(void) const
void ParseMesh(idLexer &parser, int numJoints, const idJointMat *joints)
idList< idMD5Joint > joints
int Parse1DMatrix(int x, float *m)
idFileSystem * fileSystem
const idMaterial * shader
void SetGranularity(int newgranularity)
#define MD5_VERSION_STRING
const char * GetName(void) const
bool facePlanesCalculated
void TransformVerts(idDrawVert *verts, const idJointMat *joints)
virtual const char * Name() const =0
idCVar r_showSkel("r_showSkel","0", CVAR_RENDERER|CVAR_INTEGER,"draw the skeleton when model animates, 1 = draw model with skeleton, 2 = draw skeleton only", 0, 2, idCmdSystem::ArgCompletion_Integer< 0, 2 >)
void R_DeriveTangents(srfTriangles_t *tri, bool allocFacePlanes=true)
virtual const idMaterial * FindMaterial(const char *name, bool makeDefault=true)=0
float ParseFloat(bool *errorFlag=NULL)
srfTriangles_t * R_AllocStaticTriSurf(void)
void UpdateSurface(const struct renderEntity_s *ent, const idJointMat *joints, modelSurface_t *surf)
virtual jointHandle_t GetJointHandle(const char *name) const
bool DeleteSurfaceWithId(int id)
const int SHADERPARM_MD5_SKINSCALE
void SetTranslation(const idVec3 &t)
void R_FreeDeformInfo(deformInfo_t *deformInfo)
const idMaterial * customShader
int Icmp(const char *text) const
virtual int NearestJoint(int surfaceNum, int a, int b, int c) const
idCVar r_skipSuppress("r_skipSuppress","0", CVAR_RENDERER|CVAR_BOOL,"ignore the per-view suppressions")
void SetRotation(const idMat3 &m)
bool AddPoint(const idVec3 &v)
void Error(const char *str,...) id_attribute((format(printf
idCVar r_useDeferredTangents("r_useDeferredTangents","1", CVAR_RENDERER|CVAR_BOOL,"defer tangents calculations after deform")
virtual idBounds Bounds(const struct renderEntity_s *ent) const
virtual int Memory() const
GLuint GLuint GLsizei count
virtual void VPCALL MinMax(float &min, float &max, const float *src, const int count)=0
virtual void InitEmpty(const char *name)
struct vertexWeight_s vertexWeight_t
virtual void DebugLine(const idVec4 &color, const idVec3 &start, const idVec3 &end, const int lifetime=0, const bool depthTest=false)=0
GLubyte GLubyte GLubyte GLubyte w
virtual void VPCALL TransformVerts(idDrawVert *verts, const int numVerts, const idJointMat *joints, const idVec4 *weights, const int *index, const int numWeights)=0
idVec3 ToVec3(void) const
int NumWeights(void) const
virtual void virtual void virtual void DWarning(const char *fmt,...) id_attribute((format(printf
const idMD5Joint * parent
srfTriangles_t * geometry
void ParseJoint(idLexer &parser, idMD5Joint *joint, idJointQuat *defaultPose)
const idDeclSkin * customSkin
const idMaterial * R_RemapShaderBySkin(const idMaterial *shader, const idDeclSkin *skin, const idMaterial *customShader)
int GetInteger(void) const
void * Mem_Alloc16(const int size)
void R_FreeStaticTriSurf(srfTriangles_t *tri)
virtual void DrawText(const char *text, const idVec3 &origin, float scale, const idVec4 &color, const idMat3 &viewAxis, const int align=1, const int lifetime=0, bool depthTest=false)=0
void FromTransformedBounds(const idBounds &bounds, const idVec3 &origin, const idMat3 &axis)
virtual void VPCALL Mul(float *dst, const float constant, const float *src, const int count)=0
GLubyte GLubyte GLubyte a
virtual void Printf(const char *fmt,...) id_attribute((format(printf
void R_BoundTriSurf(srfTriangles_t *tri)
idBounds Expand(const float d) const
bool UseUnsmoothedTangents(void) const
virtual void PurgeModel()
idDeclManager * declManager
int NearestJoint(int a, int b, int c) const
const idMaterial * shader
idMat3 ToMat3(void) const
int ExpectTokenString(const char *string)
idCVar r_useCachedDynamicModels("r_useCachedDynamicModels","1", CVAR_RENDERER|CVAR_BOOL,"cache snapshots of dynamic models")
void void Warning(const char *str,...) id_attribute((format(printf
virtual dynamicModel_t IsDynamicModel() const
virtual void InitFromFile(const char *fileName)
void Mem_Free16(void *ptr)
int suppressSurfaceInViewID
idBounds CalcBounds(const idJointMat *joints)
idCVar r_jointNameScale("r_jointNameScale","0.02", CVAR_RENDERER|CVAR_FLOAT,"size of joint names when r_showskel is set to 1")
virtual void Print() const
const char * c_str(void) const
virtual int NumSurfaces() const
const idVec3 & ToVec3(void) const
virtual void DebugBounds(const idVec4 &color, const idBounds &bounds, const idVec3 &org=vec3_origin, const int lifetime=0)=0
virtual idRenderModel * InstantiateDynamicModel(const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel)
virtual const char * GetJointName(jointHandle_t handle) const
virtual void Error(const char *fmt,...) id_attribute((format(printf
virtual const idJointQuat * GetDefaultPose(void) const
idCVar r_jointNameOffset("r_jointNameOffset","0.5", CVAR_RENDERER|CVAR_FLOAT,"offset of joint names when r_showskel is set to 1")
virtual int NumJoints(void) const
void R_AllocStaticTriSurfVerts(srfTriangles_t *tri, int numVerts)
bool ContainsPoint(const idVec3 &p) const
float shaderParms[MAX_ENTITY_SHADER_PARMS]
int R_DeformInfoMemoryUsed(deformInfo_t *deformInfo)
int ReadToken(idToken *token)
idList< idMD5Mesh > meshes
void R_FreeStaticTriSurfVertexCaches(srfTriangles_t *tri)
idList< idJointQuat > defaultPose
void DrawJoints(const renderEntity_t *ent, const struct viewDef_s *view) const
size_t MemoryUsed(void) const
int LoadFile(const char *filename, bool OSPath=false)
idList< idVec2 > texCoords
idSIMDProcessor * SIMDProcessor
dominantTri_t * dominantTris