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

Projecting VideoTexture #18

Closed andrasf closed 3 years ago

andrasf commented 3 years ago

Hi!

I would like to project a VideoTexture to a 3d model. Should it be possible with this library? In theory the classes act the same. But seems like only the right or bottom pixels are getting repeated in stripes.

Thanks, AndrĂ¡s

marcofugaro commented 3 years ago

the right or bottom pixels are getting repeated in stripes.

Hmm, this never happened to me before, could you share a reproducible example?

andrasf commented 3 years ago

Hi!

I modified 3d-model.html to show the problem. Maybe I am missing something very basic.

When I put the video into a canvas, and set the canvas 1px larger than the video, it looks like if the bottom 1 px of the canvas is a solid red color, the whole projected image is red.

Commit is here: https://github.com/marcofugaro/three-projected-material/compare/master...andrasf:master

AndrĂ¡s

JamesBotterill commented 3 years ago

I have a similar issue where the y axis isn't seemingly being scaled so you end up with what looks like a stripe, the video is playing as the colours change correctly.

CptCompiler commented 3 years ago

Hi @marcofugaro, thank you very much for this very cool lib. I really appreciate your work. Do you have any clue, why this could happen? Did you ever manage to get it running with a video texture?

Thanks

CptCompiler commented 3 years ago

The problem is in computeScaledDimensions. ratio will be nan because texture.image is a video element that doesn't support natrualWidth

function computeScaledDimensions(texture, camera, textureScale, cover) {
  // return some default values if the image hasn't loaded yet
  if (!texture.image) {
    return [1, 1];
  }

  const ratio = texture.image.naturalWidth / texture.image.naturalHeight;
marcofugaro commented 3 years ago

Fixed in v2.0.2!

Thanks for the tip @CptCompiler, we now have a working video example:

https://marcofugaro.github.io/three-projected-material/video

CptCompiler commented 3 years ago

Hey @marcofugaro, thank YOU for your quick fix!! I am so happy :-)