1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-06 00:55:50 +00:00

Clean up primitive set copying

This commit is contained in:
Alexei Kotov 2023-07-18 03:31:35 +03:00
parent 3f252eab5d
commit 0d70ae5028

View File

@ -1421,11 +1421,12 @@ namespace NifOsg
{ {
if (niGeometryData->recType != Nif::RC_NiTriShapeData) if (niGeometryData->recType != Nif::RC_NiTriShapeData)
return; return;
auto triangles = static_cast<const Nif::NiTriShapeData*>(niGeometryData)->triangles; auto data = static_cast<const Nif::NiTriShapeData*>(niGeometryData);
const std::vector<unsigned short>& triangles = data->triangles;
if (triangles.empty()) if (triangles.empty())
return; return;
geometry->addPrimitiveSet(new osg::DrawElementsUShort( geometry->addPrimitiveSet(
osg::PrimitiveSet::TRIANGLES, triangles.size(), (unsigned short*)triangles.data())); new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, triangles.size(), triangles.data()));
} }
else if (niGeometry->recType == Nif::RC_NiTriStrips) else if (niGeometry->recType == Nif::RC_NiTriStrips)
{ {
@ -1433,12 +1434,12 @@ namespace NifOsg
return; return;
auto data = static_cast<const Nif::NiTriStripsData*>(niGeometryData); auto data = static_cast<const Nif::NiTriStripsData*>(niGeometryData);
bool hasGeometry = false; bool hasGeometry = false;
for (const auto& strip : data->strips) for (const std::vector<unsigned short>& strip : data->strips)
{ {
if (strip.size() < 3) if (strip.size() < 3)
continue; continue;
geometry->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP, geometry->addPrimitiveSet(
strip.size(), reinterpret_cast<const unsigned short*>(strip.data()))); new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP, strip.size(), strip.data()));
hasGeometry = true; hasGeometry = true;
} }
if (!hasGeometry) if (!hasGeometry)
@ -1452,8 +1453,8 @@ namespace NifOsg
const auto& line = data->lines; const auto& line = data->lines;
if (line.empty()) if (line.empty())
return; return;
geometry->addPrimitiveSet(new osg::DrawElementsUShort( geometry->addPrimitiveSet(
osg::PrimitiveSet::LINES, line.size(), reinterpret_cast<const unsigned short*>(line.data()))); new osg::DrawElementsUShort(osg::PrimitiveSet::LINES, line.size(), line.data()));
} }
} }
handleNiGeometryData(geometry, niGeometryData, boundTextures, nifNode->name); handleNiGeometryData(geometry, niGeometryData, boundTextures, nifNode->name);