123
This commit is contained in:
1101
Editor/Material/Material.cpp
Normal file
1101
Editor/Material/Material.cpp
Normal file
File diff suppressed because it is too large
Load Diff
176
Editor/Material/Material.h
Normal file
176
Editor/Material/Material.h
Normal file
@@ -0,0 +1,176 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Crytek Engine Source File.
|
||||
// Copyright (C), Crytek Studios, 2002.
|
||||
// -------------------------------------------------------------------------
|
||||
// File name: material.h
|
||||
// Version: v1.00
|
||||
// Created: 3/2/2003 by Timur.
|
||||
// Compilers: Visual Studio.NET
|
||||
// Description:
|
||||
// -------------------------------------------------------------------------
|
||||
// History:
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __material_h__
|
||||
#define __material_h__
|
||||
#pragma once
|
||||
|
||||
#include "BaseLibraryItem.h"
|
||||
|
||||
typedef std::vector<SShaderParam> ShaderPublicParams;
|
||||
|
||||
/*
|
||||
struct SMaterial
|
||||
{
|
||||
bool m_bLighting;
|
||||
SLightMaterial m_lightMaterial;
|
||||
SShaderResources m_shaderResources;
|
||||
ShaderPublicParams m_shaderParams;
|
||||
};
|
||||
*/
|
||||
|
||||
/** CMaterial class
|
||||
Every Material is a member of material library.
|
||||
Materials can have child sub materials,
|
||||
Sub materials are applied to the same geometry of the parent material in the other material slots.
|
||||
*/
|
||||
class CRYEDIT_API CMaterial : public CBaseLibraryItem
|
||||
{
|
||||
public:
|
||||
enum EMtlFlags
|
||||
{
|
||||
MF_WIRE = 0x0001,
|
||||
MF_2SIDED = 0x0002,
|
||||
MF_ADDITIVE = 0x0004,
|
||||
MF_ADDITIVE_DECAL = 0x0008,
|
||||
MF_LIGHTING = 0x0010,
|
||||
MF_NOSHADOW = 0x0020,
|
||||
MF_ALWAYS_USED = 0x0040, //! When set forces material to be export even if not explicitly used.
|
||||
};
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CMaterial();
|
||||
~CMaterial();
|
||||
|
||||
void SetName( const CString &name );
|
||||
|
||||
//! Set name of shader used by this material.
|
||||
void SetShaderName( const CString &shaderName );
|
||||
//! Get name of shader used by this material.
|
||||
CString GetShaderName() const { return m_shaderName; };
|
||||
|
||||
//! Sets one or more material flags from EMtlFlags enum.
|
||||
void SetMaterialFlags( int flags ) { m_mtlFlags = flags; };
|
||||
//! Query this material flags.
|
||||
int GetMaterialFlags() const { return m_mtlFlags; }
|
||||
|
||||
SInputShaderResources& GetShaderResources() { return m_shaderResources; };
|
||||
|
||||
//! Get public parameters of material in variable block.
|
||||
CVarBlock* GetPublicVars();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CVarBlock* GetShaderGenParamsVars();
|
||||
void SetShaderGenParamsVars( CVarBlock *pBlock );
|
||||
unsigned int GetShaderGenMask() { return m_nShaderGenMask; }
|
||||
|
||||
//! Sets variable block of publich shader parameters.
|
||||
//! VarBlock must be in same format as returned by GetPublicVars().
|
||||
void SetPublicVars( CVarBlock *publicVars );
|
||||
|
||||
//! Return variable block of shader params.
|
||||
SShaderItem& GetShaderItem() { return m_shaderItem; };
|
||||
|
||||
//! Get texture map usage mask for shader in this material.
|
||||
unsigned int GetTexmapUsageMask() const;
|
||||
|
||||
//! Load new shader.
|
||||
bool LoadShader( const CString &shaderName );
|
||||
|
||||
//! Reload shader, update all shader parameters.
|
||||
void Update();
|
||||
|
||||
//! Serialize material settings to xml.
|
||||
virtual void Serialize( SerializeContext &ctx );
|
||||
|
||||
//! Assign this material to static geometry.
|
||||
void AssignToEntity( IEntityRender *pEntity );
|
||||
//! Assign material settings from givven geometry.
|
||||
void AssignFromGeometry( IStatObj *pGeometry );
|
||||
//! Assign material settings from character.
|
||||
void AssignFromGeometry( ICryCharInstance *pCharacter );
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Child Sub materials.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//! Get number of sub materials childs.
|
||||
int GetSubMaterialCount() const;
|
||||
//! Get sub material child by index.
|
||||
CMaterial* GetSubMaterial( int index ) const;
|
||||
//! Adds a new sub material.
|
||||
void AddSubMaterial( CMaterial *mtl );
|
||||
//! Remove specific sub material
|
||||
void RemoveSubMaterial( CMaterial *mtl );
|
||||
//! Remove all sub materials.
|
||||
void RemoveAllSubMaterials();
|
||||
//! Insert sub material in between other materials.
|
||||
void InsertSubMaterial( int slot,CMaterial *mtl );
|
||||
//! Find slot where sub material stored.
|
||||
//! @retun slot index if material found, -1 if material not found.
|
||||
int FindSubMaterial( CMaterial *mtl );
|
||||
//! Returns parent material.
|
||||
CMaterial* GetParent() const;
|
||||
|
||||
void GenerateIdRecursively();
|
||||
|
||||
//! Return pointer to engine material.
|
||||
IMatInfo* GetMatInfo() const { return m_pMatInfo; }
|
||||
|
||||
//! Swap contents of this material, with other material.
|
||||
void SwapContent( CMaterial *mtl );
|
||||
|
||||
//! Validate materials for errors.
|
||||
void Validate();
|
||||
|
||||
//! Set material to be in use.
|
||||
void SetUsed( bool bUsed=true ) { m_bInUse = bUsed; };
|
||||
bool IsUsed() const { return m_bInUse || (m_mtlFlags & MF_ALWAYS_USED); };
|
||||
|
||||
virtual void GatherUsedResources( CUsedResources &resources );
|
||||
|
||||
private:
|
||||
void SetFromMatInfo( CMatInfo *pMatInfo );
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Variables.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CString m_shaderName;
|
||||
|
||||
//! Material flags.
|
||||
int m_mtlFlags;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Shader resources.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
SShaderItem m_shaderItem;
|
||||
SLightMaterial m_lightMaterial;
|
||||
SInputShaderResources m_shaderResources;
|
||||
ShaderPublicParams m_shaderParams;
|
||||
//CVarBlockPtr m_shaderParamsVar;
|
||||
//! Common shader flags.
|
||||
unsigned int m_nShaderGenMask;
|
||||
|
||||
IMatInfo *m_pMatInfo;
|
||||
|
||||
bool m_bRegetPublicParams;
|
||||
|
||||
//! Parent of this material (if this is sub material).
|
||||
CMaterial *m_pParentMtl;
|
||||
//! Array of sub materials.
|
||||
std::vector<TSmartPtr<CMaterial> > m_subMaterials;
|
||||
|
||||
//! Material Used in level.
|
||||
bool m_bInUse;
|
||||
};
|
||||
|
||||
#endif // __material_h__
|
||||
1831
Editor/Material/MaterialDialog.cpp
Normal file
1831
Editor/Material/MaterialDialog.cpp
Normal file
File diff suppressed because it is too large
Load Diff
156
Editor/Material/MaterialDialog.h
Normal file
156
Editor/Material/MaterialDialog.h
Normal file
@@ -0,0 +1,156 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Crytek Engine Source File.
|
||||
// Copyright (C), Crytek Studios, 2002.
|
||||
// -------------------------------------------------------------------------
|
||||
// File name: MaterialDialog.h
|
||||
// Version: v1.00
|
||||
// Created: 22/1/2003 by Timur.
|
||||
// Compilers: Visual Studio.NET
|
||||
// Description:
|
||||
// -------------------------------------------------------------------------
|
||||
// History:
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __materialdialogdialog_h__
|
||||
#define __materialdialogdialog_h__
|
||||
#pragma once
|
||||
|
||||
#include "BaseLibraryDialog.h"
|
||||
#include "Controls\SplitterWndEx.h"
|
||||
#include "Controls\TreeCtrlEx.h"
|
||||
#include "Controls\PropertyCtrl.h"
|
||||
#include "Controls\PreviewModelCtrl.h"
|
||||
|
||||
class CMaterial;
|
||||
class CMaterialManager;
|
||||
|
||||
/** Dialog which hosts entity prototype library.
|
||||
*/
|
||||
class CMaterialDialog : public CBaseLibraryDialog
|
||||
{
|
||||
DECLARE_DYNAMIC(CMaterialDialog)
|
||||
public:
|
||||
CMaterialDialog( CWnd *pParent );
|
||||
~CMaterialDialog();
|
||||
|
||||
// Called every frame.
|
||||
void Update();
|
||||
|
||||
virtual UINT GetDialogMenuID();
|
||||
|
||||
public:
|
||||
afx_msg void OnAssignMaterialToSelection();
|
||||
afx_msg void OnResetMaterialOnSelection();
|
||||
afx_msg void OnGetMaterialFromSelection();
|
||||
|
||||
protected:
|
||||
IStatObj* GetGeometryFromObject( CBaseObject *pObject );
|
||||
ICryCharInstance* GetCharacterFromObject( CBaseObject *pObject );
|
||||
void DoDataExchange(CDataExchange* pDX);
|
||||
BOOL OnInitDialog();
|
||||
|
||||
afx_msg void OnDestroy();
|
||||
afx_msg void OnSize(UINT nType, int cx, int cy);
|
||||
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
|
||||
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
|
||||
|
||||
afx_msg void OnAddItem();
|
||||
afx_msg void OnPlay();
|
||||
afx_msg void OnUpdatePlay( CCmdUI* pCmdUI );
|
||||
afx_msg void OnDrawSelection();
|
||||
afx_msg void OnDrawBox();
|
||||
afx_msg void OnDrawSphere();
|
||||
afx_msg void OnDrawTeapot();
|
||||
afx_msg void OnAddSubMtl();
|
||||
afx_msg void OnDelSubMtl();
|
||||
afx_msg void OnUpdateMtlSelected( CCmdUI* pCmdUI );
|
||||
afx_msg void OnUpdateObjectSelected( CCmdUI* pCmdUI );
|
||||
afx_msg void OnUpdateAssignMtlToSelection( CCmdUI *pCmdUI );
|
||||
afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
|
||||
afx_msg void OnNotifyMtlTreeRClick(NMHDR* pNMHDR, LRESULT* pResult);
|
||||
afx_msg void OnPickMtl();
|
||||
afx_msg void OnUpdatePickMtl( CCmdUI* pCmdUI );
|
||||
afx_msg void OnCopy();
|
||||
afx_msg void OnPaste();
|
||||
afx_msg void OnGenCubemap();
|
||||
afx_msg void OnSelectAssignedObjects();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Some functions can be overriden to modify standart functionality.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void InitToolbar();
|
||||
virtual HTREEITEM InsertItemToTree( CBaseLibraryItem *pItem,HTREEITEM hParent );
|
||||
virtual void SelectItem( CBaseLibraryItem *item,bool bForceReload=false );
|
||||
virtual void DeleteItem( CBaseLibraryItem *pItem );
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CMaterial* GetSelectedMaterial();
|
||||
void OnUpdateProperties( IVariable *var );
|
||||
|
||||
|
||||
void LoadGeometry( const CString &filename );
|
||||
void ReleaseGeometry();
|
||||
void AssignMtlToGeometry();
|
||||
|
||||
//void SetTextureVars( CVariableArray *texVar,CMaterial *mtl,int id,const CString &name );
|
||||
void SetMaterialVars( CMaterial *mtl );
|
||||
|
||||
void DropToItem( HTREEITEM hItem,HTREEITEM hSrcItem,CMaterial *pMtl );
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// IDocListener listener implementation
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void OnNewDocument();
|
||||
virtual void OnLoadDocument();
|
||||
virtual void OnCloseDocument();
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum EDrawType
|
||||
{
|
||||
DRAW_BOX,
|
||||
DRAW_SPHERE,
|
||||
DRAW_TEAPOT,
|
||||
DRAW_SELECTION,
|
||||
};
|
||||
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
|
||||
CSplitterWndEx m_wndHSplitter;
|
||||
CSplitterWndEx m_wndVSplitter;
|
||||
|
||||
CPreviewModelCtrl m_previewCtrl;
|
||||
CPropertyCtrl m_propsCtrl;
|
||||
CImageList m_imageList;
|
||||
|
||||
CImageList *m_dragImage;
|
||||
|
||||
// Object to render.
|
||||
CString m_visualObject;
|
||||
IStatObj *m_pGeometry;
|
||||
IEntityRender *m_pEntityRender;
|
||||
|
||||
bool m_bRealtimePreviewUpdate;
|
||||
bool m_bOwnGeometry;
|
||||
|
||||
// Material manager.
|
||||
CMaterialManager *m_pMatManager;
|
||||
|
||||
CVarBlockPtr m_vars;
|
||||
CVarBlockPtr m_publicVars;
|
||||
CPropertyItem *m_publicVarsItems;
|
||||
CVarBlockPtr m_shaderGenParamsVars;
|
||||
CPropertyItem *m_shaderGenParamsVarsItem;
|
||||
|
||||
EDrawType m_drawType;
|
||||
CString m_geometryFile;
|
||||
|
||||
HTREEITEM m_hDropItem;
|
||||
HTREEITEM m_hDraggedItem;
|
||||
|
||||
TSmartPtr<CMaterial> m_pDraggedMtl;
|
||||
};
|
||||
|
||||
#endif // __materialdialogdialog_h__
|
||||
90
Editor/Material/MaterialLibrary.cpp
Normal file
90
Editor/Material/MaterialLibrary.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Crytek Engine Source File.
|
||||
// Copyright (C), Crytek Studios, 2002.
|
||||
// -------------------------------------------------------------------------
|
||||
// File name: entityprototypelibrary.cpp
|
||||
// Version: v1.00
|
||||
// Created: 22/1/2003 by Timur.
|
||||
// Compilers: Visual Studio.NET
|
||||
// Description:
|
||||
// -------------------------------------------------------------------------
|
||||
// History:
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "MaterialLibrary.h"
|
||||
#include "Material.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CMaterialLibrary implementation.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CMaterialLibrary::Save()
|
||||
{
|
||||
CString filename = GetFilename();
|
||||
if (filename.IsEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
XmlNodeRef root = new CXmlNode( "MaterialLibrary" );
|
||||
Serialize( root,false );
|
||||
bool bRes = root->saveToFile( GetFilename() );
|
||||
|
||||
return bRes;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CMaterialLibrary::Load( const CString &filename )
|
||||
{
|
||||
if (filename.IsEmpty())
|
||||
return false;
|
||||
SetFilename( filename );
|
||||
XmlParser parser;
|
||||
XmlNodeRef root = parser.parse( filename );
|
||||
if (!root)
|
||||
return false;
|
||||
|
||||
Serialize( root,true );
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CMaterialLibrary::Serialize( XmlNodeRef &root,bool bLoading )
|
||||
{
|
||||
if (bLoading)
|
||||
{
|
||||
// Loading.
|
||||
CString name = GetName();
|
||||
root->getAttr( "Name",name );
|
||||
SetName( name );
|
||||
for (int i = 0; i < root->getChildCount(); i++)
|
||||
{
|
||||
CMaterial *material = new CMaterial;
|
||||
AddItem( material );
|
||||
XmlNodeRef itemNode = root->getChild(i);
|
||||
CBaseLibraryItem::SerializeContext ctx( itemNode,bLoading );
|
||||
material->Serialize( ctx );
|
||||
}
|
||||
SetModified(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Saving.
|
||||
root->setAttr( "Name",GetName() );
|
||||
root->setAttr( "SandboxVersion",(const char*)GetIEditor()->GetFileVersion().ToFullString() );
|
||||
// Serialize prototypes.
|
||||
for (int i = 0; i < GetItemCount(); i++)
|
||||
{
|
||||
CMaterial *pMtl = (CMaterial*)GetItem(i);
|
||||
// Save materials with parents under thier parent xml node.
|
||||
if (pMtl->GetParent())
|
||||
continue;
|
||||
|
||||
XmlNodeRef itemNode = root->newChild( "Material" );
|
||||
CBaseLibraryItem::SerializeContext ctx( itemNode,bLoading );
|
||||
GetItem(i)->Serialize( ctx );
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Editor/Material/MaterialLibrary.h
Normal file
35
Editor/Material/MaterialLibrary.h
Normal file
@@ -0,0 +1,35 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Crytek Engine Source File.
|
||||
// Copyright (C), Crytek Studios, 2002.
|
||||
// -------------------------------------------------------------------------
|
||||
// File name: MaterialLibrary.h
|
||||
// Version: v1.00
|
||||
// Created: 22/1/2003 by Timur.
|
||||
// Compilers: Visual Studio.NET
|
||||
// Description:
|
||||
// -------------------------------------------------------------------------
|
||||
// History:
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __materiallibrary_h__
|
||||
#define __materiallibrary_h__
|
||||
#pragma once
|
||||
|
||||
#include "BaseLibrary.h"
|
||||
|
||||
/** Library of prototypes.
|
||||
*/
|
||||
class CRYEDIT_API CMaterialLibrary : public CBaseLibrary
|
||||
{
|
||||
public:
|
||||
CMaterialLibrary( CBaseLibraryManager *pManager ) : CBaseLibrary(pManager) {};
|
||||
virtual bool Save();
|
||||
virtual bool Load( const CString &filename );
|
||||
virtual void Serialize( XmlNodeRef &node,bool bLoading );
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // __materiallibrary_h__
|
||||
214
Editor/Material/MaterialManager.cpp
Normal file
214
Editor/Material/MaterialManager.cpp
Normal file
@@ -0,0 +1,214 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Crytek Engine Source File.
|
||||
// Copyright (C), Crytek Studios, 2002.
|
||||
// -------------------------------------------------------------------------
|
||||
// File name: MaterialManager.cpp
|
||||
// Version: v1.00
|
||||
// Created: 22/1/2003 by Timur.
|
||||
// Compilers: Visual Studio.NET
|
||||
// Description:
|
||||
// -------------------------------------------------------------------------
|
||||
// History:
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "MaterialManager.h"
|
||||
|
||||
#include "Material.h"
|
||||
#include "MaterialLibrary.h"
|
||||
#include "ErrorReport.h"
|
||||
|
||||
#define MATERIALS_LIBS_PATH "Editor\\Materials\\"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CMaterialManager implementation.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CMaterialManager::CMaterialManager()
|
||||
{
|
||||
m_libsPath = MATERIALS_LIBS_PATH;
|
||||
|
||||
m_pLevelLibrary = (CBaseLibrary*)AddLibrary( "Level" );
|
||||
m_pLevelLibrary->SetLevelLibrary( true );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CMaterialManager::~CMaterialManager()
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CMaterialManager::ClearAll()
|
||||
{
|
||||
ZeroStruct(m_currentMaterialGUID);
|
||||
CBaseLibraryManager::ClearAll();
|
||||
|
||||
m_pLevelLibrary = (CBaseLibrary*)AddLibrary( "Level" );
|
||||
m_pLevelLibrary->SetLevelLibrary( true );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CMaterial* CMaterialManager::LoadMaterial( CMaterialLibrary *pLibrary,XmlNodeRef &node,bool bNewGuid )
|
||||
{
|
||||
assert( pLibrary );
|
||||
assert( node != NULL );
|
||||
|
||||
CMaterial* material = new CMaterial;
|
||||
pLibrary->AddItem( material );
|
||||
|
||||
CBaseLibraryItem::SerializeContext serCtx( node,true );
|
||||
serCtx.bCopyPaste = true;
|
||||
serCtx.bUniqName = true;
|
||||
material->Serialize( serCtx );
|
||||
if (bNewGuid)
|
||||
material->GenerateIdRecursively();
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CMaterialManager::Export( XmlNodeRef &node )
|
||||
{
|
||||
XmlNodeRef libs = node->newChild( "MaterialsLibrary" );
|
||||
for (int i = 0; i < GetLibraryCount(); i++)
|
||||
{
|
||||
IDataBaseLibrary* pLib = GetLibrary(i);
|
||||
// Level libraries are saved in in level.
|
||||
XmlNodeRef libNode = libs->newChild( "Library" );
|
||||
|
||||
// Export library.
|
||||
libNode->setAttr( "Name",pLib->GetName() );
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int CMaterialManager::ExportLib( CMaterialLibrary *pLib,XmlNodeRef &libNode )
|
||||
{
|
||||
int num = 0;
|
||||
// Export library.
|
||||
libNode->setAttr( "Name",pLib->GetName() );
|
||||
libNode->setAttr( "File",pLib->GetFilename() );
|
||||
libNode->setAttr( "SandboxVersion",(const char*)GetIEditor()->GetFileVersion().ToFullString() );
|
||||
// Serialize prototypes.
|
||||
for (int j = 0; j < pLib->GetItemCount(); j++)
|
||||
{
|
||||
CMaterial *pMtl = (CMaterial*)pLib->GetItem(j);
|
||||
// Only export parent materials.
|
||||
if (pMtl->GetParent())
|
||||
continue;
|
||||
|
||||
// Do not export unused materials.
|
||||
if (!pMtl->IsUsed())
|
||||
continue;
|
||||
|
||||
XmlNodeRef itemNode = libNode->newChild( "Material" );
|
||||
CBaseLibraryItem::SerializeContext ctx( itemNode,false );
|
||||
pMtl->Serialize( ctx );
|
||||
num += 1 + pMtl->GetSubMaterialCount();
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CMaterialManager::SetCurrentMaterial( CMaterial *pMtl )
|
||||
{
|
||||
if (pMtl)
|
||||
{
|
||||
m_currentMaterialGUID = pMtl->GetGUID();
|
||||
}
|
||||
else
|
||||
ZeroStruct(m_currentMaterialGUID);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CMaterial* CMaterialManager::GetCurrentMaterial() const
|
||||
{
|
||||
GUID nullGuid;
|
||||
ZeroStruct(nullGuid);
|
||||
if (m_currentMaterialGUID != nullGuid)
|
||||
return (CMaterial*)FindItem( m_currentMaterialGUID );
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CBaseLibraryItem* CMaterialManager::MakeNewItem()
|
||||
{
|
||||
return new CMaterial;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CBaseLibrary* CMaterialManager::MakeNewLibrary()
|
||||
{
|
||||
return new CMaterialLibrary(this);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CString CMaterialManager::GetRootNodeName()
|
||||
{
|
||||
return "MaterialsLibs";
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CString CMaterialManager::GetLibsPath()
|
||||
{
|
||||
return m_libsPath;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CMaterialManager::ReportDuplicateItem( CBaseLibraryItem *pItem,CBaseLibraryItem *pOldItem )
|
||||
{
|
||||
CString sLibName;
|
||||
if (pOldItem->GetLibrary())
|
||||
sLibName = pOldItem->GetLibrary()->GetName();
|
||||
CErrorRecord err;
|
||||
err.pMaterial = (CMaterial*)pOldItem;
|
||||
err.error.Format( "Material %s with duplicate GUID to loaded material %s ignored",(const char*)pItem->GetFullName(),(const char*)pOldItem->GetFullName() );
|
||||
GetIEditor()->GetErrorReport()->ReportError( err );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CMaterialManager::Serialize( XmlNodeRef &node,bool bLoading )
|
||||
{
|
||||
CBaseLibraryManager::Serialize( node,bLoading );
|
||||
if (bLoading)
|
||||
{
|
||||
if (!FindLibrary("Shared"))
|
||||
{
|
||||
LoadLibrary( GetLibsPath() + "\\Shared.xml" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CMaterialManager::OnNewDocument()
|
||||
{
|
||||
CBaseLibraryManager::OnNewDocument();
|
||||
SetCurrentMaterial( 0 );
|
||||
if (!FindLibrary("Shared"))
|
||||
{
|
||||
LoadLibrary( GetLibsPath() + "\\Shared.xml" );
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CMaterialManager::OnLoadDocument()
|
||||
{
|
||||
CBaseLibraryManager::OnLoadDocument();
|
||||
SetCurrentMaterial( 0 );
|
||||
if (!FindLibrary("Shared"))
|
||||
{
|
||||
LoadLibrary( GetLibsPath() + "\\Shared.xml" );
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CMaterialManager::OnCloseDocument()
|
||||
{
|
||||
CBaseLibraryManager::OnCloseDocument();
|
||||
SetCurrentMaterial( 0 );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CMaterialManager::OnMissionChange()
|
||||
{
|
||||
CBaseLibraryManager::OnMissionChange();
|
||||
SetCurrentMaterial( 0 );
|
||||
}
|
||||
80
Editor/Material/MaterialManager.h
Normal file
80
Editor/Material/MaterialManager.h
Normal file
@@ -0,0 +1,80 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Crytek Engine Source File.
|
||||
// Copyright (C), Crytek Studios, 2002.
|
||||
// -------------------------------------------------------------------------
|
||||
// File name: MaterialManager.h
|
||||
// Version: v1.00
|
||||
// Created: 22/1/2003 by Timur.
|
||||
// Compilers: Visual Studio.NET
|
||||
// Description:
|
||||
// -------------------------------------------------------------------------
|
||||
// History:
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __materialmanager_h__
|
||||
#define __materialmanager_h__
|
||||
#pragma once
|
||||
|
||||
#include "BaseLibraryManager.h"
|
||||
|
||||
class CMaterial;
|
||||
class CMaterialLibrary;
|
||||
|
||||
/** Manages all entity prototypes and material libraries.
|
||||
*/
|
||||
class CRYEDIT_API CMaterialManager : public CBaseLibraryManager
|
||||
{
|
||||
public:
|
||||
//! Notification callback.
|
||||
typedef Functor0 NotifyCallback;
|
||||
|
||||
CMaterialManager();
|
||||
~CMaterialManager();
|
||||
|
||||
// Clear all prototypes and material libraries.
|
||||
void ClearAll();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Materials.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//! Loads a new material from a xml node.
|
||||
CMaterial* LoadMaterial( CMaterialLibrary *pLibrary,XmlNodeRef &node,bool bNewGuid=false );
|
||||
|
||||
//! Export property manager to game.
|
||||
void Export( XmlNodeRef &node );
|
||||
int ExportLib( CMaterialLibrary *pLib,XmlNodeRef &libNode );
|
||||
|
||||
void SetCurrentMaterial( CMaterial *pMtl );
|
||||
//! Cet currently active material.
|
||||
CMaterial* GetCurrentMaterial() const;
|
||||
//! Serialize property manager.
|
||||
virtual void Serialize( XmlNodeRef &node,bool bLoading );
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// IDocListener
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void OnNewDocument();
|
||||
virtual void OnLoadDocument();
|
||||
virtual void OnCloseDocument();
|
||||
virtual void OnMissionChange();
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
protected:
|
||||
virtual CBaseLibraryItem* MakeNewItem();
|
||||
virtual CBaseLibrary* MakeNewLibrary();
|
||||
//! Root node where this library will be saved.
|
||||
virtual CString GetRootNodeName();
|
||||
//! Path to libraries in this manager.
|
||||
virtual CString GetLibsPath();
|
||||
virtual void ReportDuplicateItem( CBaseLibraryItem *pItem,CBaseLibraryItem *pOldItem );
|
||||
|
||||
CString m_libsPath;
|
||||
|
||||
//! List of notification callbacks.
|
||||
//std::list<NotifyCallback> m_notifyCallbacks;
|
||||
GUID m_currentMaterialGUID;
|
||||
};
|
||||
|
||||
#endif // __materialmanager_h__
|
||||
Reference in New Issue
Block a user