Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conandata.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version: "5.11.0-alpha.0"
version: "5.12.0"
12 changes: 8 additions & 4 deletions include/Savitar/MeshData.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MeshData
/**
* Serialise the meshData to xml_node
*/
void toXmlNode(pugi::xml_node& xml_node);
void toXmlNode(pugi::xml_node& xml_node) const;

/**
* Return the vertices as flattend bytes.
Expand All @@ -49,7 +49,7 @@ class MeshData
*
* If there for example is a single face, it will return a byte array containing 3 ints (so 3 * 4 bytes)
*/
[[nodiscard]] bytearray getFacesAsBytes();
[[nodiscard]] bytearray getFacesAsBytes() const;

/**
* Instead of getting all unique vertices, this function returns a bytearray with 3 vertices per face.
Expand Down Expand Up @@ -93,7 +93,11 @@ class MeshData
*/
void setFacesFromBytes(const bytearray& data);

[[nodiscard]] std::vector<Vertex> getVertices();
[[nodiscard]] const std::vector<Vertex>& getVertices() const;

[[nodiscard]] const std::vector<Face>& getFaces() const;

[[nodiscard]] int getUVGroupId() const;

/**
* Reset the data of the MeshData object.
Expand All @@ -116,4 +120,4 @@ class MeshData
};
} // namespace Savitar

#endif
#endif
8 changes: 4 additions & 4 deletions include/Savitar/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Scene
* Get the scene nodes in this scene.
* \return The scene nodes that are in the scene.
*/
[[nodiscard]] std::vector<SceneNode*> getSceneNodes();
[[nodiscard]] const std::vector<SceneNode*>& getSceneNodes() const;

[[nodiscard]] std::vector<SceneNode*> getAllSceneNodes() const;

Expand All @@ -46,7 +46,7 @@ class Scene
/**
* Serialise the scene to model_node
*/
void toXmlNode(pugi::xml_node& model_node);
void toXmlNode(pugi::xml_node& model_node) const;

/**
* Store a metadata entry as metadata.
Expand Down Expand Up @@ -84,7 +84,7 @@ class Scene
* Get the unit (milimeter, inch, etc) of the scene.
* This is in milimeter by default.
*/
[[nodiscard]] std::string getUnit();
[[nodiscard]] const std::string& getUnit() const;

void setUnit(std::string unit);

Expand Down Expand Up @@ -116,4 +116,4 @@ class Scene
SceneNode* createSceneNodeFromObject(pugi::xml_node root_node, pugi::xml_node object_node);
};
} // namespace Savitar
#endif
#endif
12 changes: 6 additions & 6 deletions include/Savitar/SceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class SceneNode
SceneNode() = default;
virtual ~SceneNode() = default;

[[nodiscard]] std::string getTransformation();
void setTransformation(std::string);
[[nodiscard]] const std::string& getTransformation() const;
void setTransformation(const std::string& transformation);

[[nodiscard]] std::vector<SceneNode*> getChildren();
[[nodiscard]] std::vector<SceneNode*> getAllChildren();
[[nodiscard]] const std::vector<SceneNode*>& getChildren() const;
[[nodiscard]] std::vector<SceneNode*> getAllChildren() const;
bool addChild(SceneNode* node);

MeshData& getMeshData();
[[nodiscard]] const MeshData& getMeshData() const;
void setMeshData(const MeshData& mesh_data);

/**
Expand All @@ -51,7 +51,7 @@ class SceneNode
/**
* Get the (non-unique) display name of the node.
*/
[[nodiscard]] std::string getName();
[[nodiscard]] const std::string& getName() const;

[[maybe_unused]] void setName(std::string name);

Expand Down
4 changes: 2 additions & 2 deletions include/Savitar/TextureData.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TextureData

void fillByXMLNode(pugi::xml_node xml_node);

void toXmlNode(pugi::xml_node& resources_node);
void toXmlNode(pugi::xml_node& resources_node) const;

[[nodiscard]] std::string getTexturePath(const int texture_id) const;

Expand Down Expand Up @@ -61,4 +61,4 @@ class TextureData
};
} // namespace Savitar

#endif
#endif
18 changes: 14 additions & 4 deletions src/MeshData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ std::string MeshData::getTexturePath(const Scene* scene) const
return scene->getTexturePathFromGroupId(uv_group_id_);
}

bytearray MeshData::getFacesAsBytes()
bytearray MeshData::getFacesAsBytes() const
{
bytearray face_data;

Expand All @@ -220,7 +220,7 @@ bytearray MeshData::getFacesAsBytes()
return face_data;
}

void MeshData::toXmlNode(pugi::xml_node& node)
void MeshData::toXmlNode(pugi::xml_node& node) const
{
pugi::xml_node vertices_node = node.append_child("vertices");
for (auto& vertice : vertices_)
Expand Down Expand Up @@ -288,13 +288,23 @@ void MeshData::setFacesFromBytes(const bytearray& data)
}
}

