25#include <wx/filename.h>
38#define SG_VERSION_TAG "VERSION:2"
74 bool reuse,
bool renameNodes )
76 if(
nullptr == filename || filename[0] == 0 )
79 wxString ofile = wxString::FromUTF8Unchecked( filename );
81 if( wxFileName::Exists( ofile ) )
87 if( !wxFileName::FileExists( ofile ) )
97 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] failed to open file '%s'" ),
98 __FILE__, __FUNCTION__, __LINE__, filename );
103 op.imbue( std::locale::classic() );
104 op <<
"#VRML V2.0 utf8\n";
122 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] problems encountered writing file '%s'" ),
123 __FILE__, __FUNCTION__, __LINE__, filename );
154 const char* aPluginInfo )
156 if(
nullptr == aFileName || aFileName[0] == 0 )
159 wxString ofile = wxString::FromUTF8Unchecked( aFileName );
161 wxCHECK( aNode,
false );
163 if( wxFileName::Exists( ofile ) )
167 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] file exists not overwriting '%s'" ),
168 __FILE__, __FUNCTION__, __LINE__, aFileName );
174 if( !wxFileName::FileExists( aFileName ) )
176 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] specified path is a directory '%s'" ),
177 __FILE__, __FUNCTION__, __LINE__, aFileName );
187 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] failed to open file '%s'" ),
188 __FILE__, __FUNCTION__, __LINE__, aFileName );
195 if(
nullptr != aPluginInfo && aPluginInfo[0] != 0 )
196 output <<
"(" << aPluginInfo <<
")";
198 output <<
"(INTERNAL:0.0.0.0)";
205 wxLogTrace( MASK_3D_SG,
206 wxT(
"%s:%s:%d * [INFO] problems encountered writing cache file '%s'" ),
207 __FILE__, __FUNCTION__, __LINE__, aFileName );
210 wxRemoveFile( ofile );
218 bool (*aTagCheck)(
const char*,
void* ) )
220 if(
nullptr == aFileName || aFileName[0] == 0 )
223 wxString ofile = wxString::FromUTF8Unchecked( aFileName );
225 if( !wxFileName::FileExists( aFileName ) )
227 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] no such file '%s'" ),
228 __FILE__, __FUNCTION__, __LINE__, aFileName );
233 std::unique_ptr<SGNODE> np = std::make_unique<SCENEGRAPH>(
nullptr );
239 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] failed to open file '%s'" ),
240 __FILE__, __FUNCTION__, __LINE__, aFileName );
255 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data; missing left parenthesis"
256 " at position '%d'" ),
257 __FILE__, __FUNCTION__, __LINE__,
258 static_cast<int>( file.tellg() ) );
266 while(
')' != schar && file.good() )
268 name.push_back( schar );
290 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] corrupt data; missing left parenthesis"
291 " at position '%d'" ),
292 __FILE__, __FUNCTION__, __LINE__,
293 static_cast<int>( file.tellg() ) );
301 while(
')' != schar && file.good() )
303 name.push_back( schar );
308 if(
nullptr != aTagCheck &&
nullptr != aPluginMgr
309 && !aTagCheck(
name.c_str(), aPluginMgr ) )
317 bool rval = np->ReadCache( file,
nullptr );
322 wxLogTrace( MASK_3D_SG, wxT(
"%s:%s:%d * [INFO] problems encountered reading cache file "
324 __FILE__, __FUNCTION__, __LINE__,
336 if(
nullptr == aNode )
343 std::vector< SMESH > meshes;
357 materials.
matorder.push_back( &app );
358 materials.
matmap.emplace( &app, 0 );
360 if( aNode->
Prepare(
nullptr, materials, meshes ) )
368 size_t j = materials.
matorder.size();
371 for(
size_t i = 0; i < j; ++i )
374 model->m_Materials = lmat;
375 model->m_MaterialsSize = j;
381 for(
size_t i = 0; i < j; ++i )
382 lmesh[i] = meshes[i];
384 model->m_Meshes = lmesh;
385 model->m_MeshesSize = j;
390 size_t j = meshes.size();
392 for(
size_t i = 0; i < j; ++i )
401 if(
nullptr == aModel ||
nullptr == *aModel )
444 unsigned char* Revision )
noexcept
462 glm::dvec3 tri = glm::dvec3( 0.0, 0.0, 0.0 );
465 pts[0] = glm::dvec3( p1.
x, p1.
y, p1.
z );
466 pts[1] = glm::dvec3( p2.
x, p2.
y, p2.
z );
467 pts[2] = glm::dvec3( p3.
x, p3.
y, p3.
z );
474 tri = glm::cross( pts[1] - pts[0], pts[2] - pts[0] );
475 (void)glm::normalize( tri );
477 return SGVECTOR( tri.x, tri.y, tri.z );
483 if(
nullptr == aNode )
492 if(
nullptr == aNode )
501 if(
nullptr == aParent ||
nullptr == aChild )
510 if(
nullptr == aParent ||
nullptr == aChild )
519 if(
nullptr == aObject ||
nullptr == aRefPtr || aObject != *aRefPtr )
Define the basic data set required to represent a 3D model.
bool Prepare(const glm::dmat4 *aTransform, S3D::MATLIST &materials, std::vector< SMESH > &meshes)
Defines the generic material appearance of a scenegraph object.
void GetColor(float &aRedVal, float &aGreenVal, float &aBlueVal) const noexcept
The base class of all Scene Graph nodes.
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.
virtual bool AddRefNode(SGNODE *aNode)=0
SGNODE * GetParent(void) const noexcept
Returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie.
virtual void ReNameNodes(void)=0
Rename a node and all its child nodes in preparation for write operations.
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
virtual bool AddChildNode(SGNODE *aNode)=0
void AssociateWrapper(SGNODE **aWrapperRef) noexcept
Associate this object with a handle to itself.
virtual bool WriteVRML(std::ostream &aFile, bool aReuseFlag)=0
Writes this node's data to a VRML file.
static void formatMaterial(SMATERIAL &mat, SGAPPEARANCE const *app)
void Free3DModel(S3DMODEL &aModel)
defines the API calls for the manipulation of SG* classes
SGLIB_API void Init3DMaterial(SMATERIAL &aMat)
Initializes an SMATERIAL structure.
void INIT_SMESH(SMESH &aMesh) noexcept
SGLIB_API void RenameNodes(SGNODE *aNode)
Rename a node and all children nodes based on the current values of the global SG* class indices.
SGLIB_API void Free3DMesh(SMESH &aMesh)
Free memory used internally by an SMESH structure.
SGLIB_API SGNODE * ReadCache(const char *aFileName, void *aPluginMgr, bool(*aTagCheck)(const char *, void *))
Read a binary cache file and creates an SGNODE tree.
SGLIB_API S3D::SGTYPES GetSGNodeType(SGNODE *aNode)
SGLIB_API void Init3DMesh(SMESH &aMesh)
Create and initialize an SMESH structure.
SGLIB_API bool WriteCache(const char *aFileName, bool overwrite, SGNODE *aNode, const char *aPluginInfo)
Write the SGNODE tree to a binary cache file.
SGLIB_API bool WriteVRML(const char *filename, bool overwrite, SGNODE *aTopNode, bool reuse, bool renameNodes)
Write out the given node and its subnodes to a VRML2 file.
void INIT_SMATERIAL(SMATERIAL &aMaterial)
SGLIB_API S3DMODEL * New3DModel(void)
Create and initialize an S3DMODEL structure.
SGLIB_API void ResetNodeIndex(SGNODE *aNode)
Reset the global SG* class indices.
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
SGLIB_API SGVECTOR CalcTriNorm(const SGPOINT &p1, const SGPOINT &p2, const SGPOINT &p3)
Return the normal vector of a triangle described by vertices p1, p2, p3.
SGLIB_API void DestroyNode(SGNODE *aNode) noexcept
Delete the given SG* class node.
bool degenerate(glm::dvec3 *pts) noexcept
void FREE_SMESH(SMESH &aMesh) noexcept
void INIT_S3DMODEL(S3DMODEL &aModel) noexcept
SGLIB_API S3DMODEL * GetModel(SCENEGRAPH *aNode)
Create an S3DMODEL representation of aNode (raw data, no transforms).
SGLIB_API bool AddSGNodeChild(SGNODE *aParent, SGNODE *aChild)
void FREE_S3DMODEL(S3DMODEL &aModel)
SGLIB_API void GetLibVersion(unsigned char *Major, unsigned char *Minor, unsigned char *Patch, unsigned char *Revision) noexcept
Retrieve version information of the kicad_3dsg library.
SGLIB_API void AssociateSGNodeWrapper(SGNODE *aObject, SGNODE **aRefPtr)
SGLIB_API bool AddSGNodeRef(SGNODE *aParent, SGNODE *aChild)
SGLIB_API void Destroy3DModel(S3DMODEL **aModel)
Free memory used by an S3DMODEL structure and sets the pointer to the structure to NULL.
Define a number of macros to aid in repetitious code which is probably best expressed as a preprocess...
defines the library version of the intermediate scenegraph (SG) implementation
#define KICADSG_VERSION_MAJOR
#define KICADSG_VERSION_REVISION
#define KICADSG_VERSION_PATCH
#define KICADSG_VERSION_MINOR
#define OPEN_OSTREAM(var, name)
#define CLOSE_STREAM(var)
#define OPEN_ISTREAM(var, name)
Store the a model based on meshes and materials.
std::vector< SGAPPEARANCE const * > matorder
std::map< SGAPPEARANCE const *, int > matmap
float m_Transparency
1.0 is completely transparent, 0.0 completely opaque
SFVEC3F m_Diffuse
Default diffuse color if m_Color is NULL.
Per-vertex normal/color/texcoors structure.