KiCad PCB EDA Suite
WRL1FACESET Class Reference

#include <vrml1_faceset.h>

Inheritance diagram for WRL1FACESET:
WRL1NODE

Public Member Functions

 WRL1FACESET (NAMEREGISTER *aDictionary)
 
 WRL1FACESET (NAMEREGISTER *aDictionary, WRL1NODE *aParent)
 
virtual ~WRL1FACESET ()
 
bool Read (WRLPROC &proc, WRL1BASE *aTopNode) override
 
bool AddRefNode (WRL1NODE *aNode) override
 
bool AddChildNode (WRL1NODE *aNode) override
 
SGNODETranslateToSG (SGNODE *aParent, WRL1STATUS *sp) override
 Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg library. More...
 
void cancelDict (void)
 
WRL1NODES getNodeTypeID (const std::string &aNodeName)
 Return the ID based on the given aNodeName or WRL1_INVALID (WRL1_END) if no such node name exists. More...
 
virtual void unlinkChildNode (const WRL1NODE *aNode)
 Remove references to an owned child; it is invoked by the child upon destruction to ensure that the parent has no invalid references. More...
 
virtual void unlinkRefNode (const WRL1NODE *aNode)
 Remove pointers to a referenced node; it is invoked by the referenced node upon destruction to ensure that the referring node has no invalid references. More...
 
void addNodeRef (WRL1NODE *aNode)
 Add a pointer to a node which references, but does not own, this node. More...
 
void delNodeRef (WRL1NODE *aNode)
 Remove a pointer to a node which references, but does not own, this node. More...
 
WRL1NODES GetNodeType (void) const
 Return the type of this node instance. More...
 
WRL1NODEGetParent (void) const
 Return a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie. More...
 
virtual bool SetParent (WRL1NODE *aParent, bool doUnlink=true)
 Set the parent WRL1NODE of this object. More...
 
virtual std::string GetName (void)
 
virtual bool SetName (const std::string &aName)
 
const char * GetNodeTypeName (WRL1NODES aNodeType) const
 
size_t GetNItems (void) const
 
virtual WRL1NODEFindNode (const std::string &aNodeName)
 Search the tree of linked nodes and returns a reference to the current node with the given name. More...
 
std::string GetError (void)
 

Protected Attributes

WRL1NODEm_Parent
 
WRL1NODES m_Type
 
std::string m_Name
 
std::list< WRL1NODE * > m_BackPointers
 
std::list< WRL1NODE * > m_Children
 
std::list< WRL1NODE * > m_Refs
 
std::list< WRL1NODE * > m_Items
 
std::string m_error
 
WRL1STATUS m_current
 
SGNODEm_sgNode
 
NAMEREGISTERm_dictionary
 

Private Attributes

std::vector< int > coordIndex
 
std::vector< int > matIndex
 
std::vector< int > normIndex
 
std::vector< int > texIndex
 

Detailed Description

Definition at line 40 of file vrml1_faceset.h.

Constructor & Destructor Documentation

◆ WRL1FACESET() [1/2]

WRL1FACESET::WRL1FACESET ( NAMEREGISTER aDictionary)

Definition at line 38 of file vrml1_faceset.cpp.

38  : WRL1NODE( aDictionary )
39 {
41 }
WRL1NODE(NAMEREGISTER *aDictionary)
Definition: vrml1_node.cpp:91
WRL1NODES m_Type
Definition: vrml1_node.h:227

References WRL1NODE::m_Type, and WRL1_INDEXEDFACESET.

◆ WRL1FACESET() [2/2]

WRL1FACESET::WRL1FACESET ( NAMEREGISTER aDictionary,
WRL1NODE aParent 
)

Definition at line 44 of file vrml1_faceset.cpp.

44  :
45  WRL1NODE( aDictionary )
46 {
48  m_Parent = aParent;
49 
50  if( nullptr != m_Parent )
51  m_Parent->AddChildNode( this );
52 }
WRL1NODE(NAMEREGISTER *aDictionary)
Definition: vrml1_node.cpp:91
virtual bool AddChildNode(WRL1NODE *aNode)
Definition: vrml1_node.cpp:376
WRL1NODES m_Type
Definition: vrml1_node.h:227
WRL1NODE * m_Parent
Definition: vrml1_node.h:226

References WRL1NODE::AddChildNode(), WRL1NODE::m_Parent, WRL1NODE::m_Type, and WRL1_INDEXEDFACESET.

◆ ~WRL1FACESET()

WRL1FACESET::~WRL1FACESET ( )
virtual

Definition at line 55 of file vrml1_faceset.cpp.

56 {
57  wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Destroying IndexedFaceSet with %zu children, "
58  "%zu references, and %zu back pointers." ),
59  m_Children.size(), m_Refs.size(), m_BackPointers.size() );
60 }
std::list< WRL1NODE * > m_BackPointers
Definition: vrml1_node.h:230
std::list< WRL1NODE * > m_Refs
Definition: vrml1_node.h:232
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63
std::list< WRL1NODE * > m_Children
Definition: vrml1_node.h:231

References WRL1NODE::m_BackPointers, WRL1NODE::m_Children, WRL1NODE::m_Refs, and traceVrmlPlugin.

Member Function Documentation

◆ AddChildNode()

bool WRL1FACESET::AddChildNode ( WRL1NODE aNode)
overridevirtual

Reimplemented from WRL1NODE.

Definition at line 70 of file vrml1_faceset.cpp.

71 {
72  // this node may not own or reference any other node
73  wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
74 }

◆ addNodeRef()

void WRL1NODE::addNodeRef ( WRL1NODE aNode)
inherited

Add a pointer to a node which references, but does not own, this node.

Such back-pointers are required to ensure that invalidated references are removed when a node is deleted

Parameters
aNodeis the node holding a reference to this object.

Definition at line 216 of file vrml1_node.cpp.

217 {
218  // the parent node must never be added as a backpointer
219  if( aNode == m_Parent )
220  return;
221 
222  std::list< WRL1NODE* >::iterator sR = m_BackPointers.begin();
223  std::list< WRL1NODE* >::iterator eR = m_BackPointers.end();
224 
225  while( sR != eR )
226  {
227  if( *sR == aNode )
228  return;
229 
230  ++sR;
231  }
232 
233  m_BackPointers.push_back( aNode );
234 }
std::list< WRL1NODE * > m_BackPointers
Definition: vrml1_node.h:230
WRL1NODE * m_Parent
Definition: vrml1_node.h:226

References WRL1NODE::m_BackPointers, and WRL1NODE::m_Parent.

Referenced by WRL1NODE::AddRefNode().

◆ AddRefNode()

bool WRL1FACESET::AddRefNode ( WRL1NODE aNode)
overridevirtual

Reimplemented from WRL1NODE.

Definition at line 63 of file vrml1_faceset.cpp.

64 {
65  // this node may not own or reference any other node
66  wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
67 }

◆ cancelDict()

void WRL1NODE::cancelDict ( void  )
inherited

Definition at line 198 of file vrml1_node.cpp.

199 {
200  std::list< WRL1NODE* >::iterator sC = m_Children.begin();
201  std::list< WRL1NODE* >::iterator eC = m_Children.end();
202 
203  while( sC != eC )
204  {
205  (*sC)->cancelDict();
206  ++sC;
207  }
208 
209  if( m_Type == WRL1NODES::WRL1_BASE && nullptr != m_dictionary )
210  delete m_dictionary;
211 
212  m_dictionary = nullptr;
213 }
NAMEREGISTER * m_dictionary
Definition: vrml1_node.h:246
WRL1NODES m_Type
Definition: vrml1_node.h:227
std::list< WRL1NODE * > m_Children
Definition: vrml1_node.h:231

References WRL1NODE::m_Children, WRL1NODE::m_dictionary, WRL1NODE::m_Type, and WRL1_BASE.

Referenced by WRL1BASE::~WRL1BASE().

◆ delNodeRef()

void WRL1NODE::delNodeRef ( WRL1NODE aNode)
inherited

Remove a pointer to a node which references, but does not own, this node.

Parameters
aNodeis the node holding a reference to this object.

Definition at line 237 of file vrml1_node.cpp.

238 {
239  std::list< WRL1NODE* >::iterator np = std::find( m_BackPointers.begin(),
240  m_BackPointers.end(), aNode );
241 
242  if( np != m_BackPointers.end() )
243  {
244  m_BackPointers.erase( np );
245  return;
246  }
247 
248  wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
249  " * [BUG] delNodeRef() did not find its target." ),
250  __FILE__, __FUNCTION__, __LINE__ );
251 }
std::list< WRL1NODE * > m_BackPointers
Definition: vrml1_node.h:230
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63

