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 Selected Vertices. Show all posts
Showing posts with label Selected Vertices. Show all posts

August 22, 2011

matrix_world

This multiplies the coordinates as found in the object data with the world matrix of that object. Essentially giving the world coordinate of any selected vertex, even when the object origin is not at the world origin.


Further reading

  • http://db-in.com/blog/2011/04/cameras-on-opengl-es-2-x/

July 27, 2011

ready to generate geometry - edge fillet blender 2.5


the code is a little lengthy to post in its entirety, but you can download it here
def get_correct_verts(arc_centre, arc_start, arc_end, NUM_VERTS, context):

obj_centre = context.object.location
axis = mathutils.geometry.normal(arc_centre, arc_end, arc_start)

point1 = arc_start - arc_centre
point2 = arc_end - arc_centre
main_angle = point1.angle(point2)
main_angle_degrees = math.degrees(main_angle)

div_angle = main_angle / (NUM_VERTS - 1)

if DEBUG == True:
print("arc_centre =", arc_centre)
print("arc_start =", arc_start)
print("arc_end =", arc_end)
print("NUM_VERTS =", NUM_VERTS)

print("NormalAxis1 =", axis)
print("Main Angle (Rad)", main_angle, " > degrees", main_angle_degrees)
print("Division Angle (Radians)", div_angle)
print("AXIS:", axis)

trig_arc_verts = []

for i in range(NUM_VERTS):
rotation_matrix = mathutils.Matrix.Rotation(i*-div_angle, 3, axis)
# trig_point = (arc_start - obj_centre - arc_centre) * rotation_matrix # old
trig_point = rotation_matrix * (arc_start - obj_centre - arc_centre) # new
trig_point += obj_centre + arc_centre
trig_arc_verts.append(trig_point)

return trig_arc_verts
Matrix.Rotate() was the most complicated part, but now i've broken through that barrier it doesn't seem such utter voodoo anymore. Warning to user: you must apply scale/location/rotation transforms to your profile/object first before running the code or the vertices will appear somewhere else. Not sure if there is a cute way around that.

small update




blender 2.5 GL fillet v0.2 from zeffii stanton on Vimeo.

July 11, 2011

getting index of currently selected vertex ( or vertices)

this tells you the index of the currently selected vertex (or if more than one, then it returns the list of selected vertices)
# you must be in 'OBJECT' mode to run these.
>>> [i.index for i in bpy.context.active_object.data.vertices if i.select == True]
[5]
# or slightly shorter, when i.select returns False the element is discarded,
# but when i.select returns True, the if statement compares True with True. (overkill)
>>> [i.index for i in bpy.context.active_object.data.vertices if i.select]
[5]
# or use shorthand to access active_object (more pythonic ):
>>> current_object = bpy.context.active_object
>>> [i.index for i in current_object.data.vertices if i.select]
[5]

# to get a coordinate: (will return all selected vertices if more than one selected)
>>> [i.co for i in bpy.context.active_object.data.vertices if i.select]
[Vector((2.4389050006866455, -3.9095726013183594, 0.9682117700576782))]
Here is a similar snippet that works with bmesh and updates without requiring to enter/exit edit mode.

What about Faces?

Please see this post, it shows two ways.