21#define GLM_FORCE_RADIANS
48 wxLogTrace( MASK_3D_SG,
49 wxT(
"%s:%s:%d * [BUG] inappropriate parent to SCENEGRAPH (type %d)" ),
50 __FILE__, __FUNCTION__, __LINE__,
51 aParent->GetNodeType() );
55 m_Parent->AddChildNode( this );
85 if(
nullptr == aParent )
104 if(
nullptr == aNodeName || 0 == aNodeName[0] )
107 if( !
m_Name.compare( aNodeName ) )
117 return m_Parent->FindNode( aNodeName,
this );
123 if(
nullptr == aNode )
141 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [BUG] unlinkNode() did not find its target" ),
142 __FILE__, __FUNCTION__, __LINE__ );
162 wxCHECK( aNode,
false );
167 wxLogTrace( MASK_3D_SG,
168 wxT(
"%s:%s:%d * [BUG] object '%s' is not a valid type for this object (%d)" ),
169 __FILE__, __FUNCTION__, __LINE__,
179 return addNode( aNode,
false );
200 std::vector< SGSHAPE* >::iterator sL =
m_Shape.begin();
201 std::vector< SGSHAPE* >::iterator eL =
m_Shape.end();
205 (*sL)->ReNameNodes();
214 std::vector< SCENEGRAPH* >::iterator sL =
m_Transforms.begin();
215 std::vector< SCENEGRAPH* >::iterator eL =
m_Transforms.end();
219 (*sL)->ReNameNodes();
240 aFile <<
"DEF " <<
GetName() <<
" Transform {\n";
245 aFile <<
"USE " <<
GetName() <<
"\n";
251 aFile <<
" Transform {\n";
261 aFile <<
" center " << tmp <<
"\n";
263 aFile <<
" rotation " << tmp <<
"\n";
265 aFile <<
" scale " << tmp <<
"\n";
267 aFile <<
" scaleOrientation " << tmp <<
"\n";
275 aFile <<
" translation " << tmp <<
"\n";
277 aFile <<
" children [\n";
281 std::vector< SCENEGRAPH* >::iterator sL =
m_Transforms.begin();
282 std::vector< SCENEGRAPH* >::iterator eL =
m_Transforms.end();
286 (*sL)->WriteVRML( aFile, aReuseFlag );
293 std::vector< SCENEGRAPH* >::iterator sL =
m_RTransforms.begin();
294 std::vector< SCENEGRAPH* >::iterator eL =
m_RTransforms.end();
298 (*sL)->WriteVRML( aFile, aReuseFlag );
305 std::vector< SGSHAPE* >::iterator sL =
m_Shape.begin();
306 std::vector< SGSHAPE* >::iterator eL =
m_Shape.end();
310 (*sL)->WriteVRML( aFile, aReuseFlag );
317 std::vector< SGSHAPE* >::iterator sL =
m_RShape.begin();
318 std::vector< SGSHAPE* >::iterator eL =
m_RShape.end();
322 (*sL)->WriteVRML( aFile, aReuseFlag );
335 if(
nullptr == parentNode &&
nullptr !=
m_Parent )
351 wxCHECK( parentNode ==
m_Parent,
false );
362 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] bad stream" ),
363 __FILE__, __FUNCTION__, __LINE__ );
368 aFile <<
"[" <<
GetName() <<
"]";
381 for( i = 0; i < asize; ++i )
394 for( i = 0; i < asize; ++i )
405 aFile.write( (
char*)&asize,
sizeof(
size_t ) );
407 aFile.write( (
char*)&asize,
sizeof(
size_t ) );
409 aFile.write( (
char*)&asize,
sizeof(
size_t ) );
411 aFile.write( (
char*)&asize,
sizeof(
size_t ) );
415 for( i = 0; i < asize; ++i )
419 wxLogTrace( MASK_3D_SG,
420 wxT(
"%s:%s:%d * [INFO] bad stream while writing child transforms" ),
421 __FILE__, __FUNCTION__, __LINE__ );
430 for( i = 0; i < asize; ++i )
436 for( i = 0; i < asize; ++i )
440 wxLogTrace( MASK_3D_SG,
441 wxT(
"%s:%s:%d * [INFO] bad stream while writing child shapes" ),
442 __FILE__, __FUNCTION__, __LINE__ );
451 for( i = 0; i < asize; ++i )
469 if(
nullptr == parentNode )
474 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data; tag mismatch at position "
476 __FILE__, __FUNCTION__, __LINE__,
477 static_cast<unsigned long>( aFile.tellg() ) );
499 aFile.read( (
char*)&sizeCT,
sizeof(
size_t ) );
500 aFile.read( (
char*)&sizeRT,
sizeof(
size_t ) );
501 aFile.read( (
char*)&sizeCS,
sizeof(
size_t ) );
502 aFile.read( (
char*)&sizeRS,
sizeof(
size_t ) );
507 for( i = 0; i < sizeCT; ++i )
511 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data; bad child transform tag "
513 __FILE__, __FUNCTION__, __LINE__,
514 static_cast<unsigned long>( aFile.tellg() ) );
524 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data while reading transform "
526 __FILE__, __FUNCTION__, __LINE__,
527 static_cast<unsigned long>( aFile.tellg() ) );
534 for( i = 0; i < sizeRT; ++i )
538 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data; bad ref transform tag at "
540 __FILE__, __FUNCTION__, __LINE__,
541 static_cast<unsigned long>( aFile.tellg() ) );
550 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data: cannot find ref "
551 "transform at position %ul" ),
552 __FILE__, __FUNCTION__, __LINE__,
553 static_cast<unsigned long>( aFile.tellg() ) );
560 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data: type is not TRANSFORM "
562 __FILE__, __FUNCTION__, __LINE__,
563 static_cast<unsigned long>( aFile.tellg() ) );
572 for( i = 0; i < sizeCS; ++i )
576 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data; bad child shape tag at "
578 __FILE__, __FUNCTION__, __LINE__,
579 static_cast<unsigned long>( aFile.tellg() ) );
589 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data; corrupt data while "
590 "reading shape at position %ul" ),
591 __FILE__, __FUNCTION__, __LINE__,
592 static_cast<unsigned long>( aFile.tellg() ) );
599 for( i = 0; i < sizeRS; ++i )
603 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data; bad ref shape tag at "
605 __FILE__, __FUNCTION__, __LINE__,
606 static_cast<unsigned long>( aFile.tellg() ) );
615 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data: cannot find ref shape "
617 __FILE__, __FUNCTION__, __LINE__,
618 static_cast<unsigned long>( aFile.tellg() ) );
625 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data: type is not SGSHAPE at "
627 __FILE__, __FUNCTION__, __LINE__,
628 static_cast<unsigned long>( aFile.tellg() ) );
644 std::vector< SMESH >& meshes )
651 glm::dmat4 rM = glm::rotate( glm::dmat4( 1.0 ),
rotation_angle, glm::dvec3( rX, rY, rZ ) );
657 glm::dmat4 cM = glm::translate( glm::dmat4( 1.0 ), glm::dvec3(
center.x,
center.y,
center.z ) );
658 glm::dmat4 ncM = glm::translate( glm::dmat4( 1.0 ), glm::dvec3( -
center.x, -
center.y,
662 glm::dmat4 sM = glm::scale( glm::dmat4( 1.0 ), glm::dvec3(
scale.x,
scale.y,
scale.z ) );
666 glm::dmat4 srM = glm::rotate( glm::dmat4( 1.0 ),
scale_angle, glm::dvec3( rX, rY, rZ ) );
667 glm::dmat4 nsrM = glm::rotate( glm::dmat4( 1.0 ), -
scale_angle, glm::dvec3( rX, rY, rZ ) );
675 if(
nullptr != aTransform )
676 tx0 = (*aTransform) * tM * cM * rM * srM * sM * nsrM * ncM;
678 tx0 = tM * cM * rM * srM * sM * nsrM * ncM;
685 std::vector< SGSHAPE* >::iterator sL =
m_Shape.begin();
686 std::vector< SGSHAPE* >::iterator eL =
m_Shape.end();
688 while( sL != eL && ok )
690 ok = (*sL)->Prepare( &tx0, materials, meshes );
697 while( sL != eL && ok )
699 ok = (*sL)->Prepare( &tx0, materials, meshes );
708 std::vector< SCENEGRAPH* >::iterator sL =
m_Transforms.begin();
709 std::vector< SCENEGRAPH* >::iterator eL =
m_Transforms.end();
711 while( sL != eL && ok )
713 ok = (*sL)->Prepare( &tx0, materials, meshes );
720 while( sL != eL && ok )
722 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)