Browse Source

Points support added

Fernando Serrano 8 years ago
parent
commit
f352452145
2 changed files with 43 additions and 8 deletions
  1. 28 4
      examples/gltf_exporter.html
  2. 15 4
      examples/js/exporters/GLTFExporter.js

+ 28 - 4
examples/gltf_exporter.html

@@ -159,12 +159,36 @@
 				object2 = new THREE.Mesh( new THREE.BoxBufferGeometry( 30, 30, 30 ), material );
 				object2.name = "Cube in group";
 				object2.position.set( 0, 100, 100 );
-				group2.add( object2 );
+				// group2.add( object2 );
 
+				// ---------------------------------
+				// Axis
+				// ---------------------------------
 				var axis = new THREE.AxisHelper(100);
 				axis.name = "AxisHelper";
+				// scene1.add( axis );
+
+				// ---------------------------------
+				// Points
+				// ---------------------------------
+				var NUM_POINTS = 100;
+				var pointsArray = new Float32Array( NUM_POINTS * 3 );
+				for ( var i = 0; i < NUM_POINTS; i++ ) {
+					pointsArray[ 3 * i ] = Math.random() * 100;
+					pointsArray[ 3 * i + 1 ] = Math.random() * 100;
+					pointsArray[ 3 * i + 2 ] = Math.random() * 100;
+				}
+
+				pointsGeo = new THREE.BufferGeometry();
+				pointsGeo.addAttribute( 'position', new THREE.BufferAttribute( pointsArray, 3 ).setDynamic( true ) );
+
+				var pointsMaterial = new THREE.PointsMaterial( { color: 0xffff00 } );
+				var points = new THREE.Points( pointsGeo, pointsMaterial );
+				points.name = "Points";
+				scene1.add( points );
+
+
 
-				scene1.add( axis );
 
 				scene1.add( camera );
 
@@ -268,8 +292,8 @@
 
 				var timer = Date.now() * 0.001;
 
-				camera.position.x = Math.cos( timer ) * 800;
-				camera.position.z = Math.sin( timer ) * 800;
+				camera.position.x = Math.cos( timer ) * 300;
+				camera.position.z = Math.sin( timer ) * 300;
 
 				camera.lookAt( scene1.position );
 				renderer.render( scene1, camera );

+ 15 - 4
examples/js/exporters/GLTFExporter.js

@@ -288,7 +288,8 @@ THREE.GLTFExporter.prototype = {
 			}
 
 			if ( material instanceof THREE.MeshBasicMaterial
-				|| material instanceof THREE.LineBasicMaterial) {
+				|| material instanceof THREE.LineBasicMaterial
+				|| material instanceof THREE.PointsMaterial ) {
 
 				// emissiveFactor
 				var color = material.color.toArray();
@@ -570,7 +571,9 @@ THREE.GLTFExporter.prototype = {
 				gltfNode.name = object.name;
 			}
 
-			if ( object instanceof THREE.Mesh || object instanceof THREE.Line) {
+			if ( object instanceof THREE.Mesh
+				|| object instanceof THREE.Line 
+				|| object instanceof THREE.Points ) {
 				gltfNode.mesh = processMesh( object );
 			} else if ( object instanceof THREE.Camera ) {
 				gltfNode.camera = processCamera( object );
@@ -581,7 +584,11 @@ THREE.GLTFExporter.prototype = {
 
 				for ( var i = 0, l = object.children.length; i < l; i ++ ) {
 					var child = object.children[ i ];
-					if ( child instanceof THREE.Mesh || child instanceof THREE.Camera || child instanceof THREE.Group || child instanceof THREE.Line ) {
+					if ( child instanceof THREE.Mesh
+						|| child instanceof THREE.Camera
+						|| child instanceof THREE.Group
+						|| child instanceof THREE.Line
+						|| child instanceof THREE.Points) {
 						gltfNode.children.push( processNode( child ) );
 					}
 				}
@@ -617,7 +624,11 @@ THREE.GLTFExporter.prototype = {
 				var child = scene.children[ i ];
 
 				// @TODO Right now we just process meshes and lights
-				if ( child instanceof THREE.Mesh || child instanceof THREE.Camera || child instanceof THREE.Group || child instanceof THREE.Line ) {
+				if ( child instanceof THREE.Mesh
+					|| child instanceof THREE.Camera
+					|| child instanceof THREE.Group
+					|| child instanceof THREE.Line
+					|| child instanceof THREE.Points) {
 					gltfScene.nodes.push( processNode( child ) );
 				}
 			}