Importing a custom binary file with custom extension

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By majidarif


I have a custom packed file that contains all mesh data. I have written a script to parse it at runtime but I cannot add the file into the project since nothing is happening when I drag and drop it to the filesystem.

I guess the engine is not allowing me to import unknown or unsupported filetypes based on extension.

How can I go around this and add my own binary files?

Thank you!

:bust_in_silhouette: Reply From: Zylann

You can either write an import plugin or a custom resource loader.

Import plugins let Godot convert the file into its native format, so it can be loaded efficiently at runtime. See Import plugins — Godot Engine (stable) documentation in English

It is also possible to extend ResourceFormatLoader to load the file as-is: ResourceFormatLoader — Godot Engine (stable) documentation in English

An import plugin should work in your case if your binary file contains a mesh, so you can import it as a mesh.

Thank you for your answer and I think I will go with the import plugin route.

I have a followup question though, my single binary file contains multiple meshes (600+).

Currently when I use my script at runtime to parse it, I draw each mesh with a SurfaceTool and add it to an array.

My question is, can I import a single file but actually add multiple mesh to the res:// folder?


func get_save_extension():
	return "mesh"

func get_resource_type():
	return "Mesh"

Can I turn that into an array of meshes?

or can I just call the following:"%s.%s" % [save_path, get_save_extension()], mesh)

Multiple times?

majidarif | 2020-03-03 04:29

Hmm if your binary contains multiple meshes, you may need to import it as a scene with our multiple meshes in it, then. That’s what the DAE, GLTF or FBX importers do. I’m not familiar to how they do it, though.

Zylann | 2020-03-03 13:59

I tried MeshLibrary but it didn’t work.

I also tried Scene but I couldn’t add a mesh to a Spacial. I just need the mesh data to be used at runtime. I’m not gonna be using all but I do need to have all in memory in case I will need to use it.

I’m still looking for alternatives.

Thank you for your help.

majidarif | 2020-03-03 14:56

I also tried Scene but I couldn’t add a mesh to a Spacial

Importers that produce scenes use MeshInstance nodes to put the mesh on.

Zylann | 2020-03-03 18:37