References WRL1NODE::m_BackPointers, and traceVrmlPlugin.

◆ FindNode()

WRL1NODE * WRL1NODE::FindNode ( const std::string &  aNodeName)
virtualinherited

Search the tree of linked nodes and returns a reference to the current node with the given name.

The reference is then typically added to another node via AddRefNode().

Parameters
aNodeNameis the name of the node to search for.
Returns
is a valid node pointer on success, otherwise NULL.

Definition at line 350 of file vrml1_node.cpp.

351 {
352  if( nullptr == m_dictionary )
353  return nullptr;
354 
355  return m_dictionary->FindName( aNodeName );
356 }
WRL1NODE * FindName(const std::string &aName)
Definition: vrml1_node.cpp:72
NAMEREGISTER * m_dictionary
Definition: vrml1_node.h:246

References NAMEREGISTER::FindName(), and WRL1NODE::m_dictionary.

Referenced by WRL1BASE::implementUse().

◆ GetError()

std::string WRL1NODE::GetError ( void  )
inherited

Definition at line 344 of file vrml1_node.cpp.

345 {
346  return m_error;
347 }
std::string m_error
Definition: vrml1_node.h:234

References WRL1NODE::m_error.

◆ GetName()

std::string WRL1NODE::GetName ( void  )
virtualinherited

Reimplemented in WRL1BASE.

Definition at line 266 of file vrml1_node.cpp.

267 {
268  return m_Name;
269 }
std::string m_Name
Definition: vrml1_node.h:228

References WRL1NODE::m_Name.

◆ GetNItems()

size_t WRL1NODE::GetNItems ( void  ) const
inherited

Definition at line 338 of file vrml1_node.cpp.

339 {
340  return m_Items.size();
341 }
std::list< WRL1NODE * > m_Items
Definition: vrml1_node.h:233

References WRL1NODE::m_Items.

◆ GetNodeType()

WRL1NODES WRL1NODE::GetNodeType ( void  ) const
inherited

Return the type of this node instance.

Definition at line 254 of file vrml1_node.cpp.

255 {
256  return m_Type;
257 }
WRL1NODES m_Type
Definition: vrml1_node.h:227

References WRL1NODE::m_Type.

Referenced by WRL1NODE::AddChildNode(), WRL1NODE::AddRefNode(), WRL1BASE::implementUse(), WRL1GROUP::TranslateToSG(), and WRL1TRANSFORM::TranslateToSG().

◆ getNodeTypeID()

WRL1NODES WRL1NODE::getNodeTypeID ( const std::string &  aNodeName)
inherited

Return the ID based on the given aNodeName or WRL1_INVALID (WRL1_END) if no such node name exists.

Definition at line 327 of file vrml1_node.cpp.

328 {
329  NODEMAP::iterator it = nodenames.find( aNodeName );
330 
331  if( nodenames.end() != it )
332  return it->second;
333 
335 }
static NODEMAP nodenames
Definition: vrml1_node.cpp:88

References nodenames, and WRL1_INVALID.

Referenced by WRL1BASE::ReadNode().

◆ GetNodeTypeName()

const char * WRL1NODE::GetNodeTypeName ( WRL1NODES  aNodeType) const
inherited

Definition at line 312 of file vrml1_node.cpp.

313 {
314  if( aNodeType < WRL1NODES::WRL1_BASE || aNodeType >= WRL1NODES::WRL1_END )
315  return "*INVALID_TYPE*";
316 
317  if( aNodeType == WRL1NODES::WRL1_BASE )
318  return "*VIRTUAL_BASE*";
319 
320  NODEMAP::iterator it = nodenames.begin();
321  advance( it, ( static_cast<int>( aNodeType ) - static_cast<int>( WRL1NODES::WRL1_BEGIN ) ) );
322 
323  return it->first.c_str();
324 }
static NODEMAP nodenames
Definition: vrml1_node.cpp:88

References nodenames, WRL1_BASE, WRL1_BEGIN, and WRL1_END.

Referenced by WRL1BASE::implementUse().

◆ GetParent()

WRL1NODE * WRL1NODE::GetParent ( void  ) const
inherited

Return a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie.

top level transform).

