-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix clipping in webgl2_materials_texture3d #22649
Conversation
The camera position was too close to the 3D texture, causing clipping from certain angles.
https://threejs.org/examples/webgl2_materials_texture3d TBH, I don't see how the PR improves the example. Do you mind explaining the mentioned clipping in more detail? |
Move the object to the middle of the frustrum and make the depth of the frustrum bigger.
camera = new THREE.OrthographicCamera( - h * aspect / 2, h * aspect / 2, h / 2, - h / 2, 1, 1000 ); | ||
camera.position.set( 0, 0, 128 ); | ||
camera = new THREE.OrthographicCamera( - h * aspect / 2, h * aspect / 2, h / 2, - h / 2, 1, 2000 ); | ||
camera.position.set( -1000, 0, 128 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would camera.position.set( 0, 0, 256 )
work too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes the camera higher, which would keep the object further away than using camera.position.set( 0, 0, 128 )
. From what I understood, what matters is the initial Euclidean distance from the camera to the object's center.
I believe that it would fix the clipping due to rotation only, but not for rotation + horizontal movement.
With the frustrum size of 1000-1=999 (before), I couldn't find a distance that would reliably avoid clipping for rotation + horizontal movement. Either it would clip at the front or at the back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zooming also doesn't seem to affect the frustrum's near and far planes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let OOO be the object and C the camera.
changing only camera.position.set( 0, 0, 128 );
to camera.position.set( 0, 0, 256 );
would create the following situation:
O
O C
O
to
O C
O
O
IMO, keeping the z of the camera aligned w/ the center of the exam (z=128) makes sense. But it is subjective.
Here follows the initial viewing angle for camera.position.set( 0, 0, 256 );
:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understood, any camera.position.set( x, y, z );
, such that sqrt(x^2 + y^2 + (z-128)^2) is approx 1000 = half of the new distance for the frustrum's far plane will work fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make these temporary changes so you can see what is happening: scene.add( new THREE.AxesHelper( 256 ) );
const mesh = new THREE.Mesh( geometry, new THREE.MeshNormalMaterial() ); Fix the clipping by moving the camera back a bit; camera.position.set( - 64, - 64, 128 ); Then disable panning. controls.enablePan = false; |
Thanks for the feedback and suggestions, Your library is awesome, and I'll definitely keep using it in the future. I'm new to Open Source contributions and PRs, so please let me know if I do (or am doing) something wrong, such a too much verbosity or things like that. All of the translation and positioning functions are working exactly as expected and in agreement with the documentation. The center of the three.js/examples/webgl2_materials_texture3d.html Lines 118 to 120 in 7f9e721
Therefore, the suggestion
works fine when To keep this point of view and also enable
Since, (a - 64)² + (a - 64)² = ((2000+1)/2)², for a < 0, yelds a ~ - 643 (or a ~ - 644 if we consider the fractional coordinates of O). |
I would do what I recommended. You can't prevent clipping when the user is able to pan without limitation. |
Disable pan, move camera to -64, -64, 128 and restore original frustum.
I usually make the near and far clipping more lenient than the left and right clipping, for reasonable zoom levels and aspect ratios. If the users pan themselves to the moon, it's their fault. ;) But you're probably right, this model isn't detailed enough to justify enabling Pan. |
Thanks! |
Description
The camera position was too close to the 3D texture, causing clipping
from certain angles.
Before the repositioning:
After the repositioning: