2016-05-17 03:04:11 +12:00
|
|
|
#pragma once
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
#ifndef PLASTICDEFORMER_H
|
|
|
|
#define PLASTICDEFORMER_H
|
|
|
|
|
2016-04-14 22:15:09 +12:00
|
|
|
#include <memory>
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
// TnzCore includes
|
|
|
|
#include "tgeometry.h"
|
|
|
|
#include "tmeshimage.h"
|
|
|
|
|
|
|
|
// TnzExt includes
|
|
|
|
#include "ext/plastichandle.h"
|
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
// tcg includes
|
|
|
|
#include "tcg/tcg_list.h"
|
|
|
|
|
|
|
|
#undef DVAPI
|
|
|
|
#undef DVVAR
|
|
|
|
#ifdef TNZEXT_EXPORTS
|
|
|
|
#define DVAPI DV_EXPORT_API
|
|
|
|
#define DVVAR DV_EXPORT_VAR
|
|
|
|
#else
|
|
|
|
#define DVAPI DV_IMPORT_API
|
|
|
|
#define DVVAR DV_IMPORT_VAR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//**********************************************************************************************
|
|
|
|
// Plastic Deformation declaration
|
|
|
|
//**********************************************************************************************
|
|
|
|
|
|
|
|
/*!
|
|
|
|
The PlasticDeformer class implements an interactive mesh deformer.
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
\warning Objects of this class expect that the mesh and rigidities supplied on
|
|
|
|
construction
|
|
|
|
remain \b constant throughout the deformer's lifetime. Deforming a changed
|
|
|
|
mesh is not supported
|
|
|
|
and will typically result in a crash. Deforming a mesh whose vertex rigidities
|
|
|
|
have been
|
|
|
|
\a deleted will result in a crash. Altering the rigidities results in
|
|
|
|
undefined deformations
|
2016-03-19 06:57:51 +13:00
|
|
|
until the deformer is recompiled against them.
|
|
|
|
*/
|
2016-06-15 18:43:10 +12:00
|
|
|
class DVAPI PlasticDeformer {
|
|
|
|
class Imp;
|
|
|
|
std::unique_ptr<Imp> m_imp;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
PlasticDeformer();
|
|
|
|
~PlasticDeformer();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
friend void swap(PlasticDeformer &a, PlasticDeformer &b) {
|
|
|
|
std::swap(a.m_imp, b.m_imp);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
/*!
|
|
|
|
Returns whether the last compilation procedure succeeded, or it either failed
|
|
|
|
or was never invoked after the last initialize() call.
|
|
|
|
*/
|
|
|
|
bool compiled() const;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
/*!
|
|
|
|
Initializes a deformation on the specified mesh object.
|
|
|
|
*/
|
|
|
|
void initialize(const TTextureMeshP &mesh);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
/*!
|
|
|
|
\brief Compiles the deformer against a group of deformation handles, and returns
|
|
|
|
whether the procedure was successful.
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
\note Accepts hints about the mesh face containing each handle; the hinted face
|
|
|
|
is checked before scanning the whole mesh. In case hints are supplied, they will
|
|
|
|
be
|
|
|
|
returned with the correct face indices containing each handle.
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
\warning Requires a previous initialize() call. The compilation may legitimately
|
|
|
|
fail to process handle configurations that \a cannot result in suitable
|
|
|
|
deformations (eg, if more than 3 handles lie in the same mesh face).
|
|
|
|
*/
|
|
|
|
bool compile(const std::vector<PlasticHandle> &handles, int *faceHints = 0);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
/*!
|
|
|
|
Applies the deformation specified with input handles deformed positions,
|
|
|
|
returning
|
|
|
|
the deformed mesh vertices positions.
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
\note In case the compilation step failed or was never invoked, this function
|
|
|
|
will silently return the original, undeformed mesh vertices.
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
\warning Requires previous compile() invocation.
|
|
|
|
*/
|
|
|
|
void deform(const TPointD *dstHandlePos, double *dstVerticesCoords) const;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
/*!
|
|
|
|
Releases data from the initialize() step that is unnecessary during deform().
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
\warning Initialization data is still necessary to invoke compile(), which will
|
|
|
|
therefore need to be preceded by a new call to initialize().
|
|
|
|
*/
|
|
|
|
void releaseInitializedData();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
// Not copyable
|
|
|
|
PlasticDeformer(const PlasticDeformer &);
|
|
|
|
PlasticDeformer &operator=(const PlasticDeformer &);
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
#endif // PLASTICDEFORMER_H
|