Overte C++ Documentation
MeshPartPayload.h
1 //
2 // MeshPartPayload.h
3 // interface/src/renderer
4 //
5 // Created by Sam Gateau on 10/3/15.
6 // Copyright 2015 High Fidelity, Inc.
7 // Copyright 2024 Overte e.V.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 //
12 
13 #ifndef hifi_MeshPartPayload_h
14 #define hifi_MeshPartPayload_h
15 
16 #include "Model.h"
17 
18 #include <gpu/Batch.h>
19 #include <render/Scene.h>
20 #include <graphics/Geometry.h>
21 #include <render/HighlightStyle.h>
22 
23 class ModelMeshPartPayload {
24 public:
25  typedef render::Payload<ModelMeshPartPayload> Payload;
26  typedef Payload::DataPointer Pointer;
27 
28  ModelMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform, const uint64_t& created);
29 
30  virtual void updateMeshPart(const std::shared_ptr<const graphics::Mesh>& drawMesh, int partIndex);
31 
32  void updateClusterBuffer(const std::vector<glm::mat4>& clusterMatrices); // matrix palette skinning
33  void updateClusterBuffer(const std::vector<Model::TransformDualQuaternion>& clusterDualQuaternions); // dual quaternion skinning
34 
35  void computeAdjustedLocalBound(const std::vector<glm::mat4>& clusterMatrices); // matrix palette skinning
36  void computeAdjustedLocalBound(const std::vector<Model::TransformDualQuaternion>& clusterDualQuaternions); // dual quaternion skinning
37 
38  void updateTransformForSkinnedMesh(const Transform& modelTransform, const Model::MeshState& meshState, bool useDualQuaternionSkinning);
39 
40  // ModelMeshPartPayload functions to perform render
41  void bindMesh(gpu::Batch& batch);
42  virtual void bindTransform(gpu::Batch& batch, const Transform& transform, RenderArgs::RenderMode renderMode) const;
43  void drawCall(gpu::Batch& batch) const;
44 
45  void updateKey(const render::ItemKey& key);
46  void setShapeKey(bool invalidateShapeKey, PrimitiveMode primitiveMode, bool useDualQuaternionSkinning);
47 
48  // Render Item interface
49  render::ItemKey getKey() const;
50  render::Item::Bound getBound(RenderArgs* args) const;
51  render::ShapeKey getShapeKey() const;
52  void render(RenderArgs* args);
53 
54  size_t getVerticesCount() const { return _drawMesh ? _drawMesh->getNumVertices() : 0; }
55  size_t getMaterialTextureSize() { return _drawMaterials.getTextureSize(); }
56  int getMaterialTextureCount() { return _drawMaterials.getTextureCount(); }
57  bool hasTextureInfo() const { return _drawMaterials.hasTextureInfo(); }
58 
59  void setCauterized(bool cauterized) { _cauterized = cauterized; }
60  void setCullWithParent(bool value) { _cullWithParent = value; }
61  void setRenderWithZones(const QVector<QUuid>& renderWithZones) { _renderWithZones = renderWithZones; }
62  void setBillboardMode(BillboardMode billboardMode) { _billboardMode = billboardMode; }
63  bool passesZoneOcclusionTest(const std::unordered_set<QUuid>& containingZones) const;
64  render::HighlightStyle getOutlineStyle(const ViewFrustum& viewFrustum, const size_t height) const;
65 
66  void addMaterial(graphics::MaterialLayer material) { _drawMaterials.push(material); }
67  void removeMaterial(graphics::MaterialPointer material) { _drawMaterials.remove(material); }
68 
69  void setBlendshapeBuffer(const std::unordered_map<int, gpu::BufferPointer>& blendshapeBuffers, const QVector<int>& blendedMeshSizes);
70 
71  static bool enableMaterialProceduralShaders;
72 
73 private:
74  void initCache(const ModelPointer& model, int shapeID);
75 
76  int _meshIndex;
77  std::shared_ptr<const graphics::Mesh> _drawMesh;
78  graphics::Mesh::Part _drawPart;
79  graphics::MultiMaterial _drawMaterials;
80 
81  gpu::BufferPointer _clusterBuffer;
82  enum class ClusterBufferType { Matrices, DualQuaternions };
83  ClusterBufferType _clusterBufferType { ClusterBufferType::Matrices };
84 
85  gpu::BufferPointer _meshBlendshapeBuffer;
86  int _meshNumVertices;
87 
88  render::ItemKey _itemKey { render::ItemKey::Builder::opaqueShape().build() };
89  render::ShapeKey _shapeKey { render::ShapeKey::Builder::invalid() };
90 
91  bool _isSkinned { false };
92  bool _isBlendShaped { false };
93  bool _hasTangents { false };
94  bool _prevUseDualQuaternionSkinning { false };
95  bool _cauterized { false };
96  bool _cullWithParent { false };
97  QVector<QUuid> _renderWithZones;
98  BillboardMode _billboardMode { BillboardMode::NONE };
99  uint64_t _created;
100 
101  Transform _localTransform;
102  Transform _parentTransform;
103  graphics::Box _localBound;
104  graphics::Box _adjustedLocalBound;
105 };
106 
107 namespace render {
108  template <> const ItemKey payloadGetKey(const ModelMeshPartPayload::Pointer& payload);
109  template <> const Item::Bound payloadGetBound(const ModelMeshPartPayload::Pointer& payload, RenderArgs* args);
110  template <> const ShapeKey shapeGetShapeKey(const ModelMeshPartPayload::Pointer& payload);
111  template <> void payloadRender(const ModelMeshPartPayload::Pointer& payload, RenderArgs* args);
112  template <> bool payloadPassesZoneOcclusionTest(const ModelMeshPartPayload::Pointer& payload, const std::unordered_set<QUuid>& containingZones);
113  template <> HighlightStyle payloadGetOutlineStyle(const ModelMeshPartPayload::Pointer& payload, const ViewFrustum& viewFrustum, const size_t height);
114 }
115 
116 #endif // hifi_MeshPartPayload_h