Skip to main content

Scene Graph Morphing ? I'm 99% sure that it supports it can you show me ?

8 replies [Last post]
j0ke
Offline
Joined: 2006-06-02

Hello I like scene graph very much I think it is great and i think it can be used not from JavaFX only but from something like XAML or MXML for Java too. So its great I just have one question i know that javaFX supports morphing ( for example flash supports it, WPF doesn't support it ) can you show me example about how to use scene graph with morphing of shapes ? Thanks

And something other i know that jazz is dead but will be nice if scene graph have some codename because it is really really hard to search in google for examples because 99% of cases are for Java3D or something other.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mortennobel
Offline
Joined: 2004-11-03

As far as I know, the java scenegraph project does not supports shape morphing. But you could Morphing2D from http://swinglabs.org/.

A short java example using both the Scenegraph and the Morphing2D class, shows a red circle morphs into a rectangle.

Kind regards,
Morten

____________ Example: Morphing in Java Scenegraph using Morphing2D from SwingX

import com.sun.scenario.scenegraph.JSGPanel;
import com.sun.scenario.scenegraph.SGShape;
import com.sun.scenario.scenegraph.SGAbstractShape;
import com.sun.scenario.animation.Clip;
import com.sun.scenario.animation.TimingTargetAdapter;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.Ellipse2D;

import org.jdesktop.swingx.geom.Morphing2D;

public class MorphTest extends JFrame {
public MorphTest() {
JSGPanel panel = new JSGPanel();
getContentPane().setLayout(new BorderLayout());
getContentPane().add(panel, BorderLayout.CENTER);

final SGShape shape = new SGShape();
shape.setFillPaint(Color.red);
shape.setMode(SGAbstractShape.Mode.FILL);

final Shape source = new Rectangle(10,10,50,50);
final Shape dest = new Ellipse2D.Float(10,10,50,50);

shape.setShape(source);

panel.setScene(shape);

final Morphing2D morph = new Morphing2D(source, dest);
Clip clip = Clip.create(4000,Clip.INDEFINITE, new TimingTargetAdapter(){
public void timingEvent(float fraction) {
morph.setMorphing(fraction);
shape.setShape(morph);
}
});
clip.start();
}

public static void main(String[] args) {
MorphTest frame = new MorphTest();
frame.setSize(500,500);
frame.setVisible(true);
}
}

j0ke
Offline
Joined: 2006-06-02

hmm this doesnt work for me. The clip is started but i dont see animation. Im using JDK 1.6 update 4, swingx-0.9.2 , scenario 0.6.
But i will check how to use morphing2D maybe it's something little.

Message was edited by: j0ke

Message was edited by: j0ke

Morten Nobel-Jørgensen

I was using scenario 0.5

To make it work using 0.6 replace
public void timingEvent(float fraction) {
with
public void timingEvent(float fraction, long duration) {

Kind regards,
Morten

2008/4/16, scenario@javadesktop.org :
>
> hmm this doesnt work for me. The clip is started but i dont see animation.
> Im using JDK 1.6 update 4, swingx-0.9.2 , scenario 0.6.
> [Message sent by forum member 'j0ke' (j0ke)]
>
> http://forums.java.net/jive/thread.jspa?messageID=269438
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@scenegraph.dev.java.net
> For additional commands, e-mail: dev-help@scenegraph.dev.java.net
>
>
[att1.html]

j0ke
Offline
Joined: 2006-06-02

yes thanks now works but when the morph is completes i get
Exception in thread "AWT-EventQueue-1" java.lang.InternalError: unimplemented
at org.jdesktop.swingx.geom.Morphing2D.contains(Morphing2D.java:177)
at org.jdesktop.swingx.geom.Morphing2D.contains(Morphing2D.java:184)
at com.sun.scenario.scenegraph.SGShape.contains(SGShape.java:468)
at com.sun.scenario.scenegraph.SGNode.pickRecursive(SGNode.java:327)
at com.sun.scenario.scenegraph.SGNode.pickRecursive(SGNode.java:340)
at com.sun.scenario.scenegraph.SGNode.pickRecursive(SGNode.java:340)
at com.sun.scenario.scenegraph.SGNode.pick(SGNode.java:358)
at com.sun.scenario.scenegraph.SGEventQueue.getDeepestSGComponentTransformInverse(SGEventQueue.java:100)
at com.sun.scenario.scenegraph.SGEventQueue.beforeDispatch(SGEventQueue.java:225)
at com.sun.scenario.scenegraph.SGEventQueue.dispatchEvent(SGEventQueue.java:373)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Exception in thread "AWT-EventQueue-1" java.lang.InternalError: unimplemented
at org.jdesktop.swingx.geom.Morphing2D.contains(Morphing2D.java:177)
at org.jdesktop.swingx.geom.Morphing2D.contains(Morphing2D.java:184)
at com.sun.scenario.scenegraph.SGShape.contains(SGShape.java:468)
at com.sun.scenario.scenegraph.SGNode.pickRecursive(SGNode.java:327)
at com.sun.scenario.scenegraph.SGNode.pickRecursive(SGNode.java:340)
at com.sun.scenario.scenegraph.SGNode.pickRecursive(SGNode.java:340)
at com.sun.scenario.scenegraph.SGNode.pick(SGNode.java:358)
at com.sun.scenario.scenegraph.SGEventQueue.getDeepestSGComponentTransformInverse(SGEventQueue.java:100)
at com.sun.scenario.scenegraph.SGEventQueue.beforeDispatch(SGEventQueue.java:225)
at com.sun.scenario.scenegraph.SGEventQueue.dispatchEvent(SGEventQueue.java:373)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Exception in thread "AWT-EventQueue-1" java.lang.InternalError: unimplemented
at org.jdesktop.swingx.geom.Morphing2D.contains(Morphing2D.java:177)
at org.jdesktop.swingx.geom.Morphing2D.contains(Morphing2D.java:184)
at com.sun.scenario.scenegraph.SGShape.contains(SGShape.java:468)
at com.sun.scenario.scenegraph.SGNode.pickRecursive(SGNode.java:327)
at com.sun.scenario.scenegraph.SGNode.pickRecursive(SGNode.java:340)
at com.sun.scenario.scenegraph.SGNode.pickRecursive(SGNode.java:340)
at com.sun.scenario.scenegraph.SGNode.pick(SGNode.java:358)
at com.sun.scenario.scenegraph.SGEventQueue.getDeepestSGComponentTransformInverse(SGEventQueue.java:100)
at com.sun.scenario.scenegraph.SGEventQueue.beforeDispatch(SGEventQueue.java:225)
at com.sun.scenario.scenegraph.SGEventQueue.dispatchEvent(SGEventQueue.java:373)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

never mind its not so important for me, thanks for the help :)

j0ke
Offline
Joined: 2006-06-02

The Exception is thrown when i move the mouse over the JFrame.

Exception in thread "AWT-EventQueue-1" java.lang.InternalError: unimplemented
at org.jdesktop.swingx.geom.Morphing2D.contains(Morphing2D.java:177)

never mind. maybe is because i use swingx 0.9.2

Message was edited by: j0ke

mortennobel
Offline
Joined: 2004-11-03

The problem is that the Morphing2D does not implement collision detection, but if you only want a simple morphing animation it doesn't really matter.

To remove the error, simply overwrite the contains(Point2D point) in SGShape as showed in the example below (Alternative overwrite the contains method in Morphing2D).

Kind regards,
Morten

______________________ source code

import com.sun.scenario.scenegraph.JSGPanel;
import com.sun.scenario.scenegraph.SGShape;
import com.sun.scenario.scenegraph.SGAbstractShape;
import com.sun.scenario.animation.Clip;
import com.sun.scenario.animation.TimingTargetAdapter;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;

import org.jdesktop.swingx.geom.Morphing2D;

public class MorphTest extends JFrame {
public MorphTest() {
JSGPanel panel = new JSGPanel();
getContentPane().setLayout(new BorderLayout());
getContentPane().add(panel, BorderLayout.CENTER);

final SGShape shape = new SGShape(){
public boolean contains(Point2D point) {
return false; // collision detection is not used in this simple app
}
};
shape.setFillPaint(Color.red);
shape.setMode(SGAbstractShape.Mode.FILL);
shape.setAntialiasingHint(RenderingHints.VALUE_ANTIALIAS_ON);
final Shape source = new Rectangle(10,10,50,50);
final Shape dest = new Ellipse2D.Float(10,10,50,50);

shape.setShape(source);

panel.setScene(shape);

final Morphing2D morph = new Morphing2D(source, dest);
Clip clip = Clip.create(4000,Clip.INDEFINITE, new TimingTargetAdapter(){
public void timingEvent(float fraction) { // scenario 0.5
timingEvent(fraction,System.currentTimeMillis());
}
public void timingEvent(float fraction, long duration) { // scenario 0.6
morph.setMorphing(fraction);
shape.setShape(morph);
}
});
clip.start();
}

public static void main(String[] args) {
MorphTest frame = new MorphTest();
frame.setSize(500,500);
frame.setVisible(true);
}
}

j0ke
Offline
Joined: 2006-06-02

hm oki thanks a lot. Yes the exception is not so important for this simple app. Maybe i will write an blog post about morphing in SceneGraph ( not only about morphing ) and i will point the post to this thread too. Thanks for the help. I will mention you with special thanks in the blog post.

mortennobel
Offline
Joined: 2004-11-03

Great blog post you wrote.

I have just checked out the newest version of Java Scene Graph from subversion, and notised that it now supports for shape morphing (the ShapeEvaluator class).

This means that we can simpliy the example a great deal, and we no longer have any swingx dependencies.

Kind regards,
Morten

The new simplyfied example is:
import com.sun.scenario.scenegraph.*;
import com.sun.scenario.animation.*;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.Ellipse2D;

public class MorphTest2 extends JFrame {
public MorphTest2() {
JSGPanel panel = new JSGPanel();
getContentPane().setLayout(new BorderLayout());
getContentPane().add(panel, BorderLayout.CENTER);

final SGShape shape = new SGShape();
shape.setFillPaint(Color.red);
shape.setMode(SGAbstractShape.Mode.FILL);
shape.setAntialiasingHint(RenderingHints.VALUE_ANTIALIAS_ON);
final Shape source = new Rectangle(10,10,50,50);
final Shape dest = new Ellipse2D.Float(10,10,50,50);

shape.setShape(source);

panel.setScene(shape);

final Evaluator shapeEvaluator = Evaluators.getLinearInstance(Shape.class);
Clip clip = Clip.create(4000,Clip.INDEFINITE, new TimingTargetAdapter(){
public void timingEvent(float fraction, long duration) { // scenario 0.6
shape.setShape(shapeEvaluator.evaluate(source,dest,fraction));
}
});
clip.start();
}

public static void main(String[] args) {
MorphTest frame = new MorphTest();
frame.setSize(500,500);
frame.setVisible(true);
}
}