/** * This source file is part of OgreColladaPlugin * an addon for OGRE (Object-oriented Graphics Rendering Engine) * For the latest info, see http://www.ogre3d.org/ * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place - Suite 330, Boston, MA 02111-1307, USA, or go to * http://www.gnu.org/copyleft/lesser.txt. * * @author Philipp Hartl * @see README */ #include "OgreColladaTexture.h" #include "OgreColladaDocument.h" #include "OgreColladaLibrary.h" #include "OgreColladaSyntax.h" #include "OgreColladaUtils.h" namespace Ogre { //------------------------------------------------------------------------- ColladaImage::ColladaImage(ColladaDocument *d, xmlNode *n) : ColladaEntity(d, n) { } //------------------------------------------------------------------------- ColladaImage::~ColladaImage(void) { } //------------------------------------------------------------------------- bool ColladaImage::doImport(void) { if (mLoaded) return mStatus; else mLoaded = true; // get attributes of tag // source is a must, watch out for reference url (local, extern)! mSource = ColladaUtils::getProperty(mNode, CS_ATR_IMAGE_SOURCE); String tmp = ColladaUtils::getProperty(mNode, CS_ATR_IMAGE_FORMAT); mFormat = (!tmp.empty()) ? tmp : ""; tmp = ColladaUtils::getProperty(mNode, CS_ATR_IMAGE_HEIGHT); mHeight = (!tmp.empty()) ? static_cast(atoi(tmp.c_str())) : 0; tmp = ColladaUtils::getProperty(mNode, CS_ATR_IMAGE_WIDTH); mWidth = (!tmp.empty()) ? static_cast(atoi(tmp.c_str())) : 0; tmp = ColladaUtils::getProperty(mNode, CS_ATR_IMAGE_DEPTH); mDepth = (!tmp.empty()) ? static_cast(atoi(tmp.c_str())) : 1; mStatus = true; return mStatus; } //------------------------------------------------------------------------- // ColladaTexture //------------------------------------------------------------------------- //------------------------------------------------------------------------- ColladaTexture::ColladaTexture(ColladaDocument *d, xmlNode *n) : ColladaEntity(d, n) { mImage = NULL; mType = ColladaTextureSpecific::UNKNOWN; } //------------------------------------------------------------------------- ColladaTexture::~ColladaTexture(void) { mImage = NULL; // attention, the image instance will be deleted by the library container! mType = ColladaTextureSpecific::UNKNOWN; } //------------------------------------------------------------------------- bool ColladaTexture::doImport(void) { if (mLoaded) return mStatus; else mLoaded = true; // child // xmlNode *asset = ColladaUtils::getChildByTagName(mNode, CS_ELM_ASSET); // childs, describes the texture dataflow xmlNodePtrVector params = ColladaUtils::getChildsByTagName(mNode, CS_ELM_PARAM); xmlNode *param = NULL; if (!params.empty()) param = params.at(0); // get the texture type String texturetype = ColladaUtils::getProperty(param, CS_ATR_NAME); mType = ColladaTextureSpecific::getType(texturetype); if (mType == ColladaTextureSpecific::UNKNOWN) { LogManager::getSingleton().logMessage("ColladaTexture::doImport - unknown! " + mId); return false; } // nodes xmlNodePtrVector techniques = ColladaUtils::getChildsByTagName(mNode, CS_ELM_TECHNIQUE); // currently we are only interested in "COMMON" profile xmlNode *technique = NULL; for (xmlNodePtrVector::iterator it = techniques.begin(); it != techniques.end(); ++it) { String profile = ColladaUtils::getProperty(*it, CS_ATR_PROFILE); if (profile == CS_VAL_TECHNIQUE_PROFILE_COMMON) { technique = *it; break; } } if (technique == NULL) return false; // the child, there are more than one possible, but only one makes sense xmlNode *input = ColladaUtils::getChildByTagName(technique, CS_ELM_INPUT); // the semantic property should be "IMAGE" String semantic = ColladaUtils::getProperty(input, CS_ATR_INPUT_SEMANTIC); if (semantic != CS_VAL_INPUT_SEMANTIC_IMAGE) { LogManager::getSingleton().logMessage("ColladaTexture::doImport - unknown"); return false; } // the source url String source = ColladaUtils::getProperty(input, CS_ATR_INPUT_SOURCE); if (source.empty()) { LogManager::getSingleton().logMessage("ColladaTexture::doImport - no source url for texture is given! " + mId); return false; } // local reference of image file if (source.find("#") == 0) { source.erase(0,1); // try to find the instance and load it, if it is not already loaded mImage = mDoc->getLibrary()->getImage(source); if (mImage == NULL) { LogManager::getSingleton().logMessage("ColladaTexture::doImport - can't find the image reference " + source + "! " + mId); return false; } // try to import the entity if (!mImage->doImport()) { LogManager::getSingleton().logMessage("ColladaTexture::doImport - loading of image " + source + " failed! " + mId); return false; } } // external else { LogManager::getSingleton().logMessage("ColladaTexture::doImport - external refernces are currently not implemented! " + mId); return false; } mStatus = true; return mStatus; } //------------------------------------------------------------------------- namespace ColladaTextureSpecific { Type getType(const String &s) { if (s == CS_VAL_TEXTURE_PARAM_AMBIENT) return AMBIENT; else if (s == CS_VAL_TEXTURE_PARAM_DIFFUSE) return DIFFUSE; else if (s == CS_VAL_TEXTURE_PARAM_EMISSION) return EMISSION; else if (s == CS_VAL_TEXTURE_PARAM_SHININESS) return SHININESS; else if (s == CS_VAL_TEXTURE_PARAM_SPECULAR) return SPECULAR; else return UNKNOWN; }; } }