//////////////////////////////////////////////////////// // // GEM - Graphics Environment for Multimedia // // zmoelnig@iem.kug.ac.at // // Implementation file // // Copyright (c) 2001-2012 IOhannes m zmölnig. forum::für::umläute. IEM. zmoelnig@iem.at // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. // ///////////////////////////////////////////////////////// #include "modelOBJ.h" #include "plugins/PluginFactory.h" #include "Gem/RTE.h" #include "Gem/Exception.h" #include "Gem/Properties.h" #include using namespace gem::plugins; REGISTER_MODELLOADERFACTORY("OBJ", modelOBJ); modelOBJ :: modelOBJ(void) : m_model(NULL), m_dispList(0), m_material(0), m_flags(GLM_SMOOTH | GLM_TEXTURE), m_group(0), m_rebuild(false), m_currentH(1.f), m_currentW(1.f), m_textype(GLM_TEX_DEFAULT), m_reverse(false) { } modelOBJ ::~modelOBJ(void) { destroy(); } bool modelOBJ :: open(const std::string&name, const gem::Properties&requestprops) { destroy(); #if 0 std::vectorkeys=requestprops.keys(); unsigned int i; for(i=0; i1.)d=1.; if(m_model) glmVertexNormals(m_model, d*180.); m_rebuild=true; } if(props.get("texwidth", d)) { if(d!=m_currentW) m_rebuild=true; m_currentW=d; } if(props.get("texheight", d)) { if(d!=m_currentH) m_rebuild=true; m_currentH=d; } if(props.get("usematerials", d)) { int flags=GLM_SMOOTH | GLM_TEXTURE; if(d) flags |= GLM_MATERIAL; if(flags!=m_flags) m_rebuild=true; m_flags=flags; } std::string s; if(props.get("textype", s)) { if("UV"==s) m_textype= GLM_TEX_UV; else if("linear"==s) m_textype= GLM_TEX_LINEAR; else if("spheremap"==s) m_textype= GLM_TEX_SPHEREMAP; m_rebuild=true; } if(props.get("group", d)) { m_group=d; m_rebuild=true; } if(props.get("reverse", d)) { // LATER:move this to compile() bool reverse=d; if((reverse!=m_reverse) && m_model) { glmReverseWinding(m_model); m_rebuild=true; } m_reverse=reverse; } } void modelOBJ :: getProperties(gem::Properties&props) { props.clear(); } bool modelOBJ :: compile(void) { if(!m_model) return false; if(!(GLEW_VERSION_1_1)) { // verbose(1, "cannot build display-list now...do you have a window?"); return false; } if (m_dispList) { glDeleteLists(m_dispList, 1); m_dispList=0; } if (!m_group){ m_dispList = glmList(m_model, m_flags); } else { m_dispList = glmListGroup(m_model, m_flags, m_group); } bool res = (0 != m_dispList); if(res) m_rebuild=false; return res; } void modelOBJ :: destroy(void) { /* LATER: check valid contexts (remove glDelete from here) */ if (m_dispList) { // destroy display list glDeleteLists(m_dispList, 1); m_dispList = 0; } if(m_model) { glmDelete(m_model); m_model=NULL; } }