Surface Lighting in App Designer not Showing Properly

7 views (last 30 days)
I've recently begun to move a MATLAB GUI that I've been working on into App Designer. However, I have gotten to a point where a 3D surface plot (using trisurf) is not coming out as it did in my Guide GUI. I believe it has to do with the lighting property as the image comes up as a 2D blob rather than a 3D object with edges. Here is what it looks like:
knee.JPG
This image is what it looks like in my old Guide GUI:
knee.JPG
Here are the few lines of code that actually plot the image in App Designer:
trisurf(tri, outXYZ(:,1), outXYZ(:,2), outXYZ(:,3),'FaceColor','yellow','EdgeColor','none','FaceAlpha',1, 'FaceLighting', 'gouraud','Parent', app.KneeMask);
view(3)
axis tight;
camlight;
I used to specify the lighting outside of the trisurf call by putting
lighting gouraud
I tried moving it inside of the trisurf call in case it had anything to do with not specifying the axes (which wasn't an issue in Guide GUI), but this didn't help either. I also re-ran the code once and saved the trisurf as a variable in order to observe the lighting property and it was indeed gouraud, so I'm not sure why it's coming out as a blob. Any help with this would be much appreciated. Thank you!

Accepted Answer

Nathan Knodel
Nathan Knodel on 30 May 2019
Alright, I finally ended up figuring this out on my own. The issue was you have to create a light object, and for some reason when I called camlight it didn't work on the axes I was interested in, so the gouraud lighting didn't take effect. I had to experiment to find out how to do all of the proper syntax when specifying the axes, but here's my solution for anyone who may run into this issue when using App Designer:
trisurf(tri, outXYZ(:,1), outXYZ(:,2), outXYZ(:,3),'FaceColor','yellow','EdgeColor',...
'none','FaceAlpha',1, 'Parent', app.KneeMask);
daspect(app.KneeMask, aspect_view);
camlight(app.KneeMask);
lighting gouraud;
view(app.KneeMask,3)
axis(app.KneeMask, 'tight');
  3 Comments
Stuart Scollay
Stuart Scollay on 11 Sep 2020
I can't get this to work.
trisurf(tri,x,y,z, 'Parent', app.UIAxes3);
camlight(app.UIAxes3);
lighting phong;
When lighting is called, it creates a new figure instead of applying it to the GUI "app.UIAxes3" specified in camlight.
Any other tips on how to get it to work?
Matt
Matt on 24 Nov 2020
I also can't get camlight or light within App Designer to work. Using those functions makes the faces of my patch disappear, whereas in a normal figure window, they work just fine.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!