[Bf-blender-cvs] [b851063] cycles-ptex-49: Merge remote-tracking branch 'origin/master' into cycles-ptex-49

Nicholas Bishop noreply at git.blender.org
Tue Feb 10 22:39:00 CET 2015


Commit: b851063d24acca6bf94484218fe8df037fe07af7
Author: Nicholas Bishop
Date:   Tue Feb 10 22:38:30 2015 +0100
Branches: cycles-ptex-49
https://developer.blender.org/rBb851063d24acca6bf94484218fe8df037fe07af7

Merge remote-tracking branch 'origin/master' into cycles-ptex-49

Conflicts:
	intern/cycles/blender/blender_mesh.cpp

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



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

diff --cc intern/cycles/blender/blender_mesh.cpp
index 613d171,c5e2fa2..1f9f443
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@@ -258,85 -258,169 +258,246 @@@ static void create_mesh_volume_attribut
  		create_mesh_volume_attribute(b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_VELOCITY, frame);
  }
  
+ /* Create vertex color attributes. */
+ static void attr_create_vertex_color(Scene *scene,
+                                      Mesh *mesh,
+                                      BL::Mesh b_mesh,
+                                      const vector<int>& nverts)
+ {
+ 	BL::Mesh::tessface_vertex_colors_iterator l;
+ 	for(b_mesh.tessface_vertex_colors.begin(l); l != b_mesh.tessface_vertex_colors.end(); ++l) {
+ 		if(!mesh->need_attribute(scene, ustring(l->name().c_str())))
+ 			continue;
+ 
+ 		Attribute *attr = mesh->attributes.add(
+ 			ustring(l->name().c_str()), TypeDesc::TypeColor, ATTR_ELEMENT_CORNER_BYTE);
+ 
+ 		BL::MeshColorLayer::data_iterator c;
+ 		uchar4 *cdata = attr->data_uchar4();
+ 		size_t i = 0;
+ 
+ 		for(l->data.begin(c); c != l->data.end(); ++c, ++i) {
+ 			cdata[0] = color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color1())));
+ 			cdata[1] = color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color2())));
+ 			cdata[2] = color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color3())));
+ 
+ 			if(nverts[i] == 4) {
+ 				cdata[3] = cdata[0];
+ 				cdata[4] = cdata[2];
+ 				cdata[5] = color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color4())));
+ 				cdata += 6;
+ 			}
+ 			else
+ 				cdata += 3;
+ 		}
+ 	}
+ }
+ 
+ /* Create uv map attributes. */
+ static void attr_create_uv_map(Scene *scene,
+                                Mesh *mesh,
+                                BL::Mesh b_mesh,
+                                const vector<int>& nverts)
+ {
+ 	if (b_mesh.tessface_uv_textures.length() != 0) {
+ 		BL::Mesh::tessface_uv_textures_iterator l;
+ 
+ 		for(b_mesh.tessface_uv_textures.begin(l); l != b_mesh.tessface_uv_textures.end(); ++l) {
+ 			bool active_render = l->active_render();
+ 			AttributeStandard std = (active_render)? ATTR_STD_UV: ATTR_STD_NONE;
+ 			ustring name = ustring(l->name().c_str());
+ 
+ 			/* UV map */
+ 			if(mesh->need_attribute(scene, name) || mesh->need_attribute(scene, std)) {
+ 				Attribute *attr;
+ 
+ 				if(active_render)
+ 					attr = mesh->attributes.add(std, name);
+ 				else
+ 					attr = mesh->attributes.add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CORNER);
+ 
+ 				BL::MeshTextureFaceLayer::data_iterator t;
+ 				float3 *fdata = attr->data_float3();
+ 				size_t i = 0;
+ 
+ 				for(l->data.begin(t); t != l->data.end(); ++t, ++i) {
+ 					fdata[0] =  get_float3(t->uv1());
+ 					fdata[1] =  get_float3(t->uv2());
+ 					fdata[2] =  get_float3(t->uv3());
+ 					fdata += 3;
+ 
+ 					if(nverts[i] == 4) {
+ 						fdata[0] =  get_float3(t->uv1());
+ 						fdata[1] =  get_float3(t->uv3());
+ 						fdata[2] =  get_float3(t->uv4());
+ 						fdata += 3;
+ 					}
+ 				}
+ 			}
+ 
+ 			/* UV tangent */
+ 			std = (active_render)? ATTR_STD_UV_TANGENT: ATTR_STD_NONE;
+ 			name = ustring((string(l->name().c_str()) + ".tangent").c_str());
+ 
+ 			if(mesh->need_attribute(scene, name) || (active_render && mesh->need_attribute(scene, std))) {
+ 				std = (active_render)? ATTR_STD_UV_TANGENT_SIGN: ATTR_STD_NONE;
+ 				name = ustring((string(l->name().c_str()) + ".tangent_sign").c_str());
+ 				bool need_sign = (mesh->need_attribute(scene, name) || mesh->need_attribute(scene, std));
+ 
+ 				mikk_compute_tangents(b_mesh, &(*l), mesh, nverts, need_sign, active_render);
+ 			}
+ 		}
+ 	}
+ 	else if(mesh->need_attribute(scene, ATTR_STD_UV_TANGENT)) {
+ 		bool need_sign = mesh->need_attribute(scene, ATTR_STD_UV_TANGENT_SIGN);
+ 		mikk_compute_tangents(b_mesh, NULL, mesh, nverts, need_sign, true);
+ 	}
+ }
+ 
+ /* Create vertex pointiness attributes. */
+ static void attr_create_pointiness(Scene *scene,
+                                    Mesh *mesh,
+                                    BL::Mesh b_mesh)
+ {
+ 	if(mesh->need_attribute(scene, ATTR_STD_POINTINESS)) {
+ 		const int numverts = b_mesh.vertices.length();
+ 		Attribute *attr = mesh->attributes.add(ATTR_STD_POINTINESS);
+ 		float *data = attr->data_float();
+ 		int *counter = new int[numverts];
+ 		float *raw_data = new float[numverts];
+ 		float3 *edge_accum = new float3[numverts];
+ 
+ 		/* Calculate pointiness using single ring neighborhood. */
+ 		memset(counter, 0, sizeof(int) * numverts);
+ 		memset(raw_data, 0, sizeof(float) * numverts);
+ 		memset(edge_accum, 0, sizeof(float3) * numverts);
+ 		BL::Mesh::edges_iterator e;
+ 		int i = 0;
+ 		for(b_mesh.edges.begin(e); e != b_mesh.edges.end(); ++e, ++i) {
+ 			int v0 = b_mesh.edges[i].vertices()[0],
+ 				v1 = b_mesh.edges[i].vertices()[1];
+ 			float3 co0 = get_float3(b_mesh.vertices[v0].co()),
+ 				co1 = get_float3(b_mesh.vertices[v1].co());
+ 			float3 edge = normalize(co1 - co0);
+ 			edge_accum[v0] += edge;
+ 			edge_accum[v1] += -edge;
+ 			++counter[v0];
+ 			++counter[v1];
+ 		}
+ 		i = 0;
+ 		BL::Mesh::vertices_iterator v;
+ 		for(b_mesh.vertices.begin(v); v != b_mesh.vertices.end(); ++v, ++i) {
+ 			if(counter[i] > 0) {
+ 				float3 normal = get_float3(b_mesh.vertices[i].normal());
+ 				float angle = safe_acosf(dot(normal, edge_accum[i] / counter[i]));
+ 				raw_data[i] = angle * M_1_PI_F;
+ 			}
+ 			else {
+ 				raw_data[i] = 0.0f;
+ 			}
+ 		}
+ 
+ 		/* Blur vertices to approximate 2 ring neighborhood. */
+ 		memset(counter, 0, sizeof(int) * numverts);
+ 		memcpy(data, raw_data, sizeof(float) * numverts);
+ 		i = 0;
+ 		for(b_mesh.edges.begin(e); e != b_mesh.edges.end(); ++e, ++i) {
+ 			int v0 = b_mesh.edges[i].vertices()[0],
+ 				v1 = b_mesh.edges[i].vertices()[1];
+ 			data[v0] += raw_data[v1];
+ 			data[v1] += raw_data[v0];
+ 			++counter[v0];
+ 			++counter[v1];
+ 		}
+ 		for(i = 0; i < numverts; ++i) {
+ 			data[i] /= counter[i] + 1;
+ 		}
+ 
+ 		delete [] counter;
+ 		delete [] raw_data;
+ 		delete [] edge_accum;
+ 	}
+ }
+ 
  /* Create Mesh */
  
 +static const int quad_split_pattern[2][2][3] = {
 +	/* Note that first pattern is the one used for triangle inputs */
 +	{{0, 1, 2}, {0, 2, 3}},
 +	{{0, 1, 3}, {2, 3, 1}}
 +};
 +
 +static int quad_split_pattern_index(const float3 &a, 
 +									const float3 &b, 
 +									const float3 &c, 
 +									const float3 &d)
 +{
 +	if (is_zero(cross(b - a, c - a)) || is_zero(cross(c - a, d - a))) {
 +		return 1;
 +	}
 +	else {
 +		return 0;
 +	}
 +}
 +
- static void mesh_add_ptex_face_attributes(Mesh *mesh, BL::Mesh b_mesh,
- 										  const vector<int> &nverts,
- 										  const vector<int> &face_split_pattern)
++static void attr_create_ptex_face_attributes(Mesh *mesh, BL::Mesh b_mesh,
++											 const vector<int> &nverts,
++											 const vector<int> &face_split_pattern)
 +{
 +	BL::Mesh::tessfaces_iterator f;
 +	Attribute *face_id_attr = mesh->attributes.add(ATTR_STD_PTEX_UV);
 +	mesh->attributes.reserve();
 +
 +	float3 (*dst)[3] = (float3(*)[3])face_id_attr->data_float3();
 +	size_t cur_tri = 0;
 +	size_t cur_tessface = 0;
 +
 +	for (b_mesh.tessfaces.begin(f); f != b_mesh.tessfaces.end(); ++f) {
 +		BL::PtexTessFace ptex = f->ptex_tess_face();
 +		if (!ptex) break;
 +		const int num_triangles = (nverts[cur_tessface] == 4) ? 2 : 1;
 +		const int spi = face_split_pattern[cur_tessface];
 +
 +		for (int i = 0; i < num_triangles; i++) {
 +			for (int j = 0; j < 3; j++) {
 +				const int ci = quad_split_pattern[spi][i][j];
 +
 +				dst[cur_tri][j] = make_float3(ptex.uv()[ci * 2 + 0],
 +											  ptex.uv()[ci * 2 + 1],
 +											  ptex.id());
 +			}
 +			cur_tri++;
 +		}
 +
 +		cur_tessface++;
 +	}
 +}
 +
- static void mesh_add_ptex_layer_data(Scene *scene, Mesh *mesh, BL::Mesh b_mesh)
++static void attr_create_ptex_layer_data(Scene *scene, Mesh *mesh, BL::Mesh b_mesh)
 +{
 +	BL::Mesh::loop_ptex_iterator l;
 +	for (b_mesh.loop_ptex.begin(l); l != b_mesh.loop_ptex.end(); ++l) {
 +		const ustring layer_name = ustring(l->name());
 +		if (mesh->need_attribute(scene, layer_name)) {
 +			Attribute *attr = mesh->attributes.add(layer_name,
 +												   TypeDesc::TypeFloat,
 +												   ATTR_ELEMENT_MESH);
 +			//mesh->attributes.reserve();
 +			float *slot = attr->data_float();
 +			bool is_float;
 +			bool is_linear;
 +			// TODO
 +
 +			BL::Image image = l->image();
 +
 +			// Other alternative is: get data, pack new image here
 +			(*slot) = scene->image_manager->add_image
 +				("TODO", image.ptr.data, false, 1,
 +				 is_float, is_linear, INTERPOLATION_LINEAR, true);
 +		}
 +	}
 +}
 +
  static void create_mesh(Scene *scene, Mesh *mesh, BL::Mesh b_mesh, const vector<uint>& used_shaders)
  {
  	/* count vertices and faces */
@@@ -438,159 -517,12 +599,14 @@@
  		nverts[fi] = n;
  	}
  
- 	/* Add Ptex data if needed */
- 	mesh_add_ptex_face_attributes(mesh, b_mesh, nverts, face_split_pattern);
- 	mesh_add_ptex_layer_data(scene, mesh, b_mesh);
- 
- 	/* create vertex color attributes */
- 	{
- 		BL::Mesh::tessface_vertex_colors_iterator l;
- 
- 		for(b_mesh.tessface_vertex_colors.begin(l); l != b_mesh.tessface_vertex_colors.end(); ++l) {
- 			if(!mesh->need_attribute(scene, ustring(l->name().c_str())))
- 				continue;
- 
- 			Attribute *attr = mesh->attributes.add(
- 				ustring(l->name().c_str()), TypeDesc::TypeColor, ATTR_ELEMENT_CORNER_BYTE);
- 
- 			BL::MeshColorLayer::data_iterator c;
- 			uchar4 *cdata = attr->data_uchar4();
- 			size_t i = 0;
- 
- 			for(l->data.begin(c); c != l->data.end(); ++c, ++i) {
- 				cdata[0] = color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color1())));
- 				cdata[1] = color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color2())));
- 				cdata[2] = color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color3())));
- 
- 				if(nverts[i] == 4) {
- 					cdata[3] = cdata[0];
- 					cdata[4] = cdata[2];
- 					cdata[5] = color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color4())));
- 					cdata += 6;
- 				}
- 				else
- 					cdata += 3;
- 			}
- 		}
- 	}
- 
- 	/* create vertex pointiness attributes */
- 	/* TODO(sergey): Consider moving all the attribute creation

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list