<s> from director import geometryencoder <EOL> from director import ioUtils <EOL> from director . uuidutil import newUUID <EOL> import os <EOL> class MeshManager ( object ) : <EOL> def __init__ ( self ) : <EOL> self . meshes = { } <EOL> self . cacheDirectory = '<STR_LIT>' <EOL> self . cacheDataType = '<STR_LIT>' <EOL> self . collection = None <EOL> def initLCM ( self ) : <EOL> from director import lcmobjectcollection <EOL> self . collection = lcmobjectcollection . LCMObjectCollection ( channel = '<STR_LIT>' ) <EOL> self . collection . connectDescriptionUpdated ( self . _onDescriptionUpdated ) <EOL> for meshId in self . meshes . keys ( ) : <EOL> self . _publishMesh ( meshId ) <EOL> def add ( self , polyData , publish = True ) : <EOL> meshId = newUUID ( ) <EOL> self . meshes [ meshId ] = polyData <EOL> if publish and self . collection : <EOL> self . _publishMesh ( meshId ) <EOL> return meshId <EOL> def get ( self , meshId ) : <EOL> return self . meshes . get ( meshId ) <EOL> def getFilesystemFilename ( self , meshId ) : <EOL> if meshId in self . meshes : <EOL> filename = os . path . join ( self . cacheDirectory , '<STR_LIT>' % ( meshId , self . cacheDataType ) ) <EOL> if not os . path . isfile ( filename ) : <EOL> ioUtils . writePolyData ( self . get ( meshId ) , filename ) <EOL> return filename <EOL> return None <EOL> def _publishMesh ( self , meshId ) : <EOL> polyData = self . meshes [ meshId ] <EOL> self . collection . updateDescription ( dict ( uuid = meshId , data = geometryencoder . encodePolyData ( polyData ) ) , notify = False ) <EOL> def _onDescriptionUpdated ( self , collection , descriptionId ) : <EOL> desc = collection . getDescription ( descriptionId ) <EOL> meshId = desc [ '<STR_LIT>' ] <EOL> if meshId not in self . meshes : <EOL> polyData = geometryencoder . decodePolyData ( desc [ '<STR_LIT:data>' ] ) <EOL> self . meshes [ meshId ] = polyData </s>
