Overview
TheSphere class creates 3D spherical shapes with customizable radius and segment resolution. Spheres are generated using UV parameterization with configurable width and height segments for controlling geometry smoothness.
Constructor
ISphereOptions
string
Unique identifier for the sphere. Auto-generated if not provided.
Vector3
required
Center point of the sphere in 3D space.
number
required
Radius of the sphere.
number
required
Number of horizontal segments (longitude). Higher values create smoother spheres.
number
required
Number of vertical segments (latitude). Higher values create smoother spheres.
number
required
Hexadecimal color value for the sphere.
Methods
setConfig()
Updates the sphere configuration and regenerates geometry.getBrep()
Returns the B-Rep (Boundary Representation) data as a parsed JSON object.generateGeometry()
Regenerates the THREE.js geometry from the current configuration. Called automatically after setConfig().discardGeometry()
Disposes of the current geometry to free memory.Properties
string
Unique identifier for the sphere instance.
ISphereOptions
Current sphere configuration.
number
Get or set the sphere radius. Setting triggers geometry regeneration.
number
Get or set the sphere color.
boolean
Enable or disable outline rendering showing the sphere’s wireframe edges.
THREE.LineSegments | null
Reference to the outline mesh if outline is enabled.
Usage Examples
Basic Sphere
High-Resolution Sphere
Low-Poly Sphere
Animated Sphere
Planet with Outline
Implementation Details
UV Sphere Generation
Spheres are generated using parametric equations with UV coordinates: Rust Implementation:/workspace/source/main/opengeometry/src/primitives/sphere.rs:76-106
Material Configuration
Spheres use MeshStandardMaterial with transparency: Source:/workspace/source/main/opengeometry/src/shapes/sphere.ts:113-117
Outline from B-Rep Edges
Unlike other shapes, sphere outlines are generated from the B-Rep edge data to properly represent the geometry: Source:/workspace/source/main/opengeometry/src/shapes/sphere.ts:150-176
Face Generation
The sphere is composed of triangular faces, with special handling for the poles to avoid degenerate triangles: Source:/workspace/source/main/opengeometry/src/primitives/sphere.rs:111-136
Best Practices
Aspect Ratio: For most realistic spheres, maintain a
widthSegments:heightSegments ratio of approximately 3:2 (e.g., 24:16, 30:20, 48:32).Performance Considerations
Vertex Count
The total number of vertices generated is(widthSegments + 1) × (heightSegments + 1):
- 24×16 segments = 425 vertices
- 32×24 segments = 825 vertices
- 48×32 segments = 1,617 vertices
Face Count
Approximate number of triangular faces:widthSegments × heightSegments × 2
Live Demo
Sphere Demo
Try the Sphere shape in the browser
See Also
Cylinder
Cylindrical shapes
Cuboid
Rectangular boxes
Sweep
Custom revolution shapes

