Fix #31258: collada now selects newly added objects after import.

This commit is contained in:
Brecht Van Lommel
2012-05-03 21:32:49 +00:00
parent 552a70f177
commit b075765edd
12 changed files with 70 additions and 30 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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()];

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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);