12 #ifndef hifi_RenderableModelEntityItem_h
13 #define hifi_RenderableModelEntityItem_h
15 #include <ModelEntityItem.h>
18 #include <QStringList>
20 #include <ModelEntityItem.h>
21 #include <AnimationCache.h>
23 #include <model-networking/ModelCache.h>
24 #include <MetaModelPayload.h>
26 #include "RenderableEntityItem.h"
29 class EntityTreeRenderer;
31 namespace render {
namespace entities {
32 class ModelEntityRenderer;
36 class ModelEntityWrapper :
public ModelEntityItem {
37 using Parent = ModelEntityItem;
38 friend class render::entities::ModelEntityRenderer;
41 ModelEntityWrapper(
const EntityItemID& entityItemID) : Parent(entityItemID) {}
42 void setModel(
const ModelPointer& model);
43 ModelPointer getModel()
const;
45 bool _needsInitialSimulation {
true };
50 class RenderableModelEntityItem :
public ModelEntityWrapper {
53 friend class render::entities::ModelEntityRenderer;
54 using Parent = ModelEntityWrapper;
58 RenderableModelEntityItem(
const EntityItemID& entityItemID,
bool dimensionsInitialized);
59 virtual ~RenderableModelEntityItem();
61 virtual void setUnscaledDimensions(
const glm::vec3& value)
override;
63 virtual EntityItemProperties getProperties(
const EntityPropertyFlags& desiredProperties,
bool allowEmptyDesiredProperties)
const override;
64 void updateModelBounds();
66 glm::vec3 getPivot()
const override;
67 virtual bool supportsDetailedIntersection()
const override;
68 virtual bool findDetailedRayIntersection(
const glm::vec3& origin,
const glm::vec3& direction,
69 const glm::vec3& viewFrustumPos, OctreeElementPointer& element,
float& distance,
70 BoxFace& face, glm::vec3& surfaceNormal,
71 QVariantMap& extraInfo,
bool precisionPicking)
const override;
72 virtual bool findDetailedParabolaIntersection(
const glm::vec3& origin,
const glm::vec3& velocity,
73 const glm::vec3& acceleration,
const glm::vec3& viewFrustumPos, OctreeElementPointer& element,
74 float& parabolicDistance, BoxFace& face, glm::vec3& surfaceNormal,
75 QVariantMap& extraInfo,
bool precisionPicking)
const override;
77 virtual void setShapeType(ShapeType type)
override;
78 virtual void setCompoundShapeURL(
const QString& url)
override;
79 virtual void setModelURL(
const QString& url)
override;
81 virtual bool isReadyToComputeShape()
const override;
82 virtual void computeShapeInfo(ShapeInfo& shapeInfo)
override;
83 bool unableToLoadCollisionShape();
85 virtual bool contains(
const glm::vec3& point)
const override;
86 void stopModelOverrideIfNoParent();
88 virtual bool shouldBePhysical()
const override;
89 void simulateRelayedJoints();
90 bool getJointMapCompleted();
91 void setJointMap(std::vector<int> jointMap);
92 int avatarJointIndex(
int modelJointIndex);
93 void setOverrideTransform(
const Transform& transform,
const glm::vec3& offset);
96 virtual glm::quat getAbsoluteJointRotationInObjectFrame(
int index)
const override;
97 virtual glm::vec3 getAbsoluteJointTranslationInObjectFrame(
int index)
const override;
98 virtual int getJointParent(
int index)
const override;
99 virtual bool setAbsoluteJointRotationInObjectFrame(
int index,
const glm::quat& rotation)
override;
100 virtual bool setAbsoluteJointTranslationInObjectFrame(
int index,
const glm::vec3& translation)
override;
102 virtual glm::quat getLocalJointRotation(
int index)
const override;
103 virtual glm::vec3 getLocalJointTranslation(
int index)
const override;
104 virtual bool setLocalJointRotation(
int index,
const glm::quat& rotation)
override;
105 virtual bool setLocalJointTranslation(
int index,
const glm::vec3& translation)
override;
107 virtual void setJointRotations(
const QVector<glm::quat>& rotations)
override;
108 virtual void setJointRotationsSet(
const QVector<bool>& rotationsSet)
override;
109 virtual void setJointTranslations(
const QVector<glm::vec3>& translations)
override;
110 virtual void setJointTranslationsSet(
const QVector<bool>& translationsSet)
override;
112 virtual void locationChanged(
bool tellPhysics =
true,
bool tellChildren =
true)
override;
114 virtual int getJointIndex(
const QString& name)
const override;
115 virtual QStringList getJointNames()
const override;
118 bool needsUpdateModelBounds()
const;
119 void autoResizeJointArrays();
120 void copyAnimationJointDataToModel();
121 bool readyToAnimate()
const;
122 void fetchCollisionGeometryResource();
124 QString getCollisionShapeURL()
const;
126 GeometryResource::Pointer _collisionGeometryResource;
127 std::vector<int> _jointMap;
128 QVariantMap _originalTextures;
129 bool _jointMapCompleted {
false };
130 bool _originalTexturesRead {
false };
131 bool _dimensionsInitialized {
true };
132 bool _needsJointSimulation {
false };
133 bool _needsToRescaleModel {
false };
136 namespace render {
namespace entities {
138 class ModelEntityRenderer :
public TypedEntityRenderer<RenderableModelEntityItem>,
public MetaModelPayload {
139 using Parent = TypedEntityRenderer<RenderableModelEntityItem>;
140 friend class EntityRenderer;
144 ModelEntityRenderer(
const EntityItemPointer& entity);
145 virtual scriptable::ScriptableModelBase getScriptableModel()
override;
146 virtual bool canReplaceModelMeshPart(
int meshIndex,
int partIndex)
override;
147 virtual bool replaceScriptableModelMeshPart(scriptable::ScriptableModelBasePointer model,
int meshIndex,
int partIndex)
override;
149 void addMaterial(graphics::MaterialLayer material,
const std::string& parentMaterialName)
override;
150 void removeMaterial(graphics::MaterialPointer material,
const std::string& parentMaterialName)
override;
153 bool isFading()
const override {
return false; }
156 virtual void removeFromScene(
const ScenePointer& scene, Transaction& transaction)
override;
157 virtual void onRemoveFromSceneTyped(
const TypedEntityPointer& entity)
override;
159 void setKey(
bool didVisualGeometryRequestSucceed,
const ModelPointer& model);
160 virtual ItemKey getKey()
override;
161 virtual uint32_t metaFetchMetaSubItems(ItemIDs& subItems)
const override;
162 virtual void handleBlendedVertices(
int blendshapeNumber,
const QVector<BlendshapeOffset>& blendshapeOffsets,
163 const QVector<int>& blendedMeshSizes,
const render::ItemIDs& subItemIDs)
override;
165 virtual bool needsRenderUpdateFromTypedEntity(
const TypedEntityPointer& entity)
const override;
166 virtual void doRenderUpdateSynchronousTyped(
const ScenePointer& scene, Transaction& transaction,
const TypedEntityPointer& entity)
override;
167 virtual void doRenderUpdateAsynchronousTyped(
const TypedEntityPointer& entity)
override;
168 virtual void doRender(RenderArgs* args)
override;
170 void setIsVisibleInSecondaryCamera(
bool value)
override;
171 void setRenderLayer(RenderLayer value)
override;
172 void setCullWithParent(
bool value)
override;
175 void animate(
const TypedEntityPointer& entity,
const ModelPointer& model);
176 void mapJoints(
const TypedEntityPointer& entity,
const ModelPointer& model);
179 virtual bool isTransparent()
const override {
return false; }
181 bool _hasModel {
false };
184 bool _texturesLoaded {
false };
185 int _lastKnownCurrentFrame { -1 };
186 #ifdef MODEL_ENTITY_USE_FADE_EFFECT
187 bool _hasTransitioned{
false };
190 QUrl _parsedModelURL;
191 bool _jointMappingCompleted {
false };
192 QVector<int> _jointMapping;
193 AnimationPointer _animation;
194 QString _animationURL;
195 uint64_t _lastAnimated { 0 };
197 render::ItemKey _itemKey { render::ItemKey::Builder().withTypeMeta() };
199 bool _didLastVisualGeometryRequestSucceed {
true };
201 void processMaterials();
202 bool _allProceduralMaterialsLoaded {
false };
204 static void metaBlendshapeOperator(render::ItemID renderItemID,
int blendshapeNumber,
const QVector<BlendshapeOffset>& blendshapeOffsets,
205 const QVector<int>& blendedMeshSizes,
const render::ItemIDs& subItemIDs);
Abstract ID for editing model items. Used in EntityItem JS API.
Definition: EntityItemID.h:28
Definition: EntityItemProperties.h:106
A generic 3D model displaying geometry loaded from a URL.
Definition: Model.h:84