Changeset View
Changeset View
Standalone View
Standalone View
source/blender/collada/MeshImporter.cpp
| Show First 20 Lines • Show All 870 Lines • ▼ Show 20 Lines | if (this->mesh_geom_map.find(mesh_name) != this->mesh_geom_map.end()) | ||||
| return &this->mesh_geom_map[mesh_name]; | return &this->mesh_geom_map[mesh_name]; | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /** | /** | ||||
| * this function checks if both objects have the same | * this function checks if both objects have the same | ||||
| * materials assigned to Object (in the same order) | * materials assigned to Object (in the same order) | ||||
| * returns true if condition matches, otherwise false; | * returns true if condition matches, otherwise false; | ||||
| **/ | */ | ||||
| static bool bc_has_same_material_configuration(Object *ob1, Object *ob2) | static bool bc_has_same_material_configuration(Object *ob1, Object *ob2) | ||||
| { | { | ||||
| if (ob1->totcol != ob2->totcol) return false; // not same number of materials | if (ob1->totcol != ob2->totcol) return false; // not same number of materials | ||||
| if (ob1->totcol == 0) return false; // no material at all | if (ob1->totcol == 0) return false; // no material at all | ||||
| for (int index=0; index < ob1->totcol; index++) { | for (int index=0; index < ob1->totcol; index++) { | ||||
| if (ob1->matbits[index] != ob2->matbits[index]) return false; // shouldn't happen | if (ob1->matbits[index] != ob2->matbits[index]) return false; // shouldn't happen | ||||
| if (ob1->matbits[index] == 0) return false; // shouldn't happen | if (ob1->matbits[index] == 0) return false; // shouldn't happen | ||||
| if (ob1->mat[index] != ob2->mat[index]) return false; // different material assignment | if (ob1->mat[index] != ob2->mat[index]) return false; // different material assignment | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| /** | /** | ||||
| * | * | ||||
| * Caution here: This code assumes that all materials are assigned to Object | * Caution here: This code assumes that all materials are assigned to Object | ||||
| * and no material is assigned to Data. | * and no material is assigned to Data. | ||||
| * That is true right after the objects have been imported. | * That is true right after the objects have been imported. | ||||
| * | * | ||||
| **/ | */ | ||||
| static void bc_copy_materials_to_data(Object *ob, Mesh *me) | static void bc_copy_materials_to_data(Object *ob, Mesh *me) | ||||
| { | { | ||||
| for (int index = 0; index < ob->totcol; index++) { | for (int index = 0; index < ob->totcol; index++) { | ||||
| ob->matbits[index] = 0; | ob->matbits[index] = 0; | ||||
| me->mat[index] = ob->mat[index]; | me->mat[index] = ob->mat[index]; | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * | * | ||||
| * Remove all references to materials from the object | * Remove all references to materials from the object | ||||
| * | * | ||||
| **/ | */ | ||||
| static void bc_remove_materials_from_object(Object *ob, Mesh *me) | static void bc_remove_materials_from_object(Object *ob, Mesh *me) | ||||
| { | { | ||||
| for (int index = 0; index < ob->totcol; index++) { | for (int index = 0; index < ob->totcol; index++) { | ||||
| ob->matbits[index] = 0; | ob->matbits[index] = 0; | ||||
| ob->mat[index] = NULL; | ob->mat[index] = NULL; | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Returns the list of Users of the given Mesh object. | * Returns the list of Users of the given Mesh object. | ||||
| * Note: This function uses the object user flag to control | * Note: This function uses the object user flag to control | ||||
| * which objects have already been processed. | * which objects have already been processed. | ||||
| **/ | */ | ||||
| std::vector<Object *> MeshImporter::get_all_users_of(Mesh *reference_mesh) | std::vector<Object *> MeshImporter::get_all_users_of(Mesh *reference_mesh) | ||||
| { | { | ||||
| std::vector<Object *> mesh_users; | std::vector<Object *> mesh_users; | ||||
| for (std::vector<Object *>::iterator it = imported_objects.begin(); | for (std::vector<Object *>::iterator it = imported_objects.begin(); | ||||
| it != imported_objects.end(); ++it) | it != imported_objects.end(); ++it) | ||||
| { | { | ||||
| Object *ob = (*it); | Object *ob = (*it); | ||||
| if (bc_is_marked(ob)) { | if (bc_is_marked(ob)) { | ||||
| Show All 18 Lines | |||||
| * move the materials from Object to Data | * move the materials from Object to Data | ||||
| * else: | * else: | ||||
| * determine which materials are assigned to the first user | * determine which materials are assigned to the first user | ||||
| * check if all other users have the same materials in the same order | * check if all other users have the same materials in the same order | ||||
| * if the check is positive: | * if the check is positive: | ||||
| * Add the materials of the first user to the geometry | * Add the materials of the first user to the geometry | ||||
| * adjust all other users accordingly. | * adjust all other users accordingly. | ||||
| * | * | ||||
| **/ | */ | ||||
| void MeshImporter::optimize_material_assignements() | void MeshImporter::optimize_material_assignements() | ||||
| { | { | ||||
| for (std::vector<Object *>::iterator it = imported_objects.begin(); | for (std::vector<Object *>::iterator it = imported_objects.begin(); | ||||
| it != imported_objects.end(); ++it) | it != imported_objects.end(); ++it) | ||||
| { | { | ||||
| Object *ob = (*it); | Object *ob = (*it); | ||||
| Mesh *me = (Mesh *) ob->data; | Mesh *me = (Mesh *) ob->data; | ||||
| if (me->id.us==1) { | if (me->id.us==1) { | ||||
| ▲ Show 20 Lines • Show All 191 Lines • Show Last 20 Lines | |||||