00001
#include "StdAfx.h"
00002
#include "AddMaterialSettings.h"
00003
00004 CAddMaterialSettings::CAddMaterialSettings()
00005 {
00006 m_pCurrentMaterial = NULL;
00007 m_MaterialAmbient = m_MaterialDiffuse = m_MaterialSpecular = m_MaterialEmissive = m_iMaterialShininess = 0;
00008 m_iMaterialIndex = 0;
00009 m_iMaterialID = 1;
00010 }
00011
00012 CAddMaterialSettings::~CAddMaterialSettings()
00013 {
00014
00015 }
00016
00017
bool CAddMaterialSettings::PropertyChanging(
const void* pvProperty ,
void* pvNewValue )
00018 {
00019
bool bChangeOK = CAddResourceSettings::PropertyChanging(pvProperty, pvNewValue);
00020
00021
if(
CMaterialManager::GetSingletonPtr() == NULL)
00022
return false;
00023
00024
if(pvProperty == &m_strResourceName)
00025 {
00026
CMaterial *pMaterial =
CMaterialManager::GetSingleton().
GetResource(-1, -1, (*(CString *)pvNewValue),
"");
00027
if(pMaterial !=NULL)
00028
return false;
00029
else
00030 {
00031 m_strResourceName = *(CString *)pvNewValue;
00032 m_pCurrentMaterial->SetName(m_strResourceName);
00033
00034 m_MaterialAmbient = RGB(m_pCurrentMaterial->GetAmbient().R, m_pCurrentMaterial->GetAmbient().G, m_pCurrentMaterial->GetAmbient().B);
00035 m_MaterialDiffuse = RGB(m_pCurrentMaterial->GetDiffuse().R, m_pCurrentMaterial->GetDiffuse().G, m_pCurrentMaterial->GetDiffuse().B);
00036 m_MaterialSpecular = RGB(m_pCurrentMaterial->GetSpecular().R, m_pCurrentMaterial->GetSpecular().G, m_pCurrentMaterial->GetSpecular().B);
00037 m_MaterialEmissive = RGB(m_pCurrentMaterial->GetEmissive().R, m_pCurrentMaterial->GetEmissive().G, m_pCurrentMaterial->GetEmissive().B);
00038 m_iMaterialShininess = (
int)m_pCurrentMaterial->GetShininess();
00039
00040
for (
int i=0; i<
CMaterialManager::GetSingleton().
size(); i++)
00041 {
00042
CMaterial *pMaterial = (
CMaterial *)
CMaterialManager::GetSingleton().
at(i);
00043
if(pMaterial == m_pCurrentMaterial)
00044 {
00045 m_iMaterialIndex = i;
00046
break;
00047 }
00048 }
00049
00050 m_bUpdateRequired =
true;
00051 }
00052 }
00053
00054
if(pvProperty == &m_strResourceXMLFilename)
00055 {
00056
CMaterial *pNewMaterial = NULL;
00057
if(m_pCurrentMaterial !=NULL)
00058 {
00059 m_pCurrentMaterial->Destroy();
00060
00061 m_pCurrentMaterial->LoadXML(NULL, (*(CString *)pvNewValue));
00062 pNewMaterial = m_pCurrentMaterial;
00063 }
00064
else
00065 {
00066 pNewMaterial =
CMaterialManager::GetSingleton().
LoadResource(NULL, (*(CString *)pvNewValue));
00067 m_pCurrentMaterial = pNewMaterial;
00068 }
00069
00070 m_strResourceXMLFilename = *(CString *)pvNewValue;
00071 m_strResourceRawFilename = pNewMaterial->
GetFilename();
00072 m_strResourceName = pNewMaterial->
GetName();
00073
00074 m_bUpdateRequired =
true;
00075 }
00076
00077
if(pvProperty == &m_strResourcesDatabaseFilename)
00078 {
00079
int iRetValue =
CMaterialManager::GetSingleton().
LoadXML(NULL, (*(CString *)pvNewValue));
00080
if(iRetValue > 0)
00081 m_bUpdateRequired =
true;
00082
00083
return false;
00084 }
00085
00086
if(pvProperty == &m_iMaterialIndex)
00087 {
00088
int iTempTexIndex = *(
int *)pvNewValue;
00089
CMaterial *pMaterial =
CMaterialManager::GetSingleton().
GetResource(iTempTexIndex);
00090
if(iTempTexIndex == 1000)
00091 {
00092 CString NewTexName;
00093 NewTexName.Format(
"Material #%d", m_iMaterialID);
00094
00095 m_pCurrentMaterial =
CMaterialManager::GetSingleton().
AddResource(NewTexName);
00096 m_pCurrentMaterial->SetName(NewTexName);
00097
00098 m_strResourceName = NewTexName;
00099 m_iMaterialIndex =
CMaterialManager::GetSingleton().
size() - 1;
00100
00101 m_MaterialAmbient = RGB(m_pCurrentMaterial->GetAmbient().R, m_pCurrentMaterial->GetAmbient().G, m_pCurrentMaterial->GetAmbient().B);
00102 m_MaterialDiffuse = RGB(m_pCurrentMaterial->GetDiffuse().R, m_pCurrentMaterial->GetDiffuse().G, m_pCurrentMaterial->GetDiffuse().B);
00103 m_MaterialSpecular = RGB(m_pCurrentMaterial->GetSpecular().R, m_pCurrentMaterial->GetSpecular().G, m_pCurrentMaterial->GetSpecular().B);
00104 m_MaterialEmissive = RGB(m_pCurrentMaterial->GetEmissive().R, m_pCurrentMaterial->GetEmissive().G, m_pCurrentMaterial->GetEmissive().B);
00105 m_iMaterialShininess = (
int)m_pCurrentMaterial->GetShininess();
00106
00107 m_iMaterialID++;
00108 m_bUpdateRequired =
true;
00109
return false;
00110 }
00111
else
00112 {
00113 m_strResourceName = pMaterial->
GetName();
00114 m_iMaterialIndex = iTempTexIndex;
00115 m_pCurrentMaterial = pMaterial;
00116
00117 m_MaterialAmbient = RGB(pMaterial->GetAmbient().R, pMaterial->GetAmbient().G, pMaterial->GetAmbient().B);
00118 m_MaterialDiffuse = RGB(pMaterial->GetDiffuse().R, pMaterial->GetDiffuse().G, pMaterial->GetDiffuse().B);
00119 m_MaterialSpecular = RGB(pMaterial->GetSpecular().R, pMaterial->GetSpecular().G, pMaterial->GetSpecular().B);
00120 m_MaterialEmissive = RGB(pMaterial->GetEmissive().R, pMaterial->GetEmissive().G, pMaterial->GetEmissive().B);
00121 m_iMaterialShininess = (
int)pMaterial->
GetShininess();
00122 }
00123 }
00124
00125
if(pvProperty == &m_MaterialAmbient)
00126 {
00127 m_MaterialAmbient = *(COLORREF *)pvNewValue;
00128 m_pCurrentMaterial->SetAmbient(tRGBA(GetRValue(m_MaterialAmbient), GetGValue(m_MaterialAmbient), GetBValue(m_MaterialAmbient)));
00129 }
00130
00131
if(pvProperty == &m_MaterialDiffuse)
00132 {
00133 m_MaterialDiffuse = *(COLORREF *)pvNewValue;
00134 m_pCurrentMaterial->SetDiffuse(tRGBA(GetRValue(m_MaterialDiffuse), GetGValue(m_MaterialDiffuse), GetBValue(m_MaterialDiffuse)));
00135 }
00136
00137
if(pvProperty == &m_MaterialSpecular)
00138 {
00139 m_MaterialSpecular = *(COLORREF *)pvNewValue;
00140 m_pCurrentMaterial->SetSpecular(tRGBA(GetRValue(m_MaterialSpecular), GetGValue(m_MaterialSpecular), GetBValue(m_MaterialSpecular)));
00141 }
00142
00143
if(pvProperty == &m_MaterialEmissive)
00144 {
00145 m_MaterialEmissive = *(COLORREF *)pvNewValue;
00146 m_pCurrentMaterial->SetEmissive(tRGBA(GetRValue(m_MaterialEmissive), GetGValue(m_MaterialEmissive), GetBValue(m_MaterialEmissive)));
00147 }
00148
00149
if(pvProperty == &m_iMaterialShininess)
00150 {
00151 m_iMaterialShininess = *(
int *)pvNewValue;
00152 m_pCurrentMaterial->SetShininess(m_iMaterialShininess);
00153 }
00154
00155
return bChangeOK;
00156 }
00157
00158
void CAddMaterialSettings::GetProperties( EPropList& PropList )
00159 {
00160 CAddResourceSettings::GetProperties(PropList);
00161
00162
if(
CMaterialManager::GetSingletonPtr() == NULL)
00163
return;
00164
00165 PropList.AddTab(
"Material(s)");
00166 PropList.AddPropSeparator(
this,
"Tools");
00167
00168 EPropertyCombo *pMaterialCombo = PropList.AddPropCombo(
this,
"Material", &m_iMaterialIndex);
00169 pMaterialCombo->AddString(
"New Material", 1000);
00170
for (
int i=0; i<
CMaterialManager::GetSingleton().
size(); i++)
00171 {
00172
CMaterial *pMaterial = (
CMaterial *)
CMaterialManager::GetSingleton().
at(i);
00173 pMaterialCombo->AddString(pMaterial->
GetName(), i);
00174 }
00175
00176 PropList.AddPropFile(
this,
"XML File", &m_strResourceXMLFilename,
"XML Files (*.xml)|*.xml|All Files (*.*)|*.*||")->SetComment(
"Material XML File");
00177 PropList.AddPropFile(
this,
"XML Database", &m_strResourcesDatabaseFilename,
"XML Files (*.xml)|*.xml|All Files (*.*)|*.*||")->SetComment(
"Materials Database XML File");
00178
00179 PropList.AddPropSeparator(
this,
"Attributes");
00180 PropList.AddPropString(
this,
"strName", &m_strResourceName,
true)->SetComment(
"Material strName");
00181 PropList.AddPropColor(
this,
"Ambient", &m_MaterialAmbient,
true)->SetComment(
"Material' Ambient component");
00182 PropList.AddPropColor(
this,
"Diffuse", &m_MaterialDiffuse,
true)->SetComment(
"Material' Diffuse component");
00183 PropList.AddPropColor(
this,
"Specular", &m_MaterialSpecular,
true)->SetComment(
"Material' Specular component");
00184 PropList.AddPropColor(
this,
"Emissive", &m_MaterialEmissive,
true)->SetComment(
"Material' Emissive component");
00185 PropList.AddPropInt(
this,
"Shininess", &m_iMaterialShininess,
"",
true)->SetComment(
"Material' Shininess component");
00186 }