picomodel: support OBJs without material groups
git-svn-id: svn://svn.icculus.org/netradiant/trunk@219 61c419a2-8eb2-4b30-bcec-8cead039b335
This commit is contained in:
parent
1d2068f2f1
commit
be63f42ed5
|
|
@ -500,8 +500,33 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD )
|
||||||
int curVertex = 0;
|
int curVertex = 0;
|
||||||
int curFace = 0;
|
int curFace = 0;
|
||||||
|
|
||||||
|
int autoGroupNumber = 0;
|
||||||
|
char autoGroupNameBuf[64];
|
||||||
|
|
||||||
|
#define AUTO_GROUPNAME(namebuf) \
|
||||||
|
sprintf(namebuf, "__autogroup_%d", autoGroupNumber++)
|
||||||
|
#define NEW_SURFACE(name) \
|
||||||
|
{ \
|
||||||
|
picoSurface_t *newSurface; \
|
||||||
|
/* allocate a pico surface */ \
|
||||||
|
newSurface = PicoNewSurface( model ); \
|
||||||
|
if (newSurface == NULL) \
|
||||||
|
_obj_error_return("Error allocating surface"); \
|
||||||
|
/* reset face index for surface */ \
|
||||||
|
curFace = 0; \
|
||||||
|
/* if we can, assign the previous shader to this surface */ \
|
||||||
|
if(curSurface) \
|
||||||
|
PicoSetSurfaceShader(newSurface, curSurface->shader); \
|
||||||
|
/* set ptr to current surface */ \
|
||||||
|
curSurface = newSurface; \
|
||||||
|
/* we use triangle meshes */ \
|
||||||
|
PicoSetSurfaceType( newSurface,PICO_TRIANGLES ); \
|
||||||
|
/* set surface name */ \
|
||||||
|
PicoSetSurfaceName( newSurface,name ); \
|
||||||
|
}
|
||||||
|
|
||||||
/* helper */
|
/* helper */
|
||||||
#define _obj_error_return(m) \
|
#define _obj_error_return(m) \
|
||||||
{ \
|
{ \
|
||||||
_pico_printf( PICO_ERROR,"%s in OBJ, line %d.",m,p->curLine); \
|
_pico_printf( PICO_ERROR,"%s in OBJ, line %d.",m,p->curLine); \
|
||||||
_pico_free_parser( p ); \
|
_pico_free_parser( p ); \
|
||||||
|
|
@ -616,7 +641,6 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD )
|
||||||
/* new group (for us this means a new surface) */
|
/* new group (for us this means a new surface) */
|
||||||
else if (!_pico_stricmp(p->token,"g"))
|
else if (!_pico_stricmp(p->token,"g"))
|
||||||
{
|
{
|
||||||
picoSurface_t *newSurface;
|
|
||||||
char *groupName;
|
char *groupName;
|
||||||
|
|
||||||
/* get first group name (ignore 2nd,3rd,etc.) */
|
/* get first group name (ignore 2nd,3rd,etc.) */
|
||||||
|
|
@ -632,22 +656,15 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD )
|
||||||
_obj_error_return("Invalid or missing group name");
|
_obj_error_return("Invalid or missing group name");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
/* allocate a pico surface */
|
|
||||||
newSurface = PicoNewSurface( model );
|
|
||||||
if (newSurface == NULL)
|
|
||||||
_obj_error_return("Error allocating surface");
|
|
||||||
|
|
||||||
/* reset face index for surface */
|
if(curFace == 0)
|
||||||
curFace = 0;
|
{
|
||||||
|
PicoSetSurfaceName( curSurface,groupName );
|
||||||
/* set ptr to current surface */
|
}
|
||||||
curSurface = newSurface;
|
else
|
||||||
|
{
|
||||||
/* we use triangle meshes */
|
NEW_SURFACE(groupName);
|
||||||
PicoSetSurfaceType( newSurface,PICO_TRIANGLES );
|
}
|
||||||
|
|
||||||
/* set surface name */
|
|
||||||
PicoSetSurfaceName( newSurface,groupName );
|
|
||||||
|
|
||||||
#ifdef DEBUG_PM_OBJ_EX
|
#ifdef DEBUG_PM_OBJ_EX
|
||||||
printf("Group: '%s'\n",groupName);
|
printf("Group: '%s'\n",groupName);
|
||||||
|
|
@ -675,6 +692,13 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD )
|
||||||
int doubleslash;
|
int doubleslash;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if(curSurface == NULL)
|
||||||
|
{
|
||||||
|
_pico_printf( PICO_ERROR,"No group defined for faces, so creating an autoSurface in OBJ, line %d.",p->curLine);
|
||||||
|
AUTO_GROUPNAME(autoGroupNameBuf);
|
||||||
|
NEW_SURFACE(autoGroupNameBuf);
|
||||||
|
}
|
||||||
|
|
||||||
/* group defs *must* come before faces */
|
/* group defs *must* come before faces */
|
||||||
if (curSurface == NULL)
|
if (curSurface == NULL)
|
||||||
_obj_error_return("No group defined for faces");
|
_obj_error_return("No group defined for faces");
|
||||||
|
|
@ -843,6 +867,13 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD )
|
||||||
/* get material name */
|
/* get material name */
|
||||||
name = _pico_parse( p,0 );
|
name = _pico_parse( p,0 );
|
||||||
|
|
||||||
|
if(curFace != 0 || curSurface == NULL)
|
||||||
|
{
|
||||||
|
_pico_printf( PICO_ERROR,"No group defined for usemtl, so creating an autoSurface in OBJ, line %d.",p->curLine);
|
||||||
|
AUTO_GROUPNAME(autoGroupNameBuf);
|
||||||
|
NEW_SURFACE(autoGroupNameBuf);
|
||||||
|
}
|
||||||
|
|
||||||
/* validate material name */
|
/* validate material name */
|
||||||
if (name == NULL || !strlen(name))
|
if (name == NULL || !strlen(name))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user