Hi!
I’m very new to Maya/Py programming and I’m trying to understand some OOP concepts and how they would relate to a tool that I’m developing.
Design/Patterns
I want to represent real world objects in Maya. Those real world objects would be made up of other objects. I’ve been studying different design patterns and I think the “Composite” pattern would work well for that. So I would want all of the objects to inherit from a custom class CdbObject. So CdbComposite and CdbUnit for example would inherit from CdbObject, where CdbComposite is multiple CdbUnits.
Each CdbUnit (the leaf) would have it’s own set of attributes, as each CdbUnit would represent a different real world object that can “do” different things. A CdbComposite would then be a collection of those things with it’s own interface that would control the CdbUnits. I’m not sure how to implement that yet, I feel like I’ve glanced at some design patterns that would allow for this this. Decoration?
Somethings needs to control how each CdbUnit interacts with another as well. Each CdbUnit has a type of mount, namely male or female in most cases. I think the “mount” should be a class as well. CdbUnit would have a mount type and when is put in a CdbComposite with another CdbUnit they need to see if their mount types are compatible and then that would dictate how they would interact.
The whole idea is to define a set a universal CdbObject and then be able to introduce new types of CdbUnits or then CdbComposites to the system as time goes on. The mount class, once defined doesn’t really change but every CdbUnit needs to have one to define how it should interact with other CdbUnits.
I would then want to be able to store CdbObjects in an array or maybe a custom class array. Then add/remove, animate attributes. Save their states and load them back in.
CdbLayout (would be a collection of CdbObjects(CdbUnits/CdbComposites)
i would want to be able to call:
CdbLayout.add(CdbUnit)
CdbLayout.remote(cdbUnit)
Then be able to call:
CdbUnit.spin()
CdbUnit.pan()
CdbUnit.tilt()
And a CdbComposite would need to dynamically create and iterface that controlled all of the CdbUnit’s interfaces that are children of it.
Implementation
Up until now I’ve just had a library of .mb files that a script procedurally imports and renames and adds the name to a list. I then in Maya can select each “rig” in the viewport that has custom attributes that I can animate. The problem is when I want to combine different .mb into a new rig, I have to manually connect them.
I want to design a system where each .mb inherits from a master class. CdbObject. Then a “rig” is a CdbComposite that is a number of CdbObjects that controls the attributes of it’s children. I want to user to be able to select dynamically what .mb/CdbUnits/CdbObjects they want to combine and have the system correctly put them together and generate the UI and interface. The user would then interact with the “rig” CdbComposite through the new interface that was created.
I’m struggling conceptually of how to create the CdbObject base class, as I’m very new to the Python/PyMel/OpenMaya. I watched a video where the entire system was setup using MObjects (so Maya API) which seamed like a good way to start. What is the best way to associate a class with a .mb file?
class CdbObject():
def init(self, arg):
pass
def create(self, arg)
if arg = something:
#import file: something.mb
How do I link the imported Maya DAG nodes to the CdbObject class?
This post is all over the place, so I thank anyone for their time that has made it this far. I’m trying to understand the Maya frameworks that are available and learn how to apply OOP Patterns, which I’m also learning as I go.
Thank,
Matt