Finished initial implementation of VRML1 parser

This commit is contained in:
Cirilo Bernardo 2016-01-06 19:45:49 +11:00
parent 9d55ad375f
commit d6fbd7b4e5
4 changed files with 70 additions and 105 deletions

View File

@ -4,7 +4,7 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/v2 ${CMAKE_CURRENT_SOURCE_DIR}/v2
) )
#add_definitions( -DDEBUG_VRML1=3 -DDEBUG_VRML2=3 ) #add_definitions( -DDEBUG_VRML1=2 )
add_library( s3d_plugin_vrml MODULE add_library( s3d_plugin_vrml MODULE
vrml.cpp vrml.cpp

View File

@ -266,7 +266,7 @@ SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, bool calcNormals )
case BIND_OVERALL: case BIND_OVERALL:
// use the first (non-default) appearance definition // use the first (non-default) appearance definition
sgcolor = m_current.mat->GetAppearance( 1 ); sgcolor = m_current.mat->GetAppearance( 0 );
break; break;
case BIND_PER_FACE: case BIND_PER_FACE:
@ -290,7 +290,7 @@ SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, bool calcNormals )
default: default:
// use the default appearance definition // use the default appearance definition
sgcolor = m_current.mat->GetAppearance( 0 ); sgcolor = m_current.mat->GetAppearance( -1 );
break; break;
} }
@ -365,9 +365,9 @@ SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, bool calcNormals )
{ {
case BIND_PER_VERTEX: case BIND_PER_VERTEX:
cIndex = 3; cIndex = 3;
m_current.mat->GetColor( &pc1, 1 ); m_current.mat->GetColor( &pc1, 0 );
m_current.mat->GetColor( &pc2, 2 ); m_current.mat->GetColor( &pc2, 1 );
m_current.mat->GetColor( &pc3, 3 ); m_current.mat->GetColor( &pc3, 2 );
break; break;
case BIND_PER_VERTEX_INDEXED: case BIND_PER_VERTEX_INDEXED:
@ -383,14 +383,14 @@ SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, bool calcNormals )
return NULL; return NULL;
} }
m_current.mat->GetColor( &pc1, matIndex[0] + 1 ); m_current.mat->GetColor( &pc1, matIndex[0] );
m_current.mat->GetColor( &pc2, matIndex[1] + 1 ); m_current.mat->GetColor( &pc2, matIndex[1] );
m_current.mat->GetColor( &pc3, matIndex[2] + 1 ); m_current.mat->GetColor( &pc3, matIndex[2] );
break; break;
case BIND_PER_FACE: case BIND_PER_FACE:
cIndex = 1; cIndex = 1;
m_current.mat->GetColor( &pc1, 1 ); m_current.mat->GetColor( &pc1, 0 );
pc2.SetColor( pc1 ); pc2.SetColor( pc1 );
pc3.SetColor( pc1 ); pc3.SetColor( pc1 );
break; break;
@ -398,7 +398,7 @@ SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, bool calcNormals )
default: default:
// BIND_PER_FACE_INDEXED // BIND_PER_FACE_INDEXED
cIndex = 1; cIndex = 1;
m_current.mat->GetColor( &pc1, matIndex[0] + 1 ); m_current.mat->GetColor( &pc1, matIndex[0] );
pc2.SetColor( pc1 ); pc2.SetColor( pc1 );
pc3.SetColor( pc1 ); pc3.SetColor( pc1 );
break; break;
@ -438,11 +438,11 @@ SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, bool calcNormals )
if( noidx || cIndex >= cMaxIdx ) if( noidx || cIndex >= cMaxIdx )
{ {
m_current.mat->GetColor( &pc3, cIndex + 1 ); m_current.mat->GetColor( &pc3, cIndex );
++cIndex; ++cIndex;
} }
else else
m_current.mat->GetColor( &pc3, matIndex[cIndex++] + 1 ); m_current.mat->GetColor( &pc3, matIndex[cIndex++] );
} }
@ -456,12 +456,9 @@ SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, bool calcNormals )
if( !colorPerVertex ) if( !colorPerVertex )
{ {
if( noidx || cIndex >= cMaxIdx ) if( noidx || cIndex >= cMaxIdx )
{ m_current.mat->GetColor( &pc1, cIndex++ );
m_current.mat->GetColor( &pc1, cIndex + 1 );
++cIndex;
}
else else
m_current.mat->GetColor( &pc1, matIndex[cIndex++] + 1 ); m_current.mat->GetColor( &pc1, matIndex[cIndex++] );
pc2.SetColor( pc1 ); pc2.SetColor( pc1 );
pc3.SetColor( pc1 ); pc3.SetColor( pc1 );
@ -478,12 +475,9 @@ SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, bool calcNormals )
pc2.SetColor( pc3 ); pc2.SetColor( pc3 );
if( noidx || cIndex >= cMaxIdx ) if( noidx || cIndex >= cMaxIdx )
{ m_current.mat->GetColor( &pc3, cIndex );
m_current.mat->GetColor( &pc3, cIndex + 1 );
++cIndex;
}
else else
m_current.mat->GetColor( &pc3, matIndex[cIndex++] + 1 ); m_current.mat->GetColor( &pc3, matIndex[cIndex++] );
} }
@ -519,14 +513,21 @@ SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, bool calcNormals )
} while( 0 ); } while( 0 );
// XXX - create the hierarchy: // create the hierarchy:
// Transform // Shape
// + Shape // + (option) Appearance
// + (option) Appearance // + FaceSet
// + FaceSet IFSG_SHAPE shapeNode( aParent );
#ifdef NOGO
#endif if( sgcolor )
IFSG_FACESET fsNode( aParent ); {
if( NULL == S3D::GetSGNodeParent( sgcolor ) )
shapeNode.AddChildNode( sgcolor );
else
shapeNode.AddRefNode( sgcolor );
}
IFSG_FACESET fsNode( shapeNode );
IFSG_COORDS cpNode( fsNode ); IFSG_COORDS cpNode( fsNode );
cpNode.SetCoordsList( lCPts.size(), &lCPts[0] ); cpNode.SetCoordsList( lCPts.size(), &lCPts[0] );
IFSG_COORDINDEX ciNode( fsNode ); IFSG_COORDINDEX ciNode( fsNode );

