Mike,
   I'm able to workaround this bug with your test program by reusing
the ColoringAttributes object.
Will such workaround works for your apps. ? It much safer and efficient
to reuse objects in Java 3D.

thanks,
   Chien Yang
   Java 3D, Sun Microsystems Inc.


diff TransparencyTest.java Backup/TransparencyTest.java 206d205 < 208,217c207 < < // --- Modified by Chien. < // Reuse object is cheaper and safer. < /* < ColoringAttributes coloringAttribs = new ColoringAttributes(); < coloringAttribs.setColor(new Color3f(Color.BLUE)); < mPlatforms[0].mShape.getAppearance().setColoringAttributes(coloringAttribs); < */ < ColoringAttributes coloringAttribs = < mPlatforms[0].mShape.getAppearance().getColoringAttributes(); --- > ColoringAttributes coloringAttribs = new ColoringAttributes(); 219,220c209 < < --- > mPlatforms[0].mShape.getAppearance().setColoringAttributes(coloringAttribs); 295,300d283 < // --- Modified by Chien. < // Set write capability for color attributes write. < colorAttribs.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE); < <




Mike Pilone wrote:


Hello,

Attached is a test case for Bug ID: 4751162 View
TRANSPARENCY_SORT_GEOMETRY throws NullPointerException when viewpoint
move

This bug has been around since Sept 2002 and is still in the final
release of 1.3.1 (and the beta release for Linux). The test case
recreates the bug. Directions for the test case are included in the file
header.

Is there any chance of seeing this bug fixed and a new point release
anytime soon? This bug is a show stopper since it prevents geometry
sorting with transparency. I know Java3D is not under active development
anymore, but the work-around of "Disable Geometry Sorting" is really not
acceptable.

-mike




===========================================================================
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".
/*
 * Created on Sep 17, 2003
 * Author: Mike Pilone <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]>
 *
 * Description:
 *   Test case for bug 4751162 View
 *   TRANSPARENCY_SORT_GEOMETRY throws NullPointerException when viewpoint move
 *
 *   This bug does not appear to be related to view point move as the original
 *   bug report suggests. This test application can reproduce the bug without
 *   moving the view port. The problem appears to be related to a combination
 *   of factors, such as updating the appearance of a transparent object, while
 *   removing and adding a different transparent object.
 *
 *   java.lang.NullPointerException
 *     at javax.media.j3d.RenderBin.collectDirtyTRInfo(RenderBin.java:6307)
 *     at javax.media.j3d.RenderBin.updateObject(RenderBin.java:845)
 *     at javax.media.j3d.MasterControl.updateMirrorObjects(MasterControl.java:2694)
 *     at javax.media.j3d.MasterControl.runMonitor(MasterControl.java:3387)
 *     at javax.media.j3d.MasterControl.doWork(MasterControl.java:2951)
 *     at javax.media.j3d.MasterControlThread.run(MasterControlThread.java:28)
 *
 * Usage:
 *   To use this test case, simply run it and click on the canvas once to get the
 *   first object and label to appear. Click again to get the second (coplanar)
 *   object to appear. Click a third time to see the exception. The third click
 *   is attempting to replace one of the labels, move the first object towards
 *   the camera, and change its color. This combination of changes to the scenegraph
 *   cause the exception.
 *
 * Notes:
 *   This bug has been present since Sept 2002. It is a major bug that prevents using
 *   transparent geomtry sorting, which makes using transparent objects next to
 *   impossible for many applications. This bug therefore should have high priority.
 *
 */
/* package transparency; */

import java.applet.Applet;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.media.j3d.*;
import javax.vecmath.*;

import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;


public class TransparencyTest extends Applet implements MouseListener
{

        public static void main(String[] args)
        {
                new MainFrame(new TransparencyTest(), 400, 400);
        }

        public void init()
        {
                mPlatforms = new Platform[2];

                initUniverse();

                //  Create a simple scene and attach it to the virtual universe
                initSimpleScene();

        }

