[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54186] trunk/blender: Cycles Hair: Addition of render settings and static BVH strand width scaling

Stuart Broadfoot gbroadfoot at hotmail.com
Tue Jan 29 13:32:48 CET 2013


Revision: 54186
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54186
Author:   broadstu
Date:     2013-01-29 12:32:43 +0000 (Tue, 29 Jan 2013)
Log Message:
-----------
Cycles Hair: Addition of render settings and static BVH strand width scaling

Addition of a RNA function to toggle between the hair settings and rebuild the cache. This enables the usage of the render step, child number and full display percentage with f12 rendering.

A scaling to the strand radius has also been added for the static bvh. This only matches up with dynamic for uniform scaling.

A very small fix is included for multiple uvs/vertex colours when using child particles.

Modified Paths:
--------------
    trunk/blender/intern/cycles/blender/blender_curves.cpp
    trunk/blender/intern/cycles/render/object.cpp
    trunk/blender/source/blender/makesrna/intern/rna_particle.c

Modified: trunk/blender/intern/cycles/blender/blender_curves.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_curves.cpp	2013-01-29 12:03:38 UTC (rev 54185)
+++ trunk/blender/intern/cycles/blender/blender_curves.cpp	2013-01-29 12:32:43 UTC (rev 54186)
@@ -37,9 +37,10 @@
 void interp_weights(float t, float data[4], int type);
 float shaperadius(float shape, float root, float tip, float time);
 void InterpolateKeySegments(int seg, int segno, int key, int curve, float3 *keyloc, float *time, ParticleCurveData *CData, int interpolation);
-bool ObtainCacheParticleUV(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents, int uv_num);
-bool ObtainCacheParticleVcol(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents, int vcol_num);
-bool ObtainCacheParticleData(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents);
+void ToggleRender(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, BL::Scene *scene);
+bool ObtainCacheParticleUV(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents, bool background, int uv_num);
+bool ObtainCacheParticleVcol(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents, bool background, int vcol_num);
+bool ObtainCacheParticleData(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents, bool background);
 void ExportCurveTrianglePlanes(Mesh *mesh, ParticleCurveData *CData, int interpolation, bool use_smooth, int segments, float3 RotCam);
 void ExportCurveTriangleRibbons(Mesh *mesh, ParticleCurveData *CData, int interpolation, bool use_smooth, int segments);
 void ExportCurveTriangleGeometry(Mesh *mesh, ParticleCurveData *CData, int interpolation, bool use_smooth, int resolution, int segments);
@@ -151,7 +152,7 @@
 		curveinterp_v3_v3v3v3v3(keyloc, &ckey_loc1, &ckey_loc2, &ckey_loc3, &ckey_loc4, t);
 }
 
-bool ObtainCacheParticleData(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents)
+bool ObtainCacheParticleData(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents, bool background)
 {
 
 	int curvenum = 0;
@@ -176,12 +177,10 @@
 
 				int mi = clamp(b_psys.settings().material()-1, 0, mesh->used_shaders.size()-1);
 				int shader = mesh->used_shaders[mi];
-				int draw_step = b_psys.settings().draw_step();
+				int draw_step = background ? b_psys.settings().render_step() : b_psys.settings().draw_step();
 				int ren_step = (int)pow((float)2.0f,(float)draw_step);
-				/*b_psys.settings().render_step(draw_step);*/
-
 				int totparts = b_psys.particles.length();
-				int totchild = b_psys.child_particles.length() * b_psys.settings().draw_percentage() / 100;
+				int totchild = background ? b_psys.child_particles.length() : (int)((float)b_psys.child_particles.length() * (float)b_psys.settings().draw_percentage() / 100.0f);
 				int totcurves = totchild;
 				
 				if(use_parents || b_psys.settings().child_type() == 0)
@@ -240,7 +239,7 @@
 
 }
 
