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;
35 class ModelEntityWrapper :
public ModelEntityItem {
36 using Parent = ModelEntityItem;
37 friend class render::entities::ModelEntityRenderer;
40 ModelEntityWrapper(
const EntityItemID& entityItemID) : Parent(entityItemID) {}
41 void setModel(
const ModelPointer& model);
42 ModelPointer getModel()
const;
44 bool _needsInitialSimulation {
true };
49 class RenderableModelEntityItem :
public ModelEntityWrapper {
52 friend class render::entities::ModelEntityRenderer;
53 using Parent = ModelEntityWrapper;
55 static EntityItemPointer factory(
const EntityItemID& entityID,
const EntityItemProperties& properties);
57 RenderableModelEntityItem(
const EntityItemID& entityItemID,
bool dimensionsInitialized);
58 virtual ~RenderableModelEntityItem();
60 virtual void setUnscaledDimensions(
const glm::vec3& value)
override;
62 virtual EntityItemProperties getProperties(
const EntityPropertyFlags& desiredProperties,
bool allowEmptyDesiredProperties)
const override;
63 void updateModelBounds();
65 glm::vec3 getPivot()
const override;
66 virtual bool supportsDetailedIntersection()
const override;
67 virtual bool findDetailedRayIntersection(
const glm::vec3& origin,
const glm::vec3& direction,
68 const glm::vec3& viewFrustumPos, OctreeElementPointer& element,
float& distance,
69 BoxFace& face, glm::vec3& surfaceNormal,
70 QVariantMap& extraInfo,
bool precisionPicking)
const override;
71 virtual bool findDetailedParabolaIntersection(
const glm::vec3& origin,
const glm::vec3& velocity,
72 const glm::vec3& acceleration,
const glm::vec3& viewFrustumPos, OctreeElementPointer& element,
73 float& parabolicDistance, BoxFace& face, glm::vec3& surfaceNormal,
74 QVariantMap& extraInfo,
bool precisionPicking)
const override;
76 virtual void setShapeType(ShapeType type)
override;
77 virtual void setCompoundShapeURL(
const QString& url)
override;
78 virtual void setModelURL(
const QString& url)
override;
80 virtual bool isReadyToComputeShape()
const override;
81 virtual void computeShapeInfo(ShapeInfo& shapeInfo)
override;
82 bool unableToLoadCollisionShape();
84 virtual bool contains(
const glm::vec3& point)
const override;
85 void stopModelOverrideIfNoParent();
87 virtual bool shouldBePhysical()
const override;
88 void simulateRelayedJoints();
89 bool getJointMapCompleted();
90 void setJointMap(std::vector<int> jointMap);
91 int avatarJointIndex(
int modelJointIndex);
92 void setOverrideTransform(
const Transform& transform,
const glm::vec3& offset);
95 virtual glm::quat getAbsoluteJointRotationInObjectFrame(
int index)
const override;
96 virtual glm::vec3 getAbsoluteJointTranslationInObjectFrame(
int index)
const override;
97 virtual int getJointParent(
int index)
const override;
98 virtual bool setAbsoluteJointRotationInObjectFrame(
int index,
const glm::quat& rotation)
override;
99 virtual bool setAbsoluteJointTranslationInObjectFrame(
int index,
const glm::vec3& translation)
override;
101 virtual glm::quat getLocalJointRotation(
int index)
const override;
102 virtual glm::vec3 getLocalJointTranslation(
int index)
const override;
103 virtual bool setLocalJointRotation(
int index,
const glm::quat& rotation)
override;
104 virtual bool setLocalJointTranslation(
int index,
const glm::vec3& translation)
override;
106 virtual void setJointRotations(
const QVector<glm::quat>& rotations)
override;
107 virtual void setJointRotationsSet(
const QVector<bool>& rotationsSet)
override;
108 virtual void setJointTranslations(
const QVector<glm::vec3>& translations)
override;
109 virtual void setJointTranslationsSet(
const QVector<bool>& translationsSet)
override;
111 virtual void locationChanged(
bool tellPhysics =
true,
bool tellChildren =
true)
override;
113 virtual int getJointIndex(
const QString& name)
const override;
114 virtual QStringList getJointNames()
const override;
117 bool needsUpdateModelBounds()
const;
118 void autoResizeJointArrays();
119 void copyAnimationJointDataToModel();
120 bool readyToAnimate()
const;
121 void fetchCollisionGeometryResource();
123 QString getCollisionShapeURL()
const;
125 GeometryResource::Pointer _collisionGeometryResource;
126 std::vector<int> _jointMap;
127 QVariantMap _originalTextures;
128 bool _jointMapCompleted {
false };
129 bool _originalTexturesRead {
false };
130 bool _dimensionsInitialized {
true };
131 bool _needsJointSimulation {
false };
132 bool _needsToRescaleModel {
false };
135 namespace render {
namespace entities {
137 class ModelEntityRenderer :
public TypedEntityRenderer<RenderableModelEntityItem>,
public MetaModelPayload {
138 using Parent = TypedEntityRenderer<RenderableModelEntityItem>;
139 friend class EntityRenderer;
143 ModelEntityRenderer(
const EntityItemPointer& entity);
144 virtual scriptable::ScriptableModelBase getScriptableModel()
override;
145 virtual bool canReplaceModelMeshPart(
int meshIndex,
int partIndex)
override;
146 virtual bool replaceScriptableModelMeshPart(scriptable::ScriptableModelBasePointer model,
int meshIndex,
int partIndex)
override;
148 void addMaterial(graphics::MaterialLayer material,
const std::string& parentMaterialName)
override;
149 void removeMaterial(graphics::MaterialPointer material,
const std::string& parentMaterialName)
override;
151 void fade(render::Transaction& transaction, TransitionType type)
override;
154 virtual void removeFromScene(
const ScenePointer& scene, Transaction& transaction)
override;
155 virtual void onRemoveFromSceneTyped(
const TypedEntityPointer& entity)
override;
157 void setKey(
bool didVisualGeometryRequestSucceed,
const ModelPointer& model);
158 virtual ItemKey getKey()
override;
159 virtual uint32_t metaFetchMetaSubItems(ItemIDs& subItems)
const override;
160 virtual void handleBlendedVertices(
int blendshapeNumber,
const QVector<BlendshapeOffset>& blendshapeOffsets,
161 const QVector<int>& blendedMeshSizes,
const render::ItemIDs& subItemIDs)
override;
163 virtual bool needsRenderUpdateFromTypedEntity(
const TypedEntityPointer& entity)
const override;
164 virtual void doRenderUpdateSynchronousTyped(
const ScenePointer& scene, Transaction& transaction,
const TypedEntityPointer& entity)
override;
165 virtual void doRenderUpdateAsynchronousTyped(
const TypedEntityPointer& entity)
override;
166 virtual void doRender(RenderArgs* args)
override;
168 void setIsVisibleInSecondaryCamera(
bool value)
override;
169 void setRenderLayer(RenderLayer value)
override;
170 void setCullWithParent(
bool value)
override;
171 void setMirrorMode(MirrorMode value)
override;
172 void setPortalExitID(
const QUuid& value)
override;
175 void animate(
const TypedEntityPointer& entity,
const ModelPointer& model);
176 void updateJointData(
const QVector<glm::vec3>& translations,
const QVector<glm::quat>& rotations,
const TypedEntityPointer& entity,
const ModelPointer& model);
177 void mapJoints(
const TypedEntityPointer& entity,
const ModelPointer& model);
180 virtual bool isTransparent()
const override {
return false; }
182 bool _hasModel {
false };
185 bool _texturesLoaded {
false };
186 int _lastKnownCurrentIntegerFrame { -1 };
188 QUrl _parsedModelURL;
189 bool _jointMappingCompleted {
false };
190 QVector<int> _jointMapping;
191 AnimationPointer _animation;
192 QString _animationURL;
193 uint64_t _lastAnimated { 0 };
195 render::ItemKey _itemKey { render::ItemKey::Builder().withTypeMeta() };
197 bool _didLastVisualGeometryRequestSucceed {
true };
199 void processMaterials();
200 bool _allProceduralMaterialsLoaded {
false };
202 static void metaBlendshapeOperator(render::ItemID renderItemID,
int blendshapeNumber,
const QVector<BlendshapeOffset>& blendshapeOffsets,
203 const QVector<int>& blendedMeshSizes,
const render::ItemIDs& subItemIDs);
Abstract ID for editing model items. Used in EntityItem JS API.
Definition: EntityItemID.h:28
A generic 3D model displaying geometry loaded from a URL.
Definition: Model.h:85