antonWetzel / blender-to-godot

Importer for Godot for Blender
MIT License
10 stars 0 forks source link

Add button to reimport instead of reimport on every window toggle #1

Open coffandro opened 2 months ago

coffandro commented 2 months ago

A lot of people don't have the best PC's and personally I just don't like things re importing without it being important so I think it'd be nice to have a button at a position like here that does it? idfk {A9E01112-5BCE-4CE9-B73B-DCBF5BE0C6B0}

coffandro commented 2 months ago

I've got a button in the interface working now, can't figure out how to move it to the left of the other buttons nor how to to connect it though plugin.gd:

tool
extends EditorPlugin

var importer

var button

func _enter_tree():
    importer = preload("./importer.gd").new()
    add_import_plugin(importer)

    # Create the button
    button = Button.new()
    button.text = "Reload Blend Files"

    # Set a fixed size for the button
    button.rect_min_size = Vector2(30, 30)

    # Connect the button's pressed signal to a function
    button.connect("pressed", self, "_on_button_pressed")

    # Add the button to the toolbar, it will appear before other icons
    add_control_to_container(CONTAINER_TOOLBAR, button)

func _exit_tree():
    remove_import_plugin(importer)
    importer = null
    # Remove the button when the plugin is disabled
    remove_control_from_container(CONTAINER_TOOLBAR, button)
    button.queue_free()

func _on_button_pressed():
    print("Hello")
antonWetzel commented 2 months ago

Note

I don't plan to maintain this plugin. If possible upgrade to Godot 4.x for native Blender support or use another plugin.

Solution

Import Plugins use an options system to interact with the engine.

# importer.gd

...
# add import option
func get_import_options(preset):
    match preset:
        Preset.Default:
            return [{
                "name": "apply_modifiers",
                "default_value": true,
            }, {
                "name": "pause_reimport",
                "default_value": false,
            }]
        _:
            return []

# skip import if paused
func import(source_file, save_path, options, platform_variants, gen_files):
    if options["pause_reimport"]:
        push_warning("Reimport is paused.")
        return null
    var temp_path = source_file.replace(".blend", ".glb")
...

If you change importer.gd you must disable and reenable the plugin to load the change.