WIP: particle editor.

This commit is contained in:
Artyom Shalkhakov 2025-02-02 15:26:39 -07:00
parent 31e9679de9
commit 1b6513bb57
10 changed files with 2015 additions and 13 deletions

View file

@ -848,6 +848,8 @@ set(src_imgui ${src_imgui}
tools/imgui/lighteditor/LightEditor.cpp
tools/imgui/pdaeditor/PDAEditor.h
tools/imgui/pdaeditor/PDAEditor.cpp
tools/imgui/particleeditor/ParticleEditor.h
tools/imgui/particleeditor/ParticleEditor.cpp
)
else()
set(src_imgui sys/sys_imgui.h)

View file

@ -995,6 +995,8 @@ void idCommonLocal::InitTool( const toolFlag_t tool, const idDict *dict ) {
ImGuiTools::AfEditorInit(); // TODO: dict ?
} else if ( tool & EDITOR_PDA ) {
ImGuiTools::PDAEditorInit( dict );
} else if ( tool & EDITOR_PARTICLE ) {
ImGuiTools::ParticleEditorInit( dict );
}
#endif
@ -1291,6 +1293,22 @@ static void Com_EditAFs_f( const idCmdArgs &args ) {
#endif
}
/*
==================
Com_EditParticles_f
==================
*/
static void Com_EditParticles_f(const idCmdArgs& args) {
#ifndef IMGUI_DISABLE
ImGuiTools::ParticleEditorInit( NULL );
#elif defined(ID_ALLOW_TOOLS)
ParticleEditorInit(NULL);
#else
common->Warning( "Editors not available because dhewm3 was built without ImGui or MFC Tools" );
#endif
}
#ifdef ID_ALLOW_TOOLS
/*
==================
@ -1311,15 +1329,6 @@ static void Com_EditDecls_f( const idCmdArgs &args ) {
DeclBrowserInit( NULL );
}
/*
==================
Com_EditParticles_f
==================
*/
static void Com_EditParticles_f( const idCmdArgs &args ) {
ParticleEditorInit( NULL );
}
/*
==================
Com_EditScripts_f

View file

@ -45,8 +45,6 @@
extern void Com_DrawDhewm3SettingsMenu(); // in framework/dhewm3SettingsMenu.cpp
extern void Com_OpenCloseDhewm3SettingsMenu( bool open ); // ditto
extern void PDAEditorRun(); // in tools/pda/DialogPDAEditor.cpp
static idCVar imgui_scale( "imgui_scale", "-1.0", CVAR_SYSTEM|CVAR_FLOAT|CVAR_ARCHIVE, "factor to scale ImGUI menus by (-1: auto)" ); // TODO: limit values?
idCVar imgui_style( "imgui_style", "0", CVAR_SYSTEM|CVAR_INTEGER|CVAR_ARCHIVE, "Which ImGui style to use. 0: Dhewm3 theme, 1: Default ImGui theme, 2: User theme", 0.0f, 2.0f );

View file

@ -15,9 +15,9 @@ enum D3ImGuiWindow {
D3_ImGuiWin_LightEditor = 4, // new ingame Light Editor
D3_ImGuiWin_AfEditor = 8, // new AF Editor
D3_ImGuiWin_PDAEditor = 16, // new PDA Editor
// next should be 32, then 64, etc so a bitmask can be used
D3_ImGuiWin_ParticleEditor = 32, // next should be 64, then 128, etc so a bitmask can be used
D3_ImGuiWin_AnyEditor = D3_ImGuiWin_LightEditor | D3_ImGuiWin_AfEditor | D3_ImGuiWin_PDAEditor // to decide whether to call DrawToolWindows()
D3_ImGuiWin_AnyEditor = D3_ImGuiWin_LightEditor | D3_ImGuiWin_AfEditor | D3_ImGuiWin_PDAEditor | D3_ImGuiWin_ParticleEditor // to decide whether to call DrawToolWindows()
};
#ifndef IMGUI_DISABLE

View file

@ -74,6 +74,8 @@ void AfEditorInit();
// in-game PDA Editor
void PDAEditorInit( const idDict* spawnArgs );
void ParticleEditorInit( const idDict* spawnArgs );
}

View file

@ -40,6 +40,7 @@ If you have questions concerning this license or the applicable additional terms
#include "afeditor/AfEditor.h"
#include "lighteditor/LightEditor.h"
#include "pdaeditor/PDAEditor.h"
#include "particleeditor/ParticleEditor.h"
static bool releaseMouse = false;
@ -138,6 +139,10 @@ void DrawToolWindows()
{
PDAEditor::Instance().Draw();
}
else if ( ParticleEditor::Instance().IsShown() )
{
ParticleEditor::Instance().Draw();
}
}
void LightEditorInit( const idDict* dict )
@ -180,4 +185,23 @@ void PDAEditorInit(const idDict* dict)
D3::ImGuiHooks::OpenWindow(D3::ImGuiHooks::D3_ImGuiWin_PDAEditor);
}
void ParticleEditorInit(const idDict* spawnArgs)
{
ParticleEditor::Instance().Reset();
ParticleEditor::Instance().ShowIt( true );
impl::SetReleaseToolMouse(true);
if ( spawnArgs ) {
idStr str = spawnArgs->GetString("model");
str.StripFileExtension();
ParticleEditor::Instance().SelectParticle(str);
ParticleEditor::Instance().SetParticleVisualization(static_cast<int>(ParticleEditor::SELECTED));
}
cvarSystem->SetCVarBool("r_useCachedDynamicModels", false);
D3::ImGuiHooks::OpenWindow(D3::ImGuiHooks::D3_ImGuiWin_ParticleEditor);
}
} //namespace ImGuiTools

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,331 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __PARTICLEEDITOR_H__
#define __PARTICLEEDITOR_H__
#include "../../edit_public.h"
class idDeclParticle;
class idParticleStage;
namespace ImGuiTools
{
class ColorPicker {
public:
bool Draw( const char *label, float *r, float *g, float *b, float *a );
};
class RangeSlider {
public:
bool Draw( const char *label, float itemWidth, float sliderWidth );
void SetRange( int _min, int _max ) {
min = _min;
max = _max;
}
int GetRangeMin() {
return min;
}
int GetRangeMax() {
return max;
}
void SetValueRange(float _low, float _high) {
low = _low;
high = _high;
}
float GetValueLow() {
return low;
}
float GetValueHigh() {
return high;
}
void SetValuePos( float val ) {
SetPos( GetRangeMin() + ( GetRangeMax() - GetRangeMin() ) * ( val - low ) / ( high - low ) );
}
float GetValue() {
return low + ( high - low ) * ( float )( GetPos() - GetRangeMin() ) / ( GetRangeMax() - GetRangeMin() );
}
void SetPos( int _pos ) {
pos = _pos;
}
int GetPos() {
return pos;
}
private:
float low, high;
int pos;
int min, max;
};
class ParticleEditor {
public:
ParticleEditor(); // standard constructor
static ParticleEditor& Instance();
void SelectParticle( const char *name );
void SetParticleVisualization( int i );
void SetVectorControlUpdate( idQuat rotation );
enum { TESTMODEL, IMPACT, MUZZLE, FLIGHT, SELECTED };
void Reset();
void Draw();
void ShowIt(bool show) {
isShown = show;
}
bool IsShown() {
return isShown;
}
protected:
void OnCbnSelchangeComboParticles();
void OnCbnSelchangeComboPath();
void OnLbnSelchangeListStages();
void OnBnClickedButtonBrowsematerial();
void OnBnClickedButtonBrowsecolor();
void OnBnClickedButtonBrowsefadecolor();
void OnBnClickedButtonBrowseEntitycolor();
void OnBnClickedRadioRect();
void OnBnClickedRadioSphere();
void OnBnClickedRadioCylinder();
void OnBnClickedRadioCone();
void OnBnClickedRadioOutward();
void OnBnClickedRadioView();
void OnBnClickedRadioAimed();
void OnBnClickedRadioX();
void OnBnClickedRadioY();
void OnBnClickedRadioZ();
void OnBnClickedCheckOneshot();
void ButtonNew();
void OnBnClickedButtonSave();
void ButtonSaveAs();
void OnBnClickedButtonSaveParticles();
void OnBnClickedWorldGravity();
void OnBnClickedEntityColor();
void OnBnClickedTestModel();
void OnBnClickedImpact();
void OnBnClickedMuzzle();
void OnBnClickedFlight();
void OnBnClickedSelected();
void OnBnClickedDoom();
void OnBnClickedButtonUpdate();
void OnBnClickedParticleMode();
void OnBtnYup();
void OnBtnYdn();
void OnBtnXdn();
void OnBtnXup();
void OnBtnZup();
void OnBtnZdn();
void OnBtnDrop();
//void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
private:
bool isShown;
idStr inFileText;
bool buttonSaveParticleEntitiesEnabled;
ColorPicker colorPickerDlg;
// edit controls
bool editControlsEnabled;
bool buttonXDNEnabled;
bool buttonXUPEnabled;
bool buttonYUPEnabled;
bool buttonYDNEnabled;
bool buttonZUPEnabled;
bool buttonZDNEnabled;
bool buttonDropEmitterEnabled;
bool buttonVectorEnabled;
bool buttonBrowseColorEntityEnabled;
// stage controls
bool stageControlsEnabled;
bool editMaterialEnabled;
bool buttonBrowseMaterialEnabled;
bool editAnimFramesEnabled;
bool editAnimRateEnabled;
bool editColorEnabled;
bool buttonBrowseColorEnabled;
bool editFadeColorEnabled;
bool buttonBrowseFadeColorEnabled;
bool editFadeInEnabled;
bool sliderFadeInEnabled;
bool editFadeOutEnabled;
bool editFadeFractionEnabled;
bool sliderFadeOutEnabled;
bool sliderFadeFractionEnabled;
bool editBunchingEnabled;
bool sliderBunchingEnabled;
bool editCountEnabled;
bool sliderCountEnabled;
bool editTimeEnabled;
bool sliderTimeEnabled;
bool editCyclesEnabled;
bool editTimeOffsetEnabled;
bool editDeadTimeEnabled;
bool checkWorldGravityEnabled;
bool editGravityEnabled;
bool sliderGravityEnabled;
bool radioRectEnabled;
bool radioCylinderEnabled;
bool radioSphereEnabled;
bool editOffsetEnabled;
bool editXSizeEnabled;
bool editYSizeEnabled;
bool editZSizeEnabled;
bool editRingOffsetEnabled;
bool radioConeEnabled;
bool radioOutwardEnabled;
bool editDirectionParmEnabled;
bool radioAimedEnabled;
bool radioViewEnabled;
bool radioXEnabled;
bool radioYEnabled;
bool radioZEnabled;
bool editOrientationParm1Enabled;
bool editOrientationParm2Enabled;
bool sliderSpeedFromEnabled;
bool editSpeedFromEnabled;
bool editSpeedToEnabled;
bool sliderSpeedToEnabled;
bool sliderRotationFromEnabled;
bool editRotationFromEnabled;
bool editRotationToEnabled;
bool sliderRotationToEnabled;
bool sliderSizeFromEnabled;
bool editSizeFromEnabled;
bool editSizeToEnabled;
bool sliderSizeToEnabled;
bool sliderAspectFromEnabled;
bool editAspectFromEnabled;
bool editAspectToEnabled;
bool editSliderAspectToEnabled;
bool comboCustomPathEnabled;
bool checkEntityColorEnabled;
idList<idStr> comboParticle;
int comboParticleSel;
idList<idStr> listStages;
idHashIndex listStagesItemData;
int listStagesSel;
RangeSlider sliderBunching;
RangeSlider sliderFadeIn;
RangeSlider sliderFadeOut;
RangeSlider sliderFadeFraction;
RangeSlider sliderCount;
RangeSlider sliderTime;
RangeSlider sliderGravity;
RangeSlider sliderSpeedFrom;
RangeSlider sliderSpeedTo;
RangeSlider sliderRotationFrom;
RangeSlider sliderRotationTo;
RangeSlider sliderSizeFrom;
RangeSlider sliderSizeTo;
RangeSlider sliderAspectFrom;
RangeSlider sliderAspectTo;
//VectorCtl vectorControl;
idStr depthHack;
idStr matName;
int animFrames;
int animRate;
idStr color;
idStr fadeColor;
float timeOffset;
float deadTime;
idStr offset;
float xSize;
float ySize;
float zSize;
float ringOffset;
idStr dirParmText;
float directionParm;
int direction;
int orientation;
int distribution;
idStr viewOrigin;
idStr customPath;
idStr customParms;
float trails;
float trailTime;
float cycles;
idStr editRingOffset;
bool worldGravity;
bool entityColor;
bool randomDistribution;
float initialAngle;
float boundsExpansion;
idStr customDesc;
bool particleMode;
int visualization;
private:
void EnumParticles();
void AddStage();
void RemoveStage();
void ShowStage();
void HideStage();
idDeclParticle * GetCurParticle();
idParticleStage * GetCurStage();
void ClearDlgVars();
void CurStageToDlgVars();
void DlgVarsToCurStage();
void ShowCurrentStage();
void UpdateControlInfo();
void SetParticleView();
void UpdateParticleData();
//CToolTipCtrl toolTipCtrl;
void SetSelectedModel( const char *val );
void EnableStageControls();
void EnableEditControls();
void UpdateSelectedOrigin( float x, float y, float z );
bool mapModified;
protected:
virtual void OnOK();
};
}
#endif /* !__PARTICLEEDITOR_H__ */

