aboutsummaryrefslogtreecommitdiff
path: root/mayaPlug/shaveAPI.h
blob: fee8e2824cff457520a2e5329d6494df3641f97a (plain) (blame)
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#ifndef shaveAPI_h
#define shaveAPI_h
// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962

#define    SHAVE_API_VERSION    4

#ifdef WIN32
#  ifdef LIBSHAVEAPI_EXPORTS
#    define LIBSHAVEAPI_API __declspec(dllexport)
#  else
#    define LIBSHAVEAPI_API __declspec(dllimport)
#  endif
#else
#  define LIBSHAVEAPI_API
#endif

#include <maya/MStatus.h>
#include <maya/MString.h>

#if MAYA_API_VERSION < 20180000
class MObjectArray;
#endif


class LIBSHAVEAPI_API shaveAPI
{
public:
    typedef struct
    {
        float x;
        float y;
        float z;
    } Vertex;

    typedef struct
    {
        float r;
        float g;
        float b;
    } Color;

    class LIBSHAVEAPI_API HairInfo
    {
    public:    
        HairInfo();
        ~HairInfo();

        //
        // Free up all storage allocated by a call to shaveExportHair().
        //
        // Note that a HairInfo object is automatically cleared when it is
        // destroyed.
        //
        void    clear();

        //
        // Number of unique vertices for all hairs in the structure.
        //
        int numVertices;

        //
        // Total number of hairs in the structure.
        //
        int numHairs;

        //
        // Total number of hair vertices in the structure.
        //
        // If several hairs share a vertex, it will only be counted once in
        // 'numVertices', but will be counted once for each hair in
        // 'numHairVertices'.
        //
        int numHairVertices;

        //
        // 'hairVertices' is an array of indices into the 'vertices' array
        // and contains one entry for each vertex of each hair.  A hair's
        // vertices run up the center of the hair.
        //
        // The indices for hair N start at 'hairStartIndices[N]' and end at
        // 'hairEndIndices[N] - 1'.  <-- NOTE THE -1 !!!
        //
        // 'hairVertices' will have 'numHairVertices' elements
        // 'hairStartIndices' will have 'numHairs' elements.
        // 'hairEndIndices' will have 'numHairs' elements.
        //
        int *hairVertices;
        int *hairStartIndices;
        int *hairEndIndices;

        //
        // Material characteristics.
        //
        // Each array has one entry per hair.
        //
        float*  opacities;
        float*  speculars;
        float*  glosses;
        float*  ambDiffs;
        Color*  rootColors;
        Color*  tipColors; 
        float*  rootRadii;
        float*  tipRadii;

        //
        // 'vertices' is an array of all of the vertices in all of the
        // exported hair nodes.
        //
        // It contains 'numVertices' entries.
        //
        Vertex* vertices;

        //
        // 'velocities' contains the corresponding velocities for each
        // vertex in the 'vertices' array.
        //
        Vertex* velocities;

        //
        // Texture space coordinates for each vertex.  U and V are taken
        // from the U and V of the growth surface at the point where the
        // hair is rooted.  W ranges from 0.0 at the root of the hair to
        // 1.0 at the tip.
        //
        // 'secondaryUVWs' is not currently used.
        //
        Vertex* uvws;
        Vertex* secondaryUVWs;

        //
        // Surface normals at the root of each hair.  There is one entry
        // per hair.
        //
        // (Added April 16, 2004, version 2.7v4)
        //
        Vertex* surfaceNormals;

        //
        // So let's say that hair number N has 3 vertices.  Then its
        // structure might look something like this:
        //
        //                           hairVertices         vertices
        //                                :                   :
        //                                :                   :
        //                              +--+                +--+
        //                              |  |                |  |
        //                              +--+                +--+
        //                              |  |            --> |  |
        //                              +--+           /    +--+
        //      hairStartIndices[N] --> |  | ----     /     |  |
        //                              +--+     \   /      +--+
        //                              |  | --------       |  |
        //                              +--+       \        +--+
        //                              |  | ---    \       |  |
        //                              +--+    \    \      +--+
        //      hairEndIndices[N] ----> |  |     \    ----> |  |
        //                              +--+      \         +--+
        //                              |  |       -------> |  |
        //                              +--+                +--+
        //                                :                   :
        //
        // The X component of the first vertex of hair N would be:
        //
        //        vertices[hairVertices[hairStartIndices[N]]].x
        //
        // The Z component of the velocity vector of the last vertex of
        // hair N would be:
        //
        //        velocities[hairVertices[hairEndIndices[N]-1]].z
        //
        // Note that per-hair values, such as the various material
        // characteristics, are simply indexed by hair number. So the green
        // component of hair N's tip colour would be:
        //
        //        tipColors[N]
        //
		int* index;
		float *alpha; //was missing
    };


    class LIBSHAVEAPI_API SceneGeom
    {
    public:
        SceneGeom();
        ~SceneGeom();

        void    clear();

        //
        // Number of unique vertices for all polygons in the structure.
        //
        int numVertices;

        //
        // Total number of polygonal faces in the structure.
        //
        int numFaces;

        //
        // Total number of face vertices in the structure.
        //
        // If several faces share a vertex, it will only be counted once in
        // 'numVertices', but will be counted once for each face in
        // 'numFaceVertices'.
        //
        int numFaceVertices;

        //
        // 'faceVertices' is an array of indices into the 'vertices' array
        // and contains one entry for each vertex of each face.
        //
        // The indices for face N start at 'faceStartIndices[N]' and end at
        // 'faceEndIndices[N] - 1'.  <-- NOTE THE -1 !!!
        //
        // 'faceVertices' will have 'numFaceVertices' elements
        // 'faceStartIndices' will have 'numFaces' elements.
        // 'faceEndIndices' will have 'numFaces' elements.
        //
        int *faceVertices;
        int *faceStartIndices;
        int *faceEndIndices;

        //
        // 'vertices' is an array of all of the vertices in all of the
        // geometery contained in the structure.
        //
        // It contains 'numVertices' entries.
        //
        Vertex* vertices;

        //
        // 'velocities' contains the corresponding velocities for each
        // vertex in the 'vertices' array.
        //
        Vertex* velocities;
    };


    //
    // Export all of the hair for all of the shaveNodes in the scene and
    // place the result in 'hairInfo'.
    //
    // If 'renderableOnly' is true then only renderable shaveNodes (e.g.
    // those which are active and whose display nodes are visible, not
    // templated, etc) will be exported.
    //
    // Return Value:
    //      MS::kSuccess            Nodes found and exported.
    //
    //      MS::kNotFound           No shaveNodes found in the scene.
    //
    //      MS::kUnknownParameter   Motion blur is on, but no render camera
    //                              was found, so the hair has been exported
    //                              without blur (all velocities are zero).
    //
    static MStatus  exportAllHair(
                        HairInfo* hairInfo, bool renderableOnly = false
                    );

    //
    // Export all of the hair for all of the shaveNodes specified in the
    // 'shaveNodes' array and place the result in 'hairInfo'.
    //
    // Return Value:
    //      MS::kSuccess            Nodes found and exported.
    //
    //      MS::kNotFound           'shaveNodes' is empty.
    //
    //      MS::kInvalidParameter   'shaveNodes' contains objects which are
    //                              not shaveNodes
    //
    //      MS::kUnknownParameter   Motion blur is on, but no render camera
    //                              was found, so the hair has been exported
    //                              without blur (all velocities are zero).
    //
    static MStatus  exportHair(
                        MObjectArray& shaveNodes, HairInfo* hairInfo
                    );


    //
    // Export any geometry capable of occluding hair and/or hair shadows,
    // based on the 'Occlusion Objects' list in Shave Globals
    // (shaveGlobals.hairOcclusionObjects attribute).
    //
    // If the 'Occlusion Objects' list is set to 'all' then
    // 'hairOcclusions' will return all visible, non-transparent objects in
    // the scene while 'shadowOcclusions' will also contain those objects
    // which have primary visibility off or have transparency.
    //
    // If the 'Occlusion Objects' list in Shave Globals is set to an
    // explicit list of objects then those objects will be exported,
    // regardless of their visibility and transparency.
    //
    // If 'Native Illumination' is turned on in Shave Globals
    // (shaveGlobals.nativeIllumination attribute) then shadows are being
    // handled by the renderer itself and 'hairOccclusions' will be empty.
    //
    // Either parameter may be NULL.
    //
    // Return Value:
    //
    //      MS::kSuccess            Success.
    //
    //      MS::kUnknownParameter   Motion blur is on, but no render camera
    //                              was found, so the geometry has been
    //                              exported without blur (all velocities
    //                              are zero).
    //
    static MStatus  exportOcclusions(
                        SceneGeom* hairOcclusions, SceneGeom* shadowOcclusions
                    );


    //********************************************************************
    //
    //        OBSOLETE METHODS
    //
    //********************************************************************

    // Use shaveAPI::HairInfo::clear() instead
    static void     freeHairInfo(HairInfo* hairInfo);

    // HairInfo objects automatically initialize themselves now.
    static void     initHairInfo(HairInfo* hairInfo);
};

#endif