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 
114 {
115  animation.write(os);
116 
117  return os;
118 }
119 
120 
121 // ************************************************************************* //
Foam::glTF::animation::glTFSampler::output
label output
Definition: foamGltfAnimation.H:78
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::glTF::animation::glTFChannel::target
glTFTarget target
Definition: foamGltfAnimation.H:92
Foam::glTF::animation::glTFSampler
Definition: foamGltfAnimation.H:74
Foam::glTF::animation::glTFTarget::path
string path
Definition: foamGltfAnimation.H:85
Foam::glTF::animation::write
void write(Ostream &os) const
Write.
Definition: foamGltfAnimation.C:72
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:346
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::glTF::base
Base class for glTF entities.
Definition: foamGltfBase.H:121
Foam::glTF::animation::glTFSampler::input
label input
Definition: foamGltfAnimation.H:76
Foam::interpolation
Abstract base class for interpolation.
Definition: mappedPatchFieldBase.H:96
Foam::glTF::animation
glTF animation
Definition: foamGltfAnimation.H:65
os
OBJstream os(runTime.globalPath()/outputName)
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:353
foamGltfAnimation.H
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:339
Foam::glTF::animation::glTFSampler::interpolation
string interpolation
Definition: foamGltfAnimation.H:77
Foam::glTF::animation::glTFChannel
Definition: foamGltfAnimation.H:89
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::glTF::animation::glTFChannel::samplerId
label samplerId
Definition: foamGltfAnimation.H:91
Foam::glTF::animation::addTranslation
void addTranslation(const label inputId, const label outputId, const label nodeId, const string &interpolation)
Add translation.
Definition: foamGltfAnimation.C:51
Foam::glTF::animation::glTFTarget::node
label node
Definition: foamGltfAnimation.H:84
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::glTF::animation::animation
animation()
Default construct.
Definition: foamGltfAnimation.C:32