mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 10:07:58 +02:00
Merge pull request #6465 from ericrius1/polyLineFix
moved logic to build vertex buffer to renderable polyline class, recalculati…
This commit is contained in:
commit
5ff482071e
5 changed files with 56 additions and 41 deletions
|
@ -247,4 +247,4 @@ function cleanup() {
|
||||||
|
|
||||||
|
|
||||||
// Uncomment this line to delete whiteboard and all associated entity on script close
|
// Uncomment this line to delete whiteboard and all associated entity on script close
|
||||||
// Script.scriptEnding.connect(cleanup);
|
//Script.scriptEnding.connect(cleanup);
|
||||||
|
|
|
@ -31,6 +31,7 @@ EntityItemPointer RenderablePolyLineEntityItem::factory(const EntityItemID& enti
|
||||||
RenderablePolyLineEntityItem::RenderablePolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
RenderablePolyLineEntityItem::RenderablePolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
||||||
PolyLineEntityItem(entityItemID, properties) {
|
PolyLineEntityItem(entityItemID, properties) {
|
||||||
_numVertices = 0;
|
_numVertices = 0;
|
||||||
|
_vertices = QVector<glm::vec3>(0.0f);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,13 +115,56 @@ void RenderablePolyLineEntityItem::updateGeometry() {
|
||||||
_numVertices += 2;
|
_numVertices += 2;
|
||||||
}
|
}
|
||||||
_pointsChanged = false;
|
_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) {
|
void RenderablePolyLineEntityItem::render(RenderArgs* args) {
|
||||||
QWriteLocker lock(&_quadReadWriteLock);
|
QWriteLocker lock(&_quadReadWriteLock);
|
||||||
if (_points.size() < 2 || _normals.size () < 2 || _vertices.size() < 2) {
|
if (_points.size() < 2 || _normals.size () < 2 || _strokeWidths.size() < 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +183,8 @@ void RenderablePolyLineEntityItem::render(RenderArgs* args) {
|
||||||
Q_ASSERT(getType() == EntityTypes::PolyLine);
|
Q_ASSERT(getType() == EntityTypes::PolyLine);
|
||||||
|
|
||||||
Q_ASSERT(args->_batch);
|
Q_ASSERT(args->_batch);
|
||||||
if (_pointsChanged) {
|
if (_pointsChanged || _strokeWidthsChanged || _normalsChanged) {
|
||||||
|
updateVertices();
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,10 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateGeometry();
|
void updateGeometry();
|
||||||
|
void updateVertices();
|
||||||
gpu::BufferPointer _verticesBuffer;
|
gpu::BufferPointer _verticesBuffer;
|
||||||
unsigned int _numVertices;
|
unsigned int _numVertices;
|
||||||
|
QVector<glm::vec3> _vertices;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,9 @@ PolyLineEntityItem::PolyLineEntityItem(const EntityItemID& entityItemID, const E
|
||||||
EntityItem(entityItemID),
|
EntityItem(entityItemID),
|
||||||
_lineWidth(DEFAULT_LINE_WIDTH),
|
_lineWidth(DEFAULT_LINE_WIDTH),
|
||||||
_pointsChanged(true),
|
_pointsChanged(true),
|
||||||
|
_normalsChanged(true),
|
||||||
|
_strokeWidthsChanged(true),
|
||||||
_points(QVector<glm::vec3>(0.0f)),
|
_points(QVector<glm::vec3>(0.0f)),
|
||||||
_vertices(QVector<glm::vec3>(0.0f)),
|
|
||||||
_normals(QVector<glm::vec3>(0.0f)),
|
_normals(QVector<glm::vec3>(0.0f)),
|
||||||
_strokeWidths(QVector<float>(0.0f)),
|
_strokeWidths(QVector<float>(0.0f)),
|
||||||
_textures("")
|
_textures("")
|
||||||
|
@ -106,47 +107,13 @@ bool PolyLineEntityItem::appendPoint(const glm::vec3& point) {
|
||||||
|
|
||||||
bool PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths) {
|
bool PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths) {
|
||||||
_strokeWidths = strokeWidths;
|
_strokeWidths = strokeWidths;
|
||||||
|
_strokeWidthsChanged = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
|
bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
|
||||||
_normals = normals;
|
_normals = normals;
|
||||||
if (_points.size() < 2 || _normals.size() < 2 || _strokeWidths.size() < 2) {
|
_normalsChanged = true;
|
||||||
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;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,8 +93,9 @@ class PolyLineEntityItem : public EntityItem {
|
||||||
rgbColor _color;
|
rgbColor _color;
|
||||||
float _lineWidth;
|
float _lineWidth;
|
||||||
bool _pointsChanged;
|
bool _pointsChanged;
|
||||||
|
bool _normalsChanged;
|
||||||
|
bool _strokeWidthsChanged;
|
||||||
QVector<glm::vec3> _points;
|
QVector<glm::vec3> _points;
|
||||||
QVector<glm::vec3> _vertices;
|
|
||||||
QVector<glm::vec3> _normals;
|
QVector<glm::vec3> _normals;
|
||||||
QVector<float> _strokeWidths;
|
QVector<float> _strokeWidths;
|
||||||
QString _textures;
|
QString _textures;
|
||||||
|
|
Loading…
Reference in a new issue