SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
39 stars 10 forks source link

Faster way to get 2D images. #654

Open NeilBurkholder opened 3 years ago

NeilBurkholder commented 3 years ago

We need a faster alternative to Sketchup.active_model.active_view.write_image The problem is that when exporting half a dozen images the UI freezes for the entire duration (several seconds).

I'm proposing using a block similar to Sketchup::Http::Request.start. In addition it would be nice to get the raw data or even base64 data rather than needing to first write to a file. This might also help speed up the process.

This would allow generating images without freezing the SketchUp UI.

My current use case is pushing elevation and iso images to a web service.

NeilBurkholder commented 3 years ago

See this topic as well.

https://forums.sketchup.com/t/get-elevation-views-png/168151

DanRathbun commented 3 years ago

As I mentioned in the forum thread, file IO operations are blocking (in this and other cases) so that the user cannot interfere by making changes whilst the model or whatever (in this case views) are being saved. So an async block form method will not save you.

Down the road, the real solution would be a View#image_rep method so you could grab snapshots in memory and then write them out at your leisure, or just send the data to the server and then GC the objects.

In the short term, you might find a library that can grab screenshots. Maybe one that even ships with SketchUp ?

DanRathbun commented 3 years ago

Posted a proof in the forum topic that ImageMagick can grab screen crops, although it's not ready for "prime time" use.

thomthom commented 3 years ago

As I mentioned in the forum thread, file IO operations are blocking (in this and other cases) so that the user cannot interfere by making changes whilst the model or whatever (in this case views) are being saved. So an async block form method will not save you.

Depends what the slowdown is. If it's rendering the view to the 2d canvas then that might not be easy to do async. But actually writing the rendered pixel data to file can be done async in a background thread. And it's not unlikely the compressing is a good contributor to the slow down.

Profiling needs to be done to say for sure what can be done.

I'm proposing using a block similar to Sketchup::Http::Request.start. In addition it would be nice to get the raw data or even base64 data rather than needing to first write to a file. This might also help speed up the process.

This would allow generating images without freezing the SketchUp UI.

My current use case is pushing elevation and iso images to a web service.

When you say raw data, what do you mean? The raw uncompressed pixel data, that you'd get from ImageRep? Or are you thinking of the bytes of a compressed image (png, jpg etc)? There's a significant difference.

NeilBurkholder commented 3 years ago

When you say raw data, what do you mean? The raw uncompressed pixel data, that you'd get from ImageRep? Or are you thinking of the bytes of a compressed image (png, jpg etc)? There's a significant difference.

Either one would work, but I was thinking the compressed image bytes, as opposed to a file on disk.