Example #1
0
void convertObjectIpo(Blender::Ipo* bipo, akAnimationChannel* chan, gkScalar start, gkScalar& end, gkScalar animfps)
{
	Blender::IpoCurve* icu = (Blender::IpoCurve*)bipo->curve.first;
	while (icu)
	{
		if (icu->bezt)
		{
			gkScalar yfactor = 1;
			
			int code = -1;
			switch (icu->adrcode)
			{
			case OB_ROT_X: code = gkTransformChannel::SC_ROT_EULER_X; yfactor = 10*gkRPD; break;
			case OB_ROT_Y: code = gkTransformChannel::SC_ROT_EULER_Y; yfactor = 10*gkRPD; break;
			case OB_ROT_Z: code = gkTransformChannel::SC_ROT_EULER_Z; yfactor = 10*gkRPD; break;
			case OB_LOC_X: code = gkTransformChannel::SC_LOC_X; break;
			case OB_LOC_Y: code = gkTransformChannel::SC_LOC_Y; break;
			case OB_LOC_Z: code = gkTransformChannel::SC_LOC_Z; break;
			case OB_SIZE_X: code = gkTransformChannel::SC_SCL_X; break;
			case OB_SIZE_Y: code = gkTransformChannel::SC_SCL_Y; break;
			case OB_SIZE_Z: code = gkTransformChannel::SC_SCL_Z; break;
			}
			
			// ignore any other codes
			if (code != -1 && icu->totvert > 0)
				ConvertSpline(icu->bezt, chan, code, icu->ipo, icu->totvert, -start, 1.0f/animfps, 0, yfactor);
		}
		icu = icu->next;
	}
}
Example #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;
		
		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);
}
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);
}