Skip to content

Mismatch between reported viewport from three.js and R3f #1892

Open
@looeee

Description

@looeee

I've set up a simple sandbox here - when you click it will toggle the active viewport between two states:

  1. Initial: the full canvas, viewport = [0, 0, canvas width, canvas height]
  2. Toggled: the bottom left quarter of the screen, viewport = [0, 0, half canvas width, half canvas height]

After toggling, the current viewport size reported by three.js and R3F are logged to the console:

  1. Initial (for a canvas with width = 2228, height = 721)
R3f Viewport:  {width: 23.71, height: 7.67, factor: 93.96, distance: 5.0, aspect: 3.09}
Three.js Viewport:  (4) [0, 0, 2228, 721]

  1. Toggled (same canvas)
R3f Viewport:  {width: 23.71, height: 7.67, factor: 93.96, distance: 5.0, aspect: 3.09}
Three.js Viewport:  (4) [0, 0, 1114, 360.5]

As you can see, three.js updates to show the new size. R3F continues to report the viewport as the entire canvas.

I think the issue here is actually semantics - in R3F, the word "viewport" is being used to report various stats about the state of the canvas element combined with the dpr. However, three.js is reporting the value of glViewport.

Since viewport usually has a specific meaning in 3d computer graphics - it's the size of the viewing rectangle into which you will output the scene, in pixels - I'm inclined to say the three.js usage of the term is more correct here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    coretarget agnostic (normally to do with reconciler)documentationto do with docsv10

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions