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 -------------------------------------------------------------------------------
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 \*---------------------------------------------------------------------------*/
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;
61  sampler.interpolation = interpolation;
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 
113 Foam::Ostream& Foam::operator<<(Ostream& os, const glTF::animation& animation)
114 {
115  animation.write(os);
116 
117  return os;
118 }
119 
120 
121 // ************************************************************************* //
DynamicList< glTFSampler > samplers_
Samplers.
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:493
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
void write(Ostream &os) const
Write.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
animation()
Default construct.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:511
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
Base class for glTF entities.
Definition: foamGltfBase.H:116
void addTranslation(const label inputId, const label outputId, const label nodeId, const string &interpolation)
Add translation.
Abstract base class for volume field interpolation.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:502
DynamicList< glTFChannel > channels_
Channels.