mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 10:46:45 +01:00
Merge the review fixes of the PRs below from feat/eu07m-skinning into feat/eu07m-clips
This commit is contained in:
+23
-9
@@ -1527,9 +1527,10 @@ void TSubModel::create_geometry(std::size_t &Indexoffset, std::size_t &Vertexoff
|
||||
// since we're comparing squared radii, we need to square it back for correct results
|
||||
m_boundingradius *= m_boundingradius;
|
||||
auto const submodeloffset{offset(std::numeric_limits<float>::max())};
|
||||
for (auto const &vertex : GfxRenderer->Vertices(m_geometry.handle))
|
||||
// the positions alone: the vertices of an EU07M model on Vulkan would be made and kept whole for it
|
||||
for (auto const &position : GfxRenderer->Positions(m_geometry.handle))
|
||||
{
|
||||
squaredradius = glm::length2(submodeloffset + vertex.position);
|
||||
squaredradius = glm::length2(submodeloffset + position);
|
||||
if (squaredradius > m_boundingradius)
|
||||
{
|
||||
m_boundingradius = squaredradius;
|
||||
@@ -1653,9 +1654,9 @@ float TSubModel::MaxY(float4x4 const &m)
|
||||
if (m_geometry.handle != null_handle)
|
||||
{
|
||||
|
||||
for (auto const &vertex : GfxRenderer->Vertices(m_geometry.handle))
|
||||
for (auto const &position : GfxRenderer->Positions(m_geometry.handle))
|
||||
{
|
||||
maxy = std::max(maxy, m[0][1] * vertex.position.x + m[1][1] * vertex.position.y + m[2][1] * vertex.position.z + m[3][1]);
|
||||
maxy = std::max(maxy, m[0][1] * position.x + m[1][1] * position.y + m[2][1] * position.z + m[3][1]);
|
||||
}
|
||||
}
|
||||
else if (false == Vertices.empty())
|
||||
@@ -1797,17 +1798,30 @@ glm::vec3 TSubModel::offset(float const Geometrytestoffsetthreshold) const
|
||||
// offset of zero generally means the submodel has optimized identity matrix
|
||||
// for such cases we resort to an estimate from submodel geometry
|
||||
// TODO: do proper bounding area calculation for submodel when loading mesh and grab the centre point from it here
|
||||
auto const &vertices{(m_geometry.handle != null_handle ? GfxRenderer->Vertices(m_geometry.handle) : Vertices)};
|
||||
if (false == vertices.empty())
|
||||
// the positions alone: the vertices of an EU07M model on Vulkan would be made and kept whole for them
|
||||
gfx::position_array positions;
|
||||
if (m_geometry.handle != null_handle)
|
||||
{
|
||||
positions = GfxRenderer->Positions(m_geometry.handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
positions.reserve(Vertices.size());
|
||||
for (auto const &vertex : Vertices)
|
||||
{
|
||||
positions.push_back(vertex.position);
|
||||
}
|
||||
}
|
||||
if (false == positions.empty())
|
||||
{
|
||||
// transformation matrix for the submodel can still contain rotation and/or scaling,
|
||||
// so we pass the vertex positions through it rather than just grab them directly
|
||||
offset = glm::vec3();
|
||||
auto const vertexfactor{1.f / vertices.size()};
|
||||
auto const vertexfactor{1.f / positions.size()};
|
||||
auto const transformationmatrix{glm::make_mat4(parentmatrix.readArray())};
|
||||
for (auto const &vertex : vertices)
|
||||
for (auto const &position : positions)
|
||||
{
|
||||
offset += glm::vec3{transformationmatrix * glm::vec4{vertex.position, 1}} * vertexfactor;
|
||||
offset += glm::vec3{transformationmatrix * glm::vec4{position, 1}} * vertexfactor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user