fix for [#8814] VRML 97 Exporter bug (empty coordIndex [] indexes) Blender V2.45

null materials were not exported, but would also mess up the assignment of materials for any valid materials after the empty slots.
also made a mistake last recently that Michalis Kamburelis pointed out, changing the default orientation incorrectly. this is now set 
back to what it was in Michalis's patch.
This commit is contained in:
Campbell Barton 2008-05-10 07:58:10 +00:00
parent 76c13cc0f7
commit cc279a3aa0

@ -206,7 +206,7 @@ class VRML2Export:
if scene != inlines[0]: if scene != inlines[0]:
return return
else: else:
for i in range(allinlines): for i in xrange(allinlines):
nameinline=inlines[i].getName() nameinline=inlines[i].getName()
if (nameinline not in self.namesStandard) and (i > 0): if (nameinline not in self.namesStandard) and (i > 0):
self.writeIndented("DEF %s Inline {\n" % \ self.writeIndented("DEF %s Inline {\n" % \
@ -219,7 +219,7 @@ class VRML2Export:
def writeScript(self): def writeScript(self):
textEditor = Blender.Text.Get() textEditor = Blender.Text.Get()
alltext = len(textEditor) alltext = len(textEditor)
for i in range(alltext): for i in xrange(alltext):
nametext = textEditor[i].getName() nametext = textEditor[i].getName()
nlines = textEditor[i].getNLines() nlines = textEditor[i].getNLines()
if (self.proto == 1): if (self.proto == 1):
@ -227,14 +227,14 @@ class VRML2Export:
nametext == "proto.txt") and (nlines != None): nametext == "proto.txt") and (nlines != None):
nalllines = len(textEditor[i].asLines()) nalllines = len(textEditor[i].asLines())
alllines = textEditor[i].asLines() alllines = textEditor[i].asLines()
for j in range(nalllines): for j in xrange(nalllines):
self.writeIndented(alllines[j] + "\n") self.writeIndented(alllines[j] + "\n")
elif (self.proto == 0): elif (self.proto == 0):
if (nametext == "route" or nametext == "route.js" or \ if (nametext == "route" or nametext == "route.js" or \
nametext == "route.txt") and (nlines != None): nametext == "route.txt") and (nlines != None):
nalllines = len(textEditor[i].asLines()) nalllines = len(textEditor[i].asLines())
alllines = textEditor[i].asLines() alllines = textEditor[i].asLines()
for j in range(nalllines): for j in xrange(nalllines):
self.writeIndented(alllines[j] + "\n") self.writeIndented(alllines[j] + "\n")
self.writeIndented("\n") self.writeIndented("\n")
@ -449,8 +449,9 @@ class VRML2Export:
# (as a non-face property) and if first material has # (as a non-face property) and if first material has
# vcol paint set, we export the vertex colors # vcol paint set, we export the vertex colors
if (me.vertexColors): if (me.vertexColors):
if len(me.materials) > 0: materials = [m for m in me.materials if m]
mat = me.materials[0] if len(materials) > 0:
mat = materials[0]
if mat: if mat:
if (mat.mode & Blender.Material.Modes['VCOL_PAINT']): if (mat.mode & Blender.Material.Modes['VCOL_PAINT']):
self.vcolors = 1 self.vcolors = 1
@ -554,7 +555,7 @@ class VRML2Export:
issmooth = 0 issmooth = 0
maters = me.materials maters = me.materials
nummats = self.getNumMaterials(me) nummats = len([m for m in maters if m])
# Vertex and Face colors trump materials and image textures # Vertex and Face colors trump materials and image textures
if (self.facecolors or self.vcolors): if (self.facecolors or self.vcolors):
@ -567,18 +568,18 @@ class VRML2Export:
self.writeShape(ob, me, -1, None) self.writeShape(ob, me, -1, None)
# Do meshes with materials, possible with image textures # Do meshes with materials, possible with image textures
elif nummats > 0: elif nummats > 0:
for matnum in range(len(maters)): for matnum in xrange(len(maters)):
if maters[matnum]: images = []
images = [] if me.faceUV:
if me.faceUV: images = self.getImages(me, matnum)
images = self.getImages(me, matnum) if len(images) > 0:
if len(images) > 0: for image in images:
for image in images: self.writeShape(ob, me, matnum, image)
self.writeShape(ob, me, matnum, image)
else:
self.writeShape(ob, me, matnum, None)
else: else:
self.writeShape(ob, me, matnum, None) self.writeShape(ob, me, matnum, None)
else:
self.writeShape(ob, me, matnum, None)
else: else:
if me.faceUV: if me.faceUV:
images = self.getImages(me, -1) images = self.getImages(me, -1)
@ -596,25 +597,29 @@ class VRML2Export:
def getImages(self, me, matnum): def getImages(self, me, matnum):
imageNames = {} imageNames = {}
images = [] images = {} # make a dict to avoid dealing with images too often.
for face in me.faces: if matnum == -1:
if (matnum == -1) or (face.mat == matnum): for face in me.faces:
if (face.image): img = face.image
imName = self.cleanStr(face.image.name) if img:
if not imageNames.has_key(imName): images[img] = img # key is a dummy
images.append(face.image) else:
imageNames[imName]=1 for face in me.faces:
if face.mat == matnum:
img = face.image
if img:
images[img] = img # key is a dummy
images = images.values()
for image in images:
imName = self.cleanStr(image.name)
if not imageNames.has_key(imName):
images.append(image)
imageNames[imName]=1
return images 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): def writeCoordinates(self, me, meshName):
coordName = "coord_%s" % (meshName) coordName = "coord_%s" % (meshName)
# look up coord name, use it if available # look up coord name, use it if available
@ -649,10 +654,11 @@ class VRML2Export:
self.writeIndented("appearance Appearance {\n", 1) self.writeIndented("appearance Appearance {\n", 1)
if (matnum != -1): if (matnum != -1):
mater = me.materials[matnum] mater = me.materials[matnum]
self.writeMaterial(mater, self.cleanStr(mater.name,'')) if mater:
if (mater.mode & Blender.Material.Modes['TEXFACE']): self.writeMaterial(mater, self.cleanStr(mater.name,''))
if image != None: if (mater.mode & Blender.Material.Modes['TEXFACE']):
self.writeImageTexture(image.name, image.filename) if image != None:
self.writeImageTexture(image.name, image.filename)
else: else:
if image != None: if image != None:
self.writeImageTexture(image.name, image.filename) self.writeImageTexture(image.name, image.filename)
@ -698,11 +704,17 @@ class VRML2Export:
for face in me.faces: for face in me.faces:
if (matnum == -1) or (face.mat == matnum): if (matnum == -1) or (face.mat == matnum):
if (image == None) or (face.image == image): if (image == None) or (face.image == image):
cordStr="" fv = face.v
for v in face.verts:
indx=v.index if len(face)==3:
cordStr = cordStr + "%s " % indx self.file.write("%i %i %i -1, " % (fv[0].index, fv[1].index, fv[2].index))
self.writeUnindented(cordStr + "-1, \n") else:
#if EXPORT_TRI:
# self.file.write("%i %i %i -1, " % (fv[0].index, fv[1].index, fv[2].index))
# self.file.write("%i %i %i -1, " % (fv[0].index, fv[2].index, fv[3].index))
#else:
self.file.write("%i %i %i %i -1, " % (fv[0].index, fv[1].index, fv[2].index, fv[3].index))
self.writeIndented("]\n", -1) self.writeIndented("]\n", -1)
def writeTextureCoordinates(self, me, meshName, matnum, image): def writeTextureCoordinates(self, me, meshName, matnum, image):
@ -718,7 +730,7 @@ class VRML2Export:
indexStr = "" indexStr = ""
if (matnum == -1) or (face.mat == matnum): if (matnum == -1) or (face.mat == matnum):
if (face.image == image): if (face.image == image):
for i in range(len(face.verts)): for i in xrange(len(face.verts)):
uv = face.uv[i] uv = face.uv[i]
indexStr += "%s " % (j) indexStr += "%s " % (j)
coordStr += "%s %s, " % \ coordStr += "%s %s, " % \
@ -1217,7 +1229,7 @@ def select_file(filename):
######################################################### #########################################################
export_selection_only = Draw.Create(0) export_selection_only = Draw.Create(0)
export_rotate_z_to_y = Draw.Create(0) export_rotate_z_to_y = Draw.Create(1)
export_compressed = Draw.Create(0) export_compressed = Draw.Create(0)
def save_to_registry(): def save_to_registry():