Class ScyllaCapsuleShape
Parametric capsule shape: a cylindrical body capped by two hemispherical domes, centered on the origin with its axis aligned to Y. Replaces Unity's built-in capsule primitive with a parametric shape whose radius, total height, and tessellation can be retuned in the Inspector or at runtime.
Inherited Members
Namespace: Scylla.Core.Util.Geom
Assembly: ScyllaCore.dll
Syntax
[AddComponentMenu("Scylla/Geometry/Capsule")]
public sealed class ScyllaCapsuleShape : ScyllaShapeBase3D
Remarks
The total height is interpreted as the full extent including both caps. The cylindrical
section has height max(0, Height - 2 * Radius). When Height is
less than or equal to twice Radius, the cylinder section collapses to
zero and the shape degenerates to a sphere.
The mesh is constructed as (2 * CapRings + 1) latitudinal stacks, each with
(Segments + 1) vertices. The upper hemisphere contributes CapRings
stacks (north pole down to the upper equator at y = +cylinderHalf), and the
lower hemisphere contributes CapRings stacks (lower equator at
y = -cylinderHalf down to the south pole). The equatorial seam ring at the
cap-cylinder junction produces the cylinder body band. Normals are radially outward
from the capsule axis, giving smooth shading.
Segments is clamped to [3, 256]; CapRings is
clamped to [2, 64] at build time.
Per-face coloring uses per-vertex dispatch: Resolve(int, int, Vector3) is called once per vertex (passing the vertex index as the face index) rather than once per logical triangle region. Under GradientByY this produces a smooth gradient from the south pole to the north pole; under Cycle or Hash it produces per-vertex color variation. See IFaceColorResolver for the full dispatch contract.
Properties
CapRings
Number of latitudinal rings per hemispherical cap. Higher values reduce faceting near
the poles. The value is clamped to [2, 64] at build time. Setting this property
triggers an immediate mesh rebuild via Rebuild().
Declaration
public int CapRings { get; set; }
Property Value
| Type | Description |
|---|---|
| int | Latitudinal ring count per cap hemisphere. Default is |
Height
Total height of the capsule including both caps in local units. When this value is less
than or equal to 2 * Radius, the cylinder section collapses to zero and the shape
becomes spherical. Setting this property triggers an immediate mesh rebuild via
Rebuild().
Declaration
public float Height { get; set; }
Property Value
| Type | Description |
|---|---|
| float | Total capsule height including both hemispherical caps. Default is |
Radius
Radius of the capsule body and of each hemispherical cap in local units. Must be positive. Setting this property triggers an immediate mesh rebuild via Rebuild().
Declaration
public float Radius { get; set; }
Property Value
| Type | Description |
|---|---|
| float | The capsule radius. Default is |
Segments
Number of circumferential subdivisions around the Y axis. The value is clamped to
[3, 256] at build time. Setting this property triggers an immediate mesh rebuild
via Rebuild().
Declaration
public int Segments { get; set; }
Property Value
| Type | Description |
|---|---|
| int | Circumferential segment count. Default is |
Methods
Build(Mesh, float, float, int, int, IFaceColorResolver)
Populates target with a parametric capsule mesh. Existing mesh
data is overwritten.
Declaration
public static void Build(Mesh target, float radius, float height, int segments, int capRings, IFaceColorResolver resolver = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Mesh | target | Destination mesh. Must be non-null. |
| float | radius | Capsule radius in local units. Also the radius of each hemispherical cap. |
| float | height | Total capsule height in local units, including both caps. Values less than
|
| int | segments | Circumferential subdivisions around the Y axis. Clamped to |
| int | capRings | Latitudinal subdivisions per hemispherical cap. Clamped to |
| IFaceColorResolver | resolver | Optional per-vertex color resolver. Uses per-vertex dispatch: called once per
vertex with the vertex index as the face index and the vertex's local position as the
face center. Under GradientByY this produces a smooth
gradient from the south pole to the north pole; under Cycle
or Hash it produces per-vertex color variation. Pass
|
Remarks
This static method is the pure mesh-data entry point and may be called without a ScyllaCapsuleShape component - for example, to bake a capsule mesh into a procedural asset at editor time. The component's Rebuild() delegates to this method automatically.
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, attach the appropriate
primitive collider for this shape and return true. Return false to
let the base class fall back to UnityEngine.MeshCollider.
Declaration
protected override bool TryAttachPrimitiveCollider()
Returns
| Type | Description |
|---|---|
| bool |
|