Skip to main content
Systems are the engine that powers dynamic behavior in Pascal Editor. They run every frame to process dirty nodes, update geometries, and synchronize the scene state with Three.js objects.

Understanding Systems

A system is a React component that:
  1. Subscribes to the dirtyNodes set from the scene state
  2. Uses useFrame() to run logic every frame
  3. Processes nodes that need updates
  4. Accesses Three.js objects via the scene registry
  5. Clears the dirty flag when processing is complete
Systems are already running for core node types (walls, items, slabs, etc.). You typically create custom systems for:
  • Custom node types
  • Advanced automation
  • Performance-critical calculations
  • Integration with external services

The System Pattern

Here’s the anatomy of a system using the real ItemSystem as an example:

Creating a Custom System

1

Define your system component

Create a React component that will house your system logic:
System components don’t render anything - they’re purely for side effects. Always return null.
2

Subscribe to dirty nodes

Access the dirty nodes set to know which nodes need processing:
3

Access Three.js objects via registry

The scene registry maps node IDs to their Three.js representations:
If the mesh doesn’t exist yet, keep the node dirty so it’s processed in the next frame.
4

Implement your logic

Add your custom behavior. Here’s an example that animates items:
5

Clear the dirty flag

When processing is complete, clear the dirty flag:
Always clear the dirty flag unless you intentionally want the node to be reprocessed every frame (e.g., for animations).
6

Register your system

Add your system component to the scene:

Real-World Example: Wall Mitering System

The WallSystem is a sophisticated example that demonstrates advanced system patterns:

useFrame Priority

The second argument to useFrame() controls execution order:
Lower numbers run first:
  • Priority 2: ItemSystem (positioning)
  • Priority 4: WallSystem (geometry)
  • Priority 5: Custom systems (default)
Set priority based on dependencies. If your system needs updated item positions, use a priority higher than 2.

Performance Best Practices

Early Exit for Empty Dirty Set

Batch Processing

Group related operations to minimize redundant calculations:

Deferred Mesh Access

Scene Registry API

The scene registry provides fast lookups:

Example: Auto-Rotation System

Here’s a complete example of a system that auto-rotates items tagged with autoRotate:
Use it by adding metadata to items:

Next Steps

Event Handling

Respond to user interactions in your systems

Spatial Queries

Use spatial queries in your system logic