Skip to main content

"CANVAS CRASHED!!!" trying to use java3D in javaFX

1 reply [Last post]
yahu577
Offline
Joined: 2008-03-25
Points: 0

Hi,

I've been trying to merge a java3D example into javaFX script. I can compile & run. But then the 3d canvas is not rendered into Off-screen Rendering(and rendered into a seperate window..). And it output the msg "CANVAS CRASHED!!!".

does anyone know what the potential problem is?

here's my code:

package javafx3d;

import javafx.ui.*;
import javafx.ui.canvas.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.RotationInterpolator;

import javax.media.j3d.Canvas3D;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.Transform3D;
import javax.media.j3d.Alpha;
import javax.media.j3d.BoundingSphere;
import javax.vecmath.*;
import java.lang.Math;
import java.awt.GridBagLayout;
import java.awt.Dimension;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;

import javax.media.j3d.GraphicsConfigTemplate3D;
import com.sun.j3d.exp.swing.JCanvas3D;

class RenderPanel extends Panel {
public attribute rotator:RotationInterpolator;
}
operation RenderPanel.createComponent() {

var gCT = new GraphicsConfigTemplate3D();

var jCanvas3D = new JCanvas3D(gCT);
jCanvas3D.setResizeMode(JCanvas3D.RESIZE_IMMEDIATELY);
jCanvas3D.setSize(50,50);

var c = jCanvas3D.getOffscreenCanvas3D();

var panel=new JPanel();
panel.setLayout(new GridBagLayout());
panel.add(jCanvas3D);

var univ = new SimpleUniverse(c);
univ.getViewingPlatform().setNominalViewingTransform();
univ.getViewer().getView().setMinimumFrameCycleTime(5);
var objRoot = new BranchGroup();
var objTrans = new TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objTrans);
objTrans.addChild(new ColorCube(0.4));
var rotationAlpha = new Alpha( -1, 999);
rotator = new RotationInterpolator(rotationAlpha, objTrans);
var t = new Transform3D();
t.rotX(2);
var axis = new Transform3D(t);
rotator.setTransformAxis(axis);
var bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
rotator.setSchedulingBounds(bounds);
objRoot.addChild(rotator);
objRoot.compile();
univ.addBranchGraph(objRoot);

return panel;
}

Frame {
visible: true
screenx: 50
screeny: 100
width: 600
height: 400

content: BorderPanel {
border: EmptyBorder {left: 16 top: 16 right: 16 bottom: 16}
center: Button {
width: 10
height: 10
visible: true

}
center: Canvas {
content:
[Rect {
transform: translate(90, 90)
height: 220
width: 220
fill: new Color(0, 0, .5, .5)
arcHeight: 20
arcWidth: 20
},
View {
antialias: true
transform: translate(100, 100)
content: BorderPanel {
top: Button {text : "Click Me!" cursor: DEFAULT}

center: RenderPanel {
visible: true
preferredSize: {height: 200, width: 200}
}
}
},
View {
transform: translate(120, 150)
content: TextField {
columns: 11
value: "this is a text field"
}
}]
}
}
}

Thanks,
Andy

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pepe
Offline
Joined: 2003-06-10
Points: 0

Hello.
You do not need to to anything with JCanvas3D to have it shown within a swing application. Just do as if you were using a regular Canvas3D.
Let offscreen buffer alone.

This line of code looks very wrong (i'm not a javafx fan, nor am i used to its syntax)
var univ = new SimpleUniverse(c);
if "c" is the offscreen buffer, this is wrong. Add jcanvas3D instead.

Then, to be precise, the message you get means that rendering did not occur for a while, and swing has been waiting for it too long. This a timeout from swing to the rendering engine of java3D which enables GUIs not to be frozen in such cases.