diff --git a/modules/base/rendering/grids/renderableboxgrid.cpp b/modules/base/rendering/grids/renderableboxgrid.cpp index 22ee194217..f79ea17fc9 100644 --- a/modules/base/rendering/grids/renderableboxgrid.cpp +++ b/modules/base/rendering/grids/renderableboxgrid.cpp @@ -235,6 +235,8 @@ void RenderableBoxGrid::update(const UpdateData&) { _varray.push_back({ v7.x, v7.y, v7.z }); _varray.push_back({ v3.x, v3.y, v3.z }); + setBoundingSphere(static_cast(glm::length(urb))); + glBindVertexArray(_vaoID); glBindBuffer(GL_ARRAY_BUFFER, _vBufferID); glBufferData( diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index 7af979a23e..3afdd6209d 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -243,6 +243,8 @@ void RenderableGrid::update(const UpdateData&) { _varray[nr++] = { halfSize.x, y1, 0.f }; } + setBoundingSphere(static_cast(glm::length(halfSize))); + glBindVertexArray(_vaoID); glBindBuffer(GL_ARRAY_BUFFER, _vBufferID); glBufferData( diff --git a/modules/base/rendering/grids/renderableradialgrid.cpp b/modules/base/rendering/grids/renderableradialgrid.cpp index 67454d91b7..e260af9626 100644 --- a/modules/base/rendering/grids/renderableradialgrid.cpp +++ b/modules/base/rendering/grids/renderableradialgrid.cpp @@ -274,6 +274,8 @@ void RenderableRadialGrid::update(const UpdateData&) { } _lines.update(); + setBoundingSphere(static_cast(outerRadius)); + _gridIsDirty = false; } diff --git a/modules/base/rendering/grids/renderablesphericalgrid.cpp b/modules/base/rendering/grids/renderablesphericalgrid.cpp index 8be264d66f..059cb6dac7 100644 --- a/modules/base/rendering/grids/renderablesphericalgrid.cpp +++ b/modules/base/rendering/grids/renderablesphericalgrid.cpp @@ -103,6 +103,9 @@ RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictio _lineWidth = p.lineWidth.value_or(_lineWidth); addProperty(_lineWidth); + + // Radius is always 1 + setBoundingSphere(1.0); } bool RenderableSphericalGrid::isReady() const { diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp index bbd77b824e..d39535e4f7 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.cpp +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -460,6 +460,9 @@ bool RenderableDUMeshes::readSpeckFile() { return false; } + const float scale = static_cast(toMeter(_unit)); + double maxRadius = 0.0; + int meshIndex = 0; // The beginning of the speck file has a header that either contains comments @@ -540,23 +543,55 @@ bool RenderableDUMeshes::readSpeckFile() { // We can now read the vertices data: for (int l = 0; l < mesh.numU * mesh.numV; ++l) { std::getline(file, line); - if (line.substr(0, 1) != "}") { - std::stringstream lineData(line); - for (int i = 0; i < 7; ++i) { - GLfloat value; - lineData >> value; - bool errorReading = lineData.rdstate() & std::ifstream::failbit; - if (!errorReading) { - mesh.vertices.push_back(value); - } - else { - break; - } - } - } - else { + if (line.substr(0, 1) == "}") { break; } + + std::stringstream lineData(line); + + // Try to read three values for the position + glm::vec3 pos; + bool success = true; + for (int i = 0; i < 3; ++i) { + GLfloat value; + lineData >> value; + bool errorReading = lineData.rdstate() & std::ifstream::failbit; + if (errorReading) { + success = false; + break; + } + + GLfloat scaledValue = value * scale; + pos[i] = scaledValue; + mesh.vertices.push_back(scaledValue); + } + + if (!success) { + LERROR(fmt::format( + "Failed reading position on line {} of mesh {} in file: '{}'. " + "Stopped reading mesh data", l, meshIndex, _speckFile + )); + break; + } + + // Check if new max radius + const double r = static_cast(glm::length(pos)); + maxRadius = std::max(maxRadius, r); + + // OLD CODE: + // (2022-03-23, emmbr) None of our files included texture coordinates, + // and if they would they would still not be used by the shader + //for (int i = 0; i < 7; ++i) { + // GLfloat value; + // lineData >> value; + // bool errorReading = lineData.rdstate() & std::ifstream::failbit; + // if (!errorReading) { + // mesh.vertices.push_back(value); + // } + // else { + // break; + // } + //} } std::getline(file, line); @@ -569,6 +604,8 @@ bool RenderableDUMeshes::readSpeckFile() { } } + setBoundingSphere(maxRadius); + return true; } @@ -579,12 +616,6 @@ void RenderableDUMeshes::createMeshes() { LDEBUG("Creating planes"); for (std::pair& p : _renderingMeshesMap) { - float scale = static_cast(toMeter(_unit)); - - for (GLfloat& v : p.second.vertices) { - v *= scale; - } - for (int i = 0; i < p.second.numU; ++i) { GLuint vao; glGenVertexArrays(1, &vao); @@ -605,29 +636,32 @@ void RenderableDUMeshes::createMeshes() { ); // in_position glEnableVertexAttribArray(0); - // U and V may not be given by the user - if (p.second.vertices.size() / (p.second.numU * p.second.numV) > 3) { - glVertexAttribPointer( - 0, - 3, - GL_FLOAT, - GL_FALSE, - sizeof(GLfloat) * 5, - reinterpret_cast(sizeof(GLfloat) * i * p.second.numV) - ); + // (2022-03-23, emmbr) This code was actually never used. We only read three + // values per line and di not handle any texture cooridnates, even if there + // would have been some in the file + //// U and V may not be given by the user + //if (p.second.vertices.size() / (p.second.numU * p.second.numV) > 3) { + // glVertexAttribPointer( + // 0, + // 3, + // GL_FLOAT, + // GL_FALSE, + // sizeof(GLfloat) * 5, + // reinterpret_cast(sizeof(GLfloat) * i * p.second.numV) + // ); - // texture coords - glEnableVertexAttribArray(1); - glVertexAttribPointer( - 1, - 2, - GL_FLOAT, - GL_FALSE, - sizeof(GLfloat) * 7, - reinterpret_cast(sizeof(GLfloat) * 3 * i * p.second.numV) - ); - } - else { // no U and V: + // // texture coords + // glEnableVertexAttribArray(1); + // glVertexAttribPointer( + // 1, + // 2, + // GL_FLOAT, + // GL_FALSE, + // sizeof(GLfloat) * 7, + // reinterpret_cast(sizeof(GLfloat) * 3 * i * p.second.numV) + // ); + //} + //else { // no U and V: glVertexAttribPointer( 0, 3, @@ -636,7 +670,7 @@ void RenderableDUMeshes::createMeshes() { 0, reinterpret_cast(sizeof(GLfloat) * 3 * i * p.second.numV) ); - } + //} } // Grid: we need columns diff --git a/modules/digitaluniverse/rendering/renderablepoints.cpp b/modules/digitaluniverse/rendering/renderablepoints.cpp index d94ad66e88..b1f36dd249 100644 --- a/modules/digitaluniverse/rendering/renderablepoints.cpp +++ b/modules/digitaluniverse/rendering/renderablepoints.cpp @@ -397,12 +397,17 @@ std::vector RenderablePoints::createDataSlice() { slice.reserve(4 * _dataset.entries.size()); } + double maxRadius = 0.0; + int colorIndex = 0; for (const speck::Dataset::Entry& e : _dataset.entries) { glm::dvec3 p = e.position; double scale = toMeter(_unit); p *= scale; + const double r = glm::length(p); + maxRadius = std::max(maxRadius, r); + glm::dvec4 position(p, 1.0); if (_hasColorMapFile) { @@ -423,6 +428,7 @@ std::vector RenderablePoints::createDataSlice() { 0 : colorIndex + 1; } + setBoundingSphere(maxRadius); return slice; } diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index 891270155b..bfe86b1871 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -318,6 +319,10 @@ RenderableGalaxy::RenderableGalaxy(const ghoul::Dictionary& dictionary) _downScaleVolumeRendering.setVisibility(properties::Property::Visibility::Developer); addProperty(_downScaleVolumeRendering); addProperty(_numberOfRayCastingSteps); + + // Use max component instead of length, to avoid problems with taking square + // of huge value + setBoundingSphere(glm::compMax(0.5f * _volumeSize)); } void RenderableGalaxy::initialize() {