-bool ObtainCacheParticleUV(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents, int uv_num)
+bool ObtainCacheParticleUV(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents, bool background, int uv_num)
 {
 #if 0
 	int keyno = 0;
@@ -269,13 +268,10 @@
 #if 0
 				int mi = clamp(b_psys.settings().material()-1, 0, mesh->used_shaders.size()-1);
 				int shader = mesh->used_shaders[mi];
-				int draw_step = b_psys.settings().draw_step();
-				int ren_step = (int)pow((float)2.0f,(float)draw_step);
-				b_psys.settings().render_step(draw_step);
 #endif
 
 				int totparts = b_psys.particles.length();
-				int totchild = b_psys.child_particles.length() * b_psys.settings().draw_percentage() / 100;
+				int totchild = background ? b_psys.child_particles.length() : (int)((float)b_psys.child_particles.length() * (float)b_psys.settings().draw_percentage() / 100.0f);
 				int totcurves = totchild;
 				
 				if (use_parents || b_psys.settings().child_type() == 0)
@@ -314,7 +310,7 @@
 
 }
 
-bool ObtainCacheParticleVcol(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents, int vcol_num)
+bool ObtainCacheParticleVcol(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents, bool background, int vcol_num)
 {
 #if 0
 	int keyno = 0;
@@ -342,12 +338,9 @@
 #if 0
 				int mi = clamp(b_psys.settings().material()-1, 0, mesh->used_shaders.size()-1);
 				int shader = mesh->used_shaders[mi];
-				int draw_step = b_psys.settings().draw_step();
-				int ren_step = (int)pow((float)2.0f,(float)draw_step);
-				b_psys.settings().render_step(draw_step);
 #endif
 				int totparts = b_psys.particles.length();
-				int totchild = b_psys.child_particles.length() * b_psys.settings().draw_percentage() / 100;
+				int totchild = background ? b_psys.child_particles.length() : (int)((float)b_psys.child_particles.length() * (float)b_psys.settings().draw_percentage() / 100.0f);
 				int totcurves = totchild;
 				
 				if (use_parents || b_psys.settings().child_type() == 0)
@@ -386,6 +379,18 @@
 
 }
 
