mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 07:53:53 +00:00
Unify NiGeometry/NiGeometryData handling
This commit is contained in:
parent
8ca324af0a
commit
8fd45d85ec
5 changed files with 124 additions and 179 deletions
|
@ -259,14 +259,19 @@ namespace
|
||||||
value.isBone = false;
|
value.isBone = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(Nif::NiTriShape& value)
|
void init(Nif::NiGeometry& value)
|
||||||
{
|
{
|
||||||
init(static_cast<Nif::Node&>(value));
|
init(static_cast<Nif::Node&>(value));
|
||||||
value.recType = Nif::RC_NiTriShape;
|
value.data = Nif::NiGeometryDataPtr(nullptr);
|
||||||
value.data = Nif::NiTriShapeDataPtr(nullptr);
|
|
||||||
value.skin = Nif::NiSkinInstancePtr(nullptr);
|
value.skin = Nif::NiSkinInstancePtr(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init(Nif::NiTriShape& value)
|
||||||
|
{
|
||||||
|
init(static_cast<Nif::NiGeometry&>(value));
|
||||||
|
value.recType = Nif::RC_NiTriShape;
|
||||||
|
}
|
||||||
|
|
||||||
void init(Nif::NiSkinInstance& value)
|
void init(Nif::NiSkinInstance& value)
|
||||||
{
|
{
|
||||||
value.data = Nif::NiSkinDataPtr(nullptr);
|
value.data = Nif::NiSkinDataPtr(nullptr);
|
||||||
|
@ -361,13 +366,15 @@ namespace
|
||||||
init(mNiStringExtraData2);
|
init(mNiStringExtraData2);
|
||||||
init(mController);
|
init(mController);
|
||||||
|
|
||||||
|
mNiTriShapeData.recType = Nif::RC_NiTriShapeData;
|
||||||
mNiTriShapeData.vertices = {osg::Vec3f(0, 0, 0), osg::Vec3f(1, 0, 0), osg::Vec3f(1, 1, 0)};
|
mNiTriShapeData.vertices = {osg::Vec3f(0, 0, 0), osg::Vec3f(1, 0, 0), osg::Vec3f(1, 1, 0)};
|
||||||
mNiTriShapeData.triangles = {0, 1, 2};
|
mNiTriShapeData.triangles = {0, 1, 2};
|
||||||
mNiTriShape.data = Nif::NiTriShapeDataPtr(&mNiTriShapeData);
|
mNiTriShape.data = Nif::NiGeometryDataPtr(&mNiTriShapeData);
|
||||||
|
|
||||||
|
mNiTriShapeData2.recType = Nif::RC_NiTriShapeData;
|
||||||
mNiTriShapeData2.vertices = {osg::Vec3f(0, 0, 1), osg::Vec3f(1, 0, 1), osg::Vec3f(1, 1, 1)};
|
mNiTriShapeData2.vertices = {osg::Vec3f(0, 0, 1), osg::Vec3f(1, 0, 1), osg::Vec3f(1, 1, 1)};
|
||||||
mNiTriShapeData2.triangles = {0, 1, 2};
|
mNiTriShapeData2.triangles = {0, 1, 2};
|
||||||
mNiTriShape2.data = Nif::NiTriShapeDataPtr(&mNiTriShapeData2);
|
mNiTriShape2.data = Nif::NiGeometryDataPtr(&mNiTriShapeData2);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -873,7 +880,7 @@ namespace
|
||||||
|
|
||||||
TEST_F(TestBulletNifLoader, for_tri_shape_child_node_with_empty_data_should_return_shape_with_null_collision_shape)
|
TEST_F(TestBulletNifLoader, for_tri_shape_child_node_with_empty_data_should_return_shape_with_null_collision_shape)
|
||||||
{
|
{
|
||||||
mNiTriShape.data = Nif::NiTriShapeDataPtr(nullptr);
|
mNiTriShape.data = Nif::NiGeometryDataPtr(nullptr);
|
||||||
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({Nif::NodePtr(&mNiTriShape)}));
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({Nif::NodePtr(&mNiTriShape)}));
|
||||||
|
|
||||||
EXPECT_CALL(mNifFile, numRoots()).WillOnce(Return(1));
|
EXPECT_CALL(mNifFile, numRoots()).WillOnce(Return(1));
|
||||||
|
@ -888,7 +895,8 @@ namespace
|
||||||
|
|
||||||
TEST_F(TestBulletNifLoader, for_tri_shape_child_node_with_empty_data_triangles_should_return_shape_with_null_collision_shape)
|
TEST_F(TestBulletNifLoader, for_tri_shape_child_node_with_empty_data_triangles_should_return_shape_with_null_collision_shape)
|
||||||
{
|
{
|
||||||
mNiTriShape.data->triangles.clear();
|
auto data = static_cast<Nif::NiTriShapeData*>(mNiTriShape.data.getPtr());
|
||||||
|
data->triangles.clear();
|
||||||
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({Nif::NodePtr(&mNiTriShape)}));
|
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({Nif::NodePtr(&mNiTriShape)}));
|
||||||
|
|
||||||
EXPECT_CALL(mNifFile, numRoots()).WillOnce(Return(1));
|
EXPECT_CALL(mNifFile, numRoots()).WillOnce(Return(1));
|
||||||
|
|
|
@ -240,43 +240,6 @@ struct NiNode : Node
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NiGeometry : Node
|
struct NiGeometry : Node
|
||||||
{
|
|
||||||
struct MaterialData
|
|
||||||
{
|
|
||||||
std::vector<std::string> materialNames;
|
|
||||||
std::vector<int> materialExtraData;
|
|
||||||
unsigned int activeMaterial{0};
|
|
||||||
bool materialNeedsUpdate{false};
|
|
||||||
void read(NIFStream *nif)
|
|
||||||
{
|
|
||||||
if (nif->getVersion() <= NIFStream::generateVersion(10,0,1,0))
|
|
||||||
return;
|
|
||||||
unsigned int numMaterials = 0;
|
|
||||||
if (nif->getVersion() <= NIFStream::generateVersion(20,1,0,3))
|
|
||||||
numMaterials = nif->getBoolean(); // Has Shader
|
|
||||||
else if (nif->getVersion() >= NIFStream::generateVersion(20,2,0,5))
|
|
||||||
numMaterials = nif->getUInt();
|
|
||||||
if (numMaterials)
|
|
||||||
{
|
|
||||||
nif->getStrings(materialNames, numMaterials);
|
|
||||||
nif->getInts(materialExtraData, numMaterials);
|
|
||||||
}
|
|
||||||
if (nif->getVersion() >= NIFStream::generateVersion(20,2,0,5))
|
|
||||||
activeMaterial = nif->getUInt();
|
|
||||||
if (nif->getVersion() >= NIFFile::NIFVersion::VER_BGS)
|
|
||||||
{
|
|
||||||
materialNeedsUpdate = nif->getBoolean();
|
|
||||||
if (nif->getVersion() == NIFFile::NIFVersion::VER_BGS && nif->getBethVersion() > NIFFile::BethVersion::BETHVER_FO3)
|
|
||||||
nif->skip(8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
NiSkinInstancePtr skin;
|
|
||||||
MaterialData materialData;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct NiTriShape : NiGeometry
|
|
||||||
{
|
{
|
||||||
/* Possible flags:
|
/* Possible flags:
|
||||||
0x40 - mesh has no vertex normals ?
|
0x40 - mesh has no vertex normals ?
|
||||||
|
@ -285,14 +248,45 @@ struct NiTriShape : NiGeometry
|
||||||
been observed so far.
|
been observed so far.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
NiTriShapeDataPtr data;
|
struct MaterialData
|
||||||
|
{
|
||||||
|
std::vector<std::string> names;
|
||||||
|
std::vector<int> extra;
|
||||||
|
unsigned int active{0};
|
||||||
|
bool needsUpdate{false};
|
||||||
|
void read(NIFStream *nif)
|
||||||
|
{
|
||||||
|
if (nif->getVersion() <= NIFStream::generateVersion(10,0,1,0))
|
||||||
|
return;
|
||||||
|
unsigned int num = 0;
|
||||||
|
if (nif->getVersion() <= NIFStream::generateVersion(20,1,0,3))
|
||||||
|
num = nif->getBoolean(); // Has Shader
|
||||||
|
else if (nif->getVersion() >= NIFStream::generateVersion(20,2,0,5))
|
||||||
|
num = nif->getUInt();
|
||||||
|
if (num)
|
||||||
|
{
|
||||||
|
nif->getStrings(names, num);
|
||||||
|
nif->getInts(extra, num);
|
||||||
|
}
|
||||||
|
if (nif->getVersion() >= NIFStream::generateVersion(20,2,0,5))
|
||||||
|
active = nif->getUInt();
|
||||||
|
if (nif->getVersion() >= NIFFile::NIFVersion::VER_BGS)
|
||||||
|
needsUpdate = nif->getBoolean();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
NiGeometryDataPtr data;
|
||||||
|
NiSkinInstancePtr skin;
|
||||||
|
MaterialData material;
|
||||||
|
|
||||||
void read(NIFStream *nif) override
|
void read(NIFStream *nif) override
|
||||||
{
|
{
|
||||||
Node::read(nif);
|
Node::read(nif);
|
||||||
data.read(nif);
|
data.read(nif);
|
||||||
skin.read(nif);
|
skin.read(nif);
|
||||||
materialData.read(nif);
|
material.read(nif);
|
||||||
|
if (nif->getVersion() == NIFFile::NIFVersion::VER_BGS && nif->getBethVersion() > NIFFile::BethVersion::BETHVER_FO3)
|
||||||
|
nif->skip(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
void post(NIFFile *nif) override
|
void post(NIFFile *nif) override
|
||||||
|
@ -300,53 +294,15 @@ struct NiTriShape : NiGeometry
|
||||||
Node::post(nif);
|
Node::post(nif);
|
||||||
data.post(nif);
|
data.post(nif);
|
||||||
skin.post(nif);
|
skin.post(nif);
|
||||||
if (!skin.empty())
|
if (recType != RC_NiParticles && !skin.empty())
|
||||||
nif->setUseSkinning(true);
|
nif->setUseSkinning(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NiTriStrips : NiGeometry
|
struct NiTriShape : NiGeometry {};
|
||||||
{
|
struct NiTriStrips : NiGeometry {};
|
||||||
NiTriStripsDataPtr data;
|
struct NiLines : NiGeometry {};
|
||||||
|
struct NiParticles : NiGeometry { };
|
||||||
void read(NIFStream *nif) override
|
|
||||||
{
|
|
||||||
Node::read(nif);
|
|
||||||
data.read(nif);
|
|
||||||
skin.read(nif);
|
|
||||||
materialData.read(nif);
|
|
||||||
}
|
|
||||||
|
|
||||||
void post(NIFFile *nif) override
|
|
||||||
{
|
|
||||||
Node::post(nif);
|
|
||||||
data.post(nif);
|
|
||||||
skin.post(nif);
|
|
||||||
if (!skin.empty())
|
|
||||||
nif->setUseSkinning(true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct NiLines : NiGeometry
|
|
||||||
{
|
|
||||||
NiLinesDataPtr data;
|
|
||||||
|
|
||||||
void read(NIFStream *nif) override
|
|
||||||
{
|
|
||||||
Node::read(nif);
|
|
||||||
data.read(nif);
|
|
||||||
skin.read(nif);
|
|
||||||
}
|
|
||||||
|
|
||||||
void post(NIFFile *nif) override
|
|
||||||
{
|
|
||||||
Node::post(nif);
|
|
||||||
data.post(nif);
|
|
||||||
skin.post(nif);
|
|
||||||
if (!skin.empty())
|
|
||||||
nif->setUseSkinning(true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct NiCamera : Node
|
struct NiCamera : Node
|
||||||
{
|
{
|
||||||
|
@ -401,25 +357,6 @@ struct NiCamera : Node
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NiParticles : NiGeometry
|
|
||||||
{
|
|
||||||
NiParticlesDataPtr data;
|
|
||||||
void read(NIFStream *nif) override
|
|
||||||
{
|
|
||||||
Node::read(nif);
|
|
||||||
data.read(nif);
|
|
||||||
skin.read(nif);
|
|
||||||
materialData.read(nif);
|
|
||||||
}
|
|
||||||
|
|
||||||
void post(NIFFile *nif) override
|
|
||||||
{
|
|
||||||
Node::post(nif);
|
|
||||||
data.post(nif);
|
|
||||||
skin.post(nif);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// A node used as the base to switch between child nodes, such as for LOD levels.
|
// A node used as the base to switch between child nodes, such as for LOD levels.
|
||||||
struct NiSwitchNode : public NiNode
|
struct NiSwitchNode : public NiNode
|
||||||
{
|
{
|
||||||
|
|
|
@ -134,20 +134,18 @@ struct NiMorphData;
|
||||||
class NiPixelData;
|
class NiPixelData;
|
||||||
class NiColorData;
|
class NiColorData;
|
||||||
struct NiKeyframeData;
|
struct NiKeyframeData;
|
||||||
class NiTriShapeData;
|
|
||||||
class NiTriStripsData;
|
class NiTriStripsData;
|
||||||
class NiSkinInstance;
|
class NiSkinInstance;
|
||||||
class NiSourceTexture;
|
class NiSourceTexture;
|
||||||
class NiParticlesData;
|
|
||||||
class NiPalette;
|
class NiPalette;
|
||||||
struct NiParticleModifier;
|
struct NiParticleModifier;
|
||||||
struct NiLinesData;
|
|
||||||
struct NiBoolData;
|
struct NiBoolData;
|
||||||
struct NiSkinPartition;
|
struct NiSkinPartition;
|
||||||
struct NiFloatInterpolator;
|
struct NiFloatInterpolator;
|
||||||
struct NiPoint3Interpolator;
|
struct NiPoint3Interpolator;
|
||||||
struct NiTransformInterpolator;
|
struct NiTransformInterpolator;
|
||||||
struct BSShaderTextureSet;
|
struct BSShaderTextureSet;
|
||||||
|
struct NiGeometryData;
|
||||||
|
|
||||||
using NodePtr = RecordPtrT<Node>;
|
using NodePtr = RecordPtrT<Node>;
|
||||||
using ExtraPtr = RecordPtrT<Extra>;
|
using ExtraPtr = RecordPtrT<Extra>;
|
||||||
|
@ -162,12 +160,8 @@ using NiPixelDataPtr = RecordPtrT<NiPixelData>;
|
||||||
using NiFloatDataPtr = RecordPtrT<NiFloatData>;
|
using NiFloatDataPtr = RecordPtrT<NiFloatData>;
|
||||||
using NiColorDataPtr = RecordPtrT<NiColorData>;
|
using NiColorDataPtr = RecordPtrT<NiColorData>;
|
||||||
using NiKeyframeDataPtr = RecordPtrT<NiKeyframeData>;
|
using NiKeyframeDataPtr = RecordPtrT<NiKeyframeData>;
|
||||||
using NiTriShapeDataPtr = RecordPtrT<NiTriShapeData>;
|
|
||||||
using NiTriStripsDataPtr = RecordPtrT<NiTriStripsData>;
|
|
||||||
using NiLinesDataPtr = RecordPtrT<NiLinesData>;
|
|
||||||
using NiSkinInstancePtr = RecordPtrT<NiSkinInstance>;
|
using NiSkinInstancePtr = RecordPtrT<NiSkinInstance>;
|
||||||
using NiSourceTexturePtr = RecordPtrT<NiSourceTexture>;
|
using NiSourceTexturePtr = RecordPtrT<NiSourceTexture>;
|
||||||
using NiParticlesDataPtr = RecordPtrT<NiParticlesData>;
|
|
||||||
using NiPalettePtr = RecordPtrT<NiPalette>;
|
using NiPalettePtr = RecordPtrT<NiPalette>;
|
||||||
using NiParticleModifierPtr = RecordPtrT<NiParticleModifier>;
|
using NiParticleModifierPtr = RecordPtrT<NiParticleModifier>;
|
||||||
using NiBoolDataPtr = RecordPtrT<NiBoolData>;
|
using NiBoolDataPtr = RecordPtrT<NiBoolData>;
|
||||||
|
@ -176,12 +170,14 @@ using NiFloatInterpolatorPtr = RecordPtrT<NiFloatInterpolator>;
|
||||||
using NiPoint3InterpolatorPtr = RecordPtrT<NiPoint3Interpolator>;
|
using NiPoint3InterpolatorPtr = RecordPtrT<NiPoint3Interpolator>;
|
||||||
using NiTransformInterpolatorPtr = RecordPtrT<NiTransformInterpolator>;
|
using NiTransformInterpolatorPtr = RecordPtrT<NiTransformInterpolator>;
|
||||||
using BSShaderTextureSetPtr = RecordPtrT<BSShaderTextureSet>;
|
using BSShaderTextureSetPtr = RecordPtrT<BSShaderTextureSet>;
|
||||||
|
using NiGeometryDataPtr = RecordPtrT<NiGeometryData>;
|
||||||
|
|
||||||
using NodeList = RecordListT<Node>;
|
using NodeList = RecordListT<Node>;
|
||||||
using PropertyList = RecordListT<Property>;
|
using PropertyList = RecordListT<Property>;
|
||||||
using ExtraList = RecordListT<Extra>;
|
using ExtraList = RecordListT<Extra>;
|
||||||
using NiSourceTextureList = RecordListT<NiSourceTexture>;
|
using NiSourceTextureList = RecordListT<NiSourceTexture>;
|
||||||
using NiFloatInterpolatorList = RecordListT<NiFloatInterpolator>;
|
using NiFloatInterpolatorList = RecordListT<NiFloatInterpolator>;
|
||||||
|
using NiTriStripsDataList = RecordListT<NiTriStripsData>;
|
||||||
|
|
||||||
} // Namespace
|
} // Namespace
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -34,11 +34,10 @@ bool pathFileNameStartsWithX(const std::string& path)
|
||||||
|
|
||||||
void fillTriangleMesh(btTriangleMesh& mesh, const Nif::NiTriShapeData& data, const osg::Matrixf &transform)
|
void fillTriangleMesh(btTriangleMesh& mesh, const Nif::NiTriShapeData& data, const osg::Matrixf &transform)
|
||||||
{
|
{
|
||||||
mesh.preallocateVertices(static_cast<int>(data.vertices.size()));
|
|
||||||
mesh.preallocateIndices(static_cast<int>(data.triangles.size()));
|
|
||||||
|
|
||||||
const std::vector<osg::Vec3f> &vertices = data.vertices;
|
const std::vector<osg::Vec3f> &vertices = data.vertices;
|
||||||
const std::vector<unsigned short> &triangles = data.triangles;
|
const std::vector<unsigned short> &triangles = data.triangles;
|
||||||
|
mesh.preallocateVertices(static_cast<int>(vertices.size()));
|
||||||
|
mesh.preallocateIndices(static_cast<int>(triangles.size()));
|
||||||
|
|
||||||
for (std::size_t i = 0; i < triangles.size(); i += 3)
|
for (std::size_t i = 0; i < triangles.size(); i += 3)
|
||||||
{
|
{
|
||||||
|
@ -54,8 +53,6 @@ void fillTriangleMesh(btTriangleMesh& mesh, const Nif::NiTriStripsData& data, co
|
||||||
{
|
{
|
||||||
const std::vector<osg::Vec3f> &vertices = data.vertices;
|
const std::vector<osg::Vec3f> &vertices = data.vertices;
|
||||||
const std::vector<std::vector<unsigned short>> &strips = data.strips;
|
const std::vector<std::vector<unsigned short>> &strips = data.strips;
|
||||||
if (vertices.empty() || strips.empty())
|
|
||||||
return;
|
|
||||||
mesh.preallocateVertices(static_cast<int>(vertices.size()));
|
mesh.preallocateVertices(static_cast<int>(vertices.size()));
|
||||||
int numTriangles = 0;
|
int numTriangles = 0;
|
||||||
for (const std::vector<unsigned short>& strip : strips)
|
for (const std::vector<unsigned short>& strip : strips)
|
||||||
|
@ -102,12 +99,12 @@ void fillTriangleMesh(btTriangleMesh& mesh, const Nif::NiTriStripsData& data, co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fillTriangleMesh(btTriangleMesh& mesh, const Nif::Node* nifNode, const osg::Matrixf &transform = osg::Matrixf())
|
void fillTriangleMesh(btTriangleMesh& mesh, const Nif::NiGeometry* geometry, const osg::Matrixf &transform = osg::Matrixf())
|
||||||
{
|
{
|
||||||
if (nifNode->recType == Nif::RC_NiTriShape)
|
if (geometry->recType == Nif::RC_NiTriShape)
|
||||||
fillTriangleMesh(mesh, static_cast<const Nif::NiTriShape*>(nifNode)->data.get(), transform);
|
fillTriangleMesh(mesh, static_cast<const Nif::NiTriShapeData&>(geometry->data.get()), transform);
|
||||||
else if (nifNode->recType == Nif::RC_NiTriStrips)
|
else if (geometry->recType == Nif::RC_NiTriStrips)
|
||||||
fillTriangleMesh(mesh, static_cast<const Nif::NiTriStrips*>(nifNode)->data.get(), transform);
|
fillTriangleMesh(mesh, static_cast<const Nif::NiTriStripsData&>(geometry->data.get()), transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -341,23 +338,31 @@ void BulletNifLoader::handleNiTriShape(const Nif::Node *nifNode, int flags, cons
|
||||||
if ((flags & 0x800))
|
if ((flags & 0x800))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (nifNode->recType == Nif::RC_NiTriShape)
|
auto niGeometry = static_cast<const Nif::NiGeometry*>(nifNode);
|
||||||
|
if (niGeometry->data.empty() || niGeometry->data->vertices.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (niGeometry->recType == Nif::RC_NiTriShape)
|
||||||
{
|
{
|
||||||
const Nif::NiTriShape* shape = static_cast<const Nif::NiTriShape*>(nifNode);
|
if (niGeometry->data->recType != Nif::RC_NiTriShapeData)
|
||||||
if (!shape->skin.empty())
|
return;
|
||||||
isAnimated = false;
|
|
||||||
if (shape->data.empty() || shape->data->triangles.empty())
|
auto data = static_cast<const Nif::NiTriShapeData*>(niGeometry->data.getPtr());
|
||||||
|
if (data->triangles.empty())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else if (niGeometry->recType == Nif::RC_NiTriStrips)
|
||||||
{
|
{
|
||||||
const Nif::NiTriStrips* shape = static_cast<const Nif::NiTriStrips*>(nifNode);
|
if (niGeometry->data->recType != Nif::RC_NiTriStripsData)
|
||||||
if (!shape->skin.empty())
|
return;
|
||||||
isAnimated = false;
|
|
||||||
if (shape->data.empty() || shape->data->strips.empty())
|
auto data = static_cast<const Nif::NiTriStripsData*>(niGeometry->data.getPtr());
|
||||||
|
if (data->strips.empty())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!niGeometry->skin.empty())
|
||||||
|
isAnimated = false;
|
||||||
|
|
||||||
if (isAnimated)
|
if (isAnimated)
|
||||||
{
|
{
|
||||||
|
@ -366,7 +371,7 @@ void BulletNifLoader::handleNiTriShape(const Nif::Node *nifNode, int flags, cons
|
||||||
|
|
||||||
std::unique_ptr<btTriangleMesh> childMesh(new btTriangleMesh);
|
std::unique_ptr<btTriangleMesh> childMesh(new btTriangleMesh);
|
||||||
|
|
||||||
fillTriangleMesh(*childMesh, nifNode);
|
fillTriangleMesh(*childMesh, niGeometry);
|
||||||
|
|
||||||
std::unique_ptr<Resource::TriangleMeshShape> childShape(new Resource::TriangleMeshShape(childMesh.get(), true));
|
std::unique_ptr<Resource::TriangleMeshShape> childShape(new Resource::TriangleMeshShape(childMesh.get(), true));
|
||||||
childMesh.release();
|
childMesh.release();
|
||||||
|
@ -394,7 +399,7 @@ void BulletNifLoader::handleNiTriShape(const Nif::Node *nifNode, int flags, cons
|
||||||
if (!mAvoidStaticMesh)
|
if (!mAvoidStaticMesh)
|
||||||
mAvoidStaticMesh.reset(new btTriangleMesh(false));
|
mAvoidStaticMesh.reset(new btTriangleMesh(false));
|
||||||
|
|
||||||
fillTriangleMesh(*mAvoidStaticMesh, nifNode, transform);
|
fillTriangleMesh(*mAvoidStaticMesh, niGeometry, transform);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -402,7 +407,7 @@ void BulletNifLoader::handleNiTriShape(const Nif::Node *nifNode, int flags, cons
|
||||||
mStaticMesh.reset(new btTriangleMesh(false));
|
mStaticMesh.reset(new btTriangleMesh(false));
|
||||||
|
|
||||||
// Static shape, just transform all vertices into position
|
// Static shape, just transform all vertices into position
|
||||||
fillTriangleMesh(*mStaticMesh, nifNode, transform);
|
fillTriangleMesh(*mStaticMesh, niGeometry, transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -939,11 +939,11 @@ namespace NifOsg
|
||||||
// Load the initial state of the particle system, i.e. the initial particles and their positions, velocity and colors.
|
// Load the initial state of the particle system, i.e. the initial particles and their positions, velocity and colors.
|
||||||
void handleParticleInitialState(const Nif::Node* nifNode, osgParticle::ParticleSystem* partsys, const Nif::NiParticleSystemController* partctrl)
|
void handleParticleInitialState(const Nif::Node* nifNode, osgParticle::ParticleSystem* partsys, const Nif::NiParticleSystemController* partctrl)
|
||||||
{
|
{
|
||||||
const auto particleNode = static_cast<const Nif::NiParticles*>(nifNode);
|
auto particleNode = static_cast<const Nif::NiParticles*>(nifNode);
|
||||||
if (particleNode->data.empty())
|
if (particleNode->data.empty() || particleNode->data->recType != Nif::RC_NiParticlesData)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const Nif::NiParticlesData* particledata = particleNode->data.getPtr();
|
auto particledata = static_cast<const Nif::NiParticlesData*>(particleNode->data.getPtr());
|
||||||
|
|
||||||
osg::BoundingBox box;
|
osg::BoundingBox box;
|
||||||
|
|
||||||
|
@ -1173,50 +1173,49 @@ namespace NifOsg
|
||||||
|
|
||||||
void handleNiGeometry(const Nif::Node *nifNode, osg::Geometry *geometry, osg::Node* parentNode, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<unsigned int>& boundTextures, int animflags)
|
void handleNiGeometry(const Nif::Node *nifNode, osg::Geometry *geometry, osg::Node* parentNode, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<unsigned int>& boundTextures, int animflags)
|
||||||
{
|
{
|
||||||
const Nif::NiGeometryData* niGeometryData = nullptr;
|
const Nif::NiGeometry* niGeometry = static_cast<const Nif::NiGeometry*>(nifNode);
|
||||||
if (nifNode->recType == Nif::RC_NiTriShape)
|
if (niGeometry->data.empty())
|
||||||
|
return;
|
||||||
|
const Nif::NiGeometryData* niGeometryData = niGeometry->data.getPtr();
|
||||||
|
|
||||||
|
if (niGeometry->recType == Nif::RC_NiTriShape)
|
||||||
{
|
{
|
||||||
const Nif::NiTriShape* triShape = static_cast<const Nif::NiTriShape*>(nifNode);
|
if (niGeometryData->recType != Nif::RC_NiTriShapeData)
|
||||||
if (!triShape->data.empty())
|
return;
|
||||||
{
|
auto triangles = static_cast<const Nif::NiTriShapeData*>(niGeometryData)->triangles;
|
||||||
const Nif::NiTriShapeData* data = triShape->data.getPtr();
|
if (triangles.empty())
|
||||||
niGeometryData = static_cast<const Nif::NiGeometryData*>(data);
|
return;
|
||||||
if (!data->triangles.empty())
|
geometry->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, triangles.size(),
|
||||||
geometry->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, data->triangles.size(),
|
(unsigned short*)triangles.data()));
|
||||||
(unsigned short*)data->triangles.data()));
|
|
||||||
}
|
}
|
||||||
}
|
else if (niGeometry->recType == Nif::RC_NiTriStrips)
|
||||||
else if (nifNode->recType == Nif::RC_NiTriStrips)
|
|
||||||
{
|
|
||||||
const Nif::NiTriStrips* triStrips = static_cast<const Nif::NiTriStrips*>(nifNode);
|
|
||||||
if (!triStrips->data.empty())
|
|
||||||
{
|
|
||||||
const Nif::NiTriStripsData* data = triStrips->data.getPtr();
|
|
||||||
niGeometryData = static_cast<const Nif::NiGeometryData*>(data);
|
|
||||||
if (!data->strips.empty())
|
|
||||||
{
|
{
|
||||||
|
if (niGeometryData->recType != Nif::RC_NiTriStripsData)
|
||||||
|
return;
|
||||||
|
auto data = static_cast<const Nif::NiTriStripsData*>(niGeometryData);
|
||||||
|
bool hasGeometry = false;
|
||||||
for (const auto& strip : data->strips)
|
for (const auto& strip : data->strips)
|
||||||
{
|
{
|
||||||
if (strip.size() >= 3)
|
if (strip.size() < 3)
|
||||||
|
continue;
|
||||||
geometry->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP, strip.size(),
|
geometry->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP, strip.size(),
|
||||||
(unsigned short*)strip.data()));
|
(unsigned short*)strip.data()));
|
||||||
|
hasGeometry = true;
|
||||||
}
|
}
|
||||||
|
if (!hasGeometry)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
else if (niGeometry->recType == Nif::RC_NiLines)
|
||||||
}
|
|
||||||
else if (nifNode->recType == Nif::RC_NiLines)
|
|
||||||
{
|
{
|
||||||
const Nif::NiLines* lines = static_cast<const Nif::NiLines*>(nifNode);
|
if (niGeometryData->recType != Nif::RC_NiLinesData)
|
||||||
if (!lines->data.empty())
|
return;
|
||||||
{
|
auto data = static_cast<const Nif::NiLinesData*>(niGeometryData);
|
||||||
const Nif::NiLinesData* data = lines->data.getPtr();
|
|
||||||
niGeometryData = static_cast<const Nif::NiGeometryData*>(data);
|
|
||||||
const auto& line = data->lines;
|
const auto& line = data->lines;
|
||||||
if (!line.empty())
|
if (line.empty())
|
||||||
geometry->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::LINES, line.size(), (unsigned short*)line.data()));
|
return;
|
||||||
|
geometry->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::LINES, line.size(),
|
||||||
|
(unsigned short*)line.data()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (niGeometryData)
|
|
||||||
handleNiGeometryData(geometry, niGeometryData, boundTextures, nifNode->name);
|
handleNiGeometryData(geometry, niGeometryData, boundTextures, nifNode->name);
|
||||||
|
|
||||||
// osg::Material properties are handled here for two reasons:
|
// osg::Material properties are handled here for two reasons:
|
||||||
|
@ -1225,7 +1224,7 @@ namespace NifOsg
|
||||||
// above the actual renderable would be tedious.
|
// above the actual renderable would be tedious.
|
||||||
std::vector<const Nif::Property*> drawableProps;
|
std::vector<const Nif::Property*> drawableProps;
|
||||||
collectDrawableProperties(nifNode, drawableProps);
|
collectDrawableProperties(nifNode, drawableProps);
|
||||||
applyDrawableProperties(parentNode, drawableProps, composite, niGeometryData && !niGeometryData->colors.empty(), animflags);
|
applyDrawableProperties(parentNode, drawableProps, composite, !niGeometryData->colors.empty(), animflags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleGeometry(const Nif::Node* nifNode, osg::Group* parentNode, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<unsigned int>& boundTextures, int animflags)
|
void handleGeometry(const Nif::Node* nifNode, osg::Group* parentNode, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<unsigned int>& boundTextures, int animflags)
|
||||||
|
|
Loading…
Reference in a new issue