Merge branch 'polyvox' of github.com:sethalves/hifi into polyvox

This commit is contained in:
Seth Alves 2015-05-26 14:12:11 -07:00
commit 28e052ffdb
9 changed files with 77 additions and 32 deletions

View file

@ -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<PolyVox::PositionMaterialNormal> polyVoxMesh;

View file

@ -183,9 +183,9 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
QByteArray encodedPropertyFlags;
int propertyCount = 0;
successIDFits = packetData->appendValue(encodedID);
successIDFits = packetData->appendRawData(encodedID);
if (successIDFits) {
successTypeFits = packetData->appendValue(encodedType);
successTypeFits = packetData->appendRawData(encodedType);
}
if (successTypeFits) {
successCreatedFits = packetData->appendValue(_created);
@ -194,17 +194,17 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
successLastEditedFits = packetData->appendValue(lastEdited);
}
if (successLastEditedFits) {
successLastUpdatedFits = packetData->appendValue(encodedUpdateDelta);
successLastUpdatedFits = packetData->appendRawData(encodedUpdateDelta);
}
if (successLastUpdatedFits) {
successLastSimulatedFits = packetData->appendValue(encodedSimulatedDelta);
successLastSimulatedFits = packetData->appendRawData(encodedSimulatedDelta);
}
if (successLastSimulatedFits) {
propertyFlagsOffset = packetData->getUncompressedByteOffset();
encodedPropertyFlags = propertyFlags;
oldPropertyFlagsLength = encodedPropertyFlags.length();
successPropertyFlagsFits = packetData->appendValue(encodedPropertyFlags);
successPropertyFlagsFits = packetData->appendRawData(encodedPropertyFlags);
}
bool headerFits = successIDFits && successTypeFits && successCreatedFits && successLastEditedFits

View file

@ -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),
@ -619,23 +623,23 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
quint64 lastEdited = properties.getLastEdited();
bool successLastEditedFits = packetData->appendValue(lastEdited);
bool successIDFits = packetData->appendValue(encodedID);
bool successIDFits = packetData->appendRawData(encodedID);
if (successIDFits) {
successIDFits = packetData->appendValue(encodedToken);
successIDFits = packetData->appendRawData(encodedToken);
}
bool successTypeFits = packetData->appendValue(encodedType);
bool successTypeFits = packetData->appendRawData(encodedType);
// NOTE: We intentionally do not send "created" times in edit messages. This is because:
// 1) if the edit is to an existing entity, the created time can not be changed
// 2) if the edit is to a new entity, the created time is the last edited time
// TODO: Should we get rid of this in this in edit packets, since this has to always be 0?
bool successLastUpdatedFits = packetData->appendValue(encodedUpdateDelta);
bool successLastUpdatedFits = packetData->appendRawData(encodedUpdateDelta);
int propertyFlagsOffset = packetData->getUncompressedByteOffset();
QByteArray encodedPropertyFlags = propertyFlags;
int oldPropertyFlagsLength = encodedPropertyFlags.length();
bool successPropertyFlagsFits = packetData->appendValue(encodedPropertyFlags);
bool successPropertyFlagsFits = packetData->appendRawData(encodedPropertyFlags);
int propertyCount = 0;
bool headerFits = successIDFits && successTypeFits && successLastEditedFits

View file

@ -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();

View file

@ -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,

View file

@ -10,6 +10,7 @@
//
#include <QByteArray>
#include <QDebug>
#include <ByteCountCoding.h>
@ -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 {

View file

@ -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

View file

@ -426,7 +426,12 @@ bool OctreePacketData::appendValue(const QUuid& uuid) {
}
bool OctreePacketData::appendValue(const QByteArray& bytes) {
bool success = appendRawData((const unsigned char*)bytes.constData(), bytes.size());
// TODO: make this a ByteCountCoded leading byte
uint16_t length = bytes.size();
bool success = appendValue(length);
if (success) {
success = appendRawData((const unsigned char*)bytes.constData(), bytes.size());
}
return success;
}
@ -451,6 +456,12 @@ bool OctreePacketData::appendRawData(const unsigned char* data, int length) {
return success;
}
bool OctreePacketData::appendRawData(QByteArray data) {
return appendRawData((unsigned char *)data.data(), data.size());
}
quint64 OctreePacketData::_compressContentTime = 0;
quint64 OctreePacketData::_compressContentCalls = 0;
@ -573,3 +584,12 @@ int OctreePacketData::uppackDataFromBytes(const unsigned char* dataBytes, xColor
result.blue = dataBytes[BLUE_INDEX];
return sizeof(rgbColor);
}
int OctreePacketData::uppackDataFromBytes(const unsigned char* dataBytes, QByteArray& result) {
uint16_t length;
memcpy(&length, dataBytes, sizeof(length));
dataBytes += sizeof(length);
QByteArray value((const char*)dataBytes, length);
result = value;
return sizeof(length) + length;
}

View file

@ -183,6 +183,7 @@ public:
/// appends raw bytes, might fail if byte would cause packet to be too large
bool appendRawData(const unsigned char* data, int length);
bool appendRawData(QByteArray data);
/// returns a byte offset from beginning of the uncompressed stream based on offset from end.
/// Positive offsetFromEnd returns that many bytes before the end of uncompressed stream
@ -240,6 +241,7 @@ public:
static int uppackDataFromBytes(const unsigned char* dataBytes, QString& result);
static int uppackDataFromBytes(const unsigned char* dataBytes, QUuid& result);
static int uppackDataFromBytes(const unsigned char* dataBytes, xColor& result);
static int uppackDataFromBytes(const unsigned char* dataBytes, QByteArray& result);
private:
/// appends raw bytes, might fail if byte would cause packet to be too large