-
Notifications
You must be signed in to change notification settings - Fork 1
Custom Parts
sppmacd edited this page Aug 28, 2021
·
1 revision
In this tutorial you will learn how to create custom Parts.
The whole code needs #include <ege/scene.h>
to work.
All parts are derived from EGE::Part
class. The derived class must override these methods:
class MyPart : public EGE::Part
{
// Load a part from part data
virtual bool deserialize(SharedPtr<ObjectMap> data);
// Render a part; all coordinates are part local (you don't need to manually calculate rotation etc.)
virtual void render(Renderer& renderer) const;
// Update a geometry of the part; called just before rendering at first tick or if `setGeometryNeedUpdate()` was called by user
// This is not required by recommended (instead of setting up everything in `serialize`)
virtual void updateGeometry(Renderer& renderer);
}
See e.g. RectanglePart.
The new parts need to be registered within a registry:
EGE::PartStub::PartCreators.add("MyPart", EGE_PART_CREATOR(MyPart));
You can use this part like any other part:
{"type": "MyPart", "name": "..."}
Full source codes can be downloaded in examples repo.