[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54256] trunk/blender/intern/cycles: Cycles Hair: Fixed hair shape and inclusion of multiple attributes for triangle primitives

Stuart Broadfoot gbroadfoot at hotmail.com
Sat Feb 2 02:49:58 CET 2013


Revision: 54256
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54256
Author:   broadstu
Date:     2013-02-02 01:49:57 +0000 (Sat, 02 Feb 2013)
Log Message:
-----------
Cycles Hair: Fixed hair shape and inclusion of multiple attributes for triangle primitives

When using triangle primitives this fix enables 'closed tip'. 

UVs and vertex colours are added when using triangle primitives for hair.

Two new preset modes have also been included to allow easy access to curves and triangle planes.

Modified Paths:
--------------
    trunk/blender/intern/cycles/blender/addon/properties.py
    trunk/blender/intern/cycles/blender/blender_curves.cpp
    trunk/blender/intern/cycles/render/curves.h

Modified: trunk/blender/intern/cycles/blender/addon/properties.py
===================================================================
--- trunk/blender/intern/cycles/blender/addon/properties.py	2013-02-02 00:34:34 UTC (rev 54255)
+++ trunk/blender/intern/cycles/blender/addon/properties.py	2013-02-02 01:49:57 UTC (rev 54256)
@@ -66,9 +66,11 @@
 
 enum_curve_presets = (
     ('CUSTOM', "Custom", "Set general parameters"),
-    ('TANGENT_SHADING', "Tangent Normal", "Use planar geometry and tangent normals"),
-    ('TRUE_NORMAL', "True Normal", "Use true normals (good for thin strands)"),
-    ('ACCURATE_PRESET', "Accurate", "Use best settings (suitable for glass materials)"),
+    ('FAST_PLANES', "Fast Planes", "Use camera facing triangles (fast but memory intensive)"),
+    ('TANGENT_SHADING', "Tangent Normal", "Use planar line segments and tangent normals"),
+    ('TRUE_NORMAL', "True Normal", "Use true normals with line segments(good for thin strands)"),
+    ('ACCURATE_PRESET', "Accurate", "Use best line segment settings (suitable for glass materials)"),
+    ('SMOOTH_CURVES', "Smooth Curves", "Use smooth cardinal curves (slowest)"),
     )
 
 enum_curve_primitives = (

Modified: trunk/blender/intern/cycles/blender/blender_curves.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_curves.cpp	2013-02-02 00:34:34 UTC (rev 54255)
+++ trunk/blender/intern/cycles/blender/blender_curves.cpp	2013-02-02 01:49:57 UTC (rev 54256)
@@ -41,11 +41,12 @@
 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 ExportCurveSegments(Mesh *mesh, ParticleCurveData *CData, int interpolation, int segments);
 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);
