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
|
#ifndef _HAIR_VRAY_PARAMS_H_
#define _HAIR_VRAY_PARAMS_H_
// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962
/**********************************************************************
*<
FILE: shaveVrayParams.h
DESCRIPTION: Vray plugin parameters
HISTORY: created 29-03-2010
*>
**********************************************************************/
#include "vrayplugins.h"
#include "defparams.h"
#ifndef VRAY_OVERRIDE // not defined in earlier sdk versions
#define VRAY_OVERRIDE
#endif
struct shaveNamedParamBase : VR::VRayPluginParameter {
shaveNamedParamBase(const tchar* paramName) : name(paramName) {}
// from VRayPluginParameter
const tchar* getName() VRAY_OVERRIDE {
return name;
}
private:
const tchar* name;
};
//we need own params to avoid linking maya shave plugin with vray libs.
//fix linux SDK/Runtime param descrutor collision
struct shaveVrayIntParam:
shaveNamedParamBase,
VR::VRaySettableParamInterface,
VR::TextureIntInterface
{
shaveVrayIntParam(const tchar *paramName, int value): shaveNamedParamBase(paramName), i(value) {}
PluginBase* getPlugin(void) { return static_cast<PluginBase*>(this); }
int getInt(int index, double time) { return i; }
int getBool(int index, double time) { return i!=0; }
float getFloat(int index, double time) { return (float) i; }
PluginBase* getObject(int index, double time, const tchar **subparam=NULL) { return static_cast<PluginBase*>(this); }
PluginInterface* newInterface(InterfaceID id) {
if (id==EXT_TEXTURE_INT) return static_cast<TextureIntInterface*>(this);
if (id==EXT_SETTABLE_PARAM) return static_cast<VRaySettableParamInterface*>(this);
return VRayPluginParameter::newInterface(id);
}
void setInt(int value, int index, double time) { i=value; }
void setBool(int value, int index, double time) { i=value; }
VR::VRayParameterType getType(int index, double time) { return VR::paramtype_int; }
int getTexInt(const VR::VRayContext &rc) { return i; }
protected:
int i;
};
struct shaveVrayFloatParam:
shaveNamedParamBase,
VR::VRaySettableParamInterface,
#ifdef VRAY30
VR::TextureFloatInterface
#else
VR::TextureIntInterface
#endif
{
shaveVrayFloatParam(const tchar *paramName, float fval): shaveNamedParamBase(paramName), f(fval) {}
PluginBase* getPlugin(void) { return static_cast<PluginBase*>(this); }
int getInt(int index, double time) { return (int)f; }
int getBool(int index, double time) { return fabsf(f)<1e-12f? false: true; }
float getFloat(int index, double time) { return f; }
double getDouble(int index, double time) { return (double)f; }
PluginBase* getObject(int index, double time, const tchar **subparam=NULL) { return static_cast<PluginBase*>(this); }
PluginInterface* newInterface(InterfaceID id) {
#ifdef VRAY30
if (id==EXT_TEXTURE_FLOAT) return static_cast<TextureFloatInterface*>(this);
#else
if (id==EXT_TEXTURE_INT) return static_cast<TextureIntInterface*>(this);
#endif
if (id==EXT_SETTABLE_PARAM) return static_cast<VRaySettableParamInterface*>(this);
return VRayPluginParameter::newInterface(id);
}
void setInt(int value, int index, double time) { f=(float)value; }
void setBool(int value, int index, double time) { f=(float)value; }
void setFloat(float value, int index, double time) { f=value; }
void setDouble(double value, int index, double time) { f=(float)value; }
VR::VRayParameterType getType(int index, double time) { return VR::paramtype_float; }
#ifdef VRAY30
VR::real getTexFloat(const VR::VRayContext &rc) { return f; }
void getTexFloatBounds(VR::real &fmin, VR::real &fmax) {}
#else
float getTexFloat(const VR::VRayContext &rc) { return f; }
void getTexFloatBounds(float &fmin, float &fmax) { fmin=fmax=f; }
#endif
int getTexInt(const VR::VRayContext &rc) { return (int)f; }
protected:
float f;
};
struct shaveVrayColorParam:
shaveNamedParamBase,
VR::VRaySettableParamInterface,
VR::TextureInterface
{
shaveVrayColorParam(const tchar *paramName, float R, float G, float B): shaveNamedParamBase(paramName), r(R), g(G), b(B) {}
PluginBase* getPlugin(void) { return static_cast<PluginBase*>(this); }
virtual VR::Color getColor(int index, double time) { return VR::Color(r,g,b); }
virtual VR::AColor getAColor(int index, double time) { return VR::AColor(r,g,b,1.0f); }
PluginBase* getObject(int index, double time, const tchar **subparam=NULL) { return static_cast<PluginBase*>(this); }
PluginInterface* newInterface(InterfaceID id) {
if (id==EXT_TEXTURE) return static_cast<TextureInterface*>(this);
if (id==EXT_SETTABLE_PARAM) return static_cast<VRaySettableParamInterface*>(this);
return VRayPluginParameter::newInterface(id);
}
virtual void setColor(const VR::Color &value, int index, double time) { r = value.r; g = value.g; b = value.b; }
virtual void setColor(float R, float G, float B /*, int index, double time*/) { r = R; g = G; b = B; }
virtual void setAColor(const VR::AColor &value, int index, double time) { r = value.color.r; g = value.color.g; b = value.color.b; }
virtual VR::VRayParameterType getType(int index, double time) { return VR::paramtype_color; }
VR::AColor getTexColor(const VR::VRayContext &rc) { return VR::AColor(r,g,b,1.0f); }
void getTexColorBounds(VR::AColor &cmin, VR::AColor &cmax) { cmin=cmax=VR::AColor(r,g,b,1.0f); }
VR::Vector getColorBumpGradient(const VR::VRayContext &rc) { return VR::Vector(0.0f, 0.0f, 0.0f); }
protected:
float r;
float g;
float b;
};
struct shaveVrayStringParam:
shaveNamedParamBase,
VR::VRaySettableParamInterface
{
shaveVrayStringParam(const tchar *paramName, const tchar *value): shaveNamedParamBase(paramName) { copyToBuf(value); }
PluginBase* getPlugin(void) { return static_cast<PluginBase*>(this); }
~shaveVrayStringParam(void) { deleteBuf(); }
tchar *getString(int index, double time) { return buf; }
PluginInterface* newInterface(InterfaceID id) { return (id==EXT_SETTABLE_PARAM)? (VRaySettableParamInterface*) this : VRayPluginParameter::newInterface(id); }
void setString(const tchar *value, int index, double time) {deleteBuf(); copyToBuf(value);}
VR::VRayParameterType getType(int index, double time) { return VR::paramtype_string; }
protected:
tchar *buf;
void deleteBuf() {
if (buf) delete[] buf;
buf=NULL;
}
void copyToBuf(const tchar *str) {
size_t len=strlen(str);
buf=new tchar[len+1];
if (buf) vutils_memcpy(buf, str, (len+1)*sizeof(buf[0]));
}
};
/// A template class from which simple non-animated list parameters are derived.
template<typename T>
struct shaveVrayListParamBaseTyped: VR::DefListParamBase
{
shaveVrayListParamBaseTyped(const tchar *paramName): DefListParamBase(paramName) {}
/// Add a new element to the end of the list.
void operator+=(const T &i) { values+=i; }
/// Set the number of elements in the list.
void setCount(int n) { values.setCount(n, true); }
/// Return the i-th element in the list.
T& operator[](int i) { return values[i]; }
/// Reserve space for count elements, but set the actual count to zero.
void reserve(int count) { values.setCount(count, true); values.clear(); }
int getCount(double time) { return listLevel==0? values.count() : -1; }
protected:
VR::Table<T> values;
};
// non-animated integer list parameter.
struct shaveVrayIntListParam: shaveVrayListParamBaseTyped<int> {
/// Constructor.
/// @param paramName The name of the parameter. The object can copy the string or it can just store the pointer(in which case the pointer must be valid for the life time of the object).
shaveVrayIntListParam(const tchar *paramName, int ownName = 0): shaveVrayListParamBaseTyped<int>(paramName/*, ownName*/) {}
// shaveVrayIntListParam(const shaveVrayIntListParam & other): shaveVrayListParamBaseTyped<int>(other) { }
PluginBase* getPlugin(void) { return static_cast<PluginBase*>(this); }
// From VRayPluginParameter
virtual int getInt(int index, double time) { return values[index]; }
//virtual int getBool(int index, double time) { return values[index] != 0; }
//virtual float getFloat(int index, double time) { return (float)values[index]; }
//virtual double getDouble(int index, double time) { return (double) values[index]; }
virtual VR::IntList getIntList(double time) { return VR::IntList(&values[0], values.count()); }
virtual VR::VRayParameterType getType(int index, double time) { return VR::paramtype_int; }
// From VRaySettableParamInterface
virtual void setInt(int value, int index, double time)
{
if(index >= 0 && index < values.count()) values[index] = value;
else values += value;
}
//virtual void setBool(int value, int index, double time) { setInt(value, index, time); }
//virtual void setFloat(float value, int index, double time) { setInt((int)value, index, time); }
//virtual void setDouble(double value, int index, double time) { setInt((int)value, index, time); }
// From VRayCloneableParamInterface
//virtual VR::VRayPluginParameter * clone() { return new shaveVrayIntListParam(*this); }
protected:
};
/// A simple non-animated Vector list parameter.
struct shaveVrayVectorListParam: shaveVrayListParamBaseTyped<VR::Vector> {
/// Constructor.
/// @param paramName The name of the parameter. Note that the object just stores the pointer and so must be valid for the life time of the object.
shaveVrayVectorListParam(const tchar *paramName): shaveVrayListParamBaseTyped<VR::Vector>(paramName) {}
PluginBase* getPlugin(void) { return static_cast<PluginBase*>(this); }
VR::Vector getVector(int index, double time) { return values[index]; }
VR::VectorList getVectorList(double time) { return VR::VectorList(&values[0], values.count()); }
VR::VRayParameterType getType(int index, double time) { return VR::paramtype_vector; }
};
#endif //end of_HAIR_VRAY_PARAMS_H_
|