[Bf-blender-cvs] [af7fe83] alembic: Store MSurfaceSample data in hair strands for mapping to a mesh.

Lukas Tönne noreply at git.blender.org
Wed May 6 11:15:37 CEST 2015


Commit: af7fe835ffeff094df994f5e3fd75735f0514d8f
Author: Lukas Tönne
Date:   Wed May 6 11:13:36 2015 +0200
Branches: alembic
https://developer.blender.org/rBaf7fe835ffeff094df994f5e3fd75735f0514d8f

Store MSurfaceSample data in hair strands for mapping to a mesh.

This data is not strictly necessary for the strands drawing or rendering
or even hair simulation, because the hair root offset and rotation is
already cached explicitly. However, the strand edit mode needs this
information to correctly apply length constraints.

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

M	source/blender/blenkernel/BKE_editstrands.h
M	source/blender/blenkernel/intern/editstrands.c
M	source/blender/blenkernel/intern/object_dupli.c
M	source/blender/bmesh/intern/bmesh_strands_conv.c
M	source/blender/editors/hair/hair_object_cachelib.c
M	source/blender/editors/hair/hair_object_particles.c
M	source/blender/editors/hair/hair_undo.c
M	source/blender/makesdna/DNA_strands_types.h
M	source/blender/physics/intern/strands.cpp
M	source/blender/pointcache/alembic/abc_particles.cpp
M	source/blender/pointcache/alembic/abc_particles.h

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

diff --git a/source/blender/blenkernel/BKE_editstrands.h b/source/blender/blenkernel/BKE_editstrands.h
index b617042..ddca51e 100644
--- a/source/blender/blenkernel/BKE_editstrands.h
+++ b/source/blender/blenkernel/BKE_editstrands.h
@@ -71,7 +71,7 @@ typedef enum BMEditStrandsFlag {
 	BM_STRANDS_DIRTY_SEGLEN     = 1,
 } BMEditStrandsFlag;
 
-struct BMEditStrands *BKE_editstrands_create(struct BMesh *bm, struct DerivedMesh *root_dm);
+struct BMEditStrands *BKE_editstrands_create(struct BMesh *bm, struct DerivedMesh *root_dm, float mat[4][4]);
 struct BMEditStrands *BKE_editstrands_copy(struct BMEditStrands *es);
 struct BMEditStrands *BKE_editstrands_from_object(struct Object *ob);
 void BKE_editstrands_update_linked_customdata(struct BMEditStrands *es);
diff --git a/source/blender/blenkernel/intern/editstrands.c b/source/blender/blenkernel/intern/editstrands.c
index d2ba324..86e8192 100644
--- a/source/blender/blenkernel/intern/editstrands.c
+++ b/source/blender/blenkernel/intern/editstrands.c
@@ -55,13 +55,26 @@
 
 #include "intern/bmesh_strands_conv.h"
 
-BMEditStrands *BKE_editstrands_create(BMesh *bm, DerivedMesh *root_dm)
+/* mat can be used to transform the dm into another space,
+ * in case the edited object is not the active object:
+ *   mat = inv(M_act) * M_edit
+ */
+BMEditStrands *BKE_editstrands_create(BMesh *bm, DerivedMesh *root_dm, float mat[4][4])
 {
 	BMEditStrands *es = MEM_callocN(sizeof(BMEditStrands), __func__);
 	
 	es->bm = bm;
 	es->root_dm = CDDM_copy(root_dm);
 	
+	if (mat) {
+		DerivedMesh *dm = es->root_dm;
+		MVert *mv = dm->getVertArray(dm);
+		int totvert = dm->getNumVerts(dm), i;
+		for (i = 0; i < totvert; ++i, ++mv) {
+			mul_m4_v3(mat, mv->co);
+		}
+	}
+	
 	return es;
 }
 
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 83985d4..593bb30 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -62,6 +62,7 @@
 #include "BKE_lattice.h"
 #include "BKE_main.h"
 #include "BKE_mesh.h"
+#include "BKE_mesh_sample.h"
 #include "BKE_object.h"
 #include "BKE_particle.h"
 #include "BKE_scene.h"
