mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 20:51:12 -06:00 
			
		
		
		
	Ported some Model methods to XS
This commit is contained in:
		
							parent
							
								
									f06566dd3a
								
							
						
					
					
						commit
						b10917806a
					
				
					 7 changed files with 52 additions and 44 deletions
				
			
		|  | @ -312,6 +312,15 @@ ModelObject::invalidate_bounding_box() | |||
|     this->_bounding_box_valid = false; | ||||
| } | ||||
| 
 | ||||
| void | ||||
| ModelObject::raw_mesh(TriangleMesh* mesh) const | ||||
| { | ||||
|     for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) { | ||||
|         if ((*v)->modifier) continue; | ||||
|         mesh->merge((*v)->mesh); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #ifdef SLIC3RXS | ||||
| REGISTER_CLASS(ModelObject, "Model::Object"); | ||||
| #endif | ||||
|  | @ -349,6 +358,15 @@ ModelVolume::material() const | |||
|     return this->object->get_model()->get_material(this->_material_id); | ||||
| } | ||||
| 
 | ||||
| ModelMaterial* | ||||
| ModelVolume::assign_unique_material() | ||||
| { | ||||
|     Model* model = this->get_object()->get_model(); | ||||
|      | ||||
|     this->_material_id = 1 + model->materials.size(); | ||||
|     return model->add_material(this->_material_id); | ||||
| } | ||||
| 
 | ||||
| #ifdef SLIC3RXS | ||||
| REGISTER_CLASS(ModelVolume, "Model::Volume"); | ||||
| #endif | ||||
|  | @ -362,6 +380,22 @@ ModelInstance::ModelInstance(ModelObject *object, const ModelInstance &other) | |||
| :   object(object), rotation(other.rotation), scaling_factor(other.scaling_factor), offset(other.offset) | ||||
| {} | ||||
| 
 | ||||
| void | ||||
| ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const | ||||
| { | ||||
|     mesh->rotate_z(this->rotation);                 // rotate around mesh origin
 | ||||
|     mesh->scale(this->scaling_factor);              // scale around mesh origin
 | ||||
|     if (!dont_translate) | ||||
|         mesh->translate(this->offset.x, this->offset.y, 0); | ||||
| } | ||||
| 
 | ||||
| void | ||||
| ModelInstance::transform_polygon(Polygon* polygon) const | ||||
| { | ||||
|     polygon->rotate(this->rotation, Point(0,0));    // rotate around polygon origin
 | ||||
|     polygon->scale(this->scaling_factor);           // scale around polygon origin
 | ||||
| } | ||||
| 
 | ||||
| #ifdef SLIC3RXS | ||||
| REGISTER_CLASS(ModelInstance, "Model::Instance"); | ||||
| #endif | ||||
|  |  | |||
|  | @ -114,7 +114,7 @@ class ModelObject | |||
| 
 | ||||
|     void invalidate_bounding_box(); | ||||
| 
 | ||||
|     //void raw_mesh(TriangleMesh* mesh) const;
 | ||||
|     void raw_mesh(TriangleMesh* mesh) const; | ||||
|     //void mesh(TriangleMesh* mesh) const;
 | ||||
|     //void instance_bounding_box(size_t instance_idx, BoundingBox* bb) const;
 | ||||
|     //void center_around_origin();
 | ||||
|  | @ -149,6 +149,8 @@ class ModelVolume | |||
|     void material_id(t_model_material_id material_id); | ||||
|     ModelMaterial* material() const; | ||||
|      | ||||
|     ModelMaterial* assign_unique_material(); | ||||
|      | ||||
|     private: | ||||
|     ModelObject* object; | ||||
|     t_model_material_id _material_id; | ||||
|  | @ -166,7 +168,7 @@ class ModelInstance | |||
|     Pointf offset;              // in unscaled coordinates
 | ||||
|      | ||||
|     ModelObject* get_object() const { return this->object; }; | ||||
|     void transform_mesh(TriangleMesh* mesh, bool dont_translate) const; | ||||
|     void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const; | ||||
|     void transform_polygon(Polygon* polygon) const; | ||||
|      | ||||
|     private: | ||||
|  |  | |||
|  | @ -277,7 +277,7 @@ TriangleMesh::split() const | |||
| } | ||||
| 
 | ||||
