V-ART
|
Graphical object made of polygon meshes. More...
#include <meshobject.h>
Classes | |
class | VertexTriplet |
Public Member Functions | |
MeshObject () | |
MeshObject (const MeshObject &obj) | |
MeshObject & | operator= (const MeshObject &obj) |
virtual VART::SceneNode * | Copy () |
Returns a copy of an MeshObject. Every derived class must reimplements this method, to avoid errors with VART::SceneNode::RecursiveCopy. More... | |
void | SetMaterial (const Material &mat) |
Assigns a material to all meshes of the mesh object. More... | |
void | MakeBox (double minX, double maxX, double minY, double maxY, double minZ, double maxZ) |
Creates a box aligned with the 3 reference planes (XY, XZ and YZ). More... | |
void | GetYProjection (std::list< Point4D > *resultPtr, double height=0) const |
Computes the projection of all vertices along the Y axis. More... | |
void | Optimize () |
Optimize object for display. More... | |
void | Clear () |
Erases internal structures. More... | |
void | SetVertices (const std::vector< Point4D > &vertexVec) |
Sets the vector of vertices. More... | |
void | SetNormals (const std::vector< Point4D > &normalVec) |
Sets the vector of normals. More... | |
void | SetVertices (const char *vertexStr) |
Sets the vector of vertices. More... | |
void | SetVertex (unsigned int index, const Point4D &newValue) |
Changes one vertex. More... | |
const std::vector< double > & | GetVerticesCoordinates () |
Returns the coordinates of the vertices in the object. More... | |
void | AddFace (const char *indexStr) |
Adds a face (a mesh of a single polygon) based on previously set vertices. More... | |
void | AddMesh (const Mesh &m) |
Adds a copy of the mesh to the object. More... | |
virtual void | ComputeBoundingBox () |
Computes the bounding box. More... | |
void | ComputeBoundingBox (const Transform &trans, BoundingBox *bbPtr) |
void | ComputeSubBBoxes (const Transform &trans, int subdivisions) |
Computes de SubBBoxes and stores them. More... | |
std::vector< VART::BoundingBox > | GetSubBBoxes () |
returns the list of subdivided bounding boxes. More... | |
virtual TypeID | GetID () const |
Returns type identification of the node. More... | |
void | MergeWith (const MeshObject &obj) |
Merges one mesh object with another. More... | |
void | ApplyTransform (const Transform &trans) |
Apply Transformation to all vertices. More... | |
bool | IsEmpty () |
Checks whether the object contains geometry data. More... | |
Point4D | GetVertex (unsigned int pos) |
Returns a copy of a vertex. More... | |
void | SmallerVertex (Point4D *resultPtr) |
Computes and returns the smaller vertex. More... | |
Point4D | GetVertexMedia () |
Return the Aritmethic mean of vertexes values. More... | |
void | ComputeVertexNormals () |
Computes the normal of every vertex. More... | |
unsigned int | NumFaces () |
Computes the number of faces. More... | |
Public Member Functions inherited from VART::GraphicObj | |
GraphicObj () | |
void | Show () |
Makes the object visible. More... | |
void | Hide () |
Makes the object invisible. More... | |
void | ToggleVisibility () |
Toggles the object's visibility. More... | |
void | ToggleRecVisibility () |
Toggles the recursive object's visibility. More... | |
bool | IsVisible () |
Checks whether the object is visible. More... | |
void | ComputeRecursiveBoundingBox () |
Computes the recursive bounding box. More... | |
const BoundingBox & | GetBoundingBox () const |
Returns the bounding box. More... | |
void | SetBBoxVisibility (bool value) |
Sets the bounding box visibility. More... | |
void | SetBBoxColor (VART::Color value) |
Sets the bounding box color of graphics object. More... | |
const BoundingBox & | GetRecursiveBoundingBox () const |
Returns the recursive bounding box. More... | |
void | ToggleBBoxVisibility () |
Toggles the bounding box visibility. More... | |
void | ToggleRecBBoxVisibility () |
Toggles the recursive bounding box visibility. More... | |
unsigned int | PickName () const |
Returns the pick name. More... | |
virtual void | DrawForPicking () const |
Draws and object, setting pick info. More... | |
Public Member Functions inherited from VART::SceneNode | |
SceneNode () | |
Creates an uninitialized scene node. More... | |
SceneNode (SceneNode &node) | |
virtual | ~SceneNode () |
SceneNode & | operator= (const SceneNode &node) |
virtual SceneNode * | RecursiveCopy () |
const std::string & | GetDescription () const |
Returns a copy of the object's description. More... | |
void | SetDescription (const std::string &desc) |
Changes the object's description. More... | |
void | AddChild (SceneNode &child) |
Add a child at the end of child list. More... | |
bool | DetachChild (SceneNode *childPtr) |
Removes a child from the child list. More... | |
virtual bool | DrawOGL () const |
Recursive drawing using OpenGL commands. More... | |
void | AutoDeleteChildren () const |
Deletes (dealocate memory) recursively all children marked as 'autoDelete'. More... | |
SceneNode * | FindChildByName (const std::string &name) const |
Recusively searches its children for a given name. More... | |
std::list< SceneNode * > | GetChilds () |
bool | FindPathTo (SceneNode *targetPtr, SGPath *resultPtr) const |
Search target among children. More... | |
bool | FindPathTo (const std::string &targetName, SGPath *resultPtr) const |
Search target among children. More... | |
int | GetNodeTypeList (TypeID type, std::list< SceneNode * > &nodeList) |
Find all the nodes of with typeID 'type'. More... | |
virtual void | TraverseDepthFirst (SNOperator *operatorPtr) const |
Process all children in depth-first order. More... | |
virtual void | TraverseBreadthFirst (SNOperator *operatorPtr) const |
Process all children in breadth-first order. More... | |
virtual void | LocateDepthFirst (SNLocator *locatorPtr) const |
Seaches for a particular scene node (depth first) More... | |
virtual void | LocateBreadthFirst (SNLocator *locatorPtr) const |
Seaches for a particular scene node (breadth first) More... | |
virtual void | XmlPrintOn (std::ostream &os, unsigned int indent) const |
Recursively outputs XML representation of the scene node. More... | |
Public Member Functions inherited from VART::MemoryObj | |
MemoryObj () | |
Default constructor. More... | |
MemoryObj (const VART::MemoryObj &obj) | |
Copy constructor. More... | |
Static Public Member Functions | |
static void | ComputeTriangleNormal (const Point4D &v1, const Point4D &v2, const Point4D &v3, Point4D *resultPtr) |
Computes the normal of a triangle. More... | |
static bool | ReadFromOBJ (const std::string &filename, std::list< MeshObject * > *resultPtr) |
Read MeshObjects from a Wavefront OBJ file. More... | |
Static Public Attributes | |
static float | sizeOfNormals = 0.1f |
Size of normals for rendering (in world coordinates). More... | |
Static Public Attributes inherited from VART::SceneNode | |
static bool | recursivePrinting = true |
Protected Member Functions | |
virtual bool | DrawInstanceOGL () const |
Non-recursive drawing - should be overriden by every derived class. More... | |
void | AddNormal (unsigned int idx, const Point4D &vec) |
Adds a vector to a vertex normal. More... | |
Point4D | Vertex (unsigned int i) const |
Returns a vertex as a Point4D. More... | |
void | NormalizeAllNormals () |
Normalizes all vertex normals. More... | |
Protected Member Functions inherited from VART::SceneNode | |
bool | RecursiveFindPathTo (SceneNode *targetPtr, SGPath *resultPtr) const |
Recursive auxiliar method for FindPathTo. More... | |
bool | RecursiveFindPathTo (const std::string &targetName, SGPath *resultPtr) const |
Recursive auxiliar method for FindPathTo. More... | |
Static Protected Member Functions | |
static void | ReadVertex (std::istringstream &iss, unsigned int *vi, unsigned int *ti, unsigned int *ni) |
Reads a vertex description from a face on a OBJ file. More... | |
static void | ReadMaterialTable (const std::string &filename, std::map< std::string, Material > *matMapPtr) |
static void | ReadVerticesLine (std::istringstream &input, std::list< VertexTriplet > *resultPtr) |
Protected Attributes | |
std::vector< Point4D > | vertVec |
Vector of all vertices. More... | |
std::vector< double > | vertCoordVec |
Vector of all vertex coordinates (their coordinates in sequence). More... | |
std::vector< Point4D > | normVec |
Vector of all normals. More... | |
std::vector< double > | normCoordVec |
Vector of all vertex normals (their coordinates in sequence). More... | |
std::vector< float > | textCoordVec |
Vector of all texture coordinates. More... | |
std::list< Mesh > | meshList |
List of Meshes. More... | |
Protected Attributes inherited from VART::GraphicObj | |
bool | show |
BoundingBox | bBox |
BoundingBox | recBBox |
unsigned int | pickName |
A number that uniquely identifies the object for picking purposes. More... | |
Protected Attributes inherited from VART::SceneNode | |
std::list< SceneNode * > | childList |
Child list. More... | |
std::string | description |
Textual identification. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &output, const MeshObject &m) |
Output operator. More... | |
Additional Inherited Members | |
Public Types inherited from VART::GraphicObj | |
enum | ShowType { LINES, LINES_AND_NORMALS, POINTS, POINTS_AND_NORMALS, FILLED } |
Public Types inherited from VART::SceneNode | |
enum | TypeID { NONE, GRAPHIC_OBJ, BOX, CONE, CURVE, BEZIER, CYLINDER, IMAGE, IMAGE_2D, VOLUME, MESH_OBJECT, SPHERE, JOINT, BIAXIAL_JOINT, CONDYLAR_JOINT, ELLIPSOID_JOINT, SADDLE_JOINT, PLANE_JOINT, POLYAXIAL_JOINT, UNIAXIAL_JOINT, HINGE_JOINT, PIVOT_JOINT, TRANSFORM } |
Public Attributes inherited from VART::GraphicObj | |
ShowType | howToShow |
Defines how to show the object. More... | |
Public Attributes inherited from VART::MemoryObj | |
bool | autoDelete |
Graphical object made of polygon meshes.
A mesh object, unlike other graphical objects, maintains information about every vertex, normals, texture coordinates and edges. This is the class of choice for creating objects from files or objects whose vertex are to be edited. A mesh object may be optimized for display, and in that case vertex editing will be no longer possible.
Definition at line 25 of file meshobject.h.
VART::MeshObject::MeshObject | ( | ) |
Definition at line 32 of file meshobject.cpp.
VART::MeshObject::MeshObject | ( | const MeshObject & | obj | ) |
Definition at line 37 of file meshobject.cpp.
void VART::MeshObject::AddFace | ( | const char * | indexStr | ) |
Adds a face (a mesh of a single polygon) based on previously set vertices.
indexStr | [in] The set of indices of the face (a C-string of numbers separated by spaces) - i.e.: "0 1 2 3". |
Creates a new Mesh of a single polygon, based on the indices found in indexStr. Indices start at zero. The vertices referenced should be in counter-clockwise order. Vertices should be referenced in counter-clockwise order. No checking is done. Computes the face normal and uses it for every face vertex.
Definition at line 244 of file meshobject.cpp.
References VART::Point4D::CrossProduct(), VART::Mesh::indexVec, VART::Point4D::Normalize(), VART::Mesh::normIndVec, VART::Mesh::POLYGON, and VART::Mesh::type.
void VART::MeshObject::AddMesh | ( | const Mesh & | m | ) |
Adds a copy of the mesh to the object.
Use this method to create a custom MeshObject by hand. Since a MeshObject is composed of meshes, this is equivalent of adding a new part of the object.
Definition at line 270 of file meshobject.cpp.
|
protected |
Adds a vector to a vertex normal.
idx | [in] vertex normal index |
vec | [in] vector to add |
Definition at line 158 of file meshobject.cpp.
References VART::Point4D::GetX(), VART::Point4D::GetY(), and VART::Point4D::GetZ().
void VART::MeshObject::ApplyTransform | ( | const Transform & | trans | ) |
Apply Transformation to all vertices.
Definition at line 658 of file meshobject.cpp.
References VART::Transform::ApplyTo(), VART::Point4D::GetX(), VART::Point4D::GetY(), VART::Point4D::GetZ(), and VART::Point4D::SetXYZW().
Referenced by VART::RefSystem::RefSystem().
void VART::MeshObject::Clear | ( | ) |
Erases internal structures.
Erases previous vertices, indices, normals, texture coordinates, etc. Use before a complete change in the object.
Definition at line 59 of file meshobject.cpp.
|
virtual |
Computes the bounding box.
Implements VART::GraphicObj.
Definition at line 375 of file meshobject.cpp.
void VART::MeshObject::ComputeBoundingBox | ( | const Transform & | trans, |
VART::BoundingBox * | bbPtr | ||
) |
Definition at line 397 of file meshobject.cpp.
References VART::BoundingBox::ConditionalUpdate(), VART::BoundingBox::SetBoundingBox(), and VART::Point4D::SetXYZW().
void VART::MeshObject::ComputeSubBBoxes | ( | const Transform & | trans, |
int | subdivisions | ||
) |
Computes de SubBBoxes and stores them.
Computes 8^n, n=subdivisions, bounding boxes storing them at subBBoxes list. Trans is the vertex transformations.
Definition at line 431 of file meshobject.cpp.
References VART::BoundingBox::ConditionalUpdate(), VART::BoundingBox::SetBoundingBox(), and VART::Point4D::SetXYZW().
|
static |
Computes the normal of a triangle.
v1 | [in] 1st triangle vertex |
v2 | [in] 2nd triangle vertex |
v3 | [in] 3rd triangle vertex |
resultPtr | [out] Triangle normal (unit length). |
V1, V2 and V3 should be in counter clockwise order.
Definition at line 685 of file meshobject.cpp.
References VART::Point4D::CrossProduct(), and VART::Point4D::Normalize().
void VART::MeshObject::ComputeVertexNormals | ( | ) |
Computes the normal of every vertex.
Computes the normal of every vertex by computing face normals and then computing the average of all normals for faces that share a vertex.
Definition at line 475 of file meshobject.cpp.
|
virtual |
Returns a copy of an MeshObject. Every derived class must reimplements this method, to avoid errors with VART::SceneNode::RecursiveCopy.
Implements VART::SceneNode.
Definition at line 54 of file meshobject.cpp.
|
protectedvirtual |
Non-recursive drawing - should be overriden by every derived class.
Reimplemented from VART::SceneNode.
Definition at line 693 of file meshobject.cpp.
|
inlinevirtual |
Returns type identification of the node.
Reimplemented from VART::SceneNode.
Definition at line 134 of file meshobject.h.
References VART::SceneNode::MESH_OBJECT.
|
inline |
returns the list of subdivided bounding boxes.
Definition at line 132 of file meshobject.h.
VART::Point4D VART::MeshObject::GetVertex | ( | unsigned int | pos | ) |
Returns a copy of a vertex.
Definition at line 144 of file meshobject.cpp.
VART::Point4D VART::MeshObject::GetVertexMedia | ( | ) |
Return the Aritmethic mean of vertexes values.
Definition at line 221 of file meshobject.cpp.
|
inline |
Returns the coordinates of the vertices in the object.
Definition at line 99 of file meshobject.h.
References vertCoordVec.
void VART::MeshObject::GetYProjection | ( | std::list< Point4D > * | resultPtr, |
double | height = 0 |
||
) | const |
Computes the projection of all vertices along the Y axis.
resultPtr | [in,out] A pointer to a list that will be filled with resulting vertices. |
height | [in] Y coordinate to use in the projection (defaults to 0). |
Definition at line 344 of file meshobject.cpp.
References VART::Point4D::SetXYZW().
|
inline |
Checks whether the object contains geometry data.
Returns true if the object contains no geometry data. Actually it checks whether the mesh list is empty, which should be enough for consistent mesh objects.
Definition at line 160 of file meshobject.h.
References meshList.
Referenced by ReadFromOBJ().
void VART::MeshObject::MakeBox | ( | double | minX, |
double | maxX, | ||
double | minY, | ||
double | maxY, | ||
double | minZ, | ||
double | maxZ | ||
) |
Creates a box aligned with the 3 reference planes (XY, XZ and YZ).
Definition at line 275 of file meshobject.cpp.
References VART::Material::DARK_PLASTIC_GRAY(), VART::Mesh::indexVec, VART::Mesh::material, VART::Mesh::QUADS, and VART::Mesh::type.
void VART::MeshObject::MergeWith | ( | const MeshObject & | obj | ) |
Merges one mesh object with another.
All vertices, normals, meshes, etc. are copied inside the active object.
Definition at line 633 of file meshobject.cpp.
References VART::Mesh::IncrementIndices(), meshList, normCoordVec, normVec, textCoordVec, vertCoordVec, and vertVec.
|
protected |
Normalizes all vertex normals.
Definition at line 1013 of file meshobject.cpp.
unsigned int VART::MeshObject::NumFaces | ( | ) |
Computes the number of faces.
Definition at line 168 of file meshobject.cpp.
VART::MeshObject & VART::MeshObject::operator= | ( | const MeshObject & | obj | ) |
Definition at line 42 of file meshobject.cpp.
References meshList, normCoordVec, normVec, textCoordVec, vertCoordVec, and vertVec.
void VART::MeshObject::Optimize | ( | ) |
Optimize object for display.
This method creates an internal representation that is optimized for display (currently aimed at OpenGL - optimized representation may not be usefull for other renderers such as Direct3D). After being optimized, old data is discarded and the object can no longer be edited.
Definition at line 369 of file meshobject.cpp.
|
static |
Read MeshObjects from a Wavefront OBJ file.
filename | [in] The file (Wavefront OBJ file) name. |
resultPtr | [out] The address of an empty list of pointers to mesh objects to be filled with the addresses of newly allocated mesh objects. |
This method creates mesh objects marked as auto-delete, ie, they will be automatically deleted if attached to scene. If not, the application programmer should delete them.
Definition at line 775 of file meshobject.cpp.
References VART::MemoryObj::autoDelete, VART::File::GetPathFromString(), VART::Mesh::indexVec, IsEmpty(), VART::Mesh::material, meshList, VART::Mesh::NONE, normCoordVec, VART::Mesh::normIndVec, VART::Mesh::POLYGON, VART::Mesh::QUADS, VART::SceneNode::SetDescription(), VART::Material::SetTexture(), textCoordVec, VART::Mesh::TRIANGLES, VART::Mesh::type, and vertCoordVec.
Referenced by VART::XmlScene::LoadMeshFromFile().
|
staticprotected |
Definition at line 1033 of file meshobject.cpp.
References VART::Color::BLACK(), VART::File::GetPathFromString(), VART::Texture::HasData(), VART::Texture::LoadFromFile(), VART::Material::SetAmbientColor(), VART::Material::SetDiffuseColor(), VART::Material::SetEmissiveColor(), VART::Material::SetShininess(), VART::Material::SetSpecularColor(), and VART::Material::SetTexture().
|
staticprotected |
Reads a vertex description from a face on a OBJ file.
Definition at line 1160 of file meshobject.cpp.
References CountOccurrences().
|
staticprotected |
Definition at line 1207 of file meshobject.cpp.
void VART::MeshObject::SetMaterial | ( | const Material & | mat | ) |
Assigns a material to all meshes of the mesh object.
Definition at line 69 of file meshobject.cpp.
Referenced by VART::RefSystem::RefSystem().
void VART::MeshObject::SetNormals | ( | const std::vector< Point4D > & | normalVec | ) |
Sets the vector of normals.
Use this method to set normals for unoptimized objects. Note that normals are atomatically computed if AddFace is used to set the faces. This method clears the mesh list, so it should be called before AddFace.
Definition at line 91 of file meshobject.cpp.
void VART::MeshObject::SetVertex | ( | unsigned int | index, |
const Point4D & | newValue | ||
) |
Changes one vertex.
index | [in] Index of the vertex to be changed. |
newValue | [in] New value to be copied into the vertex. |
Definition at line 129 of file meshobject.cpp.
References VART::Point4D::GetX(), VART::Point4D::GetY(), and VART::Point4D::GetZ().
void VART::MeshObject::SetVertices | ( | const std::vector< Point4D > & | vertexVec | ) |
Sets the vector of vertices.
vertexVec | [in] The new vector of vertices. |
All vertices in vertexVec are copied into the MeshObject's internal representation. The meshList is cleared.
void VART::MeshObject::SetVertices | ( | const char * | vertexStr | ) |
Sets the vector of vertices.
vertexStr | [in] The set of vertices (a C-string of point coordinates). |
Parses all values in vertexStr and stores them into the MeshObject's internal representation. Parameter vertexStr should be set of points separated by commas, point coordinates should be separated by spaces, point may have 3 or 4 coordinates - i.e.: "1.2 0.2 3.1, 2 3 4 1, 1 2 3" The MeshObject becomes unoptimized. The meshList is cleared.
Definition at line 99 of file meshobject.cpp.
References VART::Point4D::SetXYZW().
void VART::MeshObject::SmallerVertex | ( | Point4D * | resultPtr | ) |
Computes and returns the smaller vertex.
Definition at line 192 of file meshobject.cpp.
References VART::Point4D::SetXYZ().
|
inlineprotected |
Returns a vertex as a Point4D.
Requires the the MeshObject is in optimized form.
Definition at line 244 of file meshobject.h.
References vertCoordVec.
|
friend |
Output operator.
|
protected |
List of Meshes.
Definition at line 283 of file meshobject.h.
Referenced by IsEmpty(), MergeWith(), VART::operator<<(), operator=(), and ReadFromOBJ().
|
protected |
Vector of all vertex normals (their coordinates in sequence).
This is the optimized storage of normals. It must be a vector (not a list) because OpenGL will see it as a C array.
Definition at line 274 of file meshobject.h.
Referenced by MergeWith(), operator=(), and ReadFromOBJ().
|
protected |
Vector of all normals.
This is the unoptimized storage of normals. It must be a vector (not a list) because the internal meshes identifies vertices by integers.
Definition at line 268 of file meshobject.h.
Referenced by MergeWith(), and operator=().
|
static |
Size of normals for rendering (in world coordinates).
Definition at line 212 of file meshobject.h.
|
protected |
Vector of all texture coordinates.
This is both the optimized and the unoptimized storage of texture coordinates. It must be a vector (not a list) because OpenGL will see it as a C array.
Definition at line 280 of file meshobject.h.
Referenced by MergeWith(), VART::operator<<(), operator=(), and ReadFromOBJ().
|
protected |
Vector of all vertex coordinates (their coordinates in sequence).
This is the optimized storage of vertices. It must be a vector (not a list) because OpenGL will see it as a C array. Every 3 sucessive coordinates in the array describe a vertex in the object.
Definition at line 262 of file meshobject.h.
Referenced by GetVerticesCoordinates(), MergeWith(), VART::operator<<(), operator=(), ReadFromOBJ(), and Vertex().
|
protected |
Vector of all vertices.
This is the unoptimized storage of vertices. It must be a vector (not a list) because the internal meshes identifies vertices by integers.
Definition at line 255 of file meshobject.h.
Referenced by MergeWith(), and operator=().