std::vector<Vertex> MeshData::getVertices()
const std::vector<Vertex>& MeshData::getVertices() const
{
return vertices_;
}

const std::vector<Face>& MeshData::getFaces() const
{
return faces_;
}

int MeshData::getUVGroupId() const
{
return uv_group_id_;
}

template<typename T>
void MeshData::exportToByteArray(bytearray& data, const T value)
{
data.insert(data.end(), reinterpret_cast<const uint8_t*>(&value), reinterpret_cast<const uint8_t*>(&value) + sizeof(T));
}
}
6 changes: 3 additions & 3 deletions src/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

using namespace Savitar;

std::vector<SceneNode*> Scene::getSceneNodes()
const std::vector<SceneNode*>& Scene::getSceneNodes() const
{
return scene_nodes_;
}
Expand Down Expand Up @@ -87,7 +87,7 @@ void Scene::fillByXMLNode(pugi::xml_node xml_node)
}
}

void Scene::toXmlNode(pugi::xml_node& model_node)
void Scene::toXmlNode(pugi::xml_node& model_node) const
{
pugi::xml_node resources_node = model_node.append_child("resources");
pugi::xml_node build_node = model_node.append_child("build");
Expand Down Expand Up @@ -286,7 +286,7 @@ void Scene::setMetaDataEntry(const std::string& key, const std::string& value, c
metadata_.emplace(key, MetadataEntry(value, type, preserve));
}

std::string Scene::getUnit()
const std::string& Scene::getUnit() const
{
return unit_;
}
Expand Down
12 changes: 6 additions & 6 deletions src/SceneNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

using namespace Savitar;

std::string SceneNode::getTransformation()
const std::string& SceneNode::getTransformation() const
{
return transformation_;
}

void SceneNode::setTransformation(std::string transformation)
void SceneNode::setTransformation(const std::string& transformation)
{
transformation_ = transformation;
}
Expand All @@ -28,7 +28,7 @@ std::string SceneNode::getComponentPath() const
return component_path_;
}

std::vector<SceneNode*> SceneNode::getChildren()
const std::vector<SceneNode*>& SceneNode::getChildren() const
{
return children_;
}
Expand All @@ -52,7 +52,7 @@ bool SceneNode::addChild(SceneNode* node)
return true;
}

MeshData& SceneNode::getMeshData()
const MeshData& SceneNode::getMeshData() const
{
return mesh_data_;
}
Expand Down Expand Up @@ -181,7 +181,7 @@ void SceneNode::setId(const int id)
id_ = id;
}

std::string SceneNode::getName()
const std::string& SceneNode::getName() const
{
return name_;
}
Expand Down Expand Up @@ -212,7 +212,7 @@ void SceneNode::removeSetting(std::string key)
}


std::vector<SceneNode*> SceneNode::getAllChildren()
std::vector<SceneNode*> SceneNode::getAllChildren() const
{
std::vector<SceneNode*> all_children;

Expand Down
2 changes: 1 addition & 1 deletion src/TextureData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void TextureData::fillByXMLNode(pugi::xml_node xml_node)
}
}

void TextureData::toXmlNode(pugi::xml_node& resources_node)
void TextureData::toXmlNode(pugi::xml_node& resources_node) const
{
// Handle textures paths
for (const auto& texture_path : textures_paths_)
Expand Down
14 changes: 7 additions & 7 deletions tests/ThreeMFParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,24 @@ TEST_F(ThreeMFParserTest, parse)
std::array<size_t, 4> expected_tris = { 144UL, 144UL, 0UL, 0UL };
std::array<size_t, 4> expected_child = { 0UL, 0UL, 1UL, 1UL };
int i = -1;
for (SceneNode* node : nodes)
for (const SceneNode* node : nodes)
{
++i;
MeshData& data = node->getMeshData();
const MeshData& data = node->getMeshData();

const std::vector<Vertex>& verts = data.getVertices();
EXPECT_EQ(verts.size(), expected_verts[i]);

const bytearray& tris = data.getFacesAsBytes();
EXPECT_EQ(tris.size(), expected_tris[i]);

const std::vector<SceneNode*>& children = node->getAllChildren();
const std::vector<SceneNode*> children = node->getAllChildren();
ASSERT_EQ(children.size(), expected_child[i]);
for (SceneNode* child : children)
for (const SceneNode* child : children)
{
data = child->getMeshData();
EXPECT_FALSE(data.getVertices().empty());
EXPECT_FALSE(data.getFacesAsBytes().empty());
const MeshData& child_data = child->getMeshData();
EXPECT_FALSE(child_data.getVertices().empty());
EXPECT_FALSE(child_data.getFacesAsBytes().empty());
}
}
// NOTE: To/from for content of vertices/triangles is tested in MeshDataTest.
Expand Down