Browse Source

Editor: Added option for converting Geometry to BufferGeometry.

Mr.doob 12 years ago
parent
commit
8effe4375e
3 changed files with 45 additions and 14 deletions
  1. 2 0
      editor/index.html
  2. 41 12
      editor/js/Menubar.Edit.js
  3. 2 2
      editor/js/Viewport.js

+ 2 - 0
editor/index.html

@@ -112,6 +112,8 @@
 
 		<!-- WIP -->
 
+		<script src="../examples/js/BufferGeometryUtils.js"></script>
+
 		<script src="../examples/js/exporters/BufferGeometryExporter.js"></script>
 		<script src="../examples/js/exporters/GeometryExporter.js"></script>
 		<script src="../examples/js/exporters/MaterialExporter.js"></script>

+ 41 - 12
editor/js/Menubar.Edit.js

@@ -38,6 +38,47 @@ Menubar.Edit = function ( editor ) {
 	} );
 	options.add( option );
 
+	// delete
+
+	var option = new UI.Panel();
+	option.setClass( 'option' );
+	option.setTextContent( 'Delete' );
+	option.onClick( function () {
+
+		editor.removeObject( editor.selected );
+		editor.deselect();
+
+	} );
+	options.add( option );
+
+	options.add( new UI.HorizontalRule() );
+
+	// convert to BufferGeometry
+
+	var option = new UI.Panel();
+	option.setClass( 'option' );
+	option.setTextContent( 'Convert' );
+	option.onClick( function () {
+
+		var object = editor.selected;
+
+		if ( object.geometry instanceof THREE.Geometry ) {
+
+			if ( object.parent === undefined ) return; // avoid flattening the camera or scene
+
+			if ( confirm( 'Convert ' + object.name + ' to BufferGeometry?' ) === false ) return;
+
+			delete object.__webglInit; // TODO: Remove hack (WebGLRenderer refactoring)
+
+			object.geometry = THREE.BufferGeometryUtils.fromGeometry( object.geometry );
+
+			editor.signals.objectChanged.dispatch( object );
+
+		}
+
+	} );
+	options.add( option );
+
 	// flatten
 
 	var option = new UI.Panel();
@@ -67,18 +108,6 @@ Menubar.Edit = function ( editor ) {
 	} );
 	options.add( option );
 
-	// delete
-
-	var option = new UI.Panel();
-	option.setClass( 'option' );
-	option.setTextContent( 'Delete' );
-	option.onClick( function () {
-
-		editor.removeObject( editor.selected );
-		editor.deselect();
-
-	} );
-	options.add( option );
 
 	//
 

+ 2 - 2
editor/js/Viewport.js

@@ -442,11 +442,11 @@ var Viewport = function ( editor ) {
 
 				} else if ( geometry instanceof THREE.BufferGeometry ) {
 
-					vertices += geometry.attributes.position.numItems / 3;
+					vertices += geometry.attributes.position.array.length / 3;
 
 					if ( geometry.attributes.index !== undefined ) {
 
-						faces += geometry.attributes.index.numItems / 3;
+						faces += geometry.attributes.index.array.length / 3;
 
 					} else {