| void | ||||
| TriangleMesh::merge(const TriangleMesh* mesh) | ||||
| TriangleMesh::merge(const TriangleMesh &mesh) | ||||
| { | ||||
|     // reset stats and metadata
 | ||||
|     int number_of_facets = this->stl.stats.number_of_facets; | ||||
|  | @ -285,13 +285,13 @@ TriangleMesh::merge(const TriangleMesh* mesh) | |||
|     this->repaired = false; | ||||
|      | ||||
|     // update facet count and allocate more memory
 | ||||
|     this->stl.stats.number_of_facets = number_of_facets + mesh->stl.stats.number_of_facets; | ||||
|     this->stl.stats.number_of_facets = number_of_facets + mesh.stl.stats.number_of_facets; | ||||
|     this->stl.stats.original_num_facets = this->stl.stats.number_of_facets; | ||||
|     stl_reallocate(&this->stl); | ||||
|      | ||||
|     // copy facets
 | ||||
|     for (int i = 0; i < mesh->stl.stats.number_of_facets; i++) { | ||||
|         this->stl.facet_start[number_of_facets + i] = mesh->stl.facet_start[i]; | ||||
|     for (int i = 0; i < mesh.stl.stats.number_of_facets; i++) { | ||||
|         this->stl.facet_start[number_of_facets + i] = mesh.stl.facet_start[i]; | ||||
|     } | ||||
|      | ||||
|     // update size
 | ||||
|  |  | |||
|  | @ -40,7 +40,7 @@ class TriangleMesh | |||
|     void align_to_origin(); | ||||
|     void rotate(double angle, Point* center); | ||||
|     TriangleMeshPtrs split() const; | ||||
|     void merge(const TriangleMesh* mesh); | ||||
|     void merge(const TriangleMesh &mesh); | ||||
|     void horizontal_projection(ExPolygons &retval) const; | ||||
|     void convex_hull(Polygon* hull); | ||||
|     void bounding_box(BoundingBoxf3* bb) const; | ||||
|  |  | |||
|  | @ -107,6 +107,8 @@ ModelMaterial::attributes() | |||
|         %code%{ RETVAL = &THIS->instances; %}; | ||||
|      | ||||
|     void invalidate_bounding_box(); | ||||
|     TriangleMesh* raw_mesh() | ||||
|         %code%{ RETVAL = new TriangleMesh(); THIS->raw_mesh(RETVAL); %}; | ||||
| 
 | ||||
|     Ref<BoundingBoxf3> _bounding_box(BoundingBoxf3* new_bbox = NULL) | ||||
|         %code{% | ||||
|  | @ -186,6 +188,8 @@ ModelMaterial::attributes() | |||
|         %code%{ RETVAL = THIS->modifier; %}; | ||||
|     void set_modifier(bool modifier) | ||||
|         %code%{ THIS->modifier = modifier; %}; | ||||
|      | ||||
|     ModelMaterial* assign_unique_material(); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
|  | @ -206,4 +210,7 @@ ModelMaterial::attributes() | |||
|         %code%{ THIS->scaling_factor = val; %}; | ||||
|     void set_offset(Pointf *offset) | ||||
|         %code%{ THIS->offset = *offset; %}; | ||||
|      | ||||
|     void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const; | ||||
|     void transform_polygon(Polygon* polygon) const; | ||||
| }; | ||||
|  |  | |||
|  | @ -29,7 +29,8 @@ | |||
|     void align_to_origin(); | ||||
|     void rotate(double angle, Point* center); | ||||
|     TriangleMeshPtrs split(); | ||||
|     void merge(TriangleMesh* mesh); | ||||
|     void merge(TriangleMesh* mesh) | ||||
|         %code{% THIS->merge(*mesh); %}; | ||||
|     ExPolygons horizontal_projection() | ||||
|         %code{% THIS->horizontal_projection(RETVAL); %}; | ||||
|     BoundingBoxf3* bounding_box() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alessandro Ranellucci
						Alessandro Ranellucci