Lqd's Journal

Icon

It's actually pronounced liquid!

Scenile: Using JavaFX Project Nile in Java with Scenario

Introduction

I’d like to start today with a little helper library. I call it scenile because it integrates scenario (the scenegraph powering the JavaFX runtime) with project nile (the JavaFX production suite) (plus it’s funny). I’ve talked about it on my twitter stream so some of you might be familiar with it.

Project nile allows creating resources directly from designers’ tools (such as Adobe’s Illustrator and Photoshop) or from SVG files (inkscape also exports  files that can be used by JavaFX, i don’t know if it has been updated for 1.0 though), which can then be used in your javafx script application . This is really good and will help pave the way for better java UX. Nile exports FXZ files, which are FXD files zipped, plus any resource that might be used there, images, fonts, etc. The FXD file format is basically some JavaFX script describing the scene with primitives like rectangles, effects, transforms and so on.

However, i really wanted those features in the java world. Scenile is the result of this wish. It loads fxd/fxz files and creates the appropriate scenario objects, fills the properties, creates the scenegraph and returns it to you. After that, its work is done and scenario takes over to render, animate, etc.

As it stands today, scenile is at version 0.1, i’m still not happy with some of its internals yet, but i wanted to release it early. The whole FXD primitive set is certainly not supported but it can convert the nile samples and many other files i’ve thrown at it. Sometimes i stumbled upon nile bugs, but everything it suceeded in exporting, scenile was able to load correctly in my tests.

For the library users, it’s basically calling one function asking to load a fxz file, so the extensibility – or documentation *clears throat* – doesn’t matter much yet.

Demo and downloads

Domo, arigato, mister, roboto

Domo, arigato, mister, and roboto

I made a little demo to show how you’d use it and. I first created a comp (which you can see more clearly here at flickr) and exported it to fxz with nile. Now, if you load the scene with scenile, give it to a JSGPanel, you’re good to go, and you can then add it to your Swing app for example.

I thought of it as a character selection in some kind of game. It just shows 4 little robots, clicking on one shows its name in the console when launched locally. Clicking the badge at the bottom pauses or resumes the floating animation. As a side note, in the demo, i rasterized the background: because of its complexity (around 13k nodes resulting in a 6M fxd/1.6M fxz) the demo took between 10 and 20s to load, and the animations were far from smooth. Scenario is still being optimized and debugged as we speak, and animated content doesn’t perform all that well all the time (that’s why neither does JavaFX). In the demo, this lite version is much smaller  (around 150+ nodes) and performs well on the couple machines i tested it on.

Here’s the code, and here are the binaries (not packed), both containing 1 or 3 samples. I’m using java 6 in order to get the new gradient classes, if need be i could make a java 5 version.

Click the following image to launch the demo with webstart. (Note: the demo is a little perf intensive because of the animations and gaussian blurs. It depends on the javafx runtime, and works normally on windows – with the direct3d pipeline. I don’t have access to a Mac so i don’t know how it runs there. The animation is pretty sluggish on linux, scenario and decora do not pick up opengl even though the 3 machines or so i tested it on are pretty recent, with up to date drivers. Caching the nodes in images improves the situation but it’s not looking really good either. I’m sorry about that, but i’m not sure there’s anything i could do at this point, except maybe wait for JavaFX 1.1 or the final linux version – if anyone has any idea i’ll be glad to make the appropriate changes)

launch domo arigato demo

Supported scenario versions and license

Ok, that one’s a tough cookie. I first thought about supporting all versions of scenario. At the moment, scenario exists in two states, an open source version (0.6) under the GPL, and a 1.0+ version under the JavaFX license. Both have strengths and weaknesses.

The open source scenario is asleep at the moment (i’m trying not to say it’s dead). There’s more and more forum posts asking about its status, its license, the bug fixes and new features that are in the 1.0, but there’s no answer yet. Eventually, JavaFX will be open sourced, so when that time comes scenario should be as well.

The closed source version is on the opposite very much alive but cannot be distributed (in fact i think neither can the fxd support jar both the javafx.com samples and i use) and you have to depend on the whole fx runtime instead of the small scenario jar.  I believe a jnlp extension containing scenario/decora/javacss would really be useful and actually help people wait for days when the licenses are a little less restrictive. Not a lot of people were able to use it because of the GPL anyway.

I’d still like for them to be able to use Scenile though. Right now, a couple features are 1.0 specific, if anyone using scenario 0.6 needs compatibility, i’ll do that by the next version. That’s why the code is licensed under the modified BSD license. If you use scenario 0.6 directly and can comply to its GPL license, the BSD is compatible with the GPLv2 (even though scenile will be usable for you only at v0.2 or so, not right now). There’s no problem either if you use scenario 1.0+ by depending on the javafx runtime, or if somehow we get a jnlp extension for scenario, since the BSD is very permissive and thus also compatible with the JavaFX license.

Final words

This is really a simplistic piece of technology, however the possibilities are almost limitless because it streamlines the graphic resources integration. By helping integrating those really easily, you can do whatever you want in the design phase. I intend to post other demos showcasing those possibilities some more: it’s not just useful for character selections in games, but also in traditional ui design, or as i hope we’ll see soon, skinning components and look-and-feels, and more.

Hopefully i’ll see you there.

Category: java

Tagged: ,

2 Responses

  1. Sakuraba says:

    On OSX the animation is very slow, the robots get repainted liked once a second.

    Although I am a little disappointed by the current state of this, I am at the same time looking forward to the limitless possibilities once things are highly optimized. This could make it trivial to let a designer to its work in Illustrator, export to JavaFX, integrate with backend-data using Java libraries and deploy it anywhere.

    Looking forward to JavaFX 2.0

  2. lqd says:

    I think we could cache the robots under osx as well, i’ve modified the demo to do that. I’m not sure how much of an improvement that’ll make, we’ll see.

Leave a Reply