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 
52 Foam::label& Foam::glTF::mesh::accessorId() noexcept
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 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::glTF::mesh::accessorId
label & accessorId() noexcept
Return the accessor ID.
Definition: foamGltfMesh.C:52
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:346
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::base::write
void write(Ostream &os) const
Write.
Definition: foamGltfBase.H:171
Foam::glTF::mesh::mesh
mesh()
Default construct.
Definition: foamGltfMesh.C:32
Foam::glTF::mesh::write
void write(Ostream &os) const
Write.
Definition: foamGltfMesh.C:77
os
OBJstream os(runTime.globalPath()/outputName)
foamGltfMesh.H
Foam::glTF::mesh::addColour
void addColour(const label accessorId)
Add a colour to the mesh.
Definition: foamGltfMesh.C:64
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:353
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:339
Foam::nl
constexpr char nl
Definition: Ostream.H:404
f
labelList f(nPoints)
Foam::glTF::mesh::addField
void addField(const word &name, const label accessorId)
Add a field to the mesh.
Definition: foamGltfMesh.C:58
Foam::glTF::mesh
glTF mesh
Definition: foamGltfMesh.H:64
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Tuple2
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:60