Road-hog123 / Blender-OMSI-Exporter

OMSI Mesh (.o3d) exporter addon for Blender and Blender LTS
Apache License 2.0
24 stars 0 forks source link

Exporter doesn't like objects with more than 7 Materials with different UVs #4

Closed jem-suu closed 2 years ago

jem-suu commented 2 years ago

Bug Description

Expected Outcome: Object in question exports normally (even without SDK Compatiability) Actual Outcome: See traceback message below

Steps to Reproduce

This only came up when I'm working with a junction that has more than 7 materials, so I'm not 100% sure if the exporter was built with this in mind

Screenshot of materials and UVs in this one object

image

n.b. the missing textures don't seem to affect the export, having seperated the single object into multiple ones with less materials, they also seem to export normally

image

Traceback

  File "C:\Program Files\Blender Foundation\Blender\3.0\scripts\addons\io_export_o3d\exporter.py", line 242, in triangles
    uv_layer = me.uv_layers[wrapper.uv_map]
KeyError: 'bpy_prop_collection[key]: key "" not found'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender\3.0\scripts\addons\io_export_o3d\__init__.py", line 193, in execute
    exporter.export(objects, Path(self.filepath))
  File "C:\Program Files\Blender Foundation\Blender\3.0\scripts\addons\io_export_o3d\exporter.py", line 299, in export
    mesh.triangles = [meshio.Triangle(vs, m) for vs, m in triangles()]
  File "C:\Program Files\Blender Foundation\Blender\3.0\scripts\addons\io_export_o3d\exporter.py", line 299, in <listcomp>
    mesh.triangles = [meshio.Triangle(vs, m) for vs, m in triangles()]
  File "C:\Program Files\Blender Foundation\Blender\3.0\scripts\addons\io_export_o3d\exporter.py", line 253, in triangles
    me.uv_layers.new()
RuntimeError: Error: Cannot add more than 8 UV maps

location: <unknown location>:-1

Version Information

Road-hog123 commented 2 years ago

Thanks for the report!

The intention was that the exporter would create a new UV map if a mesh did not have any, however it is actually creating a new UV map for every material slot that does not specify a UV map, so if there are enough material slots and existing UV maps the exporter can exceed Blender's limit of 8 UV maps.

Before and after Blender 3.0.0 me.uv_layers.new() returns None when trying to create a 9th UV map, so this programming error passed silently by unnoticed, but in Blender 3.0.0 it raises an exception as encountered above.

Exporter 3.0.1 for Blender 3.0 & 3.1 includes a fix for this issue and a small quality-of-life improvement.