2022-09-18 12:57:03 +00:00
|
|
|
#include "../nif/node.hpp"
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
#include <components/bullethelpers/processtrianglecallback.hpp>
|
2022-07-21 11:51:34 +00:00
|
|
|
#include <components/nif/data.hpp>
|
|
|
|
#include <components/nif/extra.hpp>
|
2018-07-08 19:22:34 +00:00
|
|
|
#include <components/nif/node.hpp>
|
|
|
|
#include <components/nifbullet/bulletnifloader.hpp>
|
|
|
|
|
|
|
|
#include <BulletCollision/CollisionShapes/btBoxShape.h>
|
|
|
|
#include <BulletCollision/CollisionShapes/btCompoundShape.h>
|
|
|
|
#include <BulletCollision/CollisionShapes/btTriangleMesh.h>
|
|
|
|
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2018-11-25 08:46:09 +00:00
|
|
|
#include <algorithm>
|
2023-03-30 19:41:40 +00:00
|
|
|
#include <span>
|
2022-08-24 22:14:17 +00:00
|
|
|
#include <type_traits>
|
2018-11-25 08:46:09 +00:00
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
template <class T>
|
|
|
|
bool compareObjects(const T* lhs, const T* rhs)
|
|
|
|
{
|
|
|
|
return (!lhs && !rhs) || (lhs && rhs && *lhs == *rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<btVector3> getTriangles(const btBvhTriangleMeshShape& shape)
|
|
|
|
{
|
|
|
|
std::vector<btVector3> result;
|
|
|
|
auto callback = BulletHelpers::makeProcessTriangleCallback([&](btVector3* triangle, int, int) {
|
|
|
|
for (std::size_t i = 0; i < 3; ++i)
|
|
|
|
result.push_back(triangle[i]);
|
|
|
|
});
|
|
|
|
btVector3 aabbMin;
|
|
|
|
btVector3 aabbMax;
|
|
|
|
shape.getAabb(btTransform::getIdentity(), aabbMin, aabbMax);
|
|
|
|
shape.processAllTriangles(&callback, aabbMin, aabbMax);
|
|
|
|
return result;
|
|
|
|
}
|
2018-11-25 08:46:09 +00:00
|
|
|
|
|
|
|
bool isNear(btScalar lhs, btScalar rhs)
|
|
|
|
{
|
|
|
|
return std::abs(lhs - rhs) <= 1e-5;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isNear(const btVector3& lhs, const btVector3& rhs)
|
|
|
|
{
|
|
|
|
return std::equal(static_cast<const btScalar*>(lhs), static_cast<const btScalar*>(lhs) + 3,
|
|
|
|
static_cast<const btScalar*>(rhs), [](btScalar lhs, btScalar rhs) { return isNear(lhs, rhs); });
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isNear(const btMatrix3x3& lhs, const btMatrix3x3& rhs)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
if (!isNear(lhs[i], rhs[i]))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isNear(const btTransform& lhs, const btTransform& rhs)
|
|
|
|
{
|
|
|
|
return isNear(lhs.getOrigin(), rhs.getOrigin()) && isNear(lhs.getBasis(), rhs.getBasis());
|
|
|
|
}
|
2021-10-31 14:19:19 +00:00
|
|
|
|
2023-03-30 19:41:40 +00:00
|
|
|
bool isNear(std::span<const btVector3> lhs, std::span<const btVector3> rhs)
|
|
|
|
{
|
|
|
|
if (lhs.size() != rhs.size())
|
|
|
|
return false;
|
|
|
|
return std::equal(
|
|
|
|
lhs.begin(), lhs.end(), rhs.begin(), [](const btVector3& l, const btVector3& r) { return isNear(l, r); });
|
|
|
|
}
|
|
|
|
|
2021-10-31 14:19:19 +00:00
|
|
|
struct WriteVec3f
|
|
|
|
{
|
|
|
|
osg::Vec3f mValue;
|
|
|
|
|
|
|
|
friend std::ostream& operator<<(std::ostream& stream, const WriteVec3f& value)
|
|
|
|
{
|
|
|
|
return stream << "osg::Vec3f {" << std::setprecision(std::numeric_limits<float>::max_exponent10)
|
|
|
|
<< value.mValue.x() << ", " << std::setprecision(std::numeric_limits<float>::max_exponent10)
|
|
|
|
<< value.mValue.y() << ", " << std::setprecision(std::numeric_limits<float>::max_exponent10)
|
|
|
|
<< value.mValue.z() << "}";
|
|
|
|
}
|
|
|
|
};
|
2018-07-08 19:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static std::ostream& operator<<(std::ostream& stream, const btVector3& value)
|
|
|
|
{
|
|
|
|
return stream << "btVector3 {" << std::setprecision(std::numeric_limits<float>::max_exponent10) << value.getX()
|
|
|
|
<< ", " << std::setprecision(std::numeric_limits<float>::max_exponent10) << value.getY() << ", "
|
|
|
|
<< std::setprecision(std::numeric_limits<float>::max_exponent10) << value.getZ() << "}";
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::ostream& operator<<(std::ostream& stream, const btMatrix3x3& value)
|
|
|
|
{
|
|
|
|
stream << "btMatrix3x3 {";
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
stream << value.getRow(i) << ", ";
|
|
|
|
return stream << "}";
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::ostream& operator<<(std::ostream& stream, const btTransform& value)
|
|
|
|
{
|
|
|
|
return stream << "btTransform {" << value.getBasis() << ", " << value.getOrigin() << "}";
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::ostream& operator<<(std::ostream& stream, const btCollisionShape* value);
|
|
|
|
|
|
|
|
static std::ostream& operator<<(std::ostream& stream, const btCompoundShape& value)
|
|
|
|
{
|
|
|
|
stream << "btCompoundShape {" << value.getLocalScaling() << ", ";
|
|
|
|
stream << "{";
|
|
|
|
for (int i = 0; i < value.getNumChildShapes(); ++i)
|
|
|
|
stream << value.getChildShape(i) << ", ";
|
|
|
|
stream << "},";
|
|
|
|
stream << "{";
|
|
|
|
for (int i = 0; i < value.getNumChildShapes(); ++i)
|
|
|
|
stream << value.getChildTransform(i) << ", ";
|
|
|
|
stream << "}";
|
|
|
|
return stream << "}";
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::ostream& operator<<(std::ostream& stream, const btBoxShape& value)
|
|
|
|
{
|
|
|
|
return stream << "btBoxShape {" << value.getLocalScaling() << ", " << value.getHalfExtentsWithoutMargin() << "}";
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Resource
|
|
|
|
{
|
|
|
|
|
|
|
|
static std::ostream& operator<<(std::ostream& stream, const TriangleMeshShape& value)
|
|
|
|
{
|
|
|
|
stream << "Resource::TriangleMeshShape {" << value.getLocalScaling() << ", "
|
|
|
|
<< value.usesQuantizedAabbCompression() << ", " << value.getOwnsBvh() << ", {";
|
|
|
|
auto callback = BulletHelpers::makeProcessTriangleCallback([&](btVector3* triangle, int, int) {
|
|
|
|
for (std::size_t i = 0; i < 3; ++i)
|
|
|
|
stream << triangle[i] << ", ";
|
|
|
|
});
|
|
|
|
btVector3 aabbMin;
|
|
|
|
btVector3 aabbMax;
|
|
|
|
value.getAabb(btTransform::getIdentity(), aabbMin, aabbMax);
|
|
|
|
value.processAllTriangles(&callback, aabbMin, aabbMax);
|
|
|
|
return stream << "}}";
|
|
|
|
}
|
|
|
|
|
2022-08-24 22:14:17 +00:00
|
|
|
static bool operator==(const CollisionBox& l, const CollisionBox& r)
|
2021-10-31 14:19:19 +00:00
|
|
|
{
|
2022-08-24 22:14:17 +00:00
|
|
|
const auto tie = [](const CollisionBox& v) { return std::tie(v.mExtents, v.mCenter); };
|
2021-10-31 14:19:19 +00:00
|
|
|
return tie(l) == tie(r);
|
|
|
|
}
|
|
|
|
|
2022-08-24 22:14:17 +00:00
|
|
|
static std::ostream& operator<<(std::ostream& stream, const CollisionBox& value)
|
2021-10-31 14:19:19 +00:00
|
|
|
{
|
|
|
|
return stream << "CollisionBox {" << WriteVec3f{ value.mExtents } << ", " << WriteVec3f{ value.mCenter } << "}";
|
|
|
|
}
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static std::ostream& operator<<(std::ostream& stream, const btCollisionShape& value)
|
|
|
|
{
|
|
|
|
switch (value.getShapeType())
|
|
|
|
{
|
|
|
|
case COMPOUND_SHAPE_PROXYTYPE:
|
|
|
|
return stream << static_cast<const btCompoundShape&>(value);
|
|
|
|
case BOX_SHAPE_PROXYTYPE:
|
|
|
|
return stream << static_cast<const btBoxShape&>(value);
|
|
|
|
case TRIANGLE_MESH_SHAPE_PROXYTYPE:
|
|
|
|
if (const auto casted = dynamic_cast<const Resource::TriangleMeshShape*>(&value))
|
|
|
|
return stream << *casted;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return stream << "btCollisionShape {" << value.getShapeType() << "}";
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::ostream& operator<<(std::ostream& stream, const btCollisionShape* value)
|
|
|
|
{
|
|
|
|
return value ? stream << "&" << *value : stream << "nullptr";
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
static std::ostream& operator<<(std::ostream& stream, const map<int, int>& value)
|
|
|
|
{
|
|
|
|
stream << "std::map<int, int> {";
|
|
|
|
for (const auto& v : value)
|
|
|
|
stream << "{" << v.first << ", " << v.second << "},";
|
|
|
|
return stream << "}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Resource
|
|
|
|
{
|
|
|
|
static bool operator==(const Resource::BulletShape& lhs, const Resource::BulletShape& rhs)
|
|
|
|
{
|
2021-10-30 01:06:22 +00:00
|
|
|
return compareObjects(lhs.mCollisionShape.get(), rhs.mCollisionShape.get())
|
|
|
|
&& compareObjects(lhs.mAvoidCollisionShape.get(), rhs.mAvoidCollisionShape.get())
|
2022-08-24 22:14:17 +00:00
|
|
|
&& lhs.mCollisionBox == rhs.mCollisionBox && lhs.mVisualCollisionType == rhs.mVisualCollisionType
|
2018-07-08 19:22:34 +00:00
|
|
|
&& lhs.mAnimatedShapes == rhs.mAnimatedShapes;
|
|
|
|
}
|
|
|
|
|
2022-08-24 22:14:17 +00:00
|
|
|
static std::ostream& operator<<(std::ostream& stream, Resource::VisualCollisionType value)
|
|
|
|
{
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case Resource::VisualCollisionType::None:
|
|
|
|
return stream << "Resource::VisualCollisionType::None";
|
|
|
|
case Resource::VisualCollisionType::Default:
|
|
|
|
return stream << "Resource::VisualCollisionType::Default";
|
|
|
|
case Resource::VisualCollisionType::Camera:
|
|
|
|
return stream << "Resource::VisualCollisionType::Camera";
|
|
|
|
}
|
|
|
|
return stream << static_cast<std::underlying_type_t<Resource::VisualCollisionType>>(value);
|
|
|
|
}
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
static std::ostream& operator<<(std::ostream& stream, const Resource::BulletShape& value)
|
|
|
|
{
|
|
|
|
return stream << "Resource::BulletShape {" << value.mCollisionShape.get() << ", "
|
2021-10-30 01:06:22 +00:00
|
|
|
<< value.mAvoidCollisionShape.get() << ", " << value.mCollisionBox << ", "
|
2022-08-24 22:14:17 +00:00
|
|
|
<< value.mAnimatedShapes << ", " << value.mVisualCollisionType << "}";
|
2018-07-08 19:22:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool operator==(const btCollisionShape& lhs, const btCollisionShape& rhs);
|
|
|
|
|
|
|
|
static bool operator==(const btCompoundShape& lhs, const btCompoundShape& rhs)
|
|
|
|
{
|
|
|
|
if (lhs.getNumChildShapes() != rhs.getNumChildShapes() || lhs.getLocalScaling() != rhs.getLocalScaling())
|
|
|
|
return false;
|
|
|
|
for (int i = 0; i < lhs.getNumChildShapes(); ++i)
|
|
|
|
{
|
|
|
|
if (!compareObjects(lhs.getChildShape(i), rhs.getChildShape(i))
|
2018-11-25 08:46:09 +00:00
|
|
|
|| !isNear(lhs.getChildTransform(i), rhs.getChildTransform(i)))
|
2018-07-08 19:22:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool operator==(const btBoxShape& lhs, const btBoxShape& rhs)
|
|
|
|
{
|
2018-11-25 08:46:09 +00:00
|
|
|
return isNear(lhs.getLocalScaling(), rhs.getLocalScaling())
|
2018-07-08 19:22:34 +00:00
|
|
|
&& lhs.getHalfExtentsWithoutMargin() == rhs.getHalfExtentsWithoutMargin();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool operator==(const btBvhTriangleMeshShape& lhs, const btBvhTriangleMeshShape& rhs)
|
|
|
|
{
|
2018-11-25 08:46:09 +00:00
|
|
|
return isNear(lhs.getLocalScaling(), rhs.getLocalScaling())
|
2018-07-08 19:22:34 +00:00
|
|
|
&& lhs.usesQuantizedAabbCompression() == rhs.usesQuantizedAabbCompression()
|
2023-03-30 19:41:40 +00:00
|
|
|
&& lhs.getOwnsBvh() == rhs.getOwnsBvh() && isNear(getTriangles(lhs), getTriangles(rhs));
|
2018-07-08 19:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool operator==(const btCollisionShape& lhs, const btCollisionShape& rhs)
|
|
|
|
{
|
|
|
|
if (lhs.getShapeType() != rhs.getShapeType())
|
|
|
|
return false;
|
|
|
|
switch (lhs.getShapeType())
|
|
|
|
{
|
|
|
|
case COMPOUND_SHAPE_PROXYTYPE:
|
|
|
|
return static_cast<const btCompoundShape&>(lhs) == static_cast<const btCompoundShape&>(rhs);
|
|
|
|
case BOX_SHAPE_PROXYTYPE:
|
|
|
|
return static_cast<const btBoxShape&>(lhs) == static_cast<const btBoxShape&>(rhs);
|
|
|
|
case TRIANGLE_MESH_SHAPE_PROXYTYPE:
|
|
|
|
if (const auto lhsCasted = dynamic_cast<const Resource::TriangleMeshShape*>(&lhs))
|
|
|
|
if (const auto rhsCasted = dynamic_cast<const Resource::TriangleMeshShape*>(&rhs))
|
|
|
|
return *lhsCasted == *rhsCasted;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using namespace testing;
|
2022-09-18 12:57:03 +00:00
|
|
|
using namespace Nif::Testing;
|
2018-07-08 19:22:34 +00:00
|
|
|
using NifBullet::BulletNifLoader;
|
|
|
|
|
2018-09-30 22:33:25 +00:00
|
|
|
void copy(const btTransform& src, Nif::Transformation& dst)
|
|
|
|
{
|
2018-07-08 19:22:34 +00:00
|
|
|
dst.pos = osg::Vec3f(src.getOrigin().x(), src.getOrigin().y(), src.getOrigin().z());
|
|
|
|
for (int row = 0; row < 3; ++row)
|
|
|
|
for (int column = 0; column < 3; ++column)
|
2023-03-08 11:17:45 +00:00
|
|
|
dst.rotation.mValues[row][column] = src.getBasis().getRow(row)[column];
|
2018-07-08 19:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct TestBulletNifLoader : Test
|
|
|
|
{
|
|
|
|
BulletNifLoader mLoader;
|
|
|
|
Nif::Node mNode;
|
|
|
|
Nif::Node mNode2;
|
|
|
|
Nif::NiNode mNiNode;
|
|
|
|
Nif::NiNode mNiNode2;
|
|
|
|
Nif::NiNode mNiNode3;
|
|
|
|
Nif::NiTriShapeData mNiTriShapeData;
|
|
|
|
Nif::NiTriShape mNiTriShape;
|
|
|
|
Nif::NiTriShapeData mNiTriShapeData2;
|
|
|
|
Nif::NiTriShape mNiTriShape2;
|
2021-10-31 14:19:19 +00:00
|
|
|
Nif::NiTriStripsData mNiTriStripsData;
|
|
|
|
Nif::NiTriStrips mNiTriStrips;
|
2018-07-08 19:22:34 +00:00
|
|
|
Nif::NiSkinInstance mNiSkinInstance;
|
|
|
|
Nif::NiStringExtraData mNiStringExtraData;
|
|
|
|
Nif::NiStringExtraData mNiStringExtraData2;
|
2023-05-24 01:27:13 +00:00
|
|
|
Nif::NiIntegerExtraData mNiIntegerExtraData;
|
2018-07-08 19:22:34 +00:00
|
|
|
Nif::Controller mController;
|
|
|
|
btTransform mTransform{ btMatrix3x3(btQuaternion(btVector3(1, 0, 0), 0.5f)), btVector3(1, 2, 3) };
|
2023-03-08 11:17:45 +00:00
|
|
|
btTransform mTransformScale2{ btMatrix3x3(btQuaternion(btVector3(1, 0, 0), 0.5f)), btVector3(2, 4, 6) };
|
|
|
|
btTransform mTransformScale3{ btMatrix3x3(btQuaternion(btVector3(1, 0, 0), 0.5f)), btVector3(3, 6, 9) };
|
|
|
|
btTransform mTransformScale4{ btMatrix3x3(btQuaternion(btVector3(1, 0, 0), 0.5f)), btVector3(4, 8, 12) };
|
2021-11-15 16:40:22 +00:00
|
|
|
const std::string mHash = "hash";
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
TestBulletNifLoader()
|
|
|
|
{
|
|
|
|
init(mNode);
|
|
|
|
init(mNode2);
|
|
|
|
init(mNiNode);
|
|
|
|
init(mNiNode2);
|
|
|
|
init(mNiNode3);
|
|
|
|
init(mNiTriShape);
|
|
|
|
init(mNiTriShape2);
|
2021-10-31 14:19:19 +00:00
|
|
|
init(mNiTriStrips);
|
2018-07-08 19:22:34 +00:00
|
|
|
init(mNiSkinInstance);
|
|
|
|
init(mNiStringExtraData);
|
|
|
|
init(mNiStringExtraData2);
|
|
|
|
init(mController);
|
|
|
|
|
2020-12-13 00:16:05 +00:00
|
|
|
mNiTriShapeData.recType = Nif::RC_NiTriShapeData;
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiTriShapeData.vertices = { osg::Vec3f(0, 0, 0), osg::Vec3f(1, 0, 0), osg::Vec3f(1, 1, 0) };
|
2023-03-08 01:24:52 +00:00
|
|
|
mNiTriShapeData.mNumTriangles = 1;
|
2023-09-04 21:08:28 +00:00
|
|
|
mNiTriShapeData.mTriangles = { 0, 1, 2 };
|
2023-08-03 19:55:06 +00:00
|
|
|
mNiTriShape.data = Nif::NiGeometryDataPtr(&mNiTriShapeData);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
2020-12-13 00:16:05 +00:00
|
|
|
mNiTriShapeData2.recType = Nif::RC_NiTriShapeData;
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiTriShapeData2.vertices = { osg::Vec3f(0, 0, 1), osg::Vec3f(1, 0, 1), osg::Vec3f(1, 1, 1) };
|
2023-03-08 01:24:52 +00:00
|
|
|
mNiTriShapeData2.mNumTriangles = 1;
|
2023-09-04 21:08:28 +00:00
|
|
|
mNiTriShapeData2.mTriangles = { 0, 1, 2 };
|
2023-08-03 19:55:06 +00:00
|
|
|
mNiTriShape2.data = Nif::NiGeometryDataPtr(&mNiTriShapeData2);
|
2021-10-31 14:19:19 +00:00
|
|
|
|
|
|
|
mNiTriStripsData.recType = Nif::RC_NiTriStripsData;
|
|
|
|
mNiTriStripsData.vertices
|
|
|
|
= { osg::Vec3f(0, 0, 0), osg::Vec3f(1, 0, 0), osg::Vec3f(1, 1, 0), osg::Vec3f(0, 1, 0) };
|
2023-03-08 01:24:52 +00:00
|
|
|
mNiTriStripsData.mNumTriangles = 2;
|
2023-09-03 14:41:52 +00:00
|
|
|
mNiTriStripsData.mStrips = { { 0, 1, 2, 3 } };
|
2023-08-03 19:55:06 +00:00
|
|
|
mNiTriStrips.data = Nif::NiGeometryDataPtr(&mNiTriStripsData);
|
2018-07-08 19:22:34 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader, for_zero_num_roots_should_return_default)
|
|
|
|
{
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
2021-11-10 19:24:17 +00:00
|
|
|
EXPECT_EQ(result->mFileName, "test.nif");
|
|
|
|
EXPECT_EQ(result->mFileHash, mHash);
|
2018-07-08 19:22:34 +00:00
|
|
|
}
|
|
|
|
|
2021-10-31 14:19:19 +00:00
|
|
|
TEST_F(TestBulletNifLoader, should_ignore_nullptr_root)
|
|
|
|
{
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(nullptr);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2021-10-31 14:19:19 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
TEST_F(TestBulletNifLoader, for_default_root_nif_node_should_return_default)
|
|
|
|
{
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader, for_default_root_collision_node_nif_node_should_return_default)
|
|
|
|
{
|
|
|
|
mNode.recType = Nif::RC_RootCollisionNode;
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader, for_default_root_nif_node_and_filename_starting_with_x_should_return_default)
|
|
|
|
{
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("xtest.nif");
|
|
|
|
file.mRoots.push_back(&mNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(
|
|
|
|
TestBulletNifLoader, for_root_nif_node_with_bounding_box_should_return_shape_with_compound_shape_and_box_inside)
|
|
|
|
{
|
|
|
|
mNode.hasBounds = true;
|
2022-06-21 21:43:16 +00:00
|
|
|
mNode.flags |= Nif::Node::Flag_BBoxCollision;
|
2020-11-14 00:42:15 +00:00
|
|
|
mNode.bounds.type = Nif::NiBoundingVolume::Type::BOX_BV;
|
|
|
|
mNode.bounds.box.extents = osg::Vec3f(1, 2, 3);
|
|
|
|
mNode.bounds.box.center = osg::Vec3f(-1, -2, -3);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
2021-10-27 23:43:25 +00:00
|
|
|
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
|
|
|
|
expected.mCollisionBox.mCenter = osg::Vec3f(-1, -2, -3);
|
2018-07-08 19:22:34 +00:00
|
|
|
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(1, 2, 3)));
|
|
|
|
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
|
|
|
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-1, -2, -3)), box.release());
|
2021-10-30 01:06:22 +00:00
|
|
|
expected.mCollisionShape.reset(shape.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader, for_child_nif_node_with_bounding_box)
|
|
|
|
{
|
|
|
|
mNode.hasBounds = true;
|
2022-06-21 21:43:16 +00:00
|
|
|
mNode.flags |= Nif::Node::Flag_BBoxCollision;
|
2020-11-14 00:42:15 +00:00
|
|
|
mNode.bounds.type = Nif::NiBoundingVolume::Type::BOX_BV;
|
|
|
|
mNode.bounds.box.extents = osg::Vec3f(1, 2, 3);
|
|
|
|
mNode.bounds.box.center = osg::Vec3f(-1, -2, -3);
|
2022-01-21 23:15:56 +00:00
|
|
|
mNode.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNode) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
2021-10-27 23:43:25 +00:00
|
|
|
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
|
|
|
|
expected.mCollisionBox.mCenter = osg::Vec3f(-1, -2, -3);
|
2018-07-08 19:22:34 +00:00
|
|
|
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(1, 2, 3)));
|
|
|
|
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
|
|
|
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-1, -2, -3)), box.release());
|
2021-10-30 01:06:22 +00:00
|
|
|
expected.mCollisionShape.reset(shape.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader,
|
|
|
|
for_root_and_child_nif_node_with_bounding_box_but_root_without_flag_should_use_child_bounds)
|
|
|
|
{
|
|
|
|
mNode.hasBounds = true;
|
2022-06-21 21:43:16 +00:00
|
|
|
mNode.flags |= Nif::Node::Flag_BBoxCollision;
|
2020-11-14 00:42:15 +00:00
|
|
|
mNode.bounds.type = Nif::NiBoundingVolume::Type::BOX_BV;
|
|
|
|
mNode.bounds.box.extents = osg::Vec3f(1, 2, 3);
|
|
|
|
mNode.bounds.box.center = osg::Vec3f(-1, -2, -3);
|
2022-01-21 23:15:56 +00:00
|
|
|
mNode.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
mNiNode.hasBounds = true;
|
2020-11-14 00:42:15 +00:00
|
|
|
mNiNode.bounds.type = Nif::NiBoundingVolume::Type::BOX_BV;
|
|
|
|
mNiNode.bounds.box.extents = osg::Vec3f(4, 5, 6);
|
|
|
|
mNiNode.bounds.box.center = osg::Vec3f(-4, -5, -6);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNode) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
2021-10-27 23:43:25 +00:00
|
|
|
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
|
|
|
|
expected.mCollisionBox.mCenter = osg::Vec3f(-1, -2, -3);
|
2018-07-08 19:22:34 +00:00
|
|
|
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(1, 2, 3)));
|
|
|
|
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
|
|
|
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-1, -2, -3)), box.release());
|
2021-10-30 01:06:22 +00:00
|
|
|
expected.mCollisionShape.reset(shape.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader,
|
|
|
|
for_root_and_two_children_where_both_with_bounds_but_only_first_with_flag_should_use_first_bounds)
|
|
|
|
{
|
|
|
|
mNode.hasBounds = true;
|
2022-06-21 21:43:16 +00:00
|
|
|
mNode.flags |= Nif::Node::Flag_BBoxCollision;
|
2020-11-14 00:42:15 +00:00
|
|
|
mNode.bounds.type = Nif::NiBoundingVolume::Type::BOX_BV;
|
|
|
|
mNode.bounds.box.extents = osg::Vec3f(1, 2, 3);
|
|
|
|
mNode.bounds.box.center = osg::Vec3f(-1, -2, -3);
|
2022-01-21 23:15:56 +00:00
|
|
|
mNode.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
mNode2.hasBounds = true;
|
2020-11-14 00:42:15 +00:00
|
|
|
mNode2.bounds.type = Nif::NiBoundingVolume::Type::BOX_BV;
|
|
|
|
mNode2.bounds.box.extents = osg::Vec3f(4, 5, 6);
|
|
|
|
mNode2.bounds.box.center = osg::Vec3f(-4, -5, -6);
|
2022-01-21 23:15:56 +00:00
|
|
|
mNode2.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
mNiNode.hasBounds = true;
|
2020-11-14 00:42:15 +00:00
|
|
|
mNiNode.bounds.type = Nif::NiBoundingVolume::Type::BOX_BV;
|
|
|
|
mNiNode.bounds.box.extents = osg::Vec3f(7, 8, 9);
|
|
|
|
mNiNode.bounds.box.center = osg::Vec3f(-7, -8, -9);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNode), Nif::NodePtr(&mNode2) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
2021-10-27 23:43:25 +00:00
|
|
|
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
|
|
|
|
expected.mCollisionBox.mCenter = osg::Vec3f(-1, -2, -3);
|
2018-07-08 19:22:34 +00:00
|
|
|
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(1, 2, 3)));
|
|
|
|
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
|
|
|
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-1, -2, -3)), box.release());
|
2021-10-30 01:06:22 +00:00
|
|
|
expected.mCollisionShape.reset(shape.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader,
|
|
|
|
for_root_and_two_children_where_both_with_bounds_but_only_second_with_flag_should_use_second_bounds)
|
|
|
|
{
|
|
|
|
mNode.hasBounds = true;
|
2020-11-14 00:42:15 +00:00
|
|
|
mNode.bounds.type = Nif::NiBoundingVolume::Type::BOX_BV;
|
|
|
|
mNode.bounds.box.extents = osg::Vec3f(1, 2, 3);
|
|
|
|
mNode.bounds.box.center = osg::Vec3f(-1, -2, -3);
|
2022-01-21 23:15:56 +00:00
|
|
|
mNode.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
mNode2.hasBounds = true;
|
2022-06-21 21:43:16 +00:00
|
|
|
mNode2.flags |= Nif::Node::Flag_BBoxCollision;
|
2020-11-14 00:42:15 +00:00
|
|
|
mNode2.bounds.type = Nif::NiBoundingVolume::Type::BOX_BV;
|
|
|
|
mNode2.bounds.box.extents = osg::Vec3f(4, 5, 6);
|
|
|
|
mNode2.bounds.box.center = osg::Vec3f(-4, -5, -6);
|
2022-01-21 23:15:56 +00:00
|
|
|
mNode2.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
mNiNode.hasBounds = true;
|
2020-11-14 00:42:15 +00:00
|
|
|
mNiNode.bounds.type = Nif::NiBoundingVolume::Type::BOX_BV;
|
|
|
|
mNiNode.bounds.box.extents = osg::Vec3f(7, 8, 9);
|
|
|
|
mNiNode.bounds.box.center = osg::Vec3f(-7, -8, -9);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNode), Nif::NodePtr(&mNode2) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
2021-10-27 23:43:25 +00:00
|
|
|
expected.mCollisionBox.mExtents = osg::Vec3f(4, 5, 6);
|
|
|
|
expected.mCollisionBox.mCenter = osg::Vec3f(-4, -5, -6);
|
2018-07-08 19:22:34 +00:00
|
|
|
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(4, 5, 6)));
|
|
|
|
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
|
|
|
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-4, -5, -6)), box.release());
|
2021-10-30 01:06:22 +00:00
|
|
|
expected.mCollisionShape.reset(shape.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader,
|
|
|
|
for_root_nif_node_with_bounds_but_without_flag_should_return_shape_with_bounds_but_with_null_collision_shape)
|
|
|
|
{
|
|
|
|
mNode.hasBounds = true;
|
2020-11-14 00:42:15 +00:00
|
|
|
mNode.bounds.type = Nif::NiBoundingVolume::Type::BOX_BV;
|
|
|
|
mNode.bounds.box.extents = osg::Vec3f(1, 2, 3);
|
|
|
|
mNode.bounds.box.center = osg::Vec3f(-1, -2, -3);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
2021-10-27 23:43:25 +00:00
|
|
|
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
|
|
|
|
expected.mCollisionBox.mCenter = osg::Vec3f(-1, -2, -3);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2023-02-25 04:06:49 +00:00
|
|
|
TEST_F(TestBulletNifLoader, for_tri_shape_root_node_should_return_static_shape)
|
2018-07-08 19:22:34 +00:00
|
|
|
{
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiTriShape);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
2023-02-25 04:06:49 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
Resource::BulletShape expected;
|
2023-02-25 04:06:49 +00:00
|
|
|
expected.mCollisionShape.reset(compound.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader,
|
2023-02-25 04:06:49 +00:00
|
|
|
for_tri_shape_root_node_with_bounds_should_return_static_shape_with_bounds_but_with_null_collision_shape)
|
2018-07-08 19:22:34 +00:00
|
|
|
{
|
|
|
|
mNiTriShape.hasBounds = true;
|
2020-11-14 00:42:15 +00:00
|
|
|
mNiTriShape.bounds.type = Nif::NiBoundingVolume::Type::BOX_BV;
|
|
|
|
mNiTriShape.bounds.box.extents = osg::Vec3f(1, 2, 3);
|
|
|
|
mNiTriShape.bounds.box.center = osg::Vec3f(-1, -2, -3);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiTriShape);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
2021-10-27 23:43:25 +00:00
|
|
|
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
|
|
|
|
expected.mCollisionBox.mCenter = osg::Vec3f(-1, -2, -3);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2023-02-25 04:06:49 +00:00
|
|
|
TEST_F(TestBulletNifLoader, for_tri_shape_child_node_should_return_static_shape)
|
2018-07-08 19:22:34 +00:00
|
|
|
{
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
2023-02-25 04:06:49 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
Resource::BulletShape expected;
|
2023-02-25 04:06:49 +00:00
|
|
|
expected.mCollisionShape.reset(compound.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2023-02-25 04:06:49 +00:00
|
|
|
TEST_F(TestBulletNifLoader, for_nested_tri_shape_child_should_return_static_shape)
|
2018-07-08 19:22:34 +00:00
|
|
|
{
|
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiNode2) }));
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiNode2.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode2.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode2);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
2023-02-25 04:06:49 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
Resource::BulletShape expected;
|
2023-02-25 04:06:49 +00:00
|
|
|
expected.mCollisionShape.reset(compound.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2023-02-25 04:06:49 +00:00
|
|
|
TEST_F(TestBulletNifLoader, for_two_tri_shape_children_should_return_static_shape_with_all_meshes)
|
2018-07-08 19:22:34 +00:00
|
|
|
{
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
|
|
|
mNiTriShape2.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children
|
|
|
|
= Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape), Nif::NodePtr(&mNiTriShape2) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
2023-02-25 04:06:49 +00:00
|
|
|
std::unique_ptr<btTriangleMesh> triangles2(new btTriangleMesh(false));
|
|
|
|
triangles2->addTriangle(btVector3(0, 0, 1), btVector3(1, 0, 1), btVector3(1, 1, 1));
|
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
compound->addChildShape(
|
|
|
|
btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles2.release(), true));
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
Resource::BulletShape expected;
|
2023-02-25 04:06:49 +00:00
|
|
|
expected.mCollisionShape.reset(compound.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader,
|
2023-02-25 04:06:49 +00:00
|
|
|
for_tri_shape_child_node_and_filename_starting_with_x_and_not_empty_skin_should_return_static_shape)
|
2018-07-08 19:22:34 +00:00
|
|
|
{
|
2023-08-03 19:55:06 +00:00
|
|
|
mNiTriShape.skin = Nif::NiSkinInstancePtr(&mNiSkinInstance);
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("xtest.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
2023-02-25 04:06:49 +00:00
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
Resource::BulletShape expected;
|
2023-02-25 04:06:49 +00:00
|
|
|
expected.mCollisionShape.reset(compound.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2023-02-25 04:06:49 +00:00
|
|
|
TEST_F(TestBulletNifLoader, for_tri_shape_root_node_and_filename_starting_with_x_should_return_animated_shape)
|
2018-07-08 19:22:34 +00:00
|
|
|
{
|
|
|
|
copy(mTransform, mNiTriShape.trafo);
|
|
|
|
mNiTriShape.trafo.scale = 3;
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("xtest.nif");
|
|
|
|
file.mRoots.push_back(&mNiTriShape);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
|
|
|
std::unique_ptr<Resource::TriangleMeshShape> mesh(new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
mesh->setLocalScaling(btVector3(3, 3, 3));
|
|
|
|
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
2023-03-08 11:17:45 +00:00
|
|
|
shape->addChildShape(mTransform, mesh.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
Resource::BulletShape expected;
|
2021-10-30 01:06:22 +00:00
|
|
|
expected.mCollisionShape.reset(shape.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
expected.mAnimatedShapes = { { -1, 0 } };
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2023-02-25 04:06:49 +00:00
|
|
|
TEST_F(TestBulletNifLoader, for_tri_shape_child_node_and_filename_starting_with_x_should_return_animated_shape)
|
2018-07-08 19:22:34 +00:00
|
|
|
{
|
|
|
|
copy(mTransform, mNiTriShape.trafo);
|
|
|
|
mNiTriShape.trafo.scale = 3;
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
mNiNode.trafo.scale = 4;
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("xtest.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
|
|
|
std::unique_ptr<Resource::TriangleMeshShape> mesh(new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
mesh->setLocalScaling(btVector3(12, 12, 12));
|
|
|
|
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
2023-03-08 11:17:45 +00:00
|
|
|
shape->addChildShape(mTransformScale4, mesh.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
Resource::BulletShape expected;
|
2021-10-30 01:06:22 +00:00
|
|
|
expected.mCollisionShape.reset(shape.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
expected.mAnimatedShapes = { { -1, 0 } };
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2023-02-25 04:06:49 +00:00
|
|
|
TEST_F(
|
|
|
|
TestBulletNifLoader, for_two_tri_shape_children_nodes_and_filename_starting_with_x_should_return_animated_shape)
|
2018-07-08 19:22:34 +00:00
|
|
|
{
|
|
|
|
copy(mTransform, mNiTriShape.trafo);
|
|
|
|
mNiTriShape.trafo.scale = 3;
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
copy(mTransform, mNiTriShape2.trafo);
|
|
|
|
mNiTriShape2.trafo.scale = 3;
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape2.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({
|
|
|
|
Nif::NodePtr(&mNiTriShape),
|
|
|
|
Nif::NodePtr(&mNiTriShape2),
|
|
|
|
}));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("xtest.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
|
|
|
std::unique_ptr<Resource::TriangleMeshShape> mesh(new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
mesh->setLocalScaling(btVector3(3, 3, 3));
|
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles2(new btTriangleMesh(false));
|
|
|
|
triangles2->addTriangle(btVector3(0, 0, 1), btVector3(1, 0, 1), btVector3(1, 1, 1));
|
|
|
|
std::unique_ptr<Resource::TriangleMeshShape> mesh2(new Resource::TriangleMeshShape(triangles2.release(), true));
|
|
|
|
mesh2->setLocalScaling(btVector3(3, 3, 3));
|
|
|
|
|
|
|
|
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
2023-03-08 11:17:45 +00:00
|
|
|
shape->addChildShape(mTransform, mesh.release());
|
|
|
|
shape->addChildShape(mTransform, mesh2.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
Resource::BulletShape expected;
|
2021-10-30 01:06:22 +00:00
|
|
|
expected.mCollisionShape.reset(shape.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
expected.mAnimatedShapes = { { -1, 0 } };
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2023-02-25 04:06:49 +00:00
|
|
|
TEST_F(TestBulletNifLoader, for_tri_shape_child_node_with_controller_should_return_animated_shape)
|
2018-07-08 19:22:34 +00:00
|
|
|
{
|
|
|
|
mController.recType = Nif::RC_NiKeyframeController;
|
2022-06-21 21:43:16 +00:00
|
|
|
mController.flags |= Nif::Controller::Flag_Active;
|
2018-07-08 19:22:34 +00:00
|
|
|
copy(mTransform, mNiTriShape.trafo);
|
|
|
|
mNiTriShape.trafo.scale = 3;
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiTriShape.controller = Nif::ControllerPtr(&mController);
|
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
mNiNode.trafo.scale = 4;
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
|
|
|
std::unique_ptr<Resource::TriangleMeshShape> mesh(new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
mesh->setLocalScaling(btVector3(12, 12, 12));
|
|
|
|
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
2023-03-08 11:17:45 +00:00
|
|
|
shape->addChildShape(mTransformScale4, mesh.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
Resource::BulletShape expected;
|
2021-10-30 01:06:22 +00:00
|
|
|
expected.mCollisionShape.reset(shape.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
expected.mAnimatedShapes = { { -1, 0 } };
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2023-02-25 04:06:49 +00:00
|
|
|
TEST_F(TestBulletNifLoader, for_two_tri_shape_children_nodes_where_one_with_controller_should_return_animated_shape)
|
2018-07-08 19:22:34 +00:00
|
|
|
{
|
|
|
|
mController.recType = Nif::RC_NiKeyframeController;
|
2022-06-21 21:43:16 +00:00
|
|
|
mController.flags |= Nif::Controller::Flag_Active;
|
2018-07-08 19:22:34 +00:00
|
|
|
copy(mTransform, mNiTriShape.trafo);
|
|
|
|
mNiTriShape.trafo.scale = 3;
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
copy(mTransform, mNiTriShape2.trafo);
|
|
|
|
mNiTriShape2.trafo.scale = 3;
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape2.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiTriShape2.controller = Nif::ControllerPtr(&mController);
|
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({
|
|
|
|
Nif::NodePtr(&mNiTriShape),
|
|
|
|
Nif::NodePtr(&mNiTriShape2),
|
|
|
|
}));
|
|
|
|
mNiNode.trafo.scale = 4;
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
2023-02-25 04:06:49 +00:00
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
2018-07-08 19:22:34 +00:00
|
|
|
std::unique_ptr<Resource::TriangleMeshShape> mesh(new Resource::TriangleMeshShape(triangles.release(), true));
|
2023-02-25 04:06:49 +00:00
|
|
|
mesh->setLocalScaling(btVector3(12, 12, 12));
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles2(new btTriangleMesh(false));
|
|
|
|
triangles2->addTriangle(btVector3(0, 0, 1), btVector3(1, 0, 1), btVector3(1, 1, 1));
|
|
|
|
std::unique_ptr<Resource::TriangleMeshShape> mesh2(new Resource::TriangleMeshShape(triangles2.release(), true));
|
|
|
|
mesh2->setLocalScaling(btVector3(12, 12, 12));
|
|
|
|
|
|
|
|
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
2023-03-08 11:17:45 +00:00
|
|
|
shape->addChildShape(mTransformScale4, mesh.release());
|
|
|
|
shape->addChildShape(mTransformScale4, mesh2.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
Resource::BulletShape expected;
|
2021-10-30 01:06:22 +00:00
|
|
|
expected.mCollisionShape.reset(shape.release());
|
2023-02-25 04:06:49 +00:00
|
|
|
expected.mAnimatedShapes = { { -1, 1 } };
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2021-10-31 14:19:19 +00:00
|
|
|
TEST_F(TestBulletNifLoader, should_add_static_mesh_to_existing_compound_mesh)
|
|
|
|
{
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2021-10-31 14:19:19 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("xtest.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mRoots.push_back(&mNiTriShape2);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2021-10-31 14:19:19 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles2(new btTriangleMesh(false));
|
|
|
|
triangles2->addTriangle(btVector3(0, 0, 1), btVector3(1, 0, 1), btVector3(1, 1, 1));
|
|
|
|
|
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
compound->addChildShape(
|
|
|
|
btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles2.release(), true));
|
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
|
|
|
expected.mCollisionShape.reset(compound.release());
|
|
|
|
expected.mAnimatedShapes = { { -1, 0 } };
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
TEST_F(
|
|
|
|
TestBulletNifLoader, for_root_avoid_node_and_tri_shape_child_node_should_return_shape_with_null_collision_shape)
|
|
|
|
{
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
mNiNode.recType = Nif::RC_AvoidNode;
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
2018-07-10 22:05:19 +00:00
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
2023-02-25 04:06:49 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
2018-07-08 19:22:34 +00:00
|
|
|
Resource::BulletShape expected;
|
2023-02-25 04:06:49 +00:00
|
|
|
expected.mAvoidCollisionShape.reset(compound.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader, for_tri_shape_child_node_with_empty_data_should_return_shape_with_null_collision_shape)
|
|
|
|
{
|
2023-08-03 19:55:06 +00:00
|
|
|
mNiTriShape.data = Nif::NiGeometryDataPtr(nullptr);
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader,
|
|
|
|
for_tri_shape_child_node_with_empty_data_triangles_should_return_shape_with_null_collision_shape)
|
|
|
|
{
|
2023-08-03 19:55:06 +00:00
|
|
|
auto data = static_cast<Nif::NiTriShapeData*>(mNiTriShape.data.getPtr());
|
2023-09-04 21:08:28 +00:00
|
|
|
data->mTriangles.clear();
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2021-04-11 08:28:56 +00:00
|
|
|
TEST_F(TestBulletNifLoader,
|
|
|
|
for_tri_shape_child_node_with_extra_data_string_equal_ncc_should_return_shape_with_cameraonly_collision)
|
|
|
|
{
|
2023-08-31 21:58:23 +00:00
|
|
|
mNiStringExtraData.mData = "NCC__";
|
2021-04-11 08:28:56 +00:00
|
|
|
mNiStringExtraData.recType = Nif::RC_NiStringExtraData;
|
|
|
|
mNiTriShape.extra = Nif::ExtraPtr(&mNiStringExtraData);
|
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2021-04-11 08:28:56 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
2023-02-25 04:06:49 +00:00
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
|
2021-04-11 08:28:56 +00:00
|
|
|
Resource::BulletShape expected;
|
2023-02-25 04:06:49 +00:00
|
|
|
expected.mCollisionShape.reset(compound.release());
|
|
|
|
|
2022-08-24 22:14:17 +00:00
|
|
|
expected.mVisualCollisionType = Resource::VisualCollisionType::Camera;
|
2021-04-11 08:28:56 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader,
|
|
|
|
for_tri_shape_child_node_with_not_first_extra_data_string_equal_ncc_should_return_shape_with_cameraonly_collision)
|
|
|
|
{
|
2023-08-31 21:58:23 +00:00
|
|
|
mNiStringExtraData.mNext = Nif::ExtraPtr(&mNiStringExtraData2);
|
|
|
|
mNiStringExtraData2.mData = "NCC__";
|
2021-04-11 08:28:56 +00:00
|
|
|
mNiStringExtraData2.recType = Nif::RC_NiStringExtraData;
|
|
|
|
mNiTriShape.extra = Nif::ExtraPtr(&mNiStringExtraData);
|
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2021-04-11 08:28:56 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
2023-02-25 04:06:49 +00:00
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
|
2021-04-11 08:28:56 +00:00
|
|
|
Resource::BulletShape expected;
|
2023-02-25 04:06:49 +00:00
|
|
|
expected.mCollisionShape.reset(compound.release());
|
2022-08-24 22:14:17 +00:00
|
|
|
expected.mVisualCollisionType = Resource::VisualCollisionType::Camera;
|
2021-04-11 08:28:56 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader,
|
|
|
|
for_tri_shape_child_node_with_extra_data_string_starting_with_nc_should_return_shape_with_nocollision)
|
2018-07-08 19:22:34 +00:00
|
|
|
{
|
2023-08-31 21:58:23 +00:00
|
|
|
mNiStringExtraData.mData = "NC___";
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiStringExtraData.recType = Nif::RC_NiStringExtraData;
|
|
|
|
mNiTriShape.extra = Nif::ExtraPtr(&mNiStringExtraData);
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
2021-04-11 08:28:56 +00:00
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
2023-02-25 04:06:49 +00:00
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
Resource::BulletShape expected;
|
2023-02-25 04:06:49 +00:00
|
|
|
expected.mCollisionShape.reset(compound.release());
|
2022-08-24 22:14:17 +00:00
|
|
|
expected.mVisualCollisionType = Resource::VisualCollisionType::Default;
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2021-04-11 08:28:56 +00:00
|
|
|
TEST_F(TestBulletNifLoader,
|
|
|
|
for_tri_shape_child_node_with_not_first_extra_data_string_starting_with_nc_should_return_shape_with_nocollision)
|
2018-07-08 19:22:34 +00:00
|
|
|
{
|
2023-08-31 21:58:23 +00:00
|
|
|
mNiStringExtraData.mNext = Nif::ExtraPtr(&mNiStringExtraData2);
|
|
|
|
mNiStringExtraData2.mData = "NC___";
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiStringExtraData2.recType = Nif::RC_NiStringExtraData;
|
|
|
|
mNiTriShape.extra = Nif::ExtraPtr(&mNiStringExtraData);
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
2021-04-11 08:28:56 +00:00
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
2023-02-25 04:06:49 +00:00
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
Resource::BulletShape expected;
|
2023-02-25 04:06:49 +00:00
|
|
|
expected.mCollisionShape.reset(compound.release());
|
2022-08-24 22:14:17 +00:00
|
|
|
expected.mVisualCollisionType = Resource::VisualCollisionType::Default;
|
2018-07-08 19:22:34 +00:00
|
|
|
|
2022-07-03 00:14:32 +00:00
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader, for_empty_root_collision_node_without_nc_should_return_shape_with_cameraonly_collision)
|
|
|
|
{
|
|
|
|
Nif::NiTriShape niTriShape;
|
|
|
|
Nif::NiNode emptyCollisionNode;
|
|
|
|
init(niTriShape);
|
|
|
|
init(emptyCollisionNode);
|
|
|
|
|
2023-08-03 19:55:06 +00:00
|
|
|
niTriShape.data = Nif::NiGeometryDataPtr(&mNiTriShapeData);
|
2022-07-03 00:14:32 +00:00
|
|
|
niTriShape.parents.push_back(&mNiNode);
|
|
|
|
|
|
|
|
emptyCollisionNode.recType = Nif::RC_RootCollisionNode;
|
|
|
|
emptyCollisionNode.parents.push_back(&mNiNode);
|
|
|
|
|
|
|
|
mNiNode.children = Nif::NodeList(
|
|
|
|
std::vector<Nif::NodePtr>({ Nif::NodePtr(&niTriShape), Nif::NodePtr(&emptyCollisionNode) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2022-07-03 00:14:32 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
2023-02-25 04:06:49 +00:00
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
|
2022-07-03 00:14:32 +00:00
|
|
|
Resource::BulletShape expected;
|
2023-02-25 04:06:49 +00:00
|
|
|
expected.mCollisionShape.reset(compound.release());
|
2022-08-24 22:14:17 +00:00
|
|
|
expected.mVisualCollisionType = Resource::VisualCollisionType::Camera;
|
2022-07-03 00:14:32 +00:00
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader,
|
|
|
|
for_tri_shape_child_node_with_extra_data_string_mrk_should_return_shape_with_null_collision_shape)
|
|
|
|
{
|
2023-08-31 21:58:23 +00:00
|
|
|
mNiStringExtraData.mData = "MRK";
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiStringExtraData.recType = Nif::RC_NiStringExtraData;
|
|
|
|
mNiTriShape.extra = Nif::ExtraPtr(&mNiStringExtraData);
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
2023-05-24 01:27:13 +00:00
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2023-07-10 17:14:53 +00:00
|
|
|
TEST_F(TestBulletNifLoader, bsx_editor_marker_flag_disables_collision_for_markers)
|
2023-05-24 01:27:13 +00:00
|
|
|
{
|
2023-08-31 21:58:23 +00:00
|
|
|
mNiIntegerExtraData.mData = 32; // BSX flag "editor marker"
|
2023-05-24 01:27:13 +00:00
|
|
|
mNiIntegerExtraData.recType = Nif::RC_BSXFlags;
|
|
|
|
mNiTriShape.extralist.push_back(Nif::ExtraPtr(&mNiIntegerExtraData));
|
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2023-07-10 17:14:53 +00:00
|
|
|
mNiTriShape.name = "EditorMarker";
|
2023-05-24 01:27:13 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
|
|
|
|
Nif::NIFFile file("test.nif");
|
2022-09-17 17:24:42 +00:00
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader,
|
|
|
|
for_tri_shape_child_node_with_extra_data_string_mrk_and_other_collision_node_should_return_shape_with_triangle_mesh_shape_with_all_meshes)
|
|
|
|
{
|
2023-08-31 21:58:23 +00:00
|
|
|
mNiStringExtraData.mData = "MRK";
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiStringExtraData.recType = Nif::RC_NiStringExtraData;
|
|
|
|
mNiTriShape.extra = Nif::ExtraPtr(&mNiStringExtraData);
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode2);
|
2018-10-26 17:21:34 +00:00
|
|
|
mNiNode2.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
mNiNode2.recType = Nif::RC_RootCollisionNode;
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiNode2.parents.push_back(&mNiNode);
|
2018-07-08 19:22:34 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiNode2) }));
|
|
|
|
mNiNode.recType = Nif::RC_NiNode;
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
2023-02-25 04:06:49 +00:00
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
Resource::BulletShape expected;
|
2023-02-25 04:06:49 +00:00
|
|
|
expected.mCollisionShape.reset(compound.release());
|
2018-07-08 19:22:34 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
2021-10-31 14:19:19 +00:00
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader, should_ignore_tri_shape_data_with_mismatching_data_rec_type)
|
|
|
|
{
|
2023-08-03 19:55:06 +00:00
|
|
|
mNiTriShape.data = Nif::NiGeometryDataPtr(&mNiTriStripsData);
|
2021-10-31 14:19:19 +00:00
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiTriShape);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2021-10-31 14:19:19 +00:00
|
|
|
|
|
|
|
const Resource::BulletShape expected;
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
2023-02-25 04:06:49 +00:00
|
|
|
TEST_F(TestBulletNifLoader, for_tri_strips_root_node_should_return_static_shape)
|
2021-10-31 14:19:19 +00:00
|
|
|
{
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiTriStrips);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2021-10-31 14:19:19 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
|
|
|
triangles->addTriangle(btVector3(1, 0, 0), btVector3(0, 1, 0), btVector3(1, 1, 0));
|
2023-02-25 04:06:49 +00:00
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
|
2021-10-31 14:19:19 +00:00
|
|
|
Resource::BulletShape expected;
|
2023-02-25 04:06:49 +00:00
|
|
|
expected.mCollisionShape.reset(compound.release());
|
2021-10-31 14:19:19 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader, should_ignore_tri_strips_data_with_mismatching_data_rec_type)
|
|
|
|
{
|
2023-08-03 19:55:06 +00:00
|
|
|
mNiTriStrips.data = Nif::NiGeometryDataPtr(&mNiTriShapeData);
|
2021-10-31 14:19:19 +00:00
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiTriStrips);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2021-10-31 14:19:19 +00:00
|
|
|
|
|
|
|
const Resource::BulletShape expected;
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader, should_ignore_tri_strips_data_with_empty_strips)
|
|
|
|
{
|
2023-09-03 14:41:52 +00:00
|
|
|
mNiTriStripsData.mStrips.clear();
|
2021-10-31 14:19:19 +00:00
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiTriStrips);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2021-10-31 14:19:19 +00:00
|
|
|
|
|
|
|
const Resource::BulletShape expected;
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader, for_static_mesh_should_ignore_tri_strips_data_with_less_than_3_strips)
|
|
|
|
{
|
2023-09-03 14:41:52 +00:00
|
|
|
mNiTriStripsData.mStrips.front() = { 0, 1 };
|
2021-10-31 14:19:19 +00:00
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiTriStrips);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2021-10-31 14:19:19 +00:00
|
|
|
|
|
|
|
const Resource::BulletShape expected;
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader, for_avoid_collision_mesh_should_ignore_tri_strips_data_with_less_than_3_strips)
|
|
|
|
{
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2021-10-31 14:19:19 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
mNiNode.recType = Nif::RC_AvoidNode;
|
2023-09-03 14:41:52 +00:00
|
|
|
mNiTriStripsData.mStrips.front() = { 0, 1 };
|
2021-10-31 14:19:19 +00:00
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("test.nif");
|
|
|
|
file.mRoots.push_back(&mNiTriStrips);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2021-10-31 14:19:19 +00:00
|
|
|
|
|
|
|
const Resource::BulletShape expected;
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader, for_animated_mesh_should_ignore_tri_strips_data_with_less_than_3_strips)
|
|
|
|
{
|
2023-09-03 14:41:52 +00:00
|
|
|
mNiTriStripsData.mStrips.front() = { 0, 1 };
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriStrips.parents.push_back(&mNiNode);
|
2021-10-31 14:19:19 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriStrips) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("xtest.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2021-10-31 14:19:19 +00:00
|
|
|
|
2021-10-31 13:59:35 +00:00
|
|
|
const Resource::BulletShape expected;
|
2021-10-31 14:19:19 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader, should_not_add_static_mesh_with_no_triangles_to_compound_shape)
|
|
|
|
{
|
2023-09-03 14:41:52 +00:00
|
|
|
mNiTriStripsData.mStrips.front() = { 0, 1 };
|
2022-01-21 23:15:56 +00:00
|
|
|
mNiTriShape.parents.push_back(&mNiNode);
|
2021-10-31 14:19:19 +00:00
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("xtest.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mRoots.push_back(&mNiTriStrips);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2021-10-31 14:19:19 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles(new btTriangleMesh(false));
|
|
|
|
triangles->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
|
|
|
|
|
|
|
std::unique_ptr<btCompoundShape> compound(new btCompoundShape);
|
|
|
|
compound->addChildShape(btTransform::getIdentity(), new Resource::TriangleMeshShape(triangles.release(), true));
|
|
|
|
|
|
|
|
Resource::BulletShape expected;
|
|
|
|
expected.mCollisionShape.reset(compound.release());
|
|
|
|
expected.mAnimatedShapes = { { -1, 0 } };
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
2022-01-21 23:15:56 +00:00
|
|
|
|
|
|
|
TEST_F(TestBulletNifLoader, should_handle_node_with_multiple_parents)
|
|
|
|
{
|
|
|
|
copy(mTransform, mNiTriShape.trafo);
|
|
|
|
mNiTriShape.trafo.scale = 4;
|
|
|
|
mNiTriShape.parents = { &mNiNode, &mNiNode2 };
|
|
|
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
mNiNode.trafo.scale = 2;
|
|
|
|
mNiNode2.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
|
|
|
mNiNode2.trafo.scale = 3;
|
|
|
|
|
2022-09-17 17:24:42 +00:00
|
|
|
Nif::NIFFile file("xtest.nif");
|
|
|
|
file.mRoots.push_back(&mNiNode);
|
|
|
|
file.mRoots.push_back(&mNiNode2);
|
|
|
|
file.mHash = mHash;
|
|
|
|
|
|
|
|
const auto result = mLoader.load(file);
|
2022-01-21 23:15:56 +00:00
|
|
|
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles1(new btTriangleMesh(false));
|
|
|
|
triangles1->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
|
|
|
std::unique_ptr<Resource::TriangleMeshShape> mesh1(new Resource::TriangleMeshShape(triangles1.release(), true));
|
|
|
|
mesh1->setLocalScaling(btVector3(8, 8, 8));
|
|
|
|
std::unique_ptr<btTriangleMesh> triangles2(new btTriangleMesh(false));
|
|
|
|
triangles2->addTriangle(btVector3(0, 0, 0), btVector3(1, 0, 0), btVector3(1, 1, 0));
|
|
|
|
std::unique_ptr<Resource::TriangleMeshShape> mesh2(new Resource::TriangleMeshShape(triangles2.release(), true));
|
|
|
|
mesh2->setLocalScaling(btVector3(12, 12, 12));
|
|
|
|
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
2023-03-08 11:17:45 +00:00
|
|
|
shape->addChildShape(mTransformScale2, mesh1.release());
|
|
|
|
shape->addChildShape(mTransformScale3, mesh2.release());
|
2022-01-21 23:15:56 +00:00
|
|
|
Resource::BulletShape expected;
|
|
|
|
expected.mCollisionShape.reset(shape.release());
|
|
|
|
expected.mAnimatedShapes = { { -1, 0 } };
|
|
|
|
|
|
|
|
EXPECT_EQ(*result, expected);
|
|
|
|
}
|
2018-07-08 19:22:34 +00:00
|
|
|
}
|