Textures

S

seatizen

Hello.
There is an example of creating shapes using TriangleFanArray class in the
Java3D Sun Tutorial - YoyoApp.java:
...
TriangleFanArray tfa;
int N = 17;
int totalN = 4*(N+1);
Point3f coords[] = new Point3f[totalN];
int stripCounts[] = {N+1, N+1, N+1, N+1};
float r = 0.6f;
float w = 0.4f;
int n;
double a;
float x, y;

// set the central points for four triangle fan strips
coords[0*(N+1)] = new Point3f(0.0f, 0.0f, w);
coords[1*(N+1)] = new Point3f(0.0f, 0.0f, 0.0f);
coords[2*(N+1)] = new Point3f(0.0f, 0.0f, 0.0f);
coords[3*(N+1)] = new Point3f(0.0f, 0.0f, -w);

for(a = 0,n = 0; n < N; a = 2.0*Math.PI/(N-1) * ++n){
x = (float) (r * Math.cos(a));
y = (float) (r * Math.sin(a));
coords[0*(N+1)+n+1] = new Point3f(x, y, w);
coords[1*(N+1)+N-n] = new Point3f(x, y, w);
coords[2*(N+1)+n+1] = new Point3f(x, y, -w);
coords[3*(N+1)+N-n] = new Point3f(x, y, -w);
}

tfa = new TriangleFanArray (totalN,
TriangleFanArray.COORDINATES, stripCounts);
...
Shape3D dach = new Shape3D(tfa, appear2);

I added it to the scene graph and my question is: how can i put a texture on
it?
I've tried to do it:
String filename = "bud1.jpg";
TextureLoader loader = new TextureLoader(filename, this);
ImageComponent2D image = loader.getImage();
Texture2D texture = new Texture2D(Texture.BASE_LEVEL,
Texture.RGBA,
image.getWidth(), image.getHeight());
texture.setImage(0, image);
appear2.setTexture(texture);

And the result is: one color cover.
Greetings...
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top