Definition at line 260 of file vrml1_node.cpp.

261 {
262  return m_Parent;
263 }
WRL1NODE * m_Parent
Definition: vrml1_node.h:226

References WRL1NODE::m_Parent.

Referenced by WRL1NODE::AddChildNode().

◆ Read()

bool WRL1FACESET::Read ( WRLPROC proc,
WRL1BASE aTopNode 
)
overridevirtual

Implements WRL1NODE.

Definition at line 77 of file vrml1_faceset.cpp.

78 {
79  char tok = proc.Peek();
80 
81  if( proc.eof() )
82  {
83  wxLogTrace( traceVrmlPlugin,
84  wxT( "%s:%s:%d\n"
85  " * [INFO] bad file format; unexpected eof %s." ),
86  __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
87 
88  return false;
89  }
90 
91  if( '{' != tok )
92  {
93  wxLogTrace( traceVrmlPlugin,
94  wxT( "%s:%s:%d\n"
95  " * [INFO] bad file format; expecting '{' but got '%s' %s." ),
96  __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
97 
98  return false;
99  }
100 
101  proc.Pop();
102  std::string glob;
103 
104  while( true )
105  {
106  if( proc.Peek() == '}' )
107  {
108  proc.Pop();
109  break;
110  }
111 
112  if( !proc.ReadName( glob ) )
113  {
114  wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n%s" ),
115  __FILE__, __FUNCTION__, __LINE__, proc.GetError() );
116 
117  return false;
118  }
119 
120  // expecting one of:
121  // coordIndex[]
122  // materialIndex[]
123 
124  if( !glob.compare( "coordIndex" ) )
125  {
126  if( !proc.ReadMFInt( coordIndex ) )
127  {
128  wxLogTrace( traceVrmlPlugin,
129  wxT( "%s:%s:%d\n"
130  " * [INFO] invalid coordIndex %s.\n"
131  " * [INFO] file: '%s'\n"
132  "%s" ),
133  __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
134  proc.GetFileName(), proc.GetError() );
135 
136  return false;
137  }
138  }
139  else if( !glob.compare( "materialIndex" ) )
140  {
141  if( !proc.ReadMFInt( matIndex ) )
142  {
143  wxLogTrace( traceVrmlPlugin,
144  wxT( "%s:%s:%d\n"
145  " * [INFO] invalid materialIndex %s.\n"
146  " * [INFO] file: '%s'\n"
147  "%s" ),
148  __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
149  proc.GetFileName(), proc.GetError() );
150 
151  return false;
152  }
153  }
154  else if( !glob.compare( "normalIndex" ) )
155  {
156  if( !proc.ReadMFInt( normIndex ) )
157  {
158  wxLogTrace( traceVrmlPlugin,
159  wxT( "%s:%s:%d\n"
160  " * [INFO] invalid normalIndex %s\n"
161  " * [INFO] file: '%s'\n"
162  "%s" ),
163  __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
164  proc.GetFileName(), proc.GetError() );
165 
166  return false;
167  }
168  }
169  else if( !glob.compare( "textureCoordIndex" ) )
170  {
171  if( !proc.ReadMFInt( texIndex ) )
172  {
173  wxLogTrace( traceVrmlPlugin,
174  wxT( "%s:%s:%d\n"
175  " * [INFO] invalid textureCoordIndex %s.\n"
176  " * [INFO] file: '%s'\n"
177  "%s" ),
178  __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
179  proc.GetFileName(), proc.GetError() );
180 
181  return false;
182  }
183  }
184  else
185  {
186  wxLogTrace( traceVrmlPlugin,
187  wxT( "%s:%s:%d\n"
188  " * [INFO] invalid IndexedFaceSet %s.\n"
189  " * [INFO] file: '%s'" ),
190  __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
191  proc.GetFileName() );
192 
193  return false;
194  }
195  } // while( true ) -- reading contents of IndexedFaceSet{}
196 
197  return true;
198 }
void Pop(void)
Definition: wrlproc.cpp:2035
std::vector< int > texIndex
Definition: vrml1_faceset.h:56
bool ReadMFInt(std::vector< int > &aMFInt32)
Definition: wrlproc.cpp:1504
std::vector< int > normIndex
Definition: vrml1_faceset.h:55
std::vector< int > matIndex
Definition: vrml1_faceset.h:54
std::string GetFilePosition() const
Definition: wrlproc.cpp:1982
std::vector< int > coordIndex
Definition: vrml1_faceset.h:53
char Peek(void)
Definition: wrlproc.cpp:2007
std::string GetFileName(void)
Definition: wrlproc.cpp:1995
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63
bool ReadName(std::string &aName)
Definition: wrlproc.cpp:289
std::string GetError(void)
Definition: wrlproc.cpp:1960
bool eof(void)
Definition: wrlproc.cpp:1954

References coordIndex, WRLPROC::eof(), WRLPROC::GetError(), WRLPROC::GetFileName(), WRLPROC::GetFilePosition(), matIndex, normIndex, WRLPROC::Peek(), WRLPROC::Pop(), WRLPROC::ReadMFInt(), WRLPROC::ReadName(), texIndex, and traceVrmlPlugin.

Referenced by WRL1BASE::readFaceSet().

◆ SetName()

bool WRL1NODE::SetName ( const std::string &  aName)
virtualinherited

Reimplemented in WRL1BASE.

Definition at line 272 of file vrml1_node.cpp.

273 {
274  if( aName.empty() )
275  return false;
276 
277  if( isdigit( aName[0] ) )
278  {
279  wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
280  " * [INFO] invalid node name '%s' (begins with digit)" ),
281  __FILE__, __FUNCTION__, __LINE__, aName );
282 
283  return false;
284  }
285 
286  // The character '+' is not allowed in names as per the VRML1 specification;
287  // however many parsers accept them and many bad generators use them so the rules
288  // have been relaxed here.
289  #define BAD_CHARS1 "\"\'#,.\\[]{}\x00\x01\x02\x03\x04\x05\x06\x09\x0A\x0B\x0C\x0D\x0E\x0F"
290  #define BAD_CHARS2 "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
291 
292  if( std::string::npos != aName.find_first_of( BAD_CHARS1 )
293  || std::string::npos != aName.find_first_of( BAD_CHARS2 ) )
294  {
295  wxLogTrace( traceVrmlPlugin,
296  wxT( "%s:%s:%d\n"
297  " * [INFO] invalid node name '%s' (contains invalid character)" ),
298  __FILE__, __FUNCTION__, __LINE__, aName );
299 
300  return false;
301  }
302 
303  m_Name = aName;
304 
305  if( m_dictionary )
306  m_dictionary->AddName( aName, this );
307 
308  return true;
309 }
std::string m_Name
Definition: vrml1_node.h:228
bool AddName(const std::string &aName, WRL1NODE *aNode)
Definition: vrml1_node.cpp:39
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63
NAMEREGISTER * m_dictionary
Definition: vrml1_node.h:246
#define BAD_CHARS2
#define BAD_CHARS1

