Work in progress: VRML1 plugin

This commit is contained in:
Cirilo Bernardo 2016-01-05 18:55:54 +11:00
parent 79e0564622
commit 9f9f146cd9
11 changed files with 886 additions and 48 deletions

View File

@ -1,5 +1,6 @@
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/v1
${CMAKE_CURRENT_SOURCE_DIR}/v2
)
@ -23,6 +24,8 @@ add_library( s3d_plugin_vrml MODULE
v1/vrml1_node.cpp
v1/vrml1_base.cpp
v1/vrml1_separator.cpp
v1/vrml1_material.cpp
v1/vrml1_matbinding.cpp
)
target_link_libraries( s3d_plugin_vrml kicad_3dsg ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} )

View File

@ -25,6 +25,8 @@
#include "vrml1_base.h"
#include "vrml1_separator.h"
#include "vrml1_material.h"
#include "vrml1_matbinding.h"
#include "plugins/3dapi/ifsg_all.h"
@ -123,19 +125,82 @@ bool WRL1BASE::Read( WRLPROC& proc )
{
#ifdef DEBUG_VRML1
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] no open file or file is not a VRML2 file\n";
std::cerr << " * [BUG] no open file or file is not a VRML1 file\n";
#endif
return false;
}
WRL1NODE* node = NULL;
std::string glob;
WRL1NODES ntype;
while( ReadNode( proc, this, &node ) && !proc.eof() );
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
if( !proc.eof() )
{
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << proc.GetError() << "\n";
}
#endif
if( proc.eof() )
return true;
return false;
}
return false;
// Process node name: only Separator, Switch and DEF are acceptable;
// WWWAnchor and LOD will not be supported
if( !glob.compare( "DEF" ) )
{
// read the name and discard it; we must not add it to the dictionary
// because that invites the possibility of a circular reference
for( int i = 0; i < 2; ++i )
{
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << proc.GetError() << "\n";
#endif
return false;
}
}
}
ntype = getNodeTypeID( glob );
size_t line = 0;
size_t column = 0;
proc.GetFilePosData( line, column );
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
std::cerr << " * [INFO] Processing node '" << glob << "' ID: " << ntype << "\n";
#endif
if( ntype != WRL1_SEPARATOR && ntype != WRL1_SWITCH )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] bad file - top node is not a Separator or Switch\n";
#endif
return false;
}
switch( ntype )
{
case WRL1_SEPARATOR:
if( !readSeparator( proc, this, NULL ) )
return false;
break;
default:
if( !readSwitch( proc, this, NULL ) )
return false;
}
return true;
}
@ -340,9 +405,9 @@ bool WRL1BASE::ReadNode( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode )
switch( ntype )
{
//
// items to be implemented:
//
//
// items to be implemented:
//
case WRL1_SEPARATOR:
if( !readSeparator( proc, aParent, aNode ) )
@ -350,6 +415,27 @@ bool WRL1BASE::ReadNode( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode )
break;
case WRL1_SWITCH:
if( !readSwitch( proc, aParent, aNode ) )
return false;
break;
case WRL1_MATERIAL:
if( !readMaterial( proc, aParent, aNode ) )
return false;
break;
case WRL1_MATERIALBINDING:
if( !readMatBinding( proc, aParent, aNode ) )
return false;
break;
//
// items not implemented or for optional future implementation:
//
@ -409,12 +495,90 @@ bool WRL1BASE::readSeparator( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode
}
bool WRL1BASE::readSwitch( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode )
{
if( NULL != aNode )
*aNode = NULL;
return false;
// XXX - TO BE IMPLEMENTED
/*
WRL1SWITCH* np = new WRL1SWITCH( m_dictionary, aParent );
if( !np->Read( proc, this ) )
{
delete np;
return false;
}
if( NULL != aNode )
*aNode = (WRL1NODE*) np;
return true;
*/
}
bool WRL1BASE::readMaterial( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode )
{
if( NULL != aNode )
*aNode = NULL;
WRL1MATERIAL* np = new WRL1MATERIAL( m_dictionary, aParent );
if( !np->Read( proc, this ) )
{
delete np;
return false;
}
if( NULL != aNode )
*aNode = (WRL1NODE*) np;
return true;
}
bool WRL1BASE::readMatBinding( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode )
{
if( NULL != aNode )
*aNode = NULL;
WRL1MATBINDING* np = new WRL1MATBINDING( m_dictionary, aParent );
if( !np->Read( proc, this ) )
{
delete np;
return false;
}
if( NULL != aNode )
*aNode = (WRL1NODE*) np;
return true;
}
SGNODE* WRL1BASE::TranslateToSG( SGNODE* aParent, bool calcNormals )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
std::cerr << " * [INFO] Translating VRML1 Base with " << m_Items.size();
std::cerr << " items\n";
#endif
if( m_Items.empty() )
return NULL;
// XXX - TO BE IMPLEMENTED
if( m_Items.size() != 1 )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << " * [INFO] Bad VRML file, >1 top level transform (";
std::cerr << m_Items.size() << ")\n";
#endif
return NULL;
return NULL;
}
return (*m_Items.begin())->TranslateToSG( NULL, true );
}

