Adds the light into the scene.

Common struct for ESM3 and ESM4 light
7220-lua-add-a-general-purpose-lexical-parser
florent.teppe 2 years ago
parent a71a86e64a
commit dc961e3189

@ -44,6 +44,7 @@
#include "../../model/world/data.hpp"
#include <components/debug/debuglog.hpp>
#include <components/esm/esmbridge.hpp>
#include <components/resource/resourcesystem.hpp>
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/lightmanager.hpp>
@ -167,7 +168,7 @@ void CSVRender::Object::update()
if (light)
{
bool isExterior = false; // FIXME
SceneUtil::addLight(mBaseNode, light, Mask_Lighting, isExterior);
SceneUtil::addLight(mBaseNode, ESM::LightCommon(*light), Mask_Lighting, isExterior);
}
}

@ -557,7 +557,7 @@ namespace MWRender
osg::Vec4f ambient(1, 1, 1, 1);
osg::ref_ptr<SceneUtil::LightSource> lightSource
= SceneUtil::createLightSource(esmLight, Mask_Lighting, exterior, ambient);
= SceneUtil::createLightSource(ESM::LightCommon(*esmLight), Mask_Lighting, exterior, ambient);
mInsert->addChild(lightSource);

@ -23,6 +23,7 @@
#include <components/esm3/loadmgef.hpp>
#include <components/esm3/loadnpc.hpp>
#include <components/esm3/loadrace.hpp>
#include <components/esm4/loadligh.hpp>
#include <components/misc/constants.hpp>
#include <components/misc/pathhelpers.hpp>
#include <components/misc/resourcehelpers.hpp>
@ -1510,7 +1511,7 @@ namespace MWRender
}
}
void Animation::addExtraLight(osg::ref_ptr<osg::Group> parent, const ESM::Light* esmLight)
void Animation::addExtraLight(osg::ref_ptr<osg::Group> parent, const ESM::LightCommon& esmLight)
{
bool exterior = mPtr.isInCell() && mPtr.getCell()->getCell()->isExterior();
@ -1854,7 +1855,9 @@ namespace MWRender
mObjectRoot, mResourceSystem, ptr.getClass().getEnchantmentColor(ptr));
}
if (ptr.getType() == ESM::Light::sRecordId && allowLight)
addExtraLight(getOrCreateObjectRoot(), ptr.get<ESM::Light>()->mBase);
addExtraLight(getOrCreateObjectRoot(), ESM::LightCommon(*ptr.get<ESM::Light>()->mBase));
if (ptr.getType() == ESM4::Light::sRecordId && allowLight)
addExtraLight(getOrCreateObjectRoot(), ESM::LightCommon(*ptr.get<ESM4::Light>()->mBase));
if (!allowLight && mObjectRoot)
{

@ -333,7 +333,7 @@ namespace MWRender
void addSingleAnimSource(const std::string& model, const std::string& baseModel);
/** Adds an additional light to the given node using the specified ESM record. */
void addExtraLight(osg::ref_ptr<osg::Group> parent, const ESM::Light* light);
void addExtraLight(osg::ref_ptr<osg::Group> parent, const ESM::LightCommon& light);
void clearAnimSources();

@ -13,6 +13,7 @@
#include <components/misc/resourcehelpers.hpp>
#include <components/esm/esmbridge.hpp>
#include <components/esm3/loadbody.hpp>
#include <components/esm3/loadmgef.hpp>
#include <components/esm3/loadrace.hpp>
@ -664,7 +665,7 @@ namespace MWRender
addOrReplaceIndividualPart(ESM::PRT_Shield, MWWorld::InventoryStore::Slot_CarriedLeft, 1,
Misc::ResourceHelpers::correctMeshPath(light->mModel, vfs), false, nullptr, true);
if (mObjectParts[ESM::PRT_Shield])
addExtraLight(mObjectParts[ESM::PRT_Shield]->getNode()->asGroup(), light);
addExtraLight(mObjectParts[ESM::PRT_Shield]->getNode()->asGroup(), ESM::LightCommon(*light));
}
}
@ -1041,7 +1042,8 @@ namespace MWRender
if (mesh.empty())
reserveIndividualPart(ESM::PRT_Shield, MWWorld::InventoryStore::Slot_CarriedLeft, 1);
if (iter->getType() == ESM::Light::sRecordId && mObjectParts[ESM::PRT_Shield])
addExtraLight(mObjectParts[ESM::PRT_Shield]->getNode()->asGroup(), iter->get<ESM::Light>()->mBase);
addExtraLight(mObjectParts[ESM::PRT_Shield]->getNode()->asGroup(),
ESM::LightCommon(*iter->get<ESM::Light>()->mBase));
}
}
else

