Work in progress: VRML2 parser

This commit is contained in:
Cirilo Bernardo 2015-12-22 19:02:18 +11:00
parent e08c0de68f
commit 189f6fa763
4 changed files with 139 additions and 9 deletions

View File

@ -117,7 +117,7 @@ bool WRL2BASE::Read( WRLPROC& proc )
WRL2NODE* node = NULL;
while( !ReadNode( proc, this, &node ) );
while( ReadNode( proc, this, &node ) );
if( proc.eof() )
return true;
@ -382,6 +382,8 @@ bool WRL2BASE::ReadNode( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
ntype = getNodeTypeID( glob );
size_t line = 0;
size_t column = 0;
proc.GetFilePosData( line, column );
std::cerr << "XXX: Processing node '" << glob << "' ID: " << ntype << "\n";
switch( ntype )
{
@ -390,61 +392,159 @@ bool WRL2BASE::ReadNode( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
//
case WRL2_APPEARANCE:
// XXX - IMPLEMENT
if( !proc.DiscardNode() )
{
std::cerr << "XXX: FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
return false;
}
else
std::cerr << "XXX: OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
break;
case WRL2_BOX:
// XXX - IMPLEMENT
if( !proc.DiscardNode() )
{
std::cerr << "XXX: FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
return false;
}
else
std::cerr << "XXX: OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
break;
case WRL2_COLOR:
// XXX - IMPLEMENT
if( !proc.DiscardNode() )
{
std::cerr << "XXX: FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
return false;
}
else
std::cerr << "XXX: OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
break;
case WRL2_CONE:
// XXX - IMPLEMENT
if( !proc.DiscardNode() )
{
std::cerr << "XXX: FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
return false;
}
else
std::cerr << "XXX: OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
break;
case WRL2_COORDINATE:
// XXX - IMPLEMENT
if( !proc.DiscardNode() )
{
std::cerr << "XXX: FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
return false;
}
else
std::cerr << "XXX: OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
break;
case WRL2_CYLINDER:
// XXX - IMPLEMENT
if( !proc.DiscardNode() )
{
std::cerr << "XXX: FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
return false;
}
else
std::cerr << "XXX: OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
break;
case WRL2_ELEVATIONGRID:
// XXX - IMPLEMENT
if( !proc.DiscardNode() )
{
std::cerr << "XXX: FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
return false;
}
else
std::cerr << "XXX: OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
break;
case WRL2_EXTRUSION:
// XXX - IMPLEMENT
if( !proc.DiscardNode() )
{
std::cerr << "XXX: FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
return false;
}
else
std::cerr << "XXX: OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
break;
case WRL2_INDEXEDFACESET:
// XXX - IMPLEMENT
if( !proc.DiscardNode() )
{
std::cerr << "XXX: FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
return false;
}
else
std::cerr << "XXX: OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
break;
case WRL2_MATERIAL:
// XXX - IMPLEMENT
if( !proc.DiscardNode() )
{
std::cerr << "XXX: FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
return false;
}
else
std::cerr << "XXX: OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
break;
case WRL2_NORMAL:
// XXX - IMPLEMENT
if( !proc.DiscardNode() )
{
std::cerr << "XXX: FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
return false;
}
else
std::cerr << "XXX: OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
break;
case WRL2_SHAPE:
// XXX - IMPLEMENT
if( !proc.DiscardNode() )
{
std::cerr << "XXX: FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
return false;
}
else
std::cerr << "XXX: OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
break;
case WRL2_SPHERE:
// XXX - IMPLEMENT
if( !proc.DiscardNode() )
{
std::cerr << "XXX: FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
return false;
}
else
std::cerr << "XXX: OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
break;
case WRL2_TRANSFORM:
case WRL2_GROUP:
if( !readTransform( proc, aParent, aNode ) )
if( !proc.DiscardNode() )
{
std::cerr << "XXX: FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
return false;
}
else
std::cerr << "XXX: OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
//if( !readTransform( proc, aParent, aNode ) )
// return false;
break;

View File

@ -114,6 +114,7 @@ bool WRL2TRANSFORM::Read( WRLPROC& proc, WRL2BASE* aTopNode )
while( true )
{
if( proc.Peek() == '}' )
return true;
if( !proc.ReadName( glob ) )
{
@ -124,6 +125,15 @@ bool WRL2TRANSFORM::Read( WRLPROC& proc, WRL2BASE* aTopNode )
return false;
}
// expecting one of:
// center
// children
// rotation
// scale
// ScaleOrientation
// XXX - TO BE IMPLEMENTED
}
// XXX - TO BE IMPLEMENTED

View File

@ -159,16 +159,20 @@ bool WRLPROC::getRawLine( void )
if( !m_buf.empty() )
return true;
m_linepos = 0;
if( m_file.bad() )
{
m_error = "bad stream";
return false;
}
GETLINE;
m_linepos = 0;
if( m_file.eof() )
return false;
if( m_file.bad() && !m_file.eof() )
GETLINE;
if( m_file.bad() && m_buf.empty() )
return false;
if( VRML_V1 == m_fileVersion && !m_buf.empty() )
@ -198,7 +202,7 @@ bool WRLPROC::EatSpace( void )
m_buf.clear();
RETRY:
while( m_buf.empty() && !m_file.bad() )
while( m_buf.empty() && !m_file.bad() && !m_file.eof() )
getRawLine();
// buffer may be empty if we have reached EOF or encountered IO errors
@ -265,6 +269,10 @@ bool WRLPROC::ReadGlob( std::string& aGlob, bool* hasComma )
return true;
}
if( '{' == m_buf[m_linepos] || '}' == m_buf[m_linepos]
|| '[' == m_buf[m_linepos] || ']' == m_buf[m_linepos] )
return true;
aGlob.append( 1, m_buf[m_linepos++] );
}
@ -353,6 +361,7 @@ bool WRLPROC::DiscardNode( void )
ostr << ", column " << m_linepos;
m_error = ostr.str();
std::cerr << m_error << "\n";
return false;
}
@ -403,7 +412,7 @@ bool WRLPROC::DiscardNode( void )
// note: if we have a ']' we must skip it and test the next non-blank character;
// this ensures that we don't miss a '}' in cases where the braces are not
// separated by space. if we had proceeded to ReadGlob() we could have had a problem.
if( ']' == m_buf[m_linepos] )
if( ']' == m_buf[m_linepos] || '[' == m_buf[m_linepos] )
{
++m_linepos;
continue;
@ -518,7 +527,7 @@ bool WRLPROC::DiscardList( void )
// note: if we have a '}' we must skip it and test the next non-blank character;
// this ensures that we don't miss a ']' in cases where the braces are not
// separated by space. if we had proceeded to ReadGlob() we could have had a problem.
if( '}' == m_buf[m_linepos] )
if( '}' == m_buf[m_linepos] || '{' == m_buf[m_linepos] )
{
++m_linepos;
continue;

View File

@ -41,6 +41,7 @@
#include "plugins/3d/3d_plugin.h"
#include "plugins/3dapi/ifsg_all.h"
#include "wrlproc.h"
#include "vrml2_base.h"
#define PLUGIN_VRML_MAJOR 1
@ -185,7 +186,17 @@ SCENEGRAPH* Load( char const* aFileName )
if( proc.GetVRMLType() == VRML_V1 )
std::cout << "XXX: Processing VRML 1.0 file\n";
else
{
std::cout << "XXX: Processing VRML 2.0 file\n";
WRL2BASE* bp = new WRL2BASE;
if( !bp->Read( proc ) )
std::cout << "XXX: load failed\n";
else
std::cout << "XXX: load completed\n";
delete bp;
}
return NULL;
}