aboutsummaryrefslogtreecommitdiff
path: root/mayaPlug/ShavePerVertTexInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mayaPlug/ShavePerVertTexInfo.cpp')
-rw-r--r--mayaPlug/ShavePerVertTexInfo.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/mayaPlug/ShavePerVertTexInfo.cpp b/mayaPlug/ShavePerVertTexInfo.cpp
new file mode 100644
index 0000000..0d56838
--- /dev/null
+++ b/mayaPlug/ShavePerVertTexInfo.cpp
@@ -0,0 +1,80 @@
+// Shave and a Haircut
+// (c) 2019 Epic Games
+// US Patent 6720962
+
+#include "ShavePerVertTexInfo.h"
+#include "shaveTextureStore.h"
+
+
+const int ShavePerVertTexInfo::mVertParams[] = { 8, 21, 40 };
+const unsigned int ShavePerVertTexInfo::mNumVertParams = sizeof(mVertParams) / sizeof(int);
+
+
+ShavePerVertTexInfo::ShavePerVertTexInfo()
+: mNumVertices(0)
+, mTextureValues(0)
+{
+}
+
+
+ShavePerVertTexInfo::~ShavePerVertTexInfo()
+{
+ clear(true);
+}
+
+
+void ShavePerVertTexInfo::clear(bool all)
+{
+ // If we have any existing texture data, delete it.
+ if (mTextureValues)
+ {
+ for (unsigned int param = 0; param < mNumVertParams; ++param)
+ {
+ if (mTextureValues[param])
+ {
+ delete [] mTextureValues[param];
+ mTextureValues[param] = 0;
+ }
+ }
+
+ if (all)
+ {
+ delete [] mTextureValues;
+ mTextureValues = 0;
+ }
+ }
+
+ mNumVertices = 0;
+}
+
+
+void ShavePerVertTexInfo::init(unsigned int numVertices)
+{
+ clear(false);
+ mNumVertices = numVertices;
+}
+
+
+bool ShavePerVertTexInfo::setValue(
+ unsigned int paramIdx,
+ unsigned int vertIdx,
+ float value
+)
+{
+ if ((paramIdx >= mNumVertParams) || (vertIdx > mNumVertices)) return false;
+
+ if (mTextureValues == 0)
+ {
+ mTextureValues = new float*[mNumVertParams];
+
+ for (unsigned int i = 0; i < mNumVertParams; ++i)
+ mTextureValues[i] = 0;
+ }
+
+ if (mTextureValues[paramIdx] == 0)
+ mTextureValues[paramIdx] = new float[mNumVertices];
+
+ mTextureValues[paramIdx][vertIdx] = value;
+
+ return true;
+}