@ -39,9 +39,9 @@
#include <components/esm3/npcstate.hpp>
#include <components/esm3/objectstate.hpp>
#include <components/esm3/readerscache.hpp>
#include <components/esm4/loadligh.hpp>
#include <components/esm4/loadrefr.hpp>
#include <components/esm4/loadstat.hpp>
#include <components/esm4/loadligh.hpp>
#include <components/misc/tuplehelpers.hpp>
#include "../mwbase/environment.hpp"

@ -11,6 +11,7 @@
#include <components/esm3/esmwriter.hpp>
#include <components/esm4/common.hpp>
#include <components/esm4/loadcell.hpp>
#include <components/esm4/loadligh.hpp>
#include <components/esm4/loadrefr.hpp>
#include <components/esm4/loadstat.hpp>
#include <components/esm4/reader.hpp>

@ -1,6 +1,9 @@
#include <components/esm/esmbridge.hpp>
#include <components/esm3/loadcell.hpp>
#include <components/esm3/loadligh.hpp>
#include <components/esm4/loadcell.hpp>
#include <components/esm4/loadligh.hpp>
#include <components/sceneutil/util.hpp>
namespace ESM
{
@ -15,4 +18,29 @@ namespace ESM
auto cell = std::get<const ESM::Cell*>(mVariant);
return *cell;
}
LightCommon::LightCommon(const ESM::Light& light)
: mFlicker(light.mData.mFlags & ESM::Light::Flicker)
, mFlickerSlow(light.mData.mFlags & ESM::Light::FlickerSlow)
, mNegative(light.mData.mFlags & ESM::Light::Negative)
, mPulse(light.mData.mFlags & ESM::Light::Pulse)
, mPulseSlow(light.mData.mFlags & ESM::Light::PulseSlow)
, mOffDefault(light.mData.mFlags & ESM::Light::OffDefault)
, mColor(SceneUtil::colourFromRGB(light.mData.mColor))
, mRadius(light.mData.mRadius)
{
}
LightCommon::LightCommon(const ESM4::Light& light)
: mFlicker(light.mData.flags & ESM4::Light::Flicker)
, mFlickerSlow(light.mData.flags & ESM4::Light::FlickerSlow)
, mNegative(light.mData.flags & ESM::Light::Negative)
, mPulse(light.mData.flags & ESM4::Light::Pulse)
, mPulseSlow(light.mData.flags & ESM4::Light::PulseSlow)
, mOffDefault(light.mData.flags & ESM4::Light::OffDefault)
, mColor(SceneUtil::colourFromRGB(light.mData.colour))
, mRadius(light.mData.radius)
{
}
}

