jon-heard / Godot-MagicaVoxel-Importer-with-Extensions

A Godot plugin to import MagicaVoxel .vox files as meshes.
MIT License
20 stars 4 forks source link

Godot hangs during import of .vox files [Godot 4] #2

Open KevinErath opened 1 year ago

KevinErath commented 1 year ago

When i install the plugin and add a single .vox File importing works, but as soon when i add several files at once it hangs while importing and it will never finish.

image

This issue becomes even more annoying when restoring a project from git and opening the godot editor. It will never finish reimporting the files.

You can test the problem by creating a new project, adding a few Voxel Files (e.g. the sample files which come with magica voxel) and then install and activate the MagixaVoxel importer plugin.

The console output is as follows: MagicaVoxel Mesh Importer: Ready MagicaVoxel MeshLibrary Importer: Ready Importing: res://addons/MagicaVoxel_Importer_with_Extensions/Metadata/vox-icon.vox (scale: 0.1, file version: 150, greedy mesh: true, snap to ground: false) Importing: res://cars.vox (scale: 0.1, file version: 200, greedy mesh: true, snap to ground: false) Importing: res://3x3x3.vox (scale: 0.1, file version: 200, greedy mesh: true, snap to ground: false) Importing: res://castle.vox (scale: 0.1, file version: 200, greedy mesh: true, snap to ground: false) Importing: res://chr_knight.vox (scale: 0.1, file version: 200, greedy mesh: true, snap to ground: false) Importing: res://doom.vox (scale: 0.1, file version: 200, greedy mesh: true, snap to ground: false) Importing: res://monu1.vox (scale: 0.1, file version: 200, greedy mesh: true, snap to ground: false) Importing: res://room.vox (scale: 0.1, file version: 200, greedy mesh: true, snap to ground: false) Importing: res://menger.vox (scale: 0.1, file version: 200, greedy mesh: true, snap to ground: false) Importing: res://teapot.vox (scale: 0.1, file version: 200, greedy mesh: true, snap to ground: false) Importing: res://monu3.vox (scale: 0.1, file version: 200, greedy mesh: true, snap to ground: false) Importing: res://monu2.vox (scale: 0.1, file version: 200, greedy mesh: true, snap to ground: false) <ArrayMesh#-9223370095848265367> <ArrayMesh#-9223370088214631934> <ArrayMesh#-9223370080128013634> <ArrayMesh#-9223370079591143786> <ArrayMesh#-9223370078584509762> <ArrayMesh#-9223370078517401459> <ArrayMesh#-9223370048519738571> <ArrayMesh#-9223370048385520529> <ArrayMesh#-9223370048217749282> <ArrayMesh#-9223370048049977438> <ArrayMesh#-9223370047932536428> <ArrayMesh#-9223370047865427044>

It seems to do something, but the import never stops. Also only a few .import files are created. Also the mesh files are never written: image

I tried godot 4.0.2, 4.0.3 RC and even the latest build of 4.1. I also tried the linux version, which has the same problem.

The issue seems related to "ResourceSaver.save(meshes[0], full_path)" as the importer itself seems to be working without any issues. For example i can manually load the voxel files from script.

With Godot 3.5 everything seems to be working (Using related MagicaVoxel Importer Version).

Do others have the same problem? Do you have an idea whats going wrong?

ezietsman commented 1 year ago

I have the same problem Godot 4.0.3 Windows 10

bei64 commented 1 year ago

Had the same issue on Mac OS and Pop OS

but it seems like it happens when there are multiple .vox files to import at the same time. if we add one file then let the importer import the file then add the next, it seem to work. but if there is a commit with multiple files then it hangs

Fifut commented 1 year ago

Same issue with Godot 4.1.2

I put a print log in the add-on script file to see what happens. Files are imported in parallel, and as importing a file takes a certain amount of time, if it's all imported at the same time, it's very, very long (for 100x100x100 grid)!

Importing involves a lot of interlocking for and while loops.

I don't know if there's a way to make sure that the importing is done one after the other.

ryangroth5 commented 1 year ago

I can comment out line 9 and 17 in plugin.gd and this works correctly, which suggests it may be a concurrancy issue with the two importers working on the same files?

// plugin.gd

@tool
extends EditorPlugin

var pluginToMesh
var pluginToMeshLibrary

func _enter_tree():
    pluginToMesh = preload('vox-importer-mesh.gd').new()
    #pluginToMeshLibrary = preload('vox-importer-meshLibrary.gd').new()
    add_import_plugin(pluginToMesh)
    add_import_plugin(pluginToMeshLibrary)
    add_custom_type("FramedMeshInstance", "MeshInstance3D",
            preload("framed_mesh_instance.gd"), preload("framed_mesh_instance.png"))

func _exit_tree():
    remove_import_plugin(pluginToMesh)
    #remove_import_plugin(pluginToMeshLibrary)
    pluginToMesh = null
    pluginToMeshLibrary = null
    remove_custom_type("FramedMeshInstance")

func _get_priority() -> float:
    return 1.0
fwsGonzo commented 1 year ago

Unfortunately the work-around did not work for me. It's stuck loading even with the comments.

bei64 commented 11 months ago

Been trying some stuff and found a workaround for the issue. in Project settings under General/Editor/Import there is a setting Use Multiple Threads. Turn off that and imports started to work for me.

AlexeyGrishin commented 11 months ago

Been trying some stuff and found a workaround for the issue. in Project settings under General/Editor/Import there is a setting Use Multiple Threads. Turn off that and imports started to work for me.

Man, you've saved my day!

steven-aj commented 10 months ago

Been trying some stuff and found a workaround for the issue. in Project settings under General/Editor/Import there is a setting Use Multiple Threads. Turn off that and imports started to work for me.

Unfortunately, this didn't speed up imports for me.\

Edit: Tried on Windows 11 & Mac OS