[Bf-blender-cvs] [8dd0ec09c53] hair_object: Implement drawing function for hair curves in edit mode.
Lukas Tönne
noreply at git.blender.org
Wed Sep 5 09:31:12 CEST 2018
Commit: 8dd0ec09c5383d753e65a37bc93d63e1e2141248
Author: Lukas Tönne
Date: Wed Sep 5 08:30:47 2018 +0100
Branches: hair_object
https://developer.blender.org/rB8dd0ec09c5383d753e65a37bc93d63e1e2141248
Implement drawing function for hair curves in edit mode.
===================================================================
M source/blender/blenkernel/BKE_mesh_sample.h
M source/blender/blenkernel/intern/mesh_sample.c
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
M source/blender/draw/intern/draw_cache_impl_hair.c
M source/blender/draw/modes/edit_hair_mode.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_mesh_sample.h b/source/blender/blenkernel/BKE_mesh_sample.h
index 8599b5a38ad..3a02ac23143 100644
--- a/source/blender/blenkernel/BKE_mesh_sample.h
+++ b/source/blender/blenkernel/BKE_mesh_sample.h
@@ -32,6 +32,7 @@ struct Mesh;
struct MFace;
struct MVert;
struct MPoly;
+struct MCol;
struct MeshSample;
struct MeshSampleGenerator;
@@ -57,6 +58,11 @@ bool BKE_mesh_sample_is_volume_sample(const struct MeshSample *sample);
/* Evaluate position and normal on the given mesh */
bool BKE_mesh_sample_eval(const struct Mesh *mesh, const struct MeshSample *sample, float loc[3], float nor[3], float tang[3]);
+/* Evaluate UV coordinates on the given mesh */
+bool BKE_mesh_sample_eval_uv(const struct Mesh *mesh, const struct MeshSample *sample, int uv_layer, float uv[2]);
+/* Evaluate vertex color on the given mesh */
+bool BKE_mesh_sample_eval_col(const struct Mesh *mesh, const struct MeshSample *sample, int col_layer, struct MLoopCol *col);
+
/* Evaluate position for the given shapekey */
bool BKE_mesh_sample_shapekey(struct Key *key, struct KeyBlock *kb, const struct MeshSample *sample, float loc[3]);
diff --git a/source/blender/blenkernel/intern/mesh_sample.c b/source/blender/blenkernel/intern/mesh_sample.c
index 4071adbb679..76d3626f709 100644
--- a/source/blender/blenkernel/intern/mesh_sample.c
+++ b/source/blender/blenkernel/intern/mesh_sample.c
@@ -199,10 +199,6 @@ bool BKE_mesh_sample_is_volume_sample(const MeshSample *sample)
bool BKE_mesh_sample_eval(const Mesh *mesh, const MeshSample *sample, float loc[3], float nor[3], float tang[3])
{
- const MVert *mverts = mesh->mvert;
- const unsigned int totverts = (unsigned int)mesh->totvert;
- const MVert *v1, *v2, *v3;
-
zero_v3(loc);
zero_v3(nor);
zero_v3(tang);
@@ -218,6 +214,11 @@ bool BKE_mesh_sample_eval(const Mesh *mesh, const MeshSample *sample, float loc[
}
else {
/* SURFACE SAMPLE */
+
+ const MVert *mverts = mesh->mvert;
+ const unsigned int totverts = (unsigned int)mesh->totvert;
+ const MVert *v1, *v2, *v3;
+
if (sample->orig_verts[0] >= totverts ||
sample->orig_verts[1] >= totverts ||
sample->orig_verts[2] >= totverts)
@@ -265,6 +266,78 @@ bool BKE_mesh_sample_eval(const Mesh *mesh, const MeshSample *sample, float loc[
}
}
+/* Evaluate UV coordinates on the given mesh */
+
+bool BKE_mesh_sample_eval_uv(const Mesh *mesh, const MeshSample *sample, int uv_layer, float uv[2])
+{
+ if (BKE_mesh_sample_is_volume_sample(sample)) {
+ /* VOLUME SAMPLE */
+ zero_v2(uv);
+ return true;
+ }
+ else {
+ /* SURFACE SAMPLE */
+
+ const unsigned int totloops = (unsigned int)mesh->totloop;
+ if (sample->orig_loops[0] >= totloops ||
+ sample->orig_loops[1] >= totloops ||
+ sample->orig_loops[2] >= totloops )
+ return false;
+
+ const MLoopUV *mloopuvs = CustomData_get_layer_n(&mesh->ldata, CD_MLOOPUV, uv_layer);
+ if (!mloopuvs)
+ {
+ return false;
+ }
+
+ madd_v2_v2fl(uv, mloopuvs[sample->orig_loops[0]].uv, sample->orig_weights[0]);
+ madd_v2_v2fl(uv, mloopuvs[sample->orig_loops[1]].uv, sample->orig_weights[1]);
+ madd_v2_v2fl(uv, mloopuvs[sample->orig_loops[2]].uv, sample->orig_weights[2]);
+
+ return true;
+ }
+}
+
+/* Evaluate vertex color on the given mesh */
+
+bool BKE_mesh_sample_eval_col(const Mesh *mesh, const MeshSample *sample, int col_layer, MLoopCol *col)
+{
+ if (BKE_mesh_sample_is_volume_sample(sample)) {
+ /* VOLUME SAMPLE */
+ col->r = col->g = col->b = col->a = 0;
+ return true;
+ }
+ else {
+ /* SURFACE SAMPLE */
+
+ const unsigned int totloops = (unsigned int)mesh->totloop;
+ if (sample->orig_loops[0] >= totloops ||
+ sample->orig_loops[1] >= totloops ||
+ sample->orig_loops[2] >= totloops )
+ return false;
+
+ MLoopCol *mloopcols = CustomData_get_layer_n(&mesh->ldata, CD_MLOOPCOL, col_layer);
+ if (!mloopcols)
+ {
+ return false;
+ }
+
+ const unsigned char *col1 = &mloopcols[sample->orig_loops[0]].r;
+ const unsigned char *col2 = &mloopcols[sample->orig_loops[1]].r;
+ const unsigned char *col3 = &mloopcols[sample->orig_loops[2]].r;
+ for (int i = 0; i < 4; ++i)
+ {
+ float f = 0.0f;
+ f += (float)col1[i] * sample->orig_weights[0];
+ f += (float)col2[i] * sample->orig_weights[1];
+ f += (float)col3[i] * sample->orig_weights[2];
+ ((unsigned char *)col)[i] = (unsigned char)f;
+ }
+
+ return true;
+ }
+}
+
/* Evaluate position for the given shapekey */
bool BKE_mesh_sample_shapekey(Key *key, KeyBlock *kb, const MeshSample *sample, float loc[3])
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index f8f860e75ad..c39ec47101a 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -3370,24 +3370,24 @@ GPUBatch *DRW_cache_particles_get_prim(int type)
/** \name Hair */
-GPUBatch *DRW_cache_hair_get_fibers(struct HairSystem *hsys, const struct HairExportCache *hair_export)
+GPUBatch *DRW_cache_hair_get_fibers(struct Object *ob, struct HairSystem *hsys, const struct HairExportCache *hair_export)
{
- return DRW_hair_batch_cache_get_fibers(hsys, hair_export);
+ return DRW_hair_batch_cache_get_fibers(ob, hsys, hair_export);
}
-GPUBatch *DRW_cache_hair_get_follicle_points(struct HairSystem *hsys)
+GPUBatch *DRW_cache_hair_get_follicle_points(struct Object *ob, struct HairSystem *hsys)
{
- return DRW_hair_batch_cache_get_follicle_points(hsys);
+ return DRW_hair_batch_cache_get_follicle_points(ob, hsys);
}
-GPUBatch *DRW_cache_hair_get_verts(struct HairSystem *hsys)
+GPUBatch *DRW_cache_hair_get_verts(struct Object *ob, struct HairSystem *hsys)
{
- return DRW_hair_batch_cache_get_verts(hsys);
+ return DRW_hair_batch_cache_get_verts(ob, hsys);
}
-GPUBatch *DRW_cache_hair_get_wire(struct HairSystem *hsys)
+GPUBatch *DRW_cache_hair_get_edit_strands(struct Object *ob, struct HairSystem *hsys)
{
- return DRW_hair_batch_cache_get_wire(hsys);
+ return DRW_hair_batch_cache_get_edit_strands(ob, hsys);
}
/* 3D cursor */
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index 8309df0057a..d57fd2528a5 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -196,10 +196,10 @@ struct GPUBatch *DRW_cache_particles_get_edit_tip_points(
struct GPUBatch *DRW_cache_particles_get_prim(int type);
/* Hair */
-struct GPUBatch *DRW_cache_hair_get_fibers(struct HairSystem *hsys, const struct HairExportCache *hair_export);
-struct GPUBatch *DRW_cache_hair_get_follicle_points(struct HairSystem *hsys);
-struct GPUBatch *DRW_cache_hair_get_verts(struct HairSystem *hsys);
-struct GPUBatch *DRW_cache_hair_get_wire(struct HairSystem *hsys);
+struct GPUBatch *DRW_cache_hair_get_fibers(struct Object *ob, struct HairSystem *hsys, const struct HairExportCache *hair_export);
+struct GPUBatch *DRW_cache_hair_get_follicle_points(struct Object *ob, struct HairSystem *hsys);
+struct GPUBatch *DRW_cache_hair_get_verts(struct Object *ob, struct HairSystem *hsys);
+struct GPUBatch *DRW_cache_hair_get_edit_strands(struct Object *ob, struct HairSystem *hsys);
/* Metaball */
struct GPUBatch *DRW_cache_mball_surface_get(struct Object *ob);
diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h
index 30033614c67..b0f01244f52 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -152,9 +152,9 @@ struct GPUBatch *DRW_particles_batch_cache_get_edit_tip_points(
struct Object *object, struct ParticleSystem *psys, struct PTCacheEdit *edit);
/* Hair */
-struct GPUBatch *DRW_hair_batch_cache_get_fibers(struct HairSystem *hsys, const struct HairExportCache *hair_export);
-struct GPUBatch *DRW_hair_batch_cache_get_follicle_points(struct HairSystem *hsys);
-struct GPUBatch *DRW_hair_batch_cache_get_verts(struct HairSystem *hsys);
-struct GPUBatch *DRW_hair_batch_cache_get_wire(struct HairSystem *hsys);
+struct GPUBatch *DRW_hair_batch_cache_get_fibers(struct Object *ob, struct HairSystem *hsys, const struct HairExportCache *hair_export);
+struct GPUBatch *DRW_hair_batch_cache_get_follicle_points(struct Object *ob, struct HairSystem *hsys);
+struct GPUBatch *DRW_hair_batch_cache_get_verts(struct Object *ob, struct HairSystem *hsys);
+struct GPUBatch *DRW_hair_batch_cache_get_edit_strands(struct Object *ob, struct HairSystem *hsys);
#endif /* __DRAW_CACHE_IMPL_H__ */
diff --git a/source/blender/draw/intern/draw_cache_impl_hair.c b/source/blender/draw/intern/draw_cache_impl_hair.c
index 0ae8fb480c4..a1cc07fbb1e 100644
--- a/source/blender/draw/intern/draw_cache_impl_hair.c
+++ b/source/blender/draw/intern/draw_cache_impl_hair.c
@@ -36,8 +36,10 @@
#include "BLI_ghash.h"
#include "DNA_hair_types.h"
+#include "DNA_mesh_types.h"
#include "DNA_scene_types.h"
+#include "BKE_customdata.h"
#include "BKE_hair.h"
#include "BKE_mesh_sample.h"
@@ -61,6 +63,9 @@
typedef struct HairBatchCache {
ParticleHairCache hair;
+ /* Control points when in edit mode. */
+ ParticleHairCache edit_hair;
+
bool is_dirty;
bool is_editmode;
} HairBatchCache;
@@ -136,6 +141,7 @@ static void hair_batch_cache_clear(HairSystem *hsys)
HairBatchCache *cache = hsys->draw_batch_cache;
if (cache) {
particle_batch_cache_clear_hair(&cache->hair);
+ particle_batch_cache_clear_hair(&cache->edit_hair);
}
}
@@ -214,12 +220,12 @@ static void hair_batch_cache_ensure_procedural_pos(
cache->point_tex = GPU_texture_create_from_vertbuf(cache->proc_point_buf);
}
-static void hair_pack_mcol(MCol *mcol, unsigned short r_scol[3])
+static void hair_pack_mcol(MLoopCol *mcol, ushort r_scol[4])
{
/* Convert to linear ushort and swizzle */
- r_scol[0] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->b]);
+ r_scol[0] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->r]);
r_scol[1] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->g]);
- r_scol[2] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->r]);
+ r_scol[2] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->b]);
}
static int hair_batch_cache_fill_strands_data(
@@ -2
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list