foamGltfBase.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Namespace
27  Foam::glTF
28 
29 Description
30  Namespace for handling glTF creation.
31  https://www.khronos.org/registry/glTF/
32 
33 Class
34  Foam::glTF::base
35 
36 Description
37  Base class for glTF entities
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef foam_gltf_base_H
42 #define foam_gltf_base_H
43 
44 #include "word.H"
45 #include "label.H"
46 #include "Ostream.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 namespace glTF
53 {
54 
55  enum class componentTypes : int
56  {
57  BYTE = 5120,
58  UNSIGNED_BYTE = 5121,
59  SHORT = 5122,
60  UNSIGNED_SHORT = 5123,
61  UNSIGNED_INT = 5125,
62  FLOAT = 5126
63  };
64 
65  // accessor
66  enum class dataTypes
67  {
68  SCALAR,
69  VEC2,
70  VEC3,
71  VEC4,
72  MAT2,
73  MAT3,
74  MAT4
75  };
76 
77  enum class attributeTypes
78  {
79  POSITION,
80  NORMAL,
81  TANGENT,
82  TEXCOORD_0,
83  TEXCOORD_1,
84  COLOR_0,
85  JOINTS_0,
86  WEIGHTS_0
87  };
88 
89  // bufferView
90  enum class targetTypes : int
91  {
92  ARRAY_BUFFER = 34962,
93  ELEMENT_ARRAY_BUFFER = 34963
94  };
95 
96  enum class primitiveModes : int
97  {
98  POINTS = 0,
99  LINES = 1,
100  LINE_LOOP = 2,
101  LINE_STRIP = 3,
102  TRIANGLES = 4,
103  TRIANGLE_STRIP = 5,
104  TRIANGLE_FAN = 6
105  };
106 
107  // Helper function to return the enum value
108  template<class Type>
109  auto key(const Type& t) -> typename std::enable_if
110  <
111  std::is_enum<Type>::value,
113  >::type
114  {
115  return static_cast<typename std::underlying_type<Type>::type>(t);
116  }
117 
118 /*---------------------------------------------------------------------------*\
119  Class base Declaration
120 \*---------------------------------------------------------------------------*/
121 
122 class base
123 {
124 protected:
125 
126  // Protected Data
127 
128  //- Name
129  word name_;
130 
131  //- ID
132  label id_;
133 
134 
135 public:
136 
137  // Constructors
138 
139  //- Default construct
140  base()
141  :
142  id_(-1)
143  {}
144 
145  //- Construct with name
146  explicit base(const word& name)
147  :
148  name_(name),
149  id_(-1)
150  {}
151 
152 
153  //- Destructor
154  ~base() = default;
155 
156 
157  // Member Functions
158 
159  //- Return access to the ID
160  label& id() noexcept
161  {
162  return id_;
163  }
164 
165  //- Return const access to the name
166  const word& name() const noexcept
167  {
168  return name_;
169  }
170 
171  //- Write
172  void write(Ostream& os) const
173  {
174  os << "," << nl
175  << indent << "\"name\" : \"" << name_ << "\"";
176  }
177 
178 
179  // Member Operators
180 
181  void operator=(const base& gltf)
182  {
183  name_ = gltf.name_;
184  id_ = gltf.id_;
185  }
186 };
187 
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 } // End namespace glTF
192 } // End namespace Foam
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #endif
197 
198 // ************************************************************************* //
Foam::glTF::primitiveModes::LINES
Foam::glTF::componentTypes::UNSIGNED_INT
4 bytes
Foam::glTF::attributeTypes
attributeTypes
Definition: foamGltfBase.H:76
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::glTF::dataTypes::SCALAR
1 component
Foam::glTF::base::base
base(const word &name)
Construct with name.
Definition: foamGltfBase.H:145
Foam::glTF::attributeTypes::NORMAL
VEC3 Normalised XYZ vertex normals.
Foam::glTF::attributeTypes::TANGENT
VEC4 XYZW vertex tangents.
Foam::glTF::dataTypes::VEC4
4 components
Foam::glTF::attributeTypes::TEXCOORD_0
VEC2 UV texture coordinates.
Foam::glTF::targetTypes::ELEMENT_ARRAY_BUFFER
vertex indices
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
Foam::glTF::componentTypes::BYTE
1 byte
Foam::glTF::base::name
const word & name() const noexcept
Return const access to the name.
Definition: foamGltfBase.H:165
Foam::glTF::primitiveModes::POINTS
Foam::glTF::componentTypes
componentTypes
Definition: foamGltfBase.H:54
Foam::glTF::targetTypes
targetTypes
Definition: foamGltfBase.H:89
Foam::glTF::base::id
label & id() noexcept
Return access to the ID.
Definition: foamGltfBase.H:159
Foam::glTF::targetTypes::ARRAY_BUFFER
vertex attributes
Foam::glTF::componentTypes::UNSIGNED_BYTE
1 byte
Foam::glTF::base::operator=
void operator=(const base &gltf)
Definition: foamGltfBase.H:180
Foam::glTF::attributeTypes::POSITION
VEC3 XYZ vertex positions; requires 'min' and 'max'.
Foam::glTF::base
Base class for glTF entities.
Definition: foamGltfBase.H:121
Foam::glTF::primitiveModes::LINE_LOOP
Foam::glTF::primitiveModes
primitiveModes
Definition: foamGltfBase.H:95
Foam::glTF::base::write
void write(Ostream &os) const
Write.
Definition: foamGltfBase.H:171
Foam::glTF::primitiveModes::TRIANGLE_STRIP
Foam::glTF::attributeTypes::JOINTS_0
VEC4.
Foam::glTF::base::name_
word name_
Name.
Definition: foamGltfBase.H:128
Foam::glTF::dataTypes::VEC3
3 components
os
OBJstream os(runTime.globalPath()/outputName)
Foam::glTF::attributeTypes::WEIGHTS_0
VEC4.
Foam::glTF::attributeTypes::TEXCOORD_1
VEC2 UV texture coordinates.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:339
Foam::glTF::dataTypes
dataTypes
Definition: foamGltfBase.H:65
Foam::glTF::dataTypes::VEC2
2 components
Foam::glTF::primitiveModes::TRIANGLES
Ostream.H
Foam::glTF::dataTypes::MAT2
4 components
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::glTF::dataTypes::MAT3
9 components
label.H
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::glTF::base::~base
~base()=default
Destructor.
Foam::glTF::componentTypes::SHORT
2 bytes
Foam::glTF::componentTypes::FLOAT
4 bytes
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
word.H
Foam::glTF::base::id_
label id_
ID.
Definition: foamGltfBase.H:131
Foam::glTF::primitiveModes::TRIANGLE_FAN
Foam::glTF::base::base
base()
Default construct.
Definition: foamGltfBase.H:139
Foam::glTF::primitiveModes::LINE_STRIP
Foam::glTF::attributeTypes::COLOR_0
VEC3 (rgb), VEC4 (rgba)
Foam::glTF::dataTypes::MAT4
16 components
Foam::glTF::componentTypes::UNSIGNED_SHORT
2 bytes