2018-10-25 00:19:38 +00:00
|
|
|
#ifndef DUST3D_MESH_GENERATOR_H
|
|
|
|
#define DUST3D_MESH_GENERATOR_H
|
2018-04-07 08:44:39 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QImage>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <QThread>
|
2018-08-27 08:50:40 +00:00
|
|
|
#include <QOpenGLWidget>
|
2018-10-25 00:19:38 +00:00
|
|
|
#include "snapshot.h"
|
2018-05-07 17:16:58 +00:00
|
|
|
#include "meshloader.h"
|
2018-10-25 00:19:38 +00:00
|
|
|
#include "outcome.h"
|
2018-09-06 15:04:59 +00:00
|
|
|
#include "positionmap.h"
|
2018-11-15 14:01:20 +00:00
|
|
|
#include "combinemode.h"
|
2018-04-07 08:44:39 +00:00
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
class GeneratedCacheContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
~GeneratedCacheContext();
|
2018-10-26 23:04:45 +00:00
|
|
|
std::map<QString, std::vector<std::pair<QVector3D, std::pair<QUuid, QUuid>>>> partBmeshVertices;
|
2018-10-25 00:19:38 +00:00
|
|
|
std::map<QString, std::vector<OutcomeNode>> partBmeshNodes;
|
2018-09-14 09:45:05 +00:00
|
|
|
std::map<QString, std::vector<std::tuple<PositionMapKey, PositionMapKey, PositionMapKey, PositionMapKey>>> partBmeshQuads;
|
2018-08-27 08:50:40 +00:00
|
|
|
std::map<QString, void *> componentCombinableMeshs;
|
2018-09-06 15:04:59 +00:00
|
|
|
std::map<QString, std::vector<QVector3D>> componentPositions;
|
2018-10-26 23:04:45 +00:00
|
|
|
std::map<QString, PositionMap<std::pair<QVector3D, std::pair<QUuid, QUuid>>>> componentVerticesSources;
|
2018-09-14 09:45:05 +00:00
|
|
|
std::map<QString, QString> partMirrorIdMap;
|
2018-11-15 14:01:20 +00:00
|
|
|
std::map<QString, std::vector<std::pair<QVector3D, float>>> componentInflateBalls;
|
2018-08-27 08:50:40 +00:00
|
|
|
void updateComponentCombinableMesh(QString componentId, void *mesh);
|
|
|
|
};
|
|
|
|
|
2018-04-07 08:44:39 +00:00
|
|
|
class MeshGenerator : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-10-25 00:19:38 +00:00
|
|
|
MeshGenerator(Snapshot *snapshot);
|
2018-04-07 08:44:39 +00:00
|
|
|
~MeshGenerator();
|
2018-08-27 08:50:40 +00:00
|
|
|
void setSharedContextWidget(QOpenGLWidget *widget);
|
2018-09-18 06:22:29 +00:00
|
|
|
void addPartPreviewRequirement(const QUuid &partId);
|
2018-08-27 08:50:40 +00:00
|
|
|
void setGeneratedCacheContext(GeneratedCacheContext *cacheContext);
|
2018-09-07 12:51:33 +00:00
|
|
|
void setSmoothNormal(bool smoothNormal);
|
2018-09-22 10:31:02 +00:00
|
|
|
void setWeldEnabled(bool weldEnabled);
|
2018-05-07 17:16:58 +00:00
|
|
|
MeshLoader *takeResultMesh();
|
2018-09-18 06:22:29 +00:00
|
|
|
MeshLoader *takePartPreviewMesh(const QUuid &partId);
|
|
|
|
const std::set<QUuid> &requirePreviewPartIds();
|
|
|
|
const std::set<QUuid> &generatedPreviewPartIds();
|
2018-10-26 23:04:45 +00:00
|
|
|
Outcome *takeOutcome();
|
2018-10-09 02:19:12 +00:00
|
|
|
void generate();
|
2018-04-07 08:44:39 +00:00
|
|
|
signals:
|
|
|
|
void finished();
|
|
|
|
public slots:
|
|
|
|
void process();
|
|
|
|
private:
|
2018-10-25 00:19:38 +00:00
|
|
|
Snapshot *m_snapshot;
|
2018-05-07 17:16:58 +00:00
|
|
|
MeshLoader *m_mesh;
|
2018-09-18 06:22:29 +00:00
|
|
|
std::map<QUuid, MeshLoader *> m_partPreviewMeshMap;
|
|
|
|
std::set<QUuid> m_requirePreviewPartIds;
|
|
|
|
std::set<QUuid> m_generatedPreviewPartIds;
|
2018-04-07 08:44:39 +00:00
|
|
|
QThread *m_thread;
|
2018-10-25 00:19:38 +00:00
|
|
|
Outcome *m_outcome;
|
2018-08-27 08:50:40 +00:00
|
|
|
QOpenGLWidget *m_sharedContextWidget;
|
|
|
|
void *m_meshliteContext;
|
|
|
|
GeneratedCacheContext *m_cacheContext;
|
2018-09-07 12:51:33 +00:00
|
|
|
bool m_smoothNormal;
|
2018-09-22 10:31:02 +00:00
|
|
|
bool m_weldEnabled;
|
2018-08-27 08:50:40 +00:00
|
|
|
float m_mainProfileMiddleX;
|
|
|
|
float m_sideProfileMiddleX;
|
|
|
|
float m_mainProfileMiddleY;
|
|
|
|
std::map<QString, std::set<QString>> m_partNodeIds;
|
|
|
|
std::map<QString, std::set<QString>> m_partEdgeIds;
|
|
|
|
std::set<QString> m_dirtyComponentIds;
|
|
|
|
std::set<QString> m_dirtyPartIds;
|
|
|
|
private:
|
|
|
|
static bool m_enableDebug;
|
2018-09-14 09:45:05 +00:00
|
|
|
static PositionMap<int> *m_forMakePositionKey;
|
2018-04-07 08:44:39 +00:00
|
|
|
private:
|
2018-10-26 23:04:45 +00:00
|
|
|
void loadVertexSources(void *meshliteContext, int meshId, QUuid partId, const std::map<int, QUuid> &bmeshToNodeIdMap, std::vector<std::pair<QVector3D, std::pair<QUuid, QUuid>>> &bmeshVertices,
|
2018-09-14 09:45:05 +00:00
|
|
|
std::vector<std::tuple<PositionMapKey, PositionMapKey, PositionMapKey, PositionMapKey>> &bmeshQuads);
|
2018-10-26 23:04:45 +00:00
|
|
|
void loadGeneratedPositionsToOutcome(void *meshliteContext, int triangulatedMeshId);
|
2018-08-27 08:50:40 +00:00
|
|
|
void collectParts();
|
|
|
|
void checkDirtyFlags();
|
|
|
|
bool checkIsComponentDirty(QString componentId);
|
|
|
|
bool checkIsPartDirty(QString partId);
|
2018-11-15 14:01:20 +00:00
|
|
|
void *combineComponentMesh(QString componentId, CombineMode *combineMode, std::vector<std::pair<QVector3D, float>> *inflateBalls);
|
|
|
|
void *combinePartMesh(QString partId, std::vector<std::pair<QVector3D, float>> *balls=nullptr);
|
2018-04-07 08:44:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|