From: Mikko Rasa Date: Fri, 24 May 2019 15:43:19 +0000 (+0300) Subject: Allow tagging objects in a scene file for retrieval after loading X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=d5c26741ed3952dd54c8a7f43ad42ba79bf2d977 Allow tagging objects in a scene file for retrieval after loading --- diff --git a/blender/io_mspgl/export_scene.py b/blender/io_mspgl/export_scene.py index 3b2147d1..9b36c48f 100644 --- a/blender/io_mspgl/export_scene.py +++ b/blender/io_mspgl/export_scene.py @@ -108,7 +108,7 @@ class SceneExporter: for o in objs: obj_res = resources[prototypes[o.name].name+".object"] - st = scene_res.create_reference_statement("object", obj_res) + st = scene_res.create_reference_statement("object", obj_res, o.name) # XXX Parent relationships screw up the location and rotation st.sub.append(Statement("position", o.location[0], o.location[1], o.location[2])) if o.rotation_mode=="AXIS_ANGLE": diff --git a/source/scene.cpp b/source/scene.cpp index ef1f246b..e6c62e80 100644 --- a/source/scene.cpp +++ b/source/scene.cpp @@ -75,16 +75,37 @@ bool Scene::frustum_cull(const Renderable &renderable) const Scene::Loader::Loader(Scene &s, Collection &c): - DataFile::CollectionObjectLoader(s, &c) + DataFile::CollectionObjectLoader(s, &c), + content(0) +{ + init(); +} + +Scene::Loader::Loader(Scene &s, Collection &c, ContentMap &m): + DataFile::CollectionObjectLoader(s, &c), + content(&m) +{ + init(); +} + +void Scene::Loader::init() { add("object", &Loader::object); + add("object", &Loader::object_tagged); } void Scene::Loader::object(const string &n) +{ + object_tagged(n, string()); +} + +void Scene::Loader::object_tagged(const string &n, const string &t) { RefPtr anob = new AnimatedObject(get_collection().get(n)); load_sub(*anob); obj.add(*anob); + if(content && !t.empty()) + (*content)[t] = anob.get(); obj.owned_data.push_back(anob.release()); } diff --git a/source/scene.h b/source/scene.h index 9e90b128..639a467f 100644 --- a/source/scene.h +++ b/source/scene.h @@ -21,13 +21,23 @@ public: class Loader: public DataFile::CollectionObjectLoader { public: - Loader(Scene &, Collection &); + typedef std::map ContentMap; + + private: + ContentMap *content; + public: + Loader(Scene &, Collection &); + Loader(Scene &, Collection &, ContentMap &); private: + void init(); + void object(const std::string &); + void object_tagged(const std::string &, const std::string &); }; protected: + // XXX If a loaded renderable is removed from the scene it needs to be removed from here as well std::vector owned_data; mutable Matrix culling_matrix; mutable Vector4 frustum_edges[6];