Try to copy the animated kart mesh.
This commit is contained in:
parent
0aa6b9fcd1
commit
9dd46b6755
@ -67,6 +67,7 @@
|
||||
#include "utils/vs.hpp"
|
||||
|
||||
#include <irrlicht.h>
|
||||
#include "../lib/irrlicht/source/Irrlicht/CSkinnedMesh.h"
|
||||
|
||||
/* Build-time check that the Irrlicht we're building against works for us.
|
||||
* Should help prevent distros building against an incompatible library.
|
||||
@ -1000,6 +1001,63 @@ scene::IMesh *IrrDriver::getMesh(const std::string &filename)
|
||||
return am->getMesh(0);
|
||||
} // getMesh
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Create a skinned mesh which has copied all meshbuffers and joints of the
|
||||
* original mesh. Note, that this will not copy any other information like
|
||||
* joints data.
|
||||
* \param mesh Original mesh
|
||||
* \return Newly created skinned mesh. You should call drop() when you don't
|
||||
* need it anymore.
|
||||
*/
|
||||
scene::IAnimatedMesh *IrrDriver::copyAnimatedMesh(scene::IAnimatedMesh *orig)
|
||||
{
|
||||
using namespace scene;
|
||||
CSkinnedMesh *mesh = dynamic_cast<CSkinnedMesh*>(orig);
|
||||
if (!mesh)
|
||||
{
|
||||
Log::error("copyAnimatedMesh", "Given mesh was not a skinned mesh.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ISkinnedMesh* skinned_mesh = m_scene_manager->createSkinnedMesh();
|
||||
|
||||
for (u32 i = 0; i < mesh->getMeshBuffers().size(); i++)
|
||||
{
|
||||
SSkinMeshBuffer * buffer = skinned_mesh->addMeshBuffer();
|
||||
*buffer = *(mesh->getMeshBuffers()[i]);
|
||||
}
|
||||
|
||||
for (u32 j = 0; j < mesh->getAllJoints().size(); ++j)
|
||||
{
|
||||
ISkinnedMesh::SJoint *joint = skinned_mesh->addJoint();
|
||||
*joint = *(mesh->getAllJoints()[j]);
|
||||
}
|
||||
|
||||
// fix children pointers (they still have old pointers)
|
||||
core::array<ISkinnedMesh::SJoint*> & new_joints = skinned_mesh->getAllJoints();
|
||||
core::array<ISkinnedMesh::SJoint*> & old_joints = mesh->getAllJoints();
|
||||
for (u32 i = 0; i < new_joints.size(); ++i)
|
||||
{
|
||||
ISkinnedMesh::SJoint * joint = new_joints[i];
|
||||
for (u32 c = 0; c < joint->Children.size(); ++c)
|
||||
{
|
||||
// the child is one of the oldJoints and must be replaced by the newjoint on the same index
|
||||
for (u32 k = 0; k < old_joints.size(); ++k)
|
||||
{
|
||||
if (joint->Children[c] == old_joints[k])
|
||||
{
|
||||
joint->Children[c] = new_joints[k];
|
||||
break;
|
||||
}
|
||||
} // k < old_joints.size
|
||||
} // c < joint->Children.size()
|
||||
} // i < new_joints.size()
|
||||
|
||||
skinned_mesh->finalize();
|
||||
|
||||
return skinned_mesh;
|
||||
} // copyAnimatedMesh
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Sets the material flags in this mesh depending on the settings in
|
||||
* material_manager.
|
||||
|
@ -457,6 +457,7 @@ public:
|
||||
void setAllMaterialFlags(scene::IMesh *mesh) const;
|
||||
scene::IAnimatedMesh *getAnimatedMesh(const std::string &name);
|
||||
scene::IMesh *getMesh(const std::string &name);
|
||||
scene::IAnimatedMesh *copyAnimatedMesh(scene::IAnimatedMesh *orig);
|
||||
video::ITexture *applyMask(video::ITexture* texture,
|
||||
const std::string& mask_path);
|
||||
void displayFPS();
|
||||
|
@ -260,7 +260,7 @@ KartModel::~KartModel()
|
||||
#endif
|
||||
|
||||
} // ~KartModel
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** This function returns a copy of this object. The memory is allocated
|
||||
* here, but needs to be managed (esp. freed) by the calling function.
|
||||
@ -280,7 +280,7 @@ KartModel* KartModel::makeCopy()
|
||||
km->m_kart_height = m_kart_height;
|
||||
km->m_kart_highest_point= m_kart_highest_point;
|
||||
km->m_kart_lowest_point = m_kart_lowest_point;
|
||||
km->m_mesh = m_mesh;
|
||||
km->m_mesh = irr_driver->copyAnimatedMesh(m_mesh);
|
||||
km->m_model_filename = m_model_filename;
|
||||
km->m_animation_speed = m_animation_speed;
|
||||
km->m_current_animation = AF_DEFAULT;
|
||||
@ -894,7 +894,8 @@ void KartModel::update(float dt, float rotation_dt, float steer, float speed)
|
||||
m_animated_node->setCurrentFrame(frame);
|
||||
} // update
|
||||
//-----------------------------------------------------------------------------
|
||||
void KartModel::attachHat(){
|
||||
void KartModel::attachHat()
|
||||
{
|
||||
m_hat_node = NULL;
|
||||
if(m_hat_name.size()>0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user