References NAMEREGISTER::AddName(), BAD_CHARS1, BAD_CHARS2, WRL1NODE::m_dictionary, WRL1NODE::m_Name, and traceVrmlPlugin.

Referenced by WRL1BASE::implementDef().

◆ SetParent()

bool WRL1NODE::SetParent ( WRL1NODE aParent,
bool  doUnlink = true 
)
virtualinherited

Set the parent WRL1NODE of this object.

Parameters
aParent[in] is the desired parent node.
doUnlinkindicates that the child must be unlinked from the parent
Returns
true if the operation succeeds; false if the given node is not allowed to be a parent to the derived object.

Reimplemented in WRL1BASE.

Definition at line 359 of file vrml1_node.cpp.

360 {
361  if( aParent == m_Parent )
362  return true;
363 
364  if( nullptr != m_Parent && doUnlink )
365  m_Parent->unlinkChildNode( this );
366 
367  m_Parent = aParent;
368 
369  if( nullptr != m_Parent )
370  m_Parent->AddChildNode( this );
371 
372  return true;
373 }
virtual void unlinkChildNode(const WRL1NODE *aNode)
Remove references to an owned child; it is invoked by the child upon destruction to ensure that the p...
Definition: vrml1_node.cpp:420
virtual bool AddChildNode(WRL1NODE *aNode)
Definition: vrml1_node.cpp:376
WRL1NODE * m_Parent
Definition: vrml1_node.h:226

References WRL1NODE::AddChildNode(), WRL1NODE::m_Parent, and WRL1NODE::unlinkChildNode().

Referenced by WRL1NODE::AddChildNode().

◆ TranslateToSG()

SGNODE * WRL1FACESET::TranslateToSG ( SGNODE aParent,
WRL1STATUS sp 
)
overridevirtual

Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg library.

Parameters
aParentis a pointer to the parent SG node.
Returns
is non-NULL on success.

Implements WRL1NODE.

Definition at line 201 of file vrml1_faceset.cpp.

202 {
203  // note: m_sgNode is unused because we cannot manage everything
204  // with a single reused transform due to the fact that VRML1
205  // may use a MatrixTransformation entity which is impossible to
206  // decompose into Rotate,Scale,Transform via an analytic expression.
207  if( !m_Parent )
208  {
209  wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] bad model: no parent node." ) );
210 
211  return nullptr;
212  }
213  else
214  {
215  if( nullptr == sp )
216  {
217  wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] bad model: no base data given." ) );
218 
219  return nullptr;
220  }
221  }
222 
223  m_current = *sp;
224 
225  if( nullptr == m_current.coord )
226  {
227  wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] bad model: no vertex set." ) );
228  return nullptr;
229  }
230 
231  if( nullptr == m_current.mat )
232  {
233  wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] bad model: no material set." ) );
234  return nullptr;
235  }
236 
237  WRLVEC3F* pcoords;
238  size_t coordsize;
239 
240  m_current.coord->GetCoords( pcoords, coordsize );
241  size_t vsize = coordIndex.size();
242 
243  if( coordsize < 3 || vsize < 3 )
244  {
245  wxLogTrace( traceVrmlPlugin,
246  wxT( " * [INFO] bad model: coordsize = %zu, indexsize = %zu" ),
247  coordsize, vsize );
248 
249  return nullptr;
250  }
251 
252  // 1. create the vertex/normals/colors lists
253  SGNODE* sgcolor = nullptr;
255  size_t matSize = matIndex.size();
256 
257  switch( mbind )
258  {
262  break;
263 
265 
266  if( matIndex.empty() )
267  {
268  wxLogTrace( traceVrmlPlugin,
269  wxT( " * [INFO] bad model: per face indexed but no indices" ) );
270 
271  // support bad models by temporarily switching bindings
273  sgcolor = m_current.mat->GetAppearance( 0 );
274  }
275 
276  break;
277 
278  default:
279 
280  // use the first appearance definition
281  sgcolor = m_current.mat->GetAppearance( 0 );
282  break;
283  }
284 
285  // copy the data into FACET structures
286 
287  SHAPE lShape;
288  FACET* fp = nullptr;
289  size_t iCoord;
290  int idx; // coordinate index
291  size_t cidx = 0; // color index
292  SGCOLOR pc1;
293 
294  if( mbind == WRL1_BINDING::BIND_OVERALL || mbind == WRL1_BINDING::BIND_DEFAULT )
295  {
296  // no per-vertex colors; we can save a few CPU cycles
297  for( iCoord = 0; iCoord < vsize; ++iCoord )
298  {
299  idx = coordIndex[iCoord];
300 
301  if( idx < 0 )
302  {
303  if( nullptr != fp )
304  {
305  if( fp->HasMinPoints() )
306  fp = nullptr;
307  else
308  fp->Init();
309  }
310 
311  continue;
312  }
313 
314  // if the coordinate is bad then skip it
315  if( idx >= (int)coordsize )
316  continue;
317 
318  if( nullptr == fp )
319  fp = lShape.NewFacet();
320 
321  // push the vertex value and index
322  WRLVEC3F vf;
323  glm::vec4 pt = glm::vec4( pcoords[idx].x, pcoords[idx].y, pcoords[idx].z, 1.0 );
324  pt = m_current.txmatrix * pt;
325  vf.x = pt.x;
326  vf.y = pt.y;
327  vf.z = pt.z;
328 
329  fp->AddVertex( vf, idx );
330  }
331  }
332  else
333  {
334  for( iCoord = 0; iCoord < vsize; ++iCoord )
335  {
336  idx = coordIndex[iCoord];
337 
338  if( idx < 0 )
339  {
340  if( nullptr != fp )
341  {
342  if( fp->HasMinPoints() )
343  fp = nullptr;
344  else
345  fp->Init();
346  }
347 
348  if( mbind == WRL1_BINDING::BIND_PER_FACE
350  ++cidx;
351 
352  continue;
353  }
354 
355  // if the coordinate is bad then skip it
356  if( idx >= (int)coordsize )
357  continue;
358 
359  if( nullptr == fp )
360  fp = lShape.NewFacet();
361 
362  // push the vertex value and index
363  WRLVEC3F vf;
364  glm::vec4 pt = glm::vec4( pcoords[idx].x, pcoords[idx].y, pcoords[idx].z, 1.0 );
365  pt = m_current.txmatrix * pt;
366  vf.x = pt.x;
367  vf.y = pt.y;
368  vf.z = pt.z;
369 
370  fp->AddVertex( vf, idx );
371 
372  // push the color if appropriate
373  switch( mbind )
374  {
376 
377  if( !fp->HasColors() )
378  {
379  m_current.mat->GetColor( &pc1, cidx );
380  fp->AddColor( pc1 );
381  }
382 
383  break;
384 
386  m_current.mat->GetColor( &pc1, idx );
387  fp->AddColor( pc1 );
388  break;
389 
391 
392  if( !fp->HasColors() )
393  {
394  if( cidx >= matSize )
395  m_current.mat->GetColor( &pc1, matIndex.back() );
396  else
397  m_current.mat->GetColor( &pc1, matIndex[cidx] );
398 
399  fp->AddColor( pc1 );
400  }
401 
402  break;
403 
405 
406  if( matIndex.empty() )
407  {
408  m_current.mat->GetColor( &pc1, idx );
409  }
410  else
411  {
412  if( iCoord >= matSize )
413  m_current.mat->GetColor( &pc1, matIndex.back() );
414  else
415  m_current.mat->GetColor( &pc1, matIndex[iCoord] );
416  }
417 
418  fp->AddColor( pc1 );
419 
420  break;
421 
422  default:
423  break;
424  }
425  }
426  }
427 
428  // extract the final data set
429  SGNODE* np = lShape.CalcShape( aParent, sgcolor, m_current.order, m_current.creaseLimit );
430 
431  return np;
432 }
SGNODE * CalcShape(SGNODE *aParent, SGNODE *aColor, WRL1_ORDER aVertexOrder, float aCreaseLimit=0.74317, bool isVRML2=false)
Definition: wrlfacet.cpp:703
glm::vec3 WRLVEC3F
Definition: wrltypes.h:188
WRL1_BINDING matbind
Definition: vrml1_node.h:97
WRL1STATUS m_current
Definition: vrml1_node.h:236
WRL1COORDS * coord
Definition: vrml1_node.h:94
float creaseLimit
Definition: vrml1_node.h:109
void AddVertex(WRLVEC3F &aVertex, int aIndex)
Add the vertex and its associated index to the internal list of polygon vertices.
Definition: wrlfacet.cpp:191
void Init()
Definition: wrlfacet.cpp:158
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
glm::mat4 txmatrix
Definition: vrml1_node.h:103
void AddColor(const SGCOLOR &aColor)
Add the given RGB color to the internal list.
Definition: wrlfacet.cpp:204
WRL1_BINDING
Definition: wrltypes.h:100
bool HasColors()
Definition: wrlfacet.cpp:182
std::vector< int > matIndex
Definition: vrml1_faceset.h:54
An abstract shape on 2D plane.
Definition: shape.h:116
std::vector< int > coordIndex
Definition: vrml1_faceset.h:53
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63
SGNODE * GetAppearance(int aIndex)
Return an SGAPPEARANCE node representing the appearance for an IndexedFaceSet.
FACET * NewFacet()
Definition: wrlfacet.cpp:695
Definition: wrlfacet.h:42
void GetColor(SGCOLOR *aColor, int aIndex)
Compute an SGCOLOR representing the appearance of a vertex or face.
WRL1NODE * m_Parent
Definition: vrml1_node.h:226
void GetCoords(WRLVEC3F *&aCoordList, size_t &aListSize)
WRL1_ORDER order
Definition: vrml1_node.h:106
WRL1MATERIAL * mat
Definition: vrml1_node.h:88
bool HasMinPoints()
Definition: wrlfacet.cpp:173

