Commit: b0717ad91eedb64fa23a7ac16403d3fc166e447a
Author: Lukas Tönne
Date: Mon Aug 14 07:58:02 2017 +0100
Branches: strand_editmode
https://developer.blender.org/rBb0717ad91eedb64fa23a7ac16403d3fc166e447a
Hair drawing data based on the new DNA hair groups.
===================================================================
M source/blender/blenkernel/BKE_editstrands.h
M source/blender/blenkernel/BKE_hair.h
M source/blender/blenkernel/intern/editstrands.c
M source/blender/blenkernel/intern/hair.c
M source/blender/blenkernel/intern/hair_draw.c
M source/blender/draw/CMakeLists.txt
M source/blender/draw/engines/eevee/eevee_materials.c
M source/blender/draw/engines/eevee/shaders/hair_lib.glsl
M source/blender/draw/intern/draw_cache.c
M source/blender/draw/intern/draw_cache.h
M source/blender/draw/intern/draw_cache_impl.h
A source/blender/draw/intern/draw_cache_impl_hair.c
M source/blender/draw/intern/draw_cache_impl_strands.c
M source/blender/draw/intern/draw_hair.c
M source/blender/draw/intern/draw_manager.c
M source/blender/editors/hair/hair_object_particles.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_editstrands.h
b/source/blender/blenkernel/BKE_editstrands.h
index 1e0ed8cf3c4..991776deda3 100644
--- a/source/blender/blenkernel/BKE_editstrands.h
+++ b/source/blender/blenkernel/BKE_editstrands.h
@@ -51,11 +51,8 @@ typedef struct BMEditStrands {
/* Scalp mesh for fixing root vertices */
struct DerivedMesh *root_dm;
-
- /* Hair fibers (optional) */
- struct HairFiber *hair_fibers;
- int hair_totfibers;
- unsigned int hair_seed;
+ struct HairPattern *hair_pattern;
+ struct HairGroup *hair_group;
int flag;
@@ -81,9 +78,6 @@ void BKE_editstrands_free(struct BMEditStrands *es);
/* === Hair Fibers === */
-bool BKE_editstrands_hair_ensure(struct BMEditStrands *es);
-void BKE_editstrands_hair_free(struct BMEditStrands *es);
-
int* BKE_editstrands_hair_get_fiber_lengths(struct BMEditStrands *es, int
subdiv);
void BKE_editstrands_hair_get_texture_buffer_size(struct BMEditStrands *es,
int subdiv, int *r_size,
int *r_strand_map_start, int
*r_strand_vertex_start, int *r_fiber_start);
diff --git a/source/blender/blenkernel/BKE_hair.h
b/source/blender/blenkernel/BKE_hair.h
index 1c079168500..b5dc42b0974 100644
--- a/source/blender/blenkernel/BKE_hair.h
+++ b/source/blender/blenkernel/BKE_hair.h
@@ -55,25 +55,13 @@ void BKE_hair_group_moveto(struct HairPattern *hair, struct
HairGroup *group, in
void BKE_hair_group_name_set(struct HairPattern *hair, struct HairGroup
*group, const char *name);
-/* ================================= */
-
-typedef struct HairFiber {
- /* Sample on the scalp mesh for the root vertex */
- MeshSample root;
- /* Indices of control strands for interpolation */
- unsigned int parent_index[4];
- /* Weights of control strands for interpolation */
- float parent_weight[4];
- /* Parametric distance to the primary control strand */
- float root_distance[2];
-} HairFiber;
-
-bool BKE_hair_fiber_get_location(const struct HairFiber *fiber, struct
DerivedMesh *root_dm, float loc[3]);
-bool BKE_hair_fiber_get_vectors(const struct HairFiber *fiber, struct
DerivedMesh *root_dm,
- float loc[3], float nor[3], float tang[3]);
-bool BKE_hair_fiber_get_matrix(const struct HairFiber *fiber, struct
DerivedMesh *root_dm, float mat[4][4]);
+void BKE_hair_update_groups(struct HairPattern *hair);
+
+/* === Draw Buffer Texture === */
typedef struct HairDrawDataInterface {
+ const struct HairGroup *group;
+
int (*get_num_strands)(const struct HairDrawDataInterface* hairdata);
int (*get_num_verts)(const struct HairDrawDataInterface* hairdata);
@@ -82,18 +70,11 @@ typedef struct HairDrawDataInterface {
void (*get_strand_vertices)(const struct HairDrawDataInterface*
hairdata, float (*r_positions)[3]);
} HairDrawDataInterface;
-struct HairFiber* BKE_hair_fibers_create(const struct HairDrawDataInterface
*hairdata,
- struct DerivedMesh *scalp, unsigned
int amount,
- unsigned int seed);
-
-int* BKE_hair_strands_get_fiber_lengths(const struct HairFiber *fibers, int
totfibers,
- const struct HairDrawDataInterface
*hairdata, int subdiv);
-
-void BKE_hair_strands_get_texture_buffer_size(const struct
HairDrawDataInterface *hairdata, int totfibers, int subdiv,
+int* BKE_hair_strands_get_fiber_lengths(const struct HairDrawDataInterface
*hairdata, int subdiv);
+void BKE_hair_strands_get_texture_buffer_size(const struct
HairDrawDataInterface *hairdata, int subdiv,
int *r_size, int
*r_strand_map_start,
int *r_strand_vertex_start, int
*r_fiber_start);
-void BKE_hair_strands_get_texture_buffer(const struct HairDrawDataInterface
*hairdata, struct DerivedMesh *scalp,
- const struct HairFiber *fibers, int
totfibers, int subdiv,
+void BKE_hair_strands_get_texture_buffer(const struct HairDrawDataInterface
*hairdata, int subdiv, struct DerivedMesh *scalp,
void *texbuffer);
/* === Draw Cache === */
@@ -102,11 +83,12 @@ enum {
BKE_HAIR_BATCH_DIRTY_ALL = 0,
};
void BKE_hair_batch_cache_dirty(struct HairGroup *group, int mode);
+void BKE_hair_batch_cache_all_dirty(struct HairPattern *hair, int mode);
void BKE_hair_batch_cache_free(struct HairGroup *group);
-int* BKE_hair_get_fiber_lengths(struct HairGroup *group, int subdiv);
+int* BKE_hair_group_get_fiber_lengths(struct HairGroup *group, int subdiv);
void BKE_hair_group_get_texture_buffer_size(struct HairGroup *group, int
subdiv, int *r_size,
int *r_strand_map_start, int
*r_strand_vertex_start, int *r_fiber_start);
-void BKE_hair_group_get_texture_buffer(struct HairGroup *group, struct
DerivedMesh *scalp, int subdiv, void *texbuffer);
+void BKE_hair_group_get_texture_buffer(struct HairGroup *group, int subdiv,
struct DerivedMesh *scalp, void *texbuffer);
#endif
diff --git a/source/blender/blenkernel/intern/editstrands.c
b/source/blender/blenkernel/intern/editstrands.c
index 723590be4a6..adbb4b707aa 100644
--- a/source/blender/blenkernel/intern/editstrands.c
+++ b/source/blender/blenkernel/intern/editstrands.c
@@ -124,7 +124,6 @@ void BKE_editstrands_update_linked_customdata(BMEditStrands
*UNUSED(es))
void BKE_editstrands_free(BMEditStrands *es)
{
BKE_editstrands_batch_cache_free(es);
- BKE_editstrands_hair_free(es);
if (es->base.bm)
BM_mesh_free(es->base.bm);
@@ -200,6 +199,7 @@ static void get_strand_vertices(const
HairDrawDataInterface* hairdata_, float (*
static EditStrandsView editstrands_get_view(BMEditStrands *edit)
{
EditStrandsView hairdata;
+ hairdata.base.group = edit->hair_group;
hairdata.base.get_num_strands = get_num_strands;
hairdata.base.get_num_verts = get_num_verts;
hairdata.base.get_strand_lengths = get_strand_lengths;
@@ -209,48 +209,24 @@ static EditStrandsView editstrands_get_view(BMEditStrands
*edit)
return hairdata;
}
-bool BKE_editstrands_hair_ensure(BMEditStrands *es)
-{
- if (!es->root_dm || es->hair_totfibers == 0) {
- BKE_editstrands_hair_free(es);
- return false;
- }
-
- if (!es->hair_fibers) {
- EditStrandsView strands = editstrands_get_view(es);
- es->hair_fibers = BKE_hair_fibers_create(&strands.base,
es->root_dm, es->hair_totfibers, es->hair_seed);
- }
-
- return true;
-}
-
-void BKE_editstrands_hair_free(BMEditStrands *es)
-{
- if (es->hair_fibers)
- {
- MEM_freeN(es->hair_fibers);
- es->hair_fibers = NULL;
- }
-}
-
int* BKE_editstrands_hair_get_fiber_lengths(BMEditStrands *es, int subdiv)
{
EditStrandsView strands = editstrands_get_view(es);
- return BKE_hair_strands_get_fiber_lengths(es->hair_fibers,
es->hair_totfibers, &strands.base, subdiv);
+ return BKE_hair_strands_get_fiber_lengths(&strands.base, subdiv);
}
void BKE_editstrands_hair_get_texture_buffer_size(BMEditStrands *es, int
subdiv, int *r_size,
int *r_strand_map_start, int
*r_strand_vertex_start, int *r_fiber_start)
{
EditStrandsView strands = editstrands_get_view(es);
- BKE_hair_strands_get_texture_buffer_size(&strands.base,
es->hair_totfibers, subdiv, r_size,
- r_strand_map_start,
r_strand_vertex_start, r_fiber_start);
+ BKE_hair_strands_get_texture_buffer_size(&strands.base, subdiv,
+ r_size, r_strand_map_start,
r_strand_vertex_start, r_fiber_start);
}
void BKE_editstrands_hair_get_texture_buffer(BMEditStrands *es, int subdiv,
void *texbuffer)
{
EditStrandsView strands = editstrands_get_view(es);
- BKE_hair_strands_get_texture_buffer(&strands.base, es->root_dm,
es->hair_fibers, es->hair_totfibers, subdiv, texbuffer);
+ BKE_hair_strands_get_texture_buffer(&strands.base, subdiv, es->root_dm,
texbuffer);
}
/* === Constraints === */
diff --git a/source/blender/blenkernel/intern/hair.c
b/source/blender/blenkernel/intern/hair.c
index 9c01fcbf788..7dc1916d29c 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -29,6 +29,7 @@
* \ingroup bke
*/
+#include <limits.h>
#include <string.h>
#include "MEM_guardedalloc.h"
@@ -37,6 +38,7 @@
#include "BLI_kdtree.h"
#include "BLI_listbase.h"
#include "BLI_rand.h"
+#include "BLI_sort.h"
#include "BLI_string_utf8.h"
#include "BLI_string_utils.h"
@@ -69,12 +71,27 @@ HairPattern* BKE_hair_copy(HairPattern *hair)
return nhair;
}
+static void hair_group_free(HairGroup *group)
+{
+ BKE_hair_batch_cache_free(group);
+
+ if (group->strands_parent_index) {
+ MEM_freeN(group->strands_parent_index);
+ }
+ if (group->strands_parent_weight) {
+ MEM_freeN(group->strands_parent_weight);
+ }
+}
+
void BKE_hair_free(struct HairPattern *hair)
{
if (hair->follicles) {
MEM_freeN(hair->follicles);
}
+ for (HairGroup *group = hair->groups.first; group; group = group->next)
{
+ hair_group_free(group);
+ }
BLI_freelistN(&hair->groups);
MEM_freeN(hair);
@@ -122,6 +139,10 @@ void BKE_hair_follicles_generate(HairPattern *hair,
DerivedMesh *scalp, int coun
}
BKE_mesh_sample_free_generator(gen);
+
+ BKE_hair_batch_cache_all_dirty(hair, BKE_HAIR_BATCH_DIRTY_ALL);
+
+ BKE_hair_update_groups(hair);
}
HairGroup* BKE_hair_group_new(HairPattern *hair, int type)
@@ -152,6 +173,8 @@ void BKE_hair_group_remove(HairPattern *hair, HairGroup
*group)
BLI_assert(BLI_findindex(&hair->groups, group) >= 0);
BLI_remlink(&hair->groups, group);
+
+ hair_group_free(group);
MEM_freeN(group);
}
@@ -184,6 +207,85 @@ void BKE_hair_group_name_set(HairPattern *hair, HairGroup
*group, const char *na
BLI_uniquename(&hair->groups, group, DATA_("Group"), '.',
offsetof(HairGroup, name), sizeof(group->name));
}
+#define HAIR_FOLLICLE_GROUP_NONE INT_MAX
+
+static void hair_claim_group_follicle(HairGroup *group, int group_index, int
*follicle_group, int i)
+{
+ if (follicle_group[i] == HAIR_FOLLICLE_GROUP_NONE) {
+ follicle_group[i] = group_index;
+ ++group->num_follicles;
+ }
+}
+
+static void hair_group_follicles_normals(HairPattern *hair, HairGroup
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs