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 {
36  const label nComponents = pTraits<typename Type::value_type>::nComponents;
37 
38  auto& bv = bufferViews_.create(name);
39  bv.byteOffset() = bytes_;
40  bv.byteLength() = fld.size()*nComponents*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& mesh = meshes_.create(name);
65  mesh.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  if (meshi > meshes_.size() - 1)
80  {
82  << "Mesh " << meshi << " out of range "
83  << (meshes_.size() - 1)
84  << abort(FatalError);
85  }
86 
87  const label accessorId = addField(fld, name);
88 
89  meshes_[meshi].addField(name, accessorId);
90 
91  return accessorId;
92 }
93 
94 
95 // ************************************************************************* //
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::glTF::scene::addField
label addField(const Type &fld, const word &name, const label target=-1)
Returns accessor index.
Foam::glTF::scene::addMesh
label addMesh(const Type &fld, const word &name)
Returns index of last mesh.
Foam::glTF::key
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
Foam::glTF::targetTypes::ARRAY_BUFFER
vertex attributes
Foam::glTF::scene::addFieldToMesh
label addFieldToMesh(const Type &fld, const word &name, const label meshi)
Returns accessor index.
fld
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))
Definition: gmvOutputLagrangian.H:23
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
Foam::glTF::mesh
glTF mesh
Definition: foamGltfMesh.H:64
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59