From 3e2a1c98fb0b4a1bc3c917557ed1e966d6a4530f Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Wed, 12 May 2021 16:29:00 +0200 Subject: [PATCH] Add property to change the number of lines connecting the prism shape --- .../solarsystem/missions/jwst/jwst.asset | 2 +- modules/base/rendering/renderableprism.cpp | 52 +++++++++++++++++-- modules/base/rendering/renderableprism.h | 1 + 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/data/assets/scene/solarsystem/missions/jwst/jwst.asset b/data/assets/scene/solarsystem/missions/jwst/jwst.asset index 5fe17877d5..72341a5105 100644 --- a/data/assets/scene/solarsystem/missions/jwst/jwst.asset +++ b/data/assets/scene/solarsystem/missions/jwst/jwst.asset @@ -92,8 +92,8 @@ local JWSTFov = { Renderable = { Type = "RenderablePrism", Segments = 6, + Lines = 3, Radius = 3.25, - Lines = 7, LineWidth = 1.0, Color = { 1.0, 1.0, 1.0 diff --git a/modules/base/rendering/renderableprism.cpp b/modules/base/rendering/renderableprism.cpp index 9f28032bd7..8e8b6b0f8d 100644 --- a/modules/base/rendering/renderableprism.cpp +++ b/modules/base/rendering/renderableprism.cpp @@ -51,6 +51,12 @@ namespace { "The number of segments the shape of the prism should have." }; + constexpr openspace::properties::Property::PropertyInfo LinesInfo = { + "NumLines", + "Number of Lines", + "The number of lines connecting the two shapes of the prism." + }; + static const openspace::properties::Property::PropertyInfo RadiusInfo = { "Radius", "Radius", @@ -91,6 +97,9 @@ namespace { // [[codegen::verbatim(SegmentsInfo.description)]] int segments; + // [[codegen::verbatim(LinesInfo.description)]] + std::optional lines; + // [[codegen::verbatim(RadiusInfo.description)]] std::optional radius; @@ -117,6 +126,7 @@ documentation::Documentation RenderablePrism::Documentation() { RenderablePrism::RenderablePrism(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _nShapeSegments(SegmentsInfo, 6, 3, 32) + , _nLines(LinesInfo, 6, 0, 32) , _radius(RadiusInfo, 10.f, 0.f, 3.0e12f) , _lineWidth(LineWidthInfo, 1.f, 1.f, 20.f) , _lineColor(LineColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) @@ -130,16 +140,19 @@ RenderablePrism::RenderablePrism(const ghoul::Dictionary& dictionary) _length.setViewOption(properties::Property::ViewOptions::Logarithmic); _nShapeSegments.onChange([&]() { _prismIsDirty = true; }); + _nLines.onChange([&]() { _prismIsDirty = true; }); _radius.onChange([&]() { _prismIsDirty = true; }); _length.onChange([&]() { _prismIsDirty = true; }); _nShapeSegments = p.segments; + _nLines = p.lines.value_or(_nShapeSegments); _radius = p.radius.value_or(_radius); _lineWidth = p.lineWidth.value_or(_lineWidth); _lineColor = p.color.value_or(_lineColor); _length = p.length.value_or(_length); addProperty(_nShapeSegments); + addProperty(_nLines); addProperty(_radius); addProperty(_lineWidth); addProperty(_lineColor); @@ -192,8 +205,11 @@ void RenderablePrism::updateVertexData() { // Get unit circle vertices on the XY-plane std::vector unitVertices; + std::vector unitVerticesLines; unitVertices.reserve(2 * _nShapeSegments); + unitVerticesLines.reserve(2 * _nLines); getUnitCircleVertices(unitVertices, _nShapeSegments); + getUnitCircleVertices(unitVerticesLines, _nLines); // Put base and top shape vertices into array for (int i = 0; i < 2; ++i) { @@ -209,6 +225,36 @@ void RenderablePrism::updateVertexData() { } } + // Put the vertices for the connecting lines into array + if (_nLines == 1) { + // In the case of just one line then connect the center points instead + // Center for base shape + _vertexArray.push_back(0.f); + _vertexArray.push_back(0.f); + _vertexArray.push_back(0.f); + + // Center for top shape + _vertexArray.push_back(0.f); + _vertexArray.push_back(0.f); + _vertexArray.push_back(_length); + } + else { + for (int j = 0, k = 0; j < _nLines && k < unitVerticesLines.size(); ++j) { + float ux = unitVerticesLines[k++]; + float uy = unitVerticesLines[k++]; + + // Base + _vertexArray.push_back(ux * _radius); // x + _vertexArray.push_back(uy * _radius); // y + _vertexArray.push_back(0.f); // z + + // Top + _vertexArray.push_back(ux * _radius); // x + _vertexArray.push_back(uy * _radius); // y + _vertexArray.push_back(_length); // z + } + } + // Indices for Base shape for (uint8_t i = 0; i < _nShapeSegments; ++i) { _indexArray.push_back(i); @@ -223,12 +269,12 @@ void RenderablePrism::updateVertexData() { } // Indices for connecting lines - for (uint8_t i = 0; i < _nShapeSegments; ++i) { + for (int i = 0, k = 0; i < _nLines; ++i) { // Reset _indexArray.push_back(255); - _indexArray.push_back(i); - _indexArray.push_back(i + _nShapeSegments); + _indexArray.push_back(2 * _nShapeSegments + k++); + _indexArray.push_back(2 * _nShapeSegments + k++); } } diff --git a/modules/base/rendering/renderableprism.h b/modules/base/rendering/renderableprism.h index 0cc0b199a1..094ae2b325 100644 --- a/modules/base/rendering/renderableprism.h +++ b/modules/base/rendering/renderableprism.h @@ -62,6 +62,7 @@ private: // Properties properties::IntProperty _nShapeSegments; + properties::IntProperty _nLines; properties::FloatProperty _radius; properties::FloatProperty _lineWidth; properties::Vec3Property _lineColor;