| 
									
										
										
										
											2011-02-21 08:38:53 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +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-21 08:38:53 +00:00
										 |  |  | /** \file GeometryExporter.h
 | 
					
						
							|  |  |  |  *  \ingroup collada | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | #ifndef __GEOMETRYEXPORTER_H__
 | 
					
						
							|  |  |  | #define __GEOMETRYEXPORTER_H__
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							| 
									
										
										
										
											2010-11-16 22:27:31 +00:00
										 |  |  | #include <set>
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "COLLADASWStreamWriter.h"
 | 
					
						
							|  |  |  | #include "COLLADASWLibraryGeometries.h"
 | 
					
						
							|  |  |  | #include "COLLADASWInputList.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_mesh_types.h"
 | 
					
						
							|  |  |  | #include "DNA_object_types.h"
 | 
					
						
							|  |  |  | #include "DNA_scene_types.h"
 | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | #include "DNA_key_types.h"
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-07 18:23:30 +00:00
										 |  |  | #include "ExportSettings.h"
 | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | #include "collada_utils.h"
 | 
					
						
							| 
									
										
										
										
											2011-09-07 18:23:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | #include "BKE_key.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-12 21:25:29 +00:00
										 |  |  | extern Object *bc_get_highest_selected_ancestor_or_self(Object *ob); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | // TODO: optimize UV sets by making indexed list with duplicates removed
 | 
					
						
							|  |  |  | class GeometryExporter : COLLADASW::LibraryGeometries | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct Face | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		unsigned int v1, v2, v3, v4; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct Normal | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		float x, y, z; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Scene *mScene; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2011-09-07 18:23:30 +00:00
										 |  |  | 	GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-07 18:23:30 +00:00
										 |  |  | 	void exportGeom(Scene *sce); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void operator()(Object *ob); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-16 11:21:03 +00:00
										 |  |  | 	void createLooseEdgeList(Object *ob, | 
					
						
							|  |  |  | 						     Mesh   *me, | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 						     std::string& geom_id); | 
					
						
							| 
									
										
										
										
											2012-05-16 11:21:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	// powerful because it handles both cases when there is material and when there's not
 | 
					
						
							| 
									
										
										
										
											2011-09-20 06:25:15 +00:00
										 |  |  | 	void createPolylist(short material_index, | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 						bool has_uvs, | 
					
						
							|  |  |  | 						bool has_color, | 
					
						
							|  |  |  | 						Object *ob, | 
					
						
							| 
									
										
										
										
											2012-05-07 18:09:59 +00:00
										 |  |  | 						Mesh   *me, | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 						std::string& geom_id, | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 						std::vector<BCPolygonNormalsIndices>& norind); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	// creates <source> for positions
 | 
					
						
							|  |  |  | 	void createVertsSource(std::string geom_id, Mesh *me); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void createVertexColorSource(std::string geom_id, Mesh *me); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-09 23:18:01 +01:00
										 |  |  | 	std::string makeTexcoordSourceId(std::string& geom_id, int layer_index, bool is_single_layer); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//creates <source> for texcoords
 | 
					
						
							|  |  |  | 	void createTexcoordsSource(std::string geom_id, Mesh *me); | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 	void createTesselatedTexcoordsSource(std::string geom_id, Mesh *me); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//creates <source> for normals
 | 
					
						
							|  |  |  | 	void createNormalsSource(std::string geom_id, Mesh *me, std::vector<Normal>& nor); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 	void create_normals(std::vector<Normal> &nor, std::vector<BCPolygonNormalsIndices> &ind, Mesh *me); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-01-27 19:39:06 +00:00
										 |  |  | 	std::string getIdBySemantics(std::string geom_id, COLLADASW::InputSemantic::Semantics type, std::string other_suffix = ""); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-01-27 19:39:06 +00:00
										 |  |  | 	COLLADASW::URI getUrlBySemantics(std::string geom_id, COLLADASW::InputSemantic::Semantics type, std::string other_suffix = ""); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	COLLADASW::URI makeUrl(std::string id); | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 	void export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2010-11-16 22:27:31 +00:00
										 |  |  | private: | 
					
						
							|  |  |  | 	std::set<std::string> exportedGeometry; | 
					
						
							| 
									
										
										
										
											2011-09-07 18:23:30 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	const ExportSettings *export_settings; | 
					
						
							| 
									
										
										
										
											2012-05-07 18:09:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-07 17:55:26 +00:00
										 |  |  | 	Mesh * get_mesh(Scene *sce, Object *ob, int apply_modifiers); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct GeometryFunctor { | 
					
						
							|  |  |  | 	// f should have
 | 
					
						
							| 
									
										
										
										
											2013-03-08 04:00:06 +00:00
										 |  |  | 	// void operator()(Object *ob)
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	template<class Functor> | 
					
						
							| 
									
										
										
										
											2012-06-12 21:25:29 +00:00
										 |  |  | 	void forEachMeshObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set) | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2012-06-12 21:25:29 +00:00
										 |  |  | 		LinkNode *node; | 
					
						
							|  |  |  | 		for (node=export_set; node; node = node->next) { | 
					
						
							|  |  |  | 			Object *ob = (Object *)node->link; | 
					
						
							| 
									
										
										
										
											2012-07-04 20:47:12 +00:00
										 |  |  | 			if (ob->type == OB_MESH) { | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 				f(ob); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |