void Exporter::RecursiveJointExtraction(MFnTransform& joint, int parentIndex){

	Bone output;
	output.parent = parentIndex;

	output.invBindPose = joint.transformation().asMatrixInverse().matrix;

	MItDependencyNodes matIt(MFn::kAnimCurve);
	while (!matIt.isDone())
	{
		MFnAnimCurve animCurve(matIt.item());

		if (!strcmp(animCurve.name().substring(0, joint.name().length() - 1).asChar(), joint.name().asChar())){

			cout << animCurve.name().asChar() << endl;
			std::string type = animCurve.name().substring(joint.name().length(), animCurve.name().length()).asChar();
			output.frames.resize(animCurve.time(animCurve.numKeys() - 1).value());
			for (int i = 0; i < output.frames.size(); i++)
			{
				MTime time;
				time.setValue(i);
				output.frames[i].time = time.value();
				if (!strcmp(type.c_str(), "_translateX")){
					cout << animCurve.evaluate(time) << endl;
					output.frames[i].trans.x = animCurve.evaluate(time);
				}
				if (!strcmp(type.c_str(), "_translateY")){
					cout << animCurve.evaluate(time) << endl;
					output.frames[i].trans.y = animCurve.evaluate(time);
				}
				if (!strcmp(type.c_str(), "_translateZ")){
					cout << animCurve.evaluate(time) << endl;
					output.frames[i].trans.z = animCurve.evaluate(time);
				}
				if (!strcmp(type.c_str(), "_rotateX")){
					cout << animCurve.evaluate(time) << endl;
					output.frames[i].rot.x = animCurve.evaluate(time);
				}
				if (!strcmp(type.c_str(), "_rotateY")){
					cout << animCurve.evaluate(time) << endl;
					output.frames[i].rot.y = animCurve.evaluate(time);
				}
				if (!strcmp(type.c_str(), "_rotateZ")){
					cout << animCurve.evaluate(time) << endl;
					output.frames[i].rot.z = animCurve.evaluate(time);
				}
			}
		}
		matIt.next();
	}


	scene_.skeleton.push_back(output);
	int children = joint.childCount();
	int parent = scene_.skeleton.size() - 1;
	for (int i = 0; i < children; i++)
		RecursiveJointExtraction(MFnTransform(joint.child(i)), parent);

};
Beispiel #2
0
void GDExporter::GetUniqueRenderContexts( MFnTransform& transform, std::list<GDRenderContext>& uniqueContexts )
{
	for(unsigned int i = 0; i < transform.childCount(); ++i)
	{
		if( transform.child(i).apiType() == MFn::kMesh )
		{
			MFnMesh childMesh( transform.child(i) );

			if( childMesh.isIntermediateObject() )
				continue;

			MDagPath meshPath;
			childMesh.getPath(meshPath);
			MFnDependencyNode depNode(meshPath.node());
			MStatus fpResult;
			MPlug gdRenderContextPlug = childMesh.findPlug("GDRenderContext", &fpResult);

			if( fpResult != MS::kSuccess )
				continue;

			GDRenderContext newContext(gdRenderContextPlug);

			bool bFound = false;
			std::list<GDRenderContext>::iterator uniqueIter = uniqueContexts.begin();
			for(; uniqueIter != uniqueContexts.end(); ++uniqueIter )
			{
				if( (*uniqueIter) == newContext )
				{
					bFound = true;
					break;
				}
			}

			if( bFound == false )
				uniqueContexts.push_back( newContext );
			else
				gdRenderContextPlug.child(0).setValue( (*uniqueIter).name.c_str() );
		}
		else if( transform.child(i).apiType() == MFn::kTransform )
		{
			MFnTransform childTransform( transform.child(i) );
			GetUniqueRenderContexts( childTransform, uniqueContexts );
		}
	}
}