aboutsummaryrefslogtreecommitdiff
path: root/vrayPlug/plugin/hairAPIimp.h
diff options
context:
space:
mode:
authorBen Marsh <[email protected]>2019-10-22 09:07:59 -0400
committerBen Marsh <[email protected]>2019-10-22 09:07:59 -0400
commitbd0027e737c6512397f841c22786274ed74b927f (patch)
treef7ffbdb8f3741bb7f24635616cc189cba5cb865c /vrayPlug/plugin/hairAPIimp.h
downloadshave-and-a-haircut-bd0027e737c6512397f841c22786274ed74b927f.tar.xz
shave-and-a-haircut-bd0027e737c6512397f841c22786274ed74b927f.zip
Adding Shave-and-a-Haircut 9.6
Diffstat (limited to 'vrayPlug/plugin/hairAPIimp.h')
-rw-r--r--vrayPlug/plugin/hairAPIimp.h333
1 files changed, 333 insertions, 0 deletions
diff --git a/vrayPlug/plugin/hairAPIimp.h b/vrayPlug/plugin/hairAPIimp.h
new file mode 100644
index 0000000..974673f
--- /dev/null
+++ b/vrayPlug/plugin/hairAPIimp.h
@@ -0,0 +1,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_
+