Drawing Textured Sphere with Toxiclibs
in
Contributed Library Questions
•
2 years ago
Hey everyone,
I'm having a big problem trying to map a texture onto a sphere in Processing using Toxiclibs. Every time I try to add a texture onto the sphere I either get a solid black Sphere or I get a white gridded Sphere. I've looked through all the documentation looking for an example of this but just can't find any. Spent nearly a whole day trying to map a flat image of the earth on the Sphere - I have done it with another sketch but I'm trying to get it re-written with Toxiclibs. I've included some pics of the current output of the sketch and the desired result.
Current Output:
Expected Result:
If anyone could help me with this or even point me in the right direction then I would be much appreciated. Code is below.
Many Thanks
Steve
- import processing.opengl.*;
- import toxi.processing.*;
- import toxi.geom.*;
- import toxi.geom.mesh.*;
- float GLOBE_RAD = 250;
- ToxiclibsSupport gfx;
- Sphere globe;
- List arcPoints;
- PImage stars, earthImage;
- void setup() {
- size(1024, 768,OPENGL);
- gfx=new ToxiclibsSupport(this);
- globe=new Sphere(new Vec3D(), GLOBE_RAD);
- stars = loadImage("stars2.jpg");
- earthImage = loadImage("world2.jpg");
- frameRate(15);
- }
- void draw() {
- background(255);
- image(stars, 0, 0);
- //Set World into the Center of the Screen
- translate(width/2,height/2,0);
- // Set Rotation to look at the UK
- rotateX(radians(140));
- rotateY(radians(90));
- //Rotate World right to left on every draw
- rotateY(frameCount * - 0.05);
- noStroke();
- lights();
- //Create the Mesh for Texture
- TriangleMesh tm = (TriangleMesh)globe.toMesh(80);
- gfx.texturedMesh(tm, earthImage, false);
- }
1