3

I am making a simple OpenGL 3.3 OBJ viewer in Python using the modules Pyglet and Ratcave. I want to load a textured sphere I made in Blender. While my Pyglet/Ratcave OBJ viewer loads untextured OBJ files, when I add textures to my project, I get this error and the program fails to load:

ValueError: could not convert string to float: 'textures'

What does this mean?

I got a different error when I tried to import textures from my OneDrive folder and use them in my Blender project. When I put the textures in the same folder as the script and OBJ/MTL files, it got rid of that error, but now I can't load the textures because, for whatever reason, Ratcave needs to convert the textures to a float and it can't do that.

import pyglet
import ratcave as rc
import time

window = pyglet.window.Window()


def update(dt):
    pass

pyglet.clock.schedule(update)

# Insert filename into WavefrontReader
obj_filename = 'Textured Sphere Eevee.obj'
obj_reader = rc.WavefrontReader(obj_filename)

# Check which meshes can be found inside the Wavefront file, and extract it into a Mesh object for rendering
print(obj_reader.bodies.keys())

Sphere = obj_reader.get_mesh("Cube")
Sphere.position.xyz = 0, 0, -10

scene= rc.Scene(meshes=[Sphere])

@window.event
def on_draw():
    with rc.default_shader:
        scene.draw()
        #scene.clear()
        #time.sleep(10)

pyglet.app.run()


Traceback (most recent call last):
  File "C:\Users\Jeffery\Desktop\Art\Pyglet Game Engine\scripts\Ratcave_OBJ_Loader_Test 2.py", line 15, in <module>
    obj_reader = rc.WavefrontReader(obj_filename)
  File "C:\Users\Jeffery\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ratcave\wavefront.py", line 28, in __init__
    self.bodies = read_wavefront(file_name)
  File "C:\Users\Jeffery\AppData\Local\Programs\Python\Python37-32\lib\site-packages\wavefront_reader\reading.py", line 114, in read_wavefront
    materials = read_mtlfile(path.join(path.dirname(fname_obj), fname_mtl))
  File "C:\Users\Jeffery\AppData\Local\Programs\Python\Python37-32\lib\site-packages\wavefront_reader\reading.py", line 88, in read_mtlfile
    material[prefix] = tuple(float(d) for d in split_data)
  File "C:\Users\Jeffery\AppData\Local\Programs\Python\Python37-32\lib\site-packages\wavefront_reader\reading.py", line 88, in <genexpr>
    material[prefix] = tuple(float(d) for d in split_data)
ValueError: could not convert string to float: 'textures'
Torxed
  • 22,866
  • 14
  • 82
  • 131
  • Blender 2.8 no longer supports Blender Internal, so that may be the problem. I have to export OBJs using Eevee now, so do you think reverting back to an earlier version of Blender (Blender 2.79 maybe?) and using Internal instead of Eevee might cause less problems? – Jeffrey Thrash Sep 09 '19 at 21:14
  • This looks like a `ratcave` / `PyWavefront` issue and not a Pyglet issue. – Torxed Sep 10 '19 at 10:18
  • Consider contacting the main authors of PyWavefront or submit a issue if this is a new behavior: https://github.com/pywavefront/PyWavefront/issues – Torxed Sep 10 '19 at 11:28
  • Thanks for the response. That seems to be the case. My OBJ files made in Blender and rendered in Eevee load flawlessly in other programs, complete with the textures and materials, so I'm not sure why Ratcave has so much trouble with the textures. – Jeffrey Thrash Sep 10 '19 at 21:35
  • It's probably just a patch gone wrong some where, or mixmatch between wavefront format changes and libraries not being up to date. Where there used to be a float number it's now passing a texture instead and probably expecting the libraries to fetch the float value from that texture. Probably easy to fix if you'd go in to `wavefront_reader\reading.py` and edit line 88 : ) But talk to the devs, they can probably fix it fast :) – Torxed Sep 11 '19 at 07:58

0 Answers0