// // EntityTypes.h // libraries/entities/src // // Created by Brad Hefta-Gaub on December 4th, 2013. // Copyright 2013 High Fidelity, Inc. // Copyright 2023-2025 Overte e.V. // // 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_EntityTypes_h #define hifi_EntityTypes_h #include #include #include #include "EntitiesLogging.h" class EntityItem; using EntityItemPointer = std::shared_ptr; using EntityItemWeakPointer = std::weak_ptr; inline uint qHash(const EntityItemPointer& a, uint seed) { return qHash(a.get(), seed); } class EntityItemID; class EntityItemProperties; class ReadBitstreamToTreeParams; typedef EntityItemPointer (*EntityTypeFactory)(const EntityItemID& entityID, const EntityItemProperties& properties); class EntityTypes { public: /*@jsdoc *

An entity may be one of the following types:

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ValueDescriptionProperties
"Shape"A basic entity such as a cube. * See also, the "Box" and "Sphere" entity types.{@link Entities.EntityProperties-Shape|EntityProperties-Shape}
"Box"A rectangular prism. This is a synonym of "Shape" for the case * where the entity's shape property value is "Cube". *

If an entity is created with its type * set to "Box" it will always be created with a shape property value of * "Cube". If an entity of type Shape or Sphere has its shape set * to "Cube" then its type will be reported as "Box".

{@link Entities.EntityProperties-Box|EntityProperties-Box}
"Sphere"A sphere. This is a synonym of "Shape" for the case * where the entity's shape property value is "Sphere". *

If an entity is created with its type * set to "Sphere" it will always be created with a shape property value of * "Sphere". If an entity of type Box or Shape has its shape set * to "Sphere" then its type will be reported as "Sphere".

{@link Entities.EntityProperties-Sphere|EntityProperties-Sphere}
"Model"A mesh model from a glTF, VRM, FBX, or OBJ file.{@link Entities.EntityProperties-Model|EntityProperties-Model}
"Text"A pane of text oriented in space.{@link Entities.EntityProperties-Text|EntityProperties-Text}
"Image"An image oriented in space.{@link Entities.EntityProperties-Image|EntityProperties-Image}
"Web"A browsable web page.{@link Entities.EntityProperties-Web|EntityProperties-Web}
"ParticleEffect"A particle system that can be used to simulate things such as fire, * smoke, snow, magic spells, etc.{@link Entities.EntityProperties-ParticleEffect|EntityProperties-ParticleEffect}
"ProceduralParticleEffect"A GPU particle system with custom update and rendering that can * be used to simulate things such as fire, smoke, snow, magic spells, etc.{@link Entities.EntityProperties-ProceduralParticleEffect|EntityProperties-ProceduralParticleEffect}
"Line"A sequence of one or more simple straight lines.{@link Entities.EntityProperties-Line|EntityProperties-Line}
"PolyLine"A sequence of one or more textured straight lines.{@link Entities.EntityProperties-PolyLine|EntityProperties-PolyLine}
"PolyVox"A set of textured voxels.{@link Entities.EntityProperties-PolyVox|EntityProperties-PolyVox}
"Grid"A grid of lines in a plane.{@link Entities.EntityProperties-Grid|EntityProperties-Grid}
"Gizmo"A gizmo intended for UI.{@link Entities.EntityProperties-Gizmo|EntityProperties-Gizmo}
"Light"A local lighting effect.{@link Entities.EntityProperties-Light|EntityProperties-Light}
"Zone"A volume of lighting effects and avatar permissions.{@link Entities.EntityProperties-Zone|EntityProperties-Zone}
"Material"Modifies the existing materials on entities and avatars.{@link Entities.EntityProperties-Material|EntityProperties-Material}
"Sound"Plays a sound.{@link Entities.EntityProperties-Sound|EntityProperties-Sound}
"Canvas"A runtime scriptable image.{@link Entities.EntityProperties-Canvas|EntityProperties-Canvas}
"Empty"Invisible, intangible entity that has no special behavior.{@link Entities.EntityProperties-Empty|EntityProperties-Empty}
"Script"Starts an entity script on its parent.{@link Entities.EntityProperties-Script|EntityProperties-Script}
* @typedef {string} Entities.EntityType */ typedef enum EntityType_t { Unknown, Box, Sphere, Shape, Model, Text, Image, Web, ParticleEffect, ProceduralParticleEffect, Line, PolyLine, PolyVox, Grid, Gizmo, Light, Zone, Material, Sound, Canvas, Empty, Script, NUM_TYPES } EntityType; static bool typeIsValid(EntityType type); static const QString& getEntityTypeName(EntityType entityType); static EntityTypes::EntityType getEntityTypeFromName(const QString& name); static bool registerEntityType(EntityType entityType, const char* name, EntityTypeFactory factoryMethod); static void extractEntityTypeAndID(const unsigned char* data, int dataLength, EntityTypes::EntityType& typeOut, QUuid& idOut); static EntityItemPointer constructEntityItem(EntityType entityType, const EntityItemID& entityID, const EntityItemProperties& properties); static EntityItemPointer constructEntityItem(const unsigned char* data, int bytesToRead); static EntityItemPointer constructEntityItem(const QUuid& id, const EntityItemProperties& properties); private: static QMap _typeToNameMap; static QMap _nameToTypeMap; static EntityTypeFactory _factories[NUM_TYPES]; static bool _factoriesInitialized; }; /// Macro for registering entity types. Make sure to add an element to the EntityType enum with your name, and your class should be /// named NameEntityItem and must of a static method called factory that takes an EnityItemID, and EntityItemProperties and return a newly /// constructed (heap allocated) instance of your type. e.g. The following prototype: // static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties); #define REGISTER_ENTITY_TYPE(x) bool x##Registration = \ EntityTypes::registerEntityType(EntityTypes::x, #x, x##EntityItem::factory); struct EntityRegistrationChecker { EntityRegistrationChecker(bool result, const char* debugMessage) { if (!result) { qCDebug(entities) << debugMessage; } } }; /// Macro for registering entity types with an overloaded factory. Like using the REGISTER_ENTITY_TYPE macro: Make sure to add /// an element to the EntityType enum with your name. But unlike REGISTER_ENTITY_TYPE, your class can be named anything /// so long as you provide a static method passed to the macro, that takes an EnityItemID, and EntityItemProperties and /// returns a newly constructed (heap allocated) instance of your type. e.g. The following prototype: // static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties); #define REGISTER_ENTITY_TYPE_WITH_FACTORY(x,y) static bool x##Registration = \ EntityTypes::registerEntityType(EntityTypes::x, #x, y); \ EntityRegistrationChecker x##RegistrationChecker( \ x##Registration, \ "UNEXPECTED: REGISTER_ENTITY_TYPE_WITH_FACTORY(" #x "," #y ") FAILED.!"); #endif // hifi_EntityTypes_h