Skip to content
This repository was archived by the owner on Dec 29, 2025. It is now read-only.

Commit 90c6adf

Browse files
Update mobile PCD+XYZ+LAS Viewer
1 parent 7d0b0c0 commit 90c6adf

File tree

1 file changed

+87
-15
lines changed

1 file changed

+87
-15
lines changed

viewers/templates/Mobile/MPCD Viewer.html

Lines changed: 87 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
var THREE, manager, pcd_loader, xyz_loader, xyz_format, las_loader, las_format;
2727
var renderer, scene, camera, pcd_obj, controls, isMobile, render_requested;
2828
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;
3030
var selected_pcd_file, selected_url_file = '';
31+
var las_displayed = false, bounding_box;
3132
var url_displayed = false, url_loading = false;
3233
var vertex_colors_present, vertex_colors_enabled;
3334
var normal_colors_present, normal_colors_enabled;
@@ -47,7 +48,10 @@
4748

4849
pcd_loader = new PCDLoader( manager );
4950
xyz_loader = new XYZLoader( manager );
51+
5052
las_loader = new LASZLoader( manager );
53+
las_loader.setSkipIntensity( true );
54+
las_loader.setSkipClassification( true );
5155
</script>
5256

5357
<!-- Original OBJ source code that inspired this: https://codepen.io/Mamboleoo/pen/PqjGdN -->
@@ -63,6 +67,8 @@
6367
<div class="fm">
6468
<button id="btn_desktop" title="Open Desktop Version" onclick="switch_to_desktop();">D</button>
6569
<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>
6672
<button title="Get remote model via URL" id="btn_url" onclick="show_url()" style="min-width: 38px;">URL</button>
6773
<label for="btn_url" title="Get remote model via URL"></label>
6874
<button title="Browse Local Files" id="btn_file_input" style="min-width: 54px;" onclick="document.getElementById('file_input').click();">Browse</button>
@@ -91,6 +97,16 @@
9197
<button title="Clear" id="btn_clear" onclick="clear_url();" style="min-width: 8.5%;">Clear</button>
9298
<label for="btn_clear" title="Clear"></label>
9399
</div>
100+
<div class="fm" id="las" style="display: none;">
101+
<label>Level of Detail for LAS/LAZ</label>&nbsp;
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>
94110
</div>
95111

96112
<div id="div_error" class="error_msg">E R R O R !</div>
@@ -106,6 +122,26 @@
106122
link.click();
107123
}
108124

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+
109145
function show_url() {
110146
if (url_displayed === true) {
111147
url_displayed = false;
@@ -201,28 +237,44 @@
201237
});
202238
}
203239

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+
204253
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();
206257

207-
bounding_box.setFromObject( pcd_obj );
208258
let size = bounding_box.getSize( new THREE.Vector3() );
209259

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 );
216264
} else {
217-
pcd_obj.scale.multiplyScalar( 1 / size.y )
265+
pcd_obj.scale.multiplyScalar( ( ww / size.x ) * 0.1 );
218266
}
219267

268+
// Get center coordinates and move to the center again
269+
270+
center_object();
271+
220272
pcd_obj.material.size = (isMobile === true) ? 0.8 : 0.1;
221273

222-
bounding_box.setFromObject( pcd_obj );
223-
let center = bounding_box.getCenter( new THREE.Vector3() );
274+
// Set camera's z distance
224275

225-
controls.target.set( center.x, center.y, center.z );
276+
camera.position.z = bounding_box.max.z + 250;
277+
camera.updateProjectionMatrix();
226278

227279
mouse_wheel = true;
228280
}
@@ -245,7 +297,9 @@
245297
xyz_format = false;
246298
mouse_down = false;
247299
mouse_wheel = true;
248-
count =0;
300+
count = 0;
301+
elevation = false;
302+
elevationColors = null;
249303
render_requested = false;
250304
vertex_colors_enabled = false;
251305
vertex_colors_present = false;
@@ -732,7 +786,7 @@
732786
renderer.render( scene, camera );
733787

734788
if (mouse_wheel === true) {
735-
if (count > 15) {
789+
if (count > 25) {
736790
mouse_wheel = false;
737791
count = 0;
738792
} else {
@@ -751,6 +805,7 @@
751805
document.getElementById('btn_url').style.backgroundColor = 'transparent';
752806
document.getElementById('btn_plus').style.backgroundColor = 'transparent';
753807
document.getElementById('btn_minus').style.backgroundColor = 'transparent';
808+
document.getElementById('btn_elevation_colors').style.backgroundColor = 'transparent';
754809

755810
// Reset the view
756811
if (reset === true) {
@@ -775,6 +830,7 @@
775830
document.getElementById('div_error').style.display = 'none';
776831
document.getElementById('url_entry').value = '';
777832
selected_url_file = '';
833+
778834
enable_disable( true );
779835
}
780836

@@ -818,6 +874,10 @@
818874
(/Android|webOS|iPhone|iPad|iPod|CriOS|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent )) ||
819875
(navigator.maxTouchPoints !== undefined && navigator.maxTouchPoints > 2 && /MacIntel/.test( navigator.platform ));
820876

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+
821881
mouse_wheel = true;
822882
}
823883

@@ -834,6 +894,18 @@
834894
mouse_wheel = true;
835895
});
836896

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+
837909
$('input[type=color]').each( function() {
838910
if (this.disabled === false ) {
839911
$(this).hover(

0 commit comments

Comments
 (0)