View File

@ -52,6 +52,9 @@ private:
bool implementDef( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode );
bool readSeparator( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode );
bool readSwitch( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode );
bool readMaterial( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode );
bool readMatBinding( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode );
std::map< std::string, WRL1INLINE* > m_inlineModels;

View File

@ -0,0 +1,222 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <iostream>
#include "vrml1_base.h"
#include "vrml1_matbinding.h"
#include "plugins/3dapi/ifsg_all.h"
WRL1MATBINDING::WRL1MATBINDING( NAMEREGISTER* aDictionary ) : WRL1NODE( aDictionary )
{
m_binding = BIND_OVERALL;
m_Type = WRL1_MATERIALBINDING;
return;
}
WRL1MATBINDING::WRL1MATBINDING( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
WRL1NODE( aDictionary )
{
m_binding = BIND_OVERALL;
m_Type = WRL1_MATERIALBINDING;
m_Parent = aParent;
if( NULL != m_Parent )
m_Parent->AddChildNode( this );
return;
}
WRL1MATBINDING::~WRL1MATBINDING()
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
std::cerr << " * [INFO] Destroying MaterialBinding node\n";
#endif
return;
}
bool WRL1MATBINDING::AddRefNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] AddRefNode is not applicable\n";
#endif
return false;
}
bool WRL1MATBINDING::AddChildNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] AddChildNode is not applicable\n";
#endif
return false;
}
bool WRL1MATBINDING::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( NULL == aTopNode )
{
#ifdef DEBUG_VRML1
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] aTopNode is NULL\n";
#endif
return false;
}
size_t line, column;
proc.GetFilePosData( line, column );
char tok = proc.Peek();
if( proc.eof() )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] bad file format; unexpected eof at line ";
std::cerr << line << ", column " << column << "\n";
#endif
return false;
}
if( '{' != tok )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << proc.GetError() << "\n";
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] bad file format; expecting '{' but got '" << tok;
std::cerr << "' at line " << line << ", column " << column << "\n";
#endif
return false;
}
proc.Pop();
std::string glob;
while( true )
{
if( proc.Peek() == '}' )
{
proc.Pop();
break;
}
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << proc.GetError() << "\n";
#endif
return false;
}
// expecting one of:
// DEFAULT
// OVERALL
// PER_PART
// PER_PART_INDEXED
// PER_FACE
// PER_FACE_INDEXED
// PER_VERTEX
// PER_VERTEX_INDEXED
proc.GetFilePosData( line, column );
if( !glob.compare( "DEFAULT" ) )
{
m_binding = BIND_DEFAULT;
}
else if( !glob.compare( "OVERALL" ) )
{
m_binding = BIND_OVERALL;
}
else if( !glob.compare( "PER_PART" ) )
{
m_binding = BIND_PER_PART;
}
else if( !glob.compare( "PER_PART_INDEXED" ) )
{
m_binding = BIND_PER_PART_INDEXED;
}
else if( !glob.compare( "PER_FACE" ) )
{
m_binding = BIND_PER_FACE;
}
else if( !glob.compare( "PER_FACE_INDEXED" ) )
{
m_binding = BIND_PER_FACE_INDEXED;
}
else if( !glob.compare( "PER_VERTEX" ) )
{
m_binding = BIND_PER_VERTEX;
}
else if( !glob.compare( "PER_VERTEX_INDEXED" ) )
{
m_binding = BIND_PER_VERTEX_INDEXED;
}
else
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] bad Material at line " << line << ", column ";
std::cerr << column << "\n";
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
#endif
m_binding = BIND_OVERALL;
}
} // while( true ) -- reading contents of MaterialBinding{}
return true;
}
SGNODE* WRL1MATBINDING::TranslateToSG( SGNODE* aParent, bool calcNormals )
{
if( m_Parent )
{
WRL1STATUS* cp = m_Parent->GetCurrentSettings();
if( NULL != cp )
cp->matbind = m_binding;
}
return NULL;
}

