mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 12:57:59 +02:00
More work on metavoxel editing (grid, etc.)
This commit is contained in:
parent
9f10a9b2c9
commit
0a3d6ae5e0
5 changed files with 114 additions and 0 deletions
13
interface/resources/shaders/grid.frag
Normal file
13
interface/resources/shaders/grid.frag
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
//
|
||||||
|
// grid.frag
|
||||||
|
// fragment shader
|
||||||
|
//
|
||||||
|
// Created by Andrzej Kapolka on 1/21/14.
|
||||||
|
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
gl_FragColor = vec4(gl_Color.rgb, exp(-0.25 / gl_FragCoord.w));
|
||||||
|
}
|
|
@ -7,7 +7,11 @@
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
// include this before QOpenGLBuffer, which includes an earlier version of OpenGL
|
||||||
|
#include "InterfaceConfig.h"
|
||||||
|
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
#include <QOpenGLBuffer>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "GeometryCache.h"
|
#include "GeometryCache.h"
|
||||||
|
@ -241,6 +245,50 @@ void GeometryCache::renderHalfCylinder(int slices, int stacks) {
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeometryCache::renderGrid(int xDivisions, int yDivisions) {
|
||||||
|
QOpenGLBuffer& buffer = _gridBuffers[IntPair(xDivisions, yDivisions)];
|
||||||
|
int vertices = (xDivisions + 1 + yDivisions + 1) * 2;
|
||||||
|
if (!buffer.isCreated()) {
|
||||||
|
GLfloat* vertexData = new GLfloat[vertices * 2];
|
||||||
|
GLfloat* vertex = vertexData;
|
||||||
|
for (int i = 0; i <= xDivisions; i++) {
|
||||||
|
float x = (float)i / xDivisions;
|
||||||
|
|
||||||
|
*(vertex++) = x;
|
||||||
|
*(vertex++) = 0.0f;
|
||||||
|
|
||||||
|
*(vertex++) = x;
|
||||||
|
*(vertex++) = 1.0f;
|
||||||
|
}
|
||||||
|
for (int i = 0; i <= yDivisions; i++) {
|
||||||
|
float y = (float)i / yDivisions;
|
||||||
|
|
||||||
|
*(vertex++) = 0.0f;
|
||||||
|
*(vertex++) = y;
|
||||||
|
|
||||||
|
*(vertex++) = 1.0f;
|
||||||
|
*(vertex++) = y;
|
||||||
|
}
|
||||||
|
buffer.create();
|
||||||
|
buffer.setUsagePattern(QOpenGLBuffer::StaticDraw);
|
||||||
|
buffer.bind();
|
||||||
|
buffer.allocate(vertexData, vertices * 2 * sizeof(GLfloat));
|
||||||
|
delete[] vertexData;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
buffer.bind();
|
||||||
|
}
|
||||||
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
|
||||||
|
glVertexPointer(2, GL_FLOAT, 0, 0);
|
||||||
|
|
||||||
|
glDrawArrays(GL_LINES, 0, vertices);
|
||||||
|
|
||||||
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
|
||||||
|
buffer.release();
|
||||||
|
}
|
||||||
|
|
||||||
QSharedPointer<NetworkGeometry> GeometryCache::getGeometry(const QUrl& url) {
|
QSharedPointer<NetworkGeometry> GeometryCache::getGeometry(const QUrl& url) {
|
||||||
QSharedPointer<NetworkGeometry> geometry = _networkGeometry.value(url);
|
QSharedPointer<NetworkGeometry> geometry = _networkGeometry.value(url);
|
||||||
if (geometry.isNull()) {
|
if (geometry.isNull()) {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
|
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
class QOpenGLBuffer;
|
||||||
|
|
||||||
class NetworkGeometry;
|
class NetworkGeometry;
|
||||||
class NetworkMesh;
|
class NetworkMesh;
|
||||||
|
@ -33,6 +34,7 @@ public:
|
||||||
void renderHemisphere(int slices, int stacks);
|
void renderHemisphere(int slices, int stacks);
|
||||||
void renderSquare(int xDivisions, int yDivisions);
|
void renderSquare(int xDivisions, int yDivisions);
|
||||||
void renderHalfCylinder(int slices, int stacks);
|
void renderHalfCylinder(int slices, int stacks);
|
||||||
|
void renderGrid(int xDivisions, int yDivisions);
|
||||||
|
|
||||||
/// Loads geometry from the specified URL.
|
/// Loads geometry from the specified URL.
|
||||||
QSharedPointer<NetworkGeometry> getGeometry(const QUrl& url);
|
QSharedPointer<NetworkGeometry> getGeometry(const QUrl& url);
|
||||||
|
@ -45,6 +47,7 @@ private:
|
||||||
QHash<IntPair, VerticesIndices> _hemisphereVBOs;
|
QHash<IntPair, VerticesIndices> _hemisphereVBOs;
|
||||||
QHash<IntPair, VerticesIndices> _squareVBOs;
|
QHash<IntPair, VerticesIndices> _squareVBOs;
|
||||||
QHash<IntPair, VerticesIndices> _halfCylinderVBOs;
|
QHash<IntPair, VerticesIndices> _halfCylinderVBOs;
|
||||||
|
QHash<IntPair, QOpenGLBuffer> _gridBuffers;
|
||||||
|
|
||||||
QHash<QUrl, QWeakPointer<NetworkGeometry> > _networkGeometry;
|
QHash<QUrl, QWeakPointer<NetworkGeometry> > _networkGeometry;
|
||||||
};
|
};
|
||||||
|
|
|
@ -79,6 +79,13 @@ MetavoxelEditorDialog::MetavoxelEditorDialog() :
|
||||||
connect(Application::getInstance(), SIGNAL(renderingInWorldInterface()), SLOT(render()));
|
connect(Application::getInstance(), SIGNAL(renderingInWorldInterface()), SLOT(render()));
|
||||||
|
|
||||||
show();
|
show();
|
||||||
|
|
||||||
|
if (_gridProgram.isLinked()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switchToResourcesParentIfRequired();
|
||||||
|
_gridProgram.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/grid.frag");
|
||||||
|
_gridProgram.link();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetavoxelEditorDialog::updateValueEditor() {
|
void MetavoxelEditorDialog::updateValueEditor() {
|
||||||
|
@ -138,7 +145,44 @@ void MetavoxelEditorDialog::updateGridPosition() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetavoxelEditorDialog::render() {
|
void MetavoxelEditorDialog::render() {
|
||||||
|
const float GRID_BRIGHTNESS = 0.5f;
|
||||||
|
glColor3f(GRID_BRIGHTNESS, GRID_BRIGHTNESS, GRID_BRIGHTNESS);
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
|
||||||
|
glm::quat rotation;
|
||||||
|
switch (_gridPlane->currentIndex()) {
|
||||||
|
case GRID_PLANE_XZ:
|
||||||
|
rotation = glm::angleAxis(90.0f, 1.0f, 0.0f, 0.0f);
|
||||||
|
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GRID_PLANE_YZ:
|
||||||
|
rotation = glm::angleAxis(-90.0f, 0.0f, 1.0f, 0.0f);
|
||||||
|
glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// center the grid around the camera position on the plane
|
||||||
|
glm::vec3 rotated = rotation * Application::getInstance()->getCamera()->getPosition();
|
||||||
|
float spacing = _gridSpacing->value();
|
||||||
|
const int GRID_DIVISIONS = 300;
|
||||||
|
glTranslatef(spacing * (floor(rotated.x / spacing) - GRID_DIVISIONS / 2),
|
||||||
|
spacing * (floor(rotated.y / spacing) - GRID_DIVISIONS / 2), _gridPosition->value());
|
||||||
|
|
||||||
|
float scale = GRID_DIVISIONS * spacing;
|
||||||
|
glScalef(scale, scale, scale);
|
||||||
|
|
||||||
|
_gridProgram.bind();
|
||||||
|
|
||||||
|
Application::getInstance()->getGeometryCache()->renderGrid(GRID_DIVISIONS, GRID_DIVISIONS);
|
||||||
|
|
||||||
|
_gridProgram.release();
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetavoxelEditorDialog::updateAttributes(const QString& select) {
|
void MetavoxelEditorDialog::updateAttributes(const QString& select) {
|
||||||
|
@ -164,3 +208,5 @@ QString MetavoxelEditorDialog::getSelectedAttribute() const {
|
||||||
QList<QListWidgetItem*> selectedItems = _attributes->selectedItems();
|
QList<QListWidgetItem*> selectedItems = _attributes->selectedItems();
|
||||||
return selectedItems.isEmpty() ? QString() : selectedItems.first()->text();
|
return selectedItems.isEmpty() ? QString() : selectedItems.first()->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProgramObject MetavoxelEditorDialog::_gridProgram;
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
|
#include "renderer/ProgramObject.h"
|
||||||
|
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
class QDoubleSpinBox;
|
class QDoubleSpinBox;
|
||||||
class QGroupBox;
|
class QGroupBox;
|
||||||
|
@ -42,6 +44,8 @@ private:
|
||||||
QDoubleSpinBox* _gridSpacing;
|
QDoubleSpinBox* _gridSpacing;
|
||||||
QDoubleSpinBox* _gridPosition;
|
QDoubleSpinBox* _gridPosition;
|
||||||
QGroupBox* _value;
|
QGroupBox* _value;
|
||||||
|
|
||||||
|
static ProgramObject _gridProgram;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__interface__MetavoxelEditorDialog__) */
|
#endif /* defined(__interface__MetavoxelEditorDialog__) */
|
||||||
|
|
Loading…
Reference in a new issue