mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 04:31:15 -06:00 
			
		
		
		
	ENABLE_ENHANCED_RELOAD_FROM_DISK
1) Modified .zip.amf import/export to save/load volume matrices and source data 2) Incremented .zip.amf version to 3
This commit is contained in:
		
							parent
							
								
									3a40565d03
								
							
						
					
					
						commit
						74747226f7
					
				
					 7 changed files with 130 additions and 35 deletions
				
			
		|  | @ -32,7 +32,7 @@ namespace pt = boost::property_tree; | |||
| // 0 : .3mf, files saved by older slic3r or other applications. No version definition in them.
 | ||||
| // 1 : Introduction of 3mf versioning. No other change in data saved into 3mf files.
 | ||||
| #if ENABLE_ENHANCED_RELOAD_FROM_DISK | ||||
| // 2 : Meshes saved in their local system and volumes matrices added to Metadata/Slic3r_PE_model.config file.
 | ||||
| // 2 : Meshes saved in their local system; Volumes' matrices and source data added to Metadata/Slic3r_PE_model.config file.
 | ||||
| const unsigned int VERSION_3MF = 2; | ||||
| #else | ||||
| const unsigned int VERSION_3MF = 1; | ||||
|  | @ -208,35 +208,6 @@ Slic3r::Transform3d get_transform_from_string(const std::string& mat_str) | |||
|     return ret; | ||||
| } | ||||
| 
 | ||||
| #if ENABLE_ENHANCED_RELOAD_FROM_DISK | ||||
| Slic3r::Transform3d get_transform_from_string(const std::string& mat_str) | ||||
| { | ||||
|     Slic3r::Transform3d ret = Slic3r::Transform3d::Identity(); | ||||
| 
 | ||||
|     if (mat_str.empty()) | ||||
|         // empty string means default identity matrix
 | ||||
|         return ret; | ||||
| 
 | ||||
|     std::vector<std::string> mat_elements_str; | ||||
|     boost::split(mat_elements_str, mat_str, boost::is_any_of(" "), boost::token_compress_on); | ||||
| 
 | ||||
|     unsigned int size = (unsigned int)mat_elements_str.size(); | ||||
|     if (size != 16) | ||||
|         // invalid data, return identity matrix
 | ||||
|         return ret; | ||||
| 
 | ||||
|     unsigned int i = 0; | ||||
|     for (unsigned int r = 0; r < 4; ++r) | ||||
|     { | ||||
|         for (unsigned int c = 0; c < 4; ++c) | ||||
|         { | ||||
|             ret(r, c) = ::atof(mat_elements_str[i++].c_str()); | ||||
|         } | ||||
|     } | ||||
|     return ret; | ||||
| } | ||||
| #endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
 | ||||
| 
 | ||||
| float get_unit_factor(const std::string& unit) | ||||
| { | ||||
|     const char* text = unit.c_str(); | ||||
|  | @ -1744,7 +1715,11 @@ namespace Slic3r { | |||
|                     volume->set_type(ModelVolume::type_from_string(metadata.value)); | ||||
| #if ENABLE_ENHANCED_RELOAD_FROM_DISK | ||||
|                 else if (metadata.key == MATRIX_KEY) | ||||
|                     volume->set_transformation(Slic3r::Geometry::Transformation(get_transform_from_string(metadata.value))); | ||||
|                 { | ||||
|                     Slic3r::Geometry::Transformation transform; | ||||
|                     transform.set_from_string(metadata.value); | ||||
|                     volume->set_transformation(transform); | ||||
|                 } | ||||
|                 else if (metadata.key == SOURCE_FILE_KEY) | ||||
|                     volume->source.input_file = metadata.value; | ||||
|                 else if (metadata.key == SOURCE_OBJECT_ID_KEY) | ||||
|  |  | |||
|  | @ -12,6 +12,9 @@ | |||
| #include "../PrintConfig.hpp" | ||||
| #include "../Utils.hpp" | ||||
| #include "../I18N.hpp" | ||||
| #if ENABLE_ENHANCED_RELOAD_FROM_DISK | ||||
| #include "../Geometry.hpp" | ||||
| #endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
 | ||||
| 
 | ||||
| #include "AMF.hpp" | ||||
| 
 | ||||
|  | @ -36,7 +39,12 @@ | |||
| //     Added x and y components of rotation
 | ||||
| //     Added x, y and z components of scale
 | ||||
| //     Added x, y and z components of mirror
 | ||||
| #if ENABLE_ENHANCED_RELOAD_FROM_DISK | ||||
| // 3 : Meshes saved in their local system; Added volumes' matrices and source data
 | ||||
| const unsigned int VERSION_AMF = 3; | ||||
| #else | ||||
| const unsigned int VERSION_AMF = 2; | ||||
| #endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
 | ||||
| const char* SLIC3RPE_AMF_VERSION = "slic3rpe_amf_version"; | ||||
| 
 | ||||
| const char* SLIC3R_CONFIG_TYPE = "slic3rpe_config"; | ||||
|  | @ -568,7 +576,12 @@ void AMFParserContext::endElement(const char * /* name */) | |||
|         stl_get_size(&stl); | ||||
|         mesh.repair(); | ||||
| 		m_volume->set_mesh(std::move(mesh)); | ||||
| #if ENABLE_ENHANCED_RELOAD_FROM_DISK | ||||
|         // pass false if the mesh offset has been already taken from the data 
 | ||||
|         m_volume->center_geometry_after_creation(m_volume->source.input_file.empty()); | ||||
| #else | ||||
|         m_volume->center_geometry_after_creation(); | ||||
| #endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
 | ||||
|         m_volume->calculate_convex_hull(); | ||||
|         m_volume_facets.clear(); | ||||
|         m_volume = nullptr; | ||||
|  | @ -664,6 +677,31 @@ void AMFParserContext::endElement(const char * /* name */) | |||
|                 } else if (strcmp(opt_key, "volume_type") == 0) { | ||||
|                     m_volume->set_type(ModelVolume::type_from_string(m_value[1])); | ||||
|                 } | ||||
| #if ENABLE_ENHANCED_RELOAD_FROM_DISK | ||||
|                 else if (strcmp(opt_key, "matrix") == 0) { | ||||
|                     Geometry::Transformation transform; | ||||
|                     transform.set_from_string(m_value[1]); | ||||
|                     m_volume->set_transformation(transform); | ||||
|                 } | ||||
|                 else if (strcmp(opt_key, "source_file") == 0) { | ||||
|                     m_volume->source.input_file = m_value[1]; | ||||
|                 } | ||||
|                 else if (strcmp(opt_key, "source_object_id") == 0) { | ||||
|                     m_volume->source.object_idx = ::atoi(m_value[1].c_str()); | ||||
|                 } | ||||
|                 else if (strcmp(opt_key, "source_volume_id") == 0) { | ||||
|                     m_volume->source.volume_idx = ::atoi(m_value[1].c_str()); | ||||
|                 } | ||||
|                 else if (strcmp(opt_key, "source_offset_x") == 0) { | ||||
|                     m_volume->source.mesh_offset(0) = ::atof(m_value[1].c_str()); | ||||
|                 } | ||||
|                 else if (strcmp(opt_key, "source_offset_y") == 0) { | ||||
|                     m_volume->source.mesh_offset(1) = ::atof(m_value[1].c_str()); | ||||
|                 } | ||||
|                 else if (strcmp(opt_key, "source_offset_z") == 0) { | ||||
|                     m_volume->source.mesh_offset(2) = ::atof(m_value[1].c_str()); | ||||
|                 } | ||||
| #endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
 | ||||
|             } | ||||
|         } else if (m_path.size() == 3) { | ||||
|             if (m_path[1] == NODE_TYPE_MATERIAL) { | ||||
|  | @ -1029,6 +1067,18 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config) | |||
| 			if (! volume->mesh().has_shared_vertices()) | ||||
| 				throw std::runtime_error("store_amf() requires shared vertices"); | ||||
|             const indexed_triangle_set &its = volume->mesh().its; | ||||
| #if ENABLE_ENHANCED_RELOAD_FROM_DISK | ||||
|             for (const Vec3f& v : its.vertices) | ||||
|             { | ||||
|                 stream << "         <vertex>\n"; | ||||
|                 stream << "           <coordinates>\n"; | ||||
|                 stream << "             <x>" << v(0) << "</x>\n"; | ||||
|                 stream << "             <y>" << v(1) << "</y>\n"; | ||||
|                 stream << "             <z>" << v(2) << "</z>\n"; | ||||
|                 stream << "           </coordinates>\n"; | ||||
|                 stream << "         </vertex>\n"; | ||||
|             } | ||||
| #else | ||||
|             const Transform3d& matrix = volume->get_matrix(); | ||||
|             for (size_t i = 0; i < its.vertices.size(); ++i) { | ||||
|                 stream << "         <vertex>\n"; | ||||
|  | @ -1040,6 +1090,7 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config) | |||
|                 stream << "           </coordinates>\n"; | ||||
|                 stream << "         </vertex>\n"; | ||||
|             } | ||||
| #endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
 | ||||
