Skip to content
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

PointsMaterial size attenuation doesn't appear to consider FOV #12150

Closed
4 of 13 tasks
orangebowlerhat opened this issue Sep 7, 2017 · 3 comments
Closed
4 of 13 tasks
Labels

Comments

@orangebowlerhat
Copy link

I'm using PerspectiveCamera and a model including some Points using a PointsMaterial. I'm using a customised version of OrbitControls.js to allow the viewing of a large and complex model. One of the changes is that zoom function changes the FOV of the camera instead of moving it closer. The camera moves to show a specfic part of the models. I've noticed that the PointsMaterial attenuation changes sizes when the camera moves closer to the model but not when the FOV is changed.

I assume the size algorithm uses distance to the camera but not FOV? I've never posted to this repo before so excuse me if I miss something. I tried to test with IE but cannot get it to load the page at the moment. Equally, not sure exactly which version of Three it is but within the last year.

Code that creates the PointsMaterial:

var texFlame = new THREE.TextureLoader().load("textures/flame.png");
mtlFlame = new THREE.PointsMaterial ({size: 2, sizeAttenuation: true, color: 0xffffff, transparent: true,  blending: THREE.AdditiveBlending, depthWrite: false, map: texFlame});

The code that changes FOV is similarly unexciting:

this.camera.fov = fov;
this.camera.updateProjectionMatrix ();
Three.js version
  • Dev
  • r87
  • ...
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, ...)

Don't know if this is hardware specific but it seems unlikely. I'm using GeForce GTX950 in Windows 10.

@orangebowlerhat orangebowlerhat changed the title Point Material Size Attenuation doesn't seem to consider FOV PointsMaterial size attenuation doesn't seem to consider FOV Sep 7, 2017
@orangebowlerhat orangebowlerhat changed the title PointsMaterial size attenuation doesn't seem to consider FOV PointsMaterial size attenuation doesn't appear to consider FOV Sep 7, 2017
@WestLangley
Copy link
Collaborator

PointsMaterial.size has units of pixels -- not world units. You will have to adjust the size yourself.

This related post may be informative: #10385 (comment).

Beware that gl_PointSize may be limited, so the size you request may not be the size you get.

@orangebowlerhat
Copy link
Author

@WestLangley. So I need to change the size property of the PointsMaterial when I change the FOV?

I did find that post before asking but I don't quite follow why it works that way. I understand that size is in pixels but attenuation already makes it not relate to devices pixels and that process surely must relate to perspective which must relate to FOV in some sense?

However, that's just explaining my own lack of understanding. I'm perfectly happy with the solution you give. Thanks.

@WestLangley
Copy link
Collaborator

I expect PointsMaterial.size will remain in units of pixels, so for reference, I'll post this work-around here.

Based on this stackoverflow answer, you can scale your points using the following pattern, which should work for reasonable values of camera.fov.

var defaultSize = 10;
points.material.size = defaultSize / Math.tan( ( Math.PI / 180 ) * camera.fov / 2 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants