// // ModelEntityItem.h // libraries/entities/src // // Created by Brad Hefta-Gaub on 12/4/13. // Copyright 2013 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #ifndef hifi_ModelEntityItem_h #define hifi_ModelEntityItem_h #include "EntityItem.h" #include #include #include "AnimationPropertyGroup.h" class ModelEntityItem : public EntityItem { public: static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties); ModelEntityItem(const EntityItemID& entityItemID); ALLOW_INSTANTIATION // This class can be instantiated // methods for getting/setting all properties of an entity virtual EntityItemProperties getProperties(const EntityPropertyFlags& desiredProperties, bool allowEmptyDesiredProperties) const override; virtual bool setProperties(const EntityItemProperties& properties) override; virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const override; virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData, EntityPropertyFlags& requestedProperties, EntityPropertyFlags& propertyFlags, EntityPropertyFlags& propertiesDidntFit, int& propertyCount, OctreeElement::AppendState& appendState) const override; virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args, EntityPropertyFlags& propertyFlags, bool overwriteLocalData, bool& somethingChanged) override; virtual void update(const quint64& now) override; bool needsToCallUpdate() const override { return isAnimatingSomething(); } virtual void debugDump() const override; void setShapeType(ShapeType type) override; virtual ShapeType getShapeType() const override; // TODO: Move these to subclasses, or other appropriate abstraction // getters/setters applicable to models and particles glm::u8vec3 getColor() const; void setColor(const glm::u8vec3& value); bool hasModel() const; virtual bool hasCompoundShapeURL() const; static const QString DEFAULT_MODEL_URL; QString getModelURL() const; virtual glm::vec3 getScaledDimensions() const override; virtual void setScaledDimensions(const glm::vec3& value) override; virtual const Transform getTransform(bool& success, int depth = 0) const override; virtual const Transform getTransform() const override; static const QString DEFAULT_COMPOUND_SHAPE_URL; QString getCompoundShapeURL() const; // Returns the URL used for the collision shape QString getCollisionShapeURL() const; // model related properties virtual void setModelURL(const QString& url); virtual void setCompoundShapeURL(const QString& url); // Animation related items... AnimationPropertyGroup getAnimationProperties() const; // TODO: audit and remove unused Animation accessors bool hasAnimation() const; QString getAnimationURL() const; virtual void setAnimationURL(const QString& url); void setAnimationCurrentFrame(float value); void setAnimationIsPlaying(bool value); void setAnimationFPS(float value); void setAnimationAllowTranslation(bool value); bool getAnimationAllowTranslation() const; void setAnimationLoop(bool loop); bool getAnimationLoop() const; void setAnimationHold(bool hold); bool getAnimationHold() const; void setRelayParentJoints(bool relayJoints); bool getRelayParentJoints() const; void setGroupCulled(bool value); bool getGroupCulled() const; bool getAnimationIsPlaying() const; float getAnimationCurrentFrame() const; float getAnimationFPS() const; bool isAnimatingSomething() const; static const QString DEFAULT_TEXTURES; const QString getTextures() const; void setTextures(const QString& textures); virtual void setJointRotations(const QVector& rotations); virtual void setJointRotationsSet(const QVector& rotationsSet); virtual void setJointTranslations(const QVector& translations); virtual void setJointTranslationsSet(const QVector& translationsSet); virtual void setAnimationJointsData(const QVector& jointsData); QVector getJointRotations() const; QVector getJointRotationsSet() const; QVector getJointTranslations() const; QVector getJointTranslationsSet() const; glm::vec3 getModelScale() const; void setModelScale(const glm::vec3& modelScale); private: void setAnimationSettings(const QString& value); // only called for old bitstream format bool applyNewAnimationProperties(AnimationPropertyGroup newProperties); ShapeType computeTrueShapeType() const; protected: void resizeJointArrays(int newSize); // these are used: // - to bounce joint data from an animation into the model/rig. // - to relay changes from scripts to model/rig. // - to relay between network and model/rig // they aren't currently updated from data in the model/rig, and they don't have a direct effect // on what's rendered. ReadWriteLockable _jointDataLock; bool _jointRotationsExplicitlySet { false }; // were the joints set as a property or just side effect of animations bool _jointTranslationsExplicitlySet{ false }; // were the joints set as a property or just side effect of animations struct ModelJointData { EntityJointData joint; bool rotationDirty { false }; bool translationDirty { false }; }; QVector _localJointData; int _lastKnownCurrentFrame{-1}; glm::u8vec3 _color; glm::vec3 _modelScale { 1.0f }; QString _modelURL; bool _relayParentJoints; bool _groupCulled { false }; ThreadSafeValueCache _compoundShapeURL; AnimationPropertyGroup _animationProperties; QString _textures; ShapeType _shapeType { SHAPE_TYPE_NONE }; private: uint64_t _lastAnimated{ 0 }; float _currentFrame{ -1.0f }; }; #endif // hifi_ModelEntityItem_h