|             num_vertices += (int)its.vertices.size(); | ||||
|         } | ||||
|         stream << "      </vertices>\n"; | ||||
|  | @ -1057,7 +1108,30 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config) | |||
|             if (volume->is_modifier()) | ||||
|                 stream << "        <metadata type=\"slic3r.modifier\">1</metadata>\n"; | ||||
|             stream << "        <metadata type=\"slic3r.volume_type\">" << ModelVolume::type_to_string(volume->type()) << "</metadata>\n"; | ||||
| 			const indexed_triangle_set &its = volume->mesh().its; | ||||
| #if ENABLE_ENHANCED_RELOAD_FROM_DISK | ||||
|             stream << "        <metadata type=\"slic3r.matrix\">"; | ||||
|             const Transform3d& matrix = volume->get_matrix(); | ||||
|             for (int r = 0; r < 4; ++r) | ||||
|             { | ||||
|                 for (int c = 0; c < 4; ++c) | ||||
|                 { | ||||
|                     stream << matrix(r, c); | ||||
|                     if ((r != 3) || (c != 3)) | ||||
|                         stream << " "; | ||||
|                 } | ||||
|             } | ||||
|             stream << "</metadata>\n"; | ||||
|             if (!volume->source.input_file.empty()) | ||||
|             { | ||||
|                 stream << "        <metadata type=\"slic3r.source_file\">" << xml_escape(volume->source.input_file) << "</metadata>\n"; | ||||
|                 stream << "        <metadata type=\"slic3r.source_object_id\">" << volume->source.object_idx << "</metadata>\n"; | ||||
|                 stream << "        <metadata type=\"slic3r.source_volume_id\">" << volume->source.volume_idx << "</metadata>\n"; | ||||
|                 stream << "        <metadata type=\"slic3r.source_offset_x\">" << volume->source.mesh_offset(0) << "</metadata>\n"; | ||||
|                 stream << "        <metadata type=\"slic3r.source_offset_y\">" << volume->source.mesh_offset(1) << "</metadata>\n"; | ||||
|                 stream << "        <metadata type=\"slic3r.source_offset_z\">" << volume->source.mesh_offset(2) << "</metadata>\n"; | ||||
|             } | ||||
| #endif // ENABLE_ENHANCED_RELOAD_FROM_DISK
 | ||||
|             const indexed_triangle_set &its = volume->mesh().its; | ||||
|             for (size_t i = 0; i < its.indices.size(); ++i) { | ||||
|                 stream << "        <triangle>\n"; | ||||
|                 for (int j = 0; j < 3; ++j) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Enrico Turri
						Enrico Turri