浏览代码

webvr_vive_paint: only upload the new strokes.

Mr.doob 8 年之前
父节点
当前提交
b9ef4dce91
共有 1 个文件被更改,包括 28 次插入0 次删除
  1. 28 0
      examples/webvr_vive_paint.html

+ 28 - 0
examples/webvr_vive_paint.html

@@ -207,12 +207,15 @@
 				var geometry = new THREE.BufferGeometry();
 
 				var positions = new THREE.BufferAttribute( new Float32Array( 1000000 * 3 ), 3 );
+				positions.dynamic = true;
 				geometry.addAttribute( 'position', positions );
 
 				var normals = new THREE.BufferAttribute( new Float32Array( 1000000 * 3 ), 3 );
+				normals.dynamic = true;
 				geometry.addAttribute( 'normal', normals );
 
 				var colors = new THREE.BufferAttribute( new Float32Array( 1000000 * 3 ), 3 );
+				colors.dynamic = true;
 				geometry.addAttribute( 'color', colors );
 
 				geometry.drawRange.count = 0;
@@ -349,8 +352,29 @@
 				}
 
 				geometry.drawRange.count = count;
+
+			}
+
+			function updateGeometry( start, end ) {
+
+				if ( start === end ) return;
+
+				var offset = start * 3;
+				var count = ( end - start ) * 3;
+
+				var geometry = line.geometry;
+				var attributes = geometry.attributes;
+
+				attributes.position.updateRange.offset = offset;
+				attributes.position.updateRange.count = count;
 				attributes.position.needsUpdate = true;
+
+				attributes.normal.updateRange.offset = offset;
+				attributes.normal.updateRange.count = count;
 				attributes.normal.needsUpdate = true;
+
+				attributes.color.updateRange.offset = offset;
+				attributes.color.updateRange.count = count;
 				attributes.color.needsUpdate = true;
 
 			}
@@ -411,9 +435,13 @@
 
 				controls.update();
 
+				var count = line.geometry.drawRange.count;
+
 				handleController( controller1 );
 				handleController( controller2 );
 
+				updateGeometry( count, line.geometry.drawRange.count );
+
 				effect.render( scene, camera );
 
 			}