2
$\begingroup$

When I plot points of a mesh to 2d using bpy_extras.object_utils.world_to_camera_view the object is centered to the camera. However the actual camera in 3d mode the objects are not centered.

An image is probably the best way to illustrate what I was expecting versus the results I am getting (see below).

Is there anyway to get these meshes off center as the camera actually sees them?

Expected:

Expecting To see this

Actual:

Actuallying seeing this

I don't know if my python code is to blame.. here it is:

..snip.. (for each vector of each mesh)
blenderVertexIndex = bpy.data.objects[obj.name].data.polygons[indexFace].vertices[indexVector]
coordinate3D = bpy.data.objects[obj.name].data.vertices[blenderVertexIndex].co * obj.matrix_world
coordinate2D = bpy_extras.object_utils.world_to_camera_view(bpy.context.scene, bpy.data.objects["Camera"], coordinate3D)
$\endgroup$
4
$\begingroup$

There may be another issue here, but at least the matrix-vector multiplication order from object to world space is wrong, it should be the other way around:

coordinate3D = obj.matrix_world * bpy.data.objects[obj.name].data.vertices[blenderVertexIndex].co
$\endgroup$
2
  • $\begingroup$ i.imgur.com/Q4z0ltl.gif Thank you! this is exactly the problem. But I've got to ask. Was the * operator changed by python or by blender? Is this a common occurrence in vector math?? $\endgroup$ – user1529413 Feb 26 '14 at 5:36
  • $\begingroup$ There was a change in 2.62 $\endgroup$ – CodeManX Feb 26 '14 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.