2015-12-08 07:31:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-03-02 22:53:49 +00:00
|
|
|
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
2020-12-16 18:19:28 +00:00
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-12-08 07:31:57 +00:00
|
|
|
*
|
|
|
|
* 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 06:46:22 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <wx/log.h>
|
|
|
|
|
2015-12-09 07:30:48 +00:00
|
|
|
#include "3d_cache/sg/sg_faceset.h"
|
|
|
|
#include "3d_cache/sg/sg_colors.h"
|
|
|
|
#include "3d_cache/sg/sg_coords.h"
|
|
|
|
#include "3d_cache/sg/sg_normals.h"
|
|
|
|
#include "3d_cache/sg/sg_coordindex.h"
|
|
|
|
#include "3d_cache/sg/sg_helpers.h"
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
SGFACESET::SGFACESET( SGNODE* aParent ) : SGNODE( aParent )
|
|
|
|
{
|
|
|
|
m_SGtype = S3D::SGTYPE_FACESET;
|
2020-12-16 18:19:28 +00:00
|
|
|
m_Colors = nullptr;
|
|
|
|
m_Coords = nullptr;
|
|
|
|
m_CoordIndices = nullptr;
|
|
|
|
m_Normals = nullptr;
|
|
|
|
m_RColors = nullptr;
|
|
|
|
m_RCoords = nullptr;
|
|
|
|
m_RNormals = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
valid = false;
|
|
|
|
validated = false;
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
m_Parent = nullptr;
|
|
|
|
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG,
|
|
|
|
wxT( "%s:%s:%d * [BUG] inappropriate parent to SGFACESET (type %s)" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
aParent->GetNodeType() );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
2020-12-16 18:19:28 +00:00
|
|
|
else if( nullptr != aParent && S3D::SGTYPE_SHAPE == aParent->GetNodeType() )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
m_Parent->AddChildNode( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SGFACESET::~SGFACESET()
|
|
|
|
{
|
|
|
|
// drop references
|
|
|
|
if( m_RColors )
|
|
|
|
{
|
|
|
|
m_RColors->delNodeRef( this );
|
2020-12-16 18:19:28 +00:00
|
|
|
m_RColors = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_RCoords )
|
|
|
|
{
|
|
|
|
m_RCoords->delNodeRef( this );
|
2020-12-16 18:19:28 +00:00
|
|
|
m_RCoords = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_RNormals )
|
|
|
|
{
|
|
|
|
m_RNormals->delNodeRef( this );
|
2020-12-16 18:19:28 +00:00
|
|
|
m_RNormals = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// delete owned objects
|
|
|
|
if( m_Colors )
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
m_Colors->SetParent( nullptr, false );
|
2015-12-08 07:31:57 +00:00
|
|
|
delete m_Colors;
|
2020-12-16 18:19:28 +00:00
|
|
|
m_Colors = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Coords )
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
m_Coords->SetParent( nullptr, false );
|
2015-12-08 07:31:57 +00:00
|
|
|
delete m_Coords;
|
2020-12-16 18:19:28 +00:00
|
|
|
m_Coords = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Normals )
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
m_Normals->SetParent( nullptr, false );
|
2015-12-08 07:31:57 +00:00
|
|
|
delete m_Normals;
|
2020-12-16 18:19:28 +00:00
|
|
|
m_Normals = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_CoordIndices )
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
m_CoordIndices->SetParent( nullptr, false );
|
2015-12-08 07:31:57 +00:00
|
|
|
delete m_CoordIndices;
|
2020-12-16 18:19:28 +00:00
|
|
|
m_CoordIndices = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SGFACESET::SetParent( SGNODE* aParent, bool notify )
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != m_Parent )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
if( aParent == m_Parent )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// handle the change in parents
|
|
|
|
if( notify )
|
|
|
|
m_Parent->unlinkChildNode( this );
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
m_Parent = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr == aParent )
|
2015-12-08 07:31:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only a SGSHAPE may be parent to a SGFACESET
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
m_Parent = aParent;
|
|
|
|
|
|
|
|
if( m_Parent )
|
|
|
|
m_Parent->AddChildNode( this );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SGNODE* SGFACESET::FindNode(const char *aNodeName, const SGNODE *aCaller)
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr == aNodeName || 0 == aNodeName[0] )
|
|
|
|
return nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
if( !m_Name.compare( aNodeName ) )
|
|
|
|
return this;
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
SGNODE* np = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
if( m_Colors )
|
|
|
|
{
|
|
|
|
np = m_Colors->FindNode( aNodeName, this );
|
|
|
|
|
|
|
|
if( np )
|
|
|
|
return np;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Coords )
|
|
|
|
{
|
|
|
|
np = m_Coords->FindNode( aNodeName, this );
|
|
|
|
|
|
|
|
if( np )
|
|
|
|
return np;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_CoordIndices )
|
|
|
|
{
|
|
|
|
np = m_CoordIndices->FindNode( aNodeName, this );
|
|
|
|
|
|
|
|
if( np )
|
|
|
|
return np;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Normals )
|
|
|
|
{
|
|
|
|
np = m_Normals->FindNode( aNodeName, this );
|
|
|
|
|
|
|
|
if( np )
|
|
|
|
return np;
|
|
|
|
}
|
|
|
|
|
|
|
|
// query the parent if appropriate
|
2020-12-16 18:19:28 +00:00
|
|
|
if( aCaller == m_Parent || nullptr == m_Parent )
|
|
|
|
return nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
return m_Parent->FindNode( aNodeName, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SGFACESET::unlinkNode( const SGNODE* aNode, bool isChild )
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr == aNode )
|
2015-12-08 07:31:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
valid = false;
|
|
|
|
validated = false;
|
|
|
|
|
|
|
|
if( isChild )
|
|
|
|
{
|
|
|
|
if( aNode == m_Colors )
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
m_Colors = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aNode == m_Coords )
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
m_Coords = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aNode == m_Normals )
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
m_Normals = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aNode == m_CoordIndices )
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
m_CoordIndices = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aNode == m_RColors )
|
|
|
|
{
|
2016-03-14 01:30:59 +00:00
|
|
|
delNodeRef( this );
|
2020-12-16 18:19:28 +00:00
|
|
|
m_RColors = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aNode == m_RCoords )
|
|
|
|
{
|
2016-03-14 01:30:59 +00:00
|
|
|
delNodeRef( this );
|
2020-12-16 18:19:28 +00:00
|
|
|
m_RCoords = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aNode == m_RNormals )
|
|
|
|
{
|
2016-03-14 01:30:59 +00:00
|
|
|
delNodeRef( this );
|
2020-12-16 18:19:28 +00:00
|
|
|
m_RNormals = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] unlinkNode() did not find its target" ),
|
2020-12-16 18:19:28 +00:00
|
|
|
__FILE__, __FUNCTION__, __LINE__ );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SGFACESET::unlinkChildNode( const SGNODE* aNode )
|
|
|
|
{
|
|
|
|
unlinkNode( aNode, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SGFACESET::unlinkRefNode( const SGNODE* aNode )
|
|
|
|
{
|
|
|
|
unlinkNode( aNode, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool SGFACESET::addNode( SGNODE* aNode, bool isChild )
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
wxCHECK( aNode, false );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
valid = false;
|
|
|
|
validated = false;
|
|
|
|
|
|
|
|
if( S3D::SGTYPE_COLORS == aNode->GetNodeType() )
|
|
|
|
{
|
|
|
|
if( m_Colors || m_RColors )
|
|
|
|
{
|
2016-01-08 06:04:17 +00:00
|
|
|
if( aNode != m_Colors && aNode != m_RColors )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] assigning multiple Colors nodes" ),
|
2020-12-16 18:19:28 +00:00
|
|
|
__FILE__, __FUNCTION__, __LINE__ );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2016-01-08 06:04:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( isChild )
|
|
|
|
{
|
|
|
|
m_Colors = (SGCOLORS*)aNode;
|
|
|
|
m_Colors->SetParent( this );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_RColors = (SGCOLORS*)aNode;
|
|
|
|
m_RColors->addNodeRef( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( S3D::SGTYPE_COORDS == aNode->GetNodeType() )
|
|
|
|
{
|
|
|
|
if( m_Coords || m_RCoords )
|
|
|
|
{
|
2016-01-08 06:04:17 +00:00
|
|
|
if( aNode != m_Coords && aNode != m_RCoords )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] assigning multiple Colors nodes" ),
|
2020-12-16 18:19:28 +00:00
|
|
|
__FILE__, __FUNCTION__, __LINE__ );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2016-01-08 06:04:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( isChild )
|
|
|
|
{
|
|
|
|
m_Coords = (SGCOORDS*)aNode;
|
|
|
|
m_Coords->SetParent( this );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_RCoords = (SGCOORDS*)aNode;
|
|
|
|
m_RCoords->addNodeRef( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( S3D::SGTYPE_NORMALS == aNode->GetNodeType() )
|
|
|
|
{
|
|
|
|
if( m_Normals || m_RNormals )
|
|
|
|
{
|
2016-01-08 06:04:17 +00:00
|
|
|
if( aNode != m_Normals && aNode != m_RNormals )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] assigning multiple Normals nodes" ),
|
2020-12-16 18:19:28 +00:00
|
|
|
__FILE__, __FUNCTION__, __LINE__ );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2016-01-08 06:04:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( isChild )
|
|
|
|
{
|
|
|
|
m_Normals = (SGNORMALS*)aNode;
|
|
|
|
m_Normals->SetParent( this );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_RNormals = (SGNORMALS*)aNode;
|
|
|
|
m_RNormals->addNodeRef( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( S3D::SGTYPE_COORDINDEX == aNode->GetNodeType() )
|
|
|
|
{
|
|
|
|
if( m_CoordIndices )
|
|
|
|
{
|
2016-01-08 06:04:17 +00:00
|
|
|
if( aNode != m_CoordIndices )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG,
|
|
|
|
wxT( "%s:%s:%d * [BUG] assigning multiple CoordIndex nodes" ),
|
2020-12-16 18:19:28 +00:00
|
|
|
__FILE__, __FUNCTION__, __LINE__ );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2016-01-08 06:04:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_CoordIndices = (SGCOORDINDEX*)aNode;
|
|
|
|
m_CoordIndices->SetParent( this );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] object type '%s' is not a valid type for "
|
|
|
|
"this object '%d'" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
aNode->GetName(),
|
2020-12-16 18:19:28 +00:00
|
|
|
aNode->GetNodeType() );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SGFACESET::AddRefNode( SGNODE* aNode )
|
|
|
|
{
|
|
|
|
return addNode( aNode, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SGFACESET::AddChildNode( SGNODE* aNode )
|
|
|
|
{
|
|
|
|
return addNode( aNode, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SGFACESET::ReNameNodes( void )
|
|
|
|
{
|
|
|
|
m_written = false;
|
|
|
|
|
|
|
|
// rename this node
|
|
|
|
m_Name.clear();
|
|
|
|
GetName();
|
|
|
|
|
|
|
|
// rename all Colors and Indices
|
|
|
|
if( m_Colors )
|
|
|
|
m_Colors->ReNameNodes();
|
|
|
|
|
|
|
|
// rename all Coordinates and Indices
|
|
|
|
if( m_Coords )
|
|
|
|
m_Coords->ReNameNodes();
|
|
|
|
|
|
|
|
if( m_CoordIndices )
|
|
|
|
m_CoordIndices->ReNameNodes();
|
|
|
|
|
|
|
|
// rename all Normals and Indices
|
|
|
|
if( m_Normals )
|
|
|
|
m_Normals->ReNameNodes();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-02 22:53:49 +00:00
|
|
|
bool SGFACESET::WriteVRML( std::ostream& aFile, bool aReuseFlag )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
if( ( nullptr == m_Coords && nullptr == m_RCoords ) || ( nullptr == m_CoordIndices ) )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aReuseFlag )
|
|
|
|
{
|
|
|
|
if( !m_written )
|
|
|
|
{
|
|
|
|
aFile << " geometry DEF " << GetName() << " IndexedFaceSet {\n";
|
|
|
|
m_written = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aFile << "USE " << GetName() << "\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aFile << " geometry IndexedFaceSet {\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Coords )
|
|
|
|
m_Coords->WriteVRML( aFile, aReuseFlag );
|
|
|
|
|
|
|
|
if( m_RCoords )
|
|
|
|
m_RCoords->WriteVRML( aFile, aReuseFlag );
|
|
|
|
|
|
|
|
if( m_CoordIndices )
|
|
|
|
m_CoordIndices->WriteVRML( aFile, aReuseFlag );
|
|
|
|
|
|
|
|
if( m_Normals || m_RNormals )
|
|
|
|
aFile << " normalPerVertex TRUE\n";
|
|
|
|
|
|
|
|
if( m_Normals )
|
|
|
|
m_Normals->WriteVRML( aFile, aReuseFlag );
|
|
|
|
|
|
|
|
if( m_RNormals )
|
|
|
|
m_RNormals->WriteVRML( aFile, aReuseFlag );
|
|
|
|
|
|
|
|
if( m_Colors )
|
|
|
|
m_Colors->WriteVRML( aFile, aReuseFlag );
|
|
|
|
|
|
|
|
if( m_RColors )
|
|
|
|
m_RColors->WriteVRML( aFile, aReuseFlag );
|
|
|
|
|
|
|
|
aFile << "}\n";
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-02 22:53:49 +00:00
|
|
|
bool SGFACESET::WriteCache( std::ostream& aFile, SGNODE* parentNode )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr == parentNode )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
wxCHECK( m_Parent, false );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
SGNODE* np = m_Parent;
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
while( nullptr != np->GetParent() )
|
2015-12-08 07:31:57 +00:00
|
|
|
np = np->GetParent();
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
if( np->WriteCache( aFile, nullptr ) )
|
2016-03-14 01:30:59 +00:00
|
|
|
{
|
|
|
|
m_written = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
wxCHECK( parentNode == m_Parent, false );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
if( !aFile.good() )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad stream" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__ );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-14 01:30:59 +00:00
|
|
|
// check if any references are unwritten and swap parents if so
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != m_RCoords && !m_RCoords->isWritten() )
|
2016-03-14 01:30:59 +00:00
|
|
|
m_RCoords->SwapParent( this );
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != m_RNormals && !m_RNormals->isWritten() )
|
2016-03-14 01:30:59 +00:00
|
|
|
m_RNormals->SwapParent( this );
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != m_RColors && !m_RColors->isWritten() )
|
2016-03-14 01:30:59 +00:00
|
|
|
m_RColors->SwapParent( this );
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
aFile << "[" << GetName() << "]";
|
2016-01-06 04:34:14 +00:00
|
|
|
#define NITEMS 7
|
2015-12-08 07:31:57 +00:00
|
|
|
bool items[NITEMS];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for( i = 0; i < NITEMS; ++i )
|
|
|
|
items[i] = 0;
|
|
|
|
|
|
|
|
i = 0;
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != m_Coords )
|
2015-12-08 07:31:57 +00:00
|
|
|
items[i] = true;
|
|
|
|
|
|
|
|
++i;
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != m_RCoords )
|
2015-12-08 07:31:57 +00:00
|
|
|
items[i] = true;
|
|
|
|
|
|
|
|
++i;
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != m_CoordIndices )
|
2015-12-08 07:31:57 +00:00
|
|
|
items[i] = true;
|
|
|
|
|
|
|
|
++i;
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != m_Normals )
|
2015-12-08 07:31:57 +00:00
|
|
|
items[i] = true;
|
|
|
|
|
|
|
|
++i;
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != m_RNormals )
|
2015-12-08 07:31:57 +00:00
|
|
|
items[i] = true;
|
|
|
|
|
|
|
|
++i;
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != m_Colors )
|
2015-12-08 07:31:57 +00:00
|
|
|
items[i] = true;
|
|
|
|
|
|
|
|
++i;
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != m_RColors )
|
2015-12-08 07:31:57 +00:00
|
|
|
items[i] = true;
|
|
|
|
|
2016-06-01 12:22:05 +00:00
|
|
|
for( int jj = 0; jj < NITEMS; ++jj )
|
2020-12-16 18:19:28 +00:00
|
|
|
aFile.write( (char*) &items[jj], sizeof( bool ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
if( items[0] )
|
|
|
|
m_Coords->WriteCache( aFile, this );
|
|
|
|
|
|
|
|
if( items[1] )
|
|
|
|
aFile << "[" << m_RCoords->GetName() << "]";
|
|
|
|
|
|
|
|
if( items[2] )
|
|
|
|
m_CoordIndices->WriteCache( aFile, this );
|
|
|
|
|
|
|
|
if( items[3] )
|
|
|
|
m_Normals->WriteCache( aFile, this );
|
|
|
|
|
|
|
|
if( items[4] )
|
|
|
|
aFile << "[" << m_RNormals->GetName() << "]";
|
|
|
|
|
|
|
|
if( items[5] )
|
|
|
|
m_Colors->WriteCache( aFile, this );
|
|
|
|
|
|
|
|
if( items[6] )
|
|
|
|
aFile << "[" << m_RColors->GetName() << "]";
|
|
|
|
|
|
|
|
if( aFile.fail() )
|
|
|
|
return false;
|
|
|
|
|
2016-03-14 01:30:59 +00:00
|
|
|
m_written = true;
|
2015-12-08 07:31:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-02 22:53:49 +00:00
|
|
|
bool SGFACESET::ReadCache( std::istream& aFile, SGNODE* parentNode )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
if( m_Coords || m_RCoords || m_CoordIndices || m_Colors || m_RColors || m_Normals
|
|
|
|
|| m_RNormals )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] non-empty node" ),
|
2020-12-16 18:19:28 +00:00
|
|
|
__FILE__, __FUNCTION__, __LINE__ );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-06 04:34:14 +00:00
|
|
|
#define NITEMS 7
|
2015-12-08 07:31:57 +00:00
|
|
|
bool items[NITEMS];
|
|
|
|
|
|
|
|
for( int i = 0; i < NITEMS; ++i )
|
2020-12-16 18:19:28 +00:00
|
|
|
aFile.read( (char*) &items[i], sizeof( bool ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
if( ( items[0] && items[1] ) || ( items[3] && items[4] ) || ( items[5] && items[6] ) )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; multiple item definitions "
|
|
|
|
"at position %d" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
static_cast<int>( aFile.tellg() ) );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
if( items[0] )
|
|
|
|
{
|
|
|
|
if( S3D::SGTYPE_COORDS != S3D::ReadTag( aFile, name ) )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad child coords tag at "
|
|
|
|
"position %d" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
static_cast<int>( aFile.tellg() ) );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Coords = new SGCOORDS( this );
|
|
|
|
m_Coords->SetName( name.c_str() );
|
|
|
|
|
|
|
|
if( !m_Coords->ReadCache( aFile, this ) )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; corrupt data while "
|
|
|
|
"reading coords '%s'" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
name );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( items[1] )
|
|
|
|
{
|
|
|
|
if( S3D::SGTYPE_COORDS != S3D::ReadTag( aFile, name ) )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad ref coords tag at "
|
|
|
|
"position %d" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
static_cast<int>( aFile.tellg() ) );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SGNODE* np = FindNode( name.c_str(), this );
|
|
|
|
|
|
|
|
if( !np )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; cannot find ref "
|
|
|
|
"coords '%s'" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
name );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( S3D::SGTYPE_COORDS != np->GetNodeType() )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; type is not SGCOORDS "
|
|
|
|
"'%s'" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
name );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_RCoords = (SGCOORDS*)np;
|
|
|
|
m_RCoords->addNodeRef( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( items[2] )
|
|
|
|
{
|
|
|
|
if( S3D::SGTYPE_COORDINDEX != S3D::ReadTag( aFile, name ) )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad coord index tag at "
|
|
|
|
"position %d" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
static_cast<int>( aFile.tellg() ) );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_CoordIndices = new SGCOORDINDEX( this );
|
|
|
|
m_CoordIndices->SetName( name.c_str() );
|
|
|
|
|
|
|
|
if( !m_CoordIndices->ReadCache( aFile, this ) )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data while reading coord "
|
|
|
|
"index '%s'" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
name );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( items[3] )
|
|
|
|
{
|
|
|
|
if( S3D::SGTYPE_NORMALS != S3D::ReadTag( aFile, name ) )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad child normals tag "
|
|
|
|
"at position %d" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
static_cast<int>( aFile.tellg() ) );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Normals = new SGNORMALS( this );
|
|
|
|
m_Normals->SetName( name.c_str() );
|
|
|
|
|
|
|
|
if( !m_Normals->ReadCache( aFile, this ) )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data while reading normals "
|
|
|
|
"'%s'" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
name );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( items[4] )
|
|
|
|
{
|
|
|
|
if( S3D::SGTYPE_NORMALS != S3D::ReadTag( aFile, name ) )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad ref normals tag at "
|
|
|
|
"position %d" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
static_cast<int>( aFile.tellg() ) );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SGNODE* np = FindNode( name.c_str(), this );
|
|
|
|
|
|
|
|
if( !np )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt: cannot find ref normals "
|
|
|
|
"'%s'" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
name );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( S3D::SGTYPE_NORMALS != np->GetNodeType() )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt: type is not SGNORMALS '%s'" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
name );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_RNormals = (SGNORMALS*)np;
|
|
|
|
m_RNormals->addNodeRef( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( items[5] )
|
|
|
|
{
|
|
|
|
if( S3D::SGTYPE_COLORS != S3D::ReadTag( aFile, name ) )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad child colors tag "
|
|
|
|
"at position %d" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
static_cast<int>( aFile.tellg() ) );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Colors = new SGCOLORS( this );
|
|
|
|
m_Colors->SetName( name.c_str() );
|
|
|
|
|
|
|
|
if( !m_Colors->ReadCache( aFile, this ) )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data while reading colors "
|
|
|
|
"'%s'" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
name );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( items[6] )
|
|
|
|
{
|
|
|
|
if( S3D::SGTYPE_COLORS != S3D::ReadTag( aFile, name ) )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad ref colors tag at "
|
|
|
|
"position %d" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
static_cast<int>( aFile.tellg() ) );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SGNODE* np = FindNode( name.c_str(), this );
|
|
|
|
|
|
|
|
if( !np )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data: cannot find ref colors "
|
|
|
|
"'%s'" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
name );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( S3D::SGTYPE_COLORS != np->GetNodeType() )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data: type is not SGCOLORS "
|
|
|
|
"'%s'" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
name );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_RColors = (SGCOLORS*)np;
|
|
|
|
m_RColors->addNodeRef( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aFile.fail() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SGFACESET::validate( void )
|
|
|
|
{
|
|
|
|
// verify the integrity of this object's data
|
|
|
|
if( validated )
|
|
|
|
return valid;
|
|
|
|
|
|
|
|
// ensure we have at least coordinates and their normals
|
2020-12-16 18:19:28 +00:00
|
|
|
if( ( nullptr == m_Coords && nullptr == m_RCoords )
|
|
|
|
|| ( nullptr == m_Normals && nullptr == m_RNormals )
|
|
|
|
|| ( nullptr == m_CoordIndices ) )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; no vertices, vertex indices, "
|
|
|
|
"or normals" ),
|
2020-12-16 18:19:28 +00:00
|
|
|
__FILE__, __FUNCTION__, __LINE__ );
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
validated = true;
|
|
|
|
valid = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check that there are >3 vertices
|
|
|
|
SGCOORDS* coords = m_Coords;
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr == coords )
|
2015-12-08 07:31:57 +00:00
|
|
|
coords = m_RCoords;
|
|
|
|
|
|
|
|
size_t nCoords = 0;
|
2020-12-16 18:19:28 +00:00
|
|
|
SGPOINT* lCoords = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
coords->GetCoordsList( nCoords, lCoords );
|
|
|
|
|
|
|
|
if( nCoords < 3 )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; fewer than 3 vertices" ),
|
2020-12-16 18:19:28 +00:00
|
|
|
__FILE__, __FUNCTION__, __LINE__ );
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
validated = true;
|
|
|
|
valid = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check that nVertices is divisible by 3 (facets are triangles)
|
|
|
|
size_t nCIdx = 0;
|
2020-12-16 18:19:28 +00:00
|
|
|
int* lCIdx = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
m_CoordIndices->GetIndices( nCIdx, lCIdx );
|
|
|
|
|
|
|
|
if( nCIdx < 3 || ( nCIdx % 3 > 0 ) )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; no vertex indices or not "
|
|
|
|
"multiple of 3" ),
|
2020-12-16 18:19:28 +00:00
|
|
|
__FILE__, __FUNCTION__, __LINE__ );
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
validated = true;
|
|
|
|
valid = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check that vertex[n] >= 0 and < nVertices
|
|
|
|
for( size_t i = 0; i < nCIdx; ++i )
|
|
|
|
{
|
2016-03-10 22:37:39 +00:00
|
|
|
if( lCIdx[i] < 0 || lCIdx[i] >= (int)nCoords )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; vertex index out of "
|
|
|
|
"bounds" ),
|
2020-12-16 18:19:28 +00:00
|
|
|
__FILE__, __FUNCTION__, __LINE__ );
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
validated = true;
|
|
|
|
valid = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check that there are as many normals as vertices
|
|
|
|
size_t nNorms = 0;
|
2020-12-16 18:19:28 +00:00
|
|
|
SGVECTOR* lNorms = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
SGNORMALS* pNorms = m_Normals;
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr == pNorms )
|
2015-12-08 07:31:57 +00:00
|
|
|
pNorms = m_RNormals;
|
|
|
|
|
|
|
|
pNorms->GetNormalList( nNorms, lNorms );
|
|
|
|
|
|
|
|
if( nNorms != nCoords )
|
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; number of normals (%ul) does "
|
|
|
|
"not match number of vertices (%ul)" ),
|
|
|
|
__FILE__, __FUNCTION__, __LINE__,
|
|
|
|
static_cast<unsigned long>( nNorms ),
|
|
|
|
static_cast<unsigned long>( nCoords ) );
|
2020-12-16 18:19:28 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
validated = true;
|
|
|
|
valid = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there are colors then ensure there are as many colors as vertices
|
|
|
|
SGCOLORS* pColors = m_Colors;
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr == pColors )
|
2015-12-08 07:31:57 +00:00
|
|
|
pColors = m_RColors;
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != pColors )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-01-06 04:34:14 +00:00
|
|
|
// we must have at least as many colors as vertices
|
2015-12-08 07:31:57 +00:00
|
|
|
size_t nColor = 0;
|
2020-12-16 18:19:28 +00:00
|
|
|
SGCOLOR* pColor = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
pColors->GetColorList( nColor, pColor );
|
|
|
|
}
|
|
|
|
|
|
|
|
validated = true;
|
|
|
|
valid = true;
|
|
|
|
return true;
|
|
|
|
}
|
2015-12-15 07:53:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SGFACESET::GatherCoordIndices( std::vector< int >& aIndexList )
|
|
|
|
{
|
|
|
|
if( m_CoordIndices )
|
|
|
|
m_CoordIndices->GatherCoordIndices( aIndexList );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-16 03:25:46 +00:00
|
|
|
bool SGFACESET::CalcNormals( SGNODE** aPtr )
|
2015-12-15 07:53:03 +00:00
|
|
|
{
|
2015-12-17 02:55:35 +00:00
|
|
|
SGCOORDS* coords = m_Coords;
|
2015-12-15 07:53:03 +00:00
|
|
|
|
2015-12-17 02:55:35 +00:00
|
|
|
if( m_RCoords )
|
|
|
|
coords = m_RCoords;
|
2015-12-15 07:53:03 +00:00
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr == coords || coords->coords.empty() )
|
2015-12-15 07:53:03 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_Normals && !m_Normals->norms.empty( ) )
|
|
|
|
return true;
|
|
|
|
|
2015-12-17 02:55:35 +00:00
|
|
|
if( m_RNormals && !m_RNormals->norms.empty( ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return coords->CalcNormals( this, aPtr );
|
2015-12-15 07:53:03 +00:00
|
|
|
}
|