Skip to content

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.

Defining a part

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.

Registering a part

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": "..."}
Clone this wiki locally