I want to display the coordinate axes and grid as shown in the image. However, the coordinate axes and grid z-fight and look messy.
I wrote the following code to solve this problem using polygon offset, but it does not work. What should I do?
/**
* 座標軸。
*/
export class Axes extends THREE.LineSegments {
/**
*
* @param size
*/
constructor(size = 1) {
const vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
const colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));
geometry.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));
const material = new THREE.LineBasicMaterial({ vertexColors : true, toneMapped : false });
material.polygonOffset = true;
material.depthTest = true;
material.polygonOffsetFactor = 1;
material.polygonOffsetUnits = 0.1;
super(geometry, material);
}
dispose() {
this.geometry.dispose();
(this.material as THREE.LineBasicMaterial).dispose();
}
}