        private void initUniverse()
        {
                setLayout(new BorderLayout());
                GraphicsConfiguration config = 
SimpleUniverse.getPreferredConfiguration();

                mCanvas = new Canvas3D(config);
                mCanvas.addMouseListener(this);
                add("Center", mCanvas);

                mUniverse = new SimpleUniverse(mCanvas, 4);

                // add mouse behaviors to ViewingPlatform
                ViewingPlatform viewingPlatform = mUniverse.getViewingPlatform();

                Viewer[] viewers = viewingPlatform.getViewers();
                for (int i = 0; i < viewers.length; i++)
                {
                        View view = viewers[i].getView();
                        
view.setTransparencySortingPolicy(View.TRANSPARENCY_SORT_GEOMETRY);
                        view.setFrontClipPolicy(View.VIRTUAL_EYE);
                        view.setBackClipPolicy(View.VIRTUAL_EYE);

                        // We use large values here since this sample is taken from an
                        // application that models the earth with a radius of 6.3 
million
                        // meters. I am pretty sure this bug will happen with a smaller
                        // universe.
                        view.setFrontClipDistance(12743067.789199999);
                        view.setBackClipDistance(25485833.068253476);

                        // Update as quickly as possible. It doesn't appear that the 
bug
                        // is related to update speeds, but it does appear to happen 
more
                        // often if all of the updates happen in one frame.
                        view.setMinimumFrameCycleTime((long) (1000.0F / 10000F));
                }

                // Move the viewing platform back a good bit. This is roughly 4 * 
earth radius
                TransformGroup tg = 
viewingPlatform.getMultiTransformGroup().getTransformGroup(0);
                Transform3D viewTransform = new Transform3D();
                viewTransform.setTranslation(new Vector3d(0, 0, 25484928.0));
                tg.setTransform(viewTransform);

        }

        private void initPlat(int index)
        {
                // Create a platform. A platform is just a simple quad with a floating
                // label
                mPlatforms[index] = new Platform("Platform " + index, mGeometry);

                BranchGroup bg = new BranchGroup();
                bg.addChild(mPlatforms[index].mShapePositionTG);

                mBG.addChild(bg);

        }

        private Platform[] mPlatforms;

        private void initSimpleScene()
        {
                // Create the scene tree
                mBG = new BranchGroup();
                mBG.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
                mBG.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);

                // Create a common geometry for all platforms. The geom lays on
                // the x/z axis so it will be rotated before display.
                float polygonSize = 0.5F;
                mGeometry = new QuadArray(4, GeometryArray.COORDINATES);
                mGeometry.setCoordinate(0, new Point3d(-polygonSize, 0, -polygonSize));
                mGeometry.setCoordinate(1, new Point3d(-polygonSize, 0, polygonSize));
                mGeometry.setCoordinate(2, new Point3d(polygonSize, 0, polygonSize));
                mGeometry.setCoordinate(3, new Point3d(polygonSize, 0, -polygonSize));

                // Finally add the bg
                mUniverse.getLocale().addBranchGraph(mBG);
        }

        public void destroy()
        {
                mUniverse.cleanup();
        }

        private SimpleUniverse mUniverse;
        private Canvas3D mCanvas;
        private BranchGroup mBG;
        private QuadArray mGeometry;

        Transform3D calculateTransform(double alt)
        {
                // Create a transform that moves the platform to the given alt and
                // rotates it so the flat face of the quad faces the camera.
                Transform3D transform = new Transform3D();
                transform.setTranslation(new Vector3d(0, 0, alt));

                //In order to get parallel with the surface of the earth, we
                // add an extra 90 degrees to the pitch rotation.
                Transform3D surface = new Transform3D();
                surface.rotX(Math.PI / 2);

                transform.mul(surface);

                return transform;
        }

        /* (non-Javadoc)
         * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
         */
        public void mouseClicked(MouseEvent e)
        {
                // On first click, create the first platform
                if (sClickCount == 0)
                {
                        initPlat(0);
                        sClickCount++;
                }

                // On second click, create the second platform. the second
                // platform will be coplaner with the first
                else if (sClickCount == 1)
                {
                        initPlat(1);
                        sClickCount++;
                }

                // On the third click, change the label, which dumps
                // part of the scene graph, and then move the first platform
                // towards the camera. We also change the color of the
                // platform. This seems to have something to do with
                // causing the exception.
                else if (sClickCount == 2)
                {
                        System.out.println("mouseClicked: Update label");
                        mPlatforms[0].setLabel("Platform 0");


                        System.out.println("mouseClicked: Update color");

                        // --- Modified by Chien.
                        // Reuse object is cheaper and safer.
                        /*
                           ColoringAttributes coloringAttribs = new 
ColoringAttributes();
                           coloringAttribs.setColor(new Color3f(Color.BLUE));
                           
mPlatforms[0].mShape.getAppearance().setColoringAttributes(coloringAttribs);
                        */
                        ColoringAttributes coloringAttribs =
                            
mPlatforms[0].mShape.getAppearance().getColoringAttributes();
                        coloringAttribs.setColor(new Color3f(Color.BLUE));



                        System.out.println("mouseClicked: Update postion");
                        
mPlatforms[0].mShapePositionTG.setTransform(calculateTransform(6371742.0f));

                        sClickCount++;
                }
        }

        /* (non-Javadoc)
         * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
         */
        public void mouseEntered(MouseEvent e)
        {
                // TODO Auto-generated method stub

        }

        /* (non-Javadoc)
         * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
         */
        public void mouseExited(MouseEvent e)
        {
                // TODO Auto-generated method stub

        }

        /* (non-Javadoc)
         * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
         */
        public void mousePressed(MouseEvent e)
        {
                // TODO Auto-generated method stub

        }

        /* (non-Javadoc)
         * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
         */
        public void mouseReleased(MouseEvent e)
        {
                // TODO Auto-generated method stub

        }

        private static int sClickCount = 0;

        private class Platform
        {
                private Shape3D mShape;
                private String mLabel;
                public Platform(String text, Geometry geometry)
                {
                        mShapePositionTG = new TransformGroup();
                        mShapeScaleTG = new TransformGroup();
                        Transform3D transform = null;

                        mShapePositionTG = new TransformGroup();
                        
mShapePositionTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
                        mShapePositionTG.setTransform(calculateTransform(6371732.0f));

                        transform = new Transform3D();
                        transform.setScale(707190.7334);
                        mShapeScaleTG.setTransform(transform);
                        mShapePositionTG.addChild(mShapeScaleTG);

                        Appearance appear = new Appearance();
                        
appear.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
                        
appear.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);

                        PolygonAttributes polyAttribs =
                                new PolygonAttributes(PolygonAttributes.POLYGON_FILL, 
PolygonAttributes.CULL_BACK, 0.0f);

                        ColoringAttributes colorAttribs = new ColoringAttributes(new 
Color3f(Color.YELLOW), ColoringAttributes.FASTEST);

                        // --- Modified by Chien.
                        // Set write capability for color attributes write.
                        
colorAttribs.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);



                        TransparencyAttributes transAttribs = new 
