2016-01-01 05:05:14 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
2016-02-23 02:31:51 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <wx/log.h>
|
2016-01-01 05:05:14 +00:00
|
|
|
|
|
|
|
#include "vrml2_base.h"
|
|
|
|
#include "vrml2_faceset.h"
|
2016-01-02 01:21:02 +00:00
|
|
|
#include "vrml2_coords.h"
|
2016-01-06 04:34:14 +00:00
|
|
|
#include "vrml2_color.h"
|
2016-02-02 05:50:46 +00:00
|
|
|
#include "wrlfacet.h"
|
2016-01-02 01:21:02 +00:00
|
|
|
#include "plugins/3dapi/ifsg_all.h"
|
2016-01-01 05:05:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
WRL2FACESET::WRL2FACESET() : WRL2NODE()
|
|
|
|
{
|
|
|
|
setDefaults();
|
|
|
|
m_Type = WRL2_INDEXEDFACESET;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WRL2FACESET::WRL2FACESET( WRL2NODE* aParent ) : WRL2NODE()
|
|
|
|
{
|
|
|
|
setDefaults();
|
|
|
|
m_Type = WRL2_INDEXEDFACESET;
|
|
|
|
m_Parent = aParent;
|
|
|
|
|
|
|
|
if( NULL != m_Parent )
|
|
|
|
m_Parent->AddChildNode( this );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WRL2FACESET::~WRL2FACESET()
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 2 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << " * [INFO] Destroying IndexedFaceSet with " << m_Children.size();
|
|
|
|
ostr << " children, " << m_Refs.size() << " references and ";
|
|
|
|
ostr << m_BackPointers.size() << " backpointers";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WRL2FACESET::setDefaults( void )
|
|
|
|
{
|
|
|
|
color = NULL;
|
|
|
|
coord = NULL;
|
|
|
|
normal = NULL;
|
|
|
|
texCoord = NULL;
|
|
|
|
|
|
|
|
ccw = true;
|
|
|
|
colorPerVertex = true;
|
|
|
|
convex = true;
|
|
|
|
normalPerVertex = true;
|
|
|
|
solid = true;
|
|
|
|
|
2016-02-07 21:56:03 +00:00
|
|
|
creaseAngle = 0.733; // approx 42 degrees; this is larger than VRML spec.
|
|
|
|
creaseLimit = 0.74317; // cos( 0.733 )
|
2016-01-01 05:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRL2FACESET::checkNodeType( WRL2NODES aType )
|
|
|
|
{
|
|
|
|
// nodes must be one of:
|
|
|
|
// Color
|
|
|
|
// Coordinate
|
|
|
|
// Normal
|
|
|
|
// TextureCoordinate
|
|
|
|
|
|
|
|
switch( aType )
|
|
|
|
{
|
|
|
|
case WRL2_COLOR:
|
|
|
|
case WRL2_COORDINATE:
|
|
|
|
case WRL2_NORMAL:
|
|
|
|
case WRL2_TEXTURECOORDINATE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRL2FACESET::isDangling( void )
|
|
|
|
{
|
|
|
|
// this node is dangling unless it has a parent of type WRL2_SHAPE
|
|
|
|
|
|
|
|
if( NULL == m_Parent || m_Parent->GetNodeType() != WRL2_SHAPE )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRL2FACESET::AddRefNode( WRL2NODE* aNode )
|
|
|
|
{
|
|
|
|
if( NULL == aNode )
|
|
|
|
{
|
2016-01-02 03:41:54 +00:00
|
|
|
#ifdef DEBUG_VRML2
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] NULL passed for aNode";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
WRL2NODES type = aNode->GetNodeType();
|
|
|
|
|
|
|
|
if( !checkNodeType( type ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] bad file format; unexpected child node '";
|
|
|
|
ostr << aNode->GetNodeTypeName( type ) << "'";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( WRL2_COLOR == type )
|
|
|
|
{
|
|
|
|
if( NULL != color )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] bad file format; multiple color nodes";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
color = aNode;
|
|
|
|
return WRL2NODE::AddRefNode( aNode );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( WRL2_COORDINATE == type )
|
|
|
|
{
|
|
|
|
if( NULL != coord )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] bad file format; multiple coordinate nodes";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
coord = aNode;
|
|
|
|
return WRL2NODE::AddRefNode( aNode );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( WRL2_NORMAL == type )
|
|
|
|
{
|
|
|
|
if( NULL != normal )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] bad file format; multiple normal nodes";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
normal = aNode;
|
|
|
|
return WRL2NODE::AddRefNode( aNode );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( WRL2_TEXTURECOORDINATE != type )
|
|
|
|
{
|
2016-01-02 03:41:54 +00:00
|
|
|
#ifdef DEBUG_VRML2
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] unexpected code branch";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( NULL != texCoord )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] bad file format; multiple texCoord nodes";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
texCoord = aNode;
|
|
|
|
return WRL2NODE::AddRefNode( aNode );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRL2FACESET::AddChildNode( WRL2NODE* aNode )
|
|
|
|
{
|
|
|
|
if( NULL == aNode )
|
|
|
|
{
|
2016-01-02 03:41:54 +00:00
|
|
|
#ifdef DEBUG_VRML2
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] NULL passed for aNode";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
WRL2NODES type = aNode->GetNodeType();
|
|
|
|
|
|
|
|
if( !checkNodeType( type ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] bad file format; unexpected child node '";
|
|
|
|
ostr << aNode->GetNodeTypeName( type ) << "'";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( WRL2_COLOR == type )
|
|
|
|
{
|
|
|
|
if( NULL != color )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] bad file format; multiple color nodes";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
color = aNode;
|
|
|
|
return WRL2NODE::AddChildNode( aNode );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( WRL2_COORDINATE == type )
|
|
|
|
{
|
|
|
|
if( NULL != coord )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] bad file format; multiple coordinate nodes";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
coord = aNode;
|
|
|
|
return WRL2NODE::AddChildNode( aNode );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( WRL2_NORMAL == type )
|
|
|
|
{
|
|
|
|
if( NULL != normal )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] bad file format; multiple normal nodes";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
normal = aNode;
|
|
|
|
return WRL2NODE::AddChildNode( aNode );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( WRL2_TEXTURECOORDINATE != type )
|
|
|
|
{
|
2016-01-02 03:41:54 +00:00
|
|
|
#ifdef DEBUG_VRML2
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] unexpected code branch";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( NULL != texCoord )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] bad file format; multiple texCoord nodes";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
texCoord = aNode;
|
|
|
|
return WRL2NODE::AddChildNode( aNode );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool WRL2FACESET::Read( WRLPROC& proc, WRL2BASE* aTopNode )
|
|
|
|
{
|
|
|
|
size_t line, column;
|
|
|
|
proc.GetFilePosData( line, column );
|
|
|
|
|
|
|
|
char tok = proc.Peek();
|
|
|
|
|
|
|
|
if( proc.eof() )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] bad file format; unexpected eof at line ";
|
|
|
|
ostr << line << ", column " << column;
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( '{' != tok )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << proc.GetError() << "\n";
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] bad file format; expecting '{' but got '" << tok;
|
|
|
|
ostr << "' at line " << line << ", column " << column;
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
proc.Pop();
|
|
|
|
std::string glob;
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
|
|
|
if( proc.Peek() == '}' )
|
|
|
|
{
|
|
|
|
proc.Pop();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !proc.ReadName( glob ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << proc.GetError();
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// expecting one of:
|
|
|
|
// [node]
|
|
|
|
// color
|
|
|
|
// coord
|
|
|
|
// normal
|
|
|
|
// texCoord
|
|
|
|
// [bool]
|
|
|
|
// ccw
|
|
|
|
// colorPerVertex
|
|
|
|
// convex
|
|
|
|
// normalPerVertex
|
|
|
|
// solid
|
|
|
|
// [ vector<int> ]
|
|
|
|
// colorIndex
|
|
|
|
// coordIndex
|
|
|
|
// normalIndex;
|
|
|
|
// [float]
|
|
|
|
// creaseAngle
|
|
|
|
|
|
|
|
proc.GetFilePosData( line, column );
|
|
|
|
|
|
|
|
if( !glob.compare( "ccw" ) )
|
|
|
|
{
|
|
|
|
if( !proc.ReadSFBool( ccw ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] invalid ccw at line " << line << ", column ";
|
|
|
|
ostr << column << "\n";
|
|
|
|
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
|
|
|
ostr << " * [INFO] message: '" << proc.GetError() << "'";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !glob.compare( "colorPerVertex" ) )
|
|
|
|
{
|
|
|
|
if( !proc.ReadSFBool( colorPerVertex ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] invalid colorPerVertex at line " << line << ", column ";
|
|
|
|
ostr << column << "\n";
|
|
|
|
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
|
|
|
ostr << " * [INFO] message: '" << proc.GetError() << "'";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !glob.compare( "convex" ) )
|
|
|
|
{
|
|
|
|
if( !proc.ReadSFBool( convex ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] invalid convex at line " << line << ", column ";
|
|
|
|
ostr << column << "\n";
|
|
|
|
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
|
|
|
ostr << " * [INFO] message: '" << proc.GetError() << "'";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !glob.compare( "normalPerVertex" ) )
|
|
|
|
{
|
|
|
|
if( !proc.ReadSFBool( normalPerVertex ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] invalid normalPerVertex at line " << line << ", column ";
|
|
|
|
ostr << column << "\n";
|
|
|
|
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
|
|
|
ostr << " * [INFO] message: '" << proc.GetError() << "'";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !glob.compare( "solid" ) )
|
|
|
|
{
|
|
|
|
if( !proc.ReadSFBool( solid ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] invalid solid at line " << line << ", column ";
|
|
|
|
ostr << column << "\n";
|
|
|
|
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
|
|
|
ostr << " * [INFO] message: '" << proc.GetError() << "'";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !glob.compare( "creaseAngle" ) )
|
|
|
|
{
|
|
|
|
if( !proc.ReadSFFloat( creaseAngle ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] invalid creaseAngle at line " << line << ", column ";
|
|
|
|
ostr << column << "\n";
|
|
|
|
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
|
|
|
ostr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-02-02 05:50:46 +00:00
|
|
|
|
|
|
|
if( creaseAngle < 0.0 )
|
|
|
|
creaseAngle = 0.0;
|
|
|
|
else if( creaseAngle > M_PI_2 )
|
|
|
|
creaseAngle = M_PI_2;
|
|
|
|
|
|
|
|
creaseLimit = cosf( creaseAngle );
|
2016-01-01 05:05:14 +00:00
|
|
|
}
|
|
|
|
else if( !glob.compare( "colorIndex" ) )
|
|
|
|
{
|
|
|
|
if( !proc.ReadMFInt( colorIndex ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] invalid colorIndex at line " << line << ", column ";
|
|
|
|
ostr << column << "\n";
|
|
|
|
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
|
|
|
ostr << " * [INFO] message: '" << proc.GetError() << "'";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !glob.compare( "coordIndex" ) )
|
|
|
|
{
|
|
|
|
if( !proc.ReadMFInt( coordIndex ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] invalid coordIndex at line " << line << ", column ";
|
|
|
|
ostr << column << "\n";
|
|
|
|
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
|
|
|
ostr << " * [INFO] message: '" << proc.GetError() << "'";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !glob.compare( "normalIndex" ) )
|
|
|
|
{
|
|
|
|
if( !proc.ReadMFInt( normalIndex ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] invalid normalIndex at line " << line << ", column ";
|
|
|
|
ostr << column << "\n";
|
|
|
|
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
|
|
|
ostr << " * [INFO] message: '" << proc.GetError() << "'";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !glob.compare( "color" ) )
|
|
|
|
{
|
|
|
|
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] could not read color node information";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !glob.compare( "coord" ) )
|
|
|
|
{
|
|
|
|
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] could not read coord node information";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !glob.compare( "normal" ) )
|
|
|
|
{
|
|
|
|
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] could not read normal node information";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !glob.compare( "texCoord" ) )
|
|
|
|
{
|
|
|
|
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] could not read texCoord node information";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-02 22:57:41 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] bad IndexedFaceSet at line " << line << ", column ";
|
|
|
|
ostr << column << "\n";
|
|
|
|
ostr << " * [INFO] file: '" << proc.GetFileName() << "'";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-01 05:05:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} // while( true ) -- reading contents of IndexedFaceSet{}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-01-01 07:55:43 +00:00
|
|
|
|
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
SGNODE* WRL2FACESET::TranslateToSG( SGNODE* aParent )
|
2016-01-01 07:55:43 +00:00
|
|
|
{
|
2016-01-02 01:21:02 +00:00
|
|
|
S3D::SGTYPES ptype = S3D::GetSGNodeType( aParent );
|
|
|
|
|
|
|
|
if( NULL != aParent && ptype != S3D::SGTYPE_SHAPE )
|
|
|
|
{
|
2016-01-02 03:41:54 +00:00
|
|
|
#ifdef DEBUG_VRML2
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] IndexedFaceSet does not have a Shape parent (parent ID: ";
|
|
|
|
ostr << ptype << ")";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-02 01:21:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-07 04:43:32 +00:00
|
|
|
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 2 )
|
2016-02-23 02:31:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << " * [INFO] Translating IndexedFaceSet with " << m_Children.size();
|
|
|
|
ostr << " children, " << m_Refs.size() << " references, ";
|
|
|
|
ostr << m_BackPointers.size() << " backpointers and ";
|
|
|
|
ostr << coordIndex.size() << " coord indices";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-07 04:43:32 +00:00
|
|
|
#endif
|
|
|
|
|
2016-01-02 01:21:02 +00:00
|
|
|
if( m_sgNode )
|
|
|
|
{
|
2016-01-04 07:10:15 +00:00
|
|
|
if( NULL != aParent )
|
2016-01-02 01:21:02 +00:00
|
|
|
{
|
2016-01-04 07:10:15 +00:00
|
|
|
if( NULL == S3D::GetSGNodeParent( m_sgNode )
|
|
|
|
&& !S3D::AddSGNodeChild( aParent, m_sgNode ) )
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else if( aParent != S3D::GetSGNodeParent( m_sgNode )
|
|
|
|
&& !S3D::AddSGNodeRef( aParent, m_sgNode ) )
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-01-02 01:21:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_sgNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t vsize = coordIndex.size();
|
|
|
|
|
|
|
|
if( NULL == coord || vsize < 3 )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
WRLVEC3F* pcoords;
|
|
|
|
size_t coordsize;
|
|
|
|
((WRL2COORDS*) coord)->GetCoords( pcoords, coordsize );
|
|
|
|
|
|
|
|
if( coordsize < 3 )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// check that all indices are valid
|
2016-02-02 05:50:46 +00:00
|
|
|
for( size_t idx = 0; idx < vsize; ++idx )
|
2016-01-02 01:21:02 +00:00
|
|
|
{
|
|
|
|
if( coordIndex[idx] < 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( coordIndex[idx] >= (int)coordsize )
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
SHAPE lShape;
|
|
|
|
FACET* fp = NULL;
|
|
|
|
size_t iCoord;
|
|
|
|
int idx; // coordinate index
|
|
|
|
size_t cidx = 0; // color index
|
|
|
|
SGCOLOR pc1;
|
2016-01-02 01:21:02 +00:00
|
|
|
|
2016-01-06 04:34:14 +00:00
|
|
|
if( NULL == color )
|
2016-01-02 01:21:02 +00:00
|
|
|
{
|
2016-02-02 05:50:46 +00:00
|
|
|
// no per-vertex colors; we can save a few CPU cycles
|
|
|
|
for( iCoord = 0; iCoord < vsize; ++iCoord )
|
2016-01-06 04:34:14 +00:00
|
|
|
{
|
2016-02-02 05:50:46 +00:00
|
|
|
idx = coordIndex[iCoord];
|
2016-01-08 05:23:42 +00:00
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
if( idx < 0 )
|
2016-01-06 04:34:14 +00:00
|
|
|
{
|
2016-02-02 05:50:46 +00:00
|
|
|
if( NULL != fp )
|
2016-01-06 04:34:14 +00:00
|
|
|
{
|
2016-02-02 05:50:46 +00:00
|
|
|
if( fp->HasMinPoints() )
|
|
|
|
fp = NULL;
|
|
|
|
else
|
|
|
|
fp->Init();
|
2016-01-06 04:34:14 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
continue;
|
2016-01-06 04:34:14 +00:00
|
|
|
}
|
2016-01-08 05:23:42 +00:00
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
// if the coordinate is bad then skip it
|
|
|
|
if( idx >= (int)coordsize )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( NULL == fp )
|
|
|
|
fp = lShape.NewFacet();
|
|
|
|
|
|
|
|
// push the vertex value and index
|
|
|
|
fp->AddVertex( pcoords[idx], idx );
|
2016-01-06 04:34:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WRL2COLOR* cn = (WRL2COLOR*) color;
|
|
|
|
WRLVEC3F tc;
|
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
for( iCoord = 0; iCoord < vsize; ++iCoord )
|
2016-01-02 01:21:02 +00:00
|
|
|
{
|
2016-02-02 05:50:46 +00:00
|
|
|
idx = coordIndex[iCoord];
|
2016-01-06 05:51:29 +00:00
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
if( idx < 0 )
|
2016-01-06 05:51:29 +00:00
|
|
|
{
|
2016-02-02 05:50:46 +00:00
|
|
|
if( NULL != fp )
|
2016-01-06 05:51:29 +00:00
|
|
|
{
|
2016-02-02 05:50:46 +00:00
|
|
|
if( fp->HasMinPoints() )
|
|
|
|
fp = NULL;
|
|
|
|
else
|
|
|
|
fp->Init();
|
2016-01-06 05:51:29 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
if( !colorPerVertex )
|
|
|
|
++cidx;
|
2016-01-06 05:51:29 +00:00
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
continue;
|
2016-01-06 05:51:29 +00:00
|
|
|
}
|
2016-01-02 01:21:02 +00:00
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
// if the coordinate is bad then skip it
|
|
|
|
if( idx >= (int)coordsize )
|
|
|
|
continue;
|
2016-01-06 05:51:29 +00:00
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
if( NULL == fp )
|
|
|
|
fp = lShape.NewFacet();
|
2016-01-06 04:34:14 +00:00
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
// push the vertex value and index
|
|
|
|
fp->AddVertex( pcoords[idx], idx );
|
2016-01-02 01:21:02 +00:00
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
// push the color if appropriate
|
|
|
|
if( !colorPerVertex )
|
2016-01-06 04:34:14 +00:00
|
|
|
{
|
2016-01-07 00:24:11 +00:00
|
|
|
if( colorIndex.empty() )
|
|
|
|
{
|
2016-02-02 05:50:46 +00:00
|
|
|
cn->GetColor( cidx, tc.x, tc.y, tc.z );
|
2016-01-07 00:24:11 +00:00
|
|
|
pc1.SetColor( tc.x, tc.y, tc.z );
|
2016-02-02 05:50:46 +00:00
|
|
|
fp->AddColor( pc1 );
|
2016-01-07 00:24:11 +00:00
|
|
|
}
|
2016-01-06 05:51:29 +00:00
|
|
|
else
|
2016-01-06 04:34:14 +00:00
|
|
|
{
|
2016-02-02 05:50:46 +00:00
|
|
|
if( cidx < colorIndex.size() )
|
|
|
|
cn->GetColor( colorIndex[cidx], tc.x, tc.y, tc.z );
|
2016-01-06 05:51:29 +00:00
|
|
|
else
|
2016-02-02 05:50:46 +00:00
|
|
|
cn->GetColor( colorIndex.back(), tc.x, tc.y, tc.z );
|
2016-01-06 05:51:29 +00:00
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
pc1.SetColor( tc.x, tc.y, tc.z );
|
|
|
|
fp->AddColor( pc1 );
|
2016-01-06 04:34:14 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-02 05:50:46 +00:00
|
|
|
else
|
2016-01-02 01:21:02 +00:00
|
|
|
{
|
2016-02-02 05:50:46 +00:00
|
|
|
if( colorIndex.empty() )
|
2016-01-02 01:21:02 +00:00
|
|
|
{
|
2016-02-02 05:50:46 +00:00
|
|
|
cn->GetColor( idx, tc.x, tc.y, tc.z );
|
|
|
|
pc1.SetColor( tc.x, tc.y, tc.z );
|
|
|
|
fp->AddColor( pc1 );
|
2016-01-02 01:21:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-02 05:50:46 +00:00
|
|
|
if( iCoord < colorIndex.size() )
|
|
|
|
cn->GetColor( colorIndex[iCoord], tc.x, tc.y, tc.z );
|
|
|
|
else
|
|
|
|
cn->GetColor( colorIndex.back(), tc.x, tc.y, tc.z );
|
2016-01-02 01:21:02 +00:00
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
pc1.SetColor( tc.x, tc.y, tc.z );
|
|
|
|
fp->AddColor( pc1 );
|
|
|
|
}
|
2016-01-02 01:21:02 +00:00
|
|
|
}
|
2016-02-02 05:50:46 +00:00
|
|
|
}
|
2016-01-02 01:21:02 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
SGNODE* np = NULL;
|
2016-01-02 01:21:02 +00:00
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
if( ccw )
|
|
|
|
np = lShape.CalcShape( aParent, NULL, ORD_CCW, creaseLimit, true );
|
2016-01-02 01:21:02 +00:00
|
|
|
else
|
2016-02-02 05:50:46 +00:00
|
|
|
np = lShape.CalcShape( aParent, NULL, ORD_CLOCKWISE, creaseLimit, true );
|
2016-01-02 01:21:02 +00:00
|
|
|
|
2016-02-02 05:50:46 +00:00
|
|
|
return np;
|
2016-01-01 07:55:43 +00:00
|
|
|
}
|
2016-01-03 03:55:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
void WRL2FACESET::unlinkChildNode( const WRL2NODE* aNode )
|
|
|
|
{
|
|
|
|
if( NULL == aNode )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( aNode->GetParent() == this )
|
|
|
|
{
|
|
|
|
if( aNode == color )
|
|
|
|
color = NULL;
|
|
|
|
else if( aNode == coord )
|
|
|
|
coord = NULL;
|
|
|
|
else if( aNode == normal )
|
|
|
|
normal = NULL;
|
|
|
|
else if( aNode == texCoord )
|
|
|
|
texCoord = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
WRL2NODE::unlinkChildNode( aNode );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WRL2FACESET::unlinkRefNode( const WRL2NODE* aNode )
|
|
|
|
{
|
|
|
|
if( NULL == aNode )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( aNode->GetParent() != this )
|
|
|
|
{
|
|
|
|
if( aNode == color )
|
|
|
|
color = NULL;
|
|
|
|
else if( aNode == coord )
|
|
|
|
coord = NULL;
|
|
|
|
else if( aNode == normal )
|
|
|
|
normal = NULL;
|
|
|
|
else if( aNode == texCoord )
|
|
|
|
texCoord = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
WRL2NODE::unlinkRefNode( aNode );
|
|
|
|
return;
|
|
|
|
}
|
2016-01-06 04:34:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool WRL2FACESET::HasColors( void )
|
|
|
|
{
|
|
|
|
if( NULL == color )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return ((WRL2COLOR*) color)->HasColors();
|
|
|
|
}
|