Open code, practice, and notes →
Download source with English comments · for reading
Three.js · 02 Renderer and Display Size
Series contents · Technology map
Stage: Scene Coordinates, Cameras, and Geometry · Editable example · Storage ID: threejs-step-02
Goals and learning outcomes
- Preserve shape proportions after resizing.
- Handle a hidden container with a size of 0.
Prerequisites
Prerequisite concepts: Parent Transforms, View Direction and Position. Prepare the result files and observation notes from unit 1.
Key concepts and explanations
Buffer Size
The renderer’s drawing buffer differs from its CSS display size. Increasing pixelRatio processes more pixels for the same display area.
Aspect Ratio
A PerspectiveCamera aspect is the viewport ratio. After resizing, call updateProjectionMatrix to apply the new projection.
Practice setup
First read the execution-scope guidance on the example screen. The following environment is for extending the assignment in a separate project. Implement it yourself in an HTML and ES module project served by a separate local HTTP development server. Pin three and addons to the same installed version and record it.
The linked example is a starting point. It does not implement every task below. Complete work beyond its supported scope in a separate project.
Practice tasks
- Prepare day-02.js and index.html in the external exercise project. Read the container size with ResizeObserver and call renderer.setSize(w,h,false).
- Update camera.aspect and the projection, and compare CSS size with buffer size in an output.
- Save the output under the 1:1 input condition, then run again under the 2:1 condition. Expected: Updating aspect prevents the sphere from stretching into an ellipse. Compare with the actual screen and logs, and record the actual result and reasons for any differences in day-02-notes.md.
Variables to observe
| Variable | Baseline | Change | Expected change / hypothesis |
|---|---|---|---|
| viewport ratio | 1:1 | 2:1 | Updating aspect prevents the sphere from stretching into an ellipse. |
Predictions in this table are not measured results. Change one condition at a time and record why the actual result differs.
Completion criteria
- Preserve shape proportions after resizing.
- Handle a hidden container with a size of 0.
Self-check
- What does the third argument of setSize control?
- How does the cost of the screen area change as DPR increases?
Official references
Linked example and execution scope
Example source · Runtime environments and limits
This is an editable browser experiment. Measurements vary with the current device and browser.
Source code and records are not overwritten automatically. Resetting an existing example also preserves your notes.
Next learning
Previous: Scene Graphs and Cameras · Next: Perspective and Orthographic Projection