From d68418d613b4712220556367979688108be05d0c Mon Sep 17 00:00:00 2001 From: Cirilo Bernardo Date: Fri, 1 Jan 2016 18:55:43 +1100 Subject: [PATCH] Work in progress: WRL2 to SGNODE translation --- plugins/3d/vrml/v2/vrml2_appearance.cpp | 7 +++ plugins/3d/vrml/v2/vrml2_appearance.h | 2 + plugins/3d/vrml/v2/vrml2_base.cpp | 66 +++++++++++++++++++++++++ plugins/3d/vrml/v2/vrml2_base.h | 1 + plugins/3d/vrml/v2/vrml2_color.cpp | 7 +++ plugins/3d/vrml/v2/vrml2_color.h | 2 + plugins/3d/vrml/v2/vrml2_coords.cpp | 7 +++ plugins/3d/vrml/v2/vrml2_coords.h | 2 + plugins/3d/vrml/v2/vrml2_faceset.cpp | 7 +++ plugins/3d/vrml/v2/vrml2_faceset.h | 2 + plugins/3d/vrml/v2/vrml2_material.cpp | 7 +++ plugins/3d/vrml/v2/vrml2_material.h | 2 + plugins/3d/vrml/v2/vrml2_node.cpp | 1 + plugins/3d/vrml/v2/vrml2_node.h | 13 +++++ plugins/3d/vrml/v2/vrml2_norms.cpp | 7 +++ plugins/3d/vrml/v2/vrml2_norms.h | 2 + plugins/3d/vrml/v2/vrml2_shape.cpp | 7 +++ plugins/3d/vrml/v2/vrml2_shape.h | 2 + plugins/3d/vrml/v2/vrml2_transform.cpp | 7 +++ plugins/3d/vrml/v2/vrml2_transform.h | 2 + plugins/3d/vrml/vrml.cpp | 5 +- 21 files changed, 157 insertions(+), 1 deletion(-) diff --git a/plugins/3d/vrml/v2/vrml2_appearance.cpp b/plugins/3d/vrml/v2/vrml2_appearance.cpp index dc3c8bf83f..17aa2f13af 100644 --- a/plugins/3d/vrml/v2/vrml2_appearance.cpp +++ b/plugins/3d/vrml/v2/vrml2_appearance.cpp @@ -346,3 +346,10 @@ bool WRL2APPEARANCE::Read( WRLPROC& proc, WRL2BASE* aTopNode ) return true; } + + +SGNODE* WRL2APPEARANCE::TranslateToSG( SGNODE* aParent ) +{ + // XXX - TO IMPLEMENT + return NULL; +} diff --git a/plugins/3d/vrml/v2/vrml2_appearance.h b/plugins/3d/vrml/v2/vrml2_appearance.h index 6f50bc76b6..6c49f2c0b1 100644 --- a/plugins/3d/vrml/v2/vrml2_appearance.h +++ b/plugins/3d/vrml/v2/vrml2_appearance.h @@ -32,6 +32,7 @@ #include "vrml2_node.h" class WRL2BASE; +class SGNODE; /** * Class WRL2APPEARANCE @@ -63,6 +64,7 @@ public: bool Read( WRLPROC& proc, WRL2BASE* aTopNode ); bool AddRefNode( WRL2NODE* aNode ); bool AddChildNode( WRL2NODE* aNode ); + SGNODE* TranslateToSG( SGNODE* aParent ); }; #endif // VRML2_APPEARANCE_H diff --git a/plugins/3d/vrml/v2/vrml2_base.cpp b/plugins/3d/vrml/v2/vrml2_base.cpp index b49d998c6d..5819eedc02 100644 --- a/plugins/3d/vrml/v2/vrml2_base.cpp +++ b/plugins/3d/vrml/v2/vrml2_base.cpp @@ -32,6 +32,7 @@ #include "vrml2_coords.h" #include "vrml2_norms.h" #include "vrml2_color.h" +#include "plugins/3dapi/ifsg_all.h" WRL2BASE::WRL2BASE() : WRL2NODE() @@ -762,3 +763,68 @@ bool WRL2BASE::readColor( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode ) return true; } + + +SGNODE* WRL2BASE::TranslateToSG( SGNODE* aParent ) +{ + if( m_Children.empty() ) + return NULL; + + if( m_topNode ) + return m_topNode; + + IFSG_TRANSFORM topNode( aParent ); + + std::list< WRL2NODE* >::iterator sC = m_Children.begin(); + std::list< WRL2NODE* >::iterator eC = m_Children.end(); + WRL2NODES type; + + // Include only Shape and Transform nodes in the top node + bool test = false; // set to true if there are any subnodes for display + + while( sC != eC ) + { + type = (*sC)->GetNodeType(); + + switch( type ) + { + case WRL2_SHAPE: + // wrap the shape in a transform + do + { + IFSG_TRANSFORM wrapper( topNode.GetRawPtr() ); + SGNODE* pshape = (*sC)->TranslateToSG( wrapper.GetRawPtr() ); + + if( NULL != pshape ) + test = true; + else + wrapper.Destroy(); + + } while( 0 ); + + break; + + case WRL2_TRANSFORM: + + if( NULL != (*sC)->TranslateToSG( topNode.GetRawPtr() ) ) + test = true; + + break; + + default: + break; + } + + ++ sC; + } + + if( false == test ) + { + topNode.Destroy(); + return NULL; + } + + m_topNode = topNode.GetRawPtr(); + + return m_topNode; +} diff --git a/plugins/3d/vrml/v2/vrml2_base.h b/plugins/3d/vrml/v2/vrml2_base.h index 195c00fe5a..9cf9e65fe8 100644 --- a/plugins/3d/vrml/v2/vrml2_base.h +++ b/plugins/3d/vrml/v2/vrml2_base.h @@ -91,6 +91,7 @@ public: // functions inherited from WRL2NODE bool Read( WRLPROC& proc, WRL2BASE* aTopNode ); bool SetParent( WRL2NODE* aParent ); + SGNODE* TranslateToSG( SGNODE* aParent ); }; #endif // VRML2_BASE_H diff --git a/plugins/3d/vrml/v2/vrml2_color.cpp b/plugins/3d/vrml/v2/vrml2_color.cpp index 60974c14bc..2595e333f5 100644 --- a/plugins/3d/vrml/v2/vrml2_color.cpp +++ b/plugins/3d/vrml/v2/vrml2_color.cpp @@ -187,3 +187,10 @@ bool WRL2COLOR::Read( WRLPROC& proc, WRL2BASE* aTopNode ) return false; } + + +SGNODE* WRL2COLOR::TranslateToSG( SGNODE* aParent ) +{ + // XXX - TO IMPLEMENT + return NULL; +} diff --git a/plugins/3d/vrml/v2/vrml2_color.h b/plugins/3d/vrml/v2/vrml2_color.h index 37f3eafd5d..b4554938d0 100644 --- a/plugins/3d/vrml/v2/vrml2_color.h +++ b/plugins/3d/vrml/v2/vrml2_color.h @@ -34,6 +34,7 @@ #include "vrml2_node.h" class WRL2BASE; +class SGNODE; /** * Class WRL2COLOR @@ -57,6 +58,7 @@ public: bool Read( WRLPROC& proc, WRL2BASE* aTopNode ); bool AddRefNode( WRL2NODE* aNode ); bool AddChildNode( WRL2NODE* aNode ); + SGNODE* TranslateToSG( SGNODE* aParent ); }; #endif // VRML2_COLOR_H diff --git a/plugins/3d/vrml/v2/vrml2_coords.cpp b/plugins/3d/vrml/v2/vrml2_coords.cpp index c44f257fed..b41a1d84b3 100644 --- a/plugins/3d/vrml/v2/vrml2_coords.cpp +++ b/plugins/3d/vrml/v2/vrml2_coords.cpp @@ -187,3 +187,10 @@ bool WRL2COORDS::Read( WRLPROC& proc, WRL2BASE* aTopNode ) return false; } + + +SGNODE* WRL2COORDS::TranslateToSG( SGNODE* aParent ) +{ + // XXX - TO IMPLEMENT + return NULL; +} diff --git a/plugins/3d/vrml/v2/vrml2_coords.h b/plugins/3d/vrml/v2/vrml2_coords.h index c4fa08c09f..0f6d3aaa3b 100644 --- a/plugins/3d/vrml/v2/vrml2_coords.h +++ b/plugins/3d/vrml/v2/vrml2_coords.h @@ -34,6 +34,7 @@ #include "vrml2_node.h" class WRL2BASE; +class SGNODE; /** * Class WRL2COORDS @@ -57,6 +58,7 @@ public: bool Read( WRLPROC& proc, WRL2BASE* aTopNode ); bool AddRefNode( WRL2NODE* aNode ); bool AddChildNode( WRL2NODE* aNode ); + SGNODE* TranslateToSG( SGNODE* aParent ); }; #endif // VRML2_COORDS_H diff --git a/plugins/3d/vrml/v2/vrml2_faceset.cpp b/plugins/3d/vrml/v2/vrml2_faceset.cpp index 96f9830132..ef3fa8e479 100644 --- a/plugins/3d/vrml/v2/vrml2_faceset.cpp +++ b/plugins/3d/vrml/v2/vrml2_faceset.cpp @@ -558,3 +558,10 @@ bool WRL2FACESET::Read( WRLPROC& proc, WRL2BASE* aTopNode ) return true; } + + +SGNODE* WRL2FACESET::TranslateToSG( SGNODE* aParent ) +{ + // XXX - TO IMPLEMENT + return NULL; +} diff --git a/plugins/3d/vrml/v2/vrml2_faceset.h b/plugins/3d/vrml/v2/vrml2_faceset.h index 71bdb68046..d020e47843 100644 --- a/plugins/3d/vrml/v2/vrml2_faceset.h +++ b/plugins/3d/vrml/v2/vrml2_faceset.h @@ -34,6 +34,7 @@ #include "vrml2_node.h" class WRL2BASE; +class SGNODE; /** * Class WRL2FACESET @@ -81,6 +82,7 @@ public: bool Read( WRLPROC& proc, WRL2BASE* aTopNode ); bool AddRefNode( WRL2NODE* aNode ); bool AddChildNode( WRL2NODE* aNode ); + SGNODE* TranslateToSG( SGNODE* aParent ); }; #endif // VRML2_FACESET_H diff --git a/plugins/3d/vrml/v2/vrml2_material.cpp b/plugins/3d/vrml/v2/vrml2_material.cpp index a3d3765620..c48aa3d14c 100644 --- a/plugins/3d/vrml/v2/vrml2_material.cpp +++ b/plugins/3d/vrml/v2/vrml2_material.cpp @@ -285,3 +285,10 @@ bool WRL2MATERIAL::Read( WRLPROC& proc, WRL2BASE* aTopNode ) return true; } + + +SGNODE* WRL2MATERIAL::TranslateToSG( SGNODE* aParent ) +{ + // XXX - TO IMPLEMENT + return NULL; +} diff --git a/plugins/3d/vrml/v2/vrml2_material.h b/plugins/3d/vrml/v2/vrml2_material.h index cd425ffd1d..c3daa1f953 100644 --- a/plugins/3d/vrml/v2/vrml2_material.h +++ b/plugins/3d/vrml/v2/vrml2_material.h @@ -32,6 +32,7 @@ #include "vrml2_node.h" class WRL2BASE; +class SGNODE; /** * Class WRL2MATERIAL @@ -62,6 +63,7 @@ public: bool Read( WRLPROC& proc, WRL2BASE* aTopNode ); bool AddRefNode( WRL2NODE* aNode ); bool AddChildNode( WRL2NODE* aNode ); + SGNODE* TranslateToSG( SGNODE* aParent ); }; #endif // VRML2_MATERIAL_H diff --git a/plugins/3d/vrml/v2/vrml2_node.cpp b/plugins/3d/vrml/v2/vrml2_node.cpp index 8cf9826017..8cef1b4e0c 100644 --- a/plugins/3d/vrml/v2/vrml2_node.cpp +++ b/plugins/3d/vrml/v2/vrml2_node.cpp @@ -42,6 +42,7 @@ static NODEMAP nodenames; WRL2NODE::WRL2NODE() { + m_topNode = NULL; m_Parent = NULL; m_Type = WRL2_END; diff --git a/plugins/3d/vrml/v2/vrml2_node.h b/plugins/3d/vrml/v2/vrml2_node.h index f9d18320d3..a39e856b4e 100644 --- a/plugins/3d/vrml/v2/vrml2_node.h +++ b/plugins/3d/vrml/v2/vrml2_node.h @@ -49,6 +49,7 @@ #include "wrlproc.h" class WRL2BASE; +class SGNODE; /** * Class WRL2NODE @@ -66,6 +67,8 @@ protected: std::list< WRL2NODE* > m_Refs; // nodes referenced by this node std::string m_error; + SGNODE* m_topNode; // the SGNODE representation of the display data + public: /** @@ -173,6 +176,16 @@ public: virtual bool AddRefNode( WRL2NODE* aNode ); std::string GetError( void ); + + /** + * Function TranslateToSG + * produces a representation of the data using the intermediate + * scenegraph structures of the kicad_3dsg library. + * + * @param aParent is a pointer to the parent SG node + * @return is non-NULL on success + */ + virtual SGNODE* TranslateToSG( SGNODE* aParent ) = 0; }; #endif // VRML2_NODE_H diff --git a/plugins/3d/vrml/v2/vrml2_norms.cpp b/plugins/3d/vrml/v2/vrml2_norms.cpp index b62a10e8c2..8845d75749 100644 --- a/plugins/3d/vrml/v2/vrml2_norms.cpp +++ b/plugins/3d/vrml/v2/vrml2_norms.cpp @@ -187,3 +187,10 @@ bool WRL2NORMS::Read( WRLPROC& proc, WRL2BASE* aTopNode ) return false; } + + +SGNODE* WRL2NORMS::TranslateToSG( SGNODE* aParent ) +{ + // XXX - TO IMPLEMENT + return NULL; +} diff --git a/plugins/3d/vrml/v2/vrml2_norms.h b/plugins/3d/vrml/v2/vrml2_norms.h index 7cffdbafb1..7eb5a5ff34 100644 --- a/plugins/3d/vrml/v2/vrml2_norms.h +++ b/plugins/3d/vrml/v2/vrml2_norms.h @@ -34,6 +34,7 @@ #include "vrml2_node.h" class WRL2BASE; +class SGNODE; /** * Class WRL2NORMS @@ -57,6 +58,7 @@ public: bool Read( WRLPROC& proc, WRL2BASE* aTopNode ); bool AddRefNode( WRL2NODE* aNode ); bool AddChildNode( WRL2NODE* aNode ); + SGNODE* TranslateToSG( SGNODE* aParent ); }; #endif // VRML2_NORMS_H diff --git a/plugins/3d/vrml/v2/vrml2_shape.cpp b/plugins/3d/vrml/v2/vrml2_shape.cpp index 4c7991a182..ec32310f9d 100644 --- a/plugins/3d/vrml/v2/vrml2_shape.cpp +++ b/plugins/3d/vrml/v2/vrml2_shape.cpp @@ -309,3 +309,10 @@ bool WRL2SHAPE::Read( WRLPROC& proc, WRL2BASE* aTopNode ) return true; } + + +SGNODE* WRL2SHAPE::TranslateToSG( SGNODE* aParent ) +{ + // XXX - TO IMPLEMENT + return NULL; +} diff --git a/plugins/3d/vrml/v2/vrml2_shape.h b/plugins/3d/vrml/v2/vrml2_shape.h index 8b416f2bf4..18406411a9 100644 --- a/plugins/3d/vrml/v2/vrml2_shape.h +++ b/plugins/3d/vrml/v2/vrml2_shape.h @@ -32,6 +32,7 @@ #include "vrml2_node.h" class WRL2BASE; +class SGNODE; /** * Class WRL2SHAPE @@ -62,6 +63,7 @@ public: bool Read( WRLPROC& proc, WRL2BASE* aTopNode ); bool AddRefNode( WRL2NODE* aNode ); bool AddChildNode( WRL2NODE* aNode ); + SGNODE* TranslateToSG( SGNODE* aParent ); }; #endif // VRML2_SHAPE_H diff --git a/plugins/3d/vrml/v2/vrml2_transform.cpp b/plugins/3d/vrml/v2/vrml2_transform.cpp index 913788b3d4..20b073263b 100644 --- a/plugins/3d/vrml/v2/vrml2_transform.cpp +++ b/plugins/3d/vrml/v2/vrml2_transform.cpp @@ -333,3 +333,10 @@ bool WRL2TRANSFORM::readChildren( WRLPROC& proc, WRL2BASE* aTopNode ) return true; } + + +SGNODE* WRL2TRANSFORM::TranslateToSG( SGNODE* aParent ) +{ + // XXX - TO IMPLEMENT + return NULL; +} diff --git a/plugins/3d/vrml/v2/vrml2_transform.h b/plugins/3d/vrml/v2/vrml2_transform.h index 73ccbdce28..857064eafc 100644 --- a/plugins/3d/vrml/v2/vrml2_transform.h +++ b/plugins/3d/vrml/v2/vrml2_transform.h @@ -32,6 +32,7 @@ #include "vrml2_node.h" class WRL2BASE; +class SGNODE; /** * Class WRL2TRANSFORM @@ -62,6 +63,7 @@ public: // functions inherited from WRL2NODE bool Read( WRLPROC& proc, WRL2BASE* aTopNode ); bool AddRefNode( WRL2NODE* aNode ); + SGNODE* TranslateToSG( SGNODE* aParent ); }; #endif // VRML2_TRANSFORM_H diff --git a/plugins/3d/vrml/vrml.cpp b/plugins/3d/vrml/vrml.cpp index 3f8a8f1574..246e6ef467 100644 --- a/plugins/3d/vrml/vrml.cpp +++ b/plugins/3d/vrml/vrml.cpp @@ -176,6 +176,7 @@ SCENEGRAPH* Load( char const* aFileName ) return NULL; LOCALESWITCH switcher; + SCENEGRAPH* scene = NULL; // VRML file processor WRLPROC proc; @@ -207,10 +208,12 @@ SCENEGRAPH* Load( char const* aFileName ) #ifdef DEBUG std::cout << " * [INFO] load completed\n"; #endif + + scene = (SCENEGRAPH*)bp->TranslateToSG( NULL ); } delete bp; } - return NULL; + return scene; }