|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Animation using raytraced images" |
| 4 | +date: 2017-01-08 05:31:13 |
| 5 | +categories: joonsrenderer update |
| 6 | +--- |
| 7 | +Sunflow is an open source global illumination rendering system written in Java written by [Christopher Kulla][fpsunflower]. I have recently updated to [build with maven][maven] using jdk-8 and to use the latest [janino jars][janino]. This is gem makes sunflow rendering easily available to `JRubyArt` and `propane` users using Joon Hylub Lees [joons-renderer][joons]:- |
| 8 | + |
| 9 | +### test.rb (JRubyArt Sketch) |
| 10 | +```ruby |
| 11 | +load_library :joonsrenderer |
| 12 | +include_package 'joons' |
| 13 | + |
| 14 | +attr_reader :jr, :eye, :center, :up, :count, :radius, :file_name |
| 15 | + |
| 16 | +def settings |
| 17 | + size(800, 600, P3D) |
| 18 | +end |
| 19 | + |
| 20 | +def setup |
| 21 | + sketch_title 'Animation' |
| 22 | + @file_name = 'Animation' |
| 23 | + @jr = JoonsRenderer.new(self) |
| 24 | + # Camera Setting. |
| 25 | + @eye = Vec3D.new(0, 0, 120) |
| 26 | + @center = Vec3D.new(0, 0, -1) |
| 27 | + @up = Vec3D.new(0, 1, 0) |
| 28 | + @count = 0 |
| 29 | + @radius = 35 |
| 30 | +end |
| 31 | + |
| 32 | +def draw |
| 33 | + jr.render # The draw loop that comes next is rendered |
| 34 | + jr.begin_record # Make sure to include things you want rendered. |
| 35 | + kamera(eye: eye, center: center, up: up) |
| 36 | + perspektiv(fov: PI / 4.0, aspect_ratio: 4 / 3.0, near_z: 5, far_z: 10_000) |
| 37 | + jr.background('cornell_box', 100, 100, 100) # Cornell Box: width, height, depth. |
| 38 | + jr.background('gi_ambient_occlusion') # Global illumination. |
| 39 | + # Sun. |
| 40 | + translate(0, -15, 0) |
| 41 | + jr.fill('light', 1, 60, 60) |
| 42 | + sphere(5) |
| 43 | + # Planet, revolving at +3 degrees per frame. |
| 44 | + translate(radius * DegLut.cos(count * 3), 0, radius * DegLut.sin(count * 3)) |
| 45 | + jr.fill('mirror') |
| 46 | + sphere(5) |
| 47 | + jr.end_record # Make sure to end record. |
| 48 | + # Display rendered image if render is completed, and the argument is true. |
| 49 | + jr.display_rendered(true) |
| 50 | + save_frame(format("%s%s", file_name, "_###.png")) |
| 51 | + @count += 1 |
| 52 | + no_loop if (count > 120) |
| 53 | +end |
| 54 | + |
| 55 | +``` |
| 56 | + |
| 57 | +### The Animated Ray Trace Sketch |
| 58 | +Now you hava a bunch of `*.png` images that you need to zip up to create a video |
| 59 | + |
| 60 | +```bash |
| 61 | +png2yuv -j Animation_%0.3d.png -f 25 -I p -b 1 > tmp.yuv # zip it all up |
| 62 | +ffmpeg2theora --optimize --videobitrate 16778 -o Animation.ogv tmp.yuv # convert |
| 63 | +``` |
| 64 | + |
| 65 | +<video src="/assets/Animation.ogv" poster="/assets/Animation.png" width="800" height="600" controls preload></video> |
| 66 | + |
| 67 | + |
| 68 | + [fpsunflower]:http://sunflow.sourceforge.net/ |
| 69 | + [maven]:https://github.com/monkstone/sunflow |
| 70 | + [joons]:https://github.com/joonhyublee/joons-renderer |
| 71 | + [janino]:http://janino-compiler.github.io/janino/ |
| 72 | + [github]:https://github.com/monkstone/joonsrenderer |
0 commit comments