Refactor native Stream serialization to new API
This commit is contained in:
@@ -174,7 +174,7 @@ void Animation::LoadTimeline(BytesContainer& result) const
|
||||
stream.WriteInt32(-1); // Parent Index
|
||||
stream.WriteInt32(childrenCount); // Children Count
|
||||
stream.WriteString(channel.NodeName, -13); // Name
|
||||
stream.Write(&Color32::White); // Color
|
||||
stream.Write(Color32::White); // Color
|
||||
const int32 parentIndex = trackIndex++;
|
||||
|
||||
auto& position = channel.Position.GetKeyframes();
|
||||
@@ -186,13 +186,13 @@ void Animation::LoadTimeline(BytesContainer& result) const
|
||||
stream.WriteInt32(parentIndex); // Parent Index
|
||||
stream.WriteInt32(0); // Children Count
|
||||
stream.WriteString(String::Format(TEXT("Track_{0}_Position"), i), -13); // Name
|
||||
stream.Write(&Color32::White); // Color
|
||||
stream.Write(Color32::White); // Color
|
||||
stream.WriteByte(0); // Type
|
||||
stream.WriteInt32(position.Count()); // Keyframes Count
|
||||
for (auto& k : position)
|
||||
{
|
||||
stream.WriteFloat(k.Time * fpsInv);
|
||||
stream.Write(&k.Value);
|
||||
stream.Write(k.Value);
|
||||
}
|
||||
trackIndex++;
|
||||
}
|
||||
@@ -206,13 +206,13 @@ void Animation::LoadTimeline(BytesContainer& result) const
|
||||
stream.WriteInt32(parentIndex); // Parent Index
|
||||
stream.WriteInt32(0); // Children Count
|
||||
stream.WriteString(String::Format(TEXT("Track_{0}_Rotation"), i), -13); // Name
|
||||
stream.Write(&Color32::White); // Color
|
||||
stream.Write(Color32::White); // Color
|
||||
stream.WriteByte(1); // Type
|
||||
stream.WriteInt32(rotation.Count()); // Keyframes Count
|
||||
for (auto& k : rotation)
|
||||
{
|
||||
stream.WriteFloat(k.Time * fpsInv);
|
||||
stream.Write(&k.Value);
|
||||
stream.Write(k.Value);
|
||||
}
|
||||
trackIndex++;
|
||||
}
|
||||
@@ -226,13 +226,13 @@ void Animation::LoadTimeline(BytesContainer& result) const
|
||||
stream.WriteInt32(parentIndex); // Parent Index
|
||||
stream.WriteInt32(0); // Children Count
|
||||
stream.WriteString(String::Format(TEXT("Track_{0}_Scale"), i), -13); // Name
|
||||
stream.Write(&Color32::White); // Color
|
||||
stream.Write(Color32::White); // Color
|
||||
stream.WriteByte(2); // Type
|
||||
stream.WriteInt32(scale.Count()); // Keyframes Count
|
||||
for (auto& k : scale)
|
||||
{
|
||||
stream.WriteFloat(k.Time * fpsInv);
|
||||
stream.Write(&k.Value);
|
||||
stream.Write(k.Value);
|
||||
}
|
||||
trackIndex++;
|
||||
}
|
||||
@@ -253,8 +253,8 @@ void Animation::LoadTimeline(BytesContainer& result) const
|
||||
stream.WriteInt32(-1); // Parent Index
|
||||
stream.WriteInt32(0); // Children Count
|
||||
stream.WriteString(e.First, -13); // Name
|
||||
stream.Write(&Color32::White); // Color
|
||||
stream.Write(&id);
|
||||
stream.Write(Color32::White); // Color
|
||||
stream.Write(id);
|
||||
stream.WriteFloat(nestedAnim.Time);
|
||||
stream.WriteFloat(nestedAnim.Duration);
|
||||
stream.WriteFloat(nestedAnim.Speed);
|
||||
@@ -268,7 +268,7 @@ void Animation::LoadTimeline(BytesContainer& result) const
|
||||
stream.WriteInt32(-1); // Parent Index
|
||||
stream.WriteInt32(0); // Children Count
|
||||
stream.WriteString(e.First, -13); // Name
|
||||
stream.Write(&Color32::White); // Color
|
||||
stream.Write(Color32::White); // Color
|
||||
stream.WriteInt32(e.Second.GetKeyframes().Count()); // Events Count
|
||||
for (const auto& k : e.Second.GetKeyframes())
|
||||
{
|
||||
@@ -331,7 +331,7 @@ bool Animation::SaveTimeline(BytesContainer& data)
|
||||
String name;
|
||||
stream.ReadString(&name, -13);
|
||||
Color32 color;
|
||||
stream.Read(&color);
|
||||
stream.Read(color);
|
||||
switch (trackType)
|
||||
{
|
||||
case 17:
|
||||
@@ -365,7 +365,7 @@ bool Animation::SaveTimeline(BytesContainer& data)
|
||||
LinearCurveKeyframe<Float3>& k = channel.Position.GetKeyframes()[i];
|
||||
stream.ReadFloat(&k.Time);
|
||||
k.Time *= fps;
|
||||
stream.Read(&k.Value);
|
||||
stream.Read(k.Value);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
@@ -375,7 +375,7 @@ bool Animation::SaveTimeline(BytesContainer& data)
|
||||
LinearCurveKeyframe<Quaternion>& k = channel.Rotation.GetKeyframes()[i];
|
||||
stream.ReadFloat(&k.Time);
|
||||
k.Time *= fps;
|
||||
stream.Read(&k.Value);
|
||||
stream.Read(k.Value);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
@@ -385,7 +385,7 @@ bool Animation::SaveTimeline(BytesContainer& data)
|
||||
LinearCurveKeyframe<Float3>& k = channel.Scale.GetKeyframes()[i];
|
||||
stream.ReadFloat(&k.Time);
|
||||
k.Time *= fps;
|
||||
stream.Read(&k.Value);
|
||||
stream.Read(k.Value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -428,7 +428,7 @@ bool Animation::SaveTimeline(BytesContainer& data)
|
||||
nestedTrack.First = name;
|
||||
auto& nestedAnim = nestedTrack.Second;
|
||||
Guid id;
|
||||
stream.Read(&id);
|
||||
stream.Read(id);
|
||||
stream.ReadFloat(&nestedAnim.Time);
|
||||
stream.ReadFloat(&nestedAnim.Duration);
|
||||
stream.ReadFloat(&nestedAnim.Speed);
|
||||
@@ -524,7 +524,7 @@ bool Animation::Save(const StringView& path)
|
||||
if (nestedAnim.Loop)
|
||||
flags |= 2;
|
||||
stream.WriteByte(flags);
|
||||
stream.Write(&id);
|
||||
stream.Write(id);
|
||||
stream.WriteFloat(nestedAnim.Time);
|
||||
stream.WriteFloat(nestedAnim.Duration);
|
||||
stream.WriteFloat(nestedAnim.Speed);
|
||||
@@ -700,7 +700,7 @@ Asset::LoadResult Animation::load()
|
||||
nestedAnim.Enabled = flags & 1;
|
||||
nestedAnim.Loop = flags & 2;
|
||||
Guid id;
|
||||
stream.Read(&id);
|
||||
stream.Read(id);
|
||||
nestedAnim.Anim = id;
|
||||
stream.ReadFloat(&nestedAnim.Time);
|
||||
stream.ReadFloat(&nestedAnim.Duration);
|
||||
|
||||
@@ -215,7 +215,7 @@ Asset::LoadResult MaterialInstance::load()
|
||||
|
||||
// Load base material
|
||||
Guid baseMaterialId;
|
||||
headerStream.Read(&baseMaterialId);
|
||||
headerStream.Read(baseMaterialId);
|
||||
auto baseMaterial = Content::LoadAsync<MaterialBase>(baseMaterialId);
|
||||
|
||||
// Load parameters
|
||||
@@ -316,8 +316,8 @@ bool MaterialInstance::Save(const StringView& path)
|
||||
MemoryWriteStream stream(512);
|
||||
{
|
||||
// Save base material ID
|
||||
const auto baseMaterialId = _baseMaterial ? _baseMaterial->GetID() : Guid::Empty;
|
||||
stream.Write(&baseMaterialId);
|
||||
const Guid baseMaterialId = _baseMaterial ? _baseMaterial->GetID() : Guid::Empty;
|
||||
stream.Write(baseMaterialId);
|
||||
|
||||
// Save parameters
|
||||
Params.Save(&stream);
|
||||
|
||||
@@ -361,7 +361,7 @@ bool Model::Save(bool withMeshDataFromGpu, const StringView& path)
|
||||
auto& slot = MaterialSlots[materialSlotIndex];
|
||||
|
||||
const auto id = slot.Material.GetID();
|
||||
stream->Write(&id);
|
||||
stream->Write(id);
|
||||
stream->WriteByte(static_cast<byte>(slot.ShadowsMode));
|
||||
stream->WriteString(slot.Name, 11);
|
||||
}
|
||||
@@ -578,7 +578,7 @@ bool Model::Save(bool withMeshDataFromGpu, const StringView& path)
|
||||
MemoryWriteStream sdfStream;
|
||||
sdfStream.WriteInt32(1); // Version
|
||||
ModelSDFHeader data(SDF, SDF.Texture->GetDescription());
|
||||
sdfStream.Write(&data);
|
||||
sdfStream.WriteBytes(&data, sizeof(data));
|
||||
TextureData sdfTextureData;
|
||||
if (SDF.Texture->DownloadData(sdfTextureData))
|
||||
return true;
|
||||
@@ -586,8 +586,8 @@ bool Model::Save(bool withMeshDataFromGpu, const StringView& path)
|
||||
{
|
||||
auto& mip = sdfTextureData.Items[0].Mips[mipLevel];
|
||||
ModelSDFMip mipData(mipLevel, mip);
|
||||
sdfStream.Write(&mipData);
|
||||
sdfStream.Write(mip.Data.Get(), mip.Data.Length());
|
||||
sdfStream.WriteBytes(&mipData, sizeof(mipData));
|
||||
sdfStream.WriteBytes(mip.Data.Get(), mip.Data.Length());
|
||||
}
|
||||
sdfChunk->Data.Copy(sdfStream.GetHandle(), sdfStream.GetPosition());
|
||||
}
|
||||
@@ -889,7 +889,7 @@ Asset::LoadResult Model::load()
|
||||
|
||||
// Material
|
||||
Guid materialId;
|
||||
stream->Read(&materialId);
|
||||
stream->Read(materialId);
|
||||
slot.Material = materialId;
|
||||
|
||||
// Shadows Mode
|
||||
@@ -964,7 +964,7 @@ Asset::LoadResult Model::load()
|
||||
case 1:
|
||||
{
|
||||
ModelSDFHeader data;
|
||||
sdfStream.Read(&data);
|
||||
sdfStream.ReadBytes(&data, sizeof(data));
|
||||
if (!SDF.Texture)
|
||||
SDF.Texture = GPUTexture::New();
|
||||
if (SDF.Texture->Init(GPUTextureDescription::New3D(data.Width, data.Height, data.Depth, data.Format, GPUTextureFlags::ShaderResource, data.MipLevels)))
|
||||
@@ -980,7 +980,7 @@ Asset::LoadResult Model::load()
|
||||
for (int32 mipLevel = 0; mipLevel < data.MipLevels; mipLevel++)
|
||||
{
|
||||
ModelSDFMip mipData;
|
||||
sdfStream.Read(&mipData);
|
||||
sdfStream.ReadBytes(&mipData, sizeof(mipData));
|
||||
void* mipBytes = sdfStream.Move(mipData.SlicePitch);
|
||||
auto task = ::New<StreamModelSDFTask>(this, SDF.Texture, Span<byte>((byte*)mipBytes, mipData.SlicePitch), mipData.MipIndex, mipData.RowPitch, mipData.SlicePitch);
|
||||
task->Start();
|
||||
|
||||
@@ -23,7 +23,7 @@ Asset::LoadResult SkeletonMask::load()
|
||||
MemoryReadStream stream(dataChunk->Get(), dataChunk->Size());
|
||||
|
||||
Guid skeletonId;
|
||||
stream.Read(&skeletonId);
|
||||
stream.Read(skeletonId);
|
||||
int32 maskedNodesCount;
|
||||
stream.ReadInt32(&maskedNodesCount);
|
||||
_maskedNodes.Resize(maskedNodesCount);
|
||||
@@ -83,7 +83,7 @@ bool SkeletonMask::Save(const StringView& path)
|
||||
// Write data
|
||||
MemoryWriteStream stream(4096);
|
||||
const auto skeletonId = Skeleton.GetID();
|
||||
stream.Write(&skeletonId);
|
||||
stream.Write(skeletonId);
|
||||
stream.WriteInt32(_maskedNodes.Count());
|
||||
for (auto& e : _maskedNodes)
|
||||
{
|
||||
|
||||
@@ -413,7 +413,7 @@ bool SkinnedModel::Save(bool withMeshDataFromGpu, const StringView& path)
|
||||
auto& slot = MaterialSlots[materialSlotIndex];
|
||||
|
||||
const auto id = slot.Material.GetID();
|
||||
stream->Write(&id);
|
||||
stream->Write(id);
|
||||
stream->WriteByte(static_cast<byte>(slot.ShadowsMode));
|
||||
stream->WriteString(slot.Name, 11);
|
||||
}
|
||||
@@ -470,7 +470,7 @@ bool SkinnedModel::Save(bool withMeshDataFromGpu, const StringView& path)
|
||||
{
|
||||
auto& node = Skeleton.Nodes[nodeIndex];
|
||||
|
||||
stream->Write(&node.ParentIndex);
|
||||
stream->Write(node.ParentIndex);
|
||||
stream->WriteTransform(node.LocalTransform);
|
||||
stream->WriteString(node.Name, 71);
|
||||
}
|
||||
@@ -482,10 +482,10 @@ bool SkinnedModel::Save(bool withMeshDataFromGpu, const StringView& path)
|
||||
{
|
||||
auto& bone = Skeleton.Bones[boneIndex];
|
||||
|
||||
stream->Write(&bone.ParentIndex);
|
||||
stream->Write(&bone.NodeIndex);
|
||||
stream->Write(bone.ParentIndex);
|
||||
stream->Write(bone.NodeIndex);
|
||||
stream->WriteTransform(bone.LocalTransform);
|
||||
stream->Write(&bone.OffsetMatrix);
|
||||
stream->Write(bone.OffsetMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -880,7 +880,7 @@ Asset::LoadResult SkinnedModel::load()
|
||||
|
||||
// Material
|
||||
Guid materialId;
|
||||
stream->Read(&materialId);
|
||||
stream->Read(materialId);
|
||||
slot.Material = materialId;
|
||||
|
||||
// Shadows Mode
|
||||
@@ -967,7 +967,7 @@ Asset::LoadResult SkinnedModel::load()
|
||||
{
|
||||
auto& node = Skeleton.Nodes[nodeIndex];
|
||||
|
||||
stream->Read(&node.ParentIndex);
|
||||
stream->Read(node.ParentIndex);
|
||||
stream->ReadTransform(&node.LocalTransform);
|
||||
stream->ReadString(&node.Name, 71);
|
||||
}
|
||||
@@ -983,10 +983,10 @@ Asset::LoadResult SkinnedModel::load()
|
||||
{
|
||||
auto& bone = Skeleton.Bones[boneIndex];
|
||||
|
||||
stream->Read(&bone.ParentIndex);
|
||||
stream->Read(&bone.NodeIndex);
|
||||
stream->Read(bone.ParentIndex);
|
||||
stream->Read(bone.NodeIndex);
|
||||
stream->ReadTransform(&bone.LocalTransform);
|
||||
stream->Read(&bone.OffsetMatrix);
|
||||
stream->Read(bone.OffsetMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user