Wednesday, November 2, 2011

Introducing: the Env3D Scene Creator

It started out as a small bug fix to the "Start Env3D" visualization tool, and quickly evolved into a full blown framework and code generation tool.  The new Scene Creator in Env3D has to ability to setup a scene in env3d using drag and drop instead of creating and placing the objects in code  -- allowing students to create nicer looking games in a fraction of the time.  Furthermore, all the learning objectives are enhanced by allowing students to examine and modify generated source code.

Inspiration

I have always wanted to integrate drag-and-drop functionality into env3d -- it just makes so much more sense than placing objects in code using a series of env.addObject(...) calls.  The idea really came from Alice - a complete drag-and-drop 3D programming environment.  While Alice is wonderful tool for students learning to program for the first time, the drawback of Alice, in my opinion, is that students are limited to drag and drop, so it is not very suitable for non-beginners trying to write more complex software. 

Another wonderful piece of software from the BlueJ team - Greenfoot, takes a different approach.  It is a 2D programming environment with some drag-and-drop support.  The major difference between Greenfoot and Alice is that students actually learn how to program in Java.  Greenfoot simply provides drag-and-drop support for placement of objects, and a framework so that students can focus on programming individual objects instead of creating everything from scratch.

The Scene Creator in Env3D takes inspiration from both Alice and Greenfoot.  It has a 3D drag-and-drop interface for object placement, but generates a Greenfoot-like framework where students must customize using Java.  I suppose this could be a "best-of-both-worlds" solution, at least from my point of view :)

Getting started

To get started, download the latest development version of env3d_template.zip and extract to a directory of your choice.  Then start BlueJ and open the extracted directory (which is a BlueJ project).

After the env3d_template project is opened, go to the tools menu and select Env3D, you'll find the "Env3D Scene Creator" option available.


If this is your first time, you'll be presented with a black window and a few drop down menu items across the top.
The first 3 drop-down menus allows you to choose the background, the ground type, the third one allows you to drop a model into the environment.  Probably best to show how it works with a video:


Feel free to change the background and the ground at any time, I have included lots of different backgrounds and floor textures.  They are located in the "textures/skybox" and "textures/floor" directory if you want to add to or remove from it.

The most exciting part is of course adding models.  The scene creator scans the models/ directory for appropriate models.  Once you have chosen the model from the models drop-down menu, you are entered into "Object Edit Mode" where the mouse will be grabbed by the 3D window.  In edit mode, you navigate with W, A, S, D keys for movement, and the mouse for looking around (just like a modern video game).  When an object is selected, it will be shown in wireframe.  You can use the UP and DOWN arrows keys to resize the object, and the LEFT and RIGHT arrow keys to rotate the obejct.  Clicking on the mouse will place the currently selected object into the environment.  Pressing ESCAPE will take you out of edit mode and you get your mouse back.

Generating Code

When you hit the save button, the code will be generated in the BlueJ project.  Each model is one class, and is inherited from the GameObject class (for the Greenfoot users, this is roughly equivalent to the Actor class in Greenfoot).  The Game class is where the game can be launched.

The GameObject class has an empty method called move().  This move() method is called every frame of the game, so various animations and game logic can be implemented by overriding the move() method in sub-classes, as shown in the above video.

Conclusion

That's it for our basic tour of the Env3D Scene Creator.  Read the code to the GameObject class and the Game class for an idea of how the framework is setup (it is very similar to the Greenfoot framework).

There are lots more to the Scene Creator, including support for animated models, that is not covered by this introductory article.  I will be posting more articles soon, so stay tuned!

Labels: , , , , , , ,

Saturday, March 12, 2011

Mouse picking

The latest version of env3d adds the ability to use the mouse to interact with objects in 3D space.

Previously, the only mouse position related methods are Env.getMouseX(), and Env.getMouseY(). These methods return only the screen coordinates but not the pointer coordinates in 3D space. This makes it hard to implement features such as using a mouse of select an object inside the 3D environment.

Users of env3d now has a few more methods to use, the details can be found at http://env3d.org/beta/node/113.

Perhaps that most important method is Env.getPick(int screenX, int screenY). This method takes the screen's x and y coordinate and returns the first object in 3D space under that coordinate. The object returned is of the generic Object type so users will have to cast it to the appropriate type before using it.

Labels: , , , , , ,

Friday, November 5, 2010

A little history of Env3D

One of my students asked me recently about the history of Env3D. I thought I'd share it here:

It was 2002, I wanted to learn opengl and see if there was any way Java can use hardware acceleration. During my research, I came across 2 opengl wrapper libraries: LWJGL and JOGL. LWJGL is a community driven project while JOGL is supported by Sun (the company behind Java).

While the logical decision was to go with JOGL, I decided to use LWJGL instead as it has a much more active and vibrant community (just visit http://lwjgl.org to see for yourself). The result was a simple 3D engine which I used to create a few simple demos, but nothing that students can actually use.

Fast forward to 2006, machines have gotten more powerful and 3D hardware acceleration is available on even the cheapest of the motherboards, so I thought it might be interesting to use 3D graphics to teach first year Java. At the same time, we switched to the BlueJ textbook which is excellent, but in my opinion, lacks the "visual punch". So I started writing the first version of Env3D to support the textbook. That first version was based on the simple engine that I created back in 2002.

After using Env3D for the first time back in 2007, I realized that the library can be used for much more than just to support BlueJ -- it is actually a general purpose library that students can use to create fun little flash like games. There are 2 problems:

1) It's not easy to distribute the game to others -- it's not good to have your user install BlueJ and the Java JDK.

2) The underlying engine was not powerful enough to support high-end features like bone animation, shaders, etc.

The first problem was relatively easy to solve, it turned out that the LWJGL community had already come up with a way to turn LWJGL programs into applets! So I modified some of my code and added a a new feature in the Env3D-BlueJ extension to automate the creation of applets.

The second problem was much harder to solve, in order to support state-of-the-art graphical features, I needed to re-program my custom engine. I decided that it was too much work for one guy, so I started looking around for an alternative engine that Env3D can be based on. My research resulted in the javamonkey engine (http://www.jmonkeyengine.com/ ). It is an open-source engine that has all the features that I wanted, and it uses LWJGL for rendering! So for the past many months, I worked really hard to switch the internals of Env3D to use the Java Monkey engine. The version that you are using right now is the result of my months-long effort. In theory, future versions of Env3D can now use all of the features of the JavaMonkey engine!

So, in a nutshell, this is how the Env3D library look now:

Your program --> Env3D --> Java Monkey Engine --> LWJGL --> 3D hardware.

Labels: , , ,

Friday, November 20, 2009

Site redesign and new version

I have completely redesigned the env3d website. Besides looking way better, I have also included complete lessons on how to use env3d in CS1. You can find them under the "Learn" section of the website.

A new version of env3d is also available. A couple of major changes:

* No need to "install" the extension anymore. Simply download and open the blank project, and follow the lessons to add your own code.

* You can now create 3D-accelerated applets for online distribution.

If you like env3d or have questions or comments, feel free to drop me a line.

Labels: , , , , , ,

Friday, December 21, 2007

Wrapping up for the year

Well, I have just finished using env3d in my first year class. Feedbacks from students are very positive. I have also learned a lot about designing a good API and have been making changes to env3d through each assignment. Lots of work but I think the results are worth it. Here are some students videos on youtube.

I'm now working on using env3d in the follow-up course which teaches inheritance and software design. A few new improvements are already in CVS, the most notable being a new EnvCanvas class for use in GUI applications, a new EnvObject base class, and a new EnvObjectInterface. These new classes will (hopefully) be used to illustrate the usefulness of an inheritance hierarchy.

Labels: , , ,

Saturday, October 20, 2007

New features and some lessons learned

The latest version of env3d (still in cvs, not released yet) will have the following new features:
  • Transparent sprite support
  • Setting of camera angles
  • All resources can be loaded from a jar file.
Since all resources are now loaded from a jar file, you can distribute your application very easily. If you are using BlueJ, you can simply export the project to a jar file. Make sure that the lwjgl native library (lwjgl.dll in windows) is in the same directory as your jar. You can now execute the jar file directly.

This also means any application written using env3d can be setup to use java webstart technology. This will be a big plus for students who want to show off their projects! In the future, I may even incorporate applet support.

New features are great and all, but in my opinion, the most important update is the removal of some of the features.
  • The "move" method will no longer be called automatically
  • Adding a room will no longer automatically add all the objects inside the room
  • Adding of "systems" are not supported
What this means is that every object must be added/removed manually (by students). Env3d is meant to be a learning engine, and as I gain more experience using it, I find that it is best to make the engine do as little "magic" as possible. The only magic here is being able to put objects into a 3d environment. The rest should be done manually.

I am having so much fun using env3d in my class this term. I think that my students are having fun as well. I am able to create examples in Env3d that map almost directly to each chapter of the textbook, I will share them on the website once I have some time (end of term most likely).

Labels: , ,

Monday, July 9, 2007

Introducing env3d

I created env3d to help with my introductory Java course. The internal 3d engine was written a couple of years ago to help me learn OpenGL. Since then, I have been trying to find a way to apply some real-time 3d graphics into my teaching.

What I am planning to do is to cover the first 7 chapters of the bluej textbook using env3d as a tool for in-class demonstration and projects. That's why you'll find that I have used java reflection instead of interface for all 3d objects definitions in my examples.

Env3d is free (under GPL). Please try it out and let me know what you think. I would really appreciate some feedback before I start using it this Fall.

Labels: , , ,