Blender  V2.93
Materials.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
19 #include <map>
20 #include <string>
21 
22 #include "BKE_context.h"
23 #include "BKE_node.h"
24 #include "BLI_listbase.h"
25 #include "DNA_material_types.h"
26 #include "DNA_node_types.h"
27 
28 #include "COLLADAFWEffectCommon.h"
29 #include "collada_utils.h"
30 
31 typedef std::map<std::string, bNode *> NodeMap;
32 
33 class MaterialNode {
34 
35  private:
36  bContext *mContext;
37  Material *material;
38  COLLADAFW::EffectCommon *effect;
39  UidImageMap *uid_image_map = nullptr;
40  KeyImageMap *key_image_map = nullptr;
41 
42  NodeMap node_map;
43  bNodeTree *ntree;
44 
45  bNode *shader_node;
46  bNode *output_node;
47 
48  bNodeTree *prepare_material_nodetree();
49  bNode *add_node(int node_type, int locx, int locy, std::string label);
50  void add_link(bNode *from_node, int from_index, bNode *to_node, int to_index);
51  bNode *add_texture_node(COLLADAFW::ColorOrTexture &cot, int locx, int locy, std::string label);
52  void setShaderType();
53 
54  public:
55  MaterialNode(bContext *C, COLLADAFW::EffectCommon *ef, Material *ma, UidImageMap &uid_image_map);
56  MaterialNode(bContext *C, Material *ma, KeyImageMap &key_image_map);
58 
59  void set_diffuse(COLLADAFW::ColorOrTexture &cot);
60  void set_specular(COLLADAFW::ColorOrTexture &cot);
61  void set_ambient(COLLADAFW::ColorOrTexture &cot);
62  void set_reflective(COLLADAFW::ColorOrTexture &cot);
63  void set_emission(COLLADAFW::ColorOrTexture &cot);
64  void set_opacity(COLLADAFW::ColorOrTexture &cot);
65  void set_reflectivity(COLLADAFW::FloatOrParam &val);
66  void set_shininess(COLLADAFW::FloatOrParam &val);
67  void set_ior(COLLADAFW::FloatOrParam &val);
68  void set_alpha(COLLADAFW::EffectCommon::OpaqueMode mode,
69  COLLADAFW::ColorOrTexture &cot,
70  COLLADAFW::FloatOrParam &val);
71 
73 };
std::map< std::string, bNode * > NodeMap
Definition: Materials.h:31
#define C
Definition: RandGen.cpp:39
void set_reflectivity(COLLADAFW::FloatOrParam &val)
Definition: Materials.cpp:136
void set_shininess(COLLADAFW::FloatOrParam &val)
void set_specular(COLLADAFW::ColorOrTexture &cot)
Definition: Materials.cpp:364
void update_material_nodetree()
Definition: Materials.cpp:108
void set_ior(COLLADAFW::FloatOrParam &val)
Definition: Materials.cpp:158
void set_reflective(COLLADAFW::ColorOrTexture &cot)
Definition: Materials.cpp:296
void set_emission(COLLADAFW::ColorOrTexture &cot)
Definition: Materials.cpp:312
Image * get_diffuse_image()
Definition: Materials.cpp:239
MaterialNode(bContext *C, COLLADAFW::EffectCommon *ef, Material *ma, UidImageMap &uid_image_map)
Definition: Materials.cpp:31
void set_opacity(COLLADAFW::ColorOrTexture &cot)
Definition: Materials.cpp:339
void set_alpha(COLLADAFW::EffectCommon::OpaqueMode mode, COLLADAFW::ColorOrTexture &cot, COLLADAFW::FloatOrParam &val)
Definition: Materials.cpp:172
void set_diffuse(COLLADAFW::ColorOrTexture &cot)
Definition: Materials.cpp:218
void set_ambient(COLLADAFW::ColorOrTexture &cot)
Definition: Materials.cpp:280
std::map< std::string, Image * > KeyImageMap
Definition: collada_utils.h:70
std::map< COLLADAFW::UniqueId, Image * > UidImageMap
Definition: collada_utils.h:69
const char * label