[Bf-funboard] sample script for use with getPerspMatrix()

Konrad Haenel public at konrad-haenel.de
Thu Oct 14 02:05:43 CEST 2004


This is great! What's it good for?

Tom Musgrove wrote:

> Here is a sample python script showing the usage of getPerspMatrix()
>
> It gets the screen pixel location of the vertices of an object and 
> prints them
>
> [code]
> # this script finds the screen pixel locations of the selected object
>
> import Blender
> from Blender import Object, NMesh, Window, Mathutils
>
> for win3d in Window.GetScreenInfo(Window.Types.VIEW3D):
>     min_x, min_y, max_x, max_y = win3d.get('vertices')
>     mid_x = (max_x+min_x)/2        #the x midpoint of the 3dview window
>     mid_y = (max_y+min_y)/2        #the y midpoint of the 3dview window
>     sx_2 = (max_x-min_x)/2        #scaling in pixels in the x direction
>     sy_2 = (max_y-min_y)/2        #scaling in pixels in the y direction
>
> obj_loc = Blender.Object.GetSelected()[0].loc
> obj_loc_vec = Mathutils.Vector(list(obj_loc))
> myMesh = Blender.Object.GetSelected()[0].getData()
> #obj_mat = Blender.Object.GetSelected()[0].getMatrix()
> obj_mat = Blender.Object.GetSelected()[0].getMatrix('worldspace')
> perspMatrix = Blender.Window.GetPerspMatrix()
> for vert in myMesh.verts:
>     myVec = Mathutils.Vector(list(vert.co+obj_loc_vec)+[1.0])
>     vertGlobalCoords = Blender.Mathutils.MatMultVec(obj_mat,myVec)
>     vertRawScreenCoords = 
> Blender.Mathutils.MatMultVec(perspMatrix,vertGlobalCoords)
>     print int(mid_x+vertRawScreenCoords[0]*sx_2) #screen x
>     print int(mid_y+vertRawScreenCoords[1]*sy_2) #screen y
> [/code]
>
> LetterRip
>
> _________________________________________________________________
> Get ready for school! Find articles, homework help and more in the 
> Back to School Guide! http://special.msn.com/network/04backtoschool.armx
>
> _______________________________________________
> Bf-funboard mailing list
> Bf-funboard at projects.blender.org
> http://projects.blender.org/mailman/listinfo/bf-funboard
>



More information about the Bf-funboard mailing list