KiCad PCB EDA Suite
ifsg_api.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <iostream>
25 #include <sstream>
26 #include <fstream>
27 #include <wx/filename.h>
28 #include <wx/log.h>
29 #include "plugins/3dapi/ifsg_api.h"
31 #include "streamwrapper.h"
32 #include "3d_cache/sg/sg_node.h"
33 #include "3d_cache/sg/scenegraph.h"
35 #include "3d_cache/sg/sg_shape.h"
36 #include "3d_cache/sg/sg_helpers.h"
37 
38 
39 #ifdef DEBUG
40 static char BadNode[] = " * [BUG] NULL pointer passed for aNode\n";
41 #endif
42 
43 // version format of the cache file
44 #define SG_VERSION_TAG "VERSION:2"
45 
46 
47 static void formatMaterial( SMATERIAL& mat, SGAPPEARANCE const* app )
48 {
49  float v0, v1, v2;
50 
51  app->ambient.GetColor( v0, v1, v2 );
52  mat.m_Ambient.x = v0;
53  mat.m_Ambient.y = v1;
54  mat.m_Ambient.z = v2;
55 
56  app->diffuse.GetColor( v0, v1, v2 );
57  mat.m_Diffuse.x = v0;
58  mat.m_Diffuse.y = v1;
59  mat.m_Diffuse.z = v2;
60  mat.m_Ambient.x *= v0;
61  mat.m_Ambient.y *= v1;
62  mat.m_Ambient.z *= v2;
63 
64  app->emissive.GetColor( v0, v1, v2 );
65  mat.m_Emissive.x = v0;
66  mat.m_Emissive.y = v1;
67  mat.m_Emissive.z = v2;
68 
69  app->specular.GetColor( v0, v1, v2 );
70  mat.m_Specular.x = v0;
71  mat.m_Specular.y = v1;
72  mat.m_Specular.z = v2;
73 
74  mat.m_Shininess = app->shininess;
75  mat.m_Transparency = app->transparency;
76 
77  return;
78 }
79 
80 
81 bool S3D::WriteVRML( const char* filename, bool overwrite, SGNODE* aTopNode,
82  bool reuse, bool renameNodes )
83 {
84  if( NULL == filename || filename[0] == 0 )
85  return false;
86 
87  wxString ofile = wxString::FromUTF8Unchecked( filename );
88 
89  if( wxFileName::Exists( ofile ) )
90  {
91  if( !overwrite )
92  return false;
93 
94  // make sure we make no attempt to write a directory
95  if( !wxFileName::FileExists( ofile ) )
96  return false;
97  }
98 
99  if( NULL == aTopNode )
100  {
101  #ifdef DEBUG
102  do {
103  std::ostringstream ostr;
104  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
105  ostr << " * [BUG] NULL pointer passed for aTopNode";
106  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
107  } while( 0 );
108  #endif
109 
110  return false;
111  }
112 
113  if( S3D::SGTYPE_TRANSFORM != aTopNode->GetNodeType() )
114  {
115  #ifdef DEBUG
116  do {
117  std::ostringstream ostr;
118  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
119  ostr << " * [BUG] aTopNode is not a SCENEGRAPH object";
120  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
121  } while( 0 );
122  #endif
123 
124  return false;
125  }
126 
127  OPEN_OSTREAM( op, filename );
128 
129  if( op.fail() )
130  {
131  std::ostringstream ostr;
132  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
133  wxString errmsg = _( "failed to open file" );
134  ostr << " * [INFO] " << errmsg.ToUTF8() << " '" << filename << "'";
135  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
136  return false;
137  }
138 
139  op.imbue( std::locale( "C" ) );
140  op << "#VRML V2.0 utf8\n";
141 
142  if( renameNodes )
143  {
144  aTopNode->ResetNodeIndex();
145  aTopNode->ReNameNodes();
146  }
147 
148  aTopNode->WriteVRML( op, reuse );
149 
150  if( !op.fail() )
151  {
152  CLOSE_STREAM( op );
153  return true;
154  }
155 
156  CLOSE_STREAM( op );
157 
158  do {
159  std::ostringstream ostr;
160  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
161  wxString errmsg = _( "problems encountered writing file" );
162  ostr << " * [INFO] " << errmsg.ToUTF8() << " '" << filename << "'";
163  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
164  } while( 0 );
165 
166  return false;
167 }
168 
169 
171 {
172  if( NULL == aNode )
173  {
174  #ifdef DEBUG
175  do {
176  std::ostringstream ostr;
177  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
178  ostr << BadNode;
179  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
180  } while( 0 );
181  #endif
182 
183  return;
184  }
185 
186  aNode->ResetNodeIndex();
187 
188  return;
189 }
190 
191 
192 void S3D::RenameNodes( SGNODE* aNode )
193 {
194  if( NULL == aNode )
195  {
196  #ifdef DEBUG
197  do {
198  std::ostringstream ostr;
199  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
200  ostr << BadNode;
201  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
202  } while( 0 );
203  #endif
204 
205  return;
206  }
207 
208  aNode->ReNameNodes();
209 
210  return;
211 }
212 
213 
214 void S3D::DestroyNode( SGNODE* aNode )
215 {
216  if( NULL == aNode )
217  {
218  #ifdef DEBUG
219  do {
220  std::ostringstream ostr;
221  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
222  ostr << BadNode;
223  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
224  } while( 0 );
225  #endif
226 
227  return;
228  }
229 
230  delete aNode;
231 
232  return;
233 }
234 
235 
236 bool S3D::WriteCache( const char* aFileName, bool overwrite, SGNODE* aNode,
237  const char* aPluginInfo )
238 {
239  if( NULL == aFileName || aFileName[0] == 0 )
240  return false;
241 
242  wxString ofile = wxString::FromUTF8Unchecked( aFileName );
243 
244  if( NULL == aNode )
245  {
246  #ifdef DEBUG
247  do {
248  std::ostringstream ostr;
249  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
250  ostr << BadNode;
251  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
252  } while( 0 );
253  #endif
254 
255  return false;
256  }
257 
258 
259  if( wxFileName::Exists( ofile ) )
260  {
261  if( !overwrite )
262  {
263  std::ostringstream ostr;
264  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
265  wxString errmsg = _( "file exists; not overwriting" );
266  ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
267  ostr << aFileName << "'";
268  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
269 
270  return false;
271  }
272 
273  // make sure we make no attempt to write a directory
274  if( !wxFileName::FileExists( aFileName ) )
275  {
276  std::ostringstream ostr;
277  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
278  wxString errmsg = _( "specified path is a directory" );
279  ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
280  ostr << aFileName << "'";
281  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
282  return false;
283  }
284  }
285 
286  OPEN_OSTREAM( output, aFileName );
287 
288  if( output.fail() )
289  {
290  std::ostringstream ostr;
291  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
292  wxString errmsg = _( "failed to open file" );
293  ostr << " * [INFO] " << errmsg.ToUTF8() << " '" << aFileName << "'";
294  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
295  return false;
296  }
297 
298  output << "(" << SG_VERSION_TAG << ")";
299 
300  if( NULL != aPluginInfo && aPluginInfo[0] != 0 )
301  output << "(" << aPluginInfo << ")";
302  else
303  output << "(INTERNAL:0.0.0.0)";
304 
305  bool rval = aNode->WriteCache( output, NULL );
306  CLOSE_STREAM( output );
307 
308  if( !rval )
309  {
310  #ifdef DEBUG
311  do {
312  std::ostringstream ostr;
313  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
314  ostr << " * [INFO] problems encountered writing cache file '";
315  ostr << aFileName << "'";
316  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
317  } while( 0 );
318  #endif
319 
320  // delete the defective file
321  wxRemoveFile( ofile );
322  }
323 
324  return rval;
325 }
326 
327 
328 SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
329  bool (*aTagCheck)( const char*, void* ) )
330 {
331  if( NULL == aFileName || aFileName[0] == 0 )
332  return NULL;
333 
334  wxString ofile = wxString::FromUTF8Unchecked( aFileName );
335 
336  if( !wxFileName::FileExists( aFileName ) )
337  {
338  std::ostringstream ostr;
339  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
340  wxString errmsg = _( "no such file" );
341  ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
342  ostr << aFileName << "'";
343  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
344 
345  return NULL;
346  }
347 
348  SGNODE* np = new SCENEGRAPH( NULL );
349 
350  if( NULL == np )
351  {
352  #ifdef DEBUG
353  do {
354  std::ostringstream ostr;
355  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
356  ostr << " * [INFO] failed to instantiate SCENEGRAPH";
357  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
358  } while( 0 );
359  #endif
360 
361  return NULL;
362  }
363 
364  OPEN_ISTREAM( file, aFileName );
365 
366  if( file.fail() )
367  {
368  delete np;
369  std::ostringstream ostr;
370  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
371  wxString errmsg = _( "failed to open file" );
372  ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
373  ostr << aFileName << "'";
374  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
375  return NULL;
376  }
377 
378  // from SG_VERSION_TAG 1, read the version tag; if it's not the expected tag
379  // then we fail to read the cache file
380  do
381  {
382  std::string name;
383  char schar;
384  file.get( schar );
385 
386  if( '(' != schar )
387  {
388  #ifdef DEBUG
389  do {
390  std::ostringstream ostr;
391  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
392  ostr << " * [INFO] corrupt data; missing left parenthesis at position ";
393  ostr << file.tellg();
394  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
395  } while( 0 );
396  #endif
397 
398  CLOSE_STREAM( file );
399  return NULL;
400  }
401 
402  file.get( schar );
403 
404  while( ')' != schar && file.good() )
405  {
406  name.push_back( schar );
407  file.get( schar );
408  }
409 
410  if( name.compare( SG_VERSION_TAG ) )
411  {
412  CLOSE_STREAM( file );
413  return NULL;
414  }
415 
416  } while( 0 );
417 
418  // from SG_VERSION_TAG 2, read the PluginInfo string and check that it matches
419  // version tag; if it's not the expected tag then we fail to read the file
420  do
421  {
422  std::string name;
423  char schar;
424  file.get( schar );
425 
426  if( '(' != schar )
427  {
428  #ifdef DEBUG
429  do {
430  std::ostringstream ostr;
431  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
432  ostr << " * [INFO] corrupt data; missing left parenthesis at position ";
433  ostr << file.tellg();
434  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
435  } while( 0 );
436  #endif
437 
438  CLOSE_STREAM( file );
439  return NULL;
440  }
441 
442  file.get( schar );
443 
444  while( ')' != schar && file.good() )
445  {
446  name.push_back( schar );
447  file.get( schar );
448  }
449 
450  // check the plugin tag
451  if( NULL != aTagCheck && NULL != aPluginMgr && !aTagCheck( name.c_str(), aPluginMgr ) )
452  {
453  CLOSE_STREAM( file );
454  return NULL;
455  }
456 
457  } while( 0 );
458 
459  bool rval = np->ReadCache( file, NULL );
460  CLOSE_STREAM( file );
461 
462  if( !rval )
463  {
464  delete np;
465  std::ostringstream ostr;
466  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
467  wxString errmsg = "problems encountered reading cache file";
468  ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
469  ostr << aFileName << "'";
470  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
471  return NULL;
472  }
473 
474  return np;
475 }
476 
477 
479 {
480  if( NULL == aNode )
481  return NULL;
482 
483  if( aNode->GetNodeType() != S3D::SGTYPE_TRANSFORM )
484  return NULL;
485 
486  S3D::MATLIST materials;
487  std::vector< SMESH > meshes;
488 
489  // the materials list shall have a default color; although the VRML
490  // default is an opaque black, the default used here shall be a median
491  // gray in hopes that it may help highlight faulty models; this color is
492  // also typical of MCAD applications. When a model has no associated
493  // material color it shall be assigned the index 0.
494  SGAPPEARANCE app( NULL );
495  app.ambient = SGCOLOR( 0.6, 0.6, 0.6 );
496  app.diffuse = SGCOLOR( 0.6, 0.6, 0.6 );
497  app.specular = app.diffuse;
498  app.shininess = 0.05;
499  app.transparency = 0.0;
500 
501  materials.matorder.push_back( &app );
502  materials.matmap.insert( std::pair< SGAPPEARANCE const*, int >( &app, 0 ) );
503 
504  if( aNode->Prepare( NULL, materials, meshes ) )
505  {
506  if( meshes.empty() )
507  return NULL;
508 
509  S3DMODEL* model = S3D::New3DModel();
510 
511  // add all the materials
512  size_t j = materials.matorder.size();
513  SMATERIAL* lmat = new SMATERIAL[j];
514 
515  for( size_t i = 0; i < j; ++i )
516  formatMaterial( lmat[i], materials.matorder[i] );
517 
518  model->m_Materials = lmat;
519  model->m_MaterialsSize = j;
520 
521  // add all the meshes
522  j = meshes.size();
523  SMESH* lmesh = new SMESH[j];
524 
525  for( size_t i = 0; i < j; ++i )
526  lmesh[i] = meshes[i];
527 
528  model->m_Meshes = lmesh;
529  model->m_MeshesSize = j;
530 
531  return model;
532  }
533 
534  size_t j = meshes.size();
535 
536  for( size_t i = 0; i < j; ++i )
537  S3D::Free3DMesh( meshes[i] );
538 
539  return NULL;
540 }
541 
542 
544 {
545  if( NULL == aModel || NULL == *aModel )
546  return;
547 
548  S3DMODEL* m = *aModel;
549  S3D::FREE_S3DMODEL( *m );
550  delete m;
551  *aModel = NULL;
552 
553  return;
554 }
555 
556 
557 void Free3DModel( S3DMODEL& aModel )
558 {
559  S3D::FREE_S3DMODEL( aModel );
560  return;
561 }
562 
563 
564 void S3D::Free3DMesh( SMESH& aMesh )
565 {
566  S3D::FREE_SMESH( aMesh );
567  return;
568 }
569 
570 
572 {
573  S3DMODEL* mp = new S3DMODEL;
574  S3D::INIT_S3DMODEL( *mp );
575  return mp;
576 }
577 
578 
580 {
581  S3D::INIT_SMATERIAL( aMat );
582  return;
583 }
584 
585 
586 void S3D::Init3DMesh( SMESH& aMesh )
587 {
588  S3D::INIT_SMESH( aMesh );
589 
590  return;
591 }
592 
593 
594 void S3D::GetLibVersion( unsigned char* Major, unsigned char* Minor,
595  unsigned char* Patch, unsigned char* Revision )
596 {
597  if( Major )
598  *Major = KICADSG_VERSION_MAJOR;
599 
600  if( Minor )
601  *Minor = KICADSG_VERSION_MINOR;
602 
603  if( Revision )
604  *Revision = KICADSG_VERSION_REVISION;
605 
606  if( Patch )
607  *Patch = KICADSG_VERSION_PATCH;
608 
609  return;
610 }
611 
612 
613 SGVECTOR S3D::CalcTriNorm( const SGPOINT& p1, const SGPOINT& p2, const SGPOINT& p3 )
614 {
615  glm::dvec3 tri = glm::dvec3( 0.0, 0.0, 0.0 );
616  glm::dvec3 pts[3];
617 
618  pts[0] = glm::dvec3( p1.x, p1.y, p1.z );
619  pts[1] = glm::dvec3( p2.x, p2.y, p2.z );
620  pts[2] = glm::dvec3( p3.x, p3.y, p3.z );
621 
622  // degenerate points are given a default 0, 0, 1 normal
623  if( S3D::degenerate( pts ) )
624  return SGVECTOR( 0.0, 0.0, 1.0 );
625 
626  // normal
627  tri = glm::cross( pts[1] - pts[0], pts[2] - pts[0] );
628  glm::normalize( tri );
629 
630  return SGVECTOR( tri.x, tri.y, tri.z );
631 }
632 
633 
635 {
636  if( NULL == aNode )
637  return SGTYPE_END;
638 
639  return aNode->GetNodeType();
640 }
641 
642 
644 {
645  if( NULL == aNode )
646  return NULL;
647 
648  return aNode->GetParent();
649 }
650 
651 
652 bool S3D::AddSGNodeRef( SGNODE* aParent, SGNODE* aChild )
653 {
654  if( NULL == aParent || NULL == aChild )
655  return false;
656 
657  return aParent->AddRefNode( aChild );
658 }
659 
660 
661 bool S3D::AddSGNodeChild( SGNODE* aParent, SGNODE* aChild )
662 {
663  if( NULL == aParent || NULL == aChild )
664  return false;
665 
666  return aParent->AddChildNode( aChild );
667 }
668 
669 
670 void S3D::AssociateSGNodeWrapper( SGNODE* aObject, SGNODE** aRefPtr )
671 {
672  if( NULL == aObject || NULL == aRefPtr || aObject != *aRefPtr )
673  return;
674 
675  aObject->AssociateWrapper( aRefPtr );
676 
677  return;
678 }
#define KICADSG_VERSION_MAJOR
Definition: sg_version.h:33
virtual void ReNameNodes(void)=0
Function ReNameNodes renames a node and all its child nodes in preparation for Write() operations...
SGCOLOR diffuse
Definition: sg_appearance.h:40
#define KICADSG_VERSION_REVISION
Definition: sg_version.h:36
SGLIB_API void RenameNodes(SGNODE *aNode)
Function RenameNodes renames a node and all children nodes based on the current values of the global ...
Definition: ifsg_api.cpp:192
SFVEC3F m_Ambient
Definition: c3dmodel.h:39
SGLIB_API S3DMODEL * New3DModel(void)
Function New3DModel creates and initializes an S3DMODEL struct.
Definition: ifsg_api.cpp:571
double x
Definition: sg_base.h:70
#define KICADSG_VERSION_PATCH
Definition: sg_version.h:35
SGLIB_API void Init3DMaterial(SMATERIAL &aMat)
Function Init3DMaterial initializes an SMATERIAL struct.
Definition: ifsg_api.cpp:579
virtual bool AddRefNode(SGNODE *aNode)=0
SGLIB_API SGNODE * ReadCache(const char *aFileName, void *aPluginMgr, bool(*aTagCheck)(const char *, void *))
Function ReadCache reads a binary cache file and creates an SGNODE tree.
Definition: ifsg_api.cpp:328
SGLIB_API void ResetNodeIndex(SGNODE *aNode)
Function ResetNodeIndex resets the global SG* class indices.
Definition: ifsg_api.cpp:170
SGLIB_API void AssociateSGNodeWrapper(SGNODE *aObject, SGNODE **aRefPtr)
Definition: ifsg_api.cpp:670
void FREE_S3DMODEL(S3DMODEL &aModel)
Definition: sg_node.cpp:420
SGLIB_API void Destroy3DModel(S3DMODEL **aModel)
Function Destroy3DModel frees memory used by an S3DMODEL structure and sets the pointer to the struct...
Definition: ifsg_api.cpp:543
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:643
float m_Transparency
1.0 is completely transparent, 0.0 completely opaque
Definition: c3dmodel.h:44
#define KICADSG_VERSION_MINOR
Definition: sg_version.h:34
double y
Definition: sg_base.h:71
std::map< SGAPPEARANCE const *, int > matmap
Definition: sg_node.h:58
defines the base class of the intermediate scene graph NODE
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
SGCOLOR emissive
Definition: sg_appearance.h:41
defines the basic data set required to represent a 3D model; this model must remain compatible with V...
Per-vertex normal/color/texcoors structure.
Definition: c3dmodel.h:76
SGLIB_API bool AddSGNodeRef(SGNODE *aParent, SGNODE *aChild)
Definition: ifsg_api.cpp:652
SMESH * m_Meshes
The meshes list of this model.
Definition: c3dmodel.h:93
SGLIB_API bool WriteVRML(const char *filename, bool overwrite, SGNODE *aTopNode, bool reuse, bool renameNodes)
Function WriteVRML writes out the given node and its subnodes to a VRML2 file.
Definition: ifsg_api.cpp:81
virtual bool ReadCache(std::istream &aFile, SGNODE *parentNode)=0
Function ReadCache Reads binary format data from a cache file.
void FREE_SMESH(SMESH &aMesh)
Definition: sg_node.cpp:380
defines the generic material appearance of a scenegraph object
SGCOLOR ambient
Definition: sg_appearance.h:39
defines a complex 3D shape for a scenegraph object
SGNODE * GetParent(void) const
Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no...
Definition: sg_node.cpp:114
static void formatMaterial(SMATERIAL &mat, SGAPPEARANCE const *app)
Definition: ifsg_api.cpp:47
float transparency
Definition: sg_appearance.h:38
void AssociateWrapper(SGNODE **aWrapperRef)
Function AssociateWrapper associates this object with a handle to itself; this handle is typically he...
Definition: sg_node.cpp:219
#define OPEN_OSTREAM(var, name)
SGLIB_API bool AddSGNodeChild(SGNODE *aParent, SGNODE *aChild)
Definition: ifsg_api.cpp:661
defines the library version of the intermediate scenegraph (SG) implementation
float m_Shininess
Definition: c3dmodel.h:43
SGLIB_API void Init3DMesh(SMESH &aMesh)
Function Init3DMesh creates and initializes an SMESH struct.
Definition: ifsg_api.cpp:586
unsigned int m_MaterialsSize
Number of materials in the material array.
Definition: c3dmodel.h:95
defines the API calls for the manipulation of SG* classes
#define SG_VERSION_TAG
Definition: ifsg_api.cpp:44
SGTYPES
Definition: sg_types.h:34
virtual bool WriteCache(std::ostream &aFile, SGNODE *parentNode)=0
Function WriteCache write's this node's data to a binary cache file; the data includes all data of ch...
SGLIB_API SGVECTOR CalcTriNorm(const SGPOINT &p1, const SGPOINT &p2, const SGPOINT &p3)
Function CalcTriNorm returns the normal vector of a triangle described by vertices p1...
Definition: ifsg_api.cpp:613
SGLIB_API S3D::SGTYPES GetSGNodeType(SGNODE *aNode)
Definition: ifsg_api.cpp:634
void Free3DModel(S3DMODEL &aModel)
Function Free3DModel frees memory used internally by an S3DMODEL structure.
Definition: ifsg_api.cpp:557
#define OPEN_ISTREAM(var, name)
void INIT_SMESH(SMESH &aMesh)
Definition: sg_node.cpp:366
void INIT_S3DMODEL(S3DMODEL &aModel)
Definition: sg_node.cpp:373
SFVEC3F m_Emissive
Definition: c3dmodel.h:41
std::vector< SGAPPEARANCE const * > matorder
Definition: sg_node.h:57
SMATERIAL * m_Materials
The materials list of this model.
Definition: c3dmodel.h:96
SGLIB_API void DestroyNode(SGNODE *aNode)
Function DestroyNode deletes the given SG* class node.
Definition: ifsg_api.cpp:214
double z
Definition: sg_base.h:72
SGCOLOR specular
Definition: sg_appearance.h:42
void INIT_SMATERIAL(SMATERIAL &aMaterial)
Definition: sg_node.cpp:359
virtual bool AddChildNode(SGNODE *aNode)=0
const char * name
SGLIB_API bool WriteCache(const char *aFileName, bool overwrite, SGNODE *aNode, const char *aPluginInfo)
Function WriteCache writes the SGNODE tree to a binary cache file.
Definition: ifsg_api.cpp:236
SFVEC3F m_Diffuse
Default diffuse color if m_Color is NULL.
Definition: c3dmodel.h:40
Store the a model based on meshes and materials.
Definition: c3dmodel.h:90
defines a number of macro functions to aid in repetitious code which is probably best expressed as a ...
#define CLOSE_STREAM(var)
SGLIB_API S3DMODEL * GetModel(SCENEGRAPH *aNode)
Function GetModel creates an S3DMODEL representation of aNode (raw data, no transforms) ...
Definition: ifsg_api.cpp:478
bool degenerate(glm::dvec3 *pts)
Definition: sg_helpers.cpp:339
unsigned int m_MeshesSize
Number of meshes in the array.
Definition: c3dmodel.h:92
void GetColor(float &aRedVal, float &aGreenVal, float &aBlueVal) const
Definition: sg_base.cpp:65
void ResetNodeIndex(void)
Function ResetNodeIndex resets the global SG* node indices in preparation for Write() operations...
Definition: sg_node.cpp:304
SGLIB_API void GetLibVersion(unsigned char *Major, unsigned char *Minor, unsigned char *Patch, unsigned char *Revision)
Function GetLibVersion retrieves version information of the kicad_3dsg library.
Definition: ifsg_api.cpp:594
SFVEC3F m_Specular
Definition: c3dmodel.h:42
virtual bool WriteVRML(std::ostream &aFile, bool aReuseFlag)=0
Function WriteVRML writes this node's data to a VRML file; this includes all data of child and refere...
bool Prepare(const glm::dmat4 *aTransform, S3D::MATLIST &materials, std::vector< SMESH > &meshes)
Definition: scenegraph.cpp:737
SGLIB_API void Free3DMesh(SMESH &aMesh)
Function Free3DMesh frees memory used internally by an SMESH structure.
Definition: ifsg_api.cpp:564