mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
Fix the scaling of renderablemodel by making the magnification a floatproperty
This commit is contained in:
2
data
2
data
Submodule data updated: 3860dfdac4...fa00aaa0c2
@@ -66,6 +66,7 @@ ModelGeometry* ModelGeometry::createFromDictionary(const ghoul::Dictionary& dict
|
||||
|
||||
ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary)
|
||||
: _parent(nullptr)
|
||||
, _magnification("magnification", "Magnification", 0.f, 0.f, 10.f)
|
||||
, _mode(GL_TRIANGLES)
|
||||
{
|
||||
setName("ModelGeometry");
|
||||
@@ -74,9 +75,8 @@ ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary)
|
||||
bool success = dictionary.getValue(keyName, name);
|
||||
ghoul_assert(success, "Name tag was not present");
|
||||
|
||||
success = dictionary.getValue(keySize, _magnification);
|
||||
if (!success)
|
||||
_magnification = 0; // if not set, models will be 1:1 (earlier 1:1000) @AA
|
||||
if (dictionary.hasKeyAndValue<double>(keySize))
|
||||
_magnification = static_cast<float>(dictionary.value<double>(keySize));
|
||||
|
||||
success = dictionary.getValue(keyObjFile, _file);
|
||||
if (!success) {
|
||||
@@ -88,6 +88,8 @@ ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary)
|
||||
if (!FileSys.fileExists(_file, true))
|
||||
LERROR("Could not load OBJ file '" << _file << "': File not found");
|
||||
|
||||
|
||||
addProperty(_magnification);
|
||||
}
|
||||
|
||||
ModelGeometry::~ModelGeometry() {
|
||||
@@ -246,5 +248,9 @@ bool ModelGeometry::getIndices(std::vector<int>* indexList) {
|
||||
return !(indexList->empty());
|
||||
}
|
||||
|
||||
void ModelGeometry::setUniforms(ghoul::opengl::ProgramObject& program) {
|
||||
program.setUniform("_magnification", _magnification);
|
||||
}
|
||||
|
||||
} // namespace modelgeometry
|
||||
} // namespace openspace
|
||||
|
||||
@@ -26,52 +26,56 @@
|
||||
#define __MODELGEOMETRY_H__
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <openspace/properties/scalarproperty.h>
|
||||
#include <modules/base/rendering/renderablemodel.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace modelgeometry {
|
||||
namespace modelgeometry {
|
||||
|
||||
class ModelGeometry : public properties::PropertyOwner {
|
||||
public:
|
||||
static ModelGeometry* createFromDictionary(const ghoul::Dictionary& dictionary);
|
||||
class ModelGeometry : public properties::PropertyOwner {
|
||||
public:
|
||||
static ModelGeometry* createFromDictionary(const ghoul::Dictionary& dictionary);
|
||||
|
||||
struct Vertex {
|
||||
GLfloat location[4];
|
||||
GLfloat tex[2];
|
||||
GLfloat normal[3];
|
||||
};
|
||||
struct Vertex {
|
||||
GLfloat location[4];
|
||||
GLfloat tex[2];
|
||||
GLfloat normal[3];
|
||||
};
|
||||
|
||||
ModelGeometry(const ghoul::Dictionary& dictionary);
|
||||
virtual ~ModelGeometry();
|
||||
virtual bool initialize(Renderable* parent);
|
||||
virtual void deinitialize();
|
||||
void render();
|
||||
virtual bool loadModel(const std::string& filename) = 0;
|
||||
void changeRenderMode(const GLenum mode);
|
||||
bool getVertices(std::vector<Vertex>* vertexList);
|
||||
bool getIndices(std::vector<int>* indexList);
|
||||
ModelGeometry(const ghoul::Dictionary& dictionary);
|
||||
virtual ~ModelGeometry();
|
||||
virtual bool initialize(Renderable* parent);
|
||||
virtual void deinitialize();
|
||||
void render();
|
||||
virtual bool loadModel(const std::string& filename) = 0;
|
||||
void changeRenderMode(const GLenum mode);
|
||||
bool getVertices(std::vector<Vertex>* vertexList);
|
||||
bool getIndices(std::vector<int>* indexList);
|
||||
|
||||
protected:
|
||||
Renderable* _parent;
|
||||
virtual void setUniforms(ghoul::opengl::ProgramObject& program);
|
||||
|
||||
bool loadObj(const std::string& filename);
|
||||
bool loadCachedFile(const std::string& filename);
|
||||
bool saveCachedFile(const std::string& filename);
|
||||
float _magnification;
|
||||
protected:
|
||||
Renderable* _parent;
|
||||
|
||||
GLuint _vaoID;
|
||||
GLuint _vbo;
|
||||
GLuint _ibo;
|
||||
GLenum _mode;
|
||||
bool loadObj(const std::string& filename);
|
||||
bool loadCachedFile(const std::string& filename);
|
||||
bool saveCachedFile(const std::string& filename);
|
||||
properties::FloatProperty _magnification;
|
||||
|
||||
std::vector<Vertex> _vertices;
|
||||
std::vector<int> _indices;
|
||||
std::string _file;
|
||||
};
|
||||
GLuint _vaoID;
|
||||
GLuint _vbo;
|
||||
GLuint _ibo;
|
||||
GLenum _mode;
|
||||
|
||||
} // namespace modelgeometry
|
||||
std::vector<Vertex> _vertices;
|
||||
std::vector<int> _indices;
|
||||
std::string _file;
|
||||
};
|
||||
|
||||
} // namespace modelgeometry
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __MODELGEOMETRY_H__
|
||||
|
||||
@@ -196,6 +196,8 @@ void RenderableModel::render(const RenderData& data) {
|
||||
|
||||
_programObject->setUniform("_performShading", _performShading);
|
||||
|
||||
_geometry->setUniforms(*_programObject);
|
||||
|
||||
if (_performFade && _fading > 0.f){
|
||||
_fading = _fading - 0.01f;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ bool WavefrontGeometry::loadModel(const std::string& filename) {
|
||||
_vertices[j + currentPosition].location[0] = tmp[0];
|
||||
_vertices[j + currentPosition].location[1] = tmp[1];
|
||||
_vertices[j + currentPosition].location[2] = tmp[2];
|
||||
_vertices[j + currentPosition].location[3] = tmp[3] + _magnification;
|
||||
_vertices[j + currentPosition].location[3] = tmp[3];
|
||||
|
||||
_vertices[j + currentPosition].normal[0] = shapes[i].mesh.normals[3 * j + 0];
|
||||
_vertices[j + currentPosition].normal[1] = shapes[i].mesh.normals[3 * j + 1];
|
||||
|
||||
@@ -29,23 +29,23 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RenderableModel;
|
||||
class RenderableModelProjection;
|
||||
class RenderableModel;
|
||||
class RenderableModelProjection;
|
||||
|
||||
namespace modelgeometry {
|
||||
namespace modelgeometry {
|
||||
|
||||
class WavefrontGeometry : public ModelGeometry {
|
||||
public:
|
||||
WavefrontGeometry(const ghoul::Dictionary& dictionary);
|
||||
class WavefrontGeometry : public ModelGeometry {
|
||||
public:
|
||||
WavefrontGeometry(const ghoul::Dictionary& dictionary);
|
||||
|
||||
bool initialize(Renderable* parent) override;
|
||||
void deinitialize() override;
|
||||
bool initialize(Renderable* parent) override;
|
||||
void deinitialize() override;
|
||||
|
||||
private:
|
||||
bool loadModel(const std::string& filename);
|
||||
};
|
||||
private:
|
||||
bool loadModel(const std::string& filename);
|
||||
};
|
||||
|
||||
} // namespace modelgeometry
|
||||
} // namespace modelgeometry
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __WAVEFRONTOBJECT_H__
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
|
||||
uniform float _magnification;
|
||||
|
||||
layout(location = 0) in vec4 in_position;
|
||||
//in vec3 in_position;
|
||||
layout(location = 1) in vec2 in_st;
|
||||
@@ -39,13 +41,15 @@ out float s;
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
void main()
|
||||
{
|
||||
void main() {
|
||||
vec4 pos = in_position;
|
||||
pos.w += _magnification;
|
||||
|
||||
// set variables
|
||||
vs_st = in_st;
|
||||
//vs_stp = in_position.xyz;
|
||||
vs_position = in_position;
|
||||
vec4 tmp = in_position;
|
||||
vs_position = pos;
|
||||
vec4 tmp = pos;
|
||||
|
||||
// this is wrong for the normal. The normal transform is the transposed inverse of the model transform
|
||||
vs_normal = normalize(ModelTransform * vec4(in_normal,0));
|
||||
|
||||
@@ -34,26 +34,29 @@ layout(location = 2) in vec3 in_normal;
|
||||
|
||||
uniform vec3 boresight;
|
||||
|
||||
uniform float _magnification;
|
||||
|
||||
out vec2 vs_st;
|
||||
out vec4 vs_normal;
|
||||
out vec4 vs_position;
|
||||
out float s;
|
||||
|
||||
|
||||
out vec4 ProjTexCoord;
|
||||
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
void main(){
|
||||
void main() {
|
||||
vec4 pos = in_position;
|
||||
pos.w += _magnification;
|
||||
|
||||
vs_st = in_st;
|
||||
vs_position = in_position;
|
||||
vec4 tmp = in_position;
|
||||
//tmp[3] += _magnification for runtime alteration of model size @AA
|
||||
vs_position = pos;
|
||||
vec4 tmp = pos;
|
||||
|
||||
vs_normal = normalize(ModelTransform * vec4(in_normal,0));
|
||||
vec4 position = pscTransform(tmp, ModelTransform);
|
||||
vs_position = tmp;
|
||||
|
||||
vec4 raw_pos = psc_to_meter(in_position, scaling);
|
||||
vec4 raw_pos = psc_to_meter(pos, scaling);
|
||||
ProjTexCoord = ProjectorMatrix * ModelTransform * raw_pos;
|
||||
position = ViewProjection * position;
|
||||
gl_Position = z_normalization(position);
|
||||
|
||||
Reference in New Issue
Block a user