Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2012-05-04 01:32:49 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2012-05-04 01:32:49 +0400
commitb075765edd9e8f18b088faf1a55358d0f8a289cd (patch)
tree8e47cac0528e5448741c88b3e4b6cfe62c0183fc /source
parent552a70f1774dcb197739281968aab58cf887fd83 (diff)
Fix #31258: collada now selects newly added objects after import.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_object.h1
-rw-r--r--source/blender/blenkernel/intern/object.c6
-rw-r--r--source/blender/blenkernel/intern/scene.c2
-rw-r--r--source/blender/collada/AnimationImporter.cpp4
-rw-r--r--source/blender/collada/ArmatureImporter.cpp4
-rw-r--r--source/blender/collada/DocumentImporter.cpp19
-rw-r--r--source/blender/collada/MeshImporter.cpp42
-rw-r--r--source/blender/collada/MeshImporter.h2
-rw-r--r--source/blender/collada/SkinInfo.cpp2
-rw-r--r--source/blender/collada/collada_utils.cpp15
-rw-r--r--source/blender/collada/collada_utils.h2
-rw-r--r--source/blender/editors/mesh/mesh_navmesh.c1
12 files changed, 70 insertions, 30 deletions
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 4fced71d7f2..2e334c4abc9 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -80,6 +80,7 @@ int exist_object(struct Object *obtest);
struct Object *add_only_object(int type, const char *name);
struct Object *add_object(struct Scene *scene, int type);
+void *add_obdata_from_type(int type);
struct Object *copy_object(struct Object *ob);
void make_local_object(struct Object *ob);
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 2cfacbcf034..280a8fdc2b2 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -747,7 +747,7 @@ int exist_object(Object *obtest)
/* *************************************************** */
-static void *add_obdata_from_type(int type)
+void *add_obdata_from_type(int type)
{
switch (type) {
case OB_MESH: return add_mesh("Mesh");
@@ -792,6 +792,9 @@ Object *add_only_object(int type, const char *name)
{
Object *ob;
+ if(!name)
+ name = get_obdata_defname(type);
+
ob= alloc_libblock(&G.main->object, ID_OB, name);
/* default object vars */
@@ -880,6 +883,7 @@ Object *add_object(struct Scene *scene, int type)
ob->lay= scene->lay;
base= scene_add_base(scene, ob);
+ scene_deselect_all(scene);
scene_select_base(scene, base);
ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 864260833a6..c8f41f26c9b 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -888,8 +888,6 @@ void scene_deselect_all(Scene *sce)
void scene_select_base(Scene *sce, Base *selbase)
{
- scene_deselect_all(sce);
-
selbase->flag |= SELECT;
selbase->object->flag= selbase->flag;
diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp
index cf815920b57..a72d51721ce 100644
--- a/source/blender/collada/AnimationImporter.cpp
+++ b/source/blender/collada/AnimationImporter.cpp
@@ -1770,9 +1770,7 @@ bool AnimationImporter::calc_joint_parent_mat_rest(float mat[4][4], float par[4]
Object *AnimationImporter::get_joint_object(COLLADAFW::Node *root, COLLADAFW::Node *node, Object *par_job)
{
if (joint_objects.find(node->getUniqueId()) == joint_objects.end()) {
- Object *job = add_object(scene, OB_EMPTY);
-
- rename_id((ID*)&job->id, (char*)get_joint_name(node));
+ Object *job = bc_add_object(scene, OB_EMPTY, (char*)get_joint_name(node));
job->lay = object_in_scene(job, scene)->lay = 2;
diff --git a/source/blender/collada/ArmatureImporter.cpp b/source/blender/collada/ArmatureImporter.cpp
index 833904e20c2..4316edf1e67 100644
--- a/source/blender/collada/ArmatureImporter.cpp
+++ b/source/blender/collada/ArmatureImporter.cpp
@@ -367,7 +367,7 @@ Object *ArmatureImporter::get_empty_for_leaves()
{
if (empty) return empty;
- empty = add_object(scene, OB_EMPTY);
+ empty = bc_add_object(scene, OB_EMPTY, NULL);
empty->empty_drawtype = OB_EMPTY_SPHERE;
return empty;
@@ -412,7 +412,7 @@ void ArmatureImporter::create_armature_bones( )
if ( get_armature_for_joint(*ri) != NULL ) continue;
//add armature object for current joint
- //Object *ob_arm = add_object(scene, OB_ARMATURE);
+ //Object *ob_arm = bc_add_object(scene, OB_ARMATURE, NULL);
Object *ob_arm = joint_parent_map[(*ri)->getUniqueId()];
diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp
index a1f69ef16bd..c793453227a 100644
--- a/source/blender/collada/DocumentImporter.cpp
+++ b/source/blender/collada/DocumentImporter.cpp
@@ -121,6 +121,9 @@ bool DocumentImporter::import()
loader.registerExtraDataCallbackHandler(ehandler);
+ // deselect all to select new objects
+ scene_deselect_all(CTX_data_scene(mContext));
+
if (!root.loadDocument(mFilename)) {
fprintf(stderr, "COLLADAFW::Root::loadDocument() returned false on 1st pass\n");
return false;
@@ -144,6 +147,8 @@ bool DocumentImporter::import()
delete ehandler;
+ mesh_importer.bmeshConversion();
+
return true;
}
@@ -157,7 +162,9 @@ void DocumentImporter::cancel(const COLLADAFW::String& errorMessage)
// The latter sounds better.
}
-void DocumentImporter::start() {}
+void DocumentImporter::start()
+{
+}
void DocumentImporter::finish()
{
@@ -298,7 +305,8 @@ Object* DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera
fprintf(stderr, "Couldn't find camera by UID.\n");
return NULL;
}
- Object *ob = add_object(sce, OB_CAMERA);
+
+ Object *ob = bc_add_object(sce, OB_CAMERA, NULL);
Camera *cam = uid_camera_map[cam_uid];
Camera *old_cam = (Camera*)ob->data;
ob->data = cam;
@@ -315,7 +323,8 @@ Object* DocumentImporter::create_lamp_object(COLLADAFW::InstanceLight *lamp, Sce
fprintf(stderr, "Couldn't find lamp by UID.\n");
return NULL;
}
- Object *ob = add_object(sce, OB_LAMP);
+
+ Object *ob = bc_add_object(sce, OB_LAMP, NULL);
Lamp *la = uid_lamp_map[lamp_uid];
Lamp *old_lamp = (Lamp*)ob->data;
ob->data = la;
@@ -398,7 +407,7 @@ void DocumentImporter::write_node (COLLADAFW::Node *node, COLLADAFW::Node *paren
if (is_joint) {
if ( par ) {
Object * empty = par;
- par = add_object(sce, OB_ARMATURE);
+ par = bc_add_object(sce, OB_ARMATURE, NULL);
bc_set_parent(par, empty->parent, mContext);
//remove empty : todo
object_map.insert(std::make_pair<COLLADAFW::UniqueId, Object *>(parent_node->getUniqueId(), par));
@@ -465,7 +474,7 @@ void DocumentImporter::write_node (COLLADAFW::Node *node, COLLADAFW::Node *paren
// if node is empty - create empty object
// XXX empty node may not mean it is empty object, not sure about this
if ( (geom_done + camera_done + lamp_done + controller_done + inst_done) < 1) {
- ob = add_object(sce, OB_EMPTY);
+ ob = bc_add_object(sce, OB_EMPTY, NULL);
objects_done->push_back(ob);
}
diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp
index 3fbd33bdd0b..ba6be75e051 100644
--- a/source/blender/collada/MeshImporter.cpp
+++ b/source/blender/collada/MeshImporter.cpp
@@ -727,6 +727,22 @@ bool MeshImporter::flat_face(unsigned int *nind, COLLADAFW::MeshVertexData& nor,
MeshImporter::MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce) : unitconverter(unitconv), scene(sce), armature_importer(arm) {}
+void MeshImporter::bmeshConversion()
+{
+ for (std::map<COLLADAFW::UniqueId, Mesh*>::iterator m = uid_mesh_map.begin();
+ m != uid_mesh_map.end(); ++m)
+ {
+ if ((*m).second) {
+ Mesh *me = (*m).second;
+ BKE_mesh_convert_mfaces_to_mpolys(me);
+ BKE_mesh_tessface_clear(me);
+
+ mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
+ }
+ }
+}
+
+
Object *MeshImporter::get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid)
{
if (uid_object_map.find(geom_uid) != uid_object_map.end())
@@ -839,10 +855,10 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri
for (it = prims.begin(); it != prims.end(); it++) {
Primitive& prim = *it;
- i = 0;
- while (i++ < prim.totface) {
- prim.mface->mat_nr = mat_index;
- prim.mface++;
+ MFace *mface = prim.mface;
+
+ for (i = 0; i < prim.totface; i++, mface++) {
+ mface->mat_nr = mat_index;
// bind texture images to faces
if (texture_face && (*color_texture)) {
texture_face->tpage = (Image*)(*color_texture)->tex->ima;
@@ -855,7 +871,6 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri
return texture_face;
}
-
Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::InstanceGeometry *geom,
bool isController,
std::map<COLLADAFW::UniqueId, Material*>& uid_material_map,
@@ -884,16 +899,16 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta
}
if (!uid_mesh_map[*geom_uid]) return NULL;
- Object *ob = add_object(scene, OB_MESH);
+ // name Object
+ const std::string& id = node->getName().size() ? node->getName() : node->getOriginalId();
+ const char *name = (id.length())? id.c_str(): NULL;
+
+ // add object
+ Object *ob = bc_add_object(scene, OB_MESH, name);
// store object pointer for ArmatureImporter
uid_object_map[*geom_uid] = ob;
- // name Object
- const std::string& id = node->getName().size() ? node->getName() : node->getOriginalId();
- if (id.length())
- rename_id(&ob->id, (char*)id.c_str());
-
// replace ob->data freeing the old one
Mesh *old_mesh = (Mesh*)ob->data;
@@ -963,10 +978,5 @@ bool MeshImporter::write_geometry(const COLLADAFW::Geometry* geom)
make_edges(me, 0);
- BKE_mesh_convert_mfaces_to_mpolys(me);
- BKE_mesh_tessface_clear(me);
-
- mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
-
return true;
}
diff --git a/source/blender/collada/MeshImporter.h b/source/blender/collada/MeshImporter.h
index 0c2e600121f..97ae4d99ad7 100644
--- a/source/blender/collada/MeshImporter.h
+++ b/source/blender/collada/MeshImporter.h
@@ -129,6 +129,8 @@ public:
MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce);
+ void bmeshConversion();
+
virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid);
MTex *assign_textures_to_uvlayer(COLLADAFW::TextureCoordinateBinding &ctexture,
diff --git a/source/blender/collada/SkinInfo.cpp b/source/blender/collada/SkinInfo.cpp
index 99a4f024f77..0727ec21682 100644
--- a/source/blender/collada/SkinInfo.cpp
+++ b/source/blender/collada/SkinInfo.cpp
@@ -151,7 +151,7 @@ void SkinInfo::set_controller(const COLLADAFW::SkinController* co)
// called from write_controller
Object *SkinInfo::create_armature(Scene *scene)
{
- ob_arm = add_object(scene, OB_ARMATURE);
+ ob_arm = bc_add_object(scene, OB_ARMATURE, NULL);
return ob_arm;
}
diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp
index 4aed29defbc..bd0f82fb0ac 100644
--- a/source/blender/collada/collada_utils.cpp
+++ b/source/blender/collada/collada_utils.cpp
@@ -34,6 +34,7 @@
#include "DNA_customdata_types.h"
#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
#include "BLI_math.h"
@@ -41,6 +42,7 @@
#include "BKE_customdata.h"
#include "BKE_depsgraph.h"
#include "BKE_object.h"
+#include "BKE_scene.h"
#include "WM_api.h" // XXX hrm, see if we can do without this
#include "WM_types.h"
@@ -110,3 +112,16 @@ int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space)
return true;
}
+Object *bc_add_object(Scene *scene, int type, const char *name)
+{
+ Object *ob = add_only_object(type, name);
+
+ ob->data= add_obdata_from_type(type);
+ ob->lay= scene->lay;
+ ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
+
+ scene_select_base(scene, scene_add_base(scene, ob));
+
+ return ob;
+}
+
diff --git a/source/blender/collada/collada_utils.h b/source/blender/collada/collada_utils.h
index b0c24152652..1f5d2b1d8da 100644
--- a/source/blender/collada/collada_utils.h
+++ b/source/blender/collada/collada_utils.h
@@ -39,6 +39,7 @@
#include "DNA_customdata_types.h"
#include "DNA_texture_types.h"
#include "BKE_context.h"
+#include "DNA_scene_types.h"
typedef std::map<COLLADAFW::TextureMapId, std::vector<MTex*> > TexIndexTextureArrayMap;
@@ -48,5 +49,6 @@ extern int bc_test_parent_loop(Object *par, Object *ob);
extern int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space=true);
extern char *bc_CustomData_get_layer_name(const CustomData *data, int type, int n);
extern char *bc_CustomData_get_active_layer_name(const CustomData *data, int type);
+extern Object *bc_add_object(Scene *scene, int type, const char *name);
#endif
diff --git a/source/blender/editors/mesh/mesh_navmesh.c b/source/blender/editors/mesh/mesh_navmesh.c
index c234cf44aec..cc640e38fc2 100644
--- a/source/blender/editors/mesh/mesh_navmesh.c
+++ b/source/blender/editors/mesh/mesh_navmesh.c
@@ -316,6 +316,7 @@ static Object *createRepresentation(bContext *C, struct recast_polyMesh *pmesh,
}
else {
obedit = base->object;
+ scene_deselect_all(scene);
scene_select_base(scene, base);
copy_v3_v3(obedit->loc, co);
copy_v3_v3(obedit->rot, rot);