Skip to content

next: extend event-data (discussion) #20

@bigmistqke

Description

@bigmistqke

Currently the next-branch passes a very minimal event-object around. For each canvas-event there is a single event-object that is passed to each individual handler:

  const createThreeEvent = <TEvent extends MouseEvent | PointerEvent | WheelEvent>(
    nativeEvent: TEvent,
  ): S3.Event<TEvent> => {
    const event = {
      ...nativeEvent,
      nativeEvent,
      stopped: false,
      stopPropagation: () => (event.stopped = true),
    };
    return event;
  };

react-three-fiber on the other hand passes an individual object for each event-handler containing the following event-data see:

{
  ...DomEvent                      // All the original event data
  ...Intersection                  // All of Three's intersection data - see note 2
  intersections: Intersection[]    // The first intersection of each intersected object
  object: Object3D                 // The object that was actually hit
  eventObject: Object3D            // The object that registered the event
  unprojectedPoint: Vector3        // Camera-unprojected point
  ray: Ray                         // The ray that was used to strike the object
  camera: Camera                   // The camera that was used in the raycaster
  sourceEvent: DomEvent            // A reference to the host event
  delta: number                    // Distance between mouse down and mouse up event in pixels
}

I didn't feel super comfortable back when I made this decision to (potentially) create so many objects on-the-fly, but maybe it's worth to follow r3f here because I assume event-handlers is where most usercode will be.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needednextIssues related to next pre-release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions