diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index 17c97a5e9e..01f30a4a06 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -67,28 +67,33 @@ int generateColor() { } void RenderablePolyLineEntityItem::updateGeometry() { - QReadLocker lock(&_quadReadWriteLock); - int compactColor = generateColor(); - _numVertices = 0; - _verticesBuffer.reset(new gpu::Buffer()); - int vertexIndex = 0; - for (int i = 0; i < _normals.size(); i++) { - _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex)); - vertexIndex++; - _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i)); - _verticesBuffer->append(sizeof(int), (gpu::Byte*)&compactColor); - _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex)); - vertexIndex++; - _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i)); - _verticesBuffer->append(sizeof(int), (gpu::Byte*)&compactColor); - - _numVertices +=2; + if (_pointsChanged) { + int compactColor = generateColor(); + _numVertices = 0; + _verticesBuffer.reset(new gpu::Buffer()); + int vertexIndex = 0; + for (int i = 0; i < _normals.size(); i++) { + compactColor = generateColor(); + _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex)); + vertexIndex++; + _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i)); + _verticesBuffer->append(sizeof(int), (gpu::Byte*)&_color); + + _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex)); + vertexIndex++; + _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i)); + _verticesBuffer->append(sizeof(int), (gpu::Byte*)_color); + + _numVertices +=2; + } + _pointsChanged = false; } _pointsChanged = false; } void RenderablePolyLineEntityItem::render(RenderArgs* args) { + QWriteLocker lock(&_quadReadWriteLock); if (_points.size() < 2 || _vertices.size() != _normals.size() * 2) { return; } diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index fb01f341a7..66aa84b1a6 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -46,7 +46,7 @@ _strokeWidths(QVector(0)) } EntityItemProperties PolyLineEntityItem::getProperties() const { - _quadReadWriteLock.lockForWrite(); + QWriteLocker lock(&_quadReadWriteLock); EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class @@ -67,7 +67,7 @@ EntityItemProperties PolyLineEntityItem::getProperties() const { } bool PolyLineEntityItem::setProperties(const EntityItemProperties& properties) { - _quadReadWriteLock.lockForWrite(); + QWriteLocker lock(&_quadReadWriteLock); bool somethingChanged = false; somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class @@ -121,7 +121,7 @@ bool PolyLineEntityItem::setNormals(const QVector& normals) { } _normals = normals; _vertices.clear(); - //Go through and create vertices for triangle strip based on normals + //Go through and create vertices for triangle strip based on normalsa if (_normals.size() != _points.size()) { return false; } @@ -130,8 +130,18 @@ bool PolyLineEntityItem::setNormals(const QVector& normals) { float width = _strokeWidths.at(i); point = _points.at(i); //Get tangent + tangent = _points.at(i+1) - point; - binormal = glm::normalize(glm::cross(tangent, normals.at(i))) * width; + glm::vec3 normal = normals.at(i); +// qDebug() << "next point" << _points.at(i+1) << "cur point" << point; + binormal = glm::normalize(glm::cross(tangent, normal)) * _lineWidth; +// qDebug() << "glm cross" << glm::cross(tangent, normal); +// qDebug()<< "binormal" << binormal; +// qDebug() <<"dot " << glm::dot(tangent, normals.at(i)); + + if(binormal.x != binormal.x) { + + } v1 = point + binormal; v2 = point - binormal; _vertices << v1 << v2; @@ -219,6 +229,7 @@ void PolyLineEntityItem::appendSubclassData(OctreePacketData* packetData, Encode int& propertyCount, OctreeElement::AppendState& appendState) const { + QWriteLocker lock(&_quadReadWriteLock); bool successPropertyFits = true; APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor());