Hello guys,
I have 3 different classes.
-Engine
-NodeBase
-Player
I defined a most of variables in Engine.h and use them at other classes via #include “Engine.h”
(like playerNP as NodePath or anim_control_collection as AnimControlCollection etc…)
Im trying to make playing animations. Here is my class functions;
//ENGINE CLASS
NodePath Engine::loadModel(string sNodeName, string sPath){
NodePath NP = NodePath(sNodeName);
NP = window->load_model(framework->get_models(), sPath);
return NP;
}
NodePath Engine::loadModelRender(string sNodeName, string sPath) {
NodePath NP = NodePath(sNodeName);
NP = window->load_model(render, sPath);
return NP;
}
NodePath Engine::loadModelToModel(NodePath sNode, string sPath)
{
return window->load_model(sNode, sPath);
}
//NODEBASE CLASS
NodePath NodeBase::loadPlayerModel(const std::string modelName, LVecBase3 modelSize, LVecBase3 modelPos)
{
const string _model_path = "bin/neuera/characters/models/" + modelName + ".bam";
NodePath NP = Engine::loadModelRender("instance", _model_path);
NP.set_name(modelName);
NP.set_scale(modelSize);
NP.set_pos(modelPos);
return NP;
}
NodePath NodeBase::loadInstanceModel(const std::string modelName, LVecBase3 modelSize, LVecBase3 modelPos)
{
const string _model_path = "bin/neuera/models/instances/" + modelName + ".bam";
NodePath NP = Engine::loadModelRender("instance", _model_path);
NP.set_name(modelName);
NP.set_scale(modelSize);
NP.set_pos(modelPos);
return NP;
}
void NodeBase::loadAnimToInstance(NodePath _node, const std::string _anim)
{
const string _actual_anim_name = _node.get_name() + "-" + _anim + ".bam";
const string _anim_path = "bin/neuera/characters/anims/" + _actual_anim_name;
Engine::loadModelToModel(_node, _anim_path);
auto_bind(_node.node(), anim_control_collection);
anim_control_collection.loop_all(true);
}
void NodeBase::setLoopMotion(NodePath _node, const std::string _anim)
{
const string _actual_anim_name = _node.get_name() + "-" + _anim + ".bam";
anim_control_collection.loop(_actual_anim_name, true);
}
void NodeBase::pushOnceMotion(NodePath _node, const std::string _anim)
{
const string _actual_anim_name = _node.get_name() + "-" + _anim + ".bam";
anim_control_collection.play(_actual_anim_name);
}
//PLAYER CLASS
Player::Player() {
playerNP = NodeBase::loadPlayerModel("orc", { 5,5,5 }, { 135,182,0 });
NodeBase::loadAnimToInstance(playerNP, "idle");
NodeBase::loadAnimToInstance(playerNP, "run");
}
//Model: "orc.bam"
//Anims: "orc-idle.bam" and "orc-run.bam"
and i tried to test it with define_key;
void TestBindFunc(const Event* pTheEvent, void* pData) {
NodeBase::setLoopMotion(playerNP, "idle"); //also tried pushOnceMotion
std::cout << "Playing idle.." << std::endl;
}
void TestBindFunc2(const Event* pTheEvent, void* pData) {
NodeBase::setLoopMotion(playerNP, "run");//also tried pushOnceMotion
std::cout << "Playing run.." << std::endl;
}
//DEFINE_KEYS
framework->define_key("s-up", "Test Bind s", TestBindFunc, nullptr);
framework->define_key("w-up", "Test Bind w", TestBindFunc2, nullptr);
But it didn’t work. Im not sure if this usage is ok for AnimControlCollection?
What is the right way to use AnimControlCollection?
Thanks all…