patch #31794 Collada: make exporter more robust, now uses BKE_object_relational_super...
authorGaia Clary <gaia.clary@machinimatrix.org>
Tue, 12 Jun 2012 21:25:29 +0000 (21:25 +0000)
committerGaia Clary <gaia.clary@machinimatrix.org>
Tue, 12 Jun 2012 21:25:29 +0000 (21:25 +0000)
25 files changed:
source/blender/collada/AnimationExporter.cpp
source/blender/collada/AnimationImporter.h
source/blender/collada/ArmatureExporter.cpp
source/blender/collada/CameraExporter.cpp
source/blender/collada/CameraExporter.h
source/blender/collada/DocumentExporter.cpp
source/blender/collada/DocumentExporter.h
source/blender/collada/DocumentImporter.cpp
source/blender/collada/EffectExporter.cpp
source/blender/collada/ExportSettings.h
source/blender/collada/GeometryExporter.cpp
source/blender/collada/GeometryExporter.h
source/blender/collada/ImageExporter.cpp
source/blender/collada/LightExporter.cpp
source/blender/collada/MaterialExporter.cpp
source/blender/collada/MaterialExporter.h
source/blender/collada/SceneExporter.cpp
source/blender/collada/collada.cpp
source/blender/collada/collada.h
source/blender/collada/collada_internal.cpp
source/blender/collada/collada_internal.h
source/blender/collada/collada_utils.cpp
source/blender/collada/collada_utils.h
source/blender/makesrna/intern/rna_scene_api.c
source/blender/windowmanager/intern/wm_operators.c

index 5898d5da670a67ada0ee7640ccdd6c73651432ad..beb098ba0fc0bf071e5112fe3b4236ba232b7cdf 100644 (file)
 #include "MaterialExporter.h"
 
 template<class Functor>
-void forEachObjectInScene(Scene *sce, Functor &f)
+void forEachObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
 {
-       Base *base= (Base*) sce->base.first;
-
-       while (base) {
-               Object *ob = base->object;
-
+       LinkNode *node;
+       for(node=export_set; node; node=node->next) {
+               Object *ob = (Object *)node->link;
                f(ob);
-
-               base= base->next;
        }
 }
 
@@ -45,7 +41,7 @@ void AnimationExporter::exportAnimations(Scene *sce)
 
                openLibrary();
 
-               forEachObjectInScene(sce, *this);
+               forEachObjectInExportSet(sce, *this, this->export_settings->export_set);
 
                closeLibrary();
        }
index 6324853d91c80d837b2e1881f70dbe3fe56a3249..d6a93a36c6e9c7498b7b5d2ccc1126a56ce9142b 100644 (file)
 #include "COLLADAFWEffect.h"
 #include "COLLADAFWInstanceGeometry.h"
 
+extern "C" {
 #include "DNA_anim_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_lamp_types.h"
 #include "DNA_camera_types.h"
+}
 
 //#include "ArmatureImporter.h"
 #include "TransformReader.h"
index 107a3fc5796752f63572543be19ca0d96510c756..e5548acadb54c89a08963a7d8cc2c8735acc294c 100644 (file)
@@ -112,7 +112,7 @@ void ArmatureExporter::export_controllers(Scene *sce)
        openLibrary();
 
        GeometryFunctor gf;
-       gf.forEachMeshObjectInScene<ArmatureExporter>(sce, *this, this->export_settings->selected);
+       gf.forEachMeshObjectInExportSet<ArmatureExporter>(sce, *this, this->export_settings->export_set);
 
        closeLibrary();
 }
index ce46c681c8cb4299db86f704c2159942c65b1dd1..4e7f2f0434fea248ebaf84bc892b574774ae6b7b 100644 (file)
 #include <string>
 
 #include "COLLADASWCamera.h"
-#include "COLLADASWCameraOptic.h"
 
+extern "C" {
 #include "DNA_camera_types.h"
-
+}
 #include "CameraExporter.h"
 
 #include "collada_internal.h"
 CamerasExporter::CamerasExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): COLLADASW::LibraryCameras(sw), export_settings(export_settings) {}
 
 template<class Functor>
