libslic3r
Library for generating gcode from 3d models
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Slic3r::Model Class Reference

#include <Model.hpp>

Public Member Functions

 Model ()
 Model constructor. More...
 
 Model (const Model &other)
 
Modeloperator= (Model other)
 
void swap (Model &other)
 
 ~Model ()
 Model destructor. More...
 
ModelObjectadd_object ()
 
ModelObjectadd_object (const ModelObject &other, bool copy_volumes=true)
 
void delete_object (size_t idx)
 
void clear_objects ()
 Delete all ModelObjects found in the current Model. More...
 
ModelMaterialadd_material (t_model_material_id material_id)
 
ModelMaterialadd_material (t_model_material_id material_id, const ModelMaterial &other)
 
ModelMaterialget_material (t_model_material_id material_id)
 
void delete_material (t_model_material_id material_id)
 
void clear_materials ()
 Delete all the ModelMaterial objects found in the current Model. More...
 
bool has_objects_with_no_instances () const
 
bool add_default_instances ()
 
BoundingBoxf3 bounding_box () const
 
void repair ()
 
void center_instances_around_point (const Pointf &point)
 
void align_instances_to_origin ()
 
void translate (coordf_t x, coordf_t y, coordf_t z)
 
TriangleMesh mesh () const
 
TriangleMesh raw_mesh () const
 
bool _arrange (const Pointfs &sizes, coordf_t dist, const BoundingBoxf *bb, Pointfs &out) const
 
bool arrange_objects (coordf_t dist, const BoundingBoxf *bb=NULL)
 
void duplicate (size_t copies_num, coordf_t dist, const BoundingBoxf *bb=NULL)
 
void duplicate_objects (size_t copies_num, coordf_t dist, const BoundingBoxf *bb=NULL)
 
void duplicate_objects_grid (size_t x, size_t y, coordf_t dist)
 
void print_info () const
 This function calls the print_info() function of each ModelObject. More...
 
bool looks_like_multipart_object () const
 
void convert_multipart_object ()
 Take all of the ModelObjects in the current Model and combines them into a single ModelObject. More...
 

Static Public Member Functions

static Model read_from_file (std::string input_file)
 

Public Attributes

ModelMaterialMap materials
 
ModelObjectPtrs objects
 
std::map< std::string, std::string > metadata
 Model metadata <name, value>, this is needed for 3MF format read/write. More...
 

Detailed Description

Model Class representing the print bed content Description of a triangular model with multiple materials, multiple instances with various affine transformations and with multiple modifier meshes. A model groups multiple objects, each object having possibly multiple instances, all objects may share multiple materials.

Constructor & Destructor Documentation

◆ Model() [1/2]

Slic3r::Model::Model ( )

Model constructor.

◆ Model() [2/2]

Slic3r::Model::Model ( const Model other)

Model constructor.

Parameters
otherModel the model to be copied

◆ ~Model()

Slic3r::Model::~Model ( )

Model destructor.

Member Function Documentation

◆ _arrange()

bool Slic3r::Model::_arrange ( const Pointfs sizes,
coordf_t  dist,
const BoundingBoxf bb,
Pointfs out 
) const

Arrange ModelInstances. ModelInstances of the same ModelObject do not preserve their relative positions. It uses the given BoundingBoxf as a hint, but falls back to free arrangement if it's not possible to fit all the parts in it.

Parameters
sizesPointfs& number of parts
distcoordf_t distance between cells
bbBoundingBoxf* (optional) pointer to the bounding box of the area to fill
outPointfs& vector of the output positions
Returns
bool whether the function finished arranging objects or it is impossible to arrange

◆ add_default_instances()

bool Slic3r::Model::add_default_instances ( )

Add a new ModelInstance to each ModelObject having no ModelInstance objects

Returns
bool

◆ add_material() [1/2]

ModelMaterial * Slic3r::Model::add_material ( t_model_material_id  material_id)

Add a new ModelMaterial to the model.

Parameters
material_idt_model_material_id the id of the new ModelMaterial to be added
Returns
ModelMaterial* a pointer to the new ModelMaterial

◆ add_material() [2/2]

ModelMaterial * Slic3r::Model::add_material ( t_model_material_id  material_id,
const ModelMaterial other 
)

Add a new ModelMaterial to the current Model. This function copies another ModelMaterial, It also delete the current ModelMaterial carrying the same material id in the map.

Parameters
material_idt_model_material_id the id of the new ModelMaterial to be added
otherModelMaterial the model material to be copied
Returns
ModelMaterial* a pointer to the new ModelMaterial

◆ add_object() [1/2]

ModelObject * Slic3r::Model::add_object ( )

Create a new object and add it to the current Model.

Returns
ModelObject* a pointer to the new Model

◆ add_object() [2/2]

ModelObject * Slic3r::Model::add_object ( const ModelObject other,
bool  copy_volumes = true 
)

Create a new object and add it to the current Model. This function copies another model object

Parameters
otherModelObject the ModelObject to be copied
copy_volumesif you also want to copy volumes of the other object. By default = true
Returns
ModelObject* a pointer to the new ModelObject

◆ align_instances_to_origin()

void Slic3r::Model::align_instances_to_origin ( )

◆ arrange_objects()

bool Slic3r::Model::arrange_objects ( coordf_t  dist,
const BoundingBoxf bb = NULL 
)

Arrange ModelObjects preserving their ModelInstance count but altering their ModelInstance positions.

Parameters
distcoordf_t distance between cells
bbBoundingBoxf* (optional) pointer to the bounding box of the area to fill
Returns
bool whether the function finished arranging objects or it is impossible to arrange

◆ bounding_box()

BoundingBoxf3 Slic3r::Model::bounding_box ( ) const

Get the bounding box of the transformed instances.

Returns
BoundingBoxf3 a bounding box object.

◆ center_instances_around_point()

void Slic3r::Model::center_instances_around_point ( const Pointf point)

Center the total bounding box of the instances around a point. This transformation works in the XY plane only and no transformation in Z is performed.

Parameters
pointpointf object to center the model instances of model objects around

◆ clear_materials()

void Slic3r::Model::clear_materials ( )

Delete all the ModelMaterial objects found in the current Model.

◆ clear_objects()

void Slic3r::Model::clear_objects ( )

Delete all ModelObjects found in the current Model.

◆ convert_multipart_object()

void Slic3r::Model::convert_multipart_object ( )

Take all of the ModelObjects in the current Model and combines them into a single ModelObject.

◆ delete_material()

void Slic3r::Model::delete_material ( t_model_material_id  material_id)

Delete a ModelMaterial carrying a certain material id if found.

Parameters
material_idt_model_material_id the id of the ModelMaterial to be deleted

◆ delete_object()

void Slic3r::Model::delete_object ( size_t  idx)

Delete a ModelObject from the current Model.

Parameters
idxsize_t the index of the desired ModelObject

◆ duplicate()

void Slic3r::Model::duplicate ( size_t  copies_num,
coordf_t  dist,
const BoundingBoxf bb = NULL 
)

Duplicate the ModelInstances of each ModelObject as a whole preserving their relative positions. This function croaks if the duplicated objects do not fit the print bed.

Parameters
copies_numsize_t number of copies
distcoordf_t distance between cells
bbBoundingBoxf* (optional) pointer to the bounding box of the area to fill

◆ duplicate_objects()

void Slic3r::Model::duplicate_objects ( size_t  copies_num,
coordf_t  dist,
const BoundingBoxf bb = NULL 
)

Duplicate each entire ModelInstances of the each ModelObject as a whole. This function will append more instances to each object and then calls arrange_objects() function to automatically rearrange everything.

Parameters
copies_numsize_t number of copies
distcoordf_t distance between cells
bbBoundingBoxf* (optional) pointer to the bounding box of the area to fill

◆ duplicate_objects_grid()

void Slic3r::Model::duplicate_objects_grid ( size_t  x,
size_t  y,
coordf_t  dist 
)

Duplicate a single ModelObject and arranges them on a grid. Grid duplication is not supported with multiple objects. It throws an exception if there is more than one ModelObject. It also throws an exception if there are no ModelObjects in the current Model.

Parameters
xsize_t number of duplicates in x direction
ysize_t offset number of duplicates in y direction
distcoordf_t distance supposed to be between the duplicated ModelObjects

◆ get_material()

ModelMaterial * Slic3r::Model::get_material ( t_model_material_id  material_id)

Get the ModelMaterial object instance having a certain material id. Returns null if the ModelMaterial object instance is not found.

Parameters
material_idt_model_material_id the id of the needed ModelMaterial object instance
Returns
ModelMaterial* a pointer to the ModelMaterial object instance or null if not found

◆ has_objects_with_no_instances()

bool Slic3r::Model::has_objects_with_no_instances ( ) const

Check if any ModelObject has no ModelInstances.

Returns
bool true means there exists at least one ModelObject with no ModelInstance objects

◆ looks_like_multipart_object()

bool Slic3r::Model::looks_like_multipart_object ( ) const

Check to see if the current Model has characteristics of having multiple parts (usually multiple volumes, etc).

Returns
bool

◆ mesh()

TriangleMesh Slic3r::Model::mesh ( ) const

Flatten all ModelInstances to a single mesh after performing instance transformations (if the object was rotated or translated).

Returns
TriangleMesh a single TriangleMesh object

◆ operator=()

Model & Slic3r::Model::operator= ( Model  other)

= Operator overloading.

Parameters
otherModel the model to be copied
Returns
Model& the current Model to enable operator cascading

◆ print_info()

void Slic3r::Model::print_info ( ) const

This function calls the print_info() function of each ModelObject.

◆ raw_mesh()

TriangleMesh Slic3r::Model::raw_mesh ( ) const

Flatten all ModelVolumes to a single mesh without any extra processing (i.e. without applying any instance duplication and/or transformation).

Returns
TriangleMesh a single TriangleMesh object

◆ read_from_file()

Model Slic3r::Model::read_from_file ( std::string  input_file)
static

Read a model from file. This function supports the following formats (STL, OBJ, AMF), It auto-detects the file format from the file name suffix.

Parameters
input_filestd::string the file path expressed in UTF-8
Returns
Model the read Model

◆ repair()

void Slic3r::Model::repair ( )

Repair the ModelObjects of the current Model. This function calls repair function on each TriangleMesh of each model object volume

◆ swap()

void Slic3r::Model::swap ( Model other)

Swap objects and materials with another model.

Parameters
otherModel the model to be swapped with

◆ translate()

void Slic3r::Model::translate ( coordf_t  x,
coordf_t  y,
coordf_t  z 
)

Translate each ModelObject with x, y, z units.

Parameters
xcoordf_t units in the x direction
ycoordf_t units in the y direction
zcoordf_t units in the z direction

Member Data Documentation

◆ materials

ModelMaterialMap Slic3r::Model::materials

Materials are owned by a model and referenced by objects through t_model_material_id. Single material may be shared by multiple models.

◆ metadata

std::map<std::string, std::string> Slic3r::Model::metadata

Model metadata <name, value>, this is needed for 3MF format read/write.

◆ objects

ModelObjectPtrs Slic3r::Model::objects

Objects are owned by a model. Each object may have multiple instances , each instance having its own transformation (shift, scale, rotation).


The documentation for this class was generated from the following files: