Skip to content

Commit b2f5409

Browse files
author
Leon
committed
examples: restore webgl_loader_pcd baseline; lint: semicolons + indentation
- Set default example back to 'binary/Zaghetto.pcd' - Restore Y-up camera initial position to (0, 0, 1) - Revert OrbitControls maxDistance to 10 for Y-up path - Keep Z-up path logic for specific datasets (no visual baseline change) Lint: - PCDLoader.js: add missing semicolons for label reading (binary/binary_compressed) - webgl_loader_pcd.html: fix indentation to tabs (ESLint indent rule)
1 parent 7d54796 commit b2f5409

File tree

2 files changed

+49
-45
lines changed

2 files changed

+49
-45
lines changed

examples/jsm/loaders/PCDLoader.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,11 @@ class PCDLoader extends Loader {
515515
}
516516

517517
if ( offset.label !== undefined ) {
518-
519-
const labelIndex = PCDheader.fields.indexOf('label')
520-
const labelType = PCDheader.type[labelIndex]
521-
const labelSize = PCDheader.size[labelIndex]
522-
label.push(this._getDataView(dataview, (PCDheader.points * offset.label) + labelSize * i, labelType, labelSize))
518+
519+
const labelIndex = PCDheader.fields.indexOf( 'label' );
520+
const labelType = PCDheader.type[ labelIndex ];
521+
const labelSize = PCDheader.size[ labelIndex ];
522+
label.push( this._getDataView( dataview, ( PCDheader.points * offset.label ) + labelSize * i, labelType, labelSize ) );
523523

524524
}
525525

