Skip to content

PerspectiveCamera - New helper method .getMarginAt(distance) #27556

@Bug-Reaper

Description

@Bug-Reaper

Description

Looking to PR a new PerspectiveCamera helper method .getMarginAt(distance) which returns the height, width and Vector3s for the corners of the camera's viewable area at the input arg distance.

A PerspectiveCamera's viewable margins at an arbitrary distance is a foundational piece of info you can build a lot of clean experiences from. It enables consistent position and scale for 3D designs and is practical for devices or UX with a variable aspect ratio that must be accounted for.

Some common use-cases include:
  • Guarantee your rendered content fits on the screen.
  • Scale 3D content to take up an exact percentage of available screen height/width.
  • Situations where you want to have objects cleanly enter and exit the visible area.
  • Reset a user controlled camera to an ideal-default.
  • Place a backdrop plane that exactly covers the visible area.
  • Solution

    Took a function I've been copying around for years and modified it to be a helper method like so.

    Alternatives

    Wanted some takes on how to best return the result, currently returns the info in a JSON obj like this:

    {
      topLeft:<Vector3>,
      topRight:<Vector3>,
      bottomRight:<Vector3>,
      bottomLeft:<Vector3>,
      height:<float>,
      width:<float>
    }

    I can't think of any methods that return JSON like this but perhaps it's okay? I also couldn't find any native THREE class that contains all of the above in an easily accessible way. If we don't want to just return JSON obj like this perhaps there's an opportunity to extend an existing class or create a new one for this use-case.

    Metadata

    Metadata

    Assignees

    No one assigned

      Projects

      No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions