@@ -7,7 +7,9 @@ import { UIPanel } from './libs/ui.js';
77import { EditorControls } from './EditorControls.js' ;
88
99import { ViewportCamera } from './Viewport.Camera.js' ;
10+ import { ViewportShading } from './Viewport.Shading.js' ;
1011import { ViewportInfo } from './Viewport.Info.js' ;
12+
1113import { ViewHelper } from './Viewport.ViewHelper.js' ;
1214import { VR } from './Viewport.VR.js' ;
1315
@@ -26,6 +28,7 @@ function Viewport( editor ) {
2628 container . setPosition ( 'absolute' ) ;
2729
2830 container . add ( new ViewportCamera ( editor ) ) ;
31+ container . add ( new ViewportShading ( editor ) ) ;
2932 container . add ( new ViewportInfo ( editor ) ) ;
3033
3134 //
@@ -41,6 +44,7 @@ function Viewport( editor ) {
4144 // helpers
4245
4346 const grid = new THREE . Group ( ) ;
47+ sceneHelpers . add ( grid ) ;
4448
4549 const grid1 = new THREE . GridHelper ( 30 , 30 , 0x888888 ) ;
4650 grid1 . material . color . setHex ( 0x888888 ) ;
@@ -49,7 +53,6 @@ function Viewport( editor ) {
4953
5054 const grid2 = new THREE . GridHelper ( 30 , 6 , 0x222222 ) ;
5155 grid2 . material . color . setHex ( 0x222222 ) ;
52- grid2 . material . depthFunc = THREE . AlwaysDepth ;
5356 grid2 . material . vertexColors = false ;
5457 grid . add ( grid2 ) ;
5558
@@ -219,6 +222,8 @@ function Viewport( editor ) {
219222
220223 // event.preventDefault();
221224
225+ if ( event . target !== renderer . domElement ) return ;
226+
222227 const array = getMousePosition ( container . dom , event . clientX , event . clientY ) ;
223228 onDownPosition . fromArray ( array ) ;
224229
@@ -628,6 +633,30 @@ function Viewport( editor ) {
628633
629634 } ) ;
630635
636+ signals . viewportShadingChanged . add ( function ( ) {
637+
638+ const viewportShading = editor . viewportShading ;
639+
640+ switch ( viewportShading ) {
641+
642+ case 'default' :
643+ scene . overrideMaterial = null ;
644+ break ;
645+
646+ case 'normals' :
647+ scene . overrideMaterial = new THREE . MeshNormalMaterial ( ) ;
648+ break ;
649+
650+ case 'wireframe' :
651+ scene . overrideMaterial = new THREE . MeshBasicMaterial ( { color : 0x000000 , wireframe : true } ) ;
652+ break ;
653+
654+ }
655+
656+ render ( ) ;
657+
658+ } ) ;
659+
631660 signals . exitedVR . add ( render ) ;
632661
633662 //
@@ -714,13 +743,8 @@ function Viewport( editor ) {
714743
715744 startTime = performance . now ( ) ;
716745
717- // Adding/removing grid to scene so materials with depthWrite false
718- // don't render under the grid.
719-
720- scene . add ( grid ) ;
721746 renderer . setViewport ( 0 , 0 , container . dom . offsetWidth , container . dom . offsetHeight ) ;
722747 renderer . render ( scene , editor . viewportCamera ) ;
723- scene . remove ( grid ) ;
724748
725749 if ( camera === editor . viewportCamera ) {
726750
0 commit comments