[Bf-blender-cvs] [fa0163b] strand_gpu: Changed mesh sample definition to use 3 vertex weights instead of a face index. This is easier to sample uniformly and avoids the need for tesselation for evaluating.

Lukas Tönne noreply at git.blender.org
Tue Jul 5 09:56:21 CEST 2016


Commit: fa0163b8c7c0b8051d7b0082e61204af1a1dce9b
Author: Lukas Tönne
Date:   Tue Mar 4 15:39:48 2014 +0100
Branches: strand_gpu
https://developer.blender.org/rBfa0163b8c7c0b8051d7b0082e61204af1a1dce9b

Changed mesh sample definition to use 3 vertex weights instead of a
face index. This is easier to sample uniformly and avoids the need for
tesselation for evaluating.

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

M	source/blender/blenkernel/intern/mesh_sample.c
M	source/blender/makesdna/DNA_meshdata_types.h
M	source/blender/makesrna/intern/rna_mesh_sample.c

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

diff --git a/source/blender/blenkernel/intern/mesh_sample.c b/source/blender/blenkernel/intern/mesh_sample.c
index 51de927..c105ffa 100644
--- a/source/blender/blenkernel/intern/mesh_sample.c
+++ b/source/blender/blenkernel/intern/mesh_sample.c
@@ -44,21 +44,21 @@
 bool BKE_mesh_sample_eval(DerivedMesh *dm, const MSurfaceSample *sample, float loc[3], float nor[3])
 {
 	MVert *mverts = dm->getVertArray(dm);
-	MVert *v1, *v2, *v3, *v4;
-	MFace *mfaces = dm->getTessFaceArray(dm);
-	int totfaces = dm->getNumTessFaces(dm);
-	MFace *mface = &mfaces[sample->orig_face];
+	int totverts = dm->getNumVerts(dm);
+	MVert *v1, *v2, *v3;
 	float vnor[3];
 	
 	zero_v3(loc);
 	zero_v3(nor);
 	
-	if (sample->orig_face >= totfaces)
+	if (sample->orig_verts[0] >= totverts ||
+	    sample->orig_verts[1] >= totverts ||
+	    sample->orig_verts[2] >= totverts)
 		return false;
 	
-	v1 = &mverts[mface->v1];
-	v2 = &mverts[mface->v2];
-	v3 = &mverts[mface->v3];
+	v1 = &mverts[sample->orig_verts[0]];
+	v2 = &mverts[sample->orig_verts[1]];
+	v3 = &mverts[sample->orig_verts[2]];
 	
 	madd_v3_v3fl(loc, v1->co, sample->orig_weights[0]);
 	madd_v3_v3fl(loc, v2->co, sample->orig_weights[1]);
@@ -71,15 +71,6 @@ bool BKE_mesh_sample_eval(DerivedMesh *dm, const MSurfaceSample *sample, float l
 	normal_short_to_float_v3(vnor, v3->no);
 	madd_v3_v3fl(nor, vnor, sample->orig_weights[2]);
 	
-	if (mface->v4) {
-		v4 = &mverts[mface->v4];
-		
-		madd_v3_v3fl(loc, v4->co, sample->orig_weights[3]);
-		
-		normal_short_to_float_v3(vnor, v4->no);
-		madd_v3_v3fl(nor, vnor, sample->orig_weights[3]);
-	}
-	
 	normalize_v3(nor);
 	
 	return true;
@@ -138,25 +129,30 @@ static void mesh_sample_surface_random(const MSurfaceSampleInfo *info, MSurfaceS
 	MFace *mfaces = info->dm->getTessFaceArray(info->dm);
 	int totfaces = info->dm->getNumTessFaces(info->dm);
 	MFace *mface;
-	float sum, inv_sum;
+	float a, b;
 	
-	sample->orig_face = BLI_rng_get_int(info->rng) % totfaces;
+	mface = &mfaces[BLI_rng_get_int(info->rng) % totfaces];
 	
-	mface = &mfaces[sample->orig_face];
-	sample->orig_weights[0] = BLI_rng_get_float(info->rng);
-	sample->orig_weights[1] = BLI_rng_get_float(info->rng);
-	sample->orig_weights[2] = BLI_rng_get_float(info->rng);
-	sample->orig_weights[3] = mface->v4 ? BLI_rng_get_float(info->rng) : 0.0f;
+	if (mface->v4 && BLI_rng_get_int(info->rng) % 2 == 0) {
+		sample->orig_verts[0] = mface->v3;
+		sample->orig_verts[1] = mface->v4;
+		sample->orig_verts[2] = mface->v1;
+	}
+	else {
+		sample->orig_verts[0] = mface->v1;
+		sample->orig_verts[1] = mface->v2;
+		sample->orig_verts[2] = mface->v3;
+	}
 	
-	sum = sample->orig_weights[0] +
-	      sample->orig_weights[1] +
-	      sample->orig_weights[2] +
-	      sample->orig_weights[3];
-	inv_sum = sum > 0.0f ? 1.0f/sum : 0.0f;
-	sample->orig_weights[0] *= inv_sum;
-	sample->orig_weights[1] *= inv_sum;
-	sample->orig_weights[2] *= inv_sum;
-	sample->orig_weights[3] *= inv_sum;
+	a = BLI_rng_get_float(info->rng);
+	b = BLI_rng_get_float(info->rng);
+	if (a + b > 1.0f) {
+		a = 1.0f - a;
+		b = 1.0f - b;
+	}
+	sample->orig_weights[0] = 1.0f - (a + b);
+	sample->orig_weights[1] = a;
+	sample->orig_weights[2] = b;
 }
 
 void BKE_mesh_sample_surface_array(const MSurfaceSampleInfo *info, MSurfaceSample *samples, int totsample)
diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h
index aa72ba1..c075d1d 100644
--- a/source/blender/makesdna/DNA_meshdata_types.h
+++ b/source/blender/makesdna/DNA_meshdata_types.h
@@ -301,9 +301,10 @@ enum {
 };
 
 typedef struct MSurfaceSample {
-	int orig_face;
-	int pad;
-	float orig_weights[4];
+	unsigned int orig_verts[3];
+	float orig_weights[3];
+	int orig_poly;
+	unsigned int orig_loops[3];
 } MSurfaceSample;
 
 /* mvert->flag */
diff --git a/source/blender/makesrna/intern/rna_mesh_sample.c b/source/blender/makesrna/intern/rna_mesh_sample.c
index e5793a5..81a3f4b 100644
--- a/source/blender/makesrna/intern/rna_mesh_sample.c
+++ b/source/blender/makesrna/intern/rna_mesh_sample.c
@@ -59,10 +59,10 @@ static void rna_def_mesh_sample(BlenderRNA *brna)
 	RNA_def_struct_sdna(srna, "MSurfaceSample");
 	RNA_def_struct_ui_text(srna, "Mesh Sample", "Point on a mesh that follows deformation");
 
-	prop = RNA_def_property(srna, "face_index", PROP_INT, PROP_UNSIGNED);
-	RNA_def_property_int_sdna(prop, NULL, "orig_face");
+	prop = RNA_def_property(srna, "vertex_indices", PROP_INT, PROP_UNSIGNED);
+	RNA_def_property_int_sdna(prop, NULL, "orig_verts");
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-	RNA_def_property_ui_text(prop, "Face Index", "Index of the mesh face");
+	RNA_def_property_ui_text(prop, "Vertex Indices", "Index of the mesh vertices used for interpolation");
 }
 
 void RNA_def_mesh_sample(BlenderRNA *brna)




More information about the Bf-blender-cvs mailing list