python api: rna array slices now return tuples rather then lists (fits with recent change made to mathutils).

minor improvements/cleanup to exporters.
This commit is contained in:
2011-01-02 09:54:44 +00:00
parent a6a2512f47
commit f101e59e09
5 changed files with 34 additions and 56 deletions

View File

@@ -110,7 +110,6 @@ def sane_name(name):
def uv_key(uv):
return round(uv[0], 6), round(uv[1], 6)
# return round(uv.x, 6), round(uv.y, 6)
# size defines:
SZ_SHORT = 2

View File

@@ -542,7 +542,7 @@ def save(operator, context, filepath="",
print('\nFBX export starting... %r' % filepath)
start_time = time.clock()
try:
file = open(filepath, 'w')
file = open(filepath, 'w', encoding='utf8')
except:
return False
@@ -1636,13 +1636,13 @@ def save(operator, context, filepath="",
# workaround, since uf.uv iteration is wrong atm
for uv in uf.uv:
if i==-1:
file.write('%.6f,%.6f' % tuple(uv))
file.write('%.6f,%.6f' % uv[:])
i=0
else:
if i==7:
file.write('\n\t\t\t ')
i=0
file.write(',%.6f,%.6f' % tuple(uv))
file.write(',%.6f,%.6f' % uv[:])
i+=1
ii+=1 # One more UV

View File

@@ -59,9 +59,8 @@ def write_mtl(scene, filepath, copy_images, mtl_dict):
return rel
file = open(filepath, "w")
# XXX
# file.write('# Blender MTL File: %s\n' % Blender.Get('filepath').split('\\')[-1].split('/')[-1])
file = open(filepath, "w", encoding='utf8')
file.write('# Blender MTL File: %r\n' % os.path.basename(bpy.data.filepath))
file.write('# Material Count: %i\n' % len(mtl_dict))
# Write material/image combinations we have used.
for key, (mtl_mat_name, mat, img) in mtl_dict.items():
@@ -137,8 +136,6 @@ def copy_file(source, dest):
def copy_images(dest_dir):
if dest_dir[-1] != os.sep:
dest_dir += os.sep
# if dest_dir[-1] != sys.sep:
# dest_dir += sys.sep
# Get unique image names
uniqueImages = {}
@@ -284,7 +281,6 @@ def write_file(filepath, objects, scene,
def veckey2d(v):
return round(v[0], 6), round(v[1], 6)
# return round(v.x, 6), round(v.y, 6)
def findVertexGroupName(face, vWeightMap):
"""
@@ -503,7 +499,7 @@ def write_file(filepath, objects, scene,
uv_face_mapping[f_index][uv_index] = uv_dict[uvkey]
except:
uv_face_mapping[f_index][uv_index] = uv_dict[uvkey] = len(uv_dict)
file.write('vt %.6f %.6f\n' % tuple(uv))
file.write('vt %.6f %.6f\n' % uv[:])
uv_unique_count = len(uv_dict)
# del uv, uvkey, uv_dict, f_index, uv_index
@@ -546,18 +542,10 @@ def write_file(filepath, objects, scene,
for f, f_index in face_index_pairs:
f_smooth= f.use_smooth
f_mat = min(f.material_index, len(materialNames)-1)
# f_mat = min(f.mat, len(materialNames)-1)
if faceuv:
tface = uv_layer[f_index]
f_image = tface.image
f_uv = tface.uv
# f_uv= [tface.uv1, tface.uv2, tface.uv3]
# if len(f.vertices) == 4:
# f_uv.append(tface.uv4)
# f_image = f.image
# f_uv= f.uv
# MAKE KEY
if faceuv and f_image: # Object is always true.

View File

@@ -95,7 +95,7 @@ class x3d_class:
self.filepath = filepath[:-1] # remove trailing z
if self.file is None:
self.file = open(self.filepath, "w")
self.file = open(self.filepath, "w", encoding='utf8')
self.bNav=0
self.nodeID=0
@@ -537,37 +537,28 @@ class x3d_class:
self.writeIndented("\n", -1)
def writeTextureCoordinates(self, mesh):
texCoordList=[]
texIndexList=[]
j=0
for face in mesh.uv_textures.active.data:
# for face in mesh.faces:
# workaround, since tface.uv iteration is wrong atm
uvs = face.uv
# uvs = [face.uv1, face.uv2, face.uv3, face.uv4] if face.vertices[3] else [face.uv1, face.uv2, face.uv3]
for uv in uvs:
# for uv in face.uv:
texIndexList.append(j)
texCoordList.append(uv)
j=j+1
texIndexList.append(-1)
if self.writingtexture == 0:
self.file.write("\n\t\t\ttexCoordIndex=\"")
texIndxStr=""
for i in range(len(texIndexList)):
texIndxStr = texIndxStr + "%d, " % texIndexList[i]
if texIndexList[i]==-1:
self.file.write(texIndxStr)
texIndxStr=""
self.file.write("\"\n\t\t\t")
fw = self.file.write
j = 0
for face in mesh.uv_textures.active.data:
if len(face.uv) == 4:
fw("%d %d %d %d -1, " % (j, j + 1, j + 2, j + 3))
j += 4
else:
fw("%d %d %d -1, " % (j, j + 1, j + 2))
j += 3
fw("\"\n\t\t\t")
else:
texCoordList = (uv for fuv in mesh.uv_textures.active.data for uv in fuv.uv)
self.writeIndented("<TextureCoordinate point=\"", 1)
for i in range(len(texCoordList)):
self.file.write("%s %s, " % (round(texCoordList[i][0],self.tp), round(texCoordList[i][1],self.tp)))
self.file.write("\" />")
fw = self.file.write
for uv in texCoordList:
fw("%.4f %.4f, " % uv[:])
fw("\" />")
self.writeIndented("\n", -1)
def writeFaceColors(self, mesh):

View File

@@ -1485,13 +1485,13 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po
{
int count, totdim;
PyObject *list = PyList_New(stop - start);
PyObject *tuple= PyTuple_New(stop - start);
totdim = RNA_property_array_dimension(ptr, prop, NULL);
if (totdim > 1) {
for (count = start; count < stop; count++)
PyList_SET_ITEM(list, count - start, pyrna_prop_array_to_py_index(self, count));
PyTuple_SET_ITEM(tuple, count - start, pyrna_prop_array_to_py_index(self, count));
}
else {
switch (RNA_property_type(prop)) {
@@ -1504,7 +1504,7 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po
RNA_property_float_get_array(ptr, prop, values);
for(count=start; count<stop; count++)
PyList_SET_ITEM(list, count-start, PyFloat_FromDouble(values[count]));
PyTuple_SET_ITEM(tuple, count-start, PyFloat_FromDouble(values[count]));
if(values != values_stack) {
PyMem_FREE(values);
@@ -1520,7 +1520,7 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po
RNA_property_boolean_get_array(ptr, prop, values);
for(count=start; count<stop; count++)
PyList_SET_ITEM(list, count-start, PyBool_FromLong(values[count]));
PyTuple_SET_ITEM(tuple, count-start, PyBool_FromLong(values[count]));
if(values != values_stack) {
PyMem_FREE(values);
@@ -1536,7 +1536,7 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po
RNA_property_int_get_array(ptr, prop, values);
for(count=start; count<stop; count++)
PyList_SET_ITEM(list, count-start, PyLong_FromSsize_t(values[count]));
PyTuple_SET_ITEM(tuple, count-start, PyLong_FromSsize_t(values[count]));
if(values != values_stack) {
PyMem_FREE(values);
@@ -1547,11 +1547,11 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po
BKE_assert(!"Invalid array type");
PyErr_SetString(PyExc_TypeError, "not an array type");
Py_DECREF(list);
list= NULL;
Py_DECREF(tuple);
tuple= NULL;
}
}
return list;
return tuple;
}
static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject *key)