2

Im trying to render a set of transform controls so that they are always visible to the user. However, When I set DepthWrite to false or use the AlwaysDepth function on the transform controls, I get the desired outcome, but the individual components of the transform controller render on top of each other too.

With DepthWrite set to false:

enter image description here

The issue (example):

enter image description here

Desired outcome (what transform controls are supposed to look like)

enter image description here

Is there anyway to set DepthWrite to false for a THREE.Group and not its individual components so that the group renders in front of other objects, but the individual components of the transform controls behave as if DepthWrite is set to true so that they don't render in front of each other?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174

1 Answers1

3

You could keep your controls in a separate scene, so they can be rendered separately, after the main scene. You'd also need to clear the depthBuffer in between render calls, so it gets rendered on top of all previously-rendered objects. Here's some pseudo-code to explain the concept:

const controls = new THREE.Group();
const scene2 = new THREE.Scene();

scene2.add(controls);
scene2.autoClear = false

// Render loop
update() {
  renderer.clear()

  // Render all your regular objects
  renderer.render(scene1, camera);

  // Clear the depthBuffer
  renderer.clearDepth();

  // Render your controls
  renderer.render(scene2, camera);
}

You can read more details about .clearDepth() in the docs.

M -
  • 26,908
  • 11
  • 49
  • 81