Fix VRML V2 parser bug. (fixes lp:1417217)
* Add support for VRML DEF coordinate key word. * Coding policy fixes by Blair Bonnett <blair.bonnett@gmail.com> * Debugging output clean up.
This commit is contained in:
parent
1e2af7fed1
commit
d819a38075
|
@ -2,7 +2,7 @@
|
|||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2014 Mario Luzeiro <mrluzeiro@gmail.com>
|
||||
* Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -59,6 +59,7 @@ S3D_MESH::~S3D_MESH()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void S3D_MESH::openGL_RenderAllChilds()
|
||||
{
|
||||
//DBG( printf( "openGL_RenderAllChilds") );
|
||||
|
@ -82,7 +83,6 @@ void S3D_MESH::openGL_RenderAllChilds()
|
|||
SetOpenGlDefaultMaterial();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -94,15 +94,10 @@ void S3D_MESH::openGL_Render()
|
|||
&& g_Parm_3D_Visu.GetFlag( FL_RENDER_SMOOTH );
|
||||
|
||||
if( m_Materials )
|
||||
{
|
||||
m_Materials->SetOpenGLMaterial( 0, useMaterial );
|
||||
}
|
||||
|
||||
if( m_CoordIndex.size() == 0)
|
||||
{
|
||||
|
||||
if( m_CoordIndex.size() == 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef( m_translation.x, m_translation.y, m_translation.z );
|
||||
|
@ -117,27 +112,29 @@ void S3D_MESH::openGL_Render()
|
|||
if( m_PerVertexNormalsNormalized.size() == 0 )
|
||||
{
|
||||
if( smoothShapes )
|
||||
{
|
||||
calcPerPointNormals();
|
||||
}
|
||||
}
|
||||
|
||||
for( unsigned int idx = 0; idx < m_CoordIndex.size(); idx++ )
|
||||
{
|
||||
if( m_MaterialIndex.size() > 1 )
|
||||
{
|
||||
if( m_Materials )
|
||||
{
|
||||
m_Materials->SetOpenGLMaterial( m_MaterialIndex[idx], useMaterial );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch( m_CoordIndex[idx].size() )
|
||||
{
|
||||
case 3: glBegin( GL_TRIANGLES );break;
|
||||
case 4: glBegin( GL_QUADS ); break;
|
||||
default: glBegin( GL_POLYGON ); break;
|
||||
case 3:
|
||||
glBegin( GL_TRIANGLES );
|
||||
break;
|
||||
case 4:
|
||||
glBegin( GL_QUADS );
|
||||
break;
|
||||
default:
|
||||
glBegin( GL_POLYGON );
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
@ -187,34 +184,36 @@ void S3D_MESH::openGL_Render()
|
|||
}
|
||||
|
||||
|
||||
void S3D_MESH::calcPointNormalized ()
|
||||
void S3D_MESH::calcPointNormalized()
|
||||
{
|
||||
//DBG( printf( "calcPointNormalized\n" ) );
|
||||
|
||||
if( isPointNormalizedComputed == true )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isPointNormalizedComputed = true;
|
||||
|
||||
if( m_PerVertexNormalsNormalized.size() > 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_PointNormalized.clear();
|
||||
|
||||
float biggerPoint = 0.0f;
|
||||
for( unsigned int i = 0; i< m_Point.size(); i++ )
|
||||
{
|
||||
if( fabs( m_Point[i].x ) > biggerPoint) biggerPoint = fabs( m_Point[i].x );
|
||||
if( fabs( m_Point[i].y ) > biggerPoint) biggerPoint = fabs( m_Point[i].y );
|
||||
if( fabs( m_Point[i].z ) > biggerPoint) biggerPoint = fabs( m_Point[i].z );
|
||||
if( fabs( m_Point[i].x ) > biggerPoint )
|
||||
biggerPoint = fabs( m_Point[i].x );
|
||||
|
||||
if( fabs( m_Point[i].y ) > biggerPoint )
|
||||
biggerPoint = fabs( m_Point[i].y );
|
||||
|
||||
if( fabs( m_Point[i].z ) > biggerPoint )
|
||||
biggerPoint = fabs( m_Point[i].z );
|
||||
}
|
||||
|
||||
biggerPoint = 1.0 / biggerPoint;
|
||||
|
||||
for( unsigned int i= 0; i< m_Point.size(); i++ )
|
||||
for( unsigned int i = 0; i < m_Point.size(); i++ )
|
||||
{
|
||||
glm::vec3 p;
|
||||
p = m_Point[i] * biggerPoint;
|
||||
|
@ -237,30 +236,22 @@ bool IsClockwise( glm::vec3 v0, glm::vec3 v1, glm::vec3 v2 )
|
|||
}
|
||||
|
||||
|
||||
void S3D_MESH::calcPerFaceNormals ()
|
||||
void S3D_MESH::calcPerFaceNormals()
|
||||
{
|
||||
//DBG( printf( "calcPerFaceNormals" ) );
|
||||
|
||||
if( isPerFaceNormalsComputed == true )
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
isPerFaceNormalsComputed = true;
|
||||
|
||||
|
||||
if( m_PerVertexNormalsNormalized.size() > 0 )
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool haveAlreadyNormals_from_model_file = false;
|
||||
|
||||
if( m_PerFaceNormalsNormalized.size() > 0 )
|
||||
{
|
||||
haveAlreadyNormals_from_model_file = true;
|
||||
}
|
||||
|
||||
m_PerFaceNormalsRaw.clear();
|
||||
m_PerFaceSquaredArea.clear();
|
||||
|
@ -268,9 +259,15 @@ void S3D_MESH::calcPerFaceNormals ()
|
|||
//DBG( printf("m_CoordIndex.size %u\n", m_CoordIndex.size()) );
|
||||
//DBG( printf("m_PointNormalized.size %u\n", m_PointNormalized.size()) );
|
||||
|
||||
// There are no points defined for the coordIndex
|
||||
if( m_PointNormalized.size() == 0 )
|
||||
{
|
||||
m_CoordIndex.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
for( unsigned int idx = 0; idx < m_CoordIndex.size(); idx++ )
|
||||
{
|
||||
|
||||
// User normalized and multiply to get better resolution
|
||||
glm::vec3 v0 = m_PointNormalized[m_CoordIndex[idx][0]];
|
||||
glm::vec3 v1 = m_PointNormalized[m_CoordIndex[idx][1]];
|
||||
|
@ -300,14 +297,10 @@ void S3D_MESH::calcPerFaceNormals ()
|
|||
float area = glm::dot( cross_prod, cross_prod );
|
||||
|
||||
if( cross_prod[2] < 0.0 )
|
||||
{
|
||||
area = -area;
|
||||
}
|
||||
|
||||
if( area < FLT_EPSILON )
|
||||
{
|
||||
area = FLT_EPSILON * 2.0f;
|
||||
}
|
||||
|
||||
m_PerFaceSquaredArea.push_back( area );
|
||||
|
||||
|
@ -315,7 +308,6 @@ void S3D_MESH::calcPerFaceNormals ()
|
|||
|
||||
if( haveAlreadyNormals_from_model_file == false )
|
||||
{
|
||||
|
||||
// normalize vertex normal
|
||||
float l = glm::length( cross_prod );
|
||||
|
||||
|
@ -328,39 +320,43 @@ void S3D_MESH::calcPerFaceNormals ()
|
|||
// Cannot calc normal
|
||||
if( ( cross_prod.x > cross_prod.y ) && ( cross_prod.x > cross_prod.z ) )
|
||||
{
|
||||
cross_prod.x = 1.0; cross_prod.y = 0.0; cross_prod.z = 0.0;
|
||||
} else if( ( cross_prod.y > cross_prod.x ) && ( cross_prod.y > cross_prod.z ))
|
||||
cross_prod.x = 1.0;
|
||||
cross_prod.y = 0.0;
|
||||
cross_prod.z = 0.0;
|
||||
}
|
||||
else if( ( cross_prod.y > cross_prod.x ) && ( cross_prod.y > cross_prod.z ) )
|
||||
{
|
||||
cross_prod.x = 0.0; cross_prod.y = 1.0; cross_prod.z = 0.0;
|
||||
} else
|
||||
cross_prod.x = 0.0;
|
||||
cross_prod.y = 1.0;
|
||||
cross_prod.z = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cross_prod.x = 0.0; cross_prod.y = 1.0; cross_prod.z = 0.0;
|
||||
cross_prod.x = 0.0;
|
||||
cross_prod.y = 0.0;
|
||||
cross_prod.z = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
m_PerFaceNormalsNormalized.push_back( cross_prod );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// http://www.bytehazard.com/code/vertnorm.html
|
||||
// http://www.emeyex.com/site/tuts/VertexNormals.pdf
|
||||
void S3D_MESH::calcPerPointNormals ()
|
||||
void S3D_MESH::calcPerPointNormals()
|
||||
{
|
||||
//DBG( printf( "calcPerPointNormals" ) );
|
||||
|
||||
if( isPerPointNormalsComputed == true )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isPerPointNormalsComputed = true;
|
||||
|
||||
if( m_PerVertexNormalsNormalized.size() > 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_PerFaceVertexNormals.clear();
|
||||
|
||||
|
@ -371,6 +367,7 @@ void S3D_MESH::calcPerPointNormals ()
|
|||
#ifdef USE_OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif /* USE_OPENMP */
|
||||
|
||||
for( unsigned int each_face_A_idx = 0; each_face_A_idx < m_CoordIndex.size(); each_face_A_idx++ )
|
||||
{
|
||||
// n = face A facet normal
|
||||
|
@ -390,15 +387,16 @@ void S3D_MESH::calcPerPointNormals ()
|
|||
for( unsigned int each_face_B_idx = 0; each_face_B_idx < m_CoordIndex.size(); each_face_B_idx++ )
|
||||
{
|
||||
//if A != B { // ignore self
|
||||
if ( each_face_A_idx != each_face_B_idx)
|
||||
if( each_face_A_idx != each_face_B_idx )
|
||||
{
|
||||
if( (m_CoordIndex[each_face_B_idx][0] == vertexIndex) ||
|
||||
(m_CoordIndex[each_face_B_idx][1] == vertexIndex) ||
|
||||
(m_CoordIndex[each_face_B_idx][2] == vertexIndex) )
|
||||
if( (m_CoordIndex[each_face_B_idx][0] == vertexIndex)
|
||||
|| (m_CoordIndex[each_face_B_idx][1] == vertexIndex)
|
||||
|| (m_CoordIndex[each_face_B_idx][2] == vertexIndex) )
|
||||
{
|
||||
glm::vec3 vector_face_B = m_PerFaceNormalsNormalized[each_face_B_idx];
|
||||
|
||||
float dot_prod = glm::dot(vector_face_A, vector_face_B);
|
||||
float dot_prod = glm::dot( vector_face_A, vector_face_B );
|
||||
|
||||
if( dot_prod > 0.05f )
|
||||
{
|
||||
face_A_normals[each_vert_A_idx] += m_PerFaceNormalsRaw[each_face_B_idx] * (m_PerFaceSquaredArea[each_face_B_idx] * dot_prod);
|
||||
|
@ -411,10 +409,7 @@ void S3D_MESH::calcPerPointNormals ()
|
|||
float l = glm::length( face_A_normals[each_vert_A_idx] );
|
||||
|
||||
if( l > FLT_EPSILON ) // avoid division by zero
|
||||
{
|
||||
face_A_normals[each_vert_A_idx] /= l;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2013 Tuomas Vaherkoski <tuomasvaherkoski@gmail.com>
|
||||
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -45,7 +45,7 @@ class X3D_MODEL_PARSER;
|
|||
class S3D_MODEL_PARSER
|
||||
{
|
||||
public:
|
||||
S3D_MODEL_PARSER(S3D_MASTER* aMaster) :
|
||||
S3D_MODEL_PARSER( S3D_MASTER* aMaster ) :
|
||||
master( aMaster )
|
||||
{}
|
||||
|
||||
|
@ -126,8 +126,8 @@ public:
|
|||
|
||||
private:
|
||||
wxString m_Filename;
|
||||
S3D_MESH *m_model;
|
||||
std::vector<S3D_MESH *> childs;
|
||||
S3D_MESH* m_model;
|
||||
std::vector< S3D_MESH* > childs;
|
||||
|
||||
std::vector< wxString > vrml_materials;
|
||||
std::vector< wxString > vrml_points;
|
||||
|
@ -142,6 +142,7 @@ private:
|
|||
};
|
||||
|
||||
|
||||
typedef std::map< std::string, std::vector< glm::vec3 > > VRML2_COORDINATE_MAP;
|
||||
|
||||
/**
|
||||
* class VRML2_MODEL_PARSER
|
||||
|
@ -165,25 +166,30 @@ public:
|
|||
private:
|
||||
int read_Transform();
|
||||
int read_DEF();
|
||||
int read_DEF_Coordinate();
|
||||
int read_Shape();
|
||||
int read_Appearance();
|
||||
int read_material();
|
||||
int read_Material();
|
||||
int read_IndexedFaceSet();
|
||||
int read_IndexedLineSet();
|
||||
int read_Coordinate();
|
||||
int read_CoordinateDef();
|
||||
int read_Normal();
|
||||
int read_NormalIndex();
|
||||
int read_Color();
|
||||
int read_coordIndex();
|
||||
int read_colorIndex();
|
||||
int read_USE();
|
||||
|
||||
bool m_normalPerVertex;
|
||||
bool colorPerVertex;
|
||||
S3D_MESH *m_model;
|
||||
std::vector<S3D_MESH *> childs;
|
||||
FILE *m_file;
|
||||
S3D_MATERIAL *m_Materials;
|
||||
S3D_MESH* m_model;
|
||||
std::vector< S3D_MESH* > childs;
|
||||
FILE* m_file;
|
||||
S3D_MATERIAL* m_Materials;
|
||||
wxString m_Filename;
|
||||
VRML2_COORDINATE_MAP m_defCoordinateMap;
|
||||
};
|
||||
|
||||
|
||||
|
@ -226,10 +232,10 @@ private:
|
|||
|
||||
bool m_normalPerVertex;
|
||||
bool colorPerVertex;
|
||||
S3D_MESH *m_model;
|
||||
std::vector<S3D_MESH *> childs;
|
||||
S3D_MATERIAL *m_Materials;
|
||||
FILE *m_file;
|
||||
S3D_MESH* m_model;
|
||||
std::vector< S3D_MESH* > childs;
|
||||
S3D_MATERIAL* m_Materials;
|
||||
FILE* m_file;
|
||||
wxString m_Filename;
|
||||
};
|
||||
|
||||
|
@ -246,8 +252,8 @@ public:
|
|||
void Load( const wxString& aFilename, double aVrmlunits_to_3Dunits );
|
||||
|
||||
private:
|
||||
VRML1_MODEL_PARSER *vrml1_parser;
|
||||
VRML2_MODEL_PARSER *vrml2_parser;
|
||||
VRML1_MODEL_PARSER* vrml1_parser;
|
||||
VRML2_MODEL_PARSER* vrml2_parser;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* Copyright (C) 2013 Tuomas Vaherkoski <tuomasvaherkoski@gmail.com>
|
||||
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras@wanadoo.fr
|
||||
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
||||
* Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -39,6 +39,16 @@
|
|||
#include "modelparsers.h"
|
||||
#include "vrml_aux.h"
|
||||
|
||||
|
||||
/**
|
||||
* Trace mask used to enable or disable the trace output of the VRML V2 parser code.
|
||||
* The debug output can be turned on by setting the WXTRACE environment variable to
|
||||
* "KI_TRACE_VRML_V2_PARSER". See the wxWidgets documentation on wxLogTrace for
|
||||
* more information.
|
||||
*/
|
||||
static const wxChar* traceVrmlV2Parser = wxT( "KI_TRACE_VRML_V2_PARSER" );
|
||||
|
||||
|
||||
VRML2_MODEL_PARSER::VRML2_MODEL_PARSER( S3D_MASTER* aMaster ) :
|
||||
S3D_MODEL_PARSER( aMaster )
|
||||
{
|
||||
|
@ -59,7 +69,7 @@ void VRML2_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3
|
|||
{
|
||||
char text[128];
|
||||
|
||||
// DBG( printf( "Load %s\n", GetChars(aFilename) ) );
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( "Load %s" ), GetChars( aFilename ) );
|
||||
m_file = wxFopen( aFilename, wxT( "rt" ) );
|
||||
|
||||
if( m_file == NULL )
|
||||
|
@ -117,9 +127,6 @@ void VRML2_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3
|
|||
|
||||
fclose( m_file );
|
||||
|
||||
|
||||
// DBG( printf( "chils size:%lu\n", childs.size() ) );
|
||||
|
||||
if( GetMaster()->IsOpenGlAllowed() )
|
||||
{
|
||||
for( unsigned int idx = 0; idx < childs.size(); idx++ )
|
||||
|
@ -134,8 +141,6 @@ int VRML2_MODEL_PARSER::read_Transform()
|
|||
{
|
||||
char text[128];
|
||||
|
||||
// DBG( printf( "Transform\n" ) );
|
||||
|
||||
while( GetNextTag( m_file, text ) )
|
||||
{
|
||||
if( *text == ']' )
|
||||
|
@ -145,7 +150,6 @@ int VRML2_MODEL_PARSER::read_Transform()
|
|||
|
||||
if( *text == '}' )
|
||||
{
|
||||
// DBG( printf( " } Exit Transform\n" ) );
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -239,7 +243,7 @@ int VRML2_MODEL_PARSER::read_Transform()
|
|||
}
|
||||
else
|
||||
{
|
||||
// DBG( printf( " %s NotImplemented\n", text ) );
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( " %s NotImplemented" ), text );
|
||||
read_NotImplemented( m_file, '}' );
|
||||
}
|
||||
}
|
||||
|
@ -248,24 +252,56 @@ int VRML2_MODEL_PARSER::read_Transform()
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read the DEF for a Coordinate
|
||||
*/
|
||||
int VRML2_MODEL_PARSER::read_DEF_Coordinate()
|
||||
{
|
||||
char text[128];
|
||||
|
||||
// Get the name of the definition.
|
||||
GetNextTag( m_file, text );
|
||||
std::string coordinateName = text;
|
||||
|
||||
while( GetNextTag( m_file, text ) )
|
||||
{
|
||||
if( ( text == NULL ) || ( *text == ']' ) )
|
||||
continue;
|
||||
|
||||
if( ( *text == '}' ) )
|
||||
return 0;
|
||||
|
||||
if( strcmp( text, "Coordinate" ) == 0 )
|
||||
{
|
||||
int retVal = read_CoordinateDef();
|
||||
|
||||
if( retVal == 0 )
|
||||
m_defCoordinateMap.insert( std::make_pair( coordinateName, m_model->m_Point ) );
|
||||
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int VRML2_MODEL_PARSER::read_DEF()
|
||||
{
|
||||
char text[128];
|
||||
|
||||
GetNextTag( m_file, text );
|
||||
// DBG( printf( "DEF %s ", text ) );
|
||||
|
||||
while( GetNextTag( m_file, text ) )
|
||||
{
|
||||
if( *text == ']' )
|
||||
{
|
||||
// DBG( printf( " skiping %c\n", *text) );
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( " skipping %c" ), *text );
|
||||
continue;
|
||||
}
|
||||
|
||||
if( *text == '}' )
|
||||
{
|
||||
// DBG( printf( " } Exit DEF\n") );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -301,17 +337,40 @@ int VRML2_MODEL_PARSER::read_DEF()
|
|||
}
|
||||
}
|
||||
|
||||
// DBG( printf( " DEF failed\n" ) );
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( " DEF failed" ) );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int VRML2_MODEL_PARSER::read_USE()
|
||||
{
|
||||
char text[128];
|
||||
|
||||
// Get the name of the definition.
|
||||
GetNextTag( m_file, text );
|
||||
std::string coordinateName = text;
|
||||
|
||||
// Look for it in our coordinate map.
|
||||
VRML2_COORDINATE_MAP::iterator coordinate;
|
||||
coordinate = m_defCoordinateMap.find( coordinateName );
|
||||
|
||||
// Not previously defined.
|
||||
if( coordinate == m_defCoordinateMap.end() )
|
||||
{
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( "USE: coordinate %s not previously defined "
|
||||
"in a DEF section." ), text );
|
||||
return -1;
|
||||
}
|
||||
|
||||
m_model->m_Point = coordinate->second;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int VRML2_MODEL_PARSER::read_Shape()
|
||||
{
|
||||
char text[128];
|
||||
|
||||
// DBG( printf( " Shape\n") );
|
||||
|
||||
while( GetNextTag( m_file, text ) )
|
||||
{
|
||||
if( *text == ']' )
|
||||
|
@ -321,12 +380,12 @@ int VRML2_MODEL_PARSER::read_Shape()
|
|||
|
||||
if( *text == '}' )
|
||||
{
|
||||
// DBG( printf( " } Exit Shape\n") );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( strcmp( text, "appearance" ) == 0 )
|
||||
{
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( "\"appearance\" key word not supported." ) );
|
||||
// skip
|
||||
}
|
||||
else if( strcmp( text, "Appearance" ) == 0 )
|
||||
|
@ -335,20 +394,25 @@ int VRML2_MODEL_PARSER::read_Shape()
|
|||
}
|
||||
else if( strcmp( text, "geometry" ) == 0 )
|
||||
{
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( "\"geometry\" key word not supported." ) );
|
||||
// skip
|
||||
}
|
||||
else if( strcmp( text, "IndexedFaceSet" ) == 0 )
|
||||
{
|
||||
read_IndexedFaceSet();
|
||||
}
|
||||
else if( strcmp( text, "IndexedLineSet" ) == 0 )
|
||||
{
|
||||
read_IndexedLineSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
// DBG( printf( " %s NotImplemented\n", text ) );
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( " %s NotImplemented" ), text );
|
||||
read_NotImplemented( m_file, '}' );
|
||||
}
|
||||
}
|
||||
|
||||
// DBG( printf( " Shape failed\n" ) );
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( " Shape failed" ) );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -357,8 +421,6 @@ int VRML2_MODEL_PARSER::read_Appearance()
|
|||
{
|
||||
char text[128];
|
||||
|
||||
// DBG( printf( " Appearance\n") );
|
||||
|
||||
while( GetNextTag( m_file, text ) )
|
||||
{
|
||||
if( *text == ']' )
|
||||
|
@ -377,7 +439,7 @@ int VRML2_MODEL_PARSER::read_Appearance()
|
|||
}
|
||||
}
|
||||
|
||||
// DBG( printf( " Appearance failed\n" ) );
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( " Appearance failed" ) );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -387,8 +449,6 @@ int VRML2_MODEL_PARSER::read_material()
|
|||
S3D_MATERIAL* material = NULL;
|
||||
char text[128];
|
||||
|
||||
// DBG( printf( " material ") );
|
||||
|
||||
if( GetNextTag( m_file, text ) )
|
||||
{
|
||||
if( strcmp( text, "Material" ) == 0 )
|
||||
|
@ -405,12 +465,8 @@ int VRML2_MODEL_PARSER::read_material()
|
|||
}
|
||||
else if( strcmp( text, "DEF" ) == 0 )
|
||||
{
|
||||
// DBG( printf( "DEF") );
|
||||
|
||||
if( GetNextTag( m_file, text ) )
|
||||
{
|
||||
// DBG( printf( "%s", text ) );
|
||||
|
||||
wxString mat_name;
|
||||
mat_name = FROM_UTF8( text );
|
||||
|
||||
|
@ -429,12 +485,8 @@ int VRML2_MODEL_PARSER::read_material()
|
|||
}
|
||||
else if( strcmp( text, "USE" ) == 0 )
|
||||
{
|
||||
// DBG( printf( "USE") );
|
||||
|
||||
if( GetNextTag( m_file, text ) )
|
||||
{
|
||||
// DBG( printf( "%s\n", text ) );
|
||||
|
||||
wxString mat_name;
|
||||
mat_name = FROM_UTF8( text );
|
||||
|
||||
|
@ -447,12 +499,12 @@ int VRML2_MODEL_PARSER::read_material()
|
|||
}
|
||||
}
|
||||
|
||||
DBG( printf( " read_material error: material not found\n" ) );
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( " read_material error: material not found" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DBG( printf( " failed material\n" ) );
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( " failed material" ) );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -462,8 +514,6 @@ int VRML2_MODEL_PARSER::read_Material()
|
|||
char text[128];
|
||||
glm::vec3 vertex;
|
||||
|
||||
// DBG( printf( " Material\n") );
|
||||
|
||||
while( GetNextTag( m_file, text ) )
|
||||
{
|
||||
if( *text == ']' )
|
||||
|
@ -478,17 +528,13 @@ int VRML2_MODEL_PARSER::read_Material()
|
|||
|
||||
if( strcmp( text, "diffuseColor" ) == 0 )
|
||||
{
|
||||
// DBG( printf( " diffuseColor") );
|
||||
parseVertex( m_file, vertex );
|
||||
// DBG( printf( "\n") );
|
||||
m_model->m_Materials->m_DiffuseColor.push_back( vertex );
|
||||
}
|
||||
else if( strcmp( text, "emissiveColor" ) == 0 )
|
||||
{
|
||||
// DBG( printf( " emissiveColor") );
|
||||
parseVertex( m_file, vertex );
|
||||
|
||||
// DBG( printf( "\n") );
|
||||
if( GetMaster()->m_use_modelfile_emissiveColor == true )
|
||||
{
|
||||
m_model->m_Materials->m_EmissiveColor.push_back( vertex );
|
||||
|
@ -496,9 +542,7 @@ int VRML2_MODEL_PARSER::read_Material()
|
|||
}
|
||||
else if( strcmp( text, "specularColor" ) == 0 )
|
||||
{
|
||||
// DBG( printf( " specularColor") );
|
||||
parseVertex( m_file, vertex );
|
||||
// DBG( printf( "\n") );
|
||||
|
||||
if( GetMaster()->m_use_modelfile_specularColor == true )
|
||||
{
|
||||
|
@ -509,7 +553,6 @@ int VRML2_MODEL_PARSER::read_Material()
|
|||
{
|
||||
float ambientIntensity;
|
||||
parseFloat( m_file, &ambientIntensity );
|
||||
// DBG( printf( " ambientIntensity %f\n", ambientIntensity) );
|
||||
|
||||
if( GetMaster()->m_use_modelfile_ambientIntensity == true )
|
||||
{
|
||||
|
@ -521,7 +564,6 @@ int VRML2_MODEL_PARSER::read_Material()
|
|||
{
|
||||
float transparency;
|
||||
parseFloat( m_file, &transparency );
|
||||
// DBG( printf( " transparency %f\n", transparency) );
|
||||
|
||||
if( GetMaster()->m_use_modelfile_transparency == true )
|
||||
{
|
||||
|
@ -533,7 +575,6 @@ int VRML2_MODEL_PARSER::read_Material()
|
|||
float shininess;
|
||||
parseFloat( m_file, &shininess );
|
||||
|
||||
// DBG( printf( " shininess %f\n", shininess) );
|
||||
// VRML value is normalized and openGL expects a value 0 - 128
|
||||
if( GetMaster()->m_use_modelfile_shininess == true )
|
||||
{
|
||||
|
@ -543,7 +584,7 @@ int VRML2_MODEL_PARSER::read_Material()
|
|||
}
|
||||
}
|
||||
|
||||
// DBG( printf( " Material failed\n" ) );
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( " Material failed\n" ) );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -552,8 +593,6 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet()
|
|||
{
|
||||
char text[128];
|
||||
|
||||
// DBG( printf( " IndexedFaceSet\n") );
|
||||
|
||||
m_normalPerVertex = false;
|
||||
colorPerVertex = false;
|
||||
|
||||
|
@ -566,7 +605,6 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet()
|
|||
|
||||
if( *text == '}' )
|
||||
{
|
||||
// DBG( printf( " } Exit IndexedFaceSet\n") );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -576,7 +614,6 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet()
|
|||
{
|
||||
if( strcmp( text, "TRUE" ) == 0 )
|
||||
{
|
||||
// DBG( printf( " m_normalPerVertex TRUE\n") );
|
||||
m_normalPerVertex = true;
|
||||
}
|
||||
}
|
||||
|
@ -587,7 +624,6 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet()
|
|||
|
||||
if( strcmp( text, "TRUE" ) )
|
||||
{
|
||||
// DBG( printf( " colorPerVertex = true\n") );
|
||||
colorPerVertex = true;
|
||||
}
|
||||
else
|
||||
|
@ -619,17 +655,43 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet()
|
|||
{
|
||||
read_colorIndex();
|
||||
}
|
||||
else if( strcmp( text, "USE" ) == 0 )
|
||||
{
|
||||
read_USE();
|
||||
}
|
||||
}
|
||||
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( " IndexedFaceSet failed %s" ), text );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int VRML2_MODEL_PARSER::read_IndexedLineSet()
|
||||
{
|
||||
char text[128];
|
||||
|
||||
while( GetNextTag( m_file, text ) )
|
||||
{
|
||||
if( ( text == NULL ) || ( *text == ']' ) )
|
||||
continue;
|
||||
|
||||
if( ( *text == '}' ) )
|
||||
return 0;
|
||||
|
||||
if( strcmp( text, "Coordinate" ) == 0 )
|
||||
read_Coordinate();
|
||||
else if( strcmp( text, "coordIndex" ) == 0 )
|
||||
read_coordIndex();
|
||||
else if( strcmp( text, "DEF" ) == 0 )
|
||||
read_DEF_Coordinate();
|
||||
}
|
||||
|
||||
// DBG( printf( " IndexedFaceSet failed %s\n", text ) );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int VRML2_MODEL_PARSER::read_colorIndex()
|
||||
{
|
||||
// DBG( printf( " read_colorIndex\n" ) );
|
||||
|
||||
m_model->m_MaterialIndex.clear();
|
||||
|
||||
if( colorPerVertex == true )
|
||||
|
@ -660,16 +722,12 @@ int VRML2_MODEL_PARSER::read_colorIndex()
|
|||
}
|
||||
}
|
||||
|
||||
// DBG( printf( " m_MaterialIndex.size: %ld\n", m_model->m_MaterialIndex.size() ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int VRML2_MODEL_PARSER::read_NormalIndex()
|
||||
{
|
||||
// DBG( printf( " read_NormalIndex\n" ) );
|
||||
|
||||
m_model->m_NormalIndex.clear();
|
||||
|
||||
glm::ivec3 coord;
|
||||
|
@ -684,26 +742,20 @@ int VRML2_MODEL_PARSER::read_NormalIndex()
|
|||
if( dummy == -1 )
|
||||
{
|
||||
m_model->m_NormalIndex.push_back( coord_list );
|
||||
// DBG( printf( " size: %lu ", coord_list.size()) );
|
||||
coord_list.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
coord_list.push_back( dummy );
|
||||
// DBG( printf( "%d ", dummy) );
|
||||
}
|
||||
}
|
||||
|
||||
// DBG( printf( " m_NormalIndex.size: %ld\n", m_model->m_NormalIndex.size() ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int VRML2_MODEL_PARSER::read_coordIndex()
|
||||
{
|
||||
// DBG( printf( " read_coordIndex\n" ) );
|
||||
|
||||
m_model->m_CoordIndex.clear();
|
||||
|
||||
glm::ivec3 coord;
|
||||
|
@ -718,18 +770,14 @@ int VRML2_MODEL_PARSER::read_coordIndex()
|
|||
if( dummy == -1 )
|
||||
{
|
||||
m_model->m_CoordIndex.push_back( coord_list );
|
||||
// DBG( printf( " size: %lu ", coord_list.size()) );
|
||||
coord_list.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
coord_list.push_back( dummy );
|
||||
// DBG( printf( "%d ", dummy) );
|
||||
}
|
||||
}
|
||||
|
||||
// DBG( printf( " m_CoordIndex.size: %ld\n", m_model->m_CoordIndex.size() ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -738,8 +786,6 @@ int VRML2_MODEL_PARSER::read_Color()
|
|||
{
|
||||
char text[128];
|
||||
|
||||
// DBG( printf( " read_Color\n") );
|
||||
|
||||
while( GetNextTag( m_file, text ) )
|
||||
{
|
||||
if( *text == ']' )
|
||||
|
@ -749,7 +795,6 @@ int VRML2_MODEL_PARSER::read_Color()
|
|||
|
||||
if( *text == '}' )
|
||||
{
|
||||
// DBG( printf( " m_DiffuseColor.size: %ld\n", m_model->m_Materials->m_DiffuseColor.size() ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -759,7 +804,7 @@ int VRML2_MODEL_PARSER::read_Color()
|
|||
}
|
||||
}
|
||||
|
||||
// DBG( printf( " read_Color failed\n") );
|
||||
wxLogTrace( traceVrmlV2Parser, wxT( " read_Color failed" ) );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -768,8 +813,6 @@ int VRML2_MODEL_PARSER::read_Normal()
|
|||
{
|
||||
char text[128];
|
||||
|
||||
// DBG( printf( " Normal\n") );
|
||||
|
||||
while( GetNextTag( m_file, text ) )
|
||||
{
|
||||
if( *text == ']' )
|
||||
|
@ -779,7 +822,6 @@ int VRML2_MODEL_PARSER::read_Normal()
|
|||
|
||||
if( *text == '}' )
|
||||
{
|
||||
// DBG( printf( " m_PerFaceNormalsNormalized.size: %lu\n", m_model->m_PerFaceNormalsNormalized.size() ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -792,8 +834,6 @@ int VRML2_MODEL_PARSER::read_Normal()
|
|||
else
|
||||
{
|
||||
parseVertexList( m_file, m_model->m_PerVertexNormalsNormalized );
|
||||
|
||||
// DBG( printf( " m_PerVertexNormalsNormalized.size: %lu\n", m_model->m_PerVertexNormalsNormalized.size() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -806,8 +846,6 @@ int VRML2_MODEL_PARSER::read_Coordinate()
|
|||
{
|
||||
char text[128];
|
||||
|
||||
// DBG( printf( " Coordinate\n") );
|
||||
|
||||
while( GetNextTag( m_file, text ) )
|
||||
{
|
||||
if( *text == ']' )
|
||||
|
@ -817,7 +855,6 @@ int VRML2_MODEL_PARSER::read_Coordinate()
|
|||
|
||||
if( *text == '}' )
|
||||
{
|
||||
// DBG( printf( " m_Point.size: %lu\n", m_model->m_Point.size() ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -829,3 +866,26 @@ int VRML2_MODEL_PARSER::read_Coordinate()
|
|||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read the point of the Coordinate for a DEF
|
||||
*/
|
||||
int VRML2_MODEL_PARSER::read_CoordinateDef()
|
||||
{
|
||||
char text[128];
|
||||
|
||||
while( GetNextTag( m_file, text ) )
|
||||
{
|
||||
if( ( text == NULL ) || ( *text == ']' ) )
|
||||
continue;
|
||||
|
||||
if( ( *text == '}' ) )
|
||||
return 0;
|
||||
|
||||
if( strcmp( text, "point" ) == 0 )
|
||||
parseVertexList( m_file, m_model->m_Point );
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue