Skip to content

File resolving issues. #267

@IceReaper

Description

@IceReaper

For a project im working on, i need to handle texture resolvement myself.
While working with this, i encountered two problems. One i could hack around, and another one which i am stuck with atm:

  1. i can use ReadContext.Create to define a custom loader for the files.
    If a .gltf references a .bin however, the function only gets passed the filename of that .bin and does not combine the gltf path with the .bin file. So when i load "foo/bar.gltf" and it references "baz.bin" i would expect to get a path "foo/baz.bin". So in the loading function i do not know where to look for that particular file. I could work around this by doing this, but thats pretty annoying, so i hope SharpGLTF adresses this by itself:
var gltfLoader = new GltfLoader(path);
var settings = ReadContext.Create(name => gltfLoader.LoadFile(name));
var modelRoot = ModelRoot.Load(path, settings);

public sealed class GltfLoader(string gltfPath)
{
    public ArraySegment<byte> LoadFile(string path)
    {
        if (path != gltfPath)
            path = Path.Combine(Path.GetDirectoryName(gltfPath), path);

        using var stream = fileSystem.OpenRead(path);
        return stream.ReadBytes((uint)stream.Length);
    }
}
  1. Texture loading should be skippable, still providing the paths to those files.
    My project requires the framework to directly load images and stream them info gpu buffers, so i do not want sharpGLTF to also load those huge images into memory as i cannot use them from there. There is currently no way to disable auto texture loading, so i tried to simply return an empty array if the requested file is neither the gltf itself, nor the .bin file. While this correctly works, the path to those textures is nowhere stored. So i am unable to pass those paths into my framework which will load the image. It would be nice if the path (maybe even the resolved path, see issue 1) of a particular texture would be stored. In the PrimaryImage propety it is already possible to access the texture name, but the path is nowhere to be found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions