|
|
|
@ -109,7 +109,8 @@ void VRML2_MODEL_PARSER::Load( const wxString aFilename ) |
|
|
|
|
|
|
|
read_Transform(); |
|
|
|
|
|
|
|
} else if( strcmp( text, "DEF" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "DEF" ) == 0 ) |
|
|
|
{ |
|
|
|
m_model = new S3D_MESH(); |
|
|
|
|
|
|
|
@ -155,36 +156,73 @@ int VRML2_MODEL_PARSER::read_Transform() |
|
|
|
if( strcmp( text, "translation" ) == 0 ) |
|
|
|
{ |
|
|
|
parseVertex( m_file, m_model->m_translation ); |
|
|
|
} else if( strcmp( text, "rotation" ) == 0 ) |
|
|
|
} |
|
|
|
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 ) |
|
|
|
{ |
|
|
|
// !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; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
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]); |
|
|
|
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 ) |
|
|
|
} |
|
|
|
} |
|
|
|
else if( strcmp( text, "scale" ) == 0 ) |
|
|
|
{ |
|
|
|
parseVertex( m_file, m_model->m_scale ); |
|
|
|
} else if( strcmp( text, "scaleOrientation" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "scaleOrientation" ) == 0 ) |
|
|
|
{ |
|
|
|
// 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 ) |
|
|
|
{ |
|
|
|
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]); |
|
|
|
} else if( strcmp( text, "center" ) == 0 ) |
|
|
|
// !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; |
|
|
|
} |
|
|
|
} |
|
|
|
else if( strcmp( text, "center" ) == 0 ) |
|
|
|
{ |
|
|
|
parseVertex( m_file, m_model->m_center ); |
|
|
|
} else if( strcmp( text, "children" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "children" ) == 0 ) |
|
|
|
{ |
|
|
|
// skip
|
|
|
|
} else if( strcmp( text, "Switch" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "Switch" ) == 0 ) |
|
|
|
{ |
|
|
|
// skip
|
|
|
|
} else if( strcmp( text, "whichChoice" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "whichChoice" ) == 0 ) |
|
|
|
{ |
|
|
|
int dummy; |
|
|
|
fscanf( m_file, "%d", &dummy ); |
|
|
|
} else if( strcmp( text, "choice" ) == 0 ) |
|
|
|
if( fscanf( m_file, "%d", &dummy ) != 1 ) |
|
|
|
{ |
|
|
|
// !TODO: log errors
|
|
|
|
} |
|
|
|
} |
|
|
|
else if( strcmp( text, "choice" ) == 0 ) |
|
|
|
{ |
|
|
|
// skip
|
|
|
|
} else if( strcmp( text, "Group" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "Group" ) == 0 ) |
|
|
|
{ |
|
|
|
// skip
|
|
|
|
} else if( strcmp( text, "Shape" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "Shape" ) == 0 ) |
|
|
|
{ |
|
|
|
S3D_MESH *parent = m_model; |
|
|
|
|
|
|
|
@ -198,10 +236,12 @@ int VRML2_MODEL_PARSER::read_Transform() |
|
|
|
|
|
|
|
m_model = parent; |
|
|
|
|
|
|
|
} else if( strcmp( text, "DEF" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "DEF" ) == 0 ) |
|
|
|
{ |
|
|
|
read_DEF(); |
|
|
|
} else |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
DBG( printf( " %s NotImplemented\n", text ) ); |
|
|
|
read_NotImplemented( m_file, '}' ); |
|
|
|
@ -238,16 +278,20 @@ int VRML2_MODEL_PARSER::read_DEF() |
|
|
|
} else if( strcmp( text, "children" ) == 0 ) |
|
|
|
{ |
|
|
|
// skip
|
|
|
|
} else if( strcmp( text, "Switch" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "Switch" ) == 0 ) |
|
|
|
{ |
|
|
|
// skip
|
|
|
|
} else if( strcmp( text, "whichChoice" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "whichChoice" ) == 0 ) |
|
|
|
{ |
|
|
|
// skip
|
|
|
|
} else if( strcmp( text, "choice" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "choice" ) == 0 ) |
|
|
|
{ |
|
|
|
// skip
|
|
|
|
}else if( strcmp( text, "Shape" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "Shape" ) == 0 ) |
|
|
|
{ |
|
|
|
S3D_MESH *parent = m_model; |
|
|
|
|
|
|
|
@ -290,16 +334,20 @@ int VRML2_MODEL_PARSER::read_Shape() |
|
|
|
if( strcmp( text, "appearance" ) == 0 ) |
|
|
|
{ |
|
|
|
//skip
|
|
|
|
} else if( strcmp( text, "Appearance" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "Appearance" ) == 0 ) |
|
|
|
{ |
|
|
|
read_Appearance(); |
|
|
|
} else if( strcmp( text, "geometry" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "geometry" ) == 0 ) |
|
|
|
{ |
|
|
|
//skip
|
|
|
|
} else if( strcmp( text, "IndexedFaceSet" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "IndexedFaceSet" ) == 0 ) |
|
|
|
{ |
|
|
|
read_IndexedFaceSet(); |
|
|
|
} else |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
DBG( printf( " %s NotImplemented\n", text ) ); |
|
|
|
read_NotImplemented( m_file, '}' ); |
|
|
|
@ -362,7 +410,8 @@ int VRML2_MODEL_PARSER::read_material() |
|
|
|
{ |
|
|
|
return read_Material(); |
|
|
|
} |
|
|
|
} else if( strcmp( text, "DEF" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "DEF" ) == 0 ) |
|
|
|
{ |
|
|
|
//DBG( printf( "DEF") );
|
|
|
|
|
|
|
|
@ -387,7 +436,8 @@ int VRML2_MODEL_PARSER::read_material() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if( strcmp( text, "USE" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "USE" ) == 0 ) |
|
|
|
{ |
|
|
|
//DBG( printf( "USE") );
|
|
|
|
|
|
|
|
@ -450,7 +500,8 @@ int VRML2_MODEL_PARSER::read_Material() |
|
|
|
{ |
|
|
|
m_model->m_Materials->m_EmissiveColor.push_back( vertex ); |
|
|
|
} |
|
|
|
} else if( strcmp( text, "specularColor" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "specularColor" ) == 0 ) |
|
|
|
{ |
|
|
|
//DBG( printf( " specularColor") );
|
|
|
|
parseVertex ( m_file, vertex); |
|
|
|
@ -459,7 +510,8 @@ int VRML2_MODEL_PARSER::read_Material() |
|
|
|
{ |
|
|
|
m_model->m_Materials->m_SpecularColor.push_back( vertex ); |
|
|
|
} |
|
|
|
} else if( strcmp( text, "ambientIntensity" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "ambientIntensity" ) == 0 ) |
|
|
|
{ |
|
|
|
float ambientIntensity; |
|
|
|
parseFloat( m_file, &ambientIntensity ); |
|
|
|
@ -468,7 +520,8 @@ int VRML2_MODEL_PARSER::read_Material() |
|
|
|
{ |
|
|
|
m_model->m_Materials->m_AmbientColor.push_back( glm::vec3( ambientIntensity, ambientIntensity, ambientIntensity ) ); |
|
|
|
} |
|
|
|
} else if( strcmp( text, "transparency" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "transparency" ) == 0 ) |
|
|
|
{ |
|
|
|
float transparency; |
|
|
|
parseFloat( m_file, &transparency ); |
|
|
|
@ -477,7 +530,8 @@ int VRML2_MODEL_PARSER::read_Material() |
|
|
|
{ |
|
|
|
m_model->m_Materials->m_Transparency.push_back( transparency ); |
|
|
|
} |
|
|
|
} else if( strcmp( text, "shininess" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "shininess" ) == 0 ) |
|
|
|
{ |
|
|
|
float shininess; |
|
|
|
parseFloat( m_file, &shininess ); |
|
|
|
@ -528,7 +582,8 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet() |
|
|
|
m_normalPerVertex = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if( strcmp( text, "colorPerVertex" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "colorPerVertex" ) == 0 ) |
|
|
|
{ |
|
|
|
GetNextTag( m_file, text ); |
|
|
|
if( strcmp( text, "TRUE" ) ) |
|
|
|
@ -540,22 +595,28 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet() |
|
|
|
colorPerVertex = false; |
|
|
|
} |
|
|
|
|
|
|
|
} else if( strcmp( text, "Coordinate" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "Coordinate" ) == 0 ) |
|
|
|
{ |
|
|
|
read_Coordinate(); |
|
|
|
} else if( strcmp( text, "Normal" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "Normal" ) == 0 ) |
|
|
|
{ |
|
|
|
read_Normal(); |
|
|
|
} else if( strcmp( text, "normalIndex" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "normalIndex" ) == 0 ) |
|
|
|
{ |
|
|
|
read_NormalIndex(); |
|
|
|
} else if( strcmp( text, "Color" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "Color" ) == 0 ) |
|
|
|
{ |
|
|
|
read_Color(); |
|
|
|
} else if( strcmp( text, "coordIndex" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "coordIndex" ) == 0 ) |
|
|
|
{ |
|
|
|
read_coordIndex(); |
|
|
|
} else if( strcmp( text, "colorIndex" ) == 0 ) |
|
|
|
} |
|
|
|
else if( strcmp( text, "colorIndex" ) == 0 ) |
|
|
|
{ |
|
|
|
read_colorIndex(); |
|
|
|
} |
|
|
|
@ -583,14 +644,17 @@ int VRML2_MODEL_PARSER::read_colorIndex() |
|
|
|
{ |
|
|
|
// it only implemented color per face, so it will store as the first in the list
|
|
|
|
m_model->m_MaterialIndex.push_back( first_index ); |
|
|
|
} else |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
first_index = index; |
|
|
|
} |
|
|
|
} |
|
|
|
} else |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
int index; |
|
|
|
|
|
|
|
while( fscanf( m_file, "%d,", &index ) ) |
|
|
|
{ |
|
|
|
m_model->m_MaterialIndex.push_back( index ); |
|
|
|
@ -622,7 +686,8 @@ int VRML2_MODEL_PARSER::read_NormalIndex() |
|
|
|
m_model->m_NormalIndex.push_back( coord_list ); |
|
|
|
//DBG( printf( " size: %lu ", coord_list.size()) );
|
|
|
|
coord_list.clear(); |
|
|
|
} else |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
coord_list.push_back( dummy ); |
|
|
|
//DBG( printf( "%d ", dummy) );
|
|
|
|
@ -654,7 +719,8 @@ int VRML2_MODEL_PARSER::read_coordIndex() |
|
|
|
m_model->m_CoordIndex.push_back( coord_list ); |
|
|
|
//DBG( printf( " size: %lu ", coord_list.size()) );
|
|
|
|
coord_list.clear(); |
|
|
|
} else |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
coord_list.push_back( dummy ); |
|
|
|
//DBG( printf( "%d ", dummy) );
|
|
|
|
@ -723,7 +789,8 @@ int VRML2_MODEL_PARSER::read_Normal() |
|
|
|
if(m_normalPerVertex == false ) |
|
|
|
{ |
|
|
|
parseVertexList( m_file, m_model->m_PerFaceNormalsNormalized ); |
|
|
|
} else |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
parseVertexList( m_file, m_model->m_PerVertexNormalsNormalized ); |
|
|
|
|
|
|
|
|