[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45858] trunk/blender: add mesh example with docs explaining polygon / loop relationship

Campbell Barton ideasman42 at gmail.com
Mon Apr 23 02:20:34 CEST 2012


Revision: 45858
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45858
Author:   campbellbarton
Date:     2012-04-23 00:20:32 +0000 (Mon, 23 Apr 2012)
Log Message:
-----------
add mesh example with docs explaining polygon / loop relationship

Added Paths:
-----------
    trunk/blender/doc/python_api/examples/bpy.types.Mesh.py

Property Changed:
----------------
    trunk/blender/


Property changes on: trunk/blender
___________________________________________________________________
Modified: svn:ignore
   - *.pdb
.*
TAGS
cscope.out
sgc.bat
sgd.bat
smc.bat
ssenv.bat
tags
user-config.py
CMakeFiles
CMakeCache.txt
blender.bin

   + *.pdb
.*
TAGS
cscope.out
sgc.bat
sgd.bat
smc.bat
ssenv.bat
tags
user-config.py
CMakeFiles
CMakeCache.txt
blender.bin
blender.kdev4
.kdev4


Added: trunk/blender/doc/python_api/examples/bpy.types.Mesh.py
===================================================================
--- trunk/blender/doc/python_api/examples/bpy.types.Mesh.py	                        (rev 0)
+++ trunk/blender/doc/python_api/examples/bpy.types.Mesh.py	2012-04-23 00:20:32 UTC (rev 45858)
@@ -0,0 +1,41 @@
+"""
+Mesh Data
++++++++++
+
+The mesh data is accessed in object mode and intended for compact storage,
+for more flexible mesh editing from python see :mod:`bmesh`.
+
+Blender stores 4 main arrays to define mesh geometry.
+
+* :class:`Mesh.vertices` (3 points in space)
+* :class:`Mesh.edges` (reference 2 vertices)
+* :class:`Mesh.loops` (reference a single vertex and edge)
+* :class:`Mesh.polygons`: (reference a range of loops)
+
+
+Each polygon reference a slice in the loop array, this way, polygons do not store vertices or corner data such as UV's directly,
+only a reference to loops that the polygon uses.
+
+:class:`Mesh.loops`, :class:`Mesh.uv_layers` :class:`Mesh.vertex_colors` are all aligned so the same polygon loop
+indicies can be used to find the UV's and vertex colors as with as the vertices.
+
+To compare mesh API options see: :ref:`NGons and Tessellation Faces <info_gotcha_mesh_faces>`
+
+
+This example script prints the vertices and UV's for each polygon, assumes the active object is a mesh with UVs.
+"""
+
+import bpy
+
+me = bpy.context.object.data
+uv_layer = me.uv.layers.active.data
+
+for poly in me.polygons:
+    print("Polygon index: %d, length: %d" % (poly.index, poly.loop_total))
+
+    # range is used here to show how the polygons reference loops,
+    # for convenience 'poly.loop_indices' can be used instead.
+    for loop_index in range(poly.loop_start, poly.loop_start + poly.loop_total):
+        print("    Vertex: %d" % me.loops[loop_index].vertex_index)
+        print("    UV: %r" % uv_layer[loop_index].uv)
+    


Property changes on: trunk/blender/doc/python_api/examples/bpy.types.Mesh.py
___________________________________________________________________
Added: svn:eol-style
   + native




More information about the Bf-blender-cvs mailing list