-
-
Notifications
You must be signed in to change notification settings - Fork 25
CURA-12544 saving and loading painted files in cura #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wawanbreton
merged 7 commits into
main
from
CURA-12544_saving-and-loading-painted-files-in-Cura
Jul 30, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
90d2c1d
Load UV coordinates for mesh data
wawanbreton 0e65f21
Allow storing UV coordinates
wawanbreton 25c883e
Allow exporting UV coordinates and texture information
wawanbreton e5fb29d
Save all resources with different IDs
wawanbreton 3ca62be
Fix wrong retrieved available ID
wawanbreton a0322fb
Clean debug code
wawanbreton 8db6981
Add documentation
wawanbreton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright (c) 2025 Ultimaker B.V. | ||
| // libSavitar is released under the terms of the LGPLv3 or higher. | ||
|
|
||
| #ifndef TEXTUREDATA_H | ||
| #define TEXTUREDATA_H | ||
|
|
||
| #include "Types.h" | ||
| #include "UVCoordinate.h" | ||
|
|
||
| #include <map> | ||
| #include <pugixml.hpp> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| namespace Savitar | ||
| { | ||
| /** | ||
| * The TextureData stores UV coordinates groups and textures paths, that will end-up as resources in the global model description | ||
| */ | ||
| class TextureData | ||
| { | ||
| public: | ||
| struct UVCoordinatesGroup | ||
| { | ||
| int texture_id; // The ID of the associated texture | ||
| std::vector<UVCoordinate> coordinates; // The actual UV coordinates of the group | ||
| }; | ||
|
|
||
| TextureData(); | ||
| virtual ~TextureData() = default; | ||
|
|
||
| void fillByXMLNode(pugi::xml_node xml_node); | ||
|
|
||
| void toXmlNode(pugi::xml_node& resources_node); | ||
|
|
||
| [[nodiscard]] std::string getTexturePath(const int texture_id) const; | ||
|
|
||
| [[nodiscard]] const UVCoordinatesGroup* getUVCoordinatesGroup(const int id) const; | ||
|
|
||
| /** | ||
| * Loads a UV coordinates group from raw data | ||
| * @param data The actual UV coordinates as an array of floats | ||
| * @param texture_id The ID of the associated texture | ||
| * @param group_id The ID of the newly created group | ||
| */ | ||
| void setUVCoordinatesGroupFromBytes(const bytearray& data, const int texture_id, const int group_id); | ||
|
|
||
| void addTexturePath(const std::string& texture_path, const int id); | ||
|
|
||
| [[nodiscard]] std::string getTexturePathFromGroupId(const int uv_group_id) const; | ||
|
|
||
| /** | ||
| * Find the next available resource ID amongst actually stored texture and UV coordinates. This should be called before | ||
| * adding any of these resources, so that IDs are unique in the end. | ||
| */ | ||
| [[nodiscard]] int getNextAvailableResourceId() const; | ||
|
|
||
| private: | ||
| std::map<int, std::string> textures_paths_; | ||
| std::map<int, UVCoordinatesGroup> uv_coordinates_; | ||
| }; | ||
| } // namespace Savitar | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Copyright (c) 2025 Ultimaker B.V. | ||
| // libSavitar is released under the terms of the LGPLv3 or higher. | ||
|
|
||
| #ifndef UVCOORDINATE_H | ||
| #define UVCOORDINATE_H | ||
|
|
||
| namespace Savitar | ||
| { | ||
| class UVCoordinate | ||
| { | ||
| public: | ||
| /** | ||
| * A UV coordinate represents the position of the point on a texture image. | ||
| */ | ||
| UVCoordinate(float u, float v); | ||
| virtual ~UVCoordinate() = default; | ||
|
|
||
| [[nodiscard]] float getU() const; | ||
| [[nodiscard]] float getV() const; | ||
|
|
||
| private: | ||
| float u_; | ||
| float v_; | ||
| }; | ||
| } // namespace Savitar | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright (c) 2025 Ultimaker B.V. | ||
| // libSavitar is released under the terms of the LGPLv3 or higher. | ||
|
|
||
| #ifndef UVCOORDINATESINDICES_H | ||
| #define UVCOORDINATESINDICES_H | ||
|
|
||
| namespace Savitar | ||
| { | ||
| /** | ||
| * UV coordinates indices contains the UV group ID and associated indices for each point of a face. A single mesh may contain indices | ||
| * from multiple texture. | ||
| */ | ||
| class UVCoordinatesIndices | ||
| { | ||
| public: | ||
| UVCoordinatesIndices(int group_index, int vertex_1_index, int vertex_2_index, int vertex_3_index); | ||
| virtual ~UVCoordinatesIndices() = default; | ||
|
|
||
| [[nodiscard]] int getGroupIndex() const; | ||
| [[nodiscard]] int getV1() const; | ||
| [[nodiscard]] int getV2() const; | ||
| [[nodiscard]] int getV3() const; | ||
|
|
||
| private: | ||
| int group_index_{}; | ||
| int vertex_1_index_{}; | ||
| int vertex_2_index_{}; | ||
| int vertex_3_index_{}; | ||
| }; | ||
| } // namespace Savitar | ||
|
|
||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason this change is needed? We just added savitar to neoprep and since javascript doens't have true integer numeric types. This change would be a bit non-idiomatic to implement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ! Since we now have to handle:
And all of them should be unique, libSavitar calculates proper IDs for everyone, so I need to store them as integers so that I can find a proper value for the next time I need an ID. If this really is an issue, I can find an other way, but I would prefer not to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strings could also solve the that specific issue right? If we use integers, can we then somehow make sure the ID never excedes$2^{53} – 1$ as this is the max safe integer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDs are using incremented integers starting from 0, so we should be safe 😄