static void ASE_KeyTFACE_LIST( const char *token ) { aseMesh_t *pMesh = ASE_GetCurrentMesh(); if ( !strcmp( token, "*MESH_TFACE" ) ) { int a, b, c; ASE_GetToken( qfalse ); ASE_GetToken( qfalse ); a = atoi( s_token ); ASE_GetToken( qfalse ); c = atoi( s_token ); ASE_GetToken( qfalse ); b = atoi( s_token ); pMesh->tfaces[pMesh->currentFace][0] = a; pMesh->tfaces[pMesh->currentFace][1] = b; pMesh->tfaces[pMesh->currentFace][2] = c; pMesh->currentFace++; } else { Error( "Unknown token '%s' in MESH_TFACE", token ); } }
static void ASE_KeyMESH_VERTEX_LIST( const char *token ) { aseMesh_t *pMesh = ASE_GetCurrentMesh(); if ( !strcmp( token, "*MESH_VERTEX" ) ) { ASE_GetToken( qfalse ); // skip number ASE_GetToken( qfalse ); pMesh->vertexes[pMesh->currentVertex].y = atof( s_token ); ASE_GetToken( qfalse ); pMesh->vertexes[pMesh->currentVertex].x = -atof( s_token ); ASE_GetToken( qfalse ); pMesh->vertexes[pMesh->currentVertex].z = atof( s_token ); pMesh->currentVertex++; if ( pMesh->currentVertex > pMesh->numVertexes ) { Error( "pMesh->currentVertex >= pMesh->numVertexes" ); } } else { Error( "Unknown token '%s' while parsing MESH_VERTEX_LIST", token ); } }
static void ASE_KeyMESH_ANIMATION( const char *token ) { aseMesh_t *pMesh = ASE_GetCurrentMesh(); // loads a single animation frame if ( !strcmp( token, "*MESH" ) ) { VERBOSE( ( "...found MESH\n" ) ); assert( pMesh->faces == 0 ); assert( pMesh->vertexes == 0 ); assert( pMesh->tvertexes == 0 ); memset( pMesh, 0, sizeof( *pMesh ) ); ASE_ParseBracedBlock( ASE_KeyMESH ); if ( ++ase.objects[ase.currentObject].anim.currentFrame == MAX_ASE_ANIMATION_FRAMES ) { Error( "Too many animation frames" ); } } else { Error( "Unknown token '%s' while parsing MESH_ANIMATION", token ); } }
static void ASE_KeyMESH_TVERTLIST( const char *token ) { aseMesh_t *pMesh = ASE_GetCurrentMesh(); if ( !strcmp( token, "*MESH_TVERT" ) ) { char u[80], v[80], w[80]; ASE_GetToken( qfalse ); ASE_GetToken( qfalse ); strcpy( u, s_token ); ASE_GetToken( qfalse ); strcpy( v, s_token ); ASE_GetToken( qfalse ); strcpy( w, s_token ); pMesh->tvertexes[pMesh->currentVertex].s = atof( u ); pMesh->tvertexes[pMesh->currentVertex].t = 1.0f - atof( v ); pMesh->currentVertex++; if ( pMesh->currentVertex > pMesh->numTVertexes ) { Error( "pMesh->currentVertex > pMesh->numTVertexes" ); } } else { Error( "Unknown token '%s' while parsing MESH_TVERTLIST" ); } }
static void ASE_KeyMESH_FACE_LIST( const char *token ) { aseMesh_t *pMesh = ASE_GetCurrentMesh(); if ( !strcmp( token, "*MESH_FACE" ) ) { ASE_GetToken( false ); // skip face number // we are flipping the order here to change the front/back facing // from 3DS to our standard (clockwise facing out) ASE_GetToken( false ); // skip label ASE_GetToken( false ); // first vertex pMesh->faces[ase.currentFace].vertexNum[0] = atoi( ase.token ); ASE_GetToken( false ); // skip label ASE_GetToken( false ); // second vertex pMesh->faces[ase.currentFace].vertexNum[2] = atoi( ase.token ); ASE_GetToken( false ); // skip label ASE_GetToken( false ); // third vertex pMesh->faces[ase.currentFace].vertexNum[1] = atoi( ase.token ); ASE_GetToken( true ); // we could parse material id and smoothing groups here /* if ( ( p = strstr( ase.token, "*MESH_MTLID" ) ) != 0 ) { p += strlen( "*MESH_MTLID" ) + 1; mtlID = atoi( p ); } else { common->Error( "No *MESH_MTLID found for face!" ); } */ ase.currentFace++; } else { common->Error( "Unknown token '%s' while parsing MESH_FACE_LIST", token ); } }
static void ASE_KeyMESH_FACE_LIST( const char *token ) { aseMesh_t *pMesh = ASE_GetCurrentMesh(); if ( !strcmp( token, "*MESH_FACE" ) ) { ASE_GetToken( qfalse ); // skip face number ASE_GetToken( qfalse ); // skip label ASE_GetToken( qfalse ); // first vertex pMesh->faces[pMesh->currentFace][0] = atoi( s_token ); ASE_GetToken( qfalse ); // skip label ASE_GetToken( qfalse ); // second vertex pMesh->faces[pMesh->currentFace][2] = atoi( s_token ); ASE_GetToken( qfalse ); // skip label ASE_GetToken( qfalse ); // third vertex pMesh->faces[pMesh->currentFace][1] = atoi( s_token ); ASE_GetToken( qtrue ); /* if ( ( p = strstr( s_token, "*MESH_MTLID" ) ) != 0 ) { p += strlen( "*MESH_MTLID" ) + 1; mtlID = atoi( p ); } else { Error( "No *MESH_MTLID found for face!" ); } */ pMesh->currentFace++; } else { Error( "Unknown token '%s' while parsing MESH_FACE_LIST", token ); } }
static void ASE_KeyMESH( const char *token ) { aseMesh_t *pMesh = ASE_GetCurrentMesh(); if( !strcmp( token, "*TIMEVALUE" ) ) { ASE_GetToken( false ); pMesh->timeValue = atoi( ase.token ); VERBOSE( ( ".....timevalue: %d\n", pMesh->timeValue ) ); } else if( !strcmp( token, "*MESH_NUMVERTEX" ) ) { ASE_GetToken( false ); pMesh->numVertexes = atoi( ase.token ); VERBOSE( ( ".....num vertexes: %d\n", pMesh->numVertexes ) ); } else if( !strcmp( token, "*MESH_NUMTVERTEX" ) ) { ASE_GetToken( false ); pMesh->numTVertexes = atoi( ase.token ); VERBOSE( ( ".....num tvertexes: %d\n", pMesh->numTVertexes ) ); } else if( !strcmp( token, "*MESH_NUMCVERTEX" ) ) { ASE_GetToken( false ); pMesh->numCVertexes = atoi( ase.token ); VERBOSE( ( ".....num cvertexes: %d\n", pMesh->numCVertexes ) ); } else if( !strcmp( token, "*MESH_NUMFACES" ) ) { ASE_GetToken( false ); pMesh->numFaces = atoi( ase.token ); VERBOSE( ( ".....num faces: %d\n", pMesh->numFaces ) ); } else if( !strcmp( token, "*MESH_NUMTVFACES" ) ) { ASE_GetToken( false ); pMesh->numTVFaces = atoi( ase.token ); VERBOSE( ( ".....num tvfaces: %d\n", pMesh->numTVFaces ) ); if( pMesh->numTVFaces != pMesh->numFaces ) { common->Error( "MESH_NUMTVFACES != MESH_NUMFACES" ); } } else if( !strcmp( token, "*MESH_NUMCVFACES" ) ) { ASE_GetToken( false ); pMesh->numCVFaces = atoi( ase.token ); VERBOSE( ( ".....num cvfaces: %d\n", pMesh->numCVFaces ) ); if( pMesh->numTVFaces != pMesh->numFaces ) { common->Error( "MESH_NUMCVFACES != MESH_NUMFACES" ); } } else if( !strcmp( token, "*MESH_VERTEX_LIST" ) ) { pMesh->vertexes = ( idVec3 * ) Mem_Alloc( sizeof( idVec3 ) * pMesh->numVertexes ); ase.currentVertex = 0; VERBOSE( ( ".....parsing MESH_VERTEX_LIST\n" ) ); ASE_ParseBracedBlock( ASE_KeyMESH_VERTEX_LIST ); } else if( !strcmp( token, "*MESH_TVERTLIST" ) ) { ase.currentVertex = 0; pMesh->tvertexes = ( idVec2 * ) Mem_Alloc( sizeof( idVec2 ) * pMesh->numTVertexes ); VERBOSE( ( ".....parsing MESH_TVERTLIST\n" ) ); ASE_ParseBracedBlock( ASE_KeyMESH_TVERTLIST ); } else if( !strcmp( token, "*MESH_CVERTLIST" ) ) { ase.currentVertex = 0; pMesh->cvertexes = ( idVec3 * ) Mem_Alloc( sizeof( idVec3 ) * pMesh->numCVertexes ); VERBOSE( ( ".....parsing MESH_CVERTLIST\n" ) ); ASE_ParseBracedBlock( ASE_KeyMESH_CVERTLIST ); } else if( !strcmp( token, "*MESH_FACE_LIST" ) ) { pMesh->faces = ( aseFace_t * ) Mem_Alloc( sizeof( aseFace_t ) * pMesh->numFaces ); ase.currentFace = 0; VERBOSE( ( ".....parsing MESH_FACE_LIST\n" ) ); ASE_ParseBracedBlock( ASE_KeyMESH_FACE_LIST ); } else if( !strcmp( token, "*MESH_TFACELIST" ) ) { if( !pMesh->faces ) { common->Error( "*MESH_TFACELIST before *MESH_FACE_LIST" ); } ase.currentFace = 0; VERBOSE( ( ".....parsing MESH_TFACE_LIST\n" ) ); ASE_ParseBracedBlock( ASE_KeyTFACE_LIST ); } else if( !strcmp( token, "*MESH_CFACELIST" ) ) { if( !pMesh->faces ) { common->Error( "*MESH_CFACELIST before *MESH_FACE_LIST" ); } ase.currentFace = 0; VERBOSE( ( ".....parsing MESH_CFACE_LIST\n" ) ); ASE_ParseBracedBlock( ASE_KeyCFACE_LIST ); } else if( !strcmp( token, "*MESH_NORMALS" ) ) { if( !pMesh->faces ) { common->DWarning( "*MESH_NORMALS before *MESH_FACE_LIST" ); } ase.currentFace = 0; VERBOSE( ( ".....parsing MESH_NORMALS\n" ) ); ASE_ParseBracedBlock( ASE_KeyMESH_NORMALS ); } }
static void ASE_KeyMESH_NORMALS( const char *token ) { aseMesh_t *pMesh = ASE_GetCurrentMesh(); aseFace_t *f; idVec3 n; pMesh->normalsParsed = true; f = &pMesh->faces[ase.currentFace]; if( !strcmp( token, "*MESH_FACENORMAL" ) ) { int num; ASE_GetToken( false ); num = atoi( ase.token ); if( num >= pMesh->numFaces || num < 0 ) { common->Error( "MESH_NORMALS face index out of range: %i", num ); } if( num != ase.currentFace ) { common->Error( "MESH_NORMALS face index != currentFace" ); } ASE_GetToken( false ); n[0] = atof( ase.token ); ASE_GetToken( false ); n[1] = atof( ase.token ); ASE_GetToken( false ); n[2] = atof( ase.token ); f->faceNormal[0] = n[0] * pMesh->transform[0][0] + n[1] * pMesh->transform[1][0] + n[2] * pMesh->transform[2][0]; f->faceNormal[1] = n[0] * pMesh->transform[0][1] + n[1] * pMesh->transform[1][1] + n[2] * pMesh->transform[2][1]; f->faceNormal[2] = n[0] * pMesh->transform[0][2] + n[1] * pMesh->transform[1][2] + n[2] * pMesh->transform[2][2]; f->faceNormal.Normalize(); ase.currentFace++; } else if( !strcmp( token, "*MESH_VERTEXNORMAL" ) ) { int num; int v; ASE_GetToken( false ); num = atoi( ase.token ); if( num >= pMesh->numVertexes || num < 0 ) { common->Error( "MESH_NORMALS vertex index out of range: %i", num ); } f = &pMesh->faces[ase.currentFace - 1]; for( v = 0; v < 3; v++ ) { if( num == f->vertexNum[v] ) { break; } } if( v == 3 ) { common->Error( "MESH_NORMALS vertex index doesn't match face" ); } ASE_GetToken( false ); n[0] = atof( ase.token ); ASE_GetToken( false ); n[1] = atof( ase.token ); ASE_GetToken( false ); n[2] = atof( ase.token ); f->vertexNormals[v][0] = n[0] * pMesh->transform[0][0] + n[1] * pMesh->transform[1][0] + n[2] * pMesh->transform[2][0]; f->vertexNormals[v][1] = n[0] * pMesh->transform[0][1] + n[1] * pMesh->transform[1][1] + n[2] * pMesh->transform[2][1]; f->vertexNormals[v][2] = n[0] * pMesh->transform[0][2] + n[1] * pMesh->transform[1][2] + n[2] * pMesh->transform[2][2]; f->vertexNormals[v].Normalize(); } }
static void ASE_KeyMESH( const char *token ) { aseMesh_t *pMesh = ASE_GetCurrentMesh(); if ( !strcmp( token, "*TIMEVALUE" ) ) { ASE_GetToken( qfalse ); pMesh->timeValue = atoi( s_token ); VERBOSE( ( ".....timevalue: %d\n", pMesh->timeValue ) ); } else if ( !strcmp( token, "*MESH_NUMVERTEX" ) ) { ASE_GetToken( qfalse ); pMesh->numVertexes = atoi( s_token ); VERBOSE( ( ".....TIMEVALUE: %d\n", pMesh->timeValue ) ); VERBOSE( ( ".....num vertexes: %d\n", pMesh->numVertexes ) ); } else if ( !strcmp( token, "*MESH_NUMFACES" ) ) { ASE_GetToken( qfalse ); pMesh->numFaces = atoi( s_token ); VERBOSE( ( ".....num faces: %d\n", pMesh->numFaces ) ); } else if ( !strcmp( token, "*MESH_NUMTVFACES" ) ) { ASE_GetToken( qfalse ); if ( atoi( s_token ) != pMesh->numFaces ) { Error( "MESH_NUMTVFACES != MESH_NUMFACES" ); } } else if ( !strcmp( token, "*MESH_NUMTVERTEX" ) ) { ASE_GetToken( qfalse ); pMesh->numTVertexes = atoi( s_token ); VERBOSE( ( ".....num tvertexes: %d\n", pMesh->numTVertexes ) ); } else if ( !strcmp( token, "*MESH_VERTEX_LIST" ) ) { pMesh->vertexes = calloc( sizeof( aseVertex_t ) * pMesh->numVertexes, 1 ); pMesh->currentVertex = 0; VERBOSE( ( ".....parsing MESH_VERTEX_LIST\n" ) ); ASE_ParseBracedBlock( ASE_KeyMESH_VERTEX_LIST ); } else if ( !strcmp( token, "*MESH_TVERTLIST" ) ) { pMesh->currentVertex = 0; pMesh->tvertexes = calloc( sizeof( aseTVertex_t ) * pMesh->numTVertexes, 1 ); VERBOSE( ( ".....parsing MESH_TVERTLIST\n" ) ); ASE_ParseBracedBlock( ASE_KeyMESH_TVERTLIST ); } else if ( !strcmp( token, "*MESH_FACE_LIST" ) ) { pMesh->faces = calloc( sizeof( aseFace_t ) * pMesh->numFaces, 1 ); pMesh->currentFace = 0; VERBOSE( ( ".....parsing MESH_FACE_LIST\n" ) ); ASE_ParseBracedBlock( ASE_KeyMESH_FACE_LIST ); } else if ( !strcmp( token, "*MESH_TFACELIST" ) ) { pMesh->tfaces = calloc( sizeof( aseFace_t ) * pMesh->numFaces, 1 ); pMesh->currentFace = 0; VERBOSE( ( ".....parsing MESH_TFACE_LIST\n" ) ); ASE_ParseBracedBlock( ASE_KeyTFACE_LIST ); } else if ( !strcmp( token, "*MESH_NORMALS" ) ) { ASE_ParseBracedBlock( 0 ); } }