Class MeshViewerPanel

All Implemented Interfaces:
ImageObserver, KeyEventDispatcher, MenuContainer, Serializable, Accessible, VerbosePrint

public class MeshViewerPanel extends JPanel implements VerbosePrint, KeyEventDispatcher

Displays a rendered mesh in 3D and provides mouse and keyboard controls for moving the camera. Each shape in the mesh can be assigned a single color. By default this colorization will be based on the normal angle, but the user can provide custom colors. Two styles of control are provided by default orbit and first person, again the user can provide others easily.

To ensure smooth updates a double buffer is used and rendering is done in a separate thread. All rendering is done in software and can't use a GPU. The rendering thread will automatically stop and stop depending on the lifecycle of this panel.

See Also:
  • Field Details

    • COLOR_NORMAL

      public static final String COLOR_NORMAL
      Name given to the default approach that colorizes based on normal angle
      See Also:
    • buttonSize

      public int buttonSize
      How big the help button appears to be
    • helpButtonFont

      public Font helpButtonFont
    • helpButtonActive

      public boolean helpButtonActive
      If the help button exists
  • Constructor Details

    • MeshViewerPanel

      public MeshViewerPanel(VertexMesh mesh)
      Convenience constructor that calls setMesh(VertexMesh, boolean) and the default constructor.
      Parameters:
      mesh - That mesh which is to be viewed. A reference is saved internally.
    • MeshViewerPanel

      public MeshViewerPanel()
      Default constructor. Configures the GUI and adds in default controls and colorizations.
  • Method Details

    • setActiveControl

      public void setActiveControl(String name)
      Changes the active camera control
    • removeNotify

      public void removeNotify()
      Perform clean up when this component is no longer being used
      Overrides:
      removeNotify in class JComponent
    • shutdownRenderThread

      public void shutdownRenderThread()
      Send a request that the rendering thread
    • setMesh

      public void setMesh(VertexMesh mesh, boolean copy)
      Sets the mesh which will be rendered.
      Parameters:
      copy - If true then a copy of the mesh will be made and saved. If false then a reference will be saved. You should create a copy if this mesh is going to be modified.
    • setSurfaceColor

      public void setSurfaceColor(String name, RenderMesh.SurfaceColor colorizer)
      Let's ou specify the RGB color for each vertex in the mesh.
      Parameters:
      name - Name given to this colorization approach
    • setVertexColors

      public void setVertexColors(String name, int[] vertexColors)
      It will colorize each surface using the color of the vertexes
      Parameters:
      name - Name given to this colorization approach
    • requestRender

      public void requestRender()
      Requests that a new image is rendered. Typically this is done when a configuration has changed. It will render when the rendering thread has a chance.
    • setHorizontalFov

      public void setHorizontalFov(double degrees)
      Changes the camera's horizontal field-of-view.
      Parameters:
      degrees - FOV in degrees
    • cycleColorizer

      public void cycleColorizer()
      Each time this is called it will change the colorizer being used, if more than one has been specified
    • paintComponent

      public void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • showHelpWindow

      public void showHelpWindow()
      Opens a window which provides help about keys and let's the user modify control settings
    • setVerbose

      public void setVerbose(@Nullable @Nullable PrintStream out, @Nullable @Nullable Set<String> configuration)
      Specified by:
      setVerbose in interface VerbosePrint
    • setRenderBackgroundColor

      public void setRenderBackgroundColor(int rgba)
      Color of background when rendering
    • getRenderBackgroundColor

      public int getRenderBackgroundColor()
    • dispatchKeyEvent

      public boolean dispatchKeyEvent(KeyEvent e)
      Provides keyboard commands that adjust how and what data is displayed
      Specified by:
      dispatchKeyEvent in interface KeyEventDispatcher