From c530c530ef05862af210e3085465936c0522b4ea Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 20 May 2015 17:26:31 -0700 Subject: [PATCH 01/72] Make eyelids follow iris as head tilts - for DDE and no face tracking --- interface/src/avatar/Head.cpp | 58 ++++++++++++++++++++++++++--------- interface/src/avatar/Head.h | 1 + 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index e0cdef109e..8691243c07 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -93,22 +93,24 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) { if (_isFaceTrackerConnected) { _blendshapeCoefficients = faceTracker->getBlendshapeCoefficients(); - if (typeid(*faceTracker) == typeid(DdeFaceTracker) - && Menu::getInstance()->isOptionChecked(MenuOption::UseAudioForMouth)) { + if (typeid(*faceTracker) == typeid(DdeFaceTracker)) { - calculateMouthShapes(); + if (Menu::getInstance()->isOptionChecked(MenuOption::UseAudioForMouth)) { + calculateMouthShapes(); - const int JAW_OPEN_BLENDSHAPE = 21; - const int MMMM_BLENDSHAPE = 34; - const int FUNNEL_BLENDSHAPE = 40; - const int SMILE_LEFT_BLENDSHAPE = 28; - const int SMILE_RIGHT_BLENDSHAPE = 29; - _blendshapeCoefficients[JAW_OPEN_BLENDSHAPE] += _audioJawOpen; - _blendshapeCoefficients[SMILE_LEFT_BLENDSHAPE] += _mouth4; - _blendshapeCoefficients[SMILE_RIGHT_BLENDSHAPE] += _mouth4; - _blendshapeCoefficients[MMMM_BLENDSHAPE] += _mouth2; - _blendshapeCoefficients[FUNNEL_BLENDSHAPE] += _mouth3; + const int JAW_OPEN_BLENDSHAPE = 21; + const int MMMM_BLENDSHAPE = 34; + const int FUNNEL_BLENDSHAPE = 40; + const int SMILE_LEFT_BLENDSHAPE = 28; + const int SMILE_RIGHT_BLENDSHAPE = 29; + _blendshapeCoefficients[JAW_OPEN_BLENDSHAPE] += _audioJawOpen; + _blendshapeCoefficients[SMILE_LEFT_BLENDSHAPE] += _mouth4; + _blendshapeCoefficients[SMILE_RIGHT_BLENDSHAPE] += _mouth4; + _blendshapeCoefficients[MMMM_BLENDSHAPE] += _mouth2; + _blendshapeCoefficients[FUNNEL_BLENDSHAPE] += _mouth3; + } + applyEyelidOffset(getFinalOrientationInWorldFrame()); } } } @@ -203,6 +205,9 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) { _mouth3, _mouth4, _blendshapeCoefficients); + + applyEyelidOffset(getOrientation()); + } else { _saccade = glm::vec3(); } @@ -218,7 +223,6 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) { } } _eyePosition = calculateAverageEyePosition(); - } void Head::calculateMouthShapes() { @@ -249,6 +253,32 @@ void Head::calculateMouthShapes() { _mouth4 = glm::mix(_audioJawOpen, _mouth4, SMILE_PERIOD + randFloat() * SMILE_RANDOM_PERIOD); } +void Head::applyEyelidOffset(glm::quat headOrientation) { + // Adjusts the eyelid blendshape coefficients so that the eyelid follows the iris as the head pitches. + + glm::quat eyeRotation = rotationBetween(headOrientation * IDENTITY_FRONT, getCorrectedLookAtPosition() - _eyePosition); + eyeRotation = eyeRotation * glm::angleAxis(safeEulerAngles(headOrientation).y, IDENTITY_UP); // Rotation w.r.t. head + float eyePitch = safeEulerAngles(eyeRotation).x; + + const float EYE_PITCH_TO_COEFFICIENT = 1.6f; // Empirically determined + const float MAX_EYELID_OFFSET = 0.8f; // So that don't fully close eyes when looking way down + float eyelidOffset = glm::clamp(-eyePitch * EYE_PITCH_TO_COEFFICIENT, -1.0f, MAX_EYELID_OFFSET); + + for (int i = 0; i < 2; i++) { + const int LEFT_EYE = 8; + float eyeCoefficient = _blendshapeCoefficients[i] - _blendshapeCoefficients[LEFT_EYE + i]; // Raw value + eyeCoefficient = glm::clamp(eyelidOffset + eyeCoefficient * (1.0f - eyelidOffset), -1.0f, 1.0f); + if (eyeCoefficient > 0.0f) { + _blendshapeCoefficients[i] = eyeCoefficient; + _blendshapeCoefficients[LEFT_EYE + i] = 0.0f; + + } else { + _blendshapeCoefficients[i] = 0.0f; + _blendshapeCoefficients[LEFT_EYE + i] = -eyeCoefficient; + } + } +} + void Head::relaxLean(float deltaTime) { // restore rotation, lean to neutral positions const float LEAN_RELAXATION_PERIOD = 0.25f; // seconds diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index e523d958a6..6eba16824e 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -155,6 +155,7 @@ private: // private methods void renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition); void calculateMouthShapes(); + void applyEyelidOffset(glm::quat headOrientation); friend class FaceModel; }; From f1fc7a2a09b7f6ee82c6ed89610212d057d3d6af Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 26 May 2015 15:46:25 -0700 Subject: [PATCH 02/72] switching over to geometry cache method for rendering lines --- libraries/entities-renderer/src/RenderableLineEntityItem.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 14628d0a7a..5fc0cef7d2 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -30,11 +31,13 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glm::quat rotation = getRotation(); glm::vec4 lineColor(toGlm(getXColor()), getLocalRenderAlpha()); glPushMatrix(); + auto geometryCache = DependencyManager::get(); glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); glm::vec3 p1 = {0.0f, 0.0f, 0.0f}; - glm::vec3& p2 = dimensions; + glm::vec3 p2 = {1.0f, 1.0, 0.0f}; + //Now we need to switch over to using gemoetryCache renderVertices method like in circleOverlay3D DependencyManager::get()->renderLine(p1, p2, lineColor, lineColor); glPopMatrix(); RenderableDebugableEntityItem::render(this, args); From 1f312b4e0200b4f5a2c38b1a605759d6778e06e0 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 26 May 2015 16:17:31 -0700 Subject: [PATCH 03/72] successfully using geometry cache! --- .../src/RenderableLineEntityItem.cpp | 19 +++++++++++++++---- .../src/RenderableLineEntityItem.h | 8 +++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 5fc0cef7d2..40830d2215 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -32,13 +32,24 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glm::vec4 lineColor(toGlm(getXColor()), getLocalRenderAlpha()); glPushMatrix(); auto geometryCache = DependencyManager::get(); + + if(_lineVerticesID == GeometryCache::UNKNOWN_ID){ + _lineVerticesID = geometryCache ->allocateID(); + } glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - glm::vec3 p1 = {0.0f, 0.0f, 0.0f}; - glm::vec3 p2 = {1.0f, 1.0, 0.0f}; - //Now we need to switch over to using gemoetryCache renderVertices method like in circleOverlay3D - DependencyManager::get()->renderLine(p1, p2, lineColor, lineColor); + + bool geometryChanged = true; + if(geometryChanged){ + QVector points; + glm::vec3 p1 = {0.0f, 0.0f, 0.0f}; + glm::vec3 p2 = {1.0f, 1.0, 0.0f}; + points << p1; + points << p2; + geometryCache->updateVertices(_lineVerticesID, points, lineColor); + } + geometryCache->renderVertices(gpu::LINES, _lineVerticesID); glPopMatrix(); RenderableDebugableEntityItem::render(this, args); }; diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.h b/libraries/entities-renderer/src/RenderableLineEntityItem.h index 0de7cd43ae..7e53915c05 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.h +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.h @@ -14,15 +14,21 @@ #include #include "RenderableDebugableEntityItem.h" +#include class RenderableLineEntityItem : public LineEntityItem { public: static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); RenderableLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : - LineEntityItem(entityItemID, properties) { } + LineEntityItem(entityItemID, properties), + _lineVerticesID(GeometryCache::UNKNOWN_ID) + { } virtual void render(RenderArgs* args); + +protected: + int _lineVerticesID; }; From dc4196df30553fb5c5aff01695388d73f08c96fa Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 26 May 2015 18:26:25 -0700 Subject: [PATCH 04/72] line entities --- libraries/entities/src/LineEntityItem.cpp | 11 ++++++++++- libraries/entities/src/LineEntityItem.h | 11 +++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index 6686f9e46a..94e17b2ead 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -20,13 +20,16 @@ #include "EntityTreeElement.h" +const float DEFAULT_LINE_WIDTH = 2.0f; + EntityItem* LineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { EntityItem* result = new LineEntityItem(entityID, properties); return result; } LineEntityItem::LineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : - EntityItem(entityItemID) + EntityItem(entityItemID) , + _lineWidth(DEFAULT_LINE_WIDTH) { _type = EntityTypes::Line; _created = properties.getCreated(); @@ -36,9 +39,12 @@ LineEntityItem::LineEntityItem(const EntityItemID& entityItemID, const EntityIte EntityItemProperties LineEntityItem::getProperties() const { EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class + COPY_ENTITY_PROPERTY_TO_PROPERTIES(lineWidth, getLineWidth); + properties._color = getXColor(); properties._colorChanged = false; + properties._glowLevel = getGlowLevel(); properties._glowLevelChanged = false; @@ -50,6 +56,7 @@ bool LineEntityItem::setProperties(const EntityItemProperties& properties) { somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); +// SET_ENTITY_PROPERTY_FROM_PROPERTIES(lineWidth, setLineWidth); if (somethingChanged) { bool wantDebug = false; @@ -72,6 +79,7 @@ int LineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, const unsigned char* dataAt = data; READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor); + READ_ENTITY_PROPERTY(PROP_LINE_WIDTH, float, setLineWidth); return bytesRead; } @@ -95,6 +103,7 @@ void LineEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits bool successPropertyFits = true; APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); + APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, getLineWidth()); } void LineEntityItem::debugDump() const { diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index a8bc867bdd..cb21b4b76c 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -51,6 +51,15 @@ class LineEntityItem : public EntityItem { _color[BLUE_INDEX] = value.blue; } + void setLineWidth(float lineWidth){ + + _lineWidth = lineWidth; + } + float getLineWidth() const{ + + return _lineWidth; + } + virtual ShapeType getShapeType() const { return SHAPE_TYPE_LINE; } // never have a ray intersection pick a LineEntityItem. @@ -60,9 +69,11 @@ class LineEntityItem : public EntityItem { void** intersectedObject, bool precisionPicking) const { return false; } virtual void debugDump() const; + static const float DEFAULT_LINE_WIDTH; protected: rgbColor _color; + float _lineWidth; }; #endif // hifi_LineEntityItem_h From 811f5db419ca1c278b4e7f92c0382966d3243282 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 26 May 2015 18:36:24 -0700 Subject: [PATCH 05/72] fixed linker error in lineentityitem.cpp --- libraries/entities/src/EntityItemProperties.h | 1 + libraries/entities/src/EntityPropertyFlags.h | 2 ++ libraries/entities/src/LineEntityItem.cpp | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 2c052d0a53..673a52b172 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -141,6 +141,7 @@ public: DEFINE_PROPERTY_GROUP(Atmosphere, atmosphere, AtmospherePropertyGroup); DEFINE_PROPERTY_GROUP(Skybox, skybox, SkyboxPropertyGroup); DEFINE_PROPERTY_REF(PROP_SOURCE_URL, SourceUrl, sourceUrl, QString); + DEFINE_PROPERTY(LINE_WIDTH, LineWidth, lineWidth, float); static QString getBackgroundModeString(BackgroundMode mode); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 8a5d96e8d2..6572a94089 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -109,6 +109,8 @@ enum EntityPropertyList { PROP_COLLISION_SOUND_URL, PROP_RESTITUTION, PROP_FRICTION, + + PROP_LINE_WIDTH, //for lines //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties ABOVE this line diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index 94e17b2ead..db0d3f807b 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -20,7 +20,7 @@ #include "EntityTreeElement.h" -const float DEFAULT_LINE_WIDTH = 2.0f; +const float LineEntityItem::DEFAULT_LINE_WIDTH = 2.0f; EntityItem* LineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { EntityItem* result = new LineEntityItem(entityID, properties); From 4fb5f0796c4d63a4b6f435cc216e1865d9cb6a12 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 26 May 2015 18:40:15 -0700 Subject: [PATCH 06/72] added props for encoding and decoding --- libraries/entities/src/EntityItemProperties.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 905fa7d104..a3067c1ce5 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -741,6 +741,10 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem _staticSkybox.appentToEditPacket(packetData, requestedProperties, propertyFlags, propertiesDidntFit, propertyCount, appendState ); } + if(properties.getType() == EntityTypes::Line){ + APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, properties.getLineWidth()); + } + APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, properties.getMarketplaceID()); APPEND_ENTITY_PROPERTY(PROP_NAME, properties.getName()); APPEND_ENTITY_PROPERTY(PROP_COLLISION_SOUND_URL, properties.getCollisionSoundURL()); @@ -975,6 +979,10 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int properties.getSkybox().decodeFromEditPacket(propertyFlags, dataAt , processedBytes); } + if(properties.getType() == EntityTypes::Line) { + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_WIDTH, float, setLineWidth); + } + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MARKETPLACE_ID, QString, setMarketplaceID); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_NAME, QString, setName); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLLISION_SOUND_URL, QString, setCollisionSoundURL); From 62539719df2d5e2bb104ec714dce5a2ba5596a66 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Wed, 27 May 2015 13:31:47 -0700 Subject: [PATCH 07/72] line width added as property to line entities --- libraries/entities-renderer/src/RenderableLineEntityItem.cpp | 4 +++- libraries/entities/src/EntityItemProperties.cpp | 5 +++++ libraries/entities/src/LineEntityItem.cpp | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 40830d2215..48c88f3894 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -31,6 +31,8 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glm::quat rotation = getRotation(); glm::vec4 lineColor(toGlm(getXColor()), getLocalRenderAlpha()); glPushMatrix(); + + glLineWidth(getLineWidth()); auto geometryCache = DependencyManager::get(); if(_lineVerticesID == GeometryCache::UNKNOWN_ID){ @@ -44,7 +46,7 @@ void RenderableLineEntityItem::render(RenderArgs* args) { if(geometryChanged){ QVector points; glm::vec3 p1 = {0.0f, 0.0f, 0.0f}; - glm::vec3 p2 = {1.0f, 1.0, 0.0f}; + glm::vec3 p2 = dimensions; points << p1; points << p2; geometryCache->updateVertices(_lineVerticesID, points, lineColor); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index a3067c1ce5..ae18611407 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 "LineEntityItem.h" AtmospherePropertyGroup EntityItemProperties::_staticAtmosphere; SkyboxPropertyGroup EntityItemProperties::_staticSkybox; @@ -90,6 +91,7 @@ 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(lineWidth, LineEntityItem::DEFAULT_LINE_WIDTH), _id(UNKNOWN_ENTITY_ID), _idSet(false), @@ -336,6 +338,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_DIRECTION, keyLightDirection); CHECK_PROPERTY_CHANGE(PROP_BACKGROUND_MODE, backgroundMode); CHECK_PROPERTY_CHANGE(PROP_SOURCE_URL, sourceUrl); + CHECK_PROPERTY_CHANGE(PROP_LINE_WIDTH, lineWidth); changedProperties += _stage.getChangedProperties(); changedProperties += _atmosphere.getChangedProperties(); @@ -418,6 +421,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE(keyLightDirection); COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(backgroundMode, getBackgroundModeAsString()); COPY_PROPERTY_TO_QSCRIPTVALUE(sourceUrl); + COPY_PROPERTY_TO_QSCRIPTVALUE(lineWidth); // Sitting properties support if (!skipDefaults) { @@ -523,6 +527,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { COPY_PROPERTY_FROM_QSCRIPTVALUE(keyLightDirection, glmVec3, setKeyLightDirection); COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(backgroundMode, BackgroundMode); COPY_PROPERTY_FROM_QSCRIPTVALUE(sourceUrl, QString, setSourceUrl); + COPY_PROPERTY_FROM_QSCRIPTVALUE(lineWidth, float, setLineWidth); _stage.copyFromScriptValue(object, _defaultSettings); _atmosphere.copyFromScriptValue(object, _defaultSettings); diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index db0d3f807b..cfbc7d0a08 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -56,7 +56,7 @@ bool LineEntityItem::setProperties(const EntityItemProperties& properties) { somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); -// SET_ENTITY_PROPERTY_FROM_PROPERTIES(lineWidth, setLineWidth); + SET_ENTITY_PROPERTY_FROM_PwaROPERTIES(lineWidth, setLineWidth); if (somethingChanged) { bool wantDebug = false; From 8edc883e4de4848eb499e6c1ce6e346832a99268 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Wed, 27 May 2015 13:47:47 -0700 Subject: [PATCH 08/72] adding serialization for Qvector --- libraries/entities/src/LineEntityItem.cpp | 2 +- libraries/octree/src/OctreePacketData.cpp | 5 +++++ libraries/octree/src/OctreePacketData.h | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index cfbc7d0a08..0c6ee0ba3a 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -56,7 +56,7 @@ bool LineEntityItem::setProperties(const EntityItemProperties& properties) { somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); - SET_ENTITY_PROPERTY_FROM_PwaROPERTIES(lineWidth, setLineWidth); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(lineWidth, setLineWidth); if (somethingChanged) { bool wantDebug = false; diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index 8bc27b872f..1854c73ec7 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -358,6 +358,7 @@ bool OctreePacketData::appendValue(quint64 value) { } bool OctreePacketData::appendValue(float value) { + const unsigned char* data = (const unsigned char*)&value; int length = sizeof(value); bool success = append(data, length); @@ -379,6 +380,10 @@ bool OctreePacketData::appendValue(const glm::vec3& value) { return success; } +bool OctreePacketData::appendValue(const QVector& value){ + +} + bool OctreePacketData::appendValue(const glm::quat& value) { const size_t VALUES_PER_QUAT = 4; const size_t PACKED_QUAT_SIZE = sizeof(uint16_t) * VALUES_PER_QUAT; diff --git a/libraries/octree/src/OctreePacketData.h b/libraries/octree/src/OctreePacketData.h index 28ea9aa681..feaac4196b 100644 --- a/libraries/octree/src/OctreePacketData.h +++ b/libraries/octree/src/OctreePacketData.h @@ -162,6 +162,9 @@ public: /// appends a non-position vector to the end of the stream, may fail if new data stream is too long to fit in packet bool appendValue(const glm::vec3& value); + + //appends a QVector of vec3's to the end of the stream, may fail if new data stream is too long to fit in packet + bool appendValue(const QVector& value); /// appends a packed quat to the end of the stream, may fail if new data stream is too long to fit in packet bool appendValue(const glm::quat& value); From 385c9be75f0bf23a8da9ed0887b4a49046be81db Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Wed, 27 May 2015 15:35:06 -0700 Subject: [PATCH 09/72] using vec of points --- .../src/RenderableLineEntityItem.cpp | 12 ++---------- libraries/entities/src/LineEntityItem.cpp | 8 +++++++- libraries/entities/src/LineEntityItem.h | 5 +++++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 48c88f3894..6fa71712c4 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -41,16 +41,8 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - - bool geometryChanged = true; - if(geometryChanged){ - QVector points; - glm::vec3 p1 = {0.0f, 0.0f, 0.0f}; - glm::vec3 p2 = dimensions; - points << p1; - points << p2; - geometryCache->updateVertices(_lineVerticesID, points, lineColor); - } + geometryCache->updateVertices(_lineVerticesID, getPoints(), lineColor); + geometryCache->renderVertices(gpu::LINES, _lineVerticesID); glPopMatrix(); RenderableDebugableEntityItem::render(this, args); diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index 0c6ee0ba3a..34fffba8fb 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -22,6 +22,7 @@ const float LineEntityItem::DEFAULT_LINE_WIDTH = 2.0f; + EntityItem* LineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { EntityItem* result = new LineEntityItem(entityID, properties); return result; @@ -29,11 +30,16 @@ EntityItem* LineEntityItem::factory(const EntityItemID& entityID, const EntityIt LineEntityItem::LineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) , - _lineWidth(DEFAULT_LINE_WIDTH) + _lineWidth(DEFAULT_LINE_WIDTH), + _points(QVector(100)) { _type = EntityTypes::Line; _created = properties.getCreated(); setProperties(properties); + glm::vec3 p1 = {0.0f, 0.0f, 0.0f}; + glm::vec3 p2 = {1.0f, 1.0f, 0.0f}; + _points << p1; + _points << p2; } EntityItemProperties LineEntityItem::getProperties() const { diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index cb21b4b76c..a42c0397c2 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -60,6 +60,10 @@ class LineEntityItem : public EntityItem { return _lineWidth; } + QVector getPoints() const{ + return _points; + } + virtual ShapeType getShapeType() const { return SHAPE_TYPE_LINE; } // never have a ray intersection pick a LineEntityItem. @@ -74,6 +78,7 @@ class LineEntityItem : public EntityItem { protected: rgbColor _color; float _lineWidth; + QVector _points; }; #endif // hifi_LineEntityItem_h From 72af4e4e674571d942b594246482ead81aa29b3c Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Thu, 28 May 2015 10:44:44 -0700 Subject: [PATCH 10/72] latest pointer --- .../src/RenderableLineEntityItem.cpp | 4 ++-- libraries/entities/src/EntityItemProperties.cpp | 8 ++++++++ libraries/entities/src/EntityItemProperties.h | 1 + .../entities/src/EntityItemPropertiesMacros.h | 7 +++++++ libraries/entities/src/EntityPropertyFlags.h | 5 +++-- libraries/entities/src/LineEntityItem.cpp | 15 +++++++++++---- libraries/entities/src/LineEntityItem.h | 8 +++++++- libraries/octree/src/OctreePacketData.cpp | 9 ++++++++- libraries/octree/src/OctreePacketData.h | 2 ++ libraries/render-utils/src/Model.h | 1 - libraries/shared/src/RegisteredMetaTypes.cpp | 10 ++++++++++ libraries/shared/src/RegisteredMetaTypes.h | 4 ++++ 12 files changed, 63 insertions(+), 11 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 6fa71712c4..3b3b204d93 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -38,10 +38,10 @@ void RenderableLineEntityItem::render(RenderArgs* args) { if(_lineVerticesID == GeometryCache::UNKNOWN_ID){ _lineVerticesID = geometryCache ->allocateID(); } - glTranslatef(position.x, position.y, position.z); +// glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - geometryCache->updateVertices(_lineVerticesID, getPoints(), lineColor); + geometryCache->updateVertices(_lineVerticesID, getLinePoints(), lineColor); geometryCache->renderVertices(gpu::LINES, _lineVerticesID); glPopMatrix(); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index ae18611407..4e4d4fd696 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -92,6 +92,7 @@ CONSTRUCT_PROPERTY(name, ENTITY_ITEM_DEFAULT_NAME), CONSTRUCT_PROPERTY(backgroundMode, BACKGROUND_MODE_INHERIT), CONSTRUCT_PROPERTY(sourceUrl, ""), CONSTRUCT_PROPERTY(lineWidth, LineEntityItem::DEFAULT_LINE_WIDTH), +CONSTRUCT_PROPERTY(linePoints, 0), _id(UNKNOWN_ENTITY_ID), _idSet(false), @@ -339,6 +340,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_BACKGROUND_MODE, backgroundMode); CHECK_PROPERTY_CHANGE(PROP_SOURCE_URL, sourceUrl); CHECK_PROPERTY_CHANGE(PROP_LINE_WIDTH, lineWidth); + CHECK_PROPERTY_CHANGE(PROP_LINE_POINTS, linePoints); changedProperties += _stage.getChangedProperties(); changedProperties += _atmosphere.getChangedProperties(); @@ -422,6 +424,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(backgroundMode, getBackgroundModeAsString()); COPY_PROPERTY_TO_QSCRIPTVALUE(sourceUrl); COPY_PROPERTY_TO_QSCRIPTVALUE(lineWidth); + COPY_PROPERTY_TO_QSCRIPTVALUE(linePoints); // Sitting properties support if (!skipDefaults) { @@ -528,6 +531,9 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(backgroundMode, BackgroundMode); COPY_PROPERTY_FROM_QSCRIPTVALUE(sourceUrl, QString, setSourceUrl); COPY_PROPERTY_FROM_QSCRIPTVALUE(lineWidth, float, setLineWidth); + COPY_PROPERTY_FROM_QSCRIPTVALUE(linePoints, qVector, setLinePoints); + + _stage.copyFromScriptValue(object, _defaultSettings); _atmosphere.copyFromScriptValue(object, _defaultSettings); @@ -748,6 +754,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem if(properties.getType() == EntityTypes::Line){ APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, properties.getLineWidth()); + APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, properties.getLinePoints()); } APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, properties.getMarketplaceID()); @@ -986,6 +993,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int if(properties.getType() == EntityTypes::Line) { READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_WIDTH, float, setLineWidth); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_POINTS, QVector, setLinePoints); } READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MARKETPLACE_ID, QString, setMarketplaceID); diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 673a52b172..ffc9763dca 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -142,6 +142,7 @@ public: DEFINE_PROPERTY_GROUP(Skybox, skybox, SkyboxPropertyGroup); DEFINE_PROPERTY_REF(PROP_SOURCE_URL, SourceUrl, sourceUrl, QString); DEFINE_PROPERTY(LINE_WIDTH, LineWidth, lineWidth, float); + DEFINE_PROPERTY_REF(LINE_POINTS, LinePoints, linePoints, QVector); static QString getBackgroundModeString(BackgroundMode mode); diff --git a/libraries/entities/src/EntityItemPropertiesMacros.h b/libraries/entities/src/EntityItemPropertiesMacros.h index 8c4f329cc9..dd55ae8b3e 100644 --- a/libraries/entities/src/EntityItemPropertiesMacros.h +++ b/libraries/entities/src/EntityItemPropertiesMacros.h @@ -94,6 +94,7 @@ inline QScriptValue convertScriptValue(QScriptEngine* e, const QString& v) { ret inline QScriptValue convertScriptValue(QScriptEngine* e, const xColor& v) { return xColorToScriptValue(e, v); } inline QScriptValue convertScriptValue(QScriptEngine* e, const glm::quat& v) { return quatToScriptValue(e, v); } inline QScriptValue convertScriptValue(QScriptEngine* e, const QScriptValue& v) { return v; } +inline QScriptValue convertScriptValue(QScriptEngine* e, const QVector& v) {return qVectorToScriptValue(e, v); } #define COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(G,g,P,p) \ if (!skipDefaults || defaultEntityProperties.get##G().get##P() != get##P()) { \ @@ -123,6 +124,7 @@ inline QScriptValue convertScriptValue(QScriptEngine* e, const QScriptValue& v) typedef glm::vec3 glmVec3; typedef glm::quat glmQuat; +typedef QVector qVector; inline float float_convertFromScriptValue(const QScriptValue& v, bool& isValid) { return v.toVariant().toFloat(&isValid); } inline uint16_t uint16_t_convertFromScriptValue(const QScriptValue& v, bool& isValid) { return v.toVariant().toInt(&isValid); } inline int int_convertFromScriptValue(const QScriptValue& v, bool& isValid) { return v.toVariant().toInt(&isValid); } @@ -149,6 +151,11 @@ inline glmVec3 glmVec3_convertFromScriptValue(const QScriptValue& v, bool& isVal return glm::vec3(0); } +inline qVector qVector_convertFromScriptValue(const QScriptValue& v, bool& isValid){ + isValid = true; + return qVectorFromScriptValue(v); +} + inline glmQuat glmQuat_convertFromScriptValue(const QScriptValue& v, bool& isValid) { isValid = false; /// assume it can't be converted QScriptValue x = v.property("x"); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 6572a94089..5e52b95c9e 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -110,8 +110,9 @@ enum EntityPropertyList { PROP_RESTITUTION, PROP_FRICTION, - PROP_LINE_WIDTH, //for lines - + //for lines + PROP_LINE_WIDTH, + PROP_LINE_POINTS, //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties ABOVE this line PROP_AFTER_LAST_ITEM, diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index 34fffba8fb..70e54d51a0 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -23,6 +23,7 @@ const float LineEntityItem::DEFAULT_LINE_WIDTH = 2.0f; + EntityItem* LineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { EntityItem* result = new LineEntityItem(entityID, properties); return result; @@ -31,21 +32,22 @@ EntityItem* LineEntityItem::factory(const EntityItemID& entityID, const EntityIt LineEntityItem::LineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) , _lineWidth(DEFAULT_LINE_WIDTH), - _points(QVector(100)) + _points(QVector(5)) { _type = EntityTypes::Line; _created = properties.getCreated(); - setProperties(properties); glm::vec3 p1 = {0.0f, 0.0f, 0.0f}; glm::vec3 p2 = {1.0f, 1.0f, 0.0f}; - _points << p1; - _points << p2; + setProperties(properties); + + } EntityItemProperties LineEntityItem::getProperties() const { EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class COPY_ENTITY_PROPERTY_TO_PROPERTIES(lineWidth, getLineWidth); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(linePoints, getLinePoints); properties._color = getXColor(); properties._colorChanged = false; @@ -63,6 +65,9 @@ bool LineEntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); SET_ENTITY_PROPERTY_FROM_PROPERTIES(lineWidth, setLineWidth); + qDebug()<<"LINE POINTS" << properties._linePoints.size(); + + SET_ENTITY_PROPERTY_FROM_PROPERTIES(linePoints, setLinePoints); if (somethingChanged) { bool wantDebug = false; @@ -86,6 +91,8 @@ int LineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor); READ_ENTITY_PROPERTY(PROP_LINE_WIDTH, float, setLineWidth); + READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector, setLinePoints); + return bytesRead; } diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index a42c0397c2..8d84e4b0d8 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -60,7 +60,13 @@ class LineEntityItem : public EntityItem { return _lineWidth; } - QVector getPoints() const{ + + void setLinePoints(const QVector& points){ + qDebug()<<"WE ARE SETTTTING POINTS *******************"; + _points = points; + } + + const QVector& getLinePoints() const{ return _points; } diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index 1854c73ec7..4f7d89492b 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -381,7 +381,14 @@ bool OctreePacketData::appendValue(const glm::vec3& value) { } bool OctreePacketData::appendValue(const QVector& value){ - + const unsigned char* data = (const unsigned char*)&value; + int length = sizeof(value); + bool success = append(data, length); + if (success){ + _bytesOfValues += length; + _totalBytesOfValues += length; + } + return success; } bool OctreePacketData::appendValue(const glm::quat& value) { diff --git a/libraries/octree/src/OctreePacketData.h b/libraries/octree/src/OctreePacketData.h index feaac4196b..23ffcf99a5 100644 --- a/libraries/octree/src/OctreePacketData.h +++ b/libraries/octree/src/OctreePacketData.h @@ -231,6 +231,7 @@ public: static int uppackDataFromBytes(const unsigned char* dataBytes, float& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } static int uppackDataFromBytes(const unsigned char* dataBytes, glm::vec3& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } + static int uppackDataFromBytes(const unsigned char* dataBytes, QVector& result) {memcpy(&result, dataBytes, sizeof(result)); return sizeof(result);} static int uppackDataFromBytes(const unsigned char* dataBytes, bool& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } static int uppackDataFromBytes(const unsigned char* dataBytes, quint64& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } static int uppackDataFromBytes(const unsigned char* dataBytes, uint32_t& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } @@ -244,6 +245,7 @@ public: static int uppackDataFromBytes(const unsigned char* dataBytes, QUuid& result); static int uppackDataFromBytes(const unsigned char* dataBytes, xColor& result); + private: /// appends raw bytes, might fail if byte would cause packet to be too large bool append(const unsigned char* data, int length); diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index 8c8c35fb4a..76a2d0855f 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -515,7 +515,6 @@ private: Q_DECLARE_METATYPE(QPointer) Q_DECLARE_METATYPE(QWeakPointer) -Q_DECLARE_METATYPE(QVector) /// Handle management of pending models that need blending class ModelBlender : public QObject, public Dependency { diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index eb60e1c31d..242dc0970a 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -72,6 +72,16 @@ void vec3FromScriptValue(const QScriptValue &object, glm::vec3 &vec3) { vec3.z = object.property("z").toVariant().toFloat(); } +QScriptValue qVectorToScriptValue(QScriptEngine* engine, const QVector &vector){ + QScriptValue array = engine->newArray(); + return array; +} + +QVector qVectorFromScriptValue(const QScriptValue &array){ + qDebug()<<"Point 2 x"<(7); +} + QScriptValue vec2toScriptValue(QScriptEngine* engine, const glm::vec2 &vec2) { QScriptValue obj = engine->newObject(); obj.setProperty("x", vec2.x); diff --git a/libraries/shared/src/RegisteredMetaTypes.h b/libraries/shared/src/RegisteredMetaTypes.h index 14f30c20fc..41bfb2004a 100644 --- a/libraries/shared/src/RegisteredMetaTypes.h +++ b/libraries/shared/src/RegisteredMetaTypes.h @@ -28,6 +28,7 @@ Q_DECLARE_METATYPE(glm::vec3) Q_DECLARE_METATYPE(glm::vec2) Q_DECLARE_METATYPE(glm::quat) Q_DECLARE_METATYPE(xColor) +Q_DECLARE_METATYPE(QVector) void registerMetaTypes(QScriptEngine* engine); @@ -55,6 +56,9 @@ void qColorFromScriptValue(const QScriptValue& object, QColor& color); QScriptValue qURLToScriptValue(QScriptEngine* engine, const QUrl& url); void qURLFromScriptValue(const QScriptValue& object, QUrl& url); +QScriptValue qVectorToScriptValue(QScriptEngine*, const QVector& vector); +QVector qVectorFromScriptValue( const QScriptValue &array); + class PickRay { public: PickRay() : origin(0.0f), direction(0.0f) { } From 92817d930265c8a2225c7f8513c96a43641bd6e2 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 28 May 2015 10:59:27 -0700 Subject: [PATCH 11/72] created-time is a property so it can be persisted to and retrieved from json saves --- libraries/entities/src/EntityItem.cpp | 19 +++++++++++++++---- libraries/entities/src/EntityItem.h | 4 ++++ .../entities/src/EntityItemProperties.cpp | 15 ++++++--------- libraries/entities/src/EntityItemProperties.h | 4 +--- .../entities/src/EntityItemPropertiesMacros.h | 11 +++++++++-- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index e0297fe7d4..8787b48f2d 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -896,6 +896,7 @@ EntityItemProperties EntityItem::getProperties() const { COPY_ENTITY_PROPERTY_TO_PROPERTIES(damping, getDamping); COPY_ENTITY_PROPERTY_TO_PROPERTIES(restitution, getRestitution); COPY_ENTITY_PROPERTY_TO_PROPERTIES(friction, getFriction); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(created, getCreated); COPY_ENTITY_PROPERTY_TO_PROPERTIES(lifetime, getLifetime); COPY_ENTITY_PROPERTY_TO_PROPERTIES(script, getScript); COPY_ENTITY_PROPERTY_TO_PROPERTIES(collisionSoundURL, getCollisionSoundURL); @@ -931,6 +932,7 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(damping, updateDamping); SET_ENTITY_PROPERTY_FROM_PROPERTIES(restitution, updateRestitution); SET_ENTITY_PROPERTY_FROM_PROPERTIES(friction, updateFriction); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(created, updateCreated); SET_ENTITY_PROPERTY_FROM_PROPERTIES(lifetime, updateLifetime); SET_ENTITY_PROPERTY_FROM_PROPERTIES(script, setScript); SET_ENTITY_PROPERTY_FROM_PROPERTIES(collisionSoundURL, setCollisionSoundURL); @@ -972,11 +974,13 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) { } void EntityItem::recordCreationTime() { - assert(_created == UNKNOWN_CREATED_TIME); - _created = usecTimestampNow(); + if (_created == UNKNOWN_CREATED_TIME) { + _created = usecTimestampNow(); + } + auto now = usecTimestampNow(); _lastEdited = _created; - _lastUpdated = _created; - _lastSimulated = _created; + _lastUpdated = now; + _lastSimulated = now; } @@ -1284,6 +1288,13 @@ void EntityItem::updateLifetime(float value) { } } +void EntityItem::updateCreated(uint64_t value) { + if (_created != value) { + _created = value; + _dirtyFlags |= EntityItem::DIRTY_LIFETIME; + } +} + void EntityItem::setSimulatorID(const QUuid& value) { _simulatorID = value; _simulatorIDChangedTime = usecTimestampNow(); diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 4f2132bef4..024616939b 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -228,6 +228,9 @@ public: float getLifetime() const { return _lifetime; } /// get the lifetime in seconds for the entity void setLifetime(float value) { _lifetime = value; } /// set the lifetime in seconds for the entity + quint64 getCreated() const { return _created; } /// get the created-time in useconds for the entity + void setCreated(quint64 value) { _created = value; } /// set the created-time in useconds for the entity + /// is this entity immortal, in that it has no lifetime set, and will exist until manually deleted bool isImmortal() const { return _lifetime == ENTITY_ITEM_IMMORTAL_LIFETIME; } @@ -325,6 +328,7 @@ public: void updateIgnoreForCollisions(bool value); void updateCollisionsWillMove(bool value); void updateLifetime(float value); + void updateCreated(uint64_t value); virtual void updateShapeType(ShapeType type) { /* do nothing */ } uint32_t getDirtyFlags() const { return _dirtyFlags; } diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 856c1a1cb4..d3f5b4d055 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -48,6 +48,7 @@ CONSTRUCT_PROPERTY(damping, ENTITY_ITEM_DEFAULT_DAMPING), CONSTRUCT_PROPERTY(restitution, ENTITY_ITEM_DEFAULT_RESTITUTION), CONSTRUCT_PROPERTY(friction, ENTITY_ITEM_DEFAULT_FRICTION), CONSTRUCT_PROPERTY(lifetime, ENTITY_ITEM_DEFAULT_LIFETIME), +CONSTRUCT_PROPERTY(created, UNKNOWN_CREATED_TIME), CONSTRUCT_PROPERTY(script, ENTITY_ITEM_DEFAULT_SCRIPT), CONSTRUCT_PROPERTY(collisionSoundURL, ENTITY_ITEM_DEFAULT_COLLISION_SOUND_URL), CONSTRUCT_PROPERTY(color, ), @@ -99,7 +100,6 @@ CONSTRUCT_PROPERTY(sourceUrl, ""), _id(UNKNOWN_ENTITY_ID), _idSet(false), _lastEdited(0), -_created(UNKNOWN_CREATED_TIME), _type(EntityTypes::Unknown), _glowLevel(0.0f), @@ -194,13 +194,6 @@ void EntityItemProperties::debugDump() const { props.debugDumpBits(); } -void EntityItemProperties::setCreated(quint64 usecTime) { - _created = usecTime; - if (_lastEdited < _created) { - _lastEdited = _created; - } -} - void EntityItemProperties::setLastEdited(quint64 usecTime) { _lastEdited = usecTime > _created ? usecTime : _created; } @@ -375,10 +368,13 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE(friction); COPY_PROPERTY_TO_QSCRIPTVALUE(density); COPY_PROPERTY_TO_QSCRIPTVALUE(lifetime); - if (!skipDefaults) { + + if (!skipDefaults || _lifetime != defaultEntityProperties._lifetime) { COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(age, getAge()); // gettable, but not settable COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(ageAsText, formatSecondsElapsed(getAge())); // gettable, but not settable } + COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(created, getCreated()); + COPY_PROPERTY_TO_QSCRIPTVALUE(script); COPY_PROPERTY_TO_QSCRIPTVALUE(registrationPoint); COPY_PROPERTY_TO_QSCRIPTVALUE(angularVelocity); @@ -488,6 +484,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { COPY_PROPERTY_FROM_QSCRIPTVALUE(restitution, float, setRestitution); COPY_PROPERTY_FROM_QSCRIPTVALUE(friction, float, setFriction); COPY_PROPERTY_FROM_QSCRIPTVALUE(lifetime, float, setLifetime); + COPY_PROPERTY_FROM_QSCRIPTVALUE(created, float, setCreated); COPY_PROPERTY_FROM_QSCRIPTVALUE(script, QString, setScript); COPY_PROPERTY_FROM_QSCRIPTVALUE(registrationPoint, glmVec3, setRegistrationPoint); COPY_PROPERTY_FROM_QSCRIPTVALUE(angularVelocity, glmVec3, setAngularVelocity); diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 26c26bd474..a0eab130c4 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -96,6 +96,7 @@ public: DEFINE_PROPERTY(PROP_RESTITUTION, Restitution, restitution, float); DEFINE_PROPERTY(PROP_FRICTION, Friction, friction, float); DEFINE_PROPERTY(PROP_LIFETIME, Lifetime, lifetime, float); + DEFINE_PROPERTY(PROP_CREATED, Created, created, quint64); DEFINE_PROPERTY_REF(PROP_SCRIPT, Script, script, QString); DEFINE_PROPERTY_REF(PROP_COLLISION_SOUND_URL, CollisionSoundURL, collisionSoundURL, QString); DEFINE_PROPERTY_REF(PROP_COLOR, Color, color, xColor); @@ -153,8 +154,6 @@ public: float getMaxDimension() const { return glm::max(_dimensions.x, _dimensions.y, _dimensions.z); } float getAge() const { return (float)(usecTimestampNow() - _created) / (float)USECS_PER_SECOND; } - quint64 getCreated() const { return _created; } - void setCreated(quint64 usecTime); bool hasCreatedTime() const { return (_created != UNKNOWN_CREATED_TIME); } bool containsBoundsProperties() const { return (_positionChanged || _dimensionsChanged); } @@ -199,7 +198,6 @@ private: QUuid _id; bool _idSet; quint64 _lastEdited; - quint64 _created; EntityTypes::EntityType _type; void setType(const QString& typeName) { _type = EntityTypes::getEntityTypeFromName(typeName); } diff --git a/libraries/entities/src/EntityItemPropertiesMacros.h b/libraries/entities/src/EntityItemPropertiesMacros.h index 33abc59e4d..30d32446e7 100644 --- a/libraries/entities/src/EntityItemPropertiesMacros.h +++ b/libraries/entities/src/EntityItemPropertiesMacros.h @@ -96,6 +96,11 @@ inline QScriptValue convertScriptValue(QScriptEngine* e, const xColor& v) { retu inline QScriptValue convertScriptValue(QScriptEngine* e, const glm::quat& v) { return quatToScriptValue(e, v); } inline QScriptValue convertScriptValue(QScriptEngine* e, const QScriptValue& v) { return v; } +// QScriptValue doesn't support "long long" ints, so use strings +inline QScriptValue convertScriptValue(QScriptEngine* e, quint64 v) { + return QString::number(v); +} + inline QScriptValue convertScriptValue(QScriptEngine* e, const QByteArray& v) { QByteArray b64 = v.toBase64(); return QScriptValue(QString(b64)); @@ -138,6 +143,10 @@ inline bool bool_convertFromScriptValue(const QScriptValue& v, bool& isValid) { inline QString QString_convertFromScriptValue(const QScriptValue& v, bool& isValid) { isValid = true; return v.toVariant().toString().trimmed(); } inline QUuid QUuid_convertFromScriptValue(const QScriptValue& v, bool& isValid) { isValid = true; return v.toVariant().toUuid(); } +// QScriptValue doesn't support "long long" ints, so use strings +inline uint64_t uint64_t_convertFromScriptValue(const QScriptValue& v, bool& isValid) { + return (uint64_t) v.toVariant().toString().trimmed().toLongLong(); +} inline QByteArray QByteArray_convertFromScriptValue(const QScriptValue& v, bool& isValid) { isValid = true; @@ -145,8 +154,6 @@ inline QByteArray QByteArray_convertFromScriptValue(const QScriptValue& v, bool& return QByteArray::fromBase64(b64.toUtf8()); } - - inline glmVec3 glmVec3_convertFromScriptValue(const QScriptValue& v, bool& isValid) { isValid = false; /// assume it can't be converted QScriptValue x = v.property("x"); From 8886e93d5fa764f983c3495e6431d012f56fce6e Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Thu, 28 May 2015 11:26:41 -0700 Subject: [PATCH 12/72] changed qVector to qVectorVec3 --- libraries/entities/src/EntityItemProperties.cpp | 2 +- libraries/entities/src/EntityItemPropertiesMacros.h | 8 ++++---- libraries/shared/src/RegisteredMetaTypes.cpp | 10 +++++++--- libraries/shared/src/RegisteredMetaTypes.h | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 4e4d4fd696..dada7ff1ea 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -531,7 +531,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(backgroundMode, BackgroundMode); COPY_PROPERTY_FROM_QSCRIPTVALUE(sourceUrl, QString, setSourceUrl); COPY_PROPERTY_FROM_QSCRIPTVALUE(lineWidth, float, setLineWidth); - COPY_PROPERTY_FROM_QSCRIPTVALUE(linePoints, qVector, setLinePoints); + COPY_PROPERTY_FROM_QSCRIPTVALUE(linePoints, qVectorVec3, setLinePoints); diff --git a/libraries/entities/src/EntityItemPropertiesMacros.h b/libraries/entities/src/EntityItemPropertiesMacros.h index dd55ae8b3e..3c087b9891 100644 --- a/libraries/entities/src/EntityItemPropertiesMacros.h +++ b/libraries/entities/src/EntityItemPropertiesMacros.h @@ -94,7 +94,7 @@ inline QScriptValue convertScriptValue(QScriptEngine* e, const QString& v) { ret inline QScriptValue convertScriptValue(QScriptEngine* e, const xColor& v) { return xColorToScriptValue(e, v); } inline QScriptValue convertScriptValue(QScriptEngine* e, const glm::quat& v) { return quatToScriptValue(e, v); } inline QScriptValue convertScriptValue(QScriptEngine* e, const QScriptValue& v) { return v; } -inline QScriptValue convertScriptValue(QScriptEngine* e, const QVector& v) {return qVectorToScriptValue(e, v); } +inline QScriptValue convertScriptValue(QScriptEngine* e, const QVector& v) {return qVectorVec3ToScriptValue(e, v); } #define COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(G,g,P,p) \ if (!skipDefaults || defaultEntityProperties.get##G().get##P() != get##P()) { \ @@ -124,7 +124,7 @@ inline QScriptValue convertScriptValue(QScriptEngine* e, const QVector qVector; +typedef QVector qVectorVec3; inline float float_convertFromScriptValue(const QScriptValue& v, bool& isValid) { return v.toVariant().toFloat(&isValid); } inline uint16_t uint16_t_convertFromScriptValue(const QScriptValue& v, bool& isValid) { return v.toVariant().toInt(&isValid); } inline int int_convertFromScriptValue(const QScriptValue& v, bool& isValid) { return v.toVariant().toInt(&isValid); } @@ -151,9 +151,9 @@ inline glmVec3 glmVec3_convertFromScriptValue(const QScriptValue& v, bool& isVal return glm::vec3(0); } -inline qVector qVector_convertFromScriptValue(const QScriptValue& v, bool& isValid){ +inline qVectorVec3 qVectorVec3_convertFromScriptValue(const QScriptValue& v, bool& isValid){ isValid = true; - return qVectorFromScriptValue(v); + return qVectorVec3FromScriptValue(v); } inline glmQuat glmQuat_convertFromScriptValue(const QScriptValue& v, bool& isValid) { diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index 242dc0970a..7b7a15416a 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -72,14 +72,18 @@ void vec3FromScriptValue(const QScriptValue &object, glm::vec3 &vec3) { vec3.z = object.property("z").toVariant().toFloat(); } -QScriptValue qVectorToScriptValue(QScriptEngine* engine, const QVector &vector){ +QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector &vector){ QScriptValue array = engine->newArray(); + for(int i = 0; i < vector.size(); i++){ + array.setProperty(i, vec3toScriptValue(vector.at(i))); + } return array; } -QVector qVectorFromScriptValue(const QScriptValue &array){ +QVector qVectorVec3FromScriptValue(const QScriptValue &array){ + QVector newVector; qDebug()<<"Point 2 x"<(7); + return QVector(8); } QScriptValue vec2toScriptValue(QScriptEngine* engine, const glm::vec2 &vec2) { diff --git a/libraries/shared/src/RegisteredMetaTypes.h b/libraries/shared/src/RegisteredMetaTypes.h index 41bfb2004a..bab4dc7d08 100644 --- a/libraries/shared/src/RegisteredMetaTypes.h +++ b/libraries/shared/src/RegisteredMetaTypes.h @@ -56,8 +56,8 @@ void qColorFromScriptValue(const QScriptValue& object, QColor& color); QScriptValue qURLToScriptValue(QScriptEngine* engine, const QUrl& url); void qURLFromScriptValue(const QScriptValue& object, QUrl& url); -QScriptValue qVectorToScriptValue(QScriptEngine*, const QVector& vector); -QVector qVectorFromScriptValue( const QScriptValue &array); +QScriptValue qVectorVec3ToScriptValue(QScriptEngine*, const QVector& vector); +QVector qVectorVec3FromScriptValue( const QScriptValue &array); class PickRay { public: From 2d6669667507a7e3785ed2c77540440ec3e7494c Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Thu, 28 May 2015 14:18:57 -0700 Subject: [PATCH 13/72] line working from array of points --- .../src/RenderableLineEntityItem.cpp | 1 + libraries/entities/src/LineEntityItem.cpp | 7 ++----- libraries/entities/src/LineEntityItem.h | 7 ++++++- libraries/shared/src/RegisteredMetaTypes.cpp | 14 ++++++++++---- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 3b3b204d93..b2ada00f1f 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -24,6 +24,7 @@ EntityItem* RenderableLineEntityItem::factory(const EntityItemID& entityID, cons } void RenderableLineEntityItem::render(RenderArgs* args) { + qDebug()<<"RENDER"; PerformanceTimer perfTimer("RenderableLineEntityItem::render"); assert(getType() == EntityTypes::Line); glm::vec3 position = getPosition(); diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index 70e54d51a0..8cf588c2b0 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -32,12 +32,10 @@ EntityItem* LineEntityItem::factory(const EntityItemID& entityID, const EntityIt LineEntityItem::LineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) , _lineWidth(DEFAULT_LINE_WIDTH), - _points(QVector(5)) + _points(QVector(0)) { _type = EntityTypes::Line; _created = properties.getCreated(); - glm::vec3 p1 = {0.0f, 0.0f, 0.0f}; - glm::vec3 p2 = {1.0f, 1.0f, 0.0f}; setProperties(properties); @@ -65,10 +63,9 @@ bool LineEntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); SET_ENTITY_PROPERTY_FROM_PROPERTIES(lineWidth, setLineWidth); - qDebug()<<"LINE POINTS" << properties._linePoints.size(); - SET_ENTITY_PROPERTY_FROM_PROPERTIES(linePoints, setLinePoints); + if (somethingChanged) { bool wantDebug = false; if (wantDebug) { diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index 8d84e4b0d8..9ac3fd5ae5 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -62,8 +62,13 @@ class LineEntityItem : public EntityItem { void setLinePoints(const QVector& points){ - qDebug()<<"WE ARE SETTTTING POINTS *******************"; + qDebug()<<"points " << points; _points = points; +// _points = QVector(0); +// glm::vec3 p1 = { 0,0,0}; +// glm::vec3 p2 = {1, 1,0}; +// _points <& getLinePoints() const{ diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index 7b7a15416a..cce628aea5 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -75,15 +75,21 @@ void vec3FromScriptValue(const QScriptValue &object, glm::vec3 &vec3) { QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector &vector){ QScriptValue array = engine->newArray(); for(int i = 0; i < vector.size(); i++){ - array.setProperty(i, vec3toScriptValue(vector.at(i))); + array.setProperty(i, vec3toScriptValue(engine, vector.at(i))); } return array; } QVector qVectorVec3FromScriptValue(const QScriptValue &array){ - QVector newVector; - qDebug()<<"Point 2 x"<(8); + QVector newVector(0); + int length = array.property("length").toInteger(); + + for(int i = 0; i < length; i++) { + glm::vec3 newVec3 = glm::vec3(); + vec3FromScriptValue(array.property(i), newVec3); + newVector << newVec3; + } + return newVector; } QScriptValue vec2toScriptValue(QScriptEngine* engine, const glm::vec2 &vec2) { From 4d4a90e9ce0da73ea8a50bf084d6414cda38c4ca Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Thu, 28 May 2015 14:30:34 -0700 Subject: [PATCH 14/72] removed render debugging --- libraries/entities-renderer/src/RenderableLineEntityItem.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index b2ada00f1f..3b3b204d93 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -24,7 +24,6 @@ EntityItem* RenderableLineEntityItem::factory(const EntityItemID& entityID, cons } void RenderableLineEntityItem::render(RenderArgs* args) { - qDebug()<<"RENDER"; PerformanceTimer perfTimer("RenderableLineEntityItem::render"); assert(getType() == EntityTypes::Line); glm::vec3 position = getPosition(); From 533148f26dda5db4e6a4233e0361b3a1436fc9dd Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Thu, 28 May 2015 15:48:31 -0700 Subject: [PATCH 15/72] line being sent as array --- libraries/entities-renderer/src/RenderableLineEntityItem.cpp | 2 +- libraries/entities/src/LineEntityItem.h | 4 +++- libraries/render-utils/src/GeometryCache.cpp | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 3b3b204d93..21880bab9b 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -43,7 +43,7 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); geometryCache->updateVertices(_lineVerticesID, getLinePoints(), lineColor); - geometryCache->renderVertices(gpu::LINES, _lineVerticesID); + geometryCache->renderVertices(gpu::LINE_STRIP, _lineVerticesID); glPopMatrix(); RenderableDebugableEntityItem::render(this, args); }; diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index 9ac3fd5ae5..50858b4b0a 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -66,9 +66,11 @@ class LineEntityItem : public EntityItem { _points = points; // _points = QVector(0); // glm::vec3 p1 = { 0,0,0}; -// glm::vec3 p2 = {1, 1,0}; +// glm::vec3 p2 = {1, -1,2}; +// glm::vec3 p3 = {4, 0, 0}; // _points <& getLinePoints() const{ diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 770717edbe..132ebbc914 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -660,7 +660,6 @@ void GeometryCache::updateVertices(int id, const QVector& points, con void GeometryCache::updateVertices(int id, const QVector& points, const glm::vec4& color) { BatchItemDetails& details = _registeredVertices[id]; - if (details.isCreated) { details.clear(); #ifdef WANT_DEBUG @@ -799,7 +798,7 @@ void GeometryCache::renderVertices(gpu::Primitive primitiveType, int id) { batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(primitiveType, details.vertices, 0); - + gpu::GLBackend::renderBatch(batch); glDisableClientState(GL_VERTEX_ARRAY); From 3627f03c0d2ffaa4acb9de73b494a6aa2d54c1ee Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Thu, 28 May 2015 16:00:24 -0700 Subject: [PATCH 16/72] drawing lines relative to position --- libraries/entities-renderer/src/RenderableLineEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 21880bab9b..9688d2bab1 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -38,7 +38,7 @@ void RenderableLineEntityItem::render(RenderArgs* args) { if(_lineVerticesID == GeometryCache::UNKNOWN_ID){ _lineVerticesID = geometryCache ->allocateID(); } -// glTranslatef(position.x, position.y, position.z); + glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); geometryCache->updateVertices(_lineVerticesID, getLinePoints(), lineColor); From 0cf9afd8ec5c7893fad373cc87df69a0088ee18d Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 28 May 2015 21:21:57 -0700 Subject: [PATCH 17/72] attempt to save _created as an iso date in utc --- interface/src/ui/ApplicationOverlay.cpp | 1 - .../entities/src/EntityItemProperties.cpp | 19 +++++++++++++++-- libraries/entities/src/EntityItemProperties.h | 2 ++ .../entities/src/EntityItemPropertiesMacros.h | 21 +++++++++++++------ 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 8a64630266..d9d2a1d971 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -507,7 +507,6 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { QPoint rv; auto canvasSize = qApp->getCanvasSize(); if (qApp->isHMDMode()) { - float t; glm::vec2 polar = getPolarCoordinates(*palm); glm::vec2 point = sphericalToScreen(-polar); rv.rx() = point.x; diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index d3f5b4d055..7457de3797 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -176,6 +176,14 @@ QString EntityItemProperties::getAnimationSettings() const { return jsonByteString; } + +void EntityItemProperties::setCreated(QDateTime v) { + QDateTime utcV = v; + // utcV.setTimeSpec(Qt::OffsetFromUTC); + _created = utcV.toMSecsSinceEpoch() * 1000; // usec per msec + qDebug() << "EntityItemProperties::setCreated QDateTime" << v << _created; +} + void EntityItemProperties::debugDump() const { qCDebug(entities) << "EntityItemProperties..."; qCDebug(entities) << " _type=" << EntityTypes::getEntityTypeName(_type); @@ -373,7 +381,10 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(age, getAge()); // gettable, but not settable COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(ageAsText, formatSecondsElapsed(getAge())); // gettable, but not settable } - COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(created, getCreated()); + + auto created = QDateTime::fromMSecsSinceEpoch(getCreated() / 1000.0f, Qt::UTC); // usec per msec + created.setTimeSpec(Qt::OffsetFromUTC); + COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(created, created); COPY_PROPERTY_TO_QSCRIPTVALUE(script); COPY_PROPERTY_TO_QSCRIPTVALUE(registrationPoint); @@ -484,7 +495,11 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { COPY_PROPERTY_FROM_QSCRIPTVALUE(restitution, float, setRestitution); COPY_PROPERTY_FROM_QSCRIPTVALUE(friction, float, setFriction); COPY_PROPERTY_FROM_QSCRIPTVALUE(lifetime, float, setLifetime); - COPY_PROPERTY_FROM_QSCRIPTVALUE(created, float, setCreated); + COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(created, QDateTime, setCreated, [this]() { + auto result = QDateTime::fromMSecsSinceEpoch(_created / 1000, Qt::UTC); // usec per msec + // result.setTimeSpec(Qt::OffsetFromUTC); + return result; + }); COPY_PROPERTY_FROM_QSCRIPTVALUE(script, QString, setScript); COPY_PROPERTY_FROM_QSCRIPTVALUE(registrationPoint, glmVec3, setRegistrationPoint); COPY_PROPERTY_FROM_QSCRIPTVALUE(angularVelocity, glmVec3, setAngularVelocity); diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index a0eab130c4..49fd206f93 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -194,6 +194,8 @@ public: void setVoxelDataDirty() { _voxelDataChanged = true; } + void setCreated(QDateTime v); + private: QUuid _id; bool _idSet; diff --git a/libraries/entities/src/EntityItemPropertiesMacros.h b/libraries/entities/src/EntityItemPropertiesMacros.h index 30d32446e7..66259ad25f 100644 --- a/libraries/entities/src/EntityItemPropertiesMacros.h +++ b/libraries/entities/src/EntityItemPropertiesMacros.h @@ -9,6 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #ifndef hifi_EntityItemPropertiesMacros_h #define hifi_EntityItemPropertiesMacros_h @@ -96,11 +98,14 @@ inline QScriptValue convertScriptValue(QScriptEngine* e, const xColor& v) { retu inline QScriptValue convertScriptValue(QScriptEngine* e, const glm::quat& v) { return quatToScriptValue(e, v); } inline QScriptValue convertScriptValue(QScriptEngine* e, const QScriptValue& v) { return v; } -// QScriptValue doesn't support "long long" ints, so use strings -inline QScriptValue convertScriptValue(QScriptEngine* e, quint64 v) { - return QString::number(v); +inline QScriptValue convertScriptValue(QScriptEngine* e, QDateTime v) { + auto utcV = v; + utcV.setTimeSpec(Qt::OffsetFromUTC); + auto result = QScriptValue(utcV.toString(Qt::ISODate)); + return result; } + inline QScriptValue convertScriptValue(QScriptEngine* e, const QByteArray& v) { QByteArray b64 = v.toBase64(); return QScriptValue(QString(b64)); @@ -143,11 +148,15 @@ inline bool bool_convertFromScriptValue(const QScriptValue& v, bool& isValid) { inline QString QString_convertFromScriptValue(const QScriptValue& v, bool& isValid) { isValid = true; return v.toVariant().toString().trimmed(); } inline QUuid QUuid_convertFromScriptValue(const QScriptValue& v, bool& isValid) { isValid = true; return v.toVariant().toUuid(); } -// QScriptValue doesn't support "long long" ints, so use strings -inline uint64_t uint64_t_convertFromScriptValue(const QScriptValue& v, bool& isValid) { - return (uint64_t) v.toVariant().toString().trimmed().toLongLong(); +inline QDateTime QDateTime_convertFromScriptValue(const QScriptValue& v, bool& isValid) { + isValid = true; + auto result = QDateTime::fromString(v.toVariant().toString().trimmed(), Qt::ISODate); + // result.setTimeSpec(Qt::OffsetFromUTC); + return result; } + + inline QByteArray QByteArray_convertFromScriptValue(const QScriptValue& v, bool& isValid) { isValid = true; QString b64 = v.toVariant().toString().trimmed(); From f5736452916b194c6d14836e60ce8432897f1bd4 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Fri, 29 May 2015 09:24:00 -0700 Subject: [PATCH 18/72] line entity width translating --- .../entities-renderer/src/RenderableLineEntityItem.cpp | 7 ++++++- libraries/entities/src/EntityItemProperties.cpp | 9 +++++++-- libraries/entities/src/EntityItemProperties.h | 2 +- libraries/entities/src/LineEntityItem.cpp | 10 +++++++--- libraries/entities/src/LineEntityItem.h | 1 - 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 9688d2bab1..63cd7f0234 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -41,7 +41,12 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - geometryCache->updateVertices(_lineVerticesID, getLinePoints(), lineColor); + QVector points; + glm::vec3 p1 = {0, 0, 0}; + glm::vec3 p2 = {1, 1, 0}; + points<updateVertices(_lineVerticesID, getLinePoints(), lineColor); + geometryCache->updateVertices(_lineVerticesID, points, lineColor); geometryCache->renderVertices(gpu::LINE_STRIP, _lineVerticesID); glPopMatrix(); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index dada7ff1ea..4a747aeea3 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -753,8 +753,9 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem } if(properties.getType() == EntityTypes::Line){ + qDebug()<<"****** LINE WIDTH!!!!!!!!!!!!!!! **********" << properties.getLineWidth(); APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, properties.getLineWidth()); - APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, properties.getLinePoints()); +// APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, properties.getLinePoints()); } APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, properties.getMarketplaceID()); @@ -992,8 +993,10 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int } if(properties.getType() == EntityTypes::Line) { + qDebug()<<"READING LINE ENTITY"; READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_WIDTH, float, setLineWidth); - READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_POINTS, QVector, setLinePoints); + qDebug()<<"width: "<< properties._lineWidth; +// READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_POINTS, QVector, setLinePoints); } READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MARKETPLACE_ID, QString, setMarketplaceID); @@ -1100,6 +1103,8 @@ void EntityItemProperties::markAllChanged() { _skybox.markAllChanged(); _sourceUrlChanged = true; + + _lineWidthChanged = true; } /// The maximum bounding cube for the entity, independent of it's rotation. diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index ffc9763dca..403cff12d3 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -141,7 +141,7 @@ public: DEFINE_PROPERTY_GROUP(Atmosphere, atmosphere, AtmospherePropertyGroup); DEFINE_PROPERTY_GROUP(Skybox, skybox, SkyboxPropertyGroup); DEFINE_PROPERTY_REF(PROP_SOURCE_URL, SourceUrl, sourceUrl, QString); - DEFINE_PROPERTY(LINE_WIDTH, LineWidth, lineWidth, float); + DEFINE_PROPERTY(PROP_LINE_WIDTH, LineWidth, lineWidth, float); DEFINE_PROPERTY_REF(LINE_POINTS, LinePoints, linePoints, QVector); static QString getBackgroundModeString(BackgroundMode mode); diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index 8cf588c2b0..5806ca4c57 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -42,13 +42,16 @@ LineEntityItem::LineEntityItem(const EntityItemID& entityItemID, const EntityIte } EntityItemProperties LineEntityItem::getProperties() const { + EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class - COPY_ENTITY_PROPERTY_TO_PROPERTIES(lineWidth, getLineWidth); COPY_ENTITY_PROPERTY_TO_PROPERTIES(linePoints, getLinePoints); properties._color = getXColor(); properties._colorChanged = false; + + properties._lineWidth = getLineWidth(); + properties._lineWidthChanged = false; properties._glowLevel = getGlowLevel(); @@ -60,7 +63,7 @@ EntityItemProperties LineEntityItem::getProperties() const { bool LineEntityItem::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(lineWidth, setLineWidth); SET_ENTITY_PROPERTY_FROM_PROPERTIES(linePoints, setLinePoints); @@ -88,7 +91,7 @@ int LineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor); READ_ENTITY_PROPERTY(PROP_LINE_WIDTH, float, setLineWidth); - READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector, setLinePoints); +// READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector, setLinePoints); return bytesRead; @@ -99,6 +102,7 @@ int LineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, EntityPropertyFlags LineEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); requestedProperties += PROP_COLOR; + requestedProperties += PROP_LINE_WIDTH; return requestedProperties; } diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index 50858b4b0a..afd20a3722 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -52,7 +52,6 @@ class LineEntityItem : public EntityItem { } void setLineWidth(float lineWidth){ - _lineWidth = lineWidth; } float getLineWidth() const{ From 9f4fff358839a364af9d47891e5cc74f2587d614 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 29 May 2015 09:33:29 -0700 Subject: [PATCH 19/72] don't need convertScriptValue(QScriptEngine* e, QDateTime v) --- libraries/entities/src/EntityItemProperties.cpp | 3 +-- libraries/entities/src/EntityItemPropertiesMacros.h | 10 ---------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 7457de3797..2c6e36fdff 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -179,7 +179,6 @@ QString EntityItemProperties::getAnimationSettings() const { void EntityItemProperties::setCreated(QDateTime v) { QDateTime utcV = v; - // utcV.setTimeSpec(Qt::OffsetFromUTC); _created = utcV.toMSecsSinceEpoch() * 1000; // usec per msec qDebug() << "EntityItemProperties::setCreated QDateTime" << v << _created; } @@ -384,7 +383,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool auto created = QDateTime::fromMSecsSinceEpoch(getCreated() / 1000.0f, Qt::UTC); // usec per msec created.setTimeSpec(Qt::OffsetFromUTC); - COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(created, created); + COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(created, created.toString(Qt::ISODate)); COPY_PROPERTY_TO_QSCRIPTVALUE(script); COPY_PROPERTY_TO_QSCRIPTVALUE(registrationPoint); diff --git a/libraries/entities/src/EntityItemPropertiesMacros.h b/libraries/entities/src/EntityItemPropertiesMacros.h index 66259ad25f..6aeb9a2142 100644 --- a/libraries/entities/src/EntityItemPropertiesMacros.h +++ b/libraries/entities/src/EntityItemPropertiesMacros.h @@ -98,21 +98,11 @@ inline QScriptValue convertScriptValue(QScriptEngine* e, const xColor& v) { retu inline QScriptValue convertScriptValue(QScriptEngine* e, const glm::quat& v) { return quatToScriptValue(e, v); } inline QScriptValue convertScriptValue(QScriptEngine* e, const QScriptValue& v) { return v; } -inline QScriptValue convertScriptValue(QScriptEngine* e, QDateTime v) { - auto utcV = v; - utcV.setTimeSpec(Qt::OffsetFromUTC); - auto result = QScriptValue(utcV.toString(Qt::ISODate)); - return result; -} - - inline QScriptValue convertScriptValue(QScriptEngine* e, const QByteArray& v) { QByteArray b64 = v.toBase64(); return QScriptValue(QString(b64)); } - - #define COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(G,g,P,p) \ if (!skipDefaults || defaultEntityProperties.get##G().get##P() != get##P()) { \ QScriptValue groupProperties = properties.property(#g); \ From a96520ca74466b63ffd87b9470ca1d75ab48296f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 29 May 2015 13:43:18 -0700 Subject: [PATCH 20/72] set up EntityItemPropertiesFromScript to either ignore or honor read-only properties --- .../entities/src/EntityItemProperties.cpp | 26 ++++++++++++------- libraries/entities/src/EntityItemProperties.h | 5 ++-- .../entities/src/EntityScriptingInterface.cpp | 2 +- libraries/entities/src/EntityTree.cpp | 2 +- libraries/octree/src/Octree.cpp | 8 ++++++ libraries/script-engine/src/ScriptEngine.cpp | 2 +- 6 files changed, 31 insertions(+), 14 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 2c6e36fdff..ec41b313a0 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -477,7 +477,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool return properties; } -void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { +void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool honorReadOnly) { QScriptValue typeScriptValue = object.property("type"); if (typeScriptValue.isValid()) { setType(typeScriptValue.toVariant().toString()); @@ -494,11 +494,12 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { COPY_PROPERTY_FROM_QSCRIPTVALUE(restitution, float, setRestitution); COPY_PROPERTY_FROM_QSCRIPTVALUE(friction, float, setFriction); COPY_PROPERTY_FROM_QSCRIPTVALUE(lifetime, float, setLifetime); - COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(created, QDateTime, setCreated, [this]() { - auto result = QDateTime::fromMSecsSinceEpoch(_created / 1000, Qt::UTC); // usec per msec - // result.setTimeSpec(Qt::OffsetFromUTC); - return result; - }); + if (!honorReadOnly) { + COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(created, QDateTime, setCreated, [this]() { + auto result = QDateTime::fromMSecsSinceEpoch(_created / 1000, Qt::UTC); // usec per msec + return result; + }); + } COPY_PROPERTY_FROM_QSCRIPTVALUE(script, QString, setScript); COPY_PROPERTY_FROM_QSCRIPTVALUE(registrationPoint, glmVec3, setRegistrationPoint); COPY_PROPERTY_FROM_QSCRIPTVALUE(angularVelocity, glmVec3, setAngularVelocity); @@ -523,7 +524,9 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { COPY_PROPERTY_FROM_QSCRIPTVALUE(locked, bool, setLocked); COPY_PROPERTY_FROM_QSCRIPTVALUE(textures, QString, setTextures); COPY_PROPERTY_FROM_QSCRIPTVALUE(userData, QString, setUserData); - //COPY_PROPERTY_FROM_QSCRIPTVALUE(simulatorID, QUuid, setSimulatorID); DO NOT accept this info from QScriptValue + if (!honorReadOnly) { + COPY_PROPERTY_FROM_QSCRIPTVALUE(simulatorID, QUuid, setSimulatorID); + } COPY_PROPERTY_FROM_QSCRIPTVALUE(text, QString, setText); COPY_PROPERTY_FROM_QSCRIPTVALUE(lineHeight, float, setLineHeight); COPY_PROPERTY_FROM_QSCRIPTVALUE(textColor, xColor, setTextColor); @@ -565,10 +568,15 @@ QScriptValue EntityItemNonDefaultPropertiesToScriptValue(QScriptEngine* engine, return properties.copyToScriptValue(engine, true); } -void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemProperties& properties) { - properties.copyFromScriptValue(object); +void EntityItemPropertiesFromScriptValueIgnoreReadOnly(const QScriptValue &object, EntityItemProperties& properties) { + properties.copyFromScriptValue(object, false); } +void EntityItemPropertiesFromScriptValueHonorReadOnly(const QScriptValue &object, EntityItemProperties& properties) { + properties.copyFromScriptValue(object, true); +} + + // TODO: Implement support for edit packets that can span an MTU sized buffer. We need to implement a mechanism for the // encodeEntityEditPacket() method to communicate the the caller which properties couldn't fit in the buffer. Similar // to how we handle this in the Octree streaming case. diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 49fd206f93..8245cf0b6a 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -63,7 +63,7 @@ public: void setType(EntityTypes::EntityType type) { _type = type; } virtual QScriptValue copyToScriptValue(QScriptEngine* engine, bool skipDefaults) const; - virtual void copyFromScriptValue(const QScriptValue& object); + virtual void copyFromScriptValue(const QScriptValue& object, bool honorReadOnly); // editing related features supported by all entities quint64 getLastEdited() const { return _lastEdited; } @@ -218,7 +218,8 @@ private: Q_DECLARE_METATYPE(EntityItemProperties); QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties); QScriptValue EntityItemNonDefaultPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties); -void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemProperties& properties); +void EntityItemPropertiesFromScriptValueIgnoreReadOnly(const QScriptValue &object, EntityItemProperties& properties); +void EntityItemPropertiesFromScriptValueHonorReadOnly(const QScriptValue &object, EntityItemProperties& properties); // define these inline here so the macros work diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 54d2ea705e..579ec2a984 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -360,7 +360,7 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra quuidFromScriptValue(entityIDValue, value.entityID); QScriptValue entityPropertiesValue = object.property("properties"); if (entityPropertiesValue.isValid()) { - EntityItemPropertiesFromScriptValue(entityPropertiesValue, value.properties); + EntityItemPropertiesFromScriptValueHonorReadOnly(entityPropertiesValue, value.properties); } value.distance = object.property("distance").toVariant().toFloat(); diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 5eec93e8f5..937472820e 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -1055,7 +1055,7 @@ bool EntityTree::readFromMap(QVariantMap& map) { QVariantMap entityMap = entityVariant.toMap(); QScriptValue entityScriptValue = variantMapToScriptValue(entityMap, scriptEngine); EntityItemProperties properties; - EntityItemPropertiesFromScriptValue(entityScriptValue, properties); + EntityItemPropertiesFromScriptValueIgnoreReadOnly(entityScriptValue, properties); EntityItemID entityItemID; if (entityMap.contains("id")) { diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index d53d29e444..adc2040b8a 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -2096,7 +2096,15 @@ void Octree::writeToJSONFile(const char* fileName, OctreeElement* element) { top = _rootElement; } + // include the "bitstream" version + PacketType expectedType = expectedDataPacketType(); + PacketVersion expectedVersion = versionForPacketType(expectedType); + entityDescription["Version"] = (int) expectedVersion; + + // store the entity data bool entityDescriptionSuccess = writeToMap(entityDescription, top, true); + + // convert the QVariantMap to JSON if (entityDescriptionSuccess && persistFile.open(QIODevice::WriteOnly)) { persistFile.write(QJsonDocument::fromVariant(entityDescription).toJson()); } else { diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 91a4e3c397..30c3fbe8e4 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -318,7 +318,7 @@ void ScriptEngine::init() { registerAvatarTypes(this); registerAudioMetaTypes(this); - qScriptRegisterMetaType(this, EntityItemPropertiesToScriptValue, EntityItemPropertiesFromScriptValue); + qScriptRegisterMetaType(this, EntityItemPropertiesToScriptValue, EntityItemPropertiesFromScriptValueHonorReadOnly); qScriptRegisterMetaType(this, EntityItemIDtoScriptValue, EntityItemIDfromScriptValue); qScriptRegisterMetaType(this, RayToEntityIntersectionResultToScriptValue, RayToEntityIntersectionResultFromScriptValue); qScriptRegisterSequenceMetaType>(this); From 6e2378e676ab5590dcd40826780a0cd76a4bc5dd Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Fri, 29 May 2015 16:19:41 -0700 Subject: [PATCH 21/72] Sound parameter tweaks. --- libraries/entities-renderer/src/EntityTreeRenderer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index dea184087b..ce9689aa18 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -1133,7 +1133,7 @@ void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityT const float energy = mass * linearVelocity * linearVelocity / 2.0f; const glm::vec3 position = collision.contactPoint; const float COLLISION_ENERGY_AT_FULL_VOLUME = 0.5f; - const float COLLISION_MINIMUM_VOLUME = 0.001f; + const float COLLISION_MINIMUM_VOLUME = 0.005f; const float energyFactorOfFull = fmin(1.0f, energy / COLLISION_ENERGY_AT_FULL_VOLUME); if (energyFactorOfFull < COLLISION_MINIMUM_VOLUME) { return; @@ -1149,7 +1149,7 @@ void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityT } // This is a hack. Quiet sound aren't really heard at all, so we compress everything to the range [1-c, 1], if we play it all. - const float COLLISION_SOUND_COMPRESSION_RANGE = 0.7f; + const float COLLISION_SOUND_COMPRESSION_RANGE = 1.0f; // This section could be removed when the value is 1, but let's see how it goes. float volume = energyFactorOfFull; volume = (volume * COLLISION_SOUND_COMPRESSION_RANGE) + (1.0f - COLLISION_SOUND_COMPRESSION_RANGE); @@ -1180,10 +1180,11 @@ void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, cons return; } // Don't respond to small continuous contacts. - const float COLLISION_MINUMUM_PENETRATION = 0.005f; + const float COLLISION_MINUMUM_PENETRATION = 0.002f; if ((collision.type != CONTACT_EVENT_TYPE_START) && (glm::length(collision.penetration) < COLLISION_MINUMUM_PENETRATION)) { return; } + qCDebug(entitiesrenderer) << "*" << collision.type << glm::length(collision.penetration); // See if we should play sounds EntityTree* entityTree = static_cast(_tree); From 9c56f6270e4e704dd51ccc31abafa75ad96b2ed8 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Fri, 29 May 2015 16:21:57 -0700 Subject: [PATCH 22/72] Remove debug print. --- libraries/entities-renderer/src/EntityTreeRenderer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index ce9689aa18..8f034409ae 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -1184,7 +1184,6 @@ void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, cons if ((collision.type != CONTACT_EVENT_TYPE_START) && (glm::length(collision.penetration) < COLLISION_MINUMUM_PENETRATION)) { return; } - qCDebug(entitiesrenderer) << "*" << collision.type << glm::length(collision.penetration); // See if we should play sounds EntityTree* entityTree = static_cast(_tree); From 4c83c6918d2682caad29b55272bcef445fbd6e11 Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Fri, 29 May 2015 16:44:16 -0700 Subject: [PATCH 23/72] fixed avatar billboards not displaying --- interface/src/Application.cpp | 19 +++++++++++++------ interface/src/Application.h | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 877b5ed931..d4f87056cd 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3103,20 +3103,27 @@ PickRay Application::computePickRay(float x, float y) const { QImage Application::renderAvatarBillboard() { auto primaryFramebuffer = DependencyManager::get()->getPrimaryFramebuffer(); glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFramebuffer)); - + + // clear the alpha channel so the background is transparent + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE); + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); + // the "glow" here causes an alpha of one Glower glower; - + const int BILLBOARD_SIZE = 64; renderRearViewMirror(QRect(0, _glWidget->getDeviceHeight() - BILLBOARD_SIZE, BILLBOARD_SIZE, BILLBOARD_SIZE), true); - + QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32); glReadPixels(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE, GL_BGRA, GL_UNSIGNED_BYTE, image.bits()); - + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glBindFramebuffer(GL_FRAMEBUFFER, 0); - + return image; } @@ -3160,7 +3167,7 @@ const ViewFrustum* Application::getDisplayViewFrustum() const { return &_displayViewFrustum; } -void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs::RenderSide renderSide) { +void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, bool billboard, RenderArgs::RenderSide renderSide) { activeRenderingThread = QThread::currentThread(); PROFILE_RANGE(__FUNCTION__); PerformanceTimer perfTimer("display"); diff --git a/interface/src/Application.h b/interface/src/Application.h index 2226c97b99..b6efb6420b 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -270,7 +270,7 @@ public: QImage renderAvatarBillboard(); - void displaySide(Camera& whichCamera, bool selfAvatarOnly = false, RenderArgs::RenderSide renderSide = RenderArgs::MONO); + void displaySide(Camera& whichCamera, bool selfAvatarOnly = false, bool billboard = false, RenderArgs::RenderSide renderSide = RenderArgs::MONO); /// Stores the current modelview matrix as the untranslated view matrix to use for transforms and the supplied vector as /// the view matrix translation. From c19115a4852b870cf7a6f994870aabe21f4f677f Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Fri, 29 May 2015 16:53:01 -0700 Subject: [PATCH 24/72] actually fixed billboard --- interface/src/Application.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d4f87056cd..0db28af77f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3383,7 +3383,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, bool billb false, selfAvatarOnly); } - { + if (!billboard) { DependencyManager::get()->setAmbientLightMode(getRenderAmbientLight()); auto skyStage = DependencyManager::get()->getSkyStage(); DependencyManager::get()->setGlobalLight(skyStage->getSunLight()->getDirection(), skyStage->getSunLight()->getColor(), skyStage->getSunLight()->getIntensity(), skyStage->getSunLight()->getAmbientIntensity()); @@ -3586,7 +3586,7 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { // render rear mirror view glPushMatrix(); - displaySide(_mirrorCamera, true); + displaySide(_mirrorCamera, true, billboard); glPopMatrix(); if (!billboard) { From 7d5dd278a19c36d57a819dbb953b8d186a349f4b Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Fri, 29 May 2015 16:54:40 -0700 Subject: [PATCH 25/72] adding unpacking --- .../src/RenderableLineEntityItem.cpp | 4 +-- .../entities/src/EntityItemProperties.cpp | 8 ++--- libraries/entities/src/LineEntityItem.cpp | 7 +++-- libraries/octree/src/OctreePacketData.cpp | 29 ++++++++++++++++--- libraries/octree/src/OctreePacketData.h | 6 ++-- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 63cd7f0234..f5e84a6bfa 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -45,8 +45,8 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glm::vec3 p1 = {0, 0, 0}; glm::vec3 p2 = {1, 1, 0}; points<updateVertices(_lineVerticesID, getLinePoints(), lineColor); - geometryCache->updateVertices(_lineVerticesID, points, lineColor); + geometryCache->updateVertices(_lineVerticesID, getLinePoints(), lineColor); +// geometryCache->updateVertices(_lineVerticesID, points, lineColor); geometryCache->renderVertices(gpu::LINE_STRIP, _lineVerticesID); glPopMatrix(); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 4a747aeea3..e0b200cdd8 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -753,9 +753,8 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem } if(properties.getType() == EntityTypes::Line){ - qDebug()<<"****** LINE WIDTH!!!!!!!!!!!!!!! **********" << properties.getLineWidth(); APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, properties.getLineWidth()); -// APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, properties.getLinePoints()); + APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, properties.getLinePoints()); } APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, properties.getMarketplaceID()); @@ -993,10 +992,8 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int } if(properties.getType() == EntityTypes::Line) { - qDebug()<<"READING LINE ENTITY"; READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_WIDTH, float, setLineWidth); - qDebug()<<"width: "<< properties._lineWidth; -// READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_POINTS, QVector, setLinePoints); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_POINTS, QVector, setLinePoints); } READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MARKETPLACE_ID, QString, setMarketplaceID); @@ -1105,6 +1102,7 @@ void EntityItemProperties::markAllChanged() { _sourceUrlChanged = true; _lineWidthChanged = true; + _linePointsChanged = true; } /// The maximum bounding cube for the entity, independent of it's rotation. diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index 5806ca4c57..167b64bde2 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -45,13 +45,14 @@ EntityItemProperties LineEntityItem::getProperties() const { EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class - COPY_ENTITY_PROPERTY_TO_PROPERTIES(linePoints, getLinePoints); properties._color = getXColor(); properties._colorChanged = false; properties._lineWidth = getLineWidth(); properties._lineWidthChanged = false; + + COPY_ENTITY_PROPERTY_TO_PROPERTIES(linePoints, getLinePoints); properties._glowLevel = getGlowLevel(); @@ -91,7 +92,7 @@ int LineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor); READ_ENTITY_PROPERTY(PROP_LINE_WIDTH, float, setLineWidth); -// READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector, setLinePoints); + READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector, setLinePoints); return bytesRead; @@ -103,6 +104,7 @@ EntityPropertyFlags LineEntityItem::getEntityProperties(EncodeBitstreamParams& p EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); requestedProperties += PROP_COLOR; requestedProperties += PROP_LINE_WIDTH; + requestedProperties += PROP_LINE_POINTS; return requestedProperties; } @@ -118,6 +120,7 @@ void LineEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, getLineWidth()); + APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, getLinePoints()); } void LineEntityItem::debugDump() const { diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index 4f7d89492b..05c7e2ee5e 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -325,6 +325,7 @@ bool OctreePacketData::appendValue(uint8_t value) { bool OctreePacketData::appendValue(uint16_t value) { const unsigned char* data = (const unsigned char*)&value; + int length = sizeof(value); bool success = append(data, length); if (success) { @@ -381,12 +382,19 @@ bool OctreePacketData::appendValue(const glm::vec3& value) { } bool OctreePacketData::appendValue(const QVector& value){ - const unsigned char* data = (const unsigned char*)&value; - int length = sizeof(value); - bool success = append(data, length); - if (success){ + const unsigned char* data = (const unsigned char*)value.data(); + uint16_t qVecSize = (uint16_t)value.size(); + int length = qVecSize * sizeof(glm::vec3); + const unsigned char* sizePointer = (const unsigned char*)&qVecSize; + bool success = append(sizePointer, sizeof(uint16_t)); + if(success){ + _bytesOfValues += qVecSize; + _totalBytesOfValues += qVecSize; + success = append(data, length); + if (success){ _bytesOfValues += length; _totalBytesOfValues += length; + } } return success; } @@ -462,6 +470,9 @@ 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; @@ -585,3 +596,13 @@ int OctreePacketData::uppackDataFromBytes(const unsigned char* dataBytes, xColor result.blue = dataBytes[BLUE_INDEX]; return sizeof(rgbColor); } + +int OctreePacketData::uppackDataFromBytes(const unsigned char *dataBytes, QVector& result){ + uint16_t length; + memcpy(&length, dataBytes, sizeof(length)); + dataBytes+= sizeof(length); + qDebug()<<"size of LENGTH: "<& result) {memcpy(&result, dataBytes, sizeof(result)); return sizeof(result);} static int uppackDataFromBytes(const unsigned char* dataBytes, bool& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } static int uppackDataFromBytes(const unsigned char* dataBytes, quint64& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } static int uppackDataFromBytes(const unsigned char* dataBytes, uint32_t& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } @@ -244,7 +244,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, QVector& result); private: /// appends raw bytes, might fail if byte would cause packet to be too large From 96a40bd673f41f0dfc114e1cc29e5aa714a70050 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 29 May 2015 18:50:26 -0700 Subject: [PATCH 26/72] basic collisions with cubic polyvoxes --- examples/voxels.js | 4 +- .../src/RenderablePolyVoxEntityItem.cpp | 159 ++++++++++++++++-- .../src/RenderablePolyVoxEntityItem.h | 13 +- .../entities/src/EntityScriptingInterface.cpp | 37 ++++ .../entities/src/EntityScriptingInterface.h | 1 + libraries/entities/src/PolyVoxEntityItem.cpp | 5 + libraries/entities/src/PolyVoxEntityItem.h | 4 +- libraries/shared/src/ShapeInfo.h | 3 +- 8 files changed, 201 insertions(+), 25 deletions(-) diff --git a/examples/voxels.js b/examples/voxels.js index e274f1c4cc..351e723a5b 100644 --- a/examples/voxels.js +++ b/examples/voxels.js @@ -15,9 +15,9 @@ function mousePressEvent(event) { for (var i = 0; i < ids.length; i++) { var id = ids[i]; if (controlHeld) { - Entities.setVoxelSphere(id, intersection.intersection, 1.2, 0); + Entities.setVoxelSphere(id, intersection.intersection, 0.5, 0); } else { - Entities.setVoxelSphere(id, intersection.intersection, 1.2, 255); + Entities.setVoxelSphere(id, intersection.intersection, 0.5, 255); } } } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 977a6511c8..9e6d512dc3 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -38,12 +38,22 @@ EntityItemPointer RenderablePolyVoxEntityItem::factory(const EntityItemID& entit return EntityItemPointer(new RenderablePolyVoxEntityItem(entityID, properties)); } +RenderablePolyVoxEntityItem::RenderablePolyVoxEntityItem(const EntityItemID& entityItemID, + const EntityItemProperties& properties) : + PolyVoxEntityItem(entityItemID, properties) { + setVoxelVolumeSize(_voxelVolumeSize); + + model::Mesh* mesh = new model::Mesh(); + model::MeshPointer meshPtr(mesh); + _modelGeometry.setMesh(meshPtr); +} + + RenderablePolyVoxEntityItem::~RenderablePolyVoxEntityItem() { delete _volData; } void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) { - if (_volData && voxelVolumeSize == _voxelVolumeSize) { return; } @@ -83,12 +93,32 @@ glm::mat4 RenderablePolyVoxEntityItem::voxelToWorldMatrix() const { return translation * rotation * centerToCorner; } + +glm::mat4 RenderablePolyVoxEntityItem::voxelToLocalMatrix() const { + glm::vec3 scale = _dimensions / _voxelVolumeSize; // meters / voxel-units + glm::mat4 scaled = glm::scale(glm::mat4(), scale); + glm::mat4 centerToCorner = glm::translate(scaled, _voxelVolumeSize / -2.0f); + return centerToCorner; +} + glm::mat4 RenderablePolyVoxEntityItem::worldToVoxelMatrix() const { glm::mat4 worldToModelMatrix = glm::inverse(voxelToWorldMatrix()); return worldToModelMatrix; } +void RenderablePolyVoxEntityItem::setAll(uint8_t toValue) { + // XXX a volume that is all "on" has no mesh. make a different call for this nearly-all code: + for (int z = 1; z < _volData->getDepth() - 1; z++) { + for (int y = 1; y < _volData->getHeight() - 1; y++) { + for (int x = 1; x < _volData->getWidth() - 1; x++) { + _volData->setVoxelAt(x, y, z, toValue); + } + } + } + compressVolumeData(); +} + void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue) { // This three-level for loop iterates over every voxel in the volume for (int z = 0; z < _volData->getDepth(); z++) { @@ -106,7 +136,6 @@ void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radi } } compressVolumeData(); - _needsModelReload = true; } void RenderablePolyVoxEntityItem::setSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords, uint8_t toValue) { @@ -119,11 +148,6 @@ void RenderablePolyVoxEntityItem::setSphere(glm::vec3 centerWorldCoords, float r } void RenderablePolyVoxEntityItem::getModel() { - if (!_volData) { - // this will cause the allocation of _volData - setVoxelVolumeSize(_voxelVolumeSize); - } - // A mesh object to hold the result of surface extraction PolyVox::SurfaceMesh polyVoxMesh; @@ -143,24 +167,25 @@ void RenderablePolyVoxEntityItem::getModel() { } // convert PolyVox mesh to a Sam mesh - model::Mesh* mesh = new model::Mesh(); - model::MeshPointer meshPtr(mesh); + auto mesh = _modelGeometry.getMesh(); const std::vector& vecIndices = polyVoxMesh.getIndices(); auto indexBuffer = new gpu::Buffer(vecIndices.size() * sizeof(uint32_t), (gpu::Byte*)vecIndices.data()); auto indexBufferPtr = gpu::BufferPointer(indexBuffer); - mesh->setIndexBuffer(gpu::BufferView(indexBufferPtr, gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::RAW))); + auto indexBufferView = new gpu::BufferView(indexBufferPtr, gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::RAW)); + mesh->setIndexBuffer(*indexBufferView); const std::vector& vecVertices = polyVoxMesh.getVertices(); auto vertexBuffer = new gpu::Buffer(vecVertices.size() * sizeof(PolyVox::PositionMaterialNormal), (gpu::Byte*)vecVertices.data()); auto vertexBufferPtr = gpu::BufferPointer(vertexBuffer); - mesh->setVertexBuffer(gpu::BufferView(vertexBufferPtr, - 0, - vertexBufferPtr->getSize() - sizeof(float) * 3, - sizeof(PolyVox::PositionMaterialNormal), - gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); + auto vertexBufferView = new gpu::BufferView(vertexBufferPtr, + 0, + vertexBufferPtr->getSize() - sizeof(float) * 3, + sizeof(PolyVox::PositionMaterialNormal), + gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)); + mesh->setVertexBuffer(*vertexBufferView); mesh->addAttribute(gpu::Stream::NORMAL, gpu::BufferView(vertexBufferPtr, sizeof(float) * 3, @@ -176,7 +201,6 @@ void RenderablePolyVoxEntityItem::getModel() { qDebug() << "---- vecIndices.size() =" << vecIndices.size(); qDebug() << "---- vecVertices.size() =" << vecVertices.size(); - _modelGeometry.setMesh(meshPtr); _needsModelReload = false; } @@ -310,6 +334,9 @@ void RenderablePolyVoxEntityItem::compressVolumeData() { // revert decompressVolumeData(); } + + _dirtyFlags |= EntityItem::DIRTY_SHAPE | EntityItem::DIRTY_MASS; + _needsModelReload = true; } @@ -329,8 +356,104 @@ void RenderablePolyVoxEntityItem::decompressVolumeData() { } } - _needsModelReload = true; - qDebug() << "--------------- voxel decompress ---------------"; qDebug() << "raw-size =" << rawSize << " compressed-size =" << _voxelData.size(); + + _dirtyFlags |= EntityItem::DIRTY_SHAPE | EntityItem::DIRTY_MASS; + _needsModelReload = true; + getModel(); +} + +bool RenderablePolyVoxEntityItem::isReadyToComputeShape() { + qDebug() << "RenderablePolyVoxEntityItem::isReadyToComputeShape" << (!_needsModelReload); + + if (_needsModelReload) { + return false; + } + + for (int z = 0; z < _volData->getDepth(); z++) { + for (int y = 0; y < _volData->getHeight(); y++) { + for (int x = 0; x < _volData->getWidth(); x++) { + if (_volData->getVoxelAt(x, y, z) > 0) { + return true; + } + } + } + } + + return false; +} + +void RenderablePolyVoxEntityItem::computeShapeInfo(ShapeInfo& info) { + qDebug() << "RenderablePolyVoxEntityItem::computeShapeInfo"; + ShapeType type = getShapeType(); + if (type != SHAPE_TYPE_COMPOUND) { + qDebug() << "RenderablePolyVoxEntityItem::computeShapeInfo NOT COMPOUND"; + PolyVoxEntityItem::computeShapeInfo(info); + info.setParams(type, 0.5f * getDimensions()); + } else { + _points.clear(); + unsigned int i = 0; + + glm::mat4 wToM = voxelToLocalMatrix(); + + AABox box; + + for (int z = 0; z < _volData->getDepth(); z++) { + for (int y = 0; y < _volData->getHeight(); y++) { + for (int x = 0; x < _volData->getWidth(); x++) { + if (_volData->getVoxelAt(x, y, z) > 0) { + QVector pointsInPart; + + float offL = -0.5f; + float offH = 0.5f; + + // XXX I don't really understand why this make it line up. + // float offL = -1.0f; + // float offH = 0.0f; + + + glm::vec3 p000 = glm::vec3(wToM * glm::vec4(x + offL, y + offL, z + offL, 1.0f)); + glm::vec3 p001 = glm::vec3(wToM * glm::vec4(x + offL, y + offL, z + offH, 1.0f)); + glm::vec3 p010 = glm::vec3(wToM * glm::vec4(x + offL, y + offH, z + offL, 1.0f)); + glm::vec3 p011 = glm::vec3(wToM * glm::vec4(x + offL, y + offH, z + offH, 1.0f)); + glm::vec3 p100 = glm::vec3(wToM * glm::vec4(x + offH, y + offL, z + offL, 1.0f)); + glm::vec3 p101 = glm::vec3(wToM * glm::vec4(x + offH, y + offL, z + offH, 1.0f)); + glm::vec3 p110 = glm::vec3(wToM * glm::vec4(x + offH, y + offH, z + offL, 1.0f)); + glm::vec3 p111 = glm::vec3(wToM * glm::vec4(x + offH, y + offH, z + offH, 1.0f)); + + box += p000; + box += p001; + box += p010; + box += p011; + box += p100; + box += p101; + box += p110; + box += p111; + + pointsInPart << p000; + pointsInPart << p001; + pointsInPart << p010; + pointsInPart << p011; + pointsInPart << p100; + pointsInPart << p101; + pointsInPart << p110; + pointsInPart << p111; + + // add next convex hull + QVector newMeshPoints; + _points << newMeshPoints; + // add points to the new convex hull + _points[i++] << pointsInPart; + } + } + } + } + + + glm::vec3 collisionModelDimensions = box.getDimensions(); + QByteArray b64 = _voxelData.toBase64(); + info.setParams(type, collisionModelDimensions, QString(b64)); + info.setConvexHulls(_points); + } } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index b04b32996b..9623fab4f9 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -21,8 +21,7 @@ class RenderablePolyVoxEntityItem : public PolyVoxEntityItem { public: static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties); - RenderablePolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : - PolyVoxEntityItem(entityItemID, properties) { } + RenderablePolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); virtual ~RenderablePolyVoxEntityItem(); @@ -47,14 +46,22 @@ public: virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize); glm::mat4 voxelToWorldMatrix() const; + glm::mat4 voxelToLocalMatrix() const; glm::mat4 worldToVoxelMatrix() const; + + virtual bool isReadyToComputeShape(); + virtual void computeShapeInfo(ShapeInfo& info); + + // coords are in voxel-volume space virtual void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue); // coords are in world-space virtual void setSphere(glm::vec3 center, float radius, uint8_t toValue); + virtual void setAll(uint8_t toValue); + private: void compressVolumeData(); void decompressVolumeData(); @@ -62,6 +69,8 @@ private: PolyVox::SimpleVolume* _volData = nullptr; model::Geometry _modelGeometry; bool _needsModelReload = true; + + QVector> _points; // XXX }; diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 579ec2a984..fe77e0799c 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -420,3 +420,40 @@ bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& c queueEntityMessage(PacketTypeEntityEdit, entityID, properties); return true; } + + +bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { + if (!_entityTree) { + return false; + } + + EntityItemPointer entity = static_cast(_entityTree->findEntityByEntityItemID(entityID)); + if (!entity) { + qCDebug(entities) << "EntityScriptingInterface::setVoxelSphere no entity with ID" << entityID; + return false; + } + + EntityTypes::EntityType entityType = entity->getType(); + if (entityType != EntityTypes::PolyVox) { + return false; + } + + auto now = usecTimestampNow(); + + PolyVoxEntityItem* polyVoxEntity = static_cast(entity.get()); + _entityTree->lockForWrite(); + polyVoxEntity->setAll(value); + entity->setLastEdited(now); + entity->setLastBroadcast(now); + _entityTree->unlock(); + + _entityTree->lockForRead(); + EntityItemProperties properties = entity->getProperties(); + _entityTree->unlock(); + + properties.setVoxelDataDirty(); + properties.setLastEdited(now); + + queueEntityMessage(PacketTypeEntityEdit, entityID, properties); + return true; +} diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 6c2dc06579..421875feef 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -118,6 +118,7 @@ public slots: Q_INVOKABLE bool getSendPhysicsUpdates() const; Q_INVOKABLE bool setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value); + Q_INVOKABLE bool setAllVoxels(QUuid entityID, int value); Q_INVOKABLE void dumpTree() const; diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index a46fdb2682..fd552f2a20 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -115,3 +115,8 @@ void PolyVoxEntityItem::debugDump() const { qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); } + +// virtual +ShapeType PolyVoxEntityItem::getShapeType() const { + return SHAPE_TYPE_COMPOUND; +} diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 53675e6efa..472e72ead0 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -51,7 +51,7 @@ class PolyVoxEntityItem : public EntityItem { _color[BLUE_INDEX] = value.blue; } - virtual ShapeType getShapeType() const { return SHAPE_TYPE_POLYVOX; } + virtual ShapeType getShapeType() const; // never have a ray intersection pick a PolyVoxEntityItem. virtual bool supportsDetailedRayIntersection() const { return true; } @@ -88,6 +88,8 @@ class PolyVoxEntityItem : public EntityItem { // coords are in world-space virtual void setSphere(glm::vec3 center, float radius, uint8_t toValue) {} + virtual void setAll(uint8_t toValue) {} + protected: rgbColor _color; glm::vec3 _voxelVolumeSize; // this is always 3 bytes diff --git a/libraries/shared/src/ShapeInfo.h b/libraries/shared/src/ShapeInfo.h index e2a77fbba2..a3fbe55f36 100644 --- a/libraries/shared/src/ShapeInfo.h +++ b/libraries/shared/src/ShapeInfo.h @@ -35,8 +35,7 @@ enum ShapeType { SHAPE_TYPE_CYLINDER_X, SHAPE_TYPE_CYLINDER_Y, SHAPE_TYPE_CYLINDER_Z, - SHAPE_TYPE_LINE, - SHAPE_TYPE_POLYVOX + SHAPE_TYPE_LINE }; class ShapeInfo { From cb72b620cf62b36ab28a85f32ec0a48a845fe312 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Fri, 29 May 2015 19:42:07 -0700 Subject: [PATCH 27/72] printing bytes out correctly --- libraries/octree/src/OctreePacketData.cpp | 64 ++++++++++++++------ libraries/shared/src/RegisteredMetaTypes.cpp | 1 + 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index 05c7e2ee5e..6afe1c0c0f 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -382,21 +382,47 @@ bool OctreePacketData::appendValue(const glm::vec3& value) { } bool OctreePacketData::appendValue(const QVector& value){ - const unsigned char* data = (const unsigned char*)value.data(); - uint16_t qVecSize = (uint16_t)value.size(); - int length = qVecSize * sizeof(glm::vec3); - const unsigned char* sizePointer = (const unsigned char*)&qVecSize; - bool success = append(sizePointer, sizeof(uint16_t)); - if(success){ - _bytesOfValues += qVecSize; - _totalBytesOfValues += qVecSize; - success = append(data, length); - if (success){ - _bytesOfValues += length; - _totalBytesOfValues += length; - } + +// const unsigned char* data = (const unsigned char*)value.data(); +// uint16_t qVecSize = (uint16_t)value.size(); +// +// int length = qVecSize * sizeof(glm::vec3); +// const unsigned char* sizePointer = (const unsigned char*)&qVecSize; +// bool success = append(sizePointer, sizeof(uint16_t)); +// if(success){ +// _bytesOfValues += qVecSize; +// _totalBytesOfValues += qVecSize; +// success = append(data, length); +// if (success){ +// _bytesOfValues += length; +// _totalBytesOfValues += length; +// } +// } +// return success; + +// const unsigned char* data = (const unsigned char*)value.data(); +// int qVecSize = value.size(); +// +// int length = qVecSize * sizeof(glm::vec3); +// +// bool success = append(data, length); +// if (success){ +// _bytesOfValues += length; +// _totalBytesOfValues += length; +// } +// return success; + qDebug("YAAAR"); + int qVecSize = value.size() * sizeof(glm::vec3); + QByteArray myArray('', qVecSize ); + const char* data = (const char*)value.data(); + for(int i = 0; i < qVecSize; i+=sizeof(float)){ + float num; + memcpy(&num, data, sizeof(float)); + qDebug()<<"NUM***"<& result){ - uint16_t length; - memcpy(&length, dataBytes, sizeof(length)); - dataBytes+= sizeof(length); - qDebug()<<"size of LENGTH: "<(); static int collisionMetaTypeId = qRegisterMetaType(); + void registerMetaTypes(QScriptEngine* engine) { qScriptRegisterMetaType(engine, vec4toScriptValue, vec4FromScriptValue); qScriptRegisterMetaType(engine, vec3toScriptValue, vec3FromScriptValue); From c5a0dd72ec0f0f11ffebc8697659495c44d77b05 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 30 May 2015 18:13:57 -0700 Subject: [PATCH 28/72] keep track of number of non-zero voxels, use this information when deciding on shape-type --- .../src/RenderablePolyVoxEntityItem.cpp | 181 ++++++++++-------- .../src/RenderablePolyVoxEntityItem.h | 5 +- 2 files changed, 103 insertions(+), 83 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 4941acdf36..389a5eac4f 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -70,6 +70,7 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) PolyVox::Vector3DInt32 highCorner(_voxelVolumeSize[0] - 1, // -1 because these corners are inclusive _voxelVolumeSize[1] - 1, _voxelVolumeSize[2] - 1); + _onCount = 0; _volData = new PolyVox::SimpleVolume(PolyVox::Region(lowCorner, highCorner)); compressVolumeData(); @@ -117,12 +118,30 @@ glm::mat4 RenderablePolyVoxEntityItem::worldToVoxelMatrix() const { } +void RenderablePolyVoxEntityItem::updateOnCount(int x, int y, int z, uint8_t toValue) { + // keep _onCount up to date + uint8_t uVoxelValue = _volData->getVoxelAt(x, y, z); + if (toValue != 0) { + if (uVoxelValue == 0) { + _onCount++; + } + } else { + // toValue == 0 + if (uVoxelValue != 0) { + _onCount--; + assert(_onCount >= 0); + } + } +} + + void RenderablePolyVoxEntityItem::setAll(uint8_t toValue) { // XXX a volume that is all "on" has no mesh. make a different call for this nearly-all code: for (int z = 1; z < _volData->getDepth() - 1; z++) { for (int y = 1; y < _volData->getHeight() - 1; y++) { for (int x = 1; x < _volData->getWidth() - 1; x++) { - _volData->setVoxelAt(x, y, z, toValue); + updateOnCount(x, y, z, toValue); + _volData->setVoxelAt(x, y, z, toValue); } } } @@ -140,6 +159,7 @@ void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radi float fDistToCenter = glm::distance(pos, center); // If the current voxel is less than 'radius' units from the center then we make it solid. if (fDistToCenter <= radius) { + updateOnCount(x, y, z, toValue); _volData->setVoxelAt(x, y, z, toValue); } } @@ -361,6 +381,7 @@ void RenderablePolyVoxEntityItem::decompressVolumeData() { for (int y = 0; y < _volData->getHeight(); y++) { for (int x = 0; x < _volData->getWidth(); x++) { int uncompressedIndex = z * _volData->getHeight() * _volData->getWidth() + y * _volData->getWidth() + x; + updateOnCount(x, y, z, uncompressedData[uncompressedIndex]); _volData->setVoxelAt(x, y, z, uncompressedData[uncompressedIndex]); } } @@ -374,96 +395,92 @@ void RenderablePolyVoxEntityItem::decompressVolumeData() { getModel(); } +// virtual +ShapeType RenderablePolyVoxEntityItem::getShapeType() const { + if (_onCount > 0) { + return SHAPE_TYPE_COMPOUND; + } + return SHAPE_TYPE_NONE; +} + + bool RenderablePolyVoxEntityItem::isReadyToComputeShape() { - qDebug() << "RenderablePolyVoxEntityItem::isReadyToComputeShape" << (!_needsModelReload); - if (_needsModelReload) { - getModel(); + return false; } - for (int z = 0; z < _volData->getDepth(); z++) { - for (int y = 0; y < _volData->getHeight(); y++) { - for (int x = 0; x < _volData->getWidth(); x++) { - if (_volData->getVoxelAt(x, y, z) > 0) { - return true; - } - } - } - } - - return false; + qDebug() << "RenderablePolyVoxEntityItem::isReadyToComputeShape" << (!_needsModelReload); + return true; } void RenderablePolyVoxEntityItem::computeShapeInfo(ShapeInfo& info) { qDebug() << "RenderablePolyVoxEntityItem::computeShapeInfo"; ShapeType type = getShapeType(); if (type != SHAPE_TYPE_COMPOUND) { - qDebug() << "RenderablePolyVoxEntityItem::computeShapeInfo NOT COMPOUND"; - PolyVoxEntityItem::computeShapeInfo(info); - info.setParams(type, 0.5f * getDimensions()); - } else { - _points.clear(); - unsigned int i = 0; - - glm::mat4 wToM = voxelToLocalMatrix(); - - AABox box; - - for (int z = 0; z < _volData->getDepth(); z++) { - for (int y = 0; y < _volData->getHeight(); y++) { - for (int x = 0; x < _volData->getWidth(); x++) { - if (_volData->getVoxelAt(x, y, z) > 0) { - QVector pointsInPart; - - float offL = -0.5f; - float offH = 0.5f; - - // XXX I don't really understand why this make it line up. - // float offL = -1.0f; - // float offH = 0.0f; - - - glm::vec3 p000 = glm::vec3(wToM * glm::vec4(x + offL, y + offL, z + offL, 1.0f)); - glm::vec3 p001 = glm::vec3(wToM * glm::vec4(x + offL, y + offL, z + offH, 1.0f)); - glm::vec3 p010 = glm::vec3(wToM * glm::vec4(x + offL, y + offH, z + offL, 1.0f)); - glm::vec3 p011 = glm::vec3(wToM * glm::vec4(x + offL, y + offH, z + offH, 1.0f)); - glm::vec3 p100 = glm::vec3(wToM * glm::vec4(x + offH, y + offL, z + offL, 1.0f)); - glm::vec3 p101 = glm::vec3(wToM * glm::vec4(x + offH, y + offL, z + offH, 1.0f)); - glm::vec3 p110 = glm::vec3(wToM * glm::vec4(x + offH, y + offH, z + offL, 1.0f)); - glm::vec3 p111 = glm::vec3(wToM * glm::vec4(x + offH, y + offH, z + offH, 1.0f)); - - box += p000; - box += p001; - box += p010; - box += p011; - box += p100; - box += p101; - box += p110; - box += p111; - - pointsInPart << p000; - pointsInPart << p001; - pointsInPart << p010; - pointsInPart << p011; - pointsInPart << p100; - pointsInPart << p101; - pointsInPart << p110; - pointsInPart << p111; - - // add next convex hull - QVector newMeshPoints; - _points << newMeshPoints; - // add points to the new convex hull - _points[i++] << pointsInPart; - } - } - } - } - - - glm::vec3 collisionModelDimensions = box.getDimensions(); - QByteArray b64 = _voxelData.toBase64(); - info.setParams(type, collisionModelDimensions, QString(b64)); - info.setConvexHulls(_points); + EntityItem::computeShapeInfo(info); + return; } + + _points.clear(); + unsigned int i = 0; + + glm::mat4 wToM = voxelToLocalMatrix(); + + AABox box; + + for (int z = 0; z < _volData->getDepth(); z++) { + for (int y = 0; y < _volData->getHeight(); y++) { + for (int x = 0; x < _volData->getWidth(); x++) { + if (_volData->getVoxelAt(x, y, z) > 0) { + QVector pointsInPart; + + float offL = -0.5f; + float offH = 0.5f; + + glm::vec3 p000 = glm::vec3(wToM * glm::vec4(x + offL, y + offL, z + offL, 1.0f)); + glm::vec3 p001 = glm::vec3(wToM * glm::vec4(x + offL, y + offL, z + offH, 1.0f)); + glm::vec3 p010 = glm::vec3(wToM * glm::vec4(x + offL, y + offH, z + offL, 1.0f)); + glm::vec3 p011 = glm::vec3(wToM * glm::vec4(x + offL, y + offH, z + offH, 1.0f)); + glm::vec3 p100 = glm::vec3(wToM * glm::vec4(x + offH, y + offL, z + offL, 1.0f)); + glm::vec3 p101 = glm::vec3(wToM * glm::vec4(x + offH, y + offL, z + offH, 1.0f)); + glm::vec3 p110 = glm::vec3(wToM * glm::vec4(x + offH, y + offH, z + offL, 1.0f)); + glm::vec3 p111 = glm::vec3(wToM * glm::vec4(x + offH, y + offH, z + offH, 1.0f)); + + box += p000; + box += p001; + box += p010; + box += p011; + box += p100; + box += p101; + box += p110; + box += p111; + + pointsInPart << p000; + pointsInPart << p001; + pointsInPart << p010; + pointsInPart << p011; + pointsInPart << p100; + pointsInPart << p101; + pointsInPart << p110; + pointsInPart << p111; + + // add next convex hull + QVector newMeshPoints; + _points << newMeshPoints; + // add points to the new convex hull + _points[i++] << pointsInPart; + } + } + } + } + + if (_points.isEmpty()) { + EntityItem::computeShapeInfo(info); + return; + } + + glm::vec3 collisionModelDimensions = box.getDimensions(); + QByteArray b64 = _voxelData.toBase64(); + info.setParams(type, collisionModelDimensions, QString(b64)); + info.setConvexHulls(_points); } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index b569d3d5b6..d659cc0e69 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -33,6 +33,7 @@ public: // _needsModelReload = true; } + void updateOnCount(int x, int y, int z, uint8_t new_value); void render(RenderArgs* args); virtual bool supportsDetailedRayIntersection() const { return true; } @@ -51,7 +52,7 @@ public: glm::mat4 voxelToLocalMatrix() const; glm::mat4 worldToVoxelMatrix() const; - + virtual ShapeType getShapeType() const; virtual bool isReadyToComputeShape(); virtual void computeShapeInfo(ShapeInfo& info); @@ -73,6 +74,8 @@ private: bool _needsModelReload = true; QVector> _points; // XXX + + int _onCount = 0; // how many non-zero voxels are in _volData }; From ad71d7b7a245a0904116bf8abc1e31e6a5143c91 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 30 May 2015 18:14:36 -0700 Subject: [PATCH 29/72] allow changing of voxel-volume-size with edit.js --- examples/edit.js | 29 +++++++++++++++++++ examples/html/entityProperties.html | 26 ++++++++++++++++- examples/libraries/entityPropertyDialogBox.js | 24 +++++++++++++++ examples/voxels.js | 13 +++++++-- 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/examples/edit.js b/examples/edit.js index 7983a49575..455b843868 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -139,6 +139,7 @@ var toolBar = (function () { newTextButton, newWebButton, newZoneButton, + newPolyVoxButton, browseMarketplaceButton; function initialize() { @@ -224,6 +225,15 @@ var toolBar = (function () { visible: false }); + newPolyVoxButton = toolBar.addTool({ + imageURL: toolIconUrl + "upload.svg", // XXX need a new icon + subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, + width: toolWidth, + height: toolHeight, + alpha: 0.9, + visible: false + }); + that.setActive(false); } @@ -266,6 +276,7 @@ var toolBar = (function () { toolBar.showTool(newTextButton, doShow); toolBar.showTool(newWebButton, doShow); toolBar.showTool(newZoneButton, doShow); + toolBar.showTool(newPolyVoxButton, doShow); }; var RESIZE_INTERVAL = 50; @@ -468,6 +479,24 @@ var toolBar = (function () { return true; } + if (newPolyVoxButton === toolBar.clicked(clickedOverlay)) { + var position = getPositionToCreateEntity(); + + if (position.x > 0 && position.y > 0 && position.z > 0) { + placingEntityID = Entities.addEntity({ + type: "PolyVox", + position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), + DEFAULT_DIMENSIONS), + dimensions: { x: 10, y: 10, z: 10 }, + voxelVolumeSize: {x:16, y:16, z:16}, + voxelSurfaceStyle: 1 + }); + } else { + print("Can't create PolyVox: would be out of bounds."); + } + return true; + } + return false; }; diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 7c214624c2..6b1fc113d4 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -354,6 +354,11 @@ var elZoneAtmosphereScatteringWavelengthsZ = document.getElementById("property-zone-atmosphere-scattering-wavelengths-z"); var elZoneAtmosphereHasStars = document.getElementById("property-zone-atmosphere-has-stars"); + var elPolyVoxSelections = document.querySelectorAll(".poly-vox-section"); + var elVoxelVolumeSizeX = document.getElementById("property-voxel-volume-size-x"); + var elVoxelVolumeSizeY = document.getElementById("property-voxel-volume-size-y"); + var elVoxelVolumeSizeZ = document.getElementById("property-voxel-volume-size-z"); + if (window.EventBridge !== undefined) { EventBridge.scriptEventReceived.connect(function(data) { @@ -588,7 +593,11 @@ elParticleEmitStrength.value = properties.emitStrength.toFixed(2); elParticleLocalGravity.value = properties.localGravity.toFixed(2); elParticleRadius.value = properties.particleRadius.toFixed(3); - } + } else if (properties.type == "PolyVox") { + elVoxelVolumeSizeX.value = properties.voxelVolumeSize.x.toFixed(2); + elVoxelVolumeSizeY.value = properties.voxelVolumeSize.y.toFixed(2); + elVoxelVolumeSizeZ.value = properties.voxelVolumeSize.z.toFixed(2); + } if (selected) { activeElement.focus(); @@ -832,6 +841,12 @@ elZoneAtmosphereScatteringWavelengthsZ.addEventListener('change', zoneAtmosphereScatterWavelengthsChangeFunction); elZoneAtmosphereHasStars.addEventListener('change', createEmitGroupCheckedPropertyUpdateFunction('atmosphere','hasStars')); + var voxelVolumeSizeChangeFunction = createEmitVec3PropertyUpdateFunction( + 'voxelVolumeSize', elVoxelVolumeSizeX, elVoxelVolumeSizeY, elVoxelVolumeSizeZ); + elVoxelVolumeSizeX.addEventListener('change', voxelVolumeSizeChangeFunction); + elVoxelVolumeSizeY.addEventListener('change', voxelVolumeSizeChangeFunction); + elVoxelVolumeSizeZ.addEventListener('change', voxelVolumeSizeChangeFunction); + elMoveSelectionToGrid.addEventListener("click", function() { EventBridge.emitWebEvent(JSON.stringify({ @@ -973,6 +988,15 @@ +
+
Voxel Volume Size
+
+
X
+
Y
+
Z
+
+
+
Rotation
diff --git a/examples/libraries/entityPropertyDialogBox.js b/examples/libraries/entityPropertyDialogBox.js index f9f8d57a51..567b6e3024 100644 --- a/examples/libraries/entityPropertyDialogBox.js +++ b/examples/libraries/entityPropertyDialogBox.js @@ -98,6 +98,21 @@ EntityPropertyDialogBox = (function () { index++; } + if (properties.type == "PolyVox") { + array.push({ label: "Shape Type:", value: properties.shapeType }); + index++; + + array.push({ label: "Voxel Space Size:", type: "header" }); + index++; + + array.push({ label: "X:", value: properties.voxelVolumeSize.x.toFixed(decimals) }); + index++; + array.push({ label: "Y:", value: properties.voxelVolumeSize.y.toFixed(decimals) }); + index++; + array.push({ label: "Z:", value: properties.voxelVolumeSize.z.toFixed(decimals) }); + index++; + } + array.push({ label: "Position:", type: "header" }); index++; array.push({ label: "X:", value: properties.position.x.toFixed(decimals) }); @@ -333,6 +348,15 @@ EntityPropertyDialogBox = (function () { properties.backgroundColor.blue = array[index++].value; } + if (properties.type == "PolyVox") { + properties.shapeType = array[index++].value; + + index++; // skip header + properties.voxelVolumeSize.x = array[index++].value; + properties.voxelVolumeSize.y = array[index++].value; + properties.voxelVolumeSize.z = array[index++].value; + } + index++; // skip header properties.position.x = array[index++].value; properties.position.y = array[index++].value; diff --git a/examples/voxels.js b/examples/voxels.js index 351e723a5b..fc9f6550f5 100644 --- a/examples/voxels.js +++ b/examples/voxels.js @@ -1,5 +1,6 @@ var controlHeld = false; +var shiftHeld = false; function mousePressEvent(event) { @@ -15,9 +16,11 @@ function mousePressEvent(event) { for (var i = 0; i < ids.length; i++) { var id = ids[i]; if (controlHeld) { - Entities.setVoxelSphere(id, intersection.intersection, 0.5, 0); + Entities.setVoxelSphere(id, intersection.intersection, 1.0, 0); + } else if (shiftHeld) { + Entities.setAllVoxels(id, 255); } else { - Entities.setVoxelSphere(id, intersection.intersection, 0.5, 255); + Entities.setVoxelSphere(id, intersection.intersection, 1.0, 255); } } } @@ -28,6 +31,9 @@ function keyPressEvent(event) { if (event.text == "CONTROL") { controlHeld = true; } + if (event.text == "SHIFT") { + shiftHeld = true; + } } @@ -35,6 +41,9 @@ function keyReleaseEvent(event) { if (event.text == "CONTROL") { controlHeld = false; } + if (event.text == "SHIFT") { + shiftHeld = false; + } } From f955cb45b2af42dd334a5474dc97a41daba6f20e Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 30 May 2015 18:14:54 -0700 Subject: [PATCH 30/72] keep track of number of non-zero voxels, use this information when deciding on shape-type --- libraries/entities/src/PolyVoxEntityItem.cpp | 6 ------ libraries/entities/src/PolyVoxEntityItem.h | 2 -- 2 files changed, 8 deletions(-) diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index fd552f2a20..a7f1128771 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -114,9 +114,3 @@ void PolyVoxEntityItem::debugDump() const { qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); } - - -// virtual -ShapeType PolyVoxEntityItem::getShapeType() const { - return SHAPE_TYPE_COMPOUND; -} diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 06abf7135d..467d41f3e1 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -41,8 +41,6 @@ class PolyVoxEntityItem : public EntityItem { ReadBitstreamToTreeParams& args, EntityPropertyFlags& propertyFlags, bool overwriteLocalData); - virtual ShapeType getShapeType() const; - // never have a ray intersection pick a PolyVoxEntityItem. virtual bool supportsDetailedRayIntersection() const { return true; } virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, From a3589788df19ed31245605b36b0afd978bc0fd90 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 30 May 2015 18:33:35 -0700 Subject: [PATCH 31/72] allow edit.js to change between cubic and marching-cubes surface extractor on polyvox entity-items. --- examples/html/entityProperties.html | 12 ++++++++++++ examples/libraries/entityPropertyDialogBox.js | 7 ++++--- .../src/RenderablePolyVoxEntityItem.cpp | 1 + libraries/entities/src/PolyVoxEntityItem.h | 3 ++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 6b1fc113d4..21e2e83136 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -358,6 +358,7 @@ var elVoxelVolumeSizeX = document.getElementById("property-voxel-volume-size-x"); var elVoxelVolumeSizeY = document.getElementById("property-voxel-volume-size-y"); var elVoxelVolumeSizeZ = document.getElementById("property-voxel-volume-size-z"); + var elVoxelSurfaceStyle = document.getElementById("property-voxel-surface-style"); if (window.EventBridge !== undefined) { @@ -597,6 +598,7 @@ elVoxelVolumeSizeX.value = properties.voxelVolumeSize.x.toFixed(2); elVoxelVolumeSizeY.value = properties.voxelVolumeSize.y.toFixed(2); elVoxelVolumeSizeZ.value = properties.voxelVolumeSize.z.toFixed(2); + elVoxelSurfaceStyle.value = properties.voxelSurfaceStyle; } if (selected) { @@ -846,6 +848,7 @@ elVoxelVolumeSizeX.addEventListener('change', voxelVolumeSizeChangeFunction); elVoxelVolumeSizeY.addEventListener('change', voxelVolumeSizeChangeFunction); elVoxelVolumeSizeZ.addEventListener('change', voxelVolumeSizeChangeFunction); + elVoxelSurfaceStyle.addEventListener('change', createEmitTextPropertyUpdateFunction('voxelSurfaceStyle')); elMoveSelectionToGrid.addEventListener("click", function() { @@ -994,6 +997,15 @@
X
Y
Z
+
+ +
Surface Extractor
+
+
diff --git a/examples/libraries/entityPropertyDialogBox.js b/examples/libraries/entityPropertyDialogBox.js index 567b6e3024..1b1a6a9c12 100644 --- a/examples/libraries/entityPropertyDialogBox.js +++ b/examples/libraries/entityPropertyDialogBox.js @@ -99,9 +99,6 @@ EntityPropertyDialogBox = (function () { } if (properties.type == "PolyVox") { - array.push({ label: "Shape Type:", value: properties.shapeType }); - index++; - array.push({ label: "Voxel Space Size:", type: "header" }); index++; @@ -111,6 +108,9 @@ EntityPropertyDialogBox = (function () { index++; array.push({ label: "Z:", value: properties.voxelVolumeSize.z.toFixed(decimals) }); index++; + + array.push({ label: "Surface Extractor", value: properties.voxelSurfaceStyle }); + index++; } array.push({ label: "Position:", type: "header" }); @@ -355,6 +355,7 @@ EntityPropertyDialogBox = (function () { properties.voxelVolumeSize.x = array[index++].value; properties.voxelVolumeSize.y = array[index++].value; properties.voxelVolumeSize.z = array[index++].value; + properties.voxelSurfaceStyle = array[index++].value; } index++; // skip header diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 389a5eac4f..97484f246f 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -188,6 +188,7 @@ void RenderablePolyVoxEntityItem::getModel() { surfaceExtractor.execute(); break; } + case PolyVoxEntityItem::SURFACE_EDGED_CUBIC: case PolyVoxEntityItem::SURFACE_CUBIC: { PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 467d41f3e1..530f073237 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -57,7 +57,8 @@ class PolyVoxEntityItem : public EntityItem { enum PolyVoxSurfaceStyle { SURFACE_MARCHING_CUBES, - SURFACE_CUBIC + SURFACE_CUBIC, + SURFACE_EDGED_CUBIC }; virtual void setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { _voxelSurfaceStyle = voxelSurfaceStyle; } From b9202ebfb62d41478167c5c5e676fe36c79099c9 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sun, 31 May 2015 09:14:59 -0700 Subject: [PATCH 32/72] added SURFACE_EDGED_CUBIC surface extractor which pads the outsides of the voxel-space with empty cells to change how the edges of the surface look --- examples/voxels.js | 4 +- .../src/RenderablePolyVoxEntityItem.cpp | 316 ++++++++++++------ .../src/RenderablePolyVoxEntityItem.h | 4 + libraries/entities/src/PolyVoxEntityItem.h | 3 + 4 files changed, 217 insertions(+), 110 deletions(-) diff --git a/examples/voxels.js b/examples/voxels.js index fc9f6550f5..5e4ea8df01 100644 --- a/examples/voxels.js +++ b/examples/voxels.js @@ -16,11 +16,11 @@ function mousePressEvent(event) { for (var i = 0; i < ids.length; i++) { var id = ids[i]; if (controlHeld) { - Entities.setVoxelSphere(id, intersection.intersection, 1.0, 0); + Entities.setVoxelSphere(id, intersection.intersection, 4.0, 0); } else if (shiftHeld) { Entities.setAllVoxels(id, 255); } else { - Entities.setVoxelSphere(id, intersection.intersection, 1.0, 255); + Entities.setVoxelSphere(id, intersection.intersection, 4.0, 255); } } } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 97484f246f..91d702e52b 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -41,11 +41,12 @@ EntityItemPointer RenderablePolyVoxEntityItem::factory(const EntityItemID& entit RenderablePolyVoxEntityItem::RenderablePolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : PolyVoxEntityItem(entityItemID, properties) { - setVoxelVolumeSize(_voxelVolumeSize); model::Mesh* mesh = new model::Mesh(); model::MeshPointer meshPtr(mesh); _modelGeometry.setMesh(meshPtr); + + setVoxelVolumeSize(_voxelVolumeSize); } @@ -66,22 +67,43 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) delete _volData; } - PolyVox::Vector3DInt32 lowCorner(0, 0, 0); - PolyVox::Vector3DInt32 highCorner(_voxelVolumeSize[0] - 1, // -1 because these corners are inclusive - _voxelVolumeSize[1] - 1, - _voxelVolumeSize[2] - 1); _onCount = 0; - _volData = new PolyVox::SimpleVolume(PolyVox::Region(lowCorner, highCorner)); - compressVolumeData(); + if (_voxelSurfaceStyle == SURFACE_EDGED_CUBIC) { + PolyVox::Vector3DInt32 lowCorner(0, 0, 0); + PolyVox::Vector3DInt32 highCorner(_voxelVolumeSize[0] + 1, // -1 + 2 because these corners are inclusive + _voxelVolumeSize[1] + 1, + _voxelVolumeSize[2] + 1); + _volData = new PolyVox::SimpleVolume(PolyVox::Region(lowCorner, highCorner)); + } else { + PolyVox::Vector3DInt32 lowCorner(0, 0, 0); + PolyVox::Vector3DInt32 highCorner(_voxelVolumeSize[0] - 1, // -1 because these corners are inclusive + _voxelVolumeSize[1] - 1, + _voxelVolumeSize[2] - 1); + _volData = new PolyVox::SimpleVolume(PolyVox::Region(lowCorner, highCorner)); + } + _volData->setBorderValue(255); + decompressVolumeData(); } void RenderablePolyVoxEntityItem::setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { if (voxelSurfaceStyle == _voxelSurfaceStyle) { - return; + return; + } + + // if we are switching to or from "edged" we need to force a resize of _volData. + if (voxelSurfaceStyle == SURFACE_EDGED_CUBIC || + _voxelSurfaceStyle == SURFACE_EDGED_CUBIC) { + if (_volData) { + delete _volData; + } + _volData = nullptr; + PolyVoxEntityItem::setVoxelSurfaceStyle(voxelSurfaceStyle); + setVoxelVolumeSize(_voxelVolumeSize); + } else { + PolyVoxEntityItem::setVoxelSurfaceStyle(voxelSurfaceStyle); } - PolyVoxEntityItem::setVoxelSurfaceStyle(voxelSurfaceStyle); _needsModelReload = true; } @@ -95,53 +117,92 @@ void RenderablePolyVoxEntityItem::setVoxelData(QByteArray voxelData) { } -glm::mat4 RenderablePolyVoxEntityItem::voxelToWorldMatrix() const { +glm::vec3 RenderablePolyVoxEntityItem::getSurfacePositionAdjustment() const { glm::vec3 scale = _dimensions / _voxelVolumeSize; // meters / voxel-units - glm::mat4 scaled = glm::scale(glm::mat4(), scale); - glm::mat4 centerToCorner = glm::translate(scaled, _voxelVolumeSize / -2.0f); - glm::mat4 rotation = glm::mat4_cast(_rotation); - glm::mat4 translation = glm::translate(getCenter()); - return translation * rotation * centerToCorner; + switch (_voxelSurfaceStyle) { + case PolyVoxEntityItem::SURFACE_MARCHING_CUBES: + return scale / 2.0f; + // return glm::vec3(0.5f, 0.5f, 0.5f); + case PolyVoxEntityItem::SURFACE_EDGED_CUBIC: + return scale / -2.0f; + // return glm::vec3(-0.5f, -0.5f, -0.5f); + case PolyVoxEntityItem::SURFACE_CUBIC: + return scale / 2.0f; + // return glm::vec3(0.5f, 0.5f, 0.5f); + } + return glm::vec3(0, 0, 0); } - glm::mat4 RenderablePolyVoxEntityItem::voxelToLocalMatrix() const { glm::vec3 scale = _dimensions / _voxelVolumeSize; // meters / voxel-units glm::mat4 scaled = glm::scale(glm::mat4(), scale); - glm::mat4 centerToCorner = glm::translate(scaled, _voxelVolumeSize / -2.0f); + glm::mat4 centerToCorner = glm::translate(scaled, (_voxelVolumeSize / -2.0f) + getSurfacePositionAdjustment()); return centerToCorner; } +glm::mat4 RenderablePolyVoxEntityItem::voxelToWorldMatrix() const { + glm::mat4 rotation = glm::mat4_cast(_rotation); + glm::mat4 translation = glm::translate(getCenter()); + return translation * rotation * voxelToLocalMatrix(); +} + + glm::mat4 RenderablePolyVoxEntityItem::worldToVoxelMatrix() const { glm::mat4 worldToModelMatrix = glm::inverse(voxelToWorldMatrix()); return worldToModelMatrix; - } +uint8_t RenderablePolyVoxEntityItem::getVoxel(int x, int y, int z) { + assert(_volData); + if (x < 0 || y < 0 || z < 0 || + x >= _voxelVolumeSize[0] || y >= _voxelVolumeSize[1] || z >= _voxelVolumeSize[2]) { + return 0; + } + + if (_voxelSurfaceStyle == SURFACE_EDGED_CUBIC) { + return _volData->getVoxelAt(x + 1, y + 1, z + 1); + } + return _volData->getVoxelAt(x, y, z); +} + +void RenderablePolyVoxEntityItem::setVoxel(int x, int y, int z, uint8_t toValue) { + assert(_volData); + if (x < 0 || y < 0 || z < 0 || + x >= _voxelVolumeSize[0] || y >= _voxelVolumeSize[1] || z >= _voxelVolumeSize[2]) { + return; + } + + if (_voxelSurfaceStyle == SURFACE_EDGED_CUBIC) { + _volData->setVoxelAt(x + 1, y + 1, z + 1, toValue); + } else { + _volData->setVoxelAt(x, y, z, toValue); + } +} + + void RenderablePolyVoxEntityItem::updateOnCount(int x, int y, int z, uint8_t toValue) { // keep _onCount up to date - uint8_t uVoxelValue = _volData->getVoxelAt(x, y, z); + uint8_t uVoxelValue = getVoxel(x, y, z); if (toValue != 0) { - if (uVoxelValue == 0) { - _onCount++; - } + if (uVoxelValue == 0) { + _onCount++; + } } else { - // toValue == 0 - if (uVoxelValue != 0) { - _onCount--; - assert(_onCount >= 0); - } + // toValue == 0 + if (uVoxelValue != 0) { + _onCount--; + assert(_onCount >= 0); + } } } void RenderablePolyVoxEntityItem::setAll(uint8_t toValue) { - // XXX a volume that is all "on" has no mesh. make a different call for this nearly-all code: - for (int z = 1; z < _volData->getDepth() - 1; z++) { - for (int y = 1; y < _volData->getHeight() - 1; y++) { - for (int x = 1; x < _volData->getWidth() - 1; x++) { - updateOnCount(x, y, z, toValue); - _volData->setVoxelAt(x, y, z, toValue); + for (int z = 0; z < _voxelVolumeSize[2]; z++) { + for (int y = 0; y < _voxelVolumeSize[1]; y++) { + for (int x = 0; x < _voxelVolumeSize[0]; x++) { + updateOnCount(x, y, z, toValue); + setVoxel(x, y, z, toValue); } } } @@ -150,17 +211,17 @@ void RenderablePolyVoxEntityItem::setAll(uint8_t toValue) { void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue) { // This three-level for loop iterates over every voxel in the volume - for (int z = 0; z < _volData->getDepth(); z++) { - for (int y = 0; y < _volData->getHeight(); y++) { - for (int x = 0; x < _volData->getWidth(); x++) { + for (int z = 0; z < _voxelVolumeSize[2]; z++) { + for (int y = 0; y < _voxelVolumeSize[1]; y++) { + for (int x = 0; x < _voxelVolumeSize[0]; x++) { // Store our current position as a vector... glm::vec3 pos(x, y, z); // And compute how far the current position is from the center of the volume float fDistToCenter = glm::distance(pos, center); // If the current voxel is less than 'radius' units from the center then we make it solid. if (fDistToCenter <= radius) { - updateOnCount(x, y, z, toValue); - _volData->setVoxelAt(x, y, z, toValue); + updateOnCount(x, y, z, toValue); + setVoxel(x, y, z, toValue); } } } @@ -235,6 +296,33 @@ void RenderablePolyVoxEntityItem::getModel() { _needsModelReload = false; } + +QString GLMatrixToString(GLfloat* m) { + QString mString = "\n"; + for (int x = 0; x < 4; x++) { + for (int y = 0; y < 4; y++) { + mString += QString::number((double)m[y*4+x], 'f', 2) + " "; + } + mString += "\n"; + } + return mString; +} + + +void printModelViewMatrix() { + GLfloat glMatrix[16]; + glGetFloatv(GL_MODELVIEW_MATRIX, glMatrix); + qDebug() << GLMatrixToString(glMatrix); +} + +void printProjectionMatrix() { + GLfloat glMatrix[16]; + glGetFloatv(GL_PROJECTION_MATRIX, glMatrix); + qDebug() << GLMatrixToString(glMatrix); +} + + + void RenderablePolyVoxEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RenderablePolyVoxEntityItem::render"); assert(getType() == EntityTypes::PolyVox); @@ -243,20 +331,23 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) { getModel(); } - glm::vec3 position = getPosition(); - glm::vec3 dimensions = getDimensions(); - glm::vec3 scale = dimensions / _voxelVolumeSize; - glm::vec3 center = getCenter(); - glm::quat rotation = getRotation(); + // glm::vec3 position = getPosition(); + // glm::vec3 dimensions = getDimensions(); + // glm::vec3 scale = dimensions / _voxelVolumeSize; + // glm::vec3 center = getCenter(); + // glm::quat rotation = getRotation(); glPushMatrix(); - glTranslatef(position.x, position.y, position.z); - glm::vec3 axis = glm::axis(rotation); - glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - glm::vec3 positionToCenter = center - position; - // make the rendered voxel volume be centered on the entity's position - positionToCenter -= _dimensions * glm::vec3(0.5f,0.5f,0.5f); - glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); - glScalef(scale.x, scale.y, scale.z); + // glTranslatef(position.x, position.y, position.z); + // glm::vec3 axis = glm::axis(rotation); + // glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); + // glm::vec3 positionToCenter = center - position; + // // make the rendered voxel volume be centered on the entity's position + // positionToCenter -= _dimensions * glm::vec3(0.5f,0.5f,0.5f) - getSurfacePositionAdjustment(); + // glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); + // glScalef(scale.x, scale.y, scale.z); + + glm::mat4 m = voxelToWorldMatrix(); + glMultMatrixf(&m[0][0]); auto mesh = _modelGeometry.getMesh(); gpu::Batch batch; @@ -341,14 +432,17 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o // compress the data in _volData and save the results. The compressed form is used during // saves to disk and for transmission over the wire void RenderablePolyVoxEntityItem::compressVolumeData() { - int rawSize = _volData->getDepth() * _volData->getHeight() * _volData->getWidth(); + int rawSize = _voxelVolumeSize[0] * _voxelVolumeSize[1] * _voxelVolumeSize[2]; QByteArray uncompressedData = QByteArray(rawSize, '\0'); - for (int z = 0; z < _volData->getDepth(); z++) { - for (int y = 0; y < _volData->getHeight(); y++) { - for (int x = 0; x < _volData->getWidth(); x++) { - uint8_t uVoxelValue = _volData->getVoxelAt(x, y, z); - int uncompressedIndex = z * _volData->getHeight() * _volData->getWidth() + y * _volData->getWidth() + x; + for (int z = 0; z < _voxelVolumeSize[2]; z++) { + for (int y = 0; y < _voxelVolumeSize[1]; y++) { + for (int x = 0; x < _voxelVolumeSize[0]; x++) { + uint8_t uVoxelValue = getVoxel(x, y, z); + int uncompressedIndex = + z * _voxelVolumeSize[1] * _voxelVolumeSize[0] + + y * _voxelVolumeSize[0] + + x; uncompressedData[uncompressedIndex] = uVoxelValue; } } @@ -373,17 +467,20 @@ void RenderablePolyVoxEntityItem::compressVolumeData() { // take compressed data and decompreess it into _volData. void RenderablePolyVoxEntityItem::decompressVolumeData() { - int rawSize = _volData->getDepth() * _volData->getHeight() * _volData->getWidth(); + int rawSize = _voxelVolumeSize[0] * _voxelVolumeSize[1] * _voxelVolumeSize[2]; QByteArray uncompressedData = QByteArray(rawSize, '\0'); uncompressedData = qUncompress(_voxelData); - for (int z = 0; z < _volData->getDepth(); z++) { - for (int y = 0; y < _volData->getHeight(); y++) { - for (int x = 0; x < _volData->getWidth(); x++) { - int uncompressedIndex = z * _volData->getHeight() * _volData->getWidth() + y * _volData->getWidth() + x; - updateOnCount(x, y, z, uncompressedData[uncompressedIndex]); - _volData->setVoxelAt(x, y, z, uncompressedData[uncompressedIndex]); + for (int z = 0; z < _voxelVolumeSize[2]; z++) { + for (int y = 0; y < _voxelVolumeSize[1]; y++) { + for (int x = 0; x < _voxelVolumeSize[0]; x++) { + int uncompressedIndex = + z * _voxelVolumeSize[1] * _voxelVolumeSize[0] + + y * _voxelVolumeSize[0] + + x; + updateOnCount(x, y, z, uncompressedData[uncompressedIndex]); + setVoxel(x, y, z, uncompressedData[uncompressedIndex]); } } } @@ -399,7 +496,7 @@ void RenderablePolyVoxEntityItem::decompressVolumeData() { // virtual ShapeType RenderablePolyVoxEntityItem::getShapeType() const { if (_onCount > 0) { - return SHAPE_TYPE_COMPOUND; + return SHAPE_TYPE_COMPOUND; } return SHAPE_TYPE_NONE; } @@ -407,7 +504,7 @@ ShapeType RenderablePolyVoxEntityItem::getShapeType() const { bool RenderablePolyVoxEntityItem::isReadyToComputeShape() { if (_needsModelReload) { - return false; + return false; } qDebug() << "RenderablePolyVoxEntityItem::isReadyToComputeShape" << (!_needsModelReload); @@ -419,7 +516,7 @@ void RenderablePolyVoxEntityItem::computeShapeInfo(ShapeInfo& info) { ShapeType type = getShapeType(); if (type != SHAPE_TYPE_COMPOUND) { EntityItem::computeShapeInfo(info); - return; + return; } _points.clear(); @@ -429,55 +526,58 @@ void RenderablePolyVoxEntityItem::computeShapeInfo(ShapeInfo& info) { AABox box; - for (int z = 0; z < _volData->getDepth(); z++) { - for (int y = 0; y < _volData->getHeight(); y++) { - for (int x = 0; x < _volData->getWidth(); x++) { - if (_volData->getVoxelAt(x, y, z) > 0) { - QVector pointsInPart; + for (int z = 0; z < _voxelVolumeSize[2]; z++) { + for (int y = 0; y < _voxelVolumeSize[1]; y++) { + for (int x = 0; x < _voxelVolumeSize[0]; x++) { + if (getVoxel(x, y, z) > 0) { + QVector pointsInPart; - float offL = -0.5f; - float offH = 0.5f; + float offL = -0.5f; + float offH = 0.5f; - glm::vec3 p000 = glm::vec3(wToM * glm::vec4(x + offL, y + offL, z + offL, 1.0f)); - glm::vec3 p001 = glm::vec3(wToM * glm::vec4(x + offL, y + offL, z + offH, 1.0f)); - glm::vec3 p010 = glm::vec3(wToM * glm::vec4(x + offL, y + offH, z + offL, 1.0f)); - glm::vec3 p011 = glm::vec3(wToM * glm::vec4(x + offL, y + offH, z + offH, 1.0f)); - glm::vec3 p100 = glm::vec3(wToM * glm::vec4(x + offH, y + offL, z + offL, 1.0f)); - glm::vec3 p101 = glm::vec3(wToM * glm::vec4(x + offH, y + offL, z + offH, 1.0f)); - glm::vec3 p110 = glm::vec3(wToM * glm::vec4(x + offH, y + offH, z + offL, 1.0f)); - glm::vec3 p111 = glm::vec3(wToM * glm::vec4(x + offH, y + offH, z + offH, 1.0f)); + // float offL = 0.0f; + // float offH = 1.0f; + + glm::vec3 p000 = glm::vec3(wToM * glm::vec4(x + offL, y + offL, z + offL, 1.0f)); + glm::vec3 p001 = glm::vec3(wToM * glm::vec4(x + offL, y + offL, z + offH, 1.0f)); + glm::vec3 p010 = glm::vec3(wToM * glm::vec4(x + offL, y + offH, z + offL, 1.0f)); + glm::vec3 p011 = glm::vec3(wToM * glm::vec4(x + offL, y + offH, z + offH, 1.0f)); + glm::vec3 p100 = glm::vec3(wToM * glm::vec4(x + offH, y + offL, z + offL, 1.0f)); + glm::vec3 p101 = glm::vec3(wToM * glm::vec4(x + offH, y + offL, z + offH, 1.0f)); + glm::vec3 p110 = glm::vec3(wToM * glm::vec4(x + offH, y + offH, z + offL, 1.0f)); + glm::vec3 p111 = glm::vec3(wToM * glm::vec4(x + offH, y + offH, z + offH, 1.0f)); - box += p000; - box += p001; - box += p010; - box += p011; - box += p100; - box += p101; - box += p110; - box += p111; + box += p000; + box += p001; + box += p010; + box += p011; + box += p100; + box += p101; + box += p110; + box += p111; - pointsInPart << p000; - pointsInPart << p001; - pointsInPart << p010; - pointsInPart << p011; - pointsInPart << p100; - pointsInPart << p101; - pointsInPart << p110; - pointsInPart << p111; + pointsInPart << p000; + pointsInPart << p001; + pointsInPart << p010; + pointsInPart << p011; + pointsInPart << p100; + pointsInPart << p101; + pointsInPart << p110; + pointsInPart << p111; - // add next convex hull - QVector newMeshPoints; - _points << newMeshPoints; - // add points to the new convex hull - _points[i++] << pointsInPart; - } - } - } + // add next convex hull + QVector newMeshPoints; + _points << newMeshPoints; + // add points to the new convex hull + _points[i++] << pointsInPart; + } + } + } } if (_points.isEmpty()) { - EntityItem::computeShapeInfo(info); - return; + EntityItem::computeShapeInfo(info); + return; } glm::vec3 collisionModelDimensions = box.getDimensions(); diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index d659cc0e69..a054a6a88f 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -33,6 +33,9 @@ public: // _needsModelReload = true; } + virtual uint8_t getVoxel(int x, int y, int z); + virtual void setVoxel(int x, int y, int z, uint8_t toValue); + void updateOnCount(int x, int y, int z, uint8_t new_value); void render(RenderArgs* args); @@ -48,6 +51,7 @@ public: virtual void setVoxelData(QByteArray voxelData); virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize); + glm::vec3 getSurfacePositionAdjustment() const; glm::mat4 voxelToWorldMatrix() const; glm::mat4 voxelToLocalMatrix() const; glm::mat4 worldToVoxelMatrix() const; diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 530f073237..8ef59f9f17 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -79,6 +79,9 @@ class PolyVoxEntityItem : public EntityItem { virtual void setAll(uint8_t toValue) {} + virtual uint8_t getVoxel(int x, int y, int z) { return 0; } + virtual void setVoxel(int x, int y, int z, uint8_t toValue) {} + protected: glm::vec3 _voxelVolumeSize; // this is always 3 bytes QByteArray _voxelData; From cfeab893e776e4c5906c9c5e39d4f1712e704a1c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sun, 31 May 2015 09:28:33 -0700 Subject: [PATCH 33/72] fix voxelToLocalMatrix --- .../src/RenderablePolyVoxEntityItem.cpp | 34 +++++-------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 91d702e52b..dfe4885717 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -49,7 +49,6 @@ RenderablePolyVoxEntityItem::RenderablePolyVoxEntityItem(const EntityItemID& ent setVoxelVolumeSize(_voxelVolumeSize); } - RenderablePolyVoxEntityItem::~RenderablePolyVoxEntityItem() { delete _volData; } @@ -86,7 +85,6 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) decompressVolumeData(); } - void RenderablePolyVoxEntityItem::setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { if (voxelSurfaceStyle == _voxelSurfaceStyle) { return; @@ -107,7 +105,6 @@ void RenderablePolyVoxEntityItem::setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxel _needsModelReload = true; } - void RenderablePolyVoxEntityItem::setVoxelData(QByteArray voxelData) { if (voxelData == _voxelData) { return; @@ -116,37 +113,36 @@ void RenderablePolyVoxEntityItem::setVoxelData(QByteArray voxelData) { decompressVolumeData(); } - glm::vec3 RenderablePolyVoxEntityItem::getSurfacePositionAdjustment() const { glm::vec3 scale = _dimensions / _voxelVolumeSize; // meters / voxel-units switch (_voxelSurfaceStyle) { case PolyVoxEntityItem::SURFACE_MARCHING_CUBES: return scale / 2.0f; - // return glm::vec3(0.5f, 0.5f, 0.5f); case PolyVoxEntityItem::SURFACE_EDGED_CUBIC: return scale / -2.0f; - // return glm::vec3(-0.5f, -0.5f, -0.5f); case PolyVoxEntityItem::SURFACE_CUBIC: return scale / 2.0f; - // return glm::vec3(0.5f, 0.5f, 0.5f); } return glm::vec3(0, 0, 0); } glm::mat4 RenderablePolyVoxEntityItem::voxelToLocalMatrix() const { glm::vec3 scale = _dimensions / _voxelVolumeSize; // meters / voxel-units - glm::mat4 scaled = glm::scale(glm::mat4(), scale); - glm::mat4 centerToCorner = glm::translate(scaled, (_voxelVolumeSize / -2.0f) + getSurfacePositionAdjustment()); - return centerToCorner; + glm::vec3 center = getCenter(); + glm::vec3 position = getPosition(); + glm::vec3 positionToCenter = center - position; + positionToCenter -= _dimensions * glm::vec3(0.5f,0.5f,0.5f) - getSurfacePositionAdjustment(); + glm::mat4 centerToCorner = glm::translate(glm::mat4(), positionToCenter); + glm::mat4 scaled = glm::scale(centerToCorner, scale); + return scaled; } glm::mat4 RenderablePolyVoxEntityItem::voxelToWorldMatrix() const { glm::mat4 rotation = glm::mat4_cast(_rotation); - glm::mat4 translation = glm::translate(getCenter()); + glm::mat4 translation = glm::translate(getPosition()); return translation * rotation * voxelToLocalMatrix(); } - glm::mat4 RenderablePolyVoxEntityItem::worldToVoxelMatrix() const { glm::mat4 worldToModelMatrix = glm::inverse(voxelToWorldMatrix()); return worldToModelMatrix; @@ -331,21 +327,7 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) { getModel(); } - // glm::vec3 position = getPosition(); - // glm::vec3 dimensions = getDimensions(); - // glm::vec3 scale = dimensions / _voxelVolumeSize; - // glm::vec3 center = getCenter(); - // glm::quat rotation = getRotation(); glPushMatrix(); - // glTranslatef(position.x, position.y, position.z); - // glm::vec3 axis = glm::axis(rotation); - // glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - // glm::vec3 positionToCenter = center - position; - // // make the rendered voxel volume be centered on the entity's position - // positionToCenter -= _dimensions * glm::vec3(0.5f,0.5f,0.5f) - getSurfacePositionAdjustment(); - // glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); - // glScalef(scale.x, scale.y, scale.z); - glm::mat4 m = voxelToWorldMatrix(); glMultMatrixf(&m[0][0]); From 5e22af8643ff1cbe6ef276a67fa2a20e19e9ce4f Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Sun, 31 May 2015 14:21:28 -0700 Subject: [PATCH 34/72] points and line width persistent accross clients --- libraries/octree/src/OctreePacketData.cpp | 74 ++++++++++++++++++----- libraries/octree/src/OctreePacketData.h | 5 +- 2 files changed, 62 insertions(+), 17 deletions(-) diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index 6afe1c0c0f..d4e56b6217 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -362,6 +362,7 @@ bool OctreePacketData::appendValue(float value) { const unsigned char* data = (const unsigned char*)&value; int length = sizeof(value); + qDebug()<<"Line Width Value!**"<& value){ // _totalBytesOfValues += length; // } // return success; - qDebug("YAAAR"); - int qVecSize = value.size() * sizeof(glm::vec3); - QByteArray myArray('', qVecSize ); - const char* data = (const char*)value.data(); - for(int i = 0; i < qVecSize; i+=sizeof(float)){ - float num; - memcpy(&num, data, sizeof(float)); - qDebug()<<"NUM***"<& result){ - glm::vec3 p1; - memcpy(&p1, dataBytes, sizeof(p1)); - - qDebug()<<"point 1***"< Date: Sun, 31 May 2015 14:46:20 -0700 Subject: [PATCH 35/72] fixed bug in qvec unpacking code --- libraries/octree/src/OctreePacketData.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index d4e56b6217..e3c438a312 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -658,15 +658,19 @@ int OctreePacketData::uppackDataFromBytes(const unsigned char *dataBytes, QVecto for(int i = 0 ; i < length; i+= sizeof(float) * 3) { //Go through and create three floats glm::vec3 point; - float num; - memcpy(&num, dataBytes, sizeof(float)); - point.x = num; - memcpy(&num, dataBytes, sizeof(float)); - point.y = num; - memcpy(&num, dataBytes, sizeof(float)); - point.z = num; + float x; + memcpy(&x, dataBytes, sizeof(float)); + point.x = x; + dataBytes += sizeof(float); + float y; + memcpy(&y, dataBytes, sizeof(float)); + point.y = y; + dataBytes += sizeof(float); + float z; + memcpy(&z, dataBytes, sizeof(float)); + point.z = z; + dataBytes += sizeof(float); result.append(point); - dataBytes += sizeof(float) * 3; } qDebug()<<"LENGTH OF ARRAY ON UNPACKING**"< Date: Sun, 31 May 2015 14:52:44 -0700 Subject: [PATCH 36/72] cleaned up logging and testing code. --- .../src/RenderableLineEntityItem.cpp | 9 +--- libraries/entities/src/LineEntityItem.h | 8 --- libraries/octree/src/OctreePacketData.cpp | 52 ------------------- libraries/octree/src/OctreePacketData.h | 5 +- 4 files changed, 2 insertions(+), 72 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index f5e84a6bfa..ceeb5a1ab4 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -31,10 +31,8 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glm::quat rotation = getRotation(); glm::vec4 lineColor(toGlm(getXColor()), getLocalRenderAlpha()); glPushMatrix(); - glLineWidth(getLineWidth()); auto geometryCache = DependencyManager::get(); - if(_lineVerticesID == GeometryCache::UNKNOWN_ID){ _lineVerticesID = geometryCache ->allocateID(); } @@ -42,13 +40,8 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); QVector points; - glm::vec3 p1 = {0, 0, 0}; - glm::vec3 p2 = {1, 1, 0}; - points<updateVertices(_lineVerticesID, getLinePoints(), lineColor); -// geometryCache->updateVertices(_lineVerticesID, points, lineColor); - - geometryCache->renderVertices(gpu::LINE_STRIP, _lineVerticesID); + geometryCache->renderVertices(gpu::LINE_STRIP, _lineVerticesID); glPopMatrix(); RenderableDebugableEntityItem::render(this, args); }; diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index afd20a3722..10001a4c71 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -59,17 +59,9 @@ class LineEntityItem : public EntityItem { return _lineWidth; } - void setLinePoints(const QVector& points){ qDebug()<<"points " << points; _points = points; -// _points = QVector(0); -// glm::vec3 p1 = { 0,0,0}; -// glm::vec3 p2 = {1, -1,2}; -// glm::vec3 p3 = {4, 0, 0}; -// _points <& getLinePoints() const{ diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index e3c438a312..f76e2a6d9b 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -362,7 +362,6 @@ bool OctreePacketData::appendValue(float value) { const unsigned char* data = (const unsigned char*)&value; int length = sizeof(value); - qDebug()<<"Line Width Value!**"<& value){ - -// const unsigned char* data = (const unsigned char*)value.data(); -// uint16_t qVecSize = (uint16_t)value.size(); -// -// int length = qVecSize * sizeof(glm::vec3); -// const unsigned char* sizePointer = (const unsigned char*)&qVecSize; -// bool success = append(sizePointer, sizeof(uint16_t)); -// if(success){ -// _bytesOfValues += qVecSize; -// _totalBytesOfValues += qVecSize; -// success = append(data, length); -// if (success){ -// _bytesOfValues += length; -// _totalBytesOfValues += length; -// } -// } -// return success; - -// const unsigned char* data = (const unsigned char*)value.data(); -// int qVecSize = value.size(); -// -// int length = qVecSize * sizeof(glm::vec3); -// -// bool success = append(data, length); -// if (success){ -// _bytesOfValues += length; -// _totalBytesOfValues += length; -// } -// return success; - uint16_t qVecSize = value.size() * sizeof(glm::vec3); - QByteArray myArray; - const char* data = (const char*)value.data(); - - char* sizePointer = (char*)&qVecSize; QByteArray vecSize(sizePointer, sizeof(uint16_t)); myArray.append(vecSize); uint16_t arrayLength; memcpy(&arrayLength, myArray.data(), sizeof(uint16_t)); - qDebug()<<"array length.. shnur"< Date: Sun, 31 May 2015 14:59:09 -0700 Subject: [PATCH 37/72] array of points takes absolute positions now, so script writer has an easier time --- libraries/entities-renderer/src/RenderableLineEntityItem.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index ceeb5a1ab4..95c0ad9d6c 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -36,7 +36,8 @@ void RenderableLineEntityItem::render(RenderArgs* args) { if(_lineVerticesID == GeometryCache::UNKNOWN_ID){ _lineVerticesID = geometryCache ->allocateID(); } - glTranslatef(position.x, position.y, position.z); + //TODO: Figure out clean , efficient way to do relative line positioning. For now we'll just use absolute positioning. + //glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); QVector points; From 9ca5310c21e4855b6a60dbb9499cc02e2788c0e7 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Sun, 31 May 2015 15:33:51 -0700 Subject: [PATCH 38/72] cleaned up another qDebugging line --- libraries/entities/src/LineEntityItem.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index 10001a4c71..9b95a41361 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -60,7 +60,6 @@ class LineEntityItem : public EntityItem { } void setLinePoints(const QVector& points){ - qDebug()<<"points " << points; _points = points; } From 00af0a43761a3af3a24d13509f58e8956513612e Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 1 Jun 2015 07:15:37 -0700 Subject: [PATCH 39/72] trying to make thing behave when voxel-space is resized --- examples/voxels.js | 4 +- .../src/RenderablePolyVoxEntityItem.cpp | 124 +++++++++++------- .../src/RenderablePolyVoxEntityItem.h | 1 + libraries/shared/src/SettingInterface.cpp | 12 +- 4 files changed, 89 insertions(+), 52 deletions(-) diff --git a/examples/voxels.js b/examples/voxels.js index 5e4ea8df01..fc9f6550f5 100644 --- a/examples/voxels.js +++ b/examples/voxels.js @@ -16,11 +16,11 @@ function mousePressEvent(event) { for (var i = 0; i < ids.length; i++) { var id = ids[i]; if (controlHeld) { - Entities.setVoxelSphere(id, intersection.intersection, 4.0, 0); + Entities.setVoxelSphere(id, intersection.intersection, 1.0, 0); } else if (shiftHeld) { Entities.setAllVoxels(id, 255); } else { - Entities.setVoxelSphere(id, intersection.intersection, 4.0, 255); + Entities.setVoxelSphere(id, intersection.intersection, 1.0, 255); } } } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index dfe4885717..63c8104c80 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -60,6 +60,8 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) qDebug() << "resetting voxel-space size"; + + glm::vec3 previousVolumeSize = _voxelVolumeSize; PolyVoxEntityItem::setVoxelVolumeSize(voxelVolumeSize); if (_volData) { @@ -82,7 +84,8 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) _volData = new PolyVox::SimpleVolume(PolyVox::Region(lowCorner, highCorner)); } _volData->setBorderValue(255); - decompressVolumeData(); + decompressVolumeData(previousVolumeSize); + compressVolumeData(); } void RenderablePolyVoxEntityItem::setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { @@ -155,6 +158,10 @@ uint8_t RenderablePolyVoxEntityItem::getVoxel(int x, int y, int z) { return 0; } + // if _voxelSurfaceStyle is SURFACE_EDGED_CUBIC, we maintain an extra layer of + // voxels all around the requested voxel space. Having the empty voxels around + // the edges changes how the surface extractor behaves. + if (_voxelSurfaceStyle == SURFACE_EDGED_CUBIC) { return _volData->getVoxelAt(x + 1, y + 1, z + 1); } @@ -211,7 +218,7 @@ void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radi for (int y = 0; y < _voxelVolumeSize[1]; y++) { for (int x = 0; x < _voxelVolumeSize[0]; x++) { // Store our current position as a vector... - glm::vec3 pos(x, y, z); + glm::vec3 pos(x + 0.5f, y + 0.5f, z + 0.5f); // consider voxels cenetered on their coordinates // And compute how far the current position is from the center of the volume float fDistToCenter = glm::distance(pos, center); // If the current voxel is less than 'radius' units from the center then we make it solid. @@ -293,29 +300,29 @@ void RenderablePolyVoxEntityItem::getModel() { } -QString GLMatrixToString(GLfloat* m) { - QString mString = "\n"; - for (int x = 0; x < 4; x++) { - for (int y = 0; y < 4; y++) { - mString += QString::number((double)m[y*4+x], 'f', 2) + " "; - } - mString += "\n"; - } - return mString; -} +// QString GLMatrixToString(GLfloat* m) { +// QString mString = "\n"; +// for (int x = 0; x < 4; x++) { +// for (int y = 0; y < 4; y++) { +// mString += QString::number((double)m[y*4+x], 'f', 2) + " "; +// } +// mString += "\n"; +// } +// return mString; +// } -void printModelViewMatrix() { - GLfloat glMatrix[16]; - glGetFloatv(GL_MODELVIEW_MATRIX, glMatrix); - qDebug() << GLMatrixToString(glMatrix); -} +// void printModelViewMatrix() { +// GLfloat glMatrix[16]; +// glGetFloatv(GL_MODELVIEW_MATRIX, glMatrix); +// qDebug() << GLMatrixToString(glMatrix); +// } -void printProjectionMatrix() { - GLfloat glMatrix[16]; - glGetFloatv(GL_PROJECTION_MATRIX, glMatrix); - qDebug() << GLMatrixToString(glMatrix); -} +// void printProjectionMatrix() { +// GLfloat glMatrix[16]; +// glGetFloatv(GL_PROJECTION_MATRIX, glMatrix); +// qDebug() << GLMatrixToString(glMatrix); +// } @@ -349,9 +356,20 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) { class RaycastFunctor { public: - RaycastFunctor() : _result(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)) { } + RaycastFunctor(PolyVox::SimpleVolume* vol) : + _result(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), + _vol(vol) { + } bool operator()(PolyVox::SimpleVolume::Sampler& sampler) { + int x = sampler.getPosition().getX(); + int y = sampler.getPosition().getY(); + int z = sampler.getPosition().getZ(); + if (x < 0 || y < 0 || z < 0 || + x > _vol->getWidth() || y > _vol->getHeight() || z > _vol->getDepth()) { + return true; + } + if (sampler.getVoxel() == 0) { return true; // keep raycasting } @@ -360,6 +378,7 @@ public: return false; } glm::vec4 _result; + const PolyVox::SimpleVolume* _vol = nullptr; }; bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& origin, @@ -375,33 +394,45 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o return true; } + // the PolyVox ray intersection code requires a near and far point. glm::mat4 wtvMatrix = worldToVoxelMatrix(); - glm::vec3 farPoint = origin + direction; + glm::vec3 normDirection = glm::normalize(direction); + + // set ray cast length to long enough to cover all of the voxel space + float distanceToEntity = glm::distance(origin, _position); + float largestDimension = glm::max(_dimensions[0], _dimensions[1], _dimensions[2]) * 2.0f; + + glm::vec3 farPoint = origin + normDirection * (distanceToEntity + largestDimension); + glm::vec4 originInVoxel = wtvMatrix * glm::vec4(origin, 1.0f); glm::vec4 farInVoxel = wtvMatrix * glm::vec4(farPoint, 1.0f); - glm::vec4 directionInVoxel = farInVoxel - originInVoxel; - + PolyVox::Vector3DFloat start(originInVoxel[0], originInVoxel[1], originInVoxel[2]); - PolyVox::Vector3DFloat pvDirection(directionInVoxel[0], directionInVoxel[1], directionInVoxel[2]); - pvDirection.normalise(); - - // the PolyVox ray intersection code requires a near and far point. - glm::vec3 scale = _dimensions / _voxelVolumeSize; // meters / voxel-units - float distanceToEntity = glm::distance(origin, _position); - float largestDimension = glm::max(_dimensions[0], _dimensions[1], _dimensions[2]); - // set ray cast length to long enough to cover all of the voxel space - pvDirection *= (distanceToEntity + largestDimension) / glm::min(scale[0], scale[1], scale[2]); + // PolyVox::Vector3DFloat pvDirection(directionInVoxel[0], directionInVoxel[1], directionInVoxel[2]); + PolyVox::Vector3DFloat far(farInVoxel[0], farInVoxel[1], farInVoxel[2]); PolyVox::RaycastResult raycastResult; - RaycastFunctor callback; - raycastResult = PolyVox::raycastWithDirection(_volData, start, pvDirection, callback); + RaycastFunctor callback(_volData); + raycastResult = PolyVox::raycastWithEndpoints(_volData, start, far, callback); if (raycastResult == PolyVox::RaycastResults::Completed) { // the ray completed its path -- nothing was hit. return false; } - glm::vec4 intersectedWorldPosition = voxelToWorldMatrix() * callback._result; + glm::vec4 result = callback._result; + switch (_voxelSurfaceStyle) { + case PolyVoxEntityItem::SURFACE_EDGED_CUBIC: + result -= glm::vec4(1, 1, 1, 0); // compensate for the extra voxel border + break; + case PolyVoxEntityItem::SURFACE_MARCHING_CUBES: + case PolyVoxEntityItem::SURFACE_CUBIC: + break; + } + + result -= glm::vec4(0.5f, 0.5f, 0.5f, 0.0f); + + glm::vec4 intersectedWorldPosition = voxelToWorldMatrix() * result; distance = glm::distance(glm::vec3(intersectedWorldPosition), origin); @@ -449,17 +480,22 @@ void RenderablePolyVoxEntityItem::compressVolumeData() { // take compressed data and decompreess it into _volData. void RenderablePolyVoxEntityItem::decompressVolumeData() { - int rawSize = _voxelVolumeSize[0] * _voxelVolumeSize[1] * _voxelVolumeSize[2]; + decompressVolumeData(_voxelVolumeSize); +} + + +void RenderablePolyVoxEntityItem::decompressVolumeData(glm::vec3 volumeSize) { + int rawSize = volumeSize[0] * volumeSize[1] * volumeSize[2]; QByteArray uncompressedData = QByteArray(rawSize, '\0'); uncompressedData = qUncompress(_voxelData); - for (int z = 0; z < _voxelVolumeSize[2]; z++) { - for (int y = 0; y < _voxelVolumeSize[1]; y++) { - for (int x = 0; x < _voxelVolumeSize[0]; x++) { + for (int z = 0; z < volumeSize[2]; z++) { + for (int y = 0; y < volumeSize[1]; y++) { + for (int x = 0; x < volumeSize[0]; x++) { int uncompressedIndex = - z * _voxelVolumeSize[1] * _voxelVolumeSize[0] + - y * _voxelVolumeSize[0] + + z * volumeSize[1] * volumeSize[0] + + y * volumeSize[0] + x; updateOnCount(x, y, z, uncompressedData[uncompressedIndex]); setVoxel(x, y, z, uncompressedData[uncompressedIndex]); diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index a054a6a88f..c8039e79c1 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -72,6 +72,7 @@ public: private: void compressVolumeData(); void decompressVolumeData(); + void decompressVolumeData(glm::vec3 volumeSize); PolyVox::SimpleVolume* _volData = nullptr; model::Geometry _modelGeometry; diff --git a/libraries/shared/src/SettingInterface.cpp b/libraries/shared/src/SettingInterface.cpp index 26cbe3ca13..ee72a4ab45 100644 --- a/libraries/shared/src/SettingInterface.cpp +++ b/libraries/shared/src/SettingInterface.cpp @@ -39,12 +39,12 @@ namespace Setting { void init() { // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings::setDefaultFormat(QSettings::IniFormat); - QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); - // set the associated application properties - applicationInfo.beginGroup("INFO"); - QCoreApplication::setApplicationName(applicationInfo.value("name").toString()); - QCoreApplication::setOrganizationName(applicationInfo.value("organizationName").toString()); - QCoreApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); + // QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); + // // set the associated application properties + // applicationInfo.beginGroup("INFO"); + // QCoreApplication::setApplicationName(applicationInfo.value("name").toString()); + // QCoreApplication::setOrganizationName(applicationInfo.value("organizationName").toString()); + // QCoreApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); // Let's set up the settings Private instance on it's own thread QThread* thread = new QThread(); From d04b61d6a8cb245897e0297b648ab1ccedab9419 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 1 Jun 2015 07:16:16 -0700 Subject: [PATCH 40/72] oops --- libraries/shared/src/SettingInterface.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/shared/src/SettingInterface.cpp b/libraries/shared/src/SettingInterface.cpp index ee72a4ab45..26cbe3ca13 100644 --- a/libraries/shared/src/SettingInterface.cpp +++ b/libraries/shared/src/SettingInterface.cpp @@ -39,12 +39,12 @@ namespace Setting { void init() { // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings::setDefaultFormat(QSettings::IniFormat); - // QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); - // // set the associated application properties - // applicationInfo.beginGroup("INFO"); - // QCoreApplication::setApplicationName(applicationInfo.value("name").toString()); - // QCoreApplication::setOrganizationName(applicationInfo.value("organizationName").toString()); - // QCoreApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); + QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); + // set the associated application properties + applicationInfo.beginGroup("INFO"); + QCoreApplication::setApplicationName(applicationInfo.value("name").toString()); + QCoreApplication::setOrganizationName(applicationInfo.value("organizationName").toString()); + QCoreApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); // Let's set up the settings Private instance on it's own thread QThread* thread = new QThread(); From 2a931119bdee73512aef793e8417adaa8274bc89 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 28 May 2015 12:17:21 -0700 Subject: [PATCH 41/72] Replace expand/collapse dialog animation with fade in/out --- interface/resources/qml/controls/Dialog.qml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/interface/resources/qml/controls/Dialog.qml b/interface/resources/qml/controls/Dialog.qml index f32b4e2e66..15c8b7bafc 100644 --- a/interface/resources/qml/controls/Dialog.qml +++ b/interface/resources/qml/controls/Dialog.qml @@ -31,7 +31,7 @@ DialogBase { * Support for animating the dialog in and out. */ enabled: false - scale: 0.0 + opacity: 0.0 // The offscreen UI will enable an object, rather than manipulating it's // visibility, so that we can do animations in both directions. Because @@ -40,20 +40,20 @@ DialogBase { // opacity, and then when the target animation value is reached, we can // modify the visibility onEnabledChanged: { - scale = enabled ? 1.0 : 0.0 + opacity = enabled ? 1.0 : 0.0 } // The actual animator - Behavior on scale { + Behavior on opacity { NumberAnimation { - duration: root.animationDuration - easing.type: Easing.InOutBounce + duration: 300 + easing.type: Easing.OutCubic } } - // Once we're scaled to 0, disable the dialog's visibility - onScaleChanged: { - visible = (scale != 0.0); + // Once we're transparent, disable the dialog's visibility + onOpacityChanged: { + visible = (opacity != 0.0); } // Some dialogs should be destroyed when they become invisible, From a43593c3b2dde13b495ada6d965459db97041b36 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 29 May 2015 15:23:55 -0700 Subject: [PATCH 42/72] Dialog opacity transition tidying --- interface/resources/qml/controls/Dialog.qml | 4 ++-- interface/resources/qml/styles/HifiConstants.qml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/resources/qml/controls/Dialog.qml b/interface/resources/qml/controls/Dialog.qml index 15c8b7bafc..aa14e2fcba 100644 --- a/interface/resources/qml/controls/Dialog.qml +++ b/interface/resources/qml/controls/Dialog.qml @@ -31,7 +31,7 @@ DialogBase { * Support for animating the dialog in and out. */ enabled: false - opacity: 0.0 + opacity: 1.0 // The offscreen UI will enable an object, rather than manipulating it's // visibility, so that we can do animations in both directions. Because @@ -46,7 +46,7 @@ DialogBase { // The actual animator Behavior on opacity { NumberAnimation { - duration: 300 + duration: animationDuration easing.type: Easing.OutCubic } } diff --git a/interface/resources/qml/styles/HifiConstants.qml b/interface/resources/qml/styles/HifiConstants.qml index d24e9ca9be..702a396afb 100644 --- a/interface/resources/qml/styles/HifiConstants.qml +++ b/interface/resources/qml/styles/HifiConstants.qml @@ -56,6 +56,6 @@ Item { QtObject { id: effects - readonly property int fadeInDuration: 400 + readonly property int fadeInDuration: 300 } } From 881941b64dd89acd98af8b00b8f4db41c8e02abc Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 29 May 2015 15:25:35 -0700 Subject: [PATCH 43/72] Restyle address bar dialog Made the dialog a stand-alone QML file that doesn't inherit from other dialog QML files so that don't need to rework all dialogs right now. --- interface/resources/qml/AddressBarDialog.qml | 185 ++++++++++++------- 1 file changed, 116 insertions(+), 69 deletions(-) diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml index e12452472a..42a0a7dd7e 100644 --- a/interface/resources/qml/AddressBarDialog.qml +++ b/interface/resources/qml/AddressBarDialog.qml @@ -1,91 +1,124 @@ import Hifi 1.0 import QtQuick 2.3 +import QtQuick.Controls 1.2 import "controls" import "styles" -Dialog { +Item { id: root HifiConstants { id: hifi } - - title: "Go to..." + objectName: "AddressBarDialog" - contentImplicitWidth: addressBarDialog.implicitWidth - contentImplicitHeight: addressBarDialog.implicitHeight - destroyOnCloseButton: false + property int animationDuration: hifi.effects.fadeInDuration + property bool destroyOnInvisible: false + property bool destroyOnCloseButton: true - onVisibleChanged: { - if (!visible) { - reset(); - } - } + implicitWidth: addressBarDialog.implicitWidth + implicitHeight: addressBarDialog.implicitHeight + + x: parent ? parent.width / 2 - width / 2 : 0 + y: parent ? parent.height / 2 - height / 2 : 0 + + AddressBarDialog { + id: addressBarDialog + + implicitWidth: box.width + implicitHeight: addressLine.height + hifi.layout.spacing * 2 + + Border { + id: box + + width: 512 + height: parent.height + border.width: 0 + radius: 6 + color: "#ededee" + + MouseArea { + id: boxDrag + + anchors.fill: parent + + drag { + target: root + minimumX: 0 + minimumY: 0 + maximumX: root.parent ? root.parent.width - root.width : 0 + maximumY: root.parent ? root.parent.height - root.height : 0 + } + } + + TextInput { + id: addressLine + + anchors.fill: parent + anchors.leftMargin: hifi.layout.spacing * 2 + anchors.rightMargin: hifi.layout.spacing * 2 + anchors.topMargin: hifi.layout.spacing + anchors.bottomMargin: hifi.layout.spacing + + font.pointSize: 15 + helperText: "Go to: place, @user, /path, network address" + + onAccepted: { + event.accepted + addressBarDialog.loadAddress(addressLine.text) + } + } + } + } + + // The UI enables an object, rather than manipulating its visibility, so that we can do animations in both directions. + // Because visibility and enabled are booleans, they cannot be animated. So when enabled is changed, we modify a property + // that can be animated, like scale or opacity, and then when the target animation value is reached, we can modify the + // visibility. + enabled: false + opacity: 1.0 onEnabledChanged: { + opacity = enabled ? 1.0 : 0.0 if (enabled) { addressLine.forceActiveFocus(); } } - onParentChanged: { - if (enabled && visible) { - addressLine.forceActiveFocus(); + + Behavior on opacity { + // Animate opacity. + NumberAnimation { + duration: animationDuration + easing.type: Easing.OutCubic } } + onOpacityChanged: { + // Once we're transparent, disable the dialog's visibility. + visible = (opacity != 0.0) + } + + onVisibleChanged: { + if (!visible) { + reset() + + // Some dialogs should be destroyed when they become invisible. + if (destroyOnInvisible) { + destroy() + } + } + + } + + function close() { + // The close function performs the same way as the OffscreenUI class: don't do anything but manipulate the enabled flag + // and let the other mechanisms decide if the window should be destroyed after the close animation completes. + if (destroyOnCloseButton) { + destroyOnInvisible = true + } + enabled = false + } + function reset() { addressLine.text = "" - goButton.source = "../images/address-bar-submit.svg" - } - - AddressBarDialog { - id: addressBarDialog - // The client area - x: root.clientX - y: root.clientY - implicitWidth: 512 - implicitHeight: border.height + hifi.layout.spacing * 4 - - - Border { - id: border - height: 64 - anchors.left: parent.left - anchors.leftMargin: hifi.layout.spacing * 2 - anchors.right: goButton.left - anchors.rightMargin: hifi.layout.spacing - anchors.verticalCenter: parent.verticalCenter - TextInput { - id: addressLine - anchors.fill: parent - helperText: "domain, location, @user, /x,y,z" - anchors.margins: hifi.layout.spacing - onAccepted: { - event.accepted - addressBarDialog.loadAddress(addressLine.text) - } - } - } - - Image { - id: goButton - width: 32 - height: 32 - anchors.right: parent.right - anchors.rightMargin: hifi.layout.spacing * 2 - source: "../images/address-bar-submit.svg" - anchors.verticalCenter: parent.verticalCenter - - MouseArea { - anchors.fill: parent - onClicked: { - parent.source = "../images/address-bar-submit-active.svg" - addressBarDialog.loadAddress(addressLine.text) - } - } - } - } - - Keys.onEscapePressed: { - enabled = false; } function toggleOrGo() { @@ -95,8 +128,22 @@ Dialog { addressBarDialog.loadAddress(addressLine.text) } } - + + Keys.onEscapePressed: { + enabled = false + } + + Keys.onPressed: { + switch(event.key) { + case Qt.Key_W: + if (event.modifiers == Qt.ControlModifier) { + event.accepted = true + enabled = false + } + break + } + } + Keys.onReturnPressed: toggleOrGo() Keys.onEnterPressed: toggleOrGo() } - From 05e251eba4f5e2d77524df1bf64e0cd32cc41df3 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 30 May 2015 12:01:50 -0700 Subject: [PATCH 44/72] Add icon to address bar dialog --- .../resources/images/address-bar-icon.svg | 63 +++++++++++++++++++ .../images/address-bar-submit-active.svg | 18 ------ .../resources/images/address-bar-submit.svg | 18 ------ interface/resources/qml/AddressBarDialog.qml | 48 +++++++++++--- 4 files changed, 102 insertions(+), 45 deletions(-) create mode 100644 interface/resources/images/address-bar-icon.svg delete mode 100644 interface/resources/images/address-bar-submit-active.svg delete mode 100644 interface/resources/images/address-bar-submit.svg diff --git a/interface/resources/images/address-bar-icon.svg b/interface/resources/images/address-bar-icon.svg new file mode 100644 index 0000000000..a6d67aabae --- /dev/null +++ b/interface/resources/images/address-bar-icon.svg @@ -0,0 +1,63 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git a/interface/resources/images/address-bar-submit-active.svg b/interface/resources/images/address-bar-submit-active.svg deleted file mode 100644 index 313b366033..0000000000 --- a/interface/resources/images/address-bar-submit-active.svg +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/interface/resources/images/address-bar-submit.svg b/interface/resources/images/address-bar-submit.svg deleted file mode 100644 index df4d7e90f6..0000000000 --- a/interface/resources/images/address-bar-submit.svg +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml index 42a0a7dd7e..a3f7c6ba18 100644 --- a/interface/resources/qml/AddressBarDialog.qml +++ b/interface/resources/qml/AddressBarDialog.qml @@ -23,8 +23,12 @@ Item { AddressBarDialog { id: addressBarDialog - implicitWidth: box.width - implicitHeight: addressLine.height + hifi.layout.spacing * 2 + property int iconOverlap: 15 // Let the circle overlap window edges and rectangular part of dialog + property int maximumX: root.parent.width - root.width + property int maximumY: root.parent.height - root.height + + implicitWidth: box.width + icon.width - iconOverlap * 2 + implicitHeight: addressLine.height + hifi.layout.spacing * 2 Border { id: box @@ -35,6 +39,8 @@ Item { radius: 6 color: "#ededee" + x: icon.width - addressBarDialog.iconOverlap * 2 // W.r.t. addressBarDialog + MouseArea { id: boxDrag @@ -42,18 +48,18 @@ Item { drag { target: root - minimumX: 0 - minimumY: 0 - maximumX: root.parent ? root.parent.width - root.width : 0 - maximumY: root.parent ? root.parent.height - root.height : 0 - } + minimumX: 0 + minimumY: 0 + maximumX: root.parent ? addressBarDialog.maximumX : 0 + maximumY: root.parent ? addressBarDialog.maximumY : 0 + } } TextInput { id: addressLine anchors.fill: parent - anchors.leftMargin: hifi.layout.spacing * 2 + anchors.leftMargin: addressBarDialog.iconOverlap + hifi.layout.spacing * 2 anchors.rightMargin: hifi.layout.spacing * 2 anchors.topMargin: hifi.layout.spacing anchors.bottomMargin: hifi.layout.spacing @@ -67,7 +73,31 @@ Item { } } } - } + + Image { + id: icon + source: "../images/address-bar-icon.svg" + width: 80 + height: 80 + anchors.right: box.left + anchors.rightMargin: -addressBarDialog.iconOverlap + anchors.verticalCenter: parent.verticalCenter + + MouseArea { + id: iconDrag + + anchors.fill: parent + + drag { + target: root + minimumX: 0 + minimumY: 0 + maximumX: root.parent ? addressBarDialog.maximumX : 0 + maximumY: root.parent ? addressBarDialog.maximumY : 0 + } + } + } + } // The UI enables an object, rather than manipulating its visibility, so that we can do animations in both directions. // Because visibility and enabled are booleans, they cannot be animated. So when enabled is changed, we modify a property From e41b4c1b7b4bfed4c8ba7af6a86a0842ddfc7ada Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sun, 31 May 2015 20:56:11 -0700 Subject: [PATCH 45/72] Add new address bar dialog error message Implemented as a new simple InformationDialog so that can try it out without reworking MessageDialog immediately for all QML UI. --- .../images/address-bar-error-close.svg | 50 ++++++ .../images/address-bar-error-icon.svg | 3 + interface/resources/qml/ErrorDialog.qml | 152 ++++++++++++++++++ interface/src/Application.cpp | 14 +- interface/src/ui/AddressBarDialog.cpp | 6 +- libraries/ui/src/ErrorDialog.cpp | 38 +++++ libraries/ui/src/ErrorDialog.h | 46 ++++++ libraries/ui/src/OffscreenUi.cpp | 10 ++ libraries/ui/src/OffscreenUi.h | 2 + 9 files changed, 311 insertions(+), 10 deletions(-) create mode 100644 interface/resources/images/address-bar-error-close.svg create mode 100644 interface/resources/images/address-bar-error-icon.svg create mode 100644 interface/resources/qml/ErrorDialog.qml create mode 100644 libraries/ui/src/ErrorDialog.cpp create mode 100644 libraries/ui/src/ErrorDialog.h diff --git a/interface/resources/images/address-bar-error-close.svg b/interface/resources/images/address-bar-error-close.svg new file mode 100644 index 0000000000..45a4dd4635 --- /dev/null +++ b/interface/resources/images/address-bar-error-close.svg @@ -0,0 +1,50 @@ + +image/svg+xml \ No newline at end of file diff --git a/interface/resources/images/address-bar-error-icon.svg b/interface/resources/images/address-bar-error-icon.svg new file mode 100644 index 0000000000..f2453fb0d4 --- /dev/null +++ b/interface/resources/images/address-bar-error-icon.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/interface/resources/qml/ErrorDialog.qml b/interface/resources/qml/ErrorDialog.qml new file mode 100644 index 0000000000..72b2c24e90 --- /dev/null +++ b/interface/resources/qml/ErrorDialog.qml @@ -0,0 +1,152 @@ +// +// ErrorDialog.qml +// +// Created by David Rowe on 30 May 2015 +// Copyright 2015 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 +// + +import Hifi 1.0 as Hifi +import QtQuick 2.3 +import QtQuick.Controls 1.2 +import QtQuick.Dialogs 1.2 +import "controls" +import "styles" + +Item { + id: root + HifiConstants { id: hifi } + + property int animationDuration: hifi.effects.fadeInDuration + property bool destroyOnInvisible: true + + Component.onCompleted: { + enabled = true + } + + onParentChanged: { + if (visible && enabled) { + forceActiveFocus(); + } + } + + implicitWidth: content.implicitWidth + implicitHeight: content.implicitHeight + + x: parent ? parent.width / 2 - width / 2 : 0 + y: parent ? parent.height / 2 - height / 2 : 0 + + Hifi.ErrorDialog { + id: content + + implicitWidth: box.width + implicitHeight: icon.height + hifi.layout.spacing * 2 + + Border { + id: box + + width: 512 + color: "#ebebeb" + radius: 2 + border.width: 1 + border.color: "#000000" + + Image { + id: icon + + source: "../images/address-bar-error-icon.svg" + width: 40 + height: 40 + anchors { + left: parent.left + leftMargin: hifi.layout.spacing + verticalCenter: parent.verticalCenter + } + } + + Text { + id: messageText + + font.pointSize: 10 + font.weight: Font.Bold + + anchors { + horizontalCenter: parent.horizontalCenter + verticalCenter: parent.verticalCenter + } + + text: content.text + } + + Image { + source: "../images/address-bar-error-close.svg" + width: 20 + height: 20 + anchors { + right: parent.right + rightMargin: hifi.layout.spacing * 2 + verticalCenter: parent.verticalCenter + } + MouseArea { + anchors.fill: parent + onClicked: { + content.accept(); + } + } + } + } + } + + // The UI enables an object, rather than manipulating its visibility, so that we can do animations in both directions. + // Because visibility and enabled are booleans, they cannot be animated. So when enabled is changed, we modify a property + // that can be animated, like scale or opacity, and then when the target animation value is reached, we can modify the + // visibility. + enabled: false + opacity: 1.0 + + onEnabledChanged: { + opacity = enabled ? 1.0 : 0.0 + } + + Behavior on opacity { + // Animate opacity. + NumberAnimation { + duration: animationDuration + easing.type: Easing.OutCubic + } + } + + onOpacityChanged: { + // Once we're transparent, disable the dialog's visibility. + visible = (opacity != 0.0) + } + + onVisibleChanged: { + if (!visible) { + // Some dialogs should be destroyed when they become invisible. + if (destroyOnInvisible) { + destroy() + } + } + } + + Keys.onPressed: { + if (event.modifiers === Qt.ControlModifier) + switch (event.key) { + case Qt.Key_W: + event.accepted = true + content.accept() + break + } else switch (event.key) { + case Qt.Key_Escape: + case Qt.Key_Back: + case Qt.Key_Enter: + case Qt.Key_Return: + event.accepted = true + content.accept() + break + } + } +} diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 877b5ed931..d43306715a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -55,40 +55,41 @@ #include #include -#include #include +#include #include #include #include #include #include +#include #include #include #include -#include +#include #include #include +#include #include #include #include +#include #include #include -#include #include #include #include #include #include #include +#include #include #include #include #include #include #include -#include -#include -#include +#include #include "Application.h" #include "AudioClient.h" @@ -799,6 +800,7 @@ void Application::initializeGL() { void Application::initializeUi() { AddressBarDialog::registerType(); + ErrorDialog::registerType(); LoginDialog::registerType(); MessageDialog::registerType(); VrMenu::registerType(); diff --git a/interface/src/ui/AddressBarDialog.cpp b/interface/src/ui/AddressBarDialog.cpp index 837702d253..3c3a843586 100644 --- a/interface/src/ui/AddressBarDialog.cpp +++ b/interface/src/ui/AddressBarDialog.cpp @@ -36,12 +36,10 @@ void AddressBarDialog::loadAddress(const QString& address) { } void AddressBarDialog::displayAddressOfflineMessage() { - OffscreenUi::information("Address offline", - "That user or place is currently offline."); + OffscreenUi::error("That user or place is currently offline"); } void AddressBarDialog::displayAddressNotFoundMessage() { - OffscreenUi::information("Address not found", - "There is no address information for that user or place."); + OffscreenUi::error("There is no address information for that user or place"); } diff --git a/libraries/ui/src/ErrorDialog.cpp b/libraries/ui/src/ErrorDialog.cpp new file mode 100644 index 0000000000..ab36ef8d36 --- /dev/null +++ b/libraries/ui/src/ErrorDialog.cpp @@ -0,0 +1,38 @@ +// +// ErrorDialog.cpp +// +// Created by David Rowe on 30 May 2015 +// Copyright 2015 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 +// + +#include "ErrorDialog.h" + +HIFI_QML_DEF(ErrorDialog) + +ErrorDialog::ErrorDialog(QQuickItem* parent) : OffscreenQmlDialog(parent) { +} + +ErrorDialog::~ErrorDialog() { +} + +QString ErrorDialog::text() const { + return _text; +} + +void ErrorDialog::setVisible(bool v) { + OffscreenQmlDialog::setVisible(v); +} + +void ErrorDialog::setText(const QString& arg) { + if (arg != _text) { + _text = arg; + emit textChanged(); + } +} + +void ErrorDialog::accept() { + OffscreenQmlDialog::accept(); +} diff --git a/libraries/ui/src/ErrorDialog.h b/libraries/ui/src/ErrorDialog.h new file mode 100644 index 0000000000..665090da1a --- /dev/null +++ b/libraries/ui/src/ErrorDialog.h @@ -0,0 +1,46 @@ +// +// ErrorDialog.h +// +// Created by David Rowe on 30 May 2015 +// Copyright 2015 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 +// + +#pragma once + +#ifndef hifi_ErrorDialog_h +#define hifi_ErrorDialog_h + +#include "OffscreenQmlDialog.h" + +class ErrorDialog : public OffscreenQmlDialog +{ + Q_OBJECT + HIFI_QML_DECL + +private: + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + +public: + ErrorDialog(QQuickItem* parent = 0); + virtual ~ErrorDialog(); + + QString text() const; + +public slots: + virtual void setVisible(bool v); + void setText(const QString& arg); + +signals: + void textChanged(); + +protected slots: + virtual void accept(); + +private: + QString _text; +}; + +#endif // hifi_ErrorDialog_h diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp index 449657ca04..d94cad20d2 100644 --- a/libraries/ui/src/OffscreenUi.cpp +++ b/libraries/ui/src/OffscreenUi.cpp @@ -13,6 +13,7 @@ #include #include #include +#include "ErrorDialog.h" #include "MessageDialog.h" @@ -130,6 +131,15 @@ void OffscreenUi::critical(const QString& title, const QString& text, static_cast(MessageDialog::Critical), buttons); } +void OffscreenUi::error(const QString& text) { + ErrorDialog* pDialog{ nullptr }; + ErrorDialog::show([&](QQmlContext* ctx, QObject* item) { + pDialog = item->findChild(); + pDialog->setText(text); + }); + pDialog->setEnabled(true); +} + OffscreenUi::ButtonCallback OffscreenUi::NO_OP_CALLBACK = [](QMessageBox::StandardButton) {}; diff --git a/libraries/ui/src/OffscreenUi.h b/libraries/ui/src/OffscreenUi.h index d3567bbb5e..4d0044e775 100644 --- a/libraries/ui/src/OffscreenUi.h +++ b/libraries/ui/src/OffscreenUi.h @@ -115,6 +115,8 @@ public: static void critical(const QString& title, const QString& text, ButtonCallback callback = NO_OP_CALLBACK, QMessageBox::StandardButtons buttons = QMessageBox::Ok); + + static void error(const QString& text); // Interim dialog in new style }; #endif From 9a8bb67f37cae3b9e328fa49227daebe6329b246 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sun, 31 May 2015 20:56:26 -0700 Subject: [PATCH 46/72] Tidy address bar dialog code --- interface/resources/qml/AddressBarDialog.qml | 56 ++++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml index a3f7c6ba18..2a18c21bdf 100644 --- a/interface/resources/qml/AddressBarDialog.qml +++ b/interface/resources/qml/AddressBarDialog.qml @@ -1,3 +1,13 @@ +// +// AddressBarDialog.qml +// +// Created by Austin Davis on 2015/04/14 +// Copyright 2015 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 +// + import Hifi 1.0 import QtQuick 2.3 import QtQuick.Controls 1.2 @@ -12,7 +22,6 @@ Item { property int animationDuration: hifi.effects.fadeInDuration property bool destroyOnInvisible: false - property bool destroyOnCloseButton: true implicitWidth: addressBarDialog.implicitWidth implicitHeight: addressBarDialog.implicitHeight @@ -24,8 +33,8 @@ Item { id: addressBarDialog property int iconOverlap: 15 // Let the circle overlap window edges and rectangular part of dialog - property int maximumX: root.parent.width - root.width - property int maximumY: root.parent.height - root.height + property int maximumX: root.parent ? root.parent.width - root.width : 0 + property int maximumY: root.parent ? root.parent.height - root.height : 0 implicitWidth: box.width + icon.width - iconOverlap * 2 implicitHeight: addressLine.height + hifi.layout.spacing * 2 @@ -39,13 +48,10 @@ Item { radius: 6 color: "#ededee" - x: icon.width - addressBarDialog.iconOverlap * 2 // W.r.t. addressBarDialog + x: icon.width - addressBarDialog.iconOverlap * 2 // Relative to addressBarDialog MouseArea { - id: boxDrag - anchors.fill: parent - drag { target: root minimumX: 0 @@ -58,18 +64,20 @@ Item { TextInput { id: addressLine - anchors.fill: parent - anchors.leftMargin: addressBarDialog.iconOverlap + hifi.layout.spacing * 2 - anchors.rightMargin: hifi.layout.spacing * 2 - anchors.topMargin: hifi.layout.spacing - anchors.bottomMargin: hifi.layout.spacing + anchors { + fill: parent + leftMargin: addressBarDialog.iconOverlap + hifi.layout.spacing * 2 + rightMargin: hifi.layout.spacing * 2 + topMargin: hifi.layout.spacing + bottomMargin: hifi.layout.spacing + } font.pointSize: 15 helperText: "Go to: place, @user, /path, network address" onAccepted: { - event.accepted - addressBarDialog.loadAddress(addressLine.text) + event.accepted = true // Generates erroneous error in program log, "ReferenceError: event is not defined". + addressBarDialog.loadAddress(addressLine.text) } } } @@ -79,15 +87,14 @@ Item { source: "../images/address-bar-icon.svg" width: 80 height: 80 - anchors.right: box.left - anchors.rightMargin: -addressBarDialog.iconOverlap - anchors.verticalCenter: parent.verticalCenter + anchors { + right: box.left + rightMargin: -addressBarDialog.iconOverlap + verticalCenter: parent.verticalCenter + } MouseArea { - id: iconDrag - anchors.fill: parent - drag { target: root minimumX: 0 @@ -138,15 +145,6 @@ Item { } - function close() { - // The close function performs the same way as the OffscreenUI class: don't do anything but manipulate the enabled flag - // and let the other mechanisms decide if the window should be destroyed after the close animation completes. - if (destroyOnCloseButton) { - destroyOnInvisible = true - } - enabled = false - } - function reset() { addressLine.text = "" } From 8a191a661d3e8d6ad0d23fc51157922569fe451e Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Mon, 1 Jun 2015 09:35:32 -0700 Subject: [PATCH 47/72] adding flag for points changed --- .../entities-renderer/src/RenderableLineEntityItem.cpp | 5 ++++- libraries/entities/src/LineEntityItem.cpp | 10 ++++++++-- libraries/entities/src/LineEntityItem.h | 5 ++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 95c0ad9d6c..5c0f7b543c 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -41,7 +41,10 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); QVector points; - geometryCache->updateVertices(_lineVerticesID, getLinePoints(), lineColor); + if(_pointsChanged){ + geometryCache->updateVertices(_lineVerticesID, getLinePoints(), lineColor); + _pointsChanged = false; + } geometryCache->renderVertices(gpu::LINE_STRIP, _lineVerticesID); glPopMatrix(); RenderableDebugableEntityItem::render(this, args); diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index 167b64bde2..28059254ad 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -32,7 +32,8 @@ EntityItem* LineEntityItem::factory(const EntityItemID& entityID, const EntityIt LineEntityItem::LineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) , _lineWidth(DEFAULT_LINE_WIDTH), - _points(QVector(0)) + _points(QVector(0)), + _pointsChanged(true) { _type = EntityTypes::Line; _created = properties.getCreated(); @@ -83,7 +84,12 @@ bool LineEntityItem::setProperties(const EntityItemProperties& properties) { return somethingChanged; } -int LineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, +void LineEntityItem::setLinePoints(const QVector& points) { + _points = points; + _pointsChanged = true; +} + +int LineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args, EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index 9b95a41361..d1665ec3f8 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -59,9 +59,7 @@ class LineEntityItem : public EntityItem { return _lineWidth; } - void setLinePoints(const QVector& points){ - _points = points; - } + void setLinePoints(const QVector& points); const QVector& getLinePoints() const{ return _points; @@ -81,6 +79,7 @@ class LineEntityItem : public EntityItem { protected: rgbColor _color; float _lineWidth; + bool _pointsChanged; QVector _points; }; From 45331e5a0e0edc2c1c747c93c3ba6d0b63f819d4 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Mon, 1 Jun 2015 09:37:54 -0700 Subject: [PATCH 48/72] removed sounds from grab script --- examples/grab.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/examples/grab.js b/examples/grab.js index f1e1b6571c..7ed69e9664 100644 --- a/examples/grab.js +++ b/examples/grab.js @@ -36,8 +36,6 @@ var angularVelocity = { z: 0 }; -var grabSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/CloseClamp.wav"); -var releaseSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/ReleaseClamp.wav"); var DROP_DISTANCE = 5.0; var DROP_COLOR = { @@ -90,10 +88,6 @@ function mousePressEvent(event) { gravity: {x: 0, y: 0, z: 0} }); - Audio.playSound(grabSound, { - position: props.position, - volume: 0.4 - }); } } @@ -135,11 +129,6 @@ function mouseReleaseEvent() { }); targetPosition = null; - Audio.playSound(grabSound, { - position: entityProps.position, - volume: 0.25 - }); - } } From 7b08537574fdc820a15d94422fdd0cf69e88721b Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Mon, 1 Jun 2015 09:51:24 -0700 Subject: [PATCH 49/72] code standards fixes --- .../src/RenderableLineEntityItem.cpp | 2 +- libraries/entities/src/LineEntityItem.h | 13 +++---------- libraries/shared/src/RegisteredMetaTypes.cpp | 4 ++-- libraries/shared/src/RegisteredMetaTypes.h | 4 ++-- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 5c0f7b543c..0351e1f4e0 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -41,7 +41,7 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); QVector points; - if(_pointsChanged){ + if(_pointsChanged) { geometryCache->updateVertices(_lineVerticesID, getLinePoints(), lineColor); _pointsChanged = false; } diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index d1665ec3f8..d9533e3204 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -51,19 +51,12 @@ class LineEntityItem : public EntityItem { _color[BLUE_INDEX] = value.blue; } - void setLineWidth(float lineWidth){ - _lineWidth = lineWidth; - } - float getLineWidth() const{ - - return _lineWidth; - } + void setLineWidth(float lineWidth){ _lineWidth = lineWidth; } + float getLineWidth() const{ return _lineWidth; } void setLinePoints(const QVector& points); - const QVector& getLinePoints() const{ - return _points; - } + const QVector& getLinePoints() const{ return _points; } virtual ShapeType getShapeType() const { return SHAPE_TYPE_LINE; } diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index dda55680cf..4f57eea411 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -73,7 +73,7 @@ void vec3FromScriptValue(const QScriptValue &object, glm::vec3 &vec3) { vec3.z = object.property("z").toVariant().toFloat(); } -QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector &vector){ +QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector& vector){ QScriptValue array = engine->newArray(); for(int i = 0; i < vector.size(); i++){ array.setProperty(i, vec3toScriptValue(engine, vector.at(i))); @@ -81,7 +81,7 @@ QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector qVectorVec3FromScriptValue(const QScriptValue &array){ +QVector qVectorVec3FromScriptValue(const QScriptValue& array){ QVector newVector(0); int length = array.property("length").toInteger(); diff --git a/libraries/shared/src/RegisteredMetaTypes.h b/libraries/shared/src/RegisteredMetaTypes.h index bab4dc7d08..48eecba227 100644 --- a/libraries/shared/src/RegisteredMetaTypes.h +++ b/libraries/shared/src/RegisteredMetaTypes.h @@ -56,8 +56,8 @@ void qColorFromScriptValue(const QScriptValue& object, QColor& color); QScriptValue qURLToScriptValue(QScriptEngine* engine, const QUrl& url); void qURLFromScriptValue(const QScriptValue& object, QUrl& url); -QScriptValue qVectorVec3ToScriptValue(QScriptEngine*, const QVector& vector); -QVector qVectorVec3FromScriptValue( const QScriptValue &array); +QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector& vector); +QVector qVectorVec3FromScriptValue( const QScriptValue& array); class PickRay { public: From b166e24ff5daac0bef3c4d401e7c5d7b6f307f65 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 1 Jun 2015 11:06:33 -0700 Subject: [PATCH 50/72] Fix initial fade-in --- interface/resources/qml/AddressBarDialog.qml | 2 +- interface/resources/qml/ErrorDialog.qml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml index 2a18c21bdf..30890c0050 100644 --- a/interface/resources/qml/AddressBarDialog.qml +++ b/interface/resources/qml/AddressBarDialog.qml @@ -111,7 +111,7 @@ Item { // that can be animated, like scale or opacity, and then when the target animation value is reached, we can modify the // visibility. enabled: false - opacity: 1.0 + opacity: 0.0 onEnabledChanged: { opacity = enabled ? 1.0 : 0.0 diff --git a/interface/resources/qml/ErrorDialog.qml b/interface/resources/qml/ErrorDialog.qml index 72b2c24e90..c0f8132f14 100644 --- a/interface/resources/qml/ErrorDialog.qml +++ b/interface/resources/qml/ErrorDialog.qml @@ -104,7 +104,7 @@ Item { // that can be animated, like scale or opacity, and then when the target animation value is reached, we can modify the // visibility. enabled: false - opacity: 1.0 + opacity: 0.0 onEnabledChanged: { opacity = enabled ? 1.0 : 0.0 From 93c3f90c950afea0a9ecb23fc29fd93e4bec90f6 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Mon, 1 Jun 2015 11:08:48 -0700 Subject: [PATCH 51/72] clened up read and write of qVec- no longer converting between qVector and qByteArray --- libraries/octree/src/OctreePacketData.cpp | 56 ++++++++--------------- 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index f76e2a6d9b..50579e3979 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -381,23 +381,19 @@ bool OctreePacketData::appendValue(const glm::vec3& value) { return success; } -bool OctreePacketData::appendValue(const QVector& value){ - uint16_t qVecSize = value.size() * sizeof(glm::vec3); - QByteArray myArray; - const char* data = (const char*)value.data(); - char* sizePointer = (char*)&qVecSize; - QByteArray vecSize(sizePointer, sizeof(uint16_t)); - myArray.append(vecSize); - uint16_t arrayLength; - memcpy(&arrayLength, myArray.data(), sizeof(uint16_t)); - for(int i = 0; i < qVecSize; i++){ - myArray.append(data[i]); - } - int length = qVecSize + sizeof(uint16_t); - bool success = append((const unsigned char*)myArray.constData(), myArray.size()); +bool OctreePacketData::appendValue(const QVector& value) { + uint16_t qVecSize = value.size(); + uint16_t sizeLength = sizeof(qVecSize); + bool success = append((const unsigned char*)&qVecSize, sizeLength); + qDebug()<<"appendlength"<& result){ +int OctreePacketData::uppackDataFromBytes(const unsigned char *dataBytes, QVector& result) { uint16_t length; memcpy(&length, dataBytes, sizeof(uint16_t)); dataBytes += sizeof(length); - glm::vec3 myVec; - for(int i = 0 ; i < length; i+= sizeof(float) * 3) { - //Go through and create three floats - glm::vec3 point; - float x; - memcpy(&x, dataBytes, sizeof(float)); - point.x = x; - dataBytes += sizeof(float); - float y; - memcpy(&y, dataBytes, sizeof(float)); - point.y = y; - dataBytes += sizeof(float); - float z; - memcpy(&z, dataBytes, sizeof(float)); - point.z = z; - dataBytes += sizeof(float); - result.append(point); - } - return length + sizeof(length); -} + qDebug()<<"unpacking length"< Date: Mon, 1 Jun 2015 11:11:08 -0700 Subject: [PATCH 52/72] removed unneeded append methods from OctreePacketData --- libraries/octree/src/OctreePacketData.cpp | 5 ----- libraries/octree/src/OctreePacketData.h | 1 - 2 files changed, 6 deletions(-) diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index 50579e3979..5096550181 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -385,7 +385,6 @@ bool OctreePacketData::appendValue(const QVector& value) { uint16_t qVecSize = value.size(); uint16_t sizeLength = sizeof(qVecSize); bool success = append((const unsigned char*)&qVecSize, sizeLength); - qDebug()<<"appendlength"< Date: Mon, 1 Jun 2015 12:01:45 -0700 Subject: [PATCH 53/72] better handling of changes to the size of voxel space. limit each dimension to 32 --- .../src/RenderablePolyVoxEntityItem.cpp | 187 ++++++++++++------ .../src/RenderablePolyVoxEntityItem.h | 4 +- libraries/entities/src/PolyVoxEntityItem.cpp | 37 +++- libraries/entities/src/PolyVoxEntityItem.h | 7 +- 4 files changed, 172 insertions(+), 63 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 63c8104c80..c3b5033466 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -53,15 +53,35 @@ RenderablePolyVoxEntityItem::~RenderablePolyVoxEntityItem() { delete _volData; } +bool inBounds(const PolyVox::SimpleVolume* vol, PolyVoxEntityItem::PolyVoxSurfaceStyle surfaceStyle, + int x, int y, int z) { + switch (surfaceStyle) { + case PolyVoxEntityItem::SURFACE_MARCHING_CUBES: + case PolyVoxEntityItem::SURFACE_CUBIC: + if (x < 0 || y < 0 || z < 0 || + x >= vol->getWidth() || y >= vol->getHeight() || z >= vol->getDepth()) { + return false; + } + return true; + + case PolyVoxEntityItem::SURFACE_EDGED_CUBIC: + if (x < 1 || y < 1 || z < 1 || + x >= vol->getWidth() - 1 || y >= vol->getHeight() - 1 || z >= vol->getDepth() - 1) { + return false; + } + return true; + } + + return false; +} + void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) { if (_volData && voxelVolumeSize == _voxelVolumeSize) { return; } - qDebug() << "resetting voxel-space size"; + qDebug() << "resetting voxel-space size" << voxelVolumeSize.x << voxelVolumeSize.y << voxelVolumeSize.z; - - glm::vec3 previousVolumeSize = _voxelVolumeSize; PolyVoxEntityItem::setVoxelVolumeSize(voxelVolumeSize); if (_volData) { @@ -71,21 +91,43 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) _onCount = 0; if (_voxelSurfaceStyle == SURFACE_EDGED_CUBIC) { + // with _EDGED_ we maintain an extra box of voxels around those that the user asked for. This + // changes how the surface extractor acts -- mainly it becomes impossible to have holes in the + // generated mesh. The non _EDGED_ modes will leave holes in the mesh at the edges of the + // voxel space. PolyVox::Vector3DInt32 lowCorner(0, 0, 0); - PolyVox::Vector3DInt32 highCorner(_voxelVolumeSize[0] + 1, // -1 + 2 because these corners are inclusive - _voxelVolumeSize[1] + 1, - _voxelVolumeSize[2] + 1); + PolyVox::Vector3DInt32 highCorner(_voxelVolumeSize.x + 1, // -1 + 2 because these corners are inclusive + _voxelVolumeSize.y + 1, + _voxelVolumeSize.z + 1); _volData = new PolyVox::SimpleVolume(PolyVox::Region(lowCorner, highCorner)); } else { PolyVox::Vector3DInt32 lowCorner(0, 0, 0); - PolyVox::Vector3DInt32 highCorner(_voxelVolumeSize[0] - 1, // -1 because these corners are inclusive - _voxelVolumeSize[1] - 1, - _voxelVolumeSize[2] - 1); + PolyVox::Vector3DInt32 highCorner(_voxelVolumeSize.x - 1, // -1 because these corners are inclusive + _voxelVolumeSize.y - 1, + _voxelVolumeSize.z - 1); _volData = new PolyVox::SimpleVolume(PolyVox::Region(lowCorner, highCorner)); } + + // having the "outside of voxel-space" value be 255 has helped me notice some problems. _volData->setBorderValue(255); - decompressVolumeData(previousVolumeSize); - compressVolumeData(); + + qDebug() << " new size is" << _volData->getWidth() << _volData->getHeight() << _volData->getDepth(); + + // I'm not sure this is needed... the docs say that each element is initialized with its default + // constructor. I'll leave it here for now. + for (int z = 0; z < _volData->getDepth(); z++) { + for (int y = 0; y < _volData->getHeight(); y++) { + for (int x = 0; x < _volData->getWidth(); x++) { + _volData->setVoxelAt(x, y, z, 0); + } + } + } + + // It's okay to decompress the old data here, because the data includes its original dimensions along + // with the voxel data, and writing voxels outside the bounds of the new space is harmless. This allows + // adjusting of the voxel-space size without overly mangling the shape. Shrinking the space and then + // restoring the previous size (without any edits in between) will put the original shape back. + decompressVolumeData(); } void RenderablePolyVoxEntityItem::setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { @@ -153,8 +195,7 @@ glm::mat4 RenderablePolyVoxEntityItem::worldToVoxelMatrix() const { uint8_t RenderablePolyVoxEntityItem::getVoxel(int x, int y, int z) { assert(_volData); - if (x < 0 || y < 0 || z < 0 || - x >= _voxelVolumeSize[0] || y >= _voxelVolumeSize[1] || z >= _voxelVolumeSize[2]) { + if (!inBounds(_volData, _voxelSurfaceStyle, x, y, z)) { return 0; } @@ -170,8 +211,7 @@ uint8_t RenderablePolyVoxEntityItem::getVoxel(int x, int y, int z) { void RenderablePolyVoxEntityItem::setVoxel(int x, int y, int z, uint8_t toValue) { assert(_volData); - if (x < 0 || y < 0 || z < 0 || - x >= _voxelVolumeSize[0] || y >= _voxelVolumeSize[1] || z >= _voxelVolumeSize[2]) { + if (!inBounds(_volData, _voxelSurfaceStyle, x, y, z)) { return; } @@ -185,6 +225,10 @@ void RenderablePolyVoxEntityItem::setVoxel(int x, int y, int z, uint8_t toValue) void RenderablePolyVoxEntityItem::updateOnCount(int x, int y, int z, uint8_t toValue) { // keep _onCount up to date + if (!inBounds(_volData, _voxelSurfaceStyle, x, y, z)) { + return; + } + uint8_t uVoxelValue = getVoxel(x, y, z); if (toValue != 0) { if (uVoxelValue == 0) { @@ -201,9 +245,9 @@ void RenderablePolyVoxEntityItem::updateOnCount(int x, int y, int z, uint8_t toV void RenderablePolyVoxEntityItem::setAll(uint8_t toValue) { - for (int z = 0; z < _voxelVolumeSize[2]; z++) { - for (int y = 0; y < _voxelVolumeSize[1]; y++) { - for (int x = 0; x < _voxelVolumeSize[0]; x++) { + for (int z = 0; z < _voxelVolumeSize.z; z++) { + for (int y = 0; y < _voxelVolumeSize.y; y++) { + for (int x = 0; x < _voxelVolumeSize.x; x++) { updateOnCount(x, y, z, toValue); setVoxel(x, y, z, toValue); } @@ -214,9 +258,9 @@ void RenderablePolyVoxEntityItem::setAll(uint8_t toValue) { void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue) { // This three-level for loop iterates over every voxel in the volume - for (int z = 0; z < _voxelVolumeSize[2]; z++) { - for (int y = 0; y < _voxelVolumeSize[1]; y++) { - for (int x = 0; x < _voxelVolumeSize[0]; x++) { + for (int z = 0; z < _voxelVolumeSize.z; z++) { + for (int y = 0; y < _voxelVolumeSize.y; y++) { + for (int x = 0; x < _voxelVolumeSize.x; x++) { // Store our current position as a vector... glm::vec3 pos(x + 0.5f, y + 0.5f, z + 0.5f); // consider voxels cenetered on their coordinates // And compute how far the current position is from the center of the volume @@ -236,7 +280,7 @@ void RenderablePolyVoxEntityItem::setSphere(glm::vec3 centerWorldCoords, float r // glm::vec3 centerVoxelCoords = worldToVoxelCoordinates(centerWorldCoords); glm::vec4 centerVoxelCoords = worldToVoxelMatrix() * glm::vec4(centerWorldCoords, 1.0f); glm::vec3 scale = _dimensions / _voxelVolumeSize; // meters / voxel-units - float scaleY = scale[0]; + float scaleY = scale.y; float radiusVoxelCoords = radiusWorldCoords / scaleY; setSphereInVolume(glm::vec3(centerVoxelCoords), radiusVoxelCoords, toValue); } @@ -356,17 +400,17 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) { class RaycastFunctor { public: - RaycastFunctor(PolyVox::SimpleVolume* vol) : + RaycastFunctor(PolyVox::SimpleVolume* vol, PolyVoxEntityItem::PolyVoxSurfaceStyle voxelSurfaceStyle) : _result(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), - _vol(vol) { + _vol(vol), + _voxelSurfaceStyle(voxelSurfaceStyle) { } bool operator()(PolyVox::SimpleVolume::Sampler& sampler) { int x = sampler.getPosition().getX(); int y = sampler.getPosition().getY(); int z = sampler.getPosition().getZ(); - if (x < 0 || y < 0 || z < 0 || - x > _vol->getWidth() || y > _vol->getHeight() || z > _vol->getDepth()) { + if (!inBounds(_vol, _voxelSurfaceStyle, x, y, z)) { return true; } @@ -379,6 +423,7 @@ public: } glm::vec4 _result; const PolyVox::SimpleVolume* _vol = nullptr; + PolyVoxEntityItem::PolyVoxSurfaceStyle _voxelSurfaceStyle; }; bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& origin, @@ -400,19 +445,19 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o // set ray cast length to long enough to cover all of the voxel space float distanceToEntity = glm::distance(origin, _position); - float largestDimension = glm::max(_dimensions[0], _dimensions[1], _dimensions[2]) * 2.0f; + float largestDimension = glm::max(_dimensions.x, _dimensions.y, _dimensions.z) * 2.0f; glm::vec3 farPoint = origin + normDirection * (distanceToEntity + largestDimension); glm::vec4 originInVoxel = wtvMatrix * glm::vec4(origin, 1.0f); glm::vec4 farInVoxel = wtvMatrix * glm::vec4(farPoint, 1.0f); - PolyVox::Vector3DFloat start(originInVoxel[0], originInVoxel[1], originInVoxel[2]); - // PolyVox::Vector3DFloat pvDirection(directionInVoxel[0], directionInVoxel[1], directionInVoxel[2]); - PolyVox::Vector3DFloat far(farInVoxel[0], farInVoxel[1], farInVoxel[2]); + PolyVox::Vector3DFloat start(originInVoxel.x, originInVoxel.y, originInVoxel.z); + // PolyVox::Vector3DFloat pvDirection(directionInVoxel.x, directionInVoxel.y, directionInVoxel.z); + PolyVox::Vector3DFloat far(farInVoxel.x, farInVoxel.y, farInVoxel.z); PolyVox::RaycastResult raycastResult; - RaycastFunctor callback(_volData); + RaycastFunctor callback(_volData, _voxelSurfaceStyle); raycastResult = PolyVox::raycastWithEndpoints(_volData, start, far, callback); if (raycastResult == PolyVox::RaycastResults::Completed) { @@ -445,31 +490,42 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o // compress the data in _volData and save the results. The compressed form is used during // saves to disk and for transmission over the wire void RenderablePolyVoxEntityItem::compressVolumeData() { - int rawSize = _voxelVolumeSize[0] * _voxelVolumeSize[1] * _voxelVolumeSize[2]; + quint16 voxelXSize = _voxelVolumeSize.x; + quint16 voxelYSize = _voxelVolumeSize.y; + quint16 voxelZSize = _voxelVolumeSize.z; + int rawSize = voxelXSize * voxelYSize * voxelZSize; + QByteArray uncompressedData = QByteArray(rawSize, '\0'); - for (int z = 0; z < _voxelVolumeSize[2]; z++) { - for (int y = 0; y < _voxelVolumeSize[1]; y++) { - for (int x = 0; x < _voxelVolumeSize[0]; x++) { + for (int z = 0; z < voxelZSize; z++) { + for (int y = 0; y < voxelYSize; y++) { + for (int x = 0; x < voxelXSize; x++) { uint8_t uVoxelValue = getVoxel(x, y, z); int uncompressedIndex = - z * _voxelVolumeSize[1] * _voxelVolumeSize[0] + - y * _voxelVolumeSize[0] + + z * voxelYSize * voxelXSize + + y * voxelXSize + x; uncompressedData[uncompressedIndex] = uVoxelValue; } } } - QByteArray newVoxelData = qCompress(uncompressedData, 9); - // HACK -- until we have a way to allow for properties larger than MTU, don't update. - if (newVoxelData.length() < 1200) { + QByteArray newVoxelData; + QDataStream writer(&newVoxelData, QIODevice::WriteOnly | QIODevice::Truncate); + writer << voxelXSize << voxelYSize << voxelZSize; + + QByteArray compressedData = qCompress(uncompressedData, 9); + writer << compressedData; + + // make sure the compressed data can be sent over the wire-protocol + if (newVoxelData.size() < 1150) { _voxelData = newVoxelData; qDebug() << "-------------- voxel compresss --------------"; qDebug() << "raw-size =" << rawSize << " compressed-size =" << newVoxelData.size(); } else { + // HACK -- until we have a way to allow for properties larger than MTU, don't update. qDebug() << "voxel data too large, reverting change."; - // revert + // revert the active voxel-space to the last version that fit. decompressVolumeData(); } @@ -478,25 +534,38 @@ void RenderablePolyVoxEntityItem::compressVolumeData() { } -// take compressed data and decompreess it into _volData. +// take compressed data and expand it into _volData. void RenderablePolyVoxEntityItem::decompressVolumeData() { - decompressVolumeData(_voxelVolumeSize); -} + QDataStream reader(_voxelData); + quint16 voxelXSize, voxelYSize, voxelZSize; + reader >> voxelXSize; + reader >> voxelYSize; + reader >> voxelZSize; + if (voxelXSize == 0 || voxelXSize > MAX_VOXEL_DIMENSION || + voxelYSize == 0 || voxelYSize > MAX_VOXEL_DIMENSION || + voxelZSize == 0 || voxelZSize > MAX_VOXEL_DIMENSION) { + qDebug() << "vixelSize is not reasonable, skipping decompressions." + << voxelXSize << voxelYSize << voxelZSize; + return; + } + + int rawSize = voxelXSize * voxelYSize * voxelZSize; + + QByteArray compressedData; + reader >> compressedData; + QByteArray uncompressedData = qUncompress(compressedData); -void RenderablePolyVoxEntityItem::decompressVolumeData(glm::vec3 volumeSize) { - int rawSize = volumeSize[0] * volumeSize[1] * volumeSize[2]; - QByteArray uncompressedData = QByteArray(rawSize, '\0'); + if (uncompressedData.size() != rawSize) { + qDebug() << "PolyVox decompress -- size is (" << voxelXSize << voxelYSize << voxelZSize << ")" << + "so expected uncompressed length of" << rawSize << "but length is" << uncompressedData.size(); + return; + } - uncompressedData = qUncompress(_voxelData); - - for (int z = 0; z < volumeSize[2]; z++) { - for (int y = 0; y < volumeSize[1]; y++) { - for (int x = 0; x < volumeSize[0]; x++) { - int uncompressedIndex = - z * volumeSize[1] * volumeSize[0] + - y * volumeSize[0] + - x; + for (int z = 0; z < voxelZSize; z++) { + for (int y = 0; y < voxelYSize; y++) { + for (int x = 0; x < voxelXSize; x++) { + int uncompressedIndex = (z * voxelYSize * voxelXSize) + (y * voxelZSize) + x; updateOnCount(x, y, z, uncompressedData[uncompressedIndex]); setVoxel(x, y, z, uncompressedData[uncompressedIndex]); } @@ -544,9 +613,9 @@ void RenderablePolyVoxEntityItem::computeShapeInfo(ShapeInfo& info) { AABox box; - for (int z = 0; z < _voxelVolumeSize[2]; z++) { - for (int y = 0; y < _voxelVolumeSize[1]; y++) { - for (int x = 0; x < _voxelVolumeSize[0]; x++) { + for (int z = 0; z < _voxelVolumeSize.z; z++) { + for (int y = 0; y < _voxelVolumeSize.y; y++) { + for (int x = 0; x < _voxelVolumeSize.x; x++) { if (getVoxel(x, y, z) > 0) { QVector pointsInPart; diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index c8039e79c1..86018b9fb2 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -70,9 +70,11 @@ public: virtual void setAll(uint8_t toValue); private: + // The PolyVoxEntityItem class has _voxelData which contains dimensions and compressed voxel data. The dimensions + // may not match _voxelVolumeSize. + void compressVolumeData(); void decompressVolumeData(); - void decompressVolumeData(glm::vec3 volumeSize); PolyVox::SimpleVolume* _volData = nullptr; model::Geometry _modelGeometry; diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index a7f1128771..e0cd397594 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -22,7 +22,8 @@ const glm::vec3 PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE = glm::vec3(32, 32, 32); -const QByteArray PolyVoxEntityItem::DEFAULT_VOXEL_DATA(qCompress(QByteArray(0), 9)); +const float PolyVoxEntityItem::MAX_VOXEL_DIMENSION = 32.0f; +const QByteArray PolyVoxEntityItem::DEFAULT_VOXEL_DATA(qCompress(QByteArray(0), 9)); // XXX const PolyVoxEntityItem::PolyVoxSurfaceStyle PolyVoxEntityItem::DEFAULT_VOXEL_SURFACE_STYLE = PolyVoxEntityItem::SURFACE_MARCHING_CUBES; @@ -41,6 +42,40 @@ PolyVoxEntityItem::PolyVoxEntityItem(const EntityItemID& entityItemID, const Ent setProperties(properties); } +void PolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) { + assert((int)_voxelVolumeSize.x == _voxelVolumeSize.x); + assert((int)_voxelVolumeSize.y == _voxelVolumeSize.y); + assert((int)_voxelVolumeSize.z == _voxelVolumeSize.z); + + _voxelVolumeSize = voxelVolumeSize; + if (_voxelVolumeSize.x < 1) { + qDebug() << "PolyVoxEntityItem::setVoxelVolumeSize clamping x of" << _voxelVolumeSize.x << "to 1"; + _voxelVolumeSize.x = 1; + } + if (_voxelVolumeSize.x > MAX_VOXEL_DIMENSION) { + qDebug() << "PolyVoxEntityItem::setVoxelVolumeSize clamping x of" << _voxelVolumeSize.x << "to max"; + _voxelVolumeSize.x = MAX_VOXEL_DIMENSION; + } + + if (_voxelVolumeSize.y < 1) { + qDebug() << "PolyVoxEntityItem::setVoxelVolumeSize clamping y of" << _voxelVolumeSize.y << "to 1"; + _voxelVolumeSize.y = 1; + } + if (_voxelVolumeSize.y > MAX_VOXEL_DIMENSION) { + qDebug() << "PolyVoxEntityItem::setVoxelVolumeSize clamping y of" << _voxelVolumeSize.y << "to max"; + _voxelVolumeSize.y = MAX_VOXEL_DIMENSION; + } + + if (_voxelVolumeSize.z < 1) { + qDebug() << "PolyVoxEntityItem::setVoxelVolumeSize clamping z of" << _voxelVolumeSize.z << "to 1"; + _voxelVolumeSize.z = 1; + } + if (_voxelVolumeSize.z > MAX_VOXEL_DIMENSION) { + qDebug() << "PolyVoxEntityItem::setVoxelVolumeSize clamping z of" << _voxelVolumeSize.z << "to max"; + _voxelVolumeSize.z = MAX_VOXEL_DIMENSION; + } +} + EntityItemProperties PolyVoxEntityItem::getProperties() const { EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class COPY_ENTITY_PROPERTY_TO_PROPERTIES(voxelVolumeSize, getVoxelVolumeSize); diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 8ef59f9f17..63bd4856d3 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -49,7 +49,7 @@ class PolyVoxEntityItem : public EntityItem { virtual void debugDump() const; - virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize) { _voxelVolumeSize = voxelVolumeSize; } + virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize); virtual const glm::vec3& getVoxelVolumeSize() const { return _voxelVolumeSize; } virtual void setVoxelData(QByteArray voxelData) { _voxelData = voxelData; } @@ -68,6 +68,8 @@ class PolyVoxEntityItem : public EntityItem { virtual PolyVoxSurfaceStyle getVoxelSurfaceStyle() const { return _voxelSurfaceStyle; } static const glm::vec3 DEFAULT_VOXEL_VOLUME_SIZE; + static const float MAX_VOXEL_DIMENSION; + static const QByteArray DEFAULT_VOXEL_DATA; static const PolyVoxSurfaceStyle DEFAULT_VOXEL_SURFACE_STYLE; @@ -81,7 +83,8 @@ class PolyVoxEntityItem : public EntityItem { virtual uint8_t getVoxel(int x, int y, int z) { return 0; } virtual void setVoxel(int x, int y, int z, uint8_t toValue) {} - + + protected: glm::vec3 _voxelVolumeSize; // this is always 3 bytes QByteArray _voxelData; From 293af425acaf17f3b61ff79317d4d5643fa48436 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 1 Jun 2015 12:49:26 -0700 Subject: [PATCH 54/72] remove vhacd block from windows build guide --- BUILD_WIN.md | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/BUILD_WIN.md b/BUILD_WIN.md index 169077ed78..e905a83ace 100644 --- a/BUILD_WIN.md +++ b/BUILD_WIN.md @@ -75,21 +75,6 @@ To prevent these problems, install OpenSSL yourself. Download the following bina Install OpenSSL into the Windows system directory, to make sure that Qt uses the version that you've just installed, and not some other version. -###vhacd -Download it directly from https://github.com/virneo/v-hacd - -To build it run the following commands - 1. cd src\ - 2. mkdir build - 3. cd build - 4. cmake .. - -Build using visual studio 2013. Build ALL_BUILD and INSTALL targets both in Release and Debug. - -This will create an output folder with include and lib directory inside it. - -Either copy the contents of output folder to ENV %HIFI_LIB_DIR%/vhacd or create an environment variable VHACD_ROOT_DIR to this output directory. - ###Build High Fidelity using Visual Studio Follow the same build steps from the CMake section of [BUILD.md](BUILD.md), but pass a different generator to CMake. From 9c52c79fe1df20bcf00ed5ff2c00fa95c3cd8860 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 1 Jun 2015 13:29:36 -0700 Subject: [PATCH 55/72] Combine icon and input areas into a single SVG --- .../{address-bar-icon.svg => address-bar.svg} | 23 +++-- interface/resources/qml/AddressBarDialog.qml | 89 +++++++++---------- 2 files changed, 57 insertions(+), 55 deletions(-) rename interface/resources/images/{address-bar-icon.svg => address-bar.svg} (81%) diff --git a/interface/resources/images/address-bar-icon.svg b/interface/resources/images/address-bar.svg similarity index 81% rename from interface/resources/images/address-bar-icon.svg rename to interface/resources/images/address-bar.svg index a6d67aabae..0a472cbe4e 100644 --- a/interface/resources/images/address-bar-icon.svg +++ b/interface/resources/images/address-bar.svg @@ -8,14 +8,14 @@ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" version="1.1" - width="200" + width="1440" height="200" data-icon="map-marker" data-container-transform="translate(24)" - viewBox="0 0 200 200" + viewBox="0 0 1440 200" id="svg4136" inkscape:version="0.91 r13725" - sodipodi:docname="address-icon.svg"> + sodipodi:docname="address-bar.svg"> @@ -24,7 +24,7 @@ image/svg+xml - + @@ -43,13 +43,22 @@ inkscape:window-height="1057" id="namedview4140" showgrid="false" - inkscape:zoom="0.43359375" - inkscape:cx="64" - inkscape:cy="144.72072" + inkscape:zoom="0.8671875" + inkscape:cx="707.02439" + inkscape:cy="52.468468" inkscape:window-x="72" inkscape:window-y="-8" inkscape:window-maximized="1" inkscape:current-layer="svg4136" /> + Date: Mon, 1 Jun 2015 13:54:14 -0700 Subject: [PATCH 56/72] Untabify --- interface/resources/qml/AddressBarDialog.qml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml index 8d11fa9bb5..3893c26f3c 100644 --- a/interface/resources/qml/AddressBarDialog.qml +++ b/interface/resources/qml/AddressBarDialog.qml @@ -100,9 +100,9 @@ Item { } // The UI enables an object, rather than manipulating its visibility, so that we can do animations in both directions. - // Because visibility and enabled are booleans, they cannot be animated. So when enabled is changed, we modify a property - // that can be animated, like scale or opacity, and then when the target animation value is reached, we can modify the - // visibility. + // Because visibility and enabled are booleans, they cannot be animated. So when enabled is changed, we modify a property + // that can be animated, like scale or opacity, and then when the target animation value is reached, we can modify the + // visibility. enabled: false opacity: 0.0 @@ -122,7 +122,7 @@ Item { } onOpacityChanged: { - // Once we're transparent, disable the dialog's visibility. + // Once we're transparent, disable the dialog's visibility. visible = (opacity != 0.0) } @@ -130,10 +130,10 @@ Item { if (!visible) { reset() - // Some dialogs should be destroyed when they become invisible. - if (destroyOnInvisible) { - destroy() - } + // Some dialogs should be destroyed when they become invisible. + if (destroyOnInvisible) { + destroy() + } } } From d1bb6473d9751f7f3c4b139306f4793e648d6ae7 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 1 Jun 2015 13:57:28 -0700 Subject: [PATCH 57/72] more work on edge handling and resizing --- .../src/RenderablePolyVoxEntityItem.cpp | 47 ++++++++++------ .../src/RenderablePolyVoxEntityItem.h | 2 + .../entities/src/EntityScriptingInterface.cpp | 56 +++++++------------ .../entities/src/EntityScriptingInterface.h | 3 + libraries/entities/src/PolyVoxEntityItem.h | 2 + 5 files changed, 58 insertions(+), 52 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index c3b5033466..e190d8f8da 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -53,8 +53,9 @@ RenderablePolyVoxEntityItem::~RenderablePolyVoxEntityItem() { delete _volData; } -bool inBounds(const PolyVox::SimpleVolume* vol, PolyVoxEntityItem::PolyVoxSurfaceStyle surfaceStyle, +bool inUserBounds(const PolyVox::SimpleVolume* vol, PolyVoxEntityItem::PolyVoxSurfaceStyle surfaceStyle, int x, int y, int z) { + // x, y, z are in user voxel-coords, not adjusted-for-edge voxel-coords. switch (surfaceStyle) { case PolyVoxEntityItem::SURFACE_MARCHING_CUBES: case PolyVoxEntityItem::SURFACE_CUBIC: @@ -65,8 +66,8 @@ bool inBounds(const PolyVox::SimpleVolume* vol, PolyVoxEntityItem::Poly return true; case PolyVoxEntityItem::SURFACE_EDGED_CUBIC: - if (x < 1 || y < 1 || z < 1 || - x >= vol->getWidth() - 1 || y >= vol->getHeight() - 1 || z >= vol->getDepth() - 1) { + if (x < 0 || y < 0 || z < 0 || + x >= vol->getWidth() - 2 || y >= vol->getHeight() - 2 || z >= vol->getDepth() - 2) { return false; } return true; @@ -75,6 +76,17 @@ bool inBounds(const PolyVox::SimpleVolume* vol, PolyVoxEntityItem::Poly return false; } + +bool inBounds(const PolyVox::SimpleVolume* vol, int x, int y, int z) { + // x, y, z are in polyvox volume coords + if (x < 0 || y < 0 || z < 0 || + x >= vol->getWidth() || y >= vol->getHeight() || z >= vol->getDepth()) { + return false; + } + return true; +} + + void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) { if (_volData && voxelVolumeSize == _voxelVolumeSize) { return; @@ -195,7 +207,7 @@ glm::mat4 RenderablePolyVoxEntityItem::worldToVoxelMatrix() const { uint8_t RenderablePolyVoxEntityItem::getVoxel(int x, int y, int z) { assert(_volData); - if (!inBounds(_volData, _voxelSurfaceStyle, x, y, z)) { + if (!inUserBounds(_volData, _voxelSurfaceStyle, x, y, z)) { return 0; } @@ -211,7 +223,7 @@ uint8_t RenderablePolyVoxEntityItem::getVoxel(int x, int y, int z) { void RenderablePolyVoxEntityItem::setVoxel(int x, int y, int z, uint8_t toValue) { assert(_volData); - if (!inBounds(_volData, _voxelSurfaceStyle, x, y, z)) { + if (!inUserBounds(_volData, _voxelSurfaceStyle, x, y, z)) { return; } @@ -225,7 +237,7 @@ void RenderablePolyVoxEntityItem::setVoxel(int x, int y, int z, uint8_t toValue) void RenderablePolyVoxEntityItem::updateOnCount(int x, int y, int z, uint8_t toValue) { // keep _onCount up to date - if (!inBounds(_volData, _voxelSurfaceStyle, x, y, z)) { + if (!inUserBounds(_volData, _voxelSurfaceStyle, x, y, z)) { return; } @@ -243,7 +255,6 @@ void RenderablePolyVoxEntityItem::updateOnCount(int x, int y, int z, uint8_t toV } } - void RenderablePolyVoxEntityItem::setAll(uint8_t toValue) { for (int z = 0; z < _voxelVolumeSize.z; z++) { for (int y = 0; y < _voxelVolumeSize.y; y++) { @@ -256,6 +267,11 @@ void RenderablePolyVoxEntityItem::setAll(uint8_t toValue) { compressVolumeData(); } +void RenderablePolyVoxEntityItem::setVoxelInVolume(glm::vec3 position, uint8_t toValue) { + updateOnCount(position.x, position.y, position.z, toValue); + setVoxel(position.x, position.y, position.z, toValue); +} + void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue) { // This three-level for loop iterates over every voxel in the volume for (int z = 0; z < _voxelVolumeSize.z; z++) { @@ -400,17 +416,17 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) { class RaycastFunctor { public: - RaycastFunctor(PolyVox::SimpleVolume* vol, PolyVoxEntityItem::PolyVoxSurfaceStyle voxelSurfaceStyle) : + RaycastFunctor(PolyVox::SimpleVolume* vol) : _result(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)), - _vol(vol), - _voxelSurfaceStyle(voxelSurfaceStyle) { + _vol(vol) { } bool operator()(PolyVox::SimpleVolume::Sampler& sampler) { int x = sampler.getPosition().getX(); int y = sampler.getPosition().getY(); int z = sampler.getPosition().getZ(); - if (!inBounds(_vol, _voxelSurfaceStyle, x, y, z)) { + + if (!inBounds(_vol, x, y, z)) { return true; } @@ -423,7 +439,6 @@ public: } glm::vec4 _result; const PolyVox::SimpleVolume* _vol = nullptr; - PolyVoxEntityItem::PolyVoxSurfaceStyle _voxelSurfaceStyle; }; bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& origin, @@ -452,13 +467,13 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o glm::vec4 originInVoxel = wtvMatrix * glm::vec4(origin, 1.0f); glm::vec4 farInVoxel = wtvMatrix * glm::vec4(farPoint, 1.0f); - PolyVox::Vector3DFloat start(originInVoxel.x, originInVoxel.y, originInVoxel.z); + PolyVox::Vector3DFloat startPoint(originInVoxel.x, originInVoxel.y, originInVoxel.z); // PolyVox::Vector3DFloat pvDirection(directionInVoxel.x, directionInVoxel.y, directionInVoxel.z); - PolyVox::Vector3DFloat far(farInVoxel.x, farInVoxel.y, farInVoxel.z); + PolyVox::Vector3DFloat endPoint(farInVoxel.x, farInVoxel.y, farInVoxel.z); PolyVox::RaycastResult raycastResult; - RaycastFunctor callback(_volData, _voxelSurfaceStyle); - raycastResult = PolyVox::raycastWithEndpoints(_volData, start, far, callback); + RaycastFunctor callback(_volData); + raycastResult = PolyVox::raycastWithEndpoints(_volData, startPoint, endPoint, callback); if (raycastResult == PolyVox::RaycastResults::Completed) { // the ray completed its path -- nothing was hit. diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index 86018b9fb2..c8f1b4a49d 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -69,6 +69,8 @@ public: virtual void setAll(uint8_t toValue); + virtual void setVoxelInVolume(glm::vec3 position, uint8_t toValue); + private: // The PolyVoxEntityItem class has _voxelData which contains dimensions and compressed voxel data. The dimensions // may not match _voxelVolumeSize. diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 34c5199a0c..6866505d58 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -17,7 +17,6 @@ #include "ModelEntityItem.h" #include "ZoneEntityItem.h" #include "EntitiesLogging.h" -#include "PolyVoxEntityItem.h" EntityScriptingInterface::EntityScriptingInterface() : @@ -395,7 +394,8 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra } -bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) { +bool EntityScriptingInterface::setVoxels(QUuid entityID, + std::function actor) { if (!_entityTree) { return false; } @@ -415,7 +415,7 @@ bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& c PolyVoxEntityItem* polyVoxEntity = static_cast(entity.get()); _entityTree->lockForWrite(); - polyVoxEntity->setSphere(center, radius, value); + actor(*polyVoxEntity); entity->setLastEdited(now); entity->setLastBroadcast(now); _entityTree->unlock(); @@ -432,38 +432,22 @@ bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& c } +bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) { + return setVoxels(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) { + polyVoxEntity.setSphere(center, radius, value); + }); +} + + +bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) { + return setVoxels(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) { + polyVoxEntity.setVoxelInVolume(position, value); + }); +} + + bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { - if (!_entityTree) { - return false; - } - - EntityItemPointer entity = static_cast(_entityTree->findEntityByEntityItemID(entityID)); - if (!entity) { - qCDebug(entities) << "EntityScriptingInterface::setVoxelSphere no entity with ID" << entityID; - return false; - } - - EntityTypes::EntityType entityType = entity->getType(); - if (entityType != EntityTypes::PolyVox) { - return false; - } - - auto now = usecTimestampNow(); - - PolyVoxEntityItem* polyVoxEntity = static_cast(entity.get()); - _entityTree->lockForWrite(); - polyVoxEntity->setAll(value); - entity->setLastEdited(now); - entity->setLastBroadcast(now); - _entityTree->unlock(); - - _entityTree->lockForRead(); - EntityItemProperties properties = entity->getProperties(); - _entityTree->unlock(); - - properties.setVoxelDataDirty(); - properties.setLastEdited(now); - - queueEntityMessage(PacketTypeEntityEdit, entityID, properties); - return true; + return setVoxels(entityID, [value](PolyVoxEntityItem& polyVoxEntity) { + polyVoxEntity.setAll(value); + }); } diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 421875feef..7761effe2f 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -21,6 +21,7 @@ #include #include #include +#include "PolyVoxEntityItem.h" #include "EntityEditPacketSender.h" @@ -117,7 +118,9 @@ public slots: Q_INVOKABLE void setSendPhysicsUpdates(bool value); Q_INVOKABLE bool getSendPhysicsUpdates() const; + bool setVoxels(QUuid entityID, std::function actor); Q_INVOKABLE bool setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value); + Q_INVOKABLE bool setVoxel(QUuid entityID, const glm::vec3& position, int value); Q_INVOKABLE bool setAllVoxels(QUuid entityID, int value); Q_INVOKABLE void dumpTree() const; diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 63bd4856d3..bf8214675b 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -81,6 +81,8 @@ class PolyVoxEntityItem : public EntityItem { virtual void setAll(uint8_t toValue) {} + virtual void setVoxelInVolume(glm::vec3 position, uint8_t toValue) {} + virtual uint8_t getVoxel(int x, int y, int z) { return 0; } virtual void setVoxel(int x, int y, int z, uint8_t toValue) {} From ea3f002a65e3ca2942cd0f965bf9b0ff4fd52245 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 1 Jun 2015 14:38:07 -0700 Subject: [PATCH 58/72] ifdef out debug pritns --- .../src/RenderablePolyVoxEntityItem.cpp | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index e190d8f8da..6f2fe42502 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -33,7 +33,6 @@ #include "EntityTreeRenderer.h" #include "RenderablePolyVoxEntityItem.h" - EntityItemPointer RenderablePolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { return EntityItemPointer(new RenderablePolyVoxEntityItem(entityID, properties)); } @@ -92,7 +91,9 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) return; } + #ifdef WANT_DEBUG qDebug() << "resetting voxel-space size" << voxelVolumeSize.x << voxelVolumeSize.y << voxelVolumeSize.z; + #endif PolyVoxEntityItem::setVoxelVolumeSize(voxelVolumeSize); @@ -123,7 +124,9 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) // having the "outside of voxel-space" value be 255 has helped me notice some problems. _volData->setBorderValue(255); + #ifdef WANT_DEBUG qDebug() << " new size is" << _volData->getWidth() << _volData->getHeight() << _volData->getDepth(); + #endif // I'm not sure this is needed... the docs say that each element is initialized with its default // constructor. I'll leave it here for now. @@ -348,44 +351,31 @@ void RenderablePolyVoxEntityItem::getModel() { sizeof(PolyVox::PositionMaterialNormal), gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); + + // auto normalAttrib = mesh->getAttributeBuffer(gpu::Stream::NORMAL); // for (auto normal = normalAttrib.begin(); normal != normalAttrib.end(); normal++) { // (*normal) = -(*normal); // } + + // mesh->addAttribute(gpu::Stream::TEXCOORD, + // gpu::BufferView(vertexBufferPtr, + // sizeof(float) * 2, + // vertexBufferPtr->getSize() - sizeof(float) * 2, + // sizeof(PolyVox::PositionMaterialNormal), + // gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::RAW))); + + + + #ifdef WANT_DEBUG qDebug() << "---- vecIndices.size() =" << vecIndices.size(); qDebug() << "---- vecVertices.size() =" << vecVertices.size(); + #endif _needsModelReload = false; } - -// QString GLMatrixToString(GLfloat* m) { -// QString mString = "\n"; -// for (int x = 0; x < 4; x++) { -// for (int y = 0; y < 4; y++) { -// mString += QString::number((double)m[y*4+x], 'f', 2) + " "; -// } -// mString += "\n"; -// } -// return mString; -// } - - -// void printModelViewMatrix() { -// GLfloat glMatrix[16]; -// glGetFloatv(GL_MODELVIEW_MATRIX, glMatrix); -// qDebug() << GLMatrixToString(glMatrix); -// } - -// void printProjectionMatrix() { -// GLfloat glMatrix[16]; -// glGetFloatv(GL_PROJECTION_MATRIX, glMatrix); -// qDebug() << GLMatrixToString(glMatrix); -// } - - - void RenderablePolyVoxEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RenderablePolyVoxEntityItem::render"); assert(getType() == EntityTypes::PolyVox); @@ -535,11 +525,15 @@ void RenderablePolyVoxEntityItem::compressVolumeData() { // make sure the compressed data can be sent over the wire-protocol if (newVoxelData.size() < 1150) { _voxelData = newVoxelData; + #ifdef WANT_DEBUG qDebug() << "-------------- voxel compresss --------------"; qDebug() << "raw-size =" << rawSize << " compressed-size =" << newVoxelData.size(); + #endif } else { // HACK -- until we have a way to allow for properties larger than MTU, don't update. + #ifdef WANT_DEBUG qDebug() << "voxel data too large, reverting change."; + #endif // revert the active voxel-space to the last version that fit. decompressVolumeData(); } @@ -560,7 +554,7 @@ void RenderablePolyVoxEntityItem::decompressVolumeData() { if (voxelXSize == 0 || voxelXSize > MAX_VOXEL_DIMENSION || voxelYSize == 0 || voxelYSize > MAX_VOXEL_DIMENSION || voxelZSize == 0 || voxelZSize > MAX_VOXEL_DIMENSION) { - qDebug() << "vixelSize is not reasonable, skipping decompressions." + qDebug() << "voxelSize is not reasonable, skipping decompressions." << voxelXSize << voxelYSize << voxelZSize; return; } @@ -587,8 +581,10 @@ void RenderablePolyVoxEntityItem::decompressVolumeData() { } } + #ifdef WANT_DEBUG qDebug() << "--------------- voxel decompress ---------------"; qDebug() << "raw-size =" << rawSize << " compressed-size =" << _voxelData.size(); + #endif _dirtyFlags |= EntityItem::DIRTY_SHAPE | EntityItem::DIRTY_MASS; _needsModelReload = true; @@ -609,12 +605,16 @@ bool RenderablePolyVoxEntityItem::isReadyToComputeShape() { return false; } + #ifdef WANT_DEBUG qDebug() << "RenderablePolyVoxEntityItem::isReadyToComputeShape" << (!_needsModelReload); + #endif return true; } void RenderablePolyVoxEntityItem::computeShapeInfo(ShapeInfo& info) { + #ifdef WANT_DEBUG qDebug() << "RenderablePolyVoxEntityItem::computeShapeInfo"; + #endif ShapeType type = getShapeType(); if (type != SHAPE_TYPE_COMPOUND) { EntityItem::computeShapeInfo(info); From 94131908fb856b2f60fc0b217c2a0d1404824e2e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 1 Jun 2015 14:53:11 -0700 Subject: [PATCH 59/72] update polyvox for xcode C++11 build --- cmake/externals/polyvox/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 76302f9b4a..28aec6dab7 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -3,8 +3,8 @@ set(EXTERNAL_NAME polyvox) include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} - URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip - URL_MD5 e3dd09a24df4db29ba370e3bea753388 + URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox.zip + URL_MD5 904b840328278c9b36fa7a14be730c34 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 @@ -45,7 +45,7 @@ else () endif () -if (WIN32) +if (WIN32) set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/PolyVoxCore/lib/PolyVoxCore.lib CACHE FILEPATH "polyvox core library") # set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/PolyVoxUtil/lib/PolyVoxUtil.lib CACHE FILEPATH "polyvox util library") elseif (APPLE) From 83bf4241e4ea7d5b6d980221053563a472e5fd3c Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Mon, 1 Jun 2015 15:16:08 -0700 Subject: [PATCH 60/72] resolved merge conflicts... but now lines not flying across clients --- cmake/externals/polyvox/CMakeLists.txt | 4 ++-- libraries/entities/src/EntityPropertyFlags.h | 11 ++++------- libraries/octree/src/OctreePacketData.h | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 76302f9b4a..1417759f4b 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -3,8 +3,8 @@ set(EXTERNAL_NAME polyvox) include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} - URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip - URL_MD5 e3dd09a24df4db29ba370e3bea753388 + URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox.zip + URL_MD5 URL_MD5 904b840328278c9b36fa7a14be730c34 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 9b93dcd373..8eb09fece0 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -109,18 +109,15 @@ enum EntityPropertyList { PROP_COLLISION_SOUND_URL, PROP_RESTITUTION, PROP_FRICTION, -<<<<<<< HEAD - - //for lines - PROP_LINE_WIDTH, - PROP_LINE_POINTS, -======= PROP_VOXEL_VOLUME_SIZE, PROP_VOXEL_DATA, PROP_VOXEL_SURFACE_STYLE, ->>>>>>> master + //for lines + PROP_LINE_WIDTH, + PROP_LINE_POINTS, + //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties ABOVE this line PROP_AFTER_LAST_ITEM, diff --git a/libraries/octree/src/OctreePacketData.h b/libraries/octree/src/OctreePacketData.h index ed9c0a4703..9476fe024e 100644 --- a/libraries/octree/src/OctreePacketData.h +++ b/libraries/octree/src/OctreePacketData.h @@ -244,7 +244,7 @@ public: static int unpackDataFromBytes(const unsigned char* dataBytes, QString& result); static int unpackDataFromBytes(const unsigned char* dataBytes, QUuid& result); static int unpackDataFromBytes(const unsigned char* dataBytes, xColor& result); - static int uppackDataFromBytes(const unsigned char* dataBytes, QVector& result); + static int unpackDataFromBytes(const unsigned char* dataBytes, QVector& result); static int unpackDataFromBytes(const unsigned char* dataBytes, QByteArray& result); From 785144404c252c3e4ae568eefbba6ce5c9a1df97 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Mon, 1 Jun 2015 15:37:29 -0700 Subject: [PATCH 61/72] changed entity packet type version number --- libraries/octree/src/OctreePacketData.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index 42b3eec2b2..9d0d98686a 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -608,7 +608,6 @@ int OctreePacketData::unpackDataFromBytes(const unsigned char *dataBytes, QVecto uint16_t length; memcpy(&length, dataBytes, sizeof(uint16_t)); dataBytes += sizeof(length); - qDebug()<<"unpacking length"< Date: Mon, 1 Jun 2015 21:19:42 -0700 Subject: [PATCH 62/72] Pitch-shift collision sounds, and make entities-renderer depend on soxr. --- libraries/entities-renderer/CMakeLists.txt | 6 +++++ .../src/EntityTreeRenderer.cpp | 26 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt index a94bfb5f97..394d156252 100644 --- a/libraries/entities-renderer/CMakeLists.txt +++ b/libraries/entities-renderer/CMakeLists.txt @@ -17,4 +17,10 @@ find_package(PolyVox REQUIRED) target_include_directories(${TARGET_NAME} SYSTEM PUBLIC ${POLYVOX_INCLUDE_DIRS}) target_link_libraries(${TARGET_NAME} ${POLYVOX_LIBRARIES}) +# for changing the pitch of collision sounds +add_dependency_external_projects(soxr) +find_package(Soxr REQUIRED) +target_link_libraries(${TARGET_NAME} ${SOXR_LIBRARIES}) +target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${SOXR_INCLUDE_DIRS}) + link_hifi_libraries(shared gpu script-engine render-utils) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 8f034409ae..e3680d4614 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "EntityTreeRenderer.h" @@ -1158,7 +1159,30 @@ void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityT options.stereo = sound->isStereo(); options.position = position; options.volume = volume; - AudioInjector* injector = new AudioInjector(sound.data(), options); + + // Shift the pitch down by ln(1 + (size / COLLISION_SIZE_FOR_STANDARD_PITCH)) / ln(2) + const float COLLISION_SIZE_FOR_STANDARD_PITCH = 0.2f; + QByteArray samples = sound->getByteArray(); + soxr_io_spec_t spec = soxr_io_spec(SOXR_INT16_I, SOXR_INT16_I); + soxr_quality_spec_t qualitySpec = soxr_quality_spec(SOXR_MQ, 0); + const int channelCount = sound->isStereo() ? 2 : 1; + const float factor = log(1.0f + (entity->getMaximumAACube().getLargestDimension() / COLLISION_SIZE_FOR_STANDARD_PITCH)) / log(2); + const int HIFI_SAMPLE_RATE = 24000; //AudioConstants::SAMPLE_RATE + const int resampledRate = HIFI_SAMPLE_RATE * factor; + const int nInputSamples = samples.size() / sizeof(int16_t); + const int nOutputSamples = nInputSamples * factor; + QByteArray resampled(nOutputSamples * sizeof(int16_t), '\0'); + const int16_t* receivedSamples = reinterpret_cast(samples.data()); + soxr_error_t soxError = soxr_oneshot(HIFI_SAMPLE_RATE, resampledRate, channelCount, + receivedSamples, nInputSamples, NULL, + reinterpret_cast(resampled.data()), nOutputSamples, NULL, + &spec, &qualitySpec, 0); + if (soxError) { + qCDebug(entitiesrenderer) << "Unable to resample" << collisionSoundURL << "from" << nInputSamples << "@" << HIFI_SAMPLE_RATE << "to" << nOutputSamples << "@" << resampledRate; + resampled = samples; + } + + AudioInjector* injector = new AudioInjector(resampled, options); injector->setLocalAudioInterface(_localAudioInterface); injector->triggerDeleteAfterFinish(); QThread* injectorThread = new QThread(); From fb379f6c00984e3fe06416dd3e40b224544c18ce Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 2 Jun 2015 08:37:45 -0700 Subject: [PATCH 63/72] Fix crash when setting avatar body with Preferences dialog closed --- interface/src/ui/AvatarAppearanceDialog.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/interface/src/ui/AvatarAppearanceDialog.cpp b/interface/src/ui/AvatarAppearanceDialog.cpp index ceaaf140c4..3ab99c141d 100644 --- a/interface/src/ui/AvatarAppearanceDialog.cpp +++ b/interface/src/ui/AvatarAppearanceDialog.cpp @@ -82,7 +82,10 @@ void AvatarAppearanceDialog::setUseFullAvatar(bool useFullAvatar) { ui.useFullAvatar->setChecked(_useFullAvatar); ui.useSeparateBodyAndHead->setChecked(!_useFullAvatar); - DependencyManager::get()->getPreferencesDialog()->avatarDescriptionChanged(); + QPointer prefs = DependencyManager::get()->getPreferencesDialog(); + if (prefs) { // Preferences dialog may have been closed + prefs->avatarDescriptionChanged(); + } } void AvatarAppearanceDialog::headURLChanged(const QString& newValue, const QString& modelName) { @@ -106,7 +109,10 @@ void AvatarAppearanceDialog::fullAvatarURLChanged(const QString& newValue, const void AvatarAppearanceDialog::accept() { saveAvatarAppearance(); - DependencyManager::get()->getPreferencesDialog()->avatarDescriptionChanged(); + QPointer prefs = DependencyManager::get()->getPreferencesDialog(); + if (prefs) { // Preferences dialog may have been closed + prefs->avatarDescriptionChanged(); + } close(); delete _marketplaceWindow; From 0837c016c52237ca6dcffdac98b8ca4d514bf4af Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Tue, 2 Jun 2015 09:18:45 -0700 Subject: [PATCH 64/72] Update constant to use AudioConstants.h --- libraries/entities-renderer/src/EntityTreeRenderer.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index e3680d4614..23e504bfb8 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "EntityTreeRenderer.h" @@ -1167,18 +1168,18 @@ void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityT soxr_quality_spec_t qualitySpec = soxr_quality_spec(SOXR_MQ, 0); const int channelCount = sound->isStereo() ? 2 : 1; const float factor = log(1.0f + (entity->getMaximumAACube().getLargestDimension() / COLLISION_SIZE_FOR_STANDARD_PITCH)) / log(2); - const int HIFI_SAMPLE_RATE = 24000; //AudioConstants::SAMPLE_RATE - const int resampledRate = HIFI_SAMPLE_RATE * factor; + const int standardRate = AudioConstants::SAMPLE_RATE; + const int resampledRate = standardRate * factor; const int nInputSamples = samples.size() / sizeof(int16_t); const int nOutputSamples = nInputSamples * factor; QByteArray resampled(nOutputSamples * sizeof(int16_t), '\0'); const int16_t* receivedSamples = reinterpret_cast(samples.data()); - soxr_error_t soxError = soxr_oneshot(HIFI_SAMPLE_RATE, resampledRate, channelCount, + soxr_error_t soxError = soxr_oneshot(standardRate, resampledRate, channelCount, receivedSamples, nInputSamples, NULL, reinterpret_cast(resampled.data()), nOutputSamples, NULL, &spec, &qualitySpec, 0); if (soxError) { - qCDebug(entitiesrenderer) << "Unable to resample" << collisionSoundURL << "from" << nInputSamples << "@" << HIFI_SAMPLE_RATE << "to" << nOutputSamples << "@" << resampledRate; + qCDebug(entitiesrenderer) << "Unable to resample" << collisionSoundURL << "from" << nInputSamples << "@" << standardRate << "to" << nOutputSamples << "@" << resampledRate; resampled = samples; } From e7c5a24e3d37f5e4bc8f54aefa60395b14cc71b7 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 2 Jun 2015 09:38:45 -0700 Subject: [PATCH 65/72] fixed packet number increment logic --- libraries/networking/src/PacketHeaders.cpp | 4 +--- libraries/networking/src/PacketHeaders.h | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/libraries/networking/src/PacketHeaders.cpp b/libraries/networking/src/PacketHeaders.cpp index c52f44b6b9..78bb3f11e1 100644 --- a/libraries/networking/src/PacketHeaders.cpp +++ b/libraries/networking/src/PacketHeaders.cpp @@ -73,7 +73,7 @@ PacketVersion versionForPacketType(PacketType packetType) { case PacketTypeEntityAdd: case PacketTypeEntityEdit: case PacketTypeEntityData: - return VERSION_NO_ENTITY_ID_SWAP; + return VERSION_ENTITIES_LINE_POINTS; case PacketTypeEntityErase: return 2; case PacketTypeAudioStreamStats: @@ -135,8 +135,6 @@ QString nameForPacketType(PacketType packetType) { PACKET_TYPE_NAME_LOOKUP(PacketTypeUnverifiedPingReply); PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityAdd); PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityEdit); - PACKET_TYPE_NAME_LOOKUP(PacketTypeParticleEntitiesFix); - PACKET_TYPE_NAME_LOOKUP(PacketTypeLinePoints); default: return QString("Type: ") + QString::number((int)packetType); } diff --git a/libraries/networking/src/PacketHeaders.h b/libraries/networking/src/PacketHeaders.h index aad7f508a1..228df1cdde 100644 --- a/libraries/networking/src/PacketHeaders.h +++ b/libraries/networking/src/PacketHeaders.h @@ -79,9 +79,7 @@ enum PacketType { PacketTypeSignedTransactionPayment, PacketTypeIceServerHeartbeat, // 50 PacketTypeUnverifiedPing, - PacketTypeUnverifiedPingReply, - PacketTypeParticleEntitiesFix, - PacketTypeLinePoints + PacketTypeUnverifiedPingReply }; typedef char PacketVersion; @@ -184,5 +182,6 @@ const PacketVersion VERSION_ENTITIES_HAVE_COLLISION_SOUND_URL = 25; const PacketVersion VERSION_ENTITIES_HAVE_FRICTION = 26; const PacketVersion VERSION_NO_ENTITY_ID_SWAP = 27; const PacketVersion VERSION_ENTITIES_PARTICLE_FIX = 28; +const PacketVersion VERSION_ENTITIES_LINE_POINTS = 29; #endif // hifi_PacketHeaders_h From 20d3814c1b1e3fda623dbe9dc13011f3c7d41b7e Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 2 Jun 2015 10:00:07 -0700 Subject: [PATCH 66/72] code review --- examples/edit.js | 17 +++--- examples/html/entityProperties.html | 58 +++++++++---------- examples/voxels.js | 5 +- .../src/RenderablePolyVoxEntityItem.cpp | 10 +--- .../entities/src/EntityItemProperties.cpp | 24 ++++---- libraries/entities/src/EntityItemProperties.h | 2 +- libraries/shared/src/SettingInterface.cpp | 12 ++-- 7 files changed, 60 insertions(+), 68 deletions(-) diff --git a/examples/edit.js b/examples/edit.js index 455b843868..8a8dcb9779 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -1,4 +1,3 @@ - // newEditEntities.js // examples // @@ -139,7 +138,7 @@ var toolBar = (function () { newTextButton, newWebButton, newZoneButton, - newPolyVoxButton, + newPolyVoxButton, browseMarketplaceButton; function initialize() { @@ -225,7 +224,7 @@ var toolBar = (function () { visible: false }); - newPolyVoxButton = toolBar.addTool({ + newPolyVoxButton = toolBar.addTool({ imageURL: toolIconUrl + "upload.svg", // XXX need a new icon subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, width: toolWidth, @@ -276,7 +275,7 @@ var toolBar = (function () { toolBar.showTool(newTextButton, doShow); toolBar.showTool(newWebButton, doShow); toolBar.showTool(newZoneButton, doShow); - toolBar.showTool(newPolyVoxButton, doShow); + toolBar.showTool(newPolyVoxButton, doShow); }; var RESIZE_INTERVAL = 50; @@ -486,10 +485,10 @@ var toolBar = (function () { placingEntityID = Entities.addEntity({ type: "PolyVox", position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), - DEFAULT_DIMENSIONS), + DEFAULT_DIMENSIONS), dimensions: { x: 10, y: 10, z: 10 }, - voxelVolumeSize: {x:16, y:16, z:16}, - voxelSurfaceStyle: 1 + voxelVolumeSize: {x:16, y:16, z:16}, + voxelSurfaceStyle: 1 }); } else { print("Can't create PolyVox: would be out of bounds."); @@ -949,7 +948,7 @@ function selectAllEtitiesInCurrentSelectionBox(keepIfTouching) { var boundingBoxCorner = Vec3.subtract(selectionManager.worldPosition, Vec3.multiply(selectionManager.worldDimensions, 0.5)); var entities = Entities.findEntitiesInBox(boundingBoxCorner, selectionManager.worldDimensions); - + if (!keepIfTouching) { var isValid; if (selectionManager.localPosition === null) { @@ -1021,7 +1020,7 @@ function handeMenuEvent(menuItem) { } } } else if (menuItem == "Import Entities" || menuItem == "Import Entities from URL") { - + var importURL; if (menuItem == "Import Entities") { importURL = Window.browse("Select models to import", "", "*.json"); diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 21e2e83136..d9cad0feff 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -21,11 +21,11 @@ els[i].setAttribute('disabled', 'disabled'); } } - + function showElements(els, show) { for (var i = 0; i < els.length; i++) { els[i].style.display = (show) ? 'block' : 'none'; - } + } } function createEmitCheckedPropertyUpdateFunction(propertyName) { @@ -344,7 +344,7 @@ var elZoneAtmosphereCenterY = document.getElementById("property-zone-atmosphere-center-y"); var elZoneAtmosphereCenterZ = document.getElementById("property-zone-atmosphere-center-z"); var elCenterAtmosphereToZone = document.getElementById("center-atmosphere-in-zone"); - + var elZoneAtmosphereInnerRadius = document.getElementById("property-zone-atmosphere-inner-radius"); var elZoneAtmosphereOuterRadius = document.getElementById("property-zone-atmosphere-outer-radius"); var elZoneAtmosphereMieScattering = document.getElementById("property-zone-atmosphere-mie-scattering"); @@ -354,12 +354,12 @@ var elZoneAtmosphereScatteringWavelengthsZ = document.getElementById("property-zone-atmosphere-scattering-wavelengths-z"); var elZoneAtmosphereHasStars = document.getElementById("property-zone-atmosphere-has-stars"); - var elPolyVoxSelections = document.querySelectorAll(".poly-vox-section"); - var elVoxelVolumeSizeX = document.getElementById("property-voxel-volume-size-x"); + var elPolyVoxSelections = document.querySelectorAll(".poly-vox-section"); + var elVoxelVolumeSizeX = document.getElementById("property-voxel-volume-size-x"); var elVoxelVolumeSizeY = document.getElementById("property-voxel-volume-size-y"); var elVoxelVolumeSizeZ = document.getElementById("property-voxel-volume-size-z"); - var elVoxelSurfaceStyle = document.getElementById("property-voxel-surface-style"); - + var elVoxelSurfaceStyle = document.getElementById("property-voxel-surface-style"); + if (window.EventBridge !== undefined) { EventBridge.scriptEventReceived.connect(function(data) { @@ -577,7 +577,7 @@ elZoneAtmosphereScatteringWavelengthsY.value = properties.atmosphere.scatteringWavelengths.y; elZoneAtmosphereScatteringWavelengthsZ.value = properties.atmosphere.scatteringWavelengths.z; elZoneAtmosphereHasStars.checked = properties.atmosphere.hasStars; - + showElements(document.getElementsByClassName('skybox-section'), elZoneBackgroundMode.value == 'skybox'); showElements(document.getElementsByClassName('atmosphere-section'), elZoneBackgroundMode.value == 'atmosphere'); } else if (properties.type == "ParticleEffect") { @@ -595,11 +595,11 @@ elParticleLocalGravity.value = properties.localGravity.toFixed(2); elParticleRadius.value = properties.particleRadius.toFixed(3); } else if (properties.type == "PolyVox") { - elVoxelVolumeSizeX.value = properties.voxelVolumeSize.x.toFixed(2); - elVoxelVolumeSizeY.value = properties.voxelVolumeSize.y.toFixed(2); - elVoxelVolumeSizeZ.value = properties.voxelVolumeSize.z.toFixed(2); - elVoxelSurfaceStyle.value = properties.voxelSurfaceStyle; - } + elVoxelVolumeSizeX.value = properties.voxelVolumeSize.x.toFixed(2); + elVoxelVolumeSizeY.value = properties.voxelVolumeSize.y.toFixed(2); + elVoxelVolumeSizeZ.value = properties.voxelVolumeSize.z.toFixed(2); + elVoxelSurfaceStyle.value = properties.voxelSurfaceStyle; + } if (selected) { activeElement.focus(); @@ -715,7 +715,7 @@ elLightCutoff.addEventListener('change', createEmitNumberPropertyUpdateFunction('cutoff')); elWebSourceURL.addEventListener('change', createEmitTextPropertyUpdateFunction('sourceUrl')); - + elParticleMaxParticles.addEventListener('change', createEmitNumberPropertyUpdateFunction('maxParticles')); elParticleLifeSpan.addEventListener('change', createEmitNumberPropertyUpdateFunction('lifespan')); elParticleEmitRate.addEventListener('change', createEmitNumberPropertyUpdateFunction('emitRate')); @@ -821,7 +821,7 @@ emitColorPropertyUpdate('color', rgb.r, rgb.g, rgb.b, 'skybox'); } }); - + elZoneSkyboxURL.addEventListener('change', createEmitGroupTextPropertyUpdateFunction('skybox','url')); var zoneAtmosphereCenterChangeFunction = createEmitGroupVec3PropertyUpdateFunction( @@ -829,8 +829,8 @@ elZoneAtmosphereCenterX.addEventListener('change', zoneAtmosphereCenterChangeFunction); elZoneAtmosphereCenterY.addEventListener('change', zoneAtmosphereCenterChangeFunction); elZoneAtmosphereCenterZ.addEventListener('change', zoneAtmosphereCenterChangeFunction); - - + + elZoneAtmosphereInnerRadius.addEventListener('change', createEmitGroupNumberPropertyUpdateFunction('atmosphere','innerRadius')); elZoneAtmosphereOuterRadius.addEventListener('change', createEmitGroupNumberPropertyUpdateFunction('atmosphere','outerRadius')); elZoneAtmosphereMieScattering.addEventListener('change', createEmitGroupNumberPropertyUpdateFunction('atmosphere','mieScattering')); @@ -848,8 +848,8 @@ elVoxelVolumeSizeX.addEventListener('change', voxelVolumeSizeChangeFunction); elVoxelVolumeSizeY.addEventListener('change', voxelVolumeSizeChangeFunction); elVoxelVolumeSizeZ.addEventListener('change', voxelVolumeSizeChangeFunction); - elVoxelSurfaceStyle.addEventListener('change', createEmitTextPropertyUpdateFunction('voxelSurfaceStyle')); - + elVoxelSurfaceStyle.addEventListener('change', createEmitTextPropertyUpdateFunction('voxelSurfaceStyle')); + elMoveSelectionToGrid.addEventListener("click", function() { EventBridge.emitWebEvent(JSON.stringify({ @@ -997,14 +997,14 @@
X
Y
Z
- +
Surface Extractor
-
+
@@ -1143,19 +1143,19 @@ - +
Max Particles
-
+
Particle Life Span
-
+
Particle Emission Rate
@@ -1188,7 +1188,7 @@
- +
Model URL
@@ -1203,7 +1203,7 @@ - +
@@ -1382,7 +1382,7 @@
- +
Stage Day
diff --git a/examples/voxels.js b/examples/voxels.js index fc9f6550f5..799af04bef 100644 --- a/examples/voxels.js +++ b/examples/voxels.js @@ -1,4 +1,3 @@ - var controlHeld = false; var shiftHeld = false; @@ -17,8 +16,8 @@ function mousePressEvent(event) { var id = ids[i]; if (controlHeld) { Entities.setVoxelSphere(id, intersection.intersection, 1.0, 0); - } else if (shiftHeld) { - Entities.setAllVoxels(id, 255); + } else if (shiftHeld) { + Entities.setAllVoxels(id, 255); } else { Entities.setVoxelSphere(id, intersection.intersection, 1.0, 255); } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 6f2fe42502..83612f3fce 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -78,11 +78,7 @@ bool inUserBounds(const PolyVox::SimpleVolume* vol, PolyVoxEntityItem:: bool inBounds(const PolyVox::SimpleVolume* vol, int x, int y, int z) { // x, y, z are in polyvox volume coords - if (x < 0 || y < 0 || z < 0 || - x >= vol->getWidth() || y >= vol->getHeight() || z >= vol->getDepth()) { - return false; - } - return true; + return !(x < 0 || y < 0 || z < 0 || x >= vol->getWidth() || y >= vol->getHeight() || z >= vol->getDepth()); } @@ -183,7 +179,7 @@ glm::vec3 RenderablePolyVoxEntityItem::getSurfacePositionAdjustment() const { case PolyVoxEntityItem::SURFACE_CUBIC: return scale / 2.0f; } - return glm::vec3(0, 0, 0); + return glm::vec3(0.0f, 0.0f, 0.0f); } glm::mat4 RenderablePolyVoxEntityItem::voxelToLocalMatrix() const { @@ -191,7 +187,7 @@ glm::mat4 RenderablePolyVoxEntityItem::voxelToLocalMatrix() const { glm::vec3 center = getCenter(); glm::vec3 position = getPosition(); glm::vec3 positionToCenter = center - position; - positionToCenter -= _dimensions * glm::vec3(0.5f,0.5f,0.5f) - getSurfacePositionAdjustment(); + positionToCenter -= _dimensions * glm::vec3(0.5f, 0.5f, 0.5f) - getSurfacePositionAdjustment(); glm::mat4 centerToCorner = glm::translate(glm::mat4(), positionToCenter); glm::mat4 scaled = glm::scale(centerToCorner, scale); return scaled; diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index eeb3bb3474..698530ef86 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -176,10 +176,8 @@ QString EntityItemProperties::getAnimationSettings() const { return jsonByteString; } - -void EntityItemProperties::setCreated(QDateTime v) { - QDateTime utcV = v; - _created = utcV.toMSecsSinceEpoch() * 1000; // usec per msec +void EntityItemProperties::setCreated(QDateTime &v) { + _created = v.toMSecsSinceEpoch() * 1000; // usec per msec qDebug() << "EntityItemProperties::setCreated QDateTime" << v << _created; } @@ -494,12 +492,6 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE(restitution, float, setRestitution); COPY_PROPERTY_FROM_QSCRIPTVALUE(friction, float, setFriction); COPY_PROPERTY_FROM_QSCRIPTVALUE(lifetime, float, setLifetime); - if (!honorReadOnly) { - COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(created, QDateTime, setCreated, [this]() { - auto result = QDateTime::fromMSecsSinceEpoch(_created / 1000, Qt::UTC); // usec per msec - return result; - }); - } COPY_PROPERTY_FROM_QSCRIPTVALUE(script, QString, setScript); COPY_PROPERTY_FROM_QSCRIPTVALUE(registrationPoint, glmVec3, setRegistrationPoint); COPY_PROPERTY_FROM_QSCRIPTVALUE(angularVelocity, glmVec3, setAngularVelocity); @@ -524,9 +516,6 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE(locked, bool, setLocked); COPY_PROPERTY_FROM_QSCRIPTVALUE(textures, QString, setTextures); COPY_PROPERTY_FROM_QSCRIPTVALUE(userData, QString, setUserData); - if (!honorReadOnly) { - COPY_PROPERTY_FROM_QSCRIPTVALUE(simulatorID, QUuid, setSimulatorID); - } COPY_PROPERTY_FROM_QSCRIPTVALUE(text, QString, setText); COPY_PROPERTY_FROM_QSCRIPTVALUE(lineHeight, float, setLineHeight); COPY_PROPERTY_FROM_QSCRIPTVALUE(textColor, xColor, setTextColor); @@ -554,6 +543,15 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE(voxelData, QByteArray, setVoxelData); COPY_PROPERTY_FROM_QSCRIPTVALUE(voxelSurfaceStyle, uint16_t, setVoxelSurfaceStyle); + if (!honorReadOnly) { + // this is used by the json reader to set things that we don't want javascript to able to affect. + COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(created, QDateTime, setCreated, [this]() { + auto result = QDateTime::fromMSecsSinceEpoch(_created / 1000, Qt::UTC); // usec per msec + return result; + }); + COPY_PROPERTY_FROM_QSCRIPTVALUE(simulatorID, QUuid, setSimulatorID); + } + _stage.copyFromScriptValue(object, _defaultSettings); _atmosphere.copyFromScriptValue(object, _defaultSettings); _skybox.copyFromScriptValue(object, _defaultSettings); diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index c6a0b21313..07879b5a6c 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -194,7 +194,7 @@ public: void setVoxelDataDirty() { _voxelDataChanged = true; } - void setCreated(QDateTime v); + void setCreated(QDateTime& v); bool hasTerseUpdateChanges() const; diff --git a/libraries/shared/src/SettingInterface.cpp b/libraries/shared/src/SettingInterface.cpp index 26cbe3ca13..ee72a4ab45 100644 --- a/libraries/shared/src/SettingInterface.cpp +++ b/libraries/shared/src/SettingInterface.cpp @@ -39,12 +39,12 @@ namespace Setting { void init() { // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings::setDefaultFormat(QSettings::IniFormat); - QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); - // set the associated application properties - applicationInfo.beginGroup("INFO"); - QCoreApplication::setApplicationName(applicationInfo.value("name").toString()); - QCoreApplication::setOrganizationName(applicationInfo.value("organizationName").toString()); - QCoreApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); + // QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); + // // set the associated application properties + // applicationInfo.beginGroup("INFO"); + // QCoreApplication::setApplicationName(applicationInfo.value("name").toString()); + // QCoreApplication::setOrganizationName(applicationInfo.value("organizationName").toString()); + // QCoreApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); // Let's set up the settings Private instance on it's own thread QThread* thread = new QThread(); From d201f7791e29f032a28d40a24d875355bba309da Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 2 Jun 2015 10:01:43 -0700 Subject: [PATCH 67/72] oops --- libraries/shared/src/SettingInterface.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/shared/src/SettingInterface.cpp b/libraries/shared/src/SettingInterface.cpp index ee72a4ab45..26cbe3ca13 100644 --- a/libraries/shared/src/SettingInterface.cpp +++ b/libraries/shared/src/SettingInterface.cpp @@ -39,12 +39,12 @@ namespace Setting { void init() { // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings::setDefaultFormat(QSettings::IniFormat); - // QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); - // // set the associated application properties - // applicationInfo.beginGroup("INFO"); - // QCoreApplication::setApplicationName(applicationInfo.value("name").toString()); - // QCoreApplication::setOrganizationName(applicationInfo.value("organizationName").toString()); - // QCoreApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); + QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); + // set the associated application properties + applicationInfo.beginGroup("INFO"); + QCoreApplication::setApplicationName(applicationInfo.value("name").toString()); + QCoreApplication::setOrganizationName(applicationInfo.value("organizationName").toString()); + QCoreApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); // Let's set up the settings Private instance on it's own thread QThread* thread = new QThread(); From 11eb073bcfd3aebf404a454ad50596d882572aa4 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 2 Jun 2015 10:04:39 -0700 Subject: [PATCH 68/72] fix comment --- libraries/shared/src/SettingInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/SettingInterface.cpp b/libraries/shared/src/SettingInterface.cpp index 26cbe3ca13..c14fd33565 100644 --- a/libraries/shared/src/SettingInterface.cpp +++ b/libraries/shared/src/SettingInterface.cpp @@ -46,7 +46,7 @@ namespace Setting { QCoreApplication::setOrganizationName(applicationInfo.value("organizationName").toString()); QCoreApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); - // Let's set up the settings Private instance on it's own thread + // Let's set up the settings Private instance on its own thread QThread* thread = new QThread(); Q_CHECK_PTR(thread); thread->setObjectName("Settings Thread"); From c90114e1ef5a2e702e7e2040797539b58c70a102 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 2 Jun 2015 10:49:45 -0700 Subject: [PATCH 69/72] Update BUILD_OSX.md --- BUILD_OSX.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/BUILD_OSX.md b/BUILD_OSX.md index 2598507c90..60fbb7cf92 100644 --- a/BUILD_OSX.md +++ b/BUILD_OSX.md @@ -12,6 +12,12 @@ We have a [homebrew formulas repository](https://github.com/highfidelity/homebre *Our [qt5 homebrew formula](https://raw.github.com/highfidelity/homebrew-formulas/master/qt5.rb) is for a patched version of Qt 5.4.x stable that removes wireless network scanning that can reduce real-time audio performance. We recommended you use this formula to install Qt.* +###Qt + +Assuming you've installed Qt 5 using the homebrew instructions above, you'll need to set QT_CMAKE_PREFIX_PATH so CMake can find your installation of Qt. For Qt 5.4.1 installed via homebrew, set QT_CMAKE_PREFIX_PATH as follows. + + export QT_CMAKE_PREFIX_PATH=/usr/local/Cellar/qt5/5.4.1/lib/cmake + ###Xcode If Xcode is your editor of choice, you can ask CMake to generate Xcode project files instead of Unix Makefiles. @@ -19,4 +25,4 @@ If Xcode is your editor of choice, you can ask CMake to generate Xcode project f After running cmake, you will have the make files or Xcode project file necessary to build all of the components. Open the hifi.xcodeproj file, choose ALL_BUILD from the Product > Scheme menu (or target drop down), and click Run. -If the build completes successfully, you will have built targets for all components located in the `build/${target_name}/Debug` directories. \ No newline at end of file +If the build completes successfully, you will have built targets for all components located in the `build/${target_name}/Debug` directories. From 55ffb7f1c0e33745059f29998387f3dacd686e92 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 2 Jun 2015 12:51:45 -0700 Subject: [PATCH 70/72] code style changes --- .../entities-renderer/src/RenderableLineEntityItem.cpp | 2 +- libraries/entities/src/EntityItemProperties.cpp | 6 +++--- libraries/entities/src/EntityItemPropertiesMacros.h | 2 +- libraries/entities/src/LineEntityItem.cpp | 4 ++-- libraries/octree/src/OctreePacketData.cpp | 9 ++------- libraries/shared/src/RegisteredMetaTypes.cpp | 6 +++--- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 480fbe5bb9..16d54feda0 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -41,7 +41,7 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); QVector points; - if(_pointsChanged) { + if (_pointsChanged) { geometryCache->updateVertices(_lineVerticesID, getLinePoints(), lineColor); _pointsChanged = false; } diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 40970fc3f1..407791a65d 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -96,7 +96,7 @@ CONSTRUCT_PROPERTY(name, ENTITY_ITEM_DEFAULT_NAME), CONSTRUCT_PROPERTY(backgroundMode, BACKGROUND_MODE_INHERIT), CONSTRUCT_PROPERTY(sourceUrl, ""), CONSTRUCT_PROPERTY(lineWidth, LineEntityItem::DEFAULT_LINE_WIDTH), -CONSTRUCT_PROPERTY(linePoints, 0), +CONSTRUCT_PROPERTY(linePoints, QVector()), _id(UNKNOWN_ENTITY_ID), @@ -769,7 +769,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem APPEND_ENTITY_PROPERTY(PROP_VOXEL_SURFACE_STYLE, properties.getVoxelSurfaceStyle()); } - if(properties.getType() == EntityTypes::Line){ + if (properties.getType() == EntityTypes::Line) { APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, properties.getLineWidth()); APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, properties.getLinePoints()); } @@ -1014,7 +1014,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VOXEL_SURFACE_STYLE, uint16_t, setVoxelSurfaceStyle); } - if(properties.getType() == EntityTypes::Line) { + if (properties.getType() == EntityTypes::Line) { READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_WIDTH, float, setLineWidth); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_POINTS, QVector, setLinePoints); } diff --git a/libraries/entities/src/EntityItemPropertiesMacros.h b/libraries/entities/src/EntityItemPropertiesMacros.h index 753a53479b..268107990b 100644 --- a/libraries/entities/src/EntityItemPropertiesMacros.h +++ b/libraries/entities/src/EntityItemPropertiesMacros.h @@ -169,7 +169,7 @@ inline glmVec3 glmVec3_convertFromScriptValue(const QScriptValue& v, bool& isVal return glm::vec3(0); } -inline qVectorVec3 qVectorVec3_convertFromScriptValue(const QScriptValue& v, bool& isValid){ +inline qVectorVec3 qVectorVec3_convertFromScriptValue(const QScriptValue& v, bool& isValid) { isValid = true; return qVectorVec3FromScriptValue(v); } diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index 49adbf97fc..c43de8d076 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -50,8 +50,8 @@ EntityItemProperties LineEntityItem::getProperties() const { properties._color = getXColor(); properties._colorChanged = false; - properties._lineWidth = getLineWidth(); - properties._lineWidthChanged = false; + + COPY_ENTITY_PROPERTY_TO_PROPERTIES(lineWidth, getLineWidth); COPY_ENTITY_PROPERTY_TO_PROPERTIES(linePoints, getLinePoints); diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index 9d0d98686a..7c977210fc 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -383,14 +383,9 @@ bool OctreePacketData::appendValue(const glm::vec3& value) { bool OctreePacketData::appendValue(const QVector& value) { uint16_t qVecSize = value.size(); - uint16_t sizeLength = sizeof(qVecSize); - bool success = append((const unsigned char*)&qVecSize, sizeLength); - if(success){ - _bytesOfValues += sizeLength; - _totalBytesOfValues += sizeLength; - } + bool success = appendValue(qVecSize); success = append((const unsigned char*)value.constData(), qVecSize * sizeof(glm::vec3)); - if(success){ + if (success) { _bytesOfValues += qVecSize * sizeof(glm::vec3); _totalBytesOfValues += qVecSize * sizeof(glm::vec3); } diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index 4f57eea411..241f835a46 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -75,17 +75,17 @@ void vec3FromScriptValue(const QScriptValue &object, glm::vec3 &vec3) { QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector& vector){ QScriptValue array = engine->newArray(); - for(int i = 0; i < vector.size(); i++){ + for (int i = 0; i < vector.size(); i++) { array.setProperty(i, vec3toScriptValue(engine, vector.at(i))); } return array; } QVector qVectorVec3FromScriptValue(const QScriptValue& array){ - QVector newVector(0); + QVector newVector; int length = array.property("length").toInteger(); - for(int i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { glm::vec3 newVec3 = glm::vec3(); vec3FromScriptValue(array.property(i), newVec3); newVector << newVec3; From a98baef73603161f7149792de9584d6923a9830f Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 2 Jun 2015 13:56:18 -0700 Subject: [PATCH 71/72] another code cleanup --- libraries/entities-renderer/src/RenderableLineEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 16d54feda0..3b18210d6b 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -33,7 +33,7 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glPushMatrix(); glLineWidth(getLineWidth()); auto geometryCache = DependencyManager::get(); - if(_lineVerticesID == GeometryCache::UNKNOWN_ID){ + if (_lineVerticesID == GeometryCache::UNKNOWN_ID) { _lineVerticesID = geometryCache ->allocateID(); } //TODO: Figure out clean , efficient way to do relative line positioning. For now we'll just use absolute positioning. From 7527efc2d6b8b9329ea1948c97d16d8c18293a79 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 2 Jun 2015 13:58:09 -0700 Subject: [PATCH 72/72] removed unsuded variable --- libraries/entities-renderer/src/RenderableLineEntityItem.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 3b18210d6b..1951b2592b 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -40,7 +40,6 @@ void RenderableLineEntityItem::render(RenderArgs* args) { //glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - QVector points; if (_pointsChanged) { geometryCache->updateVertices(_lineVerticesID, getLinePoints(), lineColor); _pointsChanged = false;