13 #ifndef hifi_RenderableEntityItem_h
14 #define hifi_RenderableEntityItem_h
16 #include <render/Scene.h>
17 #include <render/HighlightStyle.h>
19 #include <EntityItem.h>
21 #include "AbstractViewStateInterface.h"
22 #include "EntitiesRendererLogging.h"
23 #include <graphics-scripting/Forward.h>
24 #include <RenderHifi.h>
25 #include "EntityTreeRenderer.h"
26 #include "FadeObjectParams.shared.slh"
28 class EntityTreeRenderer;
30 namespace render {
namespace entities {
33 class EntityRenderer :
public QObject,
public std::enable_shared_from_this<EntityRenderer>,
public PayloadProxyInterface,
protected ReadWriteLockable,
public scriptable::ModelProvider {
36 using Pointer = std::shared_ptr<EntityRenderer>;
39 static void initEntityRenderers();
40 static Pointer addToScene(EntityTreeRenderer& renderer,
const EntityItemPointer& entity,
const ScenePointer& scene, Transaction& transaction);
43 virtual bool wantsHandControllerPointerEvents()
const {
return false; }
44 virtual bool wantsKeyboardFocus()
const {
return false; }
45 virtual void setProxyWindow(QWindow* proxyWindow) {}
46 virtual QObject* getEventHandler() {
return nullptr; }
47 virtual void emitScriptEvent(
const QVariant& message) {}
48 const EntityItemPointer& getEntity()
const {
return _entity; }
49 const ItemID& getRenderItemID()
const {
return _renderItemID; }
51 const SharedSoundPointer& getCollisionSound() {
return _collisionSound; }
52 void setCollisionSound(
const SharedSoundPointer& sound) { _collisionSound = sound; }
56 virtual void updateInScene(
const ScenePointer& scene, Transaction& transaction)
final;
57 virtual bool addToScene(
const ScenePointer& scene, Transaction& transaction)
final;
58 virtual void removeFromScene(
const ScenePointer& scene, Transaction& transaction);
60 virtual void fade(render::Transaction& transaction, TransitionType type);
62 const uint64_t& getUpdateTime()
const {
return _updateTime; }
70 virtual void addMaterial(graphics::MaterialLayer material,
const std::string& parentMaterialName);
71 virtual void removeMaterial(graphics::MaterialPointer material,
const std::string& parentMaterialName);
72 virtual graphics::MaterialPointer getTopMaterial();
73 Pipeline getPipelineType(
const graphics::MultiMaterial& materials);
74 virtual gpu::TexturePointer getTexture() {
return nullptr; }
76 virtual scriptable::ScriptableModelBase getScriptableModel()
override {
return scriptable::ScriptableModelBase(); }
78 static glm::vec4 calculatePulseColor(
const glm::vec4& color,
const PulsePropertyGroup& pulseProperties, quint64 start);
79 static glm::vec3 calculatePulseColor(
const glm::vec3& color,
const PulsePropertyGroup& pulseProperties, quint64 start);
81 virtual uint32_t metaFetchMetaSubItems(ItemIDs& subItems)
const override;
82 virtual Item::Bound getBound(RenderArgs* args)
override;
83 bool passesZoneOcclusionTest(
const std::unordered_set<QUuid>& containingZones)
const override;
84 ItemID computeMirrorView(ViewFrustum& viewFrustum)
const override;
85 static ItemID computeMirrorViewOperator(ViewFrustum& viewFrustum,
const glm::vec3& inPropertiesPosition,
const glm::quat& inPropertiesRotation,
86 MirrorMode mirrorMode,
const QUuid& portalExitID);
87 virtual void renderSimulate(RenderArgs* args)
override {}
88 virtual HighlightStyle getOutlineStyle(
const ViewFrustum& viewFrustum,
const size_t height)
const override;
90 virtual FadeProperties getFadeProperties(
const TransitionType type)
const override;
92 virtual ComponentMode getFadeOutMode()
const {
return _renderLayer == RenderLayer::WORLD ? _fadeOutMode : ComponentMode::COMPONENT_MODE_DISABLED; }
95 virtual bool needsRenderUpdateFromEntity() const final {
return needsRenderUpdateFromEntity(_entity); }
96 virtual void onAddToScene(
const EntityItemPointer& entity);
97 virtual void onRemoveFromScene(
const EntityItemPointer& entity);
99 EntityRenderer(
const EntityItemPointer& entity);
103 virtual ItemKey getKey()
override;
104 virtual ShapeKey getShapeKey()
override;
105 virtual void render(RenderArgs* args)
override final;
106 virtual render::hifi::Tag getTagMask()
const;
107 virtual render::hifi::Layer getHifiRenderLayer()
const;
110 virtual bool needsRenderUpdate()
const;
113 virtual bool needsRenderUpdateFromEntity(
const EntityItemPointer& entity)
const;
117 virtual void doRenderUpdateSynchronous(
const ScenePointer& scene, Transaction& transaction,
const EntityItemPointer& entity);
122 virtual void doRenderUpdateAsynchronous(
const EntityItemPointer& entity);
125 virtual void doRender(RenderArgs* args) = 0;
127 virtual void updateModelTransformAndBound(
const EntityItemPointer& entity);
128 virtual bool isTransparent()
const {
return false; }
129 inline bool isValidRenderItem()
const {
return _renderItemID != Item::INVALID_ITEM_ID; }
131 virtual void setIsVisibleInSecondaryCamera(
bool value) { _isVisibleInSecondaryCamera = value; }
132 virtual void setRenderLayer(RenderLayer value) { _renderLayer = value; }
133 virtual void setCullWithParent(
bool value) { _cullWithParent = value; }
134 virtual void setMirrorMode(MirrorMode value) { _mirrorMode = value; }
135 virtual void setPortalExitID(
const QUuid& value) { _portalExitID = value; }
138 std::shared_ptr<T> asTypedEntity() {
return std::static_pointer_cast<T>(_entity); }
140 static void makeStatusGetters(
const EntityItemPointer& entity, Item::Status::Getters& statusGetters);
141 const Transform& getModelTransform()
const;
143 Transform getTransformToCenterWithMaybeOnlyLocalRotation(
const EntityItemPointer& entity,
bool& success)
const;
145 FadeObjectParams getFadeParams(
const render::ScenePointer& scene)
const;
148 using MaterialMap = std::unordered_map<std::string, graphics::MultiMaterial>;
149 bool needsRenderUpdateFromMaterials()
const;
150 void updateMaterials(
bool baseMaterialChanged =
false);
151 bool materialsTransparent()
const;
152 Item::Bound getMaterialBound(RenderArgs* args);
153 void updateItemKeyBuilderFromMaterials(ItemKey::Builder& builder);
154 void updateShapeKeyBuilderFromMaterials(ShapeKey::Builder& builder);
157 SharedSoundPointer _collisionSound;
158 QUuid _changeHandlerId;
159 ItemID _renderItemID{ Item::INVALID_ITEM_ID };
160 uint64_t _updateTime{ usecTimestampNow() };
161 bool _prevIsTransparent {
false };
162 bool _visible {
false };
163 bool _isVisibleInSecondaryCamera {
false };
164 bool _canCastShadow {
false };
165 bool _cullWithParent {
false };
166 RenderLayer _renderLayer { RenderLayer::WORLD };
167 PrimitiveMode _primitiveMode { PrimitiveMode::SOLID };
168 QVector<QUuid> _renderWithZones;
169 BillboardMode _billboardMode { BillboardMode::NONE };
170 bool _cauterized {
false };
171 bool _moving {
false };
172 MirrorMode _mirrorMode { MirrorMode::NONE };
174 Transform _renderTransform;
175 Transform _prevRenderTransform;
177 FadeInPropertyGroup _fadeInProperties;
178 FadeOutPropertyGroup _fadeOutProperties;
179 ComponentMode _fadeInMode { COMPONENT_MODE_INHERIT };
180 ComponentMode _fadeOutMode { COMPONENT_MODE_INHERIT };
182 MaterialMap _materials;
183 mutable std::mutex _materialsLock;
190 Transform _modelTransform;
194 const EntityItemPointer _entity;
199 void requestRenderUpdate();
202 template <
typename T>
203 class TypedEntityRenderer :
public EntityRenderer {
204 using Parent = EntityRenderer;
207 TypedEntityRenderer(
const EntityItemPointer& entity) : Parent(entity), _typedEntity(asTypedEntity<T>()) {}
210 using TypedEntityPointer = std::shared_ptr<T>;
212 virtual void onAddToScene(
const EntityItemPointer& entity)
override final {
213 Parent::onAddToScene(entity);
214 onAddToSceneTyped(_typedEntity);
217 virtual void onRemoveFromScene(
const EntityItemPointer& entity)
override final {
218 Parent::onRemoveFromScene(entity);
219 onRemoveFromSceneTyped(_typedEntity);
222 using Parent::needsRenderUpdateFromEntity;
224 virtual bool needsRenderUpdateFromEntity(
const EntityItemPointer& entity)
const override final {
225 return Parent::needsRenderUpdateFromEntity(entity) || needsRenderUpdateFromTypedEntity(_typedEntity);
228 virtual void doRenderUpdateSynchronous(
const ScenePointer& scene, Transaction& transaction,
const EntityItemPointer& entity)
override final {
229 Parent::doRenderUpdateSynchronous(scene, transaction, entity);
230 doRenderUpdateSynchronousTyped(scene, transaction, _typedEntity);
233 virtual void doRenderUpdateAsynchronous(
const EntityItemPointer& entity)
override final {
234 Parent::doRenderUpdateAsynchronous(entity);
235 doRenderUpdateAsynchronousTyped(_typedEntity);
238 virtual bool needsRenderUpdateFromTypedEntity(
const TypedEntityPointer& entity)
const {
return false; }
239 virtual void doRenderUpdateSynchronousTyped(
const ScenePointer& scene, Transaction& transaction,
const TypedEntityPointer& entity) { }
240 virtual void doRenderUpdateAsynchronousTyped(
const TypedEntityPointer& entity) { }
241 virtual void onAddToSceneTyped(
const TypedEntityPointer& entity) { }
242 virtual void onRemoveFromSceneTyped(
const TypedEntityPointer& entity) { }
245 const TypedEntityPointer _typedEntity;