Edges from the back side are visible

I’m working with Three.js and using EdgesGeometry to render the edges of a cube. The cube itself is visible correctly, but the edges from the back side are also being rendered and appear on top of the cube, which I don’t want.

import * as THREE from “three”;

const scene = new THREE.Scene();

scene.background = new THREE.Color(0xffffff);

const camera = new THREE.PerspectiveCamera(

75,

window.innerWidth / window.innerHeight,

0.1,

1000

);

camera.position.set(3, 3, 3);

camera.lookAt(0, 0, 0);

const renderer = new THREE.WebGLRenderer({ antialias: true });

renderer.setSize(window.innerWidth, window.innerHeight);

document.body.appendChild(renderer.domElement);

const geometry = new THREE.BoxGeometry(1, 1, 1);

const material = new THREE.MeshBasicMaterial({

color: 0x00ff00,

depthTest: false,

});

const cube = new THREE.Mesh(geometry, material);

scene.add(cube);

const edges = new THREE.EdgesGeometry(geometry);

const line = new THREE.LineSegments(

edges,

new THREE.LineBasicMaterial({

color: 0x000000,

})

);

scene.add(line);

import { OrbitControls } from “three/examples/jsm/controls/OrbitControls.js”;

const controls = new OrbitControls(camera, renderer.domElement);

controls.update();

function animate() {

requestAnimationFrame(animate);

renderer.render(scene, camera);

}

animate();

window.addEventListener(“resize”, () => {

camera.aspect = window.innerWidth / window.innerHeight;

camera.updateProjectionMatrix();

renderer.setSize(window.innerWidth, window.innerHeight);

});

Why do you need depthTest: false ?

1 Like

I don’t think so, because I just need a little transparency.

cube material: {color:'lime', transparent:true, opacity:0.9}
frame material: {color:'black'}
result:

4 Likes

thank you so much :smiling_face_with_three_hearts:

2 Likes