Skip to content

Commit

Permalink
Fixes #324, texture slot raises exception when image is None, and add…
Browse files Browse the repository at this point in the history
…s new unit test
  • Loading branch information
tngreene committed Jan 2, 2018
1 parent ca3875b commit 1f8ca98
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
33 changes: 20 additions & 13 deletions io_xplane2blender/xplane_types/xplane_material.py
Expand Up @@ -174,30 +174,37 @@ def collect(self):
self.attributes.order()

def _detectTextures(self, mat):
'''
Detects the texture by using Blender's texture slot properties:
Diffuse->Color, Shading->Emit, Geometry->Normal, and Specular-> Intensity
'''
for i in range(0, len(mat.texture_slots)):
slot = mat.texture_slots[i]

if slot and slot.use and slot.texture.type == 'IMAGE':
#Props->Texture->Influence->Diffuse->[X] Color
if slot.use_map_color_diffuse and self.texture == None:
self.texture = slot.texture.image.filepath
#Props->Texture->Influence->Shading->[X] Emit
elif slot.use_map_emit and self.textureLit == None:
self.textureLit = slot.texture.image.filepath
#Props->Texture->Influence->Geometry->[X] Normal
elif slot.use_map_normal and self.textureNormal == None:
self.textureNormal = slot.texture.image.filepath
#Props->Texture->Influence->Specular->[X] Intensity
elif slot.use_map_specular and self.textureSpecular == None:
self.textureSpecular = slot.texture.image.filepath
if slot.texture.image is not None:
#Props->Texture->Influence->Diffuse->[X] Color
if slot.use_map_color_diffuse and self.texture == None:
self.texture = slot.texture.image.filepath
#Props->Texture->Influence->Shading->[X] Emit
elif slot.use_map_emit and self.textureLit == None:
self.textureLit = slot.texture.image.filepath
#Props->Texture->Influence->Geometry->[X] Normal
elif slot.use_map_normal and self.textureNormal == None:
self.textureNormal = slot.texture.image.filepath
#Props->Texture->Influence->Specular->[X] Intensity
elif slot.use_map_specular and self.textureSpecular == None:
self.textureSpecular = slot.texture.image.filepath
else:
logger.error("Texture '{0}' has no image".format(slot.texture.name))
return

# panel materials have only a color texture
if self.options.panel:
self.textureLit = None
self.textureNormal = None
self.textureSpecular = None


def collectCustomAttributes(self, mat):
xplaneFile = self.xplaneObject.xplaneBone.xplaneFile
commands = xplaneFile.commands
Expand Down
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/materials/objects/texture_slot_has_no_image.test.py
@@ -0,0 +1,16 @@
import bpy
import os
import inspect
import sys

from io_xplane2blender.tests import *
from io_xplane2blender import xplane_config

__dirname__ = os.path.dirname(__file__)

class TestTextureSlotHasNoImage(XPlaneTestCase):
def test_texture_slot_has_no_image(self):
out = self.exportLayer(0)
self.assertLoggerErrors(1)

runTestCases([TestTextureSlotHasNoImage])

0 comments on commit 1f8ca98

Please sign in to comment.