Browse Source

Fix "I'm a material but not really" bugs

Why in the world is it even possible for a material to be None? This is
just a GOTCHA for the sake of GOTCHAs.
pull/8/head
Adam Johnson 10 years ago
parent
commit
2c0aae9915
  1. 22
      korman/exporter/mesh.py
  2. 4
      korman/operators/op_lightmap.py

22
korman/exporter/mesh.py

@ -255,19 +255,27 @@ class MeshConverter:
drawables = self._export_mesh(bo)
# Create the DrawInterface
if drawables:
diface = self._mgr.add_object(pl=plDrawInterface, bl=bo)
for dspan_key, idx in drawables:
diface.addDrawable(dspan_key, idx)
def _export_mesh(self, bo):
# Step 0.8: If this mesh wants to be lit, we need to go ahead and generate it.
# Step 0.7: Update the mesh such that we can do things and schtuff...
mesh = bo.to_mesh(bpy.context.scene, True, "RENDER", calc_tessface=True)
# Step 0.8: Figure out which materials are attached to this object. Because Blender is backwards,
# we can actually have materials that are None. gotdawgit!!!
materials = [i for i in mesh.materials if i is not None]
if not materials:
return None
# Step 0.9: If this mesh wants to be lit, we need to go ahead and generate it.
self._export_static_lighting(bo)
# Step 0.9: Update the mesh such that we can do things and schtuff...
mesh = bo.to_mesh(bpy.context.scene, True, "RENDER", calc_tessface=True)
with helpers.TemporaryObject(mesh, bpy.data.meshes.remove):
# Step 1: Export all of the doggone materials.
geospans = self._export_material_spans(bo, mesh)
geospans = self._export_material_spans(bo, mesh, materials)
# Step 2: Export Blender mesh data to Plasma GeometrySpans
self._export_geometry(bo, mesh, geospans)
@ -292,10 +300,10 @@ class MeshConverter:
drawables.append((dspan.key, idx))
return drawables
def _export_material_spans(self, bo, mesh):
def _export_material_spans(self, bo, mesh, materials):
"""Exports all Materials and creates plGeometrySpans"""
geospans = [None] * len(mesh.materials)
for i, blmat in enumerate(mesh.materials):
geospans = [None] * len(materials)
for i, blmat in enumerate(materials):
matKey = self.material.export_material(bo, blmat)
geospans[i] = (self._create_geospan(bo, mesh, blmat, matKey), blmat.pass_index)
return geospans

4
korman/operators/op_lightmap.py

@ -44,6 +44,10 @@ class _LightingOperator:
shouldibake = (user_lg and user_lg.objects)
for material in mesh.materials:
if material is None:
# material is not assigned to this material... (why is this even a thing?)
continue
lg = material.light_group
self._old_lightgroups[material] = lg

Loading…
Cancel
Save