Section View Tinkering

v53 has working shatMat clipping, but broken instance transformation.

by jlhill17

JavaScript

import * as THREE from 'https://unpkg.com/three@0.120.1/build/three.module.js';
import { OrbitControls } from 'https://unpkg.com/three@0.120.1/examples/jsm/controls/OrbitControls.js';
import { BufferGeometryUtils } from 'https://unpkg.com/three@0.120.1/examples/jsm/utils/BufferGeometryUtils.js';

// ##################### SHADERS ################################

const InstancedEdgeVertexShader = `
precision highp float;

attribute vec3 offset;
attribute vec4 color;
attribute vec4 orientation;
attribute float depthOverride;

varying vec3 vPosition;
varying vec4 vColor;
varying float vDepthOverride;

#include <clipping_planes_pars_vertex>

vec3 applyTRS( vec3 position, vec3 translation, vec4 quaternion, vec3 scale )
{
   position *= scale;
   position += 2.0 * cross( quaternion.xyz, cross( quaternion.xyz, position ) + quaternion.w * position );
   return position + translation;
}

void main()
{
   #include <begin_vertex>
   #include <project_vertex>
   #include <clipping_planes_vertex>
   
   vColor = color;

   vDepthOverride = depthOverride;

   vec3 instanceScale = vec3( 1, 1, 1 );

   vec3 transformedVtx = applyTRS( position.xyz, offset, orientation, instanceScale );

   gl_Position = projectionMatrix * modelViewMatrix * vec4( transformedVtx, 1.0 );

   
}
`;

const InstancedEdgeFragmentShader = `
precision highp float;

varying vec3 vPosition;
varying vec4 vColor;
varying float vDepthOverride;

#include <clipping_planes_pars_fragment>

void main()
{
   #include <clipping_planes_fragment>
   
   vec4 color = vec4( vColor );

   gl_FragColor = color;

   if(vColor.w == 0.0)
   {
      gl_FragDepth = 1.0;
   }
   else if(vDepthOverride > 0.9)
   {
      gl_FragDepth = 0.0;
   }
   else
   {
      gl_FragDepth = gl_FragCoord.z;
   }
}
`;

// ##################### END SHADERS ############################

var camera, scene, renderer;
var planes, planeObjects;

init();
animate();

function createPlaneStencilGroup( geometry, plane, renderOrder )
{
   var group = new...