25 #include "pandatoolbase.h" 27 int init_soft2egg(
int,
char **);
32 #include <eggParametrics.h> 33 #include <animTable.h> 34 #include <linMathOutput.h> 38 #include <strstream.h> 45 #include <Performer/pr/pfLinMath.h> 49 #include <SI_macros.h> 51 static const int TEX_PER_MAT = 1;
52 static FILE *outStream = stdout;
59 soft2egg() :
EggBase(
"r:d:s:m:t:P:b:e:f:T:S:M:A:N:v:o:FhknpaxiucCD")
61 rsrc_path =
"/ful/ufs/soft371_mips2/3D/rsrc";
87 animData.is_z_up = FALSE;
96 ignore_tex_offsets = 0;
101 virtual void Usage();
102 virtual void ShowOpts();
104 virtual boolean UseOutputSwitch()
const {
109 HandleGetopts(
char flag,
char *optarg,
int &optind,
int argc,
char **argv);
112 char *GetRootName(
const char * );
113 char *RemovePathName(
const char * );
114 char *GetSliderName(
const char * );
115 char *GetFullName( SAA_Scene *, SAA_Elem * );
116 char *GetName( SAA_Scene *, SAA_Elem * );
117 char *GetModelNoteInfo( SAA_Scene *, SAA_Elem * );
118 char *MakeTableName(
const char *,
int );
119 char *DepointellizeName(
char * );
120 SAA_Elem *FindModelByName(
char *, SAA_Scene *, SAA_Elem *,
int );
121 char *ConvertTexture( SAA_Scene *, SAA_Elem * );
122 int *FindClosestTriVert(
EggVertexPool *, SAA_DVector *,
int );
123 int *MakeIndexMap(
int *,
int,
int );
124 int findShapeVert( SAA_DVector, SAA_DVector *,
int );
127 void MakeSurfaceCurve( SAA_Scene *, SAA_Elem *,
EggGroup *,
130 EggNurbsCurve *MakeUVNurbsCurve(
int,
long *,
double *,
double *,
134 float [4][4],
char * );
136 void AddKnots( perf_vector<double> &,
double *,
int, SAA_Boolean,
int );
137 void MakeJoint( SAA_Scene *, EggJoint *&,
AnimGroup *&, SAA_Elem *,
char * );
138 void MakeSoftSkin( SAA_Scene *, SAA_Elem *, SAA_Elem *,
int,
char * );
139 void CleanUpSoftSkin( SAA_Scene *, SAA_Elem *,
char * );
140 void MakeAnimTable( SAA_Scene *, SAA_Elem *,
char * );
141 void MakeVertexOffsets( SAA_Scene *, SAA_Elem *, SAA_ModelType type,
142 int,
int, SAA_DVector *,
float (*)[4],
char * );
143 void MakeMorphTable( SAA_Scene *, SAA_Elem *, SAA_Elem *,
int,
char *,
145 void MakeLinearMorphTable( SAA_Scene *, SAA_Elem *,
int,
char *,
float );
146 void MakeWeightedMorphTable( SAA_Scene *, SAA_Elem *, SAA_Elem *,
int,
147 int,
char *,
float );
148 void MakeExpressionMorphTable( SAA_Scene *, SAA_Elem *, SAA_Elem *,
int,
149 int,
char *,
float );
150 void MakeTexAnim( SAA_Scene *, SAA_Elem *,
char * );
168 SAA_Database database;
185 int ignore_tex_offsets;
218 "soft2egg takes a SoftImage scene or model\n" 219 "and outputs its contents as an egg file\n";
232 << _commandName <<
" [opts] (must specify -m or -s)\n\n" 252 " -r <path> - Used to provide soft with the resource\n" 253 " Defaults to 'c:/Softimage/SOFT_3.9.2/3D/test'.\n" 255 " -d <path> - Database path.\n" 256 " -s <scene> - Indicates that a scene will be converted.\n" 257 " -m <model> - Indicates that a model will be converted.\n" 258 " -t <path> - Specify path to place converted textures.\n" 259 " -T <name> - Specify filename for texture map listing.\n" 260 " -S <step> - Specify step for nurbs surface triangulation.\n" 261 " -M <name> - Specify model output filename. Defaults to scene name.\n" 262 " -A <name> - Specify anim output filename. Defaults to scene name.\n" 263 " -N <name> - Specify egg group name.\n" 264 " -k - Enable soft assignment for geometry.\n" 265 " -n - Specify egg NURBS representation instead of poly's.\n" 266 " -p - Specify egg polygon output for geometry.\n" 267 " -P <frame> - Specify frame number for static pose.\n" 268 " -b <frame> - Specify starting frame for animation (default = first).\n" 269 " -e <frame> - Specify ending frame for animation (default = last).\n" 270 " -f <fps> - Specify frame rate for animation playback.\n" 271 " -a - Compile animation tables if animation present.\n" 272 " -F - Ignore hierarchy and build a completely flat skeleton.\n" 273 " -v <level> - Set debug level.\n" 274 " -x - Shift NURBS parameters to preserve Alias textures.\n" 275 " -i - Ignore Soft texture uv offsets.\n" 276 " -u - Use Soft prefix in model names.\n" 277 " -c - Cancel morph conversion.\n" 278 " -C - Cancel duv conversion.\n" 279 " -D - Don't make the output model a character.\n" 280 " -o <prefix>- Convert only models with given prefix.\n";
292 HandleGetopts(
char flag,
char *optarg,
int &optind,
int argc,
char **argv)
294 boolean okflag =
true;
299 if ( strcmp( optarg,
"" ) )
303 fprintf( outStream,
"using rsrc path %s\n", rsrc_path );
308 if ( strcmp( optarg,
"" ) )
311 database_name = optarg;
312 fprintf( outStream,
"using database %s\n", database_name );
317 if ( strcmp( optarg,
"" ) )
321 fprintf( outStream,
"loading scene %s\n", scene_name );
326 if ( strcmp( optarg,
"" ) )
330 fprintf( outStream,
"loading model %s\n", model_name );
335 if ( strcmp( optarg,
"" ) )
339 fprintf( outStream,
"texture path: %s\n", tex_path );
344 if ( strcmp( optarg,
"") )
347 tex_filename = optarg;
348 fprintf( outStream,
"creating texture list file: %s\n",
353 if ( strcmp( optarg,
"" ) )
355 nurbs_step = atoi(optarg);
356 fprintf( outStream,
"NURBS step: %d\n", nurbs_step );
361 if ( strcmp( optarg,
"" ) )
363 eggFileName = optarg;
364 fprintf( outStream,
"Model output filename: %s\n", eggFileName );
369 if ( strcmp( optarg,
"" ) )
371 animFileName = optarg;
372 fprintf( outStream,
"Anim output filename: %s\n", animFileName );
377 if ( strcmp( optarg,
"" ) )
379 eggGroupName = optarg;
380 fprintf( outStream,
"Egg group name: %s\n", eggGroupName );
385 if ( strcmp( optarg,
"" ) )
387 search_prefix = optarg;
388 fprintf( outStream,
"Only converting models with prefix: %s\n",
400 fprintf( outStream,
"canceling morph conversion\n" );
405 fprintf( outStream,
"canceling uv animation conversion\n" );
410 fprintf( outStream,
"making a non-character model\n" );
416 fprintf( outStream,
"-k flag no longer necessary\n" );
421 fprintf( outStream,
"outputting egg NURBS info\n" );
426 fprintf( outStream,
"outputting egg polygon info\n" );
430 if ( strcmp( optarg,
"" ) )
433 pose_frame = atoi(optarg);
434 fprintf( outStream,
"generating static pose from frame %d\n",
441 fprintf( outStream,
"attempting to compile anim tables\n" );
446 fprintf( outStream,
"building a flat skeleton!!!\n" );
450 shift_textures = TRUE;
451 fprintf( outStream,
"shifting NURBS parameters...\n" );
455 ignore_tex_offsets = TRUE;
456 fprintf( outStream,
"ignoring texture offsets...\n" );
461 fprintf( outStream,
"using prefix in model names...\n" );
466 if ( strcmp( optarg,
"" ) )
468 verbose = atoi(optarg);
469 fprintf( outStream,
"using debug level %d\n", verbose );
474 if ( strcmp( optarg,
"" ) )
476 anim_start = atoi(optarg);
477 fprintf( outStream,
"animation starting at frame: %d\n",
483 if ( strcmp( optarg,
"" ) )
485 anim_end = atoi(optarg);
486 fprintf( outStream,
"animation ending at frame: %d\n", anim_end );
491 if ( strcmp( optarg,
"" ) )
493 anim_rate = atoi(optarg);
494 fprintf( outStream,
"animation frame rate: %d\n", anim_rate );
499 okflag = EggBase::HandleGetopts(flag, optarg, optind, argc, argv);
515 return( ( num < HUGE_VAL ) && finite( num ) );
526 GetRootName(
const char *name )
532 hyphen = strchr( name,
'-' );
535 if ( (hyphen != NULL) && len )
537 root = (
char *)malloc(
sizeof(
char)*(len+1));
538 strncpy( root, name, len );
539 root[
sizeof(char)*(len)] =
'\0';
543 root = (
char *)malloc(
sizeof(
char)*(strlen(name)+1));
544 strcpy( root, name );
558 RemovePathName(
const char *name )
565 slash = strrchr( name,
'/' );
567 root = (
char *)malloc(
sizeof(
char)*(strlen(name)+1));
570 strcpy( root, ++slash );
572 strcpy( root, name );
577 fprintf( stderr,
"Error: RemovePathName received NULL string!\n" );
578 return ( (
char *)name );
589 GetSliderName(
const char *name )
597 hyphen = strchr( name,
'-' );
608 lastPeriod = strrchr( end,
'.' );
611 if ( lastPeriod != NULL )
617 fprintf( stdout,
"slider name: '%s'\n", end );
622 return( (
char *)name );
632 GetName( SAA_Scene *scene, SAA_Elem *element )
638 SAA_elementGetNameLength( scene, element, &nameLen );
639 name = (
char *)malloc(
sizeof(
char)*++nameLen);
640 SAA_elementGetName( scene, element, nameLen, name );
652 GetFullName( SAA_Scene *scene, SAA_Elem *element )
658 SAA_elementGetNameLength( scene, element, &nameLen );
659 name = (
char *)malloc(
sizeof(
char)*++nameLen);
660 SAA_elementGetName( scene, element, nameLen, name );
666 SAA_elementGetPrefixLength( scene, element, &prefixLen );
667 prefix = (
char *)malloc(
sizeof(
char)*++prefixLen);
668 SAA_elementGetPrefix( scene, element, prefixLen, prefix );
670 strstream fullNameStrm;
673 fullNameStrm << prefix <<
"-" << name << ends;
678 return fullNameStrm.str();
688 GetModelNoteInfo( SAA_Scene *scene, SAA_Elem *model )
692 char *modelNote = NULL;
693 SAA_Boolean bigEndian;
696 SAA_elementGetUserDataSize( scene, model,
"MNOT", &size );
701 modelNote = (
char *)malloc(
sizeof(
char)*(size + 1));
704 SAA_elementGetUserData( scene, model,
"MNOT", size,
705 &bigEndian, (
void *)modelNote );
708 char *eol = strchr( modelNote,
'\n' );
712 modelNote[size] =
'\0';
715 fprintf( outStream,
"\nmodelNote = %s\n",
730 MakeTableName(
const char *name,
int number )
734 namestrm << name <<
"." << number << ends;
735 return namestrm.str();
745 FindModelByName(
char *name, SAA_Scene *scene, SAA_Elem *models,
749 SAA_Elem *foundModel = NULL;
751 for (
int model = 0; model < numModels; model++ )
753 foundName = GetName( scene, &models[model] );
755 if ( !strcmp( name, foundName ) )
758 fprintf( outStream,
"foundModel: '%s' = '%s'\n",
761 foundModel = &models[model];
762 return( foundModel );
766 fprintf( outStream,
"findModelByName: failed to find model named: '%s'\n",
769 return ( foundModel );
780 DepointellizeName(
char *name )
785 newName = (
char *)malloc(
sizeof(
char)*(strlen(name)+1));
786 sprintf( newName,
"%s", name );
788 endPtr = strchr( newName,
'.' );
789 if ( endPtr != NULL )
804 ConvertTexture( SAA_Scene *scene, SAA_Elem *texture )
806 char *fileName = NULL;
810 SAA_texture2DGetPicNameLength( scene, texture, &fileNameLen);
814 fileName = (
char *)malloc(
sizeof(
char)*++fileNameLen);
815 SAA_texture2DGetPicName( scene, texture, fileNameLen, fileName );
820 if ( (fileName != NULL) && strlen( fileName ) && strcmp( fileName,
821 "/fat/people/gregw/new_test/PICTURES/default") &&
822 ( strstr( fileName,
"noIcon" ) == NULL) )
824 char *texName = NULL;
825 char *texNamePath = NULL;
826 char *tmpName = NULL;
827 char *fileNameExt = NULL;
830 tmpName = strrchr( fileName,
'/' );
832 if ( tmpName == NULL )
840 SAA_texture2DGetTransparency( scene, texture, &transp );
842 if ( transp != 0.0f ) {
843 texName = (
char *)malloc(
sizeof(
char)*(strlen(tmpName)+6));
844 sprintf( texName,
"%s.rgba", tmpName );
846 texName = (
char *)malloc(
sizeof(
char)*(strlen(tmpName)+5));
847 sprintf( texName,
"%s.rgb", tmpName );
850 fileNameExt = (
char *)malloc(
sizeof(
char)*(strlen(fileName)+5));
851 sprintf( fileNameExt,
"%s.pic", fileName );
854 fprintf( outStream,
"Looking for texture file: '%s'\n", fileNameExt );
857 int found_file = ( access( fileNameExt, F_OK ) == 0);
863 texNamePath = (
char *)malloc(
sizeof(
char)*(strlen(tex_path) +
864 strlen(texName) + 2));
866 sprintf( texNamePath,
"%s/%s", tex_path, texName );
869 texFile << texNamePath <<
": " << fileNameExt <<
"\n";
872 if ( (access( texNamePath, F_OK ) != 0) && !texFile )
874 char *command = (
char *)malloc(
sizeof(
char)*
875 (strlen(fileNameExt) + strlen(texNamePath) + 20));
877 sprintf( command,
"image-resize -1 %s %s",
878 fileNameExt, texNamePath );
881 fprintf( outStream,
"executing %s\n", command );
889 fprintf( outStream,
"%s already exists!\n", texNamePath );
895 fprintf( outStream,
"Warning: No texture path defined" );
896 fprintf( outStream,
" - No automatic conversion performed\n" );
902 fprintf( outStream,
"Warning: Couldn't find texture file: %s\n",
909 return( texNamePath );
915 fprintf( outStream,
"Warning: ConvertTexture received NULL fileName\n" );
928 FindClosestTriVert(
EggVertexPool *vpool, SAA_DVector *vertices,
int numVert )
931 int vpoolSize = vpool->NumVertices();
938 vertMap = (
int *)malloc(
sizeof(
int)*vpoolSize);
941 for ( i = 0; i < vpoolSize; i++ )
944 for ( j = 0; j < numVert-1; j++ )
948 powf( vpool->Vertex(i)->position[0] - vertices[j].x , 2 ) +
949 powf( vpool->Vertex(i)->position[1] - vertices[j].y , 2 ) +
950 powf( vpool->Vertex(i)->position[2] - vertices[j].z , 2 ) );
953 if ( !j || ( thisDist < closestDist ) )
956 closestDist = thisDist;
959 vertMap[i] = closest;
963 fprintf( outStream,
"mapping v %d of %d:( %f, %f, %f )\n", i,
964 vpoolSize, vpool->Vertex(i)->position[0],
965 vpool->Vertex(i)->position[1],
966 vpool->Vertex(i)->position[2] );
967 fprintf( outStream,
"to cv %d of %d:( %f, %f, %f )\tdelta = %f\n",
968 closest, numVert-1, vertices[closest].x, vertices[closest].y,
969 vertices[closest].z, closestDist );
985 MakeIndexMap(
int *indices,
int numIndices,
int mapSize )
990 int *map = (
int *)malloc(
sizeof(
int)*mapSize);
994 for ( i = 0; i < mapSize; i++ )
998 while( j < numIndices )
1000 if ( indices[j] == i )
1004 fprintf( outStream,
"map[%d] = %d\n", i, map[i] );
1013 fprintf( outStream,
"Warning: orphan vertex (%d)\n", i );
1020 fprintf( outStream,
"Not enough Memory for index Map...\n");
1034 findShapeVert( SAA_DVector vertex, SAA_DVector *vertices,
int numVert )
1039 for ( i = 0; i < numVert && !found ; i++ )
1041 if ( ( vertex.x == vertices[i].x ) &&
1042 ( vertex.y == vertices[i].y ) &&
1043 ( vertex.z == vertices[i].z ) )
1048 fprintf( outStream,
"found shape vert at index %d\n", i );
1072 if ( (scene_name == NULL && model_name == NULL) || database_name == NULL )
1078 if ((result = SAA_Init(rsrc_path, FALSE)) != SI_SUCCESS)
1080 fprintf( outStream,
"Error: Couldn't get resource path!\n");
1084 if ((result = SAA_databaseLoad(database_name, &database)) != SI_SUCCESS)
1086 fprintf( outStream,
"Error: Couldn't load database!\n");
1090 if ((result = SAA_sceneGetCurrent(&scene)) == SI_SUCCESS)
1093 if ( scene_name != NULL )
1095 SAA_sceneLoad( &database, scene_name, &scene );
1098 if ( eggFileName == NULL )
1100 eggFileName = (
char *)malloc(
sizeof(
char)*
1101 (strlen( scene_name ) + 14 ));
1102 sprintf( eggFileName,
"%s", DepointellizeName(scene_name) );
1104 strcat( eggFileName,
"-nurb" );
1105 strcat( eggFileName,
"-mod.egg" );
1109 if ( make_poly || make_nurbs )
1111 unlink( eggFileName );
1112 eggFile.open( eggFileName, ios::out, 0666 );
1116 fprintf( outStream,
"Couldn't open output file: %s\n",
1123 if ( tex_filename != NULL )
1125 unlink( tex_filename );
1126 texFile.open( tex_filename, ios::out, 0666 );
1130 fprintf( outStream,
"Couldn't open output file: %s\n",
1136 if ( SAA_updatelistGet( &scene ) == SI_SUCCESS )
1140 fprintf( outStream,
"setting Scene to frame %d...\n", pose_frame );
1142 SAA_frame2Seconds( &scene, pose_frame, &time );
1143 SAA_updatelistEvalScene( &scene, time );
1145 SAA_updatelistEvalScene( &scene, time );
1147 SAA_sceneFreeze( &scene );
1153 SAA_sceneGetNbModels( &scene, &numModels );
1154 fprintf( outStream,
"Scene has %d model(s)...\n", numModels );
1159 models = (SAA_Elem *)malloc(
sizeof(SAA_Elem)*numModels);
1161 if ( models != NULL )
1163 char *rootName = GetRootName( eggFileName );
1166 if ( eggGroupName == NULL )
1167 dart = _data.CreateGroup( NULL, rootName );
1169 dart = _data.CreateGroup( NULL, eggGroupName );
1172 dart->flags |= EF_DART;
1176 rootTable = animData.CreateTable( NULL, eggFileName );
1178 if ( eggGroupName == NULL )
1179 animRoot = animData.CreateBundle( rootTable, rootName );
1181 animRoot = animData.CreateBundle( rootTable,
1185 animData.root_group.children.push_front(
1189 fprintf( outStream,
"made animRoot: %s\n", rootName );
1191 SAA_sceneGetModels( &scene, numModels, models );
1193 for ( i = 0; i < numModels; i++ )
1197 SAA_elementGetHierarchyLevel( &scene, &models[i], &level );
1202 "\negging scene model[%d]\n", i );
1204 MakeEgg( dart, NULL, NULL, &scene, &models[i] );
1208 if ( make_poly || make_nurbs )
1218 SAA_Boolean isSkeleton;
1221 for ( i = 0; i < numModels; i++ )
1223 SAA_modelIsSkeleton( &scene, &models[i], &isSkeleton );
1227 fullname = GetFullName( &scene, &models[i] );
1231 name = GetName( &scene, &models[i] );
1234 if ( strstr( fullname, search_prefix ) != NULL )
1238 MakeSoftSkin( &scene, &models[i], models,
1247 for ( i = 0; i < numModels; i++ )
1251 fullname = GetFullName( &scene, &models[i] );
1255 name = GetName( &scene, &models[i] );
1258 if ( strstr( fullname, search_prefix ) != NULL )
1259 CleanUpSoftSkin( &scene, &models[i], name );
1268 dart->StealChildren( *skeleton );
1271 _data.UniquifyNames();
1276 eggFile << _data <<
"\n";
1277 fprintf( outStream,
"\nwriting out %s...\n", eggFileName );
1288 if ( animFileName == NULL )
1290 animFileName = (
char *)malloc(
sizeof(
char)*
1291 (strlen(scene_name)+ 10 ));
1292 sprintf( animFileName,
"%s", DepointellizeName(scene_name) );
1293 strcat( animFileName,
"-chan.egg" );
1296 unlink( animFileName );
1297 animFile.open( animFileName, ios::out, 0666 );
1301 fprintf( outStream,
"Couldn't open output file: %s\n",
1312 if (anim_start == -1000)
1313 SAA_sceneGetPlayCtrlStartFrame( &scene, &anim_start );
1315 if (anim_end == -1000)
1316 SAA_sceneGetPlayCtrlEndFrame( &scene, &anim_end );
1320 fprintf( outStream,
"\nframeStart = %d\n", anim_start );
1321 fprintf( outStream,
"frameEnd = %d\n", anim_end );
1325 for ( frame = anim_start; frame <= anim_end;
1328 SAA_frame2Seconds( &scene, frame, &time );
1329 SAA_updatelistEvalScene( &scene, time );
1331 SAA_updatelistEvalScene( &scene, time );
1332 fprintf( outStream,
"\n> animating frame %d\n", frame );
1335 for ( i = 0; i < numModels; i++ )
1339 SAA_Boolean isSkeleton;
1342 SAA_modelIsSkeleton( &scene, &models[i], &isSkeleton );
1346 fullname = GetFullName( &scene, &models[i] );
1350 name = GetName( &scene, &models[i] );
1353 if ( strstr( fullname, search_prefix ) != NULL )
1358 MakeMorphTable( &scene, &models[i], models,
1359 numModels, name, time );
1364 result = SAA_modelGetType( &scene, &models[i], &type );
1369 SAA_elementGetUserDataSize( &scene, &models[i],
1370 "TEX_OFFSETS", &size );
1373 if ( ( size != 0 ) && make_duv )
1374 MakeTexAnim( &scene, &models[i], name );
1379 ( strstr( name,
"joint") != NULL ) )
1380 MakeAnimTable( &scene, &models[i], name );
1386 fprintf( outStream,
"\n" );
1389 animFile << animData <<
"\n";
1390 fprintf( outStream,
"\nwriting out %s...\n", animFileName );
1398 fprintf( outStream,
"Error: Not enough Memory for models...\n");
1402 else if ( model_name != NULL )
1405 if ( eggFileName == NULL )
1408 (
char *)malloc(
sizeof(
char)*(strlen( model_name )+13));
1409 sprintf( eggFileName,
"%s", DepointellizeName( model_name ) );
1412 strcat( eggFileName,
"-nurb" );
1413 strcat( eggFileName,
"-mod.egg" );
1416 eggFile.open( eggFileName );
1420 fprintf( outStream,
"Couldn't open output file: %s\n",
1426 SAA_elementLoad(&database, &scene, model_name, &model))
1429 fprintf( outStream,
"Loading single model...\n");
1430 MakeEgg( NULL, NULL, NULL, &scene, &model );
1433 eggFile << _data <<
"\n";
1447 SAA_Scene *scene, SAA_Elem *model )
1460 float *uScale = NULL;
1461 float *vScale = NULL;
1462 float *uOffset = NULL;
1463 float *vOffset = NULL;
1464 SAA_Boolean uv_swap = FALSE;
1466 SAA_SubElem *triangles = NULL;
1467 SAA_Elem *materials = NULL;
1468 SAA_SubElem *cvertices = NULL;
1469 SAA_DVector *cvertPos = NULL;
1470 SAA_DVector *vertices = NULL;
1471 SAA_DVector *normals = NULL;
1472 int *indices = NULL;
1473 int *indexMap = NULL;
1474 int *numTexTri = NULL;
1475 SAA_Elem *textures = NULL;
1476 char **texNameArray;
1477 float *uCoords = NULL;
1478 float *vCoords = NULL;
1479 SAA_GeomType gtype = SAA_GEOM_ORIGINAL;
1480 SAA_Boolean visible;
1485 result = SAA_modelGetType( scene, model, &type );
1489 if ( type == SAA_MNILL )
1490 fprintf( outStream,
"encountered null\n");
1491 else if ( type == SAA_MPTCH )
1492 fprintf( outStream,
"encountered patch\n" );
1493 else if ( type == SAA_MFACE )
1494 fprintf( outStream,
"encountered face\n" );
1495 else if ( type == SAA_MSMSH )
1496 fprintf( outStream,
"encountered mesh\n" );
1497 else if ( type == SAA_MJNT )
1498 fprintf( outStream,
"encountered joint\n" );
1499 else if ( type == SAA_MSPLN )
1500 fprintf( outStream,
"encountered spline\n" );
1501 else if ( type == SAA_MMETA )
1502 fprintf( outStream,
"encountered meta element\n" );
1503 else if ( type == SAA_MBALL )
1504 fprintf( outStream,
"encountered metaball\n" );
1505 else if ( type == SAA_MNCRV )
1506 fprintf( outStream,
"encountered nurb curve\n" );
1507 else if ( type == SAA_MNSRF )
1508 fprintf( outStream,
"encountered nurbs surf\n" );
1510 fprintf( outStream,
"encountered unknown type: %d\n", type );
1518 fullname = GetFullName( scene, model );
1528 name = GetName( scene, model );
1532 fprintf( outStream,
"element name <%s>\n", name );
1534 fflush( outStream );
1537 SAA_modelGetMatrix( scene, model, SAA_COORDSYS_GLOBAL, matrix );
1541 fprintf( outStream,
"model matrix = %f %f %f %f\n", matrix[0][0],
1542 matrix[0][1], matrix[0][2], matrix[0][3] );
1543 fprintf( outStream,
"model matrix = %f %f %f %f\n", matrix[1][0],
1544 matrix[1][1], matrix[1][2], matrix[1][3] );
1545 fprintf( outStream,
"model matrix = %f %f %f %f\n", matrix[2][0],
1546 matrix[2][1], matrix[2][2], matrix[2][3] );
1547 fprintf( outStream,
"model matrix = %f %f %f %f\n", matrix[3][0],
1548 matrix[3][1], matrix[3][2], matrix[3][3] );
1555 if ( (strstr( name,
"con-" ) == NULL) &&
1556 (strstr( name,
"con_" ) == NULL) &&
1557 (strstr( name,
"fly_" ) == NULL) &&
1558 (strstr( name,
"fly-" ) == NULL) &&
1559 (strstr( name,
"camRIG" ) == NULL) &&
1560 (strstr( name,
"bars" ) == NULL) &&
1562 (strstr( fullname, search_prefix ) != NULL) )
1567 gtype = SAA_GEOM_DEFORMED;
1570 SAA_modelGetNbShapes( scene, model, &numShapes );
1572 fprintf( outStream,
"MakeEgg: num shapes: %d\n", numShapes);
1577 if ( (numShapes > 0) && make_morph )
1582 if ( morphRoot == NULL )
1583 morphRoot = animData.CreateTable( animRoot,
"morph" );
1589 for ( i = 1; i < numShapes; i++ )
1591 tableName = MakeTableName( name, i );
1592 SAnimTable *table =
new SAnimTable( );
1593 table->name = tableName;
1594 table->fps = anim_rate;
1595 morphRoot->children.push_back( table );
1597 fprintf( outStream,
"created table named: '%s'\n", tableName );
1603 SAA_modelGetNodeVisibility( scene, model, &visible );
1605 fprintf( outStream,
"model visibility: %d\n", visible );
1613 (type != SAA_MNILL) &&
1614 (type != SAA_MJNT) &&
1616 (make_nurbs && ((type == SAA_MSMSH) || (type == SAA_MFACE )) ))
1617 || (!make_poly && !make_nurbs && make_duv &&
1618 ((type == SAA_MSMSH) || (type == SAA_MFACE )) ))
1622 if ( type == SAA_MNSRF )
1623 SAA_nurbsSurfaceSetStep( scene, model, nurbs_step, nurbs_step );
1626 else if ( type == SAA_MPTCH )
1627 SAA_patchSetStep( scene, model, nurbs_step, nurbs_step );
1630 result = SAA_modelGetNbTriangles( scene, model, gtype,
id, &numTri);
1632 fprintf( outStream,
"triangles: %d\n", numTri);
1634 if ( result != SI_SUCCESS )
1636 if ( verbose >= 1 ) {
1638 "Error: couldn't get number of triangles!\n" );
1639 fprintf( outStream,
"\tbailing on model: '%s'\n", name );
1645 SAA_Boolean isSkeleton = FALSE;
1647 SAA_modelIsSkeleton( scene, model, &isSkeleton );
1653 if ( isSkeleton || (strstr( name,
"joint" ) != NULL) )
1656 fprintf( outStream,
"animating Polys as joint!!!\n" );
1658 MakeJoint( scene, lastJoint, lastAnim, model, name );
1665 fprintf( outStream,
"no triangles!\n");
1670 triangles = (SAA_SubElem *)malloc(
sizeof(SAA_SubElem)*numTri);
1671 if ( triangles != NULL )
1674 SAA_modelGetTriangles( scene, model, gtype,
id, numTri, triangles );
1677 fprintf( outStream,
"Not enough Memory for triangles...\n");
1680 materials = (SAA_Elem *)malloc(
sizeof(SAA_Elem)*numTri);
1681 if ( materials != NULL )
1684 SAA_triangleGetMaterials( scene, model, numTri, triangles,
1688 fprintf( outStream,
"Not enough Memory for materials...\n");
1691 numTexTri = (
int *)malloc(
sizeof(
int)*numTri);
1694 for ( i = 0; i < numTri; i++ )
1696 result = SAA_materialRelationGetT2DLocNbElements( scene,
1697 &materials[i], FALSE, &relinfo, &numTexTri[i] );
1700 if ( result == SI_SUCCESS )
1701 numTexLoc += numTexTri[i];
1711 textures = (SAA_Elem *)malloc(
sizeof(SAA_Elem)*numTri);
1713 for ( i = 0; i < numTri; i++ )
1716 SAA_materialRelationGetT2DLocElements( scene, &materials[i],
1717 TEX_PER_MAT , &textures[i] );
1721 fprintf( outStream,
"numTexLoc = %d\n", numTexLoc);
1726 SAA_modelRelationGetT2DGlbNbElements( scene, model,
1727 FALSE, &relinfo, &numTexGlb );
1732 textures = (SAA_Elem *)malloc(
sizeof(SAA_Elem));
1735 SAA_modelRelationGetT2DGlbElements( scene, model,
1736 TEX_PER_MAT, textures );
1739 fprintf( outStream,
"numTexGlb = %d\n", numTexGlb);
1744 cvertices = (SAA_SubElem *)malloc(
sizeof(SAA_SubElem)*numTri*3);
1745 if ( cvertices != NULL )
1748 SAA_triangleGetCtrlVertices( scene, model, gtype,
id,
1749 numTri, triangles, cvertices );
1753 cvertPos = (SAA_DVector *)malloc(
sizeof(SAA_DVector)*numTri*3);
1754 SAA_ctrlVertexGetPositions( scene, model, numTri*3,
1755 cvertices, cvertPos);
1757 for ( i=0; i < numTri*3; i++ )
1759 fprintf( outStream,
"cvert[%d] = %f %f %f %f\n", i,
1760 cvertPos[i].x, cvertPos[i].y, cvertPos[i].z,
1766 fprintf( outStream,
"Not enough Memory for control vertices...\n");
1771 indices = (
int *)malloc(
sizeof(
int)*numTri*3);
1772 if ( indices != NULL )
1774 for ( i=0; i < numTri*3; i++ )
1777 SAA_ctrlVertexGetIndices( scene, model, numTri*3,
1778 cvertices, indices );
1781 for ( i=0; i < numTri*3; i++ )
1782 fprintf( outStream,
"indices[%d] = %d\n", i, indices[i] );
1785 fprintf( outStream,
"Not enough Memory for indices...\n");
1788 SAA_modelGetNbTriVertices( scene, model, &numVert );
1791 fprintf( outStream,
"num unique verts = %d\n", numVert );
1794 vertices = (SAA_DVector *)malloc(
sizeof(SAA_DVector)*numVert);
1797 SAA_modelGetTriVertices( scene, model, numVert, vertices );
1801 for ( i=0; i < numVert; i++ )
1803 fprintf( outStream,
"vertices[%d] = %f ", i, vertices[i].x );
1804 fprintf( outStream,
"%f %f %f\n", vertices[i].y,
1805 vertices[i].z, vertices[i].w );
1813 indexMap = MakeIndexMap( indices, numTri*3, numVert );
1816 normals = (SAA_DVector *)malloc(
sizeof(SAA_DVector)*numTri*3);
1817 if ( normals != NULL )
1820 SAA_ctrlVertexGetNormals( scene, model, numTri*3,
1821 cvertices, normals );
1824 fprintf( outStream,
"Not enough Memory for normals...\n");
1828 for ( i=0; i<numTri*3; i++ )
1829 fprintf( outStream,
"normals[%d] = %f %f %f %f\n", i,
1830 normals[i].x, normals[i].y, normals[i].z, normals[i].w );
1833 int uRepeat, vRepeat;
1839 uCoords = (
float *)malloc(
sizeof(
float)*numTri*numTexLoc*3);
1840 vCoords = (
float *)malloc(
sizeof(
float)*numTri*numTexLoc*3);
1843 if ( uCoords != NULL && vCoords != NULL)
1845 for ( i = 0; i < numTri*numTexLoc*3; i++ )
1846 uCoords[i] = vCoords[i] = 0.0f;
1848 SAA_ctrlVertexGetUVTxtCoords( scene, model, numTri*3,
1849 cvertices, numTexLoc*3, uCoords, vCoords );
1852 fprintf( outStream,
"Not enough Memory for texture coords...\n");
1856 for ( i=0; i<numTexLoc*3; i++ )
1857 fprintf( outStream,
"texcoords[%d] = ( %f , %f )\n", i,
1858 uCoords[i], vCoords[i] );
1862 uScale = (
float *)malloc(
sizeof(
float)*numTri);
1863 vScale = (
float *)malloc(
sizeof(
float)*numTri);
1864 uOffset = (
float *)malloc(
sizeof(
float)*numTri);
1865 vOffset = (
float *)malloc(
sizeof(
float)*numTri);
1866 texNameArray = (
char **)malloc(
sizeof(
char *)*numTri);
1868 for ( i = 0; i < numTri; i++ )
1871 texNameArray[i] = NULL;
1873 SAA_Boolean valid = FALSE;
1875 result = SAA_elementIsValid( scene, &textures[i], &valid );
1877 if ( result != SI_SUCCESS )
1878 fprintf( outStream,
"SAA_elementIsValid failed!!!!\n" );
1883 texNameArray[i] = ConvertTexture( scene, &textures[i] );
1886 fprintf( outStream,
" tritex[%d] named: %s\n", i,
1889 SAA_texture2DGetUVSwap( scene, &textures[i], &uv_swap );
1892 if ( uv_swap == TRUE )
1893 fprintf( outStream,
" swapping u and v...\n" );
1895 SAA_texture2DGetUScale( scene, &textures[i], &uScale[i] );
1896 SAA_texture2DGetVScale( scene, &textures[i], &vScale[i] );
1897 SAA_texture2DGetUOffset( scene, &textures[i], &uOffset[i] );
1898 SAA_texture2DGetVOffset( scene, &textures[i], &vOffset[i] );
1902 fprintf(outStream,
"tritex[%d] uScale: %f vScale: %f\n", i, uScale[i], vScale[i] );
1903 fprintf(outStream,
" uOffset: %f vOffset: %f\n",
1904 uOffset[i], vOffset[i] );
1908 SAA_texture2DGetRepeats( scene, &textures[i], &uRepeat,
1913 fprintf(outStream,
"uRepeat = %d, vRepeat = %d\n",
1921 fprintf( outStream,
"Invalid texture...\n");
1922 fprintf( outStream,
" tritex[%d] named: (null)\n", i );
1938 else if ( numTexGlb )
1943 SAA_elementIsValid( scene, textures, &valid );
1948 SAA_texture2DGetUVSwap( scene, textures, &uv_swap );
1951 if ( uv_swap == TRUE )
1952 fprintf( outStream,
" swapping u and v...\n" );
1955 uCoords = (
float *)malloc(
sizeof(
float)*numTri*numTexGlb*3);
1956 vCoords = (
float *)malloc(
sizeof(
float)*numTri*numTexGlb*3);
1958 for ( i = 0; i < numTri*numTexGlb*3; i++ )
1960 uCoords[i] = vCoords[i] = 0.0f;
1964 if ( uCoords != NULL && vCoords != NULL)
1966 SAA_triCtrlVertexGetGlobalUVTxtCoords( scene, model,
1967 numTri*3, cvertices, numTexGlb, textures,
1971 fprintf( outStream,
"Not enough Memory for texture coords...\n");
1975 for ( i=0; i<numTri*numTexGlb*3; i++ )
1976 fprintf( outStream,
"texcoords[%d] = ( %f , %f )\n", i,
1977 uCoords[i], vCoords[i] );
1980 texNameArray = (
char **)malloc(
sizeof(
char *));
1981 *texNameArray = ConvertTexture( scene, textures );
1984 fprintf( outStream,
" global tex named: %s\n",
1988 uScale = (
float *)malloc(
sizeof(
float));
1989 vScale = (
float *)malloc(
sizeof(
float));
1990 uOffset = (
float *)malloc(
sizeof(
float));
1991 vOffset = (
float *)malloc(
sizeof(
float));
1993 SAA_texture2DGetUScale( scene, textures, uScale );
1994 SAA_texture2DGetVScale( scene, textures, vScale );
1995 SAA_texture2DGetUOffset( scene, textures, uOffset );
1996 SAA_texture2DGetVOffset( scene, textures, vOffset );
2000 fprintf( outStream,
" global tex uScale: %f vScale: %f\n",
2002 fprintf( outStream,
" uOffset: %f vOffset: %f\n",
2003 *uOffset, *vOffset );
2006 SAA_texture2DGetRepeats( scene, textures, &uRepeat,
2011 fprintf(outStream,
"uRepeat = %d, vRepeat = %d\n",
2015 else fprintf( outStream,
"Invalid texture...\n");
2019 EggVertexPool *pool = _data.CreateVertexPool( parent, name );
2021 for ( i = 0; i < numVert; i++ )
2027 SAA_DVector local = vertices[i];
2030 _VCT_X_MAT( global, local, matrix );
2040 eggVert.set( global.x, global.y, global.z );
2042 local = normals[indexMap[i]];
2044 _VCT_X_MAT( global, local, matrix );
2046 eggNorm.set( global.x, global.y, global.z );
2047 eggNorm.normalize();
2049 pool->AddVertex( eggVert, i );
2050 pool->Vertex(i)->attrib.SetNormal( eggNorm );
2053 if ( numTexLoc && (uCoords != NULL && vCoords !=NULL ))
2057 if ( ignore_tex_offsets ) {
2058 u = uCoords[indexMap[i]];
2059 v = 1.0f - vCoords[indexMap[i]];
2061 u = (uCoords[indexMap[i]] - uOffset[indexMap[i]/3]) /
2062 uScale[indexMap[i]/3];
2064 v = 1.0f - ((vCoords[indexMap[i]] - vOffset[indexMap[i]/3]) /
2065 vScale[indexMap[i]/3]);
2068 if ( isNum(u) && isNum(v) )
2070 if ( uv_swap == TRUE )
2071 pool->Vertex(i)->attrib.SetUV( v, u );
2073 pool->Vertex(i)->attrib.SetUV( u, v );
2076 else if ( numTexGlb && (uCoords != NULL && vCoords !=NULL ) )
2080 if ( ignore_tex_offsets ) {
2081 u = uCoords[indexMap[i]];
2082 v = 1.0f - vCoords[indexMap[i]];
2084 u = (uCoords[indexMap[i]] - *uOffset) / *uScale;
2085 v = 1.0f - (( vCoords[indexMap[i]] - *vOffset ) / *vScale);
2088 if ( isNum(u) && isNum(v) )
2090 if ( uv_swap == TRUE )
2091 pool->Vertex(i)->attrib.SetUV( v, u );
2093 pool->Vertex(i)->attrib.SetUV( u, v );
2099 if (( numTexLoc || numTexGlb ) && make_duv )
2111 SAA_elementGetNbExpressions( scene, tex, NULL, FALSE,
2119 strstream uName, vName;
2122 uName << name <<
".u" << ends;
2123 vName << name <<
".v" << ends;
2131 if ( morphRoot == NULL )
2132 morphRoot = animData.CreateTable( animRoot,
2136 SAnimTable *uTable =
new SAnimTable( );
2137 uTable->name = uName.str();
2138 uTable->fps = anim_rate;
2139 morphRoot->children.push_back( uTable );
2141 fprintf( outStream,
"created duv table named: %s\n", uName.str() );
2143 SAnimTable *vTable =
new SAnimTable( );
2144 vTable->name = vName.str();
2145 vTable->fps = anim_rate;
2146 morphRoot->children.push_back( vTable );
2148 fprintf( outStream,
"created duv table named: %s\n", vName.str() );
2150 float texOffsets[4];
2154 texOffsets[0] = *uOffset;
2155 texOffsets[1] = *vOffset;
2156 texOffsets[2] = *uScale;
2157 texOffsets[3] = *vScale;
2161 texOffsets[0] = uOffset[indexMap[i]/3];
2162 texOffsets[1] = vOffset[indexMap[i]/3];
2163 texOffsets[2] = uScale[indexMap[i]/3];
2164 texOffsets[3] = vScale[indexMap[i]/3];
2168 SAA_elementSetUserData( scene, model,
"TEX_OFFSETS",
2169 sizeof( texOffsets ), TRUE, (
void **)&texOffsets );
2172 EggMorphOffset *duvU;
2173 EggMorphOffset *duvV;
2176 duvU =
new EggMorphOffset( uName.str(), 1.0 , 0.0 );
2177 pool->Vertex(i)->attrib.uv_morphs.push_back( *duvU );
2179 duvV =
new EggMorphOffset( vName.str(), 0.0 , 1.0 );
2180 pool->Vertex(i)->attrib.uv_morphs.push_back( *duvV );
2189 if ( has_morph && make_morph )
2190 MakeVertexOffsets( scene, model, type, numShapes, numVert,
2191 vertices, matrix, name );
2197 vref =
new EggVertexRef( pool);
2198 for ( i = 0; i < numVert; i++ )
2201 vref->indices.push_back( EggVertexIndex( i ) );
2221 EggGroup *group = _data.CreateGroup( parent, name);
2227 EggColor *cref = NULL;
2231 for ( i = 0; i < numTri*3; i+=3 )
2238 poly = _data.CreatePolygon( group, pool );
2239 poly->AddVertex(indices[i]);
2240 poly->AddVertex(indices[i+1]);
2241 poly->AddVertex(indices[i+2]);
2244 char *modelNoteStr = GetModelNoteInfo( scene, model );
2246 if ( modelNoteStr != NULL )
2248 if ( strstr( modelNoteStr,
"bface" ) != NULL )
2249 poly->flags |= EG_BFACE;
2254 SAA_elementIsValid( scene, &materials[i/3], &valid );
2259 SAA_materialGetDiffuse( scene, &materials[i/3], &r, &g, &b );
2260 SAA_materialGetTransparency( scene, &materials[i/3], &a );
2261 color.set( r, g, b, 1.0f - a );
2265 color.set( 1.0, 1.0, 1.0, 1.0 );
2267 cref = _data.CreateColor(color);
2268 poly->attrib.SetCRef(cref);
2270 strstream uniqueTexName;
2275 if ( (texNameArray[i/3] != NULL) &&
2276 (strcmp(texNameArray[i/3],
"NULL") != 0) )
2280 uniqueTexName << name <<
"-" 2281 << RemovePathName(texNameArray[i/3]);
2283 tref = _data.CreateTexture( texNameArray[i/3],
2284 uniqueTexName.str() );
2287 fprintf( outStream,
" tritex[%d] named: %s\n", i/3,
2288 texNameArray[i/3] );
2291 else if ( numTexGlb )
2293 if ( texNameArray != NULL )
2297 uniqueTexName << name <<
"-" 2298 << RemovePathName(*texNameArray);
2300 tref = _data.CreateTexture( *texNameArray,
2301 uniqueTexName.str() );
2304 fprintf( outStream,
" tritex named: %s\n",
2313 tref->wrapu = EggTexture::WM_repeat;
2315 tref->wrapu = EggTexture::WM_clamp;
2318 tref->wrapv = EggTexture::WM_repeat;
2320 tref->wrapv = EggTexture::WM_clamp;
2322 poly->attrib.SetTRef(tref);
2328 SAA_modelClearTriangles( scene, model );
2340 if (numTexLoc || numTexGlb)
2358 if ( (type == SAA_MNSRF) && ( visible ) && (( make_nurbs )
2359 || ( !make_nurbs && !make_poly && make_duv )) )
2362 SAA_Boolean isSkeleton = FALSE;
2364 SAA_modelIsSkeleton( scene, model, &isSkeleton );
2370 if ( isSkeleton || (strstr( name,
"joint" ) != NULL) )
2372 MakeJoint( scene, lastJoint, lastAnim, model, name );
2375 fprintf( outStream,
"animating NURBS as joint!!!\n" );
2379 int uDegree, vDegree;
2382 SAA_nurbsSurfaceGetDegree( scene, model, &uDegree, &vDegree );
2383 eggNurbsSurf->u_order = uDegree + 1;
2384 eggNurbsSurf->v_order = vDegree + 1;
2387 fprintf( outStream,
"nurbs degree: %d u, %d v\n",
2389 fprintf( outStream,
"nurbs order: %d u, %d v\n",
2390 uDegree + 1, vDegree + 1 );
2393 SAA_Boolean uClosed = FALSE;
2394 SAA_Boolean vClosed = FALSE;
2396 SAA_nurbsSurfaceGetClosed( scene, model, &uClosed, &vClosed);
2401 fprintf( outStream,
"nurbs is closed in u...\n");
2403 fprintf( outStream,
"nurbs is closed in v...\n");
2407 SAA_nurbsSurfaceGetNbVertices( scene, model, &uRows, &vRows );
2409 fprintf( outStream,
"nurbs vertices: %d u, %d v\n",
2412 int uCurves, vCurves;
2413 SAA_nurbsSurfaceGetNbCurves( scene, model, &uCurves, &vCurves );
2415 fprintf( outStream,
"nurbs curves: %d u, %d v\n",
2418 if ( shift_textures )
2422 SAA_nurbsSurfaceShiftParameterization( scene, model, -2, 0 );
2426 SAA_nurbsSurfaceShiftParameterization( scene, model, 0, -2 );
2429 SAA_nurbsSurfaceSetStep( scene, model, nurbs_step, nurbs_step );
2432 char *modelNoteStr = GetModelNoteInfo( scene, model );
2434 if ( modelNoteStr != NULL )
2436 if ( strstr( modelNoteStr,
"bface" ) != NULL )
2437 eggNurbsSurf->flags |= EG_BFACE;
2440 int numKnotsU, numKnotsV;
2442 SAA_nurbsSurfaceGetNbKnots( scene, model, &numKnotsU, &numKnotsV );
2444 fprintf( outStream,
"nurbs knots: %d u, %d v\n",
2445 numKnotsU, numKnotsV );
2447 double *knotsU, *knotsV;
2448 knotsU = (
double *)malloc(
sizeof(
double)*numKnotsU);
2449 knotsV = (
double *)malloc(
sizeof(
double)*numKnotsV);
2450 SAA_nurbsSurfaceGetKnots( scene, model, gtype, 0,
2451 numKnotsU, numKnotsV, knotsU, knotsV );
2454 fprintf( outStream,
"u knots:\n" );
2456 AddKnots( eggNurbsSurf->u_knots, knotsU, numKnotsU, uClosed, uDegree );
2458 fprintf( outStream,
"v knots:\n" );
2460 AddKnots( eggNurbsSurf->v_knots, knotsV, numKnotsV, vClosed, vDegree);
2466 eggNurbsSurf->u_subdiv = (uRows-1)*nurbs_step;
2467 eggNurbsSurf->v_subdiv = (vRows-1)*nurbs_step;
2469 SAA_modelGetNbVertices( scene, model, &numVert );
2472 fprintf( outStream,
"%d CV's\n", numVert );
2475 vertices = (SAA_DVector *)malloc(
sizeof(SAA_DVector)*numVert);
2476 SAA_modelGetVertices( scene, model, gtype, 0,
2477 numVert, vertices );
2480 EggVertexPool *pool = _data.CreateVertexPool( parent, name );
2481 eggNurbsSurf->SetVertexPool( pool );
2486 vref =
new EggVertexRef( pool);
2488 for (
int k = 0; k<numVert; k++ )
2492 fprintf( outStream,
"original cv[%d] = %f %f %f %f\n", k,
2493 vertices[k].x, vertices[k].y, vertices[k].z,
2502 _VCT_X_MAT( global, vertices[k], matrix );
2505 global.w = vertices[k].w;
2508 global.x *= global.w;
2509 global.y *= global.w;
2510 global.z *= global.w;
2534 fprintf( outStream,
"global cv[%d] = %f %f %f %f\n", k,
2535 global.x, global.y, global.z,
2539 eggVert.set( global.x, global.y, global.z,
2543 pool->AddVertex( eggVert, k );
2546 eggNurbsSurf->AddVertex( k );
2549 vref->indices.push_back( EggVertexIndex( k ) );
2555 if ( (k % uRows) == ( uRows - 1) )
2556 for (
int i = 0; i < uDegree; i++ )
2559 eggNurbsSurf->AddVertex( i+((k/uRows)*uRows) );
2562 vref->indices.push_back(
2563 EggVertexIndex( i+((k/uRows)*uRows) ) );
2586 if ( vClosed && !uClosed )
2589 for (
int i = 0; i < vDegree*uRows; i++ )
2590 eggNurbsSurf->AddVertex( i );
2593 else if ( vClosed && uClosed )
2597 for ( i = 0; i < vDegree; i++ )
2600 for ( j = 0; j < uRows; j++ )
2601 eggNurbsSurf->AddVertex( j+(i*uRows) );
2605 for ( k = 0; k < uDegree; k++ )
2606 eggNurbsSurf->AddVertex( k+(i*uRows)+((k/uRows)*uRows) );
2616 SAA_modelRelationGetMatNbElements( scene, model, FALSE, &relinfo,
2620 fprintf( outStream,
"nurbs surf has %d materials\n",
2627 materials = (SAA_Elem *)malloc(
sizeof(SAA_Elem)*numNurbMats);
2629 SAA_modelRelationGetMatElements( scene, model, relinfo,
2630 numNurbMats, materials );
2632 SAA_materialGetDiffuse( scene, &materials[0], &r, &g, &b );
2633 SAA_materialGetTransparency( scene, &materials[0], &a );
2634 nurbColor.set( r, g, b, 1.0f - a );
2637 nurbCref = _data.CreateColor(nurbColor);
2638 eggNurbsSurf->attrib.SetCRef(nurbCref);
2641 int numNurbTexLoc = 0;
2642 int numNurbTexGlb = 0;
2649 SAA_materialRelationGetT2DLocNbElements( scene, &materials[0],
2650 FALSE, &relinfo, &numNurbTexLoc );
2653 if ( numNurbTexLoc )
2656 fprintf( outStream,
"%s had %d local tex\n", name,
2660 SAA_materialRelationGetT2DLocElements( scene, &materials[0],
2661 TEX_PER_MAT, &nurbTex );
2667 SAA_modelRelationGetT2DGlbNbElements( scene, model,
2668 FALSE, &relinfo, &numNurbTexGlb );
2670 if ( numNurbTexGlb )
2673 fprintf( outStream,
"%s had %d global tex\n", name,
2677 SAA_modelRelationGetT2DGlbElements( scene,
2678 model, TEX_PER_MAT, &nurbTex );
2683 if ( numNurbTexLoc || numNurbTexGlb)
2685 char *texName = NULL;
2686 char *uniqueTexName = NULL;
2688 pfMatrix nurbTexMat;
2692 texName = ConvertTexture( scene, &nurbTex );
2696 uniqueTexName = (
char *)malloc(
sizeof(
char)*
2697 (strlen(name)+strlen(texName)+3) );
2698 sprintf( uniqueTexName,
"%s-%s", name,
2699 RemovePathName(texName) );
2703 fprintf( outStream,
"creating tref %s\n",
2707 tref = _data.CreateTexture( texName, uniqueTexName );
2709 uScale = (
float *)malloc(
sizeof(
float));
2710 vScale = (
float *)malloc(
sizeof(
float));
2711 uOffset = (
float *)malloc(
sizeof(
float));
2712 vOffset = (
float *)malloc(
sizeof(
float));
2715 SAA_texture2DGetUScale( scene, &nurbTex, uScale );
2716 SAA_texture2DGetVScale( scene, &nurbTex, vScale );
2717 SAA_texture2DGetUOffset( scene, &nurbTex, uOffset );
2718 SAA_texture2DGetVOffset( scene, &nurbTex, vOffset );
2719 SAA_texture2DGetUVSwap( scene, &nurbTex, &uv_swap );
2724 fprintf( outStream,
"nurbTex uScale: %f\n", *uScale );
2725 fprintf( outStream,
"nurbTex vScale: %f\n", *vScale );
2726 fprintf( outStream,
"nurbTex uOffset: %f\n", *uOffset );
2727 fprintf( outStream,
"nurbTex vOffset: %f\n", *vOffset );
2729 fprintf( outStream,
"nurbTex u & v swapped!\n" );
2731 fprintf( outStream,
"nurbTex u & v NOT swapped\n" );
2734 nurbTexMat.makeIdent();
2736 if ( !ignore_tex_offsets )
2740 nurbTexMat[0][0] = 0.0f;
2741 nurbTexMat[1][1] = 0.0f;
2742 nurbTexMat[0][1] = 1 / *vScale;
2743 nurbTexMat[1][0] = 1 / *uScale;
2744 nurbTexMat[2][1] = -(*uOffset / *uScale);
2745 nurbTexMat[2][0] = -(*vOffset / *vScale);
2749 nurbTexMat[0][0] = 1 / *uScale;
2750 nurbTexMat[1][1] = 1 / *vScale;
2751 nurbTexMat[2][0] = -(*uOffset / *uScale);
2752 nurbTexMat[2][1] = -(*vOffset / *vScale);
2760 fprintf( outStream,
"nurb tex matrix = %f %f %f %f\n", nurbTexMat[0][0],
2761 nurbTexMat[0][1], nurbTexMat[0][2], nurbTexMat[0][3] );
2762 fprintf( outStream,
"nurb tex matrix = %f %f %f %f\n", nurbTexMat[1][0],
2763 nurbTexMat[1][1], nurbTexMat[1][2], nurbTexMat[1][3] );
2764 fprintf( outStream,
"nurb tex matrix = %f %f %f %f\n", nurbTexMat[2][0],
2765 nurbTexMat[2][1], nurbTexMat[2][2], nurbTexMat[2][3] );
2766 fprintf( outStream,
"nurb tex matrix = %f %f %f %f\n", nurbTexMat[3][0],
2767 nurbTexMat[3][1], nurbTexMat[3][2], nurbTexMat[3][3] );
2771 tref->tex_mat = nurbTexMat;
2772 tref->flags |= EFT_TRANSFORM;
2774 eggNurbsSurf->attrib.SetTRef(tref);
2779 if (( numNurbTexLoc || numNurbTexGlb ) && make_duv )
2784 SAA_elementGetNbExpressions( scene, &nurbTex, NULL, FALSE,
2791 printf(
"nurbTex has %d expressions...\n", numExp );
2795 strstream uName, vName;
2798 uName << name <<
".u" << ends;
2799 vName << name <<
".v" << ends;
2802 if ( morphRoot == NULL )
2803 morphRoot = animData.CreateTable( animRoot,
2807 SAnimTable *uTable =
new SAnimTable( );
2808 uTable->name = uName.str();
2809 uTable->fps = anim_rate;
2810 morphRoot->children.push_back( uTable );
2812 fprintf( outStream,
"created duv table named: %s\n", uName.str() );
2814 SAnimTable *vTable =
new SAnimTable( );
2815 vTable->name = vName.str();
2816 vTable->fps = anim_rate;
2817 morphRoot->children.push_back( vTable );
2819 fprintf( outStream,
"created duv table named: %s\n", vName.str() );
2821 float texOffsets[4];
2823 texOffsets[0] = *uOffset;
2824 texOffsets[1] = *vOffset;
2825 texOffsets[2] = *uScale;
2826 texOffsets[3] = *vScale;
2829 SAA_elementSetUserData( scene, model,
"TEX_OFFSETS",
2830 sizeof( texOffsets ), TRUE, (
void **)&texOffsets );
2833 for( i = 0; i < numVert; i++ )
2836 EggMorphOffset *duvU;
2837 EggMorphOffset *duvV;
2840 eggNurbsSurf->CalcActualUV( i, tmpUV );
2841 pool->Vertex(i)->attrib.SetUV( tmpUV[0], tmpUV[1] );
2844 duvU =
new EggMorphOffset(uName.str(), 1.0 , 0.0);
2845 pool->Vertex(i)->attrib.uv_morphs.push_back(*duvU);
2847 duvV =
new EggMorphOffset(vName.str(), 0.0 , 1.0);
2848 pool->Vertex(i)->attrib.uv_morphs.push_back(*duvV);
2864 nurbColor.set( 1.0, 1.0, 1.0, 1.0 );
2874 SAA_nurbsSurfaceGetNbTrimCurves( scene, model, SAA_TRIMTYPE_TRIM,
2878 fprintf( outStream,
"nurbs surf has %d trim curves\n",
2883 trims = (SAA_SubElem *)malloc(
sizeof(SAA_SubElem)*numTrims);
2887 SAA_nurbsSurfaceGetTrimCurves( scene, model,
2888 gtype, 0, SAA_TRIMTYPE_TRIM, numTrims,
2891 MakeSurfaceCurve( scene, model, parent, eggNurbsSurf,
2892 numTrims, trims, isTrim );
2903 SAA_nurbsSurfaceGetNbTrimCurves( scene, model,
2904 SAA_TRIMTYPE_PROJECTION, &numTrims );
2907 fprintf( outStream,
"nurbs surf has %d surface curves\n",
2912 trims = (SAA_SubElem *)malloc(
sizeof(SAA_SubElem)*numTrims);
2916 SAA_nurbsSurfaceGetTrimCurves( scene, model,
2917 gtype, 0, SAA_TRIMTYPE_PROJECTION,
2920 MakeSurfaceCurve( scene, model, parent, eggNurbsSurf,
2921 numTrims, trims, isTrim );
2928 parent->children.push_back( eggNurbsSurf );
2931 if ( has_morph && make_morph )
2932 MakeVertexOffsets( scene, model, type, numShapes, numVert,
2933 vertices, matrix, name );
2942 else if ( (type == SAA_MNCRV) && ( visible ) && ( make_nurbs ) )
2949 else if ( type == SAA_MJNT )
2951 MakeJoint( scene, lastJoint, lastAnim, model, name );
2953 fprintf( outStream,
"encountered IK joint: %s\n", name );
2960 SAA_AlgorithmType algo;
2962 SAA_modelGetAlgorithm( scene, model, &algo );
2964 fprintf( outStream,
"null algorithm: %d\n", algo );
2966 if ( algo == SAA_ALG_INV_KIN )
2968 MakeJoint( scene, lastJoint, lastAnim, model, name );
2970 fprintf( outStream,
"encountered IK root: %s\n", name );
2972 else if ( algo == SAA_ALG_INV_KIN_LEAF )
2974 MakeJoint( scene, lastJoint, lastAnim, model, name );
2976 fprintf( outStream,
"encountered IK leaf: %s\n", name );
2978 else if ( algo == SAA_ALG_STANDARD )
2980 SAA_Boolean isSkeleton = FALSE;
2983 fprintf( outStream,
"encountered Standard null: %s\n", name);
2985 SAA_modelIsSkeleton( scene, model, &isSkeleton );
2991 if ( isSkeleton || (strstr( name,
"joint" ) != NULL) )
2993 MakeJoint( scene, lastJoint, lastAnim, model, name );
2995 fprintf( outStream,
"animating Standard null!!!\n" );
3001 fprintf( outStream,
"encountered some other NULL: %d\n",
3012 SAA_modelGetNbChildren( scene, model, &numChildren );
3014 fprintf( outStream,
"Model children: %d\n", numChildren );
3018 children = (SAA_Elem *)malloc(
sizeof(SAA_Elem)*numChildren);
3019 SAA_modelGetChildren( scene, model, numChildren, children );
3020 if ( children != NULL )
3022 for ( thisChild = 0; thisChild < numChildren; thisChild++ )
3025 fprintf( outStream,
"\negging child %d...\n", thisChild);
3026 MakeEgg( parent, lastJoint, lastAnim, scene,
3027 &children[thisChild] );
3031 fprintf( outStream,
"Not enough Memory for children...\n");
3034 fflush( outStream );
3038 fprintf( outStream,
"Don't descend this branch!\n" );
3052 MakeSurfaceCurve( SAA_Scene *scene, SAA_Elem *model,
EggGroup *parent,
3057 long totalSamples = 0;
3061 SAA_Elem *trimCurves;
3065 numSamples = (
long *)malloc(
sizeof(
long)*numTrims);
3067 SAA_surfaceCurveGetNbLinearSamples( scene, model, numTrims, trims,
3070 for ( i = 0; i < numTrims; i++ )
3072 totalSamples += numSamples[i];
3074 fprintf( outStream,
"numSamples[%d] = %d\n", i, numSamples[i] );
3078 fprintf( outStream,
"total samples = %ld\n", totalSamples );
3080 uSamples = (
double *)malloc(
sizeof(
double)*totalSamples);
3081 vSamples = (
double *)malloc(
sizeof(
double)*totalSamples);
3083 SAA_surfaceCurveGetLinearSamples( scene, model, numTrims, trims,
3084 numSamples, uSamples, vSamples );
3087 for (
long li = 0; li < totalSamples; li++ )
3088 fprintf( outStream,
"master list cv[%ld] = %f, %f\n", li,
3089 uSamples[li], vSamples[li] );
3091 trimCurves = (SAA_Elem *)malloc(
sizeof(SAA_Elem)*numTrims);
3093 SAA_surfaceCurveExtract( scene, model, numTrims, trims, trimCurves );
3100 for ( i = 0; i < numTrims; i++ )
3105 name = GetFullName( scene, &trimCurves[i] );
3110 name = GetName( scene, &trimCurves[i] );
3117 eggLoop->push_back( MakeUVNurbsCurve( i, numSamples, uSamples,
3118 vSamples, parent, name ) );
3119 eggTrim->push_back( *eggLoop );
3123 nurbsSurf->curves.push_back( MakeUVNurbsCurve( i, numSamples, uSamples, vSamples, parent, name ) );
3128 nurbsSurf->trims.push_back( *eggTrim );
3143 MakeUVNurbsCurve(
int numCurve,
long *numSamples,
double *uSamples,
3144 double *vSamples,
EggGroup *parent,
char *name )
3148 eggNurbsCurve->order = 2;
3152 fprintf( outStream,
"nurbs UV curve %s:\n", name );
3157 eggNurbsCurve->subdiv = 150;
3160 EggVertexPool *pool = _data.CreateVertexPool( parent, name );
3161 eggNurbsCurve->SetVertexPool( pool );
3167 for (
int o = 0; o < numCurve; o++ )
3168 offset += numSamples[o];
3170 for (
int k = 0; k<numSamples[numCurve]; k++ )
3175 eggVert.set( uSamples[k+offset], vSamples[k+offset], 1.0f );
3178 fprintf( outStream,
"cv[%d] = %f %f %f\n", k, eggVert[0],
3179 eggVert[1], eggVert[2] );
3182 pool->AddVertex( eggVert, k );
3185 eggNurbsCurve->AddVertex( k );
3189 eggNurbsCurve->knots.push_back( 0 );
3190 for ( k = 0; k < numSamples[numCurve]; k++ )
3191 eggNurbsCurve->knots.push_back( k );
3192 eggNurbsCurve->knots.push_back( numSamples[numCurve] - 1 );
3198 nurbColor.set( 0.5, 1.0, 0.5, 1.0 );
3199 nurbCref = _data.CreateColor(nurbColor);
3200 eggNurbsCurve->attrib.SetCRef(nurbCref);
3202 return( eggNurbsCurve );
3212 MakeNurbsCurve( SAA_Scene *scene, SAA_Elem *model,
EggGroup *parent,
3213 float matrix[4][4],
char *name )
3219 fprintf( outStream,
"nurbs curve %s:\n", name );
3222 SAA_nurbsCurveGetDegree( scene, model, °ree );
3223 eggNurbsCurve->order = degree + 1;
3225 fprintf( outStream,
"nurbs curve order: %d\n", degree + 1 );
3227 SAA_nurbsCurveSetStep( scene, model, nurbs_step );
3229 SAA_Boolean closed = FALSE;
3231 SAA_nurbsCurveGetClosed( scene, model, &closed );
3234 fprintf( outStream,
"nurbs curve is closed...\n");
3238 SAA_nurbsCurveGetNbKnots( scene, model, &numKnots );
3240 fprintf( outStream,
"nurbs curve knots: %d\n", numKnots );
3242 knots = (
double *)malloc(
sizeof(
double)*numKnots);
3243 SAA_nurbsCurveGetKnots( scene, model, SAA_GEOM_ORIGINAL, 0,
3246 AddKnots( eggNurbsCurve->knots, knots, numKnots, closed, degree );
3252 SAA_modelGetNbVertices( scene, model, &numCV );
3254 fprintf( outStream,
"%d CV's (=? %d)\n", numCV, (numKnots-(degree+1)) );
3257 eggNurbsCurve->subdiv = (numCV-1)*nurbs_step;
3260 SAA_DVector *cvArray;
3261 cvArray = (SAA_DVector *)malloc(
sizeof(SAA_DVector)*numCV);
3262 SAA_modelGetVertices( scene, model, SAA_GEOM_ORIGINAL, 0,
3266 EggVertexPool *pool = _data.CreateVertexPool( parent, name );
3267 eggNurbsCurve->SetVertexPool( pool );
3269 for (
int k = 0; k<numCV; k++ )
3272 fprintf( outStream,
"cv[%d] = %f %f %f %f\n", k, cvArray[k].x,
3273 cvArray[k].y, cvArray[k].z, cvArray[k].w );
3278 SAA_DVector local = cvArray[k];
3281 _HVCT_X_MAT( global, local, matrix );
3283 eggVert.set( global.x, global.y, global.z, global.w );
3286 pool->AddVertex( eggVert, k );
3289 eggNurbsCurve->AddVertex( k );
3295 for ( k = 0; k < degree; k++ )
3297 eggNurbsCurve->AddVertex( k );
3299 fprintf( outStream,
"adding cv[%d] = %f %f %f %f\n", k,
3300 cvArray[k].x, cvArray[k].y, cvArray[k].z, cvArray[k].w );
3310 nurbColor.set( 0.5, 1.0, 0.5, 1.0 );
3311 nurbCref = _data.CreateColor(nurbColor);
3312 eggNurbsCurve->attrib.SetCRef(nurbCref);
3314 return( eggNurbsCurve );
3325 AddKnots( perf_vector<double> &eggKnots,
double *knots,
int numKnots,
3326 SAA_Boolean closed,
int degree )
3329 double lastKnot = knots[0];
3336 newKnots = (
double *)malloc(
sizeof(
double)*degree);
3339 for ( k = numKnots - 1; k >= numKnots - degree; k-- )
3343 newKnots[i] = lastKnot - (knots[k] - knots[k-1]);
3344 lastKnot = newKnots[i];
3347 for ( k = degree - 1; k >= 0; k-- )
3349 eggKnots.push_back( newKnots[k] );
3351 fprintf( outStream,
"knots[%d] = %f\n", k, newKnots[k] );
3358 eggKnots.push_back( knots[k] );
3360 fprintf( outStream,
"knots[%d] = %f\n", k, knots[k] );
3364 for (k = 0; k < numKnots; k++)
3366 eggKnots.push_back( knots[k] );
3368 fprintf( outStream,
"knots[%d] = %f\n", k+1, knots[k] );
3371 lastKnot = knots[numKnots-1];
3378 for ( k = 1; k <= degree; k++ )
3380 eggKnots.push_back( lastKnot + (knots[k] - knots[k-1]) );
3382 fprintf( outStream,
"knots[%d] = %f\n", k,
3383 lastKnot + (knots[k] - knots[k-1]) );
3384 lastKnot = lastKnot + (knots[k] - knots[k-1]);
3389 eggKnots.push_back( knots[k-1] );
3391 fprintf( outStream,
"knots[%d] = %f\n", k+1, knots[k-1] );
3402 MakeJoint( SAA_Scene *scene, EggJoint *&lastJoint,
AnimGroup *&lastAnim,
3403 SAA_Elem *model,
char *name )
3408 SAA_Boolean globalFlag = FALSE;
3409 int scale_joint = 0;
3415 if (lastJoint != NULL)
3417 if ( strstr( lastJoint->name.Str(),
"scale" ) != NULL )
3421 fprintf( outStream,
"scale joint flag set!\n" );
3427 if ( (lastJoint != NULL) && !flatten && !scale_joint )
3431 fprintf( outStream,
"lastJoint = %s\n", lastJoint->name.Str() );
3432 fprintf( outStream,
"getting local transform\n" );
3435 SAA_elementSetUserData( scene, model,
"GLOBAL",
sizeof( SAA_Boolean ),
3436 TRUE, (
void **)&globalFlag );
3439 SAA_modelGetMatrix( scene, model, SAA_COORDSYS_LOCAL, matrix );
3442 Matrix[0][0] = matrix[0][0];
3443 Matrix[0][1] = matrix[0][1];
3444 Matrix[0][2] = matrix[0][2];
3445 Matrix[0][3] = matrix[0][3];
3446 Matrix[1][0] = matrix[1][0];
3447 Matrix[1][1] = matrix[1][1];
3448 Matrix[1][2] = matrix[1][2];
3449 Matrix[1][3] = matrix[1][3];
3450 Matrix[2][0] = matrix[2][0];
3451 Matrix[2][1] = matrix[2][1];
3452 Matrix[2][2] = matrix[2][2];
3453 Matrix[2][3] = matrix[2][3];
3454 Matrix[3][0] = matrix[3][0];
3455 Matrix[3][1] = matrix[3][1];
3456 Matrix[3][2] = matrix[3][2];
3457 Matrix[3][3] = matrix[3][3];
3459 joint = _data.CreateJoint( lastJoint, name );
3460 joint->transform = Matrix;
3466 fprintf( outStream,
"getting global transform\n" );
3470 SAA_elementSetUserData( scene, model,
"GLOBAL",
sizeof( SAA_Boolean ),
3471 TRUE, (
void *)&globalFlag );
3474 SAA_modelGetMatrix( scene, model, SAA_COORDSYS_GLOBAL, matrix );
3477 Matrix[0][0] = matrix[0][0];
3478 Matrix[0][1] = matrix[0][1];
3479 Matrix[0][2] = matrix[0][2];
3480 Matrix[0][3] = matrix[0][3];
3481 Matrix[1][0] = matrix[1][0];
3482 Matrix[1][1] = matrix[1][1];
3483 Matrix[1][2] = matrix[1][2];
3484 Matrix[1][3] = matrix[1][3];
3485 Matrix[2][0] = matrix[2][0];
3486 Matrix[2][1] = matrix[2][1];
3487 Matrix[2][2] = matrix[2][2];
3488 Matrix[2][3] = matrix[2][3];
3489 Matrix[3][0] = matrix[3][0];
3490 Matrix[3][1] = matrix[3][1];
3491 Matrix[3][2] = matrix[3][2];
3492 Matrix[3][3] = matrix[3][3];
3495 fprintf( outStream,
"attaching orphan chain to root\n" );
3497 joint = _data.CreateJoint( rootJnt, name );
3498 joint->transform = Matrix;
3499 lastAnim = rootAnim;
3506 fprintf( outStream,
"getting global transform\n" );
3510 SAA_elementSetUserData( scene, model,
"GLOBAL",
sizeof( SAA_Boolean ),
3511 TRUE, (
void *)&globalFlag );
3514 SAA_modelGetMatrix( scene, model, SAA_COORDSYS_GLOBAL, matrix );
3517 Matrix[0][0] = matrix[0][0];
3518 Matrix[0][1] = matrix[0][1];
3519 Matrix[0][2] = matrix[0][2];
3520 Matrix[0][3] = matrix[0][3];
3521 Matrix[1][0] = matrix[1][0];
3522 Matrix[1][1] = matrix[1][1];
3523 Matrix[1][2] = matrix[1][2];
3524 Matrix[1][3] = matrix[1][3];
3525 Matrix[2][0] = matrix[2][0];
3526 Matrix[2][1] = matrix[2][1];
3527 Matrix[2][2] = matrix[2][2];
3528 Matrix[2][3] = matrix[2][3];
3529 Matrix[3][0] = matrix[3][0];
3530 Matrix[3][1] = matrix[3][1];
3531 Matrix[3][2] = matrix[3][2];
3532 Matrix[3][3] = matrix[3][3];
3534 rootJnt = _data.CreateJoint( skeleton,
"root" );
3535 rootJnt->transform.makeIdent();
3537 fprintf( outStream,
"setting skeleton root\n" );
3538 rootJnt->flags |= EF_TRANSFORM;
3540 joint = _data.CreateJoint( rootJnt, name );
3541 joint->transform = Matrix;
3544 fprintf( outStream,
"found first chain\n" );
3548 skeletonTable = animData.CreateTable( animRoot,
"<skeleton>" );
3549 rootAnim = animData.CreateTable( skeletonTable,
"root" );
3550 XfmSAnimTable *table =
new XfmSAnimTable( );
3551 table->name =
"xform";
3552 table->fps = anim_rate;
3553 rootAnim->children.push_back( table );
3554 lastAnim = rootAnim;
3557 joint->flags |= EF_TRANSFORM;
3561 AnimGroup *anim = animData.CreateTable( lastAnim, name );
3562 XfmSAnimTable *table =
new XfmSAnimTable( );
3564 fprintf( outStream,
"created anim table: %s\n",
"xform" );
3565 table->name =
"xform";
3566 table->fps = anim_rate;
3567 anim->children.push_back( table );
3584 MakeSoftSkin( SAA_Scene *scene, SAA_Elem *model, SAA_Elem *models,
3585 int numModels,
char *name )
3589 SAA_Elem *envelopes;
3592 fprintf( outStream,
"\n>found skeleton part( %s )!\n", name );
3594 SAA_skeletonGetNbEnvelopes( scene, model, &numEnv );
3600 fprintf( outStream,
"numEnv = %d\n", numEnv );
3603 envelopes = ( SAA_Elem *)malloc(
sizeof( SAA_Elem )*numEnv );
3605 if ( envelopes != NULL )
3608 SAA_EnvType envType;
3609 bool hasEnvVertices = 0;
3611 SAA_skeletonGetEnvelopes( scene, model, numEnv, envelopes );
3613 for ( thisEnv = 0; thisEnv < numEnv; thisEnv++ )
3616 fprintf( outStream,
"env[%d]: ", thisEnv );
3618 SAA_envelopeGetType( scene, &envelopes[thisEnv], &envType );
3620 if ( envType == SAA_ENVTYPE_NONE )
3623 fprintf( outStream,
"envType = none\n" );
3625 else if ( envType == SAA_ENVTYPE_FLXLCL )
3628 fprintf( outStream,
"envType = flexible, local\n" );
3631 else if ( envType == SAA_ENVTYPE_FLXGLB )
3634 fprintf( outStream,
"envType = flexible, global\n" );
3637 else if ( envType == SAA_ENVTYPE_RGDGLB )
3640 fprintf( outStream,
"envType = rigid, global\n" );
3646 fprintf( outStream,
"envType = unknown\n" );
3650 if ( hasEnvVertices)
3652 int *numEnvVertices;
3653 SAA_SubElem *envVertices = NULL;
3655 numEnvVertices = (
int *)malloc(
sizeof(
int)*numEnv);
3657 SAA_envelopeGetNbCtrlVertices( scene, model, numEnv,
3658 envelopes, numEnvVertices );
3660 if ( numEnvVertices != NULL )
3662 int totalEnvVertices = 0;
3665 for( i = 0; i < numEnv; i++ )
3667 totalEnvVertices += numEnvVertices[i];
3669 fprintf( outStream,
"numEnvVertices[%d] = %d\n",
3670 i, numEnvVertices[i] );
3675 fprintf( outStream,
"total env verts = %d\n",
3678 if ( totalEnvVertices )
3680 envVertices = (SAA_SubElem *)malloc(
sizeof(SAA_SubElem)*totalEnvVertices);
3682 if ( envVertices != NULL )
3685 SAA_envelopeGetCtrlVertices( scene, model,
3686 numEnv, envelopes, numEnvVertices, envVertices);
3689 for ( i = 0; i < numEnv; i++ )
3691 float *weights = NULL;
3692 int vertArrayOffset = 0;
3695 fprintf( outStream,
"\nenvelope[%d]:\n", i );
3697 weights = (
float *)malloc(
sizeof(
float)*numEnvVertices[i]);
3702 int *vpoolMap = NULL;
3704 for ( j = 0; j < i; j++ )
3705 vertArrayOffset += numEnvVertices[j];
3709 "envVertArray offset = %d\n",
3713 SAA_ctrlVertexGetEnvelopeWeights(
3714 scene, model, &envelopes[i],
3716 &envVertices[vertArrayOffset], weights );
3722 envName = GetFullName( scene, &envelopes[i] );
3727 envName = GetName( scene, &envelopes[i] );
3731 fprintf( outStream,
"envelope name %s\n", envName );
3738 SAA_modelGetType( scene, &envelopes[i], &type );
3742 fprintf( outStream,
"envelope model type ");
3744 if ( type == SAA_MSMSH )
3745 fprintf( outStream,
"MESH\n" );
3746 else if ( type == SAA_MNSRF )
3747 fprintf( outStream,
"NURBS\n" );
3749 fprintf( outStream,
"OTHER\n" );
3752 int *envVtxIndices = NULL;
3753 envVtxIndices = (
int *)malloc(
sizeof(
int)*numEnvVertices[i]);
3756 SAA_ctrlVertexGetIndices( scene, &envelopes[i], numEnvVertices[i],
3757 &envVertices[vertArrayOffset], envVtxIndices );
3762 SAA_modelGetNbVertices( scene, &envelopes[i], &modelNumVert );
3764 SAA_DVector *modelVertices = NULL;
3765 modelVertices = (SAA_DVector *)malloc(
sizeof(SAA_DVector)*modelNumVert);
3768 SAA_modelGetVertices( scene, &envelopes[i],
3769 SAA_GEOM_ORIGINAL, 0, modelNumVert,
3773 SAA_DVector *globalModelVertices = NULL;
3774 globalModelVertices = (SAA_DVector *)malloc(
sizeof(SAA_DVector)*modelNumVert);
3780 SAA_modelGetMatrix( scene, &envelopes[i], SAA_COORDSYS_GLOBAL, matrix );
3783 for ( j = 0; j < modelNumVert; j++ )
3785 _VCT_X_MAT( globalModelVertices[j],
3786 modelVertices[j], matrix );
3798 if ( !make_nurbs || (type == SAA_MSMSH) )
3800 vpoolMap = FindClosestTriVert( envPool,
3801 globalModelVertices, modelNumVert );
3805 if ( envPool != NULL )
3810 (EggJoint *)(skeleton->FindDescendent( name ));
3817 for (j = 0; j < numEnvVertices[i]; j++)
3819 double scaledWeight = weights[j]/ 100.0f;
3822 if (( envVtxIndices[j] < modelNumVert )
3823 && ( envVtxIndices[j] >= 0 ))
3825 if ( (type == SAA_MNSRF) && make_nurbs )
3828 joint->AddVertex( envPool->Vertex(envVtxIndices[j]), scaledWeight );
3832 "%d: adding vref to cv %d with weight %f\n",
3833 j, envVtxIndices[j], scaledWeight );
3835 envPool->Vertex(envVtxIndices[j])->AddJoint( joint, scaledWeight );
3838 envPool->Vertex(envVtxIndices[j])->multipleJoints = 1;
3844 for ( k = 0; k < envPool->NumVertices(); k++ )
3846 if ( vpoolMap[k] == envVtxIndices[j] )
3851 joint->AddVertex(envPool->Vertex(k),
3856 "%d: adding vref from cv %d to vert %d with weight %f(vpool)\n",
3857 j, envVtxIndices[j], k, scaledWeight );
3859 envPool->Vertex(k)->AddJoint( joint, scaledWeight );
3862 envPool->Vertex(k)->multipleJoints = 1;
3870 "%d: Omitted vref from cv %d with weight %f (out of range 0 to %d )\n",
3871 j, envVtxIndices[j], scaledWeight, modelNumVert );
3878 fprintf( outStream,
"Couldn't find vpool %s!\n", envName );
3891 fprintf( outStream,
"Not enough memory for envelope vertices...\n");
3896 fprintf( outStream,
"No envelope vertices present...\n");
3906 fprintf( outStream,
"Not enough memory for envelopes...\n" );
3914 fprintf( outStream,
"Skeleton member has no envelopes...\n" );
3926 CleanUpSoftSkin( SAA_Scene *scene, SAA_Elem *model,
char *name )
3928 static EggJoint *joint;
3936 SAA_modelGetType( scene, model, &type );
3940 SAA_Elem *searchNode = model;
3943 fprintf( outStream,
"\nCleaning up model %s\n", name );
3951 SAA_modelIsSkeleton( scene, model, &skel );
3958 SAA_elementGetHierarchyLevel( scene, searchNode, &level );
3963 SAA_modelGetParent( scene, searchNode, &parent );
3968 parentName = GetFullName( scene, &parent );
3973 parentName = GetName( scene, &parent );
3976 SAA_modelGetType( scene, &parent, &type );
3978 SAA_modelIsSkeleton( scene, &parent, &skel );
3981 fprintf( outStream,
"model %s, level %d, type %d, skel %d\n",
3982 parentName, level, type, skel );
3984 searchNode = &parent;
3991 fprintf( outStream,
"at root of tree! level %d\n", level );
3996 }
while ( !skel && ( strstr( parentName,
"joint") == NULL ));
3998 EggJoint *thisJoint = NULL;
4000 if ( parentName != NULL )
4004 fprintf( outStream,
"found model parent joint %s\n", parentName);
4005 fprintf( outStream,
"looking for joint %s\n", parentName );
4007 thisJoint = (EggJoint *)(skeleton->FindDescendent( parentName ));
4011 fprintf( outStream,
"Couldn't find parent joint!\n");
4013 if ( thisJoint != NULL )
4017 fprintf( outStream,
"setting joint to %s\n", parentName );
4027 int numVerts = vPool->NumVertices() ;
4031 fprintf( outStream,
"found vpool %s w/ %d verts\n",
4034 for ( i = 0; i < numVerts; i++ )
4036 if ( vPool->Vertex(i)->multipleJoints != 1 )
4040 fprintf( outStream,
"vpool %s vert %d", name, i );
4041 fprintf( outStream,
" not assigned!\n" );
4045 joint->AddVertex( vPool->Vertex(i), 1.0f );
4049 membership = vPool->Vertex(i)->NetMembership();
4054 fprintf( outStream,
"vpool %s vert %d", name,
4056 fprintf( outStream,
" has membership %f\n",
4060 if ( membership == 0 )
4063 fprintf( outStream,
"adding full weight..\n" );
4066 joint->AddVertex( vPool->Vertex(i), 1.0f );
4073 fprintf( outStream,
"couldn't find vpool %s\n", name );
4077 if ( parentName != NULL )
4079 fprintf( outStream,
"Couldn't find joint %s\n", parentName );
4092 MakeAnimTable( SAA_Scene *scene, SAA_Elem *skeletonPart,
char *name )
4095 if ( skeletonPart != NULL )
4101 SAA_Boolean globalFlag = FALSE;
4102 SAA_Boolean bigEndian;
4105 fprintf( outStream,
"\n\nanimating child %s\n", name );
4107 SAA_elementGetUserDataSize( scene, skeletonPart,
"GLOBAL", &size );
4110 SAA_elementGetUserData( scene, skeletonPart,
"GLOBAL",
4111 sizeof( SAA_Boolean), &bigEndian, (
void *)&globalFlag );
4116 fprintf( outStream,
" using global matrix\n" );
4119 SAA_modelGetRotation( scene, skeletonPart, SAA_COORDSYS_GLOBAL,
4123 SAA_modelGetTranslation( scene, skeletonPart, SAA_COORDSYS_GLOBAL,
4127 SAA_modelGetScaling( scene, skeletonPart, SAA_COORDSYS_GLOBAL,
4133 fprintf( outStream,
"using local matrix\n" );
4136 SAA_modelGetRotation( scene, skeletonPart, SAA_COORDSYS_LOCAL,
4140 SAA_modelGetTranslation( scene, skeletonPart, SAA_COORDSYS_LOCAL,
4144 SAA_modelGetScaling( scene, skeletonPart, SAA_COORDSYS_LOCAL,
4150 fprintf( outStream,
"\nanim data: %f %f %f\n\t%f %f %f\n\t%f %f %f\n",
4151 i, j, k, h, p, r, x, y, z );
4155 XfmSAnimTable *thisTable;
4158 thisGroup = (
AnimGroup *)(animRoot->FindDescendent( name ));
4160 fprintf( outStream,
"\nlooking for anim group %s\n", name );
4161 if ( thisGroup != NULL )
4163 thisTable = (XfmSAnimTable *)(thisGroup->FindDescendent(
"xform" ));
4165 if ( thisTable != NULL )
4167 thisTable->sub_tables[0].AddElement( i );
4168 thisTable->sub_tables[1].AddElement( j );
4169 thisTable->sub_tables[2].AddElement( k );
4170 thisTable->sub_tables[3].AddElement( p );
4171 thisTable->sub_tables[4].AddElement( h );
4172 thisTable->sub_tables[5].AddElement( r );
4173 thisTable->sub_tables[6].AddElement( x );
4174 thisTable->sub_tables[7].AddElement( y );
4175 thisTable->sub_tables[8].AddElement( z );
4178 fprintf( outStream,
"Couldn't allocate anim table\n" );
4182 fprintf( outStream,
"Couldn't find anim group %s\n", name );
4187 fprintf( outStream,
"Cannot build anim table - no skeleton\n" );
4202 MakeVertexOffsets( SAA_Scene *scene, SAA_Elem *model, SAA_ModelType type,
4203 int numShapes,
int numOrigVert, SAA_DVector *originalVerts,
float 4204 matrix[4][4],
char *name )
4210 SAA_DVector *shapeVerts = NULL;
4211 SAA_DVector *uniqueVerts = NULL;
4213 if ( (type == SAA_MNSRF) && make_nurbs )
4214 SAA_nurbsSurfaceSetStep( scene, model, nurbs_step, nurbs_step );
4216 SAA_modelGetNbVertices( scene, model, &numCV );
4219 uniqueVerts = (SAA_DVector *)malloc(
sizeof(SAA_DVector)*numCV);
4220 SAA_modelGetVertices( scene, model, SAA_GEOM_ORIGINAL, 0,
4221 numCV, uniqueVerts );
4224 fprintf( outStream,
"%d CV's\n", numCV );
4228 for ( i = 0; i < numCV; i++ )
4229 fprintf( outStream,
"uniqueVerts[%d] = %f %f %f %f\n", i,
4230 uniqueVerts[i].x, uniqueVerts[i].y,
4231 uniqueVerts[i].z, uniqueVerts[i].w );
4235 for ( i = 1; i < numShapes; i++ )
4237 mTableName = MakeTableName( name, i );
4241 fprintf( outStream,
"\nMaking geometry offsets for %s...\n",
4244 if ( (type == SAA_MNSRF) && make_nurbs )
4245 fprintf( outStream,
"calculating NURBS morphs...\n" );
4247 fprintf( outStream,
"calculating triangle morphs...\n" );
4251 shapeVerts = (SAA_DVector *)malloc(
sizeof(SAA_DVector)*numCV);
4252 SAA_modelGetVertices( scene, model, SAA_GEOM_SHAPE, i+1,
4253 numCV, shapeVerts );
4257 for ( j=0; j < numCV; j++ )
4259 fprintf( outStream,
"shapeVerts[%d] = %f %f %f\n", j,
4260 shapeVerts[j].x, shapeVerts[j].y, shapeVerts[j].z );
4270 for ( j=0; j < numOrigVert; j++ )
4274 if ( (type == SAA_MNSRF) && make_nurbs )
4279 dx = shapeVerts[j].x - originalVerts[j].x;
4280 dy = shapeVerts[j].y - originalVerts[j].y;
4281 dz = shapeVerts[j].z - originalVerts[j].z;
4287 offset = findShapeVert( originalVerts[j], uniqueVerts,
4290 dx = shapeVerts[offset].x - originalVerts[j].x;
4291 dy = shapeVerts[offset].y - originalVerts[j].y;
4292 dz = shapeVerts[offset].z - originalVerts[j].z;
4297 fprintf( outStream,
"oVert[%d] = %f %f %f %f\n", j,
4298 originalVerts[j].x, originalVerts[j].y,
4299 originalVerts[j].z, originalVerts[j].w );
4301 if ( (type == SAA_MNSRF) && make_nurbs )
4303 fprintf( outStream,
"global shapeVerts[%d] = %f %f %f %f\n", j, shapeVerts[j].x, shapeVerts[j].y,
4304 shapeVerts[j].z, shapeVerts[j].w );
4309 "global shapeVerts[%d] = %f %f %f\n", offset,
4310 shapeVerts[offset].x,
4311 shapeVerts[offset].y,
4312 shapeVerts[offset].z );
4315 fprintf( outStream,
"%d: dx = %f, dy = %f, dz = %f\n", j,
4320 double total = fabs(dx)+fabs(dy)+fabs(dz);
4321 if ( total > 0.00001 )
4323 if ( vPool != NULL )
4326 EggMorphOffset *dxyz =
4327 new EggMorphOffset( mTableName, dx, dy, dz );
4332 eggVert = vPool->Vertex(j);
4335 eggVert->morphs.push_back( *dxyz );
4338 fprintf( outStream,
"Error: couldn't find vertex pool %s\n", name );
4355 MakeMorphTable( SAA_Scene *scene, SAA_Elem *model, SAA_Elem *models,
4356 int numModels,
char *name,
float time )
4359 SAA_AnimInterpType type;
4362 SAA_modelGetNbShapes( scene, model, &numShapes );
4364 if ( numShapes > 0 )
4367 fprintf( outStream,
"MakeMorphTable: %s: num shapes: %d\n",
4370 SAA_modelGetShapeInterpolation( scene, model, &type );
4372 if ( type == SAA_ANIM_LINEAR || type == SAA_ANIM_CARDINAL )
4374 MakeLinearMorphTable( scene, model, numShapes, name, time );
4379 MakeExpressionMorphTable( scene, model, models, numModels,
4380 numShapes, name, time );
4397 MakeLinearMorphTable( SAA_Scene *scene, SAA_Elem *model,
int numShapes,
4398 char *name,
float time )
4403 SAnimTable *thisTable;
4407 fprintf( outStream,
"linear interp, getting fcurve\n" );
4409 SAA_modelFcurveGetShape( scene, model, &fcurve );
4411 SAA_fcurveEval( scene, &fcurve, time, &curveVal );
4414 fprintf( outStream,
"at time %f, fcurve for %s = %f\n", time,
4417 float nextVal = 0.0f;
4420 for ( i = 1; i < numShapes; i++ )
4423 tableName = MakeTableName( name, i );
4426 fprintf( outStream,
"Linear: looking for table '%s'\n", tableName );
4429 thisTable = (SAnimTable *)(morphRoot->FindDescendent( tableName ));
4431 if ( thisTable != NULL )
4433 if ( i == (
int)curveVal )
4435 if ( curveVal - i == 0 )
4437 thisTable->AddElement( 1.0f );
4439 fprintf( outStream,
"adding element 1.0f\n" );
4443 thisTable->AddElement( 1.0f - (curveVal - i) );
4444 nextVal = curveVal - i;
4446 fprintf( outStream,
"adding element %f\n", 1.0f - (curveVal - i) );
4453 thisTable->AddElement( nextVal );
4456 fprintf( outStream,
"adding element %f\n", nextVal );
4460 thisTable->AddElement( 0.0f );
4462 fprintf( outStream,
"adding element 0.0f\n" );
4467 fprintf( outStream,
" to '%s'\n", tableName );
4470 fprintf( outStream,
"%d: Couldn't find table '%s'\n",
4487 MakeWeightedMorphTable( SAA_Scene *scene, SAA_Elem *model, SAA_Elem *models,
4488 int numModels,
int numShapes,
char *name,
float time )
4491 SAA_Elem *weightCurves;
4493 SAnimTable *thisTable;
4497 weightCurves = ( SAA_Elem *)malloc(
sizeof( SAA_Elem ) * numShapes );
4499 result = SAA_modelFcurveGetShapeWeights(
4500 scene, model, numShapes, weightCurves );
4502 if ( result == SI_SUCCESS )
4504 for (
int i = 1; i < numShapes; i++ )
4506 SAA_fcurveEval( scene, &weightCurves[i], time, &curveVal );
4509 if (!isNum(curveVal))
4513 fprintf( outStream,
"at time %f, weightCurve[%d] for %s = %f\n", time, i, name, curveVal );
4517 tableName = MakeTableName( name, i );
4521 fprintf( outStream,
"Weight: looking for table '%s'\n",
4525 thisTable = (SAnimTable *)(morphRoot->FindDescendent( tableName ));
4527 if ( thisTable != NULL )
4529 thisTable->AddElement( curveVal );
4531 fprintf( outStream,
"adding element %f\n", curveVal );
4534 fprintf( outStream,
"%d: Couldn't find table '%s'\n",
4550 MakeExpressionMorphTable( SAA_Scene *scene, SAA_Elem *model, SAA_Elem *models,
4551 int numModels,
int numShapes,
char *name,
float time )
4554 SAnimTable *thisTable;
4559 SAA_Elem *expressions;
4569 SAA_elementGetNbExpressions( scene, model, track, FALSE, &numExp );
4572 fprintf( outStream,
"%s has %d RHS expressions\n", name, numExp );
4577 expressions = (SAA_Elem *)malloc(
sizeof(SAA_Elem)*numExp);
4580 fprintf( outStream,
"getting %d RHS expressions...\n", numExp );
4582 result = SAA_elementGetExpressions( scene, model, track, FALSE,
4583 numExp, expressions );
4587 for ( j = 1; j < numExp; j++ )
4594 SAA_expressionGetNbVars( scene, &expressions[j], &numvars );
4600 varnamelen = (
int *)malloc(
sizeof(
int)*numvars);
4601 varstrlen = (
int *)malloc(
sizeof(
int)*numvars);
4603 SAA_expressionGetStringLengths( scene, &expressions[j],
4604 numvars, varnamelen, varstrlen, &expstrlen );
4609 varnamesizes = (
int *)malloc(
sizeof(
int)*numvars);
4610 varstrsizes = (
int *)malloc(
sizeof(
int)*numvars);
4612 for (
int k = 0; k < numvars; k++ )
4614 varnamesizes[k] = varnamelen[k] + 1;
4615 varstrsizes[k] = varstrlen[k] + 1;
4618 int expstrsize = expstrlen + 1;
4623 varnames = (
char **)malloc(
sizeof(
char *)*numvars);
4624 varstrs = (
char **)malloc(
sizeof(
char *)*numvars);
4626 for ( k = 0; k < numvars; k++ )
4628 varnames[k] = (
char *)malloc(
sizeof(
char)*
4631 varstrs[k] = (
char *)malloc(
sizeof(
char)*
4635 char *expstr = (
char *)malloc(
sizeof(
char)* expstrsize );
4637 SAA_expressionGetStrings( scene, &expressions[j], numvars,
4638 varnamesizes, varstrsizes, expstrsize, varnames,
4643 fprintf( outStream,
"expression = '%s'\n", expstr );
4644 fprintf( outStream,
"has %d variables\n", numvars );
4649 fprintf( outStream,
"evaling expression...\n" );
4651 SAA_expressionEval( scene, &expressions[j], time, &expVal );
4654 fprintf( outStream,
"time %f: exp val %f\n",
4658 tableName = MakeTableName( name, j );
4661 fprintf( outStream,
"Exp: looking for table '%s'\n",
4665 thisTable = (SAnimTable *)
4666 (morphRoot->FindDescendent( tableName ));
4668 if ( thisTable != NULL )
4670 thisTable->AddElement( expVal );
4672 fprintf( outStream,
"%d: adding element %f to %s\n",
4673 j, expVal, tableName );
4674 fflush( outStream );
4678 fprintf( outStream,
"%d: Couldn't find table '%s'", j,
4681 fprintf( outStream,
" for value %f\n", expVal );
4686 fprintf( outStream,
"couldn't get expressions!!!\n" );
4690 MakeWeightedMorphTable( scene, model, models, numModels,
4691 numShapes, name, time );
4704 MakeTexAnim( SAA_Scene *scene, SAA_Elem *model,
char *modelName )
4707 fprintf( outStream,
"\n\nmaking texture animation for %s...\n",
4713 SAA_Elem *materials;
4716 SAA_modelRelationGetMatNbElements( scene, model, FALSE, &relinfo,
4720 fprintf( outStream,
"surface has %d materials\n", numMats );
4726 materials = (SAA_Elem *)malloc(
sizeof(SAA_Elem)*numMats);
4728 SAA_modelRelationGetMatElements( scene, model, relinfo,
4729 numMats, materials );
4731 SAA_materialGetDiffuse( scene, &materials[0], &r, &g, &b );
4732 SAA_materialGetTransparency( scene, &materials[0], &a );
4733 Color.set( r, g, b, 1.0f - a );
4743 SAA_materialRelationGetT2DLocNbElements( scene, &materials[0],
4744 FALSE, &relinfo, &numTexLoc );
4750 fprintf( outStream,
"%s had %d local tex\n", modelName,
4754 SAA_materialRelationGetT2DLocElements( scene, &materials[0],
4755 TEX_PER_MAT, &tex );
4761 SAA_modelRelationGetT2DGlbNbElements( scene, model,
4762 FALSE, &relinfo, &numTexGlb );
4767 fprintf( outStream,
"%s had %d global tex\n", modelName, numTexGlb );
4770 SAA_modelRelationGetT2DGlbElements( scene,
4771 model, TEX_PER_MAT, &tex );
4776 if ( numTexLoc || numTexGlb)
4778 char *fullTexName = NULL;
4779 char *texName = NULL;
4780 char *uniqueTexName = NULL;
4784 SAA_texture2DGetPicNameLength( scene, &tex, &texNameLen);
4785 fullTexName = (
char *)malloc(
sizeof(
char)*++texNameLen);
4786 SAA_texture2DGetPicName( scene, &tex, texNameLen,
4791 uniqueTexName = (
char *)malloc(
sizeof(
char)*
4792 (strlen(modelName)+strlen(texName)+3) );
4793 sprintf( uniqueTexName,
"%s-%s", modelName, texName );
4795 fprintf( outStream,
"referencing tref %s\n",
4802 SAA_Boolean uv_swap = FALSE;
4805 SAA_texture2DGetUScale( scene, &tex, &uScale );
4806 SAA_texture2DGetVScale( scene, &tex, &vScale );
4807 SAA_texture2DGetUOffset( scene, &tex, &uOffset );
4808 SAA_texture2DGetVOffset( scene, &tex, &vOffset );
4809 SAA_texture2DGetUVSwap( scene, &tex, &uv_swap );
4814 fprintf( outStream,
"tex uScale: %f\n", uScale );
4815 fprintf( outStream,
"tex vScale: %f\n", vScale );
4816 fprintf( outStream,
"tex uOffset: %f\n", uOffset );
4817 fprintf( outStream,
"tex vOffset: %f\n", vOffset );
4819 fprintf( outStream,
"nurbTex u & v swapped!\n" );
4821 fprintf( outStream,
"nurbTex u & v NOT swapped\n" );
4830 if ( vPool != NULL )
4833 float oldOffsets[4];
4834 double u, v, du, dv;
4836 SAA_Boolean bigEndian;
4838 SAA_elementGetUserDataSize( scene, model,
"TEX_OFFSETS", &size );
4843 SAA_elementGetUserData( scene, model,
"TEX_OFFSETS",
4844 size, &bigEndian, (
void *)&oldOffsets );
4855 fprintf( outStream,
"original u = %f, v = %f\n",
4857 fprintf( outStream,
"u = %f, v = %f\n",
4859 fprintf( outStream,
"du = %f, dv = %f\n",
4863 strstream uName, vName;
4866 uName << modelName <<
".u" << ends;
4867 vName << modelName <<
".v" << ends;
4871 SAnimTable *thisTable;
4874 thisTable = (SAnimTable *)(morphRoot->FindDescendent(
4877 if ( thisTable != NULL )
4879 thisTable->AddElement( du );
4881 fprintf( outStream,
"adding element %f to %s\n",
4885 fprintf( outStream,
"Couldn't find uTable %s\n",
4889 thisTable = (SAnimTable *)(morphRoot->FindDescendent(
4892 if ( thisTable != NULL )
4894 thisTable->AddElement( dv );
4896 fprintf( outStream,
"adding element %f to %s\n",
4900 fprintf( outStream,
"Couldn't find vTable %s\n",
4906 fprintf( outStream,
"Couldn't find vpool %s\n", modelName );
4922 EXPCL_MISC SI_Error soft2egg(
int argc,
char *argv[]) {
4924 init_soft2egg(argc, argv);
Defines a texture map that may be applied to geometry.
This is our own Panda specialization on the default STL list.
This is the primary interface into all the egg data, and the root of the egg file structure...
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
This is the base class for AnimChannel and AnimBundle.
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
A parametric NURBS curve.
A parametric NURBS surface.
This is a base class for both EggSingleBase and EggMultiBase.
A collection of vertices.