00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Teddy/TeddyConfig.h"
00026 #if defined( TEDDY_INCLUDE_LW_SCENE )
00027
00028
00029 #include "Teddy/Imports/LWSceneFile.h"
00030 #include "Teddy/SysSupport/Messages.h"
00031 #include "Teddy/SysSupport/StdIO.h"
00032 #ifndef SWIG
00033 #include <cctype>
00034 #endif
00035 using namespace Teddy::SysSupport;
00036
00037
00038 namespace Teddy {
00039 namespace Imports {
00040
00041
00043 LWSceneFile::LWSceneFile( const char *name ){
00044 mapTokens();
00045 file = NULL;
00046 open( name );
00047 }
00048
00049
00051 LWSceneFile::~LWSceneFile(){
00052 close();
00053 }
00054
00055
00056 bool LWSceneFile::isOk(){
00057 return file!=NULL ? true : false;
00058 }
00059
00060
00062 void LWSceneFile::open( const char *name ){
00063 file = fopen( name, "r" );
00064 }
00065
00066
00068 void LWSceneFile::close(){
00069 if( file != NULL ){
00070 fclose( file );
00071 file = NULL;
00072 }
00073 }
00074
00075
00076 LwsToken LWSceneFile::read_token(){
00077 string_to_token::iterator t_it;
00078 char tmp[1024];
00079 int count;
00080
00081 if( feof(file) != 0 ){
00082 return LWS_EOF;
00083 }
00084
00085 count = fscanf( file, "%s", tmp );
00086 t_it = token_map.find( tmp );
00087
00088 if( count != 1 ){
00089 dmsg( M_LWS, "read_token() count == %d", count );
00090 return LWS_ERROR;
00091 }else if( t_it != token_map.end() ){
00092
00093 return (*t_it).second;
00094 }else{
00095 dmsg( M_LWS, "%s UNKNOWN", tmp );
00096 return read_token();
00097 }
00098 }
00099
00100
00101 void LWSceneFile::skip(){
00102 for(;;){
00103 int c = fgetc(file);
00104 if( (c == EOF) || (c == '\n') ){
00105 return;
00106 }
00107 }
00108 }
00109
00110 bool LWSceneFile::read_begin_scope(){
00111 int c;
00112 bool good = true;
00113
00114 for(;;){
00115 c = fgetc( file );
00116 if( c == '{' ){
00117 return good;
00118 }else if( isspace(c) == 0 ){
00119 good = true;
00120 }
00121 }
00122 }
00123
00124
00125 bool LWSceneFile::read_end_scope(){
00126 int c;
00127 bool good = true;
00128
00129 for(;;){
00130 c = fgetc( file );
00131 if( c == '}' ){
00132 return good;
00133 }else if( isspace(c) == 0 ){
00134 good = true;
00135 }
00136 }
00137 }
00138
00139
00140 int LWSceneFile::read_int(){
00141 int a;
00142 int count;
00143
00144 if( feof(file) != 0 ){
00145 return 0;
00146 }
00147
00148 count = fscanf( file, "%d", &a );
00149 if( count != 1 ){
00150 return 0;
00151 }else{
00152 return a;
00153 }
00154 }
00155
00156 unsigned long LWSceneFile::read_hex_int(){
00157 unsigned long a;
00158 int count;
00159
00160 if( feof(file) != 0 ){
00161 return 0;
00162 }
00163
00164 count = fscanf( file, "%8lX", &a );
00165 if( count != 1 ){
00166 return 0;
00167 }else{
00168 return a;
00169 }
00170 }
00171
00172
00173
00174 double LWSceneFile::read_double(){
00175 float a;
00176 int count;
00177
00178 if( feof(file) != 0 ){
00179 return 0;
00180 }
00181
00182 count = fscanf( file, "%f", &a );
00183 if( count != 1 ){
00184 return 0;
00185 }else{
00186 return (double)a;
00187 }
00188 }
00189
00190
00191 char *LWSceneFile::read_string(){
00192 char *line = new char[128];
00193 int count = fscanf( file, "%s", line );
00194
00195 if( count != 1 ){
00196 return 0;
00197 }else{
00198 return line;
00199 }
00200 }
00201
00202
00203 void LWSceneFile::mapToken( char *key, LwsToken token ){
00204 token_map.insert( make_pair(key,token) );
00205 }
00206
00207
00208 void LWSceneFile::mapTokens(){
00209
00210
00211 mapToken( "LWSC" , LWS_LWSC );
00212 mapToken( "FirstFrame" , LWS_FIRST_FRAME );
00213 mapToken( "LastFrame" , LWS_LAST_FRAME );
00214 mapToken( "FrameStep" , LWS_FRAME_STEP );
00215 mapToken( "FramesPerSecond" , LWS_FRAMES_PER_SECOND );
00216 mapToken( "PreviewFirstFrame" , LWS_PREVIEW_FIRST_FRAME );
00217 mapToken( "PreviewLastFrame" , LWS_PREVIEW_LAST_FRAME );
00218 mapToken( "PreviewFrameStep" , LWS_PREVIEW_FRAME_STEP );
00219 mapToken( "CurrentFrame" , LWS_CURRENT_FRAME );
00220 mapToken( "Plugin" , LWS_PLUGIN );
00221 mapToken( "EndPlugin" , LWS_END_PLUGIN );
00222
00223
00224 mapToken( "AddNullObject" , LWS_ADD_NULL_OBJECT );
00225 mapToken( "LoadObject" , LWS_LOAD_OBJECT );
00226 mapToken( "LoadObjectLayer" , LWS_LOAD_OBJECT_LAYER );
00227 mapToken( "ShowObject" , LWS_SHOW_OBJECT );
00228 mapToken( "ObjectMotion" , LWS_OBJECT_MOTION );
00229 mapToken( "ObjectDissolve" , LWS_OBJECT_DISSOLVE );
00230 mapToken( "SubdivisionOrder" , LWS_SUBDIVISION_ORDER );
00231 mapToken( "SubPatchLevel" , LWS_SUB_PATCH_LEVEL );
00232 mapToken( "ShadowOptions" , LWS_SHADOW_OPTIONS );
00233 mapToken( "DistanceDissolve" , LWS_DISTANCE_DISSOLVE );
00234 mapToken( "MaxDissolveDistance" , LWS_MAX_DISSOLVE_DISTANCE );
00235 mapToken( "ParticleSize" , LWS_PARTICLE_SIZE );
00236 mapToken( "LineSize" , LWS_LINE_SIZE );
00237 mapToken( "PolygonSize" , LWS_POLYGON_SIZE );
00238 mapToken( "UnseenByRays" , LWS_UNSEEN_BY_RAYS );
00239 mapToken( "UnseenByCamera" , LWS_UNSEEN_BY_CAMERA );
00240 mapToken( "UnaffectedByFog" , LWS_UNAFFECTED_BY_FOG );
00241 mapToken( "AffectedByFog" , LWS_AFFECTED_BY_FOG );
00242 mapToken( "ExcludeLight" , LWS_EXCLUDE_LIGHT );
00243 mapToken( "ObjPolygonEdges" , LWS_OBJ_POLYGON_EDGES );
00244 mapToken( "ObjEdgeColor" , LWS_OBJ_EDGE_COLOR );
00245 mapToken( "PolygonEdgeFlags" , LWS_POLYGON_EDGE_FLAGS );
00246 mapToken( "PolygonEdgeThickness" , LWS_POLYGON_EDGE_THICKNESS );
00247 mapToken( "PolygonEdgesZScale" , LWS_POLYGON_EDGES_Z_SCALE );
00248 mapToken( "EdgeNominalDistance" , LWS_EDGE_NOMINAL_DISTANCE );
00249
00250 mapToken( "DisplacementMap" , LWS_DISPLACEMENT_MAP );
00251 mapToken( "ClipMap" , LWS_CLIP_MAP );
00252 mapToken( "TextureImage" , LWS_TEXTURE_IMAGE );
00253 mapToken( "TextureFlags" , LWS_TEXTURE_FLAGS );
00254 mapToken( "TextureAxis" , LWS_TEXTURE_AXIS );
00255 mapToken( "TextureSize" , LWS_TEXTURE_SIZE );
00256 mapToken( "TextureCenter" , LWS_TEXTURE_CENTER );
00257 mapToken( "TextureFalloff" , LWS_TEXTURE_FALLOFF );
00258 mapToken( "TextureVelocity" , LWS_TEXTURE_VELOCITY );
00259 mapToken( "TextureAmplitude" , LWS_TEXTURE_AMPLITUDE );
00260 mapToken( "TextureValue" , LWS_TEXTURE_VALUE );
00261 mapToken( "TextureInt" , LWS_TEXTURE_INT );
00262 mapToken( "TextureFloat" , LWS_TEXTURE_FLOAT );
00263
00264
00265 mapToken( "PivotPosition" , LWS_PIVOT_POSITION );
00266 mapToken( "ParentItem" , LWS_PARENT_ITEM );
00267 mapToken( "Behaviors" , LWS_BEHAVIORS );
00268 mapToken( "NumChannels" , LWS_NUM_CHANNELS );
00269 mapToken( "Channel" , LWS_CHANNEL );
00270 mapToken( "Envelope" , LWS_ENVELOPE );
00271 mapToken( "Key" , LWS_KEY );
00272 mapToken( "LockedChannels" , LWS_LOCKED_CHANNELS );
00273 mapToken( "ParentObject" , LWS_PARENT_OBJECT );
00274 mapToken( "TargetObject" , LWS_TARGET_OBJECT );
00275 mapToken( "GoalObject" , LWS_GOAL_OBJECT );
00276 mapToken( "SchematicPosition" , LWS_SCHEMATIC_POSITION );
00277
00278 mapToken( "MorphAmount" , LWS_MORPH_AMOUNT );
00279 mapToken( "MorphTarget" , LWS_MORPH_TARGET );
00280 mapToken( "MorphSurfaces" , LWS_MORPH_SURFACES );
00281
00282 mapToken( "UseBonesFrom" , LWS_USE_BONES_FROM );
00283 mapToken( "BoneFalloffType" , LWS_BONE_FALLOFF_TYPE );
00284 mapToken( "AddBone" , LWS_ADD_BONE );
00285 mapToken( "BoneName" , LWS_BONE_NAME );
00286 mapToken( "ShowBone" , LWS_SHOW_BONE );
00287 mapToken( "BoneActive" , LWS_BONE_ACTIVE );
00288 mapToken( "BoneRestPosition" , LWS_BONE_REST_POSITION );
00289 mapToken( "BoneRestDirection" , LWS_BONE_REST_DIRECTION );
00290 mapToken( "BoneRestLength" , LWS_BONE_REST_LENGTH );
00291 mapToken( "BoneStrength" , LWS_BONE_STRENGTH );
00292 mapToken( "ScaleBoneStrength" , LWS_SCALE_BONE_STRENGTH );
00293 mapToken( "BoneLimitedRange" , LWS_BONE_LIMITED_RANGE );
00294 mapToken( "BoneMinRange" , LWS_BONE_MIN_RANGE );
00295 mapToken( "BoneMaxRange" , LWS_BONE_MAX_RANGE );
00296 mapToken( "BoneMotion" , LWS_BONE_MOTION );
00297 mapToken( "HController" , LWS_H_CONTROLLER );
00298 mapToken( "PController" , LWS_P_CONTROLLER );
00299 mapToken( "BController" , LWS_B_CONTROLLER );
00300 mapToken( "HLimits" , LWS_H_LIMITS );
00301 mapToken( "PLimits" , LWS_P_LIMITS );
00302 mapToken( "BLimits" , LWS_B_LIMITS );
00303 mapToken( "IKAnchor" , LWS_IK_ANCHOR );
00304
00305
00306 mapToken( "AmbientColor" , LWS_AMBIENT_COLOR );
00307 mapToken( "AmbientIntensity" , LWS_AMBIENT_INTENSITY );
00308 mapToken( "GlobalFlareIntensity" , LWS_GLOBAL_FLARE_INTENSITY );
00309 mapToken( "EnableLensFlares" , LWS_ENABLE_LENS_FLARES );
00310 mapToken( "EnableShadowMaps" , LWS_ENABLE_SHADOW_MAPS );
00311
00312
00313 mapToken( "AddLight" , LWS_ADD_LIGHT );
00314 mapToken( "ShowLight" , LWS_SHOW_LIGHT );
00315 mapToken( "LightName" , LWS_LIGHT_NAME );
00316 mapToken( "LightMotion" , LWS_LIGHT_MOTION );
00317 mapToken( "LightColor" , LWS_LIGHT_COLOR );
00318 mapToken( "LightType" , LWS_LIGHT_TYPE );
00319 mapToken( "LightFalloffType" , LWS_LIGHT_FALLOFF_TYPE );
00320 mapToken( "LightRange" , LWS_LIGHT_RANGE );
00321 mapToken( "LightConeAngle" , LWS_LIGHT_CONE_ANGLE );
00322 mapToken( "LightEdgeAngle" , LWS_LIGHT_EDGE_ANGLE );
00323 mapToken( "LightIntensity" , LWS_LIGHT_INTENSITY );
00324 mapToken( "Falloff" , LWS_FALLOFF );
00325 mapToken( "AffectCaustics" , LWS_AFFECT_CAUSTICS );
00326 mapToken( "AffectDiffuse" , LWS_AFFECT_DIFFUSE );
00327 mapToken( "AffectSpecular" , LWS_AFFECT_SPECULAR );
00328 mapToken( "AffectOpenGL" , LWS_AFFECT_OPEN_GL );
00329 mapToken( "UseConeAngle" , LWS_USE_CONE_ANGLE );
00330 mapToken( "LensFlare" , LWS_LENS_FLARE );
00331 mapToken( "FlareIntensity" , LWS_FLARE_INTENSITY );
00332 mapToken( "FlareDissolve" , LWS_FLARE_DISSOLVE );
00333 mapToken( "LensFlareFade" , LWS_LENS_FLARE_FADE );
00334 mapToken( "LensFlareOptions" , LWS_LENS_FLARE_OPTIONS );
00335 mapToken( "FlareRandStreakInt" , LWS_FLARE_RAND_STREAK_INT );
00336 mapToken( "FlareRandStreakDens" , LWS_FLARE_RAND_STREAK_DENS );
00337 mapToken( "FlareRandStreakSharp" , LWS_FLARE_RAND_STREAK_SHARP );
00338 mapToken( "ShadowType" , LWS_SHADOW_TYPE );
00339 mapToken( "ShadowCasting" , LWS_SHADOW_CASTING );
00340 mapToken( "ShadowMapSize" , LWS_SHADOW_MAP_SIZE );
00341 mapToken( "ShadowMapAngle" , LWS_SHADOW_MAP_ANGLE );
00342 mapToken( "ShadowFuzziness" , LWS_SHADOW_FUZZINESS );
00343
00344
00345 mapToken( "AddCamera" , LWS_ADD_CAMERA );
00346 mapToken( "CameraName" , LWS_CAMERA_NAME );
00347 mapToken( "ShowCamera" , LWS_SHOW_CAMERA );
00348 mapToken( "CameraMotion" , LWS_CAMERA_MOTION );
00349 mapToken( "ZoomFactor" , LWS_ZOOM_FACTOR );
00350 mapToken( "MotionBlur" , LWS_MOTION_BLUR );
00351 mapToken( "BlurLength" , LWS_BLUR_LENGTH );
00352 mapToken( "DepthofField" , LWS_DEPTH_OF_FIELD );
00353 mapToken( "FocalDistance" , LWS_FOCAL_DISTANCE );
00354 mapToken( "LensFStop" , LWS_LENS_F_STOP );
00355
00356 mapToken( "ResolutionMultiplier" , LWS_RESOLUTION_MULTIPLIER );
00357 mapToken( "Resolution" , LWS_RESOLUTION );
00358 mapToken( "FrameSize" , LWS_FRAME_SIZE );
00359 mapToken( "CustomSize" , LWS_CUSTOM_SIZE );
00360 mapToken( "FilmSize" , LWS_FILM_SIZE );
00361 mapToken( "NTSCWidescreen" , LWS_NTSC_WIDE_SCREEN );
00362 mapToken( "PixelAspect" , LWS_PIXEL_ASPECT );
00363 mapToken( "PixelAspectRatio" , LWS_PIXEL_ASPECT_RATIO );
00364 mapToken( "CustomPixelRatio" , LWS_CUSTOM_PIXEL_RATIO );
00365 mapToken( "LimitedRegion" , LWS_LIMITED_REGION );
00366 mapToken( "MaskPosition" , LWS_MASK_POSITION );
00367 mapToken( "ApertureHeight" , LWS_APERTURE_HEIGHT );
00368 mapToken( "RegionLimits" , LWS_REGION_LIMITS );
00369 mapToken( "SegmentMemory" , LWS_SEGMENT_MEMORY );
00370 mapToken( "Antialiasing" , LWS_ANTI_ALIASING );
00371 mapToken( "EnhancedAA" , LWS_ENHANCED_AA );
00372 mapToken( "FilterType" , LWS_FILTER_TYPE );
00373 mapToken( "AdaptiveSampling" , LWS_ADAPTIVE_SAMPLING );
00374 mapToken( "AdaptiveThreshold" , LWS_ADAPTIVE_THRESHOLD );
00375 mapToken( "FieldRendering" , LWS_FIELD_RENDERING );
00376 mapToken( "ReverseFields" , LWS_REVERSE_FIELDS );
00377
00378
00379 mapToken( "BGImage" , LWS_BG_IMAGE );
00380 mapToken( "FGImage" , LWS_FG_IMAGE );
00381 mapToken( "FGAlphaImage" , LWS_FG_ALPHA_IMAGE );
00382 mapToken( "FGDissolve" , LWS_FG_DISSOLVE );
00383 mapToken( "FGFaderAlphaMode" , LWS_FG_FADER_ALPHA_MODE );
00384 mapToken( "ImageSequenceInfo" , LWS_IMAGE_SEQUENCE_INFO );
00385 mapToken( "ForegroundKey" , LWS_FOREGROUND_KEY );
00386 mapToken( "LowClipColor" , LWS_LOW_CLIP_COLOR );
00387 mapToken( "HighClipColor" , LWS_HIGH_CLIP_COLOR );
00388 mapToken( "SolidBackdrop" , LWS_SOLID_BACKDROP );
00389 mapToken( "BackdropColor" , LWS_BACKDROP_COLOR );
00390 mapToken( "ZenithColor" , LWS_ZENITH_COLOR );
00391 mapToken( "SkyColor" , LWS_SKY_COLOR );
00392 mapToken( "GroundColor" , LWS_GROUND_COLOR );
00393 mapToken( "NadirColor" , LWS_NADIR_COLOR );
00394 mapToken( "SkySqueezeAmount" , LWS_SKY_SQUEEZE_AMOUNT );
00395 mapToken( "GroundSqueezeAmount" , LWS_GROUND_SQUEEZE_AMOUNT );
00396 mapToken( "FogType" , LWS_FOG_TYPE );
00397 mapToken( "FogMinDist" , LWS_FOG_MIN_DIST );
00398 mapToken( "FogMaxDist" , LWS_FOG_MAX_DIST );
00399 mapToken( "FogMinAmount" , LWS_FOG_MIN_AMOUNT );
00400 mapToken( "FogMaxAmount" , LWS_FOG_MAX_AMOUNT );
00401 mapToken( "FogColor" , LWS_FOG_COLOR );
00402 mapToken( "BackdropFog" , LWS_BACKDROP_FOG );
00403 mapToken( "DitherIntensity" , LWS_DITHER_INTENSITY );
00404 mapToken( "AnimatedDither" , LWS_ANIMATED_DITHER );
00405 mapToken( "Saturation" , LWS_SATURATION );
00406 mapToken( "GlowEffect" , LWS_GLOW_EFFECT );
00407 mapToken( "GlowIntensity" , LWS_GLOW_INTENSITY );
00408 mapToken( "GlowRadius" , LWS_GLOW_RADIUS );
00409
00410
00411 mapToken( "RenderMode" , LWS_RENDER_MODE );
00412 mapToken( "RayTraceEffects" , LWS_RAY_TRACE_EFFECTS );
00413 mapToken( "RayTraceOptimization" , LWS_RAY_TRACE_OPTIMIZATION );
00414 mapToken( "RayRecursionLimit" , LWS_RAY_RECURSION_LIMIT );
00415 mapToken( "DataOverlay" , LWS_DATA_OVERLAY );
00416 mapToken( "DataOverlayLabel" , LWS_DATA_OVERLAY_LABEL );
00417 mapToken( "OutputFilenameFormat" , LWS_OUTPUT_FILENAME_FORMAT );
00418 mapToken( "SaveRGB" , LWS_SAVE_RGB );
00419 mapToken( "SaveAlpha" , LWS_SAVE_ALPHA );
00420 mapToken( "SaveANIMFileName" , LWS_SAVE_ANIM_FILE_NAME );
00421 mapToken( "LockANIMPaletteFrame" , LWS_LOCK_ANIM_PALETTE_FRAME );
00422 mapToken( "BeginANIMLoopFrame" , LWS_BEGIN_ANIM_LOOP_FRAME );
00423 mapToken( "SaveRGBImagesPrefix" , LWS_SAVE_RGB_IMAGES_PREFIX );
00424 mapToken( "RGBImageFormat" , LWS_RGB_IMAGE_FORMAT );
00425 mapToken( "SaveAlphaImagesPrefix" , LWS_SAVE_ALPHA_IMAGES_PREFIX );
00426 mapToken( "AlphaImageFormat" , LWS_ALPHA_IMAGE_FORMAT );
00427 mapToken( "AlphaMode" , LWS_ALPHA_MODE );
00428 mapToken( "SaveFramestoresComment", LWS_SAVE_FRAMESTORES_COMMENT );
00429 mapToken( "FullSceneParamEval" , LWS_FULL_SCENE_PARAM_EVAL );
00430
00431
00432 mapToken( "ViewConfiguration" , LWS_VIEW_CONFIGURATION );
00433 mapToken( "DefineView" , LWS_DEFINE_VIEW );
00434 mapToken( "ViewMode" , LWS_VIEW_MODE );
00435 mapToken( "ViewAimpoint" , LWS_VIEW_AIMPOINT );
00436 mapToken( "ViewRotation" , LWS_VIEW_ROTATION );
00437 mapToken( "ViewZoomFactor" , LWS_VIEW_ZOOM_FACTOR );
00438
00439 mapToken( "LayoutGrid" , LWS_LAYOUT_GRID );
00440 mapToken( "GridNumber" , LWS_GRID_NUMBER );
00441 mapToken( "GridSize" , LWS_GRID_SIZE );
00442 mapToken( "CameraViewBG" , LWS_CAMERA_VIEW_BG );
00443 mapToken( "ShowMotionPath" , LWS_SHOW_MOTION_PATH );
00444 mapToken( "ShowSafeAreas" , LWS_SHOW_SAFE_AREAS );
00445 mapToken( "ShowBGImage" , LWS_SHOW_BG_IMAGE );
00446 mapToken( "ShowFogRadius" , LWS_SHOW_FOG_RADIUS );
00447 mapToken( "ShowFogEffect" , LWS_SHOW_FOG_EFFECT );
00448 mapToken( "ShowRedraw" , LWS_SHOW_REDRAW );
00449 mapToken( "ShowFieldChart" , LWS_SHOW_FIELD_CHART );
00450
00451 mapToken( "CurrentObject" , LWS_CURRENT_OBJECT );
00452 mapToken( "CurrentLight" , LWS_CURRENT_LIGHT );
00453 mapToken( "CurrentCamera" , LWS_CURRENT_CAMERA );
00454 mapToken( "GraphEditorData" , LWS_MAP_EDITOR_DATA );
00455 mapToken( "GraphEditorFavorites" , LWS_GRAPH_EDITOR_FAVORITES );
00456 }
00457
00458
00459 };
00460 };
00461
00462
00463 #endif // TEDDY_INCLUDE_LW_SCENE
00464