mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 05:17:02 +02:00
first cut at registered EntityType renderers
This commit is contained in:
parent
50309ef371
commit
a194db837f
3 changed files with 102 additions and 86 deletions
|
@ -45,7 +45,37 @@ void EntityTreeRenderer::clearModelsCache() {
|
||||||
_unknownEntityItemModels.clear();
|
_unknownEntityItemModels.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ModelEntityItemRenderer {
|
||||||
|
public:
|
||||||
|
static void render(EntityItem* entity) {
|
||||||
|
glm::vec3 position = entity->getPosition() * (float)TREE_SCALE;
|
||||||
|
float radius = entity->getRadius() * (float)TREE_SCALE;
|
||||||
|
glColor3f(1.0f, 0.0f, 0.0f);
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(position.x, position.y, position.z);
|
||||||
|
glutSolidSphere(radius, 15, 15);
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class BoxEntityItemRenderer {
|
||||||
|
public:
|
||||||
|
static void render(EntityItem* entity) {
|
||||||
|
glm::vec3 position = entity->getPosition() * (float)TREE_SCALE;
|
||||||
|
float size = entity->getSize() * (float)TREE_SCALE;
|
||||||
|
glColor3f(0.0f, 1.0f, 0.0f);
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(position.x, position.y, position.z);
|
||||||
|
glutSolidCube(size);
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
void EntityTreeRenderer::init() {
|
void EntityTreeRenderer::init() {
|
||||||
|
REGISTER_ENTITY_TYPE_RENDERER(Model)
|
||||||
|
REGISTER_ENTITY_TYPE_RENDERER(Box)
|
||||||
|
|
||||||
OctreeRenderer::init();
|
OctreeRenderer::init();
|
||||||
static_cast<EntityTree*>(_tree)->setFBXService(this);
|
static_cast<EntityTree*>(_tree)->setFBXService(this);
|
||||||
}
|
}
|
||||||
|
@ -373,21 +403,7 @@ void EntityTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args)
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
//glColor3ub(entityItem->getColor()[RED_INDEX],entityItem->getColor()[GREEN_INDEX],entityItem.getColor()[BLUE_INDEX]);
|
EntityTypes::renderEntityItem(entityItem);
|
||||||
|
|
||||||
EntityTypes::EntityType_t type = entityItem->getType();
|
|
||||||
|
|
||||||
//qDebug() << "rendering type=" << type;
|
|
||||||
|
|
||||||
if (type == EntityTypes::Model) {
|
|
||||||
glColor3f(1.0f, 0.0f, 0.0f);
|
|
||||||
} else {
|
|
||||||
glColor3f(0.0f, 1.0f, 0.0f);
|
|
||||||
}
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef(position.x, position.y, position.z);
|
|
||||||
glutSolidSphere(radius, 15, 15);
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
args->_itemsOutOfView++;
|
args->_itemsOutOfView++;
|
||||||
|
@ -407,3 +423,8 @@ int EntityTreeRenderer::getBoundaryLevelAdjust() const {
|
||||||
void EntityTreeRenderer::processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) {
|
void EntityTreeRenderer::processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) {
|
||||||
static_cast<EntityTree*>(_tree)->processEraseMessage(dataByteArray, sourceNode);
|
static_cast<EntityTree*>(_tree)->processEraseMessage(dataByteArray, sourceNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,11 @@
|
||||||
#include "BoxEntityItem.h"
|
#include "BoxEntityItem.h"
|
||||||
#include "ModelEntityItem.h"
|
#include "ModelEntityItem.h"
|
||||||
|
|
||||||
|
QMap<EntityTypes::EntityType_t, QString> EntityTypes::_typeToNameMap;
|
||||||
QMap<EntityTypes::EntityType_t, QString> EntityTypes::_typeNameHash;
|
QMap<QString, EntityTypes::EntityType_t> EntityTypes::_nameToTypeMap;
|
||||||
QMap<QString, EntityTypes::EntityType_t> EntityTypes::_nameTypeHash;
|
QMap<EntityTypes::EntityType_t, EntityTypeFactory> EntityTypes::_typeToFactoryMap;
|
||||||
QMap<EntityTypes::EntityType_t, EntityTypeFactory> EntityTypes::_typeFactoryHash;
|
EntityTypeRenderer EntityTypes::_renderers[EntityTypes::LAST];
|
||||||
|
bool EntityTypes::_renderersInitialized = false;
|
||||||
|
|
||||||
const QString ENTITY_TYPE_NAME_UNKNOWN = "Unknown";
|
const QString ENTITY_TYPE_NAME_UNKNOWN = "Unknown";
|
||||||
|
|
||||||
|
@ -38,8 +39,19 @@ REGISTER_ENTITY_TYPE(Pyramid)
|
||||||
|
|
||||||
|
|
||||||
const QString& EntityTypes::getEntityTypeName(EntityType_t entityType) {
|
const QString& EntityTypes::getEntityTypeName(EntityType_t entityType) {
|
||||||
QMap<EntityType_t, QString>::iterator matchedTypeName = _typeNameHash.find(entityType);
|
QMap<EntityType_t, QString>::iterator matchedTypeName = _typeToNameMap.find(entityType);
|
||||||
return matchedTypeName != _typeNameHash.end() ? matchedTypeName.value() : ENTITY_TYPE_NAME_UNKNOWN;
|
if (matchedTypeName != _typeToNameMap.end()) {
|
||||||
|
return matchedTypeName.value();
|
||||||
|
}
|
||||||
|
return ENTITY_TYPE_NAME_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityTypes::EntityType_t EntityTypes::getEntityTypeFromName(const QString& name) {
|
||||||
|
QMap<QString, EntityTypes::EntityType_t>::iterator matchedTypeName = _nameToTypeMap.find(name);
|
||||||
|
if (matchedTypeName != _nameToTypeMap.end()) {
|
||||||
|
return matchedTypeName.value();
|
||||||
|
}
|
||||||
|
return Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityTypes::registerEntityType(EntityType_t entityType, const char* name, EntityTypeFactory factoryMethod) {
|
bool EntityTypes::registerEntityType(EntityType_t entityType, const char* name, EntityTypeFactory factoryMethod) {
|
||||||
|
@ -48,78 +60,25 @@ bool EntityTypes::registerEntityType(EntityType_t entityType, const char* name,
|
||||||
qDebug() << " name=" << name;
|
qDebug() << " name=" << name;
|
||||||
qDebug() << " factoryMethod=" << (void*)factoryMethod;
|
qDebug() << " factoryMethod=" << (void*)factoryMethod;
|
||||||
|
|
||||||
_typeNameHash[entityType] = name;
|
_typeToNameMap[entityType] = name;
|
||||||
_nameTypeHash[name] = entityType;
|
_nameToTypeMap[name] = entityType;
|
||||||
_typeFactoryHash[entityType] = factoryMethod;
|
_typeToFactoryMap[entityType] = factoryMethod;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityTypes::EntityType_t EntityTypes::getEntityTypeFromName(const QString& name) {
|
|
||||||
qDebug() << "EntityTypes::getEntityTypeFromName() name=" << name;
|
|
||||||
|
|
||||||
QMap<QString, EntityTypes::EntityType_t>::iterator matchedTypeName = _nameTypeHash.find(name);
|
|
||||||
if (matchedTypeName != _nameTypeHash.end()) {
|
|
||||||
qDebug() << "EntityTypes::getEntityTypeFromName() FOUND IT! type=" << matchedTypeName.value();
|
|
||||||
return matchedTypeName.value();
|
|
||||||
}
|
|
||||||
qDebug() << "EntityTypes::getEntityTypeFromName() COULDN'T FIND TYPE!! name=" << name;
|
|
||||||
return Unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityItem* EntityTypes::constructEntityItem(EntityType_t entityType, const EntityItemID& entityID, const EntityItemProperties& properties) {
|
EntityItem* EntityTypes::constructEntityItem(EntityType_t entityType, const EntityItemID& entityID, const EntityItemProperties& properties) {
|
||||||
|
|
||||||
qDebug() << "EntityTypes::constructEntityItem(EntityType_t entityType, const EntityItemID& entityID, const EntityItemProperties& properties)";
|
qDebug() << "EntityTypes::constructEntityItem(EntityType_t entityType, const EntityItemID& entityID, const EntityItemProperties& properties)";
|
||||||
qDebug() << " entityType=" << entityType;
|
qDebug() << " entityType=" << entityType;
|
||||||
qDebug() << " entityID=" << entityID;
|
qDebug() << " entityID=" << entityID;
|
||||||
//qDebug() << " properties=" << properties;
|
|
||||||
|
|
||||||
EntityItem* newEntityItem = NULL;
|
EntityItem* newEntityItem = NULL;
|
||||||
|
|
||||||
QMap<EntityTypes::EntityType_t, EntityTypeFactory>::iterator matchedType = _typeFactoryHash.find(entityType);
|
QMap<EntityTypes::EntityType_t, EntityTypeFactory>::iterator matchedType = _typeToFactoryMap.find(entityType);
|
||||||
if (matchedType != _typeFactoryHash.end()) {
|
if (matchedType != _typeToFactoryMap.end()) {
|
||||||
EntityTypeFactory factory = matchedType.value();
|
EntityTypeFactory factory = matchedType.value();
|
||||||
|
|
||||||
qDebug() << "ABOUT TO CALL FACTORY!!!!!";
|
|
||||||
newEntityItem = factory(entityID, properties);
|
newEntityItem = factory(entityID, properties);
|
||||||
qDebug() << "AFTER FACTORY!!!!!";
|
|
||||||
} else {
|
|
||||||
qDebug() << "UNABLE TO CALL FACTORY!!!!!";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
|
|
||||||
// switch statement for now, needs to support registration of constructor
|
|
||||||
switch (entityType) {
|
|
||||||
case Model:
|
|
||||||
newEntityItem = new ModelEntityItem(entityID, properties);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Box:
|
|
||||||
newEntityItem = new BoxEntityItem(entityID, properties);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Sphere:
|
|
||||||
newEntityItem = new SphereEntityItem(entityID, properties);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Plane:
|
|
||||||
newEntityItem = new PlaneEntityItem(entityID, properties);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Cylinder:
|
|
||||||
newEntityItem = new CylinderEntityItem(entityID, properties);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Pyramid:
|
|
||||||
newEntityItem = new PyramidEntityItem(entityID, properties);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
newEntityItem = new ModelEntityItem(entityID, properties);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
return newEntityItem;
|
return newEntityItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,4 +373,27 @@ qDebug() << "EntityItem::decodeEntityEditPacket() ... lastEdited=" << lastEdited
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EntityTypes::registerEntityTypeRenderer(EntityType_t entityType, EntityTypeRenderer renderMethod) {
|
||||||
|
qDebug() << "EntityTypes::registerEntityTypeRenderer()";
|
||||||
|
qDebug() << " entityType=" << entityType;
|
||||||
|
qDebug() << " renderMethod=" << (void*)renderMethod;
|
||||||
|
|
||||||
|
if (!_renderersInitialized) {
|
||||||
|
memset(&_renderers,0,sizeof(_renderers));
|
||||||
|
_renderersInitialized = true;
|
||||||
|
}
|
||||||
|
_renderers[entityType] = renderMethod;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityTypes::renderEntityItem(EntityItem* entityItem) {
|
||||||
|
EntityType_t entityType = entityItem->getType();
|
||||||
|
EntityTypeRenderer renderMethod = _renderers[entityType];
|
||||||
|
if (renderMethod) {
|
||||||
|
renderMethod(entityItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ class EntityItemProperties;
|
||||||
class ReadBitstreamToTreeParams;
|
class ReadBitstreamToTreeParams;
|
||||||
|
|
||||||
typedef EntityItem* (*EntityTypeFactory)(const EntityItemID& entityID, const EntityItemProperties& properties);
|
typedef EntityItem* (*EntityTypeFactory)(const EntityItemID& entityID, const EntityItemProperties& properties);
|
||||||
|
typedef void (*EntityTypeRenderer)(EntityItem* entity);
|
||||||
|
|
||||||
class EntityTypes {
|
class EntityTypes {
|
||||||
public:
|
public:
|
||||||
|
@ -33,21 +34,27 @@ public:
|
||||||
Sphere,
|
Sphere,
|
||||||
Plane,
|
Plane,
|
||||||
Cylinder,
|
Cylinder,
|
||||||
Pyramid
|
Pyramid,
|
||||||
|
LAST = Pyramid
|
||||||
} EntityType_t;
|
} EntityType_t;
|
||||||
|
|
||||||
static const QString& getEntityTypeName(EntityType_t entityType);
|
static const QString& getEntityTypeName(EntityType_t entityType);
|
||||||
static bool registerEntityType(EntityType_t entityType, const char* name, EntityTypeFactory factoryMethod);
|
|
||||||
static EntityTypes::EntityType_t getEntityTypeFromName(const QString& name);
|
static EntityTypes::EntityType_t getEntityTypeFromName(const QString& name);
|
||||||
|
static bool registerEntityType(EntityType_t entityType, const char* name, EntityTypeFactory factoryMethod);
|
||||||
static EntityItem* constructEntityItem(EntityType_t entityType, const EntityItemID& entityID, const EntityItemProperties& properties);
|
static EntityItem* constructEntityItem(EntityType_t entityType, const EntityItemID& entityID, const EntityItemProperties& properties);
|
||||||
static EntityItem* constructEntityItem(const unsigned char* data, int bytesToRead, ReadBitstreamToTreeParams& args);
|
static EntityItem* constructEntityItem(const unsigned char* data, int bytesToRead, ReadBitstreamToTreeParams& args);
|
||||||
static bool decodeEntityEditPacket(const unsigned char* data, int bytesToRead, int& processedBytes,
|
static bool decodeEntityEditPacket(const unsigned char* data, int bytesToRead, int& processedBytes,
|
||||||
EntityItemID& entityID, EntityItemProperties& properties);
|
EntityItemID& entityID, EntityItemProperties& properties);
|
||||||
|
|
||||||
|
static bool registerEntityTypeRenderer(EntityType_t entityType, EntityTypeRenderer renderMethod);
|
||||||
|
static void renderEntityItem(EntityItem* entityItem);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QMap<EntityType_t, QString> _typeNameHash;
|
static QMap<EntityType_t, QString> _typeToNameMap;
|
||||||
static QMap<QString, EntityTypes::EntityType_t> _nameTypeHash;
|
static QMap<QString, EntityTypes::EntityType_t> _nameToTypeMap;
|
||||||
static QMap<EntityType_t, EntityTypeFactory> _typeFactoryHash;
|
static QMap<EntityType_t, EntityTypeFactory> _typeToFactoryMap;
|
||||||
|
static EntityTypeRenderer _renderers[LAST];
|
||||||
|
static bool _renderersInitialized;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,7 +62,13 @@ private:
|
||||||
/// named NameEntityItem and must of a static method called factory that takes an EnityItemID, and EntityItemProperties and return a newly
|
/// 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:
|
/// constructed (heap allocated) instance of your type. e.g. The following prototype:
|
||||||
// static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
|
// static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
|
||||||
#define REGISTER_ENTITY_TYPE(x) static bool x##Registration = EntityTypes::registerEntityType(EntityTypes::x, #x, x##EntityItem::factory);
|
#define REGISTER_ENTITY_TYPE(x) static bool x##Registration = \
|
||||||
|
EntityTypes::registerEntityType(EntityTypes::x, #x, x##EntityItem::factory);
|
||||||
|
|
||||||
|
#define REGISTER_ENTITY_TYPE_RENDERER(x) static bool x##RendererRegistration = \
|
||||||
|
EntityTypes::registerEntityTypeRenderer(EntityTypes::x, x##EntityItemRenderer::render); \
|
||||||
|
x##RendererRegistration = x##RendererRegistration;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // hifi_EntityTypes_h
|
#endif // hifi_EntityTypes_h
|
||||||
|
|
Loading…
Reference in a new issue