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
    Offline / Send Message
    AlainGalvan polycounter lvl 6
    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:

    1.  
    2. import mset
    3.  
    4. baker = mset.BakerObject()
    5. # Use Quick Loader
    6. 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:

    1.  
    2. import mset
    3.  
    4. # Create a new BakerObject
    5. baker = mset.BakerObject()
    6.  
    7. # Import model
    8. myMesh = mset.importModel("E:/MyMesh.fbx")
    9.  
    10. # Traverse myMesh and find objects I want to be "High" or "Low"
    11. bakerDict = {}
    12.  
    13. def traverseMesh(o):
    14. if isinstance(o, mset.MeshObject):
    15. if "_low" in o.name:
    16. key = o.name.replace("_low", "").lower()
    17. if key in bakerDict:
    18. bakerDict[key]["low"] = o
    19. else:
    20. bakerDict[key] = {"low": o, "high": None}
    21. if "_high" in o.name:
    22. key = o.name.replace("_high", "").lower()
    23. if key in bakerDict:
    24. bakerDict[key]["high"] = o
    25. else:
    26. bakerDict[key] = {"low": None, "high": o}
    27. for obj in o.getChildren():
    28. traverseMesh(obj)
    29.  
    30. # Traverse the imported mesh file
    31. traverseMesh(myMesh)
    32.  
    33. # Convert bakerDict to baker scene hierarchy
    34. for key in bakerDict.keys():
    35. if bakerDict[key]["low"] != None and bakerDict[key]["high"] != None:
    36. curGroup = None
    37. for child in baker.getChildren():
    38. if key in child.name.lower():
    39. curGroup = child
    40. if curGroup == None:
    41. curGroup = baker.addGroup(key)
    42. for gc in curGroup.getChildren():
    43. if gc.name == "Low":
    44. bakerDict[key]["low"].parent = gc
    45. if gc.name == "High":
    46. bakerDict[key]["high"].parent = gc
    47.  
    48. # Done adding model, now we can bake
    49. baker.bake()
  • pooftorrent
    Oh my god, thank you! This was exactly what I needed!
  • Psychotic_Mike
    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
    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.