[Bf-blender-cvs] [3f77506] hair_system: Smoothing function as a first feature in dedicated hair code.

Lukas Tönne noreply at git.blender.org
Sun Jul 27 11:23:13 CEST 2014


Commit: 3f775066fccb5d84a82fd6b389797693afb446bb
Author: Lukas Tönne
Date:   Sat Jul 26 20:47:35 2014 +0200
Branches: hair_system
https://developer.blender.org/rB3f775066fccb5d84a82fd6b389797693afb446bb

Smoothing function as a first feature in dedicated hair code.

This function is used in a number of places in the targeted algorithms.
It is a useful utility for parallel-transport of various properties
along a hair curve. With curled hair in particular the control curve
itself is otherwise too irregular to give usable results, for which the
smoothing offers an elegant solution.

The algorithm is described in detail in the paper "Artistic simulation
of curly hair":
http://graphics.pixar.com/library/CurlyHairA/paper.pdf

===================================================================

M	build_files/cmake/macros.cmake
M	source/blender/CMakeLists.txt
M	source/blender/editors/space_view3d/CMakeLists.txt
M	source/blender/editors/space_view3d/drawhair.c
A	source/blender/hair/CMakeLists.txt
A	source/blender/hair/HAIR_capi.cpp
A	source/blender/hair/HAIR_capi.h
A	source/blender/hair/intern/HAIR_curve.cpp
A	source/blender/hair/intern/HAIR_curve.h
A	source/blender/hair/intern/HAIR_smoothing.cpp
A	source/blender/hair/intern/HAIR_smoothing.h
A	source/blender/hair/intern/HAIR_types.h

===================================================================

diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 8890c13..8410bf3 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -490,6 +490,7 @@ macro(SETUP_BLENDER_SORTED_LIBS)
 		bf_freestyle
 		bf_ikplugin
 		bf_modifiers
+		bf_hair
 		bf_bmesh
 		bf_blenkernel
 		bf_nodes
diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index ac93961..cdbadc1 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -107,6 +107,7 @@ add_subdirectory(gpu)
 add_subdirectory(imbuf)
 add_subdirectory(nodes)
 add_subdirectory(modifiers)
+add_subdirectory(hair)
 add_subdirectory(makesdna)
 add_subdirectory(makesrna)
 
diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt
index 5856060..f401d78 100644
--- a/source/blender/editors/space_view3d/CMakeLists.txt
+++ b/source/blender/editors/space_view3d/CMakeLists.txt
@@ -25,6 +25,7 @@ set(INC
 	../../blenlib
 	../../bmesh
 	../../gpu
+	../../hair
 	../../imbuf
 	../../makesdna
 	../../makesrna
diff --git a/source/blender/editors/space_view3d/drawhair.c b/source/blender/editors/space_view3d/drawhair.c
index 3e746ff..302fa51 100644
--- a/source/blender/editors/space_view3d/drawhair.c
+++ b/source/blender/editors/space_view3d/drawhair.c
@@ -48,6 +48,8 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "HAIR_capi.h"
+
 /* ******** Hair Drawing ******** */
 
 /* TODO vertex/index buffers, etc. etc., avoid direct mode ... */
@@ -62,6 +64,25 @@ static void draw_hair_curve(HairSystem *UNUSED(hsys), HairCurve *hair)
 		glVertex3fv(point->co);
 	}
 	glEnd();
+	
+	/* smoothed curve */
+	{
+		struct SmoothingIteratorFloat3 *iter;
+		float smooth_co[3];
+		
+		glColor3f(0.5f, 1.0f, 0.1f);
+		
+		glBegin(GL_LINE_STRIP);
+		iter = HAIR_smoothing_iter_new(hair, 0.1f, 4.0f);
+		for (point = hair->points, k = 0; k < hair->totpoints; ++point, ++k) {
+			if (HAIR_smoothing_iter_valid(hair, iter)) {
+				HAIR_smoothing_iter_next(hair, iter, smooth_co);
+				glVertex3fv(smooth_co);
+			}
+		}
+		HAIR_smoothing_iter_free(iter);
+		glEnd();
+	}
 }
 
 /* called from drawobject.c, return true if nothing was drawn */
