107 lines
3.8 KiB
C++
107 lines
3.8 KiB
C++
/*
|
|
QGLView
|
|
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef GLMESH_H
|
|
#define GLMESH_H
|
|
|
|
#include <chunkstream.h>
|
|
#include "glbuffer.h"
|
|
#include "glshaders_types.h"
|
|
|
|
|
|
class Mesh
|
|
{
|
|
friend class ObjectBase;
|
|
friend class Scene;
|
|
friend class Renderer;
|
|
friend QDataStream & operator <<(QDataStream & s, const Mesh * m);
|
|
friend QDataStream & operator >>(QDataStream & s, Mesh *& m);
|
|
public:
|
|
Mesh(GLenum geom_type_ = GL_TRIANGLES);
|
|
~Mesh();
|
|
|
|
Mesh * clone();
|
|
|
|
//GLVBO & operator =(const GLVBO & o) {return *this;}
|
|
|
|
void init (QOpenGLExtraFunctions * f);
|
|
void destroy (QOpenGLExtraFunctions * f);
|
|
bool rebuffer(QOpenGLExtraFunctions * f);
|
|
void draw (QOpenGLExtraFunctions * f, int count);
|
|
void clear();
|
|
void loadObject (QOpenGLExtraFunctions * f, const QGLEngineShaders::Object & object);
|
|
void loadObjects (QOpenGLExtraFunctions * f, const QVector<QGLEngineShaders::Object> & objects);
|
|
void loadSelections(QOpenGLExtraFunctions * f, const QVector<uchar> & sels);
|
|
|
|
int verticesCount() const {return vertices_.size();}
|
|
int trianglesCount() const {return triangles_.size();}
|
|
int linesCount() const {return lines_.size();}
|
|
bool isInit() const {return vao != 0;}
|
|
bool isEmpty() const {return vertices_.isEmpty();}
|
|
uint hash() const;
|
|
|
|
QVector<QVector3D> & vertices () {changed = hash_changed = true; return vertices_;}
|
|
QVector<QVector3D> & normals () {changed = hash_changed = true; return normals_;}
|
|
QVector<QVector2D> & texcoords() {changed = hash_changed = true; return texcoords_;}
|
|
QVector< Vector3i> & indicesTriangles() {changed = hash_changed = true; return triangles_;}
|
|
QVector< Vector2i> & indicesLines () {changed = hash_changed = true; return lines_;}
|
|
|
|
void translatePoints(const QVector3D & dp);
|
|
void translatePoints(const double & x, const double & y, const double & z) {translatePoints(QVector3D(x, y, z));}
|
|
void scalePoints (const QVector3D & dp);
|
|
void scalePoints (const double & s) {scalePoints(QVector3D(s, s, s));}
|
|
void rotatePoints (const double & angle, const QVector3D & a);
|
|
void rotatePoints (const double & angle, const double & x, const double & y, const double & z) {rotatePoints(angle, QVector3D(x, y, z));}
|
|
void transformPoints(const QMatrix4x4 & mat);
|
|
void append(const Mesh * m);
|
|
|
|
bool saveToFile(const QString & filename);
|
|
bool loadFromFile(const QString & filename);
|
|
|
|
Box3D boundingBox() const;
|
|
|
|
static void prepareDrawGeom(QOpenGLExtraFunctions * f);
|
|
static void prepareDrawObj (QOpenGLExtraFunctions * f);
|
|
static void prepareDrawSel (QOpenGLExtraFunctions * f);
|
|
|
|
private:
|
|
void calculateNormals();
|
|
void calculateTangents();
|
|
void loadBuffer(QOpenGLExtraFunctions * f, Buffer & buf, const void * data, int size);
|
|
|
|
QVector<QVector3D> vertices_, normals_, tangents_, bitangents_;
|
|
QVector<QVector2D> texcoords_;
|
|
QVector< Vector3i> triangles_;
|
|
QVector< Vector2i> lines_;
|
|
|
|
QVector<QGLEngineShaders::Vertex> data_;
|
|
GLenum vao, geom_type;
|
|
Buffer buffer_geom, buffer_ind, buffer_obj, buffer_sel;
|
|
mutable uint hash_;
|
|
mutable bool hash_changed;
|
|
int vert_count;
|
|
bool changed, objects_changed, selected_changed;
|
|
|
|
};
|
|
|
|
|
|
QDataStream & operator <<(QDataStream & s, const Mesh * m);
|
|
QDataStream & operator >>(QDataStream & s, Mesh *& m);
|
|
|
|
#endif // GLMESH_H
|