| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
#include "picointernal.h" |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
typedef struct S3dsLoaderPers |
| 52 |
{ |
| 53 |
picoModel_t *model; |
| 54 |
picoSurface_t *surface; |
| 55 |
picoShader_t *shader; |
| 56 |
picoByte_t *bufptr; |
| 57 |
char *basename; |
| 58 |
int cofs; |
| 59 |
int maxofs; |
| 60 |
} |
| 61 |
T3dsLoaderPers; |
| 62 |
|
| 63 |
|
| 64 |
enum { |
| 65 |
|
| 66 |
CHUNK_MAIN = 0x4D4D, |
| 67 |
|
| 68 |
|
| 69 |
CHUNK_VERSION = 0x0002, |
| 70 |
CHUNK_EDITOR_CONFIG = 0x3D3E, |
| 71 |
CHUNK_EDITOR_DATA = 0x3D3D, |
| 72 |
CHUNK_KEYFRAME_DATA = 0xB000, |
| 73 |
|
| 74 |
|
| 75 |
CHUNK_MATERIAL = 0xAFFF, |
| 76 |
CHUNK_OBJECT = 0x4000, |
| 77 |
|
| 78 |
|
| 79 |
CHUNK_MATNAME = 0xA000, |
| 80 |
CHUNK_MATDIFFUSE = 0xA020, |
| 81 |
CHUNK_MATMAP = 0xA200, |
| 82 |
CHUNK_MATMAPFILE = 0xA300, |
| 83 |
|
| 84 |
|
| 85 |
CHUNK_OBJECT_MESH = 0x4100, |
| 86 |
|
| 87 |
|
| 88 |
CHUNK_OBJECT_VERTICES = 0x4110, |
| 89 |
CHUNK_OBJECT_FACES = 0x4120, |
| 90 |
CHUNK_OBJECT_MATERIAL = 0x4130, |
| 91 |
CHUNK_OBJECT_UV = 0x4140, |
| 92 |
}; |
| 93 |
#ifdef DEBUG_PM_3DS |
| 94 |
static struct |
| 95 |
{ |
| 96 |
int id; |
| 97 |
char *name; |
| 98 |
} |
| 99 |
debugChunkNames[] = |
| 100 |
{ |
| 101 |
{ CHUNK_MAIN, "CHUNK_MAIN" }, |
| 102 |
{ CHUNK_VERSION, "CHUNK_VERSION" }, |
| 103 |
{ CHUNK_EDITOR_CONFIG, "CHUNK_EDITOR_CONFIG" }, |
| 104 |
{ CHUNK_EDITOR_DATA, "CHUNK_EDITOR_DATA" }, |
| 105 |
{ CHUNK_KEYFRAME_DATA, "CHUNK_KEYFRAME_DATA" }, |
| 106 |
{ CHUNK_MATERIAL, "CHUNK_MATERIAL" }, |
| 107 |
{ CHUNK_OBJECT, "CHUNK_OBJECT" }, |
| 108 |
{ CHUNK_MATNAME, "CHUNK_MATNAME" }, |
| 109 |
{ CHUNK_MATDIFFUSE, "CHUNK_MATDIFFUSE" }, |
| 110 |
{ CHUNK_MATMAP, "CHUNK_MATMAP" }, |
| 111 |
{ CHUNK_MATMAPFILE, "CHUNK_MATMAPFILE" }, |
| 112 |
{ CHUNK_OBJECT_MESH, "CHUNK_OBJECT_MESH" }, |
| 113 |
{ CHUNK_OBJECT_VERTICES, "CHUNK_OBJECT_VERTICES" }, |
| 114 |
{ CHUNK_OBJECT_FACES, "CHUNK_OBJECT_FACES" }, |
| 115 |
{ CHUNK_OBJECT_MATERIAL, "CHUNK_OBJECT_MATERIAL" }, |
| 116 |
{ CHUNK_OBJECT_UV, "CHUNK_OBJECT_UV" }, |
| 117 |
{ 0, NULL } |
| 118 |
}; |
| 119 |
static char *DebugGetChunkName( int id ) { |
| 120 |
int i,max; |
| 121 |
max = sizeof( debugChunkNames ) / sizeof( debugChunkNames[0] ); |
| 122 |
|
| 123 |
for ( i = 0; i < max; i++ ) |
| 124 |
{ |
| 125 |
if ( debugChunkNames[i].id == id ) { |
| 126 |
|
| 127 |
return _pico_strlwr( debugChunkNames[i].name ); |
| 128 |
} |
| 129 |
} |
| 130 |
return "chunk_unknown"; |
| 131 |
} |
| 132 |
#endif |
| 133 |
|
| 134 |
|
| 135 |
#pragma pack(push, 1) |
| 136 |
|
| 137 |
typedef struct S3dsIndices |
| 138 |
{ |
| 139 |
unsigned short a,b,c; |
| 140 |
unsigned short visible; |
| 141 |
} |
| 142 |
T3dsIndices; |
| 143 |
|
| 144 |
typedef struct S3dsChunk |
| 145 |
{ |
| 146 |
unsigned short id; |
| 147 |
unsigned int len; |
| 148 |
} |
| 149 |
T3dsChunk; |
| 150 |
|
| 151 |
|
| 152 |
#pragma pack(pop) |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
static int _3ds_canload( PM_PARAMS_CANLOAD ){ |
| 158 |
const T3dsChunk *chunk; |
| 159 |
|
| 160 |
|
| 161 |
if ( bufSize < (int) sizeof( T3dsChunk ) ) { |
| 162 |
return PICO_PMV_ERROR_SIZE; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
chunk = (const T3dsChunk *)buffer; |
| 167 |
|
| 168 |
|
| 169 |
if ( bufSize < (int) _pico_little_long( chunk->len ) ) { |
| 170 |
return PICO_PMV_ERROR_SIZE; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
if ( _pico_little_short( chunk->id ) != CHUNK_MAIN ) { |
| 175 |
return PICO_PMV_ERROR_IDENT; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
return PICO_PMV_OK; |
| 180 |
} |
| 181 |
|
| 182 |
static T3dsChunk *GetChunk( T3dsLoaderPers *pers ){ |
| 183 |
T3dsChunk *chunk; |
| 184 |
|
| 185 |
|
| 186 |
if ( pers->cofs > pers->maxofs ) { |
| 187 |
return 0; |
| 188 |
} |
| 189 |
|
| 190 |
#ifdef DEBUG_PM_3DS |
| 191 |
|
| 192 |
#endif |
| 193 |
|
| 194 |
chunk = (T3dsChunk *)&pers->bufptr[ pers->cofs ]; |
| 195 |
if ( !chunk ) { |
| 196 |
return NULL; |
| 197 |
} |
| 198 |
|
| 199 |
chunk->id = _pico_little_short( chunk->id ); |
| 200 |
chunk->len = _pico_little_long( chunk->len ); |
| 201 |
|
| 202 |
|
| 203 |
pers->cofs += sizeof( T3dsChunk ); |
| 204 |
|
| 205 |
|
| 206 |
return chunk; |
| 207 |
} |
| 208 |
|
| 209 |
static int GetASCIIZ( T3dsLoaderPers *pers, char *dest, int max ){ |
| 210 |
int pos = 0; |
| 211 |
int ch; |
| 212 |
|
| 213 |
for (;; ) |
| 214 |
{ |
| 215 |
ch = pers->bufptr[ pers->cofs++ ]; |
| 216 |
if ( ch == '\0' ) { |
| 217 |
break; |
| 218 |
} |
| 219 |
if ( pers->cofs >= pers->maxofs ) { |
| 220 |
dest[ pos ] = '\0'; |
| 221 |
return 0; |
| 222 |
} |
| 223 |
dest[ pos++ ] = ch; |
| 224 |
if ( pos >= max ) { |
| 225 |
break; |
| 226 |
} |
| 227 |
} |
| 228 |
dest[ pos ] = '\0'; |
| 229 |
return 1; |
| 230 |
} |
| 231 |
|
| 232 |
static picoByte_t GetByte( T3dsLoaderPers *pers ){ |
| 233 |
picoByte_t *value; |
| 234 |
|
| 235 |
|
| 236 |
if ( pers->cofs > pers->maxofs ) { |
| 237 |
return 0; |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
value = (picoByte_t *)( pers->bufptr + pers->cofs ); |
| 242 |
pers->cofs += 1; |
| 243 |
return *value; |
| 244 |
} |
| 245 |
|
| 246 |
static int GetWord( T3dsLoaderPers *pers ){ |
| 247 |
unsigned short *value; |
| 248 |
|
| 249 |
|
| 250 |
if ( pers->cofs > pers->maxofs ) { |
| 251 |
return 0; |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
value = (unsigned short *)( pers->bufptr + pers->cofs ); |
| 256 |
pers->cofs += 2; |
| 257 |
return _pico_little_short( *value ); |
| 258 |
} |
| 259 |
|
| 260 |
static float GetFloat( T3dsLoaderPers *pers ){ |
| 261 |
float *value; |
| 262 |
|
| 263 |
|
| 264 |
if ( pers->cofs > pers->maxofs ) { |
| 265 |
return 0; |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
value = (float *)( pers->bufptr + pers->cofs ); |
| 270 |
pers->cofs += 4; |
| 271 |
return _pico_little_float( *value ); |
| 272 |
} |
| 273 |
|
| 274 |
static int GetMeshVertices( T3dsLoaderPers *pers ){ |
| 275 |
int numVerts; |
| 276 |
int i; |
| 277 |
|
| 278 |
|
| 279 |
numVerts = GetWord( pers ); |
| 280 |
|
| 281 |
#ifdef DEBUG_PM_3DS |
| 282 |
printf( "GetMeshVertices: numverts %d\n",numVerts ); |
| 283 |
#endif |
| 284 |
|
| 285 |
for ( i = 0; i < numVerts; i++ ) |
| 286 |
{ |
| 287 |
picoVec3_t v; |
| 288 |
v[0] = GetFloat( pers ); |
| 289 |
v[1] = GetFloat( pers ); |
| 290 |
v[2] = GetFloat( pers ); |
| 291 |
|
| 292 |
|
| 293 |
PicoSetSurfaceXYZ( pers->surface,i,v ); |
| 294 |
PicoSetSurfaceColor( pers->surface, 0, i, picoColor_white ); |
| 295 |
|
| 296 |
#ifdef DEBUG_PM_3DS_EX |
| 297 |
printf( "Vertex: x: %f y: %f z: %f\n",v[0],v[1],v[2] ); |
| 298 |
#endif |
| 299 |
} |
| 300 |
|
| 301 |
return 1; |
| 302 |
} |
| 303 |
|
| 304 |
static int GetMeshFaces( T3dsLoaderPers *pers ){ |
| 305 |
int numFaces; |
| 306 |
int i; |
| 307 |
|
| 308 |
|
| 309 |
numFaces = GetWord( pers ); |
| 310 |
|
| 311 |
#ifdef DEBUG_PM_3DS |
| 312 |
printf( "GetMeshFaces: numfaces %d\n",numFaces ); |
| 313 |
#endif |
| 314 |
|
| 315 |
for ( i = 0; i < numFaces; i++ ) |
| 316 |
{ |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
T3dsIndices face; |
| 321 |
face.a = GetWord( pers ); |
| 322 |
face.c = GetWord( pers ); |
| 323 |
face.b = GetWord( pers ); |
| 324 |
face.visible = GetWord( pers ); |
| 325 |
|
| 326 |
|
| 327 |
PicoSetSurfaceIndex( pers->surface, ( i * 3 + 0 ), (picoIndex_t)face.a ); |
| 328 |
PicoSetSurfaceIndex( pers->surface, ( i * 3 + 1 ), (picoIndex_t)face.b ); |
| 329 |
PicoSetSurfaceIndex( pers->surface, ( i * 3 + 2 ), (picoIndex_t)face.c ); |
| 330 |
|
| 331 |
#ifdef DEBUG_PM_3DS_EX |
| 332 |
printf( "Face: a: %d b: %d c: %d (%d)\n",face.a,face.b,face.c,face.visible ); |
| 333 |
#endif |
| 334 |
} |
| 335 |
|
| 336 |
return 1; |
| 337 |
} |
| 338 |
|
| 339 |
static int GetMeshTexCoords( T3dsLoaderPers *pers ){ |
| 340 |
int numTexCoords; |
| 341 |
int i; |
| 342 |
|
| 343 |
|
| 344 |
numTexCoords = GetWord( pers ); |
| 345 |
|
| 346 |
#ifdef DEBUG_PM_3DS |
| 347 |
printf( "GetMeshTexCoords: numcoords %d\n",numTexCoords ); |
| 348 |
#endif |
| 349 |
|
| 350 |
for ( i = 0; i < numTexCoords; i++ ) |
| 351 |
{ |
| 352 |
picoVec2_t uv; |
| 353 |
uv[0] = GetFloat( pers ); |
| 354 |
uv[1] = -GetFloat( pers ); |
| 355 |
|
| 356 |
|
| 357 |
if ( pers->surface == NULL ) { |
| 358 |
continue; |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
PicoSetSurfaceST( pers->surface,0,i,uv ); |
| 363 |
|
| 364 |
#ifdef DEBUG_PM_3DS_EX |
| 365 |
printf( "u: %f v: %f\n",uv[0],uv[1] ); |
| 366 |
#endif |
| 367 |
} |
| 368 |
|
| 369 |
return 1; |
| 370 |
} |
| 371 |
|
| 372 |
static int GetMeshShader( T3dsLoaderPers *pers ){ |
| 373 |
char shaderName[255] = { 0 }; |
| 374 |
picoShader_t *shader; |
| 375 |
int numSharedVerts; |
| 376 |
int setShaderName = 0; |
| 377 |
int i; |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
if ( !GetASCIIZ( pers,shaderName,sizeof( shaderName ) ) ) { |
| 386 |
return 0; |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
_pico_first_token( shaderName ); |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
shader = PicoFindShader( pers->model, shaderName, 1 ); |
| 400 |
|
| 401 |
|
| 402 |
if ( ( shader != NULL ) && pers->surface ) { |
| 403 |
|
| 404 |
const char* mapNamePtr = PicoGetShaderMapName( shader ); |
| 405 |
|
| 406 |
if ( mapNamePtr != NULL ) { |
| 407 |
#if 0 |
| 408 |
char temp[128]; |
| 409 |
const char *name; |
| 410 |
char mapName[1024 + 1]; |
| 411 |
memset( mapName,0,sizeof( mapName ) ); |
| 412 |
|
| 413 |
|
| 414 |
strcpy( mapName,mapNamePtr ); |
| 415 |
|
| 416 |
|
| 417 |
name = _pico_nopath( mapName ); |
| 418 |
strncpy( temp, name, sizeof( temp ) ); |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
if ( strlen( temp ) < 1 ) { |
| 425 |
strcpy( temp,pers->basename ); |
| 426 |
} |
| 427 |
|
| 428 |
|
| 429 |
_pico_strlwr( temp ); |
| 430 |
sprintf( mapName,"models/mapobjects/%s/%s",pers->basename,temp ); |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
#endif |
| 435 |
|
| 436 |
PicoSetSurfaceShader( pers->surface, shader ); |
| 437 |
|
| 438 |
setShaderName = 1; |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
if ( !setShaderName ) { |
| 443 |
_pico_printf( PICO_WARNING,"3DS mesh is missing shader name" ); |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
numSharedVerts = GetWord( pers ); |
| 452 |
|
| 453 |
#ifdef DEBUG_PM_3DS |
| 454 |
printf( "GetMeshShader: uses shader '%s' (nsv %d)\n",shaderName,numSharedVerts ); |
| 455 |
#endif |
| 456 |
|
| 457 |
for ( i = 0; i < numSharedVerts; i++ ) |
| 458 |
{ |
| 459 |
GetWord( pers ); |
| 460 |
} |
| 461 |
|
| 462 |
return 1; |
| 463 |
} |
| 464 |
|
| 465 |
static int GetDiffuseColor( T3dsLoaderPers *pers ){ |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
picoColor_t color; |
| 471 |
|
| 472 |
color[0] = GetByte( pers ); |
| 473 |
color[1] = GetByte( pers ); |
| 474 |
color[2] = GetByte( pers ); |
| 475 |
color[3] = 255; |
| 476 |
|
| 477 |
|
| 478 |
if ( pers->shader ) { |
| 479 |
PicoSetShaderDiffuseColor( pers->shader,color ); |
| 480 |
} |
| 481 |
#ifdef DEBUG_PM_3DS |
| 482 |
printf( "GetDiffuseColor: %d %d %d\n",color[0],color[1],color[2] ); |
| 483 |
#endif |
| 484 |
|
| 485 |
return 1; |
| 486 |
} |
| 487 |
|
| 488 |
static int DoNextEditorDataChunk( T3dsLoaderPers *pers, long endofs ){ |
| 489 |
T3dsChunk *chunk; |
| 490 |
|
| 491 |
#ifdef DEBUG_PM_3DS_EX |
| 492 |
printf( "DoNextEditorDataChunk: endofs %d\n",endofs ); |
| 493 |
#endif |
| 494 |
while ( pers->cofs < endofs ) |
| 495 |
{ |
| 496 |
long nextofs = pers->cofs; |
| 497 |
if ( ( chunk = GetChunk( pers ) ) == NULL ) { |
| 498 |
return 0; |
| 499 |
} |
| 500 |
if ( !chunk->len ) { |
| 501 |
return 0; |
| 502 |
} |
| 503 |
nextofs += chunk->len; |
| 504 |
|
| 505 |
#ifdef DEBUG_PM_3DS_EX |
| 506 |
printf( "Chunk %04x (%s), len %d pers->cofs %x\n",chunk->id,DebugGetChunkName( chunk->id ),chunk->len,pers->cofs ); |
| 507 |
#endif |
| 508 |
|
| 509 |
if ( chunk->id == CHUNK_OBJECT ) { |
| 510 |
picoSurface_t *surface; |
| 511 |
char surfaceName[ 0xff ] = { 0 }; |
| 512 |
|
| 513 |
|
| 514 |
if ( !GetASCIIZ( pers,surfaceName,sizeof( surfaceName ) ) ) { |
| 515 |
return 0; |
| 516 |
} |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
surface = PicoNewSurface( pers->model ); |
| 523 |
if ( surface == NULL ) { |
| 524 |
pers->surface = NULL; |
| 525 |
return 0; |
| 526 |
} |
| 527 |
|
| 528 |
pers->surface = surface; |
| 529 |
|
| 530 |
|
| 531 |
PicoSetSurfaceType( pers->surface,PICO_TRIANGLES ); |
| 532 |
|
| 533 |
|
| 534 |
PicoSetSurfaceName( pers->surface,surfaceName ); |
| 535 |
|
| 536 |
|
| 537 |
DoNextEditorDataChunk( pers,nextofs ); |
| 538 |
continue; |
| 539 |
} |
| 540 |
if ( chunk->id == CHUNK_OBJECT_MESH ) { |
| 541 |
|
| 542 |
if ( !DoNextEditorDataChunk( pers,nextofs ) ) { |
| 543 |
return 0; |
| 544 |
} |
| 545 |
continue; |
| 546 |
} |
| 547 |
if ( chunk->id == CHUNK_OBJECT_VERTICES ) { |
| 548 |
if ( !GetMeshVertices( pers ) ) { |
| 549 |
return 0; |
| 550 |
} |
| 551 |
continue; |
| 552 |
} |
| 553 |
if ( chunk->id == CHUNK_OBJECT_FACES ) { |
| 554 |
if ( !GetMeshFaces( pers ) ) { |
| 555 |
return 0; |
| 556 |
} |
| 557 |
continue; |
| 558 |
} |
| 559 |
if ( chunk->id == CHUNK_OBJECT_UV ) { |
| 560 |
if ( !GetMeshTexCoords( pers ) ) { |
| 561 |
return 0; |
| 562 |
} |
| 563 |
continue; |
| 564 |
} |
| 565 |
if ( chunk->id == CHUNK_OBJECT_MATERIAL ) { |
| 566 |
if ( !GetMeshShader( pers ) ) { |
| 567 |
return 0; |
| 568 |
} |
| 569 |
continue; |
| 570 |
} |
| 571 |
|
| 572 |
if ( chunk->id == CHUNK_MATERIAL ) { |
| 573 |
|
| 574 |
|
| 575 |
picoShader_t *shader; |
| 576 |
|
| 577 |
|
| 578 |
shader = PicoNewShader( pers->model ); |
| 579 |
if ( shader == NULL ) { |
| 580 |
pers->shader = NULL; |
| 581 |
return 0; |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
pers->shader = shader; |
| 586 |
|
| 587 |
|
| 588 |
DoNextEditorDataChunk( pers,nextofs ); |
| 589 |
continue; |
| 590 |
} |
| 591 |
if ( chunk->id == CHUNK_MATNAME ) { |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
if ( pers->shader ) { |
| 597 |
char *name = (char*) ( pers->bufptr + pers->cofs ); |
| 598 |
char *cleanedName = _pico_clone_alloc( name ); |
| 599 |
_pico_first_token( cleanedName ); |
| 600 |
PicoSetShaderName( pers->shader, cleanedName ); |
| 601 |
#ifdef DEBUG_PM_3DS |
| 602 |
printf( "NewShader: '%s'\n", cleanedName ); |
| 603 |
#endif |
| 604 |
_pico_free( cleanedName ); |
| 605 |
} |
| 606 |
} |
| 607 |
if ( chunk->id == CHUNK_MATDIFFUSE ) { |
| 608 |
|
| 609 |
|
| 610 |
if ( !GetDiffuseColor( pers ) ) { |
| 611 |
return 0; |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
} |
| 616 |
if ( chunk->id == CHUNK_MATMAP ) { |
| 617 |
|
| 618 |
DoNextEditorDataChunk( pers,nextofs ); |
| 619 |
continue; |
| 620 |
} |
| 621 |
if ( chunk->id == CHUNK_MATMAPFILE ) { |
| 622 |
|
| 623 |
|
| 624 |
if ( pers->shader ) { |
| 625 |
char *name = (char *)( pers->bufptr + pers->cofs ); |
| 626 |
PicoSetShaderMapName( pers->shader,name ); |
| 627 |
#ifdef DEBUG_PM_3DS |
| 628 |
printf( "NewShaderMapfile: '%s'\n",name ); |
| 629 |
#endif |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
if ( chunk->id == CHUNK_KEYFRAME_DATA ) { |
| 634 |
|
| 635 |
|
| 636 |
#ifdef DEBUG_PM_3DS |
| 637 |
printf( "KeyframeData: len %d\n",chunk->len ); |
| 638 |
#endif |
| 639 |
} |
| 640 |
|
| 641 |
pers->cofs = nextofs; |
| 642 |
if ( pers->cofs >= pers->maxofs ) { |
| 643 |
break; |
| 644 |
} |
| 645 |
} |
| 646 |
return 1; |
| 647 |
} |
| 648 |
|
| 649 |
static int DoNextChunk( T3dsLoaderPers *pers, int endofs ){ |
| 650 |
T3dsChunk *chunk; |
| 651 |
|
| 652 |
#ifdef DEBUG_PM_3DS |
| 653 |
printf( "DoNextChunk: endofs %d\n",endofs ); |
| 654 |
#endif |
| 655 |
while ( pers->cofs < endofs ) |
| 656 |
{ |
| 657 |
long nextofs = pers->cofs; |
| 658 |
if ( ( chunk = GetChunk( pers ) ) == NULL ) { |
| 659 |
return 0; |
| 660 |
} |
| 661 |
if ( !chunk->len ) { |
| 662 |
return 0; |
| 663 |
} |
| 664 |
nextofs += chunk->len; |
| 665 |
|
| 666 |
#ifdef DEBUG_PM_3DS_EX |
| 667 |
printf( "Chunk %04x (%s), len %d pers->cofs %x\n",chunk->id,DebugGetChunkName( chunk->id ),chunk->len,pers->cofs ); |
| 668 |
#endif |
| 669 |
|
| 670 |
if ( chunk->id == CHUNK_VERSION ) { |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
int version; |
| 678 |
version = GetWord( pers ); |
| 679 |
GetWord( pers ); |
| 680 |
#ifdef DEBUG_PM_3DS |
| 681 |
printf( "FileVersion: %d\n",version ); |
| 682 |
#endif |
| 683 |
|
| 684 |
|
| 685 |
if ( version == 4 ) { |
| 686 |
_pico_printf( PICO_WARNING, |
| 687 |
"3DS version is 4. Model might load incorrectly." ); |
| 688 |
} |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
} |
| 694 |
|
| 695 |
if ( chunk->id == CHUNK_EDITOR_DATA ) { |
| 696 |
if ( !DoNextEditorDataChunk( pers,nextofs ) ) { |
| 697 |
return 0; |
| 698 |
} |
| 699 |
continue; |
| 700 |
} |
| 701 |
|
| 702 |
pers->cofs = nextofs; |
| 703 |
if ( pers->cofs >= pers->maxofs ) { |
| 704 |
break; |
| 705 |
} |
| 706 |
} |
| 707 |
return 1; |
| 708 |
} |
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
static picoModel_t *_3ds_load( PM_PARAMS_LOAD ){ |
| 714 |
T3dsLoaderPers pers; |
| 715 |
picoModel_t *model; |
| 716 |
char basename[128]; |
| 717 |
|
| 718 |
|
| 719 |
model = PicoNewModel(); |
| 720 |
if ( model == NULL ) { |
| 721 |
|
| 722 |
return NULL; |
| 723 |
} |
| 724 |
|
| 725 |
memset( basename, 0, sizeof( basename ) ); |
| 726 |
strncpy( basename, _pico_nopath( fileName ), sizeof( basename ) - 1 ); |
| 727 |
_pico_setfext( basename, NULL ); |
| 728 |
|
| 729 |
|
| 730 |
pers.model = model; |
| 731 |
pers.bufptr = (picoByte_t *)_pico_alloc( bufSize ); |
| 732 |
memcpy( pers.bufptr, buffer, bufSize ); |
| 733 |
pers.basename = (char *)basename; |
| 734 |
pers.maxofs = bufSize; |
| 735 |
pers.cofs = 0L; |
| 736 |
|
| 737 |
|
| 738 |
PicoSetModelFrameNum( model,frameNum ); |
| 739 |
PicoSetModelName( model,fileName ); |
| 740 |
PicoSetModelFileName( model,fileName ); |
| 741 |
|
| 742 |
|
| 743 |
GetChunk( &pers ); |
| 744 |
|
| 745 |
|
| 746 |
if ( !DoNextChunk( &pers,pers.maxofs ) ) { |
| 747 |
|
| 748 |
PicoFreeModel( model ); |
| 749 |
return NULL; |
| 750 |
} |
| 751 |
|
| 752 |
return model; |
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
const picoModule_t picoModule3DS = |
| 757 |
{ |
| 758 |
"0.86-b", |
| 759 |
"Autodesk 3Dstudio", |
| 760 |
"seaw0lf", |
| 761 |
"2002 seaw0lf", |
| 762 |
{ |
| 763 |
"3ds",NULL,NULL,NULL |
| 764 |
}, |
| 765 |
_3ds_canload, |
| 766 |
_3ds_load, |
| 767 |
NULL, |
| 768 |
NULL |
| 769 |
}; |