This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
projects:houseofcards:start [2016/07/09 17:38] dwheele [Non-BMesh, Working script] |
projects:houseofcards:start [2017/11/18 18:03] (current) dwheele |
||
|---|---|---|---|
| Line 7: | Line 7: | ||
| * [[pythonoperators|Python Operators from Blender]] | * [[pythonoperators|Python Operators from Blender]] | ||
| * [[cardfaceinfo|Card Face Graphic Info]] | * [[cardfaceinfo|Card Face Graphic Info]] | ||
| + | * [[blenderarraynumbering|Blender Array Numbering]] | ||
| + | * [[shufflecards|Shuffle Cards Routine in Python]] | ||
| + | * [[physicssettings|Physics Settings]] | ||
| + | * [[workingpython|Work Python Scripts (backup)]] | ||
| + | * [[playingcardspecifics|Playing Card Specifics]] | ||
| My example '' | My example '' | ||
| Line 54: | Line 59: | ||
| **Following need to be run in Object mode** | **Following need to be run in Object mode** | ||
| - | UVs are stored in a UV layer: | + | ==== Printing UVs for Object ==== |
| + | |||
| + | UVs are stored in a UV layer, but still need to know which uv_layer goes with which face: | ||
| <code python> | <code python> | ||
| + | ob = bpy.data.objects[" | ||
| + | for uv_layer in ob.data.uv_layers: | ||
| + | print(" | ||
| + | |||
| for loop in ob.data.loops : | for loop in ob.data.loops : | ||
| uv_coords = ob.data.uv_layers[0].data[loop.index].uv | uv_coords = ob.data.uv_layers[0].data[loop.index].uv | ||
| - | print(uv_coords) | + | print("Loop %d: %s" % (loop.index, |
| </ | </ | ||
| + | |||
| + | ==== Get UVs per Face, Example from web ==== | ||
| + | |||
| + | https:// | ||
| + | |||
| + | <code python> | ||
| + | import bpy | ||
| + | ob = bpy.data.objects[" | ||
| + | me = ob.data; | ||
| + | |||
| + | for f in me.polygons: | ||
| + | print(" | ||
| + | for i in f.loop_indices: | ||
| + | l = me.loops[i] # The loop entry this polygon point refers to | ||
| + | v = me.vertices[l.vertex_index] # The vertex data that loop entry refers to | ||
| + | print(" | ||
| + | "at position", | ||
| + | for j,ul in enumerate(me.uv_layers): | ||
| + | print(" | ||
| + | "for this loop index" | ||
| + | </ | ||
| + | |||
| + | Noticing that the polygon where the vertex index set (2, 3, 6, 7, in my case) equals the set in the Vertex Group I defined, **has the proper UV set.** | ||
| + | |||
| + | Their explanation: | ||
| + | |||
| + | The me.loops object is really a lookup list, and each entry is NOT a loop in and of itself. The " | ||
| + | |||
| + | Running this on the default cube shows that me.polygons has six entries (the six faces of the cube). Each polygon refers to four loop indexes, making the me.loops list 24 entries long. | ||
| + | |||
| + | Every UV layer in me.uv_layers has a " | ||
| + | |||
| + | |||
| + | |||
| + | ==== Printing Vertices Per Mesh ==== | ||
| **Vertices** | **Vertices** | ||
| Line 153: | Line 199: | ||
| for vertGroup in v.groups: | for vertGroup in v.groups: | ||
| if vertGroup.group == groupIndex: | if vertGroup.group == groupIndex: | ||
| - | | + | |
| + | |||
| + | # Find the UVs to go with these Vertices | ||
| </ | </ | ||
| Line 256: | Line 305: | ||
| Going back to non-BMESH method. In BMesh, it is difficult to assemble the correct types. | Going back to non-BMESH method. In BMesh, it is difficult to assemble the correct types. | ||
| + | ==== Get Face from Mesh defined by Vertex Group ==== | ||
| + | |||
| + | <code python> | ||
| + | import bpy | ||
| + | ob = bpy.data.objects[" | ||
| + | |||
| + | |||
| + | def getFaceFromObjectContainingVertexGroup(ob, | ||
| + | |||
| + | # First, get list of Vertexes in Vertex Group | ||
| + | |||
| + | groupIndex = -1 | ||
| + | |||
| + | # This is an Object with a Mesh, see if it has the supported group name | ||
| + | for i in range(0, len(ob.vertex_groups)): | ||
| + | group = ob.vertex_groups[i] | ||
| + | if group.name == vertexGroupName: | ||
| + | groupIndex = i | ||
| + | |||
| + | # if we didn't find it, exit | ||
| + | if (groupIndex < 0): | ||
| + | return null | ||
| + | |||
| + | # Now access the vertices that are assigned to this group | ||
| + | |||
| + | bmVertGroupMembers = [] | ||
| + | |||
| + | for v in ob.data.vertices: | ||
| + | for vertGroup in v.groups: | ||
| + | if vertGroup.group == groupIndex: | ||
| + | | ||
| + | | ||
| + | |||
| + | # at this point, we have a list of vertices in bmVertGroupMembers | ||
| + | # belonging to group vertexGroupName, | ||
| + | |||
| + | for f in me.polygons: | ||
| + | print(" | ||
| + | for i in f.loop_indices: | ||
| + | l = me.loops[i] # The loop entry this polygon point refers to | ||
| + | v = me.vertices[l.vertex_index] # The vertex data that loop entry refers to | ||
| + | print(" | ||
| + | "at position", | ||
| + | for j,ul in enumerate(me.uv_layers): | ||
| + | print(" | ||
| + | "for this loop index" | ||
| + | |||
| + | </ | ||