mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-19 15:11:33 +00:00
Merge branch 'renderingfix'
This commit is contained in:
commit
b878c87ba8
4 changed files with 105 additions and 80 deletions
|
@ -24,11 +24,12 @@ namespace MWClass
|
||||||
assert (ref->base != NULL);
|
assert (ref->base != NULL);
|
||||||
const std::string &model = ref->base->model;
|
const std::string &model = ref->base->model;
|
||||||
|
|
||||||
if (!model.empty())
|
|
||||||
{
|
|
||||||
MWRender::Objects& objects = renderingInterface.getObjects();
|
MWRender::Objects& objects = renderingInterface.getObjects();
|
||||||
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
|
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
|
||||||
|
|
||||||
|
if (!model.empty())
|
||||||
objects.insertMesh(ptr, "meshes\\" + model);
|
objects.insertMesh(ptr, "meshes\\" + model);
|
||||||
|
|
||||||
const int color = ref->base->data.color;
|
const int color = ref->base->data.color;
|
||||||
const float r = ((color >> 0) & 0xFF) / 255.0f;
|
const float r = ((color >> 0) & 0xFF) / 255.0f;
|
||||||
const float g = ((color >> 8) & 0xFF) / 255.0f;
|
const float g = ((color >> 8) & 0xFF) / 255.0f;
|
||||||
|
@ -36,20 +37,18 @@ namespace MWClass
|
||||||
const float radius = float (ref->base->data.radius);
|
const float radius = float (ref->base->data.radius);
|
||||||
objects.insertLight (ptr, r, g, b, radius);
|
objects.insertLight (ptr, r, g, b, radius);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Light::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const
|
void Light::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const
|
||||||
{
|
{
|
||||||
ESMS::LiveCellRef<ESM::Light, MWWorld::RefData> *ref =
|
ESMS::LiveCellRef<ESM::Light, MWWorld::RefData> *ref =
|
||||||
ptr.get<ESM::Light>();
|
ptr.get<ESM::Light>();
|
||||||
|
|
||||||
|
|
||||||
const std::string &model = ref->base->model;
|
|
||||||
assert (ref->base != NULL);
|
assert (ref->base != NULL);
|
||||||
|
const std::string &model = ref->base->model;
|
||||||
|
|
||||||
if(!model.empty()){
|
if(!model.empty()){
|
||||||
physics.insertObjectPhysics(ptr, "meshes\\" + model);
|
physics.insertObjectPhysics(ptr, "meshes\\" + model);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Light::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const
|
void Light::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace MWClass
|
||||||
if (!model.empty())
|
if (!model.empty())
|
||||||
{
|
{
|
||||||
MWRender::Objects& objects = renderingInterface.getObjects();
|
MWRender::Objects& objects = renderingInterface.getObjects();
|
||||||
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
|
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true);
|
||||||
objects.insertMesh(ptr, "meshes\\" + model);
|
objects.insertMesh(ptr, "meshes\\" + model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,12 @@ namespace MWClass
|
||||||
ESMS::LiveCellRef<ESM::Static, MWWorld::RefData> *ref =
|
ESMS::LiveCellRef<ESM::Static, MWWorld::RefData> *ref =
|
||||||
ptr.get<ESM::Static>();
|
ptr.get<ESM::Static>();
|
||||||
|
|
||||||
|
|
||||||
const std::string &model = ref->base->model;
|
|
||||||
assert (ref->base != NULL);
|
assert (ref->base != NULL);
|
||||||
|
const std::string &model = ref->base->model;
|
||||||
|
|
||||||
if(!model.empty()){
|
if(!model.empty()){
|
||||||
physics.insertObjectPhysics(ptr, "meshes\\" + model);
|
physics.insertObjectPhysics(ptr, "meshes\\" + model);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Static::getName (const MWWorld::Ptr& ptr) const
|
std::string Static::getName (const MWWorld::Ptr& ptr) const
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#include "objects.hpp"
|
#include "objects.hpp"
|
||||||
|
|
||||||
#include <OgreSceneNode.h>
|
#include <OgreSceneNode.h>
|
||||||
|
|
||||||
#include <components/nifogre/ogre_nif_loader.hpp>
|
#include <components/nifogre/ogre_nif_loader.hpp>
|
||||||
|
|
||||||
using namespace Ogre;
|
|
||||||
using namespace MWRender;
|
using namespace MWRender;
|
||||||
|
|
||||||
|
|
||||||
bool Objects::lightConst = false;
|
bool Objects::lightConst = false;
|
||||||
float Objects::lightConstValue = 0.0f;
|
float Objects::lightConstValue = 0.0f;
|
||||||
|
|
||||||
|
@ -23,10 +23,24 @@ bool Objects::lightOutQuadInLin = false;
|
||||||
|
|
||||||
int Objects::uniqueID = 0;
|
int Objects::uniqueID = 0;
|
||||||
|
|
||||||
void Objects::setMwRoot(Ogre::SceneNode* root){
|
void Objects::clearSceneNode (Ogre::SceneNode *node)
|
||||||
|
{
|
||||||
|
/// \todo This should probably be moved into OpenEngine at some point.
|
||||||
|
for (int i=node->numAttachedObjects()-1; i>=0; --i)
|
||||||
|
{
|
||||||
|
Ogre::MovableObject *object = node->getAttachedObject (i);
|
||||||
|
node->detachObject (object);
|
||||||
|
mRenderer.getScene()->destroyMovableObject (object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Objects::setMwRoot(Ogre::SceneNode* root)
|
||||||
|
{
|
||||||
mMwRoot = root;
|
mMwRoot = root;
|
||||||
}
|
}
|
||||||
void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){
|
|
||||||
|
void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_)
|
||||||
|
{
|
||||||
Ogre::SceneNode* root = mMwRoot;
|
Ogre::SceneNode* root = mMwRoot;
|
||||||
Ogre::SceneNode* cellnode;
|
Ogre::SceneNode* cellnode;
|
||||||
if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end())
|
if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end())
|
||||||
|
@ -49,68 +63,69 @@ void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){
|
||||||
f = ptr.getCellRef().pos.rot;
|
f = ptr.getCellRef().pos.rot;
|
||||||
|
|
||||||
// Rotate around X axis
|
// Rotate around X axis
|
||||||
Quaternion xr(Radian(-f[0]), Vector3::UNIT_X);
|
Ogre::Quaternion xr(Ogre::Radian(-f[0]), Ogre::Vector3::UNIT_X);
|
||||||
|
|
||||||
// Rotate around Y axis
|
// Rotate around Y axis
|
||||||
Quaternion yr(Radian(-f[1]), Vector3::UNIT_Y);
|
Ogre::Quaternion yr(Ogre::Radian(-f[1]), Ogre::Vector3::UNIT_Y);
|
||||||
|
|
||||||
// Rotate around Z axis
|
// Rotate around Z axis
|
||||||
Quaternion zr(Radian(-f[2]), Vector3::UNIT_Z);
|
Ogre::Quaternion zr(Ogre::Radian(-f[2]), Ogre::Vector3::UNIT_Z);
|
||||||
|
|
||||||
// Rotates first around z, then y, then x
|
// Rotates first around z, then y, then x
|
||||||
insert->setOrientation(xr*yr*zr);
|
insert->setOrientation(xr*yr*zr);
|
||||||
|
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
insert->setVisible (false);
|
insert->setVisible (false);
|
||||||
ptr.getRefData().setBaseNode(insert);
|
ptr.getRefData().setBaseNode(insert);
|
||||||
isStatic = static_;
|
mIsStatic = static_;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){
|
|
||||||
|
void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh)
|
||||||
|
{
|
||||||
Ogre::SceneNode* insert = ptr.getRefData().getBaseNode();
|
Ogre::SceneNode* insert = ptr.getRefData().getBaseNode();
|
||||||
assert(insert);
|
assert(insert);
|
||||||
|
|
||||||
NifOgre::NIFLoader::load(mesh);
|
NifOgre::NIFLoader::load(mesh);
|
||||||
Entity *ent = mRend.getScene()->createEntity(mesh);
|
Ogre::Entity *ent = mRenderer.getScene()->createEntity(mesh);
|
||||||
|
|
||||||
if(!isStatic)
|
if(!mIsStatic)
|
||||||
{
|
{
|
||||||
insert->attachObject(ent);
|
insert->attachObject(ent);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Ogre::StaticGeometry* sg = 0;
|
Ogre::StaticGeometry* sg = 0;
|
||||||
if(mSG.find(ptr.getCell()) == mSG.end())
|
if(mStaticGeometry.find(ptr.getCell()) == mStaticGeometry.end())
|
||||||
{
|
{
|
||||||
uniqueID = uniqueID +1;
|
uniqueID = uniqueID +1;
|
||||||
sg = mRend.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID));
|
sg = mRenderer.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID));
|
||||||
//Create the scenenode and put it in the map
|
//Create the scenenode and put it in the map
|
||||||
mSG[ptr.getCell()] = sg;
|
mStaticGeometry[ptr.getCell()] = sg;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sg = mSG[ptr.getCell()];
|
sg = mStaticGeometry[ptr.getCell()];
|
||||||
}
|
}
|
||||||
|
|
||||||
sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale());
|
sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale());
|
||||||
sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000));
|
sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000));
|
||||||
|
|
||||||
|
mRenderer.getScene()->destroyEntity(ent);
|
||||||
mRend.getScene()->destroyEntity(ent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius){
|
|
||||||
Ogre::SceneNode* insert = mRend.getScene()->getSceneNode(ptr.getRefData().getHandle());
|
void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius)
|
||||||
|
{
|
||||||
|
Ogre::SceneNode* insert = mRenderer.getScene()->getSceneNode(ptr.getRefData().getHandle());
|
||||||
assert(insert);
|
assert(insert);
|
||||||
Ogre::Light *light = mRend.getScene()->createLight();
|
Ogre::Light *light = mRenderer.getScene()->createLight();
|
||||||
light->setDiffuseColour (r, g, b);
|
light->setDiffuseColour (r, g, b);
|
||||||
|
|
||||||
float cval=0.0f, lval=0.0f, qval=0.0f;
|
float cval=0.0f, lval=0.0f, qval=0.0f;
|
||||||
|
|
||||||
if(lightConst)
|
if(lightConst)
|
||||||
cval = lightConstValue;
|
cval = lightConstValue;
|
||||||
|
|
||||||
if(!lightOutQuadInLin)
|
if(!lightOutQuadInLin)
|
||||||
{
|
{
|
||||||
if(lightLinear)
|
if(lightLinear)
|
||||||
|
@ -145,8 +160,9 @@ bool Objects::deleteObject (const MWWorld::Ptr& ptr)
|
||||||
mCellSceneNodes.begin()); iter!=mCellSceneNodes.end(); ++iter)
|
mCellSceneNodes.begin()); iter!=mCellSceneNodes.end(); ++iter)
|
||||||
if (iter->second==parent)
|
if (iter->second==parent)
|
||||||
{
|
{
|
||||||
|
clearSceneNode (base);
|
||||||
base->removeAndDestroyAllChildren();
|
base->removeAndDestroyAllChildren();
|
||||||
mRend.getScene()->destroySceneNode (base);
|
mRenderer.getScene()->destroySceneNode (base);
|
||||||
ptr.getRefData().setBaseNode (0);
|
ptr.getRefData().setBaseNode (0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -157,29 +173,35 @@ bool Objects::deleteObject (const MWWorld::Ptr& ptr)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Objects::removeCell(MWWorld::Ptr::CellStore* store){
|
void Objects::removeCell(MWWorld::Ptr::CellStore* store)
|
||||||
|
{
|
||||||
if(mCellSceneNodes.find(store) != mCellSceneNodes.end())
|
if(mCellSceneNodes.find(store) != mCellSceneNodes.end())
|
||||||
{
|
{
|
||||||
Ogre::SceneNode* base = mCellSceneNodes[store];
|
Ogre::SceneNode* base = mCellSceneNodes[store];
|
||||||
|
|
||||||
|
for (int i=0; i<base->numChildren(); ++i)
|
||||||
|
clearSceneNode (static_cast<Ogre::SceneNode *> (base->getChild (i)));
|
||||||
|
|
||||||
base->removeAndDestroyAllChildren();
|
base->removeAndDestroyAllChildren();
|
||||||
mCellSceneNodes.erase(store);
|
mCellSceneNodes.erase(store);
|
||||||
mRend.getScene()->destroySceneNode(base);
|
mRenderer.getScene()->destroySceneNode(base);
|
||||||
base = 0;
|
base = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(mStaticGeometry.find(store) != mStaticGeometry.end())
|
||||||
if(mSG.find(store) != mSG.end())
|
|
||||||
{
|
{
|
||||||
Ogre::StaticGeometry* sg = mSG[store];
|
Ogre::StaticGeometry* sg = mStaticGeometry[store];
|
||||||
mSG.erase(store);
|
mStaticGeometry.erase(store);
|
||||||
mRend.getScene()->destroyStaticGeometry (sg);
|
mRenderer.getScene()->destroyStaticGeometry (sg);
|
||||||
sg = 0;
|
sg = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Objects::buildStaticGeometry(ESMS::CellStore<MWWorld::RefData>& cell){
|
|
||||||
if(mSG.find(&cell) != mSG.end())
|
void Objects::buildStaticGeometry(ESMS::CellStore<MWWorld::RefData>& cell)
|
||||||
|
{
|
||||||
|
if(mStaticGeometry.find(&cell) != mStaticGeometry.end())
|
||||||
{
|
{
|
||||||
Ogre::StaticGeometry* sg = mSG[&cell];
|
Ogre::StaticGeometry* sg = mStaticGeometry[&cell];
|
||||||
sg->build();
|
sg->build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
#ifndef _GAME_RENDER_OBJECTS_H
|
#ifndef _GAME_RENDER_OBJECTS_H
|
||||||
#define _GAME_RENDER_OBJECTS_H
|
#define _GAME_RENDER_OBJECTS_H
|
||||||
|
|
||||||
#include "components/esm_store/cell_store.hpp"
|
#include <openengine/ogre/renderer.hpp>
|
||||||
|
|
||||||
|
#include <components/esm_store/cell_store.hpp>
|
||||||
|
|
||||||
#include "../mwworld/refdata.hpp"
|
#include "../mwworld/refdata.hpp"
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
#include <openengine/ogre/renderer.hpp>
|
|
||||||
|
|
||||||
namespace MWRender{
|
namespace MWRender{
|
||||||
|
|
||||||
class Objects{
|
class Objects{
|
||||||
OEngine::Render::OgreRenderer &mRend;
|
OEngine::Render::OgreRenderer &mRenderer;
|
||||||
std::map<MWWorld::Ptr::CellStore *, Ogre::SceneNode *> mCellSceneNodes;
|
std::map<MWWorld::Ptr::CellStore *, Ogre::SceneNode *> mCellSceneNodes;
|
||||||
std::map<MWWorld::Ptr::CellStore *, Ogre::StaticGeometry*> mSG;
|
std::map<MWWorld::Ptr::CellStore *, Ogre::StaticGeometry*> mStaticGeometry;
|
||||||
Ogre::SceneNode* mMwRoot;
|
Ogre::SceneNode* mMwRoot;
|
||||||
bool isStatic;
|
bool mIsStatic;
|
||||||
static int uniqueID;
|
static int uniqueID;
|
||||||
static bool lightConst;
|
static bool lightConst;
|
||||||
static float lightConstValue;
|
static float lightConstValue;
|
||||||
|
@ -30,8 +31,12 @@ class Objects{
|
||||||
static float lightQuadraticRadiusMult;
|
static float lightQuadraticRadiusMult;
|
||||||
|
|
||||||
static bool lightOutQuadInLin;
|
static bool lightOutQuadInLin;
|
||||||
|
|
||||||
|
void clearSceneNode (Ogre::SceneNode *node);
|
||||||
|
///< Remove all movable objects from \a node.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Objects(OEngine::Render::OgreRenderer& _rend): mRend(_rend){}
|
Objects(OEngine::Render::OgreRenderer& renderer): mRenderer (renderer){}
|
||||||
~Objects(){}
|
~Objects(){}
|
||||||
void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_);
|
void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_);
|
||||||
void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh);
|
void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh);
|
||||||
|
|
Loading…
Reference in a new issue