diff options
author | Gaia Clary <gaia.clary@machinimatrix.org> | 2019-05-23 13:17:17 +0300 |
---|---|---|
committer | Gaia Clary <gaia.clary@machinimatrix.org> | 2019-05-23 13:29:20 +0300 |
commit | 6be9d19951ed460829d379aa90953b14a9f281f2 (patch) | |
tree | 45fe275c232ff0b4fb0e4e7205d53c8fdd6f8e9a /source/blender/collada/BlenderContext.cpp | |
parent | e9cf9e0a397f9589e00d980f0c0489641e7ed57e (diff) |
Collada exporter update
Added new feature: Collada: global axis rotation upon export (UI)
The new feature allows to specify the target rest coordinate system upon export.
This allows for example to export a character that is in Blender orientation (Y forward)
to match the Secondlife orientation where (-X forward)
- Refactor:Added new utility methods to collada_utils
Made BCMatrix class more powerfull
moved Blender related structures into new BlenderContext class
added class wrapper to encapsulate ExportSettings structure
Added blender context getters to ExportSettings
added access methods to BlenderContext into ExportSettings class
Moved class BCMatrix into BlenderContext
moved utility functions from collada_util into BlenderContext
replace own function for parenting by a call to ED_object_parent_set()
- Cleanup: removed obsolete parameters from methods
renamed parameters for better understanding
cleanup whitespace and indentation
removed obsolete comments
Diffstat (limited to 'source/blender/collada/BlenderContext.cpp')
-rw-r--r-- | source/blender/collada/BlenderContext.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/source/blender/collada/BlenderContext.cpp b/source/blender/collada/BlenderContext.cpp index 384f235e00c..709f84c3f77 100644 --- a/source/blender/collada/BlenderContext.cpp +++ b/source/blender/collada/BlenderContext.cpp @@ -18,9 +18,92 @@ * \ingroup collada */ +#include <vector> + #include "BlenderContext.h" #include "BKE_scene.h" +bool bc_is_base_node(LinkNode *export_set, Object *ob, ViewLayer *view_layer) +{ + Object *root = bc_get_highest_exported_ancestor_or_self(export_set, ob, view_layer); + return (root == ob); +} + +/** + * Returns the highest selected ancestor + * returns NULL if no ancestor is selected + * IMPORTANT: This function expects that all exported objects have set: + * ob->id.tag & LIB_TAG_DOIT + */ +Object *bc_get_highest_exported_ancestor_or_self(LinkNode *export_set, + Object *ob, + ViewLayer *view_layer) +{ + Object *ancestor = ob; + while (ob->parent) { + if (bc_is_in_Export_set(export_set, ob->parent, view_layer)) { + ancestor = ob->parent; + } + ob = ob->parent; + } + return ancestor; +} + +void bc_get_children(std::vector<Object *> &child_set, Object *ob, ViewLayer *view_layer) +{ + Base *base; + for (base = (Base *)view_layer->object_bases.first; base; base = base->next) { + Object *cob = base->object; + if (cob->parent == ob) { + switch (ob->type) { + case OB_MESH: + case OB_CAMERA: + case OB_LAMP: + case OB_EMPTY: + case OB_ARMATURE: + child_set.push_back(cob); + default: + break; + } + } + } +} + +bool bc_is_in_Export_set(LinkNode *export_set, Object *ob, ViewLayer *view_layer) +{ + bool to_export = (BLI_linklist_index(export_set, ob) != -1); + + if (!to_export) { + /* Mark this object as to_export even if it is not in the + export list, but it contains children to export */ + + std::vector<Object *> children; + bc_get_children(children, ob, view_layer); + for (int i = 0; i < children.size(); i++) { + if (bc_is_in_Export_set(export_set, children[i], view_layer)) { + to_export = true; + break; + } + } + } + return to_export; +} + +int bc_is_marked(Object *ob) +{ + return ob && (ob->id.tag & LIB_TAG_DOIT); +} + +void bc_remove_mark(Object *ob) +{ + ob->id.tag &= ~LIB_TAG_DOIT; +} + +void bc_set_mark(Object *ob) +{ + ob->id.tag |= LIB_TAG_DOIT; +} + BlenderContext::BlenderContext(bContext *C) { context = C; |