universal-tween-engine icon indicating copy to clipboard operation
universal-tween-engine copied to clipboard

Using UTE at Java Server Side

Open kapcip opened this issue 8 years ago • 7 comments

I wish to use UTE at the server side.

Requirement: I will have dynamic user data with which I will be creating animation frames in a batch. Those animation frames I will be using to create videos.

Current Problem I am using LIBGDX which renders the frame on the screen and I am able to see the Window Frame. I don't want that frame to come up instead it should be an Headless Application just generating the frames in the file systems.

Anyone can help me accomplish this?

kapcip avatar Jul 04 '16 08:07 kapcip

UTE is not bound to any framework, so you can use it to create animations for anything, even console-based apps. UTE is meant to animate Java Objects. As long as the property you want to animate has a getter and a setter (or is directly accessible), you can write a TweenAccessor for it and animate it.

AurelienRibon avatar Jul 05 '16 10:07 AurelienRibon

Hi Aurelien - First of all, Thanks for creating an awesome framework and we really love it.We have this requirement of being able to run UTE without launching the UI and still producing animations in the form of image frames on filesystem. We are unable to find a solution to the same using the UI based examples you have. Can you please guide us in the right direction if that's possible?

vishalmanchanda avatar Jul 05 '16 15:07 vishalmanchanda

The project is a bit dusty, the documentation is still hosted at google code. However, have a look at this wiki page: https://code.google.com/archive/p/java-universal-tween-engine/wikis/GetStarted.wiki

In this page, I wrote the code of an example class I want to animate, named Particle. It's just a regular plain old Java class with 2 getters and 2 setters. not related to any UI framework. Then I create a TweenAccessor for this class, to instruct UTE how to manipulate Particle instances. Finally, I call Tween.to() on instances of the class, to let the magic happen.

All this code has no relation to UI at all, it's just plain old Java objects. Just replace the Particle class with the class you want to animate.

As for producing image frames server-side, it's way beyond the role of UTE. You need to separate the concerns: have some models that abstract what you want to draw, animate those models with UTE (call tweenManager with a fixed amount of ellapsed time), and then generate your images from your model properties.

AurelienRibon avatar Jul 05 '16 15:07 AurelienRibon

Thanks a lot for the precise explanation and sharing the sample. We already have separated concerns and logic to produce screenshots. We will try this example and let you know if that lets us get the frame screenshots without launching the UI.

vishalmanchanda avatar Jul 05 '16 15:07 vishalmanchanda

Thanks a lot for your quick response over the issue we discussed. We tried according to what you've said. Here is a pseudocode of our code that we wrote:-

Timeline.createSequence()
        .push(Tween.to(tweenSprite,SpriteAccessor.POS_XY,100f).target(100,200))
        .start(manager);

while(tweenManager.containsTarget(tweenSprite)) {
    COUNT++;
    tweenManager.update(1f);
    Graphics2D graphics2D = bgSprite.getImage().createGraphics();
    graphics2D.drawImage(tweenSprite.getImage(),tweenSprite.getX(),tweenSprite.getY(),null)
    ImageIO.write(bgSprite.getImage(),"jpg",new File("screens/screen+"+COUNT+".jpg");
}

For rendering, we are using normal Java Graphics object and writing the animated frame/image to file system. Above code is working though.

But we want to use a rendering framework for that, not any of our own code. LIBGDX is one of them, as you have mentioned on your blog:- http://www.aurelienribon.com/blog/2011/04/logic-vs-render-separation-of-concerns/

Problem with LIBGDX is, so far we know, it uses LwjglApplication or LwjglFrame or LwjglCanvas to initialise any LIBGDX Application which eventually launches a UI frame (we don't want that).

We just want the silent rendering. It should create animation frames at the backend and save it in the file system. Kinda like HeadlessApplication

It'll be great if you guide us in the right direction.

kapcip avatar Jul 11 '16 11:07 kapcip

I see. I'm not anymore familiar enough with LibGDX to guide you with that. At the time I was working on it (3 years ago), it did not have such a feature. Try to ask the libGDX team about a jpeg renderer instead of the common UI window, they may have many clues about how to get this done with a minimal fork (or maybe it's already part of the engine). Sorry :/

AurelienRibon avatar Jul 11 '16 12:07 AurelienRibon

Can we use Tween without SpriteBatch? Using below example, http://wiki.lwjgl.org/wiki/Render_to_Texture_with_Frame_Buffer_Objects_(FBO) I'm able to render frames without UI Window by making some code changes. Can we use Tween here without SpriteBatch as SpriteBatch needs a Window such as LWJGL to get initialised ( We can use SpriteBatch only after OpenGL context has been created )

kapcip avatar Jul 20 '16 03:07 kapcip