@ -4,12 +4,15 @@
#include <string_view>
#include <variant>
#include <osg/Vec4>
#include <components/esm3/cellref.hpp>
#include <components/esm4/loadrefr.hpp>
namespace ESM4
{
struct Cell;
struct Light;
}
namespace ESM
@ -17,6 +20,7 @@ namespace ESM
struct Cell;
struct CellId;
struct RefId;
struct Light;
class CellVariant
{
@ -65,6 +69,22 @@ namespace ESM
ESM4::Reference& getEsm4() { return std::get<ESM4::Reference>(mVariant); }
};
struct LightCommon
{
explicit LightCommon(const ESM::Light& light);
explicit LightCommon(const ESM4::Light& light);
bool mFlicker;
bool mFlickerSlow;
bool mNegative;
bool mPulse;
bool mPulseSlow;
bool mOffDefault;
osg::Vec4 mColor;
float mRadius;
};
template <class F, class... T>
auto visit(F&& f, T&&... v)
{

@ -5,6 +5,7 @@
#include <osgParticle/ParticleSystem>
#include <components/esm/esmbridge.hpp>
#include <components/esm3/loadligh.hpp>
#include <components/fallback/fallback.hpp>
@ -86,7 +87,7 @@ namespace SceneUtil
}
osg::ref_ptr<LightSource> addLight(
osg::Group* node, const ESM::Light* esmLight, unsigned int lightMask, bool isExterior)
osg::Group* node, const ESM::LightCommon& esmLight, unsigned int lightMask, bool isExterior)
{
SceneUtil::FindByNameVisitor visitor("AttachLight");
node->accept(visitor);
@ -105,19 +106,19 @@ namespace SceneUtil
}
osg::ref_ptr<LightSource> createLightSource(
const ESM::Light* esmLight, unsigned int lightMask, bool isExterior, const osg::Vec4f& ambient)
const ESM::LightCommon& esmLight, unsigned int lightMask, bool isExterior, const osg::Vec4f& ambient)
{
osg::ref_ptr<SceneUtil::LightSource> lightSource(new SceneUtil::LightSource);
osg::ref_ptr<osg::Light> light(new osg::Light);
lightSource->setNodeMask(lightMask);
float radius = esmLight->mData.mRadius;
float radius = esmLight.mRadius;
lightSource->setRadius(radius);
configureLight(light, radius, isExterior);
osg::Vec4f diffuse = SceneUtil::colourFromRGB(esmLight->mData.mColor);
if (esmLight->mData.mFlags & ESM::Light::Negative)
osg::Vec4f diffuse = esmLight.mColor;
if (esmLight.mNegative)
{
diffuse *= -1;
diffuse.a() = 1;
@ -130,13 +131,13 @@ namespace SceneUtil
osg::ref_ptr<SceneUtil::LightController> ctrl(new SceneUtil::LightController);
ctrl->setDiffuse(light->getDiffuse());
if (esmLight->mData.mFlags & ESM::Light::Flicker)
if (esmLight.mFlicker)
ctrl->setType(SceneUtil::LightController::LT_Flicker);
if (esmLight->mData.mFlags & ESM::Light::FlickerSlow)
if (esmLight.mFlickerSlow)
ctrl->setType(SceneUtil::LightController::LT_FlickerSlow);
if (esmLight->mData.mFlags & ESM::Light::Pulse)
if (esmLight.mPulse)
ctrl->setType(SceneUtil::LightController::LT_Pulse);
if (esmLight->mData.mFlags & ESM::Light::PulseSlow)
if (esmLight.mPulseSlow)
ctrl->setType(SceneUtil::LightController::LT_PulseSlow);
lightSource->addUpdateCallback(ctrl);

@ -13,6 +13,7 @@ namespace osg
namespace ESM
{
struct Light;
struct LightCommon;
}
namespace SceneUtil
@ -32,15 +33,15 @@ namespace SceneUtil
/// @param lightMask Mask to assign to the newly created LightSource.
/// @param isExterior Is the light outside? May be used for deciding which attenuation settings to use.
osg::ref_ptr<LightSource> addLight(
osg::Group* node, const ESM::Light* esmLight, unsigned int lightMask, bool isExterior);
osg::Group* node, const ESM::LightCommon& esmLight, unsigned int lightMask, bool isExterior);
/// @brief Convert an ESM::Light to a SceneUtil::LightSource, and return it.
/// @param esmLight The light definition coming from the game files containing radius, color, flicker, etc.
/// @param lightMask Mask to assign to the newly created LightSource.
/// @param isExterior Is the light outside? May be used for deciding which attenuation settings to use.
/// @param ambient Ambient component of the light.
osg::ref_ptr<LightSource> createLightSource(const ESM::Light* esmLight, unsigned int lightMask, bool isExterior,
const osg::Vec4f& ambient = osg::Vec4f(0, 0, 0, 1));
osg::ref_ptr<LightSource> createLightSource(const ESM::LightCommon& esmLight, unsigned int lightMask,
bool isExterior, const osg::Vec4f& ambient = osg::Vec4f(0, 0, 0, 1));
}

Loading…
Cancel
Save