Skip to content

[Parity] Add a Primitive escape hatch for existing and custom Two.js objects #33

Description

@jonobr1

Summary

Add a generic React component for attaching an existing Two.js object to the declarative scene graph.

A primitive escape hatch makes custom Two.Shape subclasses, extras, clones, and objects restored with fromObject(...) usable without waiting for a bespoke wrapper or imperatively calling parent.add(...).

Proposed API sketch

const object = useMemo(() => Two.Group.fromObject(snapshot), [snapshot]);

<Primitive object={object} />

The exact name and ownership API are open for design.

Related work

Acceptance criteria

  • Attach a supplied Two.js Shape or Group to the current React parent.
  • Remove and reparent it correctly as React ownership changes.
  • Preserve React sibling ordering.
  • Forward a ref to the supplied object.
  • Define whether the wrapper owns/disposes the object, with an explicit option if both owned and borrowed objects are supported.
  • Define how prop overrides and event handlers apply to primitives.
  • Allow React children when the supplied object is a Group, or clearly document why this is unsupported.
  • Support an Arc-extra or custom Shape example.
  • Support a Group.fromObject(...) scene restoration example.
  • Add lifecycle, ordering, borrowed-resource, and custom-object tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions