From b75dec1fbc4227be8f766dadb2ca16cbf5a967fb Mon Sep 17 00:00:00 2001 From: Benau Date: Mon, 25 Jul 2022 10:54:27 +0800 Subject: [PATCH] Move struct Armature to GE --- .../graphics_engine/include/ge_animation.hpp | 62 ++++++++++--------- src/graphics/b3d_mesh_loader.cpp | 2 +- src/graphics/sp/sp_mesh.cpp | 8 +-- src/graphics/sp/sp_mesh.hpp | 12 ++-- src/graphics/sp/sp_mesh_node.cpp | 8 +-- src/graphics/sp/sp_mesh_node.hpp | 4 +- src/graphics/sp_mesh_loader.cpp | 4 +- src/graphics/sp_mesh_loader.hpp | 4 +- src/karts/kart_model.cpp | 4 +- 9 files changed, 58 insertions(+), 50 deletions(-) rename src/graphics/sp/sp_animation.hpp => lib/graphics_engine/include/ge_animation.hpp (82%) diff --git a/src/graphics/sp/sp_animation.hpp b/lib/graphics_engine/include/ge_animation.hpp similarity index 82% rename from src/graphics/sp/sp_animation.hpp rename to lib/graphics_engine/include/ge_animation.hpp index f56efd631..b560aaae2 100644 --- a/src/graphics/sp/sp_animation.hpp +++ b/lib/graphics_engine/include/ge_animation.hpp @@ -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 #include #include -#include #include +#include +#include #include #include 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* 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) diff --git a/src/graphics/b3d_mesh_loader.cpp b/src/graphics/b3d_mesh_loader.cpp index 88d8c7972..d84374a8d 100644 --- a/src/graphics/b3d_mesh_loader.cpp +++ b/src/graphics/b3d_mesh_loader.cpp @@ -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 +#include #ifndef SERVER_ONLY #include diff --git a/src/graphics/sp/sp_mesh.cpp b/src/graphics/sp/sp_mesh.cpp index 2ef638a9a..aeb1ef8e8 100644 --- a/src/graphics/sp/sp_mesh.cpp +++ b/src/graphics/sp/sp_mesh.cpp @@ -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 #include 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* dest, +void SPMesh::getSkinningMatrices(f32 frame, std::vector& 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) diff --git a/src/graphics/sp/sp_mesh.hpp b/src/graphics/sp/sp_mesh.hpp index ea45f11b1..509913a84 100644 --- a/src/graphics/sp/sp_mesh.hpp +++ b/src/graphics/sp/sp_mesh.hpp @@ -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 m_all_armatures; + std::vector m_all_armatures; public: // ------------------------------------------------------------------------ @@ -150,9 +154,9 @@ public: // ------------------------------------------------------------------------ virtual void updateBoundingBox(void); // ------------------------------------------------------------------------ - std::vector& getArmatures() { return m_all_armatures; } + std::vector& getArmatures() { return m_all_armatures; } // ------------------------------------------------------------------------ - void getSkinningMatrices(f32 frame, std::array* dest, + void getSkinningMatrices(f32 frame, std::vector& dest, float frame_interpolating = -1.0f, float rate = -1.0f); // ------------------------------------------------------------------------ s32 getJointIDWithArm(const c8* name, unsigned* arm_id) const; diff --git a/src/graphics/sp/sp_mesh_node.cpp b/src/graphics/sp/sp_mesh_node.cpp index c60f4f46c..90a757d0e 100644 --- a/src/graphics/sp/sp_mesh_node.cpp +++ b/src/graphics/sp/sp_mesh_node.cpp @@ -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 +#include 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++) { diff --git a/src/graphics/sp/sp_mesh_node.hpp b/src/graphics/sp/sp_mesh_node.hpp index 78581d47b..389cd1a1b 100644 --- a/src/graphics/sp/sp_mesh_node.hpp +++ b/src/graphics/sp/sp_mesh_node.hpp @@ -54,7 +54,7 @@ private: float m_saved_transition_frame; - std::vector > m_skinning_matrices; + std::vector m_skinning_matrices; video::SColorf m_glow_color; @@ -128,7 +128,7 @@ public: // ------------------------------------------------------------------------ SPShader* getShader(unsigned mesh_buffer_id) const; // ------------------------------------------------------------------------ - const std::array* getSkinningMatrices() const + const core::matrix4* getSkinningMatrices() const { return m_skinning_matrices.data(); } // ------------------------------------------------------------------------ RenderInfo* getRenderInfo(unsigned mb_id) const diff --git a/src/graphics/sp_mesh_loader.cpp b/src/graphics/sp_mesh_loader.cpp index 66582c883..48df248a8 100644 --- a/src/graphics/sp_mesh_loader.cpp +++ b/src/graphics/sp_mesh_loader.cpp @@ -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; } diff --git a/src/graphics/sp_mesh_loader.hpp b/src/graphics/sp_mesh_loader.hpp index 7b681ce43..efcca55c3 100644 --- a/src/graphics/sp_mesh_loader.hpp +++ b/src/graphics/sp_mesh_loader.hpp @@ -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 #include @@ -38,7 +38,7 @@ private: // ------------------------------------------------------------------------ unsigned m_bind_frame, m_joint_count, m_frame_count; // ------------------------------------------------------------------------ - std::vector m_all_armatures; + std::vector m_all_armatures; // ------------------------------------------------------------------------ std::vector m_to_bind_pose_matrices; // ------------------------------------------------------------------------ diff --git a/src/karts/kart_model.cpp b/src/karts/kart_model.cpp index 0a0282c00..4f6327183 100644 --- a/src/karts/kart_model.cpp +++ b/src/karts/kart_model.cpp @@ -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 +#include #define SKELETON_DEBUG 0 @@ -1299,7 +1299,7 @@ void KartModel::initInverseBoneMatrices() SPMesh* spm = dynamic_cast(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)