nextr3d / Character-UI

Blender add-on for creating simple yet functional UIs for your characters.
Apache License 2.0
61 stars 4 forks source link

Automatic support of Soft body modifiers in the physics tab #27

Closed Mr-Lux closed 2 years ago

Mr-Lux commented 2 years ago

Hi,

In my workflow, I use the softbody modifier as the deformation for my physics. But I noticed that it is not recognized in the UI script generator.

I fiddled with the code and just added the ability to recognized it and add it with an extra info to know which modifier is used (if it's important for someone".

I am not a programmer per se, so I don't know if I was suppose to do a pull request, so here is the snipped of those lines.

So what I did was modifie and add the following lines of code in character_ui.py

@staticmethod
    def render_cages(layout, cages, panel=1):
        for c in cages:
            if c[1] == "OP%i" % (panel):
               #declare variable in the way I know.
                _addName = ""
                for m in c[0].modifiers:
                    if (m.type == "CLOTH" or m.type == "SOFT_BODY"): #add the alternative of sofbody
                        box = layout.box()
                        if m.type == "CLOTH" : _addName = "cloth" #add the extra info in the panel to know which one is used. might be useful, idk.
                        else: _addName = "soft body"
                        box.label(text=c[0].name + " - " + _addName + " modifier")
                        row = box.row(align=True)
                        row.prop(m, "show_viewport")
                        row.prop(m, "show_render")
                        box.prop(m.point_cache, "frame_start")
                        box.prop(m.point_cache, "frame_end")
                        icon = "TRASH"
                        text = "Delete Bake"
                        if not m.point_cache.is_baked:
                            icon = "PHYSICS"
                            text = "Bake"
                        box.operator("character_ui.bake_%s" % (
                            character_id.lower()), text=text, icon=icon).object_name = c[0].name

and in physics.py

def draw(self, context):
        layout = self.layout
        collection = context.scene.character_ui_physics_collection

        def render_meshes(items):
            for i in items:
                if hasattr(i, "type"):
                    if i.type == "MESH":
                        for m in i.modifiers:
                            if m.type == "CLOTH" or m.type == "SOFT_BODY": #same added condition to get the panel
                                op = layout.operator(
                                    "character_ui.use_as_cage", text=i.name)
                                op.cage = i.name

                else:
                    render_meshes([*i.children, *i.objects])
        objects_to_render = [*collection.children, *collection.objects]
        if len(objects_to_render):
            render_meshes(objects_to_render)
        else:
            layout.label(
                text="Collection has no objects or children collections", icon="ERROR")

It works for me, but I do not know how much it could affect the rest. Hope it helps.

nextr3d commented 2 years ago

Hello, thank you for bringing this to my attention.

The whole physics tab was taken from the old script and just slightly altered so it would work with the add-on. Back then I didn't need anything else but cloth so that's why it's so limited.

Thanks for providing the code but I think it would be better if I'd add support for the rest of the physics types. But I'll definitely use your idea of showing the different names.

I'm very busy right now so I don't know when I'll be able to work on this (hopefully soon) but if you know how to create a pull request I'll be more than happy to merge it because just by looking at it and you saying it works I think it's ready to be merged.

Mr-Lux commented 2 years ago

Thanks for the answer. I think I made the pull request, hope it helps.

nextr3d commented 2 years ago

Could not find the pull request so I made it myself.

I had to fix a small bug which prevented from baking the soft body modifier.

Once again thanks for the contribution, it means a lot and patches like this are more than welcome!