29 #include "../idlib/precompiled.h"
46 #define VERBOSE( x ) { if ( ase.verbose ) { common->Printf x ; } }
68 static aseMesh_t *ASE_GetCurrentMesh(
void )
73 static int CharIsTokenDelimiter(
int ch )
80 static int ASE_GetToken(
bool restOfLine )
104 if ( ( CharIsTokenDelimiter( ase.
token[i-1] ) && !restOfLine ) ||
105 ( ( ase.
token[i-1] ==
'\n' ) || ( ase.
token[i-1] ==
'\r' ) ) )
117 static void ASE_ParseBracedBlock(
void (*parser)(
const char *token ) )
121 while ( ASE_GetToken(
false ) )
132 else if ( indent < 0 )
143 static void ASE_SkipEnclosingBraces(
void )
147 while ( ASE_GetToken(
false ) )
158 else if ( indent < 0 )
164 static void ASE_SkipRestOfLine(
void )
166 ASE_GetToken(
true );
169 static void ASE_KeyMAP_DIFFUSE(
const char *token )
173 if ( !
strcmp( token,
"*BITMAP" ) )
178 ASE_GetToken(
false );
181 char *
s = strstr( ase.
token + 1,
"\"" );
185 matname = ase.
token + 1;
192 else if ( !
strcmp( token,
"*UVW_U_OFFSET" ) )
195 ASE_GetToken(
false );
198 else if ( !
strcmp( token,
"*UVW_V_OFFSET" ) )
201 ASE_GetToken(
false );
204 else if ( !
strcmp( token,
"*UVW_U_TILING" ) )
207 ASE_GetToken(
false );
210 else if ( !
strcmp( token,
"*UVW_V_TILING" ) )
213 ASE_GetToken(
false );
216 else if ( !
strcmp( token,
"*UVW_ANGLE" ) )
219 ASE_GetToken(
false );
227 static void ASE_KeyMATERIAL(
const char *token )
229 if ( !
strcmp( token,
"*MAP_DIFFUSE" ) )
231 ASE_ParseBracedBlock( ASE_KeyMAP_DIFFUSE );
238 static void ASE_KeyMATERIAL_LIST(
const char *token )
240 if ( !
strcmp( token,
"*MATERIAL_COUNT" ) )
242 ASE_GetToken(
false );
245 else if ( !
strcmp( token,
"*MATERIAL" ) )
255 ASE_ParseBracedBlock( ASE_KeyMATERIAL );
259 static void ASE_KeyNODE_TM(
const char *token )
263 if ( !
strcmp( token,
"*TM_ROW0" ) ) {
264 for ( i = 0 ; i < 3 ; i++ ) {
265 ASE_GetToken(
false );
268 }
else if ( !
strcmp( token,
"*TM_ROW1" ) ) {
269 for ( i = 0 ; i < 3 ; i++ ) {
270 ASE_GetToken(
false );
273 }
else if ( !
strcmp( token,
"*TM_ROW2" ) ) {
274 for ( i = 0 ; i < 3 ; i++ ) {
275 ASE_GetToken(
false );
278 }
else if ( !
strcmp( token,
"*TM_ROW3" ) ) {
279 for ( i = 0 ; i < 3 ; i++ ) {
280 ASE_GetToken(
false );
286 static void ASE_KeyMESH_VERTEX_LIST(
const char *token )
290 if ( !
strcmp( token,
"*MESH_VERTEX" ) )
292 ASE_GetToken(
false );
294 ASE_GetToken(
false );
297 ASE_GetToken(
false );
300 ASE_GetToken(
false );
307 common->
Error(
"ase.currentVertex >= pMesh->numVertexes" );
312 common->
Error(
"Unknown token '%s' while parsing MESH_VERTEX_LIST", token );
316 static void ASE_KeyMESH_FACE_LIST(
const char *token )
320 if ( !
strcmp( token,
"*MESH_FACE" ) )
322 ASE_GetToken(
false );
326 ASE_GetToken(
false );
327 ASE_GetToken(
false );
330 ASE_GetToken(
false );
331 ASE_GetToken(
false );
334 ASE_GetToken(
false );
335 ASE_GetToken(
false );
338 ASE_GetToken(
true );
357 common->
Error(
"Unknown token '%s' while parsing MESH_FACE_LIST", token );
361 static void ASE_KeyTFACE_LIST(
const char *token )
365 if ( !
strcmp( token,
"*MESH_TFACE" ) )
369 ASE_GetToken(
false );
371 ASE_GetToken(
false );
372 a = atoi( ase.
token );
373 ASE_GetToken(
false );
374 c = atoi( ase.
token );
375 ASE_GetToken(
false );
376 b = atoi( ase.
token );
386 common->
Error(
"Unknown token '%s' in MESH_TFACE", token );
390 static void ASE_KeyCFACE_LIST(
const char *token )
394 if ( !
strcmp( token,
"*MESH_CFACE" ) )
396 ASE_GetToken(
false );
398 for (
int i = 0 ; i < 3 ; i++ ) {
399 ASE_GetToken(
false );
400 int a = atoi( ase.
token );
403 static int remap[3] = { 0, 2, 1 };
413 common->
Error(
"Unknown token '%s' in MESH_CFACE", token );
417 static void ASE_KeyMESH_TVERTLIST(
const char *token )
421 if ( !
strcmp( token,
"*MESH_TVERT" ) )
423 char u[80],
v[80],
w[80];
425 ASE_GetToken(
false );
427 ASE_GetToken(
false );
428 strcpy( u, ase.
token );
430 ASE_GetToken(
false );
431 strcpy( v, ase.
token );
433 ASE_GetToken(
false );
434 strcpy( w, ase.
token );
444 common->
Error(
"ase.currentVertex > pMesh->numTVertexes" );
449 common->
Error(
"Unknown token '%s' while parsing MESH_TVERTLIST", token );
453 static void ASE_KeyMESH_CVERTLIST(
const char *token )
459 if ( !
strcmp( token,
"*MESH_VERTCOL" ) )
461 ASE_GetToken(
false );
463 ASE_GetToken(
false );
466 ASE_GetToken(
false );
469 ASE_GetToken(
false );
476 common->
Error(
"ase.currentVertex > pMesh->numCVertexes" );
480 common->
Error(
"Unknown token '%s' while parsing MESH_CVERTLIST", token );
484 static void ASE_KeyMESH_NORMALS(
const char *token )
493 if ( !
strcmp( token,
"*MESH_FACENORMAL" ) )
497 ASE_GetToken(
false );
498 num = atoi( ase.
token );
500 if ( num >= pMesh->
numFaces || num < 0 ) {
501 common->
Error(
"MESH_NORMALS face index out of range: %i", num );
505 common->
Error(
"MESH_NORMALS face index != currentFace" );
508 ASE_GetToken(
false );
509 n[0] = atof( ase.
token );
510 ASE_GetToken(
false );
511 n[1] = atof( ase.
token );
512 ASE_GetToken(
false );
513 n[2]= atof( ase.
token );
523 else if ( !
strcmp( token,
"*MESH_VERTEXNORMAL" ) )
528 ASE_GetToken(
false );
529 num = atoi( ase.
token );
532 common->
Error(
"MESH_NORMALS vertex index out of range: %i", num );
537 for ( v = 0 ; v < 3 ; v++ ) {
544 common->
Error(
"MESH_NORMALS vertex index doesn't match face" );
547 ASE_GetToken(
false );
548 n[0] = atof( ase.
token );
549 ASE_GetToken(
false );
550 n[1] = atof( ase.
token );
551 ASE_GetToken(
false );
552 n[2]= atof( ase.
token );
562 static void ASE_KeyMESH(
const char *token )
566 if ( !
strcmp( token,
"*TIMEVALUE" ) )
568 ASE_GetToken(
false );
573 else if ( !
strcmp( token,
"*MESH_NUMVERTEX" ) )
575 ASE_GetToken(
false );
580 else if ( !
strcmp( token,
"*MESH_NUMTVERTEX" ) )
582 ASE_GetToken(
false );
587 else if ( !
strcmp( token,
"*MESH_NUMCVERTEX" ) )
589 ASE_GetToken(
false );
594 else if ( !
strcmp( token,
"*MESH_NUMFACES" ) )
596 ASE_GetToken(
false );
601 else if ( !
strcmp( token,
"*MESH_NUMTVFACES" ) )
603 ASE_GetToken(
false );
610 common->
Error(
"MESH_NUMTVFACES != MESH_NUMFACES" );
613 else if ( !
strcmp( token,
"*MESH_NUMCVFACES" ) )
615 ASE_GetToken(
false );
622 common->
Error(
"MESH_NUMCVFACES != MESH_NUMFACES" );
625 else if ( !
strcmp( token,
"*MESH_VERTEX_LIST" ) )
629 VERBOSE( (
".....parsing MESH_VERTEX_LIST\n" ) );
630 ASE_ParseBracedBlock( ASE_KeyMESH_VERTEX_LIST );
632 else if ( !
strcmp( token,
"*MESH_TVERTLIST" ) )
636 VERBOSE( (
".....parsing MESH_TVERTLIST\n" ) );
637 ASE_ParseBracedBlock( ASE_KeyMESH_TVERTLIST );
639 else if ( !
strcmp( token,
"*MESH_CVERTLIST" ) )
643 VERBOSE( (
".....parsing MESH_CVERTLIST\n" ) );
644 ASE_ParseBracedBlock( ASE_KeyMESH_CVERTLIST );
646 else if ( !
strcmp( token,
"*MESH_FACE_LIST" ) )
650 VERBOSE( (
".....parsing MESH_FACE_LIST\n" ) );
651 ASE_ParseBracedBlock( ASE_KeyMESH_FACE_LIST );
653 else if ( !
strcmp( token,
"*MESH_TFACELIST" ) )
655 if ( !pMesh->
faces ) {
656 common->
Error(
"*MESH_TFACELIST before *MESH_FACE_LIST" );
659 VERBOSE( (
".....parsing MESH_TFACE_LIST\n" ) );
660 ASE_ParseBracedBlock( ASE_KeyTFACE_LIST );
662 else if ( !
strcmp( token,
"*MESH_CFACELIST" ) )
664 if ( !pMesh->
faces ) {
665 common->
Error(
"*MESH_CFACELIST before *MESH_FACE_LIST" );
668 VERBOSE( (
".....parsing MESH_CFACE_LIST\n" ) );
669 ASE_ParseBracedBlock( ASE_KeyCFACE_LIST );
671 else if ( !
strcmp( token,
"*MESH_NORMALS" ) )
673 if ( !pMesh->
faces ) {
677 VERBOSE( (
".....parsing MESH_NORMALS\n" ) );
678 ASE_ParseBracedBlock( ASE_KeyMESH_NORMALS );
682 static void ASE_KeyMESH_ANIMATION(
const char *token )
687 if ( !
strcmp( token,
"*MESH" ) )
689 VERBOSE( (
"...found MESH\n" ) );
697 ASE_ParseBracedBlock( ASE_KeyMESH );
701 common->
Error(
"Unknown token '%s' while parsing MESH_ANIMATION", token );
705 static void ASE_KeyGEOMOBJECT(
const char *token )
711 if ( !
strcmp( token,
"*NODE_NAME" ) )
713 ASE_GetToken(
true );
717 else if ( !
strcmp( token,
"*NODE_PARENT" ) )
719 ASE_SkipRestOfLine();
722 else if ( !
strcmp( token,
"*NODE_TM" ) ||
723 !
strcmp( token,
"*TM_ANIMATION" ) )
725 ASE_ParseBracedBlock( ASE_KeyNODE_TM );
728 else if ( !
strcmp( token,
"*MESH" ) )
733 ASE_ParseBracedBlock( ASE_KeyMESH );
736 else if ( !
strcmp( token,
"*MATERIAL_REF" ) )
738 ASE_GetToken(
false );
740 object->materialRef = atoi( ase.
token );
743 else if ( !
strcmp( token,
"*MESH_ANIMATION" ) )
745 VERBOSE( (
"..found MESH_ANIMATION\n" ) );
747 ASE_ParseBracedBlock( ASE_KeyMESH_ANIMATION );
750 else if ( !
strcmp( token,
"*PROP_MOTIONBLUR" ) ||
751 !
strcmp( token,
"*PROP_CASTSHADOW" ) ||
752 !
strcmp( token,
"*PROP_RECVSHADOW" ) )
754 ASE_SkipRestOfLine();
771 ASE_ParseBracedBlock( ASE_KeyGEOMOBJECT );
774 static void ASE_KeyGROUP(
const char *token )
776 if ( !
strcmp( token,
"*GEOMOBJECT" ) ) {
787 memset( &ase, 0,
sizeof( ase ) );
792 ase.
len = strlen( buffer );
802 while ( ASE_GetToken(
false ) ) {
803 if ( !
strcmp( ase.
token,
"*3DSMAX_ASCIIEXPORT" ) ||
805 ASE_SkipRestOfLine();
807 ASE_SkipEnclosingBraces();
809 ASE_GetToken(
false );
810 ASE_ParseBracedBlock( ASE_KeyGROUP );
811 }
else if ( !
strcmp( ase.
token,
"*SHAPEOBJECT" ) ) {
812 ASE_SkipEnclosingBraces();
813 }
else if ( !
strcmp( ase.
token,
"*CAMERAOBJECT" ) ) {
814 ASE_SkipEnclosingBraces();
815 }
else if ( !
strcmp( ase.
token,
"*MATERIAL_LIST" ) ) {
816 VERBOSE( (
"MATERIAL_LIST\n") );
818 ASE_ParseBracedBlock( ASE_KeyMATERIAL_LIST );
819 }
else if ( !
strcmp( ase.
token,
"*GEOMOBJECT" ) ) {
821 }
else if ( ase.
token[0] ) {
868 for ( j = 0; j < obj->
frames.
Num(); j++ ) {
idList< aseMesh_t * > frames
virtual int ReadFile(const char *relativePath, void **buffer, ID_TIME_T *timestamp=NULL)=0
idFileSystem * fileSystem
void ASE_Free(aseModel_t *ase)
idList< aseMaterial_t * > materials
idList< aseObject_t * > objects
virtual void FreeFile(void *buffer)=0
idStr & BackSlashesToSlashes(void)
GLubyte GLubyte GLubyte GLubyte w
static void Copynz(char *dest, const char *src, int destsize)
aseObject_t * currentObject
GLubyte GLubyte GLubyte a
virtual void Printf(const char *fmt,...) id_attribute((format(printf
struct aseModel_s aseModel_t
int Append(const type &obj)
void ASE_ParseGeomObject(void)
aseMaterial_t * currentMaterial
aseModel_t * ASE_Parse(const char *buffer, bool verbose)
void * Mem_Alloc(const int size)
virtual const char * OSPathToRelativePath(const char *OSPath)=0
virtual void Error(const char *fmt,...) id_attribute((format(printf
virtual void virtual void Warning(const char *fmt,...) id_attribute((format(printf
aseModel_t * ASE_Load(const char *fileName)