From 988ecf9d5503fd184d4e6c652da990fcdb2b397a Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 13:18:52 -0700 Subject: [PATCH] send PolyVox voxel dimensions and compressed data over the wire --- .../src/RenderablePolyVoxEntityItem.cpp | 10 ------ .../entities/src/EntityItemProperties.cpp | 4 +++ libraries/entities/src/EntityItemProperties.h | 4 +++ libraries/entities/src/EntityPropertyFlags.h | 3 ++ libraries/entities/src/PolyVoxEntityItem.cpp | 32 +++++++++++++------ libraries/entities/src/PolyVoxEntityItem.h | 12 +++++-- 6 files changed, 44 insertions(+), 21 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index c998e2dbc6..29d8c6ebf3 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -126,19 +126,9 @@ void RenderablePolyVoxEntityItem::getModel() { setVoxelVolumeSize(_voxelVolumeSize); } - // glm::vec3 center(_volData->getDepth() / 2.0f, - // _volData->getHeight() / 2.0f, - // _volData->getWidth() / 2.0f); - // createSphereInVolume(center, 15); - // createSphereInVolume(center + glm::vec3(8.0f, 0.0f, 0.0f), 15); - // eraseSphereInVolume(center + glm::vec3(4.0f, 0.0f, 4.0f), 15); - - glm::vec3 center = getCenter(); createSphere(center, 4); createSphere(center + glm::vec3(6.0f, 0.0f, 0.0f), 2); - // eraseSphere(center + glm::vec3(0.5f, 0.0f, 4.0f), 0.8); - // A mesh object to hold the result of surface extraction PolyVox::SurfaceMesh polyVoxMesh; diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 905fa7d104..07df72656b 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -26,6 +26,7 @@ #include "ParticleEffectEntityItem.h" #include "TextEntityItem.h" #include "ZoneEntityItem.h" +#include "PolyVoxEntityItem.h" AtmospherePropertyGroup EntityItemProperties::_staticAtmosphere; SkyboxPropertyGroup EntityItemProperties::_staticSkybox; @@ -90,6 +91,9 @@ CONSTRUCT_PROPERTY(keyLightDirection, ZoneEntityItem::DEFAULT_KEYLIGHT_DIRECTION CONSTRUCT_PROPERTY(name, ENTITY_ITEM_DEFAULT_NAME), CONSTRUCT_PROPERTY(backgroundMode, BACKGROUND_MODE_INHERIT), CONSTRUCT_PROPERTY(sourceUrl, ""), +CONSTRUCT_PROPERTY(voxelVolumeSize, PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE), +CONSTRUCT_PROPERTY(voxelData, PolyVoxEntityItem::DEFAULT_VOXEL_DATA), + _id(UNKNOWN_ENTITY_ID), _idSet(false), diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 827a48f632..72b4e4ad0b 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -142,6 +142,8 @@ public: DEFINE_PROPERTY_GROUP(Atmosphere, atmosphere, AtmospherePropertyGroup); DEFINE_PROPERTY_GROUP(Skybox, skybox, SkyboxPropertyGroup); DEFINE_PROPERTY_REF(PROP_SOURCE_URL, SourceUrl, sourceUrl, QString); + DEFINE_PROPERTY_REF(PROP_VOXEL_VOLUME_SIZE, VoxelVolumeSize, voxelVolumeSize, glm::vec3); + DEFINE_PROPERTY_REF(PROP_VOXEL_DATA, VoxelData, voxelData, QByteArray); static QString getBackgroundModeString(BackgroundMode mode); @@ -282,6 +284,8 @@ inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) { DEBUG_PROPERTY_IF_CHANGED(debug, properties, ParticleRadius, particleRadius, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, MarketplaceID, marketplaceID, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, BackgroundMode, backgroundMode, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelVolumeSize, voxelVolumeSize, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelData, voxelData, ""); properties.getStage().debugDump(); properties.getAtmosphere().debugDump(); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 8a5d96e8d2..eb5cb1a0ae 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -110,6 +110,9 @@ enum EntityPropertyList { PROP_RESTITUTION, PROP_FRICTION, + PROP_VOXEL_VOLUME_SIZE, + PROP_VOXEL_DATA, + //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties ABOVE this line PROP_AFTER_LAST_ITEM, diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index f094d83af1..71f1c2fb65 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -10,6 +10,7 @@ // +#include #include #include @@ -20,17 +21,19 @@ #include "EntityTreeElement.h" +const glm::vec3 PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE = glm::vec3(32, 32, 32); +const QByteArray PolyVoxEntityItem::DEFAULT_VOXEL_DATA(qCompress(QByteArray(0), 9)); + EntityItem* PolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { - qDebug() << "XXXXXXXXXXXX XXXXXXXXXXXX making PolyVoxEntityItem entity"; EntityItem* result = new PolyVoxEntityItem(entityID, properties); return result; } PolyVoxEntityItem::PolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : - EntityItem(entityItemID) + EntityItem(entityItemID), + _voxelVolumeSize(PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE), + _voxelData(PolyVoxEntityItem::DEFAULT_VOXEL_DATA) { - qDebug() << "XXXXXXXXXXXX XXXXXXXXXXXX making PolyVoxEntityItem entity"; - _type = EntityTypes::PolyVox; _created = properties.getCreated(); setProperties(properties); @@ -39,11 +42,14 @@ PolyVoxEntityItem::PolyVoxEntityItem(const EntityItemID& entityItemID, const Ent EntityItemProperties PolyVoxEntityItem::getProperties() const { EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class - properties._color = getXColor(); - properties._colorChanged = false; + // properties._color = getXColor(); + // properties._colorChanged = false; + // properties._glowLevel = getGlowLevel(); + // properties._glowLevelChanged = false; - properties._glowLevel = getGlowLevel(); - properties._glowLevelChanged = false; + COPY_ENTITY_PROPERTY_TO_PROPERTIES(color, getXColor); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(voxelVolumeSize, getVoxelVolumeSize); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(voxelData, getVoxelData); return properties; } @@ -52,7 +58,9 @@ bool PolyVoxEntityItem::setProperties(const EntityItemProperties& properties) { bool somethingChanged = false; somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class - SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setXColor); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelVolumeSize, setVoxelVolumeSize); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelData, setVoxelData); if (somethingChanged) { bool wantDebug = false; @@ -75,6 +83,8 @@ int PolyVoxEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* dat const unsigned char* dataAt = data; READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor); + READ_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, glm::vec3, setVoxelVolumeSize); + READ_ENTITY_PROPERTY(PROP_VOXEL_DATA, QByteArray, setVoxelData); return bytesRead; } @@ -84,6 +94,8 @@ int PolyVoxEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* dat EntityPropertyFlags PolyVoxEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); requestedProperties += PROP_COLOR; + requestedProperties += PROP_VOXEL_VOLUME_SIZE; + requestedProperties += PROP_VOXEL_DATA; return requestedProperties; } @@ -98,6 +110,8 @@ void PolyVoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeB bool successPropertyFits = true; APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); + APPEND_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, getVoxelVolumeSize()); + APPEND_ENTITY_PROPERTY(PROP_VOXEL_DATA, getVoxelData()); } void PolyVoxEntityItem::debugDump() const { diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 35071b4d88..387bb86225 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -45,7 +45,7 @@ class PolyVoxEntityItem : public EntityItem { xColor getXColor() const { xColor color = { _color[RED_INDEX], _color[GREEN_INDEX], _color[BLUE_INDEX] }; return color; } void setColor(const rgbColor& value) { memcpy(_color, value, sizeof(_color)); } - void setColor(const xColor& value) { + void setXColor(const xColor& value) { _color[RED_INDEX] = value.red; _color[GREEN_INDEX] = value.green; _color[BLUE_INDEX] = value.blue; @@ -62,10 +62,18 @@ class PolyVoxEntityItem : public EntityItem { virtual void debugDump() const; virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize) { _voxelVolumeSize = voxelVolumeSize; } + virtual const glm::vec3& getVoxelVolumeSize() const { return _voxelVolumeSize; } + + virtual void setVoxelData(QByteArray voxelData) { _voxelData = voxelData; } + virtual const QByteArray& getVoxelData() const { return _voxelData; } + + static const glm::vec3 DEFAULT_VOXEL_VOLUME_SIZE; + static const QByteArray DEFAULT_VOXEL_DATA; protected: rgbColor _color; - glm::vec3 _voxelVolumeSize = glm::vec3(64, 64, 64); + glm::vec3 _voxelVolumeSize; // this is always 3 bytes + QByteArray _voxelData; }; #endif // hifi_PolyVoxEntityItem_h