⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coremodel.cpp

📁 Cal3D实现虚拟角色 Cal3D实现虚拟角色
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  * @param coreAnimationId The ID of the core animation that should be saved.  *  * @return One of the following values:  *         \li \b true if successful  *         \li \b false if an error happend  *****************************************************************************/bool CalCoreModel::saveCoreAnimation(const std::string& strFilename, int coreAnimationId){  // check if the core animation id is valid  if((coreAnimationId < 0) || (coreAnimationId >= (int)m_vectorCoreAnimation.size()))  {    CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);    return false;  }  // save the core animation  if(!CalSaver::saveCoreAnimation(strFilename, m_vectorCoreAnimation[coreAnimationId].get()))  {    return false;  }  return true;} /*****************************************************************************//** Saves a core material.  *  * This function saves a core material to a file.  *  * @param strFilename The file to which the core material should be saved to.  * @param coreMaterialId The ID of the core material that should be saved.  *  * @return One of the following values:  *         \li \b true if successful  *         \li \b false if an error happend  *****************************************************************************/bool CalCoreModel::saveCoreMaterial(const std::string& strFilename, int coreMaterialId){  // check if the core material id is valid  if((coreMaterialId < 0) || (coreMaterialId >= (int)m_vectorCoreMaterial.size()))  {    CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);    return false;  }  // save the core animation  return CalSaver::saveCoreMaterial(strFilename, m_vectorCoreMaterial[coreMaterialId].get());} /*****************************************************************************//** Saves a core mesh.  *  * This function saves a core mesh to a file.  *  * @param strFilename The file to which the core mesh should be saved to.  * @param coreMeshId The ID of the core mesh that should be saved.  *  * @return One of the following values:  *         \li \b true if successful  *         \li \b false if an error happend  *****************************************************************************/bool CalCoreModel::saveCoreMesh(const std::string& strFilename, int coreMeshId){  // check if the core mesh id is valid  if((coreMeshId < 0) || (coreMeshId >= (int)m_vectorCoreMesh.size()))  {    CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);    return false;  }  // save the core animation  return CalSaver::saveCoreMesh(strFilename, m_vectorCoreMesh[coreMeshId].get());} /*****************************************************************************//** Saves the core skeleton.  *  * This function saves the core skeleton to a file.  *  * @param strFilename The file to which the core skeleton should be saved to.  *  * @return One of the following values:  *         \li \b true if successful  *         \li \b false if an error happend  *****************************************************************************/bool CalCoreModel::saveCoreSkeleton(const std::string& strFilename){  // check if we have a core skeleton in this code model  if(!m_pCoreSkeleton)  {    CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);    return false;  }  // save the core skeleton  return CalSaver::saveCoreSkeleton(strFilename, m_pCoreSkeleton.get());} /*****************************************************************************//** Sets a core material ID.  *  * This function sets a core material ID for a core material thread / core  * material set pair.  *  * @param coreMaterialThreadId The ID of the core material thread.  * @param coreMaterialSetId The ID of the core maetrial set.  * @param coreMaterialId The ID of the core maetrial.  *  * @return One of the following values:  *         \li \b true if successful  *         \li \b false if an error happend  *****************************************************************************/bool CalCoreModel::setCoreMaterialId(int coreMaterialThreadId, int coreMaterialSetId, int coreMaterialId){  // 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 false;  }  // get the core material thread  std::map<int, int>& coreMaterialThread = (*iteratorCoreMaterialThread).second;  // remove a possible entry in the core material thread  coreMaterialThread.erase(coreMaterialSetId);  // set the given set id in the core material thread to the given core material id  coreMaterialThread.insert(std::make_pair(coreMaterialSetId, coreMaterialId));  return true;} /*****************************************************************************//** Sets the core skeleton.  *  * This function sets the core skeleton of the core model instance..  *  * @param pCoreSkeleton The core skeleton that should be set.  *****************************************************************************/void CalCoreModel::setCoreSkeleton(CalCoreSkeleton *pCoreSkeleton){  if(pCoreSkeleton == 0)  {    CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);    return;  }  m_pCoreSkeleton = pCoreSkeleton;  } /*****************************************************************************//** Stores user data.  *  * This function stores user data in the core model instance.  *  * @param userData The user data that should be stored.  *****************************************************************************/void CalCoreModel::setUserData(Cal::UserData userData){  m_userData = userData;} /*****************************************************************************//** Creates or overwrites a string-to-boneId mapping  *  * This function makes a bone ID reference-able by a string name.  *  * @param strBoneName The string that will be associated with the ID.  * @param boneId The ID number of the bone that will be referenced by the string.  *****************************************************************************/void CalCoreModel::addBoneName(const std::string& strBoneName, int boneId){  //Make sure the skeleton has been loaded first  if (m_pCoreSkeleton)  {    //Map the bone ID to the name    m_pCoreSkeleton->mapCoreBoneName(boneId, strBoneName);  }} /*****************************************************************************//** Retrieves the ID of the bone referenced by a string  *  * This function returns a bone ID  *  * @param strBoneName A string that is associated with a bone ID number.  * @return Returns:  *         \li \b -1 if there is no bone ID associated with the input string  *         \li \b the ID number of the bone asssociated with the input string  *****************************************************************************/int CalCoreModel::getBoneId(const std::string& strBoneName){  if (m_pCoreSkeleton)  {    return m_pCoreSkeleton->getCoreBoneId(strBoneName);  }  return -1;} /*****************************************************************************//** Creates or overwrites a string-to-animation ID mapping  *  * This function makes an animation ID reference-able by a string name.  * Note that we don't verify that the ID is valid because the animation  * may be added later.  * Also, if there is already a helper with this name, it will be overwritten  * without warning.  *  * @param strAnimationName The string that will be associated with the ID.  * @param coreAnimationId The ID number of the animation to be referenced by the string.  *****************************************************************************/bool CalCoreModel::addAnimationName(const std::string& strAnimationName, int coreAnimationId){  // check if the core animation id is valid  if((coreAnimationId < 0) || (coreAnimationId >= (int)m_vectorCoreAnimation.size()))  {    CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);    return false;  }  m_vectorCoreAnimation[ coreAnimationId ]->setName(strAnimationName);  m_animationName[ strAnimationName ] = coreAnimationId;  return true;} /*****************************************************************************//** Retrieves the ID of the animation referenced by a string  *  * This function returns an animation ID  *  * @param strAnimationName A string that is associated with an anim ID number.  * @return Returns:  *         \li \b -1 if there is no anim ID associated with the input string  *         \li \b the ID number of the anim asssociated with the input string  *****************************************************************************/int CalCoreModel::getCoreAnimationId(const std::string& strAnimationName){  if (m_animationName.count( strAnimationName ) < 1)  {    return -1;  }     if (getCoreAnimation(m_animationName[strAnimationName]) == NULL)  {    return -1;  }  return m_animationName[strAnimationName];} /*****************************************************************************//** Creates or overwrites a string-to-core-material ID mapping  *  * This function makes a core material ID reference-able by a string name.  * Note that we don't verify that the ID is valid because the material  * may be added later.  * Also, if there is already a helper with this name, it will be overwritten  * without warning.  *  * @param strMaterialName The string that will be associated with the ID.  * @param coreMaterialId The core ID number of the material to be referenced by the string.  *****************************************************************************/bool CalCoreModel::addMaterialName(const std::string& strMaterialName, int coreMaterialId){    // check if the core material id is valid  if((coreMaterialId < 0) || (coreMaterialId >= (int)m_vectorCoreMaterial.size()))  {    CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);    return false;  }  m_vectorCoreMaterial[ coreMaterialId ]->setName(strMaterialName);  m_materialName[ strMaterialName ] = coreMaterialId;  return true;} /*****************************************************************************//** Retrieves the ID of the core material referenced by a string  *  * This function returns a core material ID  *  * @param strMaterialName A string that is associated with a core material ID number.  * @return Returns:  *         \li \b -1 if there is no core material ID associated with the input string  *         \li \b the core ID number of the material asssociated with the input string  *****************************************************************************/int CalCoreModel::getCoreMaterialId(const std::string& strMaterialName){  if (m_materialName.count( strMaterialName ) < 1)  {    return -1;  }  if (getCoreMaterial(m_materialName[strMaterialName]) == NULL)   {    return -1;  }  return m_materialName[strMaterialName];} /*****************************************************************************//** Creates or overwrites a string-to-core-mesh ID mapping  *  * This function makes a core mesh ID reference-able by a string name.  * Note that we don't verify that the ID is valid because the mesh  * may be added later.  * Also, if there is already a helper with this name, it will be overwritten  * without warning.  *  * @param strMeshName The string that will be associated with the ID.  * @param coreMeshId The core ID number of the mesh to be referenced by the string.  *****************************************************************************/bool CalCoreModel::addMeshName(const std::string& strMeshName, int coreMeshId){  // check if the core mesh id is valid  if((coreMeshId < 0) || (coreMeshId >= (int)m_vectorCoreMesh.size()))  {    CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);    return false;  }  m_vectorCoreMesh[ coreMeshId ]->setName(strMeshName);  m_meshName[ strMeshName ] = coreMeshId;  return true;} /*****************************************************************************//** Retrieves the ID of the core mesh referenced by a string  *  * This function returns a core mesh ID  *  * @param strMeshName A string that is associated with a core mesh ID number.  * @return Returns:  *         \li \b -1 if there is no core mesh ID associated with the input string  *         \li \b the core ID number of the mesh asssociated with the input string  *****************************************************************************/int CalCoreModel::getCoreMeshId(const std::string& strMeshName){  if (m_meshName.count( strMeshName ) < 1)  {    return -1;  }  if (getCoreMesh(m_meshName[strMeshName]) == NULL)  {    return -1;  }  return m_meshName[strMeshName];} /*****************************************************************************//** Scale the core model.  *  * This function rescale all data that are in the core model instance  *  * @param factor A float with the scale factor  *  *****************************************************************************/void CalCoreModel::scale(float factor){  m_pCoreSkeleton->scale(factor);  for(size_t animationId = 0; animationId < m_vectorCoreAnimation.size(); animationId++)  {    m_vectorCoreAnimation[animationId]->scale(factor);  }  for(size_t meshId = 0; meshId < m_vectorCoreMesh.size(); meshId++)  {    m_vectorCoreMesh[meshId]->scale(factor);  }}//****************************************************************************//

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -