From ddae84dd606e5d3fb015060e4f2122d80e00594c Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Mon, 8 Mar 2021 12:49:28 +0000 Subject: [PATCH] Editor: Fixed grid depth glitches. (#21430) --- editor/js/Viewport.js | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/editor/js/Viewport.js b/editor/js/Viewport.js index 86ed95528f..69f1ba1781 100644 --- a/editor/js/Viewport.js +++ b/editor/js/Viewport.js @@ -41,7 +41,19 @@ function Viewport( editor ) { // helpers - var grid = new THREE.GridHelper( 30, 30, 0x444444, 0x888888 ); + var grid = new THREE.Group(); + + var grid1 = new THREE.GridHelper( 30, 30, 0x888888 ); + grid1.material.color.setHex( 0x888888 ); + grid1.material.vertexColors = false; + grid.add( grid1 ); + + var grid2 = new THREE.GridHelper( 30, 6, 0x222222 ); + grid2.material.color.setHex( 0x222222 ); + grid2.material.depthFunc = THREE.AlwaysDepth; + grid2.material.vertexColors = false; + grid.add( grid2 ); + var viewHelper = new ViewHelper( camera, container ); var vr = new VR( editor ); @@ -357,14 +369,14 @@ function Viewport( editor ) { mediaQuery.addListener( function ( event ) { renderer.setClearColor( event.matches ? 0x333333 : 0xaaaaaa ); - updateGridColors( grid, event.matches ? [ 0x888888, 0x222222 ] : [ 0x282828, 0x888888 ] ); + updateGridColors( grid1, grid2, event.matches ? [ 0x222222, 0x888888 ] : [ 0x888888, 0x282828 ] ); render(); } ); renderer.setClearColor( mediaQuery.matches ? 0x333333 : 0xaaaaaa ); - updateGridColors( grid, mediaQuery.matches ? [ 0x888888, 0x222222 ] : [ 0x282828, 0x888888 ] ); + updateGridColors( grid1, grid2, mediaQuery.matches ? [ 0x222222, 0x888888 ] : [ 0x888888, 0x282828 ] ); } @@ -765,27 +777,10 @@ function Viewport( editor ) { } -function updateGridColors( grid, colors ) { - - const color1 = new THREE.Color( colors[ 0 ] ); - const color2 = new THREE.Color( colors[ 1 ] ); - - const attribute = grid.geometry.attributes.color; - const array = attribute.array; - - for ( var i = 0; i < array.length; i += 12 ) { - - const color = ( i % ( 12 * 5 ) === 0 ) ? color1 : color2; - - for ( var j = 0; j < 12; j += 3 ) { - - color.toArray( array, i + j ); - - } - - } +function updateGridColors( grid1, grid2, colors ) { - attribute.needsUpdate = true; + grid1.material.color.setHex( colors[ 0 ] ); + grid2.material.color.setHex( colors[ 1 ] ); } -- GitLab