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
674 stars 58 forks source link

projectionDirection seems to be incorrect in some cases #46

Closed trusktr closed 1 year ago

trusktr commented 2 years ago

Continuing #41, here is a simple reproduction of the issue:

https://codepen.io/trusktr/pen/xxYYrYj

Note that the projection should cover the whole yellow circle (from the camera's perspective) but it comes in from the side.

Note that I called camera.updateWorldMatrix(true, true) manually, so even though ProjectedMaterial does not update parent matrices, they are updated in this example.

I believe the problem is in the projection direction calculation here:

https://github.com/marcofugaro/three-projected-material/blob/29099152d9775a5007fa5296d7f79540967fa519/src/ProjectedMaterial.js#L207-L214

Namely when both the camera and target object are children, and both not at the origin of the scene.


I've been fixing some things in my fork, although I haven't fixed this one yet. https://github.com/lume/three-projected-material

To save you time looking at my fork, everything before this commit is the same (including PRs in your repo) although I updated examples to exercise the code in more ways, and the only difference is that the code is TypeScript. From that commit and going forward are actual feature changes/fixes that are not in your repo (yet).

trusktr commented 2 years ago

Hi @marcofugaro. Have a chance to take a look at this?

marcofugaro commented 1 year ago

Fixed in v2.2.1, the parent was not taking into consideration.