Selaa lähdekoodia

Add smooth normals flag

Garrett Johnson 6 vuotta sitten
vanhempi
commit
3bceb5573d
2 muutettua tiedostoa jossa 37 lisäystä ja 6 poistoa
  1. 3 1
      examples/js/loaders/LDrawLoader.js
  2. 34 5
      examples/webgl_loader_ldraw.html

+ 3 - 1
examples/js/loaders/LDrawLoader.js

@@ -536,7 +536,9 @@ THREE.LDrawLoader = ( function () {
 
 
 						if ( parseScope.conditionalSegments.length > 0 ) {
 						if ( parseScope.conditionalSegments.length > 0 ) {
 
 
-							objGroup.add( createObject( parseScope.conditionalSegments, 2 ) );
+							var lines = createObject( parseScope.conditionalSegments, 2 );
+							lines.isConditionalLine = true;
+							objGroup.add( lines );
 
 
 						}
 						}
 
 

+ 34 - 5
examples/webgl_loader_ldraw.html

@@ -111,7 +111,8 @@
 					envMapActivated: false,
 					envMapActivated: false,
 					separateObjects: false,
 					separateObjects: false,
 					displayLines: true,
 					displayLines: true,
-					optionalLines: false
+					optionalLines: false,
+					smoothNormals: true
 				};
 				};
 
 
 				gui = new dat.GUI();
 				gui = new dat.GUI();
@@ -136,15 +137,21 @@
 
 
 				} );
 				} );
 
 
+				gui.add( guiData, 'smoothNormals' ).name( 'Smooth Normals' ).onChange( function ( value ) {
+
+					reloadObject( false );
+
+				} );
+
 				gui.add( guiData, 'displayLines' ).name( 'Display Lines' ).onChange( function ( value ) {
 				gui.add( guiData, 'displayLines' ).name( 'Display Lines' ).onChange( function ( value ) {
 
 
-					model.children[ 1 ].visible = value;
+					updateLineSegments();
 
 
 				} );
 				} );
 
 
 				gui.add( guiData, 'optionalLines' ).name( 'Optional Lines' ).onChange( function ( value ) {
 				gui.add( guiData, 'optionalLines' ).name( 'Optional Lines' ).onChange( function ( value ) {
 
 
-					model.children[ 2 ].visible = value;
+					updateLineSegments();
 
 
 				} );
 				} );
 				window.addEventListener( 'resize', onWindowResize, false );
 				window.addEventListener( 'resize', onWindowResize, false );
@@ -166,6 +173,28 @@
 
 
 			}
 			}
 
 
+			function updateLineSegments() {
+
+				model.traverse( c => {
+
+					if ( c.isLineSegments ) {
+
+						if ( c.isConditionalLine ) {
+
+							c.visible = guiData.optionalLines;
+
+						} else {
+
+							c.visible = guiData.displayLines;
+
+						}
+
+					}
+
+				} );
+
+			}
+
 			function reloadObject( resetCamera ) {
 			function reloadObject( resetCamera ) {
 
 
 				if ( model ) {
 				if ( model ) {
@@ -181,6 +210,7 @@
 
 
 				var lDrawLoader = new THREE.LDrawLoader();
 				var lDrawLoader = new THREE.LDrawLoader();
 				lDrawLoader.separateObjects = guiData.separateObjects;
 				lDrawLoader.separateObjects = guiData.separateObjects;
+				lDrawLoader.smoothNormals = guiData.smoothNormals;
 				lDrawLoader
 				lDrawLoader
 					.setPath( ldrawPath )
 					.setPath( ldrawPath )
 					.load( guiData.modelFileName, function ( group2 ) {
 					.load( guiData.modelFileName, function ( group2 ) {
@@ -231,8 +261,7 @@
 
 
 						}
 						}
 
 
-						model.children[ 1 ].visible = guiData.displayLines;
-						model.children[ 2 ].visible = guiData.optionalLines;
+						updateLineSegments();
 
 
 						// Adjust camera and light
 						// Adjust camera and light