2007-11-04 03:34:51 +00:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
PicoModel Library
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (c) 2002, Randy Reddig & seaw0lf
|
|
|
|
All rights reserved.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other aseMaterialList provided with the distribution.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Neither the names of the copyright holders nor the names of its contributors may
|
|
|
|
be used to endorse or promote products derived from this software without
|
|
|
|
specific prior written permission.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
----------------------------------------------------------------------------- */
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* marker */
|
|
|
|
#define PM_ASE_C
|
|
|
|
|
|
|
|
/* uncomment when debugging this module */
|
2008-06-26 11:21:13 +00:00
|
|
|
//#define DEBUG_PM_ASE
|
2007-11-04 03:34:51 +00:00
|
|
|
//#define DEBUG_PM_ASE_EX
|
|
|
|
|
|
|
|
|
|
|
|
/* dependencies */
|
|
|
|
#include "picointernal.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG_PM_ASE
|
|
|
|
#include "time.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* plain white */
|
|
|
|
static picoColor_t white = { 255, 255, 255, 255 };
|
|
|
|
|
|
|
|
/* jhefty - multi-subobject material support */
|
|
|
|
|
|
|
|
/* Material/SubMaterial management */
|
|
|
|
/* A material should have 1..n submaterials assigned to it */
|
|
|
|
|
|
|
|
typedef struct aseSubMaterial_s
|
|
|
|
{
|
|
|
|
struct aseSubMaterial_s* next;
|
|
|
|
int subMtlId;
|
|
|
|
picoShader_t* shader;
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
} aseSubMaterial_t;
|
|
|
|
|
|
|
|
typedef struct aseMaterial_s
|
|
|
|
{
|
|
|
|
struct aseMaterial_s* next;
|
|
|
|
struct aseSubMaterial_s* subMtls;
|
2008-06-26 11:21:13 +00:00
|
|
|
int mtlId;
|
2007-11-04 03:34:51 +00:00
|
|
|
} aseMaterial_t;
|
|
|
|
|
|
|
|
/* Material/SubMaterial management functions */
|
2012-03-17 20:01:54 +00:00
|
|
|
static aseMaterial_t* _ase_get_material( aseMaterial_t* list, int mtlIdParent ){
|
2007-11-04 03:34:51 +00:00
|
|
|
aseMaterial_t* mtl = list;
|
|
|
|
|
|
|
|
while ( mtl )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( mtlIdParent == mtl->mtlId ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
mtl = mtl->next;
|
|
|
|
}
|
|
|
|
return mtl;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static aseSubMaterial_t* _ase_get_submaterial( aseMaterial_t* list, int mtlIdParent, int subMtlId ){
|
|
|
|
aseMaterial_t* parent = _ase_get_material( list, mtlIdParent );
|
2007-11-04 03:34:51 +00:00
|
|
|
aseSubMaterial_t* subMtl = NULL;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !parent ) {
|
|
|
|
_pico_printf( PICO_ERROR, "No ASE material exists with id %i\n", mtlIdParent );
|
2007-11-04 03:34:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
subMtl = parent->subMtls;
|
|
|
|
while ( subMtl )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( subMtlId == subMtl->subMtlId ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
subMtl = subMtl->next;
|
|
|
|
}
|
|
|
|
return subMtl;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static aseMaterial_t* _ase_add_material( aseMaterial_t **list, int mtlIdParent ){
|
2007-11-04 03:34:51 +00:00
|
|
|
aseMaterial_t *mtl = _pico_calloc( 1, sizeof( aseMaterial_t ) );
|
|
|
|
mtl->mtlId = mtlIdParent;
|
|
|
|
mtl->subMtls = NULL;
|
|
|
|
mtl->next = *list;
|
|
|
|
*list = mtl;
|
|
|
|
|
|
|
|
return mtl;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static aseSubMaterial_t* _ase_add_submaterial( aseMaterial_t **list, int mtlIdParent, int subMtlId, picoShader_t* shader ){
|
2007-11-04 03:34:51 +00:00
|
|
|
aseMaterial_t *parent = _ase_get_material( *list, mtlIdParent );
|
2012-03-17 20:01:54 +00:00
|
|
|
aseSubMaterial_t *subMtl = _pico_calloc( 1, sizeof( aseSubMaterial_t ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !parent ) {
|
|
|
|
parent = _ase_add_material( list, mtlIdParent );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
subMtl->shader = shader;
|
|
|
|
subMtl->subMtlId = subMtlId;
|
|
|
|
subMtl->next = parent->subMtls;
|
|
|
|
parent->subMtls = subMtl;
|
|
|
|
|
|
|
|
return subMtl;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void _ase_free_materials( aseMaterial_t **list ){
|
2007-11-04 03:34:51 +00:00
|
|
|
aseMaterial_t* mtl = *list;
|
|
|
|
aseSubMaterial_t* subMtl = NULL;
|
|
|
|
|
|
|
|
aseMaterial_t* mtlTemp = NULL;
|
|
|
|
aseSubMaterial_t* subMtlTemp = NULL;
|
|
|
|
|
|
|
|
while ( mtl )
|
|
|
|
{
|
|
|
|
subMtl = mtl->subMtls;
|
|
|
|
while ( subMtl )
|
|
|
|
{
|
|
|
|
subMtlTemp = subMtl->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
_pico_free( subMtl );
|
2007-11-04 03:34:51 +00:00
|
|
|
subMtl = subMtlTemp;
|
|
|
|
}
|
|
|
|
mtlTemp = mtl->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
_pico_free( mtl );
|
2007-11-04 03:34:51 +00:00
|
|
|
mtl = mtlTemp;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
( *list ) = NULL;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_PM_ASE
|
2012-03-17 20:01:54 +00:00
|
|
|
static void _ase_print_materials( aseMaterial_t *list ){
|
2007-11-04 03:34:51 +00:00
|
|
|
aseMaterial_t* mtl = list;
|
|
|
|
aseSubMaterial_t* subMtl = NULL;
|
|
|
|
|
|
|
|
while ( mtl )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
_pico_printf( PICO_NORMAL, "ASE Material %i", mtl->mtlId );
|
2007-11-04 03:34:51 +00:00
|
|
|
subMtl = mtl->subMtls;
|
|
|
|
while ( subMtl )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
_pico_printf( PICO_NORMAL, " -- ASE SubMaterial %i - %s\n", subMtl->subMtlId, subMtl->shader->name );
|
2007-11-04 03:34:51 +00:00
|
|
|
subMtl = subMtl->next;
|
|
|
|
}
|
|
|
|
mtl = mtl->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif //DEBUG_PM_ASE
|
|
|
|
|
|
|
|
/* ASE Face management */
|
|
|
|
/* These are used to keep an association between a submaterial and a face definition */
|
|
|
|
/* They are kept in parallel with the current picoSurface, */
|
|
|
|
/* and are used by _ase_submit_triangles to lookup the proper material/submaterial IDs */
|
|
|
|
typedef struct aseFace_s
|
|
|
|
{
|
|
|
|
struct aseFace_s* next;
|
|
|
|
int mtlId;
|
|
|
|
int subMtlId;
|
|
|
|
int index[9];
|
|
|
|
} aseFace_t;
|
|
|
|
|
|
|
|
/* ASE Face management functions */
|
2012-03-17 20:01:54 +00:00
|
|
|
void _ase_add_face( aseFace_t **list, aseFace_t **tail, aseFace_t *newFace ){
|
2007-11-04 03:34:51 +00:00
|
|
|
/* insert as head of list */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !( *list ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*list = newFace;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
( *tail )->next = newFace;
|
2008-06-26 11:21:13 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
*tail = newFace;
|
|
|
|
newFace->next = NULL;
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
//tag the color indices so we can detect them and apply the default color to them
|
|
|
|
newFace->index[6] = -1;
|
|
|
|
newFace->index[7] = -1;
|
|
|
|
newFace->index[8] = -1;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
aseFace_t* _ase_get_face_for_index( aseFace_t *list, int index ){
|
2007-11-04 03:34:51 +00:00
|
|
|
int counter = 0;
|
|
|
|
aseFace_t* face = list;
|
|
|
|
|
|
|
|
while ( counter < index )
|
|
|
|
{
|
|
|
|
face = face->next;
|
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
return face;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
static void _ase_free_faces( aseFace_t** list, aseFace_t** tail ){
|
2007-11-04 03:34:51 +00:00
|
|
|
aseFace_t* face = *list;
|
|
|
|
aseFace_t* tempFace = NULL;
|
|
|
|
|
|
|
|
while ( face )
|
|
|
|
{
|
|
|
|
tempFace = face->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
_pico_free( face );
|
2007-11-04 03:34:51 +00:00
|
|
|
face = tempFace;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
( *list ) = NULL;
|
|
|
|
( *tail ) = NULL;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* todo:
|
|
|
|
* - apply material specific uv offsets to uv coordinates
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* _ase_canload:
|
|
|
|
* validates a 3dsmax ase model file.
|
|
|
|
*/
|
2012-03-17 20:01:54 +00:00
|
|
|
static int _ase_canload( PM_PARAMS_CANLOAD ){
|
2007-11-04 03:34:51 +00:00
|
|
|
picoParser_t *p;
|
2008-06-26 11:21:13 +00:00
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* quick data length validation */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bufSize < 80 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return PICO_PMV_ERROR_SIZE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* keep the friggin compiler happy */
|
|
|
|
*fileName = *fileName;
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* create pico parser */
|
|
|
|
p = _pico_new_parser( (picoByte_t*) buffer, bufSize );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return PICO_PMV_ERROR_MEMORY;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get first token */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( _pico_parse_first( p ) == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return PICO_PMV_ERROR_IDENT;
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* check first token */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( _pico_stricmp( p->token, "*3dsmax_asciiexport" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
_pico_free_parser( p );
|
|
|
|
return PICO_PMV_ERROR_IDENT;
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* free the pico parser object */
|
|
|
|
_pico_free_parser( p );
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* file seems to be a valid ase file */
|
|
|
|
return PICO_PMV_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* _ase_submit_triangles - jhefty
|
2012-03-17 20:01:54 +00:00
|
|
|
use the surface and the current face list to look up material/submaterial IDs
|
|
|
|
and submit them to the model for proper processing
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
The following still holds from ydnar's _ase_make_surface:
|
|
|
|
indexes 0 1 2 = vert indexes
|
|
|
|
indexes 3 4 5 = st indexes
|
|
|
|
indexes 6 7 8 = color indexes (new)
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void _ase_submit_triangles( picoSurface_t* surface, picoModel_t* model, aseMaterial_t* materials, aseFace_t* faces ){
|
2007-11-04 03:34:51 +00:00
|
|
|
aseFace_t* face;
|
|
|
|
aseSubMaterial_t* subMtl;
|
|
|
|
picoVec3_t* xyz[3];
|
|
|
|
picoVec3_t* normal[3];
|
|
|
|
picoVec2_t* st[3];
|
|
|
|
picoColor_t* color[3];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
face = faces;
|
|
|
|
while ( face != NULL )
|
|
|
|
{
|
|
|
|
/* look up the shader for the material/submaterial pair */
|
|
|
|
subMtl = _ase_get_submaterial( materials, face->mtlId, face->subMtlId );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( subMtl == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: trying default submaterial */
|
|
|
|
subMtl = _ase_get_submaterial( materials, face->mtlId, 0 );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( subMtl == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
_pico_printf( PICO_ERROR, "Could not find material/submaterial for id %d/%d\n", face->mtlId, face->subMtlId );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* we pull the data from the surface using the facelist data */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 3 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
xyz[i] = (picoVec3_t*) PicoGetSurfaceXYZ( surface, face->index[ i ] );
|
2008-06-26 11:21:13 +00:00
|
|
|
normal[i] = (picoVec3_t*) PicoGetSurfaceNormal( surface, face->index[ i ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
st[i] = (picoVec2_t*) PicoGetSurfaceST( surface, 0, face->index[ i + 3 ] );
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( face->index [ i + 6] >= 0 ) {
|
|
|
|
color[i] = (picoColor_t*)PicoGetSurfaceColor( surface, 0, face->index[ i + 6 ] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
color[i] = &white;
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* submit the triangle to the model */
|
2012-03-17 20:01:54 +00:00
|
|
|
PicoAddTriangleToModel( model, xyz, normal, 1, st, 1, color, subMtl->shader );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* advance to the next face */
|
2008-06-26 11:21:13 +00:00
|
|
|
face = face->next;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* _ase_load:
|
|
|
|
* loads a 3dsmax ase model file.
|
2012-03-17 20:01:54 +00:00
|
|
|
*/
|
|
|
|
static picoModel_t *_ase_load( PM_PARAMS_LOAD ){
|
2007-11-04 03:34:51 +00:00
|
|
|
picoModel_t *model;
|
|
|
|
picoSurface_t *surface = NULL;
|
|
|
|
picoParser_t *p;
|
2012-03-17 20:01:54 +00:00
|
|
|
char lastNodeName[ 1024 ];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
aseFace_t* faces = NULL;
|
|
|
|
aseFace_t* facesTail = NULL;
|
|
|
|
aseMaterial_t* materials = NULL;
|
|
|
|
|
|
|
|
#ifdef DEBUG_PM_ASE
|
|
|
|
clock_t start, finish;
|
|
|
|
double elapsed;
|
|
|
|
start = clock();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* helper */
|
2012-03-17 20:01:54 +00:00
|
|
|
#define _ase_error_return( m ) \
|
2007-11-04 03:34:51 +00:00
|
|
|
{ \
|
2012-03-17 20:01:54 +00:00
|
|
|
_pico_printf( PICO_ERROR,"%s in ASE, line %d.",m,p->curLine ); \
|
|
|
|
_pico_free_parser( p ); \
|
|
|
|
PicoFreeModel( model ); \
|
2007-11-04 03:34:51 +00:00
|
|
|
return NULL; \
|
|
|
|
}
|
|
|
|
/* create a new pico parser */
|
|
|
|
p = _pico_new_parser( (picoByte_t *)buffer,bufSize );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p == NULL ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* create a new pico model */
|
|
|
|
model = PicoNewModel();
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( model == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
_pico_free_parser( p );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* do model setup */
|
|
|
|
PicoSetModelFrameNum( model, frameNum );
|
|
|
|
PicoSetModelName( model, fileName );
|
|
|
|
PicoSetModelFileName( model, fileName );
|
|
|
|
|
|
|
|
/* initialize some stuff */
|
2012-03-17 20:01:54 +00:00
|
|
|
memset( lastNodeName,0,sizeof( lastNodeName ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* parse ase model file */
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( 1 )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* get first token on line */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( _pico_parse_first( p ) == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* we just skip empty lines */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->token == NULL || !strlen( p->token ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* we skip invalid ase statements */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->token[0] != '*' && p->token[0] != '{' && p->token[0] != '}' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
_pico_parse_skip_rest( p );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* remember node name */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_stricmp( p->token,"*node_name" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* read node name */
|
|
|
|
char *ptr = _pico_parse( p,0 );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ptr == NULL ) {
|
|
|
|
_ase_error_return( "Node name parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* remember node name */
|
2012-03-17 20:01:54 +00:00
|
|
|
strncpy( lastNodeName,ptr,sizeof( lastNodeName ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
/* model mesh (originally contained within geomobject) */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*mesh" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* finish existing surface */
|
|
|
|
//_ase_make_surface( model, &surface );
|
2012-03-17 20:01:54 +00:00
|
|
|
_ase_submit_triangles( surface, model,materials,faces );
|
|
|
|
_ase_free_faces( &faces,&facesTail );
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* allocate new pico surface */
|
|
|
|
surface = PicoNewSurface( NULL );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surface == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
PicoFreeModel( model );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* mesh material reference. this usually comes at the end of */
|
|
|
|
/* geomobjects after the mesh blocks. we must assume that the */
|
|
|
|
/* new mesh was already created so all we can do here is assign */
|
|
|
|
/* the material reference id (shader index) now. */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*material_ref" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
int mtlId;
|
|
|
|
aseFace_t* face;
|
|
|
|
|
|
|
|
/* we must have a valid surface */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surface == NULL ) {
|
|
|
|
_ase_error_return( "Missing mesh for material reference" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get the material ref (0..n) */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&mtlId ) ) {
|
|
|
|
_ase_error_return( "Missing material reference ID" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* fix up all of the aseFaceList in the surface to point to the parent material */
|
|
|
|
/* we've already saved off their subMtl */
|
|
|
|
face = faces;
|
|
|
|
while ( face != NULL )
|
|
|
|
{
|
|
|
|
face->mtlId = mtlId;
|
|
|
|
face = face->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* model mesh vertex */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*mesh_vertex" ) ) {
|
|
|
|
picoVec3_t v;
|
|
|
|
int index;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* we must have a valid surface */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surface == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get vertex data (orig: index +y -x +z) */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&index ) ) {
|
|
|
|
_ase_error_return( "Vertex parse error" );
|
|
|
|
}
|
|
|
|
if ( !_pico_parse_vec( p,v ) ) {
|
|
|
|
_ase_error_return( "Vertex parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* set vertex */
|
|
|
|
PicoSetSurfaceXYZ( surface,index,v );
|
|
|
|
}
|
|
|
|
/* model mesh vertex normal */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*mesh_vertexnormal" ) ) {
|
|
|
|
picoVec3_t v;
|
|
|
|
int index;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* we must have a valid surface */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surface == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get vertex data (orig: index +y -x +z) */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&index ) ) {
|
|
|
|
_ase_error_return( "Vertex parse error" );
|
|
|
|
}
|
|
|
|
if ( !_pico_parse_vec( p,v ) ) {
|
|
|
|
_ase_error_return( "Vertex parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* set vertex */
|
|
|
|
PicoSetSurfaceNormal( surface,index,v );
|
|
|
|
}
|
|
|
|
/* model mesh face */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*mesh_face" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
picoIndex_t indexes[3];
|
2012-03-17 20:01:54 +00:00
|
|
|
int index;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* we must have a valid surface */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surface == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get face index */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&index ) ) {
|
|
|
|
_ase_error_return( "Face parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get 1st vertex index */
|
|
|
|
_pico_parse( p,0 );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&indexes[0] ) ) {
|
|
|
|
_ase_error_return( "Face parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get 2nd vertex index */
|
|
|
|
_pico_parse( p,0 );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&indexes[1] ) ) {
|
|
|
|
_ase_error_return( "Face parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get 3rd vertex index */
|
|
|
|
_pico_parse( p,0 );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&indexes[2] ) ) {
|
|
|
|
_ase_error_return( "Face parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* set face indexes (note interleaved offset!) */
|
2012-03-17 20:01:54 +00:00
|
|
|
PicoSetSurfaceIndex( surface, ( index * 9 + 0 ), indexes[2] );
|
|
|
|
PicoSetSurfaceIndex( surface, ( index * 9 + 1 ), indexes[1] );
|
|
|
|
PicoSetSurfaceIndex( surface, ( index * 9 + 2 ), indexes[0] );
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* parse to the subMaterial ID */
|
|
|
|
while ( 1 )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
_pico_parse( p,0 );
|
|
|
|
if ( !_pico_stricmp( p->token,"*MESH_MTLID" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
aseFace_t* newFace;
|
|
|
|
int subMtlId;
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
_pico_parse_int( p, &subMtlId );
|
|
|
|
newFace = _pico_calloc( 1, sizeof( aseFace_t ) );
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* we fix up the mtlId later when we parse the material_ref */
|
2008-06-26 11:21:13 +00:00
|
|
|
newFace->mtlId = 0;
|
2007-11-04 03:34:51 +00:00
|
|
|
newFace->subMtlId = subMtlId;
|
|
|
|
newFace->index[0] = indexes[2];
|
|
|
|
newFace->index[1] = indexes[1];
|
|
|
|
newFace->index[2] = indexes[0];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
_ase_add_face( &faces,&facesTail,newFace );
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
/* model texture vertex */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*mesh_tvert" ) ) {
|
|
|
|
picoVec2_t uv;
|
|
|
|
int index;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* we must have a valid surface */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surface == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get uv vertex index */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&index ) ) {
|
|
|
|
_ase_error_return( "UV vertex parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get uv vertex s */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_float( p,&uv[0] ) ) {
|
|
|
|
_ase_error_return( "UV vertex parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get uv vertex t */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_float( p,&uv[1] ) ) {
|
|
|
|
_ase_error_return( "UV vertex parse error" );
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: invert t */
|
|
|
|
uv[ 1 ] = 1.0f - uv[ 1 ];
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set texture vertex */
|
|
|
|
PicoSetSurfaceST( surface,0,index,uv );
|
|
|
|
}
|
|
|
|
/* ydnar: model mesh texture face */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token, "*mesh_tface" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
picoIndex_t indexes[3];
|
2012-03-17 20:01:54 +00:00
|
|
|
int index;
|
2007-11-04 03:34:51 +00:00
|
|
|
aseFace_t* face;
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* we must have a valid surface */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surface == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get face index */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&index ) ) {
|
|
|
|
_ase_error_return( "Texture face parse error" );
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get 1st vertex index */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&indexes[0] ) ) {
|
|
|
|
_ase_error_return( "Texture face parse error" );
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get 2nd vertex index */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&indexes[1] ) ) {
|
|
|
|
_ase_error_return( "Texture face parse error" );
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get 3rd vertex index */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&indexes[2] ) ) {
|
|
|
|
_ase_error_return( "Texture face parse error" );
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set face indexes (note interleaved offset!) */
|
2012-03-17 20:01:54 +00:00
|
|
|
PicoSetSurfaceIndex( surface, ( index * 9 + 3 ), indexes[2] );
|
|
|
|
PicoSetSurfaceIndex( surface, ( index * 9 + 4 ), indexes[1] );
|
|
|
|
PicoSetSurfaceIndex( surface, ( index * 9 + 5 ), indexes[0] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
face = _ase_get_face_for_index( faces,index );
|
2007-11-04 03:34:51 +00:00
|
|
|
face->index[3] = indexes[2];
|
|
|
|
face->index[4] = indexes[1];
|
|
|
|
face->index[5] = indexes[0];
|
|
|
|
}
|
|
|
|
/* model color vertex */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*mesh_vertcol" ) ) {
|
|
|
|
picoColor_t color;
|
|
|
|
int index;
|
|
|
|
float colorInput;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* we must have a valid surface */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surface == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get color vertex index */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&index ) ) {
|
|
|
|
_ase_error_return( "UV vertex parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get R component */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_float( p,&colorInput ) ) {
|
|
|
|
_ase_error_return( "color vertex parse error" );
|
|
|
|
}
|
|
|
|
color[0] = (picoByte_t)( colorInput * 255 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get G component */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_float( p,&colorInput ) ) {
|
|
|
|
_ase_error_return( "color vertex parse error" );
|
|
|
|
}
|
|
|
|
color[1] = (picoByte_t)( colorInput * 255 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get B component */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_float( p,&colorInput ) ) {
|
|
|
|
_ase_error_return( "color vertex parse error" );
|
|
|
|
}
|
|
|
|
color[2] = (picoByte_t)( colorInput * 255 );
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* leave alpha alone since we don't get any data from the ASE format */
|
|
|
|
color[3] = 255;
|
|
|
|
|
|
|
|
/* set texture vertex */
|
|
|
|
PicoSetSurfaceColor( surface,0,index,color );
|
|
|
|
}
|
|
|
|
/* model color face */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*mesh_cface" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
picoIndex_t indexes[3];
|
2012-03-17 20:01:54 +00:00
|
|
|
int index;
|
2007-11-04 03:34:51 +00:00
|
|
|
aseFace_t* face;
|
|
|
|
|
|
|
|
/* we must have a valid surface */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surface == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get face index */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&index ) ) {
|
|
|
|
_ase_error_return( "Face parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get 1st cvertex index */
|
|
|
|
// _pico_parse( p,0 );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&indexes[0] ) ) {
|
|
|
|
_ase_error_return( "Face parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get 2nd cvertex index */
|
|
|
|
// _pico_parse( p,0 );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&indexes[1] ) ) {
|
|
|
|
_ase_error_return( "Face parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get 3rd cvertex index */
|
|
|
|
// _pico_parse( p,0 );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_int( p,&indexes[2] ) ) {
|
|
|
|
_ase_error_return( "Face parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* set face indexes (note interleaved offset!) */
|
2012-03-17 20:01:54 +00:00
|
|
|
PicoSetSurfaceIndex( surface, ( index * 9 + 6 ), indexes[2] );
|
|
|
|
PicoSetSurfaceIndex( surface, ( index * 9 + 7 ), indexes[1] );
|
|
|
|
PicoSetSurfaceIndex( surface, ( index * 9 + 8 ), indexes[0] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
face = _ase_get_face_for_index( faces,index );
|
2007-11-04 03:34:51 +00:00
|
|
|
face->index[6] = indexes[2];
|
|
|
|
face->index[7] = indexes[1];
|
|
|
|
face->index[8] = indexes[0];
|
|
|
|
}
|
|
|
|
/* model material */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token, "*material" ) ) {
|
|
|
|
aseSubMaterial_t* subMaterial = NULL;
|
|
|
|
picoShader_t *shader = NULL;
|
|
|
|
int level = 1, index;
|
|
|
|
char materialName[ 1024 ];
|
|
|
|
float transValue = 0.0f, shineValue = 1.0f;
|
|
|
|
picoColor_t ambientColor, diffuseColor, specularColor;
|
|
|
|
char *mapname = NULL;
|
|
|
|
int subMtlId, subMaterialLevel = -1;
|
2008-06-26 11:21:13 +00:00
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get material index */
|
|
|
|
_pico_parse_int( p,&index );
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* check brace */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_check( p,1,"{" ) ) {
|
|
|
|
_ase_error_return( "Material missing opening brace" );
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* parse material block */
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( 1 )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* get next token */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( _pico_parse( p,1 ) == NULL ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( !strlen( p->token ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* handle levels */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->token[0] == '{' ) {
|
|
|
|
level++;
|
|
|
|
}
|
|
|
|
if ( p->token[0] == '}' ) {
|
|
|
|
level--;
|
|
|
|
}
|
|
|
|
if ( !level ) {
|
|
|
|
break;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( level == subMaterialLevel ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set material name */
|
2012-03-17 20:01:54 +00:00
|
|
|
PicoSetShaderName( shader, materialName );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* set shader's transparency */
|
|
|
|
PicoSetShaderTransparency( shader,transValue );
|
|
|
|
|
|
|
|
/* set shader's ambient color */
|
|
|
|
PicoSetShaderAmbientColor( shader,ambientColor );
|
|
|
|
|
|
|
|
/* set diffuse alpha to transparency */
|
|
|
|
diffuseColor[3] = (picoByte_t)( transValue * 255.0 );
|
|
|
|
|
|
|
|
/* set shader's diffuse color */
|
|
|
|
PicoSetShaderDiffuseColor( shader,diffuseColor );
|
|
|
|
|
|
|
|
/* set shader's specular color */
|
|
|
|
PicoSetShaderSpecularColor( shader,specularColor );
|
|
|
|
|
|
|
|
/* set shader's shininess */
|
|
|
|
PicoSetShaderShininess( shader,shineValue );
|
|
|
|
|
|
|
|
/* set material map name */
|
|
|
|
PicoSetShaderMapName( shader, mapname );
|
|
|
|
|
|
|
|
subMaterial = _ase_add_submaterial( &materials, index, subMtlId, shader );
|
|
|
|
subMaterialLevel = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse submaterial index */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_stricmp( p->token,"*submaterial" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* allocate new pico shader */
|
2012-03-17 20:01:54 +00:00
|
|
|
_pico_parse_int( p, &subMtlId );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
shader = PicoNewShader( model );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( shader == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
PicoFreeModel( model );
|
|
|
|
return NULL;
|
2008-06-26 11:21:13 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
subMaterialLevel = level;
|
|
|
|
}
|
|
|
|
/* parse material name */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*material_name" ) ) {
|
|
|
|
char* name = _pico_parse( p,0 );
|
|
|
|
if ( name == NULL ) {
|
|
|
|
_ase_error_return( "Missing material name" );
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strcpy( materialName, name );
|
2007-11-04 03:34:51 +00:00
|
|
|
/* skip rest and continue with next token */
|
|
|
|
_pico_parse_skip_rest( p );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* parse material transparency */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*material_transparency" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get transparency value from ase */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_float( p,&transValue ) ) {
|
|
|
|
_ase_error_return( "Material transparency parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* skip rest and continue with next token */
|
|
|
|
_pico_parse_skip_rest( p );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* parse material shininess */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*material_shine" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* remark:
|
|
|
|
* - not sure but instead of '*material_shine' i might
|
|
|
|
* need to use '*material_shinestrength' */
|
|
|
|
|
|
|
|
/* get shine value from ase */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_float( p,&shineValue ) ) {
|
|
|
|
_ase_error_return( "Material shine parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* scale ase shine range 0..1 to pico range 0..127 */
|
|
|
|
shineValue *= 128.0;
|
|
|
|
|
|
|
|
/* skip rest and continue with next token */
|
|
|
|
_pico_parse_skip_rest( p );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* parse ambient material color */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*material_ambient" ) ) {
|
|
|
|
picoVec3_t vec;
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get r,g,b float values from ase */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_vec( p,vec ) ) {
|
|
|
|
_ase_error_return( "Material color parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* setup 0..255 range color values */
|
|
|
|
ambientColor[ 0 ] = (int)( vec[ 0 ] * 255.0 );
|
|
|
|
ambientColor[ 1 ] = (int)( vec[ 1 ] * 255.0 );
|
|
|
|
ambientColor[ 2 ] = (int)( vec[ 2 ] * 255.0 );
|
|
|
|
ambientColor[ 3 ] = (int)( 255 );
|
|
|
|
|
|
|
|
/* skip rest and continue with next token */
|
|
|
|
_pico_parse_skip_rest( p );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* parse diffuse material color */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*material_diffuse" ) ) {
|
|
|
|
picoVec3_t vec;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get r,g,b float values from ase */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_vec( p,vec ) ) {
|
|
|
|
_ase_error_return( "Material color parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* setup 0..255 range color */
|
|
|
|
diffuseColor[ 0 ] = (int)( vec[ 0 ] * 255.0 );
|
|
|
|
diffuseColor[ 1 ] = (int)( vec[ 1 ] * 255.0 );
|
|
|
|
diffuseColor[ 2 ] = (int)( vec[ 2 ] * 255.0 );
|
|
|
|
diffuseColor[ 3 ] = (int)( 255 );
|
|
|
|
|
|
|
|
/* skip rest and continue with next token */
|
|
|
|
_pico_parse_skip_rest( p );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* parse specular material color */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*material_specular" ) ) {
|
|
|
|
picoVec3_t vec;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get r,g,b float values from ase */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_parse_vec( p,vec ) ) {
|
|
|
|
_ase_error_return( "Material color parse error" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* setup 0..255 range color */
|
|
|
|
specularColor[ 0 ] = (int)( vec[ 0 ] * 255 );
|
|
|
|
specularColor[ 1 ] = (int)( vec[ 1 ] * 255 );
|
|
|
|
specularColor[ 2 ] = (int)( vec[ 2 ] * 255 );
|
|
|
|
specularColor[ 3 ] = (int)( 255 );
|
|
|
|
|
|
|
|
/* skip rest and continue with next token */
|
|
|
|
_pico_parse_skip_rest( p );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* material diffuse map */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !_pico_stricmp( p->token,"*map_diffuse" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
int sublevel = 0;
|
|
|
|
|
|
|
|
/* parse material block */
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( 1 )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* get next token */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( _pico_parse( p,1 ) == NULL ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( !strlen( p->token ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* handle levels */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->token[0] == '{' ) {
|
|
|
|
sublevel++;
|
|
|
|
}
|
|
|
|
if ( p->token[0] == '}' ) {
|
|
|
|
sublevel--;
|
|
|
|
}
|
|
|
|
if ( !sublevel ) {
|
|
|
|
break;
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* parse diffuse map bitmap */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !_pico_stricmp( p->token,"*bitmap" ) ) {
|
|
|
|
char* name = _pico_parse( p,0 );
|
|
|
|
if ( name == NULL ) {
|
|
|
|
_ase_error_return( "Missing material map bitmap name" );
|
|
|
|
}
|
|
|
|
mapname = _pico_alloc( strlen( name ) + 1 );
|
|
|
|
strcpy( mapname, name );
|
2007-11-04 03:34:51 +00:00
|
|
|
/* skip rest and continue with next token */
|
|
|
|
_pico_parse_skip_rest( p );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* end map_diffuse block */
|
|
|
|
}
|
|
|
|
/* end material block */
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( subMaterial == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* allocate new pico shader */
|
|
|
|
shader = PicoNewShader( model );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( shader == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
PicoFreeModel( model );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set material name */
|
|
|
|
PicoSetShaderName( shader,materialName );
|
|
|
|
|
|
|
|
/* set shader's transparency */
|
|
|
|
PicoSetShaderTransparency( shader,transValue );
|
|
|
|
|
|
|
|
/* set shader's ambient color */
|
|
|
|
PicoSetShaderAmbientColor( shader,ambientColor );
|
|
|
|
|
|
|
|
/* set diffuse alpha to transparency */
|
|
|
|
diffuseColor[3] = (picoByte_t)( transValue * 255.0 );
|
|
|
|
|
|
|
|
/* set shader's diffuse color */
|
|
|
|
PicoSetShaderDiffuseColor( shader,diffuseColor );
|
|
|
|
|
|
|
|
/* set shader's specular color */
|
|
|
|
PicoSetShaderSpecularColor( shader,specularColor );
|
|
|
|
|
|
|
|
/* set shader's shininess */
|
|
|
|
PicoSetShaderShininess( shader,shineValue );
|
|
|
|
|
|
|
|
/* set material map name */
|
|
|
|
PicoSetShaderMapName( shader, mapname );
|
|
|
|
|
|
|
|
/* this is just a material with 1 submaterial */
|
|
|
|
subMaterial = _ase_add_submaterial( &materials, index, 0, shader );
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: free mapname */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( mapname != NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
_pico_free( mapname );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
} // !_pico_stricmp ( "*material" )
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* skip unparsed rest of line and continue */
|
|
|
|
_pico_parse_skip_rest( p );
|
|
|
|
}
|
2008-06-26 11:21:13 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: finish existing surface */
|
|
|
|
// _ase_make_surface( model, &surface );
|
2012-03-17 20:01:54 +00:00
|
|
|
_ase_submit_triangles( surface, model,materials,faces );
|
|
|
|
_ase_free_faces( &faces,&facesTail );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_PM_ASE
|
2012-03-17 20:01:54 +00:00
|
|
|
_ase_print_materials( materials );
|
2007-11-04 03:34:51 +00:00
|
|
|
finish = clock();
|
2012-03-17 20:01:54 +00:00
|
|
|
elapsed = (double)( finish - start ) / CLOCKS_PER_SEC;
|
2007-11-04 03:34:51 +00:00
|
|
|
_pico_printf( PICO_NORMAL, "Loaded model in in %-.2f second(s)\n", elapsed );
|
|
|
|
#endif //DEBUG_PM_ASE
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
_ase_free_materials( &materials );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* return allocated pico model */
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pico file format module definition */
|
|
|
|
const picoModule_t picoModuleASE =
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
"1.0", /* module version string */
|
|
|
|
"Autodesk 3DSMAX ASCII", /* module display name */
|
|
|
|
"Jared Hefty, seaw0lf", /* author's name */
|
|
|
|
"2003 Jared Hefty, 2002 seaw0lf", /* module copyright */
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
"ase",NULL,NULL,NULL /* default extensions to use */
|
2007-11-04 03:34:51 +00:00
|
|
|
},
|
2012-03-17 20:01:54 +00:00
|
|
|
_ase_canload, /* validation routine */
|
|
|
|
_ase_load, /* load routine */
|
|
|
|
NULL, /* save validation routine */
|
|
|
|
NULL /* save routine */
|
2007-11-04 03:34:51 +00:00
|
|
|
};
|