marcofugaro / three-projected-material

📽 Three.js Material which lets you do Texture Projection on a 3d Model
https://marcofugaro.github.io/three-projected-material/
MIT License
671 stars 57 forks source link

Projection does not work with canvas textures #22

Closed jimbauwens closed 3 years ago

jimbauwens commented 3 years ago

Similar to the issue with video textures, canvas textures do not work as the dimensions are not properly computed in computeScaledDimensions.

This is easily solvable by using:

 const sourceWidth = texture.image.naturalWidth || texture.image.videoWidth || texture.image.clientWidth;
 const sourceHeight = texture.image.naturalHeight || texture.image.videoHeight || texture.image.clientHeight;

However, it might be cleaner to add a utility function to fetch these source dimensions, as some other code seems to fetch dimensions too (e.g. in addLoadListener).

marcofugaro commented 3 years ago

Hey, no need for the utility function, just the two lines you proposed are enough. Could you do a PR?

jimbauwens commented 3 years ago

Ok, see #23 :)