View file

@ -254,3 +254,57 @@ bool ImGui::InputTextMultilineStr( const char *label, idStr *str, const ImVec2 &
return result;
}
bool ImGui::InputDialogName( const char *text, const char *label, idStr *str ) {
bool accepted = false;
ImGui::OpenPopup( label );
if ( ImGui::BeginPopupModal( label, nullptr, ImGuiWindowFlags_AlwaysAutoResize ) ) {
ImGui::TextUnformatted( text );
if ( ImGui::InputTextStr( "Name", str ) ) {
// nop
}
if ( ImGui::Button( "OK" ) ) {
accepted = true;
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button("Cancel")) {
accepted = false;
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
return accepted;
}
bool ImGui::InputMessageBox( const char *text, const char* label, bool allowCancel ) {
bool accepted = false;
ImGui::OpenPopup( label );
if ( ImGui::BeginPopupModal( label, nullptr, ImGuiWindowFlags_AlwaysAutoResize ) ) {
ImGui::TextUnformatted( text );
if ( ImGui::Button( "OK" ) ) {
accepted = true;
ImGui::CloseCurrentPopup();
}
if ( allowCancel ) {
ImGui::SameLine();
if ( ImGui::Button( "Cancel" ) ) {
accepted = false;
ImGui::CloseCurrentPopup();
}
}
ImGui::EndPopup();
}
return accepted;
}

View file

@ -32,6 +32,7 @@ If you have questions concerning this license or the applicable additional terms
#include "sys/sys_imgui.h"
#include "idlib/Str.h"
#include "idlib/containers/List.h"
namespace ImGuiTools
{
@ -91,4 +92,8 @@ bool InputTextStr( const char* label, idStr* str, ImGuiInputTextFlags flags = 0,
bool InputTextMultilineStr( const char* label, idStr* str, const ImVec2& size = ImVec2(0, 0), ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = nullptr, void* user_data = nullptr );
bool InputDialogName( const char *text, const char *label, idStr *str );
bool InputMessageBox( const char *text, const char* label, bool allowCancel = false );
} //namespace ImGui