| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2010-10-06 07:13:42 +00:00
										 |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed, | 
					
						
							|  |  |  |  *                 Nathan Letwory | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 20:30:35 +00:00
										 |  |  | /** \file blender/collada/CameraExporter.cpp
 | 
					
						
							|  |  |  |  *  \ingroup collada | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 07:13:42 +00:00
										 |  |  | #include <string>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "COLLADASWCamera.h"
 | 
					
						
							|  |  |  | #include "COLLADASWCameraOptic.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_camera_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "CameraExporter.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "collada_internal.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-07 18:23:30 +00:00
										 |  |  | CamerasExporter::CamerasExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): COLLADASW::LibraryCameras(sw), export_settings(export_settings) {} | 
					
						
							| 
									
										
										
										
											2010-10-06 07:13:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | template<class Functor> | 
					
						
							| 
									
										
										
										
											2011-07-04 08:59:28 +00:00
										 |  |  | void forEachCameraObjectInScene(Scene *sce, Functor &f, bool export_selected) | 
					
						
							| 
									
										
										
										
											2010-10-06 07:13:42 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Base *base= (Base*) sce->base.first; | 
					
						
							|  |  |  | 	while(base) { | 
					
						
							|  |  |  | 		Object *ob = base->object; | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2011-07-04 08:59:28 +00:00
										 |  |  | 		if (ob->type == OB_CAMERA && ob->data | 
					
						
							|  |  |  | 			&& !(export_selected && !(ob->flag & SELECT))) { | 
					
						
							| 
									
										
										
										
											2010-10-06 07:13:42 +00:00
										 |  |  | 			f(ob, sce); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		base= base->next; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-07 18:23:30 +00:00
										 |  |  | void CamerasExporter::exportCameras(Scene *sce) | 
					
						
							| 
									
										
										
										
											2010-10-06 07:13:42 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	openLibrary(); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-09-07 18:23:30 +00:00
										 |  |  | 	forEachCameraObjectInScene(sce, *this, this->export_settings->selected); | 
					
						
							| 
									
										
										
										
											2010-10-06 07:13:42 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	closeLibrary(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void CamerasExporter::operator()(Object *ob, Scene *sce) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// TODO: shiftx, shifty, YF_dofdist
 | 
					
						
							|  |  |  | 	Camera *cam = (Camera*)ob->data; | 
					
						
							|  |  |  | 	std::string cam_id(get_camera_id(ob)); | 
					
						
							|  |  |  | 	std::string cam_name(id_name(cam)); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (cam->type == CAM_PERSP) { | 
					
						
							|  |  |  | 		COLLADASW::PerspectiveOptic persp(mSW); | 
					
						
							| 
									
										
										
										
											2011-11-04 14:36:06 +00:00
										 |  |  | 		persp.setXFov(RAD2DEGF(focallength_to_fov(cam->lens, cam->sensor_x)), "xfov"); | 
					
						
							| 
									
										
										
										
											2011-07-07 18:40:46 +00:00
										 |  |  | 		persp.setAspectRatio((float)(sce->r.xsch)/(float)(sce->r.ysch),false,"aspect_ratio"); | 
					
						
							|  |  |  | 		persp.setZFar(cam->clipend, false , "zfar"); | 
					
						
							| 
									
										
										
										
											2011-07-09 19:33:02 +00:00
										 |  |  | 		persp.setZNear(cam->clipsta,false , "znear"); | 
					
						
							| 
									
										
										
										
											2010-10-06 07:13:42 +00:00
										 |  |  | 		COLLADASW::Camera ccam(mSW, &persp, cam_id, cam_name); | 
					
						
							|  |  |  | 		addCamera(ccam); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		COLLADASW::OrthographicOptic ortho(mSW); | 
					
						
							| 
									
										
										
										
											2011-07-06 19:00:40 +00:00
										 |  |  | 		ortho.setXMag(cam->ortho_scale,"xmag"); | 
					
						
							| 
									
										
										
										
											2011-07-07 18:40:46 +00:00
										 |  |  | 		ortho.setAspectRatio((float)(sce->r.xsch)/(float)(sce->r.ysch),false,"aspect_ratio"); | 
					
						
							|  |  |  | 		ortho.setZFar(cam->clipend , false , "zfar"); | 
					
						
							| 
									
										
										
										
											2011-07-09 19:33:02 +00:00
										 |  |  | 		ortho.setZNear(cam->clipsta, false , "znear"); | 
					
						
							| 
									
										
										
										
											2010-10-06 07:13:42 +00:00
										 |  |  | 		COLLADASW::Camera ccam(mSW, &ortho, cam_id, cam_name); | 
					
						
							|  |  |  | 		addCamera(ccam); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }	 |