JSFiddle - React, Tailwind, and code Playground

HTML

<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
    
<script type="importmap">
	{
		"imports": {
			"three": "https://unpkg.com/three/build/three.module.js"
		}
	}
</script>

CSS

body {
	  margin: 0;
}

JavaScript

import * as THREE from 'three';
import { GLTFLoader } from 'https://unpkg.com/three/examples/jsm/loaders/GLTFLoader.js';

	import { OrbitControls } from 'https://unpkg.com/three/examples/jsm/controls/OrbitControls.js';


var scene, camera, renderer, clock;
var controls;
var redBox,blueBox,greenBox,tunnelBoxRed,tunnelBoxRed2,tunnelBoxBlue,tunnelBoxBlue2,tunnelBoxGreen,tunnelBoxGreen2
var planes=[]
init();
animate();

function init() {

  var tunnelGeometry, tunnelMaterial,tunnelMaterialRed,tunnelMaterialGreen,tunnelMaterialBlue;
  var sphereGeometry, redMaterial;
  var greenMaterial;
  var  blueMaterial;


  scene = new THREE.Scene();

  clock = new THREE.Clock();

  camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 10000);
  camera.position.z = 10;


  tunnelGeometry = new THREE.BoxGeometry(2, 2,2);


  // invisible tunnels
  tunnelMaterialRed = new THREE.MeshBasicMaterial({
    colorWrite: false, 
    depthWrite: false,
    stencilWrite: true,
    stencilRef: 1,
    stencilFunc: THREE.AlwaysStencilFunc,
    stencilFail: THREE.ReplaceStencilOp,
    stencilZFail: THREE.ReplaceStencilOp,
    stencilZPass: THREE.ReplaceStencilOp,

      });



  tunnelMaterialGreen = new THREE.MeshBasicMaterial({
    color: 0x00ff00,
    colorWrite: false, 
    depthWrite: false,
    stencilWrite: true,
    stencilRef: 2,
    stencilFunc: THREE.AlwaysStencilFunc,
    stencilFail: THREE.ReplaceStencilOp,
    stencilZFail: THREE.ReplaceStencilOp,
    stencilZPass: THREE.ReplaceStencilOp,
    
  });


  tunnelMaterialBlue = new THREE.MeshBasicMaterial({
    color: 0x0000ff,
    colorWrite: false, 
    depthWrite: false,
    stencilWrite: true,
    stencilRef: 3,
    stencilFunc: THREE.AlwaysStencilFunc,
    stencilFail: THREE.ReplaceStencilOp,
    stencilZFail: THREE.ReplaceStencilOp,
    stencilZPass: THREE.ReplaceStencilOp,
    
    

  });


  tunnelBoxRed = new THREE.Mesh(tunnelGeometry, tunnelMaterialRed);
  tunnelBoxRed2 = new...