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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
#ifndef _SHAVEOBJEXPORTER_H_
#define _SHAVEOBJEXPORTER_H_
// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962
#include <maya/MDagPath.h>
#include <maya/MDagPathArray.h>
#include <maya/MFnMesh.h>
#include <maya/MFnNurbsCurve.h>
#include <maya/MFnNurbsSurface.h>
#include <maya/MGlobal.h>
#include <maya/MIntArray.h>
#include <maya/MItDag.h>
#include <maya/MItMeshEdge.h>
#include <maya/MItMeshPolygon.h>
#include <maya/MItMeshVertex.h>
#include <maya/MItSelectionList.h>
#include <maya/MPointArray.h>
#include <maya/MSelectionList.h>
// We used to use MDagPaths to initialize function sets to access
// the input surfacs. That was always dangerous given that this
// code gets called during shaveHairShape::compute(). In Maya 8.0
// that started to cause problems when it turned out that polygon
// smooth proxy meshes were not in an internally consistent state
// in the middle of a compute(): they could have verts but not yet
// any faces.
//
// Here we get around this by pulling the geometry from the mesh's
// plug to ensure that it updates correctly. The proper approach
// GET_GEOM_FROM_DATABLOCK represents the correct approach which is to
// avoid the MDagPaths altogether and get all input geometry from the
// compute's datablock.
//
// Unfortunately that's not finished yet (shaveTextureStore still uses
// the DAG paths for the surfaces) so GET_GEOM_FROM_PLUGS represents a
// temporary workaround in which we continue to use MDagPaths to access
// the nodes, but make sure to pull the geometry from the node's plugs
// beforehand to ensure that it is up to date.
//
// Since the old approach worked prior to Maya 8.0, I'm only enabling this
// new stuff in 8.0.
#define GET_GEOM_FROM_DATABLOCK 0
#define GET_GEOM_FROM_PLUGS 1
#if MAYA_API_VERSION < 20180000
class MDataBlock;
class MFloatPointArray;
#endif
typedef struct
{
WFTYPE* theObj;
WFTYPE* uvs;
MDagPathArray meshes; // The exported meshes, in the order exported
MIntArray startFaces; // Face ID of first face of each mesh
MIntArray startVerts; // Vertex ID of first vert of each mesh
bool newtopo;
int uSubdivs;
int vSubdivs;
int lastUSubdiv;
int lastVSubdiv;
int subdDepth;
int subdSamples;
int lastSubdDepth;
int lastSubdSamples;
MObject shaveHairShape;
MString objFileName;
}ShaveExportData;
class shaveObjTranslator {
public:
shaveObjTranslator ();
virtual ~shaveObjTranslator (){}
static void* creator();
// called from shaveHairShape in order to export .obj file for the
// current node.
MStatus exportThis(MDataBlock& block, ShaveExportData& data);
MStatus exportOcclusion(MDagPathArray&, WFTYPE *);
void exportInstanceObj(MObject instanceMesh, MObject shader, MString filename);
private:
enum GeomType {
kGrowthGeom,
kCollisionGeom,
kOcclusionGeom
};
bool newtopo;
#if GET_GEOM_FROM_DATABLOCK
MObjectArray hairObjects;
MObjectArray hairComponents;
MObjectArray fullHairObjects;
MObjectArray partialHairObjects;
MObjectArray partialHairComponents;
MObjectArray skullObjects;
MObjectArray skullComponents;
MObjectArray fullSkullObjects;
MObjectArray partialSkullObjects;
MObjectArray partialSkullComponents;
#else
MSelectionList hairSelections;
MSelectionList skullSelections;
MDagPathArray fullHairObjects;
MSelectionList partialHairObjects;
MDagPathArray fullSkullObjects;
MSelectionList partialSkullObjects;
#endif
//! the total number of verts we'll write to the WFType.
int totalverts;
//! the total number of faces we'll write to the WFType.
int totalfaces;
//! the total number of fverts we'll write to the WFType.
int totalfverts;
MSpace::Space space;
MStatus objListInit();
MStatus separateOutPartialMeshes(
#if GET_GEOM_FROM_DATABLOCK
MObjectArray& objects,
MObjectArray& components,
MObjectArray& fullObjects,
MObjectArray& partialMeshes,
MObjectArray& partialMeshComponents
#else
MSelectionList& objectList,
MDagPathArray& fullObjects,
MSelectionList& partialMeshes
#endif
);
MStatus mtlLookupInit(bool**& growthFaces, bool**& collisionFaces);
void mtlLookupCleanup(bool**& growthFaces, bool**& collisionFaces);
MStatus createMtlLookup(MSelectionList& objectList, bool**& lookupTbl);
void deleteMtlLookup(MSelectionList& objectList, bool**& lookupTbl);
void exportFullObjects(
FILE* exportFile,
#if GET_GEOM_FROM_DATABLOCK
MObjectArray& objects,
#else
MDagPathArray& objects,
#endif
MObjectArray tesselations,
const char* surfaceMaterial,
const char* curveMaterial,
int& objectIndex,
int& vtxOffset,
int& faceOffset
);
void exportPartialMeshes(
FILE* exportFile,
#if GET_GEOM_FROM_DATABLOCK
MObjectArray& meshList,
#else
MSelectionList& meshList,
#endif
bool** activeFaceMap,
const char* activeFaceMaterial,
int& objectIndex,
int& vertexOffset,
int& faceOffset
);
MStatus doExport(
MString fileName,
MObjectArray tesselations,
bool** growthFaces,
bool** collisionFaces
);
void storeMeshInWFTYPE(
WFTYPE* wf,
WFTYPE* uvs,
MItMeshVertex& vertexIter,
MItMeshPolygon& faceIter,
int& vertexIndex,
int& faceIndex,
int& faceVertexIndex
);
void storeObjectInWFTYPE(
WFTYPE* wf,
WFTYPE* uvs,
#if GET_GEOM_FROM_DATABLOCK
MObject& object,
#else
MDagPath& object,
#endif
MObject tempMesh,
int& vertexIndex,
int& faceIndex,
int& faceVertexIndex
);
void getObjectCounts(
#if GET_GEOM_FROM_DATABLOCK
MObject& object,
#else
MDagPath& object,
#endif
GeomType geomType,
int& numVertices,
int& numFaces,
int& numFaceVertices,
int uTess,
int vTess,
int sDept,
int sSamp,
ShaveExportData* exportData,
MObjectArray& tesselations,
bool includeDisplacements = false
);
MStatus wfInit(
int uTess,
int vTess,
int sDept,
int sSamp,
ShaveExportData& exportData,
MObjectArray& tesselations
);
bool checkExported();
MStatus doWFType(WFTYPE* wf, WFTYPE* uvs, MObjectArray tesselations);
MObject getConnectedShader(MFnMesh);
void getCurveSamples(
#if GET_GEOM_FROM_DATABLOCK
MObject curve, MFloatPointArray& samples
#else
MDagPath curve, MFloatPointArray& samples
#endif
);
MString getShaderTexture(MObject shadingGroup);
};
#endif
|