TubeRenderer

Procedural modeling of tubes.
Available on the Unity Asset Store.

Examples




Features

Getting started

Put this code in the Awake or Start method of a MonoBehaviour script.

// add a tube //
TubeRenderer tube = gameObject.AddComponent<TubeRenderer>();

// define some points //
tube.points = new Vector3[]{Vector3.zero,new Vector3(5f,5f,0),Vector3.right*20};

// define radiuses //
tube.radiuses = new float[]{ 1f, 3f, 0.5f };

Reference (v.1.8)

Properties

Vector3[] points
Center points for the tube. Forward rotations will be calculated from the point at index 0 and upwards. The array is NOT copied; the tube will keep the reference to the array.

float[] radiuses
Radius values for the tube. Each value corresponds to the point at the same array index. Array length must !t the number of points. If 'radius' has been set then 'radiuses' will be ignored. The array is NOT copied; the tube will keep the reference to the array.

float radius
Radius for the entire tube. If 'radiusses' has been set then 'radius' will be ignored. Default is 0.1.

Color32[] colors
Vertex colors for the tube. Each value corresponds to the point at the same array index. Array length must fit the number of points. The array is NOT copied; the tube will keep the reference to the array.

int edgeCount
Edge resolution. Minimum is 3. Default is 12.

bool calculateTangents
Calculation of tangents. Default is false (to boost performance).

bool invertMesh
Mesh inversion (render the tube inside out). In most cases you should do 'Cull Front' in your shader instead. Default is false.

NormalMode normalMode
How normals are rendered. Default is NormalMode.Smooth.

CapMode caps
Closed or open end points. Default is CapMode.Both.

bool postprocessContinously
Postprocess continously (if AddPostprocess has been called). When true, postprocesses will be called every update. When false, they will only be called when tube properties are changed. Default is true.

Rect uvRect
UV mapping rect for wrapped tube body. Default is Rect(0,0,1,1).

Rect uvRectCap
UV mapping rect for tube caps (if addCaps is true). Default is Rect(0,0,1,1).

bool uvRectCapEndMirrored
Mirrored uv mapping for cap at end point (points[points.Length-1]). Default is false.

float forwardAngleOffset
Rotation offset around the tubes forward direction.

float length
Gets the total length of the tube.

Mesh mesh
Get the tube mesh. Useful for combining multiple tubes into a static mesh. Do not manipulate directly.

bool showMeshGizmos
Draw gizmos for mesh normals and tangents. Default is false.

float meshGizmoLength
Length of mesh gizmos. Default is 0.1.

float showRotationGizmos
Draw gizmos indicating rotation of each point. Default is false.

float rotationGizmoLength
Length of rotation gizmos. Default is 0.1.

Methods

void ForceUpdate()
Force update to generate the tube mesh immediately.

void MarkDynamic()
Shortcut to Mesh.MarkDynamic(). Call this if the tube will be updated often so that Unity can optimise memory use.

void AddPostprocess( Postprocess postprocess )
Add a method to receive and manipulate mesh data before it is applied. Useful for creating distortion effects or complex variations.

void RemovePostprocess( Postprocess postprocess )
Remove a postprocess method that have previously been assigned using the 'AddPostprocess' method.

Quaternion GetRotationAtPoint( int index )
Gets the rotation of a point at index in the tube.

Enums

NormalMode
Defines how normals are rendered. Options are Smooth, Hard and HardEdges.

CapMode
Defines what caps should be rendered. Options are None, Begin, End and Both.

Delegates

void Postprocess( Vector3[] vertices, Vector3[] normals, Vector4[] tangents )
Method for passing mesh data.

Whats new

v 1.8 (Aug 10, 2017)

v 1.7 (Dec 20, 2016)

v 1.6 (Jan 30, 2016)

v.1.5 (Sep 18, 2015)

v.1.4 (Aug 27, 2014)

v.1.3 (Nov 29, 2013)

v.1.2 (Nov 1, 2013)

v.1.1 (Jun 25, 2013)

v 1.0 (May 1, 2012)