Hello!
I'm trying to get the "PolygonAttributes.CULL_NONE" to work in an 3D applet.
But I can't get it right
I ad here a full class wich extends Shape3D, wich in my opinion use
"PolygonAttributes.CULL_NONE", wich also in my opinion shuld be solid.
I also add the html-file to run it and an applet.
When you have started the applet, start navigate with ARROW_DOWN-key. Then
You will see the Shape3d
The shape3d-class
import java.applet.*;
import java.awt.*;
import java.awt.Frame;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.event.*;
import java.util.Enumeration;
public class Test3dBrick extends Shape3D
{
public Test3dBrick()
{
createAppearance();
addGeometry(getContour());
addGeometry(getBody());
}
public void createAppearance()
{
Appearance appearance = new Appearance();
PolygonAttributes polygonAttributes = new PolygonAttributes();
polygonAttributes.setCullFace(PolygonAttributes.CULL_NONE);
polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL);
polygonAttributes.setBackFaceNormalFlip(true);
appearance.setPolygonAttributes(polygonAttributes);
setAppearance(appearance);
}
public Geometry getContour()
{
Color3f darkgray = new Color3f(0.2f, 0.2f, 0.2f);
IndexedLineArray indexedLineArray = new IndexedLineArray(8,
GeometryArray.COORDINATES | GeometryArray.COLOR_3 , 24);
indexedLineArray.setCoordinate(0, new
Point3f( -0.201f, -0.001f, -0.201f ));
indexedLineArray.setCoordinate(1, new Point3f( -0.201f, -0.001f,
0.201f ));
indexedLineArray.setCoordinate(2, new Point3f( 0.201f, -0.001f,
0.201f ));
indexedLineArray.setCoordinate(3, new
Point3f( 0.201f, -0.001f, -0.201f ));
indexedLineArray.setCoordinate(4, new Point3f( -0.201f,
0.201f, -0.201f ));
indexedLineArray.setCoordinate(5, new Point3f( -0.201f, 0.201f, 0.201f
));
indexedLineArray.setCoordinate(6, new Point3f( 0.201f, 0.201f, 0.201f
));
indexedLineArray.setCoordinate(7, new Point3f( 0.201f,
0.201f, -0.201f ));
indexedLineArray.setCoordinateIndex( 0, 0);
indexedLineArray.setCoordinateIndex( 1, 1);
indexedLineArray.setCoordinateIndex( 2, 1);
indexedLineArray.setCoordinateIndex( 3, 2);
indexedLineArray.setCoordinateIndex( 4, 2);
indexedLineArray.setCoordinateIndex( 5, 3);
indexedLineArray.setCoordinateIndex( 6, 3);
indexedLineArray.setCoordinateIndex( 7, 0);
indexedLineArray.setCoordinateIndex( 10, 4);
indexedLineArray.setCoordinateIndex( 11, 5);
indexedLineArray.setCoordinateIndex( 12, 5);
indexedLineArray.setCoordinateIndex( 13, 6);
indexedLineArray.setCoordinateIndex( 14, 6);
indexedLineArray.setCoordinateIndex( 15, 7);
indexedLineArray.setCoordinateIndex( 16, 7);
indexedLineArray.setCoordinateIndex( 17, 4);
indexedLineArray.setCoordinateIndex( 8, 0);
indexedLineArray.setCoordinateIndex( 9, 4);
indexedLineArray.setCoordinateIndex( 18, 1);
indexedLineArray.setCoordinateIndex( 19, 5);
indexedLineArray.setCoordinateIndex( 20, 2);
indexedLineArray.setCoordinateIndex( 21, 6);
indexedLineArray.setCoordinateIndex( 22, 3);
indexedLineArray.setCoordinateIndex( 23, 7);
indexedLineArray.setColor(0, darkgray);
return indexedLineArray;
}
public Geometry getBody()
{
Color3f lightgray = new Color3f(0.8f, 0.8f, 0.8f);
IndexedQuadArray indexedQuadArray = new IndexedQuadArray(8,
GeometryArray.COORDINATES | GeometryArray.COLOR_3 , 24);
indexedQuadArray.setCoordinate(0, new Point3f( -0.2f, 0.0f, -0.2f ));
indexedQuadArray.setCoordinate(1, new Point3f( -0.2f, 0.0f, 0.2f ));
indexedQuadArray.setCoordinate(2, new Point3f( 0.2f, 0.0f, 0.2f ));
indexedQuadArray.setCoordinate(3, new Point3f( 0.2f, 0.0f, -0.2f ));
indexedQuadArray.setCoordinate(4, new Point3f( -0.2f, 0.2f, -0.2f ));
indexedQuadArray.setCoordinate(5, new Point3f( -0.2f, 0.2f, 0.2f ));
indexedQuadArray.setCoordinate(6, new Point3f( 0.2f, 0.2f, 0.2f ));
indexedQuadArray.setCoordinate(7, new Point3f( 0.2f, 0.2f, -0.2f ));
indexedQuadArray.setCoordinateIndex( 0, 0);
indexedQuadArray.setCoordinateIndex( 1, 1);
indexedQuadArray.setCoordinateIndex( 2, 2);
indexedQuadArray.setCoordinateIndex( 3, 3);
indexedQuadArray.setCoordinateIndex( 4, 4);
indexedQuadArray.setCoordinateIndex( 5, 5);
indexedQuadArray.setCoordinateIndex( 6, 6);
indexedQuadArray.setCoordinateIndex( 7, 7);
indexedQuadArray.setCoordinateIndex( 8, 0);
indexedQuadArray.setCoordinateIndex( 9, 4);
indexedQuadArray.setCoordinateIndex( 10, 5);
indexedQuadArray.setCoordinateIndex( 11, 1);
indexedQuadArray.setCoordinateIndex( 12, 1);
indexedQuadArray.setCoordinateIndex( 13, 5);
indexedQuadArray.setCoordinateIndex( 14, 6);
indexedQuadArray.setCoordinateIndex( 15, 7);
indexedQuadArray.setCoordinateIndex( 16, 2);
indexedQuadArray.setCoordinateIndex( 17, 6);
indexedQuadArray.setCoordinateIndex( 18, 7);
indexedQuadArray.setCoordinateIndex( 19, 3);
indexedQuadArray.setCoordinateIndex( 20, 0);
indexedQuadArray.setCoordinateIndex( 21, 4);
indexedQuadArray.setCoordinateIndex( 22, 7);
indexedQuadArray.setCoordinateIndex( 23, 3);
indexedQuadArray.setColor(0, lightgray);
return indexedQuadArray;
}
}
The html-file:
<html>
<head></head>
<body bgcolor=Yellow>
<!--"CONVERTED_APPLET"-->
<!-- CONVERTER VERSION 1.3 -->
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
WIDTH = "600" HEIGHT = "400"
codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Vers
ion=1,3,0,0">
<PARAM NAME = CODE VALUE = "Shape3DTesterApplet.class" >
<PARAM NAME = CODEBASE VALUE = "." >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<PARAM NAME="scriptable" VALUE="false">
<PARAM NAME = "archive" VALUE ="java.zip">
<COMMENT>
<EMBED type="application/x-java-applet;version=1.3" CODE =
"Shape3DTesterApplet.class" CODEBASE = "." WIDTH = "600" HEIGHT = "400"
archive = "java.zip" scriptable=false
pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><N
OEMBED></COMMENT>
</NOEMBED></EMBED>
</OBJECT>
<!--"END_CONVERTED_APPLET"-->
</body>
</html>
The applet
import java.applet.*;
import java.awt.*;
import java.awt.Frame;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.keyboard.*;
public class Shape3DTesterApplet extends Applet
{
public void init()
{
setLayout(new BorderLayout());
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3D = new Canvas3D(config);
add("Center", canvas3D);
SimpleUniverse simpleUniverse = new SimpleUniverse(canvas3D);
BranchGroup branchGroup = new BranchGroup();
branchGroup.addChild(addShape3D());
TransformGroup transformGroup1 =
simpleUniverse.getViewingPlatform().getViewPlatformTransform();
KeyNavigatorBehavior keyNavigatorBehavior = new
KeyNavigatorBehavior(transformGroup1);
keyNavigatorBehavior.setSchedulingBounds(new BoundingSphere(new
Point3d(-3.0f, -3.0f, -3.0f),10000.0));
branchGroup.addChild(keyNavigatorBehavior);
simpleUniverse.addBranchGraph(branchGroup);
}
public Shape3D addShape3D()
{
Test3dBrick test3dBrick = new Test3dBrick();
return test3dBrick;
}
}
Best regards <br>
Fredrik
===========================================================================
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".