Panda3D
 All Classes Functions Variables Enumerations
colladaBindMaterial.cxx
00001 // Filename: colladaBindMaterial.cxx
00002 // Created by:  rdb (26May11)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "colladaBindMaterial.h"
00016 #include "colladaPrimitive.h"
00017 
00018 // Collada DOM includes.  No other includes beyond this point.
00019 #include "pre_collada_include.h"
00020 #include <dom/domBind_material.h>
00021 #include <dom/domEffect.h>
00022 #include <dom/domInstance_effect.h>
00023 #include <dom/domInstance_material.h>
00024 #include <dom/domMaterial.h>
00025 
00026 #if PANDA_COLLADA_VERSION >= 15
00027 #include <dom/domFx_profile.h>
00028 #else
00029 #include <dom/domFx_profile_abstract.h>
00030 #define domFx_profile domFx_profile_abstract
00031 #define domFx_profile_Array domFx_profile_abstract_Array
00032 #define getFx_profile_array getFx_profile_abstract_array
00033 #endif
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: ColladaBindMaterial::get_material
00037 //  Description: Returns the material to be applied to the given
00038 //               primitive, or NULL if there was none bound.
00039 ////////////////////////////////////////////////////////////////////
00040 CPT(RenderState) ColladaBindMaterial::
00041 get_material(const ColladaPrimitive *prim) const {
00042   if (prim == NULL || _states.count(prim->get_material()) == 0) {
00043     return NULL;
00044   }
00045   return _states.find(prim->get_material())->second;
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: ColladaBindMaterial::get_material
00050 //  Description: Returns the bound material with the indicated
00051 //               symbol, or NULL if it was not found.
00052 ////////////////////////////////////////////////////////////////////
00053 CPT(RenderState) ColladaBindMaterial::
00054 get_material(const string &symbol) const {
00055   if (_states.count(symbol) == 0) {
00056     return NULL;
00057   }
00058   return _states.find(symbol)->second;
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //     Function: ColladaBindMaterial::load_bind_material
00063 //  Description: Loads a bind_material object.
00064 ////////////////////////////////////////////////////////////////////
00065 void ColladaBindMaterial::
00066 load_bind_material(domBind_material &bind_mat) {
00067   domInstance_material_Array &mat_instances
00068     = bind_mat.getTechnique_common()->getInstance_material_array();
00069 
00070   for (size_t i = 0; i < mat_instances.getCount(); ++i) {
00071     load_instance_material(*mat_instances[i]);
00072   }
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: ColladaBindMaterial::load_instance_material
00077 //  Description: Loads an instance_material object.
00078 ////////////////////////////////////////////////////////////////////
00079 void ColladaBindMaterial::
00080 load_instance_material(domInstance_material &inst) {
00081   domMaterialRef mat = daeSafeCast<domMaterial> (inst.getTarget().getElement());
00082   nassertv(mat != NULL);
00083 
00084   domInstance_effectRef einst = mat->getInstance_effect();
00085   nassertv(einst != NULL);
00086 
00087   domInstance_effect::domSetparam_Array &setparams = einst->getSetparam_array();
00088 
00089   domEffectRef effect = daeSafeCast<domEffect>
00090     (mat->getInstance_effect()->getUrl().getElement());
00091 
00092   //TODO: read params
00093   
00094   const domFx_profile_Array &profiles = effect->getFx_profile_array();
00095   for (size_t i = 0; i < profiles.getCount(); ++i) {
00096     //profiles[i]->
00097   }
00098 }
 All Classes Functions Variables Enumerations