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

 Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Mayo de 2022

0 votos

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 comentarios

Pelajar UM
Pelajar UM el 30 de Mayo de 2022
Editada: Pelajar UM el 30 de Mayo de 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 el 30 de Mayo de 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.)
Pelajar UM
Pelajar UM el 30 de Mayo de 2022
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 el 30 de Mayo de 2022
Historically those operations were mutually exclusive. I don't know about app designer in that regard.
Pelajar UM
Pelajar UM el 30 de Mayo de 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 el 30 de Mayo de 2022
I do not know with regards to app designer.
Pelajar UM
Pelajar UM el 31 de Mayo de 2022
For anyone else wondering, this works:
ax=app.UIAxes;
ax.Interactions = [rotateInteraction zoomInteraction];
Walter Roberson
Walter Roberson el 31 de Mayo de 2022
Oh, that looks useful!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 30 de Mayo de 2022

Comentada:

el 31 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by