[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53556] trunk/blender: Added vertex color attributes (currently limited to one) and UVs included for triangle mesh hair.

Stuart Broadfoot gbroadfoot at hotmail.com
Fri Jan 4 13:44:41 CET 2013


Revision: 53556
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53556
Author:   broadstu
Date:     2013-01-04 12:44:38 +0000 (Fri, 04 Jan 2013)
Log Message:
-----------
Added vertex color attributes (currently limited to one) and UVs included for triangle mesh hair.

I have also included a small speedup for the intersection test.

Modified Paths:
--------------
    trunk/blender/intern/cycles/blender/addon/ui.py
    trunk/blender/intern/cycles/blender/blender_curves.cpp
    trunk/blender/intern/cycles/kernel/kernel_bvh.h
    trunk/blender/intern/cycles/render/curves.h
    trunk/blender/source/blender/makesrna/intern/rna_particle.c

Modified: trunk/blender/intern/cycles/blender/addon/ui.py
===================================================================
--- trunk/blender/intern/cycles/blender/addon/ui.py	2013-01-04 11:02:35 UTC (rev 53555)
+++ trunk/blender/intern/cycles/blender/addon/ui.py	2013-01-04 12:44:38 UTC (rev 53556)
@@ -975,7 +975,7 @@
         
             if cscene.primitive == 'TRIANGLES':
                 layout.prop(cscene, "triangle_method", text="Method")
-                if cscene.triangle_method == 'TESSELATED':
+                if cscene.triangle_method == 'TESSELLATED':
                     layout.prop(cscene, "resolution", text="Resolution")
                 layout.prop(cscene, "use_smooth", text="Smooth")
             elif cscene.primitive == 'LINE_SEGMENTS':

Modified: trunk/blender/intern/cycles/blender/blender_curves.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_curves.cpp	2013-01-04 11:02:35 UTC (rev 53555)
+++ trunk/blender/intern/cycles/blender/blender_curves.cpp	2013-01-04 12:44:38 UTC (rev 53556)
@@ -38,11 +38,14 @@
 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 ObtainParticleData(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData);
+bool ObtainCacheParticleUV(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents);
+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 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);
 
 ParticleCurveData::ParticleCurveData()
 {
@@ -61,6 +64,7 @@
 	curve_keynum.clear();
 	curve_length.clear();
 	curve_uv.clear();
+	curve_vcol.clear();
 
 	curvekey_co.clear();
 	curvekey_time.clear();
@@ -291,8 +295,6 @@
 				if(!use_parents && !(b_psys.settings().child_type() == 0))
 					pa_no = totparts;
 
-				BL::ParticleSystem::particles_iterator b_pa;
-				b_psys.particles.begin(b_pa);
 				for(; pa_no < totparts+totchild; pa_no++) {
 
 					CData->curve_firstkey.push_back(keyno);
@@ -314,6 +316,63 @@
 					}
 					CData->curve_length.push_back(curve_length);
 
+					curvenum++;
+
+				}
+			}
+
+		}
+	}
+
+	return true;
+
+}
+
+bool ObtainCacheParticleUV(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents)
+{
+	int keyno = 0;
+
+	if(!(mesh && b_mesh && b_ob && CData))
+		return false;
+
+	Transform tfm = get_transform(b_ob->matrix_world());
+	Transform itfm = transform_quick_inverse(tfm);
+
+	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);
+
+			BL::ParticleSettings b_part((const PointerRNA)b_psys.settings().ptr);
+
+			if((b_psys.settings().render_type()==BL::ParticleSettings::render_type_PATH)&&(b_psys.settings().type()==BL::ParticleSettings::type_HAIR)) {
+
+				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);*/
+
+				int totparts = b_psys.particles.length();
+				int totchild = b_psys.child_particles.length() * b_psys.settings().draw_percentage() / 100;
+				int totcurves = totchild;
+				
+				if (use_parents || b_psys.settings().child_type() == 0)
+					totcurves += totparts;
+
+				if (totcurves == 0)
+					continue;
+
+				int pa_no = 0;
+				if(!use_parents && !(b_psys.settings().child_type() == 0))
+					pa_no = totparts;
+
+				BL::ParticleSystem::particles_iterator b_pa;
+				b_psys.particles.begin(b_pa);
+				for(; pa_no < totparts+totchild; pa_no++) {
+
 					/*add uvs*/
 					BL::Mesh::tessface_uv_textures_iterator l;
 					b_mesh->tessface_uv_textures.begin(l);
@@ -326,8 +385,73 @@
 					if(pa_no < totparts && b_pa != b_psys.particles.end())
 						++b_pa;
 
-					curvenum++;
+				}
+			}
 
+		}
+	}
+
+	return true;
+
+}
+
+bool ObtainCacheParticleVcol(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool use_parents, int vcol_num)
+{
+	int keyno = 0;
+
+	if(!(mesh && b_mesh && b_ob && CData))
+		return false;
+
+	Transform tfm = get_transform(b_ob->matrix_world());
+	Transform itfm = transform_quick_inverse(tfm);
+
+	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);
+
+			BL::ParticleSettings b_part((const PointerRNA)b_psys.settings().ptr);
+
+			if((b_psys.settings().render_type()==BL::ParticleSettings::render_type_PATH)&&(b_psys.settings().type()==BL::ParticleSettings::type_HAIR)) {
+
+				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);*/
+
+				int totparts = b_psys.particles.length();
+				int totchild = b_psys.child_particles.length() * b_psys.settings().draw_percentage() / 100;
+				int totcurves = totchild;
+				
+				if (use_parents || b_psys.settings().child_type() == 0)
+					totcurves += totparts;
+
+				if (totcurves == 0)
+					continue;
+
+				int pa_no = 0;
+				if(!use_parents && !(b_psys.settings().child_type() == 0))
+					pa_no = totparts;
+
+				BL::ParticleSystem::particles_iterator b_pa;
+				b_psys.particles.begin(b_pa);
+				for(; pa_no < totparts+totchild; pa_no++) {
+
+					/*add uvs*/
+					BL::Mesh::tessface_vertex_colors_iterator l;
+					b_mesh->tessface_vertex_colors.begin(l);
+
+					float3 vcol = make_float3(0.0f, 0.0f, 0.0f);
+					if(b_mesh->tessface_vertex_colors.length())
+						b_psys.mcol_on_emitter(psmd, *b_pa, pa_no, vcol_num, &vcol.x);
+					CData->curve_vcol.push_back(vcol);
+
+					if(pa_no < totparts && b_pa != b_psys.particles.end())
+						++b_pa;
+
 				}
 			}
 
@@ -355,10 +479,10 @@
 
 				if(curvekey == CData->curve_firstkey[curve]) {
 					subv = 0;
-					v1 = CData->curvekey_co[curvekey+2] - CData->curvekey_co[curvekey];
+					v1 = CData->curvekey_co[min(curvekey+2,CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1)] - CData->curvekey_co[curvekey];
 				}
-				else if(curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 2)
-					v1 = CData->curvekey_co[curvekey] - CData->curvekey_co[curvekey - 2];
+				else if(curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1)
+					v1 = CData->curvekey_co[curvekey] - CData->curvekey_co[max(curvekey - 2, CData->curve_firstkey[curve])];
 				else 
 					v1 = CData->curvekey_co[curvekey + 1] - CData->curvekey_co[curvekey - 1];
 
@@ -375,10 +499,10 @@
 
 					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] - 2))
+					if(CData->psys_closetip[sys] && (subv == segments) && (curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1))
 						radius = shaperadius(CData->psys_shape[sys], CData->psys_rootradius[sys], 0.0f, 0.95f);
 
-					if((curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 2) && (subv == segments))
+					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));
@@ -404,7 +528,6 @@
 	mesh->attributes.remove(ATTR_STD_FACE_NORMAL);
 
 	/* texture coords still needed */
-
 }
 
 void ExportCurveTriangleRibbons(Mesh *mesh, ParticleCurveData *CData, int interpolation, bool use_smooth, int segments)
@@ -428,12 +551,12 @@
 				float3 v2;
 
 				if(curvekey == CData->curve_firstkey[curve]) {
-					v1 = CData->curvekey_co[curvekey+2] - CData->curvekey_co[curvekey+1];
+					v1 = CData->curvekey_co[min(curvekey+2,CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1)] - CData->curvekey_co[curvekey+1];
 					v2 = CData->curvekey_co[curvekey+1] - CData->curvekey_co[curvekey];
 				}
-				else if(curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 2) {
+				else if(curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1) {
 					v1 = CData->curvekey_co[curvekey] - CData->curvekey_co[curvekey-1];
-					v2 = CData->curvekey_co[curvekey-1] - CData->curvekey_co[curvekey-2];
+					v2 = CData->curvekey_co[curvekey-1] - CData->curvekey_co[max(curvekey-2,CData->curve_firstkey[curve])];
 				}
 				else {
 					v1 = CData->curvekey_co[curvekey+1] - CData->curvekey_co[curvekey];
@@ -457,12 +580,12 @@
 
 				if(curvekey == CData->curve_firstkey[curve]) {
 					subv = 0;
-					v1 = CData->curvekey_co[curvekey+2] - CData->curvekey_co[curvekey+1];
+					v1 = CData->curvekey_co[min(curvekey+2,CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1)] - CData->curvekey_co[curvekey+1];

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list