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 // ************************************************************************* //
Foam::glTF::animation::glTFSampler::output
label output
Definition: foamGltfAnimation.H:74
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::glTF::animation::glTFChannel::target
glTFTarget target
Definition: foamGltfAnimation.H:88
Foam::glTF::animation::channels_
DynamicList< glTFChannel > channels_
Definition: foamGltfAnimation.H:99
Foam::glTF::animation::samplers_
DynamicList< glTFSampler > samplers_
Definition: foamGltfAnimation.H:96
Foam::glTF::animation::glTFSampler
Definition: foamGltfAnimation.H:70
Foam::glTF::animation::glTFTarget::path
string path
Definition: foamGltfAnimation.H:81
Foam::glTF::animation::write
void write(Ostream &os) const
Definition: foamGltfAnimation.C:65
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Definition: Ostream.H:352
forAll
#define forAll(list, i)
Definition: stdFoam.H:349
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Definition: boundaryPatch.C:76
Foam::glTF::base
Base class for glTF entities.
Definition: foamGltfBase.H:116
Foam::glTF::animation::glTFSampler::input
label input
Definition: foamGltfAnimation.H:72
Foam::interpolation
Abstract base class for interpolation.
Definition: mappedPatchFieldBase.H:92
Foam::glTF::animation
glTF animation
Definition: foamGltfAnimation.H:61
os
OBJstream os(runTime.globalPath()/outputName)
Foam::Ostream::write
virtual bool write(const token &tok)=0
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Definition: Ostream.H:361
foamGltfAnimation.H
Foam::indent
Ostream & indent(Ostream &os)
Definition: Ostream.H:343
Foam::glTF::animation::glTFSampler::interpolation
string interpolation
Definition: foamGltfAnimation.H:73
Foam::glTF::animation::glTFChannel
Definition: foamGltfAnimation.H:85
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::glTF::animation::glTFChannel::samplerId
label samplerId
Definition: foamGltfAnimation.H:87
Foam::glTF::animation::addTranslation
void addTranslation(const label inputId, const label outputId, const label nodeId, const string &interpolation)
Definition: foamGltfAnimation.C:44
Foam::glTF::animation::glTFTarget::node
label node
Definition: foamGltfAnimation.H:80
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:52
Foam::glTF::animation::animation
animation()
Definition: foamGltfAnimation.C:25