| 
									
										
										
										
											2011-02-23 10:52:22 +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-27 20:30:35 +00:00
										 |  |  | /** \file blender/collada/GeometryExporter.cpp
 | 
					
						
							|  |  |  |  *  \ingroup collada | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 22:51:02 +00:00
										 |  |  | #include <sstream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | #include "COLLADASWPrimitves.h"
 | 
					
						
							|  |  |  | #include "COLLADASWSource.h"
 | 
					
						
							|  |  |  | #include "COLLADASWVertices.h"
 | 
					
						
							|  |  |  | #include "COLLADABUUtils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "GeometryExporter.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_meshdata_types.h"
 | 
					
						
							| 
									
										
										
										
											2012-05-07 18:09:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							| 
									
										
										
										
											2012-11-01 15:34:38 +00:00
										 |  |  | 	#include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | 	#include "BKE_DerivedMesh.h"
 | 
					
						
							| 
									
										
										
										
											2012-05-07 18:09:59 +00:00
										 |  |  | 	#include "BKE_main.h"
 | 
					
						
							|  |  |  | 	#include "BKE_global.h"
 | 
					
						
							|  |  |  | 	#include "BKE_library.h"
 | 
					
						
							| 
									
										
										
										
											2012-08-12 17:13:07 +00:00
										 |  |  | 	#include "BKE_customdata.h"
 | 
					
						
							|  |  |  | 	#include "BKE_material.h"
 | 
					
						
							|  |  |  | 	#include "BKE_mesh.h"
 | 
					
						
							| 
									
										
										
										
											2012-05-07 18:09:59 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | #include "collada_internal.h"
 | 
					
						
							| 
									
										
										
										
											2012-06-07 17:55:26 +00:00
										 |  |  | #include "collada_utils.h"
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // TODO: optimize UV sets by making indexed list with duplicates removed
 | 
					
						
							| 
									
										
										
										
											2013-02-10 17:06:05 +00:00
										 |  |  | GeometryExporter::GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryGeometries(sw), export_settings(export_settings) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-16 12:45:11 +10:00
										 |  |  | void GeometryExporter::exportGeom(const struct EvaluationContext *eval_ctx, Scene *sce) | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	openLibrary(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-21 17:44:11 +02:00
										 |  |  | 	mEvalCtx = eval_ctx; | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	mScene = sce; | 
					
						
							|  |  |  | 	GeometryFunctor gf; | 
					
						
							| 
									
										
										
										
											2012-06-12 21:25:29 +00:00
										 |  |  | 	gf.forEachMeshObjectInExportSet<GeometryExporter>(sce, *this, this->export_settings->export_set); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	closeLibrary(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GeometryExporter::operator()(Object *ob) | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | {  | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	// XXX don't use DerivedMesh, Mesh instead?
 | 
					
						
							|  |  |  | #if 0		
 | 
					
						
							|  |  |  | 	DerivedMesh *dm = mesh_get_derived_final(mScene, ob, CD_MASK_BAREMESH); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-05-07 18:09:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-26 22:46:28 +00:00
										 |  |  | 	bool use_instantiation = this->export_settings->use_object_instantiation; | 
					
						
							| 
									
										
										
										
											2017-07-21 17:44:11 +02:00
										 |  |  | 	Mesh *me = bc_get_mesh_copy(mEvalCtx, mScene,  | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 					ob, | 
					
						
							|  |  |  | 					this->export_settings->export_mesh_type, | 
					
						
							|  |  |  | 					this->export_settings->apply_modifiers, | 
					
						
							|  |  |  | 					this->export_settings->triangulate); | 
					
						
							| 
									
										
										
										
											2012-02-24 21:15:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-26 22:46:28 +00:00
										 |  |  | 	std::string geom_id = get_geometry_id(ob, use_instantiation); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	std::vector<Normal> nor; | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 	std::vector<BCPolygonNormalsIndices> norind; | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-16 22:27:31 +00:00
										 |  |  | 	// Skip if linked geometry was already exported from another reference
 | 
					
						
							| 
									
										
										
										
											2012-05-26 22:46:28 +00:00
										 |  |  | 	if (use_instantiation &&  | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | 	    exportedGeometry.find(geom_id) != exportedGeometry.end()) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-11-16 22:27:31 +00:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-05-26 22:46:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	std::string geom_name = (use_instantiation) ? id_name(ob->data) : id_name(ob); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-16 22:27:31 +00:00
										 |  |  | 	exportedGeometry.insert(geom_id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	bool has_color = (bool)CustomData_has_layer(&me->fdata, CD_MCOL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	create_normals(nor, norind, me); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// openMesh(geoId, geoName, meshId)
 | 
					
						
							| 
									
										
										
										
											2012-02-02 10:34:44 +00:00
										 |  |  | 	openMesh(geom_id, geom_name); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	// writes <source> for vertex coords
 | 
					
						
							|  |  |  | 	createVertsSource(geom_id, me); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// writes <source> for normal coords
 | 
					
						
							|  |  |  | 	createNormalsSource(geom_id, me, nor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool has_uvs = (bool)CustomData_has_layer(&me->fdata, CD_MTFACE); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// writes <source> for uv coords if mesh has uv coords
 | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 	if (has_uvs) { | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 		createTexcoordsSource(geom_id, me); | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 	if (has_color) { | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 		createVertexColorSource(geom_id, me); | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	// <vertices>
 | 
					
						
							| 
									
										
										
										
											2012-05-16 11:21:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	COLLADASW::Vertices verts(mSW); | 
					
						
							| 
									
										
										
										
											2011-01-27 19:39:06 +00:00
										 |  |  | 	verts.setId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX)); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	COLLADASW::InputList &input_list = verts.getInputList(); | 
					
						
							| 
									
										
										
										
											2011-01-27 19:39:06 +00:00
										 |  |  | 	COLLADASW::Input input(COLLADASW::InputSemantic::POSITION, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::POSITION)); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	input_list.push_back(input); | 
					
						
							|  |  |  | 	verts.add(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 	createLooseEdgeList(ob, me, geom_id); | 
					
						
							| 
									
										
										
										
											2012-05-16 11:21:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-12 18:26:01 +00:00
										 |  |  | 	// Only create Polylists if number of faces > 0
 | 
					
						
							|  |  |  | 	if (me->totface > 0) { | 
					
						
							|  |  |  | 		// XXX slow
 | 
					
						
							|  |  |  | 		if (ob->totcol) { | 
					
						
							|  |  |  | 			for (int a = 0; a < ob->totcol; a++) { | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 				createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind); | 
					
						
							| 
									
										
										
										
											2012-09-12 18:26:01 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 			createPolylist(0, has_uvs, has_color, ob, me, geom_id, norind); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	closeMesh(); | 
					
						
							| 
									
										
										
										
											2011-03-23 00:19:38 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (me->flag & ME_TWOSIDED) { | 
					
						
							|  |  |  | 		mSW->appendTextBlock("<extra><technique profile=\"MAYA\"><double_sided>1</double_sided></technique></extra>"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-05-16 11:21:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	closeGeometry(); | 
					
						
							| 
									
										
										
										
											2012-05-07 18:09:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | 	if (this->export_settings->include_shapekeys) { | 
					
						
							|  |  |  | 		Key * key = BKE_key_from_object(ob); | 
					
						
							| 
									
										
										
										
											2013-02-10 17:06:05 +00:00
										 |  |  | 		if (key) { | 
					
						
							| 
									
										
										
										
											2013-03-18 11:44:56 +00:00
										 |  |  | 			KeyBlock * kb = (KeyBlock *)key->block.first; | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | 			//skip the basis
 | 
					
						
							|  |  |  | 			kb = kb->next; | 
					
						
							|  |  |  | 			for (; kb; kb = kb->next) { | 
					
						
							| 
									
										
										
										
											2014-11-16 19:15:23 +01:00
										 |  |  | 				BKE_keyblock_convert_to_mesh(kb, me); | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 				export_key_mesh(ob, me, kb); | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-15 19:15:51 +01:00
										 |  |  | 	BKE_libblock_free_us(G.main, me); | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | void GeometryExporter::export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb) | 
					
						
							| 
									
										
										
										
											2013-02-10 17:06:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | 	std::string geom_id = get_geometry_id(ob, false) + "_morph_" + translate_id(kb->name); | 
					
						
							|  |  |  | 	std::vector<Normal> nor; | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 	std::vector<BCPolygonNormalsIndices> norind; | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (exportedGeometry.find(geom_id) != exportedGeometry.end()) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-12 17:52:18 +00:00
										 |  |  | 	std::string geom_name = kb->name; | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	exportedGeometry.insert(geom_id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool has_color = (bool)CustomData_has_layer(&me->fdata, CD_MCOL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	create_normals(nor, norind, me); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// openMesh(geoId, geoName, meshId)
 | 
					
						
							|  |  |  | 	openMesh(geom_id, geom_name); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// writes <source> for vertex coords
 | 
					
						
							|  |  |  | 	createVertsSource(geom_id, me); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// writes <source> for normal coords
 | 
					
						
							|  |  |  | 	createNormalsSource(geom_id, me, nor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool has_uvs = (bool)CustomData_has_layer(&me->fdata, CD_MTFACE); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// writes <source> for uv coords if mesh has uv coords
 | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 	if (has_uvs) { | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | 		createTexcoordsSource(geom_id, me); | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 	if (has_color) { | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | 		createVertexColorSource(geom_id, me); | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// <vertices>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	COLLADASW::Vertices verts(mSW); | 
					
						
							|  |  |  | 	verts.setId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX)); | 
					
						
							|  |  |  | 	COLLADASW::InputList &input_list = verts.getInputList(); | 
					
						
							|  |  |  | 	COLLADASW::Input input(COLLADASW::InputSemantic::POSITION, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::POSITION)); | 
					
						
							|  |  |  | 	input_list.push_back(input); | 
					
						
							|  |  |  | 	verts.add(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//createLooseEdgeList(ob, me, geom_id, norind);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// XXX slow		
 | 
					
						
							|  |  |  | 	if (ob->totcol) { | 
					
						
							|  |  |  | 		for (int a = 0; a < ob->totcol; a++) { | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 			createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind); | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 		createPolylist(0, has_uvs, has_color, ob, me, geom_id, norind); | 
					
						
							| 
									
										
										
										
											2013-01-21 13:45:49 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	closeMesh(); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (me->flag & ME_TWOSIDED) { | 
					
						
							|  |  |  | 		mSW->appendTextBlock("<extra><technique profile=\"MAYA\"><double_sided>1</double_sided></technique></extra>"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	closeGeometry(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-05-16 11:21:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void GeometryExporter::createLooseEdgeList(Object *ob, | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  |                                            Mesh   *me, | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  |                                            std::string& geom_id) | 
					
						
							| 
									
										
										
										
											2012-05-16 11:21:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MEdge *medges = me->medge; | 
					
						
							|  |  |  | 	int totedges  = me->totedge; | 
					
						
							|  |  |  | 	int edges_in_linelist = 0; | 
					
						
							|  |  |  | 	std::vector<unsigned int> edge_list; | 
					
						
							|  |  |  | 	int index; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Find all loose edges in Mesh 
 | 
					
						
							|  |  |  | 	// and save vertex indices in edge_list
 | 
					
						
							|  |  |  | 	for (index = 0; index < totedges; index++)  | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		MEdge *edge = &medges[index]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (edge->flag & ME_LOOSEEDGE) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			edges_in_linelist += 1; | 
					
						
							|  |  |  | 			edge_list.push_back(edge->v1); | 
					
						
							|  |  |  | 			edge_list.push_back(edge->v2); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (edges_in_linelist > 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		// Create the list of loose edges
 | 
					
						
							|  |  |  | 		COLLADASW::Lines lines(mSW); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		lines.setCount(edges_in_linelist); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		COLLADASW::InputList &til = lines.getInputList(); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 		// creates <input> in <lines> for vertices 
 | 
					
						
							|  |  |  | 		COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0); | 
					
						
							|  |  |  | 		til.push_back(input1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		lines.prepareToAppendValues(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (index = 0; index < edges_in_linelist; index++)  | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | 			lines.appendValues(edge_list[2 * index + 1]); | 
					
						
							|  |  |  | 			lines.appendValues(edge_list[2 * index]); | 
					
						
							| 
									
										
										
										
											2012-05-16 11:21:03 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		lines.finish(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-01 14:52:10 +02:00
										 |  |  | std::string GeometryExporter::makeVertexColorSourceId(std::string& geom_id, char *layer_name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	std::string result = getIdBySemantics(geom_id, COLLADASW::InputSemantic::COLOR) + "-" + layer_name; | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 GeometryExporter::createPolylist(short material_index, | 
					
						
							| 
									
										
										
										
											2013-02-27 13:53:43 +00:00
										 |  |  |                                       bool has_uvs, | 
					
						
							|  |  |  |                                       bool has_color, | 
					
						
							|  |  |  |                                       Object *ob, | 
					
						
							|  |  |  |                                       Mesh *me, | 
					
						
							|  |  |  |                                       std::string& geom_id, | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  |                                       std::vector<BCPolygonNormalsIndices>& norind) | 
					
						
							| 
									
										
										
										
											2013-02-27 13:53:43 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MPoly *mpolys = me->mpoly; | 
					
						
							|  |  |  | 	MLoop *mloops = me->mloop; | 
					
						
							|  |  |  | 	int totpolys  = me->totpoly; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// <vcount>
 | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	int faces_in_polylist = 0; | 
					
						
							|  |  |  | 	std::vector<unsigned long> vcount_list; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// count faces with this material
 | 
					
						
							|  |  |  | 	for (i = 0; i < totpolys; i++) { | 
					
						
							|  |  |  | 		MPoly *p = &mpolys[i]; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (p->mat_nr == material_index) { | 
					
						
							|  |  |  | 			faces_in_polylist++; | 
					
						
							|  |  |  | 			vcount_list.push_back(p->totloop); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// no faces using this material
 | 
					
						
							|  |  |  | 	if (faces_in_polylist == 0) { | 
					
						
							|  |  |  | 		fprintf(stderr, "%s: material with index %d is not used.\n", id_name(ob).c_str(), material_index); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	Material *ma = ob->totcol ? give_current_material(ob, material_index + 1) : NULL; | 
					
						
							|  |  |  | 	COLLADASW::Polylist polylist(mSW); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	// sets count attribute in <polylist>
 | 
					
						
							|  |  |  | 	polylist.setCount(faces_in_polylist); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	// sets material name
 | 
					
						
							|  |  |  | 	if (ma) { | 
					
						
							|  |  |  | 		std::string material_id = get_material_id(ma); | 
					
						
							|  |  |  | 		std::ostringstream ostr; | 
					
						
							|  |  |  | 		ostr << translate_id(material_id); | 
					
						
							|  |  |  | 		polylist.setMaterial(ostr.str()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 	COLLADASW::InputList &til = polylist.getInputList(); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	// creates <input> in <polylist> for vertices 
 | 
					
						
							|  |  |  | 	COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	// creates <input> in <polylist> for normals
 | 
					
						
							|  |  |  | 	COLLADASW::Input input2(COLLADASW::InputSemantic::NORMAL, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL), 1); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	til.push_back(input1); | 
					
						
							|  |  |  | 	til.push_back(input2); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	// if mesh has uv coords writes <input> for TEXCOORD
 | 
					
						
							|  |  |  | 	int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE); | 
					
						
							|  |  |  | 	int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE)-1; | 
					
						
							|  |  |  | 	for (i = 0; i < num_layers; i++) { | 
					
						
							|  |  |  | 		if (!this->export_settings->active_uv_only || i == active_uv_index) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// char *name = CustomData_get_layer_name(&me->fdata, CD_MTFACE, i);
 | 
					
						
							|  |  |  | 			COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD, | 
					
						
							| 
									
										
										
										
											2013-12-09 23:18:01 +01:00
										 |  |  | 									makeUrl(makeTexcoordSourceId(geom_id, i, this->export_settings->active_uv_only)), | 
					
						
							|  |  |  | 									2, // this is only until we have optimized UV sets
 | 
					
						
							|  |  |  | 									(this->export_settings->active_uv_only) ? 0 : i  // only_active_uv exported -> we have only one set
 | 
					
						
							| 
									
										
										
										
											2013-02-27 13:53:43 +00:00
										 |  |  | 									); | 
					
						
							|  |  |  | 			til.push_back(input3); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-01 14:52:10 +02:00
										 |  |  | 	int totlayer_mcol = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL); | 
					
						
							|  |  |  | 	if (totlayer_mcol > 0) { | 
					
						
							|  |  |  | 		int map_index = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int a = 0; a < totlayer_mcol; a++) { | 
					
						
							|  |  |  | 			char *layer_name = bc_CustomData_get_layer_name(&me->ldata, CD_MLOOPCOL, a); | 
					
						
							|  |  |  | 			COLLADASW::Input input4(COLLADASW::InputSemantic::COLOR, | 
					
						
							|  |  |  | 			                        makeUrl(makeVertexColorSourceId(geom_id, layer_name)), | 
					
						
							|  |  |  | 			                        (has_uvs) ? 3 : 2,  // all color layers have same index order
 | 
					
						
							|  |  |  | 			                        map_index           // set number equals color map index
 | 
					
						
							|  |  |  | 			                        ); | 
					
						
							|  |  |  | 			til.push_back(input4); | 
					
						
							|  |  |  | 			map_index++; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-02-27 13:53:43 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	// sets <vcount>
 | 
					
						
							|  |  |  | 	polylist.setVCountList(vcount_list); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	// performs the actual writing
 | 
					
						
							|  |  |  | 	polylist.prepareToAppendValues(); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// <p>
 | 
					
						
							|  |  |  | 	int texindex = 0; | 
					
						
							|  |  |  | 	for (i = 0; i < totpolys; i++) { | 
					
						
							|  |  |  | 		MPoly *p = &mpolys[i]; | 
					
						
							|  |  |  | 		int loop_count = p->totloop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (p->mat_nr == material_index) { | 
					
						
							|  |  |  | 			MLoop *l = &mloops[p->loopstart]; | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 			BCPolygonNormalsIndices normal_indices = norind[i]; | 
					
						
							| 
									
										
										
										
											2013-02-27 13:53:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			for (int j = 0; j < loop_count; j++) { | 
					
						
							|  |  |  | 				polylist.appendValues(l[j].v); | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 				polylist.appendValues(normal_indices[j]); | 
					
						
							| 
									
										
										
										
											2013-02-27 13:53:43 +00:00
										 |  |  | 				if (has_uvs) | 
					
						
							|  |  |  | 					polylist.appendValues(texindex + j); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (has_color) | 
					
						
							|  |  |  | 					polylist.appendValues(texindex + j); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		texindex += loop_count; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	polylist.finish(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | // creates <source> for positions
 | 
					
						
							|  |  |  | void GeometryExporter::createVertsSource(std::string geom_id, Mesh *me) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 	int totverts = dm->getNumVerts(dm); | 
					
						
							|  |  |  | 	MVert *verts = dm->getVertArray(dm); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	int totverts = me->totvert; | 
					
						
							|  |  |  | 	MVert *verts = me->mvert; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	COLLADASW::FloatSourceF source(mSW); | 
					
						
							| 
									
										
										
										
											2011-01-27 19:39:06 +00:00
										 |  |  | 	source.setId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::POSITION)); | 
					
						
							|  |  |  | 	source.setArrayId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::POSITION) + | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | 	                  ARRAY_ID_SUFFIX); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	source.setAccessorCount(totverts); | 
					
						
							|  |  |  | 	source.setAccessorStride(3); | 
					
						
							| 
									
										
										
										
											2014-05-01 14:52:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList(); | 
					
						
							|  |  |  | 	param.push_back("X"); | 
					
						
							|  |  |  | 	param.push_back("Y"); | 
					
						
							|  |  |  | 	param.push_back("Z"); | 
					
						
							| 
									
										
										
										
											2012-10-04 13:26:15 +00:00
										 |  |  | 	/* main function, it creates <source id = "">, <float_array id = ""
 | 
					
						
							|  |  |  | 	 * count = ""> */ | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	source.prepareToAppendValues(); | 
					
						
							|  |  |  | 	//appends data to <float_array>
 | 
					
						
							|  |  |  | 	int i = 0; | 
					
						
							|  |  |  | 	for (i = 0; i < totverts; i++) { | 
					
						
							| 
									
										
										
										
											2012-10-21 05:46:41 +00:00
										 |  |  | 		source.appendValues(verts[i].co[0], verts[i].co[1], verts[i].co[2]); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	source.finish(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-01 14:52:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | void GeometryExporter::createVertexColorSource(std::string geom_id, Mesh *me) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-01 14:52:10 +02:00
										 |  |  | 	/* Find number of vertex color layers */ | 
					
						
							|  |  |  | 	int totlayer_mcol = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL); | 
					
						
							|  |  |  | 	if (totlayer_mcol == 0) | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-01 14:52:10 +02:00
										 |  |  | 	int map_index = 0; | 
					
						
							|  |  |  | 	for (int a = 0; a < totlayer_mcol; a++) { | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-01 14:52:10 +02:00
										 |  |  | 		map_index++; | 
					
						
							|  |  |  | 		MLoopCol *mloopcol = (MLoopCol *)CustomData_get_layer_n(&me->ldata, CD_MLOOPCOL, a); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-01 14:52:10 +02:00
										 |  |  | 		COLLADASW::FloatSourceF source(mSW); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-01 14:52:10 +02:00
										 |  |  | 		char *layer_name = bc_CustomData_get_layer_name(&me->ldata, CD_MLOOPCOL, a); | 
					
						
							|  |  |  | 		std::string layer_id = makeVertexColorSourceId(geom_id, layer_name); | 
					
						
							|  |  |  | 		source.setId(layer_id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		source.setNodeName(layer_name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		source.setArrayId(layer_id + ARRAY_ID_SUFFIX); | 
					
						
							|  |  |  | 		source.setAccessorCount(me->totloop); | 
					
						
							| 
									
										
										
										
											2017-09-29 18:12:14 +10:00
										 |  |  | 		source.setAccessorStride(4); | 
					
						
							| 
									
										
										
										
											2014-05-01 14:52:10 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList(); | 
					
						
							|  |  |  | 		param.push_back("R"); | 
					
						
							|  |  |  | 		param.push_back("G"); | 
					
						
							|  |  |  | 		param.push_back("B"); | 
					
						
							| 
									
										
										
										
											2017-09-29 18:12:14 +10:00
										 |  |  | 		param.push_back("A"); | 
					
						
							| 
									
										
										
										
											2014-05-01 14:52:10 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		source.prepareToAppendValues(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		MPoly *mpoly; | 
					
						
							|  |  |  | 		int i; | 
					
						
							|  |  |  | 		for (i = 0, mpoly = me->mpoly; i < me->totpoly; i++, mpoly++) { | 
					
						
							|  |  |  | 			MLoopCol *mlc = mloopcol + mpoly->loopstart; | 
					
						
							|  |  |  | 			for (int j = 0; j < mpoly->totloop; j++, mlc++) { | 
					
						
							|  |  |  | 				source.appendValues( | 
					
						
							| 
									
										
										
										
											2017-09-29 18:12:14 +10:00
										 |  |  | 						mlc->r / 255.0f, | 
					
						
							|  |  |  | 						mlc->g / 255.0f, | 
					
						
							|  |  |  | 						mlc->b / 255.0f, | 
					
						
							|  |  |  | 						mlc->a / 255.0f | 
					
						
							| 
									
										
										
										
											2014-05-01 14:52:10 +02:00
										 |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-03-04 13:12:56 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2014-05-01 14:52:10 +02:00
										 |  |  | 		source.finish(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-09 23:18:01 +01:00
										 |  |  | std::string GeometryExporter::makeTexcoordSourceId(std::string& geom_id, int layer_index, bool is_single_layer) | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char suffix[20]; | 
					
						
							| 
									
										
										
										
											2013-12-09 23:18:01 +01:00
										 |  |  | 	if (is_single_layer) { | 
					
						
							|  |  |  | 		suffix[0] = '\0'; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		sprintf(suffix, "-%d", layer_index); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-01-27 19:39:06 +00:00
										 |  |  | 	return getIdBySemantics(geom_id, COLLADASW::InputSemantic::TEXCOORD) + suffix; | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //creates <source> for texcoords
 | 
					
						
							|  |  |  | void GeometryExporter::createTexcoordsSource(std::string geom_id, Mesh *me) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 	int totpoly   = me->totpoly; | 
					
						
							|  |  |  | 	int totuv     = me->totloop; | 
					
						
							|  |  |  | 	MPoly *mpolys = me->mpoly; | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 	int num_layers = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// write <source> for each layer
 | 
					
						
							|  |  |  | 	// each <source> will get id like meshName + "map-channel-1"
 | 
					
						
							| 
									
										
										
										
											2015-05-30 14:18:35 +02:00
										 |  |  | 	int active_uv_index = CustomData_get_active_layer_index(&me->ldata, CD_MLOOPUV); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	for (int a = 0; a < num_layers; a++) { | 
					
						
							| 
									
										
										
										
											2015-05-30 14:18:35 +02:00
										 |  |  | 		int layer_index = CustomData_get_layer_index_n(&me->ldata, CD_MLOOPUV, a); | 
					
						
							|  |  |  | 		if (!this->export_settings->active_uv_only || layer_index == active_uv_index) { | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 			MLoopUV *mloops = (MLoopUV *)CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, a); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-06-22 16:16:58 +00:00
										 |  |  | 			COLLADASW::FloatSourceF source(mSW); | 
					
						
							| 
									
										
										
										
											2013-12-09 23:18:01 +01:00
										 |  |  | 			std::string layer_id = makeTexcoordSourceId(geom_id, a, this->export_settings->active_uv_only); | 
					
						
							| 
									
										
										
										
											2012-06-22 16:16:58 +00:00
										 |  |  | 			source.setId(layer_id); | 
					
						
							|  |  |  | 			source.setArrayId(layer_id + ARRAY_ID_SUFFIX); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			source.setAccessorCount(totuv); | 
					
						
							|  |  |  | 			source.setAccessorStride(2); | 
					
						
							|  |  |  | 			COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList(); | 
					
						
							|  |  |  | 			param.push_back("S"); | 
					
						
							|  |  |  | 			param.push_back("T"); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			source.prepareToAppendValues(); | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2013-03-02 15:58:13 +00:00
										 |  |  | 			for (int index = 0; index < totpoly; index++) { | 
					
						
							|  |  |  | 				MPoly   *mpoly = mpolys+index; | 
					
						
							|  |  |  | 				MLoopUV *mloop = mloops+mpoly->loopstart; | 
					
						
							|  |  |  | 				for (int j = 0; j < mpoly->totloop; j++) { | 
					
						
							|  |  |  | 					source.appendValues(mloop[j].uv[0], | 
					
						
							|  |  |  | 										mloop[j].uv[1]); | 
					
						
							| 
									
										
										
										
											2012-06-22 16:16:58 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-06-22 16:16:58 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			source.finish(); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-16 19:02:00 +02:00
										 |  |  | bool operator<(const Normal &a, const Normal &b) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* only needed to sort normal vectors and find() them later in a map.*/ | 
					
						
							|  |  |  | 	return a.x < b.x || (a.x == b.x && (a.y < b.y || (a.y == b.y && a.z < b.z))); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //creates <source> for normals
 | 
					
						
							|  |  |  | void GeometryExporter::createNormalsSource(std::string geom_id, Mesh *me, std::vector<Normal>& nor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 	int totverts = dm->getNumVerts(dm); | 
					
						
							|  |  |  | 	MVert *verts = dm->getVertArray(dm); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	COLLADASW::FloatSourceF source(mSW); | 
					
						
							| 
									
										
										
										
											2011-01-27 19:39:06 +00:00
										 |  |  | 	source.setId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL)); | 
					
						
							|  |  |  | 	source.setArrayId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL) + | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | 	                  ARRAY_ID_SUFFIX); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	source.setAccessorCount((unsigned long)nor.size()); | 
					
						
							|  |  |  | 	source.setAccessorStride(3); | 
					
						
							|  |  |  | 	COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList(); | 
					
						
							|  |  |  | 	param.push_back("X"); | 
					
						
							|  |  |  | 	param.push_back("Y"); | 
					
						
							|  |  |  | 	param.push_back("Z"); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	source.prepareToAppendValues(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	std::vector<Normal>::iterator it; | 
					
						
							|  |  |  | 	for (it = nor.begin(); it != nor.end(); it++) { | 
					
						
							|  |  |  | 		Normal& n = *it; | 
					
						
							|  |  |  | 		source.appendValues(n.x, n.y, n.z); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	source.finish(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | void GeometryExporter::create_normals(std::vector<Normal> &normals, std::vector<BCPolygonNormalsIndices> &polygons_normals, Mesh *me) | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-04-16 19:02:00 +02:00
										 |  |  | 	std::map<Normal, unsigned int> shared_normal_indices; | 
					
						
							| 
									
										
										
										
											2013-03-04 00:17:20 +00:00
										 |  |  | 	int last_normal_index = -1; | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-04 00:17:20 +00:00
										 |  |  | 	MVert *verts  = me->mvert; | 
					
						
							|  |  |  | 	MLoop *mloops = me->mloop; | 
					
						
							| 
									
										
										
										
											2015-05-11 17:22:18 +02:00
										 |  |  | 	float(*lnors)[3] = NULL; | 
					
						
							| 
									
										
										
										
											2015-05-06 17:03:24 +02:00
										 |  |  | 	bool use_custom_normals = false; | 
					
						
							| 
									
										
										
										
											2015-04-16 19:02:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BKE_mesh_calc_normals_split(me); | 
					
						
							|  |  |  | 	if (CustomData_has_layer(&me->ldata, CD_NORMAL)) { | 
					
						
							|  |  |  | 		lnors = (float(*)[3])CustomData_get_layer(&me->ldata, CD_NORMAL); | 
					
						
							| 
									
										
										
										
											2015-05-06 17:03:24 +02:00
										 |  |  | 		use_custom_normals = true; | 
					
						
							| 
									
										
										
										
											2015-04-16 19:02:00 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 	for (int poly_index = 0; poly_index < me->totpoly; poly_index++) { | 
					
						
							|  |  |  | 		MPoly *mpoly  = &me->mpoly[poly_index]; | 
					
						
							| 
									
										
										
										
											2015-05-06 17:03:24 +02:00
										 |  |  | 		bool use_vertex_normals = use_custom_normals || mpoly->flag & ME_SMOOTH; | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-06 17:03:24 +02:00
										 |  |  | 		if (!use_vertex_normals) { | 
					
						
							| 
									
										
										
										
											2013-03-04 00:17:20 +00:00
										 |  |  | 			// For flat faces use face normal as vertex normal:
 | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			float vector[3]; | 
					
						
							| 
									
										
										
										
											2013-04-25 13:28:32 +00:00
										 |  |  | 			BKE_mesh_calc_poly_normal(mpoly, mloops+mpoly->loopstart, verts, vector); | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			Normal n = { vector[0], vector[1], vector[2] }; | 
					
						
							|  |  |  | 			normals.push_back(n); | 
					
						
							|  |  |  | 			last_normal_index++; | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 		BCPolygonNormalsIndices poly_indices; | 
					
						
							|  |  |  | 		for (int loop_index = 0; loop_index < mpoly->totloop; loop_index++) { | 
					
						
							| 
									
										
										
										
											2015-04-16 19:02:00 +02:00
										 |  |  | 			unsigned int loop_idx = mpoly->loopstart + loop_index; | 
					
						
							| 
									
										
										
										
											2015-05-06 17:03:24 +02:00
										 |  |  | 			if (use_vertex_normals) { | 
					
						
							| 
									
										
										
										
											2015-04-16 19:02:00 +02:00
										 |  |  | 				float normalized[3]; | 
					
						
							| 
									
										
										
										
											2015-05-11 17:22:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				if (use_custom_normals) { | 
					
						
							|  |  |  | 					normalize_v3_v3(normalized, lnors[loop_idx]); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							|  |  |  | 					normal_short_to_float_v3(normalized, verts[mloops[loop_index].v].no); | 
					
						
							|  |  |  | 					normalize_v3(normalized); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-04-16 19:02:00 +02:00
										 |  |  | 				Normal n = { normalized[0], normalized[1], normalized[2] }; | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-16 19:02:00 +02:00
										 |  |  | 				if (shared_normal_indices.find(n) != shared_normal_indices.end()) { | 
					
						
							|  |  |  | 					poly_indices.add_index(shared_normal_indices[n]); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 					last_normal_index++; | 
					
						
							|  |  |  | 					poly_indices.add_index(last_normal_index); | 
					
						
							| 
									
										
										
										
											2015-04-16 19:02:00 +02:00
										 |  |  | 					shared_normal_indices[n] = last_normal_index; | 
					
						
							|  |  |  | 					normals.push_back(n); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 				poly_indices.add_index(last_normal_index); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-03 13:53:32 +00:00
										 |  |  | 		polygons_normals.push_back(poly_indices); | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-25 16:49:59 +00:00
										 |  |  | std::string GeometryExporter::getIdBySemantics(std::string geom_id, COLLADASW::InputSemantic::Semantics type, std::string other_suffix) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	return geom_id + getSuffixBySemantic(type) + other_suffix; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-25 16:49:59 +00:00
										 |  |  | COLLADASW::URI GeometryExporter::getUrlBySemantics(std::string geom_id, COLLADASW::InputSemantic::Semantics type, std::string other_suffix) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-06 09:53:06 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	std::string id(getIdBySemantics(geom_id, type, other_suffix)); | 
					
						
							|  |  |  | 	return COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, id); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | COLLADASW::URI GeometryExporter::makeUrl(std::string id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, id); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |