Skip to content

Commit 2d2bba6

Browse files
authored
Merge pull request #1571 from pierotofy/sharemodel
Links for 3D meshes support
2 parents 46ea00b + b07c1f8 commit 2d2bba6

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

app/static/app/js/ModelView.jsx

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,19 @@ class SetCameraView extends React.Component{
7070

7171
class TexturedModelMenu extends React.Component{
7272
static propTypes = {
73-
toggleTexturedModel: PropTypes.func.isRequired
73+
toggleTexturedModel: PropTypes.func.isRequired,
74+
selected: PropTypes.bool
75+
}
76+
77+
static defaultProps = {
78+
selected: false
7479
}
7580

7681
constructor(props){
7782
super(props);
7883

7984
this.state = {
80-
showTexturedModel: false
85+
showTexturedModel: props.selected
8186
}
8287

8388
// Translation for sidebar.html
@@ -129,21 +134,23 @@ class ModelView extends React.Component {
129134
static defaultProps = {
130135
task: null,
131136
public: false,
132-
shareButtons: true
137+
shareButtons: true,
138+
modelType: "cloud"
133139
};
134140

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

141148
constructor(props){
142149
super(props);
143150

144151
this.state = {
145152
error: "",
146-
showTexturedModel: false,
153+
showingTexturedModel: false,
147154
initializingModel: false,
148155
selectedCamera: null,
149156
modalOpen: false
@@ -323,7 +330,7 @@ class ModelView extends React.Component {
323330
viewer.toggleSidebar();
324331

325332
if (this.hasTexturedModel()){
326-
window.ReactDOM.render(<TexturedModelMenu toggleTexturedModel={this.toggleTexturedModel}/>, $("#textured_model_button").get(0));
333+
window.ReactDOM.render(<TexturedModelMenu selected={this.props.modelType === 'mesh'} toggleTexturedModel={this.toggleTexturedModel}/>, $("#textured_model_button").get(0));
327334
}else{
328335
$("#textured_model").hide();
329336
$("#textured_model_container").hide();
@@ -356,6 +363,11 @@ class ModelView extends React.Component {
356363
this.setState({error: "Could not load point cloud. This task doesn't seem to have one. Try processing the task again."});
357364
return;
358365
}
366+
367+
// Automatically load 3D model if required
368+
if (this.hasTexturedModel() && this.props.modelType === "mesh"){
369+
this.toggleTexturedModel({ target: { checked: true }});
370+
}
359371

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

656668
this.setState({
657669
initializingModel: false,
670+
showingTexturedModel: true
658671
});
659672
}
660673

@@ -699,17 +712,23 @@ class ModelView extends React.Component {
699712
// Already initialized
700713
this.modelReference.visible = true;
701714
this.setPointCloudsVisible(false);
715+
this.setState({showingTexturedModel: true});
702716
}
703717
}else{
704718
this.modelReference.visible = false;
705719
this.setPointCloudsVisible(true);
720+
this.setState({showingTexturedModel: false});
706721
}
707722
}
708723

709724
// React render
710725
render(){
711-
const { selectedCamera } = this.state;
726+
const { selectedCamera, showingTexturedModel } = this.state;
712727
const { task } = this.props;
728+
const queryParams = {};
729+
if (showingTexturedModel){
730+
queryParams.t = "mesh";
731+
}
713732

714733
return (<div className="model-view">
715734
<ErrorMessage bind={[this, "error"]} />
@@ -735,6 +754,7 @@ class ModelView extends React.Component {
735754
task={this.props.task}
736755
popupPlacement="top"
737756
linksTarget="3d"
757+
queryParams={queryParams}
738758
/>
739759
: ""}
740760
<SwitchModeButton

app/views/public.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def handle_model_display(request, template, task_pk=None):
5353
'task': json.dumps(task.get_model_display_params()),
5454
'public': 'true',
5555
'public-edit': str(task.public_edit).lower(),
56-
'share-buttons': 'false' if settings.DESKTOP_MODE else 'true'
56+
'share-buttons': 'false' if settings.DESKTOP_MODE else 'true',
57+
'model-type': request.GET.get('t', 'cloud'),
5758
}.items()
5859
})
5960

0 commit comments

Comments
 (0)