Skip to content

Resource::get_rid is not virtual #877

Closed

Description

@tefusion

In godot core this function is virtual (https://github.com/godotengine/godot/blob/e69b7083d45c5d8698508cce7086d361c4b1f44c/core/io/resource.h#L141) which is needed because for example classes like MeshInstance3D call get_rid to get the RID of the instance on the RenderingServer.

In GDExtensions all you get is a RID get_rid() const; call within Resource which makes stuff like creating custom meshes virtually impossible.

Activity

  1. MGilleronFJ commented on Sep 30, 2022

    @MGilleronFJ

    Maybe a workaround is to use ArrayMesh, so the mesh is created internally but you still have ability to procedurally generate it? The downside though, is that if you save that resource, it will also save vertex data, which may not be desired if your mesh is procedural I guess.

    I think if this function needs to be virtual to allow creating custom meshes, that would be a feature to request in Godot's API rather than GodotCpp?

  2. tefusion commented on Sep 30, 2022

    @tefusion
    Author

    Maybe a workaround is to use ArrayMesh, so the mesh is created internally but you still have ability to procedurally generate it?

    I think if this function needs to be virtual to allow creating custom meshes, that would be a feature to request in Godot's API rather than GodotCpp?

    Although it's possible that get_rid doesnt actually need to be virtual, because unless you create a new kind of mesh (which would however require to also modify RenderingServer to make it handle it), such mesh would still be made of vertex arrays.

    ArrayMesh, BoxMesh, SphereMesh etc all use the same kind of mesh RID. The only difference is the API on the resource classes. The advantage of using Mesh over ArrayMesh would then be that mesh data would never get saved, since your code would have to provide it every time in some way. ArrayMesh would work too, but would save the data unnecessarily.

    Thanks I'll look into that. The mesh in question is https://github.com/tefusion/godot-subdiv/blob/1f0b170114c6a577af5249f093bba7471b4ca277/src/resources/baked_subdiv_mesh.cpp which does generates data compatible with ArrayMesh, I just think doing that will require a hacky looking and more expensive solution. Also the function is already virtual and usable with modules and just not in the generated extension API.

    I'll open a seperate issue in Godot core, cause you're right changes need to be done there, just didn't know where to open GDExtension issues.

  3. tefusion commented on Oct 2, 2022

    @tefusion
    Author

    Maybe a workaround is to use ArrayMesh, so the mesh is created internally but you still have ability to procedurally generate it? The downside though, is that if you save that resource, it will also save vertex data, which may not be desired if your mesh is procedural I guess.

    I think if this function needs to be virtual to allow creating custom meshes, that would be a feature to request in Godot's API rather than GodotCpp?

    I still think it being virtual would be nice, but I could resolve my issue by extending ArrayMesh and generating at the _set call. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions