49 #include <QOpenGLBuffer> 50 #include <QOpenGLVertexArrayObject> 52 #include "StelTexture.hpp" 53 #include "VecMath.hpp" 75 enum Illum { I_NONE=-1, I_DIFFUSE=0, I_DIFFUSE_AND_AMBIENT=1, I_SPECULAR=2, I_TRANSLUCENT=9 };
152 GLfloat bitangent[3];
154 static const Vertex EmptyVertex;
161 int startIndex, triangleCount;
178 bool load(
const QString& filename,
const enum vertexOrder order,
bool rebuildNormals =
false);
197 int getNumberOfStelModels()
const;
198 int getNumberOfTriangles()
const;
199 int getNumberOfVertices()
const;
200 int getNumberOfMaterials()
const;
211 bool hasPositions()
const;
212 bool hasTextureCoords()
const;
213 bool hasNormals()
const;
214 bool hasTangents()
const;
215 bool hasStelModels()
const;
241 static inline size_t getIndexBufferTypeSize() {
return indexBufferTypeSize; }
246 struct FaceAttributes
252 typedef QVector<FaceAttributes> AttributeVector;
253 typedef QVector<Vec3f> VF3Vector;
254 typedef QVector<Vec2f> VF2Vector;
256 typedef QVector<Vec3f> PosVector;
257 typedef QMap<QString,int> MatCacheT;
258 typedef QMap<int, QVector<int> > VertCacheT;
260 void addFaceAttrib(AttributeVector& attributeArray, uint index,
int material,
int object);
261 void addTrianglePos(
const PosVector& vertexCoords, VertCacheT &vertexCache,
unsigned int index,
int v0,
int v1,
int v2);
262 void addTrianglePosNormal(
const PosVector &vertexCoords,
const VF3Vector& normals, VertCacheT &vertexCache,
unsigned int index,
263 int v0,
int v1,
int v2,
264 int vn0,
int vn1,
int vn2);
265 void addTrianglePosTexCoord(
const PosVector &vertexCoords,
const VF2Vector &textureCoords, VertCacheT &vertexCache,
unsigned int index,
266 int v0,
int v1,
int v2,
267 int vt0,
int vt1,
int vt2);
268 void addTrianglePosTexCoordNormal(PosVector &vertexCoords,
const VF2Vector &textureCoords,
const VF3Vector &normals, VertCacheT &vertexCache,
unsigned int index,
269 int v0,
int v1,
int v2,
270 int vt0,
int vt1,
int vt2,
271 int vn0,
int vn1,
int vn2);
272 int addVertex(VertCacheT &vertexCache,
int hash,
const Vertex* pVertex);
274 void buildStelModels(
const AttributeVector &attributeArray);
276 void generateNormals();
278 void generateTangents();
280 void importFirstPass(QFile& pFile, MatCacheT &materialCache);
282 void importSecondPass(FILE *pFile,
const enum vertexOrder order,
const MatCacheT &materialCache);
284 bool importMaterials(
const QString& filename, MatCacheT& materialCache);
285 QString absolutePath(QString path);
289 void bindBuffersGL();
291 void unbindBuffersGL();
294 QFile* getFile(
const QString& filename);
297 QString parseTextureString(
const char *buffer)
const;
302 bool m_hasTextureCoords;
305 bool m_hasStelModels;
306 static bool vertexArraysSupported;
309 static GLenum indexBufferType;
311 static size_t indexBufferTypeSize;
312 int m_firstTransparentIndex;
315 unsigned int m_numberOfVertexCoords;
316 unsigned int m_numberOfTextureCoords;
317 unsigned int m_numberOfNormals;
318 unsigned int m_numberOfTriangles;
319 unsigned int m_numberOfMaterials;
320 unsigned int m_numberOfStelModels;
329 QVector<StelModel> m_stelModels;
330 QVector<Material> m_materials;
331 QVector<Vertex> m_vertexArray;
332 QVector<unsigned int> m_indexArray;
335 QOpenGLBuffer m_vertexBuffer;
336 QOpenGLBuffer m_indexBuffer;
337 QOpenGLVertexArrayObject* m_vertexArrayObject;
339 static QOpenGLFunctions* gl;
351 inline int OBJ::getNumberOfStelModels()
const {
return m_numberOfStelModels; }
353 inline int OBJ::getNumberOfTriangles()
const {
return m_numberOfTriangles; }
355 inline int OBJ::getNumberOfVertices()
const {
return static_cast<int>(m_vertexArray.size()); }
357 inline int OBJ::getNumberOfMaterials()
const {
return m_numberOfMaterials; }
367 inline bool OBJ::hasNormals()
const{
return m_hasNormals; }
369 inline bool OBJ::hasPositions()
const {
return m_hasPositions; }
371 inline bool OBJ::hasTangents()
const {
return m_hasTangents; }
373 inline bool OBJ::hasTextureCoords()
const {
return m_hasTextureCoords; }
375 inline bool OBJ::hasStelModels()
const {
return m_hasStelModels; }
380 inline QString OBJ::absolutePath(QString path) {
return m_basePath + path; }
Structure for a Mesh, will be used with Stellarium to render Holds the starting index, the number of triangles and a pointer to the MTL.
float alpha
Transparency [0..1].
A vertex struct holds the vertex itself (position), corresponding texture coordinates, normals, tangents and bitangents It does not use Vec3f etc.
QString emissiveMapName
Name of emissive texture.
static void setupGL()
Set up some stuff that requires a valid OpenGL context.
QVector3D ambient
Ka, Kd, Ks, Ke.
QString name
Material name.
This represents a heightmap for viewer-ground collision.
bool isLoaded() const
Returns flags.
size_t memoryUsage()
Returns an estimate of the memory usage of this instance (not fully accurate, but good enough) ...
QString heightMapName
Height map name.
QString bumpMapName
Bump map name.
bool load(const QString &filename, const enum vertexOrder order, bool rebuildNormals=false)
Loads the given obj file and, if specified rebuilds normals.
void transform(QMatrix4x4 mat)
Transform all the vertices through multiplication with a 4x4 matrix.
bool hasSpecularity
Quick check if this material has specularity.
int getNumberOfIndices() const
Getters for various datastructures.
const AABB & getBoundingBox()
Returns the bounding box for this OBJ.
bool alphatest
If to perform binary alpha testing. Default off.
QString textureName
Texture name.
bool hasTransparency
Quick check if this material has "real" transparency (i.e. needs blending)
OBJ & operator=(const OBJ &other)
Copy assignment operator. No deep copies are performed, but QVectors have copy-on-write semantics...
An axis-aligned bounding-box class.
void bindGL()
Binds the necessary GL objects, making the OBJ ready for drawing. Uses a VAO if the platform supports...
void unbindGL()
Unbinds this object's GL objects.
const Vertex * getVertexArray() const
Returns the vertex array.
void transparencyDepthSort(const Vec3f &position)
Sorts the transparent StelModels according to their distance to the specified position.
bool backfacecull
If to perform backface culling. Default on.
void finalizeForRendering()
This should be called after textures are loaded, and will re-order the StelModels to be grouped by th...
const StelModel & getStelModel(int i) const
Returns a StelModel.
void clean()
Cleanup, will be called inside the destructor.
Material()
Creates a material with the default values.
int getVertexSize() const
Returns the vertex size.
void finalize()
Needs to be called after everything is loaded.
Illum
MTL Illumination models, do not use externally anymore.
A basic Wavefront .OBJ format model loader.
static GLenum getIndexBufferType()
Returns the OpenGL index buffer type supported on this hardware.
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
void uploadTexturesGL()
Uploads the textures to GL (requires valid context)
Material & getMaterial(int i)
Returns a Material.
Encapsulates all information that the describes the surface appearance of a StelModel.
float shininess
Shininess [0..128].
vertexOrder
OBJ files can have vertices encoded in different order.
void uploadBuffersGL()
Uploads the vertex and index data to GL buffers (requires valid context)
const Vertex & getVertex(int i) const
Returns a vertex reference.