I can't apply textures to custom PShapes

TLDR: Can you apply a texture spherically to an arbitrary instance of PShape?

So, I’ve been writing code to make a solar system model. Recently, I added in Mars’s moons, Phobos and Deimos. Which, unlike everything else in my model so far, aren’t spherical. They’re bumpy, and shaped like asteroids.

Luckily, there’s a website that generously offers both downloadable 3D models for Phobos & Deimos, as well as textures to, to quote the website, “Apply spherically” to these shapes. The good news is that the shapes are rendering successfully. The bad news is, the textures aren’t.

(First is actually Phobos, second is what Processing rendered. The line through it is the axis, the stuff in the background are the orbits of other planets, moons, and dwarfs. Don’t worry about it.)

Admittedly, this is the first time I’ve used PShape. I know that if your shape is one of the defaults, like a sphere or box, the renderer knows exactly how to apply the texture. But, for custom shapes like these, it doesn’t really know what to do. It looks to me like it’s just applying the top left of the texture to every triangle individually. Which…I guess I makes sense. On surfaces like this, texture mapping is a bit ambiguous.

Now, my username isn’t all talk. As it so happens, I actually do know what it means to “apply a texture spherically”. First, apply the texture like to a sphere. Align the center of the sphere to the center of your 3D model. Now, using math and brute force, move every single pixel on your sphere either closer to or farther from the center until it’s on the surface of your 3D model. And, in theory, using the point(x,y,z) function, I could tell it to do just that.

The problem is, if I were to do that, my computer would burst into flames. There’s no way the CPU could do all that work in real time. In theory, you’d wanna delegate that task to the GPU, preferably using an algorithm created by someone more clever than me.

So, yeah…that’s my issue. I honestly don’t even know if it’s even possible to apply a texture spherically using processing. If you know how, or even know if it’s possible to do so feasibly, please tell me.

Keep in mind, I don’t necessarily need all the work done by Processing. For instance, if there’s some other class I’m not aware of that stores a 3D model and all the textures that get applied to each triangle, I’d be more than happy to use something like Blender to create that file and upload it to processing. I mean, like I said, I’m still new to this stuff, so for all I know, the class I speak of might even be PShape.

Yes you can; without the code I cannot find what exactly the problem is, but basically you need to define the texture coordinate (u, v parameters of vertex()). And you have to define it somehow - it shouldn’t be too hard if your geometry is based on a sphere, for example (then you can start with mapping longitude and latitude to u, v).

Thank you for your input. I have to ask, did you read the rest of the post, or just the title?

I hope I don’t come across as rude, I just have to make sure what you’re describing works when the shape is loaded through a file, and not declared in the sketch itself. I also have to make sure it’s feasible given the whole “spherical mapping” requirement.

Thanks!