View File

@ -0,0 +1,58 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file vrml1_matbinding.h
*/
#ifndef VRML1_MATBINDING_H
#define VRML1_MATBINDING_H
#include <vector>
#include "vrml1_node.h"
class WRL1BASE;
class SGNODE;
/**
* Class WRL1MATBINDING
*/
class WRL1MATBINDING : public WRL1NODE
{
private:
WRL1_BINDING m_binding;
public:
WRL1MATBINDING( NAMEREGISTER* aDictionary );
WRL1MATBINDING( NAMEREGISTER* aDictionary, WRL1NODE* aParent );
virtual ~WRL1MATBINDING();
// functions inherited from WRL1NODE
bool Read( WRLPROC& proc, WRL1BASE* aTopNode );
bool AddRefNode( WRL1NODE* aNode );
bool AddChildNode( WRL1NODE* aNode );
SGNODE* TranslateToSG( SGNODE* aParent, bool calcNormals );
};
#endif // VRML1_MATBINDING_H

View File

@ -0,0 +1,299 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <iostream>
#include "vrml1_base.h"
#include "vrml1_material.h"
#include "plugins/3dapi/ifsg_all.h"
WRL1MATERIAL::WRL1MATERIAL( NAMEREGISTER* aDictionary ) : WRL1NODE( aDictionary )
{
setDefaults();
m_Type = WRL1_MATERIAL;
return;
}
WRL1MATERIAL::WRL1MATERIAL( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
WRL1NODE( aDictionary )
{
setDefaults();
m_Type = WRL1_MATERIAL;
m_Parent = aParent;
if( NULL != m_Parent )
m_Parent->AddChildNode( this );
return;
}
WRL1MATERIAL::~WRL1MATERIAL()
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
std::cerr << " * [INFO] Destroying Material node\n";
#endif
return;
}
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 );
return;
}
bool WRL1MATERIAL::AddRefNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] AddRefNode is not applicable\n";
#endif
return false;
}
bool WRL1MATERIAL::AddChildNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] AddChildNode is not applicable\n";
#endif
return false;
}
bool WRL1MATERIAL::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( NULL == aTopNode )
{
#ifdef DEBUG_VRML1
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] aTopNode is NULL\n";
#endif
return false;
}
size_t line, column;
proc.GetFilePosData( line, column );
char tok = proc.Peek();
if( proc.eof() )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] bad file format; unexpected eof at line ";
std::cerr << line << ", column " << column << "\n";
#endif
return false;
}
if( '{' != tok )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << proc.GetError() << "\n";
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] bad file format; expecting '{' but got '" << tok;
std::cerr << "' at line " << line << ", column " << column << "\n";
#endif
return false;
}
proc.Pop();
std::string glob;
while( true )
{
if( proc.Peek() == '}' )
{
proc.Pop();
break;
}
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << proc.GetError() << "\n";
#endif
return false;
}
// expecting one of:
// ambientColor
// diffuseColor
// emissiveColor
// shininess
// specularColor
// transparency
proc.GetFilePosData( line, column );
if( !glob.compare( "specularColor" ) )
{
if( !proc.ReadMFVec3f( specularColor ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] invalid specularColor at line " << line << ", column ";
std::cerr << column << "\n";
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
#endif
return false;
}
}
else if( !glob.compare( "diffuseColor" ) )
{
if( !proc.ReadMFVec3f( diffuseColor ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] invalid diffuseColor at line " << line << ", column ";
std::cerr << column << "\n";
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
#endif
return false;
}
}
else if( !glob.compare( "emissiveColor" ) )
{
if( !proc.ReadMFVec3f( emissiveColor ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] invalid emissiveColor at line " << line << ", column ";
std::cerr << column << "\n";
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
#endif
return false;
}
}
else if( !glob.compare( "shininess" ) )
{
if( !proc.ReadMFFloat( shininess ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] invalid shininess at line " << line << ", column ";
std::cerr << column << "\n";
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
#endif
return false;
}
}
else if( !glob.compare( "transparency" ) )
{
if( !proc.ReadMFFloat( transparency ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] invalid transparency at line " << line << ", column ";
std::cerr << column << "\n";
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
#endif
return false;
}
}
else if( !glob.compare( "ambientColor" ) )
{
if( !proc.ReadMFVec3f( ambientColor ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] invalid ambientColor at line " << line << ", column ";
std::cerr << column << "\n";
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
#endif
return false;
}
}
else
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] bad Material at line " << line << ", column ";
std::cerr << column << "\n";
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
#endif
return false;
}
} // while( true ) -- reading contents of Material{}
return true;
}
SGNODE* WRL1MATERIAL::TranslateToSG( SGNODE* aParent, bool calcNormals )
{
if( m_Parent )
{
WRL1STATUS* cp = m_Parent->GetCurrentSettings();
if( NULL != cp )
cp->mat = this;
}
return NULL;
}