TransparencyAttributes(TransparencyAttributes.FASTEST, 0.2f);

                        //    Set the line attribute to turn off antialiasing for the 
icon
                        LineAttributes lineAtt = new LineAttributes();
                        lineAtt.setLineAntialiasingEnable(false);
                        appear.setLineAttributes(lineAtt);

                        appear.setPolygonAttributes(polyAttribs);
                        appear.setColoringAttributes(colorAttribs);
                        appear.setTransparencyAttributes(transAttribs);
                        mShape = new Shape3D(geometry, appear);
                        mShape.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
                        mShape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

                        mShapeScaleTG.addChild(mShape);

                        transform = new Transform3D();
                        transform.setScale(353603.376);
                        TransformGroup labelScaleTG = new TransformGroup();
      labelScaleTG.setTransform(transform);
                        mShapePositionTG.addChild(labelScaleTG);

                        mLabelBG = new BranchGroup();
                        mLabelBG.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
                        mLabelBG.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
                        mLabelBG.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
      labelScaleTG.addChild(mLabelBG);

                        setLabel(text);
                }

  /** Sets a new label. This involves dumping the current label scene graph
   * and creating a new one.
   *
   * @param text
   */
                public void setLabel(String text)
                {
                        mLabel = text;

                        initLabelGraph();
                }

                /**
                 *  Creates all the nodes for the label graph, including the LOD node.
                 */
                private void initLabelGraph()
                {
                        mLabelBG.removeAllChildren();

                        if ((mLabel == null) || (mLabel.length() == 0))
                        {
                                return;
                        }

                        BranchGroup bg = new BranchGroup();
                        bg.setCapability(BranchGroup.ALLOW_DETACH);
                        bg.setCapability(Group.ALLOW_CHILDREN_READ);

                        Switch lodSwitch = new Switch(Switch.CHILD_MASK);
                        lodSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

                        OrientedText2D text = new OrientedText2D(mLabel);
                        text.setAlignmentMode(OrientedText2D.ROTATE_ABOUT_POINT);
                        text.setRotationPoint(new Point3f());

                        text.setRectangleScaleFactor(.0375);
                        lodSwitch.addChild(text);

                        // Raise the text above the earth so that it does not
                        // go through the planet when rotated
                        double alt = 1;

      // Move the text slightly above the platform
                        Transform3D transform = new Transform3D();
                        transform.setTranslation(new Vector3d(0.0F, alt, 0.0F));
                        TransformGroup labelPositionBG = new TransformGroup();
                        labelPositionBG.setTransform(transform);
                        labelPositionBG.addChild(lodSwitch);
                        bg.addChild(labelPositionBG);

                        // Add an empty group so nothing appears if low LOD
                        lodSwitch.addChild(new BranchGroup());

                        float labelDist = (float)250000;
                        float[] distances = new float[] { labelDist, Float.MAX_VALUE };
                        DistanceLOD lodBehavior = new DistanceLOD(distances);
                        lodBehavior.setSchedulingBounds(new BoundingSphere(new 
Point3d(), Double.MAX_VALUE));
                        lodBehavior.addSwitch(lodSwitch);
                        bg.addChild(lodBehavior);

                        mLabelBG.addChild(bg);
                }

                public TransformGroup mShapePositionTG;
                public TransformGroup mShapeScaleTG;
                private BranchGroup mLabelBG;
        }
}

===========================================================================
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