Skip to content

Commit

Permalink
Potree units sync
Browse files Browse the repository at this point in the history
  • Loading branch information
pierotofy committed May 13, 2024
1 parent e9c2409 commit 80a7f20
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 22 additions & 1 deletion app/static/app/js/ModelView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PropTypes from 'prop-types';
import * as THREE from 'THREE';
import $ from 'jquery';
import { _, interpolate } from './classes/gettext';
import { getUnitSystem, setUnitSystem } from './classes/Units';

require('./vendor/OBJLoader');
require('./vendor/MTLLoader');
Expand Down Expand Up @@ -301,6 +302,20 @@ class ModelView extends React.Component {
viewer.setPointBudget(10*1000*1000);
viewer.setEDLEnabled(true);
viewer.loadSettingsFromURL();

const currentUnit = getUnitSystem();
const origSetUnit = viewer.setLengthUnitAndDisplayUnit;
viewer.setLengthUnitAndDisplayUnit = (lengthUnit, displayUnit) => {
if (displayUnit === 'm') setUnitSystem('metric');
else if (displayUnit === 'ft'){
// Potree doesn't have US/international imperial, so
// we default to international unless the user has previously
// selected US
if (currentUnit === 'metric') setUnitSystem("imperial");
else setUnitSystem(currentUnit);
}
origSetUnit.call(viewer, lengthUnit, displayUnit);
};

viewer.loadGUI(() => {
viewer.setLanguage('en');
Expand Down Expand Up @@ -335,7 +350,7 @@ class ModelView extends React.Component {
directional.position.z = 99999999999;
viewer.scene.scene.add( directional );

this.pointCloudFilePath(pointCloudPath => {
this.pointCloudFilePath(pointCloudPath =>{
Potree.loadPointCloud(pointCloudPath, "Point Cloud", e => {
if (e.type == "loading_failed"){
this.setState({error: "Could not load point cloud. This task doesn't seem to have one. Try processing the task again."});
Expand All @@ -351,6 +366,12 @@ class ModelView extends React.Component {

viewer.fitToScreen();

if (getUnitSystem() === 'metric'){
viewer.setLengthUnitAndDisplayUnit('m', 'm');
}else{
viewer.setLengthUnitAndDisplayUnit('m', 'ft');
}

// Load saved scene (if any)
$.ajax({
type: "GET",
Expand Down
4 changes: 4 additions & 0 deletions app/static/app/js/classes/Units.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ class ValueUnit{
}

class NanUnit{
constructor(){
this.value = NaN;
this.unit = units.meters; // Don't matter
}
toString(){
return "NaN";
}
Expand Down

0 comments on commit 80a7f20

Please sign in to comment.