// the length of each triangle strip
int[] stripLen = { 4, 4, 4, 4, 4, 4 };
// create the index buffer for our object (this tells how to
// create triangle strips from the contents of the vertex buffer).
TriangleStripArray tsa = new TriangleStripArray(0, stripLen);
//创建多边形模式。
PolygonMode pm = new PolygonMode();
pm.setShading(PolygonMode.SHADE_SMOOTH);
pm.setCulling(PolygonMode.CULL_NONE);
//生成外貌。
Appearance app = new Appearance();
app.setPolygonMode(pm);
Image texImg= null;
try{
texImg = Image.createImage(this.imageUrl);
}catch(Exception e){
String strErr="Load Image (path=";
strErr += this.imageUrl;
strErr += ") Fail!";
System.err.println(strErr);
}
Texture2D texture=null;
try{
// create texture from loaded image.
texture = new Texture2D(new Image2D(Image2D.RGB, texImg));
}catch(Exception e){
e.printStackTrace();
String strErr = "Failed to create texture Use Format --- Image2D.RGB";
System.out.println(strErr);
}
try{
// repeat texture on surface
texture.setWrapping(Texture2D.WRAP_REPEAT, Texture2D.WRAP_REPEAT);
}catch(Exception e){
e.printStackTrace();
System.out.println("Failed to create texture3");
}
try{
// Blend mode to use.
texture.setBlending(Texture2D.FUNC_DECAL);
}catch(Exception e){
System.out.println("Failed to create texture4");
}
try{
// Use nearest for performance, linear for quality
texture.setFiltering(Texture2D.FILTER_NEAREST,Texture2D.FILTER_NEAREST);
}catch(Exception e){
System.out.println("Failed to create texture5");
}
try{
app.setTexture(0, texture);
}catch(Exception e){
System.out.println("Failed to create texture6");
}
//创建网格。
mesh = new Mesh(vb, tsa, app);
mesh.setAppearance(0, app);
3 创建World
//create a camera
camera = new Camera();
camera.setPerspective(60.0f, // field of view
(float) getWidth() / (float) getHeight(), // aspectRatio
1.0f, // near clipping plane
1000.0f); // far clipping plane
camera.setTranslation(0,0, 50);
world = new World();
world.addChild(camera);
world.addChild(mesh);
world.setActiveCamera(camera);
4 绘制World
//private Graphics3D g3d = null;
|