@@ -62,15 +62,70 @@ function handleColorChange( color ) {
6262
6363}
6464
65- function guiMaterial ( gui , material ) {
65+ function needsUpdate ( material , geometry ) {
66+ return function ( ) {
67+ material . shading = + material . shading ; //Ensure number
68+ material . needsUpdate = true ;
69+ geometry . verticesNeedUpdate = true ;
70+ geometry . normalsNeedUpdate = true ;
71+ }
72+ } ;
73+
74+ function guiScene ( gui , scene ) {
75+ var folder = gui . addFolder ( 'Scene' ) ;
76+
77+ var data = {
78+ background : "#000000"
79+ }
80+
81+ var color = new THREE . Color ( ) ;
82+ var colorConvert = handleColorChange ( color ) ;
83+
84+ folder . addColor ( data , "background" ) . onChange ( function ( value ) {
85+
86+ colorConvert ( value ) ;
87+
88+ renderer . setClearColor ( color . getHex ( ) , 1 ) ;
89+
90+ } ) ;
91+
92+ guiSceneFog ( folder , scene ) ;
93+
94+ }
95+
96+ function guiSceneFog ( folder , scene ) {
97+ var fogFolder = folder . addFolder ( 'scene.fog' ) ;
98+
99+ var fog = new THREE . Fog ( 0x3f7b9d , 0 , 60 ) ;
100+
101+ var data = {
102+ fog : {
103+ "THREE.Fog()" : false ,
104+ "scene.fog.color" : fog . color . getHex ( )
105+ }
106+ } ;
107+
108+ fogFolder . add ( data . fog , 'THREE.Fog()' ) . onChange ( function ( useFog ) {
109+
110+ if ( useFog ) {
111+ scene . fog = fog ;
112+ } else {
113+ scene . fog = null ;
114+ }
115+
116+ } ) ;
117+ fogFolder . addColor ( data . fog , 'scene.fog.color' ) . onChange ( handleColorChange ( fog . color ) ) ;
118+ }
119+
120+ function guiMaterial ( gui , material , geometry ) {
66121 var folder = gui . addFolder ( 'THREE.Material' ) ;
67122
68123 folder . add ( material , 'transparent' ) ;
69124 folder . add ( material , 'opacity' , 0 , 1 ) ;
70- folder . add ( material , 'blending' , constants . blendingMode ) ;
71- folder . add ( material , 'blendSrc' , constants . destinationFactors ) ;
72- folder . add ( material , 'blendDst' , constants . destinationFactors ) ;
73- folder . add ( material , 'blendEquation' , constants . equations ) ;
125+ // folder.add( material, 'blending', constants.blendingMode );
126+ // folder.add( material, 'blendSrc', constants.destinationFactors );
127+ // folder.add( material, 'blendDst', constants.destinationFactors );
128+ // folder.add( material, 'blendEquation', constants.equations );
74129 folder . add ( material , 'depthTest' ) ;
75130 folder . add ( material , 'depthWrite' ) ;
76131 folder . add ( material , 'polygonOffset' ) ;
@@ -79,10 +134,10 @@ function guiMaterial( gui, material ) {
79134 folder . add ( material , 'alphaTest' ) ;
80135 folder . add ( material , 'overdraw' ) ;
81136 folder . add ( material , 'visible' ) ;
82- folder . add ( material , 'side' , constants . side ) ;
137+ folder . add ( material , 'side' , constants . side ) . onChange ( needsUpdate ( material , geometry ) ) ;
83138}
84139
85- function guiMeshBasicMaterial ( gui , material ) {
140+ function guiMeshBasicMaterial ( gui , material , geometry ) {
86141
87142 var data = {
88143 color : material . color . getHex ( )
@@ -111,25 +166,25 @@ function guiMeshBasicMaterial( gui, material ) {
111166 //folder.add( material, 'refractionRatio' );
112167}
113168
114- function guiMeshDepthMaterial ( gui , material ) {
169+ function guiMeshDepthMaterial ( gui , material , geometry ) {
115170
116171 var folder = gui . addFolder ( 'THREE.MeshDepthMaterial' ) ;
117172
118173 folder . add ( material , 'wireframe' ) ;
119174 folder . add ( material , 'wireframeLinewidth' , 0 , 10 ) ;
120175}
121176
122- function guiMeshNormalMaterial ( gui , material ) {
177+ function guiMeshNormalMaterial ( gui , material , geometry ) {
123178
124179 var folder = gui . addFolder ( 'THREE.MeshNormalMaterial' ) ;
125180
126181 folder . add ( material , 'morphTargets' ) ;
127- folder . add ( material , 'shading' , constants . shading ) ;
182+ folder . add ( material , 'shading' , constants . shading ) . onChange ( needsUpdate ( material , geometry ) ) ;
128183 folder . add ( material , 'wireframe' ) ;
129184 folder . add ( material , 'wireframeLinewidth' , 0 , 10 ) ;
130185}
131186
132- function guiLineBasicMaterial ( gui , material ) {
187+ function guiLineBasicMaterial ( gui , material , geometry ) {
133188
134189 var data = {
135190 color : material . color . getHex ( )
@@ -146,7 +201,7 @@ function guiLineBasicMaterial( gui, material ) {
146201
147202}
148203
149- function guiMeshLambertMaterial ( gui , material ) {
204+ function guiMeshLambertMaterial ( gui , material , geometry ) {
150205
151206 var data = {
152207 color : material . color . getHex ( ) ,
@@ -160,7 +215,7 @@ function guiMeshLambertMaterial( gui, material ) {
160215 folder . addColor ( data , 'ambient' ) . onChange ( handleColorChange ( material . ambient ) ) ;
161216 folder . addColor ( data , 'emissive' ) . onChange ( handleColorChange ( material . emissive ) ) ;
162217
163- folder . add ( material , 'shading' , constants . shading ) ;
218+ folder . add ( material , 'shading' , constants . shading ) . onChange ( needsUpdate ( material , geometry ) ) ;
164219 folder . add ( material , 'wireframe' ) ;
165220 folder . add ( material , 'wireframeLinewidth' , 0 , 10 ) ;
166221 folder . add ( material , 'wireframeLinecap' , [ "butt" , "round" , "square" ] ) ;
@@ -170,7 +225,7 @@ function guiMeshLambertMaterial( gui, material ) {
170225
171226}
172227
173- function guiMeshPhongMaterial ( gui , material ) {
228+ function guiMeshPhongMaterial ( gui , material , geometry ) {
174229
175230 var data = {
176231 color : material . color . getHex ( ) ,
@@ -187,7 +242,7 @@ function guiMeshPhongMaterial( gui, material ) {
187242 folder . addColor ( data , 'specular' ) . onChange ( handleColorChange ( material . specular ) ) ;
188243 folder . add ( material , 'shininess' , 0 , 100 ) ;
189244
190- folder . add ( material , 'shading' , constants . shading ) ;
245+ folder . add ( material , 'shading' , constants . shading ) . onChange ( needsUpdate ( material , geometry ) ) ;
191246 folder . add ( material , 'wireframe' ) ;
192247 folder . add ( material , 'wireframeLinewidth' , 0 , 10 ) ;
193248 folder . add ( material , 'wireframeLinecap' , [ "butt" , "round" , "square" ] ) ;
@@ -197,20 +252,18 @@ function guiMeshPhongMaterial( gui, material ) {
197252
198253}
199254
200-
201- function chooseFromHash ( ) {
255+ function chooseFromHash ( gui , geometry ) {
202256
203257 var selectedMaterial = window . location . hash . substring ( 1 ) || "MeshBasicMaterial" ;
204258 var material ;
205259
206- var gui = new dat . GUI ( ) ;
207260 switch ( selectedMaterial ) {
208261
209262 case "MeshBasicMaterial" :
210263
211264 material = new THREE . MeshBasicMaterial ( { color : 0x00ff00 } ) ;
212- guiMaterial ( gui , material ) ;
213- guiMeshBasicMaterial ( gui , material ) ;
265+ guiMaterial ( gui , material , geometry ) ;
266+ guiMeshBasicMaterial ( gui , material , geometry ) ;
214267
215268 return material ;
216269
@@ -219,8 +272,8 @@ function chooseFromHash() {
219272 case "MeshLambertMaterial" :
220273
221274 material = new THREE . MeshLambertMaterial ( { color : 0x00ff00 } ) ;
222- guiMaterial ( gui , material ) ;
223- guiMeshLambertMaterial ( gui , material ) ;
275+ guiMaterial ( gui , material , geometry ) ;
276+ guiMeshLambertMaterial ( gui , material , geometry ) ;
224277
225278 return material ;
226279
@@ -229,8 +282,8 @@ function chooseFromHash() {
229282 case "MeshPhongMaterial" :
230283
231284 material = new THREE . MeshPhongMaterial ( { color : 0x00ff00 } ) ;
232- guiMaterial ( gui , material ) ;
233- guiMeshPhongMaterial ( gui , material ) ;
285+ guiMaterial ( gui , material , geometry ) ;
286+ guiMeshPhongMaterial ( gui , material , geometry ) ;
234287
235288 return material ;
236289
@@ -239,8 +292,8 @@ function chooseFromHash() {
239292 case "MeshDepthMaterial" :
240293
241294 material = new THREE . MeshDepthMaterial ( { color : 0x00ff00 } ) ;
242- guiMaterial ( gui , material ) ;
243- guiMeshDepthMaterial ( gui , material ) ;
295+ guiMaterial ( gui , material , geometry ) ;
296+ guiMeshDepthMaterial ( gui , material , geometry ) ;
244297
245298 return material ;
246299
@@ -249,8 +302,8 @@ function chooseFromHash() {
249302 case "MeshNormalMaterial" :
250303
251304 material = new THREE . MeshNormalMaterial ( ) ;
252- guiMaterial ( gui , material ) ;
253- guiMeshNormalMaterial ( gui , material ) ;
305+ guiMaterial ( gui , material , geometry ) ;
306+ guiMeshNormalMaterial ( gui , material , geometry ) ;
254307
255308 return material ;
256309
@@ -259,8 +312,8 @@ function chooseFromHash() {
259312 case "LineBasicMaterial" :
260313
261314 material = new THREE . LineBasicMaterial ( { color : 0x00ff00 } ) ;
262- guiMaterial ( gui , material ) ;
263- guiLineBasicMaterial ( gui , material ) ;
315+ guiMaterial ( gui , material , geometry ) ;
316+ guiLineBasicMaterial ( gui , material , geometry ) ;
264317
265318 return material ;
266319
0 commit comments