NAP
visualizenormalsmesh.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 
7 // Local Includes
8 #include "mesh.h"
9 
10 // External Includes
11 #include <nap/resourceptr.h>
12 
13 namespace nap
14 {
15  // Forward Declares
16  class Core;
17  class RenderService;
18 
31  class NAPAPI VisualizeNormalsMesh : public IMesh
32  {
33  RTTI_ENABLE(IMesh)
34  public:
36 
40  virtual bool init(utility::ErrorState& errorState) override;
41 
45  virtual MeshInstance& getMeshInstance() override { return *mMeshInstance; }
46 
50  virtual const MeshInstance& getMeshInstance() const override { return *mMeshInstance; }
51 
57  bool calculateNormals(utility::ErrorState& error, bool push = true);
58 
59  ResourcePtr<IMesh> mReferenceMesh = nullptr;
60  float mNormalLength = 1.0f;
62 
70  bool setReferenceMesh(IMesh& mesh, nap::utility::ErrorState& error);
71 
72  protected:
73  std::unique_ptr<MeshInstance> mMeshInstance = nullptr;
74 
75  // Position Attribute data
76  nap::Vec3VertexAttribute* mPositionAttr = nullptr;
77 
78  // 'Tip' vertex attribute data, 1.0 for top vertex of normal, 0.0 for bottom vertex of normal
79  nap::FloatVertexAttribute* mTipAttr = nullptr;
80 
81  // Normal Attribute data
82  nap::Vec3VertexAttribute* mNormalsAttr = nullptr;
83 
84  // UV attribute data
85  std::vector<nap::Vec3VertexAttribute*> mUvAttrs;
86 
87  // Color attribute data
88  std::vector<nap::Vec4VertexAttribute*> mColorAttrs;
89 
90  // The current reference mesh
91  nap::IMesh* mCurrentReferenceMesh = nullptr;
92 
93  // The renderer
94  nap::RenderService* mRenderService = nullptr;
95 
100  bool createMeshInstance(utility::ErrorState& error);
101 
102  private:
109  bool setup(utility::ErrorState& error);
110  };
111 }
nap::VisualizeNormalsMesh::mColorAttrs
std::vector< nap::Vec4VertexAttribute * > mColorAttrs
Definition: visualizenormalsmesh.h:88
nap::VertexAttribute< glm::vec3 >
nap::rtti::ObjectPtr
Definition: objectptr.h:154
nap::EMemoryUsage
EMemoryUsage
Definition: gpubuffer.h:41
nap::VisualizeNormalsMesh::getMeshInstance
virtual const MeshInstance & getMeshInstance() const override
Definition: visualizenormalsmesh.h:50
nap::utility::ErrorState
Definition: errorstate.h:19
nap::IMesh
Definition: mesh.h:394
nap::VisualizeNormalsMesh
Definition: visualizenormalsmesh.h:31
nap::RenderService
Definition: renderservice.h:275
nap::Core
Definition: core.h:82
nap::EMemoryUsage::DynamicWrite
@ DynamicWrite
Buffer data is updated more than once from the CPU to the GPU.
nap
Definition: templateapp.h:17
nap::MeshInstance
Definition: mesh.h:196
nap::VisualizeNormalsMesh::mUvAttrs
std::vector< nap::Vec3VertexAttribute * > mUvAttrs
Definition: visualizenormalsmesh.h:85
nap::VisualizeNormalsMesh::getMeshInstance
virtual MeshInstance & getMeshInstance() override
Definition: visualizenormalsmesh.h:45