References FACET::AddColor(), FACET::AddVertex(), BIND_DEFAULT, BIND_OVERALL, BIND_PER_FACE, BIND_PER_FACE_INDEXED, BIND_PER_VERTEX, BIND_PER_VERTEX_INDEXED, SHAPE::CalcShape(), WRL1STATUS::coord, coordIndex, WRL1STATUS::creaseLimit, WRL1MATERIAL::GetAppearance(), WRL1MATERIAL::GetColor(), WRL1COORDS::GetCoords(), FACET::HasColors(), FACET::HasMinPoints(), FACET::Init(), WRL1NODE::m_current, WRL1NODE::m_Parent, WRL1STATUS::mat, WRL1STATUS::matbind, matIndex, SHAPE::NewFacet(), WRL1STATUS::order, traceVrmlPlugin, and WRL1STATUS::txmatrix.

◆ unlinkChildNode()

void WRL1NODE::unlinkChildNode ( const WRL1NODE aNode)
virtualinherited

Remove references to an owned child; it is invoked by the child upon destruction to ensure that the parent has no invalid references.

Parameters
aNodeis the child which is being deleted.

Definition at line 420 of file vrml1_node.cpp.

421 {
422  std::list< WRL1NODE* >::iterator sL = m_Children.begin();
423  std::list< WRL1NODE* >::iterator eL = m_Children.end();
424 
425  while( sL != eL )
426  {
427  if( *sL == aNode )
428  {
429  m_Children.erase( sL );
430  delItem( aNode );
431  return;
432  }
433 
434  ++sL;
435  }
436 }
void delItem(const WRL1NODE *aNode)
Definition: vrml1_node.cpp:464
std::list< WRL1NODE * > m_Children
Definition: vrml1_node.h:231

