OpenJSCAD.org icon indicating copy to clipboard operation
OpenJSCAD.org copied to clipboard

ability to render an image of generated file from CLI

Open jtoy opened this issue 6 years ago • 16 comments

would be wonderful if we could output a jpg/png of the rendered object from the command line. We would probably need the ability to set camera angles for said rendered item. if this functionality wasn't added directly to the CLI tool, how would one go about doing this all from the CLI?

jtoy avatar Dec 10 '17 02:12 jtoy

@jtoy I'm not sure but there are application frameworks that are available to display graphics. If that is possible then the conversion of the display buffer to PNG/JPG is typically available as well.

Maybe this is a feature for the new application. But that's yet to be determined.

z3dev avatar Dec 10 '17 07:12 z3dev

actually, this is somewhat trivial to add, with a few possible limtations

  • I already did something like this for a few projects
  • ZoomToFit allows automatically fitting the shapes in the camera view (this will be present in the new viewer)
  • you can render things to a file using the SAME renderer that will be in the viewer using https://github.com/stackgl/headless-gl
  • main limitation is , you need to run the CLI on a machine that has opengl support
  • I can add this in a few hours once the new viewer is in :)

kaosat-dev avatar Dec 12 '17 09:12 kaosat-dev

Love it, would love to see this in the app. Would we be able to configure the camera angle? I have seen apps that implement their own version of tiny renderer: https://github.com/ssloy/tinyrenderer in case we don’t want OpenGL, but I think expecting OpenGL is fine, thoughts?

On Dec 11, 2017, at 11:27 PM, Mark Moissette [email protected] wrote:

actually, this is somewhat trivial to add, with a few possible limtations

I already did something like this for a few projects ZoomToFit allows automatically fitting the shapes in the camera view (this will be present in the new viewer) you can render things to a file using the SAME renderer that will be in the viewer using https://github.com/stackgl/headless-gl main limitation is , you need to run the CLI on a machine that has opengl support I can add this in a few hours :) — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

jtoy avatar Dec 12 '17 20:12 jtoy

yes, camera angle will be configurable :) Honestly I tried to dance around the need for OpenGL for around a year (for example for docker containters), never found a solution that really works :( but if you do that would be great :) In the meantime, OpenGL only is fine I think.

kaosat-dev avatar Dec 12 '17 20:12 kaosat-dev

I use a non OpenGL rendered all the time with pybullet. They implemented tiny renderer. I have not implemented it myself before,maybe one day, need to learn more C.

On Dec 12, 2017, at 10:13 AM, Mark Moissette [email protected] wrote:

yes, camera angle will be configurable :) Honestly I tried to dance around the need for OpenGL for around a year (for example for docker containters), never found a solution that really works :( but if you do that would be great :) In the meantime, OpenGL only is fine I think.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

jtoy avatar Dec 12 '17 20:12 jtoy

btw, in the meantime, I've added a python pipeline into my own workflow that allows me to render stl into images, works, but I'd much rather have it all done in OpenJSCAD.

jtoy avatar Feb 06 '18 18:02 jtoy

just found this nodejs version to render stls to images: https://www.npmjs.com/package/node-stl-thumbnailer would it be useful if i integrated this into OpenJSCAD?

jtoy avatar Feb 07 '18 19:02 jtoy

btw, in the meantime, I've added a python pipeline into my own workflow that allows me to render stl into images, works, but I'd much rather have it all done in OpenJSCAD.

@jtoy what did you use in python to render the STLs? I've been searching endlessly for a way to render STL files to images using python.

napter avatar Oct 06 '18 04:10 napter

@napter Have a look on VTK , one can read STL, set the camera angle and render as images. Also it can be all done in offscreen, i.e without even having to load up a 3D render.

Vishnu-C avatar Feb 19 '19 13:02 Vishnu-C

See the post in the User Group. @kaosat-dev added support for rendering JSCAD designs from the command line.

https://plus.google.com/112899217323877236232/posts/FmSPdYC4xHr

z3dev avatar Feb 20 '19 06:02 z3dev

I was looking through the archives on https://openjscad.nodebb.com but I didn't find the referred post there. @kaosat-dev did you have a way to render designs to a PNG or other image?

johnwebbcole avatar Sep 01 '19 21:09 johnwebbcole

@johnwebbcole I think that you are long for this.

https://github.com/jscad/OpenJSCAD.org/tree/V2/packages/utils/regl-renderer

z3dev avatar Sep 02 '19 08:09 z3dev

@johnwebcole , yes it should work rather well using @z3devs link, this file to be more precise https://github.com/jscad/OpenJSCAD.org/blob/V2/packages/utils/regl-renderer/demo-cli.js

You need to install pngjs manually if you want to try it, had to remove it as a dependency as it does not work on TravisCi (local use should be trivial)

kaosat-dev avatar Sep 02 '19 10:09 kaosat-dev

Thx for the directions, I was able to get it working in my unit tests for jscad-utils.

johnwebbcole avatar Sep 02 '19 22:09 johnwebbcole

good to know @johnwebbcole :) (btw I really need to get in touch with you about jscad-utils soonish, lots of very useful things that we would love to have for V2)

kaosat-dev avatar Sep 04 '19 12:09 kaosat-dev

@jtoy please try using the new renderer inside your pipeline.

https://github.com/jscad/OpenJSCAD.org/tree/V2/packages/utils/regl-renderer

If that works then this thread can be closed. ;)

z3dev avatar Oct 04 '20 00:10 z3dev