Hair Curve Deformer

I was sick for a couple days this week and decided to create a instancer/deformer plugin for maya. I’ve based this on the maya hair system, at first I got it functioning with one hair and one instance object, which was not too difficult. I drive the deformation by building a new transformation matrix for each point of the instance object, based on the relative height on the hair curve and the tangents of where it was birthed on the mesh. This keeps it from twisting relative to the mesh during complex motions. After I proved this could work I put together a polygon duplicator, I was expecting there to be a button for this, there isn’t. Instead I had to have the plugin record all the data maya uses to create a mesh from scratch, re-append the data as I built each instance and then create the mesh after all my calculations were done. Although this sucked, I had to do something similar last month to rebuild meshes in mental ray so it wasn’t so bad. Here’s a sample video:

			MArrayDataHandle curve_array_handle = data.inputArrayValue(aInCurve);
			int numCurves = curve_array_handle.elementCount ();

			num_polys = pre_num_polys*numCurves;
			num_verts = pre_num_verts*numCurves;

			for (int curveNum = 0; curveNum < numCurves; curveNum++)

				MDataHandle id_handle= curve_array_handle.inputValue();
				MObject current_curve_obj =id_handle.asNurbsCurve();
				MFnNurbsCurve curveFn( current_curve_obj);
				MPoint inst_pos;
				MVector inst_normal;
				MPointOnMesh meshPt;
				MFloatVector inst_tangent;
				intersector.getClosestPoint(inst_pos, meshPt);
				int id = meshPt.faceIndex();

				MFloatVectorArray inst_tangent_array;
				int len_inst_tangent_array=inst_tangent_array.length();
				for( int a = 0; a < len_inst_tangent_array; a++ )
							inst_tangent += inst_tangent_array[a];
				inst_tangent/= len_inst_tangent_array;
				while (featherIt.isDone() == false)
						int index = featherIt.index();
						MPoint current_point = pre_feath_points[index];
						MVector curve_deriv;
						MFloatVector inst_binorm;
						MPoint curve_pos;
						double arc_len = curveFn.length();
						double hi_low_ratio = (current_point.y-lowest_point)/(highest_point - lowest_point);
						double curve_param = curveFn.findParamFromLength(hi_low_ratio*arc_len);
						inst_binorm = inst_tangent^curve_deriv;
						MVector cross_tangent =  inst_binorm^curve_deriv;
						double matrix[4][4] = {{inst_binorm.x,inst_binorm.y,inst_binorm.z,0}, {curve_deriv.x,curve_deriv.y,curve_deriv.z,0}, {cross_tangent.x,cross_tangent.y,cross_tangent.z,0},{curve_pos.x,curve_pos.y,curve_pos.z,0}};
						MMatrix inst_matrix(matrix);
						MPoint flattened_point(current_point.x,0.0,current_point.z);
						feath_points.append(flattened_point* inst_matrix);;
				for (int i = 0; i < pre_connected_verts.length();i++)
					int con_vert_print = pre_connected_verts[i]+(pre_num_verts*curveNum);
				for (int i = 0; i < pre_poly_counts.length();i++)
				for (int i = 0; i < pre_u_array.length();i++)

			MFnMeshData meshDataFn;
			MObject newMeshObj = meshDataFn.create();
			MFnMesh newMeshFn;

			outMeshDataHandle.setMObject(newMeshObj );

		//				MGlobal::displ




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: