foamGltfSceneTemplates.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-------------------------------------------------------------------------------
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
28template<class Type>
30(
31 const Type& fld,
32 const word& name,
33 const label target
34)
35{
37
38 auto& bv = bufferViews_.create(name);
39 bv.byteOffset() = bytes_;
40 bv.byteLength() = fld.size()*nCmpts*sizeof(float);
41 if (target != -1)
42 {
43 bv.target() = target;
44 }
45 bytes_ += bv.byteLength();
46
47 auto& acc = accessors_.create(name);
48 acc.bufferViewId() = bv.id();
49 acc.set(fld);
50
51 auto& obj = objects_.create(name);
52 obj.addData(fld);
53
54 return acc.id();
55}
56
57
58template<class Type>
59Foam::label Foam::glTF::scene::addMesh(const Type& fld, const word& name)
60{
61 const label accessorId =
63
64 auto& gmesh = meshes_.create(name);
65 gmesh.accessorId() = accessorId;
66
67 return meshes_.size() - 1;
68}
69
70
71template<class Type>
73(
74 const Type& fld,
75 const word& name,
76 const label meshi
77)
78{
79 auto& gmesh = getMesh(meshi);
80
81 const label accessorId = addField(fld, name);
82
83 gmesh.addField(name, accessorId);
84
85 return accessorId;
86}
87
88
89// ************************************************************************* //
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
label addField(const Type &fld, const word &name, const label target=-1)
Returns accessor index.
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.
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
A class for handling words, derived from Foam::string.
Definition: word.H:68
@ ARRAY_BUFFER
vertex attributes
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
uint8_t direction
Definition: direction.H:56
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59