View File

@ -0,0 +1,67 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file vrml1_material.h
*/
#ifndef VRML1_MATERIAL_H
#define VRML1_MATERIAL_H
#include <vector>
#include "vrml1_node.h"
class WRL1BASE;
class SGNODE;
/**
* Class WRL1MATERIAL
*/
class WRL1MATERIAL : public WRL1NODE
{
private:
std::vector< WRLVEC3F > diffuseColor;
std::vector< WRLVEC3F > emissiveColor;
std::vector< WRLVEC3F > specularColor;
std::vector< WRLVEC3F > ambientColor;
std::vector< float > shininess;
std::vector< float > transparency;
void setDefaults( void );
public:
WRL1MATERIAL( NAMEREGISTER* aDictionary );
WRL1MATERIAL( NAMEREGISTER* aDictionary, WRL1NODE* aParent );
virtual ~WRL1MATERIAL();
// functions inherited from WRL1NODE
bool Read( WRLPROC& proc, WRL1BASE* aTopNode );
bool AddRefNode( WRL1NODE* aNode );
bool AddChildNode( WRL1NODE* aNode );
SGNODE* TranslateToSG( SGNODE* aParent, bool calcNormals );
// XXX - requires a function to create/retrieve a color
};
#endif // VRML1_MATERIAL_H

View File

