Panda3D
colladaBindMaterial.cxx
1 // Filename: colladaBindMaterial.cxx
2 // Created by: rdb (26May11)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "colladaBindMaterial.h"
16 #include "colladaPrimitive.h"
17 
18 // Collada DOM includes. No other includes beyond this point.
19 #include "pre_collada_include.h"
20 #include <dom/domBind_material.h>
21 #include <dom/domEffect.h>
22 #include <dom/domInstance_effect.h>
23 #include <dom/domInstance_material.h>
24 #include <dom/domMaterial.h>
25 
26 #if PANDA_COLLADA_VERSION >= 15
27 #include <dom/domFx_profile.h>
28 #else
29 #include <dom/domFx_profile_abstract.h>
30 #define domFx_profile domFx_profile_abstract
31 #define domFx_profile_Array domFx_profile_abstract_Array
32 #define getFx_profile_array getFx_profile_abstract_array
33 #endif
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: ColladaBindMaterial::get_material
37 // Description: Returns the material to be applied to the given
38 // primitive, or NULL if there was none bound.
39 ////////////////////////////////////////////////////////////////////
40 CPT(RenderState) ColladaBindMaterial::
41 get_material(const ColladaPrimitive *prim) const {
42  if (prim == NULL || _states.count(prim->get_material()) == 0) {
43  return NULL;
44  }
45  return _states.find(prim->get_material())->second;
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: ColladaBindMaterial::get_material
50 // Description: Returns the bound material with the indicated
51 // symbol, or NULL if it was not found.
52 ////////////////////////////////////////////////////////////////////
53 CPT(RenderState) ColladaBindMaterial::
54 get_material(const string &symbol) const {
55  if (_states.count(symbol) == 0) {
56  return NULL;
57  }
58  return _states.find(symbol)->second;
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: ColladaBindMaterial::load_bind_material
63 // Description: Loads a bind_material object.
64 ////////////////////////////////////////////////////////////////////
65 void ColladaBindMaterial::
66 load_bind_material(domBind_material &bind_mat) {
67  domInstance_material_Array &mat_instances
68  = bind_mat.getTechnique_common()->getInstance_material_array();
69 
70  for (size_t i = 0; i < mat_instances.getCount(); ++i) {
71  load_instance_material(*mat_instances[i]);
72  }
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: ColladaBindMaterial::load_instance_material
77 // Description: Loads an instance_material object.
78 ////////////////////////////////////////////////////////////////////
80 load_instance_material(domInstance_material &inst) {
81  domMaterialRef mat = daeSafeCast<domMaterial> (inst.getTarget().getElement());
82  nassertv(mat != NULL);
83 
84  domInstance_effectRef einst = mat->getInstance_effect();
85  nassertv(einst != NULL);
86 
87  domInstance_effect::domSetparam_Array &setparams = einst->getSetparam_array();
88 
89  domEffectRef effect = daeSafeCast<domEffect>
90  (mat->getInstance_effect()->getUrl().getElement());
91 
92  //TODO: read params
93 
94  const domFx_profile_Array &profiles = effect->getFx_profile_array();
95  for (size_t i = 0; i < profiles.getCount(); ++i) {
96  //profiles[i]->
97  }
98 }
void load_instance_material(domInstance_material &inst)
Loads an instance_material object.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
Class that deals with COLLADA primitive structures, such as <triangles> and <polylist>.