View File

@ -31,7 +31,6 @@
WRL1MATERIAL::WRL1MATERIAL( NAMEREGISTER* aDictionary ) : WRL1NODE( aDictionary ) WRL1MATERIAL::WRL1MATERIAL( NAMEREGISTER* aDictionary ) : WRL1NODE( aDictionary )
{ {
setDefaults();
m_Type = WRL1_MATERIAL; m_Type = WRL1_MATERIAL;
return; return;
} }
@ -40,7 +39,6 @@ WRL1MATERIAL::WRL1MATERIAL( NAMEREGISTER* aDictionary ) : WRL1NODE( aDictionary
WRL1MATERIAL::WRL1MATERIAL( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) : WRL1MATERIAL::WRL1MATERIAL( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
WRL1NODE( aDictionary ) WRL1NODE( aDictionary )
{ {
setDefaults();
m_Type = WRL1_MATERIAL; m_Type = WRL1_MATERIAL;
m_Parent = aParent; m_Parent = aParent;
@ -68,36 +66,6 @@ WRL1MATERIAL::~WRL1MATERIAL()
} }
void WRL1MATERIAL::setDefaults( void )
{
// default material values as per VRML1 spec
WRLVEC3F color;
color.x = 0.8;
color.y = 0.8;
color.z = 0.8;
diffuseColor.push_back( color );
color.x = 0.2;
color.y = 0.2;
color.z = 0.2;
ambientColor.push_back( color );
color.x = 0.0;
color.y = 0.0;
color.z = 0.0;
emissiveColor.push_back( color );
specularColor.push_back( color );
shininess.push_back( 0.2 );
transparency.push_back( 0.0 );
colors[0] = NULL;
colors[1] = NULL;
return;
}
bool WRL1MATERIAL::AddRefNode( WRL1NODE* aNode ) bool WRL1MATERIAL::AddRefNode( WRL1NODE* aNode )
{ {
// this node may not own or reference any other node // this node may not own or reference any other node
@ -311,6 +279,8 @@ SGNODE* WRL1MATERIAL::TranslateToSG( SGNODE* aParent, bool calcNormals )
SGNODE* WRL1MATERIAL::GetAppearance( int aIndex ) SGNODE* WRL1MATERIAL::GetAppearance( int aIndex )
{ {
++aIndex;
// invalid indices result in the default colors // invalid indices result in the default colors
if( aIndex != 0 && aIndex != 1 ) if( aIndex != 0 && aIndex != 1 )
aIndex = 0; aIndex = 0;
@ -322,34 +292,34 @@ SGNODE* WRL1MATERIAL::GetAppearance( int aIndex )
float red, green, blue, val; float red, green, blue, val;
if( aIndex > (int)transparency.size() ) if( aIndex == 0 || transparency.empty() )
val = transparency[0]; val = 0.0;
else else
val = transparency[aIndex]; val = transparency[0];
checkRange( val ); checkRange( val );
app.SetTransparency( val ); app.SetTransparency( val );
if( aIndex > (int)shininess.size() ) if( aIndex == 0 || shininess.empty() )
val = shininess[0]; val = 0.2;
else else
val = shininess[aIndex]; val = shininess[0];
checkRange( val ); checkRange( val );
app.SetShininess( val ); app.SetShininess( val );
if( aIndex > (int)ambientColor.size() ) if( aIndex ==0 || ambientColor.empty() )
{
red = 0.2;
green = 0.2;
blue = 0.2;
}
else
{ {
red = ambientColor[0].x; red = ambientColor[0].x;
green = ambientColor[0].y; green = ambientColor[0].y;
blue = ambientColor[0].z; blue = ambientColor[0].z;
} }
else
{
red = ambientColor[aIndex].x;
green = ambientColor[aIndex].y;
blue = ambientColor[aIndex].z;
}
checkRange( red ); checkRange( red );
checkRange( green ); checkRange( green );
@ -357,18 +327,18 @@ SGNODE* WRL1MATERIAL::GetAppearance( int aIndex )
val = (red + green + blue)/3.0; val = (red + green + blue)/3.0;
app.SetAmbient( val ); app.SetAmbient( val );
if( aIndex > (int)diffuseColor.size() ) if( aIndex == 0 || diffuseColor.empty() )
{
red = 0.8;
green = 0.8;
blue = 0.8;
}
else
{ {
red = diffuseColor[0].x; red = diffuseColor[0].x;
green = diffuseColor[0].y; green = diffuseColor[0].y;
blue = diffuseColor[0].z; blue = diffuseColor[0].z;
} }
else
{
red = diffuseColor[aIndex].x;
green = diffuseColor[aIndex].y;
blue = diffuseColor[aIndex].z;
}
checkRange( red ); checkRange( red );
checkRange( green ); checkRange( green );
@ -377,15 +347,15 @@ SGNODE* WRL1MATERIAL::GetAppearance( int aIndex )
if( aIndex > (int)emissiveColor.size() ) if( aIndex > (int)emissiveColor.size() )
{ {
red = emissiveColor[0].x; red = 0.0;
green = emissiveColor[0].y; green = 0.0;
blue = emissiveColor[0].z; blue = 0.0;
} }
else else
{ {
red = emissiveColor[aIndex].x; red = emissiveColor[0].x;
green = emissiveColor[aIndex].y; green = emissiveColor[0].y;
blue = emissiveColor[aIndex].z; blue = emissiveColor[0].z;
} }
checkRange( red ); checkRange( red );
@ -395,15 +365,15 @@ SGNODE* WRL1MATERIAL::GetAppearance( int aIndex )
if( aIndex > (int)specularColor.size() ) if( aIndex > (int)specularColor.size() )
{ {
red = specularColor[0].x; red = 0.0;
green = specularColor[0].y; green = 0.0;
blue = specularColor[0].z; blue = 0.0;
} }
else else
{ {
red = specularColor[aIndex].x; red = specularColor[0].x;
green = specularColor[aIndex].y; green = specularColor[0].y;
blue = specularColor[aIndex].z; blue = specularColor[0].z;
} }
checkRange( red ); checkRange( red );
@ -429,18 +399,13 @@ void WRL1MATERIAL::GetColor( SGCOLOR* aColor, int aIndex )
float red, blue, green; float red, blue, green;
float eRed, eBlue, eGreen; float eRed, eBlue, eGreen;
if( aIndex <= 0 || ( aIndex >= (int)diffuseColor.size() if( aIndex < 0 || ( aIndex >= (int)diffuseColor.size()
&& aIndex >= (int)emissiveColor.size() ) ) && aIndex >= (int)emissiveColor.size() ) )
{ {
// If the index is out of bounds, use the default diffuse color. // If the index is out of bounds, use the default diffuse color.
red = diffuseColor[0].x; red = 0.8;
green = diffuseColor[0].y; green = 0.8;
blue = diffuseColor[0].z; blue = 0.8;
checkRange( red );
checkRange( green );
checkRange( blue );
aColor->SetColor( red, green, blue ); aColor->SetColor( red, green, blue );
return; return;
} }

View File

@ -52,7 +52,6 @@ private:
SGNODE* colors[2]; SGNODE* colors[2];
void setDefaults( void );
void checkRange( float& aValue ); void checkRange( float& aValue );
public: public: