<?xml version='1.0' encoding='utf-8' ?>
<?xml-stylesheet type="text/xsl" href="header_e.xsl" ?>
<body PageTitle="Reference cameras utilities" PageHeader="Tutorials" Updated="2021-09-16" Created="2019-11-03">
<div>
<p><a href="downloads/scripts/28/object_reference_cameras.zip">Here</a> you can download the <b>object_reference_cameras.zip </b> add-on file (requires Blender 2.8 or later)</p>
<p>
Before using this tutorial, you should install <b>Reference Cameras</b> add-on in your Blender (Here is a <a href="scripts-251_e.xml">description</a> how to do it).
</p>
<p>Note: in 2021 <b>Marcelo Marques</b> (mmmrqs) created new version of this add-on, extended by multiple additional functions. It is available from <a href="https://github.com/mmmrqs/Blender-Reference-Camera-Panel-addon">this</a> GitHub repository.</p>
<p>
In the description below I am using the original (simpler) version. This add-on groups utilities for managing cameras that I use for “fitting” my models into reference photos. (You can use a high-resolution photo as a precise reference, just like the scale drawing. See <a href="downloads/103-photo_matching.pdf">Part 1</a> and <a href="downloads/104-photo_matching.pdf">Part 2</a> of the tutorial that I wrote on this subject). 
</p>
<p>Fig. 1. and Fig. 2 show an example of such a model fitted into reference photo: </p>
<table cellSpacing="0" cellPadding="0pt" align="center">
	<tr align="center" valign="top">
		<td>
				<IMG src="images/scripts/257/image01.jpg" align="center"/>
		</td>
	</tr>
	<tr align="center" valign="top">
		<td><spanl>Fig. 1 Douglas SBD 3D model, fitted into a reference photo</spanl></td>
	</tr>
</table>
<br/>
<table cellSpacing="0" cellPadding="0pt" align="center">
	<tr align="center" valign="top">
		<td>
				<IMG src="images/scripts/257/image02_e.jpg" align="center"/>
		</td>
	</tr>
	<tr align="center" valign="top">
		<td><spanl>Fig. 2 Details of the model and its reference photo </spanl></td>
	</tr>
</table>
<p>
The model in Fig. 1 and Fig. 2 is displayed in a perspective projection from a camera. In the text below I refer to such a camera as “reference camera”. Just as in the case of the scale plans, where you use at least three different views, you can define multiple reference cameras that contain aircraft photos taken from different directions.<br/> 
Each <b>reference camera</b>:
</p>
<li>displays a reference photo as its <b>Background Image</b> (as in Fig.3);</li>
<li>is directed toward an auxiliary target object (this is implemented by a <b>Track To</b> constraint, as in Fig. 4)</li>
<br/>
<table cellSpacing="0" cellPadding="0pt" align="center">
	<tr align="center" valign="top">
		<td>
				<IMG src="images/scripts/257/image03_e.jpg" align="center"/>
		</td>
	</tr>
	<tr align="center" valign="top">
		<td><spanl>Fig. 3 Reference camera background image</spanl></td>
	</tr>
</table>
<br/>
<table cellSpacing="0" cellPadding="0pt" align="center">
	<tr align="center" valign="top">
		<td>
				<IMG src="images/scripts/257/image03_e.jpg" align="center"/>
		</td>
	</tr>
	<tr align="center" valign="top">
		<td><spanl>Fig. 4 Auxiliary camera target object</spanl></td>
	</tr>
</table>
<p>Such an auxiliary object gives you an intuitive control over the camera direction. (Each movement of the target object causes corresponding rotation of the assigned camera)</p>
</div>

<div class="subheader">Add-on activation</div>
<div>
<p>This add-on is named <b>Reference Cameras</b>. After installation, you will find it in the Object category. To use it in Blender, you have to activate it in the <b>Preferences</b> window (Fig. 5):</p>
<table cellSpacing="0" cellPadding="0pt" align="center">
	<tr align="center" valign="top">
		<td>
				<IMG src="images/scripts/257/image05_e.jpg" align="center"/>
		</td>
	</tr>
	<tr align="center" valign="top">
		<td><spanl>Fig. 5. Activation of the <b>Reference Cameras</b> add-on.</spanl></td>
	</tr>
</table>
<p>When activated, this plugin creates additional <b>Cameras</b> tab to the <b>3D View</b> side panel (the panel, which visibility you can toggle typing the <b>[N]</b> key):</p>
<table cellSpacing="0" cellPadding="0pt" align="center">
	<tr align="center" valign="top">
		<td>
				<IMG src="images/scripts/257/image06_e.jpg" align="center"/>
		</td>
	</tr>
	<tr align="center" valign="top">
		<td><spanl>Fig. 6. Contents of the <b>Cameras</b> tab</spanl></td>
	</tr>
