@ -118,6 +118,39 @@ struct Duration {
std : : chrono : : high_resolution_clock : : time_point _t ;
} ;
/* Direct shims for fast deserialization / serialization of blob data. Compared
to MagnumImporter / MagnumSceneConverter these don ' t make the whole file
resident in memory , so * much * faster . */
class BlobImporter : public Trade : : AbstractImporter {
Trade : : ImporterFeatures doFeatures ( ) const override { return { } ; }
bool doIsOpened ( ) const override { return _in ; }
void doClose ( ) override { _in = nullptr ; }
void doOpenFile ( const std : : string & filename ) override {
_in = Utility : : Directory : : mapRead ( filename ) ;
}
UnsignedInt doMeshCount ( ) const override { return 1 ; }
Containers : : Optional < Trade : : MeshData > doMesh ( UnsignedInt , UnsignedInt ) override {
return Trade : : MeshData : : deserialize ( _in ) ;
}
Containers : : Array < const char , Utility : : Directory : : MapDeleter > _in ;
} ;
class BlobSceneConverter : public Trade : : AbstractSceneConverter {
Trade : : SceneConverterFeatures doFeatures ( ) const override {
return Trade : : SceneConverterFeature : : ConvertMeshToFile ;
}
bool doConvertToFile ( const std : : string & filename , const Magnum : : Trade : : MeshData & mesh ) override {
Containers : : Array < char , Utility : : Directory : : MapDeleter > out = Utility : : Directory : : mapWrite ( filename , mesh . serializedSize ( ) ) ;
if ( ! out ) return false ;
mesh . serializeInto ( out ) ;
return true ;
}
} ;
}
int main ( int argc , char * * argv ) {
@ -151,19 +184,27 @@ plugin configuration. If the = character is omitted, it's equivalent to saying
key = true ; configuration subgroups are delimited with / . ) " )
. parse ( argc , argv ) ;
PluginManager : : Manager < Trade : : AbstractImporter > importerManager {
/* Load importer plugin, or use the blob shim in case the extension
matches and we ' re not overriding the converter to something specific */
Containers : : Optional < PluginManager : : Manager < Trade : : AbstractImporter > > importerManager ;
Containers : : Pointer < Trade : : AbstractImporter > importer ;
if ( Utility : : String : : endsWith ( args . value ( " input " ) , " .blob " ) & & args . value ( " importer " ) = = " AnySceneImporter " ) {
importer . reset ( new BlobImporter ) ;
if ( ! args . value ( " importer-options " ) . empty ( ) )
Warning { } < < " Importer options " < < args . value ( " importer-options " ) < < " ignored when loading a blob file " ;
} else {
importerManager . emplace (
args . value ( " plugin-dir " ) . empty ( ) ? std : : string { } :
Utility : : Directory : : join ( args . value ( " plugin-dir " ) , Trade : : AbstractImporter : : pluginSearchPaths ( ) [ 0 ] ) } ;
Containers : : Pointer < Trade : : AbstractImporter > importer = importerManager . loadAndInstantiate ( args . value ( " importer " ) ) ;
Utility : : Directory : : join ( args . value ( " plugin-dir " ) , Trade : : AbstractImporter : : pluginSearchPaths ( ) [ 0 ] ) ) ;
importer = importerManager - > loadAndInstantiate ( args . value ( " importer " ) ) ;
if ( ! importer ) {
Debug { } < < " Available importer plugins: " < < Utility : : String : : join ( importerManager . aliasList ( ) , " , " ) ;
Debug { } < < " Available importer plugins: " < < Utility : : String : : join ( importerManager - > aliasList ( ) , " , " ) ;
return 1 ;
}
/* Set options, if passed */
if ( args . isSet ( " verbose " ) ) importer - > setFlags ( Trade : : ImporterFlag : : Verbose ) ;
Trade : : Implementation : : setOptions ( * importer , args . value ( " importer-options " ) ) ;
}
std : : chrono : : high_resolution_clock : : duration importTime ;
@ -311,19 +352,27 @@ key=true; configuration subgroups are delimited with /.)")
}
}
/* Load converter plugin */
PluginManager : : Manager < Trade : : AbstractSceneConverter > converterManager {
/* Load converter plugin, or use the blob shim in case the extension
matches and we ' re not overriding the converter to something specific */
Containers : : Optional < PluginManager : : Manager < Trade : : AbstractSceneConverter > > converterManager ;
Containers : : Pointer < Trade : : AbstractSceneConverter > converter ;
if ( Utility : : String : : endsWith ( args . value ( " output " ) , " .blob " ) & & args . value ( " converter " ) = = " AnySceneConverter " ) {
converter . reset ( new BlobSceneConverter ) ;
if ( ! args . value ( " converter-options " ) . empty ( ) )
Warning { } < < " Converter options " < < args . value ( " converter-options " ) < < " ignored when writing a blob file " ;
} else {
converterManager . emplace (
args . value ( " plugin-dir " ) . empty ( ) ? std : : string { } :
Utility : : Directory : : join ( args . value ( " plugin-dir " ) , Trade : : AbstractSceneConverter : : pluginSearchPaths ( ) [ 0 ] ) } ;
Containers : : Pointer < Trade : : AbstractSceneConverter > converter = converterManager . loadAndInstantiate ( args . value ( " converter " ) ) ;
Utility : : Directory : : join ( args . value ( " plugin-dir " ) , Trade : : AbstractSceneConverter : : pluginSearchPaths ( ) [ 0 ] ) ) ;
converter = converterManager - > loadAndInstantiate ( args . value ( " converter " ) ) ;
if ( ! converter ) {
Debug { } < < " Available converter plugins: " < < Utility : : String : : join ( converterManager . aliasList ( ) , " , " ) ;
Debug { } < < " Available converter plugins: " < < Utility : : String : : join ( converterManager - > aliasList ( ) , " , " ) ;
return 2 ;
}
/* Set options, if passed */
if ( args . isSet ( " verbose " ) ) converter - > setFlags ( Trade : : SceneConverterFlag : : Verbose ) ;
Trade : : Implementation : : setOptions ( * converter , args . value ( " converter-options " ) ) ;
}
std : : chrono : : high_resolution_clock : : duration conversionTime ;