1 /* 2 * This program source code file is part of KiCad, a free EDA CAD application. 3 * 4 * Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com> 5 * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, you may find one here: 19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 20 * or you may search the http://www.gnu.org website for the version 2 license, 21 * or you may write to the Free Software Foundation, Inc., 22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 23 */ 24 25 /** 26 * @file scenegraph.h 27 */ 28 29 30 #ifndef SCENE_GRAPH_H 31 #define SCENE_GRAPH_H 32 33 #include <vector> 34 #include "3d_cache/sg/sg_node.h" 35 36 class SGSHAPE; 37 38 /** 39 * Define the basic data set required to represent a 3D model. 40 * 41 * This model must remain compatible with VRML2.0 in order to facilitate VRML export of 42 * scene graph data created by available 3D plugins. 43 */ 44 class SCENEGRAPH : public SGNODE 45 { 46 public: 47 void unlinkChildNode( const SGNODE* aNode ) override; 48 void unlinkRefNode( const SGNODE* aNode ) override; 49 50 SCENEGRAPH( SGNODE* aParent ); 51 virtual ~SCENEGRAPH(); 52 53 virtual bool SetParent( SGNODE* aParent, bool notify = true ) override; 54 SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller) override; 55 bool AddRefNode( SGNODE* aNode ) override; 56 bool AddChildNode( SGNODE* aNode ) override; 57 58 void ReNameNodes( void ) override; 59 bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) override; 60 61 bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override; 62 bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override; 63 64 bool Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials, 65 std::vector< SMESH >& meshes ); 66 67 private: 68 void unlinkNode( const SGNODE* aNode, bool isChild ); 69 bool addNode( SGNODE* aNode, bool isChild ); 70 71 public: 72 // note: order of transformation is Translate, Rotate, Offset 73 SGPOINT center; 74 SGPOINT translation; 75 SGVECTOR rotation_axis; 76 double rotation_angle; // radians 77 SGPOINT scale; 78 SGVECTOR scale_axis; 79 double scale_angle; // radians 80 81 private: 82 // The following are items which may be defined for reuse 83 // in a VRML output file. They do not necessarily correspond 84 // to the use of DEF within a VRML input file; it is the 85 // responsibility of the plugin to perform any necessary 86 // conversions to comply with the restrictions imposed by 87 // this scene graph structure 88 std::vector< SCENEGRAPH* > m_Transforms; // local Transform nodes 89 std::vector< SGSHAPE* > m_Shape; // local Shape nodes 90 91 std::vector< SCENEGRAPH* > m_RTransforms; // referenced Transform nodes 92 std::vector< SGSHAPE* > m_RShape; // referenced Shape nodes 93 }; 94 95 /* 96 p.120 97 Transform { 98 center 0 0 0 99 children [] 100 rotation 0 0 1 0 101 scale 1 1 1 102 scaleOrientation 0 0 1 0 103 translation 0 0 0 104 bboxCenter 0 0 0 105 bboxSize -1 -1 -1 106 } 107 */ 108 109 #endif // SCENE_GRAPH_H 110