Feature/arrow renderable (#2219)

* Create a RenderableNodeLine example asset

* First version of node direction hint renderable (arrow)

* Add possibility to set length as a multiplier of the bounding sphere

* Draw arrow cylinder using index array

* Update exponents and min max values for lengths

* Draw arrow head

* Only update arrow geometry when positions change

* Add some properties to control visuals of arrow

* Implement invert option

* Add normals and shading

* Set arrow head size by length percentage instead of angle

* Add bottom circle to cone

* Cleanup and update examples

* Remove non-existing property from example asset

* Fix vertices not updating if anchor node was changed

And some missing updates on property change

* Start cleaning up some shape rendering helper functions

* Cleanup code and move cylinder function to helper class

* Refactor cylinder creation code (fewer loops over same vector)

* Update transformations to correctly scale and place arrow

* Add the cone to make the arrowhead

* Update faulty triangle normals

* Add property visibilities

* Rename NodeDirectionHint to NodeArrow

* Apply suggestions from code review

Co-authored-by: Alexander Bock <alexander.bock@liu.se>


---------

Co-authored-by: Alexander Bock <alexander.bock@liu.se>
This commit is contained in:
Emma Broman
2023-09-11 11:04:46 +02:00
committed by GitHub
parent 7bfedbdf12
commit d77836d910
11 changed files with 1176 additions and 58 deletions
+14 -34
View File
@@ -27,6 +27,7 @@
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/engine/globals.h>
#include <openspace/rendering/helper.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/filesystem/filesystem.h>
@@ -98,20 +99,6 @@ namespace {
openspace::properties::Property::Visibility::User
};
// Generate vertices around the unit circle on the XY-plane
std::vector<float> unitCircleVertices(int sectorCount) {
std::vector<float> vertices;
vertices.reserve(2 * sectorCount);
float sectorStep = glm::two_pi<float>() / sectorCount;
for (int i = 0; i < sectorCount; ++i) {
float sectorAngle = i * sectorStep;
vertices.push_back(cos(sectorAngle)); // x
vertices.push_back(sin(sectorAngle)); // y
}
return vertices;
}
struct [[codegen::Dictionary(RenderablePrism)]] Parameters {
// [[codegen::verbatim(SegmentsInfo.description)]]
int segments;
@@ -236,17 +223,16 @@ void RenderablePrism::updateVertexData() {
_vertexArray.clear();
_indexArray.clear();
using namespace rendering::helper;
// Get unit circle vertices on the XY-plane
std::vector<float> unitVertices = unitCircleVertices(_nShapeSegments);
std::vector<float> unitVerticesLines = unitCircleVertices(_nLines);
std::vector<VertexXYZ> unitVertices = createRingXYZ(_nShapeSegments.value(), 1.f);
std::vector<VertexXYZ> unitVerticesLines = createRingXYZ(_nLines.value(), 1.f);
// Put base vertices into array
for (int j = 0, k = 0;
j < _nShapeSegments && k < static_cast<int>(unitVertices.size());
++j, k += 2)
{
float ux = unitVertices[k];
float uy = unitVertices[k + 1];
for (int j = 0; j < _nShapeSegments; ++j) {
float ux = unitVertices[j].xyz[0];
float uy = unitVertices[j].xyz[1];
_vertexArray.push_back(ux * _baseRadius); // x
_vertexArray.push_back(uy * _baseRadius); // y
@@ -254,12 +240,9 @@ void RenderablePrism::updateVertexData() {
}
// Put top shape vertices into array
for (int j = 0, k = 0;
j < _nShapeSegments && k < static_cast<int>(unitVertices.size());
++j, k += 2)
{
float ux = unitVertices[k];
float uy = unitVertices[k + 1];
for (int j = 0; j < _nShapeSegments; ++j) {
float ux = unitVertices[j].xyz[0];
float uy = unitVertices[j].xyz[1];
_vertexArray.push_back(ux * _radius); // x
_vertexArray.push_back(uy * _radius); // y
@@ -280,12 +263,9 @@ void RenderablePrism::updateVertexData() {
_vertexArray.push_back(_length);
}
else {
for (int j = 0, k = 0;
j < _nLines && k < static_cast<int>(unitVerticesLines.size());
++j, k += 2)
{
float ux = unitVerticesLines[k];
float uy = unitVerticesLines[k + 1];
for (int j = 0; j < _nLines; ++j) {
float ux = unitVerticesLines[j].xyz[0];
float uy = unitVerticesLines[j].xyz[1];
// Base
_vertexArray.push_back(ux * _baseRadius); // x