Loading...
Searching...
No Matches
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.
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;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-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 and vector-space.
Definition pTraits.H:64
A class for handling words, derived from Foam::string.
Definition word.H:66
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.
@ ARRAY_BUFFER
vertex attributes
uint8_t direction
Definition direction.H:49
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127