Ejemplo n.º 1
0
void MeshLoader_v1::ReadSkelAnim(MeshPtr mesh, DataStreamPtr & stream)
{
	Skeleton * skel = mesh->GetSkeleton();
	int version = -1;

	stream->Read(&version, sizeof (int));

	d_assert (version == K_SkelAnim_Version);

	char name[128];

	stream->Read(name, 128);

	Animation * anim = mesh->CreateAnimation(name);

	int numAnims = 0;
	stream->Read(&numAnims, sizeof(int));

	for (int i = 0; i < numAnims; ++i)
	{
		int boneId, count;

		stream->Read(&boneId, sizeof(int));
		stream->Read(&count, sizeof(int));

		if (count == 0)
			continue;

		SkeletonAnimation * skel_anim;
		skel_anim = anim->CreateSkeletonAnimation(boneId);

		KeyFrame * kf;
		float time;
		Vec3 trans;
		Quat rotate;
		Vec3 scale;

		for (int i = 0; i < count; ++i)
		{
			stream->Read(&time, sizeof(float));
			stream->Read(&trans, sizeof(float) * 3);
			stream->Read(&rotate, sizeof(float) * 4);
			stream->Read(&scale, sizeof(float) * 3);

			kf = skel_anim->CreateKeyFrame();
			kf->SetTime(time);
			kf->SetTranslate(trans);
			kf->SetRotation(rotate);
			kf->SetScale(scale);
		}
	}

	anim->_calcuLength();
}
Ejemplo n.º 2
0
void MeshLoader_v1::ReadSkeleton(MeshPtr mesh, DataStreamPtr & stream)
{
	Skeleton * skel = mesh->GetSkeleton();
	int version = -1;

	stream->Read(&version, sizeof (int));

	d_assert (version == K_Skeleton_Version);

	int boneCount = 0;

	stream->Read(&boneCount, sizeof (int));

	for (int i = 0; i < boneCount; ++i)
	{
		char Name[128];
		int flag;
		Vec3 Position;
		Quat Orientation;
		Vec3 Scale;

		stream->Read(&Name[0],  128);
		stream->Read(&flag, sizeof(int));
		stream->Read(&Position, sizeof(Vec3));
		stream->Read(&Orientation, sizeof(Quat));
		stream->Read(&Scale, sizeof(Vec3)); // equal ratio scale.

		joint * bn = skel->CreateJoint(Name);

		bn->flag = flag;
		bn->position = Position;
		bn->orientation = Orientation;
		bn->scale = Scale;
	}

	for (int i = 0; i < boneCount; ++i)
	{
		short parent;
		short child;

		stream->Read(&parent, sizeof(short));
		stream->Read(&child, sizeof(short));

		skel->SetupHiberarchy(parent, child);
	}
}
Ejemplo n.º 3
0
void MeshLoader_v0::ReadSkeleton(MeshPtr mesh, DataStreamPtr & stream)
{
    String sSkeletonName;
    stream->ReadString(sSkeletonName);
	
	TString128 Source = mesh->GetSourceName();
	Source = File::GetFileDir(Source);

	if (Source == "")
	{
		Source = sSkeletonName.c_str();
	}
	else
	{
		Source += "\\";
		Source += sSkeletonName.c_str();
	}

	SkeletonLoader::Load(mesh->GetSkeleton(), Source);
    //mesh->SetSkeletonName(sSkeletonName.c_str());
}