Skip to content

Commit

Permalink
Links for 3D meshes support
Browse files Browse the repository at this point in the history
  • Loading branch information
pierotofy committed Nov 20, 2024
1 parent 46ea00b commit b07c1f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
34 changes: 27 additions & 7 deletions app/static/app/js/ModelView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,19 @@ class SetCameraView extends React.Component{

class TexturedModelMenu extends React.Component{
static propTypes = {
toggleTexturedModel: PropTypes.func.isRequired
toggleTexturedModel: PropTypes.func.isRequired,
selected: PropTypes.bool
}

static defaultProps = {
selected: false
}

constructor(props){
super(props);

this.state = {
showTexturedModel: false
showTexturedModel: props.selected
}

// Translation for sidebar.html
Expand Down Expand Up @@ -129,21 +134,23 @@ class ModelView extends React.Component {
static defaultProps = {
task: null,
public: false,
shareButtons: true
shareButtons: true,
modelType: "cloud"
};

static propTypes = {
task: PropTypes.object.isRequired, // The object should contain two keys: {id: <taskId>, project: <projectId>}
public: PropTypes.bool, // Is the view being displayed via a shared link?
shareButtons: PropTypes.bool
shareButtons: PropTypes.bool,
modelType: PropTypes.oneOf(['cloud', 'mesh'])
};

constructor(props){
super(props);

this.state = {
error: "",
showTexturedModel: false,
showingTexturedModel: false,
initializingModel: false,
selectedCamera: null,
modalOpen: false
Expand Down Expand Up @@ -323,7 +330,7 @@ class ModelView extends React.Component {
viewer.toggleSidebar();

if (this.hasTexturedModel()){
window.ReactDOM.render(<TexturedModelMenu toggleTexturedModel={this.toggleTexturedModel}/>, $("#textured_model_button").get(0));
window.ReactDOM.render(<TexturedModelMenu selected={this.props.modelType === 'mesh'} toggleTexturedModel={this.toggleTexturedModel}/>, $("#textured_model_button").get(0));
}else{
$("#textured_model").hide();
$("#textured_model_container").hide();
Expand Down Expand Up @@ -356,6 +363,11 @@ class ModelView extends React.Component {
this.setState({error: "Could not load point cloud. This task doesn't seem to have one. Try processing the task again."});
return;
}

// Automatically load 3D model if required
if (this.hasTexturedModel() && this.props.modelType === "mesh"){
this.toggleTexturedModel({ target: { checked: true }});
}

let scene = viewer.scene;
scene.addPointCloud(e.pointcloud);
Expand Down Expand Up @@ -655,6 +667,7 @@ class ModelView extends React.Component {

this.setState({
initializingModel: false,
showingTexturedModel: true
});
}

Expand Down Expand Up @@ -699,17 +712,23 @@ class ModelView extends React.Component {
// Already initialized
this.modelReference.visible = true;
this.setPointCloudsVisible(false);
this.setState({showingTexturedModel: true});
}
}else{
this.modelReference.visible = false;
this.setPointCloudsVisible(true);
this.setState({showingTexturedModel: false});
}
}

// React render
render(){
const { selectedCamera } = this.state;
const { selectedCamera, showingTexturedModel } = this.state;
const { task } = this.props;
const queryParams = {};
if (showingTexturedModel){
queryParams.t = "mesh";
}

return (<div className="model-view">
<ErrorMessage bind={[this, "error"]} />
Expand All @@ -735,6 +754,7 @@ class ModelView extends React.Component {
task={this.props.task}
popupPlacement="top"
linksTarget="3d"
queryParams={queryParams}
/>
: ""}
<SwitchModeButton
Expand Down
3 changes: 2 additions & 1 deletion app/views/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def handle_model_display(request, template, task_pk=None):
'task': json.dumps(task.get_model_display_params()),
'public': 'true',
'public-edit': str(task.public_edit).lower(),
'share-buttons': 'false' if settings.DESKTOP_MODE else 'true'
'share-buttons': 'false' if settings.DESKTOP_MODE else 'true',
'model-type': request.GET.get('t', 'cloud'),
}.items()
})

Expand Down

0 comments on commit b07c1f8

Please sign in to comment.