-void ExportCurveSegments(Mesh *mesh, ParticleCurveData *CData, int interpolation, int segments);
-void ExportCurveTriangleUVs(Mesh *mesh, ParticleCurveData *CData, int interpolation, bool use_smooth, int segments, int vert_offset, int resol);
+void ExportCurveTriangleUV(Mesh *mesh, ParticleCurveData *CData, int interpolation, int segments, int vert_offset, int resol, float3 *uvdata);
+void ExportCurveTriangleVcol(Mesh *mesh, ParticleCurveData *CData, int interpolation, int segments, int vert_offset, int resol, float3 *fdata);
 
 ParticleCurveData::ParticleCurveData()
 {
@@ -428,13 +429,13 @@
 
 					float radius = shaperadius(CData->psys_shape[sys], CData->psys_rootradius[sys], CData->psys_tipradius[sys], time);
 
-					if(CData->psys_closetip[sys] && (subv == segments) && (curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1))
+					if((curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 2) && (subv == segments))
+						radius = shaperadius(CData->psys_shape[sys], CData->psys_rootradius[sys], CData->psys_tipradius[sys], 0.95f);
+
+					if(CData->psys_closetip[sys] && (subv == segments) && (curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 2))
 						radius = shaperadius(CData->psys_shape[sys], CData->psys_rootradius[sys], 0.0f, 0.95f);
 
-					if((curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1) && (subv == segments))
-						radius = shaperadius(CData->psys_shape[sys], CData->psys_rootradius[sys], CData->psys_tipradius[sys], 0.95f);
-
-					xbasis = normalize(cross(v1,RotCam - ickey_loc));
+					xbasis = normalize(cross(RotCam - ickey_loc,v1));
 					float3 ickey_loc_shfl = ickey_loc - radius * xbasis;
 					float3 ickey_loc_shfr = ickey_loc + radius * xbasis;
 					mesh->verts.push_back(ickey_loc_shfl);
@@ -542,12 +543,12 @@
 
 					float radius = shaperadius(CData->psys_shape[sys], CData->psys_rootradius[sys], CData->psys_tipradius[sys], time);
 
-					if(CData->psys_closetip[sys] && (subv == segments) && (curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1))
+					if((curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 2) && (subv == segments))
+						radius = shaperadius(CData->psys_shape[sys], CData->psys_rootradius[sys], CData->psys_tipradius[sys], 0.95f);
+
+					if(CData->psys_closetip[sys] && (subv == segments) && (curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 2))
 						radius = shaperadius(CData->psys_shape[sys], CData->psys_rootradius[sys], 0.0f, 0.95f);
 
-					if((curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1) && (subv == segments))
-						radius = shaperadius(CData->psys_shape[sys], CData->psys_rootradius[sys], CData->psys_tipradius[sys], 0.95f);
-
 					float3 ickey_loc_shfl = ickey_loc - radius * xbasis;
 					float3 ickey_loc_shfr = ickey_loc + radius * xbasis;
 					mesh->verts.push_back(ickey_loc_shfl);
@@ -659,12 +660,12 @@
 
 					float radius = shaperadius(CData->psys_shape[sys], CData->psys_rootradius[sys], CData->psys_tipradius[sys], time);
 
-					if(CData->psys_closetip[sys] && (subv == segments) && (curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1))
+					if((curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 2) && (subv == segments))
+						radius = shaperadius(CData->psys_shape[sys], CData->psys_rootradius[sys], CData->psys_tipradius[sys], 0.95f);
+
+					if(CData->psys_closetip[sys] && (subv == segments) && (curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 2))
 						radius = shaperadius(CData->psys_shape[sys], CData->psys_rootradius[sys], 0.0f, 0.95f);
 
-					if((curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1) && (subv == segments))
-						radius = shaperadius(CData->psys_shape[sys], CData->psys_rootradius[sys], CData->psys_tipradius[sys], 0.95f);
-
 					float angle = 2 * M_PI_F / (float)resolution;
 					for(int section = 0 ; section < resolution; section++) {
 						float3 ickey_loc_shf = ickey_loc + radius * (cosf(angle * section) * xbasis + sinf(angle * section) * ybasis);
@@ -764,17 +765,14 @@
 	}
 }
 
-void ExportCurveTriangleUVs(Mesh *mesh, ParticleCurveData *CData, int interpolation, bool use_smooth, int segments, int vert_offset, int resol)
+void ExportCurveTriangleUV(Mesh *mesh, ParticleCurveData *CData, int interpolation, int segments, int vert_offset, int resol, float3 *uvdata)
 {
+	if(uvdata == NULL)
+		return;
+
 	float time = 0.0f;
 	float prevtime = 0.0f;
 
-	Attribute *attr = mesh->attributes.find(ATTR_STD_UV);
-	if (attr == NULL)
-		return;
-		
-	float3 *uvdata = attr->data_float3();
-
 	int vertexindex = vert_offset;
 
 	for( int sys = 0; sys < CData->psys_firstcurve.size() ; sys++) {
@@ -823,6 +821,58 @@
 	}
 
 }