diff --git a/source/blender/hair/CMakeLists.txt b/source/blender/hair/CMakeLists.txt
new file mode 100644
index 0000000..ee0c543
--- /dev/null
+++ b/source/blender/hair/CMakeLists.txt
@@ -0,0 +1,56 @@
+# ***** 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.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s): Lukas Toenne
+#
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+	.
+	intern
+	../blenkernel
+	../blenlib
+	../makesdna
+	../../../intern/guardedalloc
+)
+
+set(INC_SYS
+
+)
+
+set(SRC
+	HAIR_capi.h
+	HAIR_capi.cpp
+
+	intern/HAIR_curve.h
+	intern/HAIR_curve.cpp
+	intern/HAIR_smoothing.h
+	intern/HAIR_smoothing.cpp
+	intern/HAIR_types.h
+)
+
+add_definitions(
+	-DHAIR_NAMESPACE=hair
+	-DHAIR_NAMESPACE_BEGIN=namespace\ hair\ {
+	-DHAIR_NAMESPACE_END=}
+)
+
+blender_add_lib(bf_hair "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/hair/HAIR_capi.cpp b/source/blender/hair/HAIR_capi.cpp
new file mode 100644
index 0000000..4eb54e8
--- /dev/null
+++ b/source/blender/hair/HAIR_capi.cpp
@@ -0,0 +1,77 @@
+/*
+ * ***** 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 *****
+ */
+
+extern "C" {
+#include "DNA_hair_types.h"
+}
+
+#include "HAIR_capi.h"
+
+#include "HAIR_smoothing.h"
+#include "HAIR_types.h"
+
+using namespace HAIR_NAMESPACE;
+
+struct SmoothingIteratorFloat3 *HAIR_smoothing_iter_new(struct HairCurve *curve, float rest_length, float amount)
+{
+	SmoothingIterator<float3> *iter = new SmoothingIterator<float3>(rest_length, amount);
+	
+	if (curve->totpoints >= 2) {
+		float *co0 = curve->points[0].co;
+		float *co1 = curve->points[1].co;
+		iter->begin(float3(co0[0], co0[1], co0[2]), float3(co1[0], co1[1], co1[2]));
+	}
+	else {
+		iter->num = 1; /* XXX not nice, find a better way to indicate invalid iterator */
+	}
+	
+	return (struct SmoothingIteratorFloat3 *)iter;
+}
+
+void HAIR_smoothing_iter_free(struct SmoothingIteratorFloat3 *citer)
+{
+	SmoothingIterator<float3> *iter = (SmoothingIterator<float3> *)citer;
+	
+	delete iter;
+}
+
+bool HAIR_smoothing_iter_valid(struct HairCurve *curve, struct SmoothingIteratorFloat3 *citer)
+{
+	SmoothingIterator<float3> *iter = (SmoothingIterator<float3> *)citer;
+	
+	return iter->num < curve->totpoints - 1;
+}
+
+void HAIR_smoothing_iter_next(struct HairCurve *curve, struct SmoothingIteratorFloat3 *citer, float cval[3])
+{
+	SmoothingIterator<float3> *iter = (SmoothingIterator<float3> *)citer;
+	
+	float *co = curve->points[iter->num + 1].co;
+	float3 val = iter->next(float3(co[0], co[1], co[2]));
+	cval[0] = val.x;
+	cval[1] = val.y;
+	cval[2] = val.z;
+}
diff --git a/source/blender/hair/HAIR_capi.h b/source/blender/hair/HAIR_capi.h
new file mode 100644
index 0000000..04c5279
--- /dev/null
+++ b/source/blender/hair/HAIR_capi.h
@@ -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 *****
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct HairCurve;
+
+struct SmoothingIteratorFloat3;
+
+struct SmoothingIteratorFloat3 *HAIR_smoothing_iter_new(struct HairCurve *curve, float rest_length, float amount);
+void HAIR_smoothing_iter_free(struct SmoothingIteratorFloat3 *iter);
+bool HAIR_smoothing_iter_valid(struct HairCurve *curve, struct SmoothingIteratorFloat3 *iter);
+void HAIR_smoothing_iter_next(struct HairCurve *curve, struct SmoothingIteratorFloat3 *iter, float val[3]);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/hair/intern/HAIR_curve.cpp b/source/blender/hair/intern/HAIR_curve.cpp
new file mode 100644
index 0000000..8d0314b
--- /dev/null
+++ b/source/blender/hair/intern/HAIR_curve.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_curve.h"
+
+HAIR_NAMESPACE_BEGIN
+
+Point::Point(const float3 &co) :
+    co(co)
+{
+}
+
+Curve::Curve(int totpoints, Point *points) :
+    totpoints(totpoints),
+    points(points)
+{
+}
+
+HAIR_NAMESPACE_END
diff --git a/source/blender/hair/intern/HAIR_curve.h b/source/blender/hair/intern/HAIR_curve.h
new file mode 100644
index 0000000..854f612
--- /dev/null
+++ b/source/blender/hair/intern/HAIR_curve.h
@@ -0,0 +1,49 @@
+/*
+ * ***** 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 i

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list