Class ScyllaCylinderShape
Parametric cylinder shape with configurable radius, height, segment count, and optional top and bottom caps, centered on the origin with its axis aligned to Y. Replaces Unity's built-in cylinder primitive with a true parametric mesh.
Inherited Members
Namespace: Scylla.Core.Util.Geom
Assembly: ScyllaCore.dll
Syntax
[AddComponentMenu("Scylla/Geometry/Cylinder")]
public sealed class ScyllaCylinderShape : ScyllaShapeBase3D
Remarks
Side wall normals are radial and smooth around the circumference, making the
cylinder appear round under lighting at any segment count. Cap normals are flat
(uniform +Y for the top cap, -Y for the bottom cap). Because the
cap vertices are separate from the side wall vertices, the top and bottom edges of
the cylinder are hard-shaded.
Segment count is clamped to [3, 256]. With caps enabled, vertex count is
(segments + 1) * 2 + (segments + 1) * 2 and triangle index count is
segments * 12. Without caps, vertex count is (segments + 1) * 2
and index count is segments * 6.
Per-vertex coloring (see FaceColoringMode) uses per-vertex dispatch: the resolver is called once per vertex with the vertex index and local position. This yields smooth spatial gradients under GradientByY and per-vertex speckle under Cycle or Hash.
Unity does not ship a native cylinder collider primitive. When ColliderMode is set to MatchingPrimitive, the shape falls back to a UnityEngine.MeshCollider rather than attaching a capsule (which would alter the collision shape).
The static Build(Mesh, float, float, int, bool, IFaceColorResolver) method can be called directly to populate any UnityEngine.Mesh without attaching a component, which is useful for procedural mesh pipelines.
Properties
Capped
When true, top and bottom cap discs are included in the mesh. When
false, only the open side wall is emitted. Setting this property triggers an
immediate mesh rebuild via Rebuild().
Declaration
public bool Capped { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Height
Cylinder height along the Y axis in local units. Values below 0.0001 are
clamped when set and at build time. Setting this property triggers an immediate mesh
rebuild via Rebuild().
Declaration
public float Height { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Radius
Cylinder radius in local units. Values below 0.0001 are clamped when set and
at build time. Setting this property triggers an immediate mesh rebuild via Rebuild().
Declaration
public float Radius { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Segments
Number of circumferential subdivisions. Clamped to [3, 256] when set and at build time.
Setting this property triggers an immediate mesh rebuild via
Rebuild().
Declaration
public int Segments { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
Build(Mesh, float, float, int, bool, IFaceColorResolver)
Populates target with a parametric cylinder mesh. Existing mesh
data is overwritten. Segment count is clamped to [3, 256].
Declaration
public static void Build(Mesh target, float radius, float height, int segments, bool capped, IFaceColorResolver resolver = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Mesh | target | Destination mesh. Must be non-null. |
| float | radius | Cylinder radius in local units. Determines the outer surface distance from the Y axis.
Clamped to a minimum of |
| float | height | Cylinder height along the Y axis in local units. The top rim is at
|
| int | segments | Circumferential subdivisions around the cylinder. Clamped to |
| bool | capped | When |
| IFaceColorResolver | resolver | Optional per-vertex color resolver. Uses per-vertex dispatch: when non-null, a
per-vertex color channel is emitted where the resolver is called once per vertex
with the vertex index and local position. Yields smooth gradients under
GradientByY and per-vertex speckle under
Cycle or Hash.
When |
BuildMesh(Mesh)
Subclass extension point: write vertex / triangle / normal / uv data into
target from the shape's serialized parameters. The base class
calls Clear(bool) before invoking this method and
UnityEngine.Mesh.RecalculateBounds() afterwards, so subclasses should not invoke
either themselves.
Declaration
protected override void BuildMesh(Mesh target)
Parameters
| Type | Name | Description |
|---|---|---|
| Mesh | target | The owned mesh to populate. Already cleared by the base class. |
Overrides
GetMeshName()
Returns the shape's mesh name as it should appear on the generated mesh asset. Defaults to the subclass type name; override to provide a friendlier label.
Declaration
protected override string GetMeshName()
Returns
| Type | Description |
|---|---|
| string | A short identifier for the generated mesh, used as UnityEngine.Object.name. |
Overrides
TryAttachPrimitiveCollider()
Subclass extension point: when ColliderMode is
MatchingPrimitive, obtain the appropriate primitive
collider through GetOrAddManagedCollider<T>(), size it to the current
parameters, and return true. Return false to let the base class fall
back to UnityEngine.MeshCollider.
Declaration
protected override bool TryAttachPrimitiveCollider()
Returns
| Type | Description |
|---|---|
| bool |
|
Overrides
Remarks
Runs on every rebuild. Always go through GetOrAddManagedCollider<T>()
rather than AddComponent: it reuses the collider from the previous rebuild,
so the override only has to update its size and center. A collider added directly
is not tracked by the shape and a new one would be added on every rebuild.