Author Topic: Simple Animated Texture Interface  (Read 22959 times)

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Simple Animated Texture Interface
« on: September 08, 2009, 10:43:14 pm »
-- 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.
« Last Edit: October 23, 2010, 03:50:54 am by paulscode »

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Simple Animated Texture Interface
« Reply #1 on: September 08, 2009, 10:43:59 pm »
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:
Code: [Select]
    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.
« Last Edit: September 13, 2009, 03:57:01 am by paulscode »

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Simple Animated Texture Interface
« Reply #2 on: September 10, 2009, 03:36:51 am »
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.
« Last Edit: September 14, 2009, 03:15:42 am by JavaMan »

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Simple Animated Texture Interface
« Reply #3 on: September 13, 2009, 03:54:32 am »
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.

Offline mystara

  • int
  • **
  • Posts: 79
    • View Profile
Re: Simple Animated Texture Interface
« Reply #4 on: December 15, 2009, 11:36:45 am »
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

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Simple Animated Texture Interface
« Reply #5 on: December 15, 2009, 01:28:15 pm »
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.
« Last Edit: December 20, 2009, 09:18:57 pm by paulscode »

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Simple Animated Texture Interface
« Reply #6 on: December 20, 2009, 09:22:55 pm »
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

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: Simple Animated Texture Interface
« Reply #7 on: October 22, 2010, 10:29:11 pm »
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.
« Last Edit: October 22, 2010, 10:32:28 pm by fireside »
click here->Fireside 7 Games<-

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Simple Animated Texture Interface
« Reply #8 on: October 22, 2010, 10:45:30 pm »
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.

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: Simple Animated Texture Interface
« Reply #9 on: October 23, 2010, 01:37:52 am »
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.
« Last Edit: October 23, 2010, 01:43:17 am by fireside »
click here->Fireside 7 Games<-

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Simple Animated Texture Interface
« Reply #10 on: October 23, 2010, 03:58:54 am »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Simple Animated Texture Interface
« Reply #11 on: December 20, 2011, 09:49:48 pm »
Paul, have you generated the docs? Thanks for this little project, by the way.

Offline Peter Dym

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Simple Animated Texture Interface
« Reply #12 on: February 03, 2012, 09:06:33 am »
Paul, very nice. What about the Android version? I'm just looking for something like this to my AE project.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Simple Animated Texture Interface
« Reply #13 on: February 03, 2012, 09:12:28 pm »
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)

Offline Peter Dym

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Simple Animated Texture Interface
« Reply #14 on: February 06, 2012, 09:35:59 am »
Thanx, really looking forward to see it (and use it ?) :-)