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  wxString errmsg;
132  errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
133  errmsg << " * [INFO] " << "failed to open file" << " '" << filename << "'";
134  wxLogTrace( MASK_3D_SG, errmsg );
135  return false;
136  }
137 
138  op.imbue( std::locale( "C" ) );
139  op << "#VRML V2.0 utf8\n";
140 
141  if( renameNodes )
142  {
143  aTopNode->ResetNodeIndex();
144  aTopNode->ReNameNodes();
145  }
146 
147  aTopNode->WriteVRML( op, reuse );
148 
149  if( !op.fail() )
150  {
151  CLOSE_STREAM( op );
152  return true;
153  }
154 
155  CLOSE_STREAM( op );
156 
157  wxString errmsg;
158  errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
159  errmsg << " * [INFO] " << "problems encountered writing file" << " '" << filename << "'";
160  wxLogTrace( MASK_3D_SG, errmsg );
161 
162  return false;
163 }
164 
165 
167 {
168  if( NULL == aNode )
169  {
170  #ifdef DEBUG
171  do {
172  std::ostringstream ostr;
173  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
174  ostr << BadNode;
175  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
176  } while( 0 );
177  #endif
178 
179  return;
180  }
181 
182  aNode->ResetNodeIndex();
183 
184  return;
185 }
186 
187 
188 void S3D::RenameNodes( SGNODE* aNode )
189 {
190  if( NULL == aNode )
191  {
192  #ifdef DEBUG
193  do {
194  std::ostringstream ostr;
195  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
196  ostr << BadNode;
197  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
198  } while( 0 );
199  #endif
200 
201  return;
202  }
203 
204  aNode->ReNameNodes();
205 
206  return;
207 }
208 
209 
210 void S3D::DestroyNode( SGNODE* aNode )
211 {
212  if( NULL == aNode )
213  {
214  #ifdef DEBUG
215  do {
216  std::ostringstream ostr;
217  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
218  ostr << BadNode;
219  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
220  } while( 0 );
221  #endif
222 
223  return;
224  }
225 
226  delete aNode;
227 
228  return;
229 }
230 
231 
232 bool S3D::WriteCache( const char* aFileName, bool overwrite, SGNODE* aNode,
233  const char* aPluginInfo )
234 {
235  if( NULL == aFileName || aFileName[0] == 0 )
236  return false;
237 
238  wxString ofile = wxString::FromUTF8Unchecked( aFileName );
239 
240  if( NULL == aNode )
241  {
242  #ifdef DEBUG
243  do {
244  std::ostringstream ostr;
245  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
246  ostr << BadNode;
247  wxLogTrace( MASK_3D_SG, "%s", ostr.str().c_str() );
248  } while( 0 );
249  #endif
250 
251  return false;
252  }
253 
254 
255  if( wxFileName::Exists( ofile ) )
256  {
257  if( !overwrite )
258  {
259  wxString errmsg;
260  errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
261  errmsg << " * [INFO] " << "file exists; not overwriting" << " '";
262  errmsg << aFileName << "'";
263  wxLogTrace( MASK_3D_SG, errmsg );
264 
265  return false;
266  }
267 
268  // make sure we make no attempt to write a directory
269  if( !wxFileName::FileExists( aFileName ) )
270  {
271  wxString errmsg;
272  errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
273  errmsg << " * [INFO] " << "specified path is a directory" << " '";
274  errmsg << aFileName << "'";
275  wxLogTrace( MASK_3D_SG, errmsg );
276  return false;
277  }
278  }
279 
280  OPEN_OSTREAM( output, aFileName );
281 
282  if( output.fail() )
283  {
284  wxString errmsg;
285  errmsg << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
286  errmsg << " * [INFO] " << "failed to open file" << " '" << aFileName << "'";
287  wxLogTrace( MASK_3D_SG, errmsg );
288  return false;
289  }
290 
291  output << "(" << SG_VERSION_TAG << ")";
292 
293  if( NULL != aPluginInfo && aPluginInfo[0] != 0 )
294  output << "(" << aPluginInfo << ")";
295  else
296  output << "(INTERNAL:0.0.0.0)";
297 
298  bool rval = aNode->WriteCache( output, NULL );
299  CLOSE_STREAM( output );
300 
301  if( !rval )
302  {
303  #ifdef DEBUG
304  do {
305  std::ostringstream ostr;
306  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
307  ostr << " * [INFO] problems encountered writing cache file '";
308  ostr << aFileName << "'";
309  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
310  } while( 0 );
311  #endif
312 
313  // delete the defective file
314  wxRemoveFile( ofile );
315  }
316 
317  return rval;
318 }
319 
320 
321 SGNODE* S3D::ReadCache( const char* aFileName, void* aPluginMgr,
322  bool (*aTagCheck)( const char*, void* ) )
323 {
324  if( NULL == aFileName || aFileName[0] == 0 )
325  return NULL;
326 
327  wxString ofile = wxString::FromUTF8Unchecked( aFileName );
328 
329  if( !wxFileName::FileExists( aFileName ) )
330  {
331  std::ostringstream ostr;
332  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
333  wxString errmsg = _( "no such file" );
334  ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
335  ostr << aFileName << "'";
336  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
337 
338  return NULL;
339  }
340 
341  SGNODE* np = new SCENEGRAPH( NULL );
342 
343  if( NULL == np )
344  {
345  #ifdef DEBUG
346  do {
347  std::ostringstream ostr;
348  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
349  ostr << " * [INFO] failed to instantiate SCENEGRAPH";
350  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
351  } while( 0 );
352  #endif
353 
354  return NULL;
355  }
356 
357  OPEN_ISTREAM( file, aFileName );
358 
359  if( file.fail() )
360  {
361  delete np;
362  std::ostringstream ostr;
363  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
364  wxString errmsg = _( "failed to open file" );
365  ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
366  ostr << aFileName << "'";
367  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
368  return NULL;
369  }
370 
371  // from SG_VERSION_TAG 1, read the version tag; if it's not the expected tag
372  // then we fail to read the cache file
373  do
374  {
375  std::string name;
376  char schar;
377  file.get( schar );
378 
379  if( '(' != schar )
380  {
381  #ifdef DEBUG
382  do {
383  std::ostringstream ostr;
384  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
385  ostr << " * [INFO] corrupt data; missing left parenthesis at position ";
386  ostr << file.tellg();
387  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
388  } while( 0 );
389  #endif
390 
391  CLOSE_STREAM( file );
392  return NULL;
393  }
394 
395  file.get( schar );
396 
397  while( ')' != schar && file.good() )
398  {
399  name.push_back( schar );
400  file.get( schar );
401  }
402 
403  if( name.compare( SG_VERSION_TAG ) )
404  {
405  CLOSE_STREAM( file );
406  return NULL;
407  }
408 
409  } while( 0 );
410 
411  // from SG_VERSION_TAG 2, read the PluginInfo string and check that it matches
412  // version tag; if it's not the expected tag then we fail to read the file
413  do
414  {
415  std::string name;
416  char schar;
417  file.get( schar );
418 
419  if( '(' != schar )
420  {
421  #ifdef DEBUG
422  do {
423  std::ostringstream ostr;
424  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
425  ostr << " * [INFO] corrupt data; missing left parenthesis at position ";
426  ostr << file.tellg();
427  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
428  } while( 0 );
429  #endif
430 
431  CLOSE_STREAM( file );
432  return NULL;
433  }
434 
435  file.get( schar );
436 
437  while( ')' != schar && file.good() )
438  {
439  name.push_back( schar );
440  file.get( schar );
441  }
442 
443  // check the plugin tag
444  if( NULL != aTagCheck && NULL != aPluginMgr && !aTagCheck( name.c_str(), aPluginMgr ) )
445  {
446  CLOSE_STREAM( file );
447  return NULL;
448  }
449 
450  } while( 0 );
451 
452  bool rval = np->ReadCache( file, NULL );
453  CLOSE_STREAM( file );
454 
455  if( !rval )
456  {
457  delete np;
458  std::ostringstream ostr;
459  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
460  wxString errmsg = "problems encountered reading cache file";
461  ostr << " * [INFO] " << errmsg.ToUTF8() << " '";
462  ostr << aFileName << "'";
463  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
464  return NULL;
465  }
466 
467  return np;
468 }
469 
470 
472 {
473  if( NULL == aNode )
474  return NULL;
475 
476  if( aNode->GetNodeType() != S3D::SGTYPE_TRANSFORM )
477  return NULL;
478 
479  S3D::MATLIST materials;
480  std::vector< SMESH > meshes;
481 
482  // the materials list shall have a default color; although the VRML
483  // default is an opaque black, the default used here shall be a median
484  // gray in hopes that it may help highlight faulty models; this color is
485  // also typical of MCAD applications. When a model has no associated
486  // material color it shall be assigned the index 0.
487  SGAPPEARANCE app( NULL );
488  app.ambient = SGCOLOR( 0.6, 0.6, 0.6 );
489  app.diffuse = SGCOLOR( 0.6, 0.6, 0.6 );
490  app.specular = app.diffuse;
491  app.shininess = 0.05;
492  app.transparency = 0.0;
493 
494  materials.matorder.push_back( &app );
495  materials.matmap.insert( std::pair< SGAPPEARANCE const*, int >( &app, 0 ) );
496 
497  if( aNode->Prepare( NULL, materials, meshes ) )
498  {
499  if( meshes.empty() )
500  return NULL;
501 
502  S3DMODEL* model = S3D::New3DModel();
503 
504  // add all the materials
505  size_t j = materials.matorder.size();
506  SMATERIAL* lmat = new SMATERIAL[j];
507 
508  for( size_t i = 0; i < j; ++i )
509  formatMaterial( lmat[i], materials.matorder[i] );
510 
511  model->m_Materials = lmat;
512  model->m_MaterialsSize = j;
513 
514  // add all the meshes
515  j = meshes.size();
516  SMESH* lmesh = new SMESH[j];
517 
518  for( size_t i = 0; i < j; ++i )
519  lmesh[i] = meshes[i];
520 
521  model->m_Meshes = lmesh;
522  model->m_MeshesSize = j;
523 
524  return model;
525  }
526 
527  size_t j = meshes.size();
528 
529  for( size_t i = 0; i < j; ++i )
530  S3D::Free3DMesh( meshes[i] );
531 
532  return NULL;
533 }
534 
535 
537 {
538  if( NULL == aModel || NULL == *aModel )
539  return;
540 
541  S3DMODEL* m = *aModel;
542  S3D::FREE_S3DMODEL( *m );
543  delete m;
544  *aModel = NULL;
545 
546  return;
547 }
548 
549 
550 void Free3DModel( S3DMODEL& aModel )
551 {
552  S3D::FREE_S3DMODEL( aModel );
553  return;
554 }
555 
556 
557 void S3D::Free3DMesh( SMESH& aMesh )
558 {
559  S3D::FREE_SMESH( aMesh );
560  return;
561 }
562 
563 
565 {
566  S3DMODEL* mp = new S3DMODEL;
567  S3D::INIT_S3DMODEL( *mp );
568  return mp;
569 }
570 
571 
573 {
574  S3D::INIT_SMATERIAL( aMat );
575  return;
576 }
577 
578 
579 void S3D::Init3DMesh( SMESH& aMesh )
580 {
581  S3D::INIT_SMESH( aMesh );
582 
583  return;
584 }
585 
586 
587 void S3D::GetLibVersion( unsigned char* Major, unsigned char* Minor,
588  unsigned char* Patch, unsigned char* Revision )
589 {
590  if( Major )
591  *Major = KICADSG_VERSION_MAJOR;
592 
593  if( Minor )
594  *Minor = KICADSG_VERSION_MINOR;
595 
596  if( Revision )
597  *Revision = KICADSG_VERSION_REVISION;
598 
599  if( Patch )
600  *Patch = KICADSG_VERSION_PATCH;
601 
602  return;
603 }
604 
605 
606 SGVECTOR S3D::CalcTriNorm( const SGPOINT& p1, const SGPOINT& p2, const SGPOINT& p3 )
607 {
608  glm::dvec3 tri = glm::dvec3( 0.0, 0.0, 0.0 );
609  glm::dvec3 pts[3];
610 
611  pts[0] = glm::dvec3( p1.x, p1.y, p1.z );
612  pts[1] = glm::dvec3( p2.x, p2.y, p2.z );
613  pts[2] = glm::dvec3( p3.x, p3.y, p3.z );
614 
615  // degenerate points are given a default 0, 0, 1 normal
616  if( S3D::degenerate( pts ) )
617  return SGVECTOR( 0.0, 0.0, 1.0 );
618 
619  // normal
620  tri = glm::cross( pts[1] - pts[0], pts[2] - pts[0] );
621  glm::normalize( tri );
622 
623  return SGVECTOR( tri.x, tri.y, tri.z );
624 }
625 
626 
628 {
629  if( NULL == aNode )
630  return SGTYPE_END;
631 
632  return aNode->GetNodeType();
633 }
634 
635 
637 {
638  if( NULL == aNode )
639  return NULL;
640 
641  return aNode->GetParent();
642 }
643 
644 
645 bool S3D::AddSGNodeRef( SGNODE* aParent, SGNODE* aChild )
646 {
647  if( NULL == aParent || NULL == aChild )
648  return false;
649 
650  return aParent->AddRefNode( aChild );
651 }
652 
653 
654 bool S3D::AddSGNodeChild( SGNODE* aParent, SGNODE* aChild )
655 {
656  if( NULL == aParent || NULL == aChild )
657  return false;
658 
659  return aParent->AddChildNode( aChild );
660 }
661 
662 
663 void S3D::AssociateSGNodeWrapper( SGNODE* aObject, SGNODE** aRefPtr )
664 {
665  if( NULL == aObject || NULL == aRefPtr || aObject != *aRefPtr )
666  return;
667 
668  aObject->AssociateWrapper( aRefPtr );
669 
670  return;
671 }
#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:188
SFVEC3F m_Ambient
Definition: c3dmodel.h:39
SGLIB_API S3DMODEL * New3DModel(void)
Function New3DModel creates and initializes an S3DMODEL struct.
Definition: ifsg_api.cpp:564
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:572
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:321
SGLIB_API void ResetNodeIndex(SGNODE *aNode)
Function ResetNodeIndex resets the global SG* class indices.
Definition: ifsg_api.cpp:166
SGLIB_API void AssociateSGNodeWrapper(SGNODE *aObject, SGNODE **aRefPtr)
Definition: ifsg_api.cpp:663
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:536
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:636
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:645
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:654
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:579
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:606
SGLIB_API S3D::SGTYPES GetSGNodeType(SGNODE *aNode)
Definition: ifsg_api.cpp:627
void Free3DModel(S3DMODEL &aModel)
Function Free3DModel frees memory used internally by an S3DMODEL structure.
Definition: ifsg_api.cpp:550
#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:210
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:232
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:471
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:587
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:557