[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47931] branches/soc-2012-bratwurst/source /blender/assimp: - bf_assimp: basic support for vertex colors.

Alexander Gessler alexander.gessler at gmx.net
Fri Jun 15 03:24:55 CEST 2012


Revision: 47931
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47931
Author:   aramis_acg
Date:     2012-06-15 01:24:51 +0000 (Fri, 15 Jun 2012)
Log Message:
-----------
- bf_assimp: basic support for vertex colors.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.cpp
    branches/soc-2012-bratwurst/source/blender/assimp/bassimp_internal.cpp
    branches/soc-2012-bratwurst/source/blender/assimp/bassimp_internal.h

Modified: branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.cpp	2012-06-15 01:06:14 UTC (rev 47930)
+++ branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.cpp	2012-06-15 01:24:51 UTC (rev 47931)
@@ -292,6 +292,8 @@
 
 	// see how many UV channels we have. This needs to be the same number across all meshes
 	unsigned int uv_count = static_cast<unsigned int>(-1);
+	unsigned int vc_count = static_cast<unsigned int>(-1);
+
 	for (std::vector<const aiMesh*>::const_iterator it = in_meshes.begin(), end = in_meshes.end(); it != end; ++it) {
 		const aiMesh& m = **it;
 		if (uv_count == static_cast<unsigned int>(-1)) {
@@ -303,18 +305,39 @@
 				return;
 			}
 		}
+
+		if (vc_count == static_cast<unsigned int>(-1)) {
+			vc_count = m.GetNumColorChannels();
+		}
+		else {
+			if (m.GetNumColorChannels() != vc_count) {
+				error("unexpected number of vertex color channels, ignoring");
+				return;
+			}
+		}
 	}	
 
+
 	for (unsigned int i = 0; i < uv_count; i++) {		
 		const std::string& s = get_default_uv_channel_name(i);
 		CustomData_add_layer_named(&mesh->fdata, CD_MTFACE, CD_CALLOC, NULL, mesh->totface, s.c_str());
 	}
 
-	// activate the first uv map
+	for (unsigned int i = 0; i < vc_count; i++) {		
+		const std::string& s = get_default_vc_channel_name(i);
+		CustomData_add_layer_named(&mesh->fdata, CD_MCOL, CD_CALLOC, NULL, mesh->totface, s.c_str());
+	}
+
+
+	// activate the first uv and vertex color layers, respectively
 	if (uv_count) {
-		mesh->mtface = (MTFace*)CustomData_get_layer_n(&mesh->fdata, CD_MTFACE, 0);
+		mesh->mtface = static_cast<MTFace*>(CustomData_get_layer_n(&mesh->fdata, CD_MTFACE, 0));	
 	}
 
+	if(vc_count) {
+		mesh->mcol = static_cast<MCol*>(CustomData_get_layer_n(&mesh->fdata, CD_MCOL, 0));	
+	}
+
 	MFace *mface = mesh->mface;
 	unsigned int face_index = 0;
 
@@ -350,6 +373,18 @@
 					}				
 				}
 
+				for (unsigned int k = 0; k < vc_count; k++) {
+					MCol *mcol = static_cast<MCol*>(CustomData_get_layer_n(&mesh->fdata, CD_MCOL, k));
+					for (int j = 0; j < f.mNumIndices; ++j){
+						const aiColor4D& c = m.mColors[k][f.mIndices[j]];
+						MCol& co = mcol[face_index*4+j];
+						co.r = c.r;
+						co.g = c.g;
+						co.b = c.b;
+						co.a = c.a;
+					}				
+				}
+
 				test_index_face(mface, &mesh->fdata, face_index, f.mNumIndices);
 				
 				if (has_normals) {
@@ -387,6 +422,18 @@
 						}				
 					}
 
+					for (unsigned int k = 0; k < vc_count; k++) {
+						MCol *mcol = static_cast<MCol*>(CustomData_get_layer_n(&mesh->fdata, CD_MCOL, k));
+						for (int j = 0; j < f.mNumIndices; ++j){
+							const aiColor4D& c = m.mColors[k][tri_indices[j]];
+							MCol& co = mcol[face_index*4+j];
+							co.r = c.r;
+							co.g = c.g;
+							co.b = c.b;
+							co.a = c.a;
+						}				
+					}
+
 					test_index_face(mface, &mesh->fdata, face_index, 3);
 			
 					if (has_normals) {

Modified: branches/soc-2012-bratwurst/source/blender/assimp/bassimp_internal.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/bassimp_internal.cpp	2012-06-15 01:06:14 UTC (rev 47930)
+++ branches/soc-2012-bratwurst/source/blender/assimp/bassimp_internal.cpp	2012-06-15 01:24:51 UTC (rev 47931)
@@ -50,6 +50,14 @@
 }
 
 
+std::string get_default_vc_channel_name(unsigned int index)
+{
+	std::stringstream ss; 
+	ss << "VertexColorChannel-" << index;
+	return ss.str();
+}
+
+
 // copied from /editors/object/object_relations.c
 int util_test_parent_loop(Object *par, Object *ob)
 {

Modified: branches/soc-2012-bratwurst/source/blender/assimp/bassimp_internal.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/bassimp_internal.h	2012-06-15 01:06:14 UTC (rev 47930)
+++ branches/soc-2012-bratwurst/source/blender/assimp/bassimp_internal.h	2012-06-15 01:24:51 UTC (rev 47931)
@@ -53,6 +53,7 @@
 	Object* util_add_object(Scene *scene, int type, const char *name);
 
 	std::string get_default_uv_channel_name(unsigned int index);
+	std::string get_default_vc_channel_name(unsigned int index);
 }
 
 




More information about the Bf-blender-cvs mailing list