foamGltfScene.H
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-2022 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 Class
27  Foam::glTF::scene
28 
29 Description
30  Main class to assemble glTF components into a scene
31 
32 Note
33  Implements the glTF v2 specification
34 
35 SourceFiles
36  foamGltfScene.C
37  foamGltfSceneTemplates.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_gltf_scene_H
42 #define Foam_gltf_scene_H
43 
44 #include "fileName.H"
45 #include "foamGltfList.H"
46 #include "foamGltfObject.H"
47 #include "foamGltfMesh.H"
48 #include "foamGltfBufferView.H"
49 #include "foamGltfAccessor.H"
50 #include "foamGltfAnimation.H"
51 #include "scalarField.H"
52 #include "vectorField.H"
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 
59 // Forward Declarations
60 class OFstream;
61 
62 namespace glTF
63 {
64 
65 /*---------------------------------------------------------------------------*\
66  Class glTF::scene Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class scene
70 {
71  // Private Data
72 
73  //- List of binary objects
74  glTF::List<object> objects_;
75 
76  //- List of meshes
77  glTF::List<mesh> meshes_;
78 
79  //- List of buffer views
80  glTF::List<bufferView> bufferViews_;
81 
82  //- List of accessors
83  glTF::List<accessor> accessors_;
84 
85  //- List of animations
86  glTF::List<animation> animations_;
87 
88  //- Accumulative size in bytes
89  label bytes_;
90 
91 
92  // Private Member Functions
93 
94  //- Non-const access to mesh at index (can be -1 for last mesh)
95  // FatalError for out-of-bounds
96  mesh& getMesh(label meshi);
97 
98 
99 public:
100 
101  // Constructors
102 
103  //- Default construct
104  scene();
105 
106 
107  // Public Member Functions
108 
109  //- Returns accessor index
110  template<class Type>
111  label addField
112  (
113  const Type& fld,
114  const word& name,
115  const label target = -1
116  );
117 
118  //- Returns index of last mesh
119  template<class Type>
120  label addMesh(const Type& fld, const word& name);
121 
122  //- Returns accessor index
123  template<class Type>
124  label addFieldToMesh
125  (
126  const Type& fld,
127  const word& name,
128  const label meshId
129  );
130 
131  //- Add a colour field to the mesh, optionally with an alpha channel.
132  // A constant alpha value can be specified as a field of size 1.
133  //
134  // \returns accessor index
135  label addColourToMesh
136  (
137  const vectorField& fld,
138  const word& name,
139  const label meshId,
141  );
142 
143  //- Returns index of last animation
144  label createAnimation(const word& name);
145 
146  //- Add to existing animation
147  void addToAnimation
148  (
149  const label animationi,
150  const label inputId,
151  const label outputId,
152  const label meshId,
153  const string& interpolation = "LINEAR"
154  );
155 
156 
157  // Write
158 
159  //- Write to file pair (.gltf, .bin)
160  void write(const fileName& outputFile);
161 
162  //- Write JSON (.gltf) to stream with auxiliary binary data (.bin)
163  void write(Ostream& os);
164 };
165 
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 } // End namespace glTF
170 } // End namespace Foam
171 
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 
174 #ifdef NoRepository
175  #include "foamGltfSceneTemplates.C"
176 #endif
177 
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 
180 #endif
181 
182 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:71
glTF mesh
Definition: foamGltfMesh.H:60
void addToAnimation(const label animationi, const label inputId, const label outputId, const label meshId, const string &interpolation="LINEAR")
Add to existing animation.
label addFieldToMesh(const Type &fld, const word &name, const label meshId)
Returns accessor index.
label addMesh(const Type &fld, const word &name)
Returns index of last mesh.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
label createAnimation(const word &name)
Returns index of last animation.
scene()
Default construct.
Definition: foamGltfScene.C:27
A class for handling words, derived from Foam::string.
Definition: word.H:63
Main class to assemble glTF components into a scene.
Definition: foamGltfScene.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
OBJstream os(runTime.globalPath()/outputName)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
label addField(const Type &fld, const word &name, const label target=-1)
Returns accessor index.
static const Field< scalar > & null()
Return nullObject reference Field.
Definition: FieldI.H:24
label addColourToMesh(const vectorField &fld, const word &name, const label meshId, const scalarField &alpha=scalarField::null())
Add a colour field to the mesh, optionally with an alpha channel.
Definition: foamGltfScene.C:61
Abstract base class for volume field interpolation.
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Container for glTF entities.
Definition: foamGltfList.H:47
Namespace for OpenFOAM.
void write(const fileName &outputFile)
Write to file pair (.gltf, .bin)