Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Want <cwant@ualberta.ca>2006-08-16 05:06:38 +0400
committerChris Want <cwant@ualberta.ca>2006-08-16 05:06:38 +0400
commit1f68dfb499f93960c0a188d2b205a81cd3e6a999 (patch)
tree4300e13ec88d33c0ccda2018283e8dfb4fffc341 /release
parent73f44f6fbb4ddd2b466f0d540581d3e86b3fbe28 (diff)
A mesh from the Blender python Mesh module can sometimes have
a materials array with entries that are 'None'. Added some code to check for this perverse situation.
Diffstat (limited to 'release')
-rw-r--r--release/scripts/vrml97_export.py45
1 files changed, 32 insertions, 13 deletions
diff --git a/release/scripts/vrml97_export.py b/release/scripts/vrml97_export.py
index 703460805da..3fa58339f04 100644
--- a/release/scripts/vrml97_export.py
+++ b/release/scripts/vrml97_export.py
@@ -455,8 +455,9 @@ class VRML2Export:
if (me.vertexColors):
if len(me.materials) > 0:
mat = me.materials[0]
- if (mat.mode & Blender.Material.Modes['VCOL_PAINT']):
- self.vcolors = 1
+ if mat:
+ if (mat.mode & Blender.Material.Modes['VCOL_PAINT']):
+ self.vcolors = 1
# check if object is wireframe only
if ob.drawType == Blender.Object.DrawTypes.WIRE:
@@ -557,26 +558,31 @@ class VRML2Export:
issmooth = 0
maters = me.materials
+ nummats = self.getNumMaterials(me)
# Vertex and Face colors trump materials and image textures
if (self.facecolors or self.vcolors):
- if len(maters) > 0:
- self.writeShape(ob, me, 0, None)
+ if nummats > 0:
+ if maters[0]:
+ self.writeShape(ob, me, 0, None)
+ else:
+ self.writeShape(ob, me, -1, None)
else:
self.writeShape(ob, me, -1, None)
# Do meshes with materials, possible with image textures
- elif len(maters) > 0:
+ elif nummats > 0:
for matnum in range(len(maters)):
- images = []
- if me.faceUV:
- images = self.getImages(me, matnum)
- if len(images) > 0:
- for image in images:
- self.writeShape(ob, me, matnum, image)
+ if maters[matnum]:
+ images = []
+ if me.faceUV:
+ images = self.getImages(me, matnum)
+ if len(images) > 0:
+ for image in images:
+ self.writeShape(ob, me, matnum, image)
+ else:
+ self.writeShape(ob, me, matnum, None)
else:
self.writeShape(ob, me, matnum, None)
- else:
- self.writeShape(ob, me, matnum, None)
else:
if me.faceUV:
images = self.getImages(me, -1)
@@ -604,6 +610,15 @@ class VRML2Export:
imageNames[imName]=1
return images
+ def getNumMaterials(self, me):
+ # Oh silly Blender, why do you sometimes have 'None' as
+ # a member of the me.materials array?
+ num = 0
+ for mat in me.materials:
+ if mat:
+ num = num + 1
+ return num
+
def writeCoordinates(self, me, meshName):
coordName = "coord_%s" % (meshName)
# look up coord name, use it if available
@@ -631,6 +646,10 @@ class VRML2Export:
self.writeIndented("\n")
def writeShape(self, ob, me, matnum, image):
+ # Note: at this point it is assumed for matnum!=-1 that the
+ # material in me.materials[matnum] is not equal to 'None'.
+ # Such validation should be performed by the function that
+ # calls this one.
self.writeIndented("Shape {\n",1)
self.writeIndented("appearance Appearance {\n", 1)