Hi Cyril,

  Can you please send us a complete test program for
investigation ?  Attach is a program that change
the polygon mode of a triangle when user select
the choice box. It works fine using v1.2.1.

Thanks.

- Kelvin
-------------
Java 3D Team
Sun Microsystems Inc.


>MIME-Version: 1.0
>Date: Fri, 16 Mar 2001 14:16:18 +0100
>From: BRANDY Cyril <[EMAIL PROTECTED]>
>Subject: [JAVA3D] Java3D v1.2 vs v1.2.1
>To: [EMAIL PROTECTED]
>
>Hi,
>
>When i use the new version of Java3D (1.2.1) i have problems to change the
>appearance of my geometry : i can't change the PolygoneMode (FILL, LINE,
>POINT)
>And the lighting is very strange.
>
>With Java3D 1.2 everything works fine.
>
>Does anybody have an idea of what happening ?
>
>Thanks.
>
>Here's my code :
>To setup the appearance
>                //Apparence
>                Appearance a = new Appearance();
>                a.setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE);
>                a.setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_READ);
>
>                a.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
>                a.setCapability(Appearance.ALLOW_MATERIAL_READ);
>
>                a.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
>                a.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
>
>                a.setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE);
>                a.setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_READ);
>
>                PolygonAttributes pa = new PolygonAttributes();
>                pa.setCullFace(PolygonAttributes.CULL_NONE);
>                pa.setCapability( PolygonAttributes.ALLOW_CULL_FACE_READ );
>                pa.setCapability( PolygonAttributes.ALLOW_CULL_FACE_WRITE );
>                pa.setCapability( PolygonAttributes.ALLOW_MODE_READ );
>                pa.setCapability( PolygonAttributes.ALLOW_MODE_WRITE );
>                pa.setCapability( PolygonAttributes.ALLOW_NORMAL_FLIP_READ
>);
>                pa.setCapability( PolygonAttributes.ALLOW_NORMAL_FLIP_WRITE
>);
>                pa.setCapability( PolygonAttributes.ALLOW_OFFSET_READ );
>                pa.setCapability( PolygonAttributes.ALLOW_OFFSET_WRITE );
>
>                pa.setPolygonMode(PolygonAttributes.POLYGON_LINE);
>                pa.setBackFaceNormalFlip(true);
>
>                a.setPolygonAttributes(pa);
>                shape.setAppearance(a);
>
>To change the appearance :
>
>        public void setRenderMode(int mode) {
>                if (mode==SceneElement.LINE) {
>
>shape.getAppearance().getPolygonAttributes().setPolygonMode(PolygonAttribute
>s.POLYGON_LINE);
>                }
>                else if (mode==SceneElement.FILL){
>
>shape.getAppearance().getPolygonAttributes().setPolygonMode(PolygonAttribute
>s.POLYGON_FILL);
>                }
>                else if (mode==SceneElement.POINT){
>
>shape.getAppearance().getPolygonAttributes().setPolygonMode(PolygonAttribute
>s.POLYGON_POINT);
>                }
>
>        }
>
>Cyril BRANDY
> <<...OLE_Obj...>>
>*: 33 (5) 05.61.18.43.73
>* : 33 (5) 05.61.18.64.17
>* : [EMAIL PROTECTED]
>
>===========================================================================
>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".
/*
 *    "@(#)PolygonAttributesTest.java 1.2 00/06/12"
 *
 * Copyright (c) 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * 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.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

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

public class PolygonAttributesTest extends JApplet
                                implements ActionListener {

    PolygonAttributes pa;
    JComboBox pMode;
    JComboBox pCullFace;
    JCheckBox pNormalFlip;
    JTextField pOffset;
    JTextField pOffsetFactor;

    BranchGroup createSceneGraph() {
        BranchGroup objRoot = new BranchGroup();

        Appearance app = new Appearance();
        pa = new PolygonAttributes();
        pa.setCapability(PolygonAttributes.ALLOW_CULL_FACE_READ);
        pa.setCapability(PolygonAttributes.ALLOW_CULL_FACE_WRITE);
        pa.setCapability(PolygonAttributes.ALLOW_NORMAL_FLIP_READ);
        pa.setCapability(PolygonAttributes.ALLOW_NORMAL_FLIP_WRITE);
        pa.setCapability(PolygonAttributes.ALLOW_MODE_READ);
        pa.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
        pa.setCapability(PolygonAttributes.ALLOW_OFFSET_READ);
        pa.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE);

        pa.setPolygonOffset(-0.2f);
        pa.setPolygonOffsetFactor(-0.3f);
        app.setPolygonAttributes(pa);

        TriangleArray tri1 = new TriColorTranslate(1.0f, 0.0f, 0.0f,
                                                   0.0f, 0.0f, 0.0f);
        TriangleArray tri2 = new TriColorTranslate(0.0f, 0.0f, 1.0f,
                                                   0.0f, 0.0f, 0.0f);
        Shape3D shape1 = new Shape3D(tri1, app);
        Shape3D shape2 = new Shape3D(tri2, null);

        Transform3D t = new Transform3D();
        // move the object upwards
        t.set(new Vector3f(0.0f, 0.3f, 0.0f));
        // Shrink the object
        t.setScale(0.6);

        TransformGroup trans = new TransformGroup(t);
        trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        trans.addChild(shape1);

        // offset the second shape a little bit
        t.setIdentity(); // we can reuse Transform3D
        //      t.set(new Vector3f(0.0f, 0.3f, 0.0f));
        TransformGroup trans2 = new TransformGroup(t);
        trans2.addChild(shape2);

        trans.addChild(trans2);
        objRoot.addChild(trans);

        BoundingSphere bounds =
            new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);

// Create the drag behavior node
        MouseRotate behavior = new MouseRotate();
        behavior.setTransformGroup(trans);
        trans.addChild(behavior);
        behavior.setSchedulingBounds(bounds);

        // Create the zoom behavior node
        MouseZoom behavior2 = new MouseZoom();
        behavior2.setTransformGroup(trans);
        trans.addChild(behavior2);
        behavior2.setSchedulingBounds(bounds);

        // Create the zoom behavior node
        MouseTranslate behavior3 = new MouseTranslate();
        behavior3.setTransformGroup(trans);
        trans.addChild(behavior3);
        behavior3.setSchedulingBounds(bounds);

        // Let Java 3D perform optimizations on this scene graph.
        objRoot.compile();

        return objRoot;
    }

    public PolygonAttributesTest() {
        Container contentPane = getContentPane();

        Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration());


        BranchGroup scene = createSceneGraph();
        // SimpleUniverse is a Convenience Utility class
        SimpleUniverse 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);

        // Create GUI
        JPanel panel = new JPanel();
        BoxLayout boxlayout = new BoxLayout(panel,
                                            BoxLayout.Y_AXIS);
        panel.setLayout(boxlayout);
        panel.add(createAttributesPanel());
        panel.add(createOffsetPanel());
        contentPane.add("South", panel);

        // create menu bar
        JMenuBar mb = new JMenuBar();
        // since Canvas3D is heavy weight,
        // the menu will hidden behind it if not set this
        JPopupMenu.setDefaultLightWeightPopupEnabled(false);
        JMenu fileMenu = new JMenu("File");
        JMenuItem exitItem = new JMenuItem("Exit");
        fileMenu.add(exitItem);
        mb.add(fileMenu);
        getRootPane().setJMenuBar(mb);
        exitItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        contentPane.add("Center", c);
    }


    JPanel createAttributesPanel() {
        JPanel panel = new JPanel();
        panel.setBorder(new TitledBorder("Polygon Attributes"));

        String mode[] = {"POLYGON_POINT", "POLYGON_LINE", "POLYGON_FILL"};
        pMode = new JComboBox(mode);
        pMode.addActionListener(this);
        pMode.setSelectedIndex(pa.getPolygonMode());

        String cullFace[] = {"CULL_NONE", "CULL_BACK", "CULL_FRONT"};
        pCullFace = new JComboBox(cullFace);
        pCullFace.addActionListener(this);
        pCullFace.setSelectedIndex(pa.getCullFace());

        panel.add(new JLabel("Mode"));
        panel.add(pMode);

        panel.add(new JLabel("Cull Face"));
        panel.add(pCullFace);

        pNormalFlip = new JCheckBox("BackFaceNormalFlip",
                                    pa.getBackFaceNormalFlip());
        pNormalFlip.addActionListener(this);
        panel.add(pNormalFlip);
        return panel;
    }

    JPanel createOffsetPanel() {
        JPanel panel = new JPanel();
        panel.setBorder(new TitledBorder("Polygon Offset"));
        pOffset = new JTextField(pa.getPolygonOffset()+"", 3);
        pOffset.addActionListener(this);
        panel.add(new JLabel("Offset"));
        panel.add(pOffset);
        pOffsetFactor = new JTextField(pa.getPolygonOffsetFactor()+"",
                                       3);
        pOffsetFactor.addActionListener(this);
        panel.add(new JLabel("Offset Factor"));
        panel.add(pOffsetFactor);
        return panel;
    }


    public void actionPerformed(ActionEvent e) {
        Object target = e.getSource();

        if (target == pMode) {
            pa.setPolygonMode(pMode.getSelectedIndex());
        }
        else if (target == pCullFace) {
            pa.setCullFace(pCullFace.getSelectedIndex());
        }
        else if (target == pNormalFlip) {
            pa.setBackFaceNormalFlip(pNormalFlip.isSelected());
        }
        else if (target == pOffset) {
            try {
                pa.setPolygonOffset(Float.parseFloat(pOffset.getText()));
            } catch (NumberFormatException ex) {
                pOffset.setText(pa.getPolygonOffset()+"");
            }
        }
        else if (target == pOffsetFactor) {
            try {
                pa.setPolygonOffsetFactor(
                          Float.parseFloat(pOffsetFactor.getText()));
            } catch (NumberFormatException ex) {
                pOffsetFactor.setText(pa.getPolygonOffsetFactor()+"");
            }
        }
    }

    public static void main(String[] args) {
        Frame frame = new MainFrame(new PolygonAttributesTest(), 500, 500);
    }


}

Reply via email to