Loading...
Searching...
No Matches
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/>.
26\*---------------------------------------------------------------------------*/
27
28#include "foamGltfMesh.H"
29
30// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31
33:
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 * * * * * * * * * * * * * //
53{
54 return accessorId_;
55}
56
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()),
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
101Foam::Ostream& Foam::operator<<(Ostream& os, const glTF::mesh& mesh)
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:59
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition Tuple2.H:51
Base class for glTF entities.
void write(Ostream &os) const
Write.
const word & name() const noexcept
Return const access to the name.
base()
Default construct.
void addColour(const label accessorId)
Add a colour to the mesh.
void write(Ostream &os) const
Write.
label & accessorId() noexcept
Return the accessor ID.
void addField(const word &name, const label accessorId)
Add a field to the mesh.
mesh()
Default construct.
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition Ostream.H:490
Ostream & indent(Ostream &os)
Indent stream.
Definition Ostream.H:481
const direction noexcept
Definition scalarImpl.H:265
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition Ostream.H:499
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
labelList f(nPoints)