JamesLMilner / THREEAR

A marker based Augmented Reality library for Three.js
https://jameslmilner.github.io/THREEAR/
171 stars 24 forks source link

Z-fighting bug #52

Closed martinloretzzz closed 5 years ago

martinloretzzz commented 5 years ago

Same bug as in Ar.js, solved it by myself see: https://github.com/jeromeetienne/AR.js/issues/146#issuecomment-474017046

THREEAR.initialize({ source: source }).then(controller => {
    // ...
    let m = camera.projectionMatrix;
    let far = 1000;
    let near = 0.1;

    m.elements[10] = -(far + near) / (far - near);
    m.elements[14] = -(2 * far * near) / (far - near);
    // ...
});
JamesLMilner commented 5 years ago

Thanks for posting your solution to that problem. I am not totally sure if this is something that could be fixed at the library level or if it's something that should be being applied in user land code with Three.js?

martinloretzzz commented 5 years ago

Maybe you can set the default near plane of the camera to 0.1 or 0.01, I think it would be an better default value than 0.0001.

One possibility is my workaround or maybe use the setProjectionNearPlane in arjs.artoolkit.debug.js

JamesLMilner commented 5 years ago

@0b01001101 thanks for the advice. Do you happen to have a reproduceable model / example source code I can play with by any chance?

martinloretzzz commented 5 years ago

Added it to: https://github.com/0b01001101/THREEAR/tree/zfighting model/zfighting examples/bug-zfighting.html

On line 75/76 in bug-zfighting.html you can "enable/disable" the bug

JamesLMilner commented 5 years ago

@0b01001101 thanks so much! I will take a look

JamesLMilner commented 5 years ago

In theory this is fixed now, will release soon.