Polyphase Game Engine
Loading...
Searching...
No Matches
PaintManager.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include <unordered_map>
6
7#include "Bullet/btBulletDynamicsCommon.h"
8#include "Bullet/BulletCollision/CollisionDispatch/btGhostObject.h"
9
11#include "ActionManager.h"
12
13struct PaintMeshCollision
14{
15 btCollisionObject* mCollisionObject = nullptr;
16 StaticMesh3D* mNode = nullptr;
17 StaticMeshRef mMesh;
18 glm::vec3 mPosition = {};
19 glm::quat mRotation = {};
20 glm::vec3 mScale = {};
21 bool mActive = false;
22};
23
24enum PaintBlendMode
25{
26 Mix,
27 Add,
29 Multiply,
30 AddAlpha,
31 SubtractAlpha,
32
33 Count
34};
35
36struct PaintColorOptions
37{
38 PaintBlendMode mBlendMode = PaintBlendMode::Mix;
39 glm::vec4 mColor = { 1.0f, 1.0f, 1.0f, 1.0f };
40 bool mOnlyFacingNormals = true;
41};
42
43struct PaintInstanceOptions
44{
45 StaticMeshRef mMesh;
46 float mDensity = 1.0f;
47 float mMinSeparation = 0.0f;
48 glm::vec3 mMinPosition = {};
49 glm::vec3 mMaxPosition = {};
50 glm::vec3 mMinRotation = {};
51 glm::vec3 mMaxRotation = {};
52 float mMinScale = 1.0f;
53 float mMaxScale = 1.0f;
54 bool mAlignWithNormal = false;
55 bool mErase = false;
56};
57
58struct PendingColorData
59{
61 ActionSetInstanceColorsData mOriginalData;
62 std::vector<uint32_t> mOriginalColors;
63 std::vector<float> mVertexDrawAlpha;
64 bool mAnyVertexPainted = false;
65};
66
67struct PendingInstanceData
68{
69 InstancedMesh3D* mMeshNode = nullptr;
70 std::vector<MeshInstanceData> mData;
71 std::vector<MeshInstanceData> mOriginalData;
72};
73
74class PaintManager
75{
76public:
77
78 PaintManager();
79 ~PaintManager();
80 void Update();
81 void HandleNodeDestroy(Node* node);
82
83 void AddPaintMeshCollision(const PaintMeshCollision& col);
84 void RemovePaintMeshCollision(const PaintMeshCollision& col);
85
86 void UpdateDynamicsWorld();
87 void UpdateHotkeys();
88 void UpdatePaintReticle();
89 void UpdatePaintDraw();
90
91 void FinishAdjustment();
92
93 bool mInitialized = false;
94
95 btDefaultCollisionConfiguration* mCollisionConfig = nullptr;
96 btCollisionDispatcher* mCollisionDispatcher = nullptr;
97 btDbvtBroadphase* mBroadphase = nullptr;
98 btSequentialImpulseConstraintSolver* mSolver = nullptr;
99 btDiscreteDynamicsWorld* mDynamicsWorld = nullptr;
100
101 std::unordered_map<StaticMesh3D*, PaintMeshCollision> mMeshCollisionMap;
102
103 btPairCachingGhostObject* mSphereGhost = nullptr;
104 btSphereShape* mSphereGhostShape = nullptr;
105 btGhostPairCallback* mGhostPairCallback = nullptr;
106
107 StaticMeshRef mSphereMesh;
108 MaterialRef mSphereMaterial;
109
110 glm::vec3 mSpherePosition = {};
111 glm::vec3 mSphereNormal = { 0.0f, 1.0f, 0.0f };
112 float mRadius = 1.0f;
113 float mOpacity = 1.0f;
114 bool mSphereValid = false;
115
116 float mPreAdjustRadius = 1.0f;
117 float mPreAdjustOpacity = 1.0f;
118
119 bool mAdjustRadius = false;
120 bool mAdjustOpacity = false;
121 bool mAdjustmentFinished = false;
122 glm::vec2 mAdjustmentAnchor = {};
123
124 bool mOnlyRenderSelected = false;
125
126 // Spacing is the distance we need to move between paints (in screen space currently)
127 float mSpacing = 10.0f;
128 glm::vec2 mLastPaintMousePos = {};
129
130 // Options
131 PaintColorOptions mColorOptions;
132 PaintInstanceOptions mInstanceOptions;
133
134 // Pending data
135 std::vector<PendingColorData> mPendingColorData;
136 PendingInstanceData mPendingInstanceData;
137};
138
139#endif
bool Update()
Definition Engine.cpp:710
Definition AssetRef.h:18
Definition InstancedMesh3d.h:13
Definition Node.h:67
Definition StaticMesh3d.h:12
Definition ActionManager.h:541