-
-
Notifications
You must be signed in to change notification settings - Fork 311
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
Render frame to a file instead of a window #758
Comments
draw
output to a file instead of a window
draw
output to a file instead of a window
Thanks for the issue! I think the closest example to what you're after might be To ensure that only one frame is produced, you should be able to call I don't think we provide a nice or simple way of rendering the output of the Currently the process of instantiating a WGPU adapter, device and queue is tied quite closely to the window creation process (see here). Nannou doesn't yet provide an API to set up these items without also creating a window - I think this is one area where we could improve! It is technically possible today to use the I think ideally we should eventually expose a |
That's great! I'll check them out and let you know if I'm able to get it to work. I am pretty new to Rust, so I am not very confident about contributing to a big project like this one, but I'll try to do it. Let's go! Thanks for the quick response! |
Hello, @mitchmindtree! I had some time to give it a try, and I was able to set up something by taking different bits from the pointers you gave me that ended up like this: fn main() {
nannou::app(model).simple_window(view).run();
}
fn model(app: &App) -> Model {
app.set_loop_mode(LoopMode::loop_once());
Model {}
}
fn view(app: &App, _model: &Model, frame: Frame) {
let draw = app.draw();
draw.rect()
.x_y(0.0, 0.0)
.w(100.0)
.rgb(255.0, 0.0, 0.0);
draw.to_frame(app, &frame).unwrap();
println!("Path {:#?}", capture_directory(app));
let file_path = captured_frame_path(app, &frame);
app.main_window().capture_frame(file_path);
}
fn capture_directory(app: &App) -> std::path::PathBuf {
app.project_path()
.expect("could not locate project_path")
.join(app.exe_name().unwrap())
}
fn captured_frame_path(app: &App, frame: &Frame) -> std::path::PathBuf {
app.project_path()
.expect("failed to locate `project_path`")
.join(app.exe_name().unwrap())
.join(format!("{:03}", frame.nth()))
.with_extension("png")
} As you said, a window is instantiated, and then the frame is saved to a png file. The weird thing is that it saves two frames instead of one, and the Could you give me some pointers so I can write the |
Hi @alexfertel! @dzil123 has forked this repo and made a branch that produces a headless API (sorry dan I did some snooping). In the branch theres an example called |
Hello @fenjalien! Wow, that's great! The link that worked for me was https://github.com/dzil123/nannou/tree/headless for some reason, and I took a look and it certainly is very close to what I was hoping for! I'll see if I can play with it this weekend, this got me very excited, hahaha. Thank you for snooping 😁 |
Haha, you found my branch! It's not quite ready for inclusion into nannou, and I haven't thoroughly tested it, but the example does work. I think eventually it might be possible to integrate this into the real nannou repo, with a flag during the app builder or window creation to create a HeadlessWindow instead. However, for right now HeadlessApp is simply a different struct that duplicates or fakes some functionality of the real App. It's worth noting that I would appreciate any suggestions for how this API should look, or what your typical use cases for headless rendering are. |
Just a heads up, I'm working on my own version that keeps the same drawing logic but with an API more similar to nannou's. I've already tried attaching a headless window type to the main I'm now trying to create completely separate structs focused on headless with an API as close to the main structs as possible. We may be able to abstract from there... |
A slight update, I've started a PR for a headless feature. See: #784 |
Hello! I just wanted to say that I've been playing with https://github.com/dzil123/nannou/tree/headless a lot, and it works absolutely wonderfully. I haven't felt the need to make too many changes to the example, but that is because it works well for me. It would be great having this merged into nannou! |
Sorry for noise - would just love to know if this feature is still being investigated? I would really love to be able to make use of this! Or if not is this possible, with some acrobatics, from the current version? |
My current workflow in other generative art frameworks is to generate files with the output. I would like to know if there's a way to not create a window and just specify a file to dump the first frame.
I have been searching for two days and I haven't found a solution that I'm comfortable with. The closest approach I see is something like this. If I understood the code correctly it saves the frame to a file when pressing the
s
key.Thank you for this awesome framework!
The text was updated successfully, but these errors were encountered: