Using pyglet, I am trying to create a UVSphere mesh, and on its surface I would like to display a mercator-projection map. In researching examples of pyglet texture mapping, I have found:
- Nehe tutorial 6 in pyglet. However this uses immediate mode, and shows the entire texture on each cube face.
- pyglet_obj_test, which looks like it includes texture maps. However instead of showing the chosen texture, it shows an even color.
- stackoverflow question, which looks like there was an answer with a solution. However the referenced gists showing working code have disappeared.
- Another implementation, referenced in the pyglet google group
Are there any simple examples of a working mesh + texture map in pyglet?
Edit: I found out the pyglet_obj_test code is looking for lines in the .obj
file starting with vt
in order to create texture mapping coordinates. However the Wavefront exporter in Blender apparently has no option to export this information. I exported the same mesh with each of the other available types:
COLLADA (.dae)
Stanford (.ply)
Stl (.stl)
3D Studio (.3ds)
Autodesk FBX (.fbx)
X3D Extensible 3D (.x3d)
Perhaps there's a pyglet importer for one of these formats...
Edit 2: I clearly have a poor understanding of the wavefront format. It seems vt
lines are not necessary. What I was missing is full f
maps.
For instance, to simplify things way down, I created a 3d mesh that was actually a single square, with a texture mapped onto it. In Blender it shows the square with distorted texture, but the built-in wavefront exporter produces a single line of texture mapping f 2//1 1//1 3//1 4//1
. These should apparently instead be something like f 2/0/1 1/0/1 3/0/1 4/0/1
(note there should be a number between the two slashes).
Apparently Blender only does a full (proper?) export of these lines if a texture is UV mapped. Applying a texture without a UV Map renders properly in Blender, but I guess the wavefront exporter doesn't properly handle it. Perhaps it's time for me to submit a Blender bug report...