Fix inconsistent kart size with server

This commit is contained in:
Benau 2021-01-26 14:52:22 +08:00
parent eb5bb253f3
commit 65f23987f1
4 changed files with 33 additions and 8 deletions

View File

@ -22,6 +22,8 @@ namespace scene
*/
class IMesh : public virtual IReferenceCounted
{
private:
core::vector3df m_min, m_max;
public:
//! Get the amount of mesh buffers.
@ -70,6 +72,13 @@ namespace scene
/** This is used in server without graphics to free all mesh vertex buffer if
possible, for example: kart, attachment and power model (because they are not used in physics). */
virtual void freeMeshVertexBuffer() {}
/** Avoid rounding error for kart size when reskin happening with vertex weights. */
virtual void setMinMax(const core::vector3df& min, const core::vector3df& max) { m_min = min; m_max = max; }
virtual const core::vector3df& getMin() const { return m_min; }
virtual const core::vector3df& getMax() const { return m_max; }
};
} // end namespace scene

View File

@ -6,6 +6,7 @@
#include "graphics/central_settings.hpp"
#include "graphics/stk_tex_manager.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/mesh_tools.hpp"
#include "graphics/sp/sp_animation.hpp"
#include "graphics/sp/sp_mesh.hpp"
#include "graphics/sp/sp_mesh_buffer.hpp"
@ -65,6 +66,15 @@ scene::IAnimatedMesh* B3DMeshLoader::createMesh(io::IReadFile* f)
AnimatedMesh = 0;
}
// Set the min max with straight frame (used by kart_model)
Vec3 min, max;
if (AnimatedMesh)
{
MeshTools::minMax3D(static_cast<scene::CSkinnedMesh*>
(AnimatedMesh->getMesh(m_straight_frame)), &min, &max);
AnimatedMesh->setMinMax(min.toIrrVector(), max.toIrrVector());
}
#ifndef SERVER_ONLY
if (CVS->isGLSL())
{
@ -76,6 +86,7 @@ scene::IAnimatedMesh* B3DMeshLoader::createMesh(io::IReadFile* f)
SP::SPMesh* spm = toSPM(static_cast<scene::CSkinnedMesh*>
(AnimatedMesh->getMesh(m_straight_frame)));
m_texture_string.clear();
spm->setMinMax(min.toIrrVector(), max.toIrrVector());
return spm;
}
#endif

View File

@ -21,6 +21,7 @@
#include "graphics/sp/sp_mesh_buffer.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/mesh_tools.hpp"
#include "graphics/stk_tex_manager.hpp"
#include "utils/constants.hpp"
#include "utils/mini_glm.hpp"
@ -224,6 +225,12 @@ scene::IAnimatedMesh* SPMeshLoader::createMesh(io::IReadFile* f)
}
size_num--;
}
// Calculate before finalize as spm has pre-computed straight frame
Vec3 min, max;
MeshTools::minMax3D(m_mesh, &min, &max);
m_mesh->setMinMax(min.toIrrVector(), max.toIrrVector());
if (header == "SPMA")
{
createAnimationData(f);

View File

@ -441,8 +441,8 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool human_playe
if(!m_wheel_model[i]) continue;
m_wheel_node[i] = irr_driver->addMesh(m_wheel_model[i], "wheel",
node, getRenderInfo());
Vec3 wheel_min, wheel_max;
MeshTools::minMax3D(m_wheel_model[i], &wheel_min, &wheel_max);
Vec3 wheel_min = m_wheel_model[i]->getMin();
Vec3 wheel_max = m_wheel_model[i]->getMax();
m_wheel_graphics_radius[i] = 0.5f*(wheel_max.getY() - wheel_min.getY());
m_wheel_node[i]->grab();
@ -583,10 +583,8 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
m_mesh->grab();
irr_driver->grabAllTextures(m_mesh);
Vec3 kart_min, kart_max;
MeshTools::minMax3D(m_mesh->getMesh(m_animation_frame[AF_STRAIGHT]),
&kart_min, &kart_max);
Vec3 kart_min = m_mesh->getMin();
Vec3 kart_max = m_mesh->getMax();
#ifndef SERVER_ONLY
// Test if kart model support colorization
if (CVS->isGLSL())
@ -667,9 +665,9 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
irr_driver->grabAllTextures(obj.m_model);
// Update min/max, speed weight can be scaled
Vec3 obj_min, obj_max;
scene::IMesh* mesh = obj.m_model->getMesh(0);
MeshTools::minMax3D(mesh, &obj_min, &obj_max);
Vec3 obj_min = mesh->getMin();
Vec3 obj_max = mesh->getMax();
core::vector3df transformed_min, transformed_max;
obj.m_location.transformVect(transformed_min, obj_min.toIrrVector());
obj.m_location.transformVect(transformed_max, obj_max.toIrrVector());