bool CExporter::ExportMaterialFromMaxscriptCall	(const std::string& strFilename)
{
	// check if a valid interface is set
	if(m_pInterface == 0)
	{
		SetLastError("Invalid interface pointer.", __FILE__, __LINE__);
		return false;
	}

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

	//Remove user interface
	/*
	// show export wizard sheet
	CMaterialExportSheet sheet("Cal3D Material Export", m_pInterface->GetMainWnd());
	sheet.SetMaterialLibraryCandidate(&materialLibraryCandidate);
	sheet.SetWizardMode();
	if(sheet.DoModal() != ID_WIZFINISH) return true;
	*/
	//The material has already been selected in the function materialLibraryCandidate.CreateFromInterfaceFromMaxscriptCall()

	// 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
	CalCoreMaterial coreMaterial;

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

	for(size_t mapId = 0; mapId < vectorMap.size(); mapId++)
	{
		CalCoreMaterial::Map map;
		map.filename = vectorMap[mapId].strFilename;
		coreMaterial.maps.push_back(map);
	}

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

	return true;
}
Example #2
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;
}