foamGltfMesh.C
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
26\*---------------------------------------------------------------------------*/
27
28#include "foamGltfMesh.H"
29
30// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31
33:
34 base(),
35 fields_(),
36 colours_(),
37 accessorId_(-1)
38{}
39
40
42:
43 base(name),
44 fields_(),
45 colours_(),
46 accessorId_(-1)
47{}
48
49
50// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
51
53{
54 return accessorId_;
55}
56
57
58void Foam::glTF::mesh::addField(const word& name, const label accessorId)
59{
60 fields_.append(Tuple2<string, label>("_field:" + name, accessorId));
61}
62
63
64void Foam::glTF::mesh::addColour(const label accessorId)
65{
66 colours_.append
67 (
69 (
70 "COLOR_" + Foam::name(colours_.size()),
71 accessorId
72 )
73 );
74}
75
76
78{
79 os << indent << "\"primitives\" : [{" << nl << incrIndent
80 << indent << "\"attributes\" : {" << nl << incrIndent
81 << indent << "\"POSITION\" : " << accessorId_;
82
83 for (const auto& f : fields_)
84 {
85 os << "," << nl << indent << f.first() << " : " << f.second();
86 }
87
88 for (const auto& c : colours_)
89 {
90 os << "," << nl << indent << c.first() << " : " << c.second();
91 }
92
93 os << nl << decrIndent << indent << "}," << nl
94 << indent << "\"mode\" : " << 0 << nl << decrIndent// 0 = POINTS
95 << indent << "}]";
96
98}
99
100
102{
103 mesh.write(os);
104
105 return os;
106}
107
108
109// ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:58
virtual bool write()
Write the output fields.
Base class for glTF entities.
Definition: foamGltfBase.H:122
void addColour(const label accessorId)
Add a colour to the mesh.
Definition: foamGltfMesh.C:64
label & accessorId() noexcept
Return the accessor ID.
Definition: foamGltfMesh.C:52
void addField(const word &name, const label accessorId)
Add a field to the mesh.
Definition: foamGltfMesh.C:58
mesh()
Default construct.
Definition: foamGltfMesh.C:32
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:349
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:342
const direction noexcept
Definition: Scalar.H:223
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:356
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
labelList f(nPoints)