@@ -579,10 +579,10 @@ class PCDLoader extends Loader {
579579

580580
if ( offset.label !== undefined ) {
581581

582-
const labelIndex = PCDheader.fields.indexOf('label')
583-
const labelType = PCDheader.type[labelIndex]
584-
const labelSize = PCDheader.size[labelIndex]
585-
label.push(this._getDataView(dataview, row + offset.label, labelType, labelSize))
582+
const labelIndex = PCDheader.fields.indexOf( 'label' );
583+
const labelType = PCDheader.type[ labelIndex ];
584+
const labelSize = PCDheader.size[ labelIndex ];
585+
label.push( this._getDataView( dataview, row + offset.label, labelType, labelSize ) );
586586

587587
}
588588

examples/webgl_loader_pcd.html

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -71,40 +71,42 @@
7171
points.name = file;
7272
scene.add( points );
7373

74-
// If geometry has integer label attribute, colorize by label
75-
const labelAttr = points.geometry.getAttribute( 'label' );
76-
if ( labelAttr ) {
77-
78-
const count = labelAttr.count;
79-
const colors = new Float32Array( count * 3 );
80-
const labelToColor = new Map();
81-
const tmp = new THREE.Color();
82-
83-
for ( let i = 0; i < count; i ++ ) {
84-
85-
const label = labelAttr.getX( i );
86-
let c = labelToColor.get( label );
87-
if ( c === undefined ) {
88-
// Deterministic label -> color mapping via HSL
89-
const hue = ( ( ( label * 37 ) % 360 ) + 360 ) % 360 / 360; // [0,1)
90-
tmp.setHSL( hue, 0.6, 0.5 );
91-
c = tmp.clone();
92-
labelToColor.set( label, c );
93-
}
94-
95-
colors[ i * 3 + 0 ] = c.r;
96-
colors[ i * 3 + 1 ] = c.g;
97-
colors[ i * 3 + 2 ] = c.b;
98-
74+
// If geometry has integer label attribute, colorize by label
75+
const labelAttr = points.geometry.getAttribute( 'label' );
76+
if ( labelAttr ) {
77+
78+
const count = labelAttr.count;
79+
const colors = new Float32Array( count * 3 );
80+
const labelToColor = new Map();
81+
const tmp = new THREE.Color();
82+
83+
for ( let i = 0; i < count; i ++ ) {
84+
85+
const label = labelAttr.getX( i );
86+
let c = labelToColor.get( label );
87+
if ( c === undefined ) {
88+
89+
// Deterministic label -> color mapping via HSL
90+
const hue = ( ( ( label * 37 ) % 360 ) + 360 ) % 360 / 360; // [0,1)
91+
tmp.setHSL( hue, 0.6, 0.5 );
92+
c = tmp.clone();
93+
labelToColor.set( label, c );
94+
9995
}
10096

101-
points.geometry.setAttribute( 'color', new THREE.Float32BufferAttribute( colors, 3 ) );
102-
if ( points.material && 'vertexColors' in points.material ) points.material.vertexColors = true;
97+
colors[ i * 3 + 0 ] = c.r;
98+
colors[ i * 3 + 1 ] = c.g;
99+
colors[ i * 3 + 2 ] = c.b;
103100

104101
}
105102

103+
points.geometry.setAttribute( 'color', new THREE.Float32BufferAttribute( colors, 3 ) );
104+
if ( points.material && 'vertexColors' in points.material ) points.material.vertexColors = true;
105+
106+
}
107+
106108
// For car_scene (Z-up data), use Z-up camera and fit view
107-
if ( zUpFiles.includes(file) ) {
109+
if ( zUpFiles.includes( file ) ) {
108110

109111
// Use Z-up for camera and controls
110112
camera.up.set( 0, 0, 1 );
@@ -136,16 +138,16 @@
136138
controls.target.copy( center );
137139

138140
// Place camera in an oblique top view for Z-up
139-
const viewDir = new THREE.Vector3( 0, -1, 0.5 ).normalize();
141+
const viewDir = new THREE.Vector3( 0, - 1, 0.5 ).normalize();
140142
camera.position.copy( center ).add( viewDir.multiplyScalar( distance ) );
141143
camera.lookAt( center );
142144
// Clamp polar angle to avoid flip; update matrices
143145
controls.minPolarAngle = 0.01;
144146
controls.maxPolarAngle = Math.PI - 0.01;
145147
controls.update();
146148
camera.updateProjectionMatrix();
147-
}
148-
else {
149+
150+
} else {
149151

150152
// Non car_scene: keep legacy rotateX(Math.PI) for display
151153
points.geometry.rotateX( Math.PI );
@@ -161,12 +163,12 @@
161163
controls = new OrbitControls( camera, renderer.domElement );
162164
controls.addEventListener( 'change', render );
163165
controls.minDistance = 0.5;
164-
controls.maxDistance = 1000;
166+
controls.maxDistance = 10;
165167
controls.screenSpacePanning = true;
166168

167169
// Restore initial position and target
168170
controls.target.set( 0, 0, 0 );
169-
camera.position.set( 0, 0, 2 );
171+
camera.position.set( 0, 0, 1 );
170172
camera.lookAt( 0, 0, 0 );
171173
controls.update();
172174
camera.updateProjectionMatrix();
@@ -178,12 +180,16 @@
178180
gui.add( points.material, 'size', 0.001, 0.01 ).onChange( render );
179181
// Hide color control when geometry has label-based vertex colors
180182
if ( ! labelAttr ) {
183+
181184
gui.addColor( points.material, 'color' ).onChange( render );
185+
182186
}
187+
183188
gui.add( points, 'name', [
184189
...yUpFiles,
185190
...zUpFiles,
186191
] ).name( 'type' ).onChange( e => {
192+
187193
gui.destroy();
188194
scene.remove( points );
189195
loadPointCloud( e );
@@ -197,9 +203,7 @@
197203

198204
};
199205

200-
// loadPointCloud( 'binary/Zaghetto.pcd' );
201-
202-
loadPointCloud( 'binary/fusion_lidar_scene.pcd' );
206+
loadPointCloud( 'binary/Zaghetto.pcd' );
203207

204208
window.addEventListener( 'resize', onWindowResize );
205209

0 commit comments

Comments
 (0)