|
|
|
@ -25,11 +25,9 @@ http://www.gnu.org/licenses/ .
|
|
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <OgreMatrix4.h>
|
|
|
|
|
#include <components/misc/stringops.hpp>
|
|
|
|
|
|
|
|
|
|
#include <components/nifcache/nifcache.hpp>
|
|
|
|
|
|
|
|
|
|
#include "../nif/niffile.hpp"
|
|
|
|
|
#include "../nif/node.hpp"
|
|
|
|
|
#include "../nif/data.hpp"
|
|
|
|
@ -43,11 +41,6 @@ http://www.gnu.org/licenses/ .
|
|
|
|
|
// For warning messages
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
// float infinity
|
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
|
|
typedef unsigned char ubyte;
|
|
|
|
|
|
|
|
|
|
// Extract a list of keyframe-controlled nodes from a .kf file
|
|
|
|
|
// FIXME: this is a similar copy of OgreNifLoader::loadKf
|
|
|
|
|
void extractControlledNodes(Nif::NIFFilePtr kfFile, std::set<std::string>& controlled)
|
|
|
|
@ -116,14 +109,13 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
|
|
|
|
|
{
|
|
|
|
|
mShape = static_cast<OEngine::Physic::BulletShape *>(resource);
|
|
|
|
|
mResourceName = mShape->getName();
|
|
|
|
|
mShape->mCollide = false;
|
|
|
|
|
mBoundingBox = NULL;
|
|
|
|
|
mShape->mBoxTranslation = Ogre::Vector3(0,0,0);
|
|
|
|
|
mShape->mBoxRotation = Ogre::Quaternion::IDENTITY;
|
|
|
|
|
mShape->mBoxTranslation = osg::Vec3f(0,0,0);
|
|
|
|
|
mShape->mBoxRotation = osg::Quat();
|
|
|
|
|
mCompoundShape = NULL;
|
|
|
|
|
mStaticMesh = NULL;
|
|
|
|
|
|
|
|
|
|
Nif::NIFFilePtr pnif (Nif::Cache::getInstance().load(mResourceName.substr(0, mResourceName.length()-7)));
|
|
|
|
|
Nif::NIFFilePtr pnif;// (Nif::Cache::getInstance().load(mResourceName.substr(0, mResourceName.length()-7)));
|
|
|
|
|
Nif::NIFFile & nif = *pnif.get ();
|
|
|
|
|
if (nif.numRoots() < 1)
|
|
|
|
|
{
|
|
|
|
@ -140,7 +132,7 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
|
|
|
|
|
kfname.replace(kfname.size()-4, 4, ".kf");
|
|
|
|
|
if (Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(kfname))
|
|
|
|
|
{
|
|
|
|
|
Nif::NIFFilePtr kf (Nif::Cache::getInstance().load(kfname));
|
|
|
|
|
Nif::NIFFilePtr kf;// (Nif::Cache::getInstance().load(kfname));
|
|
|
|
|
extractControlledNodes(kf, mControlledNodes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -188,28 +180,6 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
|
|
|
|
|
else if (mStaticMesh)
|
|
|
|
|
mShape->mCollisionShape = new TriangleMeshShape(mStaticMesh,true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//second pass which create a shape for raycasting.
|
|
|
|
|
mResourceName = mShape->getName();
|
|
|
|
|
mShape->mCollide = false;
|
|
|
|
|
mBoundingBox = NULL;
|
|
|
|
|
mStaticMesh = NULL;
|
|
|
|
|
mCompoundShape = NULL;
|
|
|
|
|
|
|
|
|
|
handleNode(node,0,true,true,false);
|
|
|
|
|
|
|
|
|
|
if (mCompoundShape)
|
|
|
|
|
{
|
|
|
|
|
mShape->mRaycastingShape = mCompoundShape;
|
|
|
|
|
if (mStaticMesh)
|
|
|
|
|
{
|
|
|
|
|
btTransform trans;
|
|
|
|
|
trans.setIdentity();
|
|
|
|
|
mCompoundShape->addChildShape(trans, new TriangleMeshShape(mStaticMesh,true));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (mStaticMesh)
|
|
|
|
|
mShape->mRaycastingShape = new TriangleMeshShape(mStaticMesh,true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ManualBulletShapeLoader::hasAutoGeneratedCollision(Nif::Node const * rootNode)
|
|
|
|
@ -231,8 +201,7 @@ bool ManualBulletShapeLoader::hasAutoGeneratedCollision(Nif::Node const * rootNo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ManualBulletShapeLoader::handleNode(const Nif::Node *node, int flags,
|
|
|
|
|
bool isCollisionNode,
|
|
|
|
|
bool raycasting, bool isAnimated)
|
|
|
|
|
bool isCollisionNode, bool isAnimated)
|
|
|
|
|
{
|
|
|
|
|
// Accumulate the flags from all the child nodes. This works for all
|
|
|
|
|
// the flags we currently use, at least.
|
|
|
|
@ -245,10 +214,7 @@ void ManualBulletShapeLoader::handleNode(const Nif::Node *node, int flags,
|
|
|
|
|
if (mControlledNodes.find(node->name) != mControlledNodes.end())
|
|
|
|
|
isAnimated = true;
|
|
|
|
|
|
|
|
|
|
if (!raycasting)
|
|
|
|
|
isCollisionNode = isCollisionNode || (node->recType == Nif::RC_RootCollisionNode);
|
|
|
|
|
else
|
|
|
|
|
isCollisionNode = isCollisionNode && (node->recType != Nif::RC_RootCollisionNode);
|
|
|
|
|
|
|
|
|
|
// Don't collide with AvoidNode shapes
|
|
|
|
|
if(node->recType == Nif::RC_AvoidNode)
|
|
|
|
@ -274,33 +240,26 @@ void ManualBulletShapeLoader::handleNode(const Nif::Node *node, int flags,
|
|
|
|
|
// No collision. Use an internal flag setting to mark this.
|
|
|
|
|
flags |= 0x800;
|
|
|
|
|
}
|
|
|
|
|
else if (sd->string == "MRK" && !mShowMarkers && raycasting)
|
|
|
|
|
{
|
|
|
|
|
// Marker objects should be invisible, but still have collision.
|
|
|
|
|
// Except in the editor, the marker objects are visible.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isCollisionNode || (mShape->mAutogenerated && !raycasting))
|
|
|
|
|
if (isCollisionNode || (mShape->mAutogenerated))
|
|
|
|
|
{
|
|
|
|
|
// NOTE: a trishape with hasBounds=true, but no BBoxCollision flag should NOT go through handleNiTriShape!
|
|
|
|
|
// It must be ignored completely.
|
|
|
|
|
// (occurs in tr_ex_imp_wall_arch_04.nif)
|
|
|
|
|
if(node->hasBounds)
|
|
|
|
|
{
|
|
|
|
|
if (flags & Nif::NiNode::Flag_BBoxCollision && !raycasting)
|
|
|
|
|
if (flags & Nif::NiNode::Flag_BBoxCollision)
|
|
|
|
|
{
|
|
|
|
|
mShape->mBoxTranslation = node->boundPos;
|
|
|
|
|
mShape->mBoxRotation = node->boundRot;
|
|
|
|
|
mBoundingBox = new btBoxShape(getbtVector(node->boundXYZ));
|
|
|
|
|
//mShape->mBoxRotation = node->boundRot;
|
|
|
|
|
//mBoundingBox = new btBoxShape(getbtVector(node->boundXYZ));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(node->recType == Nif::RC_NiTriShape)
|
|
|
|
|
{
|
|
|
|
|
mShape->mCollide = !(flags&0x800);
|
|
|
|
|
handleNiTriShape(static_cast<const Nif::NiTriShape*>(node), flags, node->getWorldTransform(), raycasting, isAnimated);
|
|
|
|
|
handleNiTriShape(static_cast<const Nif::NiTriShape*>(node), flags, Ogre::Matrix4()/*node->getWorldTransform()*/, isAnimated);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -312,13 +271,12 @@ void ManualBulletShapeLoader::handleNode(const Nif::Node *node, int flags,
|
|
|
|
|
for(size_t i = 0;i < list.length();i++)
|
|
|
|
|
{
|
|
|
|
|
if(!list[i].empty())
|
|
|
|
|
handleNode(list[i].getPtr(), flags, isCollisionNode, raycasting, isAnimated);
|
|
|
|
|
handleNode(list[i].getPtr(), flags, isCollisionNode, isAnimated);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ManualBulletShapeLoader::handleNiTriShape(const Nif::NiTriShape *shape, int flags, const Ogre::Matrix4 &transform,
|
|
|
|
|
bool raycasting, bool isAnimated)
|
|
|
|
|
void ManualBulletShapeLoader::handleNiTriShape(const Nif::NiTriShape *shape, int flags, const Ogre::Matrix4 &transform, bool isAnimated)
|
|
|
|
|
{
|
|
|
|
|
assert(shape != NULL);
|
|
|
|
|
|
|
|
|
@ -329,12 +287,12 @@ void ManualBulletShapeLoader::handleNiTriShape(const Nif::NiTriShape *shape, int
|
|
|
|
|
|
|
|
|
|
// If the object was marked "NCO" earlier, it shouldn't collide with
|
|
|
|
|
// anything. So don't do anything.
|
|
|
|
|
if ((flags & 0x800) && !raycasting)
|
|
|
|
|
if ((flags & 0x800))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!collide && !bbcollide && hidden && !raycasting)
|
|
|
|
|
if (!collide && !bbcollide && hidden)
|
|
|
|
|
// This mesh apparently isn't being used for anything, so don't
|
|
|
|
|
// bother setting it up.
|
|
|
|
|
return;
|
|
|
|
@ -354,18 +312,18 @@ void ManualBulletShapeLoader::handleNiTriShape(const Nif::NiTriShape *shape, int
|
|
|
|
|
childMesh->preallocateVertices(data->vertices.size());
|
|
|
|
|
childMesh->preallocateIndices(data->triangles.size());
|
|
|
|
|
|
|
|
|
|
const std::vector<Ogre::Vector3> &vertices = data->vertices;
|
|
|
|
|
const std::vector<short> &triangles = data->triangles;
|
|
|
|
|
//const std::vector<osg::Vec3f> &vertices = data->vertices;
|
|
|
|
|
//const std::vector<unsigned short> &triangles = data->triangles;
|
|
|
|
|
|
|
|
|
|
for(size_t i = 0;i < data->triangles.size();i+=3)
|
|
|
|
|
{
|
|
|
|
|
Ogre::Vector3 b1 = vertices[triangles[i+0]];
|
|
|
|
|
Ogre::Vector3 b2 = vertices[triangles[i+1]];
|
|
|
|
|
Ogre::Vector3 b3 = vertices[triangles[i+2]];
|
|
|
|
|
childMesh->addTriangle(btVector3(b1.x,b1.y,b1.z),btVector3(b2.x,b2.y,b2.z),btVector3(b3.x,b3.y,b3.z));
|
|
|
|
|
//Ogre::Vector3 b1 = vertices[triangles[i+0]];
|
|
|
|
|
//Ogre::Vector3 b2 = vertices[triangles[i+1]];
|
|
|
|
|
//Ogre::Vector3 b3 = vertices[triangles[i+2]];
|
|
|
|
|
//childMesh->addTriangle(btVector3(b1.x,b1.y,b1.z),btVector3(b2.x,b2.y,b2.z),btVector3(b3.x,b3.y,b3.z));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TriangleMeshShape* childShape = new TriangleMeshShape(childMesh,true);
|
|
|
|
|
//TriangleMeshShape* childShape = new TriangleMeshShape(childMesh,true);
|
|
|
|
|
|
|
|
|
|
float scale = shape->trafo.scale;
|
|
|
|
|
const Nif::Node* parent = shape;
|
|
|
|
@ -374,18 +332,15 @@ void ManualBulletShapeLoader::handleNiTriShape(const Nif::NiTriShape *shape, int
|
|
|
|
|
parent = parent->parent;
|
|
|
|
|
scale *= parent->trafo.scale;
|
|
|
|
|
}
|
|
|
|
|
Ogre::Quaternion q = transform.extractQuaternion();
|
|
|
|
|
Ogre::Vector3 v = transform.getTrans();
|
|
|
|
|
childShape->setLocalScaling(btVector3(scale, scale, scale));
|
|
|
|
|
//Ogre::Quaternion q = transform.extractQuaternion();
|
|
|
|
|
//Ogre::Vector3 v = transform.getTrans();
|
|
|
|
|
//childShape->setLocalScaling(btVector3(scale, scale, scale));
|
|
|
|
|
|
|
|
|
|
btTransform trans(btQuaternion(q.x, q.y, q.z, q.w), btVector3(v.x, v.y, v.z));
|
|
|
|
|
//btTransform trans(btQuaternion(q.x, q.y, q.z, q.w), btVector3(v.x, v.y, v.z));
|
|
|
|
|
|
|
|
|
|
if (raycasting)
|
|
|
|
|
mShape->mAnimatedRaycastingShapes.insert(std::make_pair(shape->recIndex, mCompoundShape->getNumChildShapes()));
|
|
|
|
|
else
|
|
|
|
|
mShape->mAnimatedShapes.insert(std::make_pair(shape->recIndex, mCompoundShape->getNumChildShapes()));
|
|
|
|
|
//mShape->mAnimatedShapes.insert(std::make_pair(shape->recIndex, mCompoundShape->getNumChildShapes()));
|
|
|
|
|
|
|
|
|
|
mCompoundShape->addChildShape(trans, childShape);
|
|
|
|
|
//mCompoundShape->addChildShape(trans, childShape);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -394,15 +349,17 @@ void ManualBulletShapeLoader::handleNiTriShape(const Nif::NiTriShape *shape, int
|
|
|
|
|
|
|
|
|
|
// Static shape, just transform all vertices into position
|
|
|
|
|
const Nif::NiTriShapeData *data = shape->data.getPtr();
|
|
|
|
|
const std::vector<Ogre::Vector3> &vertices = data->vertices;
|
|
|
|
|
const std::vector<short> &triangles = data->triangles;
|
|
|
|
|
//const std::vector<osg::Vec3f> &vertices = data->vertices;
|
|
|
|
|
//const std::vector<unsigned short> &triangles = data->triangles;
|
|
|
|
|
|
|
|
|
|
for(size_t i = 0;i < data->triangles.size();i+=3)
|
|
|
|
|
{
|
|
|
|
|
Ogre::Vector3 b1 = transform*vertices[triangles[i+0]];
|
|
|
|
|
Ogre::Vector3 b2 = transform*vertices[triangles[i+1]];
|
|
|
|
|
Ogre::Vector3 b3 = transform*vertices[triangles[i+2]];
|
|
|
|
|
/*
|
|
|
|
|
osg::Vec3f b1 = transform*vertices[triangles[i+0]];
|
|
|
|
|
osg::Vec3f b2 = transform*vertices[triangles[i+1]];
|
|
|
|
|
osg::Vec3f b3 = transform*vertices[triangles[i+2]];
|
|
|
|
|
mStaticMesh->addTriangle(btVector3(b1.x,b1.y,b1.z),btVector3(b2.x,b2.y,b2.z),btVector3(b3.x,b3.y,b3.z));
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -422,9 +379,9 @@ bool findBoundingBox (const Nif::Node* node, Ogre::Vector3& halfExtents, Ogre::V
|
|
|
|
|
{
|
|
|
|
|
if (!(node->flags & Nif::NiNode::Flag_Hidden))
|
|
|
|
|
{
|
|
|
|
|
translation = node->boundPos;
|
|
|
|
|
orientation = node->boundRot;
|
|
|
|
|
halfExtents = node->boundXYZ;
|
|
|
|
|
//translation = node->boundPos;
|
|
|
|
|
//orientation = node->boundRot;
|
|
|
|
|
//halfExtents = node->boundXYZ;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -445,7 +402,7 @@ bool findBoundingBox (const Nif::Node* node, Ogre::Vector3& halfExtents, Ogre::V
|
|
|
|
|
|
|
|
|
|
bool getBoundingBox(const std::string& nifFile, Ogre::Vector3& halfExtents, Ogre::Vector3& translation, Ogre::Quaternion& orientation)
|
|
|
|
|
{
|
|
|
|
|
Nif::NIFFilePtr pnif (Nif::Cache::getInstance().load(nifFile));
|
|
|
|
|
Nif::NIFFilePtr pnif;// (Nif::Cache::getInstance().load(nifFile));
|
|
|
|
|
Nif::NIFFile & nif = *pnif.get ();
|
|
|
|
|
|
|
|
|
|
if (nif.numRoots() < 1)
|
|
|
|
|