# Voxel-Based Digital Twin Framework for Earthwork Construction
## 4 Implementation of the Proposed System
### Graphical Simulation Environment for Model-Equipment Interaction
#### 4.1.3 Model Integration in Platform
```
Input: voxels, ID, position, metadata Output: voxels with metadata in Unity Function export_voxel_attribute_data0; Open \"voxel_attributes.csv\" for writing Write \"Voxel_ID, x,y,z, volume, material, mass, density, friction, strength, cohesion, resistance\" For each voxel: If voxel is valid:  Voxel_ID = Get voxel unique identifier  x,y,z = Get spatial coordinates of voxel center  volume = Get cubic volume  material = Get material type (user-defined or default)  mass = Get voxel mass  parameters (i..n) = Get voxel parameters value Write \"Voxel_ID, x,y,z, volume, material, mass, parameters value\" to File Function import_voxel_attribute_data0; Open \"voxel_attributes.csv\" for reading For each line in file: \"Voxel_ID, x,y,z, volume, material, mass, parameters value\" = Parse line // Find voxel in Unity project Where voxel = find voxel using Voxel_ID If voxel exists: Set voxel spatial position to (x,y,z) Resize volume based on volume attribute Assign metainformation to each voxel:  Voxel. material = material  Voxel. mass = mass  Voxel. parameters(i..n) = parameters value Close file Return voxel model with metainformation in Unity 3D
```  
**Algorithm 1** Algorithm for Voxel Property Conversion  
``` Input: voxels, ID, position, metadata Output: voxels with metadata in Unity Function export_voxel_attribute_data0; Open \"voxel_attributes.csv\" for writing Write \"Voxel_ID, x,y,z, volume, material, mass, density, friction, strength, cohesion, resistance\" For each voxel: If voxel is valid:  Voxel_ID = Get voxel unique identifier  x,y,z = Get spatial coordinates of voxel center  volume = Get cubic volume  material = Get material type (user-defined or default)  mass = Get voxel mass  parameters (i..n) = Get voxel parameters value Write \"Voxel_ID, x,y,z, volume, material, mass, parameters value\" to File Function import_voxel_attribute_data0; Open \"voxel_attributes.csv\" for reading For each line in file: \"Voxel_ID, x,y,z, volume, material, mass, parameters value\" = Parse line // Find voxel in Unity project Where voxel = find voxel using Voxel_ID If voxel exists: Set voxel spatial position to (x,y,z) Resize volume based on volume attribute Assign metainformation to each voxel:  Voxel. material = material  Voxel. mass = mass  Voxel. parameters(i..n) = parameters value Close file Return voxel model with metainformation in Unity 3D

#### 4.1.4 Modeling Model-Equipment Interaction

The core implementation to enable model-equipment interaction requires models with physical properties assigned, interaction detection capability, and voxel excavation based on the bucket force. With physical properties assigned to each component, Rigidbody and Collider components are also assigned. A Rigidbody enables the earthwork model to avoid deformation under external forces and to react to these forces. For example, the excavator falls under gravity because of its Rigidbody, and the ground Mesh Collider supports equipment navigation around the construction site. Colliders are used to detect collisions between the models during the simulation. The Rigidbody component is configured with a realistic mass value for every voxel derived from the volume and density. In addition, all voxels are assigned colliders that surround the voxel boundary and detect collisions when equipment buckets trigger the buffer zone. The voxels respond to the bucket forces based on their physical properties and Box Collider-based collision detection. When the excavator bucket enters the trigger zone of the voxels, a collision is detected. As the excavator bucket moves inside the voxels, its movement is continuously monitored because it interacts with the voxels to ensure precise alignment with the voxels. The applied force is compared with the physical properties of the voxel. When the applied force exceeds the resistive force, the voxels are excavated and added to the bucket payload. The voxel position is updated based on the movement of the excavator bucket.