-void forEachCameraObjectInScene(Scene *sce, Functor &f, bool export_selected)
+void forEachCameraObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
 {
-       Base *base = (Base*) sce->base.first;
-       while (base) {
-               Object *ob = base->object;
+       LinkNode *node;
+       for(node=export_set; node; node = node->next) {
+               Object *ob = (Object *)node->link;
 
-               if (ob->type == OB_CAMERA && ob->data && !(export_selected && !(ob->flag & SELECT))) {
+               if (ob->type == OB_CAMERA && ob->data) {
                        f(ob, sce);
                }
-               base = base->next;
        }
 }
 
@@ -57,7 +56,7 @@ void CamerasExporter::exportCameras(Scene *sce)
 {
        openLibrary();
        
-       forEachCameraObjectInScene(sce, *this, this->export_settings->selected);
+       forEachCameraObjectInExportSet(sce, *this, this->export_settings->export_set);
        
        closeLibrary();
 }
index 1b5898984bacb9818c2b14b3e24b4d0bf112ab1a..5405df8ab9ea37e354213027b8f34364a7fee255 100644 (file)
 #include "COLLADASWStreamWriter.h"
 #include "COLLADASWLibraryCameras.h"
 
+extern "C" {
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
+}
 
 #include "ExportSettings.h"
 
index e224ffce731072803aaf15dada7d9c722a692546..4e84eba500cc9ffdf6dfcfbd51485cdbb1ce0563 100644 (file)
@@ -111,7 +111,8 @@ extern char build_rev[];
 
 #include "collada_internal.h"
 #include "DocumentExporter.h"
-#include "ExportSettings.h"
+
+extern bool bc_has_object_type(LinkNode *export_set, short obtype);
 
 // can probably go after refactor is complete
 #include "InstanceWriter.h"
@@ -227,14 +228,15 @@ void DocumentExporter::exportCurrentScene(Scene *sce)
        asset.getContributor().mAuthoringTool = version_buf;
        asset.add();
        
+       LinkNode *export_set = this->export_settings->export_set;
        // <library_cameras>
-       if (has_object_type(sce, OB_CAMERA)) {
+       if (bc_has_object_type(export_set, OB_CAMERA)) {
                CamerasExporter ce(&sw, this->export_settings);
                ce.exportCameras(sce);
        }
        
        // <library_lights>
-       if (has_object_type(sce, OB_LAMP)) {
+       if (bc_has_object_type(export_set, OB_LAMP)) {
                LightsExporter le(&sw, this->export_settings);
                le.exportLights(sce);
        }
@@ -252,7 +254,7 @@ void DocumentExporter::exportCurrentScene(Scene *sce)
        me.exportMaterials(sce);
 
        // <library_geometries>
-       if (has_object_type(sce, OB_MESH)) {
+       if (bc_has_object_type(export_set, OB_MESH)) {
                GeometryExporter ge(&sw, this->export_settings);
                ge.exportGeom(sce);
        }
@@ -263,10 +265,8 @@ void DocumentExporter::exportCurrentScene(Scene *sce)
 
        // <library_controllers>
        ArmatureExporter arm_exporter(&sw, this->export_settings);
-       if (this->export_settings->include_armatures) {
-               if (has_object_type(sce, OB_ARMATURE)) {
-                       arm_exporter.export_controllers(sce);
-               }
+       if (bc_has_object_type(export_set, OB_ARMATURE)) {
+               arm_exporter.export_controllers(sce);
        }
 
        // <library_visual_scenes>
index 314ba2868e5f00beafc22104d3046fde1bc55625..05620087d76afbc2ef494021206e33e22be7faad 100644 (file)
 
 #include "ExportSettings.h"
 
+extern "C" {
+#include "DNA_customdata_types.h"
+}
+
 struct Scene;
 
 class DocumentExporter
index 6dca7828cc21d95e49debaf60d0eacc3272bca2e..fa85e7527ff0c5aa756e702e71381851d82bae3a 100644 (file)
@@ -49,6 +49,7 @@
 #include "COLLADASaxFWLLoader.h"
 #include "COLLADASaxFWLIExtraDataCallbackHandler.h"
 
+extern "C" {
 #include "BLI_listbase.h"
 #include "BLI_math.h"
 #include "BLI_string.h"
@@ -75,6 +76,8 @@
 
 #include "MEM_guardedalloc.h"
 
+}
+
 #include "ExtraHandler.h"
 #include "ErrorHandler.h"
 #include "DocumentImporter.h"
index 36ed68675255286859b839bcbb003a0c46b7baa7..644c350e8fe98a888c6390aee67c89c68128657c 100644 (file)
@@ -31,6 +31,7 @@
 #include "COLLADASWEffectProfile.h"
 
 #include "EffectExporter.h"
+#include "DocumentExporter.h"
 #include "MaterialExporter.h"
 
 #include "DNA_mesh_types.h"
@@ -82,7 +83,7 @@ void EffectsExporter::exportEffects(Scene *sce)
                this->scene = sce;
                openLibrary();
                MaterialFunctor mf;
-               mf.forEachMaterialInScene<EffectsExporter>(sce, *this, this->export_settings->selected);
+               mf.forEachMaterialInExportSet<EffectsExporter>(sce, *this, this->export_settings->export_set);
 
                closeLibrary();
        }
index a6ae29bf2b2796e118046acd1d6cd4cace266eb0..97ea687385630df6d1d21b2343c5db456edd17a4 100644 (file)
  *  \ingroup collada
  */
 
+extern "C" {
+#include "BLI_linklist.h"
+}
+
 #ifndef __EXPORTSETTINGS_H__
 #define __EXPORTSETTINGS_H__
 
@@ -33,10 +37,11 @@ struct ExportSettings
  bool selected;
  bool apply_modifiers;
  bool include_armatures;
- bool include_bone_children;
+ bool include_children;
  bool use_object_instantiation;
  bool second_life;
  char *filepath;
+ LinkNode *export_set;
 };
 
 #endif
index 53d7f1e64497d2d153f078f042fa126165875d48..bc06de4d56b98a16afe2332413c6b6997b7ba2d1 100644 (file)
@@ -61,7 +61,7 @@ void GeometryExporter::exportGeom(Scene *sce)
 
        mScene = sce;
        GeometryFunctor gf;
-       gf.forEachMeshObjectInScene<GeometryExporter>(sce, *this, this->export_settings->selected);
+       gf.forEachMeshObjectInExportSet<GeometryExporter>(sce, *this, this->export_settings->export_set);
 
        closeLibrary();
 }
index 23cdcc0a5ba1db5306dedea95f1639c519e7dd2a..f14775b9f440517769dcf53de883668983af5a6c 100644 (file)
@@ -42,6 +42,8 @@
 
 #include "ExportSettings.h"
 
+extern Object *bc_get_highest_selected_ancestor_or_self(Object *ob);
+
 // TODO: optimize UV sets by making indexed list with duplicates removed
 class GeometryExporter : COLLADASW::LibraryGeometries
 {
@@ -112,21 +114,15 @@ struct GeometryFunctor {
        // f should have
        // void operator()(Object* ob)
        template<class Functor>
-       void forEachMeshObjectInScene(Scene *sce, Functor &f, bool export_selected)
+       void forEachMeshObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
        {
-               
-               Base *base= (Base*) sce->base.first;
-               while (base) {
-                       Object *ob = base->object;
-                       
-                       if (ob->type == OB_MESH && ob->data &&
-                           !(export_selected && !(ob->flag & SELECT)) &&
-                           ((sce->lay & ob->lay)!=0))
+               LinkNode *node;
+               for (node=export_set; node; node = node->next) {
+                       Object *ob = (Object *)node->link;
+                       if (ob->type == OB_MESH)
                        {
                                f(ob);
                        }
-                       base= base->next;
-                       
                }
        }
 };
index 4d7c56ab4197d60572ad9bfcee3511b0f10cd1af..1999c68307efb3fd53a25c606289b8d28cf23c8a 100644 (file)
@@ -73,7 +73,7 @@ void ImagesExporter::exportImages(Scene *sce)
        if (hasImages(sce)) {
                openLibrary();
                MaterialFunctor mf;
-               mf.forEachMaterialInScene<ImagesExporter>(sce, *this, this->export_settings->selected);
+               mf.forEachMaterialInExportSet<ImagesExporter>(sce, *this, this->export_settings->export_set);
 
                closeLibrary();
        }
index 6d276cd782f840d57b03bad2c1205fb60f270e25..44306616a85dd750f8178846a4abe2b29981e682 100644 (file)
 #include "collada_internal.h"
 
 template<class Functor>
-void forEachLampObjectInScene(Scene *sce, Functor &f, bool export_selected)
+void forEachLampObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
 {
-       Base *base= (Base*) sce->base.first;
-       while (base) {
-               Object *ob = base->object;
+       LinkNode *node;
+       for (node=export_set; node; node = node->next) {
+               Object *ob = (Object *)node->link;
 
-               if (ob->type == OB_LAMP && ob->data && !(export_selected && !(ob->flag & SELECT))) {
+               if (ob->type == OB_LAMP && ob->data) {
                        f(ob);
                }
-               base= base->next;
        }
 }
 
@@ -55,7 +54,7 @@ void LightsExporter::exportLights(Scene *sce)
 {
        openLibrary();
        
-       forEachLampObjectInScene(sce, *this, this->export_settings->selected);
+       forEachLampObjectInExportSet(sce, *this, this->export_settings->export_set);
        
        closeLibrary();
 }
index 48fa5b690be797e5d154b39c8764ce7085c940b6..ec075e7dcf8deb336782f56ebd96e7103baa7129 100644 (file)
@@ -39,7 +39,7 @@ void MaterialsExporter::exportMaterials(Scene *sce)
                openLibrary();
 
                MaterialFunctor mf;
-               mf.forEachMaterialInScene<MaterialsExporter>(sce, *this, this->export_settings->selected);
+               mf.forEachMaterialInExportSet<MaterialsExporter>(sce, *this, this->export_settings->export_set);
 
                closeLibrary();
        }
index 4a5422184d490eb8bbf4762dde2d20b0d05aa15d..f65c8849c84ba4eadadefd86fc8a096801febaee 100644 (file)
@@ -89,11 +89,11 @@ struct MaterialFunctor {
        // f should have
        // void operator()(Material* ma)
        template<class Functor>
-       void forEachMaterialInScene(Scene *sce, Functor &f, bool export_selected)
+       void forEachMaterialInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
        {
                ForEachMaterialFunctor<Functor> matfunc(&f);
                GeometryFunctor gf;
-               gf.forEachMeshObjectInScene<ForEachMaterialFunctor<Functor> >(sce, matfunc, export_selected);
+               gf.forEachMeshObjectInExportSet<ForEachMaterialFunctor<Functor> >(sce, matfunc, export_set);
        }
 };
 
index 510107272cda1ec1245d0495027bef1c04b8df45..603a700c4a9fffbdcbb0b465486ce6b94bfb98da 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "SceneExporter.h"
 #include "collada_utils.h"
+#include "BKE_object.h"
 
 SceneExporter::SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings)
        : COLLADASW::LibraryVisualScenes(sw), arm_exporter(arm), export_settings(export_settings)
@@ -41,112 +42,89 @@ void SceneExporter::exportScene(Scene *sce)
        closeLibrary();
 }
 
-// Returns true if the parent chain does not contain any selected object
-// Otherwise return false (ob has selected predecessor)
-bool is_exported_base_node(Object *ob, bool selection_only) {
-
-       if (selection_only && ob->flag & SELECT) {
-               // Move up towards root object,
-               // stop at first selected predecessor's child,
-               // or at root, if no parent was selected
-               while (ob->parent && (ob->parent->type==OB_ARMATURE || !(ob->parent->flag & SELECT)))
+void SceneExporter::exportHierarchy(Scene *sce)
+{      
+       LinkNode *node;
+       std::vector<Object *> base_objects;
+
+       // Ensure all objects in the export_set are marked
+       for(node = this->export_settings->export_set; node; node = node->next) {
+               Object *ob = (Object*) node->link;
+               ob->id.flag |= LIB_DOIT;
+       }
+       
+       // Now find all exportable base ojects (highest in export hierarchy)
+       for(node = this->export_settings->export_set; node; node = node->next) {
+               Object *ob = (Object*) node->link;
+               if (bc_is_base_node(this->export_settings->export_set, ob)) 
                {
-                       ob = ob->parent;
+                       switch (ob->type) {
+                               case OB_MESH:
+                               case OB_CAMERA:
+                               case OB_LAMP:
+                               case OB_EMPTY:
+                               case OB_ARMATURE:
+                                       base_objects.push_back(ob);
+                                       break;
+                       }
                }
        }
 
-       return !ob->parent;
-}
-
-void SceneExporter::exportHierarchy(Scene *sce)
-{
-       Base *base= (Base*) sce->base.first;
-       while (base) {
-               Object *ob = base->object;
-
-               bool is_export_base_node = is_exported_base_node(ob, this->export_settings->selected);
-               if (is_export_base_node) {
-                       if (sce->lay & ob->lay) {
-                               switch (ob->type) {
-                                       case OB_MESH:
-                                       case OB_CAMERA:
-                                       case OB_LAMP:
-                                       case OB_EMPTY:
-                                               if (this->export_settings->selected && !(ob->flag & SELECT)) {
-                                                       break;
-                                               }
-                                               // write nodes....
-                                               writeNodes(ob, sce);
-                                               break;
-                               }
-                       }
+       // And now export the base objects:
+       for(int index=0; index < base_objects.size(); index++) {
+               Object *ob = base_objects[index];
+               if (bc_is_marked(ob)) {
+                       bc_remove_mark(ob);
+                       writeNodes(ob, sce);
                }
-
-               base= base->next;
        }
 }
 
 void SceneExporter::writeNodes(Object *ob, Scene *sce)
 {
-
        // Add associated armature first if available
-       if (this->export_settings->include_armatures) {
-               Object *ob_arm = bc_get_assigned_armature(ob);
-               if(ob_arm != NULL)
-                       writeNodes(ob_arm, sce);
+       Object *ob_arm = bc_get_assigned_armature(ob);
+       if(ob_arm != NULL && bc_is_marked(ob_arm)) {
+               bc_remove_mark(ob_arm);
+               writeNodes(ob_arm, sce);
        }
 
-       COLLADASW::Node node(mSW);
-       node.setNodeId(translate_id(id_name(ob)));
-       node.setNodeName(translate_id(id_name(ob)));
-       node.setType(COLLADASW::Node::NODE);
+       COLLADASW::Node colladaNode(mSW);
+       colladaNode.setNodeId(translate_id(id_name(ob)));
+       colladaNode.setNodeName(translate_id(id_name(ob)));
+       colladaNode.setType(COLLADASW::Node::NODE);
 
-       node.start();
+       colladaNode.start();
 
        bool is_skinned_mesh = arm_exporter->is_skinned_mesh(ob);
        std::list<Object*> child_objects;
 
-       // XXX Not sure about this.
-       // For me this looks more like a very special case for a very special purpose.
-       // Wouldn't it be better to have only one option here ?
-       //
-       // - include children
-       //
-       // Instead of "include_bone_children" ?
-       // then we could just ask:
-       // if (this->export_settings->include_children)
-       //    ...
-       if (this->export_settings->include_armatures
-               && this->export_settings->include_bone_children) {
-
-               // list child objects
-               Base *b = (Base*) sce->base.first;
-               while (b) {
-                       // cob - child object
-                       Object *cob = b->object;
-
-                       if (cob->parent == ob) {
-                               switch (cob->type) {
-                                       case OB_MESH:
-                                       case OB_CAMERA:
-                                       case OB_LAMP:
-                                       case OB_EMPTY:
-                                       case OB_ARMATURE:
+       // list child objects
+       LinkNode *node = this->export_settings->export_set ;
+       while (node) {
+               // cob - child object
+               Object *cob = (Object *)node->link;
+
+               if (cob->parent == ob) {
+                       switch (cob->type) {
+                               case OB_MESH:
+                               case OB_CAMERA:
+                               case OB_LAMP:
+                               case OB_EMPTY:
+                               case OB_ARMATURE:
+                                       if (bc_is_marked(cob))
                                                child_objects.push_back(cob);
-                                               break;
-                               }
+                                       break;
                        }
-
-                       b = b->next;
                }
+               node = node->next;
        }
 
-
        if (ob->type == OB_MESH && this->export_settings->include_armatures && is_skinned_mesh)
                // for skinned mesh we write obmat in <bind_shape_matrix>
-               TransformWriter::add_node_transform_identity(node);
+               TransformWriter::add_node_transform_identity(colladaNode);
        else
-               TransformWriter::add_node_transform_ob(node, ob);
+               TransformWriter::add_node_transform_ob(colladaNode, ob);
 
        // <instance_geometry>
        if (ob->type == OB_MESH) {
@@ -167,9 +145,6 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
        // <instance_controller>
        else if (ob->type == OB_ARMATURE) {
                arm_exporter->add_armature_bones(ob, sce, this, child_objects);
-
-               // XXX this looks unstable...
-               node.end();
        }
 
        // <instance_camera>
@@ -196,12 +171,19 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
                }
        }
 
-       for (std::list<Object*>::iterator i= child_objects.begin(); i != child_objects.end(); ++i) {
-               writeNodes(*i, sce);
+       if (ob->type == OB_ARMATURE) {
+               colladaNode.end();
        }
 
+       for (std::list<Object*>::iterator i= child_objects.begin(); i != child_objects.end(); ++i) {
+               if(bc_is_marked(*i)) {
+                       bc_remove_mark(*i);
+                       writeNodes(*i, sce);
+               }
+       }
 
-       if (ob->type != OB_ARMATURE)
-               node.end();
+       if (ob->type != OB_ARMATURE) {
+               colladaNode.end();
+       }
 }
 
index e880082c9ecaeace8982f95c257de6d3749c0bba..b852190dd4cc5676f34f61b5071e74ceb95c8844 100644 (file)
@@ -56,20 +56,12 @@ extern "C"
                int apply_modifiers,
 
                int include_armatures,
-               int include_bone_children,
+               int include_children,
 
                int use_object_instantiation,
                int second_life )
        {
                ExportSettings export_settings;
-               
-               export_settings.selected                 = selected != 0;
-               export_settings.apply_modifiers          = apply_modifiers != 0;
-               export_settings.include_armatures        = include_armatures != 0;
-               export_settings.include_bone_children    = include_bone_children != 0;
-               export_settings.second_life              = second_life != 0;
-               export_settings.use_object_instantiation = use_object_instantiation != 0;
-               export_settings.filepath                 = (char *)filepath;
 
                /* annoying, collada crashes if file cant be created! [#27162] */
                if (!BLI_exists(filepath)) {
@@ -80,9 +72,27 @@ extern "C"
                }
                /* end! */
 
+
+               export_settings.selected                 = selected != 0;
+               export_settings.apply_modifiers          = apply_modifiers != 0;
+               export_settings.include_armatures        = include_armatures != 0;
+               export_settings.include_children         = include_children != 0;
+               export_settings.second_life              = second_life != 0;
+               export_settings.use_object_instantiation = use_object_instantiation != 0;
+               export_settings.filepath                 = (char *)filepath;
+
+               int includeFilter = OB_REL_NONE;
+               if (export_settings.include_armatures) includeFilter |= OB_REL_MOD_ARMATURE;
+               if (export_settings.include_children)  includeFilter |= OB_REL_CHILDREN_RECURSIVE;
+
+               eObjectSet objectSet = (export_settings.selected) ? OB_SET_SELECTED : OB_SET_ALL;
+               export_settings.export_set = BKE_object_relational_superset(sce, objectSet, (eObRelationTypes)includeFilter);
+
                DocumentExporter exporter(&export_settings);
                exporter.exportCurrentScene(sce);
 
+               BLI_linklist_free(export_settings.export_set, NULL);
+
                return 1;
        }
 }
index 646c8469e6b48d0ce6c8c77dd1bcb11d8a5d14b3..da2179ca13534ac84cc52deca7ccfbbc4d105fd0 100644 (file)
@@ -44,11 +44,13 @@ extern "C" {
                int apply_modifiers,
 
                int include_armatures,
-               int include_bone_children,
+               int include_children,
 
                int use_object_instantiation,
                int second_life);
 
+
+
 #ifdef __cplusplus
 }
 #endif
index 81e5f88a3f8bdc714a1d09bd96ff9310fa3b8b8a..06e688a93ac825b509ff23ae88eda83baca879cb 100644 (file)
 
 /* COLLADABU_ASSERT, may be able to remove later */
 #include "COLLADABUPlatform.h"
-
 #include "collada_internal.h"
 
+#include "BLI_linklist.h"
+
 UnitConverter::UnitConverter() : unit(), up_axis(COLLADAFW::FileInfo::Z_UP) {}
 
 void UnitConverter::read_asset(const COLLADAFW::FileInfo* asset)
@@ -277,17 +278,3 @@ std::string get_material_id(Material *mat)
 {
        return translate_id(id_name(mat)) + "-material";
 }
-
-bool has_object_type(Scene *sce, short obtype)
-{
-       Base *base= (Base*) sce->base.first;
-       while (base) {
-               Object *ob = base->object;
-                       
-               if (ob->type == obtype && ob->data) {
-                       return true;
-               }
-               base= base->next;
-       }
-       return false;
-}
index d00af791a1fe0f7248809ef32e8f5b61e37e17cf..b64c75e79607e644f16b556c0ba83bd477d99cd9 100644 (file)
@@ -39,6 +39,8 @@
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "BLI_math.h"
+#include "BLI_math.h"
+#include "BLI_linklist.h"
 
 class UnitConverter
 {
@@ -96,6 +98,4 @@ extern std::string get_camera_id(Object *ob);
 
 extern std::string get_material_id(Material *mat);
 
-extern bool has_object_type(Scene* sce, short obtype);
-
 #endif /* __COLLADA_INTERNAL_H__ */
index 8693441d7c850a6d1f13aaa1f5d4700cf13be1f1..c92131d5359763f98025769fd6ecec408a52bf78 100644 (file)
@@ -32,6 +32,8 @@
 #include "COLLADAFWMeshPrimitive.h"
 #include "COLLADAFWMeshVertexData.h"
 
+#include "collada_utils.h"
+
 #include "DNA_modifier_types.h"
 #include "DNA_customdata_types.h"
 #include "DNA_object_types.h"
@@ -49,6 +51,7 @@
 
 extern "C" {
 #include "BKE_DerivedMesh.h"
+#include "BLI_linklist.h"
 }
 
 #include "WM_api.h" // XXX hrm, see if we can do without this
@@ -164,3 +167,64 @@ Object *bc_get_assigned_armature(Object *ob)
        return ob_arm;
 }
 
+// Returns the highest selected ancestor
+// returns NULL if no ancestor is selected
+// IMPORTANT: This function expects that
+// all exported objects have set:
+// ob->id.flag & LIB_DOIT
+Object *bc_get_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob) 
+{
+       Object *ancestor = ob;
+       while (ob->parent && bc_is_marked(ob->parent))
+       {
+               ob = ob->parent;
+               ancestor = ob;
+       }
+       return ancestor;
+}
+
+bool bc_is_base_node(LinkNode *export_set, Object *ob)
+{
+       Object *root = bc_get_highest_selected_ancestor_or_self(export_set, ob);
+       return (root == ob);
+}
+
+bool bc_is_in_Export_set(LinkNode *export_set, Object *ob)
+{
+       LinkNode *node = export_set;
+       
+       while (node) {
+               Object *element = (Object *)node->link;
+       
+               if (element == ob)
+                       return true;
+               
+               node= node->next;
+       }
+       return false;
+}
+
+bool bc_has_object_type(LinkNode *export_set, short obtype)
+{
+       LinkNode *node = export_set;
+       
+       while (node) {
+               Object *ob = (Object *)node->link;
+                       
+               if (ob->type == obtype && ob->data) {
+                       return true;
+               }
+               node= node->next;
+       }
+       return false;
+}
+
+int bc_is_marked(Object *ob)
+{
+       return ob && (ob->id.flag & LIB_DOIT);
+}
+
+void bc_remove_mark(Object *ob)
+{
+       ob->id.flag &= ~LIB_DOIT;
+}
index 9882b44d94cb363a7c347b6312691ee72a35a115..71365ffb8d0d0345d05d9541f204116655d87e12 100644 (file)
 #include "DNA_customdata_types.h"
 #include "DNA_texture_types.h"
 #include "BKE_context.h"
+#include "BKE_object.h"
+
 #include "DNA_scene_types.h"
 
+extern "C" {
+#include "BKE_DerivedMesh.h"
+#include "BLI_linklist.h"
+}
+
+#include "ExportSettings.h"
+
 typedef std::map<COLLADAFW::TextureMapId, std::vector<MTex*> > TexIndexTextureArrayMap;
 
 extern float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned int index);
-
 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);
 extern Mesh *bc_to_mesh_apply_modifiers(Scene *scene, Object *ob);
+
 extern Object *bc_get_assigned_armature(Object *ob);
+extern Object *bc_get_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob);
+extern bool bc_is_base_node(LinkNode *export_set, Object *ob);
+extern bool bc_is_in_Export_set(LinkNode *export_set, Object *ob);
+extern bool bc_has_object_type(LinkNode *export_set, short obtype);
+
+extern int bc_is_marked(Object *ob);
+extern void bc_remove_mark(Object *ob);
+
+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);
 
 #endif
index b2ff36285e6f80ec76f528b5cb8baa65d59f17d6..8d18f9dd1c2ecdab3df58ba26ae83f2b9c3544ae 100644 (file)
@@ -91,12 +91,12 @@ static void rna_Scene_collada_export(
        int selected,
        int apply_modifiers,
        int include_armatures,
-       int include_bone_children,
+       int include_children,
        int use_object_instantiation,
        int second_life)
 {
        collada_export(scene, filepath, selected, apply_modifiers, 
-               include_armatures, include_bone_children, 
+               include_armatures, include_children, 
                use_object_instantiation, second_life);
 }
 
@@ -128,7 +128,7 @@ void RNA_api_scene(StructRNA *srna)
        parm = RNA_def_boolean(func, "selected", 0, "Selection Only", "Export only selected elements");
        parm = RNA_def_boolean(func, "apply_modifiers", 0, "Apply Modifiers", "Apply modifiers (in Preview resolution)");
        parm = RNA_def_boolean(func, "include_armatures", 0, "Include Armatures", "Include armature(s) used by the exported objects");
-       parm = RNA_def_boolean(func, "include_bone_children", 0, "Include Bone Children", "Include all objects attached to bones of selected Armature(s)");
+       parm = RNA_def_boolean(func, "include_children", 0, "Include Children", "Include all children even if not selected");
        parm = RNA_def_boolean(func, "use_object_instantiation", 1, "Use Object Instantiation", "Instantiate multiple Objects from same Data");
        parm = RNA_def_boolean(func, "second_life", 0, "Export for Second Life", "Compatibility mode for Second Life");
        RNA_def_function_ui_description(func, "Export to collada file");
index 425baac25fd7a020190f2784f0dfb37e05ed903c..5f4a536d18f2913b099b292e4414c9e161ba9ab6 100644 (file)
@@ -2165,7 +2165,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
        int selected, second_life, 
                include_armatures,
                apply_modifiers, 
-               include_bone_children,
+               include_children,
                use_object_instantiation;
        
        if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
@@ -2179,7 +2179,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
        selected                 = RNA_boolean_get(op->ptr, "selected");
        apply_modifiers          = RNA_boolean_get(op->ptr, "apply_modifiers");
        include_armatures        = RNA_boolean_get(op->ptr, "include_armatures");
-       include_bone_children    = RNA_boolean_get(op->ptr, "include_bone_children");
+       include_children         = RNA_boolean_get(op->ptr, "include_children");
        use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation");
        second_life              = RNA_boolean_get(op->ptr, "second_life");
 
@@ -2192,7 +2192,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
                selected,
                apply_modifiers,
                include_armatures,
-               include_bone_children,
+               include_children,
                use_object_instantiation,
                second_life)) {
                return OPERATOR_FINISHED;
@@ -2225,8 +2225,8 @@ static void WM_OT_collada_export(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "include_armatures", 0, "Include Armatures",
                        "Include armature(s) used by the exported objects");
 
-       RNA_def_boolean(ot->srna, "include_bone_children", 0, "Include Bone Children",
-                       "Include all objects attached to bones of selected Armature(s)");
+       RNA_def_boolean(ot->srna, "include_children", 0, "Include Children",
+                       "Include all children even if not selected");
 
        RNA_def_boolean(ot->srna, "use_object_instantiation", 1, "Use Object Instantiation",
                            "Instantiate multiple Objects from same Data");