Home Marmoset

Is there a way to use the Quick Loader with the Python module?

Hello!

I want to load a file into the Quick Loader via python but I can't find any way to do it.
Because I have not found a way to use it I tried doing it like this:

> Import model 
> Create Baker
> Create BakeGroup
!=> Failed to reparent the model parts into the BakeGroups.

So, by chance, if the Quick Loader is unable in python; can I reparent objects somehow?

Replies

  • AlainGalvan
    Options
    Offline / Send Message
    AlainGalvan polycounter lvl 3
    You're right that the baker interface in Python doesn't support the use of the quick loader. We'll go ahead and expose the functionality for it in the next patch:

    
    import mset
    
    baker = mset.BakerObject()
    # Use Quick Loader
    baker.importModel("E:/MyModel.fbx")
    

    Currently Marmoset Toolbag does not support using the quick loader in Python, so to load files into a Baker in python you need to call <pre>mset.importModel</pre> ,  call <pre>addGroup</pre> to relevant groups, and assign the <pre>parent</pre> of the imported meshes to the <pre>"Low"</pre> or <pre>"High"</pre> objects of that group.

    Here's an example that does exactly that:

    
    import mset
    
    # Create a new BakerObject
    baker = mset.BakerObject()
    
    # Import model
    myMesh = mset.importModel("E:/MyMesh.fbx")
    
    # Traverse myMesh and find objects I want to be "High" or "Low"
    bakerDict = {}
    
    def traverseMesh(o):
    	if isinstance(o, mset.MeshObject):
    		if "_low" in o.name:
    			key = o.name.replace("_low", "").lower()
    			if key in bakerDict:
    				bakerDict[key]["low"] = o
    			else:
    				bakerDict[key] = {"low": o, "high": None}
    		if "_high" in o.name:
    			key = o.name.replace("_high", "").lower()
    			if key in bakerDict:
    				bakerDict[key]["high"] = o
    			else:
    				bakerDict[key] = {"low": None, "high": o}
    	for obj in o.getChildren():
    		traverseMesh(obj)
    
    # Traverse the imported mesh file
    traverseMesh(myMesh)
    
    # Convert bakerDict to baker scene hierarchy
    for key in bakerDict.keys():
    	if bakerDict[key]["low"] != None and bakerDict[key]["high"] != None:
    		curGroup = None
    		for child in baker.getChildren():
    			if key in child.name.lower():
    				curGroup = child
    		if curGroup == None:
    			curGroup = baker.addGroup(key)
    		for gc in curGroup.getChildren():
    			if gc.name == "Low":
    				bakerDict[key]["low"].parent = gc
    			if gc.name == "High":
    				bakerDict[key]["high"].parent = gc
    
    # Done adding model, now we can bake
    baker.bake()
    
  • pooftorrent
    Options
    Offline / Send Message
    Oh my god, thank you! This was exactly what I needed!
  • Psychotic_Mike
    Options
    Offline / Send Message
    Psychotic_Mike polycounter lvl 11
    The above method is not quite what I'm looking for. 

    Is there a way to have a group in Maya with an arbitrary amount of meshes all with either the suffix _low or _high and have marmoset create baking groups with those suffixes in the correct locations? (all _low under the low baking group and all _high in the high baking group)

    Maya

    Marmoset


    Also how would someone create an import button?
  • SunSan
    Options
    Offline / Send Message
    You can use the quick loader:

    import mset
    fbx_file = "C:/Users/zanthresun/Desktop/asd.fbx"
    baker = mset.BakerObject()
    baker.importModel(fbx_file)
Sign In or Register to comment.