+
+void ExportCurveTriangleVcol(Mesh *mesh, ParticleCurveData *CData, int interpolation, int segments, int vert_offset, int resol, float3 *fdata)
+{
+	if(fdata == NULL)
+		return;
+
+	float time = 0.0f;
+	float prevtime = 0.0f;
+
+	int vertexindex = vert_offset;
+
+	for( int sys = 0; sys < CData->psys_firstcurve.size() ; sys++) {
+		for( int curve = CData->psys_firstcurve[sys]; curve < CData->psys_firstcurve[sys] + CData->psys_curvenum[sys] ; curve++) {
+
+			for( int curvekey = CData->curve_firstkey[curve]; curvekey < CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1; curvekey++) {
+
+				int subv = 1;
+
+				if (curvekey == CData->curve_firstkey[curve])
+					subv = 0;
+				
+				for (; subv <= segments; subv++) {
+
+					float3 ickey_loc = make_float3(0.0f,0.0f,0.0f);
+
+					InterpolateKeySegments(subv, segments, curvekey, curve, &ickey_loc, &time, CData , interpolation);
+
+					if(subv!=0) {
+						for(int section = 0 ; section < resol; section++) {
+							fdata[vertexindex] = color_srgb_to_scene_linear(CData->curve_vcol[curve]);
+							vertexindex++;
+							fdata[vertexindex] = color_srgb_to_scene_linear(CData->curve_vcol[curve]);
+							vertexindex++;
+							fdata[vertexindex] = color_srgb_to_scene_linear(CData->curve_vcol[curve]);
+							vertexindex++;
+							fdata[vertexindex] = color_srgb_to_scene_linear(CData->curve_vcol[curve]);
+							vertexindex++;
+							fdata[vertexindex] = color_srgb_to_scene_linear(CData->curve_vcol[curve]);
+							vertexindex++;
+							fdata[vertexindex] = color_srgb_to_scene_linear(CData->curve_vcol[curve]);
+							vertexindex++;
+						}
+					}
+
+					prevtime = time;
+				}
+			}
+		}
+	}
+
+}
+
 /* Hair Curve Sync */
 
 void BlenderSync::sync_curve_settings()
@@ -868,6 +918,13 @@
 		curve_system_manager->use_joined = false;
 
 		switch(preset) {
+			case CURVE_FAST_PLANES:
+				/*camera facing planes*/
+				curve_system_manager->primitive = CURVE_TRIANGLES;
+				curve_system_manager->triangle_method = CURVE_CAMERA_TRIANGLES;
+				curve_system_manager->use_smooth = true;
+				curve_system_manager->resolution = 1;
+				break;
 			case CURVE_TANGENT_SHADING:
 				/*tangent shading*/
 				curve_system_manager->line_method = CURVE_UNCORRECTED;
@@ -895,6 +952,12 @@
 				curve_system_manager->use_tangent_normal_geometry = false;
 				curve_system_manager->use_tangent_normal_correction = false;
 				break;
+			case CURVE_SMOOTH_CURVES:
+				/*Cardinal curves preset*/
+				curve_system_manager->primitive = CURVE_SEGMENTS;
+				curve_system_manager->use_backfacing = true;
+				curve_system_manager->subdivisions = 4;
+				break;
 		}
 		
 	}
@@ -945,6 +1008,9 @@
 	bool use_smooth = scene->curve_system_manager->use_smooth;
 	bool use_parents = scene->curve_system_manager->use_parents;
 	bool export_tgs = scene->curve_system_manager->use_joined;
+	size_t vert_num = mesh->verts.size();
+	size_t tri_num = mesh->triangles.size();
+	int used_res = 1;
 
 	/* extract particle hair data - should be combined with connecting to mesh later*/
 
@@ -955,7 +1021,7 @@
 
 	ObtainCacheParticleData(mesh, &b_mesh, &b_ob, &CData, use_parents, !preview);
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list