[Bf-blender-cvs] [b95794d] hair_system: Added a basic volume data structure for hair simulation.
Lukas Tönne
noreply at git.blender.org
Sun Aug 24 18:54:59 CEST 2014
Commit: b95794d3c5e76b5b7044183c6c536febe8cd3c23
Author: Lukas Tönne
Date: Sun Aug 24 13:34:50 2014 +0200
Branches: hair_system
https://developer.blender.org/rBb95794d3c5e76b5b7044183c6c536febe8cd3c23
Added a basic volume data structure for hair simulation.
Using volumetric description of certain hair simulation quantities
allows very efficient calculation of otherwise costly effects, such as
hair-hair collisions (at the price of reduced accuracy).
===================================================================
M source/blender/hair/CMakeLists.txt
A source/blender/hair/intern/HAIR_volume.cpp
A source/blender/hair/intern/HAIR_volume.h
===================================================================
diff --git a/source/blender/hair/CMakeLists.txt b/source/blender/hair/CMakeLists.txt
index 121c860..cc3784f 100644
--- a/source/blender/hair/CMakeLists.txt
+++ b/source/blender/hair/CMakeLists.txt
@@ -57,6 +57,8 @@ set(SRC
intern/HAIR_collision.cpp
intern/HAIR_types.h
intern/HAIR_types.cpp
+ intern/HAIR_volume.h
+ intern/HAIR_volume.cpp
intern/HAIR_util_hash.h
)
diff --git a/source/blender/hair/intern/HAIR_volume.cpp b/source/blender/hair/intern/HAIR_volume.cpp
new file mode 100644
index 0000000..dcf8974
--- /dev/null
+++ b/source/blender/hair/intern/HAIR_volume.cpp
@@ -0,0 +1,42 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation,
+ * Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "HAIR_volume.h"
+
+HAIR_NAMESPACE_BEGIN
+
+Volume::Volume()
+{
+}
+
+void Volume::resize(int x, int y, int z)
+{
+ int totsize = x * y * z;
+
+ randomstuff.resize(totsize);
+}
+
+HAIR_NAMESPACE_END
diff --git a/source/blender/hair/intern/HAIR_volume.h b/source/blender/hair/intern/HAIR_volume.h
new file mode 100644
index 0000000..ec3fd71
--- /dev/null
+++ b/source/blender/hair/intern/HAIR_volume.h
@@ -0,0 +1,102 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation,
+ * Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __HAIR_VOLUME_H__
+#define __HAIR_VOLUME_H__
+
+#include <vector>
+
+#include "MEM_guardedalloc.h"
+
+#include "HAIR_types.h"
+
+HAIR_NAMESPACE_BEGIN
+
+template <typename T>
+struct VolumeAttribute {
+ VolumeAttribute()
+ {
+ m_data = NULL;
+ m_size = 0;
+ }
+
+ VolumeAttribute(int size)
+ {
+ alloc(size);
+ }
+
+ ~VolumeAttribute()
+ {
+ free();
+ }
+
+ T *data() { return m_data; }
+ const T *data() const { return m_data; }
+
+ int size() const { return m_size; }
+
+ void resize(int size)
+ {
+ free();
+ alloc(size);
+ }
+
+protected:
+ void alloc(int size)
+ {
+ m_data = (T*)MEM_mallocN(sizeof(T) * size, "Hair Volume Attribute");
+ m_size = size;
+ }
+
+ void free()
+ {
+ if (m_data)
+ MEM_freeN(m_data);
+ }
+
+private:
+ T *m_data;
+ int m_size;
+};
+
+typedef VolumeAttribute<float> VolumeAttributeFloat;
+typedef VolumeAttribute<int> VolumeAttributeInt;
+typedef VolumeAttribute<float3> VolumeAttributeFloat3;
+
+struct Volume {
+ Volume();
+
+ void resize(int x, int y, int z);
+
+ VolumeAttributeFloat randomstuff;
+
+private:
+ int size_x, size_y, size_z;
+};
+
+HAIR_NAMESPACE_END
+
+#endif
More information about the Bf-blender-cvs
mailing list