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 -------------------------------------------------------------------------------
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 "foamGltfMesh.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
33 :
34  base(),
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 * * * * * * * * * * * * * //
51 
53 {
54  return accessorId_;
55 }
56 
57 
58 void Foam::glTF::mesh::addField(const word& name, const label accessorId)
59 {
60  fields_.append(Tuple2<string, label>("_field:" + name, accessorId));
61 }
62 
63 
64 void Foam::glTF::mesh::addColour(const label accessorId)
65 {
66  colours_.append
67  (
69  (
70  "COLOR_" + Foam::name(colours_.size()),
71  accessorId
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 
97  base::write(os);
98 }
99 
100 
102 {
103  mesh.write(os);
104 
105  return os;
106 }
107 
108 
109 // ************************************************************************* //
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:493
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:54
void write(Ostream &os) const
Write.
Definition: foamGltfBase.H:182
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
void addColour(const label accessorId)
Add a colour to the mesh.
Definition: foamGltfMesh.C:57
void write(Ostream &os) const
Write.
Definition: foamGltfMesh.C:70
dynamicFvMesh & mesh
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
void addField(const word &name, const label accessorId)
Add a field to the mesh.
Definition: foamGltfMesh.C:51
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
mesh()
Default construct.
Definition: foamGltfMesh.C:25
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:511
labelList f(nPoints)
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
label & accessorId() noexcept
Return the accessor ID.
Definition: foamGltfMesh.C:45
const dimensionedScalar c
Speed of light in a vacuum.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:502