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-------------------------------------------------------------------------------
10License
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
26Namespace
27 Foam::glTF
28
29Description
30 Namespace for handling glTF creation.
31 https://www.khronos.org/registry/glTF/
32
33Class
34 Foam::glTF::base
35
36Description
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
50namespace Foam
51{
52namespace glTF
53{
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 };
77 enum class attributeTypes
78 {
79 POSITION,
80 NORMAL,
81 TANGENT,
84 COLOR_0,
85 JOINTS_0,
87 };
88
89 // bufferView
90 enum class targetTypes : int
91 {
92 ARRAY_BUFFER = 34962,
94 };
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,
112 typename std::underlying_type<Type>::type
113 >::type
114 {
115 return static_cast<typename std::underlying_type<Type>::type>(t);
116 }
117
118/*---------------------------------------------------------------------------*\
119 Class base Declaration
120\*---------------------------------------------------------------------------*/
122class base
123{
124protected:
125
126 // Protected Data
127
128 //- Name
129 word name_;
130
131 //- ID
132 label id_;
133
134
135public:
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
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// ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Base class for glTF entities.
Definition: foamGltfBase.H:122
~base()=default
Destructor.
base(const word &name)
Construct with name.
Definition: foamGltfBase.H:145
void write(Ostream &os) const
Write.
Definition: foamGltfBase.H:171
const word & name() const noexcept
Return const access to the name.
Definition: foamGltfBase.H:165
label & id() noexcept
Return access to the ID.
Definition: foamGltfBase.H:159
void operator=(const base &gltf)
Definition: foamGltfBase.H:180
base()
Default construct.
Definition: foamGltfBase.H:139
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
@ NORMAL
VEC3 Normalised XYZ vertex normals.
@ TEXCOORD_0
VEC2 UV texture coordinates.
@ TANGENT
VEC4 XYZW vertex tangents.
@ COLOR_0
VEC3 (rgb), VEC4 (rgba)
@ POSITION
VEC3 XYZ vertex positions; requires 'min' and 'max'.
@ TEXCOORD_1
VEC2 UV texture coordinates.
@ ELEMENT_ARRAY_BUFFER
vertex indices
@ ARRAY_BUFFER
vertex attributes
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
@ MAT3
9 components
@ MAT4
16 components
@ VEC2
2 components
@ VEC3
3 components
@ MAT2
4 components
@ VEC4
4 components
Namespace for OpenFOAM.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:342
const direction noexcept
Definition: Scalar.H:223
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
runTime write()