48 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [BUG] inappropriate parent to SGSHAPE (type %d)" ),
49 __FILE__, __FUNCTION__, __LINE__, aParent->GetNodeType() );
53 m_Parent->AddChildNode( this );
103 if(
nullptr == aParent )
122 if(
nullptr == aNodeName || 0 == aNodeName[0] )
125 if( !
m_Name.compare( aNodeName ) )
142 tmp =
m_FaceSet->FindNode( aNodeName,
this );
154 return m_Parent->FindNode( aNodeName,
this );
160 if(
nullptr == aNode )
194 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [BUG] unlinkNode() did not find its target" ),
195 __FILE__, __FUNCTION__, __LINE__ );
213 wxCHECK( aNode,
false );
221 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [BUG] assigning multiple Appearance "
223 __FILE__, __FUNCTION__, __LINE__ );
251 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [BUG] assigning multiple FaceSet nodes" ),
252 __FILE__, __FUNCTION__, __LINE__ );
274 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [BUG] object %s is not a valid type for this "
284 return addNode( aNode,
false );
323 aFile <<
"DEF " <<
GetName() <<
" Shape {\n";
328 aFile <<
" USE " <<
GetName() <<
"\n";
334 aFile <<
" Shape {\n";
344 m_FaceSet->WriteVRML( aFile, aReuseFlag );
357 if(
nullptr == parentNode )
375 wxCHECK( parentNode ==
m_Parent,
false );
379 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [BUG] bad stream" ),
380 __FILE__, __FUNCTION__, __LINE__ );
392 aFile <<
"[" <<
GetName() <<
"]";
397 for( i = 0; i <
NITEMS; ++i )
420 for(
int jj = 0; jj <
NITEMS; ++jj )
421 aFile.write( (
char*)&items[jj],
sizeof(
bool) );
451 for(
int i = 0; i <
NITEMS; ++i )
452 aFile.read( (
char*)&items[i],
sizeof(
bool) );
454 if( ( items[0] && items[1] ) || ( items[2] && items[3] ) )
456 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data; multiple item definitions "
458 __FILE__, __FUNCTION__, __LINE__,
459 static_cast<unsigned long>( aFile.tellg() ) );
470 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data; bad child appearance "
471 "tag at position %ul" ),
472 __FILE__, __FUNCTION__, __LINE__,
473 static_cast<unsigned long>( aFile.tellg() ) );
483 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data while reading appearance "
485 __FILE__, __FUNCTION__, __LINE__,
name );
495 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data; bad ref appearance tag "
497 __FILE__, __FUNCTION__, __LINE__,
498 static_cast<unsigned long>( aFile.tellg() ) );
507 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data: cannot find ref "
509 __FILE__, __FUNCTION__, __LINE__,
517 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data: type is not "
518 "SGAPPEARANCE '%s'" ),
519 __FILE__, __FUNCTION__, __LINE__,
533 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data; bad child face set tag "
535 __FILE__, __FUNCTION__, __LINE__,
536 static_cast<unsigned long>( aFile.tellg() ) );
544 if( !
m_FaceSet->ReadCache( aFile,
this ) )
546 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data while reading face set "
548 __FILE__, __FUNCTION__, __LINE__,
name );
558 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data; bad ref face set tag at "
560 __FILE__, __FUNCTION__, __LINE__,
561 static_cast<unsigned long>( aFile.tellg() ) );
570 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data: cannot find ref face "
572 __FILE__, __FUNCTION__, __LINE__,
580 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data: type is not SGFACESET "
582 __FILE__, __FUNCTION__, __LINE__,
600 std::vector< SMESH >& meshes )
620 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] bad model; inconsistent data" ),
621 __FILE__, __FUNCTION__, __LINE__ );
671 if( nColors < nCoords )
673 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] bad model; not enough colors per "
674 "vertex (%ul vs %ul)" ),
675 __FILE__, __FUNCTION__, __LINE__,
static_cast<unsigned long>( nColors ),
676 static_cast<unsigned long>( nCoords ) );
688 std::vector< int > vertices;
689 std::map< int, unsigned int > indexmap;
690 std::map< int, unsigned int >::iterator mit;
692 for(
unsigned int i = 0; i < nvidx; ++i )
694 mit = indexmap.find( lv[i] );
696 if( mit == indexmap.end() )
698 indexmap.emplace( lv[i], vertices.size() );
699 vertices.push_back( lv[i] );
703 if( vertices.size() < 3 )
705 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] bad model; not enough vertices" ),
706 __FILE__, __FUNCTION__, __LINE__ );
718 lColors =
new SFVEC3F[vertices.size()];
724 for(
size_t i = 0; i < vertices.size(); ++i )
727 glm::dvec4 pt( pCoords[ti].x, pCoords[ti].y, pCoords[ti].z, 1.0 );
728 pt = (*aTransform) * pt;
729 pColors[ti].
GetColor( lColors[i].x, lColors[i].y, lColors[i].z );
730 lCoords[i] =
SFVEC3F( pt.x, pt.y, pt.z );
735 for(
size_t i = 0; i < vertices.size(); ++i )
738 glm::dvec4 pt( pCoords[ti].x, pCoords[ti].y, pCoords[ti].z, 1.0 );
739 pt = (*aTransform) * pt;
740 lCoords[i] =
SFVEC3F( pt.x, pt.y, pt.z );
746 unsigned int* lvidx =
new unsigned int[ nvidx ];
748 for(
unsigned int i = 0; i < nvidx; ++i )
750 mit = indexmap.find( lv[i] );
752 if( mit != indexmap.end() )
753 lvidx[i] = mit->second;
767 for(
size_t i = 0; i < vertices.size(); ++i )
771 glm::dvec4 pt( x, y, z, 0.0 );
772 pt = (*aTransform) * pt;
774 lNorms[i] =
SFVEC3F( pt.x, pt.y, pt.z );
778 meshes.push_back( m );
Defines the generic material appearance of a scenegraph object.
Define an RGB color set for a scenegraph object.
bool GetColorList(size_t &aListSize, SGCOLOR *&aColorList)
void GetColor(float &aRedVal, float &aGreenVal, float &aBlueVal) const noexcept
An object to maintain a coordinate index list.
Define a vertex coordinate set for a scenegraph object.
bool GetCoordsList(size_t &aListSize, SGPOINT *&aCoordsList)
Define an indexed face set for a scenegraph.
SGCOORDINDEX * m_CoordIndices
bool GetIndices(size_t &nIndices, int *&aIndexList)
Retrieve the number of indices and a pointer to the list.
virtual bool WriteCache(std::ostream &aFile, SGNODE *parentNode)=0
Write this node's data to a binary cache file.
const char * GetName(void)
SGNODE * GetParent(void) const noexcept
Returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie.
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
std::string m_Name
name to use for referencing the entity by name.
void delNodeRef(const SGNODE *aNode)
Remove a pointer to a node which references this node, but does not own.
bool m_written
Set to true when the object has been written after a ReNameNodes().
S3D::SGTYPES m_SGtype
Type of Scene Graph node.
Define a set of vertex normals for a scene graph object.
bool GetNormalList(size_t &aListSize, SGVECTOR *&aNormalList)
SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller) override
Search the tree of linked nodes and return a reference to the first node found with the given name.
bool WriteVRML(std::ostream &aFile, bool aReuseFlag) override
Writes this node's data to a VRML file.
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Set the parent SGNODE of this object.
bool AddChildNode(SGNODE *aNode) override
void unlinkRefNode(const SGNODE *aNode) override
Remove pointers to a referenced node.
void unlinkNode(const SGNODE *aNode, bool isChild)
bool Prepare(const glm::dmat4 *aTransform, S3D::MATLIST &materials, std::vector< SMESH > &meshes)
bool AddRefNode(SGNODE *aNode) override
void ReNameNodes(void) override
Rename a node and all its child nodes in preparation for write operations.
bool addNode(SGNODE *aNode, bool isChild)
void unlinkChildNode(const SGNODE *aNode) override
Remove references to an owned child.
bool WriteCache(std::ostream &aFile, SGNODE *parentNode) override
Write this node's data to a binary cache file.
SGAPPEARANCE * m_RAppearance
bool ReadCache(std::istream &aFile, SGNODE *parentNode) override
Reads binary format data from a cache file.
SGAPPEARANCE * m_Appearance
void GetVector(double &aXVal, double &aYVal, double &aZVal) const noexcept
void INIT_SMESH(SMESH &aMesh) noexcept
bool GetMatIndex(MATLIST &aList, SGNODE *aNode, int &aIndex)
S3D::SGTYPES ReadTag(std::istream &aFile, std::string &aName)
Read the text tag of a binary cache file which is the NodeTag and unique ID number combined.
Define a number of macros to aid in repetitious code which is probably best expressed as a preprocess...
Per-vertex normal/color/texcoors structure.
unsigned int * m_FaceIdx
Triangle Face Indexes.
SFVEC3F * m_Normals
Vertex normals array.
unsigned int m_MaterialIdx
Material Index to be used in this mesh (must be < m_MaterialsSize )
unsigned int m_VertexSize
Number of vertex in the arrays.
unsigned int m_FaceIdxSize
Number of elements of the m_FaceIdx array.
SFVEC3F * m_Color
Vertex color array, can be NULL.
SFVEC3F * m_Positions
Vertex position array.