@ -57,6 +57,7 @@ public:
class WRL1BASE;
class WRL1MATERIAL;
class SGNODE;
@ -64,19 +65,16 @@ class SGNODE;
// during translation / rendering
struct WRL1STATUS
{
// XXX - as much as possible do not use pointers and if
// pointers are necessary, use the specialized rather
// than base pointers
// material
WRL1NODE* mat;
// material binding
WRL1NODE* matbind;
WRL1MATERIAL* mat;
// normals
WRL1NODE* norm;
// normal binding
WRL1NODE* normbind;
// coordinate3
WRL1NODE* coord;
// material binding
WRL1_BINDING matbind;
// normal binding
WRL1_BINDING normbind;
// transform
glm::dmat4 txmatrix;
@ -89,9 +87,9 @@ struct WRL1STATUS
void Init()
{
mat = NULL;
matbind = NULL;
matbind = BIND_OVERALL;
norm = NULL;
normbind = NULL;
normbind = BIND_DEFAULT;
coord = NULL;
txmatrix = glm::scale( glm::dmat4( 1.0 ), glm::dvec3( 1.0 ) );
return;

View File

@ -51,7 +51,7 @@ WRL1SEPARATOR::WRL1SEPARATOR( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
WRL1SEPARATOR::~WRL1SEPARATOR()
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
std::cerr << " * [INFO] Destroying Transform with " << m_Children.size();
std::cerr << " * [INFO] Destroying Separator with " << m_Children.size();
std::cerr << " children, " << m_Refs.size() << " references and ";
std::cerr << m_BackPointers.size() << " backpointers\n";
#endif
@ -62,23 +62,6 @@ WRL1SEPARATOR::~WRL1SEPARATOR()
// functions inherited from WRL1NODE
bool WRL1SEPARATOR::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
/*
* Structure of a Transform node (p.120):
*
* Transform {
* eventIn MFNode addChildren
* eventIn MFNode removeChildren
* exposedField SFVec3f center 0 0 0
* exposedField MFNode children []
* exposedField SFRotation rotation 0 0 1 0
* exposedField SFVec3f scale 1 1 1
* exposedField SFRotation scaleOrientation 0 0 1 0
* exposedField SFVec3f translation 0 0 0
* field SFVec3f bboxCenter 0 0 0
* field SFVec3f bboxSize 0 0 0
* }
*/
if( NULL == aTopNode )
{
#ifdef DEBUG_VRML1
@ -150,14 +133,16 @@ bool WRL1SEPARATOR::Read( WRLPROC& proc, WRL1BASE* aTopNode )
SGNODE* WRL1SEPARATOR::TranslateToSG( SGNODE* aParent, bool calcNormals )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
std::cerr << " * [INFO] Translating Separator with " << m_Children.size();
std::cerr << " children, " << m_Refs.size() << " references and ";
std::cerr << m_BackPointers.size() << " backpointers (total ";
std::cerr << m_Items.size() << " items)\n";
#endif
return NULL;
/*
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
std::cerr << " * [INFO] Translating Transform with " << m_Children.size();
std::cerr << " children, " << m_Refs.size() << " references and ";
std::cerr << m_BackPointers.size() << " backpointers\n";
#endif
if( m_Children.empty() && m_Refs.empty() )
return NULL;
@ -168,7 +153,7 @@ SGNODE* WRL1SEPARATOR::TranslateToSG( SGNODE* aParent, bool calcNormals )
{
#ifdef DEBUG_VRML1
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] Transform does not have a Transform parent (parent ID: ";
std::cerr << " * [BUG] Separator does not have a Separator parent (parent ID: ";
std::cerr << ptype << ")\n";
#endif
@ -200,10 +185,10 @@ SGNODE* WRL1SEPARATOR::TranslateToSG( SGNODE* aParent, bool calcNormals )
std::list< WRL1NODE* >::iterator eC = m_Children.end();
WRL1NODES type;
// Include only the following in a Transform node:
// Include only the following in a Separator node:
// Shape
// Switch
// Transform
// Separator
// Inline
bool test = false; // set to true if there are any subnodes for display

View File

@ -41,6 +41,7 @@
#include "plugins/3d/3d_plugin.h"
#include "plugins/3dapi/ifsg_all.h"
#include "wrlproc.h"
#include "vrml1_base.h"
#include "vrml2_base.h"
@ -189,12 +190,36 @@ SCENEGRAPH* Load( char const* aFileName )
#ifdef DEBUG
std::cout << " * [INFO] Processing VRML 1.0 file\n";
#endif
WRL1BASE* bp = new WRL1BASE;
// allow Inline{} files to be included
bp->SetEnableInline( true );
if( !bp->Read( proc ) )
{
#ifdef DEBUG
std::cout << " * [INFO] load failed\n";
#endif
}
else
{
#ifdef DEBUG
std::cout << " * [INFO] load completed\n";
#endif
// for now we recalculate all normals per-vertex per-face
scene = (SCENEGRAPH*)bp->TranslateToSG( NULL, true );
}
delete bp;
}
else
{
#ifdef DEBUG
std::cout << " * [INFO] Processing VRML 2.0 file\n";
#endif
WRL2BASE* bp = new WRL2BASE;
// allow Inline{} files to be included
@ -212,7 +237,7 @@ SCENEGRAPH* Load( char const* aFileName )
std::cout << " * [INFO] load completed\n";
#endif
// XXX - for now we recalculate all normals per-vertex per-facet
// for now we recalculate all normals per-vertex per-face
scene = (SCENEGRAPH*)bp->TranslateToSG( NULL, true );
}

View File

@ -86,6 +86,20 @@ enum WRL1NODES
WRL1_END = WRL1_INVALID
};
// VRML1 Material/Normal Binding values
enum WRL1_BINDING
{
BIND_DEFAULT = 0,
BIND_OVERALL,
BIND_PER_PART,
BIND_PER_PART_INDEXED,
BIND_PER_FACE,
BIND_PER_FACE_INDEXED,
BIND_PER_VERTEX,
BIND_PER_VERTEX_INDEXED,
BIND_END
};
// VRML2 Node Types
// These are used to look up node names and to quickly
// determine what routine to invoke to read a section of