You can create custom dependency graph nodes, which carry out custom operations based on their incoming data. Each node type you write can be added to the agent dependency graph.
This is an example of a node that returns the intersection between a ray and an height field.
#include <AtomsGraph/Globals.h>
#include <Atoms/Globals.h>
#include <AtomsGraph/Ports.h>
#include <AtomsGraph/NodeFactory.h>
#include <Atoms/HeightFields.h>
#include <Atoms/HeightField.h>
class HeighFieldIntersectorNode:
{
public:
NODE_STANDARD_MEMBERS
HeighFieldIntersectorNode();
virtual ~HeighFieldIntersectorNode();
private:
};
#define HEIGHTFIELDINTERSECTOR_NODE_ID 999999
NODE_STANDARD_MEMBERS_IMPL(HeighFieldIntersectorNode)
unsigned int HeighFieldIntersectorNode::staticTypeId() { return HEIGHTFIELDINTERSECTOR_NODE_ID; }
std::string HeighFieldIntersectorNode::staticTypeStr() { return std::string("HeighFieldIntersectorNode");}
HeighFieldIntersectorNode::HeighFieldIntersectorNode()
{
addInputPort(m_heightFieldNamePort);
addInputPort(m_rayOriginPort);
addInputPort(m_rayDirectionPort);
addOutputPort(m_outPositionPort);
addOutputPort(m_outNormalPort);
}
HeighFieldIntersectorNode::~HeighFieldIntersectorNode()
{
}
bool HeighFieldIntersectorNode::compute()
{
const std::string& heightFieldName = heightFieldNamePort->getRef();
if (!heightField)
return false;
float param, u, v;
unsigned int faceId = 0;
if (heightField->
intersect(rayOriginPort->getRef(), m_rayDirectionPort->getRef(), param, faceId, u, v,
false))
{
AtomsCore::Vector3 projectedPos = rayOriginPort->getRef() + double(param) * m_rayDirectionPort->getRef();
std::vector<AtomsCore::Vector3f> &normals = heightField->
normals();
AtomsCore::Vector3 hfNormal = u * normals[faceId * 3] + v * normals[faceId * 3 + 1] + (1.0f - u - v) * normals[faceId * 3 + 2];
hfNormal.normalize();
m_outPositionPort->set(projectedPos);
m_outNormalPort->set(hfNormal);
}
return true;
}
extern "C"
{
ATOMSPLUGIN_EXPORT bool initializePlugin()
{
manager.
registerNode(HeighFieldIntersectorNode::staticTypeStr(), &HeighFieldIntersectorNode::creator);
return true;
}
ATOMSPLUGIN_EXPORT bool unitializePlugin()
{
return true;
}
}
Container for all agent types.
Definition: HeightFields.h:19
static HeightFields & instance()
Singleton access.
AtomsPtr< HeightField > heightField(const std::string &name)
Gets an hf.
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.
virtual bool compute(const ComputeData *computeData)
Compute function.
Generic node port class.
Definition: PortTemplate.h:24
static LogProxy info()
Get logger proxy info.
Mesh class.
Definition: Mesh.h:30
std::vector< AtomsMath::Vector3f > & normals()
Get point normal (normal per face per vertex)
Definition: Mesh.impl.h:21
virtual bool intersect(const AtomsMath::Vector3f &orig, const AtomsMath::Vector3f &dir, float ¶m, unsigned int &outFaceId, float &outU, float &outV, bool bothDirection=false) const
intersect
AtomsMath::Vector3 Vector3
Vector3 class.
Definition: AtomsMath.h:57