From e7834365f5cd17cc97f1b44e208341d4c5d99412 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 15:33:39 -0700 Subject: [PATCH 1/7] Made polyline painting experience smoother- no more flickering --- .../src/RenderablePolyLineEntityItem.cpp | 212 +++++------ libraries/entities/src/PolyLineEntityItem.cpp | 330 +++++++++--------- 2 files changed, 271 insertions(+), 271 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index c6b7b58538..f7057ff906 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -25,12 +25,12 @@ EntityItemPointer RenderablePolyLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { - return EntityItemPointer(new RenderablePolyLineEntityItem(entityID, properties)); + return EntityItemPointer(new RenderablePolyLineEntityItem(entityID, properties)); } RenderablePolyLineEntityItem::RenderablePolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : PolyLineEntityItem(entityItemID, properties) { - _numVertices = 0; + _numVertices = 0; } @@ -40,119 +40,119 @@ gpu::TexturePointer RenderablePolyLineEntityItem::_texture; GLint RenderablePolyLineEntityItem::PAINTSTROKE_GPU_SLOT; void RenderablePolyLineEntityItem::createPipeline() { - static const int NORMAL_OFFSET = 12; - static const int COLOR_OFFSET = 24; - static const int TEXTURE_OFFSET = 28; - - auto textureCache = DependencyManager::get(); - QString path = PathUtils::resourcesPath() + "images/paintStroke.png"; - _texture = textureCache->getImageTexture(path); - _format.reset(new gpu::Stream::Format()); - _format->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); - _format->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), NORMAL_OFFSET); - _format->setAttribute(gpu::Stream::COLOR, 0, gpu::Element::COLOR_RGBA_32, COLOR_OFFSET); - _format->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), TEXTURE_OFFSET); - - auto VS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(paintStroke_vert))); - auto PS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(paintStroke_frag))); - gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(VS, PS)); - - gpu::Shader::BindingSet slotBindings; - PAINTSTROKE_GPU_SLOT = 0; - slotBindings.insert(gpu::Shader::Binding(std::string("paintStrokeTextureBinding"), PAINTSTROKE_GPU_SLOT)); - gpu::Shader::makeProgram(*program, slotBindings); - - gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - state->setDepthTest(true, true, gpu::LESS_EQUAL); - state->setBlendFunction(true, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, - gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); - _pipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state)); + static const int NORMAL_OFFSET = 12; + static const int COLOR_OFFSET = 24; + static const int TEXTURE_OFFSET = 28; + + auto textureCache = DependencyManager::get(); + QString path = PathUtils::resourcesPath() + "images/paintStroke.png"; + _texture = textureCache->getImageTexture(path); + _format.reset(new gpu::Stream::Format()); + _format->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); + _format->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), NORMAL_OFFSET); + _format->setAttribute(gpu::Stream::COLOR, 0, gpu::Element::COLOR_RGBA_32, COLOR_OFFSET); + _format->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), TEXTURE_OFFSET); + + auto VS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(paintStroke_vert))); + auto PS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(paintStroke_frag))); + gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(VS, PS)); + + gpu::Shader::BindingSet slotBindings; + PAINTSTROKE_GPU_SLOT = 0; + slotBindings.insert(gpu::Shader::Binding(std::string("paintStrokeTextureBinding"), PAINTSTROKE_GPU_SLOT)); + gpu::Shader::makeProgram(*program, slotBindings); + + gpu::StatePointer state = gpu::StatePointer(new gpu::State()); + state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setBlendFunction(true, + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + _pipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state)); } void RenderablePolyLineEntityItem::updateGeometry() { - _numVertices = 0; - _verticesBuffer.reset(new gpu::Buffer()); - int vertexIndex = 0; - vec2 uv; - float tailStart = 0.0f; - float tailEnd = 0.25f; - float tailLength = tailEnd - tailStart; - - float headStart = 0.76f; - float headEnd = 1.0f; - float headLength = headEnd - headStart; - float uCoord, vCoord; - - int numTailStrips = 5; - int numHeadStrips = 10; - int startHeadIndex = _normals.size() - numHeadStrips; - for (int i = 0; i < _normals.size(); i++) { - uCoord = 0.26f; - vCoord = 0.0f; - //tail - if(i < numTailStrips) { - uCoord = float(i)/numTailStrips * tailLength + tailStart; - } - - //head - if( i > startHeadIndex) { - uCoord = float( (i+ 1) - startHeadIndex)/numHeadStrips * headLength + headStart; - } + _numVertices = 0; + _verticesBuffer.reset(new gpu::Buffer()); + int vertexIndex = 0; + vec2 uv; + float tailStart = 0.0f; + float tailEnd = 0.25f; + float tailLength = tailEnd - tailStart; - uv = vec2(uCoord, vCoord); - - _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex)); - _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i)); - _verticesBuffer->append(sizeof(int), (gpu::Byte*)&_color); - _verticesBuffer->append(sizeof(glm::vec2), (gpu::Byte*)&uv); - vertexIndex++; + float headStart = 0.76f; + float headEnd = 1.0f; + float headLength = headEnd - headStart; + float uCoord, vCoord; + + int numTailStrips = 5; + int numHeadStrips = 10; + int startHeadIndex = _vertices.size() / 2 - numHeadStrips; + for (int i = 0; i < _vertices.size() / 2; i++) { + uCoord = 0.26f; + vCoord = 0.0f; + //tail + if (i < numTailStrips) { + uCoord = float(i) / numTailStrips * tailLength + tailStart; + } + + //head + if (i > startHeadIndex) { + uCoord = float((i + 1) - startHeadIndex) / numHeadStrips * headLength + headStart; + } + + uv = vec2(uCoord, vCoord); + + _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex)); + _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i)); + _verticesBuffer->append(sizeof(int), (gpu::Byte*)&_color); + _verticesBuffer->append(sizeof(glm::vec2), (gpu::Byte*)&uv); + vertexIndex++; + + uv.y = 1.0f; + _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex)); + _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i)); + _verticesBuffer->append(sizeof(int), (gpu::Byte*)_color); + _verticesBuffer->append(sizeof(glm::vec2), (const gpu::Byte*)&uv); + vertexIndex++; + + _numVertices += 2; + } + _pointsChanged = false; - uv.y = 1.0f; - _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex)); - _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i)); - _verticesBuffer->append(sizeof(int), (gpu::Byte*)_color); - _verticesBuffer->append(sizeof(glm::vec2), (const gpu::Byte*)&uv); - vertexIndex++; - - _numVertices +=2; - } - _pointsChanged = false; - } void RenderablePolyLineEntityItem::render(RenderArgs* args) { - QWriteLocker lock(&_quadReadWriteLock); - if (_points.size() < 2 || _vertices.size() != _normals.size() * 2) { - return; - } - - if (!_pipeline) { - createPipeline(); - } - - PerformanceTimer perfTimer("RenderablePolyLineEntityItem::render"); - Q_ASSERT(getType() == EntityTypes::PolyLine); - - Q_ASSERT(args->_batch); - if (_pointsChanged) { - updateGeometry(); - } - - gpu::Batch& batch = *args->_batch; - Transform transform = Transform(); - transform.setTranslation(getPosition()); - transform.setRotation(getRotation()); - batch.setModelTransform(transform); + QWriteLocker lock(&_quadReadWriteLock); + if (_points.size() < 2) { + return; + } - batch.setPipeline(_pipeline); - batch.setResourceTexture(PAINTSTROKE_GPU_SLOT, _texture); + if (!_pipeline) { + createPipeline(); + } - batch.setInputFormat(_format); - batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride); - - batch.draw(gpu::TRIANGLE_STRIP, _numVertices, 0); - - RenderableDebugableEntityItem::render(this, args); + PerformanceTimer perfTimer("RenderablePolyLineEntityItem::render"); + Q_ASSERT(getType() == EntityTypes::PolyLine); + + Q_ASSERT(args->_batch); + if (_pointsChanged) { + updateGeometry(); + } + + gpu::Batch& batch = *args->_batch; + Transform transform = Transform(); + transform.setTranslation(getPosition()); + transform.setRotation(getRotation()); + batch.setModelTransform(transform); + + batch.setPipeline(_pipeline); + batch.setResourceTexture(PAINTSTROKE_GPU_SLOT, _texture); + + batch.setInputFormat(_format); + batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride); + + batch.draw(gpu::TRIANGLE_STRIP, _numVertices, 0); + + RenderableDebugableEntityItem::render(this, args); }; diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index 29a44547ff..09ddc4ec76 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -27,12 +27,12 @@ const int PolyLineEntityItem::MAX_POINTS_PER_LINE = 70; EntityItemPointer PolyLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { - EntityItemPointer result { new PolyLineEntityItem(entityID, properties) }; - return result; + EntityItemPointer result{ new PolyLineEntityItem(entityID, properties) }; + return result; } PolyLineEntityItem::PolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : -EntityItem(entityItemID) , +EntityItem(entityItemID), _lineWidth(DEFAULT_LINE_WIDTH), _pointsChanged(true), _points(QVector(0.0f)), @@ -40,200 +40,200 @@ _vertices(QVector(0.0f)), _normals(QVector(0.0f)), _strokeWidths(QVector(0.0f)) { - _type = EntityTypes::PolyLine; - _created = properties.getCreated(); - setProperties(properties); + _type = EntityTypes::PolyLine; + _created = properties.getCreated(); + setProperties(properties); } EntityItemProperties PolyLineEntityItem::getProperties(EntityPropertyFlags desiredProperties) const { - QWriteLocker lock(&_quadReadWriteLock); - EntityItemProperties properties = EntityItem::getProperties(desiredProperties); // get the properties from our base class - - - properties._color = getXColor(); - properties._colorChanged = false; - - COPY_ENTITY_PROPERTY_TO_PROPERTIES(lineWidth, getLineWidth); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(linePoints, getLinePoints); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(normals, getNormals); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(strokeWidths, getStrokeWidths); - - properties._glowLevel = getGlowLevel(); - properties._glowLevelChanged = false; - return properties; + QWriteLocker lock(&_quadReadWriteLock); + EntityItemProperties properties = EntityItem::getProperties(desiredProperties); // get the properties from our base class + + + properties._color = getXColor(); + properties._colorChanged = false; + + COPY_ENTITY_PROPERTY_TO_PROPERTIES(lineWidth, getLineWidth); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(linePoints, getLinePoints); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(normals, getNormals); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(strokeWidths, getStrokeWidths); + + properties._glowLevel = getGlowLevel(); + properties._glowLevelChanged = false; + return properties; } bool PolyLineEntityItem::setProperties(const EntityItemProperties& properties) { - QWriteLocker lock(&_quadReadWriteLock); - 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); - SET_ENTITY_PROPERTY_FROM_PROPERTIES(normals, setNormals); - SET_ENTITY_PROPERTY_FROM_PROPERTIES(strokeWidths, setStrokeWidths); - - if (somethingChanged) { - bool wantDebug = false; - if (wantDebug) { - uint64_t now = usecTimestampNow(); - int elapsed = now - getLastEdited(); - qCDebug(entities) << "PolyLineEntityItem::setProperties() AFTER update... edited AGO=" << elapsed << - "now=" << now << " getLastEdited()=" << getLastEdited(); - } - setLastEdited(properties._lastEdited); - } - return somethingChanged; + QWriteLocker lock(&_quadReadWriteLock); + 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); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(normals, setNormals); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(strokeWidths, setStrokeWidths); + + if (somethingChanged) { + bool wantDebug = false; + if (wantDebug) { + uint64_t now = usecTimestampNow(); + int elapsed = now - getLastEdited(); + qCDebug(entities) << "PolyLineEntityItem::setProperties() AFTER update... edited AGO=" << elapsed << + "now=" << now << " getLastEdited()=" << getLastEdited(); + } + setLastEdited(properties._lastEdited); + } + return somethingChanged; } bool PolyLineEntityItem::appendPoint(const glm::vec3& point) { - if (_points.size() > MAX_POINTS_PER_LINE - 1) { - qDebug() << "MAX POINTS REACHED!"; - return false; - } - glm::vec3 halfBox = getDimensions() * 0.5f; - if ( (point.x < - halfBox.x || point.x > halfBox.x) || (point.y < -halfBox.y || point.y > halfBox.y) || (point.z < - halfBox.z || point.z > halfBox.z) ) { - qDebug() << "Point is outside entity's bounding box"; - return false; - } - _points << point; - _pointsChanged = true; - return true; + if (_points.size() > MAX_POINTS_PER_LINE - 1) { + qDebug() << "MAX POINTS REACHED!"; + return false; + } + glm::vec3 halfBox = getDimensions() * 0.5f; + if ((point.x < -halfBox.x || point.x > halfBox.x) || (point.y < -halfBox.y || point.y > halfBox.y) || (point.z < -halfBox.z || point.z > halfBox.z)) { + qDebug() << "Point is outside entity's bounding box"; + return false; + } + _points << point; + _pointsChanged = true; + return true; } -bool PolyLineEntityItem::setStrokeWidths(const QVector& strokeWidths ) { - _strokeWidths = strokeWidths; - return true; +bool PolyLineEntityItem::setStrokeWidths(const QVector& strokeWidths) { + _strokeWidths = strokeWidths; + return true; } bool PolyLineEntityItem::setNormals(const QVector& normals) { - _normals = normals; - if (_points.size () < 2 || _normals.size() < 2) { - return false; - } - - int minVectorSize = _normals.size(); - if (_points.size() < minVectorSize) { - minVectorSize = _points.size(); - } - if (_strokeWidths.size() < minVectorSize) { - minVectorSize = _strokeWidths.size(); - } + _normals = normals; + if (_points.size() < 2 || _normals.size() < 2) { + return false; + } - _vertices.clear(); - glm::vec3 v1, v2, tangent, binormal, point; - - for (int i = 0; i < minVectorSize-1; i++) { - float width = _strokeWidths.at(i); - point = _points.at(i); - - tangent = _points.at(i+1) - point; - glm::vec3 normal = normals.at(i); - binormal = glm::normalize(glm::cross(tangent, normal)) * width; - - //This checks to make sure binormal is not a NAN - assert(binormal.x == binormal.x); - v1 = point + binormal; - v2 = point - binormal; - _vertices << v1 << v2; - } - //for last point we can just assume binormals are same since it represents last two vertices of quad - point = _points.at(_points.size() - 1); - v1 = point + binormal; - v2 = point - binormal; - _vertices << v1 << v2; - - return true; + int minVectorSize = _normals.size(); + if (_points.size() < minVectorSize) { + minVectorSize = _points.size(); + } + if (_strokeWidths.size() < minVectorSize) { + minVectorSize = _strokeWidths.size(); + } + + _vertices.clear(); + glm::vec3 v1, v2, tangent, binormal, point; + + for (int i = 0; i < minVectorSize - 1; i++) { + float width = _strokeWidths.at(i); + point = _points.at(i); + + tangent = _points.at(i + 1) - point; + glm::vec3 normal = normals.at(i); + binormal = glm::normalize(glm::cross(tangent, normal)) * width; + + //This checks to make sure binormal is not a NAN + assert(binormal.x == binormal.x); + v1 = point + binormal; + v2 = point - binormal; + _vertices << v1 << v2; + } + //for last point we can just assume binormals are same since it represents last two vertices of quad + point = _points.at(minVectorSize - 1); + v1 = point + binormal; + v2 = point - binormal; + _vertices << v1 << v2; + + return true; } bool PolyLineEntityItem::setLinePoints(const QVector& points) { - if (points.size() > MAX_POINTS_PER_LINE) { - return false; - } - if (points.size() != _points.size()) { - _pointsChanged = true; - } - //Check to see if points actually changed. If they haven't, return before doing anything else - else if (points.size() == _points.size()) { - //same number of points, so now compare every point - for (int i = 0; i < points.size(); i++ ) { - if (points.at(i) != _points.at(i)){ - _pointsChanged = true; - break; - } - } - } - if (!_pointsChanged) { - return false; - } + if (points.size() > MAX_POINTS_PER_LINE) { + return false; + } + if (points.size() != _points.size()) { + _pointsChanged = true; + } + //Check to see if points actually changed. If they haven't, return before doing anything else + else if (points.size() == _points.size()) { + //same number of points, so now compare every point + for (int i = 0; i < points.size(); i++) { + if (points.at(i) != _points.at(i)){ + _pointsChanged = true; + break; + } + } + } + if (!_pointsChanged) { + return false; + } - for (int i = 0; i < points.size(); i++) { - glm::vec3 point = points.at(i); - glm::vec3 halfBox = getDimensions() * 0.5f; - if ((point.x < - halfBox.x || point.x > halfBox.x) || - (point.y < -halfBox.y || point.y > halfBox.y) || - (point.z < - halfBox.z || point.z > halfBox.z)) { - qDebug() << "Point is outside entity's bounding box"; - return false; - } - } - _points = points; - return true; + for (int i = 0; i < points.size(); i++) { + glm::vec3 point = points.at(i); + glm::vec3 halfBox = getDimensions() * 0.5f; + if ((point.x < -halfBox.x || point.x > halfBox.x) || + (point.y < -halfBox.y || point.y > halfBox.y) || + (point.z < -halfBox.z || point.z > halfBox.z)) { + qDebug() << "Point is outside entity's bounding box"; + return false; + } + } + _points = points; + return true; } int PolyLineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, - ReadBitstreamToTreeParams& args, - EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { - QWriteLocker lock(&_quadReadWriteLock); - int bytesRead = 0; - const unsigned char* dataAt = 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_NORMALS, QVector, setNormals); - READ_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, QVector, setStrokeWidths); - - return bytesRead; + ReadBitstreamToTreeParams& args, + EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { + QWriteLocker lock(&_quadReadWriteLock); + int bytesRead = 0; + const unsigned char* dataAt = 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_NORMALS, QVector, setNormals); + READ_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, QVector, setStrokeWidths); + + return bytesRead; } // TODO: eventually only include properties changed since the params.lastViewFrustumSent time EntityPropertyFlags PolyLineEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { - EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); - requestedProperties += PROP_COLOR; - requestedProperties += PROP_LINE_WIDTH; - requestedProperties += PROP_LINE_POINTS; - requestedProperties += PROP_NORMALS; - requestedProperties += PROP_STROKE_WIDTHS; - return requestedProperties; + EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); + requestedProperties += PROP_COLOR; + requestedProperties += PROP_LINE_WIDTH; + requestedProperties += PROP_LINE_POINTS; + requestedProperties += PROP_NORMALS; + requestedProperties += PROP_STROKE_WIDTHS; + return requestedProperties; } void PolyLineEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, - EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, - EntityPropertyFlags& requestedProperties, - EntityPropertyFlags& propertyFlags, - EntityPropertyFlags& propertiesDidntFit, - int& propertyCount, - OctreeElement::AppendState& appendState) const { - - QWriteLocker lock(&_quadReadWriteLock); - bool successPropertyFits = true; - - APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); - APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, getLineWidth()); - APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, getLinePoints()); - APPEND_ENTITY_PROPERTY(PROP_NORMALS, getNormals()); - APPEND_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, getStrokeWidths()); + EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const { + + QWriteLocker lock(&_quadReadWriteLock); + bool successPropertyFits = true; + + APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); + APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, getLineWidth()); + APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, getLinePoints()); + APPEND_ENTITY_PROPERTY(PROP_NORMALS, getNormals()); + APPEND_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, getStrokeWidths()); } void PolyLineEntityItem::debugDump() const { - quint64 now = usecTimestampNow(); - qCDebug(entities) << " QUAD EntityItem id:" << getEntityItemID() << "---------------------------------------------"; - qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; - qCDebug(entities) << " position:" << debugTreeVector(getPosition()); - qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions()); - qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); + quint64 now = usecTimestampNow(); + qCDebug(entities) << " QUAD EntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; + qCDebug(entities) << " position:" << debugTreeVector(getPosition()); + qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions()); + qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); } From 36be35a8363a02669c626d865cf57c370582fcff Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 29 Sep 2015 16:30:42 -0700 Subject: [PATCH 2/7] Update RenderablePolyLineEntityItem.cpp --- .../entities-renderer/src/RenderablePolyLineEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index f7057ff906..7d95d472ee 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -25,7 +25,7 @@ EntityItemPointer RenderablePolyLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { - return EntityItemPointer(new RenderablePolyLineEntityItem(entityID, properties)); + return EntityItemPointer(new RenderablePolyLineEntityItem(entityID, properties)); } RenderablePolyLineEntityItem::RenderablePolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : From 614312f04f5c6e68fc555b36e031916a7dfbf158 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 29 Sep 2015 16:32:07 -0700 Subject: [PATCH 3/7] Update PolyLineEntityItem.cpp --- libraries/entities/src/PolyLineEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index 09ddc4ec76..f5e6a98423 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -139,7 +139,7 @@ bool PolyLineEntityItem::setNormals(const QVector& normals) { _vertices << v1 << v2; } //for last point we can just assume binormals are same since it represents last two vertices of quad - point = _points.at(minVectorSize - 1); + point = _points.at(minVectorSize - 1); v1 = point + binormal; v2 = point - binormal; _vertices << v1 << v2; From c901a749c2c300b84cb745b36c2dddb70e000d51 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 29 Sep 2015 16:33:18 -0700 Subject: [PATCH 4/7] Update RenderablePolyLineEntityItem.cpp --- .../entities-renderer/src/RenderablePolyLineEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index 7d95d472ee..d87138637d 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -124,7 +124,7 @@ void RenderablePolyLineEntityItem::updateGeometry() { void RenderablePolyLineEntityItem::render(RenderArgs* args) { QWriteLocker lock(&_quadReadWriteLock); - if (_points.size() < 2) { + if (_points.size() < 2) { return; } From d1b016b483be465df722ab76062a018cd341718d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 16:38:21 -0700 Subject: [PATCH 5/7] untabbified lines --- .../src/RenderablePolyLineEntityItem.cpp | 178 +++++------ libraries/entities/src/PolyLineEntityItem.cpp | 294 +++++++++--------- 2 files changed, 236 insertions(+), 236 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index 7d95d472ee..27981d2530 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -30,7 +30,7 @@ EntityItemPointer RenderablePolyLineEntityItem::factory(const EntityItemID& enti RenderablePolyLineEntityItem::RenderablePolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : PolyLineEntityItem(entityItemID, properties) { - _numVertices = 0; + _numVertices = 0; } @@ -40,119 +40,119 @@ gpu::TexturePointer RenderablePolyLineEntityItem::_texture; GLint RenderablePolyLineEntityItem::PAINTSTROKE_GPU_SLOT; void RenderablePolyLineEntityItem::createPipeline() { - static const int NORMAL_OFFSET = 12; - static const int COLOR_OFFSET = 24; - static const int TEXTURE_OFFSET = 28; + static const int NORMAL_OFFSET = 12; + static const int COLOR_OFFSET = 24; + static const int TEXTURE_OFFSET = 28; - auto textureCache = DependencyManager::get(); - QString path = PathUtils::resourcesPath() + "images/paintStroke.png"; - _texture = textureCache->getImageTexture(path); - _format.reset(new gpu::Stream::Format()); - _format->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); - _format->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), NORMAL_OFFSET); - _format->setAttribute(gpu::Stream::COLOR, 0, gpu::Element::COLOR_RGBA_32, COLOR_OFFSET); - _format->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), TEXTURE_OFFSET); + auto textureCache = DependencyManager::get(); + QString path = PathUtils::resourcesPath() + "images/paintStroke.png"; + _texture = textureCache->getImageTexture(path); + _format.reset(new gpu::Stream::Format()); + _format->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); + _format->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), NORMAL_OFFSET); + _format->setAttribute(gpu::Stream::COLOR, 0, gpu::Element::COLOR_RGBA_32, COLOR_OFFSET); + _format->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), TEXTURE_OFFSET); - auto VS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(paintStroke_vert))); - auto PS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(paintStroke_frag))); - gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(VS, PS)); + auto VS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(paintStroke_vert))); + auto PS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(paintStroke_frag))); + gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(VS, PS)); - gpu::Shader::BindingSet slotBindings; - PAINTSTROKE_GPU_SLOT = 0; - slotBindings.insert(gpu::Shader::Binding(std::string("paintStrokeTextureBinding"), PAINTSTROKE_GPU_SLOT)); - gpu::Shader::makeProgram(*program, slotBindings); + gpu::Shader::BindingSet slotBindings; + PAINTSTROKE_GPU_SLOT = 0; + slotBindings.insert(gpu::Shader::Binding(std::string("paintStrokeTextureBinding"), PAINTSTROKE_GPU_SLOT)); + gpu::Shader::makeProgram(*program, slotBindings); - gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - state->setDepthTest(true, true, gpu::LESS_EQUAL); - state->setBlendFunction(true, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, - gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); - _pipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state)); + gpu::StatePointer state = gpu::StatePointer(new gpu::State()); + state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setBlendFunction(true, + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + _pipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state)); } void RenderablePolyLineEntityItem::updateGeometry() { - _numVertices = 0; - _verticesBuffer.reset(new gpu::Buffer()); - int vertexIndex = 0; - vec2 uv; - float tailStart = 0.0f; - float tailEnd = 0.25f; - float tailLength = tailEnd - tailStart; + _numVertices = 0; + _verticesBuffer.reset(new gpu::Buffer()); + int vertexIndex = 0; + vec2 uv; + float tailStart = 0.0f; + float tailEnd = 0.25f; + float tailLength = tailEnd - tailStart; - float headStart = 0.76f; - float headEnd = 1.0f; - float headLength = headEnd - headStart; - float uCoord, vCoord; + float headStart = 0.76f; + float headEnd = 1.0f; + float headLength = headEnd - headStart; + float uCoord, vCoord; - int numTailStrips = 5; - int numHeadStrips = 10; - int startHeadIndex = _vertices.size() / 2 - numHeadStrips; - for (int i = 0; i < _vertices.size() / 2; i++) { - uCoord = 0.26f; - vCoord = 0.0f; - //tail - if (i < numTailStrips) { - uCoord = float(i) / numTailStrips * tailLength + tailStart; - } + int numTailStrips = 5; + int numHeadStrips = 10; + int startHeadIndex = _vertices.size() / 2 - numHeadStrips; + for (int i = 0; i < _vertices.size() / 2; i++) { + uCoord = 0.26f; + vCoord = 0.0f; + //tail + if (i < numTailStrips) { + uCoord = float(i) / numTailStrips * tailLength + tailStart; + } - //head - if (i > startHeadIndex) { - uCoord = float((i + 1) - startHeadIndex) / numHeadStrips * headLength + headStart; - } + //head + if (i > startHeadIndex) { + uCoord = float((i + 1) - startHeadIndex) / numHeadStrips * headLength + headStart; + } - uv = vec2(uCoord, vCoord); + uv = vec2(uCoord, vCoord); - _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex)); - _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i)); - _verticesBuffer->append(sizeof(int), (gpu::Byte*)&_color); - _verticesBuffer->append(sizeof(glm::vec2), (gpu::Byte*)&uv); - vertexIndex++; + _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex)); + _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i)); + _verticesBuffer->append(sizeof(int), (gpu::Byte*)&_color); + _verticesBuffer->append(sizeof(glm::vec2), (gpu::Byte*)&uv); + vertexIndex++; - uv.y = 1.0f; - _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex)); - _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i)); - _verticesBuffer->append(sizeof(int), (gpu::Byte*)_color); - _verticesBuffer->append(sizeof(glm::vec2), (const gpu::Byte*)&uv); - vertexIndex++; + uv.y = 1.0f; + _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex)); + _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i)); + _verticesBuffer->append(sizeof(int), (gpu::Byte*)_color); + _verticesBuffer->append(sizeof(glm::vec2), (const gpu::Byte*)&uv); + vertexIndex++; - _numVertices += 2; - } - _pointsChanged = false; + _numVertices += 2; + } + _pointsChanged = false; } void RenderablePolyLineEntityItem::render(RenderArgs* args) { - QWriteLocker lock(&_quadReadWriteLock); - if (_points.size() < 2) { - return; - } + QWriteLocker lock(&_quadReadWriteLock); + if (_points.size() < 2) { + return; + } - if (!_pipeline) { - createPipeline(); - } + if (!_pipeline) { + createPipeline(); + } - PerformanceTimer perfTimer("RenderablePolyLineEntityItem::render"); - Q_ASSERT(getType() == EntityTypes::PolyLine); + PerformanceTimer perfTimer("RenderablePolyLineEntityItem::render"); + Q_ASSERT(getType() == EntityTypes::PolyLine); - Q_ASSERT(args->_batch); - if (_pointsChanged) { - updateGeometry(); - } + Q_ASSERT(args->_batch); + if (_pointsChanged) { + updateGeometry(); + } - gpu::Batch& batch = *args->_batch; - Transform transform = Transform(); - transform.setTranslation(getPosition()); - transform.setRotation(getRotation()); - batch.setModelTransform(transform); + gpu::Batch& batch = *args->_batch; + Transform transform = Transform(); + transform.setTranslation(getPosition()); + transform.setRotation(getRotation()); + batch.setModelTransform(transform); - batch.setPipeline(_pipeline); - batch.setResourceTexture(PAINTSTROKE_GPU_SLOT, _texture); + batch.setPipeline(_pipeline); + batch.setResourceTexture(PAINTSTROKE_GPU_SLOT, _texture); - batch.setInputFormat(_format); - batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride); + batch.setInputFormat(_format); + batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride); - batch.draw(gpu::TRIANGLE_STRIP, _numVertices, 0); + batch.draw(gpu::TRIANGLE_STRIP, _numVertices, 0); - RenderableDebugableEntityItem::render(this, args); + RenderableDebugableEntityItem::render(this, args); }; diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index f5e6a98423..c29ed43041 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -27,8 +27,8 @@ const int PolyLineEntityItem::MAX_POINTS_PER_LINE = 70; EntityItemPointer PolyLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { - EntityItemPointer result{ new PolyLineEntityItem(entityID, properties) }; - return result; + EntityItemPointer result{ new PolyLineEntityItem(entityID, properties) }; + return result; } PolyLineEntityItem::PolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : @@ -40,200 +40,200 @@ _vertices(QVector(0.0f)), _normals(QVector(0.0f)), _strokeWidths(QVector(0.0f)) { - _type = EntityTypes::PolyLine; - _created = properties.getCreated(); - setProperties(properties); + _type = EntityTypes::PolyLine; + _created = properties.getCreated(); + setProperties(properties); } EntityItemProperties PolyLineEntityItem::getProperties(EntityPropertyFlags desiredProperties) const { - QWriteLocker lock(&_quadReadWriteLock); - EntityItemProperties properties = EntityItem::getProperties(desiredProperties); // get the properties from our base class + QWriteLocker lock(&_quadReadWriteLock); + EntityItemProperties properties = EntityItem::getProperties(desiredProperties); // get the properties from our base class - properties._color = getXColor(); - properties._colorChanged = false; + properties._color = getXColor(); + properties._colorChanged = false; - COPY_ENTITY_PROPERTY_TO_PROPERTIES(lineWidth, getLineWidth); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(linePoints, getLinePoints); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(normals, getNormals); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(strokeWidths, getStrokeWidths); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(lineWidth, getLineWidth); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(linePoints, getLinePoints); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(normals, getNormals); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(strokeWidths, getStrokeWidths); - properties._glowLevel = getGlowLevel(); - properties._glowLevelChanged = false; - return properties; + properties._glowLevel = getGlowLevel(); + properties._glowLevelChanged = false; + return properties; } bool PolyLineEntityItem::setProperties(const EntityItemProperties& properties) { - QWriteLocker lock(&_quadReadWriteLock); - bool somethingChanged = false; - somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class + QWriteLocker lock(&_quadReadWriteLock); + 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); - SET_ENTITY_PROPERTY_FROM_PROPERTIES(normals, setNormals); - SET_ENTITY_PROPERTY_FROM_PROPERTIES(strokeWidths, setStrokeWidths); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(lineWidth, setLineWidth); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(linePoints, setLinePoints); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(normals, setNormals); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(strokeWidths, setStrokeWidths); - if (somethingChanged) { - bool wantDebug = false; - if (wantDebug) { - uint64_t now = usecTimestampNow(); - int elapsed = now - getLastEdited(); - qCDebug(entities) << "PolyLineEntityItem::setProperties() AFTER update... edited AGO=" << elapsed << - "now=" << now << " getLastEdited()=" << getLastEdited(); - } - setLastEdited(properties._lastEdited); - } - return somethingChanged; + if (somethingChanged) { + bool wantDebug = false; + if (wantDebug) { + uint64_t now = usecTimestampNow(); + int elapsed = now - getLastEdited(); + qCDebug(entities) << "PolyLineEntityItem::setProperties() AFTER update... edited AGO=" << elapsed << + "now=" << now << " getLastEdited()=" << getLastEdited(); + } + setLastEdited(properties._lastEdited); + } + return somethingChanged; } bool PolyLineEntityItem::appendPoint(const glm::vec3& point) { - if (_points.size() > MAX_POINTS_PER_LINE - 1) { - qDebug() << "MAX POINTS REACHED!"; - return false; - } - glm::vec3 halfBox = getDimensions() * 0.5f; - if ((point.x < -halfBox.x || point.x > halfBox.x) || (point.y < -halfBox.y || point.y > halfBox.y) || (point.z < -halfBox.z || point.z > halfBox.z)) { - qDebug() << "Point is outside entity's bounding box"; - return false; - } - _points << point; - _pointsChanged = true; - return true; + if (_points.size() > MAX_POINTS_PER_LINE - 1) { + qDebug() << "MAX POINTS REACHED!"; + return false; + } + glm::vec3 halfBox = getDimensions() * 0.5f; + if ((point.x < -halfBox.x || point.x > halfBox.x) || (point.y < -halfBox.y || point.y > halfBox.y) || (point.z < -halfBox.z || point.z > halfBox.z)) { + qDebug() << "Point is outside entity's bounding box"; + return false; + } + _points << point; + _pointsChanged = true; + return true; } bool PolyLineEntityItem::setStrokeWidths(const QVector& strokeWidths) { - _strokeWidths = strokeWidths; - return true; + _strokeWidths = strokeWidths; + return true; } bool PolyLineEntityItem::setNormals(const QVector& normals) { - _normals = normals; - if (_points.size() < 2 || _normals.size() < 2) { - return false; - } + _normals = normals; + if (_points.size() < 2 || _normals.size() < 2) { + return false; + } - int minVectorSize = _normals.size(); - if (_points.size() < minVectorSize) { - minVectorSize = _points.size(); - } - if (_strokeWidths.size() < minVectorSize) { - minVectorSize = _strokeWidths.size(); - } + int minVectorSize = _normals.size(); + if (_points.size() < minVectorSize) { + minVectorSize = _points.size(); + } + if (_strokeWidths.size() < minVectorSize) { + minVectorSize = _strokeWidths.size(); + } - _vertices.clear(); - glm::vec3 v1, v2, tangent, binormal, point; + _vertices.clear(); + glm::vec3 v1, v2, tangent, binormal, point; - for (int i = 0; i < minVectorSize - 1; i++) { - float width = _strokeWidths.at(i); - point = _points.at(i); + for (int i = 0; i < minVectorSize - 1; i++) { + float width = _strokeWidths.at(i); + point = _points.at(i); - tangent = _points.at(i + 1) - point; - glm::vec3 normal = normals.at(i); - binormal = glm::normalize(glm::cross(tangent, normal)) * width; + tangent = _points.at(i + 1) - point; + glm::vec3 normal = normals.at(i); + binormal = glm::normalize(glm::cross(tangent, normal)) * width; - //This checks to make sure binormal is not a NAN - assert(binormal.x == binormal.x); - v1 = point + binormal; - v2 = point - binormal; - _vertices << v1 << v2; - } - //for last point we can just assume binormals are same since it represents last two vertices of quad + //This checks to make sure binormal is not a NAN + assert(binormal.x == binormal.x); + v1 = point + binormal; + v2 = point - binormal; + _vertices << v1 << v2; + } + //for last point we can just assume binormals are same since it represents last two vertices of quad point = _points.at(minVectorSize - 1); - v1 = point + binormal; - v2 = point - binormal; - _vertices << v1 << v2; + v1 = point + binormal; + v2 = point - binormal; + _vertices << v1 << v2; - return true; + return true; } bool PolyLineEntityItem::setLinePoints(const QVector& points) { - if (points.size() > MAX_POINTS_PER_LINE) { - return false; - } - if (points.size() != _points.size()) { - _pointsChanged = true; - } - //Check to see if points actually changed. If they haven't, return before doing anything else - else if (points.size() == _points.size()) { - //same number of points, so now compare every point - for (int i = 0; i < points.size(); i++) { - if (points.at(i) != _points.at(i)){ - _pointsChanged = true; - break; - } - } - } - if (!_pointsChanged) { - return false; - } + if (points.size() > MAX_POINTS_PER_LINE) { + return false; + } + if (points.size() != _points.size()) { + _pointsChanged = true; + } + //Check to see if points actually changed. If they haven't, return before doing anything else + else if (points.size() == _points.size()) { + //same number of points, so now compare every point + for (int i = 0; i < points.size(); i++) { + if (points.at(i) != _points.at(i)){ + _pointsChanged = true; + break; + } + } + } + if (!_pointsChanged) { + return false; + } - for (int i = 0; i < points.size(); i++) { - glm::vec3 point = points.at(i); - glm::vec3 halfBox = getDimensions() * 0.5f; - if ((point.x < -halfBox.x || point.x > halfBox.x) || - (point.y < -halfBox.y || point.y > halfBox.y) || - (point.z < -halfBox.z || point.z > halfBox.z)) { - qDebug() << "Point is outside entity's bounding box"; - return false; - } - } - _points = points; - return true; + for (int i = 0; i < points.size(); i++) { + glm::vec3 point = points.at(i); + glm::vec3 halfBox = getDimensions() * 0.5f; + if ((point.x < -halfBox.x || point.x > halfBox.x) || + (point.y < -halfBox.y || point.y > halfBox.y) || + (point.z < -halfBox.z || point.z > halfBox.z)) { + qDebug() << "Point is outside entity's bounding box"; + return false; + } + } + _points = points; + return true; } int PolyLineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, - ReadBitstreamToTreeParams& args, - EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { - QWriteLocker lock(&_quadReadWriteLock); - int bytesRead = 0; - const unsigned char* dataAt = data; + ReadBitstreamToTreeParams& args, + EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { + QWriteLocker lock(&_quadReadWriteLock); + int bytesRead = 0; + const unsigned char* dataAt = 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_NORMALS, QVector, setNormals); - READ_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, QVector, setStrokeWidths); + 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_NORMALS, QVector, setNormals); + READ_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, QVector, setStrokeWidths); - return bytesRead; + return bytesRead; } // TODO: eventually only include properties changed since the params.lastViewFrustumSent time EntityPropertyFlags PolyLineEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { - EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); - requestedProperties += PROP_COLOR; - requestedProperties += PROP_LINE_WIDTH; - requestedProperties += PROP_LINE_POINTS; - requestedProperties += PROP_NORMALS; - requestedProperties += PROP_STROKE_WIDTHS; - return requestedProperties; + EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); + requestedProperties += PROP_COLOR; + requestedProperties += PROP_LINE_WIDTH; + requestedProperties += PROP_LINE_POINTS; + requestedProperties += PROP_NORMALS; + requestedProperties += PROP_STROKE_WIDTHS; + return requestedProperties; } void PolyLineEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, - EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, - EntityPropertyFlags& requestedProperties, - EntityPropertyFlags& propertyFlags, - EntityPropertyFlags& propertiesDidntFit, - int& propertyCount, - OctreeElement::AppendState& appendState) const { + EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const { - QWriteLocker lock(&_quadReadWriteLock); - bool successPropertyFits = true; + QWriteLocker lock(&_quadReadWriteLock); + bool successPropertyFits = true; - APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); - APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, getLineWidth()); - APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, getLinePoints()); - APPEND_ENTITY_PROPERTY(PROP_NORMALS, getNormals()); - APPEND_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, getStrokeWidths()); + APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); + APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, getLineWidth()); + APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, getLinePoints()); + APPEND_ENTITY_PROPERTY(PROP_NORMALS, getNormals()); + APPEND_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, getStrokeWidths()); } void PolyLineEntityItem::debugDump() const { - quint64 now = usecTimestampNow(); - qCDebug(entities) << " QUAD EntityItem id:" << getEntityItemID() << "---------------------------------------------"; - qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; - qCDebug(entities) << " position:" << debugTreeVector(getPosition()); - qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions()); - qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); + quint64 now = usecTimestampNow(); + qCDebug(entities) << " QUAD EntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; + qCDebug(entities) << " position:" << debugTreeVector(getPosition()); + qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions()); + qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); } From 5ce3b13a4c006406656ecb65f99668f0d8debcc9 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 17:31:02 -0700 Subject: [PATCH 6/7] Fixed spacing issues --- libraries/entities/src/PolyLineEntityItem.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index c29ed43041..a01c2ce17b 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -183,9 +183,9 @@ bool PolyLineEntityItem::setLinePoints(const QVector& points) { } int PolyLineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, - ReadBitstreamToTreeParams& args, - EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { - QWriteLocker lock(&_quadReadWriteLock); + ReadBitstreamToTreeParams& args, + EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { + QWriteLocker lock(&_quadReadWriteLock); int bytesRead = 0; const unsigned char* dataAt = data; @@ -211,12 +211,12 @@ EntityPropertyFlags PolyLineEntityItem::getEntityProperties(EncodeBitstreamParam } void PolyLineEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, - EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, - EntityPropertyFlags& requestedProperties, - EntityPropertyFlags& propertyFlags, - EntityPropertyFlags& propertiesDidntFit, - int& propertyCount, - OctreeElement::AppendState& appendState) const { + EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const { QWriteLocker lock(&_quadReadWriteLock); bool successPropertyFits = true; From 1760720b2be77e53278ff8fa325d400f86f204b5 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 17:42:20 -0700 Subject: [PATCH 7/7] added check for normals and vertices --- .../entities-renderer/src/RenderablePolyLineEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index 27981d2530..572b24e99f 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -124,7 +124,7 @@ void RenderablePolyLineEntityItem::updateGeometry() { void RenderablePolyLineEntityItem::render(RenderArgs* args) { QWriteLocker lock(&_quadReadWriteLock); - if (_points.size() < 2) { + if (_points.size() < 2 || _normals.size () < 2 || _vertices.size() < 2) { return; }