Stellarium
24.4
|
Representation of a custom subset of a Wavefront .obj file, including only triangle data and materials. More...
#include <StelOBJ.hpp>
Data Structures | |
struct | Material |
Defines a material loaded from an .mtl file. More... | |
struct | MaterialGroup |
Represents a bunch of faces following after each other that use the same material. More... | |
struct | Object |
Represents an OBJ object as defined with the 'o' statement. More... | |
struct | Vertex |
A Vertex struct holds the vertex itself (position), corresponding texture coordinates, normals, tangents and bitangents It does not use Vec3f etc. More... | |
Public Types | |
enum | VertexOrder { XYZ , XZY , YXZ , YZX , ZXY , ZYX } |
Possible vertex orderings with load() | |
typedef QVector< MaterialGroup > | MaterialGroupList |
typedef QVector< Vec3f > | V3Vec |
typedef QVector< Vec2f > | V2Vec |
typedef QVector< Vertex > | VertexList |
typedef QVector< unsigned int > | IndexList |
typedef QVector< unsigned short > | ShortIndexList |
typedef QVector< Material > | MaterialList |
typedef QMap< QString, int > | MaterialMap |
typedef QVector< Object > | ObjectList |
typedef QMap< QString, int > | ObjectMap |
Public Member Functions | |
StelOBJ () | |
Constructs an empty StelOBJ. Use load() to load data from a .obj file. | |
void | clear () |
Resets all data contained in this StelOBJ. | |
unsigned int | getFaceCount () const |
Returns the number of faces. More... | |
const VertexList & | getVertexList () const |
Returns an vertex list, suitable for loading into OpenGL arrays. | |
const IndexList & | getIndexList () const |
Returns an index list, suitable for use with OpenGL element arrays. | |
const MaterialList & | getMaterialList () const |
Returns the list of materials. | |
const ObjectList & | getObjectList () const |
Returns the list of objects. | |
const ObjectMap & | getObjectMap () const |
Returns the object map (mapping the object names to their indices in the object list) | |
const AABBox & | getAABBox () const |
Returns the global AABB of all vertices of the OBJ. | |
const Vec3f & | getCentroid () const |
Returns the global centroid of all vertices of the OBJ. More... | |
bool | load (const QString &filename, const VertexOrder vertexOrder=VertexOrder::XYZ, const bool forceCreateNormals=false) |
Loads an .obj file by name. More... | |
bool | load (QIODevice &device, const QString &basePath, const VertexOrder vertexOrder=VertexOrder::XYZ, const bool forceCreateNormals=false) |
Loads an .obj file from the specified device. More... | |
bool | isLoaded () const |
Returns true if this object contains valid data from a load() method. | |
void | rebuildNormals () |
Rebuilds vertex normals as the average of face normals. | |
bool | canUseShortIndices () const |
Returns if unsigned short indices can be used instead of unsigned int indices, to save some memory. More... | |
ShortIndexList | getShortIndexList () const |
Converts the index list (as returned by getIndexList()) to use unsigned short instead of integer. More... | |
void | scale (double factor) |
Scales the vertex positions according to the given factor. More... | |
void | transform (const QMatrix4x4 &mat, bool onlyPosition=false) |
Applies the given transformation matrix to the vertex data. More... | |
void | splitVertexData (V3Vec *position, V2Vec *texCoord=Q_NULLPTR, V3Vec *normal=Q_NULLPTR, V3Vec *tangent=Q_NULLPTR, V3Vec *bitangent=Q_NULLPTR) const |
Splits the vertex data into separate arrays. More... | |
void | clearVertexData () |
Clears the internal vertex list to save space, meaning getVertexList() returns an empty list! The other members are unaffected (indices, materials, objects etc. More... | |
Representation of a custom subset of a Wavefront .obj file, including only triangle data and materials.
|
inline |
Returns if unsigned short indices can be used instead of unsigned int indices, to save some memory.
This can only be done if the model has less vertices than std::numeric_limits<unsigned short>::max()
void StelOBJ::clearVertexData | ( | ) |
Clears the internal vertex list to save space, meaning getVertexList() returns an empty list! The other members are unaffected (indices, materials, objects etc.
still work). The vertex list can only be restored when the OBJ data is freshly loaded again, so don't do this if you require it later.
This is intended to be used together with splitVertexData(), when you want your own vertex format.
|
inline |
Returns the global centroid of all vertices of the OBJ.
|
inline |
Returns the number of faces.
We only use triangle faces, so this is always the index count divided by 3.
ShortIndexList StelOBJ::getShortIndexList | ( | ) | const |
Converts the index list (as returned by getIndexList()) to use unsigned short instead of integer.
If this is not possible (canUseShortIndices() returns false), an empty list is returned.
bool StelOBJ::load | ( | const QString & | filename, |
const VertexOrder | vertexOrder = VertexOrder::XYZ , |
||
const bool | forceCreateNormals = false |
||
) |
Loads an .obj file by name.
Supports .gz decompression, and then calls load(QIODevice) for the actual loading.
bool StelOBJ::load | ( | QIODevice & | device, |
const QString & | basePath, | ||
const VertexOrder | vertexOrder = VertexOrder::XYZ , |
||
const bool | forceCreateNormals = false |
||
) |
Loads an .obj file from the specified device.
device | The device to load OBJ data from |
basePath | The path to use to find additional files (like material definitions) |
vertexOrder | The order to use for vertex positions |
forceCreateNormals | set true to force creation of normals even if they exist |
void StelOBJ::scale | ( | double | factor | ) |
Scales the vertex positions according to the given factor.
This may be useful for importing, because many exporters don't handle very large or very small models well. For example, the solar system objects are modeled with kilometer units, and then converted to AU on loading.
void StelOBJ::splitVertexData | ( | V3Vec * | position, |
V2Vec * | texCoord = Q_NULLPTR , |
||
V3Vec * | normal = Q_NULLPTR , |
||
V3Vec * | tangent = Q_NULLPTR , |
||
V3Vec * | bitangent = Q_NULLPTR |
||
) | const |
Splits the vertex data into separate arrays.
If a given parameter vector is null, it is not filled.
void StelOBJ::transform | ( | const QMatrix4x4 & | mat, |
bool | onlyPosition = false |
||
) |
Applies the given transformation matrix to the vertex data.
onlyPosition | If true, only the position information is transformed, the normals/tangents are skipped |