1
$\begingroup$

I know this is a very specific use case, but maybe the answer could be useful for other people who want to automate rendering large batches of cameras in Blender.

In another program I generated mesh geometries that resemble the shape of blenders camera objects. Now I'm looking for a way to convert these mesh "pyramids" to actual camera objects in Blender.

One would have to extract the vertex coordinate of the "pyramid's tip", the direction it is pointing and the distance, then use this information + a global orientation (positive Z direction) for creating a camera object.

Ideally also the aspect ratio of the pyramid's single quad face would be extracted and used for the rendering aspect ration, but this cannot be set in the camera object's properties as far as I know.

Maybe someone with more knowledge of bpy can lead me in the right direction.

enter image description here

$\endgroup$
5
  • $\begingroup$ with a bit of tinkering you can get the location of the tip (the only vertex that is linked to 4 edges), the center of the quad with docs.blender.org/api/current/…, that will give you the local matrix of the camera (location + rotation). The length of this vector will also give you the focal length, though I don't know the relation between the size of the camera widget and the focal length in Blender, I'm sure it follows a linear or quadratic regression which is easy enough to find with an online tool. $\endgroup$
    – Gorgious
    Mar 12 at 11:03
  • $\begingroup$ the aspect ratio is indeed tied to the scene properties though; But it can be retrieved by comparing the edge lengths of the quad. Although you should ask yourself if you would not be better of exporting this data as text information and use a parser to create cameras directly instead of jumping through hoops with this method which seems very complicated for what it does. You're figuratively translating english to chinese then back to english when you can directly import english using a script. Depends on your source software scripting capabilities though $\endgroup$
    – Gorgious
    Mar 12 at 11:04
  • $\begingroup$ i have code ready that positions camera exactly at pyramid tip & set the same orientation/rotation as the mesh and make it point in the correct direction. but it seems that it is not possible to set the size of the 4 corners of the camera's rectanglular region as they are tied to the Resolution_X/Y. i tried tinkering and incraesing resolution x/y but it doesn't grow bigger. just aspect ratio wise adjusts. only increasing the scale of the actual camera object can get it to fit the mesh size. so if you have a mesh size of 1mx1m your camera can never reach that size for example. am i wrong? $\endgroup$ Mar 12 at 13:16
  • $\begingroup$ you are right @Gorgious I should skip the mesh representation and re-analyzing steps and just write a text / json file with the required information, especially because I'm not really familiar with bpy yet. The reason for the first idea was to have everything contained in one file and thoroughly visually represented $\endgroup$
    – spline_bb
    Mar 12 at 13:52
  • $\begingroup$ @HarryMcKenzie this seems correct, at least from my experience with setting cameras in blender manually. The scale of the camera object doesnt seem to affect the captured frame and therefore only serves presentiveness purposes . Focal length and distance to object are the crucial parameters, that would have to be calculated to fit the field of view angle exactly. $\endgroup$
    – spline_bb
    Mar 12 at 14:12

0

Your Answer

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

Browse other questions tagged or ask your own question.