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
)
#add_definitions( -DDEBUG_VRML1=3 -DDEBUG_VRML2=3 )
#add_definitions( -DDEBUG_VRML1=2 )
add_library( s3d_plugin_vrml MODULE
vrml.cpp

View File

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

View File

@ -31,7 +31,6 @@
WRL1MATERIAL::WRL1MATERIAL( NAMEREGISTER* aDictionary ) : WRL1NODE( aDictionary )
{
setDefaults();
m_Type = WRL1_MATERIAL;
return;
}
@ -40,7 +39,6 @@ WRL1MATERIAL::WRL1MATERIAL( NAMEREGISTER* aDictionary ) : WRL1NODE( aDictionary
WRL1MATERIAL::WRL1MATERIAL( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
WRL1NODE( aDictionary )
{
setDefaults();
m_Type = WRL1_MATERIAL;
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 )
{
// 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 )
{
++aIndex;
// invalid indices result in the default colors
if( aIndex != 0 && aIndex != 1 )
aIndex = 0;
@ -322,34 +292,34 @@ SGNODE* WRL1MATERIAL::GetAppearance( int aIndex )
float red, green, blue, val;
if( aIndex > (int)transparency.size() )
val = transparency[0];
if( aIndex == 0 || transparency.empty() )
val = 0.0;
else
val = transparency[aIndex];
val = transparency[0];
checkRange( val );
app.SetTransparency( val );
if( aIndex > (int)shininess.size() )
val = shininess[0];
if( aIndex == 0 || shininess.empty() )
val = 0.2;
else
val = shininess[aIndex];
val = shininess[0];
checkRange( 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;
green = ambientColor[0].y;
blue = ambientColor[0].z;
}
else
{
red = ambientColor[aIndex].x;
green = ambientColor[aIndex].y;
blue = ambientColor[aIndex].z;
}
checkRange( red );
checkRange( green );
@ -357,18 +327,18 @@ SGNODE* WRL1MATERIAL::GetAppearance( int aIndex )
val = (red + green + blue)/3.0;
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;
green = diffuseColor[0].y;
blue = diffuseColor[0].z;
}
else
{
red = diffuseColor[aIndex].x;
green = diffuseColor[aIndex].y;
blue = diffuseColor[aIndex].z;
}
checkRange( red );
checkRange( green );
@ -377,15 +347,15 @@ SGNODE* WRL1MATERIAL::GetAppearance( int aIndex )
if( aIndex > (int)emissiveColor.size() )
{
red = emissiveColor[0].x;
green = emissiveColor[0].y;
blue = emissiveColor[0].z;
red = 0.0;
green = 0.0;
blue = 0.0;
}
else
{
red = emissiveColor[aIndex].x;
green = emissiveColor[aIndex].y;
blue = emissiveColor[aIndex].z;
red = emissiveColor[0].x;
green = emissiveColor[0].y;
blue = emissiveColor[0].z;
}
checkRange( red );
@ -395,15 +365,15 @@ SGNODE* WRL1MATERIAL::GetAppearance( int aIndex )
if( aIndex > (int)specularColor.size() )
{
red = specularColor[0].x;
green = specularColor[0].y;
blue = specularColor[0].z;
red = 0.0;
green = 0.0;
blue = 0.0;
}
else
{
red = specularColor[aIndex].x;
green = specularColor[aIndex].y;
blue = specularColor[aIndex].z;
red = specularColor[0].x;
green = specularColor[0].y;
blue = specularColor[0].z;
}
checkRange( red );
@ -429,18 +399,13 @@ void WRL1MATERIAL::GetColor( SGCOLOR* aColor, int aIndex )
float red, blue, green;
float eRed, eBlue, eGreen;
if( aIndex <= 0 || ( aIndex >= (int)diffuseColor.size()
if( aIndex < 0 || ( aIndex >= (int)diffuseColor.size()
&& aIndex >= (int)emissiveColor.size() ) )
{
// If the index is out of bounds, use the default diffuse color.
red = diffuseColor[0].x;
green = diffuseColor[0].y;
blue = diffuseColor[0].z;
checkRange( red );
checkRange( green );
checkRange( blue );
red = 0.8;
green = 0.8;
blue = 0.8;
aColor->SetColor( red, green, blue );
return;
}

View File

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