Ejemplo n.º 1
0
void gkAnimationLoader::convertAction25(Blender::bAction* action, gkScalar animfps)
{
	gkKeyedAnimation* act = gkAnimationManager::getSingleton().createKeyedAnimation(gkResourceName(GKB_IDNAME(action), m_groupName));
	
	if(!act)
		return;
	
	// min/max
	gkScalar start, end;
	get25ActionStartEnd(action, start, end);
	
	Blender::FCurve* bfc = (Blender::FCurve*)action->curves.first;
	
	while (bfc)
	{
		utString rnap (bfc->rna_path);
		utString chan_name;
		utString transform_name;
		
		akAnimationChannel* chan;
		
		// Pose action
		if (rnap.substr(0, 10) == "pose.bones")
		{
			// TODO use regex?
			size_t i = rnap.rfind('\"');
			chan_name = rnap.substr(12, i - 12);
			transform_name = rnap.substr(i + 3, rnap.length() - i + 3);
			
			chan = act->getChannel(chan_name);
			if(!chan)
			{
				chan = new gkBoneChannel(chan_name, act);
				act->addChannel(chan);
			}
		}
		// Object action
		else
		{
			transform_name = rnap;
			chan_name = "GKMainObjectChannel";
			
			chan = act->getChannel(chan_name);
			if(!chan)
			{
				gkObjectChannel* ochan = new gkObjectChannel(chan_name, act);
				
				ochan->setEulerRotation(true);
				
				chan = static_cast<akAnimationChannel*>(ochan);
				act->addChannel(chan);
			}
		}
		
		
		if (bfc->bezt)
		{
			int code = -1;
			if (transform_name == "rotation_quaternion")
			{
				if (bfc->array_index == 0) code = gkTransformChannel::SC_ROT_QUAT_W;
				else if (bfc->array_index == 1) code = gkTransformChannel::SC_ROT_QUAT_X;
				else if (bfc->array_index == 2) code = gkTransformChannel::SC_ROT_QUAT_Y;
				else if (bfc->array_index == 3) code = gkTransformChannel::SC_ROT_QUAT_Z;
			}
			else if (transform_name == "rotation_euler")
			{
				if (bfc->array_index == 0) code = gkTransformChannel::SC_ROT_EULER_X;
				else if (bfc->array_index == 1) code = gkTransformChannel::SC_ROT_EULER_Y;
				else if (bfc->array_index == 2) code = gkTransformChannel::SC_ROT_EULER_Z;
			}
			else if (transform_name == "location")
			{
				if (bfc->array_index == 0) code = gkTransformChannel::SC_LOC_X;
				else if (bfc->array_index == 1) code = gkTransformChannel::SC_LOC_Y;
				else if (bfc->array_index == 2) code = gkTransformChannel::SC_LOC_Z;
			}
			else if (transform_name == "scale")
			{
				if (bfc->array_index == 0) code = gkTransformChannel::SC_SCL_X;
				else if (bfc->array_index == 1) code = gkTransformChannel::SC_SCL_Y;
				else if (bfc->array_index == 2) code = gkTransformChannel::SC_SCL_Z;
			}
			
			// ignore any other codes
			if (code != -1 && bfc->totvert > 0)
				ConvertSpline(bfc->bezt, chan, code, bfc->bezt->ipo, bfc->totvert, -start, 1.0f/animfps, 0, 1);
		}

		if (bfc->next == 0 || bfc->next->prev != bfc)
			break; //FIX: Momo_WalkBack fcurve is broken in uncompressed 256a.
		
		bfc = bfc->next;
	}
	
	
	// apply time range
	act->setLength( (end-start)/animfps);
}
Ejemplo n.º 2
0
void gkAnimationLoader::convertAction25(Blender::bAction* action, gkScalar animfps)
{
	gkKeyedAnimation* act = gkAnimationManager::getSingleton().createKeyedAnimation(gkResourceName(GKB_IDNAME(action), m_groupName));
	
	if(!act)
		return;
	
	// min/max
	gkScalar start, end;
	get25ActionStartEnd(action, start, end);
	
	Blender::FCurve* bfc = (Blender::FCurve*)action->curves.first;
	
	while (bfc)
	{
		utString rnap (bfc->rna_path);
		utString chan_name;
		utString transform_name;
		
		printf("rnap = %s \n",rnap.c_str());


		akAnimationChannel* chan;
		
		// Pose action
		if (rnap.substr(0, 10) == "pose.bones")
		{
			// TODO use regex?
			size_t i = rnap.rfind('\"');
			chan_name = rnap.substr(12, i - 12);
			transform_name = rnap.substr(i + 3, rnap.length() - i + 3);
			
			chan = act->getChannel(chan_name);
			if(!chan)
			{
				chan = new gkBoneChannel(chan_name, act);
				act->addChannel(chan);
			}
		}
		// Object action
		else
		{
			transform_name = rnap;
			chan_name = "GKMainObjectChannel";
			
			chan = act->getChannel(chan_name);
			if(!chan)
			{
				gkObjectChannel* ochan = new gkObjectChannel(chan_name, act);
				
				ochan->setEulerRotation(true);
				
				chan = static_cast<akAnimationChannel*>(ochan);
				act->addChannel(chan);
			}
		}
		
		
		if (bfc->bezt)
		{
			int code = -1;
			if (transform_name == "rotation_quaternion")
			{
				if (bfc->array_index == 0) code = gkTransformChannel::SC_ROT_QUAT_W;
				else if (bfc->array_index == 1) code = gkTransformChannel::SC_ROT_QUAT_X;
				else if (bfc->array_index == 2) code = gkTransformChannel::SC_ROT_QUAT_Y;
				else if (bfc->array_index == 3) code = gkTransformChannel::SC_ROT_QUAT_Z;
			}
			else if (transform_name == "rotation_euler")
			{
				if (bfc->array_index == 0) code = gkTransformChannel::SC_ROT_EULER_X;
				else if (bfc->array_index == 1) code = gkTransformChannel::SC_ROT_EULER_Y;
				else if (bfc->array_index == 2) code = gkTransformChannel::SC_ROT_EULER_Z;
			}
			else if (transform_name == "location")
			{
				if (bfc->array_index == 0) code = gkTransformChannel::SC_LOC_X;
				else if (bfc->array_index == 1) code = gkTransformChannel::SC_LOC_Y;
				else if (bfc->array_index == 2) code = gkTransformChannel::SC_LOC_Z;
			}
			else if (transform_name == "scale")
			{
				if (bfc->array_index == 0) code = gkTransformChannel::SC_SCL_X;
				else if (bfc->array_index == 1) code = gkTransformChannel::SC_SCL_Y;
				else if (bfc->array_index == 2) code = gkTransformChannel::SC_SCL_Z;
			}
			//add channel    zy
			else if (transform_name == "alpha")
			{
				code = gkTransformChannel::SC_ALPHA;
			}else if(transform_name == "diffuse_color")
			{
				if (bfc->array_index == 0) code = gkTransformChannel::SC_DIFFUSE_COLOR_R;
				else if (bfc->array_index == 1) code = gkTransformChannel::SC_DIFFUSE_COLOR_G;
				else if (bfc->array_index == 2) code = gkTransformChannel::SC_DIFFUSE_COLOR_B;
			}else if(transform_name == "texture_slots[0].offset")
			{
				if (bfc->array_index == 0) code = gkTransformChannel::SC_TEXTURE0_OFFSET_X;
				else if (bfc->array_index == 1) code = gkTransformChannel::SC_TEXTURE0_OFFSET_Y;
				else if (bfc->array_index == 2) code = gkTransformChannel::SC_TEXTURE0_OFFSET_Z;
			}
			else if(transform_name == "texture_slots[1].offset")
			{
				if (bfc->array_index == 0) code = gkTransformChannel::SC_TEXTURE1_OFFSET_X;
				else if (bfc->array_index == 1) code = gkTransformChannel::SC_TEXTURE1_OFFSET_Y;
				else if (bfc->array_index == 2) code = gkTransformChannel::SC_TEXTURE1_OFFSET_Z;
			}
			else if(transform_name == "image_user.frame_duration")
			{
				code = gkTransformChannel::SC_IMAGE_FRAME;
			}else if(transform_name == "texture_slots[0].alpha_factor")
			{
				code = gkTransformChannel::SC_TEXTURE0_ALPHA_FACTOR;
			}else if(transform_name == "texture_slots[1].alpha_factor")
			{
				code = gkTransformChannel::SC_TEXTURE1_ALPHA_FACTOR;
			}else if(transform_name == "texture_slots[0].diffuse_color_factor")
			{
				code = gkTransformChannel::SC_TEXTURE0_DIFFUSE_COLOR_FACTOR;
			}
			else if(transform_name == "texture_slots[1].diffuse_color_factor")
			{
				code = gkTransformChannel::SC_TEXTURE1_DIFFUSE_COLOR_FACTOR;
			}
			else
			{
				gkPrintf("Not supported animation format");
			}
			
			// ignore any other codes
			if (code != -1 && bfc->totvert > 0)
				ConvertSpline(bfc->bezt, chan, code, bfc->bezt->ipo, bfc->totvert, -start, 1.0f/animfps, 0, 1);
		}

		if (bfc->next == 0 || bfc->next->prev != bfc)
			break; //FIX: Momo_WalkBack fcurve is broken in uncompressed 256a.
		
		bfc = bfc->next;
	}
	
	
	// apply time range
	act->setLength( (end-start)/animfps);
	act->setStartFrame(start);
	act->setEndFrame(end);
}