NAP
scatterpointsmesh.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 #include "mesh.h"
7 #include "triangleiterator.h"
8 
9 // External Includes
10 #include <nap/resource.h>
11 #include <nap/resourceptr.h>
12 
13 namespace nap
14 {
15  // Forward Declares
16  class Core;
17  class RenderService;
18 
24  class NAPAPI ScatterPointsMesh : public IMesh
25  {
26  RTTI_ENABLE(IMesh)
27  public:
28  ScatterPointsMesh(Core& core);
29 
34  virtual bool init(utility::ErrorState& errorState) override;
35 
39  virtual MeshInstance& getMeshInstance() override { return *mMeshInstance; }
40 
44  virtual const MeshInstance& getMeshInstance() const override { return *mMeshInstance; }
45 
46  ResourcePtr<IMesh> mReferenceMesh = nullptr;
47  int mNumberOfPoints = 1000;
49 
50  protected:
51  // Creates the mesh and shape
52  bool createMeshInstance(nap::utility::ErrorState& error);
53 
54  // Sets up the mesh instance based on the total amount of points to scatter
55  bool setup(nap::utility::ErrorState& error);
56 
57  // Scatter points
58  bool scatterPoints(nap::utility::ErrorState& error);
59 
60  //Helper function that computes the total visible area of the mesh
61  using TriangleAreaMap = std::map<float, Triangle>;
62  float computeArea(TriangleAreaMap& outMap);
63 
64  std::unique_ptr<MeshInstance> mMeshInstance = nullptr;
65  nap::Vec3VertexAttribute* mPositionAttr = nullptr;
66  nap::Vec3VertexAttribute* mNormalsAttr = nullptr;
67  std::vector<nap::Vec3VertexAttribute*> mUvAttrs;
68  std::vector<nap::Vec4VertexAttribute*> mColorAttrs;
69  RenderService* mRenderService = nullptr;
70  };
71 }
nap::ScatterPointsMesh
Definition: scatterpointsmesh.h:24
nap::VertexAttribute< glm::vec3 >
nap::EMemoryUsage::Static
@ Static
Buffer data is uploaded only once from the CPU to the GPU.
nap::ScatterPointsMesh::getMeshInstance
virtual MeshInstance & getMeshInstance() override
Definition: scatterpointsmesh.h:39
nap::ScatterPointsMesh::getMeshInstance
virtual const MeshInstance & getMeshInstance() const override
Definition: scatterpointsmesh.h:44
nap::rtti::ObjectPtr
Definition: objectptr.h:154
nap::EMemoryUsage
EMemoryUsage
Definition: gpubuffer.h:41
nap::utility::ErrorState
Definition: errorstate.h:19
nap::IMesh
Definition: mesh.h:394
nap::ScatterPointsMesh::mColorAttrs
std::vector< nap::Vec4VertexAttribute * > mColorAttrs
Color attribute data.
Definition: scatterpointsmesh.h:68
nap::RenderService
Definition: renderservice.h:275
nap::Core
Definition: core.h:82
nap::ScatterPointsMesh::mUvAttrs
std::vector< nap::Vec3VertexAttribute * > mUvAttrs
UV attribute data.
Definition: scatterpointsmesh.h:67
nap
Definition: templateapp.h:17
nap::MeshInstance
Definition: mesh.h:196
nap::ScatterPointsMesh::TriangleAreaMap
std::map< float, Triangle > TriangleAreaMap
Definition: scatterpointsmesh.h:61