1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Modernize NiTriShapeData

This commit is contained in:
Alexei Kotov 2023-09-05 00:08:28 +03:00
parent 56ee2588a5
commit cfd37dbcc6
5 changed files with 15 additions and 22 deletions

View File

@ -325,13 +325,13 @@ namespace
mNiTriShapeData.recType = Nif::RC_NiTriShapeData; 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.mNumTriangles = 1; mNiTriShapeData.mNumTriangles = 1;
mNiTriShapeData.triangles = { 0, 1, 2 }; mNiTriShapeData.mTriangles = { 0, 1, 2 };
mNiTriShape.data = Nif::NiGeometryDataPtr(&mNiTriShapeData); mNiTriShape.data = Nif::NiGeometryDataPtr(&mNiTriShapeData);
mNiTriShapeData2.recType = Nif::RC_NiTriShapeData; 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.mNumTriangles = 1; mNiTriShapeData2.mNumTriangles = 1;
mNiTriShapeData2.triangles = { 0, 1, 2 }; mNiTriShapeData2.mTriangles = { 0, 1, 2 };
mNiTriShape2.data = Nif::NiGeometryDataPtr(&mNiTriShapeData2); mNiTriShape2.data = Nif::NiGeometryDataPtr(&mNiTriShapeData2);
mNiTriStripsData.recType = Nif::RC_NiTriStripsData; mNiTriStripsData.recType = Nif::RC_NiTriStripsData;
@ -978,7 +978,7 @@ namespace
for_tri_shape_child_node_with_empty_data_triangles_should_return_shape_with_null_collision_shape) for_tri_shape_child_node_with_empty_data_triangles_should_return_shape_with_null_collision_shape)
{ {
auto data = static_cast<Nif::NiTriShapeData*>(mNiTriShape.data.getPtr()); auto data = static_cast<Nif::NiTriShapeData*>(mNiTriShape.data.getPtr());
data->triangles.clear(); data->mTriangles.clear();
mNiTriShape.parents.push_back(&mNiNode); mNiTriShape.parents.push_back(&mNiNode);
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) })); mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));

View File

@ -93,25 +93,17 @@ namespace Nif
{ {
NiTriBasedGeomData::read(nif); NiTriBasedGeomData::read(nif);
// We have three times as many vertices as triangles, so this uint32_t numIndices;
// is always equal to mNumTriangles * 3. nif->read(numIndices);
int cnt = nif->getInt();
bool hasTriangles = true; bool hasTriangles = true;
if (nif->getVersion() > NIFFile::NIFVersion::VER_OB_OLD) if (nif->getVersion() > NIFFile::NIFVersion::VER_OB_OLD)
hasTriangles = nif->getBoolean(); nif->read(hasTriangles);
if (hasTriangles) if (hasTriangles)
nif->readVector(triangles, cnt); nif->readVector(mTriangles, numIndices);
// Read the match list, which lists the vertices that are equal to mMatchGroups.resize(nif->get<uint16_t>());
// vertices. We don't actually need need this for anything, so for (auto& group : mMatchGroups)
// just skip it. nif->readVector(group, nif->get<uint16_t>());
unsigned short verts = nif->getUShort();
for (unsigned short i = 0; i < verts; i++)
{
// Number of vertices matching vertex 'i'
int num = nif->getUShort();
nif->skip(num * sizeof(short));
}
} }
void NiTriStripsData::read(NIFStream* nif) void NiTriStripsData::read(NIFStream* nif)

View File

@ -55,7 +55,8 @@ namespace Nif
struct NiTriShapeData : public NiTriBasedGeomData struct NiTriShapeData : public NiTriBasedGeomData
{ {
// Triangles, three vertex indices per triangle // Triangles, three vertex indices per triangle
std::vector<unsigned short> triangles; std::vector<unsigned short> mTriangles;
std::vector<std::vector<unsigned short>> mMatchGroups;
void read(NIFStream* nif) override; void read(NIFStream* nif) override;
}; };

View File

@ -46,7 +46,7 @@ namespace
void fillTriangleMesh(btTriangleMesh& mesh, const Nif::NiTriShapeData& data) void fillTriangleMesh(btTriangleMesh& mesh, const Nif::NiTriShapeData& data)
{ {
prepareTriangleMesh(mesh, data); prepareTriangleMesh(mesh, data);
const std::vector<unsigned short>& triangles = data.triangles; const std::vector<unsigned short>& triangles = data.mTriangles;
for (std::size_t i = 0; i < triangles.size(); i += 3) for (std::size_t i = 0; i < triangles.size(); i += 3)
mesh.addTriangleIndices(triangles[i + 0], triangles[i + 1], triangles[i + 2]); mesh.addTriangleIndices(triangles[i + 0], triangles[i + 1], triangles[i + 2]);
} }
@ -87,7 +87,7 @@ namespace
return {}; return {};
auto data = static_cast<const Nif::NiTriShapeData*>(geometry.data.getPtr()); auto data = static_cast<const Nif::NiTriShapeData*>(geometry.data.getPtr());
if (data->triangles.empty()) if (data->mTriangles.empty())
return {}; return {};
return function(static_cast<const Nif::NiTriShapeData&>(*data)); return function(static_cast<const Nif::NiTriShapeData&>(*data));

View File

@ -1430,7 +1430,7 @@ namespace NifOsg
if (niGeometryData->recType != Nif::RC_NiTriShapeData) if (niGeometryData->recType != Nif::RC_NiTriShapeData)
return; return;
auto data = static_cast<const Nif::NiTriShapeData*>(niGeometryData); auto data = static_cast<const Nif::NiTriShapeData*>(niGeometryData);
const std::vector<unsigned short>& triangles = data->triangles; const std::vector<unsigned short>& triangles = data->mTriangles;
if (triangles.empty()) if (triangles.empty())
return; return;
geometry->addPrimitiveSet( geometry->addPrimitiveSet(