]> git.lizzy.rs Git - minetest.git/blobdiff - src/content_cao.cpp
Allow the LUA API to set animations to meshes as well as the animation speed. Also...
[minetest.git] / src / content_cao.cpp
index b3c0370b8a058977b8731dfdb973372535e3cfcc..4df238b249c551ced6bf3a38cf7137b4d8581895 100644 (file)
@@ -42,6 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "map.h"
 #include <IMeshManipulator.h>
 #include <IAnimatedMeshSceneNode.h>
+#include <IBoneSceneNode.h>
 
 class Settings;
 struct ToolCapabilities;
@@ -805,7 +806,8 @@ class GenericCAO : public ClientActiveObject
                        if(mesh)
                        {
                                m_animated_meshnode = smgr->addAnimatedMeshSceneNode(mesh, NULL);
-                               
+                               m_animated_meshnode->setMD2Animation(scene::EMAT_STAND);
+                               m_animated_meshnode->animateJoints(); // Needed for some animations
                                m_animated_meshnode->setScale(v3f(m_prop.visual_size.X,
                                                m_prop.visual_size.Y,
                                                m_prop.visual_size.X));
@@ -922,6 +924,7 @@ class GenericCAO : public ClientActiveObject
                        m_visuals_expired = false;
                        removeFromScene();
                        addToScene(m_smgr, m_gamedef->tsrc(), m_irr);
+                       updateAnimations();
                }
 
                if(m_prop.physical){
@@ -1066,8 +1069,7 @@ class GenericCAO : public ClientActiveObject
                                        if(texturestring == "")
                                                continue; // Empty texture string means don't modify that material
                                        texturestring += mod;
-                                       video::IVideoDriver* driver = m_animated_meshnode->getSceneManager()->getVideoDriver();
-                                       video::ITexture* texture = driver->getTexture(texturestring.c_str());
+                                       video::ITexture* texture = tsrc->getTextureRaw(texturestring);
                                        if(!texture)
                                        {
                                                errorstream<<"GenericCAO::updateTextures(): Could not load texture "<<texturestring<<std::endl;
@@ -1135,6 +1137,25 @@ class GenericCAO : public ClientActiveObject
                }
        }
 
+       void updateAnimations()
+       {
+               if(!m_animated_meshnode)
+                       return;
+
+               m_animated_meshnode->setFrameLoop(m_prop.animation_frames.X, m_prop.animation_frames.Y);
+               m_animated_meshnode->setAnimationSpeed(m_prop.animation_speed);
+               m_animated_meshnode->setTransitionTime(m_prop.animation_blend);
+
+               for(std::map<std::string, v3f>::const_iterator ii = m_prop.animation_bone_position.begin(); ii != m_prop.animation_bone_position.end(); ++ii){
+                       if((*ii).second.X || (*ii).second.Y || (*ii).second.Z) { }
+                       // Bone positioning code will go here
+               }
+               for(std::map<std::string, v3f>::const_iterator ii = m_prop.animation_bone_rotation.begin(); ii != m_prop.animation_bone_rotation.end(); ++ii){
+                       if((*ii).second.X || (*ii).second.Y || (*ii).second.Z) { }
+                       // Bone rotation code will go here
+               }
+       }
+
        void processMessage(const std::string &data)
        {
                //infostream<<"GenericCAO: Got message"<<std::endl;