Пример #1
0
void CDlgClient::OnBtConvert() 
{
  HTREEITEM hSelected = m_Tree.GetSelectedItem();
  // just in case that no item is seleceted
  if(hSelected==NULL) {
    return;
  }

  NodeInfo &niSelected = theApp.m_dlgBarTreeView.GetNodeInfo(hSelected);
  // if selected type is mesh list
  if(niSelected.ni_iType == NT_MESHLODLIST) {

    MeshInstance *pmshi = (MeshInstance*)niSelected.ni_pPtr;
    CTString fnMesh = pmshi->mi_pMesh->GetName();
    // save and convert mesh instance
    if(theApp.SaveMeshListFile(*pmshi,TRUE)) {
      theApp.NotificationMessage("Mesh list file '%s' converted",(const char*)fnMesh);
      theApp.UpdateRootModelInstance();
    } else {
      theApp.ErrorMessage("Cannot convert mesh file '%s'",(const char*)fnMesh);
    }
  // if selected type is skeleton list
  } else if(niSelected.ni_iType == NT_SKELETONLODLIST) {
    // Get pointer to skeleton
    CSkeleton *pskl = (CSkeleton*)niSelected.ni_pPtr;
    CTString fnSkeleton = pskl->GetName();
    // save and convert mesh instance
    if(theApp.SaveSkeletonListFile(*pskl,TRUE)) {
      theApp.NotificationMessage("Skeleton list file '%s' converted",(const char*)fnSkeleton);
      theApp.UpdateRootModelInstance();
    } else {
      theApp.ErrorMessage("Cannot convert skeleton list file '%s'",(const char*)fnSkeleton);
    }
  // if selected type is animset
  } else if(niSelected.ni_iType == NT_ANIMSET) {
    // Get pointer to animset
    CAnimSet *pas = (CAnimSet*)niSelected.ni_pPtr;
    CTString fnAnimSet = pas->GetName();
    // save and convert mesh instance
    if(theApp.SaveAnimSetFile(*pas,TRUE)) {
      theApp.NotificationMessage("AnimSet file '%s' converted",(const char*)fnAnimSet);
      theApp.UpdateRootModelInstance();
    } else {
      theApp.ErrorMessage("Cannot convert animset file '%s'",(const char*)fnAnimSet);
    }
  }
  CSeriousSkaStudioDoc *pDoc = theApp.GetDocument();
  pDoc->MarkAsChanged();
}
// save skeleton list file 
BOOL CSeriousSkaStudioApp::SaveSkeletonListFile(CSkeleton &skl, BOOL bConvert)
{
  DisableRendering();
  CTFileName fnSkeletonList = skl.GetName();
  fnSkeletonList = fnSkeletonList.NoExt() + ".asl";
  try {
    fnSkeletonList.RemoveApplicationPath_t();
  }
  catch(char *){}

  // back up current skeleton list file
  CTString strBackUp;
  try {
    strBackUp.Load_t(fnSkeletonList);
  }
  catch(char*){}

  CTFileStream ostrFile;
  try {
    ostrFile.Create_t(fnSkeletonList,CTStream::CM_TEXT);
    SaveSkeletonList_t(skl,ostrFile);
    ostrFile.Close();
  } catch(char *strError) {
    ErrorMessage(strError);
    EnableRendering();
    return FALSE;
  }

  if(bConvert) {
    if(!ConvertSkeleton(fnSkeletonList)) {
      // convert failed
      if(strBackUp.Length()>0) {
        // try returning old mesh list file
        try {
          strBackUp.Save_t(fnSkeletonList);
        }
        catch(char*){}
      }
    }
  }
  EnableRendering();
  return TRUE;
}