How to load model in code?

HromonHromon Posts: 5Member

I have a question, very interesting, how to use external resources (obj, gltf2, etc.) through the code so that they can be added and deleted freely and the game responded to this?
 
For example, I have a compiled, ready-made game, and it should load models from some folder and display them on the screen

Comments

  • TwistedTwiglegTwistedTwigleg Posts: 3,525Admin

    As far as I know, it isn't really possible to load certain resources, like 3D models, outside of the project resources in Godot right now. I made a GitHub issue on this, but as far as I know, there is no way to import the source files for certain resources in Godot.

    If you are okay with converting the files to a format Godot can use, then there are some options. One option is to use .pck files that contain all of the data you want to import. This is probably the best way, since it is officially supported in Godot and allows for importing any/all resources. 3D models, textures, scripts, and more should be importable with .pck files.
    I have not used it myself, but there is a tutorial on the Godot documentation that explains a bit about how .pck files work.

    Another option is to export the files using Godot's file class, and then import that. I made a plugin for this, but like .pck files, it requires an addition step and the source files (like .obj) cannot be directly imported, but rather they have to be converted first.

    Finally, another option is writing an importer in GDScript or C#. Here on the forums, a user wrote their own OBJ parser in Godot (GDScript I believe) so they could import .obj files outside of the project in Godot. Here is a link to that topic if you want to take a look.

    Hopefully this helps a bit.
    Also, welcome to the forums!

  • HromonHromon Posts: 5Member

    Hopefully this helps a bit.
    Also, welcome to the forums!

    Thank you for your reply.

    Yes, I thought about the parser, but I don’t know what to do with binary files.
    I didn’t work with PCK and I don’t even know how, but I will definitely try it.

    Also, as an option, I thought of creating my own mini format and making an import plugin for the blender, but I don’t know its API.

  • MegalomaniakMegalomaniak Posts: 3,001Admin

    @Hromon Don't forget to check your email for a account confirmation link, as it stands all your posts are going to the moderation queue. There's a chance it might have ended up in your spam folder if you can't find it in other ones.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file