25#define GLM_FORCE_RADIANS 
   52        wxLogTrace( MASK_3D_SG,
 
   53                    wxT( 
"%s:%s:%d * [BUG] inappropriate parent to SCENEGRAPH (type %d)" ),
 
   54                    __FILE__, __FUNCTION__, __LINE__,
 
   55                    aParent->GetNodeType() );
 
   59        m_Parent->AddChildNode( this );
 
 
   89        if( 
nullptr == aParent )
 
 
  108    if( 
nullptr == aNodeName || 0 == aNodeName[0] )
 
  111    if( !
m_Name.compare( aNodeName ) )
 
  121    return m_Parent->FindNode( aNodeName, 
this );
 
 
  127    if( 
nullptr == aNode )
 
  145    wxLogTrace( MASK_3D_SG, wxT( 
"%s:%s:%d * [BUG] unlinkNode() did not find its target" ),
 
  146                __FILE__, __FUNCTION__, __LINE__ );
 
 
  166    wxCHECK( aNode, 
false );
 
  171    wxLogTrace( MASK_3D_SG,
 
  172                wxT( 
"%s:%s:%d * [BUG] object '%s' is not a valid type for this object (%d)" ),
 
  173                __FILE__, __FUNCTION__, __LINE__,
 
 
  183    return addNode( aNode, 
false );
 
 
  204        std::vector< SGSHAPE* >::iterator sL = 
m_Shape.begin();
 
  205        std::vector< SGSHAPE* >::iterator eL = 
m_Shape.end();
 
  209            (*sL)->ReNameNodes();
 
  218        std::vector< SCENEGRAPH* >::iterator sL = 
m_Transforms.begin();
 
  219        std::vector< SCENEGRAPH* >::iterator eL = 
m_Transforms.end();
 
  223            (*sL)->ReNameNodes();
 
 
  244            aFile << 
"DEF " << 
GetName() << 
" Transform {\n";
 
  249            aFile << 
"USE " << 
GetName() << 
"\n";
 
  255        aFile << 
" Transform {\n";
 
  265    aFile << 
"  center " << tmp << 
"\n";
 
  267    aFile << 
"  rotation " << tmp << 
"\n";
 
  269    aFile << 
"  scale " << tmp << 
"\n";
 
  271    aFile << 
"  scaleOrientation " << tmp << 
"\n";
 
  279    aFile << 
"  translation " << tmp << 
"\n";
 
  281    aFile << 
" children [\n";
 
  285        std::vector< SCENEGRAPH* >::iterator sL = 
m_Transforms.begin();
 
  286        std::vector< SCENEGRAPH* >::iterator eL = 
m_Transforms.end();
 
  290            (*sL)->WriteVRML( aFile, aReuseFlag );
 
  297        std::vector< SCENEGRAPH* >::iterator sL = 
m_RTransforms.begin();
 
  298        std::vector< SCENEGRAPH* >::iterator eL = 
m_RTransforms.end();
 
  302            (*sL)->WriteVRML( aFile, aReuseFlag );
 
  309        std::vector< SGSHAPE* >::iterator sL = 
m_Shape.begin();
 
  310        std::vector< SGSHAPE* >::iterator eL = 
m_Shape.end();
 
  314            (*sL)->WriteVRML( aFile, aReuseFlag );
 
  321        std::vector< SGSHAPE* >::iterator sL = 
m_RShape.begin();
 
  322        std::vector< SGSHAPE* >::iterator eL = 
m_RShape.end();
 
  326            (*sL)->WriteVRML( aFile, aReuseFlag );
 
 
  339    if( 
nullptr == parentNode && 
nullptr != 
m_Parent )
 
  355    wxCHECK( parentNode == 
m_Parent, 
false );
 
  366        wxLogTrace( MASK_3D_SG, wxT( 
"%s:%s:%d * [INFO] bad stream" ),
 
  367                    __FILE__, __FUNCTION__, __LINE__ );
 
  372    aFile << 
"[" << 
GetName() << 
"]";
 
  385    for( i = 0; i < asize; ++i )
 
  398    for( i = 0; i < asize; ++i )
 
  409    aFile.write( (
char*)&asize, 
sizeof( 
size_t ) );
 
  411    aFile.write( (
char*)&asize, 
sizeof( 
size_t ) );
 
  413    aFile.write( (
char*)&asize, 
sizeof( 
size_t ) );
 
  415    aFile.write( (
char*)&asize, 
sizeof( 
size_t ) );
 
  419    for( i = 0; i < asize; ++i )
 
  423            wxLogTrace( MASK_3D_SG,
 
  424                        wxT( 
"%s:%s:%d * [INFO] bad stream while writing child transforms" ),
 
  425                        __FILE__, __FUNCTION__, __LINE__ );
 
  434    for( i = 0; i < asize; ++i )
 
  440    for( i = 0; i < asize; ++i )
 
  444            wxLogTrace( MASK_3D_SG,
 
  445                        wxT( 
"%s:%s:%d * [INFO] bad stream while writing child shapes" ),
 
  446                        __FILE__, __FUNCTION__, __LINE__ );
 
  455    for( i = 0; i < asize; ++i )
 
 
  473    if( 
nullptr == parentNode )
 
  478            wxLogTrace( MASK_3D_SG, wxT( 
"%s:%s:%d * [INFO] corrupt data; tag mismatch at position " 
  480                        __FILE__, __FUNCTION__, __LINE__,
 
  481                        static_cast<unsigned long>( aFile.tellg() ) );
 
  503    aFile.read( (
char*)&sizeCT, 
sizeof( 
size_t ) );
 
  504    aFile.read( (
char*)&sizeRT, 
sizeof( 
size_t ) );
 
  505    aFile.read( (
char*)&sizeCS, 
sizeof( 
size_t ) );
 
  506    aFile.read( (
char*)&sizeRS, 
sizeof( 
size_t ) );
 
  511    for( i = 0; i < sizeCT; ++i )
 
  515            wxLogTrace( MASK_3D_SG, wxT( 
"%s:%s:%d * [INFO] corrupt data; bad child transform tag " 
  517                        __FILE__, __FUNCTION__, __LINE__,
 
  518                        static_cast<unsigned long>( aFile.tellg() ) );
 
  528            wxLogTrace( MASK_3D_SG, wxT( 
"%s:%s:%d * [INFO] corrupt data while reading transform " 
  530                        __FILE__, __FUNCTION__, __LINE__,
 
  531                        static_cast<unsigned long>( aFile.tellg() ) );
 
  538    for( i = 0; i < sizeRT; ++i )
 
  542            wxLogTrace( MASK_3D_SG, wxT( 
"%s:%s:%d * [INFO] corrupt data; bad ref transform tag at " 
  544                        __FILE__, __FUNCTION__, __LINE__,
 
  545                        static_cast<unsigned long>( aFile.tellg() ) );
 
  554            wxLogTrace( MASK_3D_SG, wxT( 
"%s:%s:%d * [INFO] corrupt data: cannot find ref " 
  555                                         "transform at position %ul" ),
 
  556                        __FILE__, __FUNCTION__, __LINE__,
 
  557                        static_cast<unsigned long>( aFile.tellg() ) );
 
  564            wxLogTrace( MASK_3D_SG, wxT( 
"%s:%s:%d * [INFO] corrupt data: type is not TRANSFORM " 
  566                        __FILE__, __FUNCTION__, __LINE__,
 
  567                        static_cast<unsigned long>( aFile.tellg() ) );
 
  576    for( i = 0; i < sizeCS; ++i )
 
  580            wxLogTrace( MASK_3D_SG, wxT( 
"%s:%s:%d * [INFO] corrupt data; bad child shape tag at " 
  582                        __FILE__, __FUNCTION__, __LINE__,
 
  583                        static_cast<unsigned long>( aFile.tellg() ) );
 
  593            wxLogTrace( MASK_3D_SG, wxT( 
"%s:%s:%d * [INFO] corrupt data; corrupt data while " 
  594                                        "reading shape at position %ul" ),
 
  595                        __FILE__, __FUNCTION__, __LINE__,
 
  596                        static_cast<unsigned long>( aFile.tellg() ) );
 
  603    for( i = 0; i < sizeRS; ++i )
 
  607            wxLogTrace( MASK_3D_SG, wxT( 
"%s:%s:%d * [INFO] corrupt data; bad ref shape tag at " 
  609                        __FILE__, __FUNCTION__, __LINE__,
 
  610                        static_cast<unsigned long>( aFile.tellg() ) );
 
  619            wxLogTrace( MASK_3D_SG, wxT( 
"%s:%s:%d * [INFO] corrupt data: cannot find ref shape " 
  621                        __FILE__, __FUNCTION__, __LINE__,
 
  622                        static_cast<unsigned long>( aFile.tellg() ) );
 
  629            wxLogTrace( MASK_3D_SG, wxT( 
"%s:%s:%d * [INFO] corrupt data: type is not SGSHAPE at " 
  631                        __FILE__, __FUNCTION__, __LINE__,
 
  632                        static_cast<unsigned long>( aFile.tellg() ) );
 
 
  648                          std::vector< SMESH >& meshes )
 
  655    glm::dmat4 rM = glm::rotate( glm::dmat4( 1.0 ), 
rotation_angle, glm::dvec3( rX, rY, rZ ) );
 
  661    glm::dmat4 cM = glm::translate( glm::dmat4( 1.0 ), glm::dvec3( 
center.x, 
center.y, 
center.z ) );
 
  662    glm::dmat4 ncM = glm::translate( glm::dmat4( 1.0 ), glm::dvec3( -
center.x, -
center.y,
 
  666    glm::dmat4 sM = glm::scale( glm::dmat4( 1.0 ), glm::dvec3( 
scale.x, 
scale.y, 
scale.z ) );
 
  670    glm::dmat4 srM = glm::rotate( glm::dmat4( 1.0 ), 
scale_angle, glm::dvec3( rX, rY, rZ ) );
 
  671    glm::dmat4 nsrM = glm::rotate( glm::dmat4( 1.0 ), -
scale_angle, glm::dvec3( rX, rY, rZ ) );
 
  679    if( 
nullptr != aTransform )
 
  680        tx0  = (*aTransform) * tM * cM * rM * srM * sM * nsrM * ncM;
 
  682        tx0  = tM * cM * rM * srM * sM * nsrM * ncM;
 
  689        std::vector< SGSHAPE* >::iterator sL = 
m_Shape.begin();
 
  690        std::vector< SGSHAPE* >::iterator eL = 
m_Shape.end();
 
  692        while( sL != eL && ok )
 
  694            ok = (*sL)->Prepare( &tx0, materials, meshes );
 
  701        while( sL != eL && ok )
 
  703            ok = (*sL)->Prepare( &tx0, materials, meshes );
 
  712        std::vector< SCENEGRAPH* >::iterator sL = 
m_Transforms.begin();
 
  713        std::vector< SCENEGRAPH* >::iterator eL = 
m_Transforms.end();
 
  715        while( sL != eL && ok )
 
  717            ok = (*sL)->Prepare( &tx0, materials, meshes );
 
  724        while( sL != eL && ok )
 
  726            ok = (*sL)->Prepare( &tx0, materials, meshes );
 
 
void unlinkChildNode(const SGNODE *aNode) override
Remove references to an owned child.
 
bool Prepare(const glm::dmat4 *aTransform, S3D::MATLIST &materials, std::vector< SMESH > &meshes)
 
bool AddChildNode(SGNODE *aNode) override
 
std::vector< SGSHAPE * > m_RShape
 
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 ReadCache(std::istream &aFile, SGNODE *parentNode) override
Reads binary format data from a cache file.
 
void unlinkNode(const SGNODE *aNode, bool isChild)
 
SCENEGRAPH(SGNODE *aParent)
 
std::vector< SCENEGRAPH * > m_RTransforms
 
void ReNameNodes(void) override
Rename a node and all its child nodes in preparation for write operations.
 
std::vector< SGSHAPE * > m_Shape
 
std::vector< SCENEGRAPH * > m_Transforms
 
bool addNode(SGNODE *aNode, bool isChild)
 
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 WriteCache(std::ostream &aFile, SGNODE *parentNode) override
Write this node's data to a binary cache file.
 
bool AddRefNode(SGNODE *aNode) override
 
void unlinkRefNode(const SGNODE *aNode) override
Remove pointers to a referenced node.
 
void SetName(const char *aName)
 
void ResetNodeIndex(void) noexcept
Reset the global SG* node indices in preparation for write operations.
 
virtual bool WriteCache(std::ostream &aFile, SGNODE *parentNode)=0
Write this node's data to a binary cache file.
 
const char * GetName(void)
 
bool isWritten(void) noexcept
Return true if the object had already been written to a cache file or VRML file.
 
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.
 
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 complex 3D shape for a scenegraph object.
 
bool ReadCache(std::istream &aFile, SGNODE *parentNode) override
Reads binary format data from a cache file.
 
bool ReadVector(std::istream &aFile, SGVECTOR &aVector)
 
bool ReadPoint(std::istream &aFile, SGPOINT &aPoint)
 
bool WritePoint(std::ostream &aFile, const SGPOINT &aPoint)
 
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.
 
bool WriteVector(std::ostream &aFile, const SGVECTOR &aVector)
 
void FormatPoint(std::string &result, const SGPOINT &point)
 
void FormatOrientation(std::string &result, const SGVECTOR &axis, double rotation)
 
Define a number of macros to aid in repetitious code which is probably best expressed as a preprocess...
 
#define DEL_OBJS(aType, aList)
 
#define ADD_NODE(aNodeID, aType, aNode, aOwnedList, aRefList, isChild)
 
#define DROP_REFS(aType, aList)
 
#define FIND_NODE(aType, aName, aNodeList, aCallingNode)
 
#define UNLINK_NODE(aNodeID, aType, aNode, aOwnedList, aRefList, isChild)