Note that there are some explanatory texts on larger screens.

plurals
  1. POJava3D disappearance act
    primarykey
    data
    text
    <p>It seems to me Java3D has a problem redrawing the scene sometimes when the Frame/JPanel/Canvas3D has been resized. I have a problem in my application using Java3D/JUNG3D where if the Frame/JPanel/Canvas3D's horizontal size is of certain size, the entire scene disappears. I was trying to simply the problem then found that a similar problem occurs in the following sample code: <a href="http://www.java3d.org/samples.html" rel="nofollow">http://www.java3d.org/samples.html</a> (The second to last example, "Text 3D Example") I will paste at the bottom for convenience.</p> <p>Steps:</p> <ol> <li>Install Java3D</li> <li>Build this example using the 3 Java3D jars. </li> <li>Run</li> <li>Stretch the frame horizontally to 500 pixels or so then everything disappears. Shrink it back then it's there again. While things have disappeared, stretch vertically and things appear again.</li> </ol> <p>It certainly seems to have something to do with the Frame/JPanel/Canvas3D aspect ratio and that of the content that it displays. My own problem is slightly different I'm guessing because I'm displaying scene of different aspect ratio and the underlying problem is the same. Can anyone tell me how I might be able to get around this bug/feature so that the scene never disappears when the window is resized?</p> <p>Here are what I've tried so far with no success:</p> <ol> <li>Catching the JPanel resize event then forcing the Canvas3D to redraw</li> <li>Playing with double buffering settings</li> <li>Many other things I can't recall right now - just came back from a vacation :)</li> </ol> <p>Code :</p> <pre><code>import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.geometry.*; public class Titles { public static void main(String[] args) { Titles t = new Titles(); t.setUp(); } public void setUp() { JFrame jf = new JFrame("Welcome"); // kill the window on close jf.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent winEvent) { System.exit(0); } }); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1, 1, 2, 2)); GraphicsConfiguration config = SimpleUniverse .getPreferredConfiguration(); Canvas3D canvas3D = new Canvas3D(config); canvas3D.setSize(360, 160); SimpleUniverse universe = new SimpleUniverse(canvas3D); BranchGroup group = new BranchGroup(); addObjects(group); addLights(group); universe.getViewingPlatform().setNominalViewingTransform(); universe.addBranchGraph(group); panel.add(canvas3D); jf.getContentPane().add(panel, BorderLayout.CENTER); jf.pack(); jf.setVisible(true); } public void addLights(BranchGroup group) { BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0); Color3f light1Color = new Color3f(1.0f, 1.0f, 1.0f); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); group.addChild(light1); // Set up the ambient light Color3f ambientColor = new Color3f(.1f, .1f, .1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); group.addChild(ambientLightNode); } private void addObjects(BranchGroup group) { Font3D f3d = new Font3D(new Font("TestFont", Font.PLAIN, 2), new FontExtrusion()); Text3D text = new Text3D(f3d, new String("Java3D.org"), new Point3f(-3.5f, -.5f, -4.5f)); text.setString("Java3D.org"); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f blue = new Color3f(.2f, 0.2f, 0.6f); Appearance a = new Appearance(); Material m = new Material(blue, blue, blue, white, 80.0f); m.setLightingEnable(true); a.setMaterial(m); Shape3D sh = new Shape3D(); sh.setGeometry(text); sh.setAppearance(a); TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); Transform3D tDown = new Transform3D(); Transform3D rot = new Transform3D(); Vector3f v3f = new Vector3f(-1.6f, -1.35f, -6.5f); t3d.setTranslation(v3f); rot.rotX(Math.PI / 5); t3d.mul(rot); v3f = new Vector3f(0, -1.4f, 0f); tDown.setTranslation(v3f); t3d.mul(tDown); tg.setTransform(t3d); tg.addChild(sh); group.addChild(tg); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload