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 -------------------------------------------------------------------------------
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 template<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 
58 template<class Type>
59 Foam::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 
71 template<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 // ************************************************************************* //
uint8_t direction
Definition: direction.H:46
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
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 expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
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.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103