Replaced Mesh serialization with Splash::serialize

This commit is contained in:
Emmanuel Durand
2021-09-13 09:19:46 -04:00
committed by Emmanuel Durand
parent ff33ea0961
commit 0da87ffddd
10 changed files with 530 additions and 123 deletions
@@ -25,6 +25,8 @@
#ifndef SPLASH_SERIALIZE_IMAGEBUFFER_H
#define SPLASH_SERIALIZE_IMAGEBUFFER_H
#include <iostream>
#include "./core/serializer.h"
#include "./core/imagebuffer.h"
+154
View File
@@ -0,0 +1,154 @@
/*
* Copyright (C) 2021 Emmanuel Durand
*
* This file is part of Splash.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Splash is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Splash. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* @serialize_mesh.h
* Implements serialization of Mesh
*/
#ifndef SPLASH_SERIALIZE_MESH_H
#define SPLASH_SERIALIZE_MESH_H
#include <type_traits>
#include <glm/glm.hpp>
#include "./core/serializer.h"
#include "./mesh/mesh.h"
namespace Splash::Serial::detail
{
/*************/
template <class T>
struct getSizeHelper<T, typename std::enable_if<std::is_same<glm::vec2, T>::value>::type>
{
static uint32_t value(const T& /*obj*/)
{
return 2 * sizeof(float);
}
};
template <class T>
struct serializeHelper<T, typename std::enable_if<std::is_same<glm::vec2, T>::value>::type>
{
static void apply(const T& obj, std::vector<uint8_t>::iterator& it)
{
const auto data = reinterpret_cast<const uint8_t*>(&obj);
const auto size = 2 * sizeof(float);
std::copy(data, data + size, it);
it += size;
}
};
template <class T>
struct deserializeHelper<T, typename std::enable_if<std::is_same<glm::vec2, T>::value>::type>
{
static T apply(std::vector<uint8_t>::const_iterator& it)
{
T vector;
auto data = reinterpret_cast<uint8_t*>(&vector);
const auto size = 2 * sizeof(float);
std::copy(it, it + size, data);
it += size;
return vector;
}
};
/*************/
template <class T>
struct getSizeHelper<T, typename std::enable_if<std::is_same<glm::vec4, T>::value>::type>
{
static uint32_t value(const T& /*obj*/)
{
return 4 * sizeof(float);
}
};
template <class T>
struct serializeHelper<T, typename std::enable_if<std::is_same<glm::vec4, T>::value>::type>
{
static void apply(const T& obj, std::vector<uint8_t>::iterator& it)
{
const auto data = reinterpret_cast<const uint8_t*>(&obj);
const auto size = 4 * sizeof(float);
std::copy(data, data + size, it);
it += size;
}
};
template <class T>
struct deserializeHelper<T, typename std::enable_if<std::is_same<glm::vec4, T>::value>::type>
{
static T apply(std::vector<uint8_t>::const_iterator& it)
{
T vector;
auto data = reinterpret_cast<uint8_t*>(&vector);
const auto size = 4 * sizeof(float);
std::copy(it, it + size, data);
it += size;
return vector;
}
};
/*************/
template <class T>
struct getSizeHelper<T, typename std::enable_if<std::is_base_of<Mesh::MeshContainer, T>::value>::type>
{
static uint32_t value(const T& obj)
{
uint32_t acc = getSize(obj.name);
acc += getSize(obj.vertices);
acc += getSize(obj.uvs);
acc += getSize(obj.normals);
acc += getSize(obj.annexe);
return acc;
}
};
template <class T>
struct serializeHelper<T, typename std::enable_if<std::is_base_of<Mesh::MeshContainer, T>::value>::type>
{
static void apply(const T& obj, std::vector<uint8_t>::iterator& it)
{
serializer(obj.name, it);
serializer(obj.vertices, it);
serializer(obj.uvs, it);
serializer(obj.normals, it);
serializer(obj.annexe, it);
}
};
template <class T>
struct deserializeHelper<T, typename std::enable_if<std::is_base_of<Mesh::MeshContainer, T>::value>::type>
{
static T apply(std::vector<uint8_t>::const_iterator& it)
{
Mesh::MeshContainer meshContainer;
meshContainer.name = deserializer<std::string>(it);
meshContainer.vertices = std::move(deserializer<std::vector<glm::vec4>>(it));
meshContainer.uvs = std::move(deserializer<std::vector<glm::vec2>>(it));
meshContainer.normals = std::move(deserializer<std::vector<glm::vec4>>(it));
meshContainer.annexe = std::move(deserializer<std::vector<glm::vec4>>(it));
return meshContainer;
}
};
}
#endif // SPLASH_SERIALIZE_MESH_H
+19 -5
View File
@@ -107,7 +107,7 @@ struct getSizeHelper<T, typename std::enable_if<std::is_arithmetic<T>::value ||
template <class T>
struct getSizeHelper<T, typename std::enable_if<std::is_same<T, std::string>::value>::type>
{
static uint32_t value(const T& obj) { return sizeof(uint32_t) + obj.size() * sizeof(char); }
static uint32_t value(const T& obj) { return sizeof(uint32_t) + obj.size() * sizeof(typename T::value_type); }
};
template <class T>
@@ -184,6 +184,19 @@ struct serializeHelper<T, typename std::enable_if<std::is_arithmetic<T>::value |
}
};
template <class T>
struct serializeHelper<T, typename std::enable_if<std::is_same<std::string, T>::value>::type>
{
static void apply(const T& obj, std::vector<uint8_t>::iterator& it)
{
const auto size = static_cast<uint32_t>(obj.size());
serializer(size, it);
const auto data = reinterpret_cast<const uint8_t*>(obj.data());
std::copy(data, data + size * sizeof(typename T::value_type), it);
it += size * sizeof(typename T::value_type);
}
};
template <class T>
struct serializeHelper<T, typename std::enable_if<is_specialisation_of<std::chrono::time_point, T>::value>::type>
{
@@ -198,7 +211,7 @@ struct serializeHelper<T, typename std::enable_if<is_specialisation_of<std::chro
};
template <class T>
struct serializeHelper<T, typename std::enable_if<isIterable<T>::value>::type>
struct serializeHelper<T, typename std::enable_if<isIterable<T>::value && !std::is_same<std::string, T>::value>::type>
{
static void apply(const T& obj, std::vector<uint8_t>::iterator& it)
{
@@ -284,10 +297,11 @@ struct deserializeHelper<T, typename std::enable_if<std::is_same<T, std::string>
{
static T apply(std::vector<uint8_t>::const_iterator& it)
{
auto size = deserializer<uint32_t>(it);
const auto size = deserializer<uint32_t>(it);
auto obj = T(static_cast<size_t>(size), ' ');
for (uint32_t i = 0; i < size; ++i)
obj[i] = deserializer<typename T::value_type>(it);
auto data = reinterpret_cast<uint8_t*>(obj.data());
std::copy(it, it + size * sizeof(typename T::value_type), data);
it += size * sizeof(typename T::value_type);
return obj;
}
};
+18 -103
View File
@@ -1,6 +1,8 @@
#include "./mesh/mesh.h"
#include "./core/root_object.h"
#include "./core/serializer.h"
#include "./core/serialize/serialize_mesh.h"
#include "./mesh/meshloader.h"
#include "./utils/log.h"
#include "./utils/osutils.h"
@@ -10,25 +12,19 @@ namespace Splash
{
/*************/
Mesh::Mesh(RootObject* root)
Mesh::Mesh(RootObject* root, MeshContainer meshContainer)
: BufferObject(root)
, _mesh(meshContainer)
{
init();
_renderingPriority = Priority::MEDIA;
}
/*************/
Mesh::~Mesh()
{
#ifdef DEBUG
Log::get() << Log::DEBUGGING << "Mesh::~Mesh - Destructor" << Log::endl;
#endif
}
/*************/
void Mesh::init()
{
_type = "mesh";
_renderingPriority = Priority::MEDIA;
registerAttributes();
// This is used for getting documentation "offline"
@@ -142,36 +138,15 @@ bool Mesh::read(const std::string& filename)
/*************/
SerializedObject Mesh::serialize() const
{
SerializedObject obj;
if (Timer::get().isDebug())
Timer::get() << "serialize " + _name;
// For this, we will use the getVertex, getUV, etc. methods to create a serialized representation of the mesh
std::vector<std::vector<float>> data;
data.push_back(getVertCoordsFlat());
data.push_back(getUVCoordsFlat());
data.push_back(getNormalsFlat());
data.push_back(getAnnexeFlat());
std::shared_lock<std::shared_mutex> readLock(_readMutex);
const int nbrVertices = data[0].size() / 4;
int totalSize = sizeof(nbrVertices); // We add to all this the total number of vertices
for (auto& d : data)
totalSize += d.size() * sizeof(d[0]);
obj.resize(totalSize);
auto currentObjPtr = obj.data();
const char* ptr = reinterpret_cast<const char*>(&nbrVertices);
std::copy(ptr, ptr + sizeof(nbrVertices), currentObjPtr);
currentObjPtr += sizeof(nbrVertices);
for (auto& d : data)
{
ptr = reinterpret_cast<const char*>(d.data());
std::copy(ptr, ptr + d.size() * sizeof(float), currentObjPtr);
currentObjPtr += d.size() * sizeof(float);
}
auto mesh = _mesh;
mesh.name = _name;
std::vector<uint8_t> data;
Serial::serialize(mesh, data);
SerializedObject obj(ResizableArray(std::move(data)));
if (Timer::get().isDebug())
Timer::get() >> ("serialize " + _name);
@@ -188,75 +163,15 @@ bool Mesh::deserialize(SerializedObject&& obj)
if (Timer::get().isDebug())
Timer::get() << "deserialize " + _name;
// First, we get the number of vertices
int nbrVertices;
char* ptr = reinterpret_cast<char*>(&nbrVertices);
// After this, obj does not hold any more data
const auto serializedMesh = obj.grabData();
auto serializedMeshIt = serializedMesh.cbegin();
auto mesh = Serial::detail::deserializer<MeshContainer>(serializedMeshIt);
auto currentObjPtr = obj.data();
std::copy(currentObjPtr, currentObjPtr + sizeof(nbrVertices), ptr); // This will fail if float have different size between sender and receiver
currentObjPtr += sizeof(nbrVertices);
_bufferMesh = mesh;
_meshUpdated = true;
if (nbrVertices < 0 || nbrVertices > static_cast<int>(obj.size()))
{
Log::get() << Log::WARNING << "Mesh::" << __FUNCTION__ << " - Bad buffer received, discarding" << Log::endl;
return false;
}
std::vector<std::vector<float>> data;
data.push_back(std::vector<float>(nbrVertices * 4));
data.push_back(std::vector<float>(nbrVertices * 2));
data.push_back(std::vector<float>(nbrVertices * 4));
bool hasAnnexe = false;
if (obj.size() > static_cast<uint32_t>(nbrVertices) * 4 * 14) // Check whether there is an annexe buffer in all this
{
hasAnnexe = true;
data.push_back(std::vector<float>(nbrVertices * 4));
}
// Let's read the values
try
{
for (auto& d : data)
{
ptr = reinterpret_cast<char*>(d.data());
std::copy(currentObjPtr, currentObjPtr + d.size() * sizeof(float), ptr);
currentObjPtr += d.size() * sizeof(float);
}
// Next step: use these values to reset the vertices of _mesh
MeshContainer mesh;
mesh.vertices.resize(nbrVertices);
const auto vertPtr = reinterpret_cast<float*>(mesh.vertices.data());
std::copy(data[0].data(), data[0].data() + nbrVertices * 4, vertPtr);
mesh.uvs.resize(nbrVertices);
const auto uvsPtr = reinterpret_cast<float*>(mesh.uvs.data());
std::copy(data[1].data(), data[1].data() + nbrVertices * 2, uvsPtr);
mesh.normals.resize(nbrVertices);
const auto normalsPtr = reinterpret_cast<float*>(mesh.normals.data());
std::copy(data[2].data(), data[2].data() + nbrVertices * 4, normalsPtr);
if (hasAnnexe)
{
mesh.annexe.resize(nbrVertices);
const auto annexePtr = reinterpret_cast<float*>(mesh.annexe.data());
std::copy(data[3].data(), data[3].data() + nbrVertices * 4, annexePtr);
}
_bufferMesh = mesh;
_meshUpdated = true;
updateTimestamp();
}
catch (...)
{
createDefaultMesh();
Log::get()(Log::ERROR, __FUNCTION__, " - Unable to deserialize the given object");
return false;
}
updateTimestamp();
if (Timer::get().isDebug())
Timer::get() >> ("deserialize " + _name);
+13 -14
View File
@@ -42,16 +42,23 @@ namespace Splash
class Mesh : public BufferObject
{
public:
struct MeshContainer
{
std::string name;
std::vector<glm::vec4> vertices;
std::vector<glm::vec2> uvs;
std::vector<glm::vec4> normals;
std::vector<glm::vec4> annexe;
};
public:
/**
* Constructor
* \param root Root object
* \param meshContainer Mesh container to initialize the Mesh from
*/
Mesh(RootObject* root);
/**
* Destructor
*/
virtual ~Mesh() override;
Mesh(RootObject* root, MeshContainer meshContainer = MeshContainer());
/**
* No copy constructor, but a copy operator
@@ -141,14 +148,6 @@ class Mesh : public BufferObject
virtual void update() override;
protected:
struct MeshContainer
{
std::vector<glm::vec4> vertices;
std::vector<glm::vec2> uvs;
std::vector<glm::vec4> normals;
std::vector<glm::vec4> annexe;
};
std::string _filepath{};
MeshContainer _mesh;
MeshContainer _bufferMesh;
+2
View File
@@ -81,6 +81,7 @@ target_sources(unitTests PRIVATE
unit_tests/core/value.cpp
unit_tests/core/world.cpp
unit_tests/core/serialize/serialize_imagebuffer.cpp
unit_tests/core/serialize/serialize_mesh.cpp
unit_tests/image/image.cpp
unit_tests/image/image_list.cpp
unit_tests/utils/dense_deque.cpp
@@ -109,6 +110,7 @@ if (NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
add_custom_command(OUTPUT update_assets
COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/data
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/data/*.json ${CMAKE_CURRENT_BINARY_DIR}/data/
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/data/*.obj ${CMAKE_CURRENT_BINARY_DIR}/data/
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/../data/share/splash/color_map.png ${CMAKE_CURRENT_BINARY_DIR}/data/
)
+254
View File
@@ -0,0 +1,254 @@
# Blender v2.76 (sub 0) OBJ File: 'plane_1_projector.blend'
# www.blender.org
o Cubes_Plane.001
v -1.000000 -0.000000 -0.500000
v -1.000000 0.000000 0.500000
v -1.000000 1.000000 -0.500000
v -1.000000 1.000000 0.500000
v 0.000000 1.000000 -0.500000
v 0.000000 -1.000000 -0.500000
v 0.000000 -1.000000 0.500000
v 0.000000 0.000000 -0.500000
v 1.000000 -1.000000 -0.500000
v 1.000000 -1.000000 0.500000
v 1.000000 0.000000 -0.500000
v 1.000000 -0.000000 0.500000
v 1.000000 1.000000 -0.500000
v 0.000000 0.000000 0.500000
v 0.000000 -0.000000 1.500000
v 0.000000 1.000000 0.500000
v 0.000000 1.000000 1.500000
v 1.000000 -0.000000 1.500000
v 1.000000 1.000000 0.500000
v 1.000000 1.000000 1.500000
v -1.000000 0.000000 0.000000
v -1.000000 0.500000 0.500000
v -1.000000 1.000000 -0.000000
v -1.000000 0.500000 -0.500000
v -0.500000 1.000000 0.500000
v 0.000000 1.000000 -0.000000
v -0.500000 1.000000 -0.500000
v 0.000000 0.000000 0.000000
v 0.000000 0.500000 -0.500000
v -0.500000 0.000000 0.500000
v -0.500000 -0.000000 -0.500000
v 0.000000 -1.000000 0.000000
v 0.000000 -0.500000 0.500000
v 0.000000 -0.500000 -0.500000
v 1.000000 0.000000 0.000000
v 0.500000 0.000000 -0.500000
v 1.000000 -0.500000 0.500000
v 1.000000 -1.000000 0.000000
v 1.000000 -0.500000 -0.500000
v 0.500000 -1.000000 0.500000
v 0.500000 -1.000000 -0.500000
v 1.000000 1.000000 -0.000000
v 0.500000 1.000000 -0.500000
v 1.000000 0.500000 0.500000
v 1.000000 0.500000 -0.500000
v 0.000000 0.000000 1.000000
v 0.000000 0.500000 1.500000
v 0.000000 1.000000 1.000000
v 0.000000 0.500000 0.500000
v 0.500000 1.000000 1.500000
v 1.000000 1.000000 1.000000
v 0.500000 1.000000 0.500000
v 1.000000 0.500000 1.500000
v 1.000000 0.000000 1.000000
v 0.500000 -0.000000 1.500000
v 0.500000 0.000000 0.500000
v 0.500000 0.500000 1.500000
v 0.500000 0.000000 1.000000
v 1.000000 0.500000 1.000000
v 0.500000 1.000000 1.000000
v 0.000000 0.500000 1.000000
v 0.500000 0.500000 -0.500000
v 1.000000 0.500000 -0.000000
v 0.500000 1.000000 -0.000000
v 0.500000 -0.500000 0.500000
v 0.500000 -0.500000 -0.500000
v 0.500000 -1.000000 0.000000
v 1.000000 -0.500000 0.000000
v 0.000000 -0.500000 0.000000
v -0.500000 0.500000 0.500000
v -0.500000 0.500000 -0.500000
v -0.500000 0.000000 0.000000
v -0.500000 1.000000 -0.000000
v -1.000000 0.500000 -0.000000
vt 0.100000 0.500000
vt 0.100000 0.400000
vt 0.200000 0.400000
vt 0.200000 0.500000
vt 0.900000 0.100000
vt 0.900000 0.000000
vt 1.000000 0.000000
vt 1.000000 0.100000
vt 0.700000 0.200000
vt 0.700000 0.300000
vt 0.600000 0.300000
vt 0.600000 0.200000
vt 0.500000 0.900000
vt 0.500000 1.000000
vt 0.400000 1.000000
vt 0.400000 0.900000
vt 0.700000 0.400000
vt 0.600000 0.400000
vt 0.500000 0.300000
vt 0.500000 0.400000
vt 0.000000 0.400000
vt 0.000000 0.300000
vt 0.100000 0.300000
vt 0.300000 0.100000
vt 0.200000 0.100000
vt 0.200000 0.000000
vt 0.300000 0.000000
vt 0.900000 0.300000
vt 0.900000 0.400000
vt 0.800000 0.400000
vt 0.800000 0.300000
vt 0.300000 0.700000
vt 0.300000 0.800000
vt 0.200000 0.800000
vt 0.200000 0.700000
vt 0.700000 0.700000
vt 0.700000 0.600000
vt 0.800000 0.600000
vt 0.800000 0.700000
vt 0.800000 0.500000
vt 0.700000 0.500000
vt 0.700000 0.100000
vt 0.600000 0.100000
vt 0.000000 0.200000
vt 0.100000 0.200000
vt 0.300000 0.500000
vt 0.300000 0.400000
vt 0.400000 0.400000
vt 0.400000 0.500000
vt 0.900000 0.700000
vt 0.900000 0.600000
vt 1.000000 0.600000
vt 1.000000 0.700000
vt 0.500000 0.700000
vt 0.500000 0.800000
vt 0.400000 0.800000
vt 0.400000 0.700000
vt 0.700000 0.000000
vt 0.600000 0.000000
vt 0.700000 0.900000
vt 0.700000 1.000000
vt 0.600000 1.000000
vt 0.600000 0.900000
vt 0.700000 0.800000
vt 0.600000 0.800000
vt 0.800000 0.800000
vt 0.800000 0.900000
vt 0.800000 1.000000
vt 0.800000 0.000000
vt 0.800000 0.100000
vt 0.500000 0.600000
vt 0.400000 0.600000
vt 0.500000 0.100000
vt 0.500000 0.000000
vt 0.600000 0.600000
vt 0.600000 0.700000
vt 0.500000 0.200000
vt 0.400000 0.200000
vt 0.400000 0.100000
vt 0.900000 0.800000
vt 1.000000 0.800000
vt 0.300000 0.600000
vt 0.200000 0.600000
vt 0.400000 0.000000
vt 0.300000 0.300000
vt 0.300000 0.200000
vt 0.400000 0.300000
vt 0.200000 0.300000
vt 0.200000 0.200000
vt 0.600000 0.500000
vt 0.900000 0.200000
vt 0.800000 0.200000
vt 1.000000 0.200000
vt 1.000000 0.300000
vt 1.000000 0.400000
vt 0.100000 0.600000
vt 0.000000 0.600000
vt 0.000000 0.500000
vn -1.000000 0.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 0.000000 1.000000
vn 1.000000 0.000000 0.000000
s off
f 74/1/1 23/2/1 3/3/1 24/4/1
f 73/5/2 26/6/2 5/7/2 27/8/2
f 31/9/3 71/10/3 29/11/3 8/12/3
f 72/13/4 21/14/4 1/15/4 31/16/4
f 71/10/3 27/17/3 5/18/3 29/11/3
f 70/19/5 25/11/5 4/18/5 22/20/5
f 44/2/6 12/21/6 35/22/6 63/23/6
f 68/24/6 38/25/6 9/26/6 39/27/6
f 67/28/4 32/29/4 6/30/4 41/31/4
f 66/32/3 36/33/3 11/34/3 39/35/3
f 64/36/2 42/37/2 13/38/2 43/39/2
f 37/17/5 12/30/5 56/40/5 65/41/5
f 62/42/3 43/9/3 13/12/3 45/43/3
f 63/23/6 35/22/6 11/44/6 45/45/6
f 61/46/1 48/47/1 16/48/1 49/49/1
f 60/50/2 51/51/2 19/52/2 52/53/2
f 58/54/4 46/55/4 14/56/4 56/57/4
f 36/58/3 62/42/3 45/43/3 11/59/3
f 57/60/5 50/61/5 17/62/5 47/63/5
f 55/64/5 57/60/5 47/63/5 15/65/5
f 18/66/5 53/67/5 57/60/5 55/64/5
f 53/67/5 20/68/5 50/61/5 57/60/5
f 8/69/3 29/70/3 62/42/3 36/58/3
f 54/71/4 58/54/4 56/57/4 12/72/4
f 51/43/6 59/73/6 44/74/6 19/59/6
f 18/75/4 55/76/4 58/54/4 54/71/4
f 55/76/4 15/65/4 46/55/4 58/54/4
f 20/12/6 53/77/6 59/73/6 51/43/6
f 53/77/6 18/78/6 54/79/6 59/73/6
f 48/80/2 60/50/2 52/53/2 16/81/2
f 17/66/2 50/39/2 60/50/2 48/80/2
f 50/39/2 20/38/2 51/51/2 60/50/2
f 46/82/1 61/46/1 49/49/1 14/72/1
f 15/83/1 47/4/1 61/46/1 46/82/1
f 47/4/1 17/3/1 48/47/1 61/46/1
f 59/73/6 54/79/6 12/84/6 44/74/6
f 69/85/1 28/86/1 8/78/1 34/87/1
f 65/41/5 56/40/5 14/38/5 33/37/5
f 33/88/1 14/89/1 28/86/1 69/85/1
f 16/65/2 52/76/2 64/36/2 26/64/2
f 52/76/2 19/75/2 42/37/2 64/36/2
f 42/88/6 63/23/6 45/45/6 13/89/6
f 14/65/4 30/63/4 72/13/4 28/55/4
f 25/70/2 16/69/2 26/6/2 73/5/2
f 40/90/5 65/41/5 33/37/5 7/75/5
f 10/18/5 37/17/5 65/41/5 40/90/5
f 41/82/3 66/32/3 39/35/3 9/83/3
f 6/72/3 34/57/3 66/32/3 41/82/3
f 34/57/3 8/56/3 36/33/3 66/32/3
f 38/91/4 67/28/4 41/31/4 9/92/4
f 10/93/4 40/94/4 67/28/4 38/91/4
f 40/94/4 7/95/4 32/29/4 67/28/4
f 35/79/6 68/24/6 39/27/6 11/84/6
f 12/78/6 37/86/6 68/24/6 35/79/6
f 37/86/6 10/89/6 38/25/6 68/24/6
f 26/64/2 64/36/2 43/39/2 5/66/2
f 29/70/3 5/92/3 43/9/3 62/42/3
f 19/3/6 44/2/6 63/23/6 42/88/6
f 32/47/1 69/85/1 34/87/1 6/48/1
f 7/3/1 33/88/1 69/85/1 32/47/1
f 30/87/5 70/19/5 22/20/5 2/48/5
f 1/92/3 24/31/3 71/10/3 31/9/3
f 24/31/3 3/30/3 27/17/3 71/10/3
f 30/63/4 2/62/4 21/14/4 72/13/4
f 28/55/4 72/13/4 31/16/4 8/56/4
f 14/78/5 49/77/5 70/19/5 30/87/5
f 49/77/5 16/12/5 25/11/5 70/19/5
f 23/91/2 73/5/2 27/8/2 3/93/2
f 4/92/2 25/70/2 73/5/2 23/91/2
f 21/96/1 74/1/1 24/4/1 1/83/1
f 2/97/1 22/98/1 74/1/1 21/96/1
f 22/98/1 4/21/1 23/2/1 74/1/1
@@ -15,7 +15,6 @@
* along with Splash. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <vector>
#include <doctest.h>
@@ -0,0 +1,57 @@
/*
* This file is part of Splash.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Splash is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Splash. If not, see <http://www.gnu.org/licenses/>.
*/
#include <vector>
#include <doctest.h>
#include "./core/serialize/serialize_mesh.h"
#include "./core/serializer.h"
#include "./mesh/mesh.h"
#include "./utils/osutils.h"
using namespace Splash;
/*************/
class MeshMockup : public Mesh
{
public:
MeshMockup()
: Mesh(nullptr)
{
}
MeshContainer getContainer() const { return _mesh; }
};
/*************/
TEST_CASE("Testing Mesh serialization")
{
MeshMockup mesh;
mesh.read(Utils::getCurrentWorkingDirectory() + "/data/cubes.obj");
auto container = mesh.getContainer();
CHECK(container.vertices.size() != 0);
std::vector<uint8_t> serializedMesh;
Serial::serialize(container, serializedMesh);
const auto deserializedMesh = Serial::deserialize<Mesh::MeshContainer>(serializedMesh);
CHECK_EQ(container.name, deserializedMesh.name);
CHECK_EQ(container.vertices, deserializedMesh.vertices);
CHECK_EQ(container.uvs, deserializedMesh.uvs);
CHECK_EQ(container.normals, deserializedMesh.normals);
CHECK_EQ(container.annexe, deserializedMesh.annexe);
}
+11
View File
@@ -2,6 +2,7 @@
#include <chrono>
#include <deque>
#include <iostream>
#include <tuple>
#include <vector>
@@ -30,6 +31,16 @@ TEST_CASE("Testing serialized size computation")
CHECK(Serial::getSize(chrono::system_clock::time_point(chrono::duration<int64_t, std::milli>(123456))) == sizeof(int64_t));
}
/*************/
TEST_CASE("Testing serialization of std::string")
{
const std::string someString = "Once upon a time...";
CHECK_EQ(Serial::getSize(someString), 23); // 4 (size as uint32_t) + 19 (char count)
std::vector<uint8_t> buffer;
Serial::serialize(someString, buffer);
CHECK_EQ(someString, Serial::deserialize<std::string>(buffer));
}
/*************/
TEST_CASE("Testing serialized size computation for containers of containers")
{