-
Notifications
You must be signed in to change notification settings - Fork 3
/
apiMeshSubSceneOverride.h
167 lines (136 loc) · 4.99 KB
/
apiMeshSubSceneOverride.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//-
// ==========================================================================
// Copyright 2015 Autodesk, Inc. All rights reserved.
//
// Use of this software is subject to the terms of the Autodesk
// license agreement provided at the time of installation or download,
// or which otherwise accompanies this software in either electronic
// or hard copy form.
// ==========================================================================
//+
///////////////////////////////////////////////////////////////////////////////
//
// apiMeshSubSceneOverride.h
//
// Handles vertex data preparation for drawing the user defined shape in
// Viewport 2.0.
//
////////////////////////////////////////////////////////////////////////////////
#include <maya/MPxSubSceneOverride.h>
#include <map>
#include <set>
#include <vector>
namespace MHWRender {
class MVertexBuffer;
class MIndexBuffer;
class MShaderInstance;
class MRenderItem;
class MIntersection;
}
class apiMesh;
class apiMeshGeom;
struct ID3D11Buffer;
namespace apiMeshSubSceneOverrideHelpers {
class ShadedItemUserData;
}
class apiMeshSubSceneOverride : public MHWRender::MPxSubSceneOverride
{
public:
static MPxSubSceneOverride* Creator(const MObject& obj)
{
return new apiMeshSubSceneOverride(obj);
}
virtual ~apiMeshSubSceneOverride();
virtual MHWRender::DrawAPI supportedDrawAPIs() const;
virtual bool requiresUpdate(
const MHWRender::MSubSceneContainer& container,
const MHWRender::MFrameContext& frameContext) const;
virtual void update(
MHWRender::MSubSceneContainer& container,
const MHWRender::MFrameContext& frameContext);
virtual bool furtherUpdateRequired(
const MHWRender::MFrameContext& frameContext);
virtual bool areUIDrawablesDirty() const;
virtual bool hasUIDrawables() const;
virtual void addUIDrawables(
MHWRender::MUIDrawManager& drawManager,
const MHWRender::MFrameContext& frameContext);
virtual void updateSelectionGranularity(
const MDagPath& path,
MHWRender::MSelectionContext& selectionContext);
// Fix component selection
virtual bool getInstancedSelectionPath(const MHWRender::MRenderItem& renderItem, const MHWRender::MIntersection& intersection, MDagPath& dagPath) const;
void untrackLinkLostData(apiMeshSubSceneOverrideHelpers::ShadedItemUserData* data);
static MStatus registerComponentConverters();
static MStatus deregisterComponentConverters();
private:
apiMeshSubSceneOverride(const MObject& obj);
void manageRenderItems(
MHWRender::MSubSceneContainer& container,
const MHWRender::MFrameContext& frameContext,
bool updateGeometry);
void rebuildGeometryBuffers();
void rebuildActiveComponentIndexBuffers();
void deleteBuffers();
void deleteGeometryBuffers();
void deleteActiveComponentIndexBuffers();
static void shadedItemLinkLost(MUserData* userData);
MObject fObject;
apiMesh* fMesh;
struct InstanceInfo
{
MMatrix fTransform;
bool fIsSelected;
InstanceInfo() : fIsSelected(false) {}
InstanceInfo(const MMatrix& matrix, bool selected) : fTransform(matrix), fIsSelected(selected) {}
};
typedef std::map<unsigned int, InstanceInfo> InstanceInfoMap;
InstanceInfoMap fInstanceInfoCache;
static const MString sWireName;
static const MString sSelectName;
static const MString sBoxName;
static const MString sSelectedBoxName;
static const MString sShadedName;
static const MString sTexturedName;
static const MString sVertexSelectionName;
static const MString sEdgeSelectionName;
static const MString sFaceSelectionName;
static const MString sActiveVertexName;
static const MString sActiveEdgeName;
static const MString sActiveFaceName;
MHWRender::MShaderInstance* fWireShader;
MHWRender::MShaderInstance* fThickWireShader;
MHWRender::MShaderInstance* fSelectShader;
MHWRender::MShaderInstance* fThickSelectShader;
MHWRender::MShaderInstance* fShadedShader;
MHWRender::MShaderInstance* fVertexComponentShader;
MHWRender::MShaderInstance* fEdgeComponentShader;
MHWRender::MShaderInstance* fFaceComponentShader;
MHWRender::MVertexBuffer* fPositionBuffer;
MHWRender::MVertexBuffer* fNormalBuffer;
MHWRender::MVertexBuffer* fBoxPositionBuffer;
MHWRender::MIndexBuffer* fWireIndexBuffer;
MHWRender::MIndexBuffer* fBoxIndexBuffer;
MHWRender::MIndexBuffer* fShadedIndexBuffer;
MHWRender::MIndexBuffer* fActiveVerticesIndexBuffer;
MHWRender::MIndexBuffer* fActiveEdgesIndexBuffer;
MHWRender::MIndexBuffer* fActiveFacesIndexBuffer;
// Client buffers
unsigned int fBoxPositionBufferId;
unsigned int fBoxIndexBufferId;
ID3D11Buffer* fBoxPositionBufferDX;
ID3D11Buffer* fBoxIndexBufferDX;
float fThickLineWidth;
unsigned int fNumInstances;
bool fIsInstanceMode;
// Variables to control sample queue of updates to
// allow for line width to increase incrementally without
// user control.
bool fUseQueuedLineUpdate;
float fQueuedLineWidth;
bool fQueueUpdate;
std::set<int> fActiveVerticesSet;
std::set<int> fActiveEdgesSet;
std::set<int> fActiveFacesSet;
std::vector<apiMeshSubSceneOverrideHelpers::ShadedItemUserData*> fLinkLostCallbackData;
};