I modified the Java3D demo program "AppearanceTest" to mimic the behavior
that was failing for my application. I attached the source and bytecode if
you want to check it out...

Of course, it's not like I can look forward to having it fixed anytime
soon...

If I carry a picket sign outside of Macintosh until they spend the money on
a Java3D liscense, would Sun then hire back Mark Hood and Kelvin Chung to
help me out??!!


/* * @(#)AppearanceTest.java 1.28 02/10/21 13:36:45 * * Copyright (c) 1996-2002 Sun Microsystems, Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * This software is provided "AS IS," without a warranty of any * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that Software is not designed,licensed or intended * for use in the design, construction, operation or maintenance of * any nuclear facility. */

/*

The spheres are initially all given their own Appearance with a Red
material.

Toggleing between "Vertical" and "Horizontal" calls the setMaterial method
for  each Sphere's Appearance, producing RGB stripes that *should* all be
the same color...

Interestingly - the first toggle works, the rest fail. Also, the Spheres
that are colored incorrectly seem random and change between different
invocations of the test program...

*/

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import javax.swing.*;
import com.sun.j3d.utils.geometry.*;

public class AppearanceTest extends Applet implements ActionListener {

   private SimpleUniverse u = null;
   private int num = 25;

Appearance[][] apps;

   Color3f red = new Color3f(Color.RED);
   Color3f blue = new Color3f(Color.BLUE);
   Color3f green = new Color3f(Color.GREEN);
   Color3f black = new Color3f(Color.BLACK);
   Color3f white = new Color3f(Color.WHITE);

   Material redMat = new Material(red, black, red, white, 75.0f);
   Material blueMat = new Material(blue, black, blue, white, 75.0f);
   Material greenMat = new Material(green, black, green, white, 75.0f);

   public void actionPerformed(ActionEvent evt){
        String command = evt.getActionCommand();
        if (command.equals("Vertical")){
        for (int i=0;i<num;i++){
            for (int j=0; j<num; j++) {
               if (j % 3 == 0) apps[i][j].setMaterial(redMat);
               if (j % 3 == 1) apps[i][j].setMaterial(blueMat);
               if (j % 3 == 2) apps[i][j].setMaterial(greenMat);
            }
       }} else {
        for (int i=0;i<num;i++){
            for (int j=0; j<num; j++) {
               if (j % 3 == 0) apps[j][i].setMaterial(redMat);
               if (j % 3 == 1) apps[j][i].setMaterial(blueMat);
               if (j % 3 == 2) apps[j][i].setMaterial(greenMat);
            }
       }}

}

private BranchGroup createSceneGraph() {

       BranchGroup objRoot = new BranchGroup();
       BoundingSphere bounds =
           new BoundingSphere(new Point3d(0.0,0.0,0.0), 1000.0);
       Background bg = new Background();
       bg.setApplicationBounds(bounds);
       objRoot.addChild(bg);
       Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
       Vector3f lDir1  = new Vector3f(-1.0f, -1.0f, -1.0f);
       Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
       AmbientLight aLgt = new AmbientLight(alColor);
       aLgt.setInfluencingBounds(bounds);
       DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
       lgt1.setInfluencingBounds(bounds);
       objRoot.addChild(aLgt);
       objRoot.addChild(lgt1);

       int row, col;
       apps = new Appearance[num][num];
       for (row = 0; row < num; row++)
           for (col = 0; col < num; col++)
               apps[row][col] = createAppearance();

       for (int i = 0; i < num; i++) {
           double ypos = (double)(i - num/2) * 0.06;
           for (int j = 0; j < num; j++) {
               double xpos = (double)(j - num/2) * 0.06;
               objRoot.addChild(createObject(apps[i][j], 0.05,  xpos, ypos));
           }
       }
       objRoot.compile();
       return objRoot;
   }


private Appearance createAppearance() { Appearance app = new Appearance(); app.setCapability(Appearance.ALLOW_MATERIAL_WRITE); app.setMaterial(redMat); return app; }


private Group createObject(Appearance app, double scale, double xpos, double ypos) {

       Transform3D t = new Transform3D();
       t.set(scale, new Vector3d(xpos, ypos, 0.0));
       TransformGroup objTrans = new TransformGroup(t);
       TransformGroup spinTg = new TransformGroup();
       Sphere shape = new Sphere();
       shape.setAppearance(app);
       spinTg.addChild(shape);
       Transform3D yAxis = new Transform3D();
       BoundingSphere bounds =
           new BoundingSphere(new Point3d(0.0,0.0,0.0), 10000.0);
       objTrans.addChild(spinTg);
       return objTrans;
   }


public AppearanceTest() { }

   public void init() {
       setLayout(new BorderLayout());
       GraphicsConfiguration config =
          SimpleUniverse.getPreferredConfiguration();

       Canvas3D c = new Canvas3D(config);
       add("Center", c);

       JPanel menu = new JPanel(new FlowLayout());
       JButton one = new JButton("Vertical");
       JButton two = new JButton("Horizontal");
       one.addActionListener(this);
       two.addActionListener(this);
       menu.add(one);
       menu.add(two);
       add("North", menu);

       // Create a simple scene and attach it to the virtual universe
       BranchGroup scene = createSceneGraph();
       u = new SimpleUniverse(c);

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

       u.addBranchGraph(scene);
   }

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

   //
   // The following allows AppearanceTest to be run as an application
   // as well as an applet
   //
   public static void main(String[] args) {
       new MainFrame(new AppearanceTest(), 700, 700);
   }
}

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail

===========================================================================
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".
/*
 *      @(#)AppearanceTest.java 1.28 02/10/21 13:36:45
 *
 * Copyright (c) 1996-2002 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Redistribution in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in
 *   the documentation and/or other materials provided with the
 *   distribution.
 *
 * Neither the name of Sun Microsystems, Inc. or the names of
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * This software is provided "AS IS," without a warranty of any
 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
 * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
 * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
 * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
 * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
 * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * You acknowledge that Software is not designed,licensed or intended
 * for use in the design, construction, operation or maintenance of
 * any nuclear facility.
 */

/*

 The spheres are initially all given their own Appearance with a Red material.

 Toggleing between "Vertical" and "Horizontal" calls the setMaterial method for  each Sphere's Appearance, producing RGB stripes that *should* all be the same color...

 Interestingly - the first toggle works, the rest fail. Also, the Spheres that are colored incorrectly seem random and change between different invocations of the test program...

*/

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import javax.swing.*;
import com.sun.j3d.utils.geometry.*;

public class AppearanceTest extends Applet implements ActionListener {

    private SimpleUniverse u = null;
    private int num = 25;

    Appearance[][] apps;

    Color3f red = new Color3f(Color.RED);
    Color3f blue = new Color3f(Color.BLUE);
    Color3f green = new Color3f(Color.GREEN);
    Color3f black = new Color3f(Color.BLACK);
    Color3f white = new Color3f(Color.WHITE);

    Material redMat = new Material(red, black, red, white, 75.0f);
    Material blueMat = new Material(blue, black, blue, white, 75.0f);
    Material greenMat = new Material(green, black, green, white, 75.0f);

    public void actionPerformed(ActionEvent evt){
         String command = evt.getActionCommand();
         if (command.equals("Vertical")){
         for (int i=0;i<num;i++){
             for (int j=0; j<num; j++) {
                if (j % 3 == 0) apps[i][j].setMaterial(redMat);
                if (j % 3 == 1) apps[i][j].setMaterial(blueMat);
                if (j % 3 == 2) apps[i][j].setMaterial(greenMat);
             }
        }} else {
         for (int i=0;i<num;i++){
             for (int j=0; j<num; j++) {
                if (j % 3 == 0) apps[j][i].setMaterial(redMat);
                if (j % 3 == 1) apps[j][i].setMaterial(blueMat);
                if (j % 3 == 2) apps[j][i].setMaterial(greenMat);
             }
        }}

    }

    private BranchGroup createSceneGraph() {

        BranchGroup objRoot = new BranchGroup();
        BoundingSphere bounds =
            new BoundingSphere(new Point3d(0.0,0.0,0.0), 1000.0);
        Background bg = new Background();
        bg.setApplicationBounds(bounds);
        objRoot.addChild(bg);
        Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
        Vector3f lDir1  = new Vector3f(-1.0f, -1.0f, -1.0f);
        Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
        AmbientLight aLgt = new AmbientLight(alColor);
        aLgt.setInfluencingBounds(bounds);
        DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
        lgt1.setInfluencingBounds(bounds);
        objRoot.addChild(aLgt);
        objRoot.addChild(lgt1);

        int row, col;
        apps = new Appearance[num][num];
        for (row = 0; row < num; row++)
            for (col = 0; col < num; col++)
                apps[row][col] = createAppearance();

        for (int i = 0; i < num; i++) {
            double ypos = (double)(i - num/2) * 0.06;
            for (int j = 0; j < num; j++) {
                double xpos = (double)(j - num/2) * 0.06;
                objRoot.addChild(createObject(apps[i][j], 0.05,  xpos, ypos));
            }
        }
        objRoot.compile();
        return objRoot;
    }


    private Appearance createAppearance() {
        Appearance app = new Appearance();
        app.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
        app.setMaterial(redMat);
        return app;
    }


    private Group createObject(Appearance app, double scale,
                               double xpos, double ypos) {

        Transform3D t = new Transform3D();
        t.set(scale, new Vector3d(xpos, ypos, 0.0));
        TransformGroup objTrans = new TransformGroup(t);
        TransformGroup spinTg = new TransformGroup();
        Sphere shape = new Sphere();
        shape.setAppearance(app);
        spinTg.addChild(shape);
        Transform3D yAxis = new Transform3D();
        BoundingSphere bounds =
            new BoundingSphere(new Point3d(0.0,0.0,0.0), 10000.0);
        objTrans.addChild(spinTg);
        return objTrans;
    }


    public AppearanceTest() {
    }

    public void init() {
        setLayout(new BorderLayout());
        GraphicsConfiguration config =
           SimpleUniverse.getPreferredConfiguration();

        Canvas3D c = new Canvas3D(config);
        add("Center", c);

        JPanel menu = new JPanel(new FlowLayout());
        JButton one = new JButton("Vertical");
        JButton two = new JButton("Horizontal");
        one.addActionListener(this);
        two.addActionListener(this);
        menu.add(one);
        menu.add(two);
        add("North", menu);

        // Create a simple scene and attach it to the virtual universe
        BranchGroup scene = createSceneGraph();
        u = new SimpleUniverse(c);

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

        u.addBranchGraph(scene);
    }

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

    //
    // The following allows AppearanceTest to be run as an application
    // as well as an applet
    //
    public static void main(String[] args) {
        new MainFrame(new AppearanceTest(), 700, 700);
    }
}

Attachment: AppearanceTest.class
Description: application/java

Reply via email to