Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

Showing posts with label index. Show all posts
Showing posts with label index. Show all posts

March 09, 2014

Tools for debugging Mesh Editing scripts (Index Visualizer and Debug mode)

I love many things about Blender, but debugging scripts that interact with Meshes is not one of them. It should be easy to visualize Edge / Vertex / Face indices. Don't worry, this isn't a rant without solution.

Exhibit 1

`bpy.app.debug = True` will add a set of options to the Display panel while in Edit Mode. The options are great but depending on theme and DPI the indices are difficult to make out. With softblend theme the overlay information borders on useless.


Exhibit 2

This script by Crouch, CoDEmanX and additions by me does pretty much the same but draws polygons behind the numbers for better contrast, this is customizable so usable no matter which theme you may be most comfortable with.

I'm quite happy with the script solution, it would be nice to have it available on each Blender installation as part of the `debug` mode. Anyone learning the ways of geometry related coding would benefit.

Improvements?

My underlay addition can be optimized by calculating the standard polygon once per possible width of index number. (quick implementation of said method) Further minimal mode would ditch the rounded corner and be much lighter, but if you have to visualize many vertex / edge / face indices you probably don't understand the algorithm you are trying to implement.

May 14, 2011

Blender Python Printing Vertex Coordinates of selected Mesh

Below you will find the necessary code to get vertex information for yourself in a few easy steps. Running Blender in debug mode has index visualizer built in to allow you to see index information in realtime.
import bpy
for item in bpy.data.objects:
    
    print(item.name)
    if item.type == 'MESH':
        for vertex in item.data.vertices:
            print(vertex.co)
or
import bpy
for item in bpy.data.objects:
    
    print(item.name)
    if item.type == 'MESH':
        vert_list = [vertex.co for vertex in item.data.vertices]
        for vert in vert_list:
            print(vert)
we can go even further.. print faces(polygons), vertices, indices, face normals
# blender 2.6x
import bpy

current_obj = bpy.context.active_object

print("="*40) # printing marker
for face in current_obj.data.polygons:
    verts_in_face = face.vertices[:]
    print("face index", face.index)
    print("normal", face.normal)
    for vert in verts_in_face:
        print("vert", vert, " vert co", current_obj.data.vertices[vert].co)
if you need world coordinates, blenderscripting -- matrixworld will be a good place to find information. Compare the following snippet with the previous one.