I plot a stl file by pressing a button. Then I rotate it around and change the view. And when I click on the button again, the view goes back to the default position.
I don't want it to go back to the deafult. I want it to use the latest view. But this doesn't work and still goes back to the default:
function ButtonPushed(app, event)
X = get(app.UIAxes,"View");
set ( app.UIAxes,"View", X);
data = stlread ("model.stl");
trisurf (data,'Parent', app.UIAxes);
end

 Réponse acceptée

Walter Roberson
Walter Roberson le 30 Mai 2022

0 votes

Try
function ButtonPushed(app, event)
X = app.UIAxes.View;
data = stlread ("model.stl");
trisurf (data,'Parent', app.UIAxes);
drawnow;
app.UIAxes.View = X;
end

8 commentaires

Pelajar UM
Pelajar UM le 30 Mai 2022
Modifié(e) : Pelajar UM le 30 Mai 2022
Thanks a lot. This works but you can see that the view angle is being changed (first it goes to default and then immediately to the new angle). Is there a way to set the view before plotting the stl, so that you cannot see the switching?
Edit: I could do this by removing "drawnow" but somehow then I cannot rotate the model. When I click, it pans instead....
Walter Roberson
Walter Roberson le 30 Mai 2022
You could try moving the drawnow() to below setting the View.
I have been working on a different question having to do with App Designer in which the user was getting strange angles and sizes, and setting the view was not working; the workaround there was to drawnow() before setting view. (I suspect the matter was related to the CameraPosition the user had set.)
Thanks. Moving the drawnow to below setting the View is the same as removing it.
It works but then I cannot rotate the model unless I add:
rotate3d (app.UIAxes, "on");
but in that case the zoom feature is disabled.
Walter Roberson
Walter Roberson le 30 Mai 2022
Historically those operations were mutually exclusive. I don't know about app designer in that regard.
Pelajar UM
Pelajar UM le 30 Mai 2022
I see. Is there a way to combine the click with a key to switch between zoom and rotate?
In a typical 3D/CAD software, you hold down Ctrl or shift and then you can rotate.
Walter Roberson
Walter Roberson le 30 Mai 2022
I do not know with regards to app designer.
For anyone else wondering, this works:
ax=app.UIAxes;
ax.Interactions = [rotateInteraction zoomInteraction];
Walter Roberson
Walter Roberson le 31 Mai 2022
Oh, that looks useful!

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by