[code=Java][
int StripCount[] = new int[2];
float vert[] = { -0.5f, -0.5f, -0.5f, 0.6f, -0.6f, -0.6f, 0.7f, -0.8f, 0.7f,
-0.5f, -0.5f, -0.5f, 0.6f, -0.6f, -0.6f, 0.9f, -0.9f, -0.9f,
0.6f, -0.6f, -0.6f, 0.7f, -0.8f, 0.7f, 0.9f, -0.9f, -0.9f
};//平面坐标
float color[] = { 1.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.5f, 1.0f, 0.8f, 0.0f,
0.9f, 0.6f, 0.1f, 1.0f, 0.1f, 0.7f, 1.0f, 0.5f, 0.3f,
0.1f, 0.1f, 0.1f, 1.0f, 0.3f, 0.3f, 1.0f, 0.4f, 0.2f,
};//平面颜色
StripCount[0] = 9;
StripCount[1] = 9;
TriangleStripArray tri = new TriangleStripArray(18,
TriangleStripArray.COORDINATES | TriangleStripArray.TEXTURE_COORDINATE_3, StripCount);
tri.setCoordinates(0, vert);
// tri.setColors(0, color);
tri.setTextureCoordinate(0, 0, vert);
PolygonAttributes pa = new PolygonAttributes();
pa.setCullFace(PolygonAttributes.CULL_NONE);//设置双面显示。有前面、后面和双面。
Appearance ap = new Appearance();
ap.setPolygonAttributes(pa);
//纹理贴图
TextureLoader loader = new TextureLoader("e:\\1.jpg","LUMINANCE", new Container());
Texture texture = loader.getTexture();
texture.setBoundaryModeS(Texture.WRAP);
texture.setBoundaryModeT(Texture.WRAP);
// texture.setBoundaryColor(new Color4f(0.0f, 1.0f, 0.0f, 0.0f));
//纹理属性
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);
ap.setTexture(texture);
ap.setTextureAttributes(texAttr);
/code]
这样图形并没有贴上图片,不知何因,望高手救急!
int StripCount[] = new int[2];
float vert[] = { -0.5f, -0.5f, -0.5f, 0.6f, -0.6f, -0.6f, 0.7f, -0.8f, 0.7f,
-0.5f, -0.5f, -0.5f, 0.6f, -0.6f, -0.6f, 0.9f, -0.9f, -0.9f,
0.6f, -0.6f, -0.6f, 0.7f, -0.8f, 0.7f, 0.9f, -0.9f, -0.9f
};//平面坐标
float color[] = { 1.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.5f, 1.0f, 0.8f, 0.0f,
0.9f, 0.6f, 0.1f, 1.0f, 0.1f, 0.7f, 1.0f, 0.5f, 0.3f,
0.1f, 0.1f, 0.1f, 1.0f, 0.3f, 0.3f, 1.0f, 0.4f, 0.2f,
};//平面颜色
StripCount[0] = 9;
StripCount[1] = 9;
TriangleStripArray tri = new TriangleStripArray(18,
TriangleStripArray.COORDINATES | TriangleStripArray.TEXTURE_COORDINATE_3, StripCount);
tri.setCoordinates(0, vert);
// tri.setColors(0, color);
tri.setTextureCoordinate(0, 0, vert);
PolygonAttributes pa = new PolygonAttributes();
pa.setCullFace(PolygonAttributes.CULL_NONE);//设置双面显示。有前面、后面和双面。
Appearance ap = new Appearance();
ap.setPolygonAttributes(pa);
//纹理贴图
TextureLoader loader = new TextureLoader("e:\\1.jpg","LUMINANCE", new Container());
Texture texture = loader.getTexture();
texture.setBoundaryModeS(Texture.WRAP);
texture.setBoundaryModeT(Texture.WRAP);
// texture.setBoundaryColor(new Color4f(0.0f, 1.0f, 0.0f, 0.0f));
//纹理属性
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);
ap.setTexture(texture);
ap.setTextureAttributes(texAttr);
/code]
这样图形并没有贴上图片,不知何因,望高手救急!
int StripCount[] = new int[2];
float vert[] = { -0.5f, -0.5f, -0.5f, 0.6f, -0.6f, -0.6f, 0.7f, -0.8f, 0.7f,
-0.5f, -0.5f, -0.5f, 0.6f, -0.6f, -0.6f, 0.9f, -0.9f, -0.9f,
0.6f, -0.6f, -0.6f, 0.7f, -0.8f, 0.7f, 0.9f, -0.9f, -0.9f
};//平面坐标float color[] = { 1.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.5f, 1.0f, 0.8f, 0.0f,
0.9f, 0.6f, 0.1f, 1.0f, 0.1f, 0.7f, 1.0f, 0.5f, 0.3f,
0.1f, 0.1f, 0.1f, 1.0f, 0.3f, 0.3f, 1.0f, 0.4f, 0.2f,
};//平面颜色
StripCount[0] = 9;
StripCount[1] = 9;
TriangleStripArray tri = new TriangleStripArray(18,
TriangleStripArray.COORDINATES | TriangleStripArray.TEXTURE_COORDINATE_3, StripCount);
tri.setCoordinates(0, vert);
// tri.setColors(0, color);
tri.setTextureCoordinate(0, 0, vert);
PolygonAttributes pa = new PolygonAttributes();
pa.setCullFace(PolygonAttributes.CULL_NONE);//设置双面显示。有前面、后面和双面。
Appearance ap = new Appearance();
ap.setPolygonAttributes(pa);
//纹理贴图
TextureLoader loader = new TextureLoader("e:\\1.jpg","LUMINANCE", new Container());
Texture texture = loader.getTexture();
texture.setBoundaryModeS(Texture.WRAP);
texture.setBoundaryModeT(Texture.WRAP);
// texture.setBoundaryColor(new Color4f(0.0f, 1.0f, 0.0f, 0.0f));
//纹理属性
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);ap.setTexture(texture);
ap.setTextureAttributes(texAttr);
private float vert[] = {
-1f , 1f, -.2f, -1f , -1f, -.2f,
1f , -1f, -.2f, 1f , 1f, -.2f,
};
private Point2f texCoord[] = {
new Point2f(0.0f, 0.0f),
new Point2f(1.0f, 0.0f),
new Point2f(1.0f, 1.0f),
new Point2f(0.0f, 1.0f)
}; public Bottom(){
QuadArray tri = new QuadArray(4,
QuadArray.COORDINATES|QuadArray.TEXTURE_COORDINATE_2);
tri.setCoordinates(0,vert);
for (int i = 0; i < 4; i++) {
tri.setTextureCoordinate(i, texCoord[i%4]);
} this.setGeometry(tri);
}
}
String classDir = this.getClass().getResource("/").getPath();
TextureLoader texLoader2 = new TextureLoader( classDir+"res/js2.jpg", this);
Shape3D s=new Bottom();
Appearance ap3 = new Appearance( );
ap3.setTexture(texLoader2.getTexture());
PolygonAttributes pa = new PolygonAttributes();
pa.setCullFace(PolygonAttributes.CULL_NONE);
ap3.setPolygonAttributes(pa);
s.setAppearance(ap3);
objRoot.addChild(s);