Stellarium  0.90.0
List of all members | Classes | 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>

Classes

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() More...
 
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. More...
 
void clear ()
 Resets all data contained in this StelOBJ. More...
 
unsigned int getFaceCount () const
 Returns the number of faces. More...
 
const VertexList & getVertexList () const
 Returns an vertex list, suitable for loading into OpenGL arrays. More...
 
const IndexList & getIndexList () const
 Returns an index list, suitable for use with OpenGL element arrays. More...
 
const MaterialList & getMaterialList () const
 Returns the list of materials. More...
 
const ObjectList & getObjectList () const
 Returns the list of objects. More...
 
const ObjectMap & getObjectMap () const
 Returns the object map (mapping the object names to their indices in the object list) More...
 
const AABBoxgetAABBox () const
 Returns the global AABB of all vertices of the OBJ. More...
 
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. More...
 
void rebuildNormals ()
 Rebuilds vertex normals as the average of face normals. More...
 
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

Representation of a custom subset of a Wavefront .obj file, including only triangle data and materials.

Definition at line 37 of file StelOBJ.hpp.

Member Enumeration Documentation

Possible vertex orderings with load()

Definition at line 41 of file StelOBJ.hpp.

Constructor & Destructor Documentation

StelOBJ::StelOBJ ( )

Constructs an empty StelOBJ. Use load() to load data from a .obj file.

Member Function Documentation

bool StelOBJ::canUseShortIndices ( ) const
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()

Definition at line 264 of file StelOBJ.hpp.

void StelOBJ::clear ( )

Resets all data contained in this StelOBJ.

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.

const AABBox& StelOBJ::getAABBox ( ) const
inline

Returns the global AABB of all vertices of the OBJ.

Definition at line 237 of file StelOBJ.hpp.

const Vec3f& StelOBJ::getCentroid ( ) const
inline

Returns the global centroid of all vertices of the OBJ.

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

Definition at line 242 of file StelOBJ.hpp.

unsigned int StelOBJ::getFaceCount ( ) const
inline

Returns the number of faces.

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

Definition at line 224 of file StelOBJ.hpp.

const IndexList& StelOBJ::getIndexList ( ) const
inline

Returns an index list, suitable for use with OpenGL element arrays.

Definition at line 229 of file StelOBJ.hpp.

const MaterialList& StelOBJ::getMaterialList ( ) const
inline

Returns the list of materials.

Definition at line 231 of file StelOBJ.hpp.

const ObjectList& StelOBJ::getObjectList ( ) const
inline

Returns the list of objects.

Definition at line 233 of file StelOBJ.hpp.

const ObjectMap& StelOBJ::getObjectMap ( ) const
inline

Returns the object map (mapping the object names to their indices in the object list)

Definition at line 235 of file StelOBJ.hpp.

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.

const VertexList& StelOBJ::getVertexList ( ) const
inline

Returns an vertex list, suitable for loading into OpenGL arrays.

Definition at line 227 of file StelOBJ.hpp.

bool StelOBJ::isLoaded ( ) const
inline

Returns true if this object contains valid data from a load() method.

Definition at line 256 of file StelOBJ.hpp.

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

Loads an .obj file by name.

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 
)

Loads an .obj file from the specified device.

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::rebuildNormals ( )

Rebuilds vertex normals as the average of face normals.

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.

Parameters
onlyPositionIf true, only the position information is transformed, the normals/tangents are skipped

The documentation for this class was generated from the following file: