Trouble loading a 3D Model from C:\

Hi,

Does anyone have any experience/tips loading a 3D model from outside of the application’s resources? (My application is a Windows-Only simulation, many of the cross-platform warnings about this is understood).

I’ve got a super-simple example below that loads the resource one, but not the external one.

    public static void TestLoadModel(Node parent)
    {
        string ModelPathG = "C:/Util/Godot/Globe4-3DModels/Prep/Ship/GenericSupportShip/GenericSupportShip.glb";
        string ModelPathF = "C:/Util/Godot/Globe4-3DModels/Prep/Ship/GenericSupportShip/GenericSupportShip.fbx";
        string ModelPathR = "res://Resources/Models/Plane/Plane_Paper/PaperPlanes_v002.glb";

        PackedScene importedModel = (PackedScene)ResourceLoader.Load(ModelPathR);

        if (importedModel != null)
        {
            // Instance the model. Add the model to the scene
            Node modelInstance = importedModel.Instantiate();
            parent.AddChild(modelInstance);
            GD.Print($"====== Loaded model: {ModelPathR}");
        }
        else
        {
            GD.PrintErr($"====== Failed to load model: {ModelPathR}");
        }
    }

I’ve looked into other examples using GLTFState, but Godot isn’t compiling these as it has no visibility of the name, and I don’t know of any addition “using” clause or anything I could need.

Any help would be great. Thanks.

Hi,
should work with GltfDocument.
Try something similar:

var gLTFDocument = new GltfDocument();
var gLTFState = new GltfState();

var err = gLTFDocument.AppendFromFile(filePath, gLTFState, flags, basePath);

if (err == Error.Ok)
{
	Node3D scene = gLTFDocument.GenerateScene(gLTFState) as Node3D;
}

doc: GLTFDocument — Godot Engine (stable) documentation in English

Have a dormant project with modding support that uses it similarly to load objects in the level editor.

1 Like

Thanks. I hadn’t got passed the capitalization GLTFState vs GltfState.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.