curv icon indicating copy to clipboard operation
curv copied to clipboard

Scriptable camera position

Open sebastien opened this issue 6 years ago • 5 comments

I would like to run curv with an offscreen rendering target (like -o png) so that it works with all curv programs. For instance:

curv -o png -O aa=4 curv/examples/mandelbrot.curv

yields the following error:

ERROR: can't export an infinite 2D shape to PNG
at file "deps/curv/examples/mandelbrot.curv":
 1|>make_shape {
 2|>    dist : everything.dist,
 3|>    colour (x,y,_,_) :
 4|>        do  var z := [x,y];
 5|>            var color := [0,0,0];
 6|>            var i := 0;
 7|>            while (i < 100) (
 8|>                z := csqr(z) + [x,y];
 9|>                if (dot(z,z) > 4)
10|>                    let cr = (i-1)-log(log(dot(z,z))/log 2)/log 2;
11|>                    in (
12|>                        color := [0.95+.012*cr, 1, .2+.4*(1+sin(.3*cr))];
13|>                        i := 100;
14|>                    )
15|>                else
16|>                    i := i + 1;
17|>            );
18|>        in sRGB.HSV color,
19|>    is_2d : true,
20|>}

I suppose this could be solved by introducing new options/flags to specify what should be rendered:

  • width, height for the width/height of the resulting image
  • scale for 2d renders (ie, the zoom)
  • x,y,z camera position for 3d renders (not sure if we can set fov and up) -- or whatever parameters you already use for rendering the 3d shapes.

This will allow me to fallback to server-side rendering when shaders don't compile to working WebGL:

image

sebastien avatar Jan 07 '19 22:01 sebastien

I think this restriction against exporting an infinite shape only applies to 2D shapes. It's because the 2D shape is scaled to fill the image. For 3D shapes, you essentially get a screen dump of whatever normally appears in the viewer window.

Here is a quick workaround:

curv -o mandel.png -x 'intersection(file "examples/mandelbrot.curv", rect(10,10))'

This trick provides a lot of flexibility, and covers most of what you asked for. There is no accessible FOV parameter right now, however.

doug-moen avatar Jan 07 '19 22:01 doug-moen

Smart! But what about camera position on a 3D shape and output image resolution? It's not super urgent, as I think the WebGL 2 fix that you suggested will solve this problem for now, and I can generate PNG from the canvas.

sebastien avatar Jan 08 '19 00:01 sebastien

Curv generates a PNG from the OpenGL viewport, and as you noted, it's just as easy for you to do that. In which case, you have direct control over camera and zoom.

From the Curv command line, you can simulate zoom and camera control by scaling, translating and rotating the object. It's a bit hacky; scriptable camera controls might be a good idea.

From the Curv command line, when exporting to PNG, you control output image resolution using -Oxsize= and -Oysize=. But, there is no command line control of the size of the viewer window, so that's another extension you might need.

doug-moen avatar Jan 08 '19 01:01 doug-moen

Cleaning up old issues... This now works: curv -o png -O aa=4 curv/examples/mandelbrot.curv. What's left to do? Scriptable camera position, using -O camera=.... Updating title of issue.

doug-moen avatar Sep 04 '19 01:09 doug-moen

This would be cool for two reasons:

  1. Allows for generating nice previews for people
  2. Gives curv some exposure when sharing said previews :)

lf94 avatar Sep 23 '21 11:09 lf94