forked from swayfreeda/ImageBasedModellingEduV1.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaterial_lib.cpp
executable file
·57 lines (48 loc) · 1.77 KB
/
material_lib.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright (C) 2015, Nils Moehrle
* TU Darmstadt - Graphics, Capture and Massively Parallel Computing
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD 3-Clause license. See the LICENSE.txt file for details.
*/
#include <fstream>
#include <cstring>
#include <cerrno>
#include <util/exception.h>
#include <util/file_system.h>
#include <core/image.h>
#include <core/image_io.h>
#include "material_lib.h"
MaterialLib::MaterialLib() {
}
void
MaterialLib::add_material(std::string const & name, Material material) {
material_names.push_back(name);
materials.push_back(material);
}
void
MaterialLib::save_to_files(std::string const & prefix) const {
std::string filename = prefix + ".mtl";
std::ofstream out(filename.c_str());
if (!out.good())
throw util::FileException(filename, std::strerror(errno));
std::string name = util::fs::basename(prefix);
for (std::size_t i = 0; i < materials.size(); ++i) {
//TODO read the material parameter
std::string diffuse_map_postfix = "_" + material_names[i] + "_map_Kd.png";
out << "newmtl " << material_names[i] << std::endl
<< "Ka 1.000000 1.000000 1.000000" << std::endl
<< "Kd 1.000000 1.000000 1.000000" << std::endl
<< "Ks 0.000000 0.000000 0.000000" << std::endl
<< "Tr 1.000000" << std::endl
<< "illum 1" << std::endl
<< "Ns 1.000000" << std::endl
<< "map_Kd " << name + diffuse_map_postfix << std::endl;
}
out.close();
for (std::size_t i = 0; i < materials.size(); ++i) {
std::string filename = prefix + "_" + material_names[i] + "_map_Kd.png";
util::fs::copy_file(materials[i].diffuse_map.c_str(), filename.c_str());
}
}