📄 coremodel.cpp
字号:
//****************************************************************************//// coremodel.cpp //// Copyright (C) 2001, 2002 Bruno 'Beosil' Heidelberger ////****************************************************************************//// This library 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.1 of the License, or (at //// your option) any later version. ////****************************************************************************//#ifdef HAVE_CONFIG_H#include "config.h"#endif//****************************************************************************//// Includes ////****************************************************************************//#include "cal3d/coremodel.h"#include "cal3d/error.h"#include "cal3d/coreskeleton.h"#include "cal3d/coreanimation.h"#include "cal3d/coremorphanimation.h"#include "cal3d/coremesh.h"#include "cal3d/corematerial.h"#include "cal3d/loader.h"#include "cal3d/saver.h" /*****************************************************************************//** Constructs the core model instance. * * This function is the default constructor of the core model instance. *****************************************************************************/CalCoreModel::CalCoreModel(const std::string& name): m_strName(name), m_pCoreSkeleton(0), m_userData(0){} /*****************************************************************************//** Destructs the core model instance. * * This function is the destructor of the core model instance. *****************************************************************************/CalCoreModel::~CalCoreModel(){ // destroy all core morph animations std::vector<CalCoreMorphAnimation *>::iterator iteratorCoreMorphAnimation; for(iteratorCoreMorphAnimation = m_vectorCoreMorphAnimation.begin(); iteratorCoreMorphAnimation != m_vectorCoreMorphAnimation.end(); ++iteratorCoreMorphAnimation) { delete (*iteratorCoreMorphAnimation); } m_vectorCoreMorphAnimation.clear();} /*****************************************************************************//** Adds a core animation. * * This function adds a core animation to the core model instance. * * @param pCoreAnimation A pointer to the core animation that should be added. * * @return \li the assigned animation \b ID of the added core animation *****************************************************************************/int CalCoreModel::addCoreAnimation(CalCoreAnimation *pCoreAnimation){ int animationId = m_vectorCoreAnimation.size(); m_vectorCoreAnimation.push_back(pCoreAnimation); return animationId;} /*****************************************************************************//** Adds a core morph animation. * * This function adds a core morph animation to the core model instance. * * @param pCoreMorphAnimation A pointer to the core morph animation that * should be added. * * @return One of the following values: * \li the assigned morph animation \b ID of the added core morph animation * \li \b -1 if an error happend *****************************************************************************/int CalCoreModel::addCoreMorphAnimation(CalCoreMorphAnimation *pCoreMorphAnimation){ // get the id of the core morph animation int morphAnimationId; morphAnimationId = m_vectorCoreMorphAnimation.size(); m_vectorCoreMorphAnimation.push_back(pCoreMorphAnimation); return morphAnimationId;} /*****************************************************************************//** Adds a core material. * * This function adds a core material to the core model instance. * * @param pCoreMaterial A pointer to the core material that should be added. * * @return One of the following values: * \li the assigned material \b ID of the added core material * \li \b -1 if an error happend *****************************************************************************/int CalCoreModel::addCoreMaterial(CalCoreMaterial *pCoreMaterial){ // get the id of the core material int materialId = m_vectorCoreMaterial.size(); m_vectorCoreMaterial.push_back(pCoreMaterial); return materialId;} /*****************************************************************************//** Adds a core mesh. * * This function adds a core mesh to the core model instance. * * @param pCoreMesh A pointer to the core mesh that should be added. * * @return One of the following values: * \li the assigned mesh \b ID of the added core material * \li \b -1 if an error happend *****************************************************************************/int CalCoreModel::addCoreMesh(CalCoreMesh *pCoreMesh){ // get the id of the core mesh int meshId = m_vectorCoreMesh.size(); m_vectorCoreMesh.push_back(pCoreMesh); return meshId;} /*****************************************************************************//** Creates a core material thread. * * This function creates a new core material thread with the given ID. * * @param coreMaterialThreadId The ID of the core material thread that should * be created. * * @return One of the following values: * \li \b true if successful * \li \b false if an error happend *****************************************************************************/bool CalCoreModel::createCoreMaterialThread(int coreMaterialThreadId){ // insert an empty core material thread with a given id std::map<int, int> mapCoreMaterialThreadId; m_mapmapCoreMaterialThread.insert(std::make_pair(coreMaterialThreadId, mapCoreMaterialThreadId)); return true;} /*****************************************************************************//** Provides access to a core animation. * * This function returns the core animation with the given ID. * * @param coreAnimationId The ID of the core animation that should be returned. * * @return One of the following values: * \li a pointer to the core animation * \li \b 0 if an error happend *****************************************************************************/CalCoreAnimation *CalCoreModel::getCoreAnimation(int coreAnimationId){ if((coreAnimationId < 0) || (coreAnimationId >= (int)m_vectorCoreAnimation.size())) { CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__); return 0; } return m_vectorCoreAnimation[coreAnimationId].get();} /*****************************************************************************//** Provides access to a core morph animation. * * This function returns the core morph animation with the given ID. * * @param coreMorphAnimationId The ID of the core morph animation that should be returned. * * @return One of the following values: * \li a pointer to the core morph animation * \li \b 0 if an error happend *****************************************************************************/CalCoreMorphAnimation *CalCoreModel::getCoreMorphAnimation(int coreMorphAnimationId){ if((coreMorphAnimationId < 0) || (coreMorphAnimationId >= (int)m_vectorCoreMorphAnimation.size())) { CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__); return 0; } return m_vectorCoreMorphAnimation[coreMorphAnimationId];} /*****************************************************************************//** Returns the number of core animations. * * This function returns the number of core animations in the core model * instance. * * @return The number of core animations. *****************************************************************************/int CalCoreModel::getCoreAnimationCount(){ return m_vectorCoreAnimation.size();} /*****************************************************************************//** Returns the number of core morph animations. * * This function returns the number of core morph animations in the core model * instance. * * @return The number of core morph animations. *****************************************************************************/int CalCoreModel::getCoreMorphAnimationCount(){ return m_vectorCoreMorphAnimation.size();} /*****************************************************************************//** Provides access to a core material. * * This function returns the core material with the given ID. * * @param coreMaterialId The ID of the core material that should be returned. * * @return One of the following values: * \li a pointer to the core material * \li \b 0 if an error happend *****************************************************************************/CalCoreMaterial *CalCoreModel::getCoreMaterial(int coreMaterialId){ if((coreMaterialId < 0) || (coreMaterialId >= (int)m_vectorCoreMaterial.size())) { CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__); return 0; } return m_vectorCoreMaterial[coreMaterialId].get();} /*****************************************************************************//** Returns the number of core materials. * * This function returns the number of core materials in the core model * instance. * * @return The number of core materials. *****************************************************************************/int CalCoreModel::getCoreMaterialCount(){ return m_vectorCoreMaterial.size();} /*****************************************************************************//** Returns a specified core material ID. * * This function returns the core material ID for a specified core material * thread / core material set pair. * * @param coreMaterialThreadId The ID of the core material thread. * @param coreMaterialSetId The ID of the core material set. * * @return One of the following values: * \li the \b ID of the core material * \li \b -1 if an error happend *****************************************************************************/int CalCoreModel::getCoreMaterialId(int coreMaterialThreadId, int coreMaterialSetId){ // find the core material thread std::map<int, std::map<int, int> >::iterator iteratorCoreMaterialThread; iteratorCoreMaterialThread = m_mapmapCoreMaterialThread.find(coreMaterialThreadId); if(iteratorCoreMaterialThread == m_mapmapCoreMaterialThread.end()) { CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__); return -1; } // get the core material thread std::map<int, int>& coreMaterialThread = (*iteratorCoreMaterialThread).second; // find the material id for the given set std::map<int, int>::iterator iteratorSet; iteratorSet = coreMaterialThread.find(coreMaterialSetId); if(iteratorSet == coreMaterialThread.end()) { CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__); return -1; } return (*iteratorSet).second;} /*****************************************************************************//** Provides access to a core mesh. * * This function returns the core mesh with the given ID. * * @param coreMeshId The ID of the core mesh that should be returned. * * @return One of the following values: * \li a pointer to the core mesh * \li \b 0 if an error happend *****************************************************************************/CalCoreMesh *CalCoreModel::getCoreMesh(int coreMeshId){ if((coreMeshId < 0) || (coreMeshId >= (int)m_vectorCoreMesh.size())) { CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__); return 0; } return m_vectorCoreMesh[coreMeshId].get();} /*****************************************************************************//** Returns the number of core meshes. * * This function returns the number of core meshes in the core model instance. * * @return The number of core meshes. *****************************************************************************/int CalCoreModel::getCoreMeshCount(){ return m_vectorCoreMesh.size();} /*****************************************************************************//** Provides access to the core skeleton. * * This function returns the core skeleton. * * @return One of the following values: * \li a pointer to the core skeleton * \li \b 0 if an error happend *****************************************************************************/CalCoreSkeleton *CalCoreModel::getCoreSkeleton(){ return m_pCoreSkeleton.get();} /*****************************************************************************//** Provides access to the user data. * * This function returns the user data stored in the core model instance. * * @return The user data stored in the core model instance. *****************************************************************************/Cal::UserData CalCoreModel::getUserData(){ return m_userData;} /*****************************************************************************//** Loads a core animation. * * This function loads a core animation from a file. * * @param strFilename The file from which the core animation should be loaded * from. * * @return One of the following values: * \li the assigned \b ID of the loaded core animation * \li \b -1 if an error happend *****************************************************************************/int CalCoreModel::loadCoreAnimation(const std::string& strFilename){ // the core skeleton has to be loaded already if(!m_pCoreSkeleton) { CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -