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,
size_t mirrorDepth)
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 void setMirrorMode(MirrorMode mirrorMode) { _mirrorMode = mirrorMode; }
64 void setPortalExitID(
const QUuid& portalExitID) { _portalExitID = portalExitID; }
65 bool passesZoneOcclusionTest(
const std::unordered_set<QUuid>& containingZones)
const;
66 render::ItemID computeMirrorView(ViewFrustum& viewFrustum)
const;
67 render::HighlightStyle getOutlineStyle(
const ViewFrustum& viewFrustum,
const size_t height)
const;
69 void addMaterial(graphics::MaterialLayer material) { _drawMaterials.push(material); }
70 void removeMaterial(graphics::MaterialPointer material) { _drawMaterials.remove(material); }
72 void setBlendshapeBuffer(
const std::unordered_map<int, gpu::BufferPointer>& blendshapeBuffers,
const QVector<int>& blendedMeshSizes);
75 mutable Transform _previousRenderTransform;
78 void initCache(
const ModelPointer& model,
int shapeID);
81 std::shared_ptr<const graphics::Mesh> _drawMesh;
82 graphics::Mesh::Part _drawPart;
83 graphics::MultiMaterial _drawMaterials;
85 gpu::BufferPointer _clusterBuffer;
86 enum class ClusterBufferType { Matrices, DualQuaternions };
87 ClusterBufferType _clusterBufferType { ClusterBufferType::Matrices };
89 gpu::BufferPointer _meshBlendshapeBuffer;
92 render::ItemKey _itemKey { render::ItemKey::Builder::opaqueShape().build() };
93 render::ShapeKey _shapeKey { render::ShapeKey::Builder::invalid() };
95 bool _isSkinned {
false };
96 bool _isBlendShaped {
false };
97 bool _hasTangents {
false };
98 bool _prevUseDualQuaternionSkinning {
false };
99 bool _cauterized {
false };
100 bool _cullWithParent {
false };
101 QVector<QUuid> _renderWithZones;
102 BillboardMode _billboardMode { BillboardMode::NONE };
103 MirrorMode _mirrorMode { MirrorMode::NONE };
107 Transform _localTransform;
108 Transform _parentTransform;
109 graphics::Box _localBound;
110 graphics::Box _adjustedLocalBound;
114 template <>
const ItemKey payloadGetKey(
const ModelMeshPartPayload::Pointer& payload);
115 template <>
const Item::Bound payloadGetBound(
const ModelMeshPartPayload::Pointer& payload, RenderArgs* args);
116 template <>
const ShapeKey shapeGetShapeKey(
const ModelMeshPartPayload::Pointer& payload);
117 template <>
void payloadRender(
const ModelMeshPartPayload::Pointer& payload, RenderArgs* args);
118 template <>
bool payloadPassesZoneOcclusionTest(
const ModelMeshPartPayload::Pointer& payload,
const std::unordered_set<QUuid>& containingZones);
119 template <> ItemID payloadComputeMirrorView(
const ModelMeshPartPayload::Pointer& payload, ViewFrustum& viewFrustum);
120 template <> HighlightStyle payloadGetOutlineStyle(
const ModelMeshPartPayload::Pointer& payload,
const ViewFrustum& viewFrustum,
const size_t height);