2018-01-10 23:51:15 +01:00
|
|
|
#include "animation/property_animation.h"
|
|
|
|
#include "engine/crc32.h"
|
2019-06-20 16:49:34 +02:00
|
|
|
#include "engine/allocator.h"
|
2018-01-10 23:51:15 +01:00
|
|
|
#include "engine/log.h"
|
|
|
|
#include "engine/reflection.h"
|
2019-06-21 18:49:30 +02:00
|
|
|
#include "engine/serializer.h"
|
2018-01-10 23:51:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
namespace Lumix
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2018-01-11 21:13:59 +01:00
|
|
|
const ResourceType PropertyAnimation::TYPE("property_animation");
|
|
|
|
|
|
|
|
|
2018-08-22 20:53:54 +02:00
|
|
|
PropertyAnimation::PropertyAnimation(const Path& path, ResourceManager& resource_manager, IAllocator& allocator)
|
2018-01-10 23:51:15 +01:00
|
|
|
: Resource(path, resource_manager, allocator)
|
2019-06-20 16:49:34 +02:00
|
|
|
, m_allocator(allocator)
|
2018-01-11 02:19:31 +01:00
|
|
|
, fps(30)
|
|
|
|
, curves(allocator)
|
2018-01-10 23:51:15 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-15 17:39:51 +01:00
|
|
|
PropertyAnimation::Curve& PropertyAnimation::addCurve()
|
|
|
|
{
|
2019-06-20 16:49:34 +02:00
|
|
|
return curves.emplace(m_allocator);
|
2018-01-15 17:39:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-21 18:49:30 +02:00
|
|
|
bool PropertyAnimation::save(TextSerializer& serializer)
|
2018-01-24 00:37:44 +01:00
|
|
|
{
|
|
|
|
if (!isReady()) return false;
|
|
|
|
|
2019-06-21 18:49:30 +02:00
|
|
|
serializer.write("count", curves.size());
|
2018-01-24 00:37:44 +01:00
|
|
|
for (Curve& curve : curves)
|
|
|
|
{
|
2020-12-10 22:40:13 +01:00
|
|
|
serializer.write("component", reflection::getComponent(curve.cmp_type)->name);
|
2019-06-21 18:49:30 +02:00
|
|
|
serializer.write("property", curve.property->name);
|
|
|
|
serializer.write("keys_count", curve.frames.size());
|
2018-01-24 00:37:44 +01:00
|
|
|
for (int i = 0; i < curve.frames.size(); ++i)
|
|
|
|
{
|
2019-06-21 18:49:30 +02:00
|
|
|
serializer.write("frame", curve.frames[i]);
|
|
|
|
serializer.write("value", curve.values[i]);
|
2018-01-24 00:37:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-11 22:39:39 +02:00
|
|
|
bool PropertyAnimation::load(u64 size, const u8* mem)
|
2018-01-10 23:51:15 +01:00
|
|
|
{
|
2019-06-11 22:39:39 +02:00
|
|
|
InputMemoryStream file(mem, size);
|
2020-01-28 19:28:25 +01:00
|
|
|
TextDeserializer serializer(file);
|
2018-01-10 23:51:15 +01:00
|
|
|
|
2019-06-21 18:49:30 +02:00
|
|
|
int count;
|
2019-07-25 18:50:31 +02:00
|
|
|
serializer.read(Ref(count));
|
2019-06-21 18:49:30 +02:00
|
|
|
for (int i = 0; i < count; ++i) {
|
2019-06-20 16:49:34 +02:00
|
|
|
Curve& curve = curves.emplace(m_allocator);
|
2019-06-21 18:49:30 +02:00
|
|
|
char tmp[32];
|
2019-09-10 18:12:05 +02:00
|
|
|
serializer.read(Span(tmp));
|
2020-12-10 22:40:13 +01:00
|
|
|
curve.cmp_type = reflection::getComponentType(tmp);
|
2019-09-10 18:12:05 +02:00
|
|
|
serializer.read(Span(tmp));
|
2020-03-05 01:11:41 +01:00
|
|
|
// TODO
|
2019-06-21 18:49:30 +02:00
|
|
|
|
|
|
|
int keys_count;
|
2019-07-25 18:50:31 +02:00
|
|
|
serializer.read(Ref(keys_count));
|
2019-06-21 18:49:30 +02:00
|
|
|
curve.frames.resize(keys_count);
|
|
|
|
curve.values.resize(keys_count);
|
|
|
|
for (int j = 0; j < keys_count; ++j) {
|
2020-02-16 13:07:20 +01:00
|
|
|
serializer.read(Ref(curve.frames[j]));
|
|
|
|
serializer.read(Ref(curve.values[j]));
|
2018-01-10 23:51:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PropertyAnimation::unload()
|
|
|
|
{
|
2018-01-11 02:19:31 +01:00
|
|
|
curves.clear();
|
2018-01-10 23:51:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Lumix
|