Skip to content

Commit

Permalink
Handle delta rotation for animation:
Browse files Browse the repository at this point in the history
 - handle properly pma flags (there are two known - took from pia2pma tool)
 - read & generate delta rotation from pma / to pia
 - update for blender tools is needed - mwl4/BlenderTools@21ae543
  • Loading branch information
mwl4 committed Nov 8, 2021
1 parent 12cba5c commit fc57807
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
Binary file modified bin/win_x86/converter_pix.exe
Binary file not shown.
53 changes: 50 additions & 3 deletions src/model/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool Animation::loadAnim0x03(const uint8_t *const buffer, const size_t size)
}
}

if (header->m_flags == 2)
if (header->m_flags & pma_header_t::FLAG_HAS_MOVEMENT)
{
m_movement = std::make_unique<Array<Float3>>(header->m_frames);
for (u32 i = 0; i < header->m_frames; ++i)
Expand All @@ -72,6 +72,15 @@ bool Animation::loadAnim0x03(const uint8_t *const buffer, const size_t size)
}
}

if (header->m_flags & pma_header_t::FLAG_HAS_ROTATION)
{
m_rotation = std::make_unique<Array<Quaternion>>(header->m_frames);
for (u32 i = 0; i < header->m_frames; ++i)
{
(*m_rotation)[i] = *((quat_t *)(buffer + header->m_delta_rot_offset) + i);
}
}

return true;
}

Expand Down Expand Up @@ -102,7 +111,7 @@ bool Animation::loadAnim0x04(const uint8_t *const buffer, const size_t size)
}
}

if (header->m_flags == 2)
if (header->m_flags & pma_header_t::FLAG_HAS_MOVEMENT)
{
m_movement = std::make_unique<Array<Float3>>(header->m_frames);
for (u32 i = 0; i < header->m_frames; ++i)
Expand All @@ -111,6 +120,15 @@ bool Animation::loadAnim0x04(const uint8_t *const buffer, const size_t size)
}
}

if (header->m_flags & pma_header_t::FLAG_HAS_ROTATION)
{
m_rotation = std::make_unique<Array<Quaternion>>(header->m_frames);
for (u32 i = 0; i < header->m_frames; ++i)
{
(*m_rotation)[i] = *((quat_t *)(buffer + header->m_delta_rot_offset) + i);
}
}

return true;
}

Expand Down Expand Up @@ -179,7 +197,7 @@ void Animation::saveToPia(String exportPath) const
global["Skeleton"] = relativePath((m_model->filePath() + ".pis"), directory(m_filePath));
global["TotalTime"] = double{ m_totalLength };
global["BoneChannelCount"] = (int)m_bones.size();
global["CustomChannelCount"] = m_movement ? 1 : 0;
global["CustomChannelCount"] = (m_movement ? 1 : 0) + (m_rotation ? 1 : 0);

if (m_movement)
{
Expand Down Expand Up @@ -210,6 +228,35 @@ void Animation::saveToPia(String exportPath) const
}
}

if (m_rotation)
{
Pix::Value &channel = root["CustomChannel"];
channel["Name"] = "Prism Rotation";
channel["StreamCount"] = 2;
channel["KeyframeCount"] = m_timeframes.size();

{
Pix::Value &stream = channel["Stream"];
stream["Format"] = Pix::Value::Enumeration("FLOAT");
stream["Tag"] = "_TIME";
stream.allocateIndexedObjects(m_timeframes.size());
for (size_t timeframe = 0; timeframe < m_timeframes.size(); ++timeframe)
{
stream[timeframe] = Float1(m_timeframes[timeframe]);
}
}
{
Pix::Value &stream = channel["Stream"];
stream["Format"] = Pix::Value::Enumeration("FLOAT4");
stream["Tag"] = "_ROTATION";
stream.allocateIndexedObjects(m_timeframes.size());
for (size_t keyframe = 0; keyframe < m_timeframes.size(); ++keyframe)
{
stream[keyframe] = (*m_rotation)[keyframe];
}
}
}

for (size_t boneIndex = 0; boneIndex < m_bones.size(); ++boneIndex)
{
if (m_bones[boneIndex] >= m_model->boneCount())
Expand Down
1 change: 1 addition & 0 deletions src/model/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Animation
Array<Array<Frame>> m_frames; // @[bone][frame]
Array<float> m_timeframes;
UniquePtr<Array<Float3>> m_movement;
UniquePtr<Array<Quaternion>> m_rotation;

String m_filePath;
bool m_loaded = false;
Expand Down
6 changes: 5 additions & 1 deletion src/structs/pma_0x03.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ namespace prism
i32 m_delta_trans_offset; // +36
i32 m_delta_rot_offset; // +40

static const u32 SUPPORTED_VERSION = 0x03;
static const u32 SUPPORTED_VERSION = 0x03;

static const u32 FLAG_HAS_MOVEMENT = (1 << 1);
static const u32 FLAG_HAS_ROTATION = (1 << 2);

}; ENSURE_SIZE(pma_header_t, 44);

struct pma_frame_t
Expand Down
6 changes: 5 additions & 1 deletion src/structs/pma_0x04.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ namespace prism
i32 m_delta_trans_offset; // +36
i32 m_delta_rot_offset; // +40

static const u32 SUPPORTED_VERSION = 0x04;
static const u32 SUPPORTED_VERSION = 0x04;

static const u32 FLAG_HAS_MOVEMENT = (1 << 1);
static const u32 FLAG_HAS_ROTATION = (1 << 2);

}; ENSURE_SIZE(pma_header_t, 44);

struct pma_frame_t
Expand Down

0 comments on commit fc57807

Please sign in to comment.