# ------------------------------------------------------------------------- # Description block """ bb_granuleconstants.py File version: 2.0.0 Compatibility: XSI 4.2, 5.11 Bernard Lebel September 2006 DESCRIPTION: Provides a bunch of constant dictionaries and lists as well as an object model interface. See BB wiki for documentation. HISTORY: 1.0.0: replaces bb_granuleexport_dictionaries.py 1.0.1: moved the file to bb_pipeline.bb_granules, renamed it from bb_granuleexport_constants to bb_granuleconstants 1.0.2: removed the kinematics from the element (models) constants 2.0.0: ***complete*** re-write of the constants, it was a mess """ # ------------------------------------------------------------------------- # Import block import getpass #from bb_texturing.bb_shaders import bb_dictionaryShaderCLSID #from bb_scripting import bb_logger # ------------------------------------------------------------------------- # ========================================================== # ========================================================== # # # DATA # # # ========================================================== # ========================================================== # ------------------------------------------------------------------------- # -------------------------------------- # MYSQL # -------------------------------------- dPROJECT_DATABASES = { 'TS': 'PipelineTorah' } # / dDATABASEMAP # -------------------------------------- # ELEMENTS # -------------------------------------- # All families by name aELEMENT_FAMILIES_BY_NAME = [ 'DYNAMIC', 'STATIC', 'STAGE' ] dELEMENT_FAMILIES_BY_NAME = { 'DYNAMIC' : 'D', 'STATIC' : 'S', 'STAGE' : 'G' } # All families by letter aELEMENT_FAMILIES_BY_LETTER = [ dELEMENT_FAMILIES_BY_NAME[ sFamily ] for sFamily in aELEMENT_FAMILIES_BY_NAME ] dELEMENT_FAMILIES_BY_LETTER = {} for sFamily, sLetter in dELEMENT_FAMILIES_BY_NAME.items(): dELEMENT_FAMILIES_BY_LETTER[ sLetter ] = sFamily # Families specific to model granules aMETAMODEL_FAMILIES_BY_NAME = [ 'DYNAMIC', 'STATIC', 'STAGE' ] # Families specific to stage granules aMETASTAGE_FAMILIES_BY_NAME = [ 'STAGE' ] # Meta groups # { meta group : [ meta parameters ] } dMETA_GROUPS = { 'model': [ 'ID', 'Project', 'ElementFamily', 'ElementDescription', 'ElementFullCode', 'ElementRoot', 'ElementMain', 'SubElementName', 'ModelClass', 'ModelRoot', 'ModelFile' ], 'stage': [ 'ID', 'Project', 'ElementFamily', 'ElementDescription', 'ElementFullCode', 'ElementRoot', ], 'shot': [ 'ID', 'Project' ] } aMETA_GROUPS = [ 'model', 'stage', 'shot' ] aMETA_PROPERTIES = [] dMETA_RPOPERTIES = { 'model': [ 'bb_emetamodel', 'bb_exportmetamodelgranulesproperty' ], 'stage': [ 'bb_emetastage' ], 'shot': [] } """ NOTE: so what's the difference between the metamodel group and the metastage group? metamodel group (metamodel): All granules, including models, of this group are related to models. Whenever we export/import granules or models of that group, they always depend in the model they belong to. Such granules use the bb_emetamodel custom property attached to their respective model to know where to go/come from. Also, granules of this group may go in any of the ELEMENTS directories. metastage group (metastage): Granules exported/imported from that group are NOT related to models in any way, but rather to specific stages. Such granules can include models. However, these granules use the bb_emetastage custom property to know where to go. Granules of this group may go ONLY in the STAGE directory. """ # -------------------------------------- # MODELS # -------------------------------------- dMODEL_CLASSES_BY_NAME = { 'MODELING' : 'MOD', 'SHAPE' : 'SHP', 'RENDERING' : 'RND', 'RIGGING - ANIMATION' : 'ANI', 'RIGGING - ENVELOPE' : 'ENV', 'RIGGING - GUIDE' : 'GUD', 'RIGGING - PARTICLES' : 'PTC' } dMODEL_CLASSES_BY_ACRONYM = {} for sModelClassName, sModelClassAcronym in dMODEL_CLASSES_BY_NAME.items(): dMODEL_CLASSES_BY_ACRONYM[ sModelClassAcronym ] = sModelClassName # Model classes specific to static elements aSTATIC_MODEL_CLASSES = [ 'MODELING', 'RENDERING' ] # Model classes specific to stage elements aSTAGE_MODEL_CLASSES = [ 'MODELING', 'RENDERING' ] # Model classes specific to dynamic elements aDYNAMIC_MODEL_CLASSES = [ 'MODELING', 'SHAPE', 'RENDERING', 'RIGGING - ANIMATION', 'RIGGING - ENVELOPE', 'RIGGING - GUIDE', 'RIGGING - PARTICLES' ] aMODEL_CLASSES_BY_NAME = aDYNAMIC_MODEL_CLASSES[:] aMODEL_CLASSES_BY_ACRONYM = [] for sModelClassName in aMODEL_CLASSES_BY_NAME: aMODEL_CLASSES_BY_ACRONYM.append( dMODEL_CLASSES_BY_NAME[ sModelClassName ] ) # -------------------------------------- # GRANULES # -------------------------------------- # Supported granules aGRANULES_ALL = [ 'vertexcolor', 'clskey', 'envweights', 'map', 'uvspace', 'wtmap', 'mat', 'picture', 'synoptic', 'model', 'kine', 'passe' ] # Database table types aTABLE_TYPES = [ 'element', 'stage', 'shot' ] # Replacement for dTABLEMAP_ELEMENTS. # Subgranules: a subgranule is any granule that is not a model. # Models are kind of "super-granules", because they encapsulate many types of subgranules. dGRANULES = { 'vertexcolor': { 'implemented': True, 'dbtable_element': 'TB_EGRANULES_CAV', 'dbtable_stage': None, 'dbtable_shot': None, 'dbcolumns': [ 'ColorAtVerticesIDs' ], 'isclusterproperty': True, 'clusterchannels': [ 'red', 'green', 'blue', 'alpha' ], 'clusterpropertypreset': 'ColorAtVertices', 'isxml': True, 'xmlheader': 'coloratvertices', 'fileextension': 'bbxmlcav', 'directory': 'COLORATVERTICES', 'ppg_label': 'Color at vertices', 'metamodelgroup': True, 'metastagegroup': False, 'subgranule': True }, 'clskey': { 'implemented': False, 'dbtable_element': 'TB_EGRANULES_SHP', 'dbtable_stage': None, 'dbtable_shot': None, 'dbcolumns': [ 'ShapesIDs' ], 'isclusterproperty': True, 'clusterchannels': [ '0', '1', '2' ], 'clusterpropertypreset': None, 'isxml': True, 'xmlheader': 'shape', 'fileextension': 'bbxmlshp', 'directory': 'SHAPES', 'ppg_label': 'Shapes', 'metamodelgroup': True, 'metastagegroup': False, 'subgranule': True }, 'envweights': { 'implemented': True, 'dbtable_element': 'TB_EGRANULES_ENV', 'dbtable_stage': None, 'dbtable_shot': None, 'dbcolumns': [ 'EnvelopeWeightsIDs' ], 'isclusterproperty': True, 'clusterchannels': [], 'clusterpropertypreset': None, 'isxml': True, 'xmlheader': 'envelope', 'fileextension': 'bbxmlenv', 'directory': 'ENVELOPEWEIGHTS', 'ppg_label': 'Envelope weights', 'metamodelgroup': True, 'metastagegroup': False, 'subgranule': True }, 'map': { 'implemented': True, 'dbtable_element': 'TB_EGRANULES_SYM', 'dbtable_stage': None, 'dbtable_shot': None, 'dbcolumns': [ 'SymmetryMapsIDs' ], 'isclusterproperty': True, 'clusterchannels': [ 'weight' ], 'clusterpropertypreset': 'Symmetry Map Property', 'isxml': True, 'xmlheader': 'symmetrymap', 'fileextension': 'bbxmlsymmap', 'directory': 'SYMMETRYMAPS', 'ppg_label': 'Symmetry maps', 'metamodelgroup': True, 'metastagegroup': False, 'subgranule': True }, 'uvspace': { 'implemented': True, 'dbtable_element': 'TB_EGRANULES_UV', 'dbtable_stage': None, 'dbtable_shot': None, 'dbtable_stage': None, 'dbtable_shot': None, 'dbcolumns': [ 'UVsIDs' ], 'isclusterproperty': True, 'clusterchannels': [ 'u', 'v', 'w' ], 'clusterpropertypreset': 'Texture Projection', 'isxml': True, 'xmlheader': 'uv', 'fileextension': 'bbxmluv', 'directory': 'UVS', 'ppg_label': 'UVs', 'metamodelgroup': True, 'metastagegroup': False, 'subgranule': True }, 'wtmap': { 'implemented': True, 'dbtable_element': 'TB_EGRANULES_WMAP', 'dbtable_stage': None, 'dbtable_shot': None, 'dbcolumns': [ 'WeightMapsIDs' ], 'isclusterproperty': True, 'clusterchannels': [ 'weight' ], 'clusterpropertypreset': 'Weight Map Property', 'isxml': True, 'xmlheader': 'weightmap', 'fileextension': 'bbxmlwmap', 'directory': 'WEIGHTMAPS', 'ppg_label': 'Weight maps', 'metamodelgroup': True, 'metastagegroup': False, 'subgranule': True }, 'mat': { 'implemented': True, 'dbtable_element': 'TB_EGRANULES_MAT', 'dbtable_stage': 'TB_GGRANULES_MAT', 'dbtable_shot': None, 'dbcolumns': [ 'MaterialsIDs' ], 'isclusterproperty': False, 'clusterchannels': None, 'clusterpropertypreset': None, 'isxml': True, 'xmlheader': 'material', 'fileextension': 'bbxmlmat', 'directory': 'MATERIALS', 'ppg_label': 'Materials', 'metamodelgroup': True, 'metastagegroup': True, 'subgranule': True }, 'picture': { 'implemented': False, 'dbtable_element': 'TB_EGRANULES_PIC', 'dbtable_stage': None, 'dbtable_shot': None, 'dbcolumns': [ 'PicturesIDs' ], 'isclusterproperty': False, 'clusterchannels': None, 'clusterpropertypreset': None, 'isxml': False, 'xmlheader': None, 'fileextension': None, 'directory': 'PICTURES', 'ppg_label': 'Pictures', 'metamodelgroup': True, 'metastagegroup': True, 'subgranule': True }, 'synoptic': { 'implemented': False, 'dbtable_element': 'TB_EGRANULES_SYNO', 'dbtable_stage': None, 'dbtable_shot': None, 'dbcolumns': [ 'SynopticsIDs' ], 'isclusterproperty': False, 'clusterchannels': None, 'clusterpropertypreset': None, 'isxml': False, 'xmlheader': None, 'fileextension': 'html', 'directory': 'SYNOPTICS', 'ppg_label': 'Synoptics', 'metamodelgroup': True, 'metastagegroup': True, 'subgranule': True }, 'model': { 'implemented': True, 'dbtable_element': 'TB_EGRANULES_MODELS', 'dbtable_stage': 'TB_GGRANULES_MODELS', 'dbtable_shot': None, 'dbcolumns': [ 'MainModelsIDs', 'SubElementModelsIDs' ], 'isclusterproperty': False, 'clusterchannels': None, 'clusterpropertypreset': None, 'isxml': False, 'xmlheader': None, 'fileextension': 'emdl', 'directory': 'MODELS', 'ppg_label': 'Models', 'metamodelgroup': True, 'metastagegroup': True, 'subgranule': False }, 'kine': { 'implemented': True, 'dbtable_element': 'TB_EGRANULES_SYNO', 'dbtable_stage': 'TB_GGRANULES_SYNO', 'dbtable_shot': None, 'dbcolumns': [ 'KinematicsIDs' ], 'isclusterproperty': False, 'clusterchannels': None, 'clusterpropertypreset': None, 'isxml': True, 'xmlheader': 'kinematics', 'fileextension': 'bbxmlkine', 'directory': 'KINEMATICS', 'ppg_label': 'Kinematics', 'metamodelgroup': False, 'metastagegroup': True, 'subgranule': True }, 'passe': { 'implemented': False, 'dbtable_element': None, 'dbtable_stage': 'TB_GGRANULES_PASSES', 'dbtable_shot': None, 'dbcolumns': [ 'PassesIDs' ], 'isclusterproperty': False, 'clusterchannels': None, 'clusterpropertypreset': None, 'isxml': True, 'xmlheader': 'passe', 'fileextension': 'bbxmlpasse', 'directory': 'PASSES', 'ppg_label': 'Passes', 'metamodelgroup': False, 'metastagegroup': True, 'subgranule': True } } # -------------------------------------- # CONSTRAINTS # -------------------------------------- # Map the constraint preset to the constraint type dCONSTRAINT_PRESETS = { 'poscns' : 'Position', 'oricns' : 'Orientation', 'dircns' : 'Direction', 'posecns' : 'Pose', 'distcns' : 'Distance', 'sclcns' : 'Scaling', 'symmetrycns' : 'Symmetry', 'pathcns' : 'Path', 'crvcns' : 'Curve', 'surfcns' : 'Surface', '2ptscns' : 'TwoPoints', '3ptscns' : 'ThreePoints', 'Nptscns' : 'NPoints', 'objclscns' : 'ObjectToCluster', 'bvolcns' : 'BoundingVolume', 'bplanecns' : 'BoundingPlane' } # Map the operator preset to the operator type dJOINT_OPERATORS = { 'SkeletonUpVectorOp' : 'SkeletonUpVector', 'SkeletonPrefAxisOp' : 'SkeletonPrefAxis' } # -------------------------------------- # XML # -------------------------------------- # List of supported values that can be read from XML parameter tags aXML_DATATYPES = [ 0, 2, 3, 4, 5, 8, 11, 18, 19, 22, 23, 31 ] # Map Python built-in function to convert from XML parameter tag to true data type dXML_DATATYPES = { 0: None, 2: int, 3: long, 4: float, 5: float, 8: str, 11: bool, 18: int, 19: long, 22: int, 23: int, 31: str } # ------------------------------------------------------------------------- # ========================================================== # ========================================================== # # # INTERFACE # # # ========================================================== # ========================================================== # ------------------------------------------------------------------------- # -------------------------------------- # MySQL # -------------------------------------- class bbMySQL: def __init__( self ): # Connection and authentification self.sDBUSER = 'produser' self.sDBPASSWORD = 'produser' #~ self.sDBHOST = '192.168.10.101' self.sDBHOST = '192.168.10.108' # station Bernard # Transactions self.sSELECT = 'SELECT' self.sUPDATE = 'UPDATE' self.sINSERT = 'INSERT' self.sLOCK = 'LOCK' self.sUNLOCK = 'UNLOCK' # Result fetching self.iFETCH_NONE = 0 # used with INSERT and UPDATE queries / iNOFETCHCOUNT self.iFETCH_ONE = 1 # fetchone() / iONEFETCHCOUNT self.iFETCH_ALL = 0 # fetchall() / iALLFETCHCOUNT # -------------------------------------- # DATABASES # -------------------------------------- class bbProjectDatabase: def __init__( self, sProject ): self.project = sProject self.database = dPROJECT_DATABASES[ self.project ] class bbProjectDatabases: def __call__( self, sProject ): if not sProject in dPROJECT_DATABASES: return None else: return bbProjectDatabase( sProject ) def __contains__( self, sProject ): if not sProject in dPROJECT_DATABASES: return False else: return True # -------------------------------------- # ELEMENTS # -------------------------------------- class bbElementFamily: def __init__( self, sElement, iType ): """ iType: 0: by name 1: by letter """ # Public if iType == 0: self.family = sElement self.letter = aELEMENT_FAMILIES_BY_NAME[ self.name ] else: self.family = aELEMENT_FAMILIES_BY_LETTER[ sElement ] self.letter = sElement class bbElementFamilies: def __getitem__( self, i ): return aELEMENT_FAMILIES_BY_NAME[i], aELEMENT_FAMILIES_BY_LETTER[i] def __call__( self, sElementFamily ): if sElementType in dELEMENT_FAMILIES_BY_NAME: return bbElementFamily( sElementFamily, 0 ) elif sElementType in dELEMENT_FAMILIES_BY_LETTER: return bbElementFamily( sElementFamily, 1 ) else: return None def __contains__( self, sElementFamily ): if sElementType in dELEMENT_FAMILIES_BY_NAME: return False else: return True # -------------------------------------- # META PARAMETERS # -------------------------------------- class bbMetaParameter: def __init__( self, sMetaGroup ): # Public self.parameters = dMETA_GROUPS[ sMetaGroup ] def __getitem__( self, i ): return self.parameters[i] def __contains__( self, sParameter ): if sParameter in self.parameters: return True else: return False class bbMetaParameters: def __getitem__( self, i ): return bbMetaParameter( aMETA_GROUPS[i] ) def __call__( self, sMetaGroup ): if not sMetaGroup in dMETA_GROUPS: return None else: return bbMetaParameter( sMetaGroup ) def __contains__( self, sMetaGroup ): if not sMetaGroup in dMETA_GROUPS: return False else: return True # -------------------------------------- # MODELS # -------------------------------------- class bbModelClass: def __init__( self, sModelClass, iType ): """ iType: 0: by name 1: by acronym """ # by name if iType == 0: self.modelclassname = sModelClass self.modelclassacronym = dMODEL_CLASSES_BY_NAME[ self.modelclassname ] # by acronym else: self.modelclassname = dMODEL_CLASSES_BY_ACRONYM[ sModelClass ] self.modelclassacronym = sModelClass class bbModelClasses: def __getitem__( self, i ): return aMODEL_CLASSES_BY_NAME[i], aMODEL_CLASSES_BY_ACRONYM[i] def __call__( self, sModelClass ): if sModelClass in dMODEL_CLASSES_BY_NAME: return bbModelClass( sModelClass, 0 ) elif sModelClass in dMODEL_CLASSES_BY_ACRONYM: return bbModelClass( sModelClass, 1 ) else: return None def __contains__( self, sModelClass ): if sModelClass in dMODEL_CLASSES_BY_NAME: return False else: return True # -------------------------------------- # GRANULES # -------------------------------------- class bbGranuleDBTable: def __init__( self, sGranuleType, sTableType ): # Public self.table = dGRANULES[ sGranuleType ][ 'dbtable_%s' % (sTableType,) ] class bbGranuleDBTables: def __init__( self, sGranuleType ): # Private self.sGranuleType = sGranuleType def __call__( self, sTableType ): """ sTableType (string): model stage shot """ if not sTableType in aTABLE_TYPES: return None else: return bbGranuleDBTable( self.sGranuleType, sTableType ) def __contains__( self, sTableType ): if not sTableType in aTABLE_TYPES: return False else: return True def __str__( self ): return str( aTABLE_TYPES ) class bbMetaGroup: def __init__( self, sGranuleType, sMetaGroup ): """ ATTRIBUTES: group (string): the meta group name (model or stage) enabled (boolean): if this particular group is enabled for this granule type families (list): the families for this meta group """ # Public self.group = sMetaGroup if sMetaGroup == 'model': self.enabled = dGRANULES[ sGranuleType ][ 'metamodelgroup' ] self.families = aMETAMODEL_FAMILIES_BY_NAME else: self.enabled = dGRANULES[ sGranuleType ][ 'metastagegroup' ] self.families = aMETASTAGE_FAMILIES_BY_NAME class bbMetaGroups: def __init__( self, sGranuleType ): # Private self.sGranuleType = sGranuleType def __call__( self, sMetaGroup ): """ sMetaGroup (string): model stage """ if not sMetaGroup in aMETA_GROUPS: return None else: return bbMetaGroup( self.sGranuleType, sMetaGroup ) def __contains__( self, sMetaGroup ): if not sMetaGroup in aMETA_GROUPS: return False else: return True class bbGranuleType: def __init__( self, sGranuleType ): # PRIVATE self.sGranuleType = sGranuleType #PUBLIC # Instance self.scriptname = self.sGranuleType self.name = dGRANULES[ sGranuleType ][ 'ppg_label' ] # Implemented self.implemented = dGRANULES[ sGranuleType ][ 'implemented' ] # Cluster properties self.isclusterproperty = dGRANULES[ sGranuleType ][ 'isclusterproperty' ] self.clusterchannels = dGRANULES[ sGranuleType ][ 'clusterchannels' ] self.clusterpropertypreset = dGRANULES[ sGranuleType ][ 'clusterpropertypreset' ] # XML self.isxml = dGRANULES[ sGranuleType ][ 'isxml' ] self.xmlheader = dGRANULES[ sGranuleType ][ 'xmlheader' ] # File system self.fileextension = dGRANULES[ sGranuleType ][ 'fileextension' ] self.directory = dGRANULES[ sGranuleType ][ 'directory' ] # PPG self.ppglabel = dGRANULES[ sGranuleType ][ 'ppg_label' ] # Databases self.dbcolumns = dGRANULES[ sGranuleType ][ 'dbcolumns' ] # Sub-granule self.subgranule = dGRANULES[ sGranuleType ][ 'subgranule' ] def __getattr__( self, sAttribute ): if sAttribute == 'metagroups': return bbMetaGroups( self.sGranuleType ) elif sAttribute == 'dbtables': return bbGranuleDBTables( self.sGranuleType ) else: return None def __str__( self ): return self.scriptname class bbGranuleTypes: def __getitem__( self, i ): return bbGranuleType( aGRANULES_ALL[i] ) def __call__( self, sGranuleType ): if not sGranuleType in dGRANULES: return None else: return bbGranuleType( sGranuleType ) def __contains__( self, sGranuleType ): if not sGranuleType in dGRANULES: return False else: return True def __str__( self ): return str(aGRANULES_ALL) # -------------------------------------- # CONSTRAINTS # -------------------------------------- class bbConstraintPreset: def __init__( self, sConstraintName ): self.constraint = sConstraintName self.preset = dCONSTRAINT_PRESETS[ self.constraint ] class bbConstraintPresets: def __call__( self, sConstraintName ): if not sConstraintName in dCONSTRAINT_PRESETS: return None else: return bbConstraintPreset( sConstraintName ) def __contains__( self, sConstraintName ): if not sConstraintName in dCONSTRAINT_PRESETS: return False else: return True class bbJointOperator: def __init__( self, sOperatorName ): self.operator = sOperatorName self.preset = dJOINT_OPERATORS[ self.operator ] class bbJointOperators: def __call__( self, sOperatorName ): if not sOperatorName in dJOINT_OPERATORS: return None else: return bbJoinOperator( sOperatorName ) def __contains__( self, sOperatorName ): if not sOperatorName in dJOINT_OPERATORS: return False else: return True # -------------------------------------- # XML # -------------------------------------- class bbXMLDataType: def __init__( self, iDatatype ): self.xmltype = iDatatype self.xsitype = dXML_DATATYPES[ self.xmltype ] class bbXMLDataTypes: def __getitem__( self, i ): return aXML_DATATYPES[i] def __call__( self, iDatatype ): if not iDatatype in dXML_DATATYPES: return None else: return bbXMLDataType( iDatatype ) def __contains__( self, iDatatype ): if not iDatatype in dXML_DATATYPES: return False else: return True # -------------------------------------- # MAIN # -------------------------------------- class bbGranuleConstants: def __init__( self ): # User running the script self.sUSER = getpass.getuser() # Verbosity flat self.bVERBOSE = False # Default value # Shaders #self.dSHADERS_DICTIONARY_BY_CLSID = bb_dictionaryShaderCLSID.dShadersDictionaryByCLSID # Asset version self.iNO_PREVIOUS_ASSET_VERSION = 0 self.iMIN_CURRENT_ASSET_VERSION = 1 self.iDEFAULT_ID = 1 # Granule import preferences, set per granule self.iOVERWRITE_DISABLED = 0 # don't import at all (usually aborts the execution altogether) self.iOVERWRITE_PRESERVE = 1 # import only if granule does not exists self.iOVERWRITE_OVERWRITE = 2 # import and overwrite existing granules def __getattr__( self, sAttribute ): # Attributes that return instances self.dAttributes = { 'sql': bbMySQL, 'projectdatabases': bbProjectDatabases, 'elementfamilies': bbElementFamilies, 'metaparameters': bbMetaParameters, 'modelclasses': bbModelClasses, 'granules': bbGranuleTypes, 'constraintpresets': bbConstraintPresets, 'jointoperators': bbJointOperators, 'xmldatatypes': bbXMLDataTypes } if not sAttribute in self.dAttributes: #bb_logger.log( '', '< bb_granulesconstants_bbGranuleConstants.__getattr__ > :: Attribute "%s" not implemented.' % (sAttribute,), 'ERROR' ) return None else: # Call the named class return self.dAttributes[ sAttribute ]() # ------------------------------------------------------------------------- # Script block #~ c = bbGranuleConstants()