SceneConverterAvailability LightWave 6.0 Scene converters load scene files written in formats other than LightWave's native format. When the user selects a scene file to load, Layout first tries to load it directly as a LightWave format file. If it can't, it passes the filename to each installed scene converter until one of them claims to recognize the file. The scene converter reads the file and rewrites it as a LightWave scene file, passing the name of this temporary file back to Layout. After loading this file, Layout calls the scene converter's deleteTmp function to remove it. Activation Function XCALL_( int ) MySceneConvert( long version, GlobalFunc *global, LWSceneConverter *local, void *serverData ); The local argument to a scene converter's activation function is an LWSceneConverter. typedef struct st_LWSceneConverter { const char *filename; LWError readFailure; const char *tmpScene; void (*deleteTmp) (const char *tmpScene); } LWSceneConverter;
Example Most scene converters will follow the pattern shown in this pseudocode. Note that rather than write our own deleteTmp function for removing the temporary LightWave scene file, we just pass back the C runtime remove function. #include <lwserver.h> #include <lwscenecv.h> #include <stdio.h> #include <stdlib.h> XCALL_( int ) MySceneConvert( long version, GlobalFunc *global, LWSceneConverter *local, void *serverData ) { static char tempfile[ 260 ]; FILE *ifp, *ofp; ifp = fopen( local->filename, "rb" ); if ( !ifp ) return AFUNC_BADLOCAL; ... read some of the file ... if ( not our format ) return AFUNC_OK; ofp = fopen( tempfile, "w" ); if ( !ofp ) { fclose( ifp ); local->readFailure = "Couldn't create temp scene file."; return AFUNC_OK; } ... convert the scene ... if ( error while converting ) { fclose( ifp ); fclose( ofp ); local->readFailure = "Error while converting."; return AFUNC_OK; } /* successful */ local->tmpScene = tempfile; local->deleteTemp = remove; return AFUNC_OK; } ServerRecord ServerDesc[] = { { LWSCENECONVERTER_CLASS, "MySceneConverter", MySceneConvert }, { NULL } }; |