diff options
author | Gaia Clary <gaia.clary@machinimatrix.org> | 2015-11-27 16:56:20 +0300 |
---|---|---|
committer | Gaia Clary <gaia.clary@machinimatrix.org> | 2015-11-27 16:56:52 +0300 |
commit | 85362dfe807afc28ff51d8d467c317f91ab04efa (patch) | |
tree | e61bd5a67e4032b25c1d735e2b90e6a082766ba8 /source/blender/collada | |
parent | 20fc9c00fddeabc524ba91815108e52edd85ce4b (diff) |
fix T46868: added workaround for a collada issue with UTF8 filenames
Diffstat (limited to 'source/blender/collada')
-rw-r--r-- | source/blender/collada/DocumentExporter.cpp | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index 7398126c97b..b2f960a5b3b 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -98,6 +98,7 @@ extern "C" #include "BKE_material.h" #include "BKE_object.h" #include "BKE_scene.h" +#include "BKE_appdir.h" #include "ED_keyframing.h" #ifdef WITH_BUILDINFO @@ -153,6 +154,26 @@ char *bc_CustomData_get_active_layer_name(const CustomData *data, int type) DocumentExporter::DocumentExporter(const ExportSettings *export_settings) : export_settings(export_settings) { } +static COLLADABU::NativeString make_temp_filepath(char *name, char *extension) +{ + char tempfile[FILE_MAX]; + const char *tempdir = BKE_tempdir_session(); + + if (name == NULL){ + name = tmpnam(NULL); + } + + BLI_make_file_string(NULL, tempfile, tempdir, name); + + if (extension) { + BLI_ensure_extension(tempfile, FILE_MAX, extension); + } + + COLLADABU::NativeString native_filename = + COLLADABU::NativeString(tempfile, COLLADABU::NativeString::ENCODING_UTF8); + return native_filename; +} + // TODO: it would be better to instantiate animations rather than create a new one per object // COLLADA allows this through multiple <channel>s in <animation>. // For this to work, we need to know objects that use a certain action. @@ -163,18 +184,17 @@ void DocumentExporter::exportCurrentScene(Scene *sce) PropertyRNA *system; /* unused , *scale; */ clear_global_id_map(); - - COLLADABU::NativeString native_filename = - COLLADABU::NativeString(std::string(this->export_settings->filepath), COLLADABU::NativeString::ENCODING_UTF8); - COLLADASW::StreamWriter sw(native_filename); + + COLLADABU::NativeString native_filename = make_temp_filepath(NULL, ".dae"); + COLLADASW::StreamWriter *writer = new COLLADASW::StreamWriter(native_filename); fprintf(stdout, "Collada export: %s\n", this->export_settings->filepath); // open <collada> - sw.startDocument(); + writer->startDocument(); // <asset> - COLLADASW::Asset asset(&sw); + COLLADASW::Asset asset(writer); RNA_id_pointer_create(&(sce->id), &sceneptr); unit_settings = RNA_pointer_get(&sceneptr, "unit_settings"); @@ -241,41 +261,41 @@ void DocumentExporter::exportCurrentScene(Scene *sce) LinkNode *export_set = this->export_settings->export_set; // <library_cameras> if (bc_has_object_type(export_set, OB_CAMERA)) { - CamerasExporter ce(&sw, this->export_settings); + CamerasExporter ce(writer, this->export_settings); ce.exportCameras(sce); } // <library_lights> if (bc_has_object_type(export_set, OB_LAMP)) { - LightsExporter le(&sw, this->export_settings); + LightsExporter le(writer, this->export_settings); le.exportLights(sce); } // <library_images> - ImagesExporter ie(&sw, this->export_settings); + ImagesExporter ie(writer, this->export_settings); ie.exportImages(sce); // <library_effects> - EffectsExporter ee(&sw, this->export_settings); + EffectsExporter ee(writer, this->export_settings); ee.exportEffects(sce); // <library_materials> - MaterialsExporter me(&sw, this->export_settings); + MaterialsExporter me(writer, this->export_settings); me.exportMaterials(sce); // <library_geometries> if (bc_has_object_type(export_set, OB_MESH)) { - GeometryExporter ge(&sw, this->export_settings); + GeometryExporter ge(writer, this->export_settings); ge.exportGeom(sce); } // <library_animations> - AnimationExporter ae(&sw, this->export_settings); + AnimationExporter ae(writer, this->export_settings); bool has_animations = ae.exportAnimations(sce); // <library_controllers> - ArmatureExporter arm_exporter(&sw, this->export_settings); - ControllerExporter controller_exporter(&sw , this->export_settings); + ArmatureExporter arm_exporter(writer, this->export_settings); + ControllerExporter controller_exporter(writer, this->export_settings); if (bc_has_object_type(export_set, OB_ARMATURE) || this->export_settings->include_shapekeys) { controller_exporter.export_controllers(sce); @@ -283,7 +303,7 @@ void DocumentExporter::exportCurrentScene(Scene *sce) // <library_visual_scenes> - SceneExporter se(&sw, &arm_exporter, this->export_settings); + SceneExporter se(writer, &arm_exporter, this->export_settings); if (has_animations && this->export_settings->export_transformation_type == BC_TRANSFORMATION_TYPE_MATRIX) { // channels adressing <matrix> objects is not (yet) supported @@ -301,12 +321,16 @@ void DocumentExporter::exportCurrentScene(Scene *sce) // <scene> std::string scene_name(translate_id(id_name(sce))); - COLLADASW::Scene scene(&sw, COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, + COLLADASW::Scene scene(writer, COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, scene_name)); scene.add(); // close <Collada> - sw.endDocument(); + writer->endDocument(); + delete writer; + + // Finally move the created document into place + BLI_rename(native_filename.c_str(), this->export_settings->filepath); } |