Fixed a but where applying the modifier option was disabled, Meshes woudl have there objects matricies applied.

(Now always work on copied data- Blender.Mesh could do with a copy function)
Now triangulate works without "Apply Modifiers" enabled.

Much thanks to Gianluca Faletti for helping me track down the problem.
This commit is contained in:
Campbell Barton 2006-04-03 16:14:24 +00:00
parent 36f498aae0
commit e9a9caee4c

@ -70,7 +70,8 @@ def saneFilechars(name):
def sortPair(a,b): def sortPair(a,b):
return min(a,b), max(a,b) return min(a,b), max(a,b)
def getMeshFromObject(object, name=None, mesh=None): def getMeshFromObject(scn, ob, name=None, mesh=None, EXPORT_APPLY_MODIFIERS=True):
if mesh: if mesh:
mesh.verts = None # Clear the mesh mesh.verts = None # Clear the mesh
else: else:
@ -80,13 +81,25 @@ def getMeshFromObject(object, name=None, mesh=None):
mesh = Mesh.New(name) mesh = Mesh.New(name)
type = object.getType() type = ob.getType()
dataname = object.getData(1) dataname = ob.getData(1)
try: if EXPORT_APPLY_MODIFIERS:
mesh.getFromObject(object.name) try:
except: mesh.getFromObject(ob.name)
return None except:
return None
else:
'''
Dont apply modifiers, copy the mesh.
So we can transform the data. its easiest just to get a copy of the mesh.
'''
tempob= Blender.Object.New('Mesh')
tempob.shareFrom(ob)
scn.link(tempob)
mesh.getFromObject(tempob.name)
scn.unlink(tempob)
if type == 'Mesh': if type == 'Mesh':
tempMe = Mesh.Get( dataname ) tempMe = Mesh.Get( dataname )
@ -102,7 +115,7 @@ def getMeshFromObject(object, name=None, mesh=None):
# Surf- no python interface # Surf- no python interface
# MBall- no material access in python interface. # MBall- no material access in python interface.
data = object.getData() data = ob.getData()
materials = data.getMaterials() materials = data.getMaterials()
mesh.materials = materials mesh.materials = materials
print 'assigning materials for non mesh' print 'assigning materials for non mesh'
@ -234,6 +247,7 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False):
print 'OBJ Export path: "%s"' % filename print 'OBJ Export path: "%s"' % filename
global MTL_DICT global MTL_DICT
temp_mesh_name = '~tmp-mesh' temp_mesh_name = '~tmp-mesh'
time1 = sys.time() time1 = sys.time()
scn = Scene.GetCurrent() scn = Scene.GetCurrent()
@ -271,33 +285,32 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False):
for ob in objects: for ob in objects:
# Will work for non meshes now! :) # Will work for non meshes now! :)
if EXPORT_APPLY_MODIFIERS or ob.getType() != 'Mesh': m = getMeshFromObject(scn, ob, temp_mesh_name, containerMesh, EXPORT_APPLY_MODIFIERS)
m = getMeshFromObject(ob, temp_mesh_name, containerMesh) if not m:
if not m: continue
continue
# We have a valid mesh
if EXPORT_TRI:
# Add a dummy object to it.
oldmode = Mesh.Mode()
Mesh.Mode(Mesh.SelectModes['FACE'])
quadcount = 0
for f in m.faces:
if len(f.v) == 4:
f.sel = 1
quadcount +=1
# We have a valid mesh if quadcount:
if m and EXPORT_APPLY_MODIFIERS and EXPORT_TRI: tempob = Blender.Object.New('Mesh')
# Add a dummy object to it. tempob.link(m)
oldmode = Mesh.Mode() scn.link(tempob)
Mesh.Mode(Mesh.SelectModes['FACE']) m.quadToTriangle(0) # more=0 shortest length
quadcount = 0 oldmode = Mesh.Mode(oldmode)
for f in m.faces: scn.unlink(tempob)
if len(f.v) == 4: Mesh.Mode(oldmode)
f.sel = 1
quadcount +=1
if quadcount:
tempob = Blender.Object.New('Mesh')
tempob.link(m)
scn.link(tempob)
m.quadToTriangle(0) # more=0 shortest length
oldmode = Mesh.Mode(oldmode)
scn.unlink(tempob)
Mesh.Mode(oldmode)
else: # We are a mesh. get the data.
m = ob.getData(mesh=1)
faces = [ f for f in m.faces ] faces = [ f for f in m.faces ]
if EXPORT_EDGES: if EXPORT_EDGES:
@ -323,8 +336,6 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False):
materialNames.append(None) materialNames.append(None)
# Cant use LC because some materials are None. # Cant use LC because some materials are None.
# materialNames = map(lambda mat: mat.name, materials) # Bug Blender, dosent account for null materials, still broken. # materialNames = map(lambda mat: mat.name, materials) # Bug Blender, dosent account for null materials, still broken.
else:
materialNames = []
# Possible there null materials, will mess up indicies # Possible there null materials, will mess up indicies
# but at least it will export, wait until Blender gets fixed. # but at least it will export, wait until Blender gets fixed.
@ -350,7 +361,6 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False):
else: # if EXPORT_GROUP_BY_OB: else: # if EXPORT_GROUP_BY_OB:
file.write('g %s\n' % obnamestring) file.write('g %s\n' % obnamestring)
# Vert # Vert
for v in m.verts: for v in m.verts:
file.write('v %.6f %.6f %.6f\n' % tuple(v.co)) file.write('v %.6f %.6f %.6f\n' % tuple(v.co))
@ -543,7 +553,7 @@ def write_ui(filename):
pup_block = [\ pup_block = [\
('Mesh Options...'),\ ('Mesh Options...'),\
('Apply Modifiers', EXPORT_APPLY_MODIFIERS, 'Use transformed mesh data from each object. May break vert order for morph targets.'),\ ('Apply Modifiers', EXPORT_APPLY_MODIFIERS, 'Use transformed mesh data from each object. May break vert order for morph targets.'),\
('Triangulate', EXPORT_TRI, 'Triangulate quads (Depends on "Apply Modifiers").'),\ ('Triangulate', EXPORT_TRI, 'Triangulate quadsModifiers.'),\
('Edges', EXPORT_EDGES, 'Edges not connected to faces.'),\ ('Edges', EXPORT_EDGES, 'Edges not connected to faces.'),\
('Normals', EXPORT_NORMALS, 'Export vertex normal data (Ignored on import).'),\ ('Normals', EXPORT_NORMALS, 'Export vertex normal data (Ignored on import).'),\
('UVs', EXPORT_UV, 'Export texface UV coords.'),\ ('UVs', EXPORT_UV, 'Export texface UV coords.'),\