Commit cb91e095 authored by Wayne Stambaugh's avatar Wayne Stambaugh

Coding policy fixes and comment out debugging output.

parent 5f70ec63
......@@ -28,65 +28,63 @@
#include "vrml_aux.h"
char SkipGetChar ( FILE* File )
char SkipGetChar( FILE* File )
{
char c;
bool re_parse;
char c;
bool re_parse;
if( (c = fgetc( File )) == EOF )
if( ( c = fgetc( File ) ) == EOF )
{
//DBG( printf( "EOF\n" ) );
// DBG( printf( "EOF\n" ) );
return EOF;
}
//DBG( printf( "c %c 0x%02X\n", c, c ) );
// DBG( printf( "c %c 0x%02X\n", c, c ) );
do
{
re_parse = false;
if ((c == ' ') || (c == '\t') || (c == '{') || (c == '['))
if( (c == ' ') || (c == '\t') || (c == '{') || (c == '[') )
{
//DBG( printf( "Skipping space \\t or { or [\n" ) );
// DBG( printf( "Skipping space \\t or { or [\n" ) );
do
{
if( (c = fgetc( File )) == EOF )
if( ( c = fgetc( File ) ) == EOF )
{
//DBG( printf( "EOF\n" ) );
// DBG( printf( "EOF\n" ) );
return EOF;
}
}
while((c == ' ') || (c == '\t') || (c == '{') || (c == '['));
} while( (c == ' ') || (c == '\t') || (c == '{') || (c == '[') );
}
if ((c == '#') || (c == '\n') || (c == '\r') || (c == 0) || (c == ','))
if( (c == '#') || (c == '\n') || (c == '\r') || (c == 0) || (c == ',') )
{
if (c == '#')
if( c == '#' )
{
//DBG( printf( "Skipping # \\n or \\r or 0, 0x%02X\n", c ) );
// DBG( printf( "Skipping # \\n or \\r or 0, 0x%02X\n", c ) );
do
{
if( (c = fgetc( File )) == EOF )
if( ( c = fgetc( File ) ) == EOF )
{
//DBG( printf( "EOF\n" ) );
// DBG( printf( "EOF\n" ) );
return EOF;
}
}
while((c != '\n') && (c != '\r') && (c != 0) && (c != ','));
} while( (c != '\n') && (c != '\r') && (c != 0) && (c != ',') );
}
else
{
if( (c = fgetc( File )) == EOF )
if( ( c = fgetc( File ) ) == EOF )
{
//DBG( printf( "EOF\n" ) );
// DBG( printf( "EOF\n" ) );
return EOF;
}
}
re_parse = true;
}
}while(re_parse == true);
} while( re_parse == true );
return c;
}
......@@ -94,35 +92,38 @@ char SkipGetChar ( FILE* File )
char* GetNextTag( FILE* File, char* tag )
{
char c = SkipGetChar( File );
if (c == EOF)
if( c == EOF )
{
return NULL;
}
tag[0] = c;
tag[1] = 0;
//DBG( printf( "tag[0] %c\n", tag[0] ) );
tag[0] = c;
tag[1] = 0;
// DBG( printf( "tag[0] %c\n", tag[0] ) );
if( (c != '}') && (c != ']') )
{
char *dst = &tag[1];
while( fscanf( File, "%c", dst) )
char* dst = &tag[1];
while( fscanf( File, "%c", dst ) )
{
if( (*dst == ' ') || (*dst == '[') || (*dst == '{') ||
(*dst == '\t') || (*dst == '\n')|| (*dst == '\r') )
if( (*dst == ' ') || (*dst == '[') || (*dst == '{')
|| (*dst == '\t') || (*dst == '\n')|| (*dst == '\r') )
{
*dst = 0;
break;
}
dst++;
}
//DBG( printf( "tag %s\n", tag ) );
// DBG( printf( "tag %s\n", tag ) );
c = SkipGetChar( File );
if (c != EOF)
if( c != EOF )
{
// Puts again the read char in the buffer
ungetc( c, File );
......@@ -133,40 +134,44 @@ char* GetNextTag( FILE* File, char* tag )
}
int read_NotImplemented( FILE* File, char closeChar)
int read_NotImplemented( FILE* File, char closeChar )
{
char c;
//DBG( printf( "look for %c\n", closeChar) );
while( (c = fgetc( File )) != EOF )
// DBG( printf( "look for %c\n", closeChar) );
while( ( c = fgetc( File ) ) != EOF )
{
if( c == '{' )
{
//DBG( printf( "{\n") );
// DBG( printf( "{\n") );
read_NotImplemented( File, '}' );
} else if( c == '[' )
}
else if( c == '[' )
{
//DBG( printf( "[\n") );
// DBG( printf( "[\n") );
read_NotImplemented( File, ']' );
} else if( c == closeChar )
}
else if( c == closeChar )
{
//DBG( printf( "%c\n", closeChar) );
// DBG( printf( "%c\n", closeChar) );
return 0;
}
}
DBG( printf( " NotImplemented failed\n" ) );
// DBG( printf( " NotImplemented failed\n" ) );
return -1;
}
int parseVertexList( FILE* File, std::vector< glm::vec3 > &dst_vector)
int parseVertexList( FILE* File, std::vector<glm::vec3>& dst_vector )
{
//DBG( printf( " parseVertexList\n" ) );
// DBG( printf( " parseVertexList\n" ) );
dst_vector.clear();
glm::vec3 vertex;
while( parseVertex ( File, vertex ) == 3 )
while( parseVertex( File, vertex ) == 3 )
{
dst_vector.push_back( vertex );
}
......@@ -175,32 +180,34 @@ int parseVertexList( FILE* File, std::vector< glm::vec3 > &dst_vector)
}
int parseVertex( FILE* File, glm::vec3 &dst_vertex )
int parseVertex( FILE* File, glm::vec3& dst_vertex )
{
float a,b,c;
int ret = fscanf( File, "%e %e %e", &a, &b, &c );
float a, b, c;
int ret = fscanf( File, "%e %e %e", &a, &b, &c );
dst_vertex.x = a;
dst_vertex.y = b;
dst_vertex.z = c;
dst_vertex.x = a;
dst_vertex.y = b;
dst_vertex.z = c;
char s = SkipGetChar( File );
if (s != EOF)
if( s != EOF )
{
// Puts again the read char in the buffer
ungetc( s, File );
}
//DBG( printf( "ret%d(%.9f,%.9f,%.9f)", ret, a,b,c) );
// DBG( printf( "ret%d(%.9f,%.9f,%.9f)", ret, a,b,c) );
return ret;
}
int parseFloat( FILE* File, float *dst_float )
int parseFloat( FILE* File, float* dst_float )
{
float value;
int ret = fscanf( File, "%e", &value );
float value;
int ret = fscanf( File, "%e", &value );
*dst_float = value;
return ret;
......
......@@ -40,7 +40,7 @@ VRML1_MODEL_PARSER::VRML1_MODEL_PARSER( S3D_MASTER* aMaster ) :
S3D_MODEL_PARSER( aMaster )
{
m_model = NULL;
m_file = NULL;
m_file = NULL;
}
......@@ -48,16 +48,16 @@ VRML1_MODEL_PARSER::~VRML1_MODEL_PARSER()
{
for( unsigned int idx = 0; idx < childs.size(); idx++ )
{
delete childs[idx];
delete childs[idx];
}
}
void VRML1_MODEL_PARSER::Load( const wxString aFilename )
{
char text[128];
char text[128];
//DBG( printf( "Load %s\n", static_cast<const char*>(aFilename.mb_str()) ) );
// DBG( printf( "Load %s\n", static_cast<const char*>(aFilename.mb_str()) ) );
m_file = wxFopen( aFilename, wxT( "rt" ) );
if( m_file == NULL )
......@@ -71,19 +71,22 @@ void VRML1_MODEL_PARSER::Load( const wxString aFilename )
float vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
glScalef( vrmlunits_to_3Dunits, vrmlunits_to_3Dunits, vrmlunits_to_3Dunits );
glm::vec3 matScale( GetMaster()->m_MatScale.x, GetMaster()->m_MatScale.y, GetMaster()->m_MatScale.z );
glm::vec3 matRot( GetMaster()->m_MatRotation.x, GetMaster()->m_MatRotation.y, GetMaster()->m_MatRotation.z );
glm::vec3 matPos( GetMaster()->m_MatPosition.x, GetMaster()->m_MatPosition.y, GetMaster()->m_MatPosition.z );
glm::vec3 matScale( GetMaster()->m_MatScale.x, GetMaster()->m_MatScale.y,
GetMaster()->m_MatScale.z );
glm::vec3 matRot( GetMaster()->m_MatRotation.x, GetMaster()->m_MatRotation.y,
GetMaster()->m_MatRotation.z );
glm::vec3 matPos( GetMaster()->m_MatPosition.x, GetMaster()->m_MatPosition.y,
GetMaster()->m_MatPosition.z );
#define SCALE_3D_CONV ((IU_PER_MILS * 1000.0f) / UNITS3D_TO_UNITSPCB)
#define SCALE_3D_CONV ( (IU_PER_MILS * 1000.0f) / UNITS3D_TO_UNITSPCB )
//glPushMatrix();
// glPushMatrix();
glTranslatef( matPos.x * SCALE_3D_CONV, matPos.y * SCALE_3D_CONV, matPos.z * SCALE_3D_CONV );
glRotatef(-matRot.z, 0.0f, 0.0f, 1.0f );
glRotatef(-matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef(-matRot.x, 1.0f, 0.0f, 0.0f );
glRotatef( -matRot.z, 0.0f, 0.0f, 1.0f );
glRotatef( -matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef( -matRot.x, 1.0f, 0.0f, 0.0f );
glScalef( matScale.x, matScale.y, matScale.z );
......@@ -94,8 +97,7 @@ void VRML1_MODEL_PARSER::Load( const wxString aFilename )
while( GetNextTag( m_file, text ) )
{
if ( ( text == NULL ) || ( *text == '}' ) || ( *text == ']' ) )
if( ( text == NULL ) || ( *text == '}' ) || ( *text == ']' ) )
{
continue;
}
......@@ -112,7 +114,7 @@ void VRML1_MODEL_PARSER::Load( const wxString aFilename )
SetLocaleTo_Default(); // revert to the current locale
//DBG( printf( "chils size:%lu\n", childs.size() ) );
// DBG( printf( "chils size:%lu\n", childs.size() ) );
if( GetMaster()->IsOpenGlAllowed() )
{
......@@ -123,18 +125,18 @@ void VRML1_MODEL_PARSER::Load( const wxString aFilename )
}
}
int VRML1_MODEL_PARSER::read_separator()
{
char text[128];
char text[128];
//DBG( printf( "Separator\n" ) );
// DBG( printf( "Separator\n" ) );
while( GetNextTag( m_file, text) )
while( GetNextTag( m_file, text ) )
{
if( strcmp( text, "Material" ) == 0 )
{
readMaterial( );
readMaterial();
}
else if( strcmp( text, "Coordinate3" ) == 0 )
{
......@@ -146,9 +148,9 @@ int VRML1_MODEL_PARSER::read_separator()
}
else if( strcmp( text, "Separator" ) == 0 )
{
S3D_MESH *parent = m_model;
S3D_MESH* parent = m_model;
S3D_MESH *new_mesh_model = new S3D_MESH();
S3D_MESH* new_mesh_model = new S3D_MESH();
m_model->childs.push_back( new_mesh_model );
......@@ -159,10 +161,10 @@ int VRML1_MODEL_PARSER::read_separator()
m_model = parent;
}
else if ( ( *text != '}' ) )
else if( ( *text != '}' ) )
{
//DBG( printf( "read_NotImplemented %s\n", text ) );
read_NotImplemented( m_file, '}');
// DBG( printf( "read_NotImplemented %s\n", text ) );
read_NotImplemented( m_file, '}' );
}
else
{
......@@ -176,12 +178,12 @@ int VRML1_MODEL_PARSER::read_separator()
int VRML1_MODEL_PARSER::readMaterial()
{
char text[128];
char text[128];
S3D_MATERIAL* material = NULL;
//DBG( printf( " readMaterial\n" ) );
// DBG( printf( " readMaterial\n" ) );
wxString mat_name;
wxString mat_name;
material = new S3D_MATERIAL( GetMaster(), mat_name );
......@@ -191,12 +193,12 @@ int VRML1_MODEL_PARSER::readMaterial()
while( GetNextTag( m_file, text ) )
{
if ( ( text == NULL ) || ( *text == ']' ) )
if( ( text == NULL ) || ( *text == ']' ) )
{
continue;
}
if ( ( *text == '}' ) )
if( ( *text == '}' ) )
{
return 0;
}
......@@ -207,23 +209,23 @@ int VRML1_MODEL_PARSER::readMaterial()
}
else if( strcmp( text, "diffuseColor" ) == 0 )
{
readMaterial_diffuseColor( );
readMaterial_diffuseColor();
}
else if( strcmp( text, "emissiveColor" ) == 0 )
{
readMaterial_emissiveColor( );
readMaterial_emissiveColor();
}
else if( strcmp( text, "specularColor" ) == 0 )
{
readMaterial_specularColor( );
readMaterial_specularColor();
}
else if( strcmp( text, "shininess" ) == 0 )
{
readMaterial_shininess( );
readMaterial_shininess();
}
else if( strcmp( text, "transparency" ) == 0 )
{
readMaterial_transparency( );
readMaterial_transparency();
}
}
......@@ -231,27 +233,27 @@ int VRML1_MODEL_PARSER::readMaterial()
}
int VRML1_MODEL_PARSER::readCoordinate3( )
int VRML1_MODEL_PARSER::readCoordinate3()
{
char text[128];
char text[128];
//DBG( printf( " readCoordinate3\n" ) );
// DBG( printf( " readCoordinate3\n" ) );
while( GetNextTag( m_file, text ) )
{
if ( ( text == NULL ) || ( *text == ']' ) )
if( ( text == NULL ) || ( *text == ']' ) )
{
continue;
}
if ( ( *text == '}' ) )
if( ( *text == '}' ) )
{
return 0;
}
if( strcmp( text, "point" ) == 0 )
{
readCoordinate3_point( );
readCoordinate3_point();
}
}
......@@ -259,60 +261,61 @@ int VRML1_MODEL_PARSER::readCoordinate3( )
}
int VRML1_MODEL_PARSER::readIndexedFaceSet( )
int VRML1_MODEL_PARSER::readIndexedFaceSet()
{
char text[128];
char text[128];
//DBG( printf( " readIndexedFaceSet\n" ) );
// DBG( printf( " readIndexedFaceSet\n" ) );
while( GetNextTag( m_file, text ) )
{
if ( ( text == NULL ) || ( *text == ']' ) )
if( ( text == NULL ) || ( *text == ']' ) )
{
continue;
}
if ( ( *text == '}' ) )
if( ( *text == '}' ) )
{
return 0;
}
if( strcmp( text, "coordIndex" ) == 0 )
{
readIndexedFaceSet_coordIndex( );
readIndexedFaceSet_coordIndex();
}
else if( strcmp( text, "materialIndex" ) == 0 )
{
readIndexedFaceSet_materialIndex( );
readIndexedFaceSet_materialIndex();
}
}
return -1;
}
int VRML1_MODEL_PARSER::readMaterial_ambientColor( )
int VRML1_MODEL_PARSER::readMaterial_ambientColor()
{
//DBG( printf( " readMaterial_ambientColor\n" ) );
// DBG( printf( " readMaterial_ambientColor\n" ) );
return parseVertexList( m_file, m_model->m_Materials->m_AmbientColor);
return parseVertexList( m_file, m_model->m_Materials->m_AmbientColor );
}
int VRML1_MODEL_PARSER::readMaterial_diffuseColor( )
int VRML1_MODEL_PARSER::readMaterial_diffuseColor()
{
//DBG( printf( " readMaterial_diffuseColor\n" ) );
// DBG( printf( " readMaterial_diffuseColor\n" ) );
return parseVertexList( m_file, m_model->m_Materials->m_DiffuseColor);
return parseVertexList( m_file, m_model->m_Materials->m_DiffuseColor );
}
int VRML1_MODEL_PARSER::readMaterial_emissiveColor( )
int VRML1_MODEL_PARSER::readMaterial_emissiveColor()
{
//DBG( printf( " readMaterial_emissiveColor\n" ) );
// DBG( printf( " readMaterial_emissiveColor\n" ) );
int ret = parseVertexList( m_file, m_model->m_Materials->m_EmissiveColor);
int ret = parseVertexList( m_file, m_model->m_Materials->m_EmissiveColor );
if( GetMaster()->m_use_modelfile_emissiveColor == false)
if( GetMaster()->m_use_modelfile_emissiveColor == false )
{
m_model->m_Materials->m_EmissiveColor.clear();
}
......@@ -323,11 +326,11 @@ int VRML1_MODEL_PARSER::readMaterial_emissiveColor( )
int VRML1_MODEL_PARSER::readMaterial_specularColor()
{
//DBG( printf( " readMaterial_specularColor\n" ) );
// DBG( printf( " readMaterial_specularColor\n" ) );
int ret = parseVertexList( m_file, m_model->m_Materials->m_SpecularColor );
if( GetMaster()->m_use_modelfile_specularColor == false)
if( GetMaster()->m_use_modelfile_specularColor == false )
{
m_model->m_Materials->m_SpecularColor.clear();
}
......@@ -336,9 +339,9 @@ int VRML1_MODEL_PARSER::readMaterial_specularColor()
}
int VRML1_MODEL_PARSER::readMaterial_shininess( )
int VRML1_MODEL_PARSER::readMaterial_shininess()
{
//DBG( printf( " readMaterial_shininess\n" ) );
// DBG( printf( " readMaterial_shininess\n" ) );
m_model->m_Materials->m_Shininess.clear();
......@@ -356,7 +359,7 @@ int VRML1_MODEL_PARSER::readMaterial_shininess( )
m_model->m_Materials->m_Shininess.clear();
}
//DBG( printf( " m_Shininess.size: %ld\n", m_model->m_Materials->m_Shininess.size() ) );
// DBG( printf( " m_Shininess.size: %ld\n", m_model->m_Materials->m_Shininess.size() ) );
return 0;
}
......@@ -364,13 +367,13 @@ int VRML1_MODEL_PARSER::readMaterial_shininess( )
int VRML1_MODEL_PARSER::readMaterial_transparency()
{
//DBG( printf( " readMaterial_transparency\n" ) );
// DBG( printf( " readMaterial_transparency\n" ) );
m_model->m_Materials->m_Transparency.clear();
float tmp;
while( fscanf (m_file, "%f,", &tmp) )
while( fscanf( m_file, "%f,", &tmp ) )
{
m_model->m_Materials->m_Transparency.push_back( tmp );
}
......@@ -380,7 +383,7 @@ int VRML1_MODEL_PARSER::readMaterial_transparency()
m_model->m_Materials->m_Transparency.clear();
}
//DBG( printf( " m_Transparency.size: %ld\n", m_model->m_Materials->m_Transparency.size() ) );
// DBG( printf( " m_Transparency.size: %ld\n", m_model->m_Materials->m_Transparency.size() ) );
return 0;
}
......@@ -388,7 +391,7 @@ int VRML1_MODEL_PARSER::readMaterial_transparency()
int VRML1_MODEL_PARSER::readCoordinate3_point()
{
//DBG( printf( " readCoordinate3_point\n" ) );
// DBG( printf( " readCoordinate3_point\n" ) );
if( parseVertexList( m_file, m_model->m_Point ) == 0 )
{
......@@ -401,13 +404,14 @@ int VRML1_MODEL_PARSER::readCoordinate3_point()
int VRML1_MODEL_PARSER::readIndexedFaceSet_coordIndex()
{
//DBG( printf( " readIndexedFaceSet_coordIndex\n" ) );
// DBG( printf( " readIndexedFaceSet_coordIndex\n" ) );
m_model->m_CoordIndex.clear();
glm::ivec3 coord;
int dummy; // should be -1
int dummy; // should be -1
while( fscanf( m_file, "%d,%d,%d,%d,", &coord[0], &coord[1], &coord[2], &dummy ) )
{
std::vector<int> coord_list;
......@@ -417,21 +421,22 @@ int VRML1_MODEL_PARSER::readIndexedFaceSet_coordIndex()
coord_list[1] = coord[1];
coord_list[2] = coord[2];
if( (coord[0] == coord[1]) ||
(coord[0] == coord[2]) ||
(coord[2] == coord[1]) )
if( (coord[0] == coord[1])
|| (coord[0] == coord[2])
|| (coord[2] == coord[1]) )
{
//DBG( printf( " invalid coordIndex at index %lu (%d, %d, %d, %d)\n", m_model->m_CoordIndex.size()+1,coord[0], coord[1], coord[2], dummy ) );
// DBG( printf( " invalid coordIndex at index %lu (%d, %d, %d, %d)\n", m_model->m_CoordIndex.size()+1,coord[0], coord[1], coord[2], dummy ) );
}
if (dummy != -1)
if( dummy != -1 )
{
//DBG( printf( " Error at index %lu, -1 Expected, got %d\n", m_model->m_CoordIndex.size()+1, dummy ) );
// DBG( printf( " Error at index %lu, -1 Expected, got %d\n", m_model->m_CoordIndex.size()+1, dummy ) );
}
m_model->m_CoordIndex.push_back( coord_list );
}
//DBG( printf( " m_CoordIndex.size: %ld\n", m_model->m_CoordIndex.size() ) );
// DBG( printf( " m_CoordIndex.size: %ld\n", m_model->m_CoordIndex.size() ) );
return 0;
}
......@@ -439,17 +444,18 @@ int VRML1_MODEL_PARSER::readIndexedFaceSet_coordIndex()
int VRML1_MODEL_PARSER::readIndexedFaceSet_materialIndex()
{
//DBG( printf( " readIndexedFaceSet_materialIndex\n" ) );
// DBG( printf( " readIndexedFaceSet_materialIndex\n" ) );
m_model->m_MaterialIndex.clear();
int index;
while( fscanf( m_file, "%d,", &index ) )
{
m_model->m_MaterialIndex.push_back( index );
}
//DBG( printf( " m_MaterialIndex.size: %ld\n", m_model->m_MaterialIndex.size() ) );
// DBG( printf( " m_MaterialIndex.size: %ld\n", m_model->m_MaterialIndex.size() ) );
return 0;
}
......@@ -48,18 +48,18 @@ VRML2_MODEL_PARSER::VRML2_MODEL_PARSER( S3D_MASTER* aMaster ) :
VRML2_MODEL_PARSER::~VRML2_MODEL_PARSER()
{
for(unsigned int idx = 0; idx < childs.size(); idx++)
for( unsigned int idx = 0; idx < childs.size(); idx++ )
{
delete childs[idx];
delete childs[idx];
}
}
void VRML2_MODEL_PARSER::Load( const wxString aFilename )
{
char text[128];
char text[128];
//DBG( printf( "Load %s\n", static_cast<const char*>(aFilename.mb_str()) ) );
// DBG( printf( "Load %s\n", static_cast<const char*>(aFilename.mb_str()) ) );
m_file = wxFopen( aFilename, wxT( "rt" ) );
if( m_file == NULL )
......@@ -67,27 +67,27 @@ void VRML2_MODEL_PARSER::Load( const wxString aFilename )
return;
}
glShadeModel(GL_SMOOTH);
glEnable(GL_NORMALIZE);
glShadeModel( GL_SMOOTH );
glEnable( GL_NORMALIZE );
float vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
glScalef( vrmlunits_to_3Dunits, vrmlunits_to_3Dunits, vrmlunits_to_3Dunits );
glm::vec3 matScale( GetMaster()->m_MatScale.x, GetMaster()->m_MatScale.y,
GetMaster()->m_MatScale.z );
GetMaster()->m_MatScale.z );
glm::vec3 matRot( GetMaster()->m_MatRotation.x, GetMaster()->m_MatRotation.y,
GetMaster()->m_MatRotation.z );
GetMaster()->m_MatRotation.z );
glm::vec3 matPos( GetMaster()->m_MatPosition.x, GetMaster()->m_MatPosition.y,
GetMaster()->m_MatPosition.z );
GetMaster()->m_MatPosition.z );
#define SCALE_3D_CONV ((IU_PER_MILS * 1000.0f) / UNITS3D_TO_UNITSPCB)
#define SCALE_3D_CONV ( (IU_PER_MILS * 1000.0f) / UNITS3D_TO_UNITSPCB )
glTranslatef( matPos.x * SCALE_3D_CONV, matPos.y * SCALE_3D_CONV, matPos.z * SCALE_3D_CONV );
glRotatef(-matRot.z, 0.0f, 0.0f, 1.0f );
glRotatef(-matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef(-matRot.x, 1.0f, 0.0f, 0.0f );
glRotatef( -matRot.z, 0.0f, 0.0f, 1.0f );
glRotatef( -matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef( -matRot.x, 1.0f, 0.0f, 0.0f );
glScalef( matScale.x, matScale.y, matScale.z );
......@@ -98,7 +98,6 @@ void VRML2_MODEL_PARSER::Load( const wxString aFilename )
while( GetNextTag( m_file, text ) )
{
if( ( text == NULL ) || ( *text == '}' ) || ( *text == ']' ) )
{
continue;
......@@ -110,7 +109,6 @@ void VRML2_MODEL_PARSER::Load( const wxString aFilename )
childs.push_back( m_model );
read_Transform();
}
else if( strcmp( text, "DEF" ) == 0 )
{
......@@ -125,7 +123,7 @@ void VRML2_MODEL_PARSER::Load( const wxString aFilename )
SetLocaleTo_Default(); // revert to the current locale
//DBG( printf( "chils size:%lu\n", childs.size() ) );
// DBG( printf( "chils size:%lu\n", childs.size() ) );
if( GetMaster()->IsOpenGlAllowed() )
{
......@@ -139,21 +137,23 @@ void VRML2_MODEL_PARSER::Load( const wxString aFilename )
int VRML2_MODEL_PARSER::read_Transform()
{
char text[128];
char text[128];
//DBG( printf( "Transform\n" ) );
// DBG( printf( "Transform\n" ) );
while( GetNextTag( m_file, text ) )
{
if ( ( text == NULL ) || ( *text == ']' ) )
if( ( text == NULL ) || ( *text == ']' ) )
{
continue;
}
if ( ( *text == '}' ) )
if( ( *text == '}' ) )
{
//DBG( printf( " } Exit Transform\n" ) );
// DBG( printf( " } Exit Transform\n" ) );
break;
}
if( strcmp( text, "translation" ) == 0 )
{
parseVertex( m_file, m_model->m_translation );
......@@ -161,19 +161,19 @@ int VRML2_MODEL_PARSER::read_Transform()
else if( strcmp( text, "rotation" ) == 0 )
{
if( fscanf( m_file, "%f %f %f %f", &m_model->m_rotation[0],
&m_model->m_rotation[1],
&m_model->m_rotation[2],
&m_model->m_rotation[3] ) != 4 )
&m_model->m_rotation[1],
&m_model->m_rotation[2],
&m_model->m_rotation[3] ) != 4 )
{
// !TODO: log errors
m_model->m_rotation[0] = 0.0f;
m_model->m_rotation[1] = 0.0f;
m_model->m_rotation[2] = 0.0f;
m_model->m_rotation[3] = 0.0f;
m_model->m_rotation[0] = 0.0f;
m_model->m_rotation[1] = 0.0f;
m_model->m_rotation[2] = 0.0f;
m_model->m_rotation[3] = 0.0f;
}
else
{
m_model->m_rotation[3] = m_model->m_rotation[3] * 180.0f / 3.14f; // !TODO: use constants or functions
m_model->m_rotation[3] = m_model->m_rotation[3] * 180.0f / 3.14f; // !TODO: use constants or functions
}
}
else if( strcmp( text, "scale" ) == 0 )
......@@ -184,15 +184,15 @@ int VRML2_MODEL_PARSER::read_Transform()
{
// this m_scaleOrientation is not implemented, but it will be parsed
if( fscanf( m_file, "%f %f %f %f", &m_model->m_scaleOrientation[0],
&m_model->m_scaleOrientation[1],
&m_model->m_scaleOrientation[2],
&m_model->m_scaleOrientation[3] ) != 4 )
&m_model->m_scaleOrientation[1],
&m_model->m_scaleOrientation[2],
&m_model->m_scaleOrientation[3] ) != 4 )
{
// !TODO: log errors
m_model->m_scaleOrientation[0] = 0.0f;
m_model->m_scaleOrientation[1] = 0.0f;
m_model->m_scaleOrientation[2] = 0.0f;
m_model->m_scaleOrientation[3] = 0.0f;
m_model->m_scaleOrientation[0] = 0.0f;
m_model->m_scaleOrientation[1] = 0.0f;
m_model->m_scaleOrientation[2] = 0.0f;
m_model->m_scaleOrientation[3] = 0.0f;
}
}
else if( strcmp( text, "center" ) == 0 )
......@@ -210,6 +210,7 @@ int VRML2_MODEL_PARSER::read_Transform()
else if( strcmp( text, "whichChoice" ) == 0 )
{
int dummy;
if( fscanf( m_file, "%d", &dummy ) != 1 )
{
// !TODO: log errors
......@@ -225,9 +226,9 @@ int VRML2_MODEL_PARSER::read_Transform()
}
else if( strcmp( text, "Shape" ) == 0 )
{
S3D_MESH *parent = m_model;
S3D_MESH* parent = m_model;
S3D_MESH *new_mesh_model = new S3D_MESH();
S3D_MESH* new_mesh_model = new S3D_MESH();
m_model->childs.push_back( new_mesh_model );
......@@ -236,7 +237,6 @@ int VRML2_MODEL_PARSER::read_Transform()
read_Shape();
m_model = parent;
}
else if( strcmp( text, "DEF" ) == 0 )
{
......@@ -244,39 +244,41 @@ int VRML2_MODEL_PARSER::read_Transform()
}
else
{
DBG( printf( " %s NotImplemented\n", text ) );
// DBG( printf( " %s NotImplemented\n", text ) );
read_NotImplemented( m_file, '}' );
}
}
return 0;
}
int VRML2_MODEL_PARSER::read_DEF()
{
char text[128];
char text[128];
GetNextTag( m_file, text);
//DBG( printf( "DEF %s ", text ) );
GetNextTag( m_file, text );
// DBG( printf( "DEF %s ", text ) );
while( GetNextTag( m_file, text ) )
{
if( ( text == NULL ) || ( *text == ']' ) )
{
//DBG( printf( " skiping %c\n", *text) );
// DBG( printf( " skiping %c\n", *text) );
continue;
}
if( ( *text == '}' ) )
{
//DBG( printf( " } Exit DEF\n") );
// DBG( printf( " } Exit DEF\n") );
return 0;
}
if( strcmp( text, "Transform" ) == 0 )
{
return read_Transform ();
} else if( strcmp( text, "children" ) == 0 )
return read_Transform();
}
else if( strcmp( text, "children" ) == 0 )
{
// skip
}
......@@ -294,8 +296,8 @@ int VRML2_MODEL_PARSER::read_DEF()
}
else if( strcmp( text, "Shape" ) == 0 )
{
S3D_MESH *parent = m_model;
S3D_MESH *new_mesh_model = new S3D_MESH();
S3D_MESH* parent = m_model;
S3D_MESH* new_mesh_model = new S3D_MESH();
m_model->childs.push_back( new_mesh_model );
m_model = new_mesh_model;
......@@ -304,33 +306,33 @@ int VRML2_MODEL_PARSER::read_DEF()
}
}
DBG( printf( " DEF failed\n" ) );
// DBG( printf( " DEF failed\n" ) );
return -1;
}
int VRML2_MODEL_PARSER::read_Shape()
{
char text[128];
char text[128];
//DBG( printf( " Shape\n") );
// DBG( printf( " Shape\n") );
while( GetNextTag( m_file, text ) )
{
if ( ( text == NULL ) || ( *text == ']' ) )
if( ( text == NULL ) || ( *text == ']' ) )
{
continue;
}
if ( ( *text == '}' ) )
if( ( *text == '}' ) )
{
//DBG( printf( " } Exit Shape\n") );
// DBG( printf( " } Exit Shape\n") );
return 0;
}
if( strcmp( text, "appearance" ) == 0 )
{
//skip
// skip
}
else if( strcmp( text, "Appearance" ) == 0 )
{
......@@ -338,7 +340,7 @@ int VRML2_MODEL_PARSER::read_Shape()
}
else if( strcmp( text, "geometry" ) == 0 )
{
//skip
// skip
}
else if( strcmp( text, "IndexedFaceSet" ) == 0 )
{
......@@ -346,30 +348,30 @@ int VRML2_MODEL_PARSER::read_Shape()
}
else
{
DBG( printf( " %s NotImplemented\n", text ) );
// DBG( printf( " %s NotImplemented\n", text ) );
read_NotImplemented( m_file, '}' );
}
}
DBG( printf( " Shape failed\n") );
// DBG( printf( " Shape failed\n" ) );
return -1;
}
int VRML2_MODEL_PARSER::read_Appearance()
{
char text[128];
char text[128];
//DBG( printf( " Appearance\n") );
// DBG( printf( " Appearance\n") );
while( GetNextTag( m_file, text ) )
{
if ( ( text == NULL ) || ( *text == ']' ) )
if( ( text == NULL ) || ( *text == ']' ) )
{
continue;
}
if ( ( *text == '}' ) )
if( ( *text == '}' ) )
{
return 0;
}
......@@ -380,7 +382,7 @@ int VRML2_MODEL_PARSER::read_Appearance()
}
}
DBG( printf( " Appearance failed\n") );
// DBG( printf( " Appearance failed\n" ) );
return -1;
}
......@@ -388,15 +390,15 @@ int VRML2_MODEL_PARSER::read_Appearance()
int VRML2_MODEL_PARSER::read_material()
{
S3D_MATERIAL* material = NULL;
char text[128];
char text[128];
//DBG( printf( " material ") );
// DBG( printf( " material ") );
if( GetNextTag( m_file, text ) )
{
if( strcmp( text, "Material" ) == 0 )
{
wxString mat_name;
wxString mat_name;
material = new S3D_MATERIAL( GetMaster(), mat_name );
GetMaster()->Insert( material );
m_model->m_Materials = material;
......@@ -408,13 +410,13 @@ int VRML2_MODEL_PARSER::read_material()
}
else if( strcmp( text, "DEF" ) == 0 )
{
//DBG( printf( "DEF") );
// DBG( printf( "DEF") );
if( GetNextTag( m_file, text ) )
{
//DBG( printf( "%s", text ) );
// DBG( printf( "%s", text ) );
wxString mat_name;
wxString mat_name;
mat_name = FROM_UTF8( text );
material = new S3D_MATERIAL( GetMaster(), mat_name );
......@@ -432,13 +434,13 @@ int VRML2_MODEL_PARSER::read_material()
}
else if( strcmp( text, "USE" ) == 0 )
{
//DBG( printf( "USE") );
// DBG( printf( "USE") );
if( GetNextTag( m_file, text ) )
{
//DBG( printf( "%s\n", text ) );
// DBG( printf( "%s\n", text ) );
wxString mat_name;
wxString mat_name;
mat_name = FROM_UTF8( text );
for( material = GetMaster()->m_Materials; material; material = material->Next() )
......@@ -449,46 +451,49 @@ int VRML2_MODEL_PARSER::read_material()
return 0;
}
}
DBG( printf( " read_material error: material not found\n" ) );
}
}
}
DBG( printf( " failed material\n") );
// DBG( printf( " failed material\n" ) );
return -1;
}
int VRML2_MODEL_PARSER::read_Material()
{
char text[128];
char text[128];
glm::vec3 vertex;
//DBG( printf( " Material\n") );
// DBG( printf( " Material\n") );
while( GetNextTag( m_file, text ) )
{
if ( ( text == NULL ) || ( *text == ']' ) )
if( ( text == NULL ) || ( *text == ']' ) )
{
continue;
}
if ( ( *text == '}' ) )
if( ( *text == '}' ) )
{
return 0;
}
if( strcmp( text, "diffuseColor" ) == 0 )
{
//DBG( printf( " diffuseColor") );
parseVertex ( m_file, vertex);
//DBG( printf( "\n") );
// 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 )
}
else if( strcmp( text, "emissiveColor" ) == 0 )
{
//DBG( printf( " emissiveColor") );
parseVertex ( m_file, vertex);
//DBG( printf( "\n") );
// 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 +501,9 @@ int VRML2_MODEL_PARSER::read_Material()
}
else if( strcmp( text, "specularColor" ) == 0 )
{
//DBG( printf( " specularColor") );
parseVertex ( m_file, vertex);
//DBG( printf( "\n") );
// DBG( printf( " specularColor") );
parseVertex( m_file, vertex );
// DBG( printf( "\n") );
if( GetMaster()->m_use_modelfile_specularColor == true )
{
......@@ -509,18 +514,19 @@ int VRML2_MODEL_PARSER::read_Material()
{
float ambientIntensity;
parseFloat( m_file, &ambientIntensity );
//DBG( printf( " ambientIntensity %f\n", ambientIntensity) );
// DBG( printf( " ambientIntensity %f\n", ambientIntensity) );
if( GetMaster()->m_use_modelfile_ambientIntensity == true )
{
m_model->m_Materials->m_AmbientColor.push_back( glm::vec3( ambientIntensity, ambientIntensity, ambientIntensity ) );
m_model->m_Materials->m_AmbientColor.push_back( glm::vec3( ambientIntensity,
ambientIntensity, ambientIntensity ) );
}
}
else if( strcmp( text, "transparency" ) == 0 )
{
float transparency;
parseFloat( m_file, &transparency );
//DBG( printf( " transparency %f\n", transparency) );
// DBG( printf( " transparency %f\n", transparency) );
if( GetMaster()->m_use_modelfile_transparency == true )
{
......@@ -532,7 +538,7 @@ int VRML2_MODEL_PARSER::read_Material()
float shininess;
parseFloat( m_file, &shininess );
//DBG( printf( " shininess %f\n", 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 )
{
......@@ -542,30 +548,30 @@ int VRML2_MODEL_PARSER::read_Material()
}
}
DBG( printf( " Material failed\n") );
// DBG( printf( " Material failed\n" ) );
return -1;
}
int VRML2_MODEL_PARSER::read_IndexedFaceSet()
{
char text[128];
char text[128];
//DBG( printf( " IndexedFaceSet\n") );
// DBG( printf( " IndexedFaceSet\n") );
m_normalPerVertex = false;
colorPerVertex = false;
while( GetNextTag( m_file, text ) )
{
if ( ( text == NULL ) || ( *text == ']' ) )
if( ( text == NULL ) || ( *text == ']' ) )
{
continue;
}
if ( ( *text == '}' ) )
if( ( *text == '}' ) )
{
//DBG( printf( " } Exit IndexedFaceSet\n") );
// DBG( printf( " } Exit IndexedFaceSet\n") );
return 0;
}
......@@ -575,7 +581,7 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet()
{
if( strcmp( text, "TRUE" ) == 0 )
{
//DBG( printf( " m_normalPerVertex TRUE\n") );
// DBG( printf( " m_normalPerVertex TRUE\n") );
m_normalPerVertex = true;
}
}
......@@ -583,18 +589,18 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet()
else if( strcmp( text, "colorPerVertex" ) == 0 )
{
GetNextTag( m_file, text );
if( strcmp( text, "TRUE" ) )
{
//DBG( printf( " colorPerVertex = true\n") );
// DBG( printf( " colorPerVertex = true\n") );
colorPerVertex = true;
}
else
{
colorPerVertex = false;
}
}
else if( strcmp( text, "Coordinate" ) == 0 )
else if( strcmp( text, "Coordinate" ) == 0 )
{
read_Coordinate();
}
......@@ -618,17 +624,16 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet()
{
read_colorIndex();
}
}
DBG( printf( " IndexedFaceSet failed %s\n", text) );
// DBG( printf( " IndexedFaceSet failed %s\n", text ) );
return -1;
}
int VRML2_MODEL_PARSER::read_colorIndex()
{
//DBG( printf( " read_colorIndex\n" ) );
// DBG( printf( " read_colorIndex\n" ) );
m_model->m_MaterialIndex.clear();
......@@ -636,6 +641,7 @@ int VRML2_MODEL_PARSER::read_colorIndex()
{
int index;
int first_index;
while( fscanf( m_file, "%d, ", &index ) )
{
if( index == -1 )
......@@ -659,7 +665,7 @@ int VRML2_MODEL_PARSER::read_colorIndex()
}
}
//DBG( printf( " m_MaterialIndex.size: %ld\n", m_model->m_MaterialIndex.size() ) );
// DBG( printf( " m_MaterialIndex.size: %ld\n", m_model->m_MaterialIndex.size() ) );
return 0;
}
......@@ -667,32 +673,33 @@ int VRML2_MODEL_PARSER::read_colorIndex()
int VRML2_MODEL_PARSER::read_NormalIndex()
{
//DBG( printf( " read_NormalIndex\n" ) );
// DBG( printf( " read_NormalIndex\n" ) );
m_model->m_NormalIndex.clear();
glm::ivec3 coord;
int dummy; // should be -1
int dummy; // should be -1
std::vector<int> coord_list;
coord_list.clear();
while( fscanf (m_file, "%d, ", &dummy ) == 1 )
while( fscanf( m_file, "%d, ", &dummy ) == 1 )
{
if( dummy == -1 )
{
m_model->m_NormalIndex.push_back( coord_list );
//DBG( printf( " size: %lu ", coord_list.size()) );
// DBG( printf( " size: %lu ", coord_list.size()) );
coord_list.clear();
}
else
{
coord_list.push_back( dummy );
//DBG( printf( "%d ", dummy) );
// DBG( printf( "%d ", dummy) );
}
}
//DBG( printf( " m_NormalIndex.size: %ld\n", m_model->m_NormalIndex.size() ) );
// DBG( printf( " m_NormalIndex.size: %ld\n", m_model->m_NormalIndex.size() ) );
return 0;
}
......@@ -700,32 +707,33 @@ int VRML2_MODEL_PARSER::read_NormalIndex()
int VRML2_MODEL_PARSER::read_coordIndex()
{
//DBG( printf( " read_coordIndex\n" ) );
// DBG( printf( " read_coordIndex\n" ) );
m_model->m_CoordIndex.clear();
glm::ivec3 coord;
int dummy; // should be -1
int dummy; // should be -1
std::vector<int> coord_list;
coord_list.clear();
while( fscanf (m_file, "%d, ", &dummy ) == 1 )
while( fscanf( m_file, "%d, ", &dummy ) == 1 )
{
if( dummy == -1 )
{
m_model->m_CoordIndex.push_back( coord_list );
//DBG( printf( " size: %lu ", coord_list.size()) );
// DBG( printf( " size: %lu ", coord_list.size()) );
coord_list.clear();
}
else
{
coord_list.push_back( dummy );
//DBG( printf( "%d ", dummy) );
// DBG( printf( "%d ", dummy) );
}
}
//DBG( printf( " m_CoordIndex.size: %ld\n", m_model->m_CoordIndex.size() ) );
// DBG( printf( " m_CoordIndex.size: %ld\n", m_model->m_CoordIndex.size() ) );
return 0;
}
......@@ -733,20 +741,20 @@ int VRML2_MODEL_PARSER::read_coordIndex()
int VRML2_MODEL_PARSER::read_Color()
{
char text[128];
char text[128];
//DBG( printf( " read_Color\n") );
// DBG( printf( " read_Color\n") );
while( GetNextTag( m_file, text ) )
{
if ( ( text == NULL ) || ( *text == ']' ) )
if( ( text == NULL ) || ( *text == ']' ) )
{
continue;
}
if ( ( *text == '}' ) )
if( ( *text == '}' ) )
{
//DBG( printf( " m_DiffuseColor.size: %ld\n", m_model->m_Materials->m_DiffuseColor.size() ) );
// DBG( printf( " m_DiffuseColor.size: %ld\n", m_model->m_Materials->m_DiffuseColor.size() ) );
return 0;
}
......@@ -756,35 +764,33 @@ int VRML2_MODEL_PARSER::read_Color()
}
}
//DBG( printf( " read_Color failed\n") );
// DBG( printf( " read_Color failed\n") );
return -1;
}
int VRML2_MODEL_PARSER::read_Normal()
{
char text[128];
char text[128];
//DBG( printf( " Normal\n") );
// DBG( printf( " Normal\n") );
while( GetNextTag( m_file, text ) )
{
if ( ( text == NULL ) || ( *text == ']' ) )
if( ( text == NULL ) || ( *text == ']' ) )
{
continue;
}
if ( ( *text == '}' ) )
if( ( *text == '}' ) )
{
//DBG( printf( " m_PerFaceNormalsNormalized.size: %lu\n", m_model->m_PerFaceNormalsNormalized.size() ) );
// DBG( printf( " m_PerFaceNormalsNormalized.size: %lu\n", m_model->m_PerFaceNormalsNormalized.size() ) );
return 0;
}
if( strcmp( text, "vector" ) == 0 )
{
if(m_normalPerVertex == false )
if( m_normalPerVertex == false )
{
parseVertexList( m_file, m_model->m_PerFaceNormalsNormalized );
}
......@@ -792,7 +798,7 @@ int VRML2_MODEL_PARSER::read_Normal()
{
parseVertexList( m_file, m_model->m_PerVertexNormalsNormalized );
//DBG( printf( " m_PerVertexNormalsNormalized.size: %lu\n", m_model->m_PerVertexNormalsNormalized.size() ) );
// DBG( printf( " m_PerVertexNormalsNormalized.size: %lu\n", m_model->m_PerVertexNormalsNormalized.size() ) );
}
}
}
......@@ -803,29 +809,28 @@ int VRML2_MODEL_PARSER::read_Normal()
int VRML2_MODEL_PARSER::read_Coordinate()
{
char text[128];
char text[128];
//DBG( printf( " Coordinate\n") );
// DBG( printf( " Coordinate\n") );
while( GetNextTag( m_file, text ) )
{
if ( ( text == NULL ) || ( *text == ']' ) )
if( ( text == NULL ) || ( *text == ']' ) )
{
continue;
}
if ( ( *text == '}' ) )
if( ( *text == '}' ) )
{
//DBG( printf( " m_Point.size: %lu\n", m_model->m_Point.size() ) );
// DBG( printf( " m_Point.size: %lu\n", m_model->m_Point.size() ) );
return 0;
}
if( strcmp( text, "point" ) == 0 )
{
parseVertexList( m_file, m_model->m_Point);
parseVertexList( m_file, m_model->m_Point );
}
}
return -1;
}
......@@ -76,20 +76,21 @@ void VRML_MODEL_PARSER::Load( const wxString aFilename )
if( fgets( line, 11, file ) == NULL )
{
fclose( file );
return;
}
fclose( file );
if( stricmp( line, "#VRML V2.0" ) == 0)
if( stricmp( line, "#VRML V2.0" ) == 0 )
{
//DBG( printf( "About to parser a #VRML V2.0 file\n" ) );
vrml2_parser->Load( aFilename );
return;
}
else if( stricmp( line, "#VRML V1.0" ) == 0)
else if( stricmp( line, "#VRML V1.0" ) == 0 )
{
//DBG( printf( "About to parser a #VRML V1.0 file\n" ) );
vrml1_parser->Load( aFilename );
......@@ -97,5 +98,5 @@ void VRML_MODEL_PARSER::Load( const wxString aFilename )
return;
}
DBG( printf( "Unknown VRML file format: %s\n", line ) );
// DBG( printf( "Unknown VRML file format: %s\n", line ) );
}
......@@ -43,11 +43,13 @@
X3D_MODEL_PARSER::X3D_MODEL_PARSER( S3D_MASTER* aMaster ) :
S3D_MODEL_PARSER( aMaster )
{}
{
}
X3D_MODEL_PARSER::~X3D_MODEL_PARSER()
{}
{
}
void X3D_MODEL_PARSER::Load( const wxString aFilename )
......@@ -66,28 +68,28 @@ void X3D_MODEL_PARSER::Load( const wxString aFilename )
return;
}
glShadeModel(GL_SMOOTH);
glEnable(GL_NORMALIZE);
glShadeModel( GL_SMOOTH );
glEnable( GL_NORMALIZE );
float vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
glScalef( vrmlunits_to_3Dunits, vrmlunits_to_3Dunits, vrmlunits_to_3Dunits );
glm::vec3 matScale( GetMaster()->m_MatScale.x, GetMaster()->m_MatScale.y,
GetMaster()->m_MatScale.z );
GetMaster()->m_MatScale.z );
glm::vec3 matRot( GetMaster()->m_MatRotation.x, GetMaster()->m_MatRotation.y,
GetMaster()->m_MatRotation.z );
GetMaster()->m_MatRotation.z );
glm::vec3 matPos( GetMaster()->m_MatPosition.x, GetMaster()->m_MatPosition.y,
GetMaster()->m_MatPosition.z );
GetMaster()->m_MatPosition.z );
#define SCALE_3D_CONV ((IU_PER_MILS * 1000.0f) / UNITS3D_TO_UNITSPCB)
#define SCALE_3D_CONV ( (IU_PER_MILS * 1000.0f) / UNITS3D_TO_UNITSPCB )
glTranslatef( matPos.x * SCALE_3D_CONV, matPos.y * SCALE_3D_CONV, matPos.z * SCALE_3D_CONV );
glRotatef(-matRot.z, 0.0f, 0.0f, 1.0f );
glRotatef(-matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef(-matRot.x, 1.0f, 0.0f, 0.0f );
glRotatef( -matRot.z, 0.0f, 0.0f, 1.0f );
glRotatef( -matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef( -matRot.x, 1.0f, 0.0f, 0.0f );
glScalef( matScale.x, matScale.y, matScale.z );
......@@ -103,8 +105,8 @@ void X3D_MODEL_PARSER::Load( const wxString aFilename )
GetChildsByName( doc.GetRoot(), wxT( "Transform" ), transforms );
for( NODE_LIST::iterator node_it = transforms.begin();
node_it != transforms.end();
node_it++ )
node_it != transforms.end();
node_it++ )
{
m_model = new S3D_MESH();
childs.push_back( m_model );
......@@ -112,7 +114,7 @@ void X3D_MODEL_PARSER::Load( const wxString aFilename )
readTransform( *node_it );
}
//DBG( printf( "chils size:%lu\n", childs.size() ) );
// DBG( printf( "chils size:%lu\n", childs.size() ) );
if( GetMaster()->IsOpenGlAllowed() )
{
......@@ -140,7 +142,7 @@ wxString X3D_MODEL_PARSER::VRML2_representation()
" geometry IndexedFaceSet {\n"
" solid TRUE\n"
" coord Coordinate {\n"
" point [\n") +
" point [\n" ) +
vrml_points[i] +
wxT( " ]\n"
" }\n"
......@@ -156,19 +158,19 @@ wxString X3D_MODEL_PARSER::VRML2_representation()
void X3D_MODEL_PARSER::GetChildsByName( wxXmlNode* aParent,
const wxString aName,
std::vector< wxXmlNode* >& aResult )
const wxString aName,
std::vector<wxXmlNode*>& aResult )
{
// Breadth-first search (BFS)
std::queue< wxXmlNode* > found;
std::queue<wxXmlNode*> found;
found.push( aParent );
while( !found.empty() )
{
wxXmlNode *elem = found.front();
wxXmlNode* elem = found.front();
for( wxXmlNode *child = elem->GetChildren();
for( wxXmlNode* child = elem->GetChildren();
child != NULL;
child = child->GetNext() )
{
......@@ -197,11 +199,13 @@ void X3D_MODEL_PARSER::GetNodeProperties( wxXmlNode* aNode, PROPERTY_MAP& aProps
}
}
/* Private ----- */
void X3D_MODEL_PARSER::readTransform( wxXmlNode* aTransformNode )
{
NODE_LIST childnodes;
GetChildsByName( aTransformNode, wxT( "Material" ), childnodes );
for( NODE_LIST::iterator node = childnodes.begin();
......@@ -216,7 +220,7 @@ void X3D_MODEL_PARSER::readTransform( wxXmlNode* aTransformNode )
PROPERTY_MAP properties;
GetNodeProperties( aTransformNode, properties );
GetChildsByName( aTransformNode, wxT("IndexedFaceSet"), childnodes );
GetChildsByName( aTransformNode, wxT( "IndexedFaceSet" ), childnodes );
for( NODE_LIST::iterator node = childnodes.begin();
node != childnodes.end();
......@@ -234,6 +238,7 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
glm::vec3 color;
PROPERTY_MAP properties;
GetNodeProperties( aMatNode, properties );
// DEFine new Material named as value of DEF
......@@ -246,10 +251,9 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
m_model->m_Materials = material;
if( !parseDoubleTriplet( properties[ wxT( "diffuseColor" ) ],
color ) )
if( !parseDoubleTriplet( properties[ wxT( "diffuseColor" ) ], color ) )
{
DBG( printf("diffuseColor parsing error") );
// DBG( printf( "diffuseColor parsing error" ) );
}
else
{
......@@ -258,7 +262,7 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
if( !parseDoubleTriplet( properties[ wxT( "specularColor" ) ], color ) )
{
DBG( printf("specularColor parsing error") );
// DBG( printf( "specularColor parsing error" ) );
}
else
{
......@@ -267,7 +271,7 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
if( !parseDoubleTriplet( properties[ wxT( "emissiveColor" ) ], color ) )
{
DBG( printf("emissiveColor parsing error") );
// DBG( printf( "emissiveColor parsing error" ) );
}
else
{
......@@ -283,7 +287,7 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
}
else
{
DBG( printf( "ambienterror" ) );
// DBG( printf( "ambienterror" ) );
}
values.SetString( properties[ wxT( "shininess" ) ] );
......@@ -296,7 +300,7 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
}
else
{
DBG( printf( "shininess error" ) );
// DBG( printf( "shininess error" ) );
}
values.SetString( properties[ wxT( "transparency" ) ] );
......@@ -307,12 +311,12 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
}
else
{
DBG( printf( "trans error") );
// DBG( printf( "trans error" ) );
}
// VRML
wxString vrml_material;
PROPERTY_MAP::const_iterator p = ++properties.begin(); // skip DEF
PROPERTY_MAP::const_iterator p = ++properties.begin(); // skip DEF
for( ; p != properties.end(); p++ )
{
......@@ -321,7 +325,6 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
vrml_materials.push_back( vrml_material );
}
// USE existing material named by value of USE
else if( properties.find( wxT( "USE" ) ) != properties.end() )
{
......@@ -335,28 +338,28 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
wxString vrml_material;
vrml_material.Append( wxString::Format( wxT( "specularColor %f %f %f\n" ),
material->m_SpecularColor[0].x,
material->m_SpecularColor[0].y,
material->m_SpecularColor[0].z ) );
material->m_SpecularColor[0].x,
material->m_SpecularColor[0].y,
material->m_SpecularColor[0].z ) );
vrml_material.Append( wxString::Format( wxT( "diffuseColor %f %f %f\n" ),
material->m_DiffuseColor[0].x,
material->m_DiffuseColor[0].y,
material->m_DiffuseColor[0].z ) );
material->m_DiffuseColor[0].x,
material->m_DiffuseColor[0].y,
material->m_DiffuseColor[0].z ) );
vrml_material.Append( wxString::Format( wxT( "emissiveColor %f %f %f\n" ),
material->m_EmissiveColor[0].x,
material->m_EmissiveColor[0].y,
material->m_EmissiveColor[0].z ) );
material->m_EmissiveColor[0].x,
material->m_EmissiveColor[0].y,
material->m_EmissiveColor[0].z ) );
vrml_material.Append( wxString::Format( wxT( "ambientIntensity %f\n"),
material->m_AmbientColor[0].x ) );
vrml_material.Append( wxString::Format( wxT( "ambientIntensity %f\n" ),
material->m_AmbientColor[0].x ) );
vrml_material.Append( wxString::Format( wxT( "shininess %f\n"),
material->m_Shininess[0] ) );
vrml_material.Append( wxString::Format( wxT( "shininess %f\n" ),
material->m_Shininess[0] ) );
vrml_material.Append( wxString::Format( wxT( "transparency %f\n"),
material->m_Transparency[0] ) );
vrml_material.Append( wxString::Format( wxT( "transparency %f\n" ),
material->m_Transparency[0] ) );
vrml_materials.push_back( vrml_material );
......@@ -366,38 +369,38 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
}
}
DBG( printf( "ReadMaterial error: material not found\n" ) );
// DBG( printf( "ReadMaterial error: material not found\n" ) );
}
}
bool X3D_MODEL_PARSER::parseDoubleTriplet( const wxString& aData,
S3D_VERTEX& aResult )
S3D_VERTEX& aResult )
{
wxStringTokenizer tokens(aData);
wxStringTokenizer tokens( aData );
double x,y,z;
double x, y, z;
bool ret = tokens.GetNextToken().ToDouble( &x ) &&
tokens.GetNextToken().ToDouble( &y ) &&
tokens.GetNextToken().ToDouble( &z );
bool ret = tokens.GetNextToken().ToDouble( &x )
&& tokens.GetNextToken().ToDouble( &y )
&& tokens.GetNextToken().ToDouble( &z );
aResult.x = x;
aResult.y = y;
aResult.z = z;
aResult.x = x;
aResult.y = y;
aResult.z = z;
return ret;
}
void X3D_MODEL_PARSER::rotate( S3D_VERTEX& aV,
S3D_VERTEX& aU,
double angle )
S3D_VERTEX& aU,
double angle )
{
S3D_VERTEX rotated;
double C = cos( angle );
double S = sin( angle );
double t = 1.0 - C;
double C = cos( angle );
double S = sin( angle );
double t = 1.0 - C;
rotated.x = ( t * aU.x * aU.x + C ) * aV.x +
( t * aU.x * aU.y - S * aU.z ) * aV.y +
......@@ -411,9 +414,9 @@ void X3D_MODEL_PARSER::rotate( S3D_VERTEX& aV,
( t * aU.y * aU.z + S * aU.x ) * aV.y +
( t * aU.z * aU.z + C) * aV.z;
aV.x = rotated.x;
aV.y = rotated.y;
aV.z = rotated.z;
aV.x = rotated.x;
aV.y = rotated.y;
aV.z = rotated.z;
}
......@@ -424,12 +427,13 @@ void X3D_MODEL_PARSER::rotate( S3D_VERTEX& aV,
* 4. Apply geometry to Master object
*/
void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
PROPERTY_MAP& aTransformProps)
PROPERTY_MAP& aTransformProps )
{
/* Step 1: Read transform data
* --------------------------- */
S3D_VERTEX translation;
parseDoubleTriplet( aTransformProps[ wxT( "translation" ) ], translation );
S3D_VERTEX scale;
......@@ -437,35 +441,36 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
S3D_VERTEX rotation;
double angle = 0.0;
wxStringTokenizer tokens(aTransformProps[ wxT( "rotation" ) ]);
wxStringTokenizer tokens( aTransformProps[ wxT( "rotation" ) ] );
double x,y,z;
if( !(tokens.GetNextToken().ToDouble( &x ) &&
tokens.GetNextToken().ToDouble( &y ) &&
tokens.GetNextToken().ToDouble( &z ) &&
tokens.GetNextToken().ToDouble( &angle ) ) )
double x, y, z;
if( !( tokens.GetNextToken().ToDouble( &x )
&& tokens.GetNextToken().ToDouble( &y )
&& tokens.GetNextToken().ToDouble( &z )
&& tokens.GetNextToken().ToDouble( &angle ) ) )
{
DBG( printf("rotation read error") );
// DBG( printf( "rotation read error" ) );
}
else
{
rotation.x = x;
rotation.y = y;
rotation.z = z;
rotation.x = x;
rotation.y = y;
rotation.z = z;
}
/* Step 2: Read all coordinate points
* ---------------------------- */
std::vector< double > points;
std::vector<double> points;
NODE_LIST coordinates;
GetChildsByName( aFaceNode, wxT( "Coordinate" ), coordinates);
GetChildsByName( aFaceNode, wxT( "Coordinate" ), coordinates );
PROPERTY_MAP coordinate_properties;
// IndexedFaceSet has one Coordinate child node
GetNodeProperties( coordinates[0], coordinate_properties );
// Save points to vector as doubles
wxStringTokenizer point_tokens( coordinate_properties[ wxT("point") ] );
wxStringTokenizer point_tokens( coordinate_properties[ wxT( "point" ) ] );
double point = 0.0;
while( point_tokens.HasMoreTokens() )
......@@ -482,7 +487,7 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
if( points.size() % 3 != 0 )
{
DBG( printf( "Number of points is incorrect" ) );
// DBG( printf( "Number of points is incorrect" ) );
return;
}
......@@ -490,14 +495,14 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
* apply transforms in order of SCALE, ROTATION, TRANSLATION
*/
wxString vrml_pointlist;
std::vector< S3D_VERTEX > triplets;
std::vector<S3D_VERTEX> triplets;
for( unsigned id = 0; id < points.size() / 3; id++ )
{
int triplet_indx = id * 3;
S3D_VERTEX point( points[ triplet_indx ],
points[ triplet_indx + 1 ],
points[ triplet_indx + 2 ] );
points[ triplet_indx + 1 ],
points[ triplet_indx + 2 ] );
point.x *= scale.x;
point.y *= scale.y;
......@@ -520,9 +525,9 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
/* Step 3: Read all color points
* ---------------------------- */
std::vector< double > color_points;
std::vector<double> color_points;
NODE_LIST color;
GetChildsByName( aFaceNode, wxT( "Color" ), color);
GetChildsByName( aFaceNode, wxT( "Color" ), color );
// Some models lack color information, need to handle this safely
if( !color.empty() )
......@@ -532,7 +537,7 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
GetNodeProperties( color[0], color_properties );
// Save points to vector as doubles
wxStringTokenizer colorpoint_tokens( color_properties[ wxT("color") ] );
wxStringTokenizer colorpoint_tokens( color_properties[ wxT( "color" ) ] );
double color_point = 0.0;
while( colorpoint_tokens.HasMoreTokens() )
......@@ -549,21 +554,22 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
if( color_points.size() % 3 != 0 )
{
DBG( printf( "Number of points is incorrect" ) );
// DBG( printf( "Number of points is incorrect" ) );
return;
}
/* Create 3D face color from 3 color points
*/
m_model->m_Materials->m_DiffuseColor.clear();
for( unsigned id = 0; id < color_points.size() / 3; id++ )
{
m_model->m_MaterialIndex.push_back( id );
int color_triplet_indx = id * 3;
glm::vec3 colorface( color_points[ color_triplet_indx + 0 ],
color_points[ color_triplet_indx + 1 ],
color_points[ color_triplet_indx + 2 ] );
color_points[ color_triplet_indx + 1 ],
color_points[ color_triplet_indx + 2 ] );
m_model->m_Materials->m_DiffuseColor.push_back( colorface );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment