mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 04:31:15 -06:00 
			
		
		
		
	Moved the projection function into PrintObject.cpp
This commit is contained in:
		
							parent
							
								
									79ef456d7c
								
							
						
					
					
						commit
						7fc4a71715
					
				
					 3 changed files with 111 additions and 109 deletions
				
			
		|  | @ -192,6 +192,11 @@ public: | |||
|     std::vector<ExPolygons>     slice_support_blockers() const { return this->slice_support_volumes(ModelVolumeType::SUPPORT_BLOCKER); } | ||||
|     std::vector<ExPolygons>     slice_support_enforcers() const { return this->slice_support_volumes(ModelVolumeType::SUPPORT_ENFORCER); } | ||||
| 
 | ||||
|     // Helpers to project custom supports on slices
 | ||||
|     void project_and_append_custom_supports(FacetSupportType type, std::vector<ExPolygons>& expolys) const; | ||||
|     void project_and_append_custom_enforcers(std::vector<ExPolygons>& enforcers) const { project_and_append_custom_supports(FacetSupportType::ENFORCER, enforcers); } | ||||
|     void project_and_append_custom_blockers(std::vector<ExPolygons>& blockers) const { project_and_append_custom_supports(FacetSupportType::BLOCKER, blockers); } | ||||
| 
 | ||||
| private: | ||||
|     // to be called from Print only.
 | ||||
|     friend class Print; | ||||
|  |  | |||
|  | @ -2645,4 +2645,107 @@ void PrintObject::_generate_support_material() | |||
|     support_material.generate(*this); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void PrintObject::project_and_append_custom_supports( | ||||
|         FacetSupportType type, std::vector<ExPolygons>& expolys) const | ||||
| { | ||||
|     for (const ModelVolume* mv : this->model_object()->volumes) { | ||||
|         const auto& custom_facets = mv->m_supported_facets.get_facets(type); | ||||
|         const TriangleMesh& mesh = mv->mesh(); | ||||
|         const Transform3f& tr1 = mv->get_matrix().cast<float>(); | ||||
|         const Transform3f& tr2 = this->trafo().cast<float>(); | ||||
| 
 | ||||
|         // List of all layers.
 | ||||
|         const LayerPtrs& layers = this->layers(); | ||||
| 
 | ||||
|         // Make sure that enforcers vector can be used.
 | ||||
|         if (! custom_facets.empty()) | ||||
|         expolys.resize(layers.size()); | ||||
| 
 | ||||
|         // Iterate over all triangles.
 | ||||
|         for (int facet_idx : custom_facets) { | ||||
|             std::array<Vec3f, 3> facet; | ||||
|             std::array<float, 3> z_heights; | ||||
| 
 | ||||
|             // Transform the triangle into worlds coords.
 | ||||
|             for (int i=0; i<3; ++i) | ||||
|                 facet[i] = tr2 * tr1 * mesh.its.vertices[mesh.its.indices[facet_idx](i)]; | ||||
| 
 | ||||
|             // Sort the three vertices according to z-coordinate.
 | ||||
|             std::sort(facet.begin(), facet.end(), | ||||
|                       [](const Vec3f& pt1, const Vec3f&pt2) { | ||||
|                           return pt1.z() < pt2.z(); | ||||
|                       }); | ||||
| 
 | ||||
|             Polygon triangle; | ||||
|             for (int i=0; i<3; ++i) { | ||||
|                 z_heights[i] = facet[i].z(); | ||||
|                 triangle.append(Point::new_scale(facet[i].x(), facet[i].y())); | ||||
|                 triangle.translate(this->center_offset()); | ||||
|             } | ||||
| 
 | ||||
|             // Find lowest slice not below the triangle.
 | ||||
|             auto it = std::lower_bound(layers.begin(), layers.end(), z_heights[0], | ||||
|                           [](const Layer* l1, float z) { | ||||
|                                return l1->slice_z < z; | ||||
|                           }); | ||||
| 
 | ||||
| 
 | ||||
|             // Calculate how to move points on triangle sides per unit z increment.
 | ||||
|             Point ta(triangle.points[1] - triangle.points[0]); | ||||
|             Point tb(triangle.points[2] - triangle.points[0]); | ||||
| 
 | ||||
|             ta *= 1./(z_heights[1] - z_heights[0]); | ||||
|             tb *= 1./(z_heights[2] - z_heights[0]); | ||||
| 
 | ||||
|             Points proj; | ||||
|             proj.emplace_back(triangle.points[0]); | ||||
| 
 | ||||
|             Point a(proj.back()); | ||||
|             Point b(proj.back()); | ||||
|             float last_z = facet[0].z(); | ||||
|             bool passed_first = false; | ||||
|             bool stop = false; | ||||
| 
 | ||||
|             // Project a sub-triangle on all slices intersecting the triangle.
 | ||||
|             while (it != layers.end()) { | ||||
|                 const float z = (*it)->slice_z; | ||||
| 
 | ||||
|                 if (z > z_heights[1] && ! passed_first) { | ||||
|                     a = triangle.points[1]; | ||||
|                     ta = triangle.points[2]-triangle.points[1]; | ||||
|                     ta *= 1./(z_heights[2] - z_heights[1]); | ||||
|                     proj.push_back(a); | ||||
|                     passed_first = true; | ||||
|                 } | ||||
|                 a += ta * (z-last_z); | ||||
| 
 | ||||
|                 if (z > z_heights[2] || it+1 == layers.end()) { | ||||
|                     b = triangle.points[2]; | ||||
|                     proj.push_back(b); | ||||
|                     stop = true; | ||||
|                 } | ||||
|                 else { | ||||
|                     b += tb * (z-last_z); | ||||
|                     proj.push_back(a+ta); | ||||
|                     proj.push_back(b+tb); | ||||
|                 } | ||||
| 
 | ||||
|                 if (it != layers.begin()) | ||||
|                     expolys[it-layers.begin()-1].emplace_back(proj); | ||||
| 
 | ||||
|                 if (stop) | ||||
|                     break; | ||||
| 
 | ||||
|                 proj.clear(); | ||||
|                 proj.push_back(b); | ||||
|                 proj.push_back(a); | ||||
| 
 | ||||
|                 ++it; | ||||
|                 last_z = z; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| } // namespace Slic3r
 | ||||
|  |  | |||
|  | @ -971,115 +971,9 @@ PrintObjectSupportMaterial::MyLayersPtr PrintObjectSupportMaterial::top_contact_ | |||
|     std::vector<ExPolygons> enforcers = object.slice_support_enforcers(); | ||||
|     std::vector<ExPolygons> blockers  = object.slice_support_blockers(); | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     ///////////////////////////////////////////////////////////////////////////
 | ||||
|     ///     TEMPORARY INLINE DRAFT PROJECTING CUSTOM SUPPORTS ON SLICES     ///
 | ||||
|     /// ///////////////////////////////////////////////////////////////////////
 | ||||
|     const auto& data = object.model_object()->volumes.front()->m_supported_facets; | ||||
|     const auto& custom_enf = data.get_facets(FacetSupportType::ENFORCER); | ||||
|     const TriangleMesh& mesh = object.model_object()->volumes.front()->mesh(); | ||||
|     const Transform3f& tr1 = object.model_object()->volumes.front()->get_matrix().cast<float>(); | ||||
|     const Transform3f& tr2 = object.trafo().cast<float>(); | ||||
| 
 | ||||
|     // Make a list of all layers.
 | ||||
|     const LayerPtrs& layers = object.layers(); | ||||
| 
 | ||||
|     // Make sure that enforcers vector can be used.
 | ||||
|     if (! custom_enf.empty()) | ||||
|         enforcers.resize(layers.size()); | ||||
| 
 | ||||
|     // Iterate over all triangles.
 | ||||
|     for (int facet_idx : custom_enf) { | ||||
|         std::array<Vec3f, 3> facet; | ||||
|         std::array<float, 3> z_heights; | ||||
| 
 | ||||
|         // Transform the triangle into worlds coords.
 | ||||
|         for (int i=0; i<3; ++i) | ||||
|             facet[i] = tr2 * tr1 * mesh.its.vertices[mesh.its.indices[facet_idx](i)]; | ||||
| 
 | ||||
|         // Sort the three vertices according to z-coordinate.
 | ||||
|         std::sort(facet.begin(), facet.end(), | ||||
|                   [](const Vec3f& pt1, const Vec3f&pt2) { | ||||
|                       return pt1.z() < pt2.z(); | ||||
|                   }); | ||||
| 
 | ||||
|         Polygon triangle; | ||||
|         for (int i=0; i<3; ++i) { | ||||
|             z_heights[i] = facet[i].z(); | ||||
|             triangle.append(Point::new_scale(facet[i].x(), facet[i].y())); | ||||
|             triangle.translate(object.center_offset()); | ||||
|         } | ||||
| 
 | ||||
|         // Find lowest slice not below the triangle.
 | ||||
|         auto it = std::lower_bound(layers.begin(), layers.end(), z_heights[0], | ||||
|                       [](const Layer* l1, float z) { | ||||
|                            return l1->slice_z < z; | ||||
|                       }); | ||||
| 
 | ||||
| 
 | ||||
|         // Calculate how to move points on triangle sides per unit z increment.
 | ||||
|         Point ta(triangle.points[1] - triangle.points[0]); | ||||
|         Point tb(triangle.points[2] - triangle.points[0]); | ||||
| 
 | ||||
|         ta *= 1./(z_heights[1] - z_heights[0]); | ||||
|         tb *= 1./(z_heights[2] - z_heights[0]); | ||||
| 
 | ||||
|         Points proj; | ||||
|         proj.emplace_back(triangle.points[0]); | ||||
| 
 | ||||
|         Point a(proj.back()); | ||||
|         Point b(proj.back()); | ||||
|         float last_z = facet[0].z(); | ||||
|         bool passed_first = false; | ||||
|         bool stop = false; | ||||
| 
 | ||||
|         // Project a sub-triangle on all slices intersecting the triangle.
 | ||||
|         while (it != layers.end()) { | ||||
|             const float z = (*it)->slice_z; | ||||
| 
 | ||||
|             if (z > z_heights[1] && ! passed_first) { | ||||
|                 a = triangle.points[1]; | ||||
|                 ta = triangle.points[2]-triangle.points[1]; | ||||
|                 ta *= 1./(z_heights[2] - z_heights[1]); | ||||
|                 proj.push_back(a); | ||||
|                 passed_first = true; | ||||
|             } | ||||
|             a += ta * (z-last_z); | ||||
| 
 | ||||
|             if (z > z_heights[2] || it+1 == layers.end()) { | ||||
|                 b = triangle.points[2]; | ||||
|                 proj.push_back(b); | ||||
|                 stop = true; | ||||
|             } | ||||
|             else { | ||||
|                 b += tb * (z-last_z); | ||||
|                 proj.push_back(a+ta); | ||||
|                 proj.push_back(b+tb); | ||||
|             } | ||||
| 
 | ||||
|             if (it != layers.begin()) | ||||
|                 enforcers[it-layers.begin()-1].emplace_back(proj); | ||||
| 
 | ||||
|             if (stop) | ||||
|                 break; | ||||
| 
 | ||||
|             proj.clear(); | ||||
|             proj.push_back(b); | ||||
|             proj.push_back(a); | ||||
| 
 | ||||
|             ++it; | ||||
|             last_z = z; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     ///////////////////////////////////////////////////////////////////////////
 | ||||
|     ///////////////////////////////////////////////////////////////////////////
 | ||||
|     ///////////////////////////////////////////////////////////////////////////
 | ||||
| 
 | ||||
|     // Append custom supports.
 | ||||
|     object.project_and_append_custom_enforcers(enforcers); | ||||
|     object.project_and_append_custom_blockers(blockers); | ||||
| 
 | ||||
|     // Output layers, sorted by top Z.
 | ||||
|     MyLayersPtr contact_out; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lukas Matena
						Lukas Matena