</table>
</div>
<divf/>
<div class="subheader">Quick switching between reference cameras</div>
<div>
<p>Manual switching between reference cameras is cumbersome. You have to select the camera object, set it as the active camera, then adjust the reference image aspect ratio in the <b>Output</b> tab. I needed a utility for single-click switching between the reference cameras. (It has to be as easy as switching between the orthogonal views). Thus, in the <b>Cameras</b> tab you can find the <b>Ref Cameras</b> panel. Each button in this panel represents a reference camera defined in your scene.
</p>
<p>
The content of this panel is automatically generated from a collection which name ends with “<em>RC:Cameras</em>” text:
</p>
<table cellSpacing="0" cellPadding="0pt" align="center">
	<tr align="center" valign="top">
		<td>
				<IMG src="images/scripts/257/image07_e.jpg" style="max-width:1000px;" align="center"/>
		</td>
	</tr>
	<tr align="center" valign="top">
		<td><spanl>Fig. 7. Automatic generation of the <b>Ref Cameras</b> buttons</spanl></td>
	</tr>
</table>
<p>All what you have to do is to place all your reference cameras in such a collection. Its prefix is still up to you. As you can see in the figure above, I also placed there the camera targets – just to have everything “in one place”. Once activated, <b>Reference Cameras</b> add-on monitors structure of the current scene. When it finds the first collection which name ends with “RC:Cameras”, it searches its contents for the reference cameras (i.e. cameras with <b>Background Image</b>s and active <b>Track To</b> constraints). For each such a camera it adds a button in the <b>Ref Cameras</b> panel. (Labeled with the camera object name). 
</p>
<p>When you click such a button, it switches the projection in the active 3D View to the corresponding reference camera:</p>
<table cellSpacing="0" cellPadding="0pt" align="center">
	<tr align="center" valign="top">
		<td>
				<IMG src="images/scripts/257/image08_e.jpg" style="max-width:1000px;" align="center"/>
		</td>
	</tr>
	<tr align="center" valign="top">
		<td><spanl>Fig. 8. Switching 3D View projection to another reference camera</spanl></td>
	</tr>
</table>
<p>After you click this button, the add-on also places additional links to the current camera and its target in a collection named <b><em>RC:Temporary:</em></b></p>
<table cellSpacing="0" cellPadding="0pt" align="center">
	<tr align="center" valign="top">
		<td>
				<IMG src="images/scripts/257/image09_e.jpg" style="max-width:1000px;" align="center"/>
		</td>
	</tr>
	<tr align="center" valign="top">
		<td><spanl>Fig. 9. “Working” collection: <em><b>RC:Temporary</b></em></spanl></td>
	</tr>
</table>
<p>Most probably you will keep collection <b><em>*RC:Cameras</em></b> as invisible (to avoid clutter in the scene – you do not need to see all camera targets simultaneously). That’s why this plugin “exposes” links to the current camera and its target in a separate, visible collection. In this way you can easily adjust this projection, when needed. 
</p>
<p><b>Reference Cameras</b> will create <b><em>RC:Temporary</em></b> collection, if it does not exist in your scene. Once it is created, you can move it into any place in your scene hierarchy. Like in the case of the <b><em>*RC:Cameras</em></b>, you can also  add a prefix to this name. 
</p>
<p>
<u><b>Note</b></u>: collection <b><em>RC:Temporary</em></b> must be visible. Otherwise the <b>Ref Cameras</b> buttons will not work
</p>
<p>
<u><b>Note</b></u>: the active camera and its target are simultaneously in two collections: <b><em>*RC:Cameras</em></b> (this is their permanent location), which is usually hidden, and <b><em>*RC:Temporary</em></b>, which must be visible. Content of the <b><em>*RC:Temporary</em></b> is cleared every time you click a button from the <b>Ref Cameras</b> panel.
</p>
</div>
<div class="subheader">Adjusting camera focal length</div>
<div>
<p>For the modern photos created as *.jpg files, you can read their camera focal length from the image metadata and then set this value to your reference camera in Blender. Then you can focus on determining the remaining six unknowns (the Xc, Yc, Zc of the camera location, and its direction, determined by the Xt, Yt, Zt coordinates of the target object). However, for the older photos the focal length is the seventh unknown. In the picture below you can see a case when I did what I could to set up the camera and target position, matching the aircraft contour. However, there were still differences in the wing “trapeze” shape and in the direction of the propeller blade (the one which is pointing toward the camera):</p>
<table cellSpacing="0" cellPadding="0pt" align="center">
	<tr align="center" valign="top">
		<td>
				<IMG src="images/scripts/257/image10_e.jpg" style="max-width:1000px;" align="center"/>
		</td>
	</tr>
	<tr align="center" valign="top">
		<td><spanl>Fig. 10. An example of a perspective projection, which camera requires different focal lens  </spanl></td>
	</tr>
</table>
<p>These are symptoms of a wrong camera lens length. 
</p>
<p>When you try to alter this parameter without the <b>Reference Cameras</b> plugin, you will observe significant changes in the model relative size:
</p>
<table cellSpacing="0" cellPadding="0pt" align="center">
	<tr align="center" valign="top">
		<td>
				<IMG src="images/scripts/257/image11_e.jpg" style="max-width:1000px;" align="center"/>
		</td>
	</tr>
	<tr align="center" valign="top">
		<td><spanl>Fig. 11. Side effect of altering the camera lens focal length in the standard Blender: a serious change of the relative model size</spanl></td>
	</tr>
</table>
<p>When you decrease the camera focal length, it decreases the relative size of the model in the camera frame (Fig. 11). When you increase focal length – the model “grows up” in the frame. Thus, in the standard Blender, after every change of the focal length you have to fit your model to the reference photo anew. Of course, the most obvious method is adjusting camera distance (along its local Z axis) from the model. You can ever calculate a movement that compensates changes in the focal length. Below you can see its idea:</p>
<table cellSpacing="0" cellPadding="0pt" align="center">
	<tr align="center" valign="top">
		<td>
				<IMG src="images/scripts/257/image12_e.jpg" style="max-width:1000px;" align="center"/>
		</td>
	</tr>
	<tr align="center" valign="top">
		<td><spanl>Fig. 12. Compensating with camera distance the changes in the lens length</spanl></td>
	</tr>
</table>
<p>
Anyway, still such a manual adjustment is quite cumbersome. That’s why I added to <b>Reference Cameras</b> plugin an automatic compensation of the lens length changes, which works as in Fig. 12. When you change the lens length of a reference camera, the add-on compensates this by changing the distance from the camera to its target. This movement is calculated in such a way that the relative size of the camera target in the camera frame remains constant. (This means, that this automatic compensation preserves relative size of any contour which lies on the plane which is perpendicular to the camera and passes through the origin of the camera target object. I am referring to this plane as “neutral plane”).
</p>
<p>Thus, to easily adjust camera lens length without need for manual refitting the model for a projection which resembles a side view, place the camera target object in the aircraft symmetry plane. (In the case below I placed camera target inside the fuselage, in the cockpit):
</p>
<table cellSpacing="0" cellPadding="0pt" align="center">
	<tr align="center" valign="top">
		<td>
				<IMG src="images/scripts/257/image13_e.jpg" style="max-width:1000px;" align="center"/>
		</td>
	</tr>
	<tr align="center" valign="top">
		<td><spanl>Fig. 13. An example of automatic lens length compensation</spanl></td>
	</tr>
</table>
<p>Then when you start changing the camera lens length (for example, using the additional control exposed in the <b>Cameras:Current</b> panel, as in Fig. 13), you will see in its frame the changing proportions of the model (the shape of the wing trapezoid, direction of the propeller blade, etc.) Simultaneously, the model contour which lies on the aircraft symmetry plane remains fixed.</p>
<p> 
The best way to learn how the lens length affects your camera view is to change its value smoothly, using mouse. You can do it by dragging your mouse over the <b>Current:Lens</b> field, simultaneously keeping the <b>[Alt]</b> key down. (You can also use this trick in the <b>Camera</b> properties, <b>Lens</b> panel, altering the <b>Focal Length</b> field). If you want to increase precision of these changes – press also <b>[Shift]</b> key, while dragging your mouse.
</p>
<p><u><b>Note</b></u>: This automatic compensation occurs only for the lens length of the reference cameras, when the <b>Reference Cameras</b> add-on is activated;</p>
<p><u><b>Note</b></u>: if you notice that the camera view “blinks” after every change of the camera focal length, open and then minimize the Blender <b>Preferences</b> window (<b>Edit: Preferences</b>). This simple step eliminates “blinking” of this view. (I cannot explain this effect, but at least in the current Blender version: 2.80, this add-on works smoothly when you have opened more than one Blender window.)</p>
</div>
</body>
