2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed,
21
* ***** END GPL LICENSE BLOCK *****
24
/** \file blender/collada/ImageExporter.cpp
29
#include "COLLADABUURI.h"
30
#include "COLLADASWImage.h"
32
#include "ImageExporter.h"
33
#include "MaterialExporter.h"
35
#include "DNA_texture_types.h"
37
#include "BKE_global.h"
39
#include "BKE_utildefines.h"
40
#include "BLI_fileops.h"
41
#include "BLI_path_util.h"
42
#include "BLI_string.h"
44
ImagesExporter::ImagesExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryImages(sw), export_settings(export_settings)
47
bool ImagesExporter::hasImages(Scene *sce)
49
Base *base = (Base *)sce->base.first;
52
Object *ob= base->object;
54
for (a = 0; a < ob->totcol; a++)
56
Material *ma = give_current_material(ob, a+1);
58
// no material, but check all of the slots
61
for (b = 0; b < MAX_MTEX; b++) {
62
MTex *mtex = ma->mtex[b];
63
if (mtex && mtex->tex && mtex->tex->ima) return true;
72
void ImagesExporter::exportImages(Scene *sce)
77
mf.forEachMaterialInScene<ImagesExporter>(sce, *this, this->export_settings->selected);
83
void ImagesExporter::operator()(Material *ma, Object *ob)
86
for (a = 0; a < MAX_MTEX; a++) {
87
MTex *mtex = ma->mtex[a];
88
if (mtex && mtex->tex && mtex->tex->ima) {
90
Image *image = mtex->tex->ima;
91
std::string name(id_name(image));
92
name = translate_id(name);
98
BLI_split_dir_part(this->export_settings->filepath, dir, sizeof(dir));
100
BKE_rebase_path(abs, sizeof(abs), rel, sizeof(rel), G.main->name, image->name, dir);
102
if (abs[0] != '\0') {
104
// make absolute source path
105
BLI_strncpy(src, image->name, sizeof(src));
106
BLI_path_abs(src, G.main->name);
108
// make dest directory if it doesn't exist
109
BLI_make_existing_file(abs);
111
if (BLI_copy(src, abs) != 0) {
112
fprintf(stderr, "Cannot copy image to file's directory.\n");
116
if (find(mImages.begin(), mImages.end(), name) == mImages.end()) {
117
COLLADASW::Image img(COLLADABU::URI(COLLADABU::URI::nativePathToUri(rel)), name, name); /* set name also to mNameNC. This helps other viewers import files exported from Blender better */
120
mImages.push_back(name);