Sorry that I didn't include the full code. Here I attach two files to show
the problem I have.
The triangle vertices are input in the following order ( (1,2) (3,4) - ()
represents a block, ea. contains 2 triagles
(5,6) (7,8)
(9,10)(11,12))
I casted the output of GeomtryInfo.getGeometryArray to TriangleStripArray
and then set the capability bits in TestUniverse.java.
Later in the MenuDemo.java as a response to menu click, I use
Shape3D.getGeometry() to trace back the geometry. The order of the vertices
is from bottom up. If I use a block (made of 2 triangles) to describe the
problem the order of the blocks is as follows
((6)(5) - () represents a
block (quad)
(4)(3)
(2)(1) )
you will see what I mean in the menuDemo, when "restore color" clicked, I
set color in a reverse order.
i hope that I stated clear enough for you to figure out.
Thanks again!
At 06:04 PM 5/31/2001 -0700, you wrote:
>Lan,
>
>I'm not sure I understand exactly what you are asking. The code you
>have below does not call the Stripifier at all. However, you should set
>the color of your data before you call the stripifier. Color
>information is used for building strips. Please send me a short demo
>program if you are having problems.
>
>andrea
>
>
>Lan Wu-Cavener wrote:
> >
> > Hi, all:
> >
> > I used the GeometryInfo to read in Triangle_Array. After calling
> > stripifier, I retrieve the GoemetryArray using shape3D. getGeometry().
> >
> > Then when I use GeometryArray.setColor(int index, Color3f color), I found
> > the triangles are number in a reverse order respective to their original
> > input order. For instance, I have a trip of 4 triangles which are input in
> > the order from left to right. After I called all the aforementioned
> > functions, The ".setColor(index, black) with index from 0-3 will set the
> > vertex 0 to 3 of the right most triangle to black.
> >
> > I have tried couple of time, one with the IndexedGeometryArray, I found the
> > same results.
> > Could any one confirm that is what it should be? Thanks!
> >
> > Lan
> >
> > GeometryInfo gi1 = new GeometryInfo(GeometryInfo.TRIANGLE_ARRAY);
> > gi1.setCoordinates(tvertices);
> > gi1.setCoordinateIndices(tvertex_ind);
> > gi1.setColors(colors);
> > gi1.setColorIndices(tcolor_ind);
> > Lan Wu-Cavener
> > Research Associate and Programmer
> > Dept. of Landscape Architecture
> >
> > ===========================================================================
> > 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".
>
>===========================================================================
>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".
/////////////////////////////////////////////////////
//
// Color and Lighting test ...
//
//
/////////////////////////////////////////////////////////
import javax.swing.*;
import com.sun.j3d.utils.geometry.*;
import java.applet.*;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import java.awt.*;
import com.sun.j3d.utils.image.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import javax.swing.*;
import javax.swing.border.*;
public class TestUniverse extends JPanel {
private Canvas3D canvas;
private SimpleUniverse universe;
private BranchGroup objRoot;
private AppearanceSet appearanceSet;
private BoundingSphere bounds;
private TransformGroup scaleBack;
private TransformGroup objTrans;
private Shape3D tshape;
private Color3f red = new Color3f(1.0f,0.0f,0.0f);
private Color3f green = new Color3f(0.0f,1.0f,0.0f);
private Color3f blue = new Color3f(0.0f,0.0f,1.0f);
private Color3f yellow = new Color3f(1.0f,1.0f,0.0f);
private Color3f red1 = new Color3f(.70f,0.20f,0.20f);
private Color3f green1 = new Color3f(0.0f,1.0f,0.30f);
private Color3f blue1 = new Color3f(0.30f,0.0f,1.0f);
private Color3f yellow1 = new Color3f(4.0f,5.0f,0.0f);
private Color3f black = new Color3f(.0f,.0f,.0f);
private Color3f white = new Color3f(1.0f,1.0f,1.0f);
private Color3f am = new Color3f(0.5f, 0.5f,0.5f);
private Color3f emm = new Color3f(0.f, 0.f,0.f);
private Color3f dif = new Color3f(0.f, 0.f,1.f);
private Color3f spe = new Color3f(1.f, 1.f,1.f);
private static final Color3f brown = new Color3f( 0.78f, 0.2f, 0.1f );
private static final Color3f cyan = new Color3f( 0.0f, 1.0f, 1.0f );
private static final Color3f orange = new Color3f( 1.0f, 0.5f, 0.0f );
private static final Color3f pink = new Color3f( 1.0f, 0.0f, 0.5f );
private ShapeConstructor constructor1;
//=====================================
public BranchGroup createSceneGraph() {
//=====================================
// Create the root of the branch graph
objRoot = new BranchGroup();
// Create the bounding leaf node
bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 150.0);
Color3f lColor2 = new Color3f(1f, 1f, 1f);
PointLight lgt2 = new PointLight(lColor2, new Point3f(0f, 0f, 1f), new
Point3f(0.25f, 0.1f, 0.01f));
lgt2.setInfluencingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0));
objRoot.addChild(lgt2);
scaleBack = new TransformGroup();
Matrix4d mat_init = new Matrix4d ( 1.0, 0.0 , 0.0 , -5.0,
0.0, 1.0 , 0.0 , 0.0,
0.0, 0.0, 1.0, -10.0,
0.0, 0.0 , 0.0, 1.0);
Transform3D t1 = new Transform3D(mat_init);
t1.normalize();
scaleBack.setTransform(t1);
objTrans = new TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(scaleBack);
scaleBack.addChild(objTrans);
Color3f[] colors = {red, green, blue, yellow, white, cyan, orange,
pink, brown, red1, green1,
blue1, yellow1, black};
tshape = new Shape3D();
/* float[] vertices = { -3.0f,0.0f,-2.0f,
0.0f,0.0f,4.0f,
3.0f,0.0f,-2.0f,
0.0f,4.0f,0.0f};
int[] vertice_indices = { 0,3,1,
1,3,2,
0,2,3,
1,2,0};
int [] color_indices = {0,0,0,
1,1,1,
2,2,2,
3,3,3};
*/
float[] tvertices = {3.f, 0.f, -2.f,
3.f, -1.f, -2.f,
3.f, -2.f, -2.f,
3.f, -3.f, -2.f,
4.f, 0.f, -2.f,
4.f, -1.f, -2.f,
4.f, -2.f, -2.f,
4.f, -3.f, -2.f,
5.f, 0.f, -2.f,
5.f, -1.f, -2.f,
5.f, -2.f, -2.f,
5.f, -3.f, -2.f};
int[] tvertex_ind = {0,1,5, 0,5,4,
4,5,9, 4,9,8,
1,2,6, 1,6,5,
5,6,10, 5,10,9,
2,3,7, 2,7,6,
6,7,11, 6,11,10};
/*
Color3f[] colors = {red, green, blue, yellow, white, cyan, orange, pink, brown, red1,
green1, blue1, yellow1, black};
int[] tcolor_ind = {9,0,0, 9,1,1, 9,2,2, 9,3,3, 9,4,4, 9,5,5,
9,6,6, 9,7,7, 9,8,8,
0,1,1, 0,2,2, 0, 3,3};
*/
int[] tcolor_ind = {9,0,0, 9,0,0, 9,1,1, 9,1,1, 9,2,2, 9,2,2,
9,3,3, 9,3,3,
9,4,4, 9,4,4, 9,5,5, 9, 5,5};
int[][] stripCounts = {{3,3,3,3},
{3,3,3,3},
{3,3,3,3}};
GeometryInfo gi1 = new GeometryInfo(GeometryInfo.TRIANGLE_ARRAY);
gi1.setCoordinates(tvertices);
gi1.setCoordinateIndices(tvertex_ind);
gi1.setColors(colors);
gi1.setColorIndices(tcolor_ind);
NormalGenerator ng1 = new NormalGenerator();
ng1.generateNormals(gi1);
Stripifier st1 = new Stripifier();
st1.stripify(gi1);
// generate TriangleStripArray, the order of the quads(why?) returned by shape3D is
reversed
TriangleStripArray ttristrip = (TriangleStripArray) gi1.getGeometryArray();
ttristrip.setCapability(TriangleStripArray.ALLOW_COLOR_WRITE);
ttristrip.setCapability(TriangleStripArray.ALLOW_COLOR_READ);
// - Set the geometry for the shape
tshape.setGeometry( ttristrip );
tshape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
tshape.setCapability(Shape3D.ALLOW_GEOMETRY_READ );
tshape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
objTrans.addChild(tshape);
// Have Java 3D perform optimizations on this scene graph.
objRoot.compile();
System.out.println("start rendering");
return objRoot;
}
public Canvas3D getCanvas3D() { return canvas; }
//
// The following allows HelloUniverse to be run as an application
// as well as an applet
//
public Shape3D getTShape() { return tshape; }
//======================
public TestUniverse() {
//======================
setLayout(new BorderLayout());
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
canvas = new Canvas3D(config)
{
Dimension canvasPrefSize = new Dimension( 700, 500 );
public Dimension getPreferredSize() { return canvasPrefSize; }
};
add("Center", canvas);
// canvas.addKeyListener(this);
// Create a simple scene and attach it to the virtual universe
BranchGroup scene = createSceneGraph();
SimpleUniverse u = new SimpleUniverse(canvas);
// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.*;
import javax.swing.border.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.util.Enumeration;
public class MenuDemo extends JPanel implements ItemListener, ActionListener{
private TestUniverse universe;
private boolean pressed = false;
private Shape3D shape3d;
private Shape3D tshape3d;
private Color3f am = new Color3f(0.5f, 0.5f,0.5f);
private Color3f emm = new Color3f(0.f, 0.f,0.f);
private Color3f dif = new Color3f(0.f, 0.f,1.f);
private Color3f spe = new Color3f(1.f, 1.f,1.f);
private Color3f white = new Color3f(1.0f,1.0f,1.0f);
private Color3f black = new Color3f(0.0f,0.0f,0.0f);
private Color3f red = new Color3f(1.0f,0.0f,0.0f);
private Color3f green = new Color3f(0.0f,1.0f,0.0f);
private Color3f blue = new Color3f(0.0f,0.0f,1.0f);
private Color3f yellow = new Color3f(1.0f,1.0f,0.0f);
private static final Color3f brown = new Color3f( 0.78f, 0.2f, 0.1f );
private static final Color3f cyan = new Color3f( 0.0f, 1.0f, 1.0f );
private static final Color3f orange = new Color3f( 1.0f, 0.5f, 0.0f );
private static final Color3f pink = new Color3f( 1.0f, 0.0f, 0.5f );
private Color3f red1 = new Color3f(.70f,0.20f,0.20f);
private Color3f green1 = new Color3f(0.0f,1.0f,0.30f);
private Color3f blue1 = new Color3f(0.30f,0.0f,1.0f);
private Color3f yellow1 = new Color3f(4.0f,5.0f,0.0f);
Color3f[] colors1 = {red1, black, white, yellow1};
/* private GeometryArray geometryArray1;
private IndexedTriangleStripArray itsa;
int[] new_colorInd = {3,3,3, 0,0,0, 0,0,0,1,1,1};
int[] old_colorInd = {0,0,0, 1,1,1, 2,2,2, 3,3,3};
*/
public MenuDemo() {
JMenuBar menuBar;
JMenu menu, submenu;
JMenuItem menuItem;
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
setLayout(new BorderLayout());
universe = new TestUniverse();
// shape3d = universe.getShape();
tshape3d = universe.getTShape();
universe.setMinimumSize( new Dimension(60,60));
universe.setPreferredSize(
universe.getCanvas3D().getPreferredSize() );
add(universe, BorderLayout.SOUTH);
//Create the menu bar.
menuBar = new JMenuBar();
//Build the first menu.
menu = new JMenu("Menu A");
menu.setMnemonic(KeyEvent.VK_A);
menu.getAccessibleContext().setAccessibleDescription(
"try this one");
menuBar.add(menu);
//a group of JMenuItems
menuItem = new JMenuItem("A text-only menu item",
KeyEvent.VK_T);
//menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_1, ActionEvent.ALT_MASK));
menuItem.getAccessibleContext().setAccessibleDescription(
"This doesn't really do anything");
menu.add(menuItem);
menuItem = new JMenuItem("Both text and icon",
new ImageIcon("images/middle.gif"));
menuItem.setMnemonic(KeyEvent.VK_B);
menuItem.addActionListener(this);
menu.add(menuItem);
menuItem = new JMenuItem(new ImageIcon("images/middle.gif"));
menuItem.setMnemonic(KeyEvent.VK_D);
menuItem.addActionListener(this);
menu.add(menuItem);
//a group of radio button menu items
menu.addSeparator();
submenu = new JMenu("A submenu");
submenu.setMnemonic(KeyEvent.VK_S);
menuItem = new JMenuItem("change color");
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_2, ActionEvent.ALT_MASK));
menuItem.addActionListener(this);
submenu.add(menuItem);
menuItem = new JMenuItem("restore color");
menuItem.addActionListener(this);
submenu.add(menuItem);
menu.add(submenu);
menuItem = new JMenuItem("Exit");
menuItem.addActionListener(this);
menu.add(menuItem);
//Build second menu in the menu bar.
menu = new JMenu("Test");
menu.setMnemonic(KeyEvent.VK_N);
menu.getAccessibleContext().setAccessibleDescription(
"out of here");
menu.addActionListener(this);
menuBar.add(menu);
add(menuBar,BorderLayout.NORTH);
}
public void actionPerformed(ActionEvent e) {
JMenuItem source = (JMenuItem)(e.getSource());
String Item_Name = source.getText();
AppearanceSet appSet = new AppearanceSet();
Appearance app = new Appearance();
app.setCapability(app.ALLOW_MATERIAL_READ);
app.setCapability(app.ALLOW_MATERIAL_WRITE);
GeometryArray tsa;
GeometryStripArray gsa;
IndexedGeometryArray iga;
// tsa = (GeometryArray) tshape3d.getGeometry();
gsa = (GeometryStripArray) tshape3d.getGeometry();
if (Item_Name.equals("restore color")) {
System.out.println("action of menu, restore");
//red, green, blue, yellow, white, cyan
gsa.setColor(23,black);
gsa.setColor(22,red);
gsa.setColor(21,red);
gsa.setColor(20,red);
gsa.setColor(19,black);
gsa.setColor(18,green);
gsa.setColor(17,green);
gsa.setColor(16,green);
gsa.setColor(15,black);
gsa.setColor(14,blue);
gsa.setColor(13,blue);
gsa.setColor(12,blue);
gsa.setColor(11,black);
gsa.setColor(10,yellow);
gsa.setColor(9,yellow);
gsa.setColor(8,yellow);
gsa.setColor(7,black);
gsa.setColor(6,white);
gsa.setColor(5,white);
gsa.setColor(4,white);
gsa.setColor(3,black);
gsa.setColor(2,cyan);
gsa.setColor(1,cyan);
gsa.setColor(0,cyan);
}
if (Item_Name.equals("change color")) {
gsa.setColor(0,black);
gsa.setColor(1,red);
gsa.setColor(2,red);
gsa.setColor(3,red);
gsa.setColor(4,black);
gsa.setColor(5,green);
gsa.setColor(6,green);
gsa.setColor(7,green);
gsa.setColor(8,black);
gsa.setColor(9,blue);
gsa.setColor(10,blue);
gsa.setColor(11,blue);
gsa.setColor(12,black);
gsa.setColor(13,yellow);
gsa.setColor(14,yellow);
gsa.setColor(15,yellow);
gsa.setColor(16,black);
gsa.setColor(17,white);
//red, green, blue, yellow, white, cyan
gsa.setColor(18,white);
gsa.setColor(19,white);
gsa.setColor(20,black);
gsa.setColor(21,cyan);
gsa.setColor(22,cyan);
gsa.setColor(23,cyan);
}
repaint();
if (Item_Name.equals("Exit"))
{
System.exit( 0 );
}
}
public void itemStateChanged(ItemEvent e) {}
public static void main(String[] args) {
JFrame frame = new JFrame("test menu");
frame.getAccessibleContext().setAccessibleDescription("A sample application to
demonstrate Java2D features");
int WIDTH = 700, HEIGHT = 600;
frame.setSize(WIDTH, HEIGHT);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation(d.width/2 - WIDTH/2, d.height/2 - HEIGHT/2);
// frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
public void windowDeiconified(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
});
MenuDemo me = new MenuDemo();
frame.getContentPane().add(me, BorderLayout.CENTER);
frame.validate();
// me.requestDefaultFocus();
frame.setVisible(true);
}
}
Lan Wu-Cavener
Research Associate and Programmer
Dept. of Landscape Architecture