Overview
The 3D LEGO Builder Simulator provides a highly analytical virtual laboratory designed to examine, reconstruct, and dynamically simulate interlocking modular structures inside a browser workspace. Combining advanced physics-driven spatial kinematics with real-time rigid-body solvers, this application bridges the division between digital coordinate design environments and physical mass structures. The computational solver models real-world static loading, sliding frictions, kinetic energy transfers, and mechanical constraint locks directly on modular architectural elements.
Under ordinary operational parameters, individual blocks act as dynamic entities governed by Newtonian laws of motion. Using explicit representations of translational and rotational inertia tensors, the simulation accurately represents kinetic behaviors. This makes it an ideal platform for exploring structural load distribution, centroid stabilization, collapse thresholds, and material structural engineering. The interactive interface allows blocks of diverse volumetric densities, scaling metrics, and centroid distributions to be introduced and linked.
To understand the computational framework of the physics engine, let the general position vector of a modular rigid body $i$ be given by the generalized state vector $\mathbf{q}_i = [\mathbf{x}_i^T, \boldsymbol{\theta}_i^T]^T$, where $\mathbf{x}_i = [x, y, z]^T \in \mathbb{R}^3$ represents the spatial translational coordinate and $\boldsymbol{\theta}_i$ represents rotational quaternions representing spatial orientations in $SO(3)$. The system steps forward dynamically using discretized Euler equations, continually evaluating spatial contact manifolds to determine stability, normal reactions, and friction forces.
How to Use
Navigating this virtual mechanics sandbox relies on standard user interface triggers, spatial projection vectors, and structural commands:
- Accretion Configuration: Utilize the element configuration dropdown in the control panel to define the dimensional scaling matrix of the modular unit. Select a specific volumetric footprint, such as standard cubes, elongated panels, or tall columns.
- Chromatic Mapping: Alter the color picker vector to apply localized light absorption properties to newly accreted bodies. This assigns a specific material appearance vector to the elements.
- Dynamic Generation: Trigger the "Accrete Element" button to spawn the selected modular unit at a localized altitude above the simulation origin. Newtonian gravity immediately initiates down-axis translation.
- Interactive Dynamic Manipulation: Click or touch directly on any block to convert its state from a dynamic simulation body to a kinematic controller. Dragging the pointer creates a projection vector parallel to the camera view plane. Dragged blocks can be used to push or clear other blocks within the viewport.
- Vector Matrix Rotations: With an active element selected, execute horizontal rotational transformations via the "Yaw Left 90°" and "Yaw Right 90°" commands. This modifies the orientation quaternion matrix by applying discrete orthogonal rotation steps around the global vertical axis.
- The Chemical Welding System: Enable the "Locking Welds" mode before dropping blocks onto each other. When active, any collision between dynamic blocks automatically initiates constraint formation, permanently welding their spatial transforms to prevent collapse.
- Resetting and Baseline Alignment: At any point, clicking the "Reset Baseline" button immediately empties the constraint and object lists, returning the scene state to a blank workspace.
Technical Details
The structural architecture of this simulator combines WebGL-based mesh rendering via the Three.js framework with rigid-body mechanics computed by the CANNON-es physics engine. The canvas container is designed with decoupled, relative boundary dimensions to prevent layout calculation loops while scaling. When the renderer initializes, it queries the layout dimensions and configures back-buffer scale properties using standard device pixel ratios:
$$DPR = \text{window.devicePixelRatio}$$
This scaling ensures high visual definition across diverse display types. Kinematic coordinate mapping translates standard pointer screen-space parameters into 3D world coordinates. The cursor coordinate vector $\mathbf{p} = [x_s, y_s]^T$ is converted to a normalized raycasting origin and direction vector:
$$\mathbf{R}(t) = \mathbf{O} + t \mathbf{D}$$
The dragging mechanic projects an invisible mathematical plane perpendicular to the camera look-vector. The intersection point is computed dynamically by solving:
$$\mathbf{n} \cdot (\mathbf{R}(t) - \mathbf{P}_0) = 0$$
where $\mathbf{n}$ is the normal vector of the projection plane and $\mathbf{P}_0$ is the current position of the active block.
The welding/locking system uses rigid distance constraints to bond collided meshes together. In the physics core, a lock constraint is represented as an overdetermined system of algebraic equations restricting relative translation and rotation between body $A$ and body $B$. The constraint equations are evaluated in a Gauss-Seidel solver, which modifies impulses iteratively to enforce zero relative velocity at structural boundaries:
$$\mathbf{J} \mathbf{v} = 0$$
where $\mathbf{J}$ is the constraint Jacobian matrix and $\mathbf{v}$ represents the combined linear and angular velocity vectors of the connected rigid-body pair. Under constant external gravity load $\mathbf{f}_{\text{ext}}$, the dynamic integration system resolves contact state changes across successive discrete time windows $\Delta t$:
$$M \mathbf{v}^{n+1} = M \mathbf{v}^n + \Delta t \mathbf{f}_{\text{ext}} + \mathbf{J}^T \boldsymbol{\lambda}$$
$$\mathbf{J} \mathbf{v}^{n+1} + \boldsymbol{\beta} \mathbf{C} = 0$$
where $M$ represents the system generalized mass matrix, $\boldsymbol{\lambda}$ represents structural constraint impulses, $\mathbf{C}$ is the boundary constraint violation vector, and $\boldsymbol{\beta}$ is the Baumgarte stabilization factor designed to offset numerical drift.
Future Directions
Planned enhancements focus on introducing modular attachment grids, structural stress analysis, and structural saving modules:
- Coordinate Lattice Clamping (Snap-to-Grid): Real-time clamping of spatial kinematic trajectories to a discrete mathematical lattice $\mathbb{Z}^3$. While dragging, translation vectors will snap to increments of:
$$x_{\text{snapped}} = \text{round}\left(\frac{x}{\Delta}\right) \cdot \Delta$$
enabling the structural layout to align systematically without structural overlaps.
- Local Storage State Preservation: A client-side saving mechanism using browser local storage APIs. This module will serialize active coordinate arrays, rotational quaternions, chromatic values, and lock-constraint lists into lightweight JSON schemas, allowing users to preserve and resume layout configurations across browser sessions.
- Volumetric Stress and Deflection Maps: Real-time color mapping representing structural load and stress distribution. Using simple finite element approximations, the simulator will dynamically recolor elements based on gravity load transfer vectors, shifting from cool hues to high-stress warm indicators to show structural weaknesses.