99 */
1010import * as THREE from 'three'
1111import DebugManager from '../../../../services/debug-manager.js'
12+ import { CANVAS_TEXTURE_RESOLUTION } from '../../../../etc/config.ts'
1213
1314export default class Canvas {
14- /**
15- * @type {DebugManager }
16- */
17- #debugManager: DebugManager
18-
1915 /**
2016 * @type {THREE.CanvasTexture }
2117 */
@@ -26,6 +22,11 @@ export default class Canvas {
2622 */
2723 element : HTMLCanvasElement
2824
25+ /**
26+ * @type {DebugManager }
27+ */
28+ #debugManager: DebugManager
29+
2930 /**
3031 * @type {CanvasRenderingContext2D }
3132 */
@@ -60,23 +61,19 @@ export default class Canvas {
6061 * Constructor
6162 *
6263 * @param {DebugManager } debugManager
63- * @param {number } resolutionWidth
64- * @param {number } resolutionHeight
6564 * @param {string } pointerImageSrc
6665 * @param {number } pointerImageSize
6766 * @param {number } pointerTrailingFactor
6867 */
6968 constructor (
7069 debugManager : DebugManager ,
71- resolutionWidth : number ,
72- resolutionHeight : number ,
7370 pointerImageSrc : string ,
7471 pointerImageSize : number = 0.1 ,
7572 pointerTrailingFactor : number = 0.05 ,
7673 ) {
7774 this . #debugManager = debugManager
7875 this . #pointerTrailingFactor = pointerTrailingFactor
79- this . #initCanvasTexture( resolutionWidth , resolutionHeight )
76+ this . #initCanvasTexture( )
8077 this . #initPointerImage( pointerImageSrc , pointerImageSize )
8178 }
8279
@@ -206,17 +203,19 @@ export default class Canvas {
206203 * Init canvas texture used to detect pointer location and
207204 * displace points
208205 *
209- * @param {number } resolutionWidth
210- * @param {number } resolutionHeight
211206 * @returns {void }
212- * @note The canvas will have the same number of pixels as the
213- * image.
214- * That is why it is used the image resolution as its dimensions
207+ * @note This canvas will work as a texture, but it is not necessary
208+ * to use 1 to 1 map between renderer/image pixels and
209+ * it.
210+ * It is considered that a low-resolution texture
211+ * improves performance without affecting the final effect
215212 */
216- #initCanvasTexture( resolutionWidth : number , resolutionHeight : number ) : void {
213+ #initCanvasTexture( ) : void {
217214 this . element = document . createElement ( 'canvas' )
218- this . element . width = resolutionWidth
219- this . element . height = resolutionHeight
215+ this . element . style . width = `${ CANVAS_TEXTURE_RESOLUTION } px`
216+ this . element . style . height = `${ CANVAS_TEXTURE_RESOLUTION } px`
217+ this . element . width = CANVAS_TEXTURE_RESOLUTION
218+ this . element . height = CANVAS_TEXTURE_RESOLUTION
220219 this . texture = new THREE . CanvasTexture ( this . element )
221220
222221 this . #context = this . element . getContext ( '2d' ) as CanvasRenderingContext2D
0 commit comments