~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/collada/MeshImporter.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-05-12 20:02:22 UTC
  • mfrom: (14.2.16 sid)
  • Revision ID: package-import@ubuntu.com-20120512200222-lznjs2cxzaq96wua
Tags: 2.63a-1
* New upstream bugfix release
  + debian/patches/: re-worked since source code changed

Show diffs side-by-side

added added

removed removed

Lines of Context:
727
727
 
728
728
MeshImporter::MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce) : unitconverter(unitconv), scene(sce), armature_importer(arm) {}
729
729
 
 
730
void MeshImporter::bmeshConversion()
 
731
{
 
732
        for (std::map<COLLADAFW::UniqueId, Mesh*>::iterator m = uid_mesh_map.begin();
 
733
                        m != uid_mesh_map.end(); ++m)
 
734
        {
 
735
                if ((*m).second) {
 
736
                        Mesh *me = (*m).second;
 
737
                        BKE_mesh_convert_mfaces_to_mpolys(me);
 
738
                        BKE_mesh_tessface_clear(me);
 
739
 
 
740
                        mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
 
741
                }
 
742
        }
 
743
}
 
744
 
 
745
 
730
746
Object *MeshImporter::get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid)
731
747
{
732
748
        if (uid_object_map.find(geom_uid) != uid_object_map.end())
839
855
                
840
856
                for (it = prims.begin(); it != prims.end(); it++) {
841
857
                        Primitive& prim = *it;
842
 
                        i = 0;
843
 
                        while (i++ < prim.totface) {
844
 
                                prim.mface->mat_nr = mat_index;
845
 
                                prim.mface++;
 
858
                        MFace *mface = prim.mface;
 
859
 
 
860
                        for (i = 0; i < prim.totface; i++, mface++) {
 
861
                                mface->mat_nr = mat_index;
846
862
                                // bind texture images to faces
847
863
                                if (texture_face && (*color_texture)) {
848
 
                                        texture_face->mode = TF_TEX;
849
864
                                        texture_face->tpage = (Image*)(*color_texture)->tex->ima;
850
865
                                        texture_face++;
851
866
                                }
856
871
        return texture_face;
857
872
}
858
873
 
859
 
 
860
874
Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::InstanceGeometry *geom,
861
875
                                                   bool isController,
862
876
                                                   std::map<COLLADAFW::UniqueId, Material*>& uid_material_map,
885
899
        }
886
900
        if (!uid_mesh_map[*geom_uid]) return NULL;
887
901
        
888
 
        Object *ob = add_object(scene, OB_MESH);
 
902
        // name Object
 
903
        const std::string& id = node->getName().size() ? node->getName() : node->getOriginalId();
 
904
        const char *name = (id.length())? id.c_str(): NULL;
 
905
        
 
906
        // add object
 
907
        Object *ob = bc_add_object(scene, OB_MESH, name);
889
908
 
890
909
        // store object pointer for ArmatureImporter
891
910
        uid_object_map[*geom_uid] = ob;
892
911
        
893
 
        // name Object
894
 
        const std::string& id = node->getName().size() ? node->getName() : node->getOriginalId();
895
 
        if (id.length())
896
 
                rename_id(&ob->id, (char*)id.c_str());
897
 
        
898
912
        // replace ob->data freeing the old one
899
913
        Mesh *old_mesh = (Mesh*)ob->data;
900
914
 
922
936
                        fprintf(stderr, "invalid referenced material for %s\n", mat_array[i].getName().c_str());
923
937
                }
924
938
        }
925
 
                
 
939
 
926
940
        return ob;
927
941
}
928
942
 
949
963
        
950
964
        const std::string& str_geom_id = mesh->getName().size() ? mesh->getName() : mesh->getOriginalId();
951
965
        Mesh *me = add_mesh((char*)str_geom_id.c_str());
 
966
        me->id.us--; // is already 1 here, but will be set later in set_mesh
952
967
 
953
968
        // store the Mesh pointer to link it later with an Object
954
969
        this->uid_mesh_map[mesh->getUniqueId()] = me;
963
978
 
964
979
        make_edges(me, 0);
965
980
 
966
 
        mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
967
 
 
968
 
        BKE_mesh_convert_mfaces_to_mpolys(me);
969
981
        return true;
970
982
}