@@ -1623,6 +1624,7 @@ static void dupli_strands_data_update(CacheLibrary *cachelib, DupliObjectData *d
 
 					scurve->numverts = pa->totkey;
 					copy_m3_m4(scurve->root_matrix, hairmat);
+					BKE_mesh_sample_from_particle(&scurve->msurf, psys, data->dm, pa);
 
 					for (k = 0, hkey = pa->hair; k < pa->totkey; ++k, ++hkey) {
 						copy_v3_v3(svert->co, hkey->co);
diff --git a/source/blender/bmesh/intern/bmesh_strands_conv.c b/source/blender/bmesh/intern/bmesh_strands_conv.c
index fc3524c..d422462 100644
--- a/source/blender/bmesh/intern/bmesh_strands_conv.c
+++ b/source/blender/bmesh/intern/bmesh_strands_conv.c
@@ -177,13 +177,7 @@ static void bm_make_strands(BMesh *bm, Strands *strands, Key *key, struct Derive
 			BM_elem_float_data_named_set(&bm->vdata, v, CD_PROP_FLT, CD_HAIR_WEIGHT, it_vert.vertex->weight);
 			
 			/* root */
-			if (it_vert.index == 0) {
-				// XXX TODO
-//				MSurfaceSample root_loc;
-//				if (BKE_mesh_sample_from_particle(&root_loc, psys, emitter_dm, pa)) {
-//					BM_elem_meshsample_data_named_set(&bm->vdata, v, CD_MSURFACE_SAMPLE, CD_HAIR_ROOT_LOCATION, &root_loc);
-//				}
-			}
+			BM_elem_meshsample_data_named_set(&bm->vdata, v, CD_MSURFACE_SAMPLE, CD_HAIR_ROOT_LOCATION, &it_strand.curve->msurf);
 			
 			/* set shapekey data */
 			if (key) {
@@ -405,7 +399,7 @@ BLI_INLINE void bmesh_quick_edgedraw_flag(MEdge *med, BMEdge *e)
 #endif
 
 static void strands_make_strand(BMesh *bm, BMVert *root, Strands *UNUSED(strands), Key *UNUSED(key),
-                                struct DerivedMesh *UNUSED(emitter_dm), struct BVHTreeFromMesh *UNUSED(emitter_bvhtree),
+                                struct DerivedMesh *emitter_dm, struct BVHTreeFromMesh *UNUSED(emitter_bvhtree),
                                 StrandIterator *it_strand)
 {
 	int numverts = BM_strands_keys_count(root);
@@ -415,7 +409,7 @@ static void strands_make_strand(BMesh *bm, BMVert *root, Strands *UNUSED(strands
 	StrandVertexIterator it_vert;
 	
 	it_strand->curve->numverts = numverts;
-	// XXX TODO
+	/* init root matrix, fully constructed below for non-degenerate strands */
 	unit_m3(it_strand->curve->root_matrix);
 	
 	BKE_strand_vertex_iter_init(&it_vert, it_strand);
@@ -424,17 +418,14 @@ static void strands_make_strand(BMesh *bm, BMVert *root, Strands *UNUSED(strands
 		
 		/* root */
 		if (it_vert.index == 0) {
-			// XXX TODO
-#if 0
-			MSurfaceSample root_loc;
-			BM_elem_meshsample_data_named_get(&bm->vdata, v, CD_MSURFACE_SAMPLE, CD_HAIR_ROOT_LOCATION, &root_loc);
-			if (!BKE_mesh_sample_to_particle(&root_loc, psys, emitter_dm, emitter_bvhtree, pa)) {
-				pa->num = 0;
-				pa->num_dmcache = DMCACHE_NOTFOUND;
-				zero_v4(pa->fuv);
-				pa->foffset = 0.0f;
-			}
-#endif
+			float loc[3], nor[3], tang[3];
+			BM_elem_meshsample_data_named_get(&bm->vdata, v, CD_MSURFACE_SAMPLE, CD_HAIR_ROOT_LOCATION, &it_strand->curve->msurf);
+			BKE_mesh_sample_eval(emitter_dm, &it_strand->curve->msurf, loc, nor, tang);
+			
+			/* construct root matrix */
+			copy_v3_v3(it_strand->curve->root_matrix[2], nor);
+			copy_v3_v3(it_strand->curve->root_matrix[0], tang);
+			cross_v3_v3v3(it_strand->curve->root_matrix[1], it_strand->curve->root_matrix[2], it_strand->curve->root_matrix[0]);
 		}
 		
 		copy_v3_v3(it_vert.vertex->co, v->co);
diff --git a/source/blender/editors/hair/hair_object_cachelib.c b/source/blender/editors/hair/hair_object_cachelib.c
index e075083..982c805 100644
--- a/source/blender/editors/hair/hair_object_cachelib.c
+++ b/source/blender/editors/hair/hair_object_cachelib.c
@@ -70,7 +70,7 @@ bool ED_hair_object_init_cache_edit(Object *ob)
 	if (!skmd->edit) {
 		BMesh *bm = BKE_cache_strands_to_bmesh(strands, skmd->key, mat, skmd->shapenr - 1, dm);
 		
-		skmd->edit = BKE_editstrands_create(bm, dm);
+		skmd->edit = BKE_editstrands_create(bm, dm, mat);
 	}
 	
 	return true;
diff --git a/source/blender/editors/hair/hair_object_particles.c b/source/blender/editors/hair/hair_object_particles.c
index 75cb0fd..a6d0532 100644
--- a/source/blender/editors/hair/hair_object_particles.c
+++ b/source/blender/editors/hair/hair_object_particles.c
@@ -73,7 +73,7 @@ bool ED_hair_object_init_particle_edit(Scene *scene, Object *ob)
 			else
 				dm = NULL;
 			
-			psys->hairedit = BKE_editstrands_create(bm, dm);
+			psys->hairedit = BKE_editstrands_create(bm, dm, NULL);
 		}
 		return true;
 	}
diff --git a/source/blender/editors/hair/hair_undo.c b/source/blender/editors/hair/hair_undo.c
index e68122e..a58b9c0 100644
--- a/source/blender/editors/hair/hair_undo.c
+++ b/source/blender/editors/hair/hair_undo.c
@@ -124,7 +124,7 @@ static void strands_undo_to_edit(void *undov, void *editv, void *UNUSED(obdata))
 	 * because it owns the root_dm and we have to copy it before
 	 * it gets released when freeing the old edit.
 	 */
-	edit_tmp = BKE_editstrands_create(bm, dm);
+	edit_tmp = BKE_editstrands_create(bm, dm, NULL);
 	BKE_editstrands_free(edit);
 	*edit = *edit_tmp;
 	
diff --git a/source/blender/makesdna/DNA_strands_types.h b/source/blender/makesdna/DNA_strands_types.h
index 2e52ad1..1c794ee 100644
--- a/source/blender/makesdna/DNA_strands_types.h
+++ b/source/blender/makesdna/DNA_strands_types.h
@@ -25,6 +25,8 @@
 
 #include "DNA_defs.h"
 
+#include "DNA_meshdata_types.h"
+
 typedef struct StrandsVertex {
 	float co[3];
 	float base[3]; /* base shape, defining deformation for children */
@@ -46,6 +48,8 @@ typedef struct StrandsMotionState {
 typedef struct StrandsCurve {
 	int numverts;
 	float root_matrix[3][3];
+	
+	MSurfaceSample msurf;
 } StrandsCurve;
 
 typedef struct Strands {
diff --git a/source/blender/physics/intern/strands.cpp b/source/blender/physics/intern/strands.cpp
index ad2a43a..19a31f7 100644
--- a/source/blender/physics/intern/strands.cpp
+++ b/source/blender/physics/intern/strands.cpp
@@ -60,6 +60,9 @@ static bool strand_get_root_vectors(BMEditStrands *edit, BMVert *root, float loc
 	DerivedMesh *root_dm = edit->root_dm;
 	MSurfaceSample root_sample;
 	
+	if (!CustomData_has_layer(&bm->vdata, CD_MSURFACE_SAMPLE))
+		return false;
+	
 	BM_elem_meshsample_data_named_get(&bm->vdata, root, CD_MSURFACE_SAMPLE, CD_HAIR_ROOT_LOCATION, &root_sample);
 	return BKE_mesh_sample_eval(root_dm, &root_sample, loc, nor, tang);
 }
@@ -101,8 +104,9 @@ static void strands_apply_root_locations(BMEditStrands *edit)
 	BM_ITER_STRANDS(root, &iter, edit->bm, BM_STRANDS_OF_MESH) {
 		float loc[3], nor[3], tang[3];
 		
-		if (strand_get_root_vectors(edit, root, loc, nor, tang))
+		if (strand_get_root_vectors(edit, root, loc, nor, tang)) {
 			copy_v3_v3(root->co, loc);
+		}
 	}
 }
 
diff --git a/source/blender/pointcache/alembic/abc_particles.cpp b/source/blender/pointcache/alembic/abc_particles.cpp
index 6ebaa36..89c1858 100644
--- a/source/blender/pointcache/alembic/abc_particles.cpp
+++ b/source/blender/pointcache/alembic/abc_particles.cpp
@@ -31,6 +31,7 @@ extern "C" {
 #include "DNA_particle_types.h"
 
 #include "BKE_anim.h"
+#include "BKE_mesh_sample.h"
 #include "BKE_particle.h"
 #include "BKE_strands.h"
 }
@@ -57,6 +58,10 @@ struct StrandsChildrenSample {
 struct StrandsSample {
 	std::vector<int32_t> numverts;
 	std::vector<Quatf> root_rotations;
+	std::vector<uint32_t> root_orig_verts;
+	std::vector<float32_t> root_orig_weights;
+	std::vector<int32_t> root_orig_poly;
+	std::vector<uint32_t> root_orig_loops;
 	
 	std::vector<V3f> positions;
 	std::vector<float32_t> times;
@@ -450,6 +455,10 @@ void AbcHairWriter::init_abc(OObject parent)
 	OCompoundProperty geom_props = schema.getArbGeomParams();
 	
 	m_param_root_rot = OQuatfGeomParam(geom_props, "root_rotations", false, kUniformScope, 1, 0);
+	m_param_root_orig_verts = OUInt32GeomParam(geom_props, "root_orig_verts", false, kUniformScope, 1, 0);
+	m_param_root_orig_weights = OFloatGeomParam(geom_props, "root_orig_weights", false, kUniformScope, 1, 0);
+	m_param_root_orig_poly = OInt32GeomParam(geom_props, "root_orig_poly", false, kUniformScope, 1, 0);
+	m_param_root_orig_loops = OUInt32GeomParam(geom_props, "root_orig_loops", false, kUniformScope, 1, 0);
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list