mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 03:29:44 -06:00
Add bounding spheres to a bunch of renderable types (#1957)
* RenderabeDUMeshes (And reimplement reading of vertex info from speck, to make it easier to compute sphere. The plan is to phase out this renderable anyways) * RenderablePoints * Grids: RenderableGrid, RenderableBoxGrid, RenderableRadialGrid & RenderableSphericalGrid * RenderableGalaxy
This commit is contained in:
@@ -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<double>(glm::length(urb)));
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
|
||||
glBufferData(
|
||||
|
||||
@@ -243,6 +243,8 @@ void RenderableGrid::update(const UpdateData&) {
|
||||
_varray[nr++] = { halfSize.x, y1, 0.f };
|
||||
}
|
||||
|
||||
setBoundingSphere(static_cast<double>(glm::length(halfSize)));
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
|
||||
glBufferData(
|
||||
|
||||
@@ -274,6 +274,8 @@ void RenderableRadialGrid::update(const UpdateData&) {
|
||||
}
|
||||
_lines.update();
|
||||
|
||||
setBoundingSphere(static_cast<double>(outerRadius));
|
||||
|
||||
_gridIsDirty = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -460,6 +460,9 @@ bool RenderableDUMeshes::readSpeckFile() {
|
||||
return false;
|
||||
}
|
||||
|
||||
const float scale = static_cast<float>(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<double>(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<const int, RenderingMesh>& p : _renderingMeshesMap) {
|
||||
float scale = static_cast<float>(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<GLvoid*>(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<GLvoid*>(sizeof(GLfloat) * i * p.second.numV)
|
||||
// );
|
||||
|
||||
// texture coords
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(
|
||||
1,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(GLfloat) * 7,
|
||||
reinterpret_cast<GLvoid*>(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<GLvoid*>(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<GLvoid*>(sizeof(GLfloat) * 3 * i * p.second.numV)
|
||||
);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
// Grid: we need columns
|
||||
|
||||
@@ -397,12 +397,17 @@ std::vector<double> 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<double> RenderablePoints::createDataSlice() {
|
||||
0 :
|
||||
colorIndex + 1;
|
||||
}
|
||||
setBoundingSphere(maxRadius);
|
||||
|
||||
return slice;
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtx/component_wise.hpp>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <optional>
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user