Panda3D
daeMaterials.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file daeMaterials.h
10  * @author rdb
11  * @date 2008-10-03
12  */
13 
14 #ifndef DAEMATERIALS_H
15 #define DAEMATERIALS_H
16 
17 #include "pandatoolbase.h"
18 #include "eggMaterial.h"
19 #include "eggTexture.h"
20 #include "eggPrimitive.h"
21 #include "eggGroup.h"
22 #include "pointerTo.h"
23 #include "pt_EggTexture.h"
24 #include "pt_EggMaterial.h"
25 
26 #include "pre_fcollada_include.h"
27 #include <FCollada.h>
28 #include <FCDocument/FCDGeometryInstance.h>
29 #include <FCDocument/FCDMaterialInstance.h>
30 #include <FCDocument/FCDEffectStandard.h>
31 #include <FCDocument/FCDEffectParameterSampler.h>
32 #include <FCDocument/FCDExtra.h>
33 
34 /**
35  * This class is seperated from the converter file because otherwise it would
36  * get too big and needlessly complicated.
37  */
39 public:
40  DaeMaterials(const FCDGeometryInstance* geometry_instance);
41  virtual ~DaeMaterials() {};
42 
43  void add_material_instance(const FCDMaterialInstance* instance);
44  void apply_to_primitive(const std::string semantic, const PT(EggPrimitive) to);
45  void apply_to_group(const std::string semantic, const PT(EggGroup) to, bool invert_transparency=false);
46  const std::string get_uvset_name(const std::string semantic, FUDaeGeometryInput::Semantic input_semantic, int32 input_set);
47 
48  static EggTexture::TextureType convert_texture_type(const FCDEffectParameterSampler::SamplerType orig_type);
49  static EggTexture::WrapMode convert_wrap_mode(const FUDaeTextureWrapMode::WrapMode orig_mode);
50  static EggTexture::FilterType convert_filter_type(const FUDaeTextureFilterFunction::FilterFunction orig_type);
51 
52 private:
53  // Holds stuff for color blend attribs.
54  struct DaeBlendSettings : public ReferenceCount {
55  bool _enabled;
56  LColor _color;
57  EggGroup::BlendOperand _operand_a;
58  EggGroup::BlendOperand _operand_b;
59  };
60 
61  // Holds information to bind texcoord inputs to textures.
62  struct DaeVertexInputBinding : public ReferenceCount {
63  int32 _input_set;
64  FUDaeGeometryInput::Semantic _input_semantic;
65  std::string _semantic;
66  };
67 
68  // Holds stuff for an individual material.
69  struct DaeMaterial : public ReferenceCount {
70  pvector<PT_EggTexture> _egg_textures;
71  PT_EggMaterial _egg_material;
72  bool _double_sided;
73  pvector<PT(DaeVertexInputBinding)> _uvsets;
74  PT(DaeBlendSettings) _blend;
75  };
76 
77  void process_texture_bucket(const std::string semantic, const FCDEffectStandard* effect_common, FUDaeTextureChannel::Channel bucket, EggTexture::EnvType envtype = EggTexture::ET_unspecified, EggTexture::Format format = EggTexture::F_unspecified);
78  void process_extra(const std::string semantic, const FCDExtra* extra);
79  static PT(DaeBlendSettings) convert_blend(FCDEffectStandard::TransparencyMode mode, const LColor &transparent, double transparency);
80 
81  pmap<const std::string, PT(DaeMaterial)> _materials;
82 
83 public:
84  virtual TypeHandle get_type() const {
85  return get_class_type();
86  }
87  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
88  static TypeHandle get_class_type() {
89  return _type_handle;
90  }
91  static void init_type() {
92  TypedReferenceCount::init_type();
93  register_type(_type_handle, "DaeMaterials",
94  TypedReferenceCount::get_class_type());
95  }
96 
97 private:
98  static TypeHandle _type_handle;
99 };
100 
101 #endif
DaeMaterials::convert_filter_type
static EggTexture::FilterType convert_filter_type(const FUDaeTextureFilterFunction::FilterFunction orig_type)
Converts an FCollada filter function to the EggTexture wrap type equivalent.
Definition: daeMaterials.cxx:335
DaeMaterials::add_material_instance
void add_material_instance(const FCDMaterialInstance *instance)
Adds a material instance.
Definition: daeMaterials.cxx:50
pt_EggMaterial.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pt_EggTexture.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
eggPrimitive.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector< PT_EggTexture >
ReferenceCount
A base class for all things that want to be reference-counted.
Definition: referenceCount.h:38
pmap
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
DaeMaterials::apply_to_primitive
void apply_to_primitive(const std::string semantic, const PT(EggPrimitive) to)
Applies the stuff to the given EggPrimitive.
Definition: daeMaterials.cxx:215
DaeMaterials
This class is seperated from the converter file because otherwise it would get too big and needlessly...
Definition: daeMaterials.h:38
eggMaterial.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
eggTexture.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggPrimitive
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
Definition: eggPrimitive.h:47
DaeMaterials::convert_wrap_mode
static EggTexture::WrapMode convert_wrap_mode(const FUDaeTextureWrapMode::WrapMode orig_mode)
Converts an FCollada wrap mode to the EggTexture wrap mode equivalent.
Definition: daeMaterials.cxx:309
TypedReferenceCount
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
Definition: typedReferenceCount.h:31
DaeMaterials::convert_texture_type
static EggTexture::TextureType convert_texture_type(const FCDEffectParameterSampler::SamplerType orig_type)
Converts an FCollada sampler type to the EggTexture texture type equivalent.
Definition: daeMaterials.cxx:289
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
pre_fcollada_include.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DaeMaterials::apply_to_group
void apply_to_group(const std::string semantic, const PT(EggGroup) to, bool invert_transparency=false)
Applies the colorblend stuff to the given EggGroup.
Definition: daeMaterials.cxx:230
pandatoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggGroup
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
Definition: eggGroup.h:34
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
eggGroup.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DaeMaterials::get_uvset_name
const std::string get_uvset_name(const std::string semantic, FUDaeGeometryInput::Semantic input_semantic, int32 input_set)
Returns the semantic of the uvset with the specified input set, or an empty string if the given mater...
Definition: daeMaterials.cxx:257