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
332
333
|
// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962
/**********************************************************************
*<
FILE: hairAPIImp.h
DESCRIPTION: Implementation of C++ Intefraces for SHAVE2 functions
CREATED BY: Vladimir Dubovoy <[email protected]>
HISTORY: created 20-08-2008
*>
**********************************************************************/
#ifndef _SHAVE2_API_IMPLEMENTATION_H_
#define _SHAVE2_API_IMPLEMENTATION_H_
#include "hairAPIvrayutil.h"
#include <vector>
#ifdef _WIN32
#include <windows.h>
#include <process.h>
#else
#include <pthread.h>
#endif
#ifndef FLT_MAX
#define FLT_MAX 3.402823466e+38F
#endif
#define USE_MEMFILE
extern "C"
{
void SHAVEprint_engine2(void);
}
class HairStack;
class HairVoxel : public IHairVoxel {
public:
HAIRAPI HairVoxel();
HAIRAPI HairVoxel(HairStack* hstack,
const VERT& pmin, const VERT& pmai,
int ix, int iy, int iz,
bool squirrel);
HAIRAPI HairVoxel(HairStack* hstack,
const VERT& pmin, const VERT& pmai,
int stack_id, int ix, int iy, int iz,
bool squirrel);
HAIRAPI ~HairVoxel();
/*
| from IHairVoxel
*/
HAIRAPI bool HasHair() const;
HAIRAPI bool IsNodeVoxel() const;
HAIRAPI int GetNodeID(void) const;
HAIRAPI bool GetBbox(VERT& pmin, VERT& pmax) const;
HAIRAPI const HairType& GetHair(/*bool isShadow = false*/);
HAIRAPI const HairUVs& GetUVs (/*bool isShadow = false*/);
/////////////////////////////////////////////////////////////////////////
// These methods retrive data from voxel's HairType
////////////////////////////////////////////////////////////////////////
int GetNumVerts () const;
int GetNumStrands() const;
int GetNumFaces() const;
void GetVert (int vertidx, float& x, float& y, float& z) const;
void GetVelocity(int vertidx, float& x, float& y, float& z) const;
void GetStrand (int strandidx, int& v_start, int& v_end) const;
void GetFace (int faceidx, int& v_start, int& v_end) const;
bool IsColorConst (int strandidx) const;
void GetRootColor (int strandidx, float& r, float& g, float& b) const;
void GetTipColor (int strandidx, float& r, float& g, float& b) const;
void GetVertColor (int strandidx, int knot_idx, float& r, float& g, float& b) const;
void GetColor (int strandidx, float t, float& r, float& g, float& b) const;
void GetSurfNormal(int strandidx, float& x, float& y, float& z) const;
float GetStrandGlossiness(int strandidx) const;
float GetStrandSpecLevel(int strandidx) const;
float GetStrandOpacity(int strandidx) const;
float GetStrandAmbDiff(int strandidx) const;
protected:
//const memeber access
inline const HairType& hairtype() const {return m_hairtype;}
inline const HairUVs& hairuvs() const {return m_hairuvs;}
inline HairStack* stack() const {return m_stack;}
inline const VERT& bboxMin() const {return m_bboxMin;}
inline const VERT& bboxMax() const {return m_bboxMax;}
inline bool hashair() const {return m_hashair;}
inline bool nodevoxel() const {return m_nodevoxel;}
inline int nodeindex() const {return m_nodeindex;}
inline bool squirrel() const {return m_squirrel;}
//member access
inline HairType& _hairtype(){return m_hairtype;}
inline HairUVs& _hairuvs(){return m_hairuvs;}
inline HairStack*& _stack() {return m_stack;}
inline VERT& _bboxMin() {return m_bboxMin;}
inline VERT& _bboxMax() {return m_bboxMax;}
inline bool& _hashair() {return m_hashair;}
inline bool& _nodevoxel() {return m_nodevoxel;}
inline int& _nodeindex() {return m_nodeindex;}
inline bool& _squirrel() {return m_squirrel;}
private:
bool m_hashair;
bool m_nodevoxel;
int m_nodeindex;
HairType m_hairtype;
HairUVs m_hairuvs;
VERT m_bboxMin;
VERT m_bboxMax;
HairStack* m_stack;
bool m_squirrel;
};
#ifndef _VOXEL_VECTOR_TYPE_
#define _VOXEL_VECTOR_TYPE_
typedef std::vector<HairVoxel*> HVoxels;
#endif
#ifndef _INT_VECTOR_TYPE_
#define _INT_VECTOR_TYPE_
typedef std::vector<int> intvector;
#endif
class HairNode : public IHairNode {
public:
HAIRAPI HairNode(HairStack* hstack, int stack_id, bool squirrel);
HAIRAPI ~HairNode();
/*
| from IHairNode
*/
HAIRAPI bool GetBbox(VERT& pmin, VERT& pmax) const;
HAIRAPI int GetStackID() const;
HAIRAPI int GetNumVoxels()const;
HAIRAPI IHairVoxel* GetVoxel(int i) const;
/////////////////////////////////////////////////////////////////////////
// These methods retrieve data from node's voxels
////////////////////////////////////////////////////////////////////////
int GetNumVerts () const;
int GetNumStrands() const;
int GetNumFaces() const;
void GetVert (int vertidx, float& x, float& y, float& z) const;
void GetVelocity(int vertidx, float& x, float& y, float& z) const;
void GetStrand (int strandidx, int& v_start, int& v_end) const;
void GetFace (int faceidx, int& v_start, int& v_end) const;
bool IsColorConst (int strandidx) const;
void GetRootColor (int strandidx, float& r, float& g, float& b) const;
void GetTipColor (int strandidx, float& r, float& g, float& b) const;
void GetVertColor (int strandidx, int knot_idx, float& r, float& g, float& b) const;
void GetColor (int strandidx, float t, float& r, float& g, float& b) const;
void GetSurfNormal(int strandidx, float& x, float& y, float& z) const;
float GetStrandGlossiness(int strandidx) const;
float GetStrandSpecLevel(int strandidx) const;
float GetStrandOpacity(int strandidx) const;
float GetStrandAmbDiff(int strandidx) const;
protected:
inline bool vertIndexToVoxVertIndex(int i, int& vox, int& vox_vert) const
{
if(i < (int)vtovoxs().size())
{
vox = vtovox(i);
vox_vert = vtovoxV(i);
return true;
}
return false;
}
inline bool strandIndexToVoxStrandIndex(int i, int& vox, int& vox_strand) const
{
if(i < (int)stovoxs().size())
{
vox = stovox(i);
vox_strand = stovoxS(i);
return true;
}
return false;
}
//const member access
inline int stackid() const {return m_stackid;}
inline const HVoxels& voxels() const {return m_voxels;}
inline HairVoxel* voxel(int i) const {return m_voxels[i];}
inline HairStack* stack() const {return m_stack;}
inline const VERT& bboxMin() const {return m_bboxMin;}
inline const VERT& bboxMax() const {return m_bboxMax;}
inline const intvector& vtovoxs() const {return m_vtovoxs;}
inline int vtovox(int i) const {return m_vtovoxs[i];}
inline const intvector& vtovoxVs() const {return m_vtovoxVs;}
inline int vtovoxV(int i)const {return m_vtovoxVs[i];}
inline const intvector& stovoxs() const {return m_stovoxs;}
inline int stovox(int i) const {return m_stovoxs[i];}
inline const intvector& stovoxSs() const {return m_stovoxSs;}
inline int stovoxS(int i)const {return m_stovoxSs[i];}
inline bool squirrel() const {return m_squirrel;}
//member access
inline int& _stackid() {return m_stackid;}
inline HVoxels& _voxels() {return m_voxels;}
inline HairVoxel*& _voxel(int i) {return m_voxels[i];}
inline HairStack*& _stack() {return m_stack;}
inline VERT& _bboxMin() {return m_bboxMin;}
inline VERT& _bboxMax() {return m_bboxMax;}
inline intvector& _vtovoxs() {return m_vtovoxs;}
inline int& _vtovox(int i) {return m_vtovoxs[i];}
inline intvector& _vtovoxVs() {return m_vtovoxVs;}
inline int& _vtovoxV(int i){return m_vtovoxVs[i];}
inline intvector& _stovoxs() {return m_stovoxs;}
inline int& _stovox(int i) {return m_stovoxs[i];}
inline intvector& _stovoxSs() {return m_stovoxSs;}
inline int& _stovoxV(int i){return m_stovoxSs[i];}
inline bool& _squirrel() {return m_squirrel;}
private:
int m_stackid;
HVoxels m_voxels;
HairStack* m_stack;
VERT m_bboxMin;
VERT m_bboxMax;
intvector m_vtovoxs; //maps vert index to voxel index
intvector m_vtovoxVs; //maps vert index to vert index of voxel
intvector m_stovoxs; //maps strand index to voxel index
intvector m_stovoxSs; //maps strand index to strand index of voxel
bool m_squirrel;
};
#ifndef _NODE_VECTOR_TYPE_
#define _NODE_VECTOR_TYPE_
typedef std::vector<HairNode*> HNodes;
#endif
class HairStack : public IHairStack {
public:
HAIRAPI HairStack(void* bdata, long size, bool needxyswap);
HAIRAPI HairStack(char* fname, bool needxyswap);
HAIRAPI ~HairStack();
/*
| from IHairStack
*/
HAIRAPI bool Init(void* bdata, long size);
HAIRAPI bool Init(char* fname);
HAIRAPI void Clear();
HAIRAPI char* GetDRAname() const;
HAIRAPI int GetNumVoxels() const;
HAIRAPI int GetVoxelRes() const;
HAIRAPI IHairVoxel* GetHairVoxel(int vox_x, int vox_y, int vox_z);
HAIRAPI IHairVoxel* GetHairVoxel(int vox_index);
HAIRAPI IHairNode* GetHairNodeByID (int stack_id, bool squirrel = false);
HAIRAPI bool GetNeedYZswap() const {return needyzswap();}
#ifdef USE_MEMFILE
MEMFILE* GetMemFile() { return &_mem();}
#endif
void Lock();
void UnLock();
protected:
#ifdef WIN32
CRITICAL_SECTION csect;
#else
pthread_mutex_t mutex;
#endif
inline bool voxelXYZformIDX(int index, int& x, int& y, int& z);
inline bool voxelIDXformXYZ(int& index, int x, int y, int z);
//const member access
inline char* draname() const {return m_draname;}
inline const HNodes& nodes() const {return m_nodes;}
inline HairNode* node(int i) const {return m_nodes[i];}
inline const HVoxels& voxels() const {return m_voxels;}
inline HairVoxel* voxel(int i)const {return m_voxels[i];}
inline int voxres() const {return m_voxres;}
inline bool needyzswap()const {return m_needyzswap;}
#ifdef USE_MEMFILE
inline const MEMFILE& mem() const {return m_mem;}
#endif
//member access
inline char*& _draname() {return m_draname;}
inline HNodes& _nodes() {return m_nodes;}
inline HairNode*& _node(int i) {return m_nodes[i];}
inline HVoxels& _voxels() {return m_voxels;}
inline HairVoxel*& _voxel(int i){return m_voxels[i];}
inline int& _voxres() {return m_voxres;}
inline bool& _needyzswap(){return m_needyzswap;}
#ifdef USE_MEMFILE
inline MEMFILE& _mem() {return m_mem;}
#endif
private:
char* m_draname;
HNodes m_nodes;
HVoxels m_voxels;
int m_voxres;
bool m_needyzswap;
#ifdef USE_MEMFILE
MEMFILE m_mem;
#endif
};
#endif //end of _SHAVE2_API_IMPLEMENTATION_H_
|