NFF spheres are working now.
Added additional NFF test model. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@128 67173fc5-114c-0410-ac8e-9d2fd5bffc1fpull/1/head
parent
96f2b0b536
commit
1a55e7e8f1
|
@ -90,14 +90,15 @@ bool NFFImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler) const
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
bool GetNextLine(const char*& buffer, char out[4096])
|
||||
{
|
||||
if ('\0' == *buffer)return false;
|
||||
|
||||
char* _out = out;
|
||||
char* const end = _out+4096;
|
||||
while (!IsLineEnd( *buffer ) && _out < end)
|
||||
*_out++ = *buffer++;
|
||||
*_out = '\0';
|
||||
|
||||
if ('\0' == *buffer)return false;
|
||||
while (IsLineEnd( *buffer ))++buffer;
|
||||
if ('\0' != *buffer)while (IsLineEnd( *buffer ))++buffer;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -150,6 +151,9 @@ void NFFImporter::InternReadFile( const std::string& pFile,
|
|||
|
||||
ShadingInfo s; // current material info
|
||||
|
||||
// degree of tesselation
|
||||
unsigned int iTesselation = 4;
|
||||
|
||||
char line[4096];
|
||||
const char* sz;
|
||||
unsigned int sphere = 0,cylinder = 0,cone = 0,numNamed = 0;
|
||||
|
@ -182,25 +186,26 @@ void NFFImporter::InternReadFile( const std::string& pFile,
|
|||
SkipSpaces(sz,&sz);
|
||||
m = strtol10(sz);
|
||||
|
||||
out->faces.push_back(m);
|
||||
out->vertices.reserve(out->vertices.size()+m);
|
||||
for (unsigned int n = 0; n < m;++n)
|
||||
{
|
||||
if(!GetNextLine(buffer,line))
|
||||
{
|
||||
DefaultLogger::get()->error("NFF: Unexpected EOF was encountered");
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
aiVector3D v; sz = &line[0];
|
||||
AI_NFF_PARSE_TRIPLE(v);
|
||||
out->vertices.push_back(v);
|
||||
|
||||
if (&meshesWithNormals.back() == out)
|
||||
if ('p' == line[1])
|
||||
{
|
||||
AI_NFF_PARSE_TRIPLE(v);
|
||||
out->normals.push_back(v);
|
||||
}
|
||||
}
|
||||
out->faces.push_back(m);
|
||||
}
|
||||
// 'f' - shading information block
|
||||
else if ('f' == line[0] && IsSpace(line[1]))
|
||||
|
@ -254,12 +259,18 @@ void NFFImporter::InternReadFile( const std::string& pFile,
|
|||
AI_NFF_PARSE_SHAPE_INFORMATION();
|
||||
|
||||
// generate the sphere - it consists of simple triangles
|
||||
StandardShapes::MakeSphere(aiVector3D(), radius, 500.0f, currentMesh.vertices);
|
||||
currentMesh.faces.resize(currentMesh.vertices.size(),3);
|
||||
StandardShapes::MakeSphere(aiVector3D(), radius, iTesselation, currentMesh.vertices);
|
||||
currentMesh.faces.resize(currentMesh.vertices.size()/3,3);
|
||||
|
||||
// generate a name for the mesh
|
||||
::sprintf(currentMesh.name,"sphere_%i",sphere++);
|
||||
}
|
||||
// 'tess' - tesselation
|
||||
else if (!strncmp(line,"tess",4) && IsSpace(line[4]))
|
||||
{
|
||||
sz = &line[5];SkipSpaces(&sz);
|
||||
iTesselation = strtol10(sz);
|
||||
}
|
||||
// 'c' - cone
|
||||
else if ('c' == line[0] && IsSpace(line[1]))
|
||||
{
|
||||
|
@ -280,8 +291,8 @@ void NFFImporter::InternReadFile( const std::string& pFile,
|
|||
center1 = -center2;
|
||||
|
||||
// generate the cone - it consists of simple triangles
|
||||
StandardShapes::MakeCone(center1, radius1, center2, radius2, 500.0f, currentMesh.vertices);
|
||||
currentMesh.faces.resize(currentMesh.vertices.size(),3);
|
||||
StandardShapes::MakeCone(center1, radius1, center2, radius2, iTesselation, currentMesh.vertices);
|
||||
currentMesh.faces.resize(currentMesh.vertices.size()/3,3);
|
||||
|
||||
// generate a name for the mesh
|
||||
if (radius1 != radius2)
|
||||
|
@ -384,7 +395,9 @@ void NFFImporter::InternReadFile( const std::string& pFile,
|
|||
|
||||
// generate a material for the mesh
|
||||
MaterialHelper* pcMat = (MaterialHelper*)(pScene->
|
||||
mMaterials[m++] = new MaterialHelper());
|
||||
mMaterials[m] = new MaterialHelper());
|
||||
|
||||
mesh->mMaterialIndex = m++;
|
||||
|
||||
aiString s;
|
||||
s.Set(AI_DEFAULT_MATERIAL_NAME);
|
||||
|
|
Binary file not shown.
|
@ -69,14 +69,33 @@ public:
|
|||
std::vector<aiVector3D>& positions);
|
||||
|
||||
|
||||
/** @brief Generates a dodecahedron
|
||||
*
|
||||
* @param center Center point of the dodecahedron
|
||||
* @param length Face length of the dodecahedron
|
||||
* @param positions Receives output triangles.
|
||||
*/
|
||||
static void MakeDodecahedron(aiVector3D& center,float length,
|
||||
std::vector<aiVector3D>& positions);
|
||||
|
||||
/** @brief Generates an octahedron
|
||||
*
|
||||
* @param center Center point of the octahedron
|
||||
* @param length Face length of the octahedron
|
||||
* @param positions Receives output triangles.
|
||||
*/
|
||||
static void MakeOctahedron(aiVector3D& center,float length,
|
||||
std::vector<aiVector3D>& positions);
|
||||
|
||||
|
||||
/** @brief Generates a sphere
|
||||
*
|
||||
* @param center Center point of the sphere
|
||||
* @param radius Radius of the sphere
|
||||
* @param tess Number of triangles in the equator line of the sphere
|
||||
* @param tess Number of subdivions - 0 generates a octahedron
|
||||
* @param positions Receives output triangles.
|
||||
*/
|
||||
static void MakeSphere(aiVector3D& center,float radius,float tess,
|
||||
static void MakeSphere(aiVector3D& center,float radius,unsigned int tess,
|
||||
std::vector<aiVector3D>& positions);
|
||||
|
||||
/** @brief Generates a cone or a cylinder, either opened or closed.
|
||||
|
@ -100,12 +119,12 @@ public:
|
|||
* @param radius1 First radius
|
||||
* @param center2 Second center point
|
||||
* @param radius2 Second radius
|
||||
* @param tess Number of triangles per circle
|
||||
* @param tess Number of subdivisions
|
||||
* @param bOpened true for an open cone/cylinder.
|
||||
* @param positions Receives output triangles.
|
||||
*/
|
||||
static void MakeCone(aiVector3D& center1,float radius1,
|
||||
aiVector3D& center2,float radius2,float tess,
|
||||
aiVector3D& center2,float radius2,unsigned int tess,
|
||||
std::vector<aiVector3D>& positions,bool bOpened = false);
|
||||
|
||||
/** @brief Generates a flat circle
|
||||
|
@ -115,11 +134,11 @@ public:
|
|||
* @param normal Normal vector of the circle.
|
||||
* This is also the normal vector of all triangles generated by
|
||||
* this function.
|
||||
* @param tess Number of triangles
|
||||
* @param tess Number of triangles
|
||||
* @param positions Receives output triangles.
|
||||
*/
|
||||
static void MakeCircle(aiVector3D& center, aiVector3D& normal,
|
||||
float radius, float tess,
|
||||
float radius, unsigned int tess,
|
||||
std::vector<aiVector3D>& positions);
|
||||
|
||||
};
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
# a centered sphere
|
||||
s 0 0 0 5
|
||||
|
||||
# a polgyon that should not be visible
|
||||
p 4
|
||||
5 0 0
|
||||
0 -5 0
|
||||
-5 0 0
|
||||
0 5 0
|
|
@ -2,7 +2,7 @@
|
|||
#default color
|
||||
|
||||
# A simple sphere
|
||||
s 5.0 5.0 5.0 10.0
|
||||
s 5.0 5.0 5.0 3.0
|
||||
|
||||
#blue
|
||||
f 0.0 0.0 1.0 0 1 1
|
||||
|
|
Loading…
Reference in New Issue