Simple Animated Texture Interface

Started by paulscode, September 08, 2009, 10:43:14 PM

Previous topic - Next topic

paulscode

-- This slot is reserved for the most recent working releases --




Downloads:

Texture Animator  Version date:  October 22, 2010
This includes the I2DAnimationController interface and the TextureAnimator helper class.

Example Implementations of I2DAnimationController:

GIF Controller  Version date:  September 12, 2009
Implementation of I2DAnimationController for playing GIF animations.

JMF Video Controller  Version date:  September 12, 2009
Implementation of I2DAnimationController for playing AVI, MOV, and MPEG videos via JMF.  Note: the pure-java version of JMF (which doesn't require user to install a native library) is compatible with only a very limited number of codecs (MOV H.263 encoding is about the best it can handle).

Manual 2D Manipulation Controller  Version date:  September 12, 2009
Implementation of I2DAnimationController to demonstrate manual 2D manipulation.  This example simulates the classic "mystify" screensaver.


Demos:

Animation Cube  (download the Source Code)
Demonstrates all three of the above I2DAnimationController example implementations - GIF, JMF video, and manual 2D.


Documentation:

Currently having a problem generating the JavaDoc for TextureAnimator.  Will post after I resolve the issue.

paulscode

#1
Project Overview:

After some recent work with ITextureEffect, I had the idea of creating a common interface for animating textures, whether from GIFs, AVIs, MOVs, etc., or from manual 2D graphics manipulation.

This project is built around a 2D animation controller interface, called I2DAnimationController.  It has interface methods for common actions like open(), play(), stop(), pause(), rewind(), etc.  On the surface, it might look like a movie player, but depending on what the controller is used for, you only need to implement whichever of the methods you want to use.  So for example, for manual 2D graphics manipulation, you only implement the following two methods:
    public Image getFrame();
    public boolean frameChanged();
    public int getWidth();
    public int getHeight();
    public void cleanup();

This allows you to manually manipulate the awt.Image however you like, and that image will be applied to the animated texture.

The second part of this project is a helper class called TextureAnimator, which takes instances of I2DAnimationController and creates ITextureEffects for the specified textures.  You can animate them individually via an animate( String texturename, Object syncObject ) method, or animate all of them them at once via an animateAll( Object syncObject ) method.

Just to give you an idea of how versatile this setup is, it is possible to create a second World and FrameBuffer with software-rendering, passing the display() method a BufferedImage's getGraphics(), and return a handle to that image through the getFrame() implementation.  This allows you to create a seperate 3D world rendered onto a texture inside another 3D world.  I'm not sure what you would use that for, but I tried it and it does work.

I also provided some example ITextureAnimator implementations for GIF, JMF video, and manual 2D image manipulation.

JavaMan

#2
Wow! Sounds exciting. I was trying to create a Swing to jpct binder to create "3D" uis, but for some reason I couldn't get the texture quality fast or good enough. Maybe I'll be able to use this project when you put it out. That movie applet you posted was amazing: it was so fast.

--Edit--Wow again. Amazingly fast.

paulscode

I finished writing the basic infrastructure and some example implementations of the I2DAnimationController interface.  I posted a few downloads above, including a simple demo applet.  I am currently having problems generating the JavaDoc, so I wasn't able to post that yet.

There is currently a bug (only in software-rendering mode), which it appears to be related to UVs, but it could also be related to the PixelGrabber code.  You can see the problem in the above demo applet by right-clicking on the canvas to switch between hardware and software rendering modes:

I'll try and create a simpler test-case to try and pinpoint the problem.

mystara

I am very interested in this. I have a short (few seconds) looping movie that I'd like to use as a texture and this looks like exactly the right thing to use!

Can you give an indication as to its efficiency? Is there one format or way of encoding the animation that will keep the frame rate high? I'm trying to FRAPS the output at 30 fps, so I need it to be ultra efficient :D

paulscode

#5
I just used JMF to play MOV H.263 encoding because it was free and easy to find and that particular encoding doesn't require the user to install the full version of JMF on their computer.  I'm sure there are probably better/more efficient options out there, though, if you were to do a little research.

As for efficiency once you have decoded the frames, probably the best thing would be if you make the width of your video/animation some power of 2, although I haven't really run any comparisons to acquire solid numbers on this.  Also, there is currently some kind of alignment problem with the code in my ITextureEffect implementation when using it in software rendering.  I'll try and correct the problem when I get back from vacation in January.

paulscode

I just wanted to correct a typo, since I've had two people ask me about it recently.  I meant to type MOV H.263 is about the best format that the pure-java version of JMF can handle, not H.264

fireside

#7
Just took a look at the demo so far.  I don't know if you know this, but the lwjgl applet loader was listed as potentially harmful and it was recommended not to run by java.  I don't suppose you have a demo of it running in software mode?  Looks like it would be useful for special effects.
click here->Fireside 7 Games<-

paulscode

I'll put together a software-mode only version.  Note that while this texture effect approach is easier to use and will work in any case, it is best suited for effects which require too many frames to fit into a single texture (videos, etc).   The "mosaic texture" idea which I used in my Animated Textures project (placing everything onto a single texture and changing the u/v coordinates to animate), while a little less wieldy, performs faster for effects with fewer frames (such as most GIF animations).  Ultimately, it just depends on the particular project I suppose.

fireside

#9
Hmm, the animated textures (animated gifs) would be more what I'm looking for yes.  I guess a software only wouldn't be necessary just on my account, then.  It looks like there is one there for animated GIF's.
click here->Fireside 7 Games<-

paulscode

Actually, looking back at the code, the applet already does both hardware and software mode (right-click to switch between the two).  The interface itself doesn't really care which rendering method jPCT is using.

There was a small bug related to this topic.  It manifested itself in software mode by misalignment and color problems (strangely, hardware mode didn't experience any problem even though the texture was not defined correctly).  I had solved the bug some time ago, but I never got around to updating this project.  I've recompiled and tested it, and everything seems to be working now, in case anyone is copying the code in their own projects.

AGP

Paul, have you generated the docs? Thanks for this little project, by the way.

Peter Dym

Paul, very nice. What about the Android version? I'm just looking for something like this to my AE project.

paulscode

Sorry, I totally forgot to port this to Android (I was going to after I ported my animated GIF texture project).   It will be very simple to port (just plugging in Bitmap's instead of BufferedImage's).  I'll look into this sometime next week.  Obviously the JMF video controller probably won't work on Android (not sure what alternatives to JMF are available on Android for accessing video frames)

Peter Dym

Thanx, really looking forward to see it (and use it ?) :-)