/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see . *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Author$ *
* $Date$ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS FastMeshNode - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include "OBJNode.hh"
#include "../GL/gl.hh"
#include
//== NAMESPACES ===============================================================
namespace ACG {
namespace SceneGraph {
//== IMPLEMENTATION ==========================================================
void
OBJNode::
boundingBox(Vec3f& _bbMin, Vec3f& _bbMax)
{
for(unsigned int i=0; i vIdx, tIdx;
int component(0), nV(0);
bool endOfVertex(false);
char *p0, *p1(s+2);
vIdx.clear();
tIdx.clear();
while(p1)
{
p0 = p1;
// overwrite next separator
if (p1)
{
while (*p1 != '/' && *p1 != '\r' && *p1 != '\n' &&
*p1 != ' ' && *p1 != '\0')
p1++;
// detect end of vertex
if (*p1 != '/') endOfVertex = true;
// replace separator by '\0'
if (*p1 != '\0')
{
*p1 = '\0';
p1++; // point to next token
}
// detect end of line and break
if (*p1 == '\0' || *p1 == '\n')
p1 = 0;
}
if (*p0 != '\0')
{
switch (component)
{
case 0: vIdx.push_back(atoi(p0)-1); break;
case 1: tIdx.push_back(atoi(p0)-1); break;
case 2: /* ignore vertex normals */ break;
}
component++;
if (endOfVertex)
{
component = 0;
nV++;
endOfVertex = false;
}
}
}
if (vIdx.size() >= 3)
{
// texture
if (vIdx.size() == tIdx.size())
{
for (unsigned int i1=1, i2=2; i2 < vIdx.size(); ++i1, ++i2)
faces_.push_back(Face(vIdx[0], vIdx[i1], vIdx[i2],
tIdx[0], tIdx[i1], tIdx[i2]));
}
// no texture
else
{
for (unsigned int i1=1, i2=2; i2 < vIdx.size(); ++i1, ++i2)
{
faces_.push_back(Face(vIdx[0], vIdx[i1], vIdx[i2]));
}
}
}
}
s[0]=' ';
}
fclose(in);
update_face_normals();
return true;
}
//----------------------------------------------------------------------------
void
OBJNode::update_face_normals()
{
normals_.clear();
normals_.reserve(faces_.size());
std::vector::const_iterator f_it(faces_.begin()), f_end(faces_.end());
for (; f_it!=f_end; ++f_it)
{
const Vec3f& v0(vertex(f_it->i0));
const Vec3f& v1(vertex(f_it->i1));
const Vec3f& v2(vertex(f_it->i2));
normals_.push_back(((v1-v0) % (v2-v0)).normalize());
}
}
//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================