From 7f967153ef993752c65bcda70bb4724eb76025af Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 6 Jan 2016 15:00:58 +0100 Subject: [PATCH] OpenCS: create light sources --- apps/opencs/view/render/object.cpp | 30 ++++++++++++++++++++++++- apps/opencs/view/render/scenewidget.cpp | 5 ++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/apps/opencs/view/render/object.cpp b/apps/opencs/view/render/object.cpp index 2ff80b38b..f202be4bc 100644 --- a/apps/opencs/view/render/object.cpp +++ b/apps/opencs/view/render/object.cpp @@ -17,7 +17,9 @@ #include "../../model/world/refidcollection.hpp" #include -#include +#include +#include +#include #include "mask.hpp" @@ -62,6 +64,7 @@ void CSVRender::Object::update() const CSMWorld::RefIdCollection& referenceables = mData.getReferenceables(); int index = referenceables.searchId (mReferenceableId); + const ESM::Light* light = NULL; if (index==-1) error = 1; @@ -73,6 +76,14 @@ void CSVRender::Object::update() referenceables.findColumnIndex (CSMWorld::Columns::ColumnId_Model)). toString().toUtf8().constData(); + int recordType = + referenceables.getData (index, + referenceables.findColumnIndex(CSMWorld::Columns::ColumnId_RecordType)).toInt(); + if (recordType == CSMWorld::UniversalId::Type_Light) + { + light = &dynamic_cast& >(referenceables.getRecord(index)).get(); + } + if (model.empty()) error = 2; } @@ -97,6 +108,21 @@ void CSVRender::Object::update() std::cerr << e.what() << std::endl; } } + + if (light) + { + const Fallback::Map* fallback = mData.getFallbackMap(); + static bool outQuadInLin = fallback->getFallbackBool("LightAttenuation_OutQuadInLin"); + static bool useQuadratic = fallback->getFallbackBool("LightAttenuation_UseQuadratic"); + static float quadraticValue = fallback->getFallbackFloat("LightAttenuation_QuadraticValue"); + static float quadraticRadiusMult = fallback->getFallbackFloat("LightAttenuation_QuadraticRadiusMult"); + static bool useLinear = fallback->getFallbackBool("LightAttenuation_UseLinear"); + static float linearRadiusMult = fallback->getFallbackFloat("LightAttenuation_LinearRadiusMult"); + static float linearValue = fallback->getFallbackFloat("LightAttenuation_LinearValue"); + bool isExterior = false; // FIXME + SceneUtil::addLight(mBaseNode, light, Mask_ParticleSystem, ~0u, isExterior, outQuadInLin, useQuadratic, + quadraticValue, quadraticRadiusMult, useLinear, linearRadiusMult, linearValue); + } } void CSVRender::Object::adjustTransform() @@ -131,6 +157,8 @@ CSVRender::Object::Object (CSMWorld::Data& data, osg::Group* parentNode, : mData (data), mBaseNode(0), mSelected(false), mParentNode(parentNode), mResourceSystem(data.getResourceSystem().get()), mForceBaseToZero (forceBaseToZero) { mBaseNode = new osg::PositionAttitudeTransform; + mBaseNode->addCullCallback(new SceneUtil::LightListCallback); + mOutline = new osgFX::Scribe; mOutline->addChild(mBaseNode); diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index d7138b392..c51b22e09 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -14,6 +14,7 @@ #include #include +#include #include "../widget/scenetoolmode.hpp" @@ -64,7 +65,9 @@ RenderWidget::RenderWidget(QWidget *parent, Qt::WindowFlags f) mView->getCamera()->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) ); mView->getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast(traits->width)/static_cast(traits->height), 1.0f, 10000.0f ); - mRootNode = new osg::Group; + SceneUtil::LightManager* lightMgr = new SceneUtil::LightManager; + lightMgr->setStartLight(1); + mRootNode = lightMgr; mView->getCamera()->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON); mView->getCamera()->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::ON);