This example operator adds an offset to a joint transform.
#include <AtomsGraph/Ports.h>
#include <Atoms/Globals.h>
#include <Atoms/Graph/Operator.h>
{
public:
NODE_STANDARD_MEMBERS
JointOffsetOperator();
virtual ~JointOffsetOperator();
private:
int m_jointId;
bool m_first;
};
#define JOINT_OFFSET_OPERATOR_ID 9999991
NODE_STANDARD_MEMBERS_IMPL(JointOffsetOperator)
unsigned int JointOffsetOperator::staticTypeId() { return JOINT_OFFSET_OPERATOR_ID; }
std::string JointOffsetOperator::staticTypeStr() { return std::string("JointOffsetOperator"); }
JointOffsetOperator::JointOffsetOperator() : Operator()
{
m_jointName->set("");
addInputPort(m_jointName);
addInputPort(m_offsetMatrix);
addInputPort(m_inPose);
m_worldSpace->set(false);
addInputPort(m_worldSpace );
m_jointId= -1;
m_first = true;
}
JointConstraintOperator::~JointConstraintOperator()
{
}
bool JointConstraintOperator::compute()
{
{
return false;
}
outPose = inPose;
if (!m_agent)
{
return false;
}
if(!m_agent->agentType())
{
return false;
}
if (m_first)
{
m_jointId = skeleton.
jointId(m_targetJoint->getRef());
}
if (m_jointId == -1)
{
Logger::error() << "Could not find " << m_targetJoint->getRef() << "joint.";
return false;
}
if (worldSpace->get())
{
poser.setWorldMatrix(pose, m_offsetMatrix->getRef()* currentMtx, jointIdTmp);
}
else
{
}
return true;
}
Operator node.
Definition: Operator.h:26
Joint pose.
Definition: JointPose.h:20
void setMatrix(const Matrix &matrix)
Sets the joint matrix.
Matrix matrix() const
Gets the joint matrix.
Pose class.
Definition: Pose.h:32
unsigned short numJoints() const
Gets the number of joints.
Definition: Pose.impl.h:12
JointPose & jointPose(unsigned short index)
Gets the joint pose.
Definition: Pose.impl.h:17
Poser class.
Definition: Poser.h:24
Skeleton class.
Definition: Skeleton.h:68
int jointId(const std::string &name) const
Gets the joint id.
Definition: Skeleton.impl.h:174
virtual bool compute(const ComputeData *computeData)
Compute function.
Generic node port class.
Definition: PortTemplate.h:24
static LogProxy warning()
Get logger proxy warning.
static LogProxy error()
Get logger proxy error.
AtomsMath::Matrix Matrix
Matrix class.
Definition: AtomsMath.h:63
The operator can be added by this custom behaviour module.
#include <Atoms/BehaviourModule.h>
{
public:
JointOffsetModule ();
virtual ~JointOffsetModule ();
};
{
return new JointOffsetModule();
}
JointOffsetModule::JointOffsetModule() :
{
AtomsCore::StringMetadata jointName("");
addAttribute("jointName", &jointName, false);
AtomsCore::MatrixMetadata offsetMatrix;
addAttribute("offsetMatrix", &offsetMatrix, true);
AtomsCore::BoolMetadata worldSpace(false);
addAttribute("worldSpace", &worldSpace);
}
JointOffsetModule::~JointOffsetModule()
{
}
void JointOffsetModule::agentsCreated(
const std::vector<Atoms::Agent*>& agents,
Atoms::AgentGroup* agentGroup)
{
const std::string& jointName= metadata.
getTypedEntry<AtomsCore::StringMetadata>(
"jointName")->get();
bool worldSpace = metadata.
getTypedEntry<AtomsCore::BoolMetadata>(
"worldSpace")->get();
tbb::parallel_for(tbb::blocked_range<unsigned int>(0, agents.size()),
[&](const tbb::blocked_range<unsigned int>& r)
{
char groupIdChar[12];
std::string groupIdStr;
groupIdStr.reserve(12);
for (unsigned int i = r.begin(); i < r.end(); i++)
{
Atoms::Agent* agent = agents[i];
Atoms::AgentBehaviourNetwork& network = agent->network();
Atoms::Operator* endOperator = network.buildPoseNode();
Atoms::JointOffsetOperator* jointOffset = static_cast<Atoms::JointOffsetOperator*>(network.manager().createNode(Atoms::JointOffsetOperator::staticTypeStr(), "jointOffset"));
jointOffset->setAgent(agent);
network.manager().connectAttr(endOperator->name(), "outPose", jointOffset ->name(), "inPose");
jointOffset->getInputPort<AtomsGraph::StringPort>("jointName")->set(jointName);
jointOffset->getInputPort<AtomsGraph::BooleanPort>("worldSpace")->set(worldSpace );
AtomsCore::Matrix agentOffsetMatrix = offsetMatrix;
AtomsPtr<AtomsCore::IntMetadata> groupIdPtr = agent->metadata().getTypedEntry<AtomsCore::IntMetadata>(ATOMS_AGENT_GROUPID);
if (groupIdPtr)
{
sprintf(groupIdChar, "%d", groupIdPtr->value());
groupIdStr = groupIdChar;
if (offsetMatrixOverrideMap)
{
AtomsPtr<AtomsCore::MatrixMetadata> offsetMatrixAgentMeta = offsetMatrixOverrideMap->getTypedEntry<AtomsCore::MatrixMetadata>(groupIdStr);
if (offsetMatrixAgentMeta)
offsetMatrix = offsetMatrixAgentMeta->get();
}
}
jointOffset->getInputPort<AtomsGraph::MatrixPort>("offsetMatrix")->set(offsetMatrix);
network.setBuildPoseNode(jointOffset);
}
});
}
extern "C"
{
ATOMSPLUGIN_EXPORT bool initializePlugin()
{
manager.
registerNode(JointConstraintOperator::staticTypeStr(), &JointConstraintOperator::creator);
moduleManager.
registerBehaviourModule(
"SimpleJointOffset", &JointOffsetModule::creator, Atoms::JointOffsetModule::kNative);
return true;
}
ATOMSPLUGIN_EXPORT bool unitializePlugin()
{
return true;
}
}
Agent group.
Definition: AgentGroup.h:36
Behaviour module.
Definition: BehaviourModule.h:32
virtual void agentsCreated(const std::vector< Agent * > &agents, AgentGroup *agentGroup=nullptr)
Agents Created.
Behaviour module factory.
Definition: BehaviourModules.h:22
bool deregisterBehaviourModule(const std::string &name)
Deregisters a Behaviour module type from the factory.
static BehaviourModules & instance()
Singleton access.
bool registerBehaviourModule(const std::string &moduleName, creatorFn func, unsigned int moduleType=kNative, bool replace=false, const std::string category="")
Registers a behaviour module in the factory.
Node factory.
Definition: NodeFactory.h:24
static NodeFactory & instance()
Singleton access.
void registerNode(const std::string &name, creatorFn funct)
Registers a node type.
void deregisterNode(const std::string &name)
Deregisters a node type.
static LogProxy info()
Get logger proxy info.
Atoms namespace.
Definition: Agent.h:29