Hi Kelvin,

I've attached source code to illustrate the bug.

Thanks,
Renoir

Kelvin Chung wrote:

> Hi Renoir,
>
>     Thanks for your bug report. Please send us a
> test program for investigation so that we can fix
> it before release.
>
> - Kelvin
> ------------
> Java 3D Team
> Sun Microsystems Inc.
>
> >Delivered-To: [EMAIL PROTECTED]
> >X-Accept-Language: en
> >MIME-Version: 1.0
> >Date: Mon, 26 Nov 2001 15:21:43 +0200
> >From: Renoir Sewjee <[EMAIL PROTECTED]>
> >Subject: [JAVA3D] AntiAliasing Problem 1.3 beta
> >To: [EMAIL PROTECTED]
> >
> >Hi,
> >
> >There seems to be an antialiasing problem in j3d 1.3 beta (see attached
> >picture) - the areas that are supposed to be transparent are filled with
> >the background colour.  My setup is WinNT, NVidia Vanta, j2sdk 1.3.1_01
> >(also tested on 1.4 beta 3, same results).
> >
> >Regards,
> >Renoir
> >
> >--
> >Renoir Sewjee
> >Software Engineer
> >ISS International (Welkom)
> >Tel: +27 (0)57 912 2702
> >Fax: +27 (0)57 912 2652
> >--
> >

--
Renoir Sewjee
Software Engineer
ISS International (Welkom)
Tel: +27 (0)57 912 2702
Fax: +27 (0)57 912 2652
--

import java.awt.Dimension;
import java.awt.BorderLayout;

import javax.swing.JFrame;

import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Color3f;

import javax.media.j3d.Canvas3D;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.Background;
import javax.media.j3d.Material;
import javax.media.j3d.Appearance;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Shape3D;
import javax.media.j3d.PointArray;
import javax.media.j3d.PointAttributes;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.TransparencyAttributes;

import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;

/**
 * Illustrates an antialiasing problem in 1.3 beta: when antialiased geometry is in 
front of
 * geometry that allows transparency, the parts of the antialiased geometry that are 
supposed to
 * be transparent are rendered in the background colour.
 *
 * As an example,
 * A point array with antialiased points in drawn in front of a sphere, when the 
sphere can be
 * transparent (transparency att set and transparency mode != none) you will see a 
border around the points.
 *
 */

public class AntiAliasingBug extends JFrame
{
    public AntiAliasingBug(boolean sphereTransparent)
    {
        super();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        BoundingSphere everywhere = new BoundingSphere(new Point3d(), 
Double.MAX_VALUE);

        Canvas3D canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
        canvas.setDoubleBufferEnable(true);
        getContentPane().add(canvas, BorderLayout.CENTER);

        SimpleUniverse universe = new SimpleUniverse(canvas);
        universe.getViewingPlatform().setNominalViewingTransform();

        BranchGroup lights = new BranchGroup();

        DirectionalLight directionalLight = new DirectionalLight();
        directionalLight.setInfluencingBounds(everywhere);
        lights.addChild(directionalLight);

        AmbientLight ambientLight = new AmbientLight();
        ambientLight.setInfluencingBounds(everywhere);
        lights.addChild(ambientLight);

        universe.getViewingPlatform().getViewPlatformTransform().addChild(lights);

        BranchGroup root = new BranchGroup();

        Background background = new Background(1, 1, 1);
        background.setApplicationBounds(everywhere);
        root.addChild(background);

        /*
         * Sphere.
         *
         */

        Material sphereMaterial = new Material();
        sphereMaterial.setDiffuseColor(1, 0, 1);

        Appearance sphereAppearance = new Appearance();
        sphereAppearance.setMaterial(sphereMaterial);

        if (sphereTransparent)
            // Sphere can be transparent.
            sphereAppearance.setTransparencyAttributes(new 
TransparencyAttributes(TransparencyAttributes.NICEST, 0.0f));
        else
            // Sphere cannot be transparent - could even leave out the following 
statement.
            sphereAppearance.setTransparencyAttributes(new 
TransparencyAttributes(TransparencyAttributes.NONE, 0.0f));

        root.addChild(new Sphere(0.5f, Sphere.GENERATE_NORMALS, sphereAppearance));

        /*
         * Point Array.
         *
         */

        PointAttributes pointAttributes = new PointAttributes(10, true);

        Appearance pointAppearance = new Appearance();
        pointAppearance.setPointAttributes(pointAttributes);

        Point3f point  = new Point3f();
        Color3f colour = new Color3f();

        PointArray pointArray = new PointArray(5, PointArray.COORDINATES | 
PointArray.COLOR_3);
        point.set(0.0f, 0.0f, 0.6f);
        colour.set(0, 1, 0);
        pointArray.setCoordinate(0, point);
        pointArray.setColor(0, colour);

        point.set(0.0f, 0.1f, 0.6f);
        colour.set(1, 0, 0);
        pointArray.setCoordinate(1, point);
        pointArray.setColor(1, colour);

        point.set(0.0f, -0.1f, 0.6f);
        colour.set(1, 0, 0);
        pointArray.setCoordinate(2, point);
        pointArray.setColor(2, colour);

        point.set(0.1f, 0.0f, 0.6f);
        colour.set(0, 0, 1);
        pointArray.setCoordinate(3, point);
        pointArray.setColor(3, colour);

        point.set(-0.1f, 0.0f, 0.6f);
        colour.set(0, 0, 1);
        pointArray.setCoordinate(4, point);
        pointArray.setColor(4, colour);

        root.addChild(new Shape3D(pointArray, pointAppearance));

        /*
         * Orbit Behaviour.
         *
         */

        OrbitBehavior orbitter = new OrbitBehavior(canvas, OrbitBehavior.REVERSE_ALL);
        orbitter.setSchedulingBounds(everywhere);
        orbitter.setViewingPlatform(universe.getViewingPlatform());
        root.addChild(orbitter);

        root.compile();
        universe.addBranchGraph(root);
    }

    public static void main(String[] args)
    {
        boolean sphereTransparent = true;

        if (args.length >= 1)
            {
                if (args[0].toLowerCase().equals("true"))  sphereTransparent = true;
                if (args[0].toLowerCase().equals("false")) sphereTransparent = false;
            }
        else
            {
                System.err.println();
                System.err.println("usage: java AntiAliasingBug [true | false]");
                System.err.println("A first argument of true allows the sphere to have 
transparency (the default).");
                System.err.println();
            }

        AntiAliasingBug app = new AntiAliasingBug(sphereTransparent);
        app.setTitle("AntiAliasing Bug 1.3 beta");
        app.setSize(800, 600);
        app.setVisible(true);
    }
}

Reply via email to