OBJ smooting groups exported enabled for by default for the first smooth group (should have been disabled)
gen_library.c - Own error, hashing did not decref the tuple it created. Draw.c - callback also missed a decref
This commit is contained in:
@@ -68,15 +68,11 @@ def fixName(name):
|
|||||||
else:
|
else:
|
||||||
return name.replace(' ', '_')
|
return name.replace(' ', '_')
|
||||||
|
|
||||||
# Used to add the scene name into the filename without using odd chars
|
|
||||||
global MTL_DICT
|
|
||||||
|
|
||||||
# A Dict of Materials
|
# A Dict of Materials
|
||||||
# (material.name, image.name):matname_imagename # matname_imagename has gaps removed.
|
# (material.name, image.name):matname_imagename # matname_imagename has gaps removed.
|
||||||
MTL_DICT = {}
|
MTL_DICT = {}
|
||||||
|
|
||||||
def write_mtl(filename):
|
def write_mtl(filename):
|
||||||
global MTL_DICT
|
|
||||||
|
|
||||||
world = Blender.World.GetCurrent()
|
world = Blender.World.GetCurrent()
|
||||||
if world:
|
if world:
|
||||||
@@ -88,23 +84,14 @@ def write_mtl(filename):
|
|||||||
file.write('# Blender3D MTL File: %s\n' % Blender.Get('filename').split('\\')[-1].split('/')[-1])
|
file.write('# Blender3D MTL File: %s\n' % Blender.Get('filename').split('\\')[-1].split('/')[-1])
|
||||||
file.write('# Material Count: %i\n' % len(MTL_DICT))
|
file.write('# Material Count: %i\n' % len(MTL_DICT))
|
||||||
# Write material/image combinations we have used.
|
# Write material/image combinations we have used.
|
||||||
for key, mtl_mat_name in MTL_DICT.iteritems():
|
for key, (mtl_mat_name, mat, img) in MTL_DICT.iteritems():
|
||||||
|
|
||||||
# Get the Blender data for the material and the image.
|
# Get the Blender data for the material and the image.
|
||||||
# Having an image named None will make a bug, dont do it :)
|
# Having an image named None will make a bug, dont do it :)
|
||||||
|
|
||||||
file.write('newmtl %s\n' % mtl_mat_name) # Define a new material: matname_imgname
|
file.write('newmtl %s\n' % mtl_mat_name) # Define a new material: matname_imgname
|
||||||
|
|
||||||
if key[0] == None:
|
if mat:
|
||||||
#write a dummy material here?
|
|
||||||
file.write('Ns 0\n')
|
|
||||||
file.write('Ka %.6f %.6f %.6f\n' % tuple([c for c in worldAmb]) ) # Ambient, uses mirror colour,
|
|
||||||
file.write('Kd 0.8 0.8 0.8\n')
|
|
||||||
file.write('Ks 0.8 0.8 0.8\n')
|
|
||||||
file.write('d 1\n') # No alpha
|
|
||||||
file.write('illum 2\n') # light normaly
|
|
||||||
else:
|
|
||||||
mat = Blender.Material.Get(key[0])
|
|
||||||
file.write('Ns %.6f\n' % ((mat.getHardness()-1) * 1.9607843137254901) ) # Hardness, convert blenders 1-511 to MTL's
|
file.write('Ns %.6f\n' % ((mat.getHardness()-1) * 1.9607843137254901) ) # Hardness, convert blenders 1-511 to MTL's
|
||||||
file.write('Ka %.6f %.6f %.6f\n' % tuple([c*mat.amb for c in worldAmb]) ) # Ambient, uses mirror colour,
|
file.write('Ka %.6f %.6f %.6f\n' % tuple([c*mat.amb for c in worldAmb]) ) # Ambient, uses mirror colour,
|
||||||
file.write('Kd %.6f %.6f %.6f\n' % tuple([c*mat.ref for c in mat.rgbCol]) ) # Diffuse
|
file.write('Kd %.6f %.6f %.6f\n' % tuple([c*mat.ref for c in mat.rgbCol]) ) # Diffuse
|
||||||
@@ -120,13 +107,20 @@ def write_mtl(filename):
|
|||||||
else:
|
else:
|
||||||
file.write('illum 2\n') # light normaly
|
file.write('illum 2\n') # light normaly
|
||||||
|
|
||||||
|
else:
|
||||||
|
#write a dummy material here?
|
||||||
|
file.write('Ns 0\n')
|
||||||
|
file.write('Ka %.6f %.6f %.6f\n' % tuple([c for c in worldAmb]) ) # Ambient, uses mirror colour,
|
||||||
|
file.write('Kd 0.8 0.8 0.8\n')
|
||||||
|
file.write('Ks 0.8 0.8 0.8\n')
|
||||||
|
file.write('d 1\n') # No alpha
|
||||||
|
file.write('illum 2\n') # light normaly
|
||||||
|
|
||||||
# Write images!
|
# Write images!
|
||||||
if key[1] != None: # We have an image on the face!
|
if img: # We have an image on the face!
|
||||||
img = Image.Get(key[1])
|
|
||||||
file.write('map_Kd %s\n' % img.filename.split('\\')[-1].split('/')[-1]) # Diffuse mapping image
|
file.write('map_Kd %s\n' % img.filename.split('\\')[-1].split('/')[-1]) # Diffuse mapping image
|
||||||
|
|
||||||
elif key[0] != None: # No face image. if we havea material search for MTex image.
|
elif not mat: # No face image. if we havea material search for MTex image.
|
||||||
for mtex in mat.getTextures():
|
for mtex in mat.getTextures():
|
||||||
if mtex and mtex.tex.type == Blender.Texture.Types.IMAGE:
|
if mtex and mtex.tex.type == Blender.Texture.Types.IMAGE:
|
||||||
try:
|
try:
|
||||||
@@ -157,26 +151,26 @@ def copy_images(dest_dir):
|
|||||||
|
|
||||||
# Get unique image names
|
# Get unique image names
|
||||||
uniqueImages = {}
|
uniqueImages = {}
|
||||||
for matname, imagename in MTL_DICT.iterkeys(): # Only use image name
|
for matname, mat, image in MTL_DICT.itervalues(): # Only use image name
|
||||||
# Get Texface images
|
# Get Texface images
|
||||||
if imagename != None:
|
if image:
|
||||||
uniqueImages[imagename] = None # Should use sets here. wait until Python 2.4 is default.
|
uniqueImages[image] = image # Should use sets here. wait until Python 2.4 is default.
|
||||||
|
|
||||||
# Get MTex images
|
# Get MTex images
|
||||||
if matname != None:
|
if mat:
|
||||||
mat= Blender.Material.Get(matname)
|
|
||||||
for mtex in mat.getTextures():
|
for mtex in mat.getTextures():
|
||||||
if mtex and mtex.tex.type == Blender.Texture.Types.IMAGE:
|
if mtex and mtex.tex.type == Blender.Texture.Types.IMAGE:
|
||||||
try:
|
image_tex = mtex.tex.image
|
||||||
uniqueImages[mtex.tex.image.name] = None
|
if image_tex:
|
||||||
except:
|
try:
|
||||||
pass
|
uniqueImages[image_tex] = image_tex
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# Now copy images
|
# Now copy images
|
||||||
copyCount = 0
|
copyCount = 0
|
||||||
|
|
||||||
for imageName in uniqueImages.iterkeys():
|
for bImage in uniqueImages.itervalues():
|
||||||
bImage = Image.Get(imageName)
|
|
||||||
image_path = sys.expandpath(bImage.filename)
|
image_path = sys.expandpath(bImage.filename)
|
||||||
if sys.exists(image_path):
|
if sys.exists(image_path):
|
||||||
# Make a name for the target path.
|
# Make a name for the target path.
|
||||||
@@ -187,12 +181,6 @@ def copy_images(dest_dir):
|
|||||||
copyCount+=1
|
copyCount+=1
|
||||||
print '\tCopied %d images' % copyCount
|
print '\tCopied %d images' % copyCount
|
||||||
|
|
||||||
def veckey3d(v):
|
|
||||||
return round(v.x, 6), round(v.y, 6), round(v.z, 6)
|
|
||||||
|
|
||||||
def veckey2d(v):
|
|
||||||
return round(v.x, 6), round(v.y, 6)
|
|
||||||
|
|
||||||
def write(filename, objects,\
|
def write(filename, objects,\
|
||||||
EXPORT_TRI=False, EXPORT_EDGES=False, EXPORT_NORMALS=False, EXPORT_NORMALS_HQ=False,\
|
EXPORT_TRI=False, EXPORT_EDGES=False, EXPORT_NORMALS=False, EXPORT_NORMALS_HQ=False,\
|
||||||
EXPORT_UV=True, EXPORT_MTL=True, EXPORT_COPY_IMAGES=False,\
|
EXPORT_UV=True, EXPORT_MTL=True, EXPORT_COPY_IMAGES=False,\
|
||||||
@@ -204,8 +192,14 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False, EXPORT_MORPH_TARGET=False)
|
|||||||
eg.
|
eg.
|
||||||
write( 'c:\\test\\foobar.obj', Blender.Object.GetSelected() ) # Using default options.
|
write( 'c:\\test\\foobar.obj', Blender.Object.GetSelected() ) # Using default options.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
def veckey3d(v):
|
||||||
|
return round(v.x, 6), round(v.y, 6), round(v.z, 6)
|
||||||
|
|
||||||
|
#def veckey2d(v):
|
||||||
|
# return round(v.x, 6), round(v.y, 6)
|
||||||
|
|
||||||
print 'OBJ Export path: "%s"' % filename
|
print 'OBJ Export path: "%s"' % filename
|
||||||
global MTL_DICT
|
|
||||||
temp_mesh_name = '~tmp-mesh'
|
temp_mesh_name = '~tmp-mesh'
|
||||||
|
|
||||||
time1 = sys.time()
|
time1 = sys.time()
|
||||||
@@ -301,6 +295,7 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False, EXPORT_MORPH_TARGET=False)
|
|||||||
materials = me.materials
|
materials = me.materials
|
||||||
|
|
||||||
materialNames = []
|
materialNames = []
|
||||||
|
materialItems = materials[:]
|
||||||
if materials:
|
if materials:
|
||||||
for mat in materials:
|
for mat in materials:
|
||||||
if mat: # !=None
|
if mat: # !=None
|
||||||
@@ -313,7 +308,7 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False, EXPORT_MORPH_TARGET=False)
|
|||||||
# 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.
|
||||||
materialNames.extend((16-len(materialNames)) * [None])
|
materialNames.extend((16-len(materialNames)) * [None])
|
||||||
|
materialItems.extend((16-len(materialItems)) * [None])
|
||||||
|
|
||||||
# Sort by Material, then images
|
# Sort by Material, then images
|
||||||
# so we dont over context switch in the obj file.
|
# so we dont over context switch in the obj file.
|
||||||
@@ -375,19 +370,22 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False, EXPORT_MORPH_TARGET=False)
|
|||||||
globalNormals[noKey] = totno
|
globalNormals[noKey] = totno
|
||||||
totno +=1
|
totno +=1
|
||||||
file.write('vn %.6f %.6f %.6f\n' % noKey)
|
file.write('vn %.6f %.6f %.6f\n' % noKey)
|
||||||
|
if not faceuv:
|
||||||
|
f_image = None
|
||||||
|
|
||||||
for f in faces:
|
for f in faces:
|
||||||
f_v= f.v
|
f_v= f.v
|
||||||
|
f_smooth= f.smooth
|
||||||
|
f_mat = min(f.mat, len(materialNames)-1)
|
||||||
if faceuv:
|
if faceuv:
|
||||||
|
f_image = f.image
|
||||||
f_uv= f.uv
|
f_uv= f.uv
|
||||||
|
|
||||||
# MAKE KEY
|
# MAKE KEY
|
||||||
if EXPORT_UV and faceuv and f.image: # Object is always true.
|
if EXPORT_UV and faceuv and f_image: # Object is always true.
|
||||||
key = materialNames[min(f.mat,len(materialNames)-1)], f.image.name
|
key = materialNames[f_mat], f_image.name
|
||||||
#key = materialNames[f.mat], f.image.name
|
|
||||||
else:
|
else:
|
||||||
key = materialNames[min(f.mat,len(materialNames)-1)], None # No image, use None instead.
|
key = materialNames[f_mat], None # No image, use None instead.
|
||||||
#key = materialNames[f.mat], None # No image, use None instead.
|
|
||||||
|
|
||||||
# CHECK FOR CONTEXT SWITCH
|
# CHECK FOR CONTEXT SWITCH
|
||||||
if key == contextMat:
|
if key == contextMat:
|
||||||
@@ -395,16 +393,13 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False, EXPORT_MORPH_TARGET=False)
|
|||||||
else:
|
else:
|
||||||
if key[0] == None and key[1] == None:
|
if key[0] == None and key[1] == None:
|
||||||
# Write a null material, since we know the context has changed.
|
# Write a null material, since we know the context has changed.
|
||||||
matstring = '(null)'
|
if EXPORT_GROUP_BY_MAT:
|
||||||
|
file.write('g %s_%s\n' % (fixName(ob.name), fixName(ob.getData(1))) ) # can be mat_image or (null)
|
||||||
file.write('usemtl (null)\n') # mat, image
|
file.write('usemtl (null)\n') # mat, image
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try: # Faster to try then 2x dict lookups.
|
mat_data= MTL_DICT.get(key)
|
||||||
# We have the material, just need to write the context switch,
|
if not mat_data:
|
||||||
matstring = MTL_DICT[key]
|
|
||||||
|
|
||||||
|
|
||||||
except KeyError:
|
|
||||||
# First add to global dict so we can export to mtl
|
# First add to global dict so we can export to mtl
|
||||||
# Then write mtl
|
# Then write mtl
|
||||||
|
|
||||||
@@ -413,28 +408,27 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False, EXPORT_MORPH_TARGET=False)
|
|||||||
|
|
||||||
# If none image dont bother adding it to the name
|
# If none image dont bother adding it to the name
|
||||||
if key[1] == None:
|
if key[1] == None:
|
||||||
matstring = MTL_DICT[key] ='%s' % fixName(key[0])
|
mat_data = MTL_DICT[key] = ('%s'%fixName(key[0])), materialItems[f_mat], f_image
|
||||||
else:
|
else:
|
||||||
matstring = MTL_DICT[key] = '%s_%s' % (fixName(key[0]), fixName(key[1]))
|
mat_data = MTL_DICT[key] = ('%s_%s' % (fixName(key[0]), fixName(key[1]))), materialItems[f_mat], f_image
|
||||||
|
|
||||||
if EXPORT_GROUP_BY_MAT:
|
if EXPORT_GROUP_BY_MAT:
|
||||||
file.write('g %s_%s_%s\n' % (fixName(ob.name), fixName(ob.getData(1)), matstring) ) # can be mat_image or (null)
|
file.write('g %s_%s_%s\n' % (fixName(ob.name), fixName(ob.getData(1)), mat_data[0]) ) # can be mat_image or (null)
|
||||||
file.write('usemtl %s\n' % matstring) # can be mat_image or (null)
|
file.write('usemtl %s\n' % mat_data[0]) # can be mat_image or (null)
|
||||||
|
|
||||||
contextMat = key
|
contextMat = key
|
||||||
|
if f_smooth != contextSmooth:
|
||||||
if f.smooth != contextSmooth:
|
if f_smooth: # on now off
|
||||||
if contextSmooth: # on now off
|
|
||||||
file.write('s off\n')
|
|
||||||
contextSmooth = True
|
|
||||||
else: # was off now on
|
|
||||||
file.write('s 1\n')
|
file.write('s 1\n')
|
||||||
contextSmooth = False
|
contextSmooth = f_smooth
|
||||||
|
else: # was off now on
|
||||||
|
file.write('s off\n')
|
||||||
|
contextSmooth = f_smooth
|
||||||
|
|
||||||
file.write('f')
|
file.write('f')
|
||||||
if faceuv and EXPORT_UV:
|
if faceuv and EXPORT_UV:
|
||||||
if EXPORT_NORMALS:
|
if EXPORT_NORMALS:
|
||||||
if f.smooth: # Smoothed, use vertex normals
|
if f_smooth: # Smoothed, use vertex normals
|
||||||
for vi, v in enumerate(f_v):
|
for vi, v in enumerate(f_v):
|
||||||
file.write( ' %d/%d/%d' % (\
|
file.write( ' %d/%d/%d' % (\
|
||||||
v.index+totverts,\
|
v.index+totverts,\
|
||||||
@@ -459,7 +453,7 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False, EXPORT_MORPH_TARGET=False)
|
|||||||
|
|
||||||
else: # No UV's
|
else: # No UV's
|
||||||
if EXPORT_NORMALS:
|
if EXPORT_NORMALS:
|
||||||
if f.smooth: # Smoothed, use vertex normals
|
if f_smooth: # Smoothed, use vertex normals
|
||||||
for v in f_v:
|
for v in f_v:
|
||||||
file.write( ' %d//%d' % (\
|
file.write( ' %d//%d' % (\
|
||||||
v.index+totverts,\
|
v.index+totverts,\
|
||||||
@@ -515,7 +509,6 @@ def write_ui(filename):
|
|||||||
#if not BPyMessages.Warning_SaveOver(filename):
|
#if not BPyMessages.Warning_SaveOver(filename):
|
||||||
# return
|
# return
|
||||||
|
|
||||||
|
|
||||||
EXPORT_APPLY_MODIFIERS = Draw.Create(1)
|
EXPORT_APPLY_MODIFIERS = Draw.Create(1)
|
||||||
EXPORT_ROTX90 = Draw.Create(1)
|
EXPORT_ROTX90 = Draw.Create(1)
|
||||||
EXPORT_TRI = Draw.Create(0)
|
EXPORT_TRI = Draw.Create(0)
|
||||||
@@ -535,7 +528,6 @@ def write_ui(filename):
|
|||||||
|
|
||||||
# removed too many options are bad!
|
# removed too many options are bad!
|
||||||
|
|
||||||
|
|
||||||
# Get USER Options
|
# Get USER Options
|
||||||
pup_block = [\
|
pup_block = [\
|
||||||
('Context...'),\
|
('Context...'),\
|
||||||
|
|||||||
@@ -740,7 +740,7 @@ static void exec_but_callback(void *pyobj, void *data)
|
|||||||
PyObject *result;
|
PyObject *result;
|
||||||
PyObject * pyvalue;
|
PyObject * pyvalue;
|
||||||
uiBut *but = (uiBut *)data;
|
uiBut *but = (uiBut *)data;
|
||||||
PyObject *arg = PyTuple_New( 2 );
|
PyObject *arg;
|
||||||
PyObject *callback = (PyObject *)pyobj;
|
PyObject *callback = (PyObject *)pyobj;
|
||||||
|
|
||||||
double value = ui_get_but_val(but);
|
double value = ui_get_but_val(but);
|
||||||
@@ -795,6 +795,7 @@ static void exec_but_callback(void *pyobj, void *data)
|
|||||||
printf("Error, no button type matched.");
|
printf("Error, no button type matched.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
arg = PyTuple_New( 2 );
|
||||||
if (uiblock==NULL)
|
if (uiblock==NULL)
|
||||||
PyTuple_SetItem( arg, 0, PyInt_FromLong(but->retval - EXPP_BUTTON_EVENTS_OFFSET) );
|
PyTuple_SetItem( arg, 0, PyInt_FromLong(but->retval - EXPP_BUTTON_EVENTS_OFFSET) );
|
||||||
else
|
else
|
||||||
@@ -803,6 +804,8 @@ static void exec_but_callback(void *pyobj, void *data)
|
|||||||
PyTuple_SetItem( arg, 1, pyvalue );
|
PyTuple_SetItem( arg, 1, pyvalue );
|
||||||
|
|
||||||
result = PyObject_CallObject( callback, arg );
|
result = PyObject_CallObject( callback, arg );
|
||||||
|
Py_DECREF(arg);
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Py_DECREF(pyvalue);
|
Py_DECREF(pyvalue);
|
||||||
PyErr_Print( );
|
PyErr_Print( );
|
||||||
|
|||||||
@@ -330,9 +330,12 @@ long GenericLib_hash(PyObject * pydata)
|
|||||||
{
|
{
|
||||||
ID *id = ((BPy_GenericLib *)pydata)->id;
|
ID *id = ((BPy_GenericLib *)pydata)->id;
|
||||||
PyObject *pyhash = PyTuple_New( 2 );
|
PyObject *pyhash = PyTuple_New( 2 );
|
||||||
|
long hash;
|
||||||
PyTuple_SetItem( pyhash, 0, PyString_FromString(id->name) );
|
PyTuple_SetItem( pyhash, 0, PyString_FromString(id->name) );
|
||||||
if (id->lib) PyTuple_SetItem( pyhash, 0, PyString_FromString(id->lib->name) );
|
if (id->lib) PyTuple_SetItem( pyhash, 1, PyString_FromString(id->lib->name) );
|
||||||
else PyTuple_SetItem( pyhash, 1, Py_None );
|
else PyTuple_SetItem( pyhash, 1, EXPP_incr_ret(Py_None) );
|
||||||
return PyObject_Hash(pyhash);
|
hash = PyObject_Hash(pyhash);
|
||||||
|
Py_DECREF(pyhash);
|
||||||
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user