Class Link3D


public class Link3D extends Mesh
Renderer for thick 3D links. Each link segment is expanded into a small open prism in world coordinates, which gives links a proper depth relationship to spheres and to other links while keeping the appearance unlit and simple.
Author:
Christoph Hauert
  • Field Details

    • VERTICES_PER_FACE

      private static final int VERTICES_PER_FACE
      Number of triangle vertices used per rectangular side face.
      See Also:
    • MIN_AXIS_LENGTH2

      private static final double MIN_AXIS_LENGTH2
      Smallest admissible squared link length.
      See Also:
    • HELPER_AXIS_Z_THRESHOLD

      private static final double HELPER_AXIS_Z_THRESHOLD
      Threshold used when choosing a helper axis for constructing the prism basis.
      See Also:
    • DEFAULT_COLOR

      private static final Color DEFAULT_COLOR
      Fallback color used when link geometry does not provide vertex colors.
    • positionAttribute

      private BufferAttribute positionAttribute
      Vertex positions required by the renderer.
    • colorAttribute

      private BufferAttribute colorAttribute
      Per-vertex colors used to support directional gradients.
    • shaderMaterial

      private final ShaderMaterial shaderMaterial
      Material wrapping the custom shader.
    • axis

      private final Vector3 axis
      Temporary storage for the link axis.
    • axisHelper

      private final Vector3 axisHelper
      Temporary helper axis used to construct an orthonormal basis around the link axis.
    • radialU

      private final Vector3 radialU
      Temporary first basis vector spanning the prism cross-section.
    • radialV

      private final Vector3 radialV
      Temporary second basis vector spanning the prism cross-section.
    • linkCount

      private int linkCount
      Number of link segments stored in the current geometry.
    • geometryLinkCount

      private int geometryLinkCount
      Number of link segments the current buffers were allocated for.
    • lineWidth

      private double lineWidth
      Current link width in world coordinates.
    • linkGeometry

      private Geometry linkGeometry
      Source line geometry used to rebuild thick-link prisms after width changes.
    • linkFallbackColor

      private Color linkFallbackColor
      Fallback color used when rebuilding links without explicit vertex colors.
  • Constructor Details

    • Link3D

      public Link3D()
      Create an empty 3D link mesh.
  • Method Details

    • setLinks

      public void setLinks(Geometry lineGeometry)
      Update the links rendered by this mesh.
      Parameters:
      lineGeometry - the geometry containing link endpoints and optional colors
    • setLinks

      public void setLinks(Geometry lineGeometry, Color fallbackColor)
      Update the links rendered by this mesh.
      Parameters:
      lineGeometry - the geometry containing link endpoints and optional colors
      fallbackColor - the color to use when vertex colors are absent
    • clear

      public void clear()
      Hide all links from this mesh while keeping the allocated buffers intact.
    • setLineWidth

      public void setLineWidth(double lineWidth)
      Set the thickness of the rendered links in world coordinates.
      Parameters:
      lineWidth - the desired link width
    • rebuildLinks

      private void rebuildLinks()
      Rebuild the prism geometry from the cached source lines and current width.
    • createGeometry

      private void createGeometry(int links)
      Allocate or resize the buffer geometry used for the current link count while keeping the mesh and geometry instances stable.
      Parameters:
      links - the number of link segments
    • ensureGeometry

      private void ensureGeometry(int links)
      Ensure that the backing geometry has capacity for the requested link count.
      Parameters:
      links - the number of link segments to render
    • invalidateGpuBuffers

      private void invalidateGpuBuffers()
      Force the renderer to upload fresh GPU buffers for the current attributes. Parallax caches WebGL buffers behind each attribute, so dynamic link updates must invalidate those handles explicitly.
    • createAttribute

      private BufferAttribute createAttribute(int vertices, int itemSize)
      Create a floating-point buffer attribute.
      Parameters:
      vertices - the number of vertices
      itemSize - the number of components per vertex
      Returns:
      the new attribute
    • writeLink

      private void writeLink(int vertexOffset, Vector3 start, Vector3 end, Color startColor, Color endColor)
      Write one thick-link prism into the underlying buffers.
      Parameters:
      vertexOffset - the first vertex index of the segment
      start - the segment start position
      end - the segment end position
      startColor - the color at the start point
      endColor - the color at the end point
    • writeFace

      private int writeFace(int vertexOffset, Vector3 start, Vector3 end, Color startColor, Color endColor, double uA, double vA, double uB, double vB)
      Write one rectangular side face of the link prism.
      Parameters:
      vertexOffset - the first vertex index of the face
      start - the segment start position
      end - the segment end position
      startColor - the color at the start point
      endColor - the color at the end point
      uA - the first corner coefficient along radialU
      vA - the first corner coefficient along radialV
      uB - the second corner coefficient along radialU
      vB - the second corner coefficient along radialV
      Returns:
      the next free vertex index
    • writeVertex

      private void writeVertex(int index, double x, double y, double z, Color color)
      Write one triangle vertex to the underlying buffers.
      Parameters:
      index - the vertex index
      x - the x-coordinate
      y - the y-coordinate
      z - the z-coordinate
      color - the vertex color
    • getVertexColor

      private Color getVertexColor(List<Color> colors, int index, Color fallbackColor)
      Resolve the color for one line vertex.
      Parameters:
      colors - the optional color array
      index - the vertex index
      fallbackColor - the color to use when no explicit value exists
      Returns:
      the selected color
    • markGeometryDirty

      private void markGeometryDirty()
      Mark all geometry buffers as dirty after an update.