[Bf-python] Re: problem with absolute vertex coords

Campbell Barton cbarton at metavr.com
Thu Feb 3 11:09:09 CET 2005


Melchior FRANZ wrote:

>* joeedh -- Thursday 03 February 2005 02:32:
>* * Melchior FRANZ -- Thursday 03 February 2005 01:08:
>  
>
>>>I wrote a Python script[1] that outputs vertex coordinates to an xml file that I
>>>can directly use for FlightGear[2] animations. But it turned out that the coords
>>>aren't correct -- they are too big.
>>>      
>>>
>
>  
>
>>You have to multiply the vertex by the object's 4x4 3d transformation 
>>matrix.  I think this involves Mathutils.  You just copy the vertex 
>>location into a Mathutils.Vector object (it should already be in one, 
>>actually I think)  resize it to 4D (as wierd as that sounds, it adds a 
>>fourth element to the location array) then use |the MatMulVec mathutils 
>>function
>>    
>>
>
>Many thanks! Works perfectly. For the archive, this did it:
>
>  import Blender
>  from Blender import Mathutils
>  from Blender.Mathutils import Vector, VecMultMat
>  ...
>  mat = object.getMatrix()
>  mesh = object.getData()
>  for v in mesh.verts:
>          vec = Vector([v[0],v[1],v[2]])
>          vec.resize4D()
>          vec = VecMultMat(vec, mat)
>          print vec[0], vec[1], vec[2]
>
>m.
>_______________________________________________
>Bf-python mailing list
>Bf-python at projects.blender.org
>http://projects.blender.org/mailman/listinfo/bf-python
>
>
>  
>

You probably should use

mat = object.getMatrix('worldspace')
instead of 
mat = object.getMatrix()

Incase of parenting etc.

- Cam


-- 
Campbell J Barton

Sierra Suites Hotel
32 Fourth Av Waltham, Room 103
phone: 781 622 1900
mobile: 617 935 6773

133 Hope Street
Geelong West, Victoria 3218 Australia

URL:    http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241




More information about the Bf-python mailing list