[Bf-blender-cvs] [524874c] hair_immediate_fixes: First customdata layer for particle mass.
Lukas Tönne
noreply at git.blender.org
Fri Nov 28 10:43:46 CET 2014
Commit: 524874c920639cedafedd226498ece98d18c2c66
Author: Lukas Tönne
Date: Fri Nov 28 10:17:29 2014 +0100
Branches: hair_immediate_fixes
https://developer.blender.org/rB524874c920639cedafedd226498ece98d18c2c66
First customdata layer for particle mass.
This is more for testing purposes, since currently there is only a
single mass property for the psys as a whole. This should change in the
future though, to allow variable mass per strand or vertex.
===================================================================
M source/blender/blenkernel/BKE_customdata.h
M source/blender/blenkernel/intern/customdata.c
M source/blender/bmesh/intern/bmesh_interp.c
M source/blender/bmesh/intern/bmesh_interp.h
M source/blender/bmesh/intern/bmesh_strands_conv.c
M source/blender/bmesh/intern/bmesh_strands_conv.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index 30a5889..89c3c1e 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -240,6 +240,7 @@ void *CustomData_get(const struct CustomData *data, int index, int type);
void *CustomData_get_n(const struct CustomData *data, int type, int index, int n);
void *CustomData_bmesh_get(const struct CustomData *data, void *block, int type);
void *CustomData_bmesh_get_n(const struct CustomData *data, void *block, int type, int n);
+void *CustomData_bmesh_get_named(const struct CustomData *data, void *block, int type, const char *name);
/* gets the layer at physical index n, with no type checking.
*/
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 1c2aed6..fb02d02 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -2688,6 +2688,18 @@ void *CustomData_bmesh_get_layer_n(const CustomData *data, void *block, int n)
return (char *)block + data->layers[n].offset;
}
+/*Bmesh Custom Data Functions. Should replace editmesh ones with these as well, due to more effecient memory alloc*/
+void *CustomData_bmesh_get_named(const CustomData *data, void *block, int type, const char *name)
+{
+ int layer_index;
+
+ /* get the layer index of the named layer of type */
+ layer_index = CustomData_get_named_layer_index(data, type, name);
+ if (layer_index == -1) return NULL;
+
+ return (char *)block + data->layers[layer_index].offset;
+}
+
bool CustomData_layer_has_math(const struct CustomData *data, int layer_n)
{
const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[layer_n].type);
diff --git a/source/blender/bmesh/intern/bmesh_interp.c b/source/blender/bmesh/intern/bmesh_interp.c
index a32f281..f93675f 100644
--- a/source/blender/bmesh/intern/bmesh_interp.c
+++ b/source/blender/bmesh/intern/bmesh_interp.c
@@ -893,3 +893,15 @@ void BM_elem_float_data_set(CustomData *cd, void *element, int type, const float
float *f = CustomData_bmesh_get(cd, ((BMHeader *)element)->data, type);
if (f) *f = val;
}
+
+float BM_elem_float_data_named_get(CustomData *cd, void *element, int type, const char *name)
+{
+ const float *f = CustomData_bmesh_get_named(cd, ((BMHeader *)element)->data, type, name);
+ return f ? *f : 0.0f;
+}
+
+void BM_elem_float_data_named_set(CustomData *cd, void *element, int type, const char *name, const float val)
+{
+ float *f = CustomData_bmesh_get_named(cd, ((BMHeader *)element)->data, type, name);
+ if (f) *f = val;
+}
diff --git a/source/blender/bmesh/intern/bmesh_interp.h b/source/blender/bmesh/intern/bmesh_interp.h
index c605ad3..0315702 100644
--- a/source/blender/bmesh/intern/bmesh_interp.h
+++ b/source/blender/bmesh/intern/bmesh_interp.h
@@ -41,6 +41,8 @@ void BM_data_layer_copy(BMesh *bm, CustomData *data, int type, int src_n, int d
float BM_elem_float_data_get(CustomData *cd, void *element, int type);
void BM_elem_float_data_set(CustomData *cd, void *element, int type, const float val);
+float BM_elem_float_data_named_get(CustomData *cd, void *element, int type, const char *name);
+void BM_elem_float_data_named_set(CustomData *cd, void *element, int type, const char *name, const float val);
void BM_face_interp_from_face_ex(BMesh *bm, BMFace *target, BMFace *source, const bool do_vertex,
void **blocks, void **blocks_v, float (*cos_2d)[2], float axis_mat[3][3]);
diff --git a/source/blender/bmesh/intern/bmesh_strands_conv.c b/source/blender/bmesh/intern/bmesh_strands_conv.c
index e7fa3fc..61556ea 100644
--- a/source/blender/bmesh/intern/bmesh_strands_conv.c
+++ b/source/blender/bmesh/intern/bmesh_strands_conv.c
@@ -44,6 +44,8 @@
#include "bmesh.h"
#include "intern/bmesh_private.h" /* for element checking */
+const char *CD_PSYS_MASS = "PSYS_MASS";
+
int BM_strands_count_psys_keys(ParticleSystem *psys)
{
ParticleData *pa;
@@ -82,6 +84,10 @@ void BM_strands_cd_flag_apply(BMesh *bm, const char UNUSED(cd_flag))
/* CustomData_bmesh_init_pool() must run first */
BLI_assert(bm->vdata.totlayer == 0 || bm->vdata.pool != NULL);
BLI_assert(bm->edata.totlayer == 0 || bm->edata.pool != NULL);
+
+ if (CustomData_get_named_layer_index(&bm->vdata, CD_PROP_FLT, CD_PSYS_MASS) < 0) {
+ BM_data_layer_add_named(bm, &bm->vdata, CD_PROP_FLT, CD_PSYS_MASS);
+ }
}
char BM_strands_cd_flag_from_bmesh(BMesh *UNUSED(bm))
@@ -148,6 +154,9 @@ static void bm_make_particles(BMesh *bm, ParticleSystem *psys, float (*keyco)[3]
BMVert *v = NULL, *v_prev;
BMEdge *e;
+ /* XXX currently all particles and keys have the same mass, this may change */
+ float mass = psys->part->mass;
+
vindex = 0;
for (p = 0, pa = psys->particles; p < psys->totpart; ++p, ++pa) {
@@ -171,6 +180,8 @@ static void bm_make_particles(BMesh *bm, ParticleSystem *psys, float (*keyco)[3]
// CustomData_to_bmesh_block(&me->vdata, &bm->vdata, vindex, &v->head.data, true);
CustomData_bmesh_set_default(&bm->vdata, &v->head.data);
+ BM_elem_float_data_named_set(&bm->vdata, v, CD_PROP_FLT, CD_PSYS_MASS, mass);
+
/* set shapekey data */
if (psys->key) {
/* set shape key original index */
@@ -244,8 +255,6 @@ void BM_strands_bm_from_psys(BMesh *bm, ParticleSystem *psys,
return; /* sanity check */
}
-// vtable = MEM_mallocN(sizeof(void **) * me->totvert, "mesh to bmesh vtable");
-
actkey = bm_set_shapekey_from_psys(bm, psys, totvert, act_key_nr);
if (actkey)
keyco = actkey->data;
@@ -253,7 +262,7 @@ void BM_strands_bm_from_psys(BMesh *bm, ParticleSystem *psys,
CustomData_bmesh_init_pool(&bm->vdata, totvert, BM_VERT);
CustomData_bmesh_init_pool(&bm->edata, totedge, BM_EDGE);
-// BM_mesh_cd_flag_apply(bm, psys->cd_flag);
+ BM_strands_cd_flag_apply(bm, /*psys->cd_flag*/0);
cd_shape_keyindex_offset = psys->key ? CustomData_get_offset(&bm->vdata, CD_SHAPE_KEYINDEX) : -1;
diff --git a/source/blender/bmesh/intern/bmesh_strands_conv.h b/source/blender/bmesh/intern/bmesh_strands_conv.h
index 75945b0..8766d18 100644
--- a/source/blender/bmesh/intern/bmesh_strands_conv.h
+++ b/source/blender/bmesh/intern/bmesh_strands_conv.h
@@ -36,6 +36,8 @@ struct BMesh;
struct Mesh;
struct ParticleSystem;
+extern const char *CD_PSYS_MASS;
+
void BM_strands_cd_validate(struct BMesh *bm);
void BM_strands_cd_flag_ensure(struct BMesh *bm, struct ParticleSystem *psys, const char cd_flag);
void BM_strands_cd_flag_apply(struct BMesh *bm, const char cd_flag);
More information about the Bf-blender-cvs
mailing list