Class Mesh

All Implemented Interfaces:
Pickable, Hintable, Renderable, Savable
Direct Known Subclasses:
BMText, BMTextBackground, Box, Capsule, ClipmapLevel, Cylinder, Disk, Dodecahedron, Dome, DrawableCamera, Extrusion, GeoSphere, Hexagon, Icosahedron, InteractRing, Line, Octahedron, OrientedBox, Point, PQTorus, ProjectedGrid, Pyramid, Quad, QuadBox, QuadQuad, RoundedBox, SkinnedMesh, SkyDome, Sphere, StripBox, Teapot, TextMesh, Torus, TrailMesh, Tube, UIArc, UIDisk, UIQuad

public class Mesh extends Spatial implements Renderable, Pickable
A Mesh is a spatial describing a renderable geometric object. Data about the mesh is stored locally using MeshData.
  • Field Details

    • RENDER_VERTEX_ONLY

      public static boolean RENDER_VERTEX_ONLY
    • _meshData

      protected MeshData _meshData
      Actual buffer representation of the mesh
    • _modelBound

      protected BoundingVolume _modelBound
      Local model bounding volume
    • _states

      protected final EnumMap<RenderState.StateType,RenderState> _states
      The compiled list of renderstates for this mesh, taking into account ancestors states - updated with updateRenderStates()
    • _lightState

      protected transient LightState _lightState
      The compiled lightState for this mesh
    • _defaultColor

      protected ColorRGBA _defaultColor
      Default color to use when no per vertex colors are set
    • _isVisible

      protected boolean _isVisible
      Visibility setting that can be used after the scenegraph hierarchical culling
  • Constructor Details

    • Mesh

      public Mesh()
      Constructs a new Mesh.
    • Mesh

      public Mesh(String name)
      Constructs a new Mesh with a given name.
      Parameters:
      name - the name of the mesh. This is required for identification purposes.
  • Method Details

    • getMeshData

      public MeshData getMeshData()
      Retrieves the mesh data object used by this mesh.
      Returns:
      the mesh data object
    • setMeshData

      public void setMeshData(MeshData meshData)
      Sets the mesh data object for this mesh.
      Parameters:
      meshData - the mesh data object
    • getModelBound

      public BoundingVolume getModelBound()
      Retrieves the local bounding volume for this mesh.
      Returns:
      the local bounding volume for this mesh
    • getModelBound

      public BoundingVolume getModelBound(BoundingVolume store)
      Retrieves a copy of the local bounding volume for this mesh.
      Parameters:
      store - the bounding volume
      Returns:
      a copy of the local bounding volume for this mesh
    • setModelBound

      public void setModelBound(BoundingVolume modelBound)
      Sets the local bounding volume for this mesh to the given bounds, updated to fit the vertices of this Mesh. Marks the spatial as having dirty world bounds.
      Parameters:
      modelBound - the bounding volume - only type is used, actual values are replaced.
    • setModelBound

      public void setModelBound(BoundingVolume modelBound, boolean autoCompute)
      Sets the local bounding volume for this mesh to the given bounding volume. If autoCompute is true (default, if not given) then we will modify the given modelBound to fit the current vertices of this mesh. This will also mark the spatial as having dirty world bounds.
      Parameters:
      modelBound - the bounding volume
      autoCompute - if true, update the given modelBound to fit the vertices of this Mesh.
    • updateModelBound

      public void updateModelBound()
      Recalculate the local bounding volume of this Mesh to fit its vertices.
    • updateWorldBound

      public void updateWorldBound(boolean recurse)
      Description copied from class: Spatial
      updates the bounding volume of the world. Abstract, geometry transforms the bound while node merges the children's bound. In most cases, users will want to call updateModelBound() and let this function be called automatically during updateGeometricState().
      Specified by:
      updateWorldBound in class Spatial
      Parameters:
      recurse - true to recurse down the scenegraph tree
    • getWorldVectors

      public FloatBuffer getWorldVectors(FloatBuffer store)
      translates/rotates and scales the vectors of this Mesh to world coordinates based on its world settings. The results are stored in the given FloatBuffer. If given FloatBuffer is null, one is created.
      Parameters:
      store - the FloatBuffer to store the results in, or null if you want one created.
      Returns:
      store or new FloatBuffer if store == null.
    • getWorldNormals

      public FloatBuffer getWorldNormals(FloatBuffer store)
      rotates the normals of this Mesh to world normals based on its world settings. The results are stored in the given FloatBuffer. If given FloatBuffer is null, one is created.
      Parameters:
      store - the FloatBuffer to store the results in, or null if you want one created.
      Returns:
      store or new FloatBuffer if store == null.
    • render

      public void render(Renderer renderer)
      Description copied from interface: Renderable
      Render the object using the supplied renderer instance.
      Specified by:
      render in interface Renderable
      Parameters:
      renderer - the renderer
    • render

      public void render(Renderer renderer, MeshData meshData)
    • renderArrays

      protected void renderArrays(Renderer renderer, MeshData meshData, int primcount, ContextCapabilities caps)
    • renderVBO

      protected void renderVBO(Renderer renderer, MeshData meshData, int primcount)
    • applyWorldRenderStates

      protected void applyWorldRenderStates(boolean recurse, RenderState.StateStack stack)
      Description copied from class: Spatial
      The method actually implements how the render states are applied to this spatial and (if recurse is true) any children it may have. By default, this function does nothing.
      Overrides:
      applyWorldRenderStates in class Spatial
      Parameters:
      recurse - true to recurse down the scenegraph tree
      stack - The stack for each state
    • isVisible

      public boolean isVisible()
    • setVisible

      public void setVisible(boolean isVisible)
    • draw

      public void draw(Renderer r)
      Description copied from class: Spatial
      draw abstract method that handles drawing data to the renderer if it is geometry and passing the call to it's children if it is a node.
      Specified by:
      draw in class Spatial
      Parameters:
      r - the renderer used for display.
    • sortLights

      public void sortLights()
      Sorts the lights based on distance to mesh bounding volume
      Overrides:
      sortLights in class Spatial
    • getLightState

      public LightState getLightState()
    • setLightState

      public void setLightState(LightState lightState)
    • setDefaultColor

      public void setDefaultColor(ReadOnlyColorRGBA color)
      setDefaultColor sets the color to be used if no per vertex color buffer is set.
      Parameters:
      color - the default color to set
    • setDefaultColor

      public void setDefaultColor(float r, float g, float b, float a)
      setDefaultColor sets the color to be used if no per vertex color buffer is set.
      Parameters:
      r - the red component of the default color to set
      g - the green component of the default color to set
      b - the blue component of the default color to set
      a - the alpha component of the default color to set
    • getDefaultColor

      public ReadOnlyColorRGBA getDefaultColor()
      Returns:
      the default color
    • getWorldRenderState

      public RenderState getWorldRenderState(RenderState.StateType type)
      Parameters:
      type - StateType of RenderState we want to grab
      Returns:
      the compiled RenderState for this Mesh, either from RenderStates applied locally or those inherited from this Mesh's ancestors. May be null if a state of the given type was never applied in either place.
    • setSolidColor

      public void setSolidColor(ReadOnlyColorRGBA color)
      setSolidColor sets the color array of this geometry to a single color. For greater efficiency, try setting the the ColorBuffer to null and using DefaultColor instead.
      Parameters:
      color - the color to set.
    • setRandomColors

      public void setRandomColors()
      Sets every color of this geometry's color array to a random color.
    • supportsBoundsIntersectionRecord

      public boolean supportsBoundsIntersectionRecord()
      Specified by:
      supportsBoundsIntersectionRecord in interface Pickable
      Returns:
      true if this pickable supports intersectsWorldBoundsWhere. False if this method will always return null.
    • supportsPrimitivesIntersectionRecord

      public boolean supportsPrimitivesIntersectionRecord()
      Specified by:
      supportsPrimitivesIntersectionRecord in interface Pickable
      Returns:
      true if this pickable supports intersectsPrimitivesWhere. False if this method will always return null.
    • intersectsWorldBound

      public boolean intersectsWorldBound(Ray3 ray)
      Specified by:
      intersectsWorldBound in interface Pickable
      Parameters:
      ray - a ray, in world coordinates.
      Returns:
      true if the given ray intersects our world bounding volume. false if it does not.
    • intersectsWorldBoundsWhere

      public IntersectionRecord intersectsWorldBoundsWhere(Ray3 ray)
      Specified by:
      intersectsWorldBoundsWhere in interface Pickable
      Parameters:
      ray - a ray, in world coordinates.
      Returns:
      an intersection record containing information about where the ray intersected our bounding volume, or null if it does not.
    • intersectsPrimitivesWhere

      public IntersectionRecord intersectsPrimitivesWhere(Ray3 ray)
      Specified by:
      intersectsPrimitivesWhere in interface Pickable
      Parameters:
      ray - a ray, in world coordinates.
      Returns:
      an intersection record containing information about where the ray intersected our primitives, or null if it does not.
    • makeCopy

      public Mesh makeCopy(boolean shareGeometricData)
      Description copied from class: Spatial
      Create a copy of this spatial.
      Overrides:
      makeCopy in class Spatial
      Parameters:
      shareGeometricData - if true, reuse any data fields describing the geometric shape of the spatial, as applicable.
      Returns:
      the copy as described.
    • makeInstanced

      public Mesh makeInstanced()
      Description copied from class: Spatial
      Creates and returns a new instance of this spatial. Used for instanced rendering. All instances visible on the screen will be drawn in one draw call. The new instance will share all data (meshData and renderStates) with the current mesh and all other instances created from this spatial.
      Overrides:
      makeInstanced in class Spatial
      Returns:
      an instanced copy of this node
    • reorderIndices

      public void reorderIndices(IndexBufferData<?> newIndices, IndexMode[] modes, int[] lengths)
      Let this mesh know we want to change its indices to the provided new order. Override this to provide extra functionality for sub types as needed.
      Parameters:
      newIndices - the IntBufferData to switch to.
      modes - the new segment modes to use.
      lengths - the new lengths to use.
    • reorderVertexData

      public void reorderVertexData(int[] newVertexOrder)
      Swap around the order of the vertex data in this Mesh. This is usually called by a tool that has attempted to determine a more optimal order for vertex data.
      Parameters:
      newVertexOrder - a mapping to the desired new order, where the current location of a vertex is the index into this array and the value at that location in the array is the new location to store the vertex data.
    • reorderVertexData

      protected void reorderVertexData(int[] newVertexOrder, MeshData meshData)
      Swap around the order of the vertex data in the given MeshData. Override to provide specific behavior to the Mesh object.
      Parameters:
      newVertexOrder - a mapping to the desired new order, where the current location of a vertex is the index into this array and the value at that location in the array is the new location to store the vertex data.
      meshData - the meshData object to work against.
    • getClassTag

      public Class<? extends Mesh> getClassTag()
      Specified by:
      getClassTag in interface Savable
      Overrides:
      getClassTag in class Spatial
      See Also:
    • write

      public void write(OutputCapsule capsule) throws IOException
      Specified by:
      write in interface Savable
      Overrides:
      write in class Spatial
      Parameters:
      capsule - the capsule
      Throws:
      IOException - Signals that an I/O exception has occurred.
      See Also:
    • read

      public void read(InputCapsule capsule) throws IOException
      Specified by:
      read in interface Savable
      Overrides:
      read in class Spatial
      Parameters:
      capsule - the input capsule
      Throws:
      IOException - Signals that an I/O exception has occurred.
      See Also: