forked from bartvdbraak/blender
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:
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,14 +81,26 @@ 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)
|
||||||
|
|
||||||
|
if EXPORT_APPLY_MODIFIERS:
|
||||||
try:
|
try:
|
||||||
mesh.getFromObject(object.name)
|
mesh.getFromObject(ob.name)
|
||||||
except:
|
except:
|
||||||
return None
|
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 )
|
||||||
mesh.materials = tempMe.materials
|
mesh.materials = tempMe.materials
|
||||||
@ -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,13 +285,12 @@ 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
|
# We have a valid mesh
|
||||||
if m and EXPORT_APPLY_MODIFIERS and EXPORT_TRI:
|
if EXPORT_TRI:
|
||||||
# Add a dummy object to it.
|
# Add a dummy object to it.
|
||||||
oldmode = Mesh.Mode()
|
oldmode = Mesh.Mode()
|
||||||
Mesh.Mode(Mesh.SelectModes['FACE'])
|
Mesh.Mode(Mesh.SelectModes['FACE'])
|
||||||
@ -296,8 +309,8 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False):
|
|||||||
scn.unlink(tempob)
|
scn.unlink(tempob)
|
||||||
Mesh.Mode(oldmode)
|
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.'),\
|
||||||
|
Loading…
Reference in New Issue
Block a user