Revision: 47973
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47973
Author:   aramis_acg
Date:     2012-06-15 18:15:27 +0000 (Fri, 15 Jun 2012)
Log Message:
-----------
- bf_assimp: support singular lines in meshes. Code for this is based on 
Collada.

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

Modified: branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.cpp  
2012-06-15 17:57:39 UTC (rev 47972)
+++ branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.cpp  
2012-06-15 18:15:27 UTC (rev 47973)
@@ -475,7 +475,6 @@
                        }
                }
        }
-
 }
 
 void MeshImporter::assign_textures_to_face(const MFace& fac, MTFace& tfac, 
unsigned int assimp_mat_id, unsigned int uv_index)
@@ -488,6 +487,88 @@
 }
 
 
+unsigned int MeshImporter::count_lines()
+{
+       unsigned int count = 0;
+       for (std::vector<const aiMesh*>::const_iterator it = in_meshes.begin(), 
end = in_meshes.end(); it != end; ++it) {
+               const aiMesh& m = **it;
+
+               for (unsigned int i = 0; i < m.mNumFaces; ++i) {
+
+                       const aiFace& f = m.mFaces[i];
+                       if (f.mNumIndices == 2) {
+                               ++count;
+                       }
+               }
+       }
+
+       return count;
+}
+
+void MeshImporter::mesh_add_edges(unsigned int len)
+{
+       if (!len) {
+               return;
+       }
+
+       CustomData edata;
+       MEdge *medge;
+       int i, totedge;
+
+       totedge = mesh->totedge + len;
+
+       /* update customdata  */
+       CustomData_copy(&mesh->edata, &edata, CD_MASK_MESH, CD_DEFAULT, 
totedge);
+       CustomData_copy_data(&mesh->edata, &edata, 0, 0, mesh->totedge);
+
+       if (!CustomData_has_layer(&edata, CD_MEDGE)) {
+               CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, NULL, 
totedge);
+       }
+
+       CustomData_free(&mesh->edata, mesh->totedge);
+       mesh->edata = edata;
+       mesh_update_customdata_pointers(mesh, FALSE); /* new edges don't change 
tessellation */
+
+       /* set default flags */
+       medge = &mesh->medge[mesh->totedge];
+       for (i = 0; i < len; i++, medge++) {
+               medge->flag = ME_EDGEDRAW | ME_EDGERENDER | SELECT;
+       }
+       mesh->totedge = totedge;
+}
+
+
+void MeshImporter::convert_lines()
+{
+       const unsigned int loose_edge_count = count_lines();
+       if (loose_edge_count > 0) {
+
+               const unsigned int face_edge_count  = mesh->totedge;
+               const unsigned int total_edge_count = loose_edge_count + 
face_edge_count;
+
+               mesh_add_edges(loose_edge_count);
+               MEdge *med = mesh->medge + face_edge_count;
+
+               for (std::vector<const aiMesh*>::const_iterator it = 
in_meshes.begin(), end = in_meshes.end(); it != end; ++it) {
+                       const aiMesh& m = **it;
+
+                       for (unsigned int i = 0; i < m.mNumFaces; ++i) {
+                               const aiFace& f = m.mFaces[i];
+                               if (f.mNumIndices == 2) {
+                                       med->bweight = 0;
+                                       med->crease  = 0;
+                                       med->flag    = 0;
+                                       med->v1      = f.mIndices[0];
+                                       med->v2      = f.mIndices[1];
+
+                                       ++med;
+                               }
+                       }
+               }
+       }
+}
+
+
 // initiate the conversion from aiMesh to BlenMesh.
 void MeshImporter::convert()
 {
@@ -495,6 +576,9 @@
        convert_faces();
 
        BKE_mesh_make_edges(mesh, 0);
+
+       // so far we ignored all lines, now add them to the final mesh
+       convert_lines();
 }
 
 }

Modified: branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.h    
2012-06-15 17:57:39 UTC (rev 47972)
+++ branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.h    
2012-06-15 18:15:27 UTC (rev 47973)
@@ -61,6 +61,12 @@
        void convert_vertices();
        void convert_faces();
 
+       void convert_lines();
+       void mesh_add_edges(unsigned int len);
+
+       // count line primitives contained in the mesh(es)
+       unsigned int count_lines();
+
        // count extra tris added by polygon triangulation
        unsigned int count_new_tris();
 

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to