[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24400] trunk/blender: bpy/ rna api class feature
Campbell Barton
ideasman42 at gmail.com
Sun Nov 8 02:13:19 CET 2009
Revision: 24400
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24400
Author: campbellbarton
Date: 2009-11-08 02:13:19 +0100 (Sun, 08 Nov 2009)
Log Message:
-----------
bpy/rna api class feature
- python defined classes will be used when available (otherwise automaically generated metaclasses are made as before)
- use properties rather then functions for python defined rna class's
- call the classes getattr AFTER doing an RNA lookup, avoids setting and clearing exceptions for most attribute lookups, tested UI scripts are ~25% faster.
- extending rna py classes this way is a nicer alternative to modifying the generated metaclasses in place.
Example class
--- snip
class Object(bpy.types.ID):
def _get_children(self):
return [child for child in bpy.data.objects if child.parent == self]
children = property(_get_children)
--- snip
The C initialization function looks in bpy_types.py for classes matching RNA structure names, using them when available.
This means all objects in python will be instances of these classes.
Python properties/funcs defined in ID py class will also be available for subclasses for eg. (Group Mesh etc)
Modified Paths:
--------------
trunk/blender/release/scripts/modules/bpy_ext/Mesh.py
trunk/blender/release/scripts/modules/bpy_ext/Object.py
trunk/blender/release/scripts/modules/bpy_ext/__init__.py
trunk/blender/release/scripts/op/mesh.py
trunk/blender/release/scripts/op/mesh_skin.py
trunk/blender/source/blender/python/intern/bpy_interface.c
trunk/blender/source/blender/python/intern/bpy_rna.c
trunk/blender/source/blender/python/intern/bpy_rna.h
Added Paths:
-----------
trunk/blender/release/scripts/modules/bpy_types.py
Modified: trunk/blender/release/scripts/modules/bpy_ext/Mesh.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_ext/Mesh.py 2009-11-07 23:10:18 UTC (rev 24399)
+++ trunk/blender/release/scripts/modules/bpy_ext/Mesh.py 2009-11-08 01:13:19 UTC (rev 24400)
@@ -1,72 +0,0 @@
-# ##### BEGIN GPL LICENSE BLOCK #####
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-def ord_ind(i1,i2):
- if i1<i2: return i1,i2
- return i2,i1
-
-def edge_key(ed):
- v1, v2 = tuple(ed.verts)
- return ord_ind(v1, v2)
-
-def face_edge_keys(face):
- verts = tuple(face.verts)
- if len(verts)==3:
- return ord_ind(verts[0], verts[1]), ord_ind(verts[1], verts[2]), ord_ind(verts[2], verts[0])
-
- return ord_ind(verts[0], verts[1]), ord_ind(verts[1], verts[2]), ord_ind(verts[2], verts[3]), ord_ind(verts[3], verts[0])
-
-def mesh_edge_keys(mesh):
- return [edge_key for face in mesh.faces for edge_key in face.edge_keys()]
-
-def mesh_edge_face_count_dict(mesh, face_edge_keys=None):
-
- # Optional speedup
- if face_edge_keys==None:
- face_edge_keys = [face.edge_keys() for face in face_list]
-
- face_edge_count = {}
- for face_keys in face_edge_keys:
- for key in face_keys:
- try:
- face_edge_count[key] += 1
- except:
- face_edge_count[key] = 1
-
-
- return face_edge_count
-
-def mesh_edge_face_count(mesh, face_edge_keys=None):
- edge_face_count_dict = mesh.edge_face_count_dict(face_edge_keys)
- return [edge_face_count_dict.get(ed.key(), 0) for ed in mesh.edges]
-
-import bpy
-
-# * Edge *
-class_obj = bpy.types.MeshEdge
-class_obj.key = edge_key
-
-# * Face *
-class_obj = bpy.types.MeshFace
-class_obj.edge_keys = face_edge_keys
-
-# * Mesh *
-class_obj = bpy.types.Mesh
-class_obj.edge_keys = mesh_edge_keys
-class_obj.edge_face_count = mesh_edge_face_count
-class_obj.edge_face_count_dict = mesh_edge_face_count_dict
Modified: trunk/blender/release/scripts/modules/bpy_ext/Object.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_ext/Object.py 2009-11-07 23:10:18 UTC (rev 24399)
+++ trunk/blender/release/scripts/modules/bpy_ext/Object.py 2009-11-08 01:13:19 UTC (rev 24400)
@@ -1,22 +0,0 @@
-# ##### BEGIN GPL LICENSE BLOCK #####
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-import bpy
-class_obj = bpy.types.Object
-
-class_obj.getChildren = lambda self: [child for child in bpy.data.objects if child.parent == self]
Modified: trunk/blender/release/scripts/modules/bpy_ext/__init__.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_ext/__init__.py 2009-11-07 23:10:18 UTC (rev 24399)
+++ trunk/blender/release/scripts/modules/bpy_ext/__init__.py 2009-11-08 01:13:19 UTC (rev 24400)
@@ -1,20 +0,0 @@
-# ##### BEGIN GPL LICENSE BLOCK #####
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-import bpy_ext.Object
-import bpy_ext.Mesh
Added: trunk/blender/release/scripts/modules/bpy_types.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_types.py (rev 0)
+++ trunk/blender/release/scripts/modules/bpy_types.py 2009-11-08 01:13:19 UTC (rev 24400)
@@ -0,0 +1,82 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+import bpy
+
+StructRNA = bpy.types.Struct.__bases__[0]
+# StructRNA = bpy.types.Struct
+
+
+class Object(bpy.types.ID):
+
+ def _get_children(self):
+ return [child for child in bpy.data.objects if child.parent == self]
+
+ children = property(_get_children)
+
+
+def ord_ind(i1,i2):
+ if i1<i2: return i1,i2
+ return i2,i1
+
+class Mesh(bpy.types.ID):
+
+ def _get_edge_keys(self):
+ return [edge_key for face in self.faces for edge_key in face.edge_keys]
+
+ edge_keys = property(_get_edge_keys)
+
+ def _get_edge_face_count_dict(self):
+ face_edge_keys = [face.edge_keys for face in self.faces]
+ face_edge_count = {}
+ for face_keys in face_edge_keys:
+ for key in face_keys:
+ try:
+ face_edge_count[key] += 1
+ except:
+ face_edge_count[key] = 1
+
+ return face_edge_count
+
+ edge_face_count_dict = property(_get_edge_face_count_dict)
+
+ def _get_edge_face_count(self):
+ edge_face_count_dict = self.edge_face_count_dict
+ return [edge_face_count_dict.get(ed.key, 0) for ed in mesh.edges]
+
+ edge_face_count = property(_get_edge_face_count)
+
+
+class MeshEdge(StructRNA):
+
+ def _get_key(self):
+ return ord_ind(*tuple(self.verts))
+
+ key = property(_get_key)
+
+
+class MeshFace(StructRNA):
+
+ def _get_edge_keys(self):
+ verts = tuple(self.verts)
+ if len(verts)==3:
+ return ord_ind(verts[0], verts[1]), ord_ind(verts[1], verts[2]), ord_ind(verts[2], verts[0])
+
+ return ord_ind(verts[0], verts[1]), ord_ind(verts[1], verts[2]), ord_ind(verts[2], verts[3]), ord_ind(verts[3], verts[0])
+
+ edge_keys = property(_get_edge_keys)
Modified: trunk/blender/release/scripts/op/mesh.py
===================================================================
--- trunk/blender/release/scripts/op/mesh.py 2009-11-07 23:10:18 UTC (rev 24399)
+++ trunk/blender/release/scripts/op/mesh.py 2009-11-08 01:13:19 UTC (rev 24400)
@@ -28,9 +28,9 @@
mesh = ob.data
face_list = [face for face in mesh.faces]
- face_edge_keys = [face.edge_keys() for face in face_list]
+ face_edge_keys = [face.edge_keys for face in face_list]
- edge_face_count = mesh.edge_face_count_dict(face_edge_keys)
+ edge_face_count = mesh.edge_face_count_dict
def test_interior(index):
for key in face_edge_keys[index]:
Modified: trunk/blender/release/scripts/op/mesh_skin.py
===================================================================
--- trunk/blender/release/scripts/op/mesh_skin.py 2009-11-07 23:10:18 UTC (rev 24399)
+++ trunk/blender/release/scripts/op/mesh_skin.py 2009-11-08 01:13:19 UTC (rev 24400)
@@ -256,11 +256,11 @@
if MESH_MODE == 'FACE':
context.scene.tool_settings.mesh_selection_mode = 'EDGE'
# value is [edge, face_sel_user_in]
- edge_dict= dict((ed.key(), [ed, 0]) for ed in me.edges)
+ edge_dict= dict((ed.key, [ed, 0]) for ed in me.edges)
for f in me.faces:
if f.selected:
- for edkey in f.edge_keys():
+ for edkey in f.edge_keys:
edge_dict[edkey][1] += 1
context.scene.tool_settings.mesh_selection_mode = MESH_MODE
@@ -280,7 +280,7 @@
vert_used = [False] * tot
for ed in selEdges:
- i1, i2 = ed.key()
+ i1, i2 = ed.key
vert_siblings[i1].append(i2)
vert_siblings[i2].append(i1)
Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c 2009-11-07 23:10:18 UTC (rev 24399)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c 2009-11-08 01:13:19 UTC (rev 24400)
@@ -176,35 +176,35 @@
{
PyObject *mod;
+ /* Needs to be first since this dir is needed for future modules */
+ char *modpath= BLI_gethome_folder("scripts/modules", BLI_GETHOME_ALL);
+ if(modpath) {
+ PyObject *sys_path= PySys_GetObject("path"); /* borrow */
+ PyObject *py_modpath= PyUnicode_FromString(modpath);
+ PyList_Insert(sys_path, 0, py_modpath); /* add first */
+ Py_DECREF(py_modpath);
+ }
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list