spite / THREE.MeshLine

Mesh replacement for THREE.Line
MIT License
2.14k stars 381 forks source link

Issue with Orthographic camera? #26

Closed malekcellier closed 7 years ago

malekcellier commented 7 years ago

Hi!

I am using this piece of code to change the view from Perspective to Orthographic and back:

function toggleCamera() {
    if (camera instanceof THREE.PerspectiveCamera) {
        camera = new THREE.OrthographicCamera(window.innerWidth / -16, window.innerWidth / 16, window.innerHeight / 16, window.innerHeight / -16, -200, 500);
        camera.position.set(0, 0, 500);
        camera.name = 'Camera';
        camera.up.set(0,0,1);
        camera.lookAt(scene.position);
    } else {
        camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 5000);
        camera.position.set(0, -1500/2, 1000/2);
        camera.up.set(0,0,1);
        camera.lookAt(scene.position);
        camera.name = 'Camera';
    }
    // the orbit controls to rotate the camera
    controls = new THREE.OrbitControls(camera, container);
    controls.enableDamping = true;
    controls.dampingFactor = 0.25;
    controls.rotateSpeed = 1.0;      
}

I obtain the following: perspectivecamera orthographiccamera

where one can see that the orthographic has lines all around.

Is that a bug or me misusing the API?

BR M

spite commented 7 years ago

You're using it right, it's probably a problem with the shader math. I never thought of testing it with an OrthographicCamera, so definitely some things are different. I'll check it out.

johanna-schmidt commented 7 years ago

Hi, any news on this issue? Just because I also ran into the same problem when using the orthographic camera...

spite commented 7 years ago

I think you have to tweak the lineWidth value, and check or uncheck sizeAttenuation. Try lowering lineWidth to .01 or something like that (it changes with your scene size)

Here's the graph example with an OrthographicCamera:

screen shot 2016-12-11 at 12 55 07
johanna-schmidt commented 7 years ago

thank you very much, that works like a charm!

gaitat commented 7 years ago

Is there a correlation between lineWidth for a perspective camera and lineWidth for an orthographic camera?

karimbeyrouti commented 7 years ago

It is indeed the same issue - works with a lineWidth of 0.01. Thank you.

mkarnicki commented 6 years ago

Hi. First of all, thank you for awesome THREE.MeshLine :)!

Could we please re-open this issue? Since using a value of 3 with PerspectiveCamera and 0.003 with OrthogonalCamera yields roughly the same results for me (lineWidth-wise), I suspect this could be fixed within THREE.MeshLine. Otherwise MeshLine consumer has to keep track of all the materials used and update them whenever camera type is toggled.

I completely don't mind waiting for a fix (I myself am not enough fluent with graphics and THREE to help out) and I just subscribed to this issue, but I'd really like this issue to stay in the issue pool than be closed, perhaps though with a more descriptive title, such as:

Orthographic camera requires different lineWidth values than PerspectiveCamera

Thanks and have a great day, @spite !

zhongyin-hu commented 5 years ago

Hi. @spite thank you for awesome THREE.MeshLine. I need such a fix as well and would appreciate a lot if this issue could be re-opened.

ryanking1809 commented 4 years ago

I'm finding lineWidth: 0.158 is roughly equal to 100px in orthographic for those who need pixel accuracy (I haven't found any circumstances where this changes yet).

axion014 commented 4 years ago

My PR is apparently rejected for the exact reason his workaround in example made out no line—actually very thin line when I fixed the shader math. I hope this changes but maybe I just have to add a new API for fixed version and leave the current version alone.

ryanking1809 commented 4 years ago

I'm now maintaining a version with your fork. https://github.com/ryanking1809/threejs-meshline