References WRL1NODE::delItem(), and WRL1NODE::m_Children.

Referenced by WRL1NODE::SetParent(), and WRL1NODE::~WRL1NODE().

◆ unlinkRefNode()

void WRL1NODE::unlinkRefNode ( const WRL1NODE aNode)
virtualinherited

Remove pointers to a referenced node; it is invoked by the referenced node upon destruction to ensure that the referring node has no invalid references.

Parameters
aNodeis the node which is being deleted.

Definition at line 439 of file vrml1_node.cpp.

440 {
441  std::list< WRL1NODE* >::iterator sL = m_Refs.begin();
442  std::list< WRL1NODE* >::iterator eL = m_Refs.end();
443 
444  while( sL != eL )
445  {
446  if( *sL == aNode )
447  {
448  m_Refs.erase( sL );
449  delItem( aNode );
450  return;
451  }
452 
453  ++sL;
454  }
455 }
std::list< WRL1NODE * > m_Refs
Definition: vrml1_node.h:232
void delItem(const WRL1NODE *aNode)
Definition: vrml1_node.cpp:464

References WRL1NODE::delItem(), and WRL1NODE::m_Refs.

Member Data Documentation

◆ coordIndex

std::vector< int > WRL1FACESET::coordIndex
private

Definition at line 53 of file vrml1_faceset.h.

Referenced by Read(), and TranslateToSG().

◆ m_BackPointers

◆ m_Children

◆ m_current

WRL1STATUS WRL1NODE::m_current
protectedinherited

◆ m_dictionary

◆ m_error

std::string WRL1NODE::m_error
protectedinherited

Definition at line 234 of file vrml1_node.h.

Referenced by WRL1NODE::GetError().

◆ m_Items

◆ m_Name

std::string WRL1NODE::m_Name
protectedinherited

Definition at line 228 of file vrml1_node.h.

Referenced by WRL1NODE::GetName(), WRL1NODE::SetName(), and WRL1NODE::~WRL1NODE().

◆ m_Parent

◆ m_Refs

◆ m_sgNode

SGNODE* WRL1NODE::m_sgNode
protectedinherited

Definition at line 237 of file vrml1_node.h.

Referenced by WRL1NODE::WRL1NODE().

◆ m_Type

◆ matIndex

std::vector< int > WRL1FACESET::matIndex
private

Definition at line 54 of file vrml1_faceset.h.

Referenced by Read(), and TranslateToSG().

◆ normIndex

std::vector< int > WRL1FACESET::normIndex
private

Definition at line 55 of file vrml1_faceset.h.

Referenced by Read().

◆ texIndex

std::vector< int > WRL1FACESET::texIndex
private

Definition at line 56 of file vrml1_faceset.h.

Referenced by Read().


The documentation for this class was generated from the following files: