|
26 | 26 | var THREE, manager, pcd_loader, xyz_loader, xyz_format, las_loader, las_format; |
27 | 27 | var renderer, scene, camera, pcd_obj, controls, isMobile, render_requested; |
28 | 28 | var mouse_down, mouse_wheel, reset_rotation, events_initialized, count = 0; |
29 | | - var ww = window.innerWidth, wh = window.innerHeight, bounding_box; |
| 29 | + var ww = window.innerWidth, wh = window.innerHeight; |
30 | 30 | var selected_pcd_file, selected_url_file = ''; |
| 31 | + var las_displayed = false, bounding_box; |
31 | 32 | var url_displayed = false, url_loading = false; |
32 | 33 | var vertex_colors_present, vertex_colors_enabled; |
33 | 34 | var normal_colors_present, normal_colors_enabled; |
|
47 | 48 |
|
48 | 49 | pcd_loader = new PCDLoader( manager ); |
49 | 50 | xyz_loader = new XYZLoader( manager ); |
| 51 | + |
50 | 52 | las_loader = new LASZLoader( manager ); |
| 53 | + las_loader.setSkipIntensity( true ); |
| 54 | + las_loader.setSkipClassification( true ); |
51 | 55 | </script> |
52 | 56 |
|
53 | 57 | <!-- Original OBJ source code that inspired this: https://codepen.io/Mamboleoo/pen/PqjGdN --> |
|
63 | 67 | <div class="fm"> |
64 | 68 | <button id="btn_desktop" title="Open Desktop Version" onclick="switch_to_desktop();">D</button> |
65 | 69 | <label for="btn_desktop" title="Open Desktop Version"></label> |
| 70 | + <button title="Set Level of Detail for Displaying LAS/LAZ Models" id="btn_las" onclick="show_las();" style="min-width: 34px;">LOD</button> |
| 71 | + <label for="btn_las" title="Set Level of Detail for Displaying LAS/LAZ Models"></label> |
66 | 72 | <button title="Get remote model via URL" id="btn_url" onclick="show_url()" style="min-width: 38px;">URL</button> |
67 | 73 | <label for="btn_url" title="Get remote model via URL"></label> |
68 | 74 | <button title="Browse Local Files" id="btn_file_input" style="min-width: 54px;" onclick="document.getElementById('file_input').click();">Browse</button> |
|
91 | 97 | <button title="Clear" id="btn_clear" onclick="clear_url();" style="min-width: 8.5%;">Clear</button> |
92 | 98 | <label for="btn_clear" title="Clear"></label> |
93 | 99 | </div> |
| 100 | + <div class="fm" id="las" style="display: none;"> |
| 101 | + <label>Level of Detail for LAS/LAZ</label> |
| 102 | + <select id="detail_level" style="min-width: 100px;"> |
| 103 | + <option value="" disabled selected>Percentage</option> |
| 104 | + <option value="1" onclick="set_las_details( 1 );">100%</option> |
| 105 | + <option value="2" onclick="set_las_details( 2 );">50%</option> |
| 106 | + <option value="4" onclick="set_las_details( 4 );">25%</option> |
| 107 | + <option value="10" onclick="set_las_details( 10 );">10%</option> |
| 108 | + </select> |
| 109 | + </div> |
94 | 110 | </div> |
95 | 111 |
|
96 | 112 | <div id="div_error" class="error_msg">E R R O R !</div> |
|
106 | 122 | link.click(); |
107 | 123 | } |
108 | 124 |
|
| 125 | + function show_las() { |
| 126 | + if (las_displayed === true) { |
| 127 | + document.getElementById('las').style.display = 'none'; |
| 128 | + document.getElementById('btn_las').style.backgroundColor = 'transparent'; |
| 129 | + las_displayed = false; |
| 130 | + } else { |
| 131 | + document.getElementById('las').style.display = 'block'; |
| 132 | + document.getElementById('btn_las').style.backgroundColor = 'lightgreen'; |
| 133 | + las_displayed = true; |
| 134 | + } |
| 135 | + |
| 136 | + resize(); |
| 137 | + |
| 138 | + mouse_wheel = true; |
| 139 | + } |
| 140 | + |
| 141 | + function set_las_details( skip_points = 1 ) { |
| 142 | + las_loader.setSkipPoints( skip_points ); |
| 143 | + } |
| 144 | + |
109 | 145 | function show_url() { |
110 | 146 | if (url_displayed === true) { |
111 | 147 | url_displayed = false; |
|
201 | 237 | }); |
202 | 238 | } |
203 | 239 |
|
| 240 | + function center_object() { |
| 241 | + bounding_box.setFromObject( pcd_obj ); |
| 242 | + let center = bounding_box.getCenter( new THREE.Vector3() ).multiplyScalar( -1 ); |
| 243 | + |
| 244 | + // Move to the center |
| 245 | + |
| 246 | + if (center.x !== 0) pcd_obj.translateX( center.x ); |
| 247 | + if (center.y !== 0) pcd_obj.translateY( center.y ); |
| 248 | + if (center.z !== 0) pcd_obj.translateZ( center.z ); |
| 249 | + |
| 250 | + mouse_wheel = true; |
| 251 | + } |
| 252 | + |
204 | 253 | function set_initial_scale() { |
205 | | - // Set the initial scale of the object so it comes to view |
| 254 | + // Set the initial scale of the object so it hopefully comes to view |
| 255 | + |
| 256 | + center_object(); |
206 | 257 |
|
207 | | - bounding_box.setFromObject( pcd_obj ); |
208 | 258 | let size = bounding_box.getSize( new THREE.Vector3() ); |
209 | 259 |
|
210 | | - if ( size.y > 1 ) { |
211 | | - pcd_obj.scale.multiplyScalar( 50 / size.y ); |
212 | | - } else if ( size.y > 0.02 ) { |
213 | | - pcd_obj.scale.multiplyScalar( 25 / size.y ); |
214 | | - } else if ( size.y > 0.01 ) { |
215 | | - pcd_obj.scale.multiplyScalar( 10 / size.y ); |
| 260 | + // Scale according to window width / height, whichever is greater |
| 261 | + |
| 262 | + if (ww > wh) { |
| 263 | + pcd_obj.scale.multiplyScalar( ( wh / size.y ) * 0.1 ); |
216 | 264 | } else { |
217 | | - pcd_obj.scale.multiplyScalar( 1 / size.y ) |
| 265 | + pcd_obj.scale.multiplyScalar( ( ww / size.x ) * 0.1 ); |
218 | 266 | } |
219 | 267 |
|
| 268 | + // Get center coordinates and move to the center again |
| 269 | + |
| 270 | + center_object(); |
| 271 | + |
220 | 272 | pcd_obj.material.size = (isMobile === true) ? 0.8 : 0.1; |
221 | 273 |
|
222 | | - bounding_box.setFromObject( pcd_obj ); |
223 | | - let center = bounding_box.getCenter( new THREE.Vector3() ); |
| 274 | + // Set camera's z distance |
224 | 275 |
|
225 | | - controls.target.set( center.x, center.y, center.z ); |
| 276 | + camera.position.z = bounding_box.max.z + 250; |
| 277 | + camera.updateProjectionMatrix(); |
226 | 278 |
|
227 | 279 | mouse_wheel = true; |
228 | 280 | } |
|
245 | 297 | xyz_format = false; |
246 | 298 | mouse_down = false; |
247 | 299 | mouse_wheel = true; |
248 | | - count =0; |
| 300 | + count = 0; |
| 301 | + elevation = false; |
| 302 | + elevationColors = null; |
249 | 303 | render_requested = false; |
250 | 304 | vertex_colors_enabled = false; |
251 | 305 | vertex_colors_present = false; |
|
732 | 786 | renderer.render( scene, camera ); |
733 | 787 |
|
734 | 788 | if (mouse_wheel === true) { |
735 | | - if (count > 15) { |
| 789 | + if (count > 25) { |
736 | 790 | mouse_wheel = false; |
737 | 791 | count = 0; |
738 | 792 | } else { |
|
751 | 805 | document.getElementById('btn_url').style.backgroundColor = 'transparent'; |
752 | 806 | document.getElementById('btn_plus').style.backgroundColor = 'transparent'; |
753 | 807 | document.getElementById('btn_minus').style.backgroundColor = 'transparent'; |
| 808 | + document.getElementById('btn_elevation_colors').style.backgroundColor = 'transparent'; |
754 | 809 |
|
755 | 810 | // Reset the view |
756 | 811 | if (reset === true) { |
|
775 | 830 | document.getElementById('div_error').style.display = 'none'; |
776 | 831 | document.getElementById('url_entry').value = ''; |
777 | 832 | selected_url_file = ''; |
| 833 | + |
778 | 834 | enable_disable( true ); |
779 | 835 | } |
780 | 836 |
|
|
818 | 874 | (/Android|webOS|iPhone|iPad|iPod|CriOS|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent )) || |
819 | 875 | (navigator.maxTouchPoints !== undefined && navigator.maxTouchPoints > 2 && /MacIntel/.test( navigator.platform )); |
820 | 876 |
|
| 877 | + if (navigator.userAgent.indexOf('Chrome') > -1 || navigator.userAgent.indexOf('Safari') > -1 || isMobile === true) { |
| 878 | + $('#detail_level').change( function() { $(this).children(':selected').click(); }); |
| 879 | + } |
| 880 | + |
821 | 881 | mouse_wheel = true; |
822 | 882 | } |
823 | 883 |
|
|
834 | 894 | mouse_wheel = true; |
835 | 895 | }); |
836 | 896 |
|
| 897 | + $('select').each( function() { |
| 898 | + if (this.disabled === false) { |
| 899 | + $(this).hover( |
| 900 | + function() { $(this)[ 0 ].style.border = 'solid 2px red'; }, |
| 901 | + function() { $(this)[ 0 ].style.border = 'solid 1px blue'; }); |
| 902 | + } else { |
| 903 | + $(this).unbind('mouseenter mouseleave'); |
| 904 | + } |
| 905 | + |
| 906 | + mouse_wheel = true; |
| 907 | + }); |
| 908 | + |
837 | 909 | $('input[type=color]').each( function() { |
838 | 910 | if (this.disabled === false ) { |
839 | 911 | $(this).hover( |
|
0 commit comments