mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:23:52 +00:00
Problems with handles
This commit is contained in:
parent
16ff2a7a1b
commit
7bd911b401
10 changed files with 126 additions and 14 deletions
|
@ -24,7 +24,7 @@ namespace MWClass
|
|||
|
||||
void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
|
||||
{
|
||||
/*
|
||||
|
||||
ESMS::LiveCellRef<ESM::Creature, MWWorld::RefData> *ref =
|
||||
ptr.get<ESM::Creature>();
|
||||
|
||||
|
@ -33,15 +33,14 @@ namespace MWClass
|
|||
|
||||
if (!model.empty())
|
||||
{
|
||||
MWRender::Creatures& creatures = renderingInterface.getCreatures();
|
||||
//creatures.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
|
||||
//creatures.insertMesh(ptr, "meshes\\" + model);
|
||||
}*/
|
||||
MWRender::Actors& actors = renderingInterface.getActors();
|
||||
actors.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
|
||||
actors.insertMesh(ptr, "meshes\\" + model);
|
||||
}
|
||||
}
|
||||
|
||||
void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const
|
||||
{
|
||||
/*
|
||||
ESMS::LiveCellRef<ESM::Creature, MWWorld::RefData> *ref =
|
||||
ptr.get<ESM::Creature>();
|
||||
|
||||
|
@ -50,7 +49,7 @@ namespace MWClass
|
|||
assert (ref->base != NULL);
|
||||
if(!model.empty()){
|
||||
physics.insertActorPhysics(ptr, "meshes\\" + model);
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#define GAME_MWCLASS_CREATURE_H
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwrender/renderinginterface.hpp"
|
||||
#include "../mwrender/actors.hpp"
|
||||
|
||||
|
||||
namespace MWClass
|
||||
|
|
|
@ -250,6 +250,7 @@ namespace MWMechanics
|
|||
while (iter!=mActors.end())
|
||||
if (iter->getCell()==cellStore)
|
||||
{
|
||||
std::cout << "Erasing an actor";
|
||||
mActors.erase (iter++);
|
||||
}
|
||||
else
|
||||
|
|
89
apps/openmw/mwrender/actors.cpp
Normal file
89
apps/openmw/mwrender/actors.cpp
Normal file
|
@ -0,0 +1,89 @@
|
|||
#include "actors.hpp"
|
||||
#include <OgreSceneNode.h>
|
||||
#include <components/nifogre/ogre_nif_loader.hpp>
|
||||
|
||||
using namespace Ogre;
|
||||
using namespace MWRender;
|
||||
|
||||
void Actors::setMwRoot(Ogre::SceneNode* root){
|
||||
mMwRoot = root;
|
||||
}
|
||||
void Actors::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){
|
||||
Ogre::SceneNode* cellnode;
|
||||
if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end())
|
||||
{
|
||||
//Create the scenenode and put it in the map
|
||||
cellnode = mMwRoot->createChildSceneNode();
|
||||
mCellSceneNodes[ptr.getCell()] = cellnode;
|
||||
}
|
||||
else
|
||||
{
|
||||
cellnode = mCellSceneNodes[ptr.getCell()];
|
||||
}
|
||||
|
||||
Ogre::SceneNode* insert = cellnode->createChildSceneNode();
|
||||
const float *f = ptr.getRefData().getPosition().pos;
|
||||
insert->setPosition(f[0], f[1], f[2]);
|
||||
insert->setScale(ptr.getCellRef().scale, ptr.getCellRef().scale, ptr.getCellRef().scale);
|
||||
|
||||
// Convert MW rotation to a quaternion:
|
||||
f = ptr.getCellRef().pos.rot;
|
||||
|
||||
// Rotate around X axis
|
||||
Quaternion xr(Radian(-f[0]), Vector3::UNIT_X);
|
||||
|
||||
// Rotate around Y axis
|
||||
Quaternion yr(Radian(-f[1]), Vector3::UNIT_Y);
|
||||
|
||||
// Rotate around Z axis
|
||||
Quaternion zr(Radian(-f[2]), Vector3::UNIT_Z);
|
||||
|
||||
// Rotates first around z, then y, then x
|
||||
insert->setOrientation(xr*yr*zr);
|
||||
if (!enabled)
|
||||
insert->setVisible (false);
|
||||
ptr.getRefData().setBaseNode(insert);
|
||||
|
||||
|
||||
}
|
||||
void Actors::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){
|
||||
Ogre::SceneNode* insert = ptr.getRefData().getBaseNode();
|
||||
assert(insert);
|
||||
|
||||
NifOgre::NIFLoader::load(mesh);
|
||||
Entity *ent = mRend.getScene()->createEntity(mesh);
|
||||
insert->attachObject(ent);
|
||||
}
|
||||
|
||||
bool Actors::deleteObject (const MWWorld::Ptr& ptr)
|
||||
{
|
||||
if (Ogre::SceneNode *base = ptr.getRefData().getBaseNode())
|
||||
{
|
||||
Ogre::SceneNode *parent = base->getParentSceneNode();
|
||||
|
||||
for (std::map<MWWorld::Ptr::CellStore *, Ogre::SceneNode *>::const_iterator iter (
|
||||
mCellSceneNodes.begin()); iter!=mCellSceneNodes.end(); ++iter)
|
||||
if (iter->second==parent)
|
||||
{
|
||||
base->removeAndDestroyAllChildren();
|
||||
mRend.getScene()->destroySceneNode (base);
|
||||
ptr.getRefData().setBaseNode (0);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Actors::removeCell(MWWorld::Ptr::CellStore* store){
|
||||
if(mCellSceneNodes.find(store) != mCellSceneNodes.end())
|
||||
{
|
||||
Ogre::SceneNode* base = mCellSceneNodes[store];
|
||||
base->removeAndDestroyAllChildren();
|
||||
mCellSceneNodes.erase(store);
|
||||
mRend.getScene()->destroySceneNode(base);
|
||||
base = 0;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
#define _GAME_RENDER_ACTORS_H
|
||||
|
||||
#include "components/esm_store/cell_store.hpp"
|
||||
#include <map>
|
||||
|
||||
#include "../mwworld/refdata.hpp"
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
@ -10,14 +11,21 @@ namespace MWRender{
|
|||
class Actors{
|
||||
OEngine::Render::OgreRenderer &mRend;
|
||||
std::map<MWWorld::Ptr::CellStore *, Ogre::SceneNode *> mCellSceneNodes;
|
||||
std::map<MWWorld::Ptr::CellStore *, Ogre::StaticGeometry*> mSG;
|
||||
Ogre::SceneNode* mMwRoot;
|
||||
bool isStatic;
|
||||
static int uniqueID;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
Actors(OEngine::Render::OgreRenderer& _rend): mRend(_rend){}
|
||||
~Actors(){}
|
||||
Actors(OEngine::Render::OgreRenderer& _rend): mRend(_rend){}
|
||||
~Actors(){}
|
||||
void setMwRoot(Ogre::SceneNode* root);
|
||||
void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_);
|
||||
void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh);
|
||||
bool deleteObject (const MWWorld::Ptr& ptr);
|
||||
///< \return found?
|
||||
|
||||
void removeCell(MWWorld::Ptr::CellStore* store);
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
|
@ -42,6 +42,7 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const
|
|||
mMwRoot = rt->createChildSceneNode();
|
||||
mMwRoot->pitch(Degree(-90));
|
||||
mObjects.setMwRoot(mMwRoot);
|
||||
mActors.setMwRoot(mMwRoot);
|
||||
|
||||
//used to obtain ingame information of ogre objects (which are faced or selected)
|
||||
mRaySceneQuery = mRendering.getScene()->createRayQuery(Ray());
|
||||
|
@ -75,6 +76,7 @@ MWRender::Player& RenderingManager::getPlayer(){
|
|||
|
||||
void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store){
|
||||
mObjects.removeCell(store);
|
||||
mActors.removeCell(store);
|
||||
}
|
||||
|
||||
void RenderingManager::cellAdded (MWWorld::Ptr::CellStore *store)
|
||||
|
@ -94,6 +96,10 @@ void RenderingManager::removeObject (const MWWorld::Ptr& ptr)
|
|||
{
|
||||
/// \todo delete non-object MW-references
|
||||
}
|
||||
if (!mActors.deleteObject (ptr))
|
||||
{
|
||||
/// \todo delete non-object MW-references
|
||||
}
|
||||
}
|
||||
|
||||
void RenderingManager::moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position)
|
||||
|
|
|
@ -191,6 +191,7 @@ namespace MWWorld
|
|||
|
||||
void PhysicsSystem::insertActorPhysics(const MWWorld::Ptr& ptr, const std::string model){
|
||||
Ogre::SceneNode* node = ptr.getRefData().getBaseNode();
|
||||
std::cout << "Adding node with name" << node->getName();
|
||||
addActor (node->getName(), model, node->getPosition());
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace MWWorld
|
|||
|
||||
void Scene::unloadCell (CellStoreCollection::iterator iter)
|
||||
{
|
||||
|
||||
std::cout << "Unloading cell\n";
|
||||
ListHandles functor;
|
||||
|
||||
MWWorld::Ptr::CellStore* active = *iter;
|
||||
|
@ -73,6 +73,7 @@ namespace MWWorld
|
|||
mPhysics->removeObject (node->getName());
|
||||
}
|
||||
}
|
||||
//mPhysics->removeObject("Unnamed_43");
|
||||
mWorld->getLocalScripts().clearCell (active);
|
||||
mEnvironment.mMechanicsManager->dropActors (active);
|
||||
mEnvironment.mSoundManager->stopSound (active);
|
||||
|
|
|
@ -581,7 +581,6 @@ public:
|
|||
int count = nif->getInt();
|
||||
//std::vector<Ogre::Quaternion> quat(count);
|
||||
//std::vector<float> rottime(count);
|
||||
std::cout << "r";
|
||||
if(count)
|
||||
{
|
||||
|
||||
|
|
|
@ -1038,6 +1038,7 @@ void NIFLoader::handleNode(Nif::Node *node, int flags,
|
|||
//FIXME: "Bip01" isn't every time the root bone
|
||||
if (node->name == "Bip01" || node->name == "Root Bone") //root node, create a skeleton
|
||||
{
|
||||
|
||||
mSkel = SkeletonManager::getSingleton().create(getSkeletonName(), resourceGroup, true);
|
||||
|
||||
/*if (node->extra->recType == RC_NiTextKeyExtraData )
|
||||
|
@ -1240,6 +1241,11 @@ void NIFLoader::loadResource(Resource *resource)
|
|||
bounds.maxX(), bounds.maxY(), bounds.maxZ()));
|
||||
mesh->_setBoundingSphereRadius(bounds.getRadius());
|
||||
}
|
||||
|
||||
if (!mSkel.isNull())
|
||||
{
|
||||
mesh->_notifySkeleton(mSkel);
|
||||
}
|
||||
}
|
||||
|
||||
MeshPtr NIFLoader::load(const std::string &name,
|
||||
|
|
Loading…
Reference in a new issue