21 unsigned int occurrences = 0;
22 string::size_type pos = s.find(c);
23 while (pos != string::npos)
26 pos = s.find(c, pos+1);
44 this->GraphicObj::operator =(obj);
71 list<VART::Mesh>::iterator iter;
72 for (iter = meshList.begin(); iter != meshList.end(); ++iter)
79 unsigned int numberOfVertex = vertexVec.size();
80 vertCoordVec.reserve(numberOfVertex * 3);
81 for (
unsigned int i = 0; i < numberOfVertex; ++i) {
82 vertCoordVec.push_back(vertexVec[i].GetX());
83 vertCoordVec.push_back(vertexVec[i].GetY());
84 vertCoordVec.push_back(vertexVec[i].GetZ());
88 ComputeRecursiveBoundingBox();
96 ComputeRecursiveBoundingBox();
101 string valStr = vertexStr;
102 istringstream iss(valStr);
104 bool notFinished =
true;
109 if (!(iss >> x >> y >> z))
119 vertVec.push_back(point);
123 }
while (notFinished);
125 ComputeBoundingBox();
126 ComputeRecursiveBoundingBox();
133 unsigned int newIndex = index*3;
134 vertCoordVec[newIndex] = newValue.
GetX();
135 vertCoordVec[newIndex+1] = newValue.
GetY();
136 vertCoordVec[newIndex+2] = newValue.
GetZ();
140 vertVec[index] = newValue;
148 unsigned int newPos = pos*3;
149 return VART::Point4D(vertCoordVec[newPos],vertCoordVec[newPos+1],vertCoordVec[newPos+2]);
160 unsigned int coordIdx = idx*3;
161 normCoordVec[coordIdx] += vec.
GetX();
163 normCoordVec[coordIdx] += vec.
GetY();
165 normCoordVec[coordIdx] += vec.
GetZ();
170 unsigned int result = 0;
171 list<Mesh>::iterator iter = meshList.begin();
173 for (; iter != meshList.end(); ++iter)
178 result += iter->indexVec.size() / 4;
180 case Mesh::TRIANGLES:
181 result += iter->indexVec.size() / 3;
184 cerr <<
"Error: MeshObject::NumFaces not implementes for meshes of type "
185 <<
static_cast<int>(iter->type) <<
"\n";
196 Point4D smaller(vertCoordVec[0],vertCoordVec[1],vertCoordVec[2]);
198 unsigned int size = vertCoordVec.size();
199 for (
unsigned int i=3; i < size; i += 3)
202 temp.
SetXYZ(vertCoordVec[i],vertCoordVec[i+1],vertCoordVec[i+2]);
206 *resultPtr = smaller;
211 unsigned int size = vertVec.size();
212 for (
unsigned int i=1; i < size; ++i)
214 if (vertVec[i] < smaller)
215 smaller = vertVec[i];
217 *resultPtr = smaller;
225 cerr <<
"\aWarning: MeshObject::GetVertexMedia() is deprecated.\n";
229 size = vertCoordVec.size();
231 for(
int i=0; i < size ; i+=3)
233 mean +=
VART::Point4D( vertCoordVec[i], vertCoordVec[i+1], vertCoordVec[i+2]);
239 mean = mean / (size/3);
246 string valStr = indexStr;
247 istringstream iss(valStr);
249 unsigned int thisFacesNormalIndex = normVec.size();
256 mesh.
normIndVec.push_back(thisFacesNormalIndex);
258 meshList.push_back(mesh);
267 normVec.push_back(normal);
272 meshList.push_back(m);
277 cerr <<
"MeshObject::MakeBox is deprecated. Use VART::Box.\n";
278 assert((minX <= maxX) && (minY <= maxY) && (minZ <= maxZ));
281 double coordinateArray[] = { minX,minY,minZ,
305 double* endOfCoordinateArray = coordinateArray +
sizeof(coordinateArray)/
sizeof(
double);
306 unsigned int indexArray[] = { 0,1,2,3,
312 unsigned int* endOfIndexArray = indexArray +
sizeof(indexArray)/
sizeof(
int);
313 double normalArray[] = { 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1,
314 0,0,1, 0,0,1, 0,0,1, 0,0,1,
315 -1,0,0, -1,0,0, 1,0,0, 1,0,0,
316 -1,0,0, -1,0,0, 1,0,0, 1,0,0,
317 0,-1,0, 0,1,0, 0,1,0, 0,-1,0,
318 0,-1,0, 0,1,0, 0,1,0, 0,-1,0 };
319 double* endOfNormalArray = normalArray +
sizeof(normalArray)/
sizeof(
double);
320 float textArray[] = { 0,0,0, 0,1,0, 1,1,0, 1,0,0,
321 0,0,0, 0,1,0, 1,1,0, 1,0,0,
322 0,0,0, 0,1,0, 1,1,0, 1,0,0,
323 0,0,0, 0,1,0, 1,1,0, 1,0,0,
324 0,0,0, 0,1,0, 1,1,0, 1,0,0,
325 0,0,0, 0,1,0, 1,1,0, 1,0,0 };
326 float* endOfTextArray = textArray +
sizeof(textArray)/
sizeof(
float);
329 vertCoordVec.clear();
330 normCoordVec.clear();
331 textCoordVec.clear();
333 vertCoordVec.assign(coordinateArray,endOfCoordinateArray);
334 normCoordVec.assign(normalArray,endOfNormalArray);
335 textCoordVec.assign(textArray,endOfTextArray);
337 mesh.
indexVec.assign(indexArray,endOfIndexArray);
339 meshList.push_back(mesh);
340 ComputeBoundingBox();
341 ComputeRecursiveBoundingBox();
349 if (vertCoordVec.size() > 6)
351 unsigned int vertexVetEnd = vertCoordVec.size();
352 for (
unsigned int i=0; i < vertexVetEnd; i+=3)
354 point.
SetXYZW(vertCoordVec[i],height,vertCoordVec[i+2],1);
355 resultPtr->push_back(point);
360 unsigned int vertexVetEnd = vertVec.size();
361 for (
unsigned int i=0; i < vertexVetEnd; ++i)
363 point.
SetXYZW(vertVec[i].GetX(), height, vertVec[i].GetZ(), 1);
364 resultPtr->push_back(point);
376 if (vertCoordVec.size() > 0)
379 bBox.SetBoundingBox(vertCoordVec[0], vertCoordVec[1], vertCoordVec[2],
380 vertCoordVec[0], vertCoordVec[1], vertCoordVec[2]);
382 for (
unsigned int i=3; i < vertCoordVec.size(); i+=3)
383 bBox.ConditionalUpdate(vertCoordVec[i], vertCoordVec[i+1], vertCoordVec[i+2]);
388 bBox.SetBoundingBox(vertVec[0].GetX(), vertVec[0].GetY(), vertVec[0].GetZ(),
389 vertVec[0].GetX(), vertVec[0].GetY(), vertVec[0].GetZ());
391 for (
unsigned int i=1; i < vertVec.size(); ++i)
392 bBox.ConditionalUpdate(vertVec[i]);
394 bBox.ProcessCenter();
401 if (vertCoordVec.size() > 0)
404 p.
SetXYZW( vertCoordVec[0], vertCoordVec[1], vertCoordVec[2], 1 );
406 bbPtr->
SetBoundingBox(p.GetX(), p.GetY(), p.GetZ() , p.GetX(), p.GetY(), p.GetZ());
408 for (
unsigned int i=3; i < vertCoordVec.size(); i+=3)
410 p.SetXYZW( vertCoordVec[i], vertCoordVec[i+1], vertCoordVec[i+2], 1 );
420 bbPtr->
SetBoundingBox(p.GetX(), p.GetY(), p.GetZ() , p.GetX(), p.GetY(), p.GetZ());
422 for (
unsigned int i=1; i < vertVec.size(); ++i)
435 std::vector<VART::Point4D> pointList;
438 if (vertCoordVec.size() <= 0)
441 pointList.reserve( (
int) (vertCoordVec.size() / 3) );
444 p.
SetXYZW( vertCoordVec[0], vertCoordVec[1], vertCoordVec[2], 1 );
446 pointList.push_back( p );
447 globalBBox.
SetBoundingBox(p.GetX(), p.GetY(), p.GetZ() , p.GetX(), p.GetY(), p.GetZ());
450 for (
unsigned int i=3; i < vertCoordVec.size(); i+=3)
452 p.SetXYZW( vertCoordVec[i], vertCoordVec[i+1], vertCoordVec[i+2], 1 );
454 pointList.push_back( p );
458 if( subdivisions <= 0)
460 subBBoxes.push_back( globalBBox );
464 subBBoxes.reserve( (
int)pow(8.0f, subdivisions) );
466 subDivideBBox( globalBBox, subdivisions-1, pointList);
479 normCoordVec.assign(vertCoordVec.size(), 0);
482 list<Mesh>::iterator iter = meshList.begin();
483 for (; iter != meshList.end(); ++iter)
485 unsigned int p1Idx = 0;
486 unsigned int p2Idx = 1;
487 unsigned int p3Idx = 2;
488 unsigned int end = iter->indexVec.size();
494 ComputeTriangleNormal(Vertex(iter->indexVec[p1Idx]),
495 Vertex(iter->indexVec[p2Idx]),
496 Vertex(iter->indexVec[p3Idx]), &normal);
498 AddNormal(iter->indexVec[p1Idx], normal);
499 AddNormal(iter->indexVec[p2Idx], normal);
500 AddNormal(iter->indexVec[p3Idx], normal);
504 case Mesh::TRIANGLES:
509 case Mesh::TRIANGLE_STRIP:
514 case Mesh::TRIANGLE_FAN:
518 AddNormal(iter->indexVec[p3Idx+1], normal);
523 case Mesh::QUAD_STRIP:
524 AddNormal(iter->indexVec[p3Idx+1], normal);
531 for (; p3Idx < end; ++p3Idx)
532 AddNormal(iter->indexVec[p3Idx], normal);
535 cerr <<
"Error: MeshObject::ComputeVertexNormals not implemented for mesh type "
536 <<
static_cast<int>(iter->type) << endl;
542 NormalizeAllNormals();
545 void VART::MeshObject::subDivideBBox(
VART::BoundingBox motherBox,
int subdivisions, std::vector<VART::Point4D> pointList )
558 computeNewSubBBox( newBBox, subdivisions, pointList );
563 computeNewSubBBox( newBBox, subdivisions, pointList );
568 computeNewSubBBox( newBBox, subdivisions, pointList );
573 computeNewSubBBox( newBBox, subdivisions, pointList );
578 computeNewSubBBox( newBBox, subdivisions, pointList );
583 computeNewSubBBox( newBBox, subdivisions, pointList );
588 computeNewSubBBox( newBBox, subdivisions, pointList );
593 computeNewSubBBox( newBBox, subdivisions, pointList );
596 void VART::MeshObject::computeNewSubBBox(
VART::BoundingBox oldBox,
int subdivisions, std::vector<VART::Point4D> pointList)
598 std::vector<Point4D> newPointList;
600 bool initialized =
false;
602 for(
unsigned int i=0; (i < pointList.size()) && (!initialized); i++ )
605 newBBox.
SetBoundingBox( pointList[i].GetX(), pointList[i].GetY(), pointList[i].GetZ(),
606 pointList[i].GetX(), pointList[i].GetY(), pointList[i].GetZ());
615 for(
unsigned int i=0; i < pointList.size(); i+=3 )
627 if(subdivisions == 0)
628 subBBoxes.push_back( newBBox );
630 subDivideBBox( newBBox, subdivisions-1, pointList);
635 bool bothOptimized = vertVec.empty() && obj.
vertVec.empty();
636 list<VART::Mesh>::const_iterator iter = obj.
meshList.begin();
638 unsigned int prevNumVertices;
639 assert (bothOptimized || (vertCoordVec.empty() && obj.
vertCoordVec.empty()));
641 prevNumVertices = (bothOptimized? (vertCoordVec.size()/3) : vertVec.size());
642 for (; iter != obj.
meshList.end(); ++iter)
646 meshList.push_back(mesh);
649 vertVec.insert(vertVec.end(), obj.
vertVec.begin(), obj.
vertVec.end());
651 normVec.insert(normVec.end(), obj.
normVec.begin(), obj.
normVec.end());
654 ComputeBoundingBox();
655 ComputeRecursiveBoundingBox();
662 if (vertCoordVec.empty())
664 for (size = vertVec.size(); i < size; ++i)
672 for (size = vertCoordVec.size(); i < size; i+=3)
674 vertex.
SetXYZW(vertCoordVec[i],vertCoordVec[i+1],vertCoordVec[i+2],1);
676 vertCoordVec[i] = vertex.
GetX();
677 vertCoordVec[i+1] = vertex.
GetY();
678 vertCoordVec[i+2] = vertex.
GetZ();
681 ComputeBoundingBox();
682 ComputeRecursiveBoundingBox();
696 list<VART::Mesh>::const_iterator iter;
702 case LINES_AND_NORMALS:
703 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
706 case POINTS_AND_NORMALS:
707 glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
710 glPolygonMode(GL_FRONT, GL_FILL);
713 if (vertCoordVec.size() > 0)
717 glVertexPointer(3, GL_DOUBLE, 0, &vertCoordVec[0]);
718 glNormalPointer(GL_DOUBLE, 0, &normCoordVec[0]);
719 if (!textCoordVec.empty())
720 glTexCoordPointer(3, GL_FLOAT, 0, &textCoordVec[0]);
721 if ((howToShow == LINES_AND_NORMALS) || (howToShow == POINTS_AND_NORMALS))
723 unsigned int numVertices = vertCoordVec.size() / 3;
724 unsigned int index = 0;
725 Material::PLASTIC_WHITE().DrawOGL();
727 for (
unsigned int i=0; i < numVertices; ++i)
729 glVertex3dv(&vertCoordVec[index]);
730 glVertex3d(vertCoordVec[index] + sizeOfNormals*normCoordVec[index],
731 vertCoordVec[index+1]+sizeOfNormals*normCoordVec[index+1],
732 vertCoordVec[index+2]+sizeOfNormals*normCoordVec[index+2]);
737 for (iter = meshList.begin(); iter != meshList.end(); ++iter)
742 result &= iter->DrawInstanceOGL();
747 unsigned int meshSize;
749 for (iter = meshList.begin(); iter != meshList.end(); ++iter)
751 iter->material.DrawOGL();
752 glBegin(iter->GetOglType());
753 meshSize = iter->indexVec.size();
754 assert(meshSize == iter->normIndVec.size());
755 for (i = 0; i < meshSize; ++i)
758 glNormal3dv(normVec[iter->normIndVec[i]].VetXYZW());
759 glVertex4dv(vertVec[iter->indexVec[i]].VetXYZW());
766 bBox.DrawInstanceOGL();
768 recBBox.DrawInstanceOGL();
782 ifstream file(filename.c_str());
784 cout <<
"Loading " << filename <<
"...\n" << flush;
786 cerr <<
"MeshObject::ReadFromOBJ failed to open '" << filename <<
"'.\n";
792 resultPtr->push_back(meshObjectPtr);
800 map<string,VART::Material> materialMap;
801 map<string,VART::Texture> textureMap;
803 map<VertexTriplet, unsigned int> vertIndexesMap;
804 vector<float> vertCoordTempVec;
805 vector<float> vertNormTempVec;
806 vector<float> textCoordTempVec;
809 unsigned int faceCounter = 0;
810 unsigned int objCounter = 0;
811 unsigned int lineNumber = 0;
813 while (getline(file, line)) {
816 if(iss.peek() != -1) {
819 static unsigned int index = 0;
827 vertCoordTempVec.push_back(x);
828 vertCoordTempVec.push_back(y);
829 vertCoordTempVec.push_back(z);
831 else if (lineID ==
"vn") {
838 vertNormTempVec.push_back(x);
839 vertNormTempVec.push_back(y);
840 vertNormTempVec.push_back(z);
842 else if (lineID ==
"vt") {
846 textCoordTempVec.push_back(x);
847 textCoordTempVec.push_back(y);
848 textCoordTempVec.push_back(0.0f);
850 else if (lineID ==
"f") {
851 list<VertexTriplet> vertices;
852 ReadVerticesLine(iss, &vertices);
854 switch(vertices.size()) {
855 case 1: cerr <<
"ReadFromObj found a face with 1 vertex!\n";
857 case 2: cerr <<
"ReadFromObj found a face with 2 vertices!\n";
868 if (mesh.
type != Mesh::NONE) {
869 if (tempType != mesh.
type) {
872 meshObjectPtr->
meshList.push_back(mesh);
875 mesh.
type = tempType;
879 mesh.
type = tempType;
886 for (
auto& vTriple : vertices) {
887 map<VertexTriplet, unsigned int>::iterator pos =
888 vertIndexesMap.find(vTriple);
889 if (pos != vertIndexesMap.end()) {
891 mesh.
indexVec.push_back(pos->second);
894 vertIndexesMap.insert(make_pair(vTriple, index));
899 unsigned int i = (vTriple.vertexIndex-1)*3;
900 meshObjectPtr->
vertCoordVec.push_back(vertCoordTempVec[i]);
901 meshObjectPtr->
vertCoordVec.push_back(vertCoordTempVec[++i]);
902 meshObjectPtr->
vertCoordVec.push_back(vertCoordTempVec[++i]);
904 if (vTriple.textIndex != 0) {
905 i = (vTriple.textIndex-1)*3;
906 meshObjectPtr->
textCoordVec.push_back(textCoordTempVec[i]);
907 meshObjectPtr->
textCoordVec.push_back(textCoordTempVec[++i]);
908 meshObjectPtr->
textCoordVec.push_back(textCoordTempVec[++i]);
911 i = (vTriple.normIndex-1)*3;
912 meshObjectPtr->
normCoordVec.push_back(vertNormTempVec[i]);
913 meshObjectPtr->
normCoordVec.push_back(vertNormTempVec[++i]);
914 meshObjectPtr->
normCoordVec.push_back(vertNormTempVec[++i]);
919 else if (lineID ==
"usemtl")
924 meshObjectPtr->
meshList.push_back(mesh);
932 else if (lineID ==
"usemap")
936 transform(name.begin(), name.end(), name.begin(), ::tolower);
938 if(!texture.HasData())
941 if(! texture.LoadFromFile(name) )
943 ": could not read texture file '" << name <<
"'" << endl;
944 textureMap[name] = texture;
948 else if (lineID ==
"mtllib")
953 else if (lineID ==
"maplib")
956 else if (lineID ==
"o")
963 meshObjectPtr->
meshList.push_back(mesh);
970 resultPtr->remove(meshObjectPtr);
971 delete meshObjectPtr;
977 resultPtr->push_back(meshObjectPtr);
980 else if (lineID[0] ==
'#')
983 else if (lineID ==
"g")
986 else if (lineID ==
"s")
990 cerr <<
"Error in '" << filename <<
"', line " << lineNumber <<
": unknown ID '"
991 << lineID <<
"'" << endl;
997 meshObjectPtr->
meshList.push_back(mesh);
1000 list<VART::MeshObject*>::iterator iter;
1001 for (iter = resultPtr->begin(); iter != resultPtr->end(); ++iter)
1003 (*iter)->ComputeBoundingBox();
1004 (*iter)->ComputeRecursiveBoundingBox();
1006 clog <<
"File " << filename <<
" finished loading ("
1007 << objCounter <<
" objects, "
1008 << faceCounter <<
" polygons).\n";
1015 unsigned int i0 = 0;
1016 unsigned int i1 = 1;
1017 unsigned int i2 = 2;
1019 while (i2 < normCoordVec.size())
1021 size = sqrt(normCoordVec[i0]*normCoordVec[i0] +
1022 normCoordVec[i1]*normCoordVec[i1] +
1023 normCoordVec[i2]*normCoordVec[i2]);
1024 normCoordVec[i0] /= size;
1025 normCoordVec[i1] /= size;
1026 normCoordVec[i2] /= size;
1036 ifstream file(filename.c_str());
1040 string materialName;
1044 std::map<std::string,VART::Texture> textureMap;
1048 unsigned int lineNumber = 0;
1051 if( !file.is_open() )
1053 cerr <<
"Error in '" << filename <<
"': could not read material table file." << endl;
1056 while (getline(file,line))
1061 if (lineID ==
"newmtl")
1064 if (materialName.size() > 0)
1065 matMapPtr->insert(make_pair(materialName,material));
1067 iss >> ws >> materialName;
1069 else if (lineID ==
"Ns")
1076 else if (lineID ==
"Kd")
1080 static_cast<unsigned char>(g*255),
1081 static_cast<unsigned char>(b*255)));
1083 else if (lineID ==
"Ka")
1087 static_cast<unsigned char>(g*255),
1088 static_cast<unsigned char>(b*255)));
1090 else if (lineID ==
"Ks")
1094 static_cast<unsigned char>(g*255),
1095 static_cast<unsigned char>(b*255)));
1097 else if (lineID ==
"Ke")
1101 static_cast<unsigned char>(g*255),
1102 static_cast<unsigned char>(b*255)));
1104 else if ((lineID ==
"d") || (lineID ==
"Tr"))
1109 else if (lineID ==
"illum")
1116 else if (lineID ==
"map_Kd")
1119 texture = textureMap[textureName];
1125 cerr <<
"Error reading map_Kd in '" << filename <<
"', line "
1126 << lineNumber <<
": could not read texture file '"
1127 << path << textureName <<
"'" << endl;
1129 textureMap[textureName] = texture;
1133 else if (lineID ==
"Ni")
1141 float opticalDensity;
1142 iss >> opticalDensity;
1144 else if (lineID ==
"#")
1149 cerr <<
"Error in '" << filename <<
"', line " << lineNumber <<
": unknown ID '"
1150 << lineID <<
"'" << endl;
1155 if (materialName.size() > 0)
1156 matMapPtr->insert(make_pair(materialName,material));
1161 unsigned int* viPtr,
unsigned int* tiPtr,
unsigned int* niPtr)
1167 unsigned int& vi = *viPtr;
1168 unsigned int& ti = *tiPtr;
1169 unsigned int& ni = *niPtr;
1171 string vertexString;
1172 iss >> vertexString;
1173 if (vertexString.empty())
1174 throw "Input Finished";
1176 istringstream vStream(vertexString);
1179 vStream >> vi >> slash;
1180 if (slashOccurrences == 2) {
1181 if(vStream.peek() !=
'/')
1184 static bool notWarned =
true;
1186 clog <<
"Warning: OBJ file is missing texture indices.\n";
1193 static bool notWarned =
true;
1195 cerr <<
"Error: OBJ file is missing normal indices.\n";
1202 cerr <<
"Error while reading. See MeshObject::ReadVertex.\n";
1208 std::list<VertexTriplet>* resultPtr)
1212 unsigned int vi, ni, ti;
1215 ReadVertex(input, &vi, &ni, &ti);
1219 catch (
char const* error) {
1228 output <<
"[ MeshObject '" << m.
description <<
"'\n" << flush
1229 <<
" " << size/3 <<
" vertices: (";
1230 for (
unsigned int i = 0; i < size; ++i) {
1236 output <<
")\n " << size/3 <<
" texture coordinates: ( ";
1237 for (
unsigned int i = 0; i < size; ++i) {
1243 output <<
")\n " << m.
meshList.size() <<
" meshes: ";
1244 list<Mesh>::const_iterator iter = m.
meshList.begin();
1245 for (; iter != m.
meshList.end(); ++iter)
1246 output <<
"(" << *iter <<
")\n";
unsigned int CountOccurrences(char c, string s)
Base class for objects that compose a scene graph.
Point4D GetVertex(unsigned int pos)
Returns a copy of a vertex.
static void ReadMaterialTable(const std::string &filename, std::map< std::string, Material > *matMapPtr)
Points and vectors using homogeneous coordinates.
std::vector< unsigned int > normIndVec
indexes of the normals (for unoptimized meshes)
void AddNormal(unsigned int idx, const Point4D &vec)
Adds a vector to a vertex normal.
void SetEmissiveColor(const Color &c)
Sets the emissive color of the material.
static void ComputeTriangleNormal(const Point4D &v1, const Point4D &v2, const Point4D &v3, Point4D *resultPtr)
Computes the normal of a triangle.
void CutBBox(const BoundingBox &box)
Test against other bounding box and update itself if its outside the given bbox.
void SetBoundingBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ)
void AddFace(const char *indexStr)
Adds a face (a mesh of a single polygon) based on previously set vertices.
static const Color & GREEN()
Green opaque color.
void SetShininess(float newValue)
Set the shininess of the material.
std::list< Mesh > meshList
List of Meshes.
static const Material & DARK_PLASTIC_GRAY()
void Normalize()
Normalizes the point/vector.
void ConditionalUpdate(double x, double y, double z)
Updates the bounding box if any given coordinate is outside it.
bool HasData() const
Indicates if a texture object contains data.
std::string description
Textual identification.
void GetYProjection(std::list< Point4D > *resultPtr, double height=0) const
Computes the projection of all vertices along the Y axis.
void SetAmbientColor(const Color &c)
Sets the ambient color of the material.
RGBA color representation.
Axis aligned bounding box.
Header file for V-ART class "File".
void SetVertices(const std::vector< Point4D > &vertexVec)
Sets the vector of vertices.
void SetColor(const Color &value)
Sets the bounding box color.
double GetGreaterZ() const
A mesh is part of an graphical object, in which faces are made of vertices according to some rule of ...
double GetSmallerX() const
bool testPoint(VART::Point4D p)
Test if a point is included in the bbox.
void IncrementIndices(unsigned int increment)
Returns the mesh type as OpenGL enum.
Point4D GetVertexMedia()
Return the Aritmethic mean of vertexes values.
bool IsEmpty()
Checks whether the object contains geometry data.
std::vector< double > normCoordVec
Vector of all vertex normals (their coordinates in sequence).
void NormalizeAllNormals()
Normalizes all vertex normals.
void SetTexture(const Texture &t)
Sets the texture of material.
Point4D CrossProduct(const Point4D &p) const
Computes the cross product between "this" and "p".
void SetXYZ(double x, double y, double z)
static std::string GetPathFromString(const std::string &fileName)
void SetSpecularColor(const Color &c)
Sets the specular color (highlight color) of the material.
void SmallerVertex(Point4D *resultPtr)
Computes and returns the smaller vertex.
2D image to use as texture.
void SetDiffuseColor(const Color &c)
Sets the diffuse color (main color) of the material.
virtual void ComputeBoundingBox()
Computes the bounding box.
void Clear()
Erases internal structures.
double GetSmallerY() const
void SetDescription(const std::string &desc)
Changes the object's description.
Material properties for graphical objects.
static const Color & BLACK()
Black opaque color.
std::vector< float > textCoordVec
Vector of all texture coordinates.
double GetGreaterY() const
void SetMaterial(const Material &mat)
Assigns a material to all meshes of the mesh object.
ostream & operator<<(ostream &output, const MeshObject &m)
virtual bool DrawInstanceOGL() const
Non-recursive drawing - should be overriden by every derived class.
void ComputeSubBBoxes(const Transform &trans, int subdivisions)
Computes de SubBBoxes and stores them.
void AddMesh(const Mesh &m)
Adds a copy of the mesh to the object.
std::vector< unsigned int > indexVec
indexes of the vertices (start at 0) defining faces
unsigned int NumFaces()
Computes the number of faces.
void ApplyTransform(const Transform &trans)
Apply Transformation to all vertices.
static float sizeOfNormals
Size of normals for rendering (in world coordinates).
void SetVertex(unsigned int index, const Point4D &newValue)
Changes one vertex.
void SetNormals(const std::vector< Point4D > &normalVec)
Sets the vector of normals.
const Point4D & GetCenter() const
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.
std::vector< double > vertCoordVec
Vector of all vertex coordinates (their coordinates in sequence).
std::vector< Point4D > normVec
Vector of all normals.
static void ReadVerticesLine(std::istringstream &input, std::list< VertexTriplet > *resultPtr)
void SetXYZW(double x, double y, double z, double w)
Header file for V-ART class "MeshObject".
void Optimize()
Optimize object for display.
std::vector< Point4D > vertVec
Vector of all vertices.
static bool ReadFromOBJ(const std::string &filename, std::list< MeshObject * > *resultPtr)
Read MeshObjects from a Wavefront OBJ file.
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).
void MergeWith(const MeshObject &obj)
Merges one mesh object with another.
virtual VART::SceneNode * Copy()
Returns a copy of an MeshObject. Every derived class must reimplements this method, to avoid errors with VART::SceneNode::RecursiveCopy.
void ComputeVertexNormals()
Computes the normal of every vertex.
double GetGreaterX() const
double GetSmallerZ() const
Graphical object made of polygon meshes.
MeshObject & operator=(const MeshObject &obj)
bool LoadFromFile(const std::string &fileName)
Loads a texture from a file.