mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 02:12:45 +01:00
Use new Clump structures in rwviewer + remove old renderer
This commit is contained in:
parent
d798509f93
commit
0a0be3c52a
@ -473,57 +473,6 @@ void GameRenderer::renderPostProcess() {
|
||||
renderer->drawArrays(glm::mat4(), &ssRectDraw, wdp);
|
||||
}
|
||||
|
||||
void GameRenderer::renderGeometry(Clump* model, size_t g,
|
||||
const glm::mat4& modelMatrix, float opacity,
|
||||
GameObject* object) {
|
||||
for (size_t sg = 0; sg < model->geometries[g]->subgeom.size(); ++sg) {
|
||||
SubGeometry& subgeom = model->geometries[g]->subgeom[sg];
|
||||
|
||||
Renderer::DrawParameters dp;
|
||||
|
||||
dp.colour = {255, 255, 255, 255};
|
||||
dp.count = subgeom.numIndices;
|
||||
dp.start = subgeom.start;
|
||||
dp.textures = {0};
|
||||
|
||||
if (model->geometries[g]->materials.size() > subgeom.material) {
|
||||
Geometry::Material& mat =
|
||||
model->geometries[g]->materials[subgeom.material];
|
||||
|
||||
if (mat.textures.size() > 0) {
|
||||
auto tex = mat.textures[0].texture;
|
||||
if (tex) {
|
||||
dp.textures = {tex->getName()};
|
||||
}
|
||||
}
|
||||
|
||||
if ((model->geometries[g]->flags &
|
||||
RW::BSGeometry::ModuleMaterialColor) ==
|
||||
RW::BSGeometry::ModuleMaterialColor) {
|
||||
dp.colour = mat.colour;
|
||||
|
||||
if (object && object->type() == GameObject::Vehicle) {
|
||||
auto vehicle = static_cast<VehicleObject*>(object);
|
||||
if (dp.colour.r == 60 && dp.colour.g == 255 &&
|
||||
dp.colour.b == 0) {
|
||||
dp.colour = glm::u8vec4(vehicle->colourPrimary, 255);
|
||||
} else if (dp.colour.r == 255 && dp.colour.g == 0 &&
|
||||
dp.colour.b == 175) {
|
||||
dp.colour = glm::u8vec4(vehicle->colourSecondary, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dp.colour.a *= opacity;
|
||||
|
||||
dp.diffuse = mat.diffuseIntensity;
|
||||
dp.ambient = mat.ambientIntensity;
|
||||
}
|
||||
|
||||
renderer->draw(modelMatrix, &model->geometries[g]->dbuff, dp);
|
||||
}
|
||||
}
|
||||
|
||||
void GameRenderer::renderEffects(GameWorld* world) {
|
||||
renderer->useProgram(particleProg);
|
||||
|
||||
@ -654,49 +603,6 @@ void GameRenderer::drawColour(const glm::vec4& colour, glm::vec4 extents) {
|
||||
renderer->invalidate();
|
||||
}
|
||||
|
||||
bool GameRenderer::renderFrame(Clump* m, ModelFrame* f, const glm::mat4& matrix,
|
||||
GameObject* object, float opacity,
|
||||
bool queueTransparent) {
|
||||
auto localmatrix = matrix;
|
||||
bool vis = true;
|
||||
|
||||
if (object && object->skeleton) {
|
||||
// Skeleton is loaded with the correct matrix via Animator.
|
||||
localmatrix *= object->skeleton->getMatrix(f);
|
||||
|
||||
vis = object->skeleton->getData(f->getIndex()).enabled;
|
||||
} else {
|
||||
localmatrix *= f->getTransform();
|
||||
}
|
||||
|
||||
if (vis) {
|
||||
for (size_t g : f->getGeometries()) {
|
||||
if (!object || !object->animator) {
|
||||
RW::BSGeometryBounds& bounds = m->geometries[g]->geometryBounds;
|
||||
|
||||
glm::vec3 boundpos = bounds.center + glm::vec3(localmatrix[3]);
|
||||
if (!_camera.frustum.intersects(boundpos, bounds.radius)) {
|
||||
culled++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
renderGeometry(m, g, localmatrix, opacity, object);
|
||||
}
|
||||
}
|
||||
|
||||
for (ModelFrame* c : f->getChildren()) {
|
||||
renderFrame(m, c, localmatrix, object, queueTransparent);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void GameRenderer::renderModel(Clump* model, const glm::mat4& modelMatrix,
|
||||
GameObject* object) {
|
||||
renderFrame(model, model->frames[model->rootFrameIdx], modelMatrix, object,
|
||||
1.f);
|
||||
}
|
||||
|
||||
void GameRenderer::renderPaths() {
|
||||
/*glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, debugTex);
|
||||
|
@ -51,30 +51,6 @@ class GameRenderer {
|
||||
/** The low-level drawing interface to use */
|
||||
Renderer* renderer;
|
||||
|
||||
/** Stores data for deferring transparent objects */
|
||||
struct RQueueEntry {
|
||||
Clump* model;
|
||||
size_t g;
|
||||
size_t sg;
|
||||
glm::mat4 matrix;
|
||||
Renderer::DrawParameters dp;
|
||||
GameObject* object;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief renders a model's frame.
|
||||
* @param m
|
||||
* @param f
|
||||
* @param matrix
|
||||
* @param object
|
||||
* @param queueTransparent abort the draw if the frame contains transparent
|
||||
* materials
|
||||
* @return True if the frame was drawn, false if it should be queued
|
||||
*/
|
||||
bool renderFrame(Clump* m, ModelFrame* f, const glm::mat4& matrix,
|
||||
GameObject* object, float opacity,
|
||||
bool queueTransparent = true);
|
||||
|
||||
// Temporary variables used during rendering
|
||||
float _renderAlpha;
|
||||
GameWorld* _renderWorld;
|
||||
@ -155,15 +131,6 @@ public:
|
||||
void drawTexture(TextureData* texture, glm::vec4 extents);
|
||||
void drawColour(const glm::vec4& colour, glm::vec4 extents);
|
||||
|
||||
/**
|
||||
* Renders a model (who'd have thought)
|
||||
*/
|
||||
void renderModel(Clump*, const glm::mat4& modelMatrix,
|
||||
GameObject* = nullptr);
|
||||
|
||||
void renderGeometry(Clump*, size_t geom, const glm::mat4& modelMatrix,
|
||||
float opacity, GameObject* = nullptr);
|
||||
|
||||
/** method for rendering AI debug information */
|
||||
void renderPaths();
|
||||
|
||||
|
@ -6,13 +6,13 @@
|
||||
#include <data/Skeleton.hpp>
|
||||
#include <engine/Animator.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <objects/GameObject.hpp>
|
||||
#include <render/GameRenderer.hpp>
|
||||
#include <render/OpenGLRenderer.hpp>
|
||||
|
||||
#include <objects/CharacterObject.hpp>
|
||||
#include <objects/GameObject.hpp>
|
||||
#include <objects/InstanceObject.hpp>
|
||||
#include <objects/VehicleObject.hpp>
|
||||
#include <render/GameRenderer.hpp>
|
||||
#include <render/ObjectRenderer.hpp>
|
||||
#include <render/OpenGLRenderer.hpp>
|
||||
|
||||
ViewerWidget::ViewerWidget(QGLFormat g, QWidget* parent,
|
||||
const QGLWidget* shareWidget, Qt::WindowFlags f)
|
||||
@ -113,10 +113,15 @@ void ViewerWidget::paintGL() {
|
||||
cos(viewAngles.x) * cos(viewAngles.y), sin(viewAngles.y));
|
||||
|
||||
if (model) {
|
||||
model->getFrame()->updateHierarchyTransform();
|
||||
|
||||
// Ensure camera is still accurate
|
||||
vc.position = eye * viewDistance;
|
||||
glm::mat4 proj = vc.frustum.projection();
|
||||
glm::mat4 view =
|
||||
glm::lookAt(eye * viewDistance, glm::vec3(0.f, 0.f, 0.f),
|
||||
glm::vec3(0.f, 0.f, 1.f));
|
||||
glm::mat4 view = glm::lookAt(vc.position, glm::vec3(0.f, 0.f, 0.f),
|
||||
glm::vec3(0.f, 0.f, 1.f));
|
||||
vc.rotation = -glm::quat_cast(view);
|
||||
vc.frustum.update(proj * view);
|
||||
|
||||
r.getRenderer()->setSceneParameters(
|
||||
{proj, view, glm::vec4(0.15f), glm::vec4(0.7f), glm::vec4(1.f),
|
||||
@ -126,9 +131,12 @@ void ViewerWidget::paintGL() {
|
||||
|
||||
r.setupRender();
|
||||
|
||||
r.renderModel(model, m, dummyObject);
|
||||
ObjectRenderer renderer(world(), vc, 1.f, 0);
|
||||
RenderList renders;
|
||||
renderer.renderClump(model, glm::mat4(), nullptr, renders);
|
||||
r.getRenderer()->drawBatched(renders);
|
||||
|
||||
drawFrameWidget(model->frames[model->rootFrameIdx]);
|
||||
drawFrameWidget(model->getFrame().get());
|
||||
r.renderPostProcess();
|
||||
} else if (world()->allObjects.size() > 0) {
|
||||
vc.frustum.fov = glm::radians(90.f);
|
||||
@ -143,26 +151,24 @@ void ViewerWidget::paintGL() {
|
||||
|
||||
void ViewerWidget::drawFrameWidget(ModelFrame* f, const glm::mat4& m) {
|
||||
auto thisM = m * f->getTransform();
|
||||
if (f->getGeometries().size() == 0) {
|
||||
Renderer::DrawParameters dp;
|
||||
dp.count = _frameWidgetGeom->getCount();
|
||||
dp.start = 0;
|
||||
dp.ambient = 1.f;
|
||||
dp.diffuse = 1.f;
|
||||
if (f == selectedFrame) {
|
||||
dp.colour = {255, 255, 0, 255};
|
||||
// Sorry!
|
||||
glLineWidth(10.f);
|
||||
} else {
|
||||
dp.colour = {255, 255, 255, 255};
|
||||
glLineWidth(1.f);
|
||||
}
|
||||
dp.textures = {whiteTex};
|
||||
renderer->getRenderer()->drawArrays(thisM, _frameWidgetDraw, dp);
|
||||
Renderer::DrawParameters dp;
|
||||
dp.count = _frameWidgetGeom->getCount();
|
||||
dp.start = 0;
|
||||
dp.ambient = 1.f;
|
||||
dp.diffuse = 1.f;
|
||||
if (f == selectedFrame) {
|
||||
dp.colour = {255, 255, 0, 255};
|
||||
// Sorry!
|
||||
glLineWidth(10.f);
|
||||
} else {
|
||||
dp.colour = {255, 255, 255, 255};
|
||||
glLineWidth(1.f);
|
||||
}
|
||||
dp.textures = {whiteTex};
|
||||
renderer->getRenderer()->drawArrays(thisM, _frameWidgetDraw, dp);
|
||||
|
||||
for (auto c : f->getChildren()) {
|
||||
drawFrameWidget(c, thisM);
|
||||
drawFrameWidget(c.get(), thisM);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,10 +27,10 @@ int DFFFramesTreeModel::rowCount(const QModelIndex& parent) const {
|
||||
QModelIndex DFFFramesTreeModel::index(int row, int column,
|
||||
const QModelIndex& parent) const {
|
||||
if (parent.row() == -1 && parent.column() == -1) {
|
||||
return createIndex(row, column, model->frames[model->rootFrameIdx]);
|
||||
return createIndex(row, column, model->getFrame().get());
|
||||
}
|
||||
ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer());
|
||||
ModelFrame* p = f->getChildren()[row];
|
||||
ModelFrame* p = f->getChildren()[row].get();
|
||||
return createIndex(row, column, p);
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ QModelIndex DFFFramesTreeModel::parent(const QModelIndex& child) const {
|
||||
auto cp = c->getParent();
|
||||
if (cp->getParent()) {
|
||||
for (size_t i = 0; i < cp->getParent()->getChildren().size(); ++i) {
|
||||
if (cp->getParent()->getChildren()[i] == c->getParent()) {
|
||||
if (cp->getParent()->getChildren()[i].get() == c->getParent()) {
|
||||
return createIndex(i, 0, c->getParent());
|
||||
}
|
||||
}
|
||||
|
@ -6,23 +6,10 @@ void ModelFramesWidget::updateInfoBox(Clump* model, ModelFrame* f) {
|
||||
if (f == nullptr) {
|
||||
_frameLabel->setText("");
|
||||
} else {
|
||||
auto labText = QString("Name: %1\nTranslation: %2\nTextures:%3")
|
||||
auto labText = QString("Name: %1\nTranslation: %2")
|
||||
.arg(QString::fromStdString(f->getName()))
|
||||
.arg(QString::fromStdString(
|
||||
glm::to_string(f->getDefaultTranslation())));
|
||||
QString geomString;
|
||||
for (size_t gi : f->getGeometries()) {
|
||||
auto& g = model->geometries[gi];
|
||||
// for(Model::SubGeometry& sg : g->subgeom)
|
||||
for (Geometry::Material& m : g->materials) {
|
||||
for (Geometry::Texture& t : m.textures) {
|
||||
geomString += QString("\n %1 (%2)")
|
||||
.arg(t.name.c_str())
|
||||
.arg(t.alphaName.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
labText = labText.arg(geomString);
|
||||
_frameLabel->setText(labText);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user