+void ToggleRender(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, BL::Scene *scene)
+{
+	BL::Object::modifiers_iterator b_mod;
+	for(b_ob->modifiers.begin(b_mod); b_mod != b_ob->modifiers.end(); ++b_mod) {
+		if ((b_mod->type() == b_mod->type_PARTICLE_SYSTEM) && (b_mod->show_viewport()) && (b_mod->show_render())) {
+			BL::ParticleSystemModifier psmd((const PointerRNA)b_mod->ptr);
+			BL::ParticleSystem b_psys((const PointerRNA)psmd.particle_system().ptr);
+			b_psys.ToggleRender(*scene, *b_ob);
+		}
+	}
+}
+
 void ExportCurveTrianglePlanes(Mesh *mesh, ParticleCurveData *CData, int interpolation, bool use_smooth, int segments, float3 RotCam)
 {
 	int vertexno = mesh->verts.size();
@@ -945,8 +950,11 @@
 
 	ParticleCurveData CData;
 
-	ObtainCacheParticleData(mesh, &b_mesh, &b_ob, &CData, use_parents);
+	if(!preview)
+		ToggleRender(mesh, &b_mesh, &b_ob, &b_scene);
 
+	ObtainCacheParticleData(mesh, &b_mesh, &b_ob, &CData, use_parents, !preview);
+
 	/* attach strands to mesh */
 	BL::Object b_CamOb = b_scene.camera();
 	float3 RotCam = make_float3(0.0f, 0.0f, 0.0f);
@@ -959,7 +967,7 @@
 
 	if(primitive == CURVE_TRIANGLES){
 		int vert_num = mesh->triangles.size() * 3;
-		ObtainCacheParticleUV(mesh, &b_mesh, &b_ob, &CData, use_parents, 0);
+		ObtainCacheParticleUV(mesh, &b_mesh, &b_ob, &CData, use_parents, !preview, 0);
 		if(triangle_method == CURVE_CAMERA_TRIANGLES) {
 			ExportCurveTrianglePlanes(mesh, &CData, interpolation, use_smooth, segments, RotCam);
 			ExportCurveTriangleUVs(mesh, &CData, interpolation, use_smooth, segments, vert_num, 1);
@@ -1021,7 +1029,7 @@
 				Attribute *attr_vcol = mesh->curve_attributes.add(
 					ustring(l->name().c_str()), TypeDesc::TypeColor, ATTR_ELEMENT_CURVE);
 
-				ObtainCacheParticleVcol(mesh, &b_mesh, &b_ob, &CData, use_parents, vcol_num);
+				ObtainCacheParticleVcol(mesh, &b_mesh, &b_ob, &CData, use_parents, !preview, vcol_num);
 
 				float3 *vcol = attr_vcol->data_float3();
 
@@ -1051,7 +1059,7 @@
 					else
 						attr = mesh->curve_attributes.add(name, TypeDesc::TypePoint,  ATTR_ELEMENT_CURVE);
 
-					ObtainCacheParticleUV(mesh, &b_mesh, &b_ob, &CData, use_parents, uv_num);
+					ObtainCacheParticleUV(mesh, &b_mesh, &b_ob, &CData, use_parents, !preview, uv_num);
 
 					float3 *uv = attr->data_float3();
 
@@ -1065,6 +1073,9 @@
 
 	}
 
+	if(!preview)
+		ToggleRender(mesh, &b_mesh, &b_ob, &b_scene);
+
 	mesh->compute_bounds();
 }
 

Modified: trunk/blender/intern/cycles/render/object.cpp
===================================================================
--- trunk/blender/intern/cycles/render/object.cpp	2013-01-29 12:03:38 UTC (rev 54185)
+++ trunk/blender/intern/cycles/render/object.cpp	2013-01-29 12:32:43 UTC (rev 54186)
@@ -84,12 +84,20 @@
 {
 	if(!mesh || tfm == transform_identity())
 		return;
-	
+
+	float3 c0 = transform_get_column(&tfm, 0);
+	float3 c1 = transform_get_column(&tfm, 1);
+	float3 c2 = transform_get_column(&tfm, 2);
+	float scalar = pow(fabsf(dot(cross(c0, c1), c2)), 1.0f/3.0f);
+
 	for(size_t i = 0; i < mesh->verts.size(); i++)
 		mesh->verts[i] = transform_point(&tfm, mesh->verts[i]);
 
-	for(size_t i = 0; i < mesh->curve_keys.size(); i++)
+	for(size_t i = 0; i < mesh->curve_keys.size(); i++) {
 		mesh->curve_keys[i].co = transform_point(&tfm, mesh->curve_keys[i].co);
+		/* scale for strand radius - only correct for uniform transforms*/
+		mesh->curve_keys[i].radius *= scalar;
+	}
 
 	/* store matrix to transform later. when accessing these as attributes we
 	 * do not want the transform to be applied for consistency between static

Modified: trunk/blender/source/blender/makesrna/intern/rna_particle.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_particle.c	2013-01-29 12:03:38 UTC (rev 54185)
+++ trunk/blender/source/blender/makesrna/intern/rna_particle.c	2013-01-29 12:32:43 UTC (rev 54186)
@@ -299,6 +299,7 @@
 	int path_nbr = 0;
 	int totpart;
 	int max_k = 0;
+	int step_nbr = 0;
 
 	if (particlesystem == NULL)
 		return;
@@ -306,14 +307,21 @@
 	part = particlesystem->part;
 	pars = particlesystem->particles;
 
+	if(particlesystem->renderdata) {
+		step_nbr = part->ren_step;
+		totchild = particlesystem->totchild;
+	}
+	else {
+		step_nbr = part->draw_step;
+		totchild = (int)((float)particlesystem->totchild * (float)(part->disp) / 100.0f);
+	}
+
 	if (part == NULL || pars == NULL || !psys_check_enabled(object, particlesystem))
 		return;
 	
 	if (part->ren_as == PART_DRAW_OB || part->ren_as == PART_DRAW_GR || part->ren_as == PART_DRAW_NOT)
 		return;
 
-	totchild = particlesystem->totchild * part->disp / 100;
-
 	/* can happen for disconnected/global hair */
 	if (part->type == PART_HAIR && !particlesystem->childcache)
 		totchild = 0;
@@ -324,7 +332,7 @@
 		return;
 
 	if (part->ren_as == PART_DRAW_PATH && particlesystem->pathcache)
-		path_nbr = (int)pow(2.0, part->draw_step);
+		path_nbr = (int)pow(2.0, step_nbr);
 
 	if (particle_no < totpart) {
 
@@ -373,7 +381,10 @@
 
 	part = particlesystem->part;
 
+	if(particlesystem->renderdata)
 		totchild = particlesystem->totchild;
+	else

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list