Hello Java 3D Cognescenti,
    I am trying to get going with Java3D for statistical visualization.  My
application will have the following characteristics:
- It will have large amounts of objects (10's of thousands) and so I want to
avoid the memory requirements of the straightforward scene graph approach.
- It will not be using animation, and so I want to avoid using threads that
perform infinite rendering calls as they do in the PureImmediate example
from Sun... the app will also be doing calculations, and I don't want to
load the CPU with calls to render unchanged scenes, and would prefer to
render explicitly when I know it has changed.
- My strategy is to use the "pure immediate" rendering mode, and to sublass
Canvas3D, overriding it's paint(Graphics g) method to do the rendering, then
to call repaint() after a change due to, e.g., user interaction.

    It works, sort of, but there is a problem - on contracting the frame,
although the result is correct, there seems to be extra drawing calls made
that will be inefficient for large data (looks like it's drawn, cleared by
white, and drawn again)... and on expanding the frame, the result is wrong
on every second render- the app display just a blank white canvas on
alternate frames.

    Below is a source code transcript, derived from the PureImmediate
example, that demonstrates my approach and my difficulty.  Can anyone please
tell me how I can properly do this (preferably by demonstrating, as I am a
newbie with using this library in Java)?

   Thank you in advance,
   Barry

//===========BEGIN SOURCE CODE============
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;

/**
* Pure immediate mode example program.  In pure immediate mode, the
* renderer must be stopped on the Canvas being rendered into. In our
* example, this is done immediately after the canvas is created. A
* separate thread is started up to do the immediate mode rendering.
*
* Current Problem: On redraws, due to e.g., resize events -
*   - On expansion, display is visible on alternate draws only, see
*     pure white background otherwise
*   - On contraction, display is visible each time, but a flash of
*     white seems to betray 3 draw events... with the last producing
*     the desired display.
*/
public class PureImmediateBarry extends Frame {

private Canvas3D canvas;

private SimpleUniverse u = null;

   public PureImmediateBarry()
   {
     super();
     init();
     pack();
   }

   //
   // init: create the canvas, stop the renderer,
   // create the universe.
   //
   public void init() {
       setLayout(new BorderLayout());
       GraphicsConfiguration config =
          SimpleUniverse.getPreferredConfiguration();

       canvas = new PureCanvas3D(config);
       canvas.stopRenderer();
       add("Center", canvas);

       // Create the universe and viewing branch
       u = new SimpleUniverse(canvas);

       // This will move the ViewPlatform back a bit so the
       // objects in the scene can be viewed.
       u.getViewingPlatform().setNominalViewingTransform();

}

   public static void main(String[] args) {
     PureImmediateBarry pure= new PureImmediateBarry();
     pure.show();
   }


//Barry: Inner class to do rendering public class PureCanvas3D extends Canvas3D { private Geometry cube = null; private Transform3D cmt = new Transform3D(); private int n=0; private GraphicsContext3D gc3D = null;

   PureCanvas3D(GraphicsConfiguration config)
   {
     super(config);
     setSize(600,400);

     // Set up 3D Graphics context
     gc3D = getGraphicsContext3D();
     gc3D.setAppearance(new Appearance());

     // Set up geometry
     cube = new ColorCube(0.4).getGeometry();

}

   //
   // Renders a single frame by clearing the canvas, drawing the
   // geometry, and swapping the draw and display buffer.
   //
   public void paint(Graphics g) {   //render() {
       super.paint(g);

n++;

gc3D.clear();

       if (isOffScreen())
         System.out.println("Offscreen:" + n);
       else
         System.out.println("Onscreen:" + n);

       // Render the geometry for this frame
       gc3D.setModelTransform(cmt);
       gc3D.draw(cube);
       swap();
   }

 }  //PureCanvas3D
}
//===========END SOURCE CODE=============


"Dare to be naive" ...Buckminster Fuller


Barry Wythoff
23B Congress St
Newburyport, MA 01950

Tel: 978-462-8854
Email: [EMAIL PROTECTED]

_________________________________________________________________
Groove on the latest from the hot new rock groups!  Get downloads, videos,
and more here.  http://special.msn.com/entertainment/wiredformusic.armx

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to