Merge pull request #6465 from ericrius1/polyLineFix

moved logic to build vertex buffer to renderable polyline class, recalculati…
This commit is contained in:
Clément Brisset 2015-11-25 11:02:02 -08:00
commit 5ff482071e
5 changed files with 56 additions and 41 deletions

View file

@ -247,4 +247,4 @@ function cleanup() {
// Uncomment this line to delete whiteboard and all associated entity on script close
// Script.scriptEnding.connect(cleanup);
//Script.scriptEnding.connect(cleanup);

View file

@ -31,6 +31,7 @@ EntityItemPointer RenderablePolyLineEntityItem::factory(const EntityItemID& enti
RenderablePolyLineEntityItem::RenderablePolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
PolyLineEntityItem(entityItemID, properties) {
_numVertices = 0;
_vertices = QVector<glm::vec3>(0.0f);
}
@ -114,13 +115,56 @@ void RenderablePolyLineEntityItem::updateGeometry() {
_numVertices += 2;
}
_pointsChanged = false;
_normalsChanged = false;
_strokeWidthsChanged = false;
}
void RenderablePolyLineEntityItem::updateVertices() {
// Calculate the minimum vector size out of normals, points, and stroke widths
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;
int finalIndex = minVectorSize - 1;
for (int i = 0; i < finalIndex; i++) {
float width = _strokeWidths.at(i);
point = _points.at(i);
tangent = _points.at(i);
tangent = _points.at(i + 1) - point;
glm::vec3 normal = _normals.at(i);
binormal = glm::normalize(glm::cross(tangent, normal)) * width;
// Check to make sure binormal is not a NAN. If it is, don't add to vertices vector
if (binormal.x != binormal.x) {
continue;
}
v1 = point + binormal;
v2 = point - binormal;
_vertices << v1 << v2;
}
// For last point we can assume binormals are the same since it represents the last two vertices of quad
point = _points.at(finalIndex);
v1 = point + binormal;
v2 = point - binormal;
_vertices << v1 << v2;
}
void RenderablePolyLineEntityItem::render(RenderArgs* args) {
QWriteLocker lock(&_quadReadWriteLock);
if (_points.size() < 2 || _normals.size () < 2 || _vertices.size() < 2) {
if (_points.size() < 2 || _normals.size () < 2 || _strokeWidths.size() < 2) {
return;
}
@ -139,7 +183,8 @@ void RenderablePolyLineEntityItem::render(RenderArgs* args) {
Q_ASSERT(getType() == EntityTypes::PolyLine);
Q_ASSERT(args->_batch);
if (_pointsChanged) {
if (_pointsChanged || _strokeWidthsChanged || _normalsChanged) {
updateVertices();
updateGeometry();
}

View file

@ -40,8 +40,10 @@ public:
protected:
void updateGeometry();
void updateVertices();
gpu::BufferPointer _verticesBuffer;
unsigned int _numVertices;
QVector<glm::vec3> _vertices;
};

View file

@ -34,8 +34,9 @@ PolyLineEntityItem::PolyLineEntityItem(const EntityItemID& entityItemID, const E
EntityItem(entityItemID),
_lineWidth(DEFAULT_LINE_WIDTH),
_pointsChanged(true),
_normalsChanged(true),
_strokeWidthsChanged(true),
_points(QVector<glm::vec3>(0.0f)),
_vertices(QVector<glm::vec3>(0.0f)),
_normals(QVector<glm::vec3>(0.0f)),
_strokeWidths(QVector<float>(0.0f)),
_textures("")
@ -106,47 +107,13 @@ bool PolyLineEntityItem::appendPoint(const glm::vec3& point) {
bool PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths) {
_strokeWidths = strokeWidths;
_strokeWidthsChanged = true;
return true;
}
bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
_normals = normals;
if (_points.size() < 2 || _normals.size() < 2 || _strokeWidths.size() < 2) {
return false;
}
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;
int finalIndex = minVectorSize -1;
for (int i = 0; i < finalIndex; 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(finalIndex);
v1 = point + binormal;
v2 = point - binormal;
_vertices << v1 << v2;
_normalsChanged = true;
return true;
}

View file

@ -93,8 +93,9 @@ class PolyLineEntityItem : public EntityItem {
rgbColor _color;
float _lineWidth;
bool _pointsChanged;
bool _normalsChanged;
bool _strokeWidthsChanged;
QVector<glm::vec3> _points;
QVector<glm::vec3> _vertices;
QVector<glm::vec3> _normals;
QVector<float> _strokeWidths;
QString _textures;