curv3d / curv

a language for making art using mathematics
Apache License 2.0
1.14k stars 73 forks source link

Scriptable camera position #56

Open sebastien opened 5 years ago

sebastien commented 5 years ago

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:

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

image

doug-moen commented 5 years ago

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.

sebastien commented 5 years ago

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.

doug-moen commented 5 years ago

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 commented 4 years ago

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.

lf94 commented 2 years ago

This would be cool for two reasons:

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