diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index bc11190c3..a20c884af 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -626,7 +626,7 @@ ModelObject::raw_mesh() const TriangleMesh mesh; for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) { if ((*v)->modifier) continue; - mesh.merge((*v)->get_transformed_mesh()); + mesh.merge((*v)->get_transformed_mesh(nullptr)); } return mesh; } @@ -1026,6 +1026,13 @@ ModelVolume::get_transformed_mesh(TransformationMatrix const * additional_trafo) return mesh; } +TriangleMesh* +ModelVolume::get_transformed_meshptr(TransformationMatrix const * additional_trafo) +{ + this->transformed_mesh = get_transformed_mesh(additional_trafo); + return &(this->transformed_mesh); +} + t_model_material_id ModelVolume::material_id() const { @@ -1111,6 +1118,12 @@ TransformationMatrix ModelInstance::get_trafo_matrix(bool dont_translate) const return trafo; } +TransformationMatrix* ModelInstance::get_trafo_matrixptr(bool dont_translate) +{ + this->trafo = this->get_trafo_matrix(dont_translate); + return &(this->trafo); +} + BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mesh, bool dont_translate) const { // rotate around mesh origin diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index 06806ba07..363e85760 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -478,9 +478,14 @@ class ModelVolume ModelObject* get_object() const { return this->object; }; /// Get the ModelVolume's mesh, transformed by the ModelVolume's TransformationMatrix - /// \param additional_trafo optional additional transformation + /// \param additional_trafo additional transformation /// \return TriangleMesh the transformed mesh - TriangleMesh get_transformed_mesh(TransformationMatrix const * additional_trafo = nullptr) const; + TriangleMesh get_transformed_mesh(TransformationMatrix const * additional_trafo) const; + + /// Get the ModelVolume's mesh as pointer, transformed by the ModelVolume's TransformationMatrix + /// \param additional_trafo additional transformation + /// \return TriangleMesh the transformed mesh + TriangleMesh* get_transformed_meshptr(TransformationMatrix const * additional_trafo); /// Get the material id of this ModelVolume object /// \return t_model_material_id the material id string @@ -509,6 +514,8 @@ class ModelVolume ///< The id of the this ModelVolume t_model_material_id _material_id; + TriangleMesh transformed_mesh; ///< The transformed mesh only to be used by the perl binding + /// Constructor /// \param object ModelObject* pointer to the owner ModelObject /// \param mesh TriangleMesh the mesh of the new ModelVolume object @@ -552,6 +559,10 @@ class ModelInstance /// \param dont_translate bool whether to translate the mesh or not TransformationMatrix get_trafo_matrix(bool dont_translate = false) const; + /// Returns a pointer to TransformationMatrix defined by the instance's Transform an external TriangleMesh to the returned TriangleMesh object + /// \param dont_translate bool whether to translate the mesh or not + TransformationMatrix* get_trafo_matrixptr(bool dont_translate = false); + /// Calculate a bounding box of a transformed mesh. To be called on an external mesh. /// \param mesh TriangleMesh* pointer to the the mesh /// \param dont_translate bool whether to translate the bounding box or not @@ -588,6 +599,8 @@ class ModelInstance /// Swap attributes between another ModelInstance object /// \param other ModelInstance& the other instance object void swap(ModelInstance &other); + + TransformationMatrix trafo; ///< Trafomatrix for perl binding }; } diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp index be41c328e..2746563eb 100644 --- a/xs/xsp/Model.xsp +++ b/xs/xsp/Model.xsp @@ -290,6 +290,8 @@ ModelMaterial::attributes() %code%{ RETVAL = &THIS->config; %}; Ref mesh() %code%{ RETVAL = &THIS->mesh; %}; + + Ref get_transformed_meshptr(TransformationMatrix * additional_trafo = nullptr); bool modifier() %code%{ RETVAL = THIS->modifier; %}; @@ -327,6 +329,8 @@ ModelMaterial::attributes() void set_offset(Pointf *offset) %code%{ THIS->offset = *offset; %}; - void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const; + Ref get_trafo_matrixptr(bool dont_translate); + + void transform_mesh(TriangleMesh* mesh, bool dont_translate) const; void transform_polygon(Polygon* polygon) const; }; diff --git a/xs/xsp/my.map b/xs/xsp/my.map index 9a8bd2e3e..fc887bef1 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -57,6 +57,9 @@ TriangleMesh* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T Clone O_OBJECT_SLIC3R_T +TransformationMatrix* O_OBJECT_SLIC3R +Ref O_OBJECT_SLIC3R_T + SLAPrint* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T Clone O_OBJECT_SLIC3R_T diff --git a/xs/xsp/typemap.xspt b/xs/xsp/typemap.xspt index 6a1847b94..2642abe37 100644 --- a/xs/xsp/typemap.xspt +++ b/xs/xsp/typemap.xspt @@ -88,6 +88,8 @@ %typemap{TriangleMesh*}; %typemap{Ref}{simple}; %typemap{Clone}{simple}; +%typemap{TransformationMatrix*}; +%typemap{Ref}{simple}; %typemap{PolylineCollection*}; %typemap{Ref}{simple}; %typemap{Clone}{simple};