Move struct Armature to GE

This commit is contained in:
Benau 2022-07-25 10:54:27 +08:00
parent 61b87d3b31
commit b75dec1fbc
9 changed files with 58 additions and 50 deletions

View File

@ -1,38 +1,43 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2018 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/* ==========================================================================
* Copyright (c) 2022 SuperTuxKart-Team
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
* ==========================================================================
*/
#ifndef HEADER_SP_ANIMATION_HPP
#define HEADER_SP_ANIMATION_HPP
#include "utils/log.hpp"
#include "utils/types.hpp"
#ifndef HEADER_GE_ANIMATION_HPP
#define HEADER_GE_ANIMATION_HPP
#include <IReadFile.h>
#include <matrix4.h>
#include <quaternion.h>
#include <array>
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <string>
using namespace irr;
namespace SP
namespace GE
{
struct LocRotScale
@ -120,7 +125,8 @@ struct Armature
}
if (!non_parent_bone)
{
Log::fatal("SPMeshLoader::Armature", "Non-parent bone missing in armature");
printf("SPMeshLoader::Armature: Non-parent bone missing in armature");
exit(-1);
}
unsigned frame_size = 0;
spm->read(&frame_size, 2);
@ -138,8 +144,7 @@ struct Armature
}
}
// ------------------------------------------------------------------------
/* Because matrix4 in windows is not 64 bytes */
void getPose(float frame, std::array<float, 16>* dest,
void getPose(float frame, core::matrix4* dest,
float frame_interpolating = -1.0f, float rate = -1.0f)
{
getInterpolatedMatrices(frame);
@ -166,13 +171,12 @@ struct Armature
}
for (unsigned i = 0; i < m_joint_used; i++)
{
core::matrix4 m = getWorldMatrix(m_interpolated_matrices, i) *
dest[i] = getWorldMatrix(m_interpolated_matrices, i) *
m_joint_matrices[i];
memcpy(&dest[i], m.pointer(), 64);
}
}
// ------------------------------------------------------------------------
void getPose(float frame, core::matrix4* dest)
void getPose(core::matrix4* dest, float frame)
{
getInterpolatedMatrices(frame);
for (auto& p : m_world_matrices)

View File

@ -8,7 +8,6 @@
#include "graphics/material.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"
#include "mini_glm.hpp"
@ -18,6 +17,7 @@
#include "../../lib/irrlicht/source/Irrlicht/os.h"
#include <algorithm>
#include <ge_animation.hpp>
#ifndef SERVER_ONLY
#include <ge_main.hpp>

View File

@ -16,11 +16,11 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "graphics/sp/sp_mesh.hpp"
#include "graphics/sp/sp_animation.hpp"
#include "graphics/sp/sp_mesh_buffer.hpp"
#include "graphics/material.hpp"
#include "mini_glm.hpp"
#include <ge_animation.hpp>
#include <algorithm>
namespace SP
@ -103,7 +103,7 @@ s32 SPMesh::getJointIDWithArm(const c8* name, unsigned* arm_id) const
{
for (unsigned i = 0; i < m_all_armatures.size(); i++)
{
const Armature& arm = m_all_armatures[i];
const GE::Armature& arm = m_all_armatures[i];
auto found = std::find(arm.m_joint_names.begin(),
arm.m_joint_names.end(), name);
if (found != arm.m_joint_names.end())
@ -119,7 +119,7 @@ s32 SPMesh::getJointIDWithArm(const c8* name, unsigned* arm_id) const
} // getJointIDWithArm
// ----------------------------------------------------------------------------
void SPMesh::getSkinningMatrices(f32 frame, std::array<float, 16>* dest,
void SPMesh::getSkinningMatrices(f32 frame, std::vector<core::matrix4>& dest,
float frame_interpolating, float rate)
{
unsigned accumulated_joints = 0;
@ -147,7 +147,7 @@ void SPMesh::updateBoundingBox()
void SPMesh::finalize()
{
updateBoundingBox();
for (Armature& arm : getArmatures())
for (GE::Armature& arm : getArmatures())
{
arm.getInterpolatedMatrices((float)m_bind_frame);
for (auto& p : arm.m_world_matrices)

View File

@ -31,10 +31,14 @@ using namespace scene;
class B3DMeshLoader;
class SPMeshLoader;
namespace GE
{
struct Armature;
}
namespace SP
{
class SPMeshBuffer;
struct Armature;
class SPMesh : public ISkinnedMesh
{
@ -49,7 +53,7 @@ private:
unsigned m_bind_frame, m_total_joints, m_joint_using, m_frame_count;
std::vector<SP::Armature> m_all_armatures;
std::vector<GE::Armature> m_all_armatures;
public:
// ------------------------------------------------------------------------
@ -150,9 +154,9 @@ public:
// ------------------------------------------------------------------------
virtual void updateBoundingBox(void);
// ------------------------------------------------------------------------
std::vector<Armature>& getArmatures() { return m_all_armatures; }
std::vector<GE::Armature>& getArmatures() { return m_all_armatures; }
// ------------------------------------------------------------------------
void getSkinningMatrices(f32 frame, std::array<float, 16>* dest,
void getSkinningMatrices(f32 frame, std::vector<core::matrix4>& dest,
float frame_interpolating = -1.0f, float rate = -1.0f);
// ------------------------------------------------------------------------
s32 getJointIDWithArm(const c8* name, unsigned* arm_id) const;

View File

@ -16,7 +16,6 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "graphics/sp/sp_mesh_node.hpp"
#include "graphics/sp/sp_animation.hpp"
#include "graphics/sp/sp_base.hpp"
#include "graphics/sp/sp_mesh.hpp"
#include "graphics/sp/sp_mesh_buffer.hpp"
@ -29,6 +28,7 @@
#include "../../../lib/irrlicht/source/Irrlicht/CBoneSceneNode.h"
#include <algorithm>
#include <ge_animation.hpp>
namespace SP
{
@ -103,7 +103,7 @@ void SPMeshNode::setMesh(irr::scene::IAnimatedMesh* mesh)
#endif
unsigned bone_idx = 0;
m_skinning_matrices.resize(m_mesh->getJointCount());
for (Armature& arm : m_mesh->getArmatures())
for (GE::Armature& arm : m_mesh->getArmatures())
{
for (const std::string& bone_name : arm.m_joint_names)
{
@ -169,11 +169,11 @@ IMesh* SPMeshNode::getMeshForCurrentFrame()
{
return m_mesh;
}
m_mesh->getSkinningMatrices(getFrameNr(), m_skinning_matrices.data(),
m_mesh->getSkinningMatrices(getFrameNr(), m_skinning_matrices,
m_saved_transition_frame, TransitingBlend);
recursiveUpdateAbsolutePosition();
for (Armature& arm : m_mesh->getArmatures())
for (GE::Armature& arm : m_mesh->getArmatures())
{
for (unsigned i = 0; i < arm.m_joint_names.size(); i++)
{

View File

@ -54,7 +54,7 @@ private:
float m_saved_transition_frame;
std::vector<std::array<float, 16> > m_skinning_matrices;
std::vector<core::matrix4> m_skinning_matrices;
video::SColorf m_glow_color;
@ -128,7 +128,7 @@ public:
// ------------------------------------------------------------------------
SPShader* getShader(unsigned mesh_buffer_id) const;
// ------------------------------------------------------------------------
const std::array<float, 16>* getSkinningMatrices() const
const core::matrix4* getSkinningMatrices() const
{ return m_skinning_matrices.data(); }
// ------------------------------------------------------------------------
RenderInfo* getRenderInfo(unsigned mb_id) const

View File

@ -734,8 +734,8 @@ void SPMeshLoader::createAnimationData(irr::io::IReadFile* spm)
unsigned accumulated_joints = 0;
for (unsigned i = 0; i < armature_size; i++)
{
m_all_armatures[i].getPose((float)m_bind_frame,
&m_to_bind_pose_matrices[accumulated_joints]);
m_all_armatures[i].getPose(&m_to_bind_pose_matrices[accumulated_joints],
(float)m_bind_frame);
accumulated_joints += m_all_armatures[i].m_joint_used;
}

View File

@ -18,7 +18,7 @@
#ifndef HEADER_SP_MESH_LOADER_HPP
#define HEADER_SP_MESH_LOADER_HPP
#include "graphics/sp/sp_animation.hpp"
#include "ge_animation.hpp"
#include <IMeshLoader.h>
#include <ISceneManager.h>
@ -38,7 +38,7 @@ private:
// ------------------------------------------------------------------------
unsigned m_bind_frame, m_joint_count, m_frame_count;
// ------------------------------------------------------------------------
std::vector<SP::Armature> m_all_armatures;
std::vector<GE::Armature> m_all_armatures;
// ------------------------------------------------------------------------
std::vector<core::matrix4> m_to_bind_pose_matrices;
// ------------------------------------------------------------------------

View File

@ -31,7 +31,6 @@
#include "graphics/material.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"
#include "graphics/sp/sp_mesh_node.hpp"
@ -48,6 +47,7 @@
#include "IMeshManipulator.h"
#include <algorithm>
#include <ge_animation.hpp>
#define SKELETON_DEBUG 0
@ -1299,7 +1299,7 @@ void KartModel::initInverseBoneMatrices()
SPMesh* spm = dynamic_cast<SPMesh*>(m_mesh);
if (spm)
{
for (Armature& arm : spm->getArmatures())
for (GE::Armature& arm : spm->getArmatures())
{
arm.getInterpolatedMatrices(striaght_frame);
for (auto& p : arm.m_world_matrices)