Merge branch 'Importer' of https://github.com/teamfisk/TacticalZ into Importer
Conflicts: src/Engine/Rendering/RawModelCustom.cpp tools/MayaExporter/MayaExporter/Skeleton.cpp
This commit is contained in:
@@ -40,8 +40,8 @@ void RawModelCustom::ReadMeshFile(std::string filePath)
|
||||
void RawModelCustom::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||
{
|
||||
#ifdef BOOST_LITTLE_ENDIAN
|
||||
hasSkin = *(bool*)(fileData + offset);
|
||||
offset += sizeof(bool);
|
||||
hasSkin = true;//*(bool*)(fileData + offset);
|
||||
//offset += sizeof(bool);
|
||||
if (hasSkin) {
|
||||
m_SkinedVertices.resize(*(unsigned int*)(fileData + offset));
|
||||
}
|
||||
@@ -68,7 +68,7 @@ void RawModelCustom::ReadVertices(unsigned int& offset, char* fileData, unsigned
|
||||
if (offset + m_SkinedVertices.size() * sizeof(SkinedVertex) > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading skined vertices failed");
|
||||
}
|
||||
memcpy(&m_SkinedVertices[0], fileData + offset, m_Vertices.size() * sizeof(SkinedVertex));
|
||||
memcpy(&m_SkinedVertices[0], fileData + offset, m_SkinedVertices.size() * sizeof(SkinedVertex));
|
||||
offset += m_SkinedVertices.size() * sizeof(SkinedVertex);
|
||||
} else {
|
||||
if (offset + m_Vertices.size() * sizeof(Vertex) > fileByteSize) {
|
||||
@@ -331,26 +331,42 @@ void RawModelCustom::ReadAnimationClipSingle(unsigned int &offset, char* fileDat
|
||||
if (offset + sizeof(float) > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading AnimationClip duration failed");
|
||||
}
|
||||
|
||||
newAnimation.Duration = *(float*)(fileData + offset);
|
||||
offset += sizeof(float);
|
||||
|
||||
if (offset + sizeof(unsigned int) > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading AnimationClip NrOfKeyframes failed");
|
||||
throw Resource::FailedLoadingException("Reading AnimationClip numberOfJointFrames failed");
|
||||
}
|
||||
unsigned int nrOfKeyframes = *(unsigned int*)(fileData + offset);
|
||||
unsigned int numberOfJointFrames = *(unsigned int*)(fileData + offset);
|
||||
offset += sizeof(unsigned int);
|
||||
|
||||
newAnimation.Keyframes.reserve(nrOfKeyframes);
|
||||
for (unsigned int i = 0; i < nrOfKeyframes; i++) {
|
||||
ReadAnimationKeyFrame(offset, fileData, fileByteSize, newAnimation);
|
||||
for (unsigned int i = 0; i < numberOfJointFrames; i++) {
|
||||
if (offset + sizeof(unsigned int) > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading AnimationClip JointID failed");
|
||||
}
|
||||
int jointID = *(unsigned int*)(fileData + offset);
|
||||
offset += sizeof(unsigned int);
|
||||
|
||||
if (offset + sizeof(unsigned int) > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading AnimationClip numberOFKeyFrames failed");
|
||||
}
|
||||
unsigned int numberOFKeyFrames = *(unsigned int*)(fileData + offset);
|
||||
offset += sizeof(unsigned int);
|
||||
|
||||
if (numberOFKeyFrames > 0) {
|
||||
newAnimation.JointAnimations[jointID].reserve(numberOFKeyFrames);
|
||||
|
||||
for (unsigned int j = 0; j < numberOFKeyFrames; j++) {
|
||||
ReadAnimationKeyFrame(offset, fileData, fileByteSize, newAnimation.JointAnimations[jointID]);
|
||||
}
|
||||
}
|
||||
}
|
||||
m_Skeleton->Animations[newAnimation.Name] = newAnimation;
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
void RawModelCustom::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, Skeleton::Animation& animation)
|
||||
void RawModelCustom::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, std::vector<Skeleton::Animation::Keyframe>& animation)
|
||||
{
|
||||
Skeleton::Animation::Keyframe newKeyFrame;
|
||||
|
||||
@@ -366,23 +382,26 @@ void RawModelCustom::ReadAnimationKeyFrame(unsigned int &offset, char* fileData,
|
||||
newKeyFrame.Time = *(float*)(fileData + offset);
|
||||
offset += sizeof(float);
|
||||
|
||||
if (offset + sizeof(unsigned int) > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading AnimationKeyFrame NrOfJoints failed");
|
||||
if (offset + sizeof(float) * 3 > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading AnimationKeyFrame Position failed");
|
||||
}
|
||||
unsigned int nrOfJoints = *(unsigned int*)(fileData + offset);
|
||||
offset += sizeof(unsigned int);
|
||||
memcpy(&newKeyFrame.BoneProperties.Position[0], fileData + offset, sizeof(float) * 3);
|
||||
offset += sizeof(float) * 3;
|
||||
|
||||
if (offset + sizeof(Skeleton::Animation::Keyframe::BoneProperty) * nrOfJoints> fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading AnimationKeyFrame joints failed");
|
||||
if (offset + sizeof(float) * 4 > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading AnimationKeyFrame Rotation failed");
|
||||
}
|
||||
memcpy(&newKeyFrame.BoneProperties.Rotation[0], fileData + offset, sizeof(float) * 4);
|
||||
offset += sizeof(float) * 4;
|
||||
|
||||
Skeleton::Animation::Keyframe::BoneProperty newBone;
|
||||
for (unsigned int i = 0; i < nrOfJoints; i++) {
|
||||
memcpy(&newBone, (fileData + offset), sizeof(Skeleton::Animation::Keyframe::BoneProperty));
|
||||
offset += sizeof(Skeleton::Animation::Keyframe::BoneProperty);
|
||||
newKeyFrame.BoneProperties[newBone.ID] = newBone;
|
||||
if (offset + sizeof(float) * 3 > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading AnimationKeyFrame Scale failed");
|
||||
}
|
||||
animation.Keyframes.push_back(newKeyFrame);
|
||||
memcpy(&newKeyFrame.BoneProperties.Scale[0], fileData + offset, sizeof(float) * 3);
|
||||
offset += sizeof(float) * 3;
|
||||
|
||||
|
||||
animation.push_back(newKeyFrame);
|
||||
}
|
||||
|
||||
RawModelCustom::~RawModelCustom()
|
||||
|
||||
Reference in New Issue
Block a user