2016-01-05 21:29:13 +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 00:20:34 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <wx/log.h>
|
2016-01-05 21:29:13 +00:00
|
|
|
|
|
|
|
#include "vrml1_base.h"
|
|
|
|
#include "vrml1_faceset.h"
|
|
|
|
#include "vrml1_coords.h"
|
2016-01-06 04:34:14 +00:00
|
|
|
#include "vrml1_material.h"
|
2016-02-01 06:27:50 +00:00
|
|
|
#include "wrlfacet.h"
|
2016-01-05 21:29:13 +00:00
|
|
|
#include "plugins/3dapi/ifsg_all.h"
|
|
|
|
|
|
|
|
|
|
|
|
WRL1FACESET::WRL1FACESET( NAMEREGISTER* aDictionary ) : WRL1NODE( aDictionary )
|
|
|
|
{
|
2021-03-11 00:02:39 +00:00
|
|
|
m_Type = WRL1NODES::WRL1_INDEXEDFACESET;
|
2016-01-05 21:29:13 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WRL1FACESET::WRL1FACESET( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
|
|
|
|
WRL1NODE( aDictionary )
|
|
|
|
{
|
2021-03-11 00:02:39 +00:00
|
|
|
m_Type = WRL1NODES::WRL1_INDEXEDFACESET;
|
2016-01-05 21:29:13 +00:00
|
|
|
m_Parent = aParent;
|
|
|
|
|
|
|
|
if( NULL != m_Parent )
|
|
|
|
m_Parent->AddChildNode( this );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WRL1FACESET::~WRL1FACESET()
|
|
|
|
{
|
|
|
|
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
|
2016-02-23 00:20:34 +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-05 21:29:13 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-05 21:29:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRL1FACESET::AddRefNode( WRL1NODE* aNode )
|
|
|
|
{
|
|
|
|
// this node may not own or reference any other node
|
|
|
|
|
|
|
|
#ifdef DEBUG_VRML1
|
2016-02-23 00:20:34 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] AddRefNode is not applicable";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-05 21:29:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRL1FACESET::AddChildNode( WRL1NODE* aNode )
|
|
|
|
{
|
|
|
|
// this node may not own or reference any other node
|
|
|
|
|
|
|
|
#ifdef DEBUG_VRML1
|
2016-02-23 00:20:34 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] AddChildNode is not applicable";
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-05 21:29:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRL1FACESET::Read( WRLPROC& proc, WRL1BASE* aTopNode )
|
|
|
|
{
|
|
|
|
size_t line, column;
|
|
|
|
proc.GetFilePosData( line, column );
|
|
|
|
|
|
|
|
char tok = proc.Peek();
|
|
|
|
|
|
|
|
if( proc.eof() )
|
|
|
|
{
|
|
|
|
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
|
2016-02-23 00:20:34 +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-05 21:29:13 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-05 21:29:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( '{' != tok )
|
|
|
|
{
|
|
|
|
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
|
2016-02-23 00:20:34 +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-05 21:29:13 +00:00
|
|
|
#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 )
|
2016-02-23 00:20:34 +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-05 21:29:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// expecting one of:
|
|
|
|
// coordIndex[]
|
|
|
|
// materialIndex[]
|
|
|
|
|
|
|
|
proc.GetFilePosData( line, column );
|
|
|
|
|
|
|
|
if( !glob.compare( "coordIndex" ) )
|
|
|
|
{
|
|
|
|
if( !proc.ReadMFInt( coordIndex ) )
|
|
|
|
{
|
|
|
|
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
|
2016-02-23 00:20:34 +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-05 21:29:13 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-05 21:29:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !glob.compare( "materialIndex" ) )
|
|
|
|
{
|
|
|
|
if( !proc.ReadMFInt( matIndex ) )
|
|
|
|
{
|
|
|
|
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
|
2016-02-23 00:20:34 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] invalid materialIndex 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-05 21:29:13 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-05 21:29:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-01-06 04:34:14 +00:00
|
|
|
else if( !glob.compare( "normalIndex" ) )
|
|
|
|
{
|
|
|
|
if( !proc.ReadMFInt( normIndex ) )
|
|
|
|
{
|
|
|
|
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
|
2016-02-23 00:20:34 +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-06 04:34:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-06 04:34:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !glob.compare( "textureCoordIndex" ) )
|
|
|
|
{
|
|
|
|
if( !proc.ReadMFInt( texIndex ) )
|
|
|
|
{
|
|
|
|
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
|
2016-02-23 00:20:34 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] invalid textureCoordIndex 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-06 04:34:14 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-06 04:34:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-01-05 21:29:13 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
|
2016-02-23 00:20:34 +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-05 21:29:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} // while( true ) -- reading contents of IndexedFaceSet{}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-08 05:23:42 +00:00
|
|
|
SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
|
2016-01-05 21:29:13 +00:00
|
|
|
{
|
2016-01-08 05:23:42 +00:00
|
|
|
// note: m_sgNode is unused because we cannot manage everything
|
|
|
|
// with a single reused transform due to the fact that VRML1
|
|
|
|
// may use a MatrixTransformation entity which is impossible to
|
|
|
|
// decompose into Rotate,Scale,Transform via an anlytic expression.
|
|
|
|
if( !m_Parent )
|
2016-01-06 04:34:14 +00:00
|
|
|
{
|
2016-01-08 05:23:42 +00:00
|
|
|
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
|
2016-02-23 00:20:34 +00:00
|
|
|
wxLogTrace( MASK_VRML, " * [INFO] bad model: no parent node\n" );
|
2016-01-08 05:23:42 +00:00
|
|
|
#endif
|
2016-01-06 04:34:14 +00:00
|
|
|
|
2016-01-08 05:23:42 +00:00
|
|
|
return NULL;
|
2016-01-06 04:34:14 +00:00
|
|
|
}
|
2016-01-08 05:23:42 +00:00
|
|
|
else
|
2016-01-05 21:29:13 +00:00
|
|
|
{
|
2016-01-08 05:23:42 +00:00
|
|
|
if( NULL == sp )
|
|
|
|
{
|
|
|
|
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
|
2016-02-23 00:20:34 +00:00
|
|
|
wxLogTrace( MASK_VRML, " * [INFO] bad model: no base data given\n" );
|
2016-01-08 05:23:42 +00:00
|
|
|
#endif
|
2016-01-05 21:29:13 +00:00
|
|
|
|
2016-01-06 04:34:14 +00:00
|
|
|
return NULL;
|
2016-01-08 05:23:42 +00:00
|
|
|
}
|
2016-01-05 21:29:13 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 05:23:42 +00:00
|
|
|
m_current = *sp;
|
|
|
|
|
2016-01-06 04:34:14 +00:00
|
|
|
if( NULL == m_current.coord || NULL == m_current.mat )
|
2016-01-08 05:23:42 +00:00
|
|
|
{
|
|
|
|
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
|
|
|
|
if( NULL == m_current.coord )
|
2016-02-23 02:37:35 +00:00
|
|
|
{
|
2016-02-23 00:20:34 +00:00
|
|
|
wxLogTrace( MASK_VRML, " * [INFO] bad model: no vertex set\n" );
|
2016-02-23 02:37:35 +00:00
|
|
|
}
|
2016-01-08 05:23:42 +00:00
|
|
|
|
|
|
|
if( NULL == m_current.mat )
|
2016-02-23 02:37:35 +00:00
|
|
|
{
|
2016-02-23 00:20:34 +00:00
|
|
|
wxLogTrace( MASK_VRML, " * [INFO] bad model: no material set\n" );
|
2016-02-23 02:37:35 +00:00
|
|
|
}
|
2016-01-08 05:23:42 +00:00
|
|
|
#endif
|
|
|
|
|
2016-01-06 04:34:14 +00:00
|
|
|
return NULL;
|
2016-01-08 05:23:42 +00:00
|
|
|
}
|
2016-01-06 04:34:14 +00:00
|
|
|
|
2016-01-06 07:02:21 +00:00
|
|
|
WRLVEC3F* pcoords;
|
|
|
|
size_t coordsize;
|
|
|
|
|
|
|
|
m_current.coord->GetCoords( pcoords, coordsize );
|
|
|
|
size_t vsize = coordIndex.size();
|
|
|
|
|
|
|
|
if( coordsize < 3 || vsize < 3 )
|
2016-01-08 05:23:42 +00:00
|
|
|
{
|
|
|
|
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
|
2016-02-23 00:20:34 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << " * [INFO] bad model: coordsize, indexsize = " << coordsize;
|
|
|
|
ostr << ", " << vsize;
|
|
|
|
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-08 05:23:42 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-06 07:02:21 +00:00
|
|
|
return NULL;
|
2016-01-08 05:23:42 +00:00
|
|
|
}
|
2016-01-06 07:02:21 +00:00
|
|
|
|
2016-01-06 04:34:14 +00:00
|
|
|
// 1. create the vertex/normals/colors lists
|
|
|
|
SGNODE* sgcolor = NULL;
|
2016-01-19 04:21:00 +00:00
|
|
|
WRL1_BINDING mbind = m_current.matbind;
|
2016-02-01 06:27:50 +00:00
|
|
|
size_t matSize = matIndex.size();
|
2016-01-19 04:21:00 +00:00
|
|
|
|
|
|
|
switch( mbind )
|
2016-01-05 21:29:13 +00:00
|
|
|
{
|
2021-03-10 23:52:21 +00:00
|
|
|
case WRL1_BINDING::BIND_PER_FACE:
|
|
|
|
case WRL1_BINDING::BIND_PER_VERTEX:
|
|
|
|
case WRL1_BINDING::BIND_PER_VERTEX_INDEXED:
|
2016-01-06 07:02:21 +00:00
|
|
|
break;
|
|
|
|
|
2021-03-10 23:52:21 +00:00
|
|
|
case WRL1_BINDING::BIND_PER_FACE_INDEXED:
|
2016-01-06 07:02:21 +00:00
|
|
|
|
|
|
|
if( matIndex.empty() )
|
2016-01-08 05:23:42 +00:00
|
|
|
{
|
|
|
|
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
|
2016-02-23 00:20:34 +00:00
|
|
|
wxLogTrace( MASK_VRML, " * [INFO] bad model: per face indexed but no indices\n" );
|
2016-01-08 05:23:42 +00:00
|
|
|
#endif
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2016-01-19 04:21:00 +00:00
|
|
|
// support bad models by temporarily switching bindings
|
2021-03-10 23:52:21 +00:00
|
|
|
mbind = WRL1_BINDING::BIND_OVERALL;
|
2016-01-19 04:21:00 +00:00
|
|
|
sgcolor = m_current.mat->GetAppearance( 0 );
|
2016-01-08 05:23:42 +00:00
|
|
|
}
|
2016-01-06 07:02:21 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2016-01-06 04:34:14 +00:00
|
|
|
default:
|
|
|
|
|
2016-01-07 00:24:11 +00:00
|
|
|
// use the first appearance definition
|
|
|
|
sgcolor = m_current.mat->GetAppearance( 0 );
|
2016-01-06 04:34:14 +00:00
|
|
|
break;
|
2016-01-05 21:29:13 +00:00
|
|
|
}
|
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
// copy the data into FACET structures
|
2016-01-05 21:29:13 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
SHAPE lShape;
|
|
|
|
FACET* fp = NULL;
|
|
|
|
size_t iCoord;
|
|
|
|
int idx; // coordinate index
|
|
|
|
size_t cidx = 0; // color index
|
|
|
|
SGCOLOR pc1;
|
2016-01-05 21:29:13 +00:00
|
|
|
|
2021-03-10 23:52:21 +00:00
|
|
|
if( mbind == WRL1_BINDING::BIND_OVERALL || mbind == WRL1_BINDING::BIND_DEFAULT )
|
2016-01-07 00:24:11 +00:00
|
|
|
{
|
2016-02-01 06:27:50 +00:00
|
|
|
// no per-vertex colors; we can save a few CPU cycles
|
|
|
|
for( iCoord = 0; iCoord < vsize; ++iCoord )
|
2016-01-05 21:29:13 +00:00
|
|
|
{
|
2016-02-01 06:27:50 +00:00
|
|
|
idx = coordIndex[iCoord];
|
2016-01-06 07:02:21 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
if( idx < 0 )
|
2016-01-06 07:02:21 +00:00
|
|
|
{
|
2016-02-01 06:27:50 +00:00
|
|
|
if( NULL != fp )
|
2016-01-06 07:02:21 +00:00
|
|
|
{
|
2016-02-01 06:27:50 +00:00
|
|
|
if( fp->HasMinPoints() )
|
|
|
|
fp = NULL;
|
|
|
|
else
|
|
|
|
fp->Init();
|
2016-01-06 07:02:21 +00:00
|
|
|
}
|
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-01-06 07:02:21 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
// if the coordinate is bad then skip it
|
|
|
|
if( idx >= (int)coordsize )
|
|
|
|
continue;
|
2016-01-08 05:23:42 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
if( NULL == fp )
|
|
|
|
fp = lShape.NewFacet();
|
2016-01-08 05:23:42 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
// push the vertex value and index
|
|
|
|
WRLVEC3F vf;
|
|
|
|
glm::vec4 pt = glm::vec4( pcoords[idx].x, pcoords[idx].y, pcoords[idx].z, 1.0 );
|
|
|
|
pt = m_current.txmatrix * pt;
|
|
|
|
vf.x = pt.x;
|
|
|
|
vf.y = pt.y;
|
|
|
|
vf.z = pt.z;
|
|
|
|
|
|
|
|
fp->AddVertex( vf, idx );
|
2016-01-05 21:29:13 +00:00
|
|
|
}
|
2016-01-06 07:02:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-01 06:27:50 +00:00
|
|
|
for( iCoord = 0; iCoord < vsize; ++iCoord )
|
2016-01-05 21:29:13 +00:00
|
|
|
{
|
2016-02-01 06:27:50 +00:00
|
|
|
idx = coordIndex[iCoord];
|
2016-01-05 21:29:13 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
if( idx < 0 )
|
2016-01-05 21:29:13 +00:00
|
|
|
{
|
2016-02-01 06:27:50 +00:00
|
|
|
if( NULL != fp )
|
|
|
|
{
|
|
|
|
if( fp->HasMinPoints() )
|
|
|
|
fp = NULL;
|
|
|
|
else
|
|
|
|
fp->Init();
|
|
|
|
}
|
2016-01-06 07:02:21 +00:00
|
|
|
|
2021-03-10 23:52:21 +00:00
|
|
|
if( mbind == WRL1_BINDING::BIND_PER_FACE
|
|
|
|
|| mbind == WRL1_BINDING::BIND_PER_FACE_INDEXED )
|
2016-02-01 06:27:50 +00:00
|
|
|
++cidx;
|
2016-01-06 07:02:21 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-01-06 07:02:21 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
// if the coordinate is bad then skip it
|
|
|
|
if( idx >= (int)coordsize )
|
|
|
|
continue;
|
2016-01-06 07:02:21 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
if( NULL == fp )
|
|
|
|
fp = lShape.NewFacet();
|
2016-01-06 07:02:21 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
// push the vertex value and index
|
|
|
|
WRLVEC3F vf;
|
|
|
|
glm::vec4 pt = glm::vec4( pcoords[idx].x, pcoords[idx].y, pcoords[idx].z, 1.0 );
|
|
|
|
pt = m_current.txmatrix * pt;
|
|
|
|
vf.x = pt.x;
|
|
|
|
vf.y = pt.y;
|
|
|
|
vf.z = pt.z;
|
2016-01-06 07:02:21 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
fp->AddVertex( vf, idx );
|
2016-01-06 07:02:21 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
// push the color if appropriate
|
|
|
|
switch( mbind )
|
2016-01-07 07:03:07 +00:00
|
|
|
{
|
2021-03-10 23:52:21 +00:00
|
|
|
case WRL1_BINDING::BIND_PER_FACE:
|
2016-01-07 07:03:07 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
if( !fp->HasColors() )
|
|
|
|
{
|
|
|
|
m_current.mat->GetColor( &pc1, cidx );
|
|
|
|
fp->AddColor( pc1 );
|
|
|
|
}
|
2016-01-07 07:03:07 +00:00
|
|
|
|
|
|
|
break;
|
2016-01-06 07:02:21 +00:00
|
|
|
|
2021-03-10 23:52:21 +00:00
|
|
|
case WRL1_BINDING::BIND_PER_VERTEX:
|
2016-02-01 06:27:50 +00:00
|
|
|
m_current.mat->GetColor( &pc1, idx );
|
|
|
|
fp->AddColor( pc1 );
|
2016-01-08 05:23:42 +00:00
|
|
|
break;
|
|
|
|
|
2021-03-10 23:52:21 +00:00
|
|
|
case WRL1_BINDING::BIND_PER_FACE_INDEXED:
|
2016-02-01 06:27:50 +00:00
|
|
|
if( !fp->HasColors() )
|
2016-01-06 07:02:21 +00:00
|
|
|
{
|
2016-02-01 06:27:50 +00:00
|
|
|
if( cidx >= matSize )
|
|
|
|
m_current.mat->GetColor( &pc1, matIndex.back() );
|
|
|
|
else
|
|
|
|
m_current.mat->GetColor( &pc1, matIndex[cidx] );
|
|
|
|
|
|
|
|
fp->AddColor( pc1 );
|
2016-01-06 07:02:21 +00:00
|
|
|
}
|
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
break;
|
2016-01-06 07:02:21 +00:00
|
|
|
|
2021-03-10 23:52:21 +00:00
|
|
|
case WRL1_BINDING::BIND_PER_VERTEX_INDEXED:
|
2016-02-01 06:27:50 +00:00
|
|
|
|
|
|
|
if( matIndex.empty() )
|
2016-01-06 07:02:21 +00:00
|
|
|
{
|
2021-02-02 05:25:35 +00:00
|
|
|
m_current.mat->GetColor( &pc1, idx );
|
2016-01-06 07:02:21 +00:00
|
|
|
}
|
2016-02-01 06:27:50 +00:00
|
|
|
else
|
2016-01-08 05:23:42 +00:00
|
|
|
{
|
2016-02-01 06:27:50 +00:00
|
|
|
if( iCoord >= matSize )
|
|
|
|
m_current.mat->GetColor( &pc1, matIndex.back() );
|
|
|
|
else
|
|
|
|
m_current.mat->GetColor( &pc1, matIndex[iCoord] );
|
2016-01-08 05:23:42 +00:00
|
|
|
}
|
2016-01-05 21:29:13 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
fp->AddColor( pc1 );
|
2016-01-08 05:23:42 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
break;
|
2016-01-07 07:03:07 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
default:
|
|
|
|
break;
|
2016-01-07 07:03:07 +00:00
|
|
|
}
|
2016-01-05 21:29:13 +00:00
|
|
|
}
|
2016-01-06 08:45:49 +00:00
|
|
|
}
|
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
// extract the final data set
|
2016-02-02 00:23:15 +00:00
|
|
|
SGNODE* np = lShape.CalcShape( aParent, sgcolor, m_current.order, m_current.creaseLimit );
|
2016-01-06 07:02:21 +00:00
|
|
|
|
2016-02-01 06:27:50 +00:00
|
|
|
return np;
|
2016-01-05 21:29:13 +00:00
|
|
|
}
|