#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(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(this); } PluginInterface* newInterface(InterfaceID id) { if (id==EXT_TEXTURE_INT) return static_cast(this); if (id==EXT_SETTABLE_PARAM) return static_cast(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(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(this); } PluginInterface* newInterface(InterfaceID id) { #ifdef VRAY30 if (id==EXT_TEXTURE_FLOAT) return static_cast(this); #else if (id==EXT_TEXTURE_INT) return static_cast(this); #endif if (id==EXT_SETTABLE_PARAM) return static_cast(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(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(this); } PluginInterface* newInterface(InterfaceID id) { if (id==EXT_TEXTURE) return static_cast(this); if (id==EXT_SETTABLE_PARAM) return static_cast(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(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 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 values; }; // non-animated integer list parameter. struct shaveVrayIntListParam: shaveVrayListParamBaseTyped { /// 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(paramName/*, ownName*/) {} // shaveVrayIntListParam(const shaveVrayIntListParam & other): shaveVrayListParamBaseTyped(other) { } PluginBase* getPlugin(void) { return static_cast(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 { /// 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(paramName) {} PluginBase* getPlugin(void) { return static_cast(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_