Skip to content

Commit

Permalink
Editor: Fixed grid colors in dark mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Aug 25, 2020
1 parent b38b9ae commit 14f4ae1
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions editor/js/Viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,6 @@ function Viewport( editor ) {
// helpers

var grid = new THREE.GridHelper( 30, 30, 0x444444, 0x888888 );

var array = grid.geometry.attributes.color.array;

for ( var i = 0; i < array.length; i += 60 ) {

for ( var j = 0; j < 12; j ++ ) {

array[ i + j ] = 0.26;

}

}

//

var viewHelper = new ViewHelper( camera, container );

//
Expand Down Expand Up @@ -368,12 +353,14 @@ function Viewport( editor ) {
mediaQuery.addListener( function ( event ) {

renderer.setClearColor( event.matches ? 0x333333 : 0xaaaaaa );
updateGridColors( grid, event.matches ? [ 0x888888, 0x222222 ] : [ 0x282828, 0x888888 ] );

if ( scene.background === null ) render();
render();

} );

renderer.setClearColor( mediaQuery.matches ? 0x333333 : 0xaaaaaa );
updateGridColors( grid, mediaQuery.matches ? [ 0x888888, 0x222222 ] : [ 0x282828, 0x888888 ] );

}

Expand Down Expand Up @@ -764,4 +751,28 @@ 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 );

}

}

attribute.needsUpdate = true;

}

export { Viewport };

0 comments on commit 14f4ae1

Please sign in to comment.