13 #ifndef hifi_MeshPartPayload_h
14 #define hifi_MeshPartPayload_h
18 #include <gpu/Batch.h>
19 #include <render/Scene.h>
20 #include <graphics/Geometry.h>
21 #include <render/HighlightStyle.h>
23 class ModelMeshPartPayload {
25 typedef render::Payload<ModelMeshPartPayload> Payload;
26 typedef Payload::DataPointer Pointer;
28 ModelMeshPartPayload(ModelPointer model,
int meshIndex,
int partIndex,
int shapeIndex,
const Transform& transform,
const uint64_t& created);
30 virtual void updateMeshPart(
const std::shared_ptr<const graphics::Mesh>& drawMesh,
int partIndex);
32 void updateClusterBuffer(
const std::vector<glm::mat4>& clusterMatrices);
33 void updateClusterBuffer(
const std::vector<Model::TransformDualQuaternion>& clusterDualQuaternions);
35 void computeAdjustedLocalBound(
const std::vector<glm::mat4>& clusterMatrices);
36 void computeAdjustedLocalBound(
const std::vector<Model::TransformDualQuaternion>& clusterDualQuaternions);
38 void updateTransformForSkinnedMesh(
const Transform& modelTransform,
const Model::MeshState& meshState,
bool useDualQuaternionSkinning);
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;
45 void updateKey(
const render::ItemKey& key);
46 void setShapeKey(
bool invalidateShapeKey, PrimitiveMode primitiveMode,
bool useDualQuaternionSkinning);
49 render::ItemKey getKey()
const;
50 render::Item::Bound getBound(RenderArgs* args)
const;
51 render::ShapeKey getShapeKey()
const;
52 void render(RenderArgs* args);
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(); }
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;
66 void addMaterial(graphics::MaterialLayer material) { _drawMaterials.push(material); }
67 void removeMaterial(graphics::MaterialPointer material) { _drawMaterials.remove(material); }
69 void setBlendshapeBuffer(
const std::unordered_map<int, gpu::BufferPointer>& blendshapeBuffers,
const QVector<int>& blendedMeshSizes);
71 static bool enableMaterialProceduralShaders;
74 void initCache(
const ModelPointer& model,
int shapeID);
77 std::shared_ptr<const graphics::Mesh> _drawMesh;
78 graphics::Mesh::Part _drawPart;
79 graphics::MultiMaterial _drawMaterials;
81 gpu::BufferPointer _clusterBuffer;
82 enum class ClusterBufferType { Matrices, DualQuaternions };
83 ClusterBufferType _clusterBufferType { ClusterBufferType::Matrices };
85 gpu::BufferPointer _meshBlendshapeBuffer;
88 render::ItemKey _itemKey { render::ItemKey::Builder::opaqueShape().build() };
89 render::ShapeKey _shapeKey { render::ShapeKey::Builder::invalid() };
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 };
101 Transform _localTransform;
102 Transform _parentTransform;
103 graphics::Box _localBound;
104 graphics::Box _adjustedLocalBound;
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);