Skip to main content

Overview

The Cuboid class creates 3D rectangular box shapes (also known as rectangular prisms or boxes). Cuboids are defined by their center point and dimensions along the X, Y, and Z axes.

Constructor

ICuboidOptions

ogid
string
Unique identifier for the cuboid. Auto-generated if not provided.
center
Vector3
required
Center point of the cuboid in 3D space.
width
number
required
Width of the cuboid along the X-axis.
height
number
required
Height of the cuboid along the Y-axis.
depth
number
required
Depth of the cuboid along the Z-axis.
color
number
required
Hexadecimal color value for the cuboid.

Methods

setConfig()

Updates the cuboid configuration and regenerates geometry.
Example:

getBrepData()

Returns the B-Rep (Boundary Representation) data as a parsed JSON object.
Example:

generateGeometry()

Regenerates the THREE.js geometry from the current configuration. Called automatically after setConfig().

discardGeometry()

Disposes of the current geometry to free memory.

Properties

ogid
string
Unique identifier for the cuboid instance.
options
ICuboidOptions
Current cuboid configuration.
width
number
Get or set the cuboid width. Setting triggers geometry regeneration.
color
number
Get or set the cuboid color.
outline
boolean
Enable or disable outline rendering for the cuboid edges.
outlineMesh
THREE.Line | null
Reference to the outline mesh if outline is enabled.

Usage Examples

Basic Cuboid

Cuboid with Outline

Cube (Equal Dimensions)

Dynamic Cuboid Scaling

Building Block

Implementation Details

Geometry Generation

Cuboids are created by defining a rectangular base on the XZ plane and extruding it along the Y-axis using the extrude_brep_face operation. Rust Implementation: /workspace/source/main/opengeometry/src/primitives/cuboid.rs:80-129

Material Configuration

Cuboids use MeshStandardMaterial with transparency: Source: /workspace/source/main/opengeometry/src/shapes/cuboid.ts:100-104

B-Rep Structure

Cuboids have a well-defined B-Rep structure:
  • 8 vertices (corners)
  • 12 edges (connecting corners)
  • 6 faces (sides)
Source: /workspace/source/main/opengeometry/src/primitives/cuboid.rs:86-128

Best Practices

Center-Based Positioning: Cuboids are positioned by their center point, making rotation and scaling operations more intuitive.
Non-Zero Dimensions: All dimensions (width, height, depth) should be greater than zero. Zero or negative values may cause rendering issues.
Memory Management: Use discardGeometry() when removing cuboids from the scene to properly free GPU memory.

Live Demo

Cuboid Demo

Try the Cuboid shape in the browser

See Also

Wedge

Triangular prism shapes

Cylinder

Cylindrical shapes

Polygon

2D base shapes
Last modified on March 14, 2026