浏览代码

PCDLoader: Add support for label field. (#24381)

Michael Herzog 3 年之前
父节点
当前提交
354db9b7cf
共有 1 个文件被更改,包括 21 次插入0 次删除
  1. 21 0
      examples/jsm/loaders/PCDLoader.js

+ 21 - 0
examples/jsm/loaders/PCDLoader.js

@@ -2,6 +2,7 @@ import {
 	BufferGeometry,
 	BufferGeometry,
 	FileLoader,
 	FileLoader,
 	Float32BufferAttribute,
 	Float32BufferAttribute,
+	Int32BufferAttribute,
 	Loader,
 	Loader,
 	LoaderUtils,
 	LoaderUtils,
 	Points,
 	Points,
@@ -230,6 +231,7 @@ class PCDLoader extends Loader {
 		const normal = [];
 		const normal = [];
 		const color = [];
 		const color = [];
 		const intensity = [];
 		const intensity = [];
+		const label = [];
 
 
 		// ascii
 		// ascii
 
 
@@ -292,6 +294,12 @@ class PCDLoader extends Loader {
 
 
 				}
 				}
 
 
+				if ( offset.label !== undefined ) {
+
+					label.push( parseInt( line[ offset.label ] ) );
+
+				}
+
 			}
 			}
 
 
 		}
 		}
@@ -352,6 +360,12 @@ class PCDLoader extends Loader {
 
 
 				}
 				}
 
 
+				if ( offset.label !== undefined ) {
+
+					const labelIndex = PCDheader.fields.indexOf( 'label' );
+					label.push( dataview.getInt32( ( PCDheader.points * offset.label ) + PCDheader.size[ labelIndex ] * i, this.littleEndian ) );
+
+				}
 
 
 			}
 			}
 
 
@@ -396,6 +410,12 @@ class PCDLoader extends Loader {
 
 
 				}
 				}
 
 
+				if ( offset.label !== undefined ) {
+
+					label.push( dataview.getInt32( row + offset.label, this.littleEndian ) );
+
+				}
+
 			}
 			}
 
 
 		}
 		}
@@ -408,6 +428,7 @@ class PCDLoader extends Loader {
 		if ( normal.length > 0 ) geometry.setAttribute( 'normal', new Float32BufferAttribute( normal, 3 ) );
 		if ( normal.length > 0 ) geometry.setAttribute( 'normal', new Float32BufferAttribute( normal, 3 ) );
 		if ( color.length > 0 ) geometry.setAttribute( 'color', new Float32BufferAttribute( color, 3 ) );
 		if ( color.length > 0 ) geometry.setAttribute( 'color', new Float32BufferAttribute( color, 3 ) );
 		if ( intensity.length > 0 ) geometry.setAttribute( 'intensity', new Float32BufferAttribute( intensity, 1 ) );
 		if ( intensity.length > 0 ) geometry.setAttribute( 'intensity', new Float32BufferAttribute( intensity, 1 ) );
+		if ( label.length > 0 ) geometry.setAttribute( 'label', new Int32BufferAttribute( label, 1 ) );
 
 
 		geometry.computeBoundingSphere();
 		geometry.computeBoundingSphere();