Scene System

Scene System

Scenes, nodes, and components — the core building blocks of every Nova-3D world.

Overview

Nova-3D uses a scene graph: a hierarchy of nodes, each of which can have components attached to it. This pattern is familiar from engines like Urho3D, Godot, and Unity. The three main classes are:

  • Nova3D::Scene — the root; owns the scene graph
  • Nova3D::Node — a spatial entity with a name and transform
  • Nova3D::Component — behavior or visual data attached to a node

Scene

Create a scene by constructing it with the context:

auto* scene = new Nova3D::Scene(GetContext());

The scene itself is the root node. You add child nodes to it to build the world.

Nodes

Nodes represent spatial entities. Each node has:

  • A name (for debugging and lookup)
  • A position, rotation, and scale relative to its parent
  • Zero or more child nodes
  • Zero or more components
// Create a child node from the scene
auto* boxNode = scene->CreateChild("Box");

// Set its transform
boxNode->SetPosition(Nova3D::Vector3(0.0f, 1.0f, 5.0f));
boxNode->SetScale(Nova3D::Vector3(1.0f, 1.0f, 1.0f));
boxNode->SetRotation(Nova3D::Quaternion::IDENTITY);

Nodes can be nested to form a hierarchy:

auto* parentNode = scene->CreateChild("Parent");
auto* childNode  = parentNode->CreateChild("Child");
childNode->SetPosition(Nova3D::Vector3(0, 1, 0));  // relative to parent

Components

Components add behavior or visual properties to nodes. You add them with CreateComponent<T>():

// Attach a camera to a node
auto* cameraNode = scene->CreateChild("Camera");
cameraNode->SetPosition(Nova3D::Vector3(0, 2, -5));
auto* camera = cameraNode->CreateComponent<Nova3D::Camera>();

// Access a component later
auto* cam = cameraNode->GetComponent<Nova3D::Camera>();

Writing a Custom Component

Subclass Nova3D::Component and override Update() to add game logic to a node:

class RotatorComponent : public Nova3D::Component {
public:
    explicit RotatorComponent(Nova3D::Context* ctx)
        : Nova3D::Component(ctx) {}

    void Update(float deltaTime) override {
        auto* node = GetNode();
        // Rotate ~45 degrees per second around the Y axis
        auto rot = node->GetRotation();
        rot = rot * Nova3D::Quaternion(0.0f, 45.0f * deltaTime, 0.0f);
        node->SetRotation(rot);
    }
};

// Attach it:
boxNode->CreateComponent<RotatorComponent>();

Transform Hierarchy

A child node's world position is the combination of its local transform and its parent's world transform. This lets you group objects so moving a parent moves all its children:

auto* vehicle = scene->CreateChild("Vehicle");
vehicle->SetPosition(Nova3D::Vector3(10, 0, 0));

auto* wheel = vehicle->CreateChild("FrontWheel");
wheel->SetPosition(Nova3D::Vector3(1, -0.5f, 1.5f));
// World position of wheel: (11, -0.5, 1.5)

Math Types

All spatial data uses Nova-3D math types from Nova3D/Math/:

TypeUse
Nova3D::Vector22D positions, UV coordinates
Nova3D::Vector33D positions, directions, scale
Nova3D::QuaternionRotations (use instead of Euler angles)
Nova3D::ColorRGBA color values
Nova3D::Matrix3x4Transform matrix
Rendering → ← Engine Concepts