1 #pragma once 2 3 #ifndef PLASTICDEFORMER_H 4 #define PLASTICDEFORMER_H 5 6 #include <memory> 7 8 // TnzCore includes 9 #include "tgeometry.h" 10 #include "tmeshimage.h" 11 12 // TnzExt includes 13 #include "ext/plastichandle.h" 14 15 // STL includes 16 #include <vector> 17 18 // tcg includes 19 #include "tcg/tcg_list.h" 20 21 #undef DVAPI 22 #undef DVVAR 23 #ifdef TNZEXT_EXPORTS 24 #define DVAPI DV_EXPORT_API 25 #define DVVAR DV_EXPORT_VAR 26 #else 27 #define DVAPI DV_IMPORT_API 28 #define DVVAR DV_IMPORT_VAR 29 #endif 30 31 //********************************************************************************************** 32 // Plastic Deformation declaration 33 //********************************************************************************************** 34 35 /*! 36 The PlasticDeformer class implements an interactive mesh deformer. 37 38 \warning Objects of this class expect that the mesh and rigidities supplied on 39 construction 40 remain \b constant throughout the deformer's lifetime. Deforming a changed 41 mesh is not supported 42 and will typically result in a crash. Deforming a mesh whose vertex rigidities 43 have been 44 \a deleted will result in a crash. Altering the rigidities results in 45 undefined deformations 46 until the deformer is recompiled against them. 47 */ 48 class DVAPI PlasticDeformer { 49 class Imp; 50 std::unique_ptr<Imp> m_imp; 51 52 public: 53 PlasticDeformer(); 54 ~PlasticDeformer(); 55 56 /*! 57 Returns whether the last compilation procedure succeeded, or it either failed 58 or was never invoked after the last initialize() call. 59 */ 60 bool compiled() const; 61 62 /*! 63 Initializes a deformation on the specified mesh object. 64 */ 65 void initialize(const TTextureMeshP &mesh); 66 67 /*! 68 \brief Compiles the deformer against a group of deformation handles, and returns 69 whether the procedure was successful. 70 71 \note Accepts hints about the mesh face containing each handle; the hinted face 72 is checked before scanning the whole mesh. In case hints are supplied, they will 73 be 74 returned with the correct face indices containing each handle. 75 76 \warning Requires a previous initialize() call. The compilation may legitimately 77 fail to process handle configurations that \a cannot result in suitable 78 deformations (eg, if more than 3 handles lie in the same mesh face). 79 */ 80 bool compile(const std::vector<PlasticHandle> &handles, int *faceHints = 0); 81 82 /*! 83 Applies the deformation specified with input handles deformed positions, 84 returning 85 the deformed mesh vertices positions. 86 87 \note In case the compilation step failed or was never invoked, this function 88 will silently return the original, undeformed mesh vertices. 89 90 \warning Requires previous compile() invocation. 91 */ 92 void deform(const TPointD *dstHandlePos, double *dstVerticesCoords) const; 93 94 /*! 95 Releases data from the initialize() step that is unnecessary during deform(). 96 97 \warning Initialization data is still necessary to invoke compile(), which will 98 therefore need to be preceded by a new call to initialize(). 99 */ 100 void releaseInitializedData(); 101 102 private: 103 // Not copyable 104 PlasticDeformer(const PlasticDeformer &); 105 PlasticDeformer &operator=(const PlasticDeformer &); 106 }; 107 108 #endif // PLASTICDEFORMER_H 109