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
diff options
context:
space:
mode:
authorGaia Clary <gaia.clary@machinimatrix.org>2018-11-23 17:57:45 +0300
committerGaia Clary <gaia.clary@machinimatrix.org>2018-11-23 19:08:14 +0300
commit322cf89a1444c685219ed6b863c9c74d41b5d1d1 (patch)
tree4145b1ec18a0c5cd4fe344d4e9ed49a0c2d33d0b /source/blender/collada/SceneExporter.cpp
parent3bf7c846eeb4a728c62100b40463874d83f5b3e0 (diff)
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer. There is still some cleaning up to be done. But the Exporter/Importer basically work within Blender 2.8 Some details: User Interface: The interface has been reorganized to look more like the FBX interface. New options in user interface: * keep_keyframes: When sampling the distance between 2 keyframes is defined by the sampling rate. Furthermore the keyframes defined in the FCurves are not exported. However when this option is enabled then also the defined keyframes will be added to the exported fcurves * keep_smooth_curves: When sampling we do not use FCurves. So we also have no Curve handles for smooth exporting. However when this option is enabled, Blender does its best to recreate the handles for export. This is a very experimental feature and it is know to break when: - the exported animated objects have parent inverse matrices different from the unit matrix - The exported objects have negative scaling There may be many other situations when this feature breaks. This needs to be further tested. It may be removed later or replaced by something less wonky. BlenderContext: is a new class that contains the bridge to Blender. It contains pointers to the current export/import context plus derived values of Depsgraph, Scene, Main Reporting: I reorganized the output on the Blender Console to become more informative and more readable Preservation of Item names: name attributes are now encoded with XML entities. This makes sure that i can export/import names exactly defined in the tool. This affects material names, bone names and object names. Hierarchy export: * Object and Bone Hierarchies are now exported correctly by taking the Blender parent/child hierarchy into account * Export also not selected intermediate objects Problem: When we export an Object Hierarchy, then we must export all elements of the hierarchy to maintain the transforms. This is especially important when exporting animated objects, because the animation curves are exported as relative curves based on the parent-child hierarchy. If an intermediate animated object is missing then the exported animation breaks. Solution: If the "Selected" Optioon is enabled, then take care to also export all objects which are not selected and hidden, but which are parents of selected objects. Node Based Material Importer (wip): Added basic support for Materials with diffuse color and diffuse textures. More properties (opacity, emission) need changes in the used shader. Note: Materials are all constructed by using the principled BSDF shader. Animation Exporter: * Massive optimization of the Animation Bake tool (Animation Sampler). Instead of sampling each fcurve separately, i now sample all exported fcurves simultaneously. So i avoid many (many!) scene updates during animation export. * Add support for Continuous Acceleration (Fcurve handles) This allows us to create smoother FCurves during importing Collada Animation curves. Possibly this should become an option ionstead of a fixed import feature. * Add support for sampling curves (to bake animations) * The animation sampler now can be used for any animation curve. Before the sampler only looked at curves which are supported by Standard Collada 1.4. However the Collada exporter currently ignores all animation curves which are not covered by the 1.4.1 Collada Standards. There is still some room for improvements here (work in progres) Known issues: * Some exports do currently not work reliably, among those are the camera animations, material animations and light animations those animations will be added back next (work in progres) * Exporting animation curves with keyframes (and tangents) sometimes results in odd curves (when parent inverse matrix is involved) This needs to be checked in more depth (probably it can not be solved). * Export of "all animations in scene" is disabled because the Collada Importer can not handle this reliably at the moment (work in progres). * Support for Animation Clip export Added one extra level to the exported animations such that now all scene animations are enclosed: <Animation name="id_name(ob)_Action"> <Animation>...</Animation> ... </Animation> Animation Importer: * Import of animations for objects with multiple materials When importing multiple materials for one object, the imported material animation curves have all been assigned to the first material in the object. Error handling (wip): The Importer was a bit confused as it sometimes ignored fatal parsing errors and continued to import. I did my best to unconfuse it, but i believe that this needs to be tested more. Refactoring: update : move generation of effect id names into own function update : adjust importer/exporter for no longer supported HEMI lights cleanup: Removed no lopnger existing attribute from the exporter presets cleanup: Removed not needed Context attribute from DocumentExporter fix : Avoid duplicate deletion of temporary items cleanup: fixed indentation and white space issues update : Make BCAnimation class more self contained cleanup: Renamed classes, updated comments for better reading cleanup: Moved static class functions to collada_utils cleanup: Moved typedefs to more intuitive locations cleanup: indentation and class method declarations cleanup: Removed no longer needed methods update : Moved Classes into separate files cleanup: Added comments cleanup: take care of name conventions ... : many more small changes, not helpful to list them all
Diffstat (limited to 'source/blender/collada/SceneExporter.cpp')
-rw-r--r--source/blender/collada/SceneExporter.cpp264
1 files changed, 130 insertions, 134 deletions
diff --git a/source/blender/collada/SceneExporter.cpp b/source/blender/collada/SceneExporter.cpp
index f21d82bd393..7a815e7d3e3 100644
--- a/source/blender/collada/SceneExporter.cpp
+++ b/source/blender/collada/SceneExporter.cpp
@@ -34,22 +34,25 @@ extern "C" {
#include "SceneExporter.h"
#include "collada_utils.h"
-SceneExporter::SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings)
- : COLLADASW::LibraryVisualScenes(sw), arm_exporter(arm), export_settings(export_settings)
+SceneExporter::SceneExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings):
+ blender_context(blender_context),
+ COLLADASW::LibraryVisualScenes(sw), arm_exporter(arm), export_settings(export_settings)
{
}
-void SceneExporter::exportScene(bContext *C, Depsgraph *depsgraph, Scene *sce)
+void SceneExporter::exportScene()
{
+ ViewLayer *view_layer = blender_context.get_view_layer();
+
// <library_visual_scenes> <visual_scene>
- std::string id_naming = id_name(sce);
- openVisualScene(translate_id(id_naming), id_naming);
- exportHierarchy(C, depsgraph, sce);
+ std::string name = id_name(view_layer);
+ openVisualScene(translate_id(name), encode_xml(name));
+ exportHierarchy();
closeVisualScene();
closeLibrary();
}
-void SceneExporter::exportHierarchy(bContext *C, Depsgraph *depsgraph, Scene *sce)
+void SceneExporter::exportHierarchy()
{
LinkNode *node;
std::vector<Object *> base_objects;
@@ -82,164 +85,157 @@ void SceneExporter::exportHierarchy(bContext *C, Depsgraph *depsgraph, Scene *sc
Object *ob = base_objects[index];
if (bc_is_marked(ob)) {
bc_remove_mark(ob);
- writeNodes(C, depsgraph, ob, sce);
+ writeNodes(ob);
}
}
}
+void SceneExporter::writeNodeList(std::vector<Object *> &child_objects, Object *parent)
+{
+ /* TODO: Handle the case where a parent is not exported
+ Actually i am not even sure if this can be done at all
+ in a good way.
+ I really prefer to enforce the export of hidden
+ elements in an object hierarchy. When the children of
+ the hidden elements are exported as well.
+ */
+ for (int i = 0; i < child_objects.size(); ++i) {
+ Object *child = child_objects[i];
+ if (bc_is_marked(child)) {
+ bc_remove_mark(child);
+ writeNodes(child);
+ }
+ }
+}
-void SceneExporter::writeNodes(bContext *C, Depsgraph *depsgraph, Object *ob, Scene *sce)
+void SceneExporter::writeNodes(Object *ob)
{
+ ViewLayer *view_layer = blender_context.get_view_layer();
+
+ std::vector<Object *> child_objects;
+ bc_get_children(child_objects, ob, view_layer);
+ bool can_export = bc_is_in_Export_set(this->export_settings->export_set, ob, view_layer);
+
// Add associated armature first if available
bool armature_exported = false;
Object *ob_arm = bc_get_assigned_armature(ob);
+
if (ob_arm != NULL) {
- armature_exported = bc_is_in_Export_set(this->export_settings->export_set, ob_arm);
+ armature_exported = bc_is_in_Export_set(this->export_settings->export_set, ob_arm, view_layer);
if (armature_exported && bc_is_marked(ob_arm)) {
bc_remove_mark(ob_arm);
- writeNodes(C, depsgraph, ob_arm, sce);
+ writeNodes(ob_arm);
armature_exported = true;
}
}
- COLLADASW::Node colladaNode(mSW);
- colladaNode.setNodeId(translate_id(id_name(ob)));
- colladaNode.setNodeName(translate_id(id_name(ob)));
- colladaNode.setType(COLLADASW::Node::NODE);
-
- colladaNode.start();
+ if (can_export) {
+ COLLADASW::Node colladaNode(mSW);
+ colladaNode.setNodeId(translate_id(id_name(ob)));
+ colladaNode.setNodeName(encode_xml(id_name(ob)));
+ colladaNode.setType(COLLADASW::Node::NODE);
- std::list<Object *> child_objects;
+ colladaNode.start();
- // list child objects
- LinkNode *node;
- for (node=this->export_settings->export_set; node; node=node->next) {
- // cob - child object
- Object *cob = (Object *)node->link;
+ if (ob->type == OB_MESH && armature_exported) {
+ // for skinned mesh we write obmat in <bind_shape_matrix>
+ TransformWriter::add_node_transform_identity(colladaNode);
+ }
+ else {
+ TransformWriter::add_node_transform_ob(colladaNode, ob, this->export_settings->export_transformation_type);
+ }
- if (cob->parent == ob) {
- switch (cob->type) {
- case OB_MESH:
- case OB_CAMERA:
- case OB_LAMP:
- case OB_EMPTY:
- case OB_GPENCIL:
- case OB_ARMATURE:
- if (bc_is_marked(cob))
- child_objects.push_back(cob);
- break;
+ // <instance_geometry>
+ if (ob->type == OB_MESH) {
+ bool instance_controller_created = false;
+ if (armature_exported) {
+ instance_controller_created = arm_exporter->add_instance_controller(ob);
+ }
+ if (!instance_controller_created) {
+ COLLADASW::InstanceGeometry instGeom(mSW);
+ instGeom.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob, this->export_settings->use_object_instantiation)));
+ instGeom.setName(encode_xml(id_name(ob)));
+ InstanceWriter::add_material_bindings(instGeom.getBindMaterial(),
+ ob,
+ this->export_settings->active_uv_only);
+ instGeom.add();
}
}
- }
-
- if (ob->type == OB_MESH && armature_exported)
- // for skinned mesh we write obmat in <bind_shape_matrix>
- TransformWriter::add_node_transform_identity(colladaNode);
- else {
- TransformWriter::add_node_transform_ob(colladaNode, ob, this->export_settings->export_transformation_type);
- }
- // <instance_geometry>
- if (ob->type == OB_MESH) {
- bool instance_controller_created = false;
- if (armature_exported) {
- instance_controller_created = arm_exporter->add_instance_controller(ob);
+ // <instance_controller>
+ else if (ob->type == OB_ARMATURE) {
+ arm_exporter->add_armature_bones(ob, view_layer, this, child_objects);
}
- if (!instance_controller_created) {
- COLLADASW::InstanceGeometry instGeom(mSW);
- instGeom.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob, this->export_settings->use_object_instantiation)));
- instGeom.setName(translate_id(id_name(ob)));
- InstanceWriter::add_material_bindings(instGeom.getBindMaterial(), ob, this->export_settings->active_uv_only);
- instGeom.add();
+ // <instance_camera>
+ else if (ob->type == OB_CAMERA) {
+ COLLADASW::InstanceCamera instCam(mSW, COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_camera_id(ob)));
+ instCam.add();
}
- }
-
- // <instance_controller>
- else if (ob->type == OB_ARMATURE) {
- arm_exporter->add_armature_bones(C, depsgraph, ob, sce, this, child_objects);
- }
- // <instance_camera>
- else if (ob->type == OB_CAMERA) {
- COLLADASW::InstanceCamera instCam(mSW, COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_camera_id(ob)));
- instCam.add();
- }
-
- // <instance_light>
- else if (ob->type == OB_LAMP) {
- COLLADASW::InstanceLight instLa(mSW, COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_light_id(ob)));
- instLa.add();
- }
-
- // empty object
- else if (ob->type == OB_EMPTY) { // TODO: handle groups (OB_DUPLICOLLECTION
- if ((ob->transflag & OB_DUPLICOLLECTION) == OB_DUPLICOLLECTION && ob->dup_group) {
- Collection *collection = ob->dup_group;
- /* printf("group detected '%s'\n", group->id.name + 2); */
- FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(collection, object)
- {
- printf("\t%s\n", object->id.name);
- }
- FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
+ // <instance_light>
+ else if (ob->type == OB_LAMP) {
+ COLLADASW::InstanceLight instLa(mSW, COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_light_id(ob)));
+ instLa.add();
}
- }
-
- if (ob->type == OB_ARMATURE) {
- colladaNode.end();
- }
- if (BLI_listbase_is_empty(&ob->constraints) == false) {
- bConstraint *con = (bConstraint *) ob->constraints.first;
- while (con) {
- std::string con_name(translate_id(con->name));
- std::string con_tag = con_name + "_constraint";
- printf("%s\n", con_name.c_str());
- printf("%s\n\n", con_tag.c_str());
- colladaNode.addExtraTechniqueChildParameter("blender",con_tag,"type",con->type);
- colladaNode.addExtraTechniqueChildParameter("blender",con_tag,"enforce",con->enforce);
- colladaNode.addExtraTechniqueChildParameter("blender",con_tag,"flag",con->flag);
- colladaNode.addExtraTechniqueChildParameter("blender",con_tag,"headtail",con->headtail);
- colladaNode.addExtraTechniqueChildParameter("blender",con_tag,"lin_error",con->lin_error);
- colladaNode.addExtraTechniqueChildParameter("blender",con_tag,"own_space",con->ownspace);
- colladaNode.addExtraTechniqueChildParameter("blender",con_tag,"rot_error",con->rot_error);
- colladaNode.addExtraTechniqueChildParameter("blender",con_tag,"tar_space",con->tarspace);
- colladaNode.addExtraTechniqueChildParameter("blender",con_tag,"lin_error",con->lin_error);
-
- //not ideal: add the target object name as another parameter.
- //No real mapping in the .dae
- //Need support for multiple target objects also.
- const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
- ListBase targets = {NULL, NULL};
- if (cti && cti->get_constraint_targets) {
-
- bConstraintTarget *ct;
- Object *obtar;
-
- cti->get_constraint_targets(con, &targets);
-
- for (ct = (bConstraintTarget *)targets.first; ct; ct = ct->next) {
- obtar = ct->tar;
- std::string tar_id((obtar) ? id_name(obtar) : "");
- colladaNode.addExtraTechniqueChildParameter("blender",con_tag,"target_id",tar_id);
+ // empty object
+ else if (ob->type == OB_EMPTY) { // TODO: handle groups (OB_DUPLICOLLECTION
+ if ((ob->transflag & OB_DUPLICOLLECTION) == OB_DUPLICOLLECTION && ob->dup_group) {
+ Collection *collection = ob->dup_group;
+ /* printf("group detected '%s'\n", group->id.name + 2); */
+ FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(collection, object)
+ {
+ printf("\t%s\n", object->id.name);
}
-
- if (cti->flush_constraint_targets)
- cti->flush_constraint_targets(con, &targets, 1);
-
+ FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
}
- con = con->next;
- }
- }
-
- for (std::list<Object *>::iterator i = child_objects.begin(); i != child_objects.end(); ++i) {
- if (bc_is_marked(*i)) {
- bc_remove_mark(*i);
- writeNodes(C, depsgraph, *i, sce);
+ if (BLI_listbase_is_empty(&ob->constraints) == false) {
+ bConstraint *con = (bConstraint *)ob->constraints.first;
+ while (con) {
+ std::string con_name(encode_xml(con->name));
+ std::string con_tag = con_name + "_constraint";
+ printf("%s\n", con_name.c_str());
+ printf("%s\n\n", con_tag.c_str());
+ colladaNode.addExtraTechniqueChildParameter("blender", con_tag, "type", con->type);
+ colladaNode.addExtraTechniqueChildParameter("blender", con_tag, "enforce", con->enforce);
+ colladaNode.addExtraTechniqueChildParameter("blender", con_tag, "flag", con->flag);
+ colladaNode.addExtraTechniqueChildParameter("blender", con_tag, "headtail", con->headtail);
+ colladaNode.addExtraTechniqueChildParameter("blender", con_tag, "lin_error", con->lin_error);
+ colladaNode.addExtraTechniqueChildParameter("blender", con_tag, "own_space", con->ownspace);
+ colladaNode.addExtraTechniqueChildParameter("blender", con_tag, "rot_error", con->rot_error);
+ colladaNode.addExtraTechniqueChildParameter("blender", con_tag, "tar_space", con->tarspace);
+ colladaNode.addExtraTechniqueChildParameter("blender", con_tag, "lin_error", con->lin_error);
+
+ //not ideal: add the target object name as another parameter.
+ //No real mapping in the .dae
+ //Need support for multiple target objects also.
+ const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
+ ListBase targets = { NULL, NULL };
+ if (cti && cti->get_constraint_targets) {
+
+ bConstraintTarget *ct;
+ Object *obtar;
+
+ cti->get_constraint_targets(con, &targets);
+
+ for (ct = (bConstraintTarget *)targets.first; ct; ct = ct->next) {
+ obtar = ct->tar;
+ std::string tar_id((obtar) ? id_name(obtar) : "");
+ colladaNode.addExtraTechniqueChildParameter("blender", con_tag, "target_id", tar_id);
+ }
+
+ if (cti->flush_constraint_targets)
+ cti->flush_constraint_targets(con, &targets, 1);
+
+ }
+
+ con = con->next;
+ }
+ }
}
- }
-
- if (ob->type != OB_ARMATURE)
+ writeNodeList(child_objects, ob);
colladaNode.end();
+ }
}