XLIVE99 / AutoGrid

Autotile system for gridmap in godot engine
MIT License
55 stars 3 forks source link

Feature Request: Create bitmasks for all meshinstance3d children #6

Open programnoir opened 1 month ago

programnoir commented 1 month ago

I think it'd be really handy if there was a fast way to set up an imported tilegrid that created and then set bitmasks for you. Lemme show you what I mean.

image

Here you can see I've added a button to the AutoGrid panel called "Quick Setup". All it does is iterate through children and add bitmasks.

func fast_setup() -> void:
    if( editMode == false ):
        print( "--- AUTOGRID ERROR --- Turn Edit Mode on." )
        return
    var children = get_editor_interface().get_edited_scene_root().get_children()
    if children.size() == 0:
        print("--- AUTOGRID ERROR --- Empty scene!")
        return
    for child in children:
        if child.name.ends_with("_agrid"):
            print( "--- AUTOGRID ERROR --- Autotile already generated." )
            return
    #   End defensive returns
    for child in children:
        if( child.has_node("AutoGrid_Bitmask") == false ):
            activateButton.create_bitmask( child )
            child.get_node( "AutoGrid_Bitmask" ).hide()
            child.get_node( "AutoGrid_Bitmask" ).deactivate()

image

There are a few additional features that I think would be good for this tool.

  1. Generating Trimesh static bodies for each mesh. I can't seem to find the function to do this, but you can select all the nodes and then select the option to generate the mesh for all of them. Still, that button would be great for expediting the process.
  2. Setting the bitmasks if it detects a valid name. You'll notice that my scene has nodes that are named binary numbers representing a bitmask. It's not a long enough name for a full bitmask, of course, but we could make an exception case where if the name is "eight binary digits long", then we'd assign bitmasks according to the currently selected AutoTile Axes in that right edge tab.

The only reason that I didn't move forward with implementing feature 2 myself is because apparently you represent bitmasks differently from how I learned on the web. A resource I found online taught me about starting from the top left corner (0x01) and proceeding left-to-right, row-by-row, until I arrive at the bottom-right corner (0x80). Your bitmasks sort of "spiral" upward, instead, it seems? If I'm understanding that right, I'd love to learn more about how it works!

By the way, are you interested in including collaborators on this plugin? If you prefer I stick with a fork, I can certainly do that, instead.

XLIVE99 commented 4 weeks ago

Thanks for the feature request. I have made this plugin to just have an autotile implementation of TileMap node. I am still missing some extra features but I don't know how to do them yet. With that in mind, let's continue with your feature requests:

I made bitmasks the way it came to my mind. I am sorry for this, it will make things a little hard. I am struggling to remember the bit order but you are right, it goes sort of spiral. Actually, bit value calculated by children order of the "AutoGrid_Bitmask" node. If you check "bitmask_holder.gd" script, calculate_bit_value() function, you can see top most child is the right most bit. Autotile algorithm is the same as TileMap node's autotile algorithm, I just extended it for 3D.

I will be grateful for collaborations, it will make things easier and faster.

XLIVE99 commented 3 weeks ago

In new version (v1.3) I have added quick setup feature. You just need to select MeshInstance nodes then AutoGrid/Create Bitmask to create bitmasks for each selected MeshInstance, same goes for removing.

I implemented automatically reloading autotile info with scene changes but then removed it because it reloads everytime, this can cause some trouble if you are switching scenes and didn't save autotile info, all your painted bitmasks will revert itself.

I will be waiting for your feedback on new version, if there won't any response in a month, I will consider this done and close the issue.