1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 16:19:54 +00:00
openmw-tes3mp/components/nifbullet/bulletnifloader.hpp
2015-05-09 01:06:55 +02:00

139 lines
3.6 KiB
C++

/*
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/ .
*/
#ifndef OPENMW_COMPONENTS_NIFBULLET_BULLETNIFLOADER_HPP
#define OPENMW_COMPONENTS_NIFBULLET_BULLETNIFLOADER_HPP
#include <cassert>
#include <string>
#include <BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h>
#include <BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h>
#include <BulletCollision/CollisionShapes/btCompoundShape.h>
#include <btBulletDynamicsCommon.h>
#include <openengine/bullet/BulletShapeLoader.h>
#include <osg/Matrixf>
// For warning messages
#include <iostream>
namespace Nif
{
class Node;
struct Transformation;
struct NiTriShape;
}
namespace NifBullet
{
// Subclass btBhvTriangleMeshShape to auto-delete the meshInterface
struct TriangleMeshShape : public btBvhTriangleMeshShape
{
TriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression)
: btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression)
{
}
virtual ~TriangleMeshShape()
{
delete getTriangleInfoMap();
delete m_meshInterface;
}
};
/**
*Load bulletShape from NIF files.
*/
class ManualBulletShapeLoader
{
public:
ManualBulletShapeLoader(bool showMarkers=false)
: mShape(NULL)
, mCompoundShape(NULL)
, mStaticMesh(NULL)
, mBoundingBox(NULL)
, mShowMarkers(showMarkers)
{
}
virtual ~ManualBulletShapeLoader();
void warn(const std::string &msg)
{
std::cerr << "NIFLoader: Warn:" << msg << "\n";
}
void fail(const std::string &msg)
{
std::cerr << "NIFLoader: Fail: "<< msg << std::endl;
abort();
}
/**
*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);
private:
btVector3 getbtVector(Ogre::Vector3 const &v);
/**
*Parse a node.
*/
void handleNode(Nif::Node const *node, int flags, bool isCollisionNode, bool isAnimated=false);
/**
*Helper function
*/
bool hasAutoGeneratedCollision(const Nif::Node *rootNode);
/**
*convert a NiTriShape to a bullet trishape.
*/
void handleNiTriShape(const Nif::NiTriShape *shape, int flags, const osg::Matrixf& transform, bool isAnimated);
std::string mResourceName;
OEngine::Physic::BulletShape* mShape;//current shape
btCompoundShape* mCompoundShape;
btTriangleMesh* mStaticMesh;
btBoxShape *mBoundingBox;
std::set<std::string> mControlledNodes;
bool mShowMarkers;
};
bool getBoundingBox(const std::string& nifFile, Ogre::Vector3& halfExtents, Ogre::Vector3& translation, Ogre::Quaternion& orientation);
bool findBoundingBox(const Nif::Node* node, Ogre::Vector3& halfExtents, Ogre::Vector3& translation, Ogre::Quaternion& orientation);
}
#endif