Exemple #1
0
int CalCoreModel::loadCoreMaterial(const std::string& strFilename, const std::string& strMaterialName)
{
  int id = -1;
  std::map<std::string, int>::iterator it = m_materialName.find(strMaterialName);
  if (it != m_materialName.end())
  {
    id=(*it).second;

    // the core skeleton has to be loaded already
    if(!m_pCoreSkeleton)
    {
      CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);
      return -1;
    }
    if(m_vectorCoreMaterial[id])
    {
      CalError::setLastError(CalError::INDEX_BUILD_FAILED, __FILE__, __LINE__);
      return -1;
    }
    CalCoreMaterialPtr pCoreMaterial = CalLoader::loadCoreMaterial(strFilename);
    if(!pCoreMaterial) return -1;
    pCoreMaterial->setName(strMaterialName);
    m_vectorCoreMaterial[id] = pCoreMaterial;
  }
  else
  {
    id = loadCoreMaterial(strFilename);
    if(id >= 0)
      addMaterialName(strMaterialName, id);
  }

  return id;
}
Exemple #2
0
int CalCoreModel::loadCoreMaterial(const std::string& strFilename)
{
  // the core skeleton has to be loaded already
  if(!m_pCoreSkeleton)
  {
    CalError::setLastError(CalError::INVALID_HANDLE, __FILE__, __LINE__);
    return -1;
  }

  // load a new core material
  CalCoreMaterialPtr pCoreMaterial = CalLoader::loadCoreMaterial(strFilename);
  if(!pCoreMaterial) return -1;

  // add core material to this core model
  return addCoreMaterial(pCoreMaterial.get());
}
Exemple #3
0
bool CExporter::ExportMaterial(const std::string& strFilename)
{
  // check if a valid interface is set
  if(m_pInterface == 0)
  {
    SetLastError("Invalid handle.", __FILE__, __LINE__);
    return false;
  }

  // check if a valid interface is set
  if(m_pInterface == 0)
  {
    SetLastError("Invalid handle.", __FILE__, __LINE__);
    return false;
  }

  // build a material library candidate
  CMaterialLibraryCandidate materialLibraryCandidate;
  if(!materialLibraryCandidate.CreateFromInterface()) return false;

  // show export wizard sheet
  CMaterialExportSheet sheet("Cal3D Material Export", m_pInterface->GetMainWnd());
  sheet.SetMaterialLibraryCandidate(&materialLibraryCandidate);
  sheet.SetWizardMode();
  if(sheet.DoModal() != ID_WIZFINISH) return true;

  // get selected material candidate
  CMaterialCandidate *pMaterialCandidate;
  pMaterialCandidate = materialLibraryCandidate.GetSelectedMaterialCandidate();
  if(pMaterialCandidate == 0)
  {
    SetLastError("No material selected.", __FILE__, __LINE__);
    return false;
  }

  // create the core material instance
  CalCoreMaterialPtr coreMaterial = new CalCoreMaterial;

  // set the ambient color
  CalCoreMaterial::Color coreColor;
  float color[4];
  pMaterialCandidate->GetAmbientColor(&color[0]);
  coreColor.red = (unsigned char)(255.0f * color[0]);
  coreColor.green = (unsigned char)(255.0f * color[1]);
  coreColor.blue = (unsigned char)(255.0f * color[2]);
  coreColor.alpha = (unsigned char)(255.0f * color[3]);
  coreMaterial->setAmbientColor(coreColor);


  // set the diffuse color
  pMaterialCandidate->GetDiffuseColor(&color[0]);
  coreColor.red = (unsigned char)(255.0f * color[0]);
  coreColor.green = (unsigned char)(255.0f * color[1]);
  coreColor.blue = (unsigned char)(255.0f * color[2]);
  coreColor.alpha = (unsigned char)(255.0f * color[3]);
  coreMaterial->setDiffuseColor(coreColor);

  // set the specular color
  pMaterialCandidate->GetSpecularColor(&color[0]);
  coreColor.red = (unsigned char)(255.0f * color[0]);
  coreColor.green = (unsigned char)(255.0f * color[1]);
  coreColor.blue = (unsigned char)(255.0f * color[2]);
  coreColor.alpha = (unsigned char)(255.0f * color[3]);
  coreMaterial->setSpecularColor(coreColor);

  // set the shininess factor
  coreMaterial->setShininess(pMaterialCandidate->GetShininess());

  // get the map vector of the material candidate
  std::vector<CMaterialCandidate::Map>& vectorMap = pMaterialCandidate->GetVectorMap();

  // reserve memory for all the material data
  if(!coreMaterial->reserve(vectorMap.size()))
  {
    SetLastError("Memory reservation for maps failed.", __FILE__, __LINE__);
    return false;
  }

  // load all maps
  for(size_t mapId = 0; mapId < vectorMap.size(); mapId++)
  {
    CalCoreMaterial::Map map;

    // set map data
    map.strFilename = vectorMap[mapId].strFilename;

    // set map in the core material instance
    coreMaterial->setMap(mapId, map);
  }

  // save core mesh to the file
  if(!CalSaver::saveCoreMaterial(strFilename, coreMaterial.get()))
  {
    SetLastError(CalError::getLastErrorText(), __FILE__, __LINE__);
    return false;
  }

  return true;
}