diff options
| author | Ben Marsh <[email protected]> | 2019-10-22 09:07:59 -0400 |
|---|---|---|
| committer | Ben Marsh <[email protected]> | 2019-10-22 09:07:59 -0400 |
| commit | bd0027e737c6512397f841c22786274ed74b927f (patch) | |
| tree | f7ffbdb8f3741bb7f24635616cc189cba5cb865c /vrayPlug/plugin/shaveVrayInstanceBase.cpp | |
| download | archived-shave-and-a-haircut-bd0027e737c6512397f841c22786274ed74b927f.tar.xz archived-shave-and-a-haircut-bd0027e737c6512397f841c22786274ed74b927f.zip | |
Adding Shave-and-a-Haircut 9.6
Diffstat (limited to 'vrayPlug/plugin/shaveVrayInstanceBase.cpp')
| -rw-r--r-- | vrayPlug/plugin/shaveVrayInstanceBase.cpp | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/vrayPlug/plugin/shaveVrayInstanceBase.cpp b/vrayPlug/plugin/shaveVrayInstanceBase.cpp new file mode 100644 index 0000000..9678b13 --- /dev/null +++ b/vrayPlug/plugin/shaveVrayInstanceBase.cpp @@ -0,0 +1,153 @@ +// Shave and a Haircut +// (c) 2019 Epic Games +// US Patent 6720962 + +/********************************************************************** + *< + FILE: shaveVrayInstanceBase.cpp + + DESCRIPTION: VRay base class for regular and insted hair VRay instance classes + + CREATED BY: Vladimir Dubovoy <[email protected]> + + HISTORY: created 12-05-2010 + + *> + **********************************************************************/ + +#include "shaveVrayInstanceBase.h" + +//IHairStack* shaveVrayInstanceBase::stack = NULL; + +IHairStack* stack = NULL; + +void shaveVrayInstanceBase::loadHair() +{ + if(!stack) + { + //we can not do it in standalone case + //shaveVrayIntListParam* dataParam = plugin->GetDataParam(); + //shaveVrayIntParam* dataSizeParam = plugin->GetDataSizeParam(); + + bool dra_as_param = false; + bool dra_as_file = false; + VR::VRayPluginParameter *dataParam=plugin->paramList->getParam("draData"); + VR::VRayPluginParameter *dataSizeParam=plugin->paramList->getParam("draSize"); + if(dataSizeParam && dataParam /*&& dataParam->getCount(0) > 0*/) + { + LOGMSG("SHAVE", "shaveVrayInstance: importing DRA from memory"); + + VR::IntList L = dataParam->getIntList(0); + + //int N = dataParam->getCount(0); + int N = L.count(); + int size = dataSizeParam->getInt(0,0); + if(N > 0 && size > 0) + { + dra_as_param = true; + + + LOGMSGI("SHAVE", "shaveVrayInstance: DRA data size ", size); + LOGMSGI("SHAVE", "shaveVrayInstance: DRA intlist count ", N); + + int extra = 0; + int n = size/sizeof(int); + if(size > n*sizeof(int)) + { + extra = size - n*sizeof(int); + } + LOGMSGI("SHAVE", "shaveVrayInstance: (debug) exta bytes ", extra); + + char* data = (char*)malloc(size); + int* idata = (int*)data; + int chpos = 0; + long intsum = 0; + for(int oo = 0; oo < N; oo++) + { + if(oo < n) + { + //int v = dataParam->getInt(oo,0.0); + int v = L[oo]; + idata[oo] = v; + chpos += sizeof(int); + + intsum += v; + } + else + { + //int A = dataParam->getInt(oo,0.0); + int A = L[oo]; + char* AA = (char*)(&A); + for(int j = 0; j < extra; j++) + { + data[chpos+j] = AA[j]; + } + + intsum += A; + } + } + ///// checksum // + int sum = 0; + for(int oo = 0; oo < size; oo++) + { + sum += (unsigned char)data[oo]; + } + LOGMSGI("SHAVE", "shaveVrayInstance: (debug) checksum ", (int)sum); + LOGMSGI("SHAVE", "shaveVrayInstance: (debug) intsum ", (int)intsum); + + stack = LoadHair((void*)data,(long)size); + } + + } + + if(!dra_as_param && !shaveVrayPlugin::draFile.empty()) + { + dra_as_file = true; + LOGMSG("SHAVE", "shaveVrayInstance: importing DRA from file."); + stack = LoadHair((char*)shaveVrayPlugin::draFile.ptr()); + } + + if(!dra_as_param && !dra_as_file) + { + LOGMSG("SHAVE", "shaveVrayInstance: no DRA source specified."); + } + } + if(!hair() && stack) + { + if(stack) + { + try + { + _hair() = stack->GetHairNodeByID(stackid(),GetSquirrel()); + } + catch(...) + { + LOGMSG("SHAVE", "shaveVrayInstance: an exception occured when accessing DRA."); + } + if(!hair()) + LOGMSGI("SHAVE", "shaveVrayInstance: can not create Hair node (id)",stackid()); + } + else + LOGMSG("SHAVE", "shaveVrayInstance::compileGeometry NULL stack."); + } +} + +void shaveVrayInstanceBase::freeMem() +{ + //free primitieves here + for(unsigned int i = 0; i < (unsigned int)voxprims().size(); i++) + if(voxprim(i)) + { + delete voxprim(i); + _voxprim(i) = NULL; + } + _voxprims().clear(); + + + if(stack) + { + delete stack; + stack = NULL; + } +} + |