Documentation
    Preparing search index...

    Function registerPhysicsSerializers

    • Registers the §6a physics components on components and returns it (§23–§25, §79, PH-17 — 2026-08-06; joined by §12's swept character controller, PH-11b, 2026-08-21).

      import { registerPhysicsSerializers } from "fourJS";
      import { createDefaultComponentSerializers } from "@fourjs/serialization";

      const components = registerPhysicsSerializers(createDefaultComponentSerializers());

      Separated from registerSceneNodeTypes because a headless simulation has physics and no widgets, and pulling @fourjs/ui and @fourjs/text into its bundle to save a scene would be a real cost for nothing (§91's tree-shaking requirement on the umbrella). registerSceneNodeTypes calls this, so an application that wants everything still makes one call.

      The serializers themselves live in @fourjs/physics — this function only performs the registration, which is the one act neither that package nor @fourjs/serialization may perform alone. What a physics document carries (the authored state, never the solve) is documented there; the boundary worth repeating here is that reloading a scene is not restoring a simulation. Registering a reloaded node with a world is a separate, explicit step:

      const root = instantiateScene(decodeSceneDocument(text), io.components, io.read);
      for (const node of bodyNodes(root)) world.addBody(node);

      and a save taken while the solver held contacts reloads to the same scene, not to the same solve — the §79/§34 line tests/integration measures.

      Parameters

      Returns ComponentSerializerRegistry

      FourError INVALID_APPLICATION_STATE if either type name is already registered — ComponentSerializerRegistry.register refuses duplicates, so calling this twice on one registry is an error rather than a silent overwrite.