mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 06:35:30 +00:00
Modernize NiTriShapeData
This commit is contained in:
parent
56ee2588a5
commit
cfd37dbcc6
@ -325,13 +325,13 @@ namespace
|
||||
mNiTriShapeData.recType = Nif::RC_NiTriShapeData;
|
||||
mNiTriShapeData.vertices = { osg::Vec3f(0, 0, 0), osg::Vec3f(1, 0, 0), osg::Vec3f(1, 1, 0) };
|
||||
mNiTriShapeData.mNumTriangles = 1;
|
||||
mNiTriShapeData.triangles = { 0, 1, 2 };
|
||||
mNiTriShapeData.mTriangles = { 0, 1, 2 };
|
||||
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.mNumTriangles = 1;
|
||||
mNiTriShapeData2.triangles = { 0, 1, 2 };
|
||||
mNiTriShapeData2.mTriangles = { 0, 1, 2 };
|
||||
mNiTriShape2.data = Nif::NiGeometryDataPtr(&mNiTriShapeData2);
|
||||
|
||||
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)
|
||||
{
|
||||
auto data = static_cast<Nif::NiTriShapeData*>(mNiTriShape.data.getPtr());
|
||||
data->triangles.clear();
|
||||
data->mTriangles.clear();
|
||||
mNiTriShape.parents.push_back(&mNiNode);
|
||||
mNiNode.children = Nif::NodeList(std::vector<Nif::NodePtr>({ Nif::NodePtr(&mNiTriShape) }));
|
||||
|
||||
|
@ -93,25 +93,17 @@ namespace Nif
|
||||
{
|
||||
NiTriBasedGeomData::read(nif);
|
||||
|
||||
// We have three times as many vertices as triangles, so this
|
||||
// is always equal to mNumTriangles * 3.
|
||||
int cnt = nif->getInt();
|
||||
uint32_t numIndices;
|
||||
nif->read(numIndices);
|
||||
bool hasTriangles = true;
|
||||
if (nif->getVersion() > NIFFile::NIFVersion::VER_OB_OLD)
|
||||
hasTriangles = nif->getBoolean();
|
||||
nif->read(hasTriangles);
|
||||
if (hasTriangles)
|
||||
nif->readVector(triangles, cnt);
|
||||
nif->readVector(mTriangles, numIndices);
|
||||
|
||||
// Read the match list, which lists the vertices that are equal to
|
||||
// vertices. We don't actually need need this for anything, so
|
||||
// just skip it.
|
||||
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));
|
||||
}
|
||||
mMatchGroups.resize(nif->get<uint16_t>());
|
||||
for (auto& group : mMatchGroups)
|
||||
nif->readVector(group, nif->get<uint16_t>());
|
||||
}
|
||||
|
||||
void NiTriStripsData::read(NIFStream* nif)
|
||||
|
@ -55,7 +55,8 @@ namespace Nif
|
||||
struct NiTriShapeData : public NiTriBasedGeomData
|
||||
{
|
||||
// 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;
|
||||
};
|
||||
|
@ -46,7 +46,7 @@ namespace
|
||||
void fillTriangleMesh(btTriangleMesh& mesh, const Nif::NiTriShapeData& 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)
|
||||
mesh.addTriangleIndices(triangles[i + 0], triangles[i + 1], triangles[i + 2]);
|
||||
}
|
||||
@ -87,7 +87,7 @@ namespace
|
||||
return {};
|
||||
|
||||
auto data = static_cast<const Nif::NiTriShapeData*>(geometry.data.getPtr());
|
||||
if (data->triangles.empty())
|
||||
if (data->mTriangles.empty())
|
||||
return {};
|
||||
|
||||
return function(static_cast<const Nif::NiTriShapeData&>(*data));
|
||||
|
@ -1430,7 +1430,7 @@ namespace NifOsg
|
||||
if (niGeometryData->recType != Nif::RC_NiTriShapeData)
|
||||
return;
|
||||
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())
|
||||
return;
|
||||
geometry->addPrimitiveSet(
|
||||
|
Loading…
x
Reference in New Issue
Block a user