Stellarium  0.90.0
Data Structures | Public Types | Public Member Functions
StelOBJ Class Reference

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< MaterialGroupMaterialGroupList
 
typedef QVector< Vec3fV3Vec
 
typedef QVector< Vec2fV2Vec
 
typedef QVector< VertexVertexList
 
typedef QVector< unsigned int > IndexList
 
typedef QVector< unsigned short > ShortIndexList
 
typedef QVector< MaterialMaterialList
 
typedef QMap< QString, int > MaterialMap
 
typedef QVector< ObjectObjectList
 
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 AABBoxgetAABBox () const
 Returns the global AABB of all vertices of the OBJ.
 
const Vec3fgetCentroid () const
 Returns the global centroid of all vertices of the OBJ. More...
 
bool load (const QString &filename, const VertexOrder vertexOrder=VertexOrder::XYZ)
 Loads an .obj file by name. More...
 
bool load (QIODevice &device, const QString &basePath, const VertexOrder vertexOrder=VertexOrder::XYZ)
 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...
 

Detailed Description

Member Function Documentation

bool StelOBJ::canUseShortIndices ( ) const
inline

This can only be done if the model has less vertices than std::numeric_limits<unsigned short>::max()

void StelOBJ::clearVertexData ( )

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.

const Vec3f& StelOBJ::getCentroid ( ) const
inline
Note
This is a very simple centroid calculation which simply accumulates all vertex positions and divides by their number. Most notably, it does not take vertex density into account, so this may not correspond to the geometric center/center of mass of the object
unsigned int StelOBJ::getFaceCount ( ) const
inline

We only use triangle faces, so this is always the index count divided by 3.

ShortIndexList StelOBJ::getShortIndexList ( ) const

If this is not possible (canUseShortIndices() returns false), an empty list is returned.

bool StelOBJ::load ( const QString &  filename,
const VertexOrder  vertexOrder = VertexOrder::XYZ 
)

Supports .gz decompression, and then calls load(QIODevice) for the actual loading.

Returns
true if load was successful
bool StelOBJ::load ( QIODevice &  device,
const QString &  basePath,
const VertexOrder  vertexOrder = VertexOrder::XYZ 
)
Parameters
deviceThe device to load OBJ data from
basePathThe path to use to find additional files (like material definitions)
vertexOrderThe order to use for vertex positions
Returns
true if load was successful
void StelOBJ::scale ( double  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

If a given parameter vector is null, it is not filled.

void StelOBJ::transform ( const QMatrix4x4 &  mat,
bool  onlyPosition = false 
)
Parameters
onlyPositionIf true, only the position information is transformed, the normals/tangents are skipped