foamGltfSceneWriter.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) 2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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 "foamGltfSceneWriter.H"
29#include "OFstream.H"
30#include "OSspecific.H"
31
32// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33
35:
36 ofile_(nullptr),
37 scene_(nullptr)
38{
39 open(outputFile);
40}
41
42
43// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
44
46{
47 close();
48}
49
50
51// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52
54{
55 return (ofile_ && scene_);
56}
57
58
60{
61 return (ofile_ ? ofile_->name() : fileName::null);
62}
63
64
66{
67 return *scene_;
68}
69
70
72{
73 return *scene_;
74}
75
76
78{
79 close();
80
81 fileName jsonFile(outputFile.lessExt());
82 jsonFile.ext("gltf");
83
84 // Note: called on master only
85 if (!isDir(jsonFile.path()))
86 {
87 mkDir(jsonFile.path());
88 }
89
90 ofile_.reset(new OFstream(jsonFile));
91 scene_.reset(new glTF::scene());
92}
93
94
96{
97 if (ofile_ && scene_)
98 {
99 scene_->write(*ofile_);
100 }
101 ofile_.reset(nullptr);
102 scene_.reset(nullptr);
103}
104
105
106// ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Output to file stream, using an OSstream.
Definition: OFstream.H:57
A class for handling file names.
Definition: fileName.H:76
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileNameI.H:230
word ext() const
Return file name extension (part after last .)
Definition: fileNameI.H:218
static std::string path(const std::string &str)
Return directory path name (part before last /)
Definition: fileNameI.H:176
sceneWriter()=default
Default construct.
void close()
Write scene and close file.
void open(const fileName &outputFile)
Flush, output and open a new file for output.
const fileName & path() const
The json file name. Empty with !valid()
bool valid() const noexcept
True if output file and scene exist.
~sceneWriter()
Destructor - calls close()
const scene & getScene() const
Const access to the scene. Error if valid() is not true!
Main class to assemble glTF components into a scene.
Definition: foamGltfScene.H:69
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Definition: MSwindows.C:515
const direction noexcept
Definition: Scalar.H:223
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: MSwindows.C:651
static constexpr char open
Definition: FlatOutput.H:73