Class ScyllaSphereShape
Parametric UV sphere with configurable radius, longitudinal segments, and latitudinal rings. Replaces Unity's built-in sphere primitive with a true parametric shape that can be retuned in the Inspector or at runtime.
Inherited Members
Namespace: Scylla.Core.Util.Geom
Assembly: ScyllaCore.dll
Syntax
[AddComponentMenu("Scylla/Geometry/Sphere")]
public sealed class ScyllaSphereShape : ScyllaShapeBase3D
Remarks
The sphere is constructed as a standard latitude / longitude grid with
(rings + 1) * (segments + 1) vertices. Normals are equal to the unit
direction from the center, producing smooth shading. UVs map longitude to
u and latitude to v, with v = 1 at the north pole and
v = 0 at the south pole.
Segments and Rings are clamped to
[3, 256] at build time to prevent degenerate or excessively dense meshes.
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 vertical gradient across the entire sphere; under Cycle or Hash it produces per-vertex color variation. See IFaceColorResolver for the full dispatch contract.
For a sphere with near-uniform triangle distribution across its surface (better silhouette quality at low polygon counts), use ScyllaIcoSphereShape instead.
Properties
Radius
Sphere 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 | The radius of the sphere in local space. Default is |
Rings
Number of latitudinal rings (stacks) between the south pole and the north pole.
Increasing this value improves the roundness of the sphere near its poles. The value
is clamped to [3, 256] when set and at build time. Setting this property triggers an
immediate mesh rebuild via Rebuild().
Declaration
public int Rings { get; set; }
Property Value
| Type | Description |
|---|---|
| int | Latitudinal ring count. Default is |
Segments
Number of longitudinal subdivisions (slices) around the Y axis. Increasing this value
improves the roundness of the sphere's silhouette. The value is 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 | Longitudinal slice count. Default is |
Methods
Build(Mesh, float, int, int, IFaceColorResolver)
Populates target with a parametric UV sphere mesh. Existing mesh
data is overwritten. Segment and ring counts are clamped to [3, 256].
Declaration
public static void Build(Mesh target, float radius, int segments, int rings, IFaceColorResolver resolver = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Mesh | target | Destination mesh. Must be non-null. |
| float | radius | Sphere radius in local units. Clamped to a minimum of |
| int | segments | Longitudinal subdivisions (slices) around the Y axis. Clamped to |
| int | rings | Latitudinal rings (stacks) from pole to pole. 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
vertical gradient; 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 ScyllaSphereShape component - for example, to bake a sphere 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, 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.