Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider exposing the internal frame count in ImageSequence #1968

Open
RoboDoig opened this issue Aug 12, 2024 · 2 comments
Open

Consider exposing the internal frame count in ImageSequence #1968

RoboDoig opened this issue Aug 12, 2024 · 2 comments

Comments

@RoboDoig
Copy link

Relates to the Bonsai.Shaders package.

In some cases, it is useful to be able to access the total frame count of a texture sequence at runtime in Bonsai. For example, when scrubbing through a texture sequence one may want to 'wrap' back around after the maximum or minimum index of the sequence has been reached. To do this, the limits of the texture sequence indices must be available.

As far as I can tell it's very tricky to access these values either through current Bonsai operators or extensions. ImageSequence can access this internally via GetFrames but the public property FrameCount is not updated if there is no user provided value (though the internal frame count can be overwritten if there is user-provided value for FrameCount). A simple solution might be to update the FrameCount property during the GetFrames method.

@RoboDoig RoboDoig changed the title Expose the internal frame count in ImageSequence Consider exposing the internal frame count in ImageSequence Aug 13, 2024
@RoboDoig
Copy link
Author

RoboDoig commented Sep 2, 2024

From Bonsai dev club 2/9/24:

Suggestion is rather to make TextureSequence a public class (like TextureArray), then the frame count can be accessed from the ResourceManager for the window (see BindTexture).

Making it public also requires documenting it.

@RoboDoig
Copy link
Author

RoboDoig commented Sep 5, 2024

Tested the PR for this with the following extension which allows me to access the texture sequence data needed for e.g.wrapping functionality:

using Bonsai;
using System;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
using Bonsai.Shaders;

public class GetTextureData : Source<TextureSequence>
{
    [TypeConverter(typeof(TextureNameConverter))]
    public string TextureName {get; set;}

    public override IObservable<TextureSequence> Generate()
    {
        return ShaderManager.WindowSource.Select(window => 
        {
            var textureSequence = window.ResourceManager.Load<Texture>(TextureName) as TextureSequence;
            Console.WriteLine(textureSequence.Textures.Length);
            return textureSequence;
        });
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant