Allow animated models in track to have different animation
This commit is contained in:
parent
6486d1548b
commit
6a142e8d2e
@ -178,6 +178,9 @@ namespace scene
|
||||
\return The newly created clone of this node. */
|
||||
virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0) = 0;
|
||||
|
||||
virtual u32 getAnimationSetNum() = 0;
|
||||
virtual void addAnimationSet(u32 start, u32 end) = 0;
|
||||
virtual void useAnimationSet(u32 set_num) = 0;
|
||||
};
|
||||
|
||||
} // end namespace scene
|
||||
|
@ -992,6 +992,15 @@ ISceneNode* CAnimatedMeshSceneNode::clone(ISceneNode* newParent, ISceneManager*
|
||||
return newNode;
|
||||
}
|
||||
|
||||
void CAnimatedMeshSceneNode::useAnimationSet(u32 set_num)
|
||||
{
|
||||
if (m_animation_set.empty())
|
||||
{
|
||||
setFrameLoop(getStartFrame(), getEndFrame());
|
||||
return;
|
||||
}
|
||||
setFrameLoop(m_animation_set[set_num * 2], m_animation_set[set_num * 2 + 1]);
|
||||
}
|
||||
|
||||
} // end namespace scene
|
||||
} // end namespace irr
|
||||
|
@ -19,6 +19,8 @@ namespace scene
|
||||
|
||||
class CAnimatedMeshSceneNode : public IAnimatedMeshSceneNode
|
||||
{
|
||||
private:
|
||||
core::array<u32> m_animation_set;
|
||||
public:
|
||||
|
||||
//! constructor
|
||||
@ -158,6 +160,14 @@ namespace scene
|
||||
\return The newly created clone of this node. */
|
||||
virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0);
|
||||
|
||||
virtual u32 getAnimationSetNum() { return m_animation_set.size() / 2; }
|
||||
virtual void addAnimationSet(u32 start, u32 end)
|
||||
{
|
||||
m_animation_set.push_back(start);
|
||||
m_animation_set.push_back(end);
|
||||
}
|
||||
virtual void useAnimationSet(u32 set_num);
|
||||
|
||||
protected:
|
||||
|
||||
//! Get a static mesh for the current frame of this animated mesh
|
||||
|
@ -101,8 +101,6 @@ void ThreeStrikesBattle::reset()
|
||||
25.0f : 20.0f;
|
||||
|
||||
const unsigned int kart_amount = (unsigned int)m_karts.size();
|
||||
|
||||
int idCamera = 0;
|
||||
for(unsigned int n=0; n<kart_amount; n++)
|
||||
{
|
||||
if (dynamic_cast<SpareTireAI*>(m_karts[n]->getController()) != NULL)
|
||||
|
@ -102,6 +102,24 @@ LODNode* ModelDefinitionLoader::instanciateAsLOD(const XMLNode* node, scene::ISc
|
||||
scene::IAnimatedMeshSceneNode* scene_node = irr_driver
|
||||
->addAnimatedMesh(a_mesh, group[m].m_model_file, NULL, ri);
|
||||
|
||||
std::vector<int> frames_start;
|
||||
if (node)
|
||||
node->get("frame-start", &frames_start);
|
||||
|
||||
std::vector<int> frames_end;
|
||||
if (node)
|
||||
node->get("frame-end", &frames_end);
|
||||
|
||||
if (frames_start.empty() && frames_end.empty())
|
||||
{
|
||||
frames_start.push_back(scene_node->getStartFrame());
|
||||
frames_end.push_back(scene_node->getEndFrame());
|
||||
}
|
||||
assert(frames_start.size() == frames_end.size());
|
||||
for (unsigned int i = 0 ; i < frames_start.size() ; i++)
|
||||
scene_node->addAnimationSet(frames_start[i], frames_end[i]);
|
||||
scene_node->useAnimationSet(0);
|
||||
|
||||
m_track->handleAnimatedTextures(scene_node, *group[m].m_xml);
|
||||
|
||||
lod_node->add(group[m].m_distance, scene_node, true);
|
||||
|
@ -314,6 +314,28 @@ TrackObjectPresentationLOD::~TrackObjectPresentationLOD()
|
||||
irr_driver->removeNode(m_node);
|
||||
} // TrackObjectPresentationLOD
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void TrackObjectPresentationLOD::reset()
|
||||
{
|
||||
LODNode* ln = dynamic_cast<LODNode*>(m_node);
|
||||
if (ln)
|
||||
{
|
||||
for (scene::ISceneNode* node : ln->getAllNodes())
|
||||
{
|
||||
scene::IAnimatedMeshSceneNode* a_node =
|
||||
dynamic_cast<scene::IAnimatedMeshSceneNode*>(node);
|
||||
if (a_node)
|
||||
{
|
||||
RandomGenerator rg;
|
||||
int animation_set = 0;
|
||||
if (a_node->getAnimationSetNum() > 0)
|
||||
animation_set = rg.get(a_node->getAnimationSetNum());
|
||||
a_node->useAnimationSet(animation_set);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // reset
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
TrackObjectPresentationMesh::TrackObjectPresentationMesh(
|
||||
const XMLNode& xml_node,
|
||||
@ -481,8 +503,6 @@ void TrackObjectPresentationMesh::init(const XMLNode* xml_node,
|
||||
m_node = irr_driver->addMesh(m_mesh, m_model_file, parent, m_render_info);
|
||||
enabled = false;
|
||||
m_force_always_hidden = true;
|
||||
m_frame_start = 0;
|
||||
m_frame_end = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -490,8 +510,6 @@ void TrackObjectPresentationMesh::init(const XMLNode* xml_node,
|
||||
m_node = irr_driver->addMesh(m_mesh, m_model_file, parent, m_render_info);
|
||||
enabled = false;
|
||||
m_force_always_hidden = true;
|
||||
m_frame_start = 0;
|
||||
m_frame_end = 0;
|
||||
Track *track = Track::getCurrentTrack();
|
||||
if (track && track && xml_node)
|
||||
track->addPhysicsOnlyNode(m_node);
|
||||
@ -516,13 +534,23 @@ void TrackObjectPresentationMesh::init(const XMLNode* xml_node,
|
||||
m_model_file, parent, m_render_info);
|
||||
m_node = node;
|
||||
|
||||
m_frame_start = node->getStartFrame();
|
||||
std::vector<int> frames_start;
|
||||
if (xml_node)
|
||||
xml_node->get("frame-start", &m_frame_start);
|
||||
xml_node->get("frame-start", &frames_start);
|
||||
|
||||
m_frame_end = node->getEndFrame();
|
||||
std::vector<int> frames_end;
|
||||
if (xml_node)
|
||||
xml_node->get("frame-end", &m_frame_end);
|
||||
xml_node->get("frame-end", &frames_end);
|
||||
|
||||
if (frames_start.empty() && frames_end.empty())
|
||||
{
|
||||
frames_start.push_back(node->getStartFrame());
|
||||
frames_end.push_back(node->getEndFrame());
|
||||
}
|
||||
assert(frames_start.size() == frames_end.size());
|
||||
for (unsigned int i = 0 ; i < frames_start.size() ; i++)
|
||||
node->addAnimationSet(frames_start[i], frames_end[i]);
|
||||
node->useAnimationSet(0);
|
||||
|
||||
Track *track = Track::getCurrentTrack();
|
||||
if (track && track && xml_node)
|
||||
@ -542,9 +570,6 @@ void TrackObjectPresentationMesh::init(const XMLNode* xml_node,
|
||||
stkmesh->setIsDisplacement(displacing);
|
||||
#endif
|
||||
|
||||
m_frame_start = 0;
|
||||
m_frame_end = 0;
|
||||
|
||||
Track *track = Track::getCurrentTrack();
|
||||
if (track && xml_node)
|
||||
track->handleAnimatedTextures(m_node, *xml_node);
|
||||
@ -593,7 +618,11 @@ void TrackObjectPresentationMesh::reset()
|
||||
|
||||
// irrlicht's "setFrameLoop" is a misnomer, it just sets the first and
|
||||
// last frame, even if looping is disabled
|
||||
a_node->setFrameLoop(m_frame_start, m_frame_end);
|
||||
RandomGenerator rg;
|
||||
int animation_set = 0;
|
||||
if (a_node->getAnimationSetNum() > 0)
|
||||
animation_set = rg.get(a_node->getAnimationSetNum());
|
||||
a_node->useAnimationSet(animation_set);
|
||||
}
|
||||
} // reset
|
||||
|
||||
|
@ -207,6 +207,7 @@ public:
|
||||
ModelDefinitionLoader& model_def_loader,
|
||||
RenderInfo* ri);
|
||||
virtual ~TrackObjectPresentationLOD();
|
||||
virtual void reset() OVERRIDE;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
@ -226,12 +227,6 @@ private:
|
||||
/** True if the object is in the skybox */
|
||||
bool m_is_in_skybox;
|
||||
|
||||
/** Start frame of the animation to be played. */
|
||||
unsigned int m_frame_start;
|
||||
|
||||
/** End frame of the animation to be played. */
|
||||
unsigned int m_frame_end;
|
||||
|
||||
std::string m_model_file;
|
||||
|
||||
RenderInfo* m_render_info;
|
||||
|
Loading…
x
Reference in New Issue
Block a user