2011-01-13 16:51:50 +00:00
|
|
|
/*
|
|
|
|
OpenMW - The completely unofficial reimplementation of Morrowind
|
|
|
|
Copyright (C) 2008-2010 Nicolay Korslund
|
|
|
|
Email: < korslund@gmail.com >
|
|
|
|
WWW: http://openmw.sourceforge.net/
|
|
|
|
|
|
|
|
This file (ogre_nif_loader.h) is part of the OpenMW package.
|
|
|
|
|
|
|
|
OpenMW is distributed as free software: you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License
|
|
|
|
version 3, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
version 3 along with this program. If not, see
|
|
|
|
http://www.gnu.org/licenses/ .
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2013-02-24 21:52:23 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_NIFBULLET_BULLETNIFLOADER_HPP
|
|
|
|
#define OPENMW_COMPONENTS_NIFBULLET_BULLETNIFLOADER_HPP
|
2011-01-13 16:51:50 +00:00
|
|
|
|
2012-07-17 07:27:12 +00:00
|
|
|
#include <cassert>
|
2011-01-13 16:51:50 +00:00
|
|
|
#include <string>
|
2011-02-26 15:37:47 +00:00
|
|
|
#include <BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h>
|
|
|
|
#include <BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h>
|
2011-01-13 16:51:50 +00:00
|
|
|
#include <btBulletDynamicsCommon.h>
|
2013-03-08 22:46:25 +00:00
|
|
|
#include <openengine/bullet/BulletShapeLoader.h>
|
2011-01-13 16:51:50 +00:00
|
|
|
|
|
|
|
// For warning messages
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace Nif
|
|
|
|
{
|
|
|
|
class Node;
|
|
|
|
class Transformation;
|
|
|
|
class NiTriShape;
|
|
|
|
}
|
|
|
|
|
2011-06-19 16:45:23 +00:00
|
|
|
namespace NifBullet
|
|
|
|
{
|
2011-01-13 16:51:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*Load bulletShape from NIF files.
|
|
|
|
*/
|
2012-11-08 17:48:07 +00:00
|
|
|
class ManualBulletShapeLoader : public OEngine::Physic::BulletShapeLoader
|
2011-01-13 16:51:50 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-07-31 16:46:32 +00:00
|
|
|
ManualBulletShapeLoader()
|
|
|
|
: mShape(NULL)
|
|
|
|
, mBoundingBox(NULL)
|
|
|
|
, mHasShape(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-25 18:37:05 +00:00
|
|
|
virtual ~ManualBulletShapeLoader();
|
2011-01-13 16:51:50 +00:00
|
|
|
|
2013-02-20 04:35:52 +00:00
|
|
|
void warn(const std::string &msg)
|
2011-04-01 21:35:56 +00:00
|
|
|
{
|
|
|
|
std::cerr << "NIFLoader: Warn:" << msg << "\n";
|
|
|
|
}
|
2011-01-13 16:51:50 +00:00
|
|
|
|
2013-02-20 04:35:52 +00:00
|
|
|
void fail(const std::string &msg)
|
2011-04-01 21:35:56 +00:00
|
|
|
{
|
|
|
|
std::cerr << "NIFLoader: Fail: "<< msg << std::endl;
|
2013-02-20 04:35:52 +00:00
|
|
|
abort();
|
2011-04-01 21:35:56 +00:00
|
|
|
}
|
2011-01-13 16:51:50 +00:00
|
|
|
|
2011-04-01 21:35:56 +00:00
|
|
|
/**
|
|
|
|
*This function should not be called manualy. Use load instead. (this is called by the BulletShapeManager when you use load).
|
|
|
|
*/
|
|
|
|
void loadResource(Ogre::Resource *resource);
|
2011-01-13 16:51:50 +00:00
|
|
|
|
2011-04-01 21:35:56 +00:00
|
|
|
/**
|
|
|
|
*This function load a new bulletShape from a NIF file into the BulletShapeManager.
|
|
|
|
*When the file is loaded, you can then use BulletShapeManager::getByName() to retrive the bulletShape.
|
|
|
|
*Warning: this function will just crash if the resourceGroup doesn't exist!
|
|
|
|
*/
|
|
|
|
void load(const std::string &name,const std::string &group);
|
2011-01-13 16:51:50 +00:00
|
|
|
|
|
|
|
private:
|
2013-01-03 17:33:19 +00:00
|
|
|
btVector3 getbtVector(Ogre::Vector3 const &v);
|
2011-01-13 16:51:50 +00:00
|
|
|
|
2011-04-01 21:35:56 +00:00
|
|
|
/**
|
|
|
|
*Parse a node.
|
|
|
|
*/
|
2013-03-14 18:03:42 +00:00
|
|
|
void handleNode(btTriangleMesh* mesh, Nif::Node const *node, int flags, bool isCollisionNode, bool raycasting, bool isMarker);
|
2011-03-23 12:42:28 +00:00
|
|
|
|
|
|
|
/**
|
2012-06-06 20:29:44 +00:00
|
|
|
*Helper function
|
2011-03-23 12:42:28 +00:00
|
|
|
*/
|
2013-02-20 04:35:52 +00:00
|
|
|
bool hasRootCollisionNode(const Nif::Node *node);
|
2011-01-13 16:51:50 +00:00
|
|
|
|
2011-04-01 21:35:56 +00:00
|
|
|
/**
|
|
|
|
*convert a NiTriShape to a bullet trishape.
|
|
|
|
*/
|
2013-03-08 22:46:25 +00:00
|
|
|
void handleNiTriShape(btTriangleMesh* mesh, const Nif::NiTriShape *shape, int flags, const Ogre::Matrix4 &transform, bool raycasting);
|
2011-01-13 16:51:50 +00:00
|
|
|
|
2013-07-31 16:46:32 +00:00
|
|
|
std::string mResourceName;
|
2011-01-13 16:51:50 +00:00
|
|
|
|
2013-07-31 16:46:32 +00:00
|
|
|
OEngine::Physic::BulletShape* mShape;//current shape
|
2012-08-04 19:43:33 +00:00
|
|
|
btBoxShape *mBoundingBox;
|
2013-03-08 22:46:25 +00:00
|
|
|
|
|
|
|
bool mHasShape;
|
2011-01-13 16:51:50 +00:00
|
|
|
};
|
|
|
|
|
2011-06-19 16:45:23 +00:00
|
|
|
}
|
|
|
|
|
2011-01-13 16:51:50 +00:00
|
|
|
#endif
|