123
This commit is contained in:
1683
Editor/Particles/ParticleDialog.cpp
Normal file
1683
Editor/Particles/ParticleDialog.cpp
Normal file
File diff suppressed because it is too large
Load Diff
151
Editor/Particles/ParticleDialog.h
Normal file
151
Editor/Particles/ParticleDialog.h
Normal file
@@ -0,0 +1,151 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Crytek Engine Source File.
|
||||
// Copyright (C), Crytek Studios, 2002.
|
||||
// -------------------------------------------------------------------------
|
||||
// File name: particledialog.h
|
||||
// Version: v1.00
|
||||
// Created: 17/6/2003 by Timur.
|
||||
// Compilers: Visual Studio.NET
|
||||
// Description:
|
||||
// -------------------------------------------------------------------------
|
||||
// History:
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __particledialog_h__
|
||||
#define __particledialog_h__
|
||||
#pragma once
|
||||
|
||||
#include "BaseLibraryDialog.h"
|
||||
#include "Controls\SplitterWndEx.h"
|
||||
#include "Controls\TreeCtrlEx.h"
|
||||
#include "Controls\PropertyCtrl.h"
|
||||
#include "Controls\PreviewModelCtrl.h"
|
||||
|
||||
class CParticleItem;
|
||||
class CParticleManager;
|
||||
|
||||
/** Dialog which hosts entity prototype library.
|
||||
*/
|
||||
class CParticleDialog : public CBaseLibraryDialog
|
||||
{
|
||||
DECLARE_DYNAMIC(CParticleDialog)
|
||||
public:
|
||||
CParticleDialog( CWnd *pParent );
|
||||
~CParticleDialog();
|
||||
|
||||
// Called every frame.
|
||||
void Update();
|
||||
|
||||
virtual UINT GetDialogMenuID();
|
||||
|
||||
public:
|
||||
afx_msg void OnAssignParticleToSelection();
|
||||
afx_msg void OnResetParticleOnSelection();
|
||||
afx_msg void OnGetParticleFromSelection();
|
||||
|
||||
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 OnAddSubItem();
|
||||
afx_msg void OnDelSubItem();
|
||||
afx_msg void OnUpdateItemSelected( 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 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 );
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CParticleItem* GetSelectedParticle();
|
||||
void OnUpdateProperties( IVariable *var );
|
||||
|
||||
void AssignParticleToEntity( CParticleItem *pItem,CBaseObject *pObject );
|
||||
|
||||
//void LoadGeometry( const CString &filename );
|
||||
//void ReleaseGeometry();
|
||||
//void AssignMtlToGeometry();
|
||||
|
||||
//void SetTextureVars( CVariableArray *texVar,CParticleItem *mtl,int id,const CString &name );
|
||||
void SetParticleVars( CParticleItem *mtl );
|
||||
|
||||
void DropToItem( HTREEITEM hItem,HTREEITEM hSrcItem,CParticleItem *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;
|
||||
|
||||
// Particle manager.
|
||||
CParticleManager *m_pPartManager;
|
||||
|
||||
CVarBlockPtr m_vars;
|
||||
|
||||
EDrawType m_drawType;
|
||||
CString m_geometryFile;
|
||||
|
||||
HTREEITEM m_hDropItem;
|
||||
HTREEITEM m_hDraggedItem;
|
||||
|
||||
TSmartPtr<CParticleItem> m_pDraggedMtl;
|
||||
};
|
||||
|
||||
#endif // __particledialog_h__
|
||||
434
Editor/Particles/ParticleItem.cpp
Normal file
434
Editor/Particles/ParticleItem.cpp
Normal file
@@ -0,0 +1,434 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Crytek Engine Source File.
|
||||
// Copyright (C), Crytek Studios, 2002.
|
||||
// -------------------------------------------------------------------------
|
||||
// File name: particleitem.cpp
|
||||
// Version: v1.00
|
||||
// Created: 17/6/2003 by Timur.
|
||||
// Compilers: Visual Studio.NET
|
||||
// Description:
|
||||
// -------------------------------------------------------------------------
|
||||
// History:
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "ParticleItem.h"
|
||||
|
||||
#include "ParticleLibrary.h"
|
||||
#include "BaseLibraryManager.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CParticleItem::CParticleItem()
|
||||
{
|
||||
m_pParentParticles = 0;
|
||||
m_pEffect = GetIEditor()->Get3DEngine()->CreateParticleEffect();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CParticleItem::~CParticleItem()
|
||||
{
|
||||
GetIEditor()->Get3DEngine()->DeleteParticleEffect( m_pEffect );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleItem::SetName( const CString &name )
|
||||
{
|
||||
CBaseLibraryItem::SetName( name );
|
||||
if (m_pEffect)
|
||||
m_pEffect->SetName( GetFullName() );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleItem::Serialize( SerializeContext &ctx )
|
||||
{
|
||||
CBaseLibraryItem::Serialize( ctx );
|
||||
XmlNodeRef node = ctx.node;
|
||||
if (ctx.bLoading)
|
||||
{
|
||||
// Loading.
|
||||
CString texture,geometry,material;
|
||||
int process = 0;
|
||||
for (int i = 0; i < node->getChildCount(); i++)
|
||||
{
|
||||
XmlNodeRef paramsNode = node->getChild(i);
|
||||
if (!paramsNode->isTag("Params"))
|
||||
continue;
|
||||
|
||||
if (!m_pEffect)
|
||||
continue;
|
||||
|
||||
ParticleParams ¶ms = m_pEffect->GetParticleParams(process);
|
||||
|
||||
paramsNode->getAttr( "Texture",texture );
|
||||
paramsNode->getAttr( "Geometry",geometry );
|
||||
paramsNode->getAttr( "Material",material );
|
||||
|
||||
bool bEnabled = true;
|
||||
paramsNode->getAttr( "Active",bEnabled );
|
||||
m_pEffect->SetEnabled( bEnabled );
|
||||
|
||||
int blendType;
|
||||
paramsNode->getAttr( "Flags",params.nParticleFlags );
|
||||
paramsNode->getAttr( "BlendType",blendType );
|
||||
paramsNode->getAttr( "Focus",params.fFocus );
|
||||
paramsNode->getAttr( "Speed",params.fSpeed.value );
|
||||
paramsNode->getAttr( "SpeedFadeOut",params.fSpeedFadeOut );
|
||||
paramsNode->getAttr( "SpeedAccel",params.fSpeedAccel );
|
||||
paramsNode->getAttr( "AirResistance",params.fAirResistance );
|
||||
paramsNode->getAttr( "SpeedVar",params.fSpeed.variation );
|
||||
paramsNode->getAttr( "Size",params.fSize.value );
|
||||
paramsNode->getAttr( "SizeVar",params.fSize.variation );
|
||||
paramsNode->getAttr( "SizeSpeed",params.fSizeSpeed );
|
||||
paramsNode->getAttr( "SizeFadeIn",params.fSizeFadeIn );
|
||||
paramsNode->getAttr( "SizeFadeOut",params.fSizeFadeOut );
|
||||
paramsNode->getAttr( "ObjectScale",params.fObjectScale );
|
||||
paramsNode->getAttr( "Count",params.nCount );
|
||||
paramsNode->getAttr( "LifeTime",params.fLifeTime.value );
|
||||
paramsNode->getAttr( "LifeTimeVar",params.fLifeTime.variation );
|
||||
paramsNode->getAttr( "FadeInTime",params.fFadeInTime );
|
||||
paramsNode->getAttr( "FramesCount",params.nTexAnimFramesCount );
|
||||
paramsNode->getAttr( "Tail",params.fTailLenght );
|
||||
paramsNode->getAttr( "TailSteps",params.nTailSteps );
|
||||
paramsNode->getAttr( "Stretch",params.fStretch );
|
||||
paramsNode->getAttr( "RealPhysics",params.bRealPhysics );
|
||||
paramsNode->getAttr( "DrawLast",params.nDrawLast );
|
||||
paramsNode->getAttr( "Bounciess",params.fBouncenes );
|
||||
paramsNode->getAttr( "TurbulenceSize",params.fTurbulenceSize );
|
||||
paramsNode->getAttr( "TurbulenceSpeed",params.fTurbulenceSpeed );
|
||||
//paramsNode->getAttr( "RandomPosOffset",params.fPosRandomOffset );
|
||||
|
||||
paramsNode->getAttr( "StartColor",params.vColorStart );
|
||||
paramsNode->getAttr( "EndColor",params.vColorEnd );
|
||||
paramsNode->getAttr( "Rotation",params.vRotation.value );
|
||||
paramsNode->getAttr( "RotationVar",params.vRotation.variation );
|
||||
paramsNode->getAttr( "InitAngles",params.vInitAngles.value );
|
||||
paramsNode->getAttr( "InitAnglesVar",params.vInitAngles.variation );
|
||||
paramsNode->getAttr( "Gravity",params.vGravity );
|
||||
paramsNode->getAttr( "ChildSpawnPeriod",params.fChildSpawnPeriod );
|
||||
paramsNode->getAttr( "ChildSpawnTime",params.fChildSpawnTime );
|
||||
|
||||
paramsNode->getAttr( "PositionOffset",params.vPositionOffset );
|
||||
paramsNode->getAttr( "RandomOffset",params.vRandomPositionOffset );
|
||||
paramsNode->getAttr( "SpawnDelay",params.fSpawnDelay.value );
|
||||
paramsNode->getAttr( "SpawnDelayVar",params.fSpawnDelay.variation );
|
||||
paramsNode->getAttr( "EmitterLifeTime",params.fEmitterLifeTime.value );
|
||||
paramsNode->getAttr( "EmitterLifeTimeVar",params.fEmitterLifeTime.variation );
|
||||
paramsNode->getAttr( "SpawnPeriod",params.fSpawnPeriod );
|
||||
|
||||
IParticleEffect::SoundParams soundParams;
|
||||
CString sound;
|
||||
paramsNode->getAttr( "Sound",sound );
|
||||
paramsNode->getAttr( "SoundVolume",soundParams.volume );
|
||||
paramsNode->getAttr( "SoundMinRange",soundParams.minRadius );
|
||||
paramsNode->getAttr( "SoundMaxRange",soundParams.maxRadius );
|
||||
paramsNode->getAttr( "SoundLoop",soundParams.bLoop );
|
||||
paramsNode->getAttr( "SoundOnEverySpawn",soundParams.bOnEverySpawn );
|
||||
soundParams.szSound = sound;
|
||||
m_pEffect->SetSoundParams( soundParams );
|
||||
|
||||
params.eBlendType = (ParticleBlendType)blendType;
|
||||
|
||||
m_pEffect->SetGeometry( process,geometry );
|
||||
m_pEffect->SetTexture( process,texture );
|
||||
m_pEffect->SetMaterialName( process,material );
|
||||
|
||||
process++;
|
||||
}
|
||||
|
||||
// Serialize childs.
|
||||
|
||||
CParticleManager *pManager = GetIEditor()->GetParticleManager();
|
||||
|
||||
// Serialize childs.
|
||||
XmlNodeRef childsNode = node->findChild( "Childs" );
|
||||
if (childsNode)
|
||||
{
|
||||
for (i = 0; i < childsNode->getChildCount(); i++)
|
||||
{
|
||||
XmlNodeRef xchild = childsNode->getChild(i);
|
||||
CParticleItem *pItem = new CParticleItem;
|
||||
GetLibrary()->AddItem( pItem );
|
||||
SerializeContext childCtx(ctx);
|
||||
childCtx.node = xchild;
|
||||
pItem->Serialize( childCtx );
|
||||
|
||||
AddChild( pItem );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
// Saving.
|
||||
for (i = 0; i < IParticleEffect::NUM_PARTICLE_PROCESSES; i++)
|
||||
{
|
||||
if (!m_pEffect)
|
||||
continue;
|
||||
|
||||
ParticleParams ¶ms = m_pEffect->GetParticleParams(i);
|
||||
// Save particle params.
|
||||
XmlNodeRef paramsNode = node->newChild( "Params" );
|
||||
|
||||
paramsNode->setAttr( "Active",m_pEffect->IsEnabled() );
|
||||
paramsNode->setAttr( "Flags",params.nParticleFlags );
|
||||
paramsNode->setAttr( "BlendType",(int)params.eBlendType );
|
||||
paramsNode->setAttr( "Focus",params.fFocus );
|
||||
paramsNode->setAttr( "Speed",params.fSpeed.value );
|
||||
paramsNode->setAttr( "SpeedFadeOut",params.fSpeedFadeOut );
|
||||
paramsNode->setAttr( "SpeedAccel",params.fSpeedAccel );
|
||||
paramsNode->setAttr( "AirResistance",params.fAirResistance );
|
||||
paramsNode->setAttr( "SpeedVar",params.fSpeed.variation );
|
||||
paramsNode->setAttr( "Size",params.fSize.value );
|
||||
paramsNode->setAttr( "SizeVar",params.fSize.variation );
|
||||
paramsNode->setAttr( "SizeFadeIn",params.fSizeFadeIn );
|
||||
paramsNode->setAttr( "SizeFadeOut",params.fSizeFadeOut );
|
||||
paramsNode->setAttr( "SizeSpeed",params.fSizeSpeed );
|
||||
paramsNode->setAttr( "ObjectScale",params.fObjectScale );
|
||||
paramsNode->setAttr( "Count",params.nCount );
|
||||
paramsNode->setAttr( "LifeTime",params.fLifeTime.value );
|
||||
paramsNode->setAttr( "LifeTimeVar",params.fLifeTime.variation );
|
||||
paramsNode->setAttr( "FadeInTime",params.fFadeInTime );
|
||||
paramsNode->setAttr( "FramesCount",params.nTexAnimFramesCount );
|
||||
paramsNode->setAttr( "Tail",params.fTailLenght );
|
||||
paramsNode->setAttr( "TailSteps",params.nTailSteps );
|
||||
paramsNode->setAttr( "Stretch",params.fStretch );
|
||||
paramsNode->setAttr( "RealPhysics",params.bRealPhysics );
|
||||
paramsNode->setAttr( "DrawLast",params.nDrawLast );
|
||||
paramsNode->setAttr( "Bounciess",params.fBouncenes );
|
||||
paramsNode->setAttr( "TurbulenceSize",params.fTurbulenceSize );
|
||||
paramsNode->setAttr( "TurbulenceSpeed",params.fTurbulenceSpeed );
|
||||
//paramsNode->setAttr( "RandomPosOffset",params.fPosRandomOffset );
|
||||
|
||||
paramsNode->setAttr( "StartColor",params.vColorStart );
|
||||
paramsNode->setAttr( "EndColor",params.vColorEnd );
|
||||
paramsNode->setAttr( "Rotation",params.vRotation );
|
||||
paramsNode->setAttr( "RotationVar",params.vRotation.variation );
|
||||
paramsNode->setAttr( "InitAngles",params.vInitAngles );
|
||||
paramsNode->setAttr( "InitAnglesVar",params.vInitAngles.variation );
|
||||
paramsNode->setAttr( "Gravity",params.vGravity );
|
||||
paramsNode->setAttr( "ChildSpawnPeriod",params.fChildSpawnPeriod );
|
||||
paramsNode->setAttr( "ChildSpawnTime",params.fChildSpawnTime );
|
||||
|
||||
paramsNode->setAttr( "PositionOffset",params.vPositionOffset );
|
||||
paramsNode->setAttr( "RandomOffset",params.vRandomPositionOffset );
|
||||
paramsNode->setAttr( "SpawnDelay",params.fSpawnDelay.value );
|
||||
paramsNode->setAttr( "SpawnDelayVar",params.fSpawnDelay.variation );
|
||||
paramsNode->setAttr( "EmitterLifeTime",params.fEmitterLifeTime.value );
|
||||
paramsNode->setAttr( "EmitterLifeTimeVar",params.fEmitterLifeTime.variation );
|
||||
paramsNode->setAttr( "SpawnPeriod",params.fSpawnPeriod );
|
||||
|
||||
paramsNode->setAttr( "Texture",m_pEffect->GetTexture(i) );
|
||||
paramsNode->setAttr( "Geometry",m_pEffect->GetGeometry(i) );
|
||||
paramsNode->setAttr( "Material",m_pEffect->GetMaterialName(i) );
|
||||
|
||||
IParticleEffect::SoundParams soundParams;
|
||||
m_pEffect->GetSoundParams( soundParams );
|
||||
paramsNode->setAttr( "Sound",soundParams.szSound );
|
||||
paramsNode->setAttr( "SoundVolume",soundParams.volume );
|
||||
paramsNode->setAttr( "SoundMinRange",soundParams.minRadius );
|
||||
paramsNode->setAttr( "SoundMaxRange",soundParams.maxRadius );
|
||||
paramsNode->setAttr( "SoundLoop",soundParams.bLoop );
|
||||
paramsNode->setAttr( "SoundOnEverySpawn",soundParams.bOnEverySpawn );
|
||||
}
|
||||
// Serialize childs.
|
||||
XmlNodeRef childsNode = node->newChild( "Childs" );
|
||||
for (i = 0; i < m_childs.size(); i++)
|
||||
{
|
||||
XmlNodeRef xchild = childsNode->newChild( "Particles" );
|
||||
SerializeContext childCtx(ctx);
|
||||
childCtx.node = xchild;
|
||||
m_childs[i]->Serialize( childCtx );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int CParticleItem::GetChildCount() const
|
||||
{
|
||||
return m_childs.size();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CParticleItem* CParticleItem::GetChild( int index ) const
|
||||
{
|
||||
assert( index >= 0 && index < m_childs.size() );
|
||||
return m_childs[index];
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleItem::AddChild( CParticleItem *pItem )
|
||||
{
|
||||
assert( pItem );
|
||||
pItem->m_pParentParticles = this;
|
||||
m_childs.push_back(pItem);
|
||||
pItem->m_library = m_library;
|
||||
|
||||
// Change name to be without group.
|
||||
if (pItem->GetName() != pItem->GetShortName())
|
||||
{
|
||||
pItem->SetName( m_library->GetManager()->MakeUniqItemName(pItem->GetShortName()) );
|
||||
}
|
||||
|
||||
if (m_pEffect)
|
||||
m_pEffect->AddChild( pItem->GetEffect() );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleItem::RemoveChild( CParticleItem *pItem )
|
||||
{
|
||||
assert( pItem );
|
||||
TSmartPtr<CParticleItem> refholder = pItem;
|
||||
if (stl::find_and_erase( m_childs,pItem ))
|
||||
{
|
||||
pItem->m_pParentParticles = NULL;
|
||||
}
|
||||
if (m_pEffect)
|
||||
m_pEffect->RemoveChild( pItem->GetEffect() );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleItem::ClearChilds()
|
||||
{
|
||||
// Also delete them from the library.
|
||||
for (int i = 0; i < m_childs.size(); i++)
|
||||
{
|
||||
m_childs[i]->m_pParentParticles = NULL;
|
||||
}
|
||||
m_childs.clear();
|
||||
|
||||
if (m_pEffect)
|
||||
m_pEffect->ClearChilds();
|
||||
}
|
||||
|
||||
/*
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleItem::InsertChild( int slot,CParticleItem *pItem )
|
||||
{
|
||||
if (slot < 0)
|
||||
slot = 0;
|
||||
if (slot > m_childs.size())
|
||||
slot = m_childs.size();
|
||||
|
||||
assert( pItem );
|
||||
pItem->m_pParentParticles = this;
|
||||
pItem->m_library = m_library;
|
||||
|
||||
m_childs.insert( m_childs.begin() + slot,pItem );
|
||||
m_pMatInfo->RemoveAllSubMtls();
|
||||
for (int i = 0; i < m_childs.size(); i++)
|
||||
{
|
||||
m_pMatInfo->AddSubMtl( m_childs[i]->m_pMatInfo );
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int CParticleItem::FindChild( CParticleItem *pItem )
|
||||
{
|
||||
for (int i = 0; i < m_childs.size(); i++)
|
||||
{
|
||||
if (m_childs[i] == pItem)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CParticleItem* CParticleItem::GetParent() const
|
||||
{
|
||||
return m_pParentParticles;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
IParticleEffect* CParticleItem::GetEffect() const
|
||||
{
|
||||
return m_pEffect;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleItem::GenerateIdRecursively()
|
||||
{
|
||||
GenerateId();
|
||||
for (int i = 0; i < m_childs.size(); i++)
|
||||
{
|
||||
m_childs[i]->GenerateIdRecursively();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleItem::Update()
|
||||
{
|
||||
// Mark library as modified.
|
||||
GetLibrary()->SetModified();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleItem::SetDefaults()
|
||||
{
|
||||
if (m_pEffect)
|
||||
{
|
||||
{
|
||||
ParticleParams ¶ms = m_pEffect->GetParticleParams(0);
|
||||
params.nCount = 1;
|
||||
params.fSize = 1;
|
||||
params.fLifeTime = 1;
|
||||
params.fSpeed = 1;
|
||||
params.vColorStart.Set(1,1,1);
|
||||
params.vColorEnd.Set(1,1,1);
|
||||
}
|
||||
{
|
||||
ParticleParams ¶ms = m_pEffect->GetParticleParams(1);
|
||||
params.fSize = 1;
|
||||
params.fLifeTime = 1;
|
||||
params.fSpeed = 1;
|
||||
params.vColorStart.Set(1,1,1);
|
||||
params.vColorEnd.Set(1,1,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleItem::GatherUsedResources( CUsedResources &resources )
|
||||
{
|
||||
for (int k = 0; k < IParticleEffect::NUM_PARTICLE_PROCESSES; k++)
|
||||
{
|
||||
if (strlen(m_pEffect->GetTexture(k)) > 0)
|
||||
resources.Add( m_pEffect->GetTexture(k) );
|
||||
if (strlen(m_pEffect->GetGeometry(k)) > 0)
|
||||
resources.Add( m_pEffect->GetGeometry(k) );
|
||||
|
||||
IParticleEffect::SoundParams snd;
|
||||
m_pEffect->GetSoundParams( snd );
|
||||
if (strlen(snd.szSound) > 0)
|
||||
resources.Add( snd.szSound );
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleItem::GetFrom3DEngine()
|
||||
{
|
||||
IParticleEffect_AutoPtr pEffect = GetIEditor()->Get3DEngine()->FindParticleEffect( GetFullName() );
|
||||
if (!pEffect)
|
||||
return;
|
||||
|
||||
CString str = GetLibrary()->GetName() + ".";
|
||||
|
||||
// Copy 3d engine particle effect to this one..
|
||||
ClearChilds();
|
||||
for (int i = 0; i < pEffect->GetChildCount(); i++)
|
||||
{
|
||||
CParticleItem *pItem = new CParticleItem;
|
||||
GetLibrary()->AddItem( pItem );
|
||||
pItem->m_pEffect = pEffect->GetChild(i);
|
||||
CString name = pEffect->GetName();
|
||||
name.Replace( str,"" );
|
||||
pItem->SetName( name );
|
||||
AddChild( pItem );
|
||||
}
|
||||
|
||||
m_pEffect = pEffect;
|
||||
}
|
||||
81
Editor/Particles/ParticleItem.h
Normal file
81
Editor/Particles/ParticleItem.h
Normal file
@@ -0,0 +1,81 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Crytek Engine Source File.
|
||||
// Copyright (C), Crytek Studios, 2002.
|
||||
// -------------------------------------------------------------------------
|
||||
// File name: particleitem.h
|
||||
// Version: v1.00
|
||||
// Created: 17/6/2003 by Timur.
|
||||
// Compilers: Visual Studio.NET
|
||||
// Description:
|
||||
// -------------------------------------------------------------------------
|
||||
// History:
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __particleitem_h__
|
||||
#define __particleitem_h__
|
||||
#pragma once
|
||||
|
||||
#include "BaseLibraryItem.h"
|
||||
#include <I3dEngine.h>
|
||||
|
||||
/*! CParticleItem contain definition of particle system spawning parameters.
|
||||
*
|
||||
*/
|
||||
class CRYEDIT_API CParticleItem : public CBaseLibraryItem
|
||||
{
|
||||
public:
|
||||
CParticleItem();
|
||||
~CParticleItem();
|
||||
|
||||
virtual void SetName( const CString &name );
|
||||
void Serialize( SerializeContext &ctx );
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Child particle systems.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//! Get number of sub Particles childs.
|
||||
int GetChildCount() const;
|
||||
//! Get sub Particles child by index.
|
||||
CParticleItem* GetChild( int index ) const;
|
||||
//! Adds a new sub Particles.
|
||||
void AddChild( CParticleItem *mtl );
|
||||
//! Remove specific sub Particles
|
||||
void RemoveChild( CParticleItem *mtl );
|
||||
//! Remove all sub Particles.
|
||||
void ClearChilds();
|
||||
//! Insert sub particles in between other particles.
|
||||
//void InsertChild( int slot,CParticleItem *mtl );
|
||||
//! Find slot where sub Particles stored.
|
||||
//! @retun slot index if Particles found, -1 if Particles not found.
|
||||
int FindChild( CParticleItem *mtl );
|
||||
//! Returns parent Particles.
|
||||
CParticleItem* GetParent() const;
|
||||
|
||||
void GenerateIdRecursively();
|
||||
|
||||
//! Called when new patricle effect created.
|
||||
void SetDefaults();
|
||||
|
||||
//! Called after particle parameters where updated.
|
||||
void Update();
|
||||
|
||||
//! Get particle effect assigned to this particle item.
|
||||
IParticleEffect* GetEffect() const;
|
||||
|
||||
virtual void GatherUsedResources( CUsedResources &resources );
|
||||
|
||||
void GetFrom3DEngine();
|
||||
|
||||
private:
|
||||
IParticleEffect_AutoPtr m_pEffect;
|
||||
|
||||
//! Parent of this material (if this is sub material).
|
||||
CParticleItem *m_pParentParticles;
|
||||
//! Array of sub particle items.
|
||||
std::vector<TSmartPtr<CParticleItem> > m_childs;
|
||||
};
|
||||
|
||||
#endif // __particleitem_h__
|
||||
|
||||
89
Editor/Particles/ParticleLibrary.cpp
Normal file
89
Editor/Particles/ParticleLibrary.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Crytek Engine Source File.
|
||||
// Copyright (C), Crytek Studios, 2002.
|
||||
// -------------------------------------------------------------------------
|
||||
// File name: particlelibrary.cpp
|
||||
// Version: v1.00
|
||||
// Created: 17/6/2003 by Timur.
|
||||
// Compilers: Visual Studio.NET
|
||||
// Description:
|
||||
// -------------------------------------------------------------------------
|
||||
// History:
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "ParticleLibrary.h"
|
||||
#include "ParticleItem.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CParticleLibrary implementation.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CParticleLibrary::Save()
|
||||
{
|
||||
XmlNodeRef root = new CXmlNode( "ParticleLibrary" );
|
||||
Serialize( root,false );
|
||||
bool bRes = root->saveToFile( GetFilename() );
|
||||
return bRes;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CParticleLibrary::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 CParticleLibrary::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++)
|
||||
{
|
||||
XmlNodeRef itemNode = root->getChild(i);
|
||||
// Only accept nodes with correct name.
|
||||
if (stricmp(itemNode->getTag(),"Particles") != 0)
|
||||
continue;
|
||||
CParticleItem *pItem = new CParticleItem;
|
||||
AddItem( pItem );
|
||||
|
||||
CBaseLibraryItem::SerializeContext ctx( itemNode,bLoading );
|
||||
pItem->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++)
|
||||
{
|
||||
CParticleItem *pItem = (CParticleItem*)GetItem(i);
|
||||
// Save materials with childs under thier parent table.
|
||||
if (pItem->GetParent())
|
||||
continue;
|
||||
|
||||
XmlNodeRef itemNode = root->newChild( "Particles" );
|
||||
CBaseLibraryItem::SerializeContext ctx( itemNode,bLoading );
|
||||
GetItem(i)->Serialize( ctx );
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Editor/Particles/ParticleLibrary.h
Normal file
36
Editor/Particles/ParticleLibrary.h
Normal file
@@ -0,0 +1,36 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Crytek Engine Source File.
|
||||
// Copyright (C), Crytek Studios, 2002.
|
||||
// -------------------------------------------------------------------------
|
||||
// File name: particlelibrary.h
|
||||
// Version: v1.00
|
||||
// Created: 17/6/2003 by Timur.
|
||||
// Compilers: Visual Studio.NET
|
||||
// Description:
|
||||
// -------------------------------------------------------------------------
|
||||
// History:
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __particlelibrary_h__
|
||||
#define __particlelibrary_h__
|
||||
#pragma once
|
||||
|
||||
#include "BaseLibrary.h"
|
||||
|
||||
#define GLOBAL_PARTICLES_ROOT "Particles"
|
||||
|
||||
/** Library of prototypes.
|
||||
*/
|
||||
class CRYEDIT_API CParticleLibrary : public CBaseLibrary
|
||||
{
|
||||
public:
|
||||
CParticleLibrary( CBaseLibraryManager *pManager ) : CBaseLibrary(pManager) {};
|
||||
virtual bool Save();
|
||||
virtual bool Load( const CString &filename );
|
||||
virtual void Serialize( XmlNodeRef &node,bool bLoading );
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // __particlelibrary_h__
|
||||
121
Editor/Particles/ParticleManager.cpp
Normal file
121
Editor/Particles/ParticleManager.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Crytek Engine Source File.
|
||||
// Copyright (C), Crytek Studios, 2002.
|
||||
// -------------------------------------------------------------------------
|
||||
// File name: particlemanager.cpp
|
||||
// Version: v1.00
|
||||
// Created: 17/6/2003 by Timur.
|
||||
// Compilers: Visual Studio.NET
|
||||
// Description:
|
||||
// -------------------------------------------------------------------------
|
||||
// History:
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "ParticleManager.h"
|
||||
|
||||
#include "ParticleItem.h"
|
||||
#include "ParticleLibrary.h"
|
||||
|
||||
#include "GameEngine.h"
|
||||
#include "GameExporter.h"
|
||||
|
||||
#define PARICLES_LIBS_PATH "Editor\\Particles\\"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CParticleManager implementation.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CParticleManager::CParticleManager()
|
||||
{
|
||||
m_libsPath = PARICLES_LIBS_PATH;
|
||||
|
||||
m_pLevelLibrary = (CBaseLibrary*)AddLibrary( "Level" );
|
||||
m_pLevelLibrary->SetLevelLibrary( true );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CParticleManager::~CParticleManager()
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleManager::ClearAll()
|
||||
{
|
||||
CBaseLibraryManager::ClearAll();
|
||||
|
||||
m_pLevelLibrary = (CBaseLibrary*)AddLibrary( "Level" );
|
||||
m_pLevelLibrary->SetLevelLibrary( true );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CBaseLibraryItem* CParticleManager::MakeNewItem()
|
||||
{
|
||||
return new CParticleItem;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CBaseLibrary* CParticleManager::MakeNewLibrary()
|
||||
{
|
||||
return new CParticleLibrary(this);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CString CParticleManager::GetRootNodeName()
|
||||
{
|
||||
return "ParticleLibs";
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CString CParticleManager::GetLibsPath()
|
||||
{
|
||||
return m_libsPath;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleManager::Serialize( XmlNodeRef &node,bool bLoading )
|
||||
{
|
||||
CBaseLibraryManager::Serialize( node,bLoading );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleManager::Export( XmlNodeRef &node )
|
||||
{
|
||||
XmlNodeRef libs = node->newChild( "ParticlesLibrary" );
|
||||
for (int i = 0; i < GetLibraryCount(); i++)
|
||||
{
|
||||
IDataBaseLibrary* pLib = GetLibrary(i);
|
||||
if (pLib->IsLevelLibrary())
|
||||
continue;
|
||||
// Level libraries are saved in in level.
|
||||
XmlNodeRef libNode = libs->newChild( "Library" );
|
||||
libNode->setAttr( "Name",pLib->GetName() );
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleManager::PasteToParticleItem( CParticleItem* pItem,XmlNodeRef &node,bool bWithChilds )
|
||||
{
|
||||
assert( pItem );
|
||||
assert( node != NULL );
|
||||
|
||||
CBaseLibraryItem::SerializeContext serCtx( node,true );
|
||||
serCtx.bCopyPaste = true;
|
||||
serCtx.bIgnoreChilds = !bWithChilds;
|
||||
pItem->Serialize( serCtx );
|
||||
pItem->GenerateIdRecursively();
|
||||
|
||||
for (int i = 0; i < pItem->GetChildCount(); i++)
|
||||
{
|
||||
CParticleItem *pChildItem = pItem->GetChild(i);
|
||||
pChildItem->SetName( MakeUniqItemName(pChildItem->GetName()) );
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CParticleManager::DeleteItem( CBaseLibraryItem* pItem )
|
||||
{
|
||||
CParticleItem *pPartItem = ((CParticleItem*)pItem);
|
||||
if (pPartItem->GetParent())
|
||||
pPartItem->GetParent()->RemoveChild(pPartItem);
|
||||
|
||||
CBaseLibraryManager::DeleteItem( pItem );
|
||||
}
|
||||
63
Editor/Particles/ParticleManager.h
Normal file
63
Editor/Particles/ParticleManager.h
Normal file
@@ -0,0 +1,63 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Crytek Engine Source File.
|
||||
// Copyright (C), Crytek Studios, 2002.
|
||||
// -------------------------------------------------------------------------
|
||||
// File name: particlemanager.h
|
||||
// Version: v1.00
|
||||
// Created: 17/6/2003 by Timur.
|
||||
// Compilers: Visual Studio.NET
|
||||
// Description:
|
||||
// -------------------------------------------------------------------------
|
||||
// History:
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __particlemanager_h__
|
||||
#define __particlemanager_h__
|
||||
#pragma once
|
||||
|
||||
#include "BaseLibraryManager.h"
|
||||
|
||||
class CParticleItem;
|
||||
class CParticleLibrary;
|
||||
struct SExportParticleEffect;
|
||||
|
||||
/** Manages Particle libraries and systems.
|
||||
*/
|
||||
class CRYEDIT_API CParticleManager : public CBaseLibraryManager
|
||||
{
|
||||
public:
|
||||
CParticleManager();
|
||||
~CParticleManager();
|
||||
|
||||
// Clear all prototypes and material libraries.
|
||||
void ClearAll();
|
||||
|
||||
virtual void DeleteItem( CBaseLibraryItem* pItem );
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Materials.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//! Loads a new material from a xml node.
|
||||
void PasteToParticleItem( CParticleItem* pItem,XmlNodeRef &node,bool bWithChilds );
|
||||
|
||||
//! Serialize manager.
|
||||
virtual void Serialize( XmlNodeRef &node,bool bLoading );
|
||||
|
||||
//! Export particle systems to game.
|
||||
void Export( XmlNodeRef &node );
|
||||
|
||||
protected:
|
||||
void AddExportItem( std::vector<SExportParticleEffect> &effects,CParticleItem *pItem,int parent );
|
||||
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();
|
||||
|
||||
CString m_libsPath;
|
||||
};
|
||||
|
||||
#endif // __particlemanager_h__
|
||||
Reference in New Issue
Block a user