[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33997] trunk/blender: python api: rna array slices now return tuples rather then lists ( fits with recent change made to mathutils).
Campbell Barton
ideasman42 at gmail.com
Sun Jan 2 10:54:45 CET 2011
Revision: 33997
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33997
Author: campbellbarton
Date: 2011-01-02 10:54:44 +0100 (Sun, 02 Jan 2011)
Log Message:
-----------
python api: rna array slices now return tuples rather then lists (fits with recent change made to mathutils).
minor improvements/cleanup to exporters.
Modified Paths:
--------------
trunk/blender/release/scripts/op/io_scene_3ds/export_3ds.py
trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py
trunk/blender/release/scripts/op/io_scene_obj/export_obj.py
trunk/blender/release/scripts/op/io_scene_x3d/export_x3d.py
trunk/blender/source/blender/python/intern/bpy_rna.c
Modified: trunk/blender/release/scripts/op/io_scene_3ds/export_3ds.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_3ds/export_3ds.py 2011-01-02 06:52:47 UTC (rev 33996)
+++ trunk/blender/release/scripts/op/io_scene_3ds/export_3ds.py 2011-01-02 09:54:44 UTC (rev 33997)
@@ -110,7 +110,6 @@
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
Modified: trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py 2011-01-02 06:52:47 UTC (rev 33996)
+++ trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py 2011-01-02 09:54:44 UTC (rev 33997)
@@ -542,7 +542,7 @@
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 @@
# 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
Modified: trunk/blender/release/scripts/op/io_scene_obj/export_obj.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_obj/export_obj.py 2011-01-02 06:52:47 UTC (rev 33996)
+++ trunk/blender/release/scripts/op/io_scene_obj/export_obj.py 2011-01-02 09:54:44 UTC (rev 33997)
@@ -59,9 +59,8 @@
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_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 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 @@
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 @@
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:
+ 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.
Modified: trunk/blender/release/scripts/op/io_scene_x3d/export_x3d.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_x3d/export_x3d.py 2011-01-02 06:52:47 UTC (rev 33996)
+++ trunk/blender/release/scripts/op/io_scene_x3d/export_x3d.py 2011-01-02 09:54:44 UTC (rev 33997)
@@ -95,7 +95,7 @@
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 @@
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):
Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c 2011-01-02 06:52:47 UTC (rev 33996)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c 2011-01-02 09:54:44 UTC (rev 33997)
@@ -1485,13 +1485,13 @@
{
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 @@
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 @@
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 @@
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 @@
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)
More information about the Bf-blender-cvs
mailing list