|
71 | 71 | points.name = file; |
72 | 72 | scene.add( points ); |
73 | 73 |
|
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 | + |
99 | 95 | } |
100 | 96 |
|
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; |
103 | 100 |
|
104 | 101 | } |
105 | 102 |
|
| 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 | + |
106 | 108 | // For car_scene (Z-up data), use Z-up camera and fit view |
107 | | - if ( zUpFiles.includes(file) ) { |
| 109 | + if ( zUpFiles.includes( file ) ) { |
108 | 110 |
|
109 | 111 | // Use Z-up for camera and controls |
110 | 112 | camera.up.set( 0, 0, 1 ); |
|
136 | 138 | controls.target.copy( center ); |
137 | 139 |
|
138 | 140 | // 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(); |
140 | 142 | camera.position.copy( center ).add( viewDir.multiplyScalar( distance ) ); |
141 | 143 | camera.lookAt( center ); |
142 | 144 | // Clamp polar angle to avoid flip; update matrices |
143 | 145 | controls.minPolarAngle = 0.01; |
144 | 146 | controls.maxPolarAngle = Math.PI - 0.01; |
145 | 147 | controls.update(); |
146 | 148 | camera.updateProjectionMatrix(); |
147 | | - } |
148 | | - else { |
| 149 | + |
| 150 | + } else { |
149 | 151 |
|
150 | 152 | // Non car_scene: keep legacy rotateX(Math.PI) for display |
151 | 153 | points.geometry.rotateX( Math.PI ); |
|
161 | 163 | controls = new OrbitControls( camera, renderer.domElement ); |
162 | 164 | controls.addEventListener( 'change', render ); |
163 | 165 | controls.minDistance = 0.5; |
164 | | - controls.maxDistance = 1000; |
| 166 | + controls.maxDistance = 10; |
165 | 167 | controls.screenSpacePanning = true; |
166 | 168 |
|
167 | 169 | // Restore initial position and target |
168 | 170 | controls.target.set( 0, 0, 0 ); |
169 | | - camera.position.set( 0, 0, 2 ); |
| 171 | + camera.position.set( 0, 0, 1 ); |
170 | 172 | camera.lookAt( 0, 0, 0 ); |
171 | 173 | controls.update(); |
172 | 174 | camera.updateProjectionMatrix(); |
|
178 | 180 | gui.add( points.material, 'size', 0.001, 0.01 ).onChange( render ); |
179 | 181 | // Hide color control when geometry has label-based vertex colors |
180 | 182 | if ( ! labelAttr ) { |
| 183 | + |
181 | 184 | gui.addColor( points.material, 'color' ).onChange( render ); |
| 185 | + |
182 | 186 | } |
| 187 | + |
183 | 188 | gui.add( points, 'name', [ |
184 | 189 | ...yUpFiles, |
185 | 190 | ...zUpFiles, |
186 | 191 | ] ).name( 'type' ).onChange( e => { |
| 192 | + |
187 | 193 | gui.destroy(); |
188 | 194 | scene.remove( points ); |
189 | 195 | loadPointCloud( e ); |
|
197 | 203 |
|
198 | 204 | }; |
199 | 205 |
|
200 | | - // loadPointCloud( 'binary/Zaghetto.pcd' ); |
201 | | - |
202 | | - loadPointCloud( 'binary/fusion_lidar_scene.pcd' ); |
| 206 | + loadPointCloud( 'binary/Zaghetto.pcd' ); |
203 | 207 |
|
204 | 208 | window.addEventListener( 'resize', onWindowResize ); |
205 | 209 |
|
|
0 commit comments