foamGltfAnimation.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 "foamGltfAnimation.H"
29
30// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31
33:
34 base(),
35 samplers_(),
36 channels_()
37{}
38
39
41:
42 base(name),
43 samplers_(),
44 channels_()
45{}
46
47
48// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49
51(
52 const label inputId,
53 const label outputId,
54 const label nodeId,
55 const string& interpolation
56)
57{
58 glTFSampler sampler;
59 sampler.input = inputId;
60 sampler.output = outputId;
62 samplers_.append(sampler);
63
64 glTFChannel channel;
65 channel.samplerId = samplers_.size() - 1;
66 channel.target.node = nodeId;
67 channel.target.path = "translation";
68 channels_.append(channel);
69}
70
71
73{
74 os << indent << "\"samplers\" : [" << nl << incrIndent;
75
76 forAll(samplers_, i)
77 {
78 const auto& sampler = samplers_[i];
79
80 os << indent << "{" << nl << incrIndent
81 << indent << "\"input\" : " << sampler.input << "," << nl
82 << indent << "\"interpolation\" : " << sampler.interpolation
83 << "," << nl
84 << indent << "\"output\" : " << sampler.output << nl
85 << decrIndent << indent << "}";
86
87 if (i != samplers_.size() - 1) os << "," << nl;
88 }
89
90 os << nl << decrIndent << indent << "]," << nl;
91
92 os << indent << "\"channels\" : [" << nl << incrIndent;
93
94 forAll(channels_, i)
95 {
96 const auto& channel = channels_[i];
97
98 os << indent << "{" << nl << incrIndent
99 << indent << "\"sampler\" : " << channel.samplerId << "," << nl
100 << indent << "\"target\" : {" << incrIndent << nl
101 << indent << "\"node\" : " << channel.target.node << "," << nl
102 << indent << "\"path\" : " << channel.target.path << nl
103 << decrIndent << indent << "}" << nl
104 << decrIndent << indent << "}";
105
106 if (i != channels_.size() - 1) os << "," << nl;
107 }
108
109 os << nl << decrIndent << indent << "]";
110}
111
112
114{
115 animation.write(os);
116
117 return os;
118}
119
120
121// ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual bool write()
Write the output fields.
void write(Ostream &os) const
Write.
animation()
Default construct.
void addTranslation(const label inputId, const label outputId, const label nodeId, const string &interpolation)
Add translation.
Base class for glTF entities.
Definition: foamGltfBase.H:122
Abstract base class for volume field interpolation.
Definition: interpolation.H:60
A class for handling words, derived from Foam::string.
Definition: word.H:68
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
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
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333