# Development of a Virtual Reality-Based System for Simulating Welding Processes
## Appendix K
TurnOnOff(d_Position); } /// Turn on/ Turn off the weld process void TurnOnOff(float d_Position) { if (temp_1_Position == 0) { temp_1_Position = d_Position; } if (d_Position > max_1_Position) { //Turn off if (weldJoint.GetComponent<Collider>().enabled) { weldJoint.GetComponent<Collider>().enabled = false; var emission = objWeldArc.emission;emission.enabled = false; //nightVisionController.ToggleNightVision(false); audioWeld.SetActive(false); } } else { if(d_Position > min_l_Position) { //Turn on if (!weldJoint.GetComponent<Collider>().enabled) { wellJoint.GetComponent<Collider>().enabled = true; var emission = objWeldArc.emission; emission.enabled = true; audioWeld.SetActive(true); // nightVisionController.ToggleNightVision(true); } } } } //Determining the position of the weld arc void CheckForDestination() { Ray ray = new Ray (weldStick.transform.position, weldStick.transform.rotation * Vector3.forward*10); RaycastHit hit; if (Physics.Raycast(ray,out hit)) { Debug.DrawRay(weldStick.transform.position, weldStick.transform.rotation * Vector3.forward* hit.distance, Color.green); posHit = hit.point; objWeldArc.transform.position = posHit; } else { Debug.DrawRay(weldStick.transform.position, weldStick.transform.rotation * Vector3.forward, Color.green); posHit = Vector3.zero; Debug.Log(\"Did not Hit\"); } // bool b = Physics.Raycast(ray, out hit, 1 << 9); } }
```

## Appendix L

Program for drawing the weld joint: using System.Collections.Generic; using UnityEngine; public class Mesh04: MonoBehaviour { public Vector3 GridSize = new Vector3(3, 3, 3); public float SurfaceLevel = 0.5t; public LineRenderer line = null;public Material material = null;

private GridPoint[,,] p = null;

private List<Vector3> vertices = new List<Vector3>();

private List<int> triangles = new List<int>());

private List<Vector2> uv = new List<Vector2>();

private GridCell cell = new GridCell();

private bool bRequestBuild = false;

public bool showGrid = true;

private void Start()

p = new GridPoint[(int) GridSize.x + 1, (int) GridSize.y + 1, (int) GridSize.z + 1];

InitGrid();

private void Update()

if (Input.GetKeyDown(KeyCode.Space) == true)

BuildMesh();

if (bRequestBuild == true)

BuildMesh();

bRequestBuild = false;

private void OnEnable()

GridPoint.OnPointValueChange += OnPointValueChange;

private void OnDisable()

GridPoint.OnPointValueChange == OnPointValueChange;

private void InitGrid()

//apply noise to points

float nx = 0;

float ny = 0;

float nx = 0;

for (float z = 0; z <= GridSize.z; z++)

for (float y = 0; y <= GridSize.y; y++)

for (float x = 0; x <= GridSize.x; x++)

GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);

if(showGrid)

go.GetComponent<MeshRenderer>().enabled = true;

else

go.GetComponent<MeshRenderer>().enabled = false;go.transform.parent = this.transform;

go.GetComponent<Collider>().isTrigger = true;

Rigidbody rb = go.gameObject.AddComponent<Rigidbody>();

rb.useGravity = false;

GridPoint gp = go.gameObject.AddComponent<GridPoint>();

gp.Position = new Vector3(x, y, z);

gp.Size = 0.1f;

gp.Value = SurfaceLevel + 0.05f;

p[(int)x, (int)y, (int)z] = gp;

public void DrawLines()

float X = GridSize.x;

float Y = GridSize.y;

float Z = GridSize.z;

line.positionCount = 16;

line.SetPosition(0, new Vector3(0, 0, 0)); //C

line.SetPosition(1, new Vector3(0, Y, 0)); //A

line.SetPosition(2, new Vector3(X, Y, 0)); //B

line.SetPosition(3, new Vector3(X, 0, 0)); //D

line.SetPosition(4, new Vector3(0, 0, 0)); \(\rightarrow\) //C

line.SetPosition(5, new Vector3(0, 0, 2)); //G

line.SetPosition(6, new Vector3(0, Y, Z)); //E

line.SetPosition(7, new Vector3(X, Y, Z)); //F

line.SetPosition(8, new Vector3(X, 0, Z)); //H

line.SetPosition(9, new Vector3(0, 2)); \(\rightarrow\) //G

line.SetPosition(10, new Vector3(0, Y, 2)); //E

line.SetPosition(11, new Vector3(0, Y, 0)); //A

line.SetPosition(12, new Vector3(X, Y, 0)); //B

line.SetPosition(13, new Vector3(X, Y, 2)); //F

line.SetPosition(14, new Vector3(X, 0, Z)); //H

line.SetPosition(15, new Vector3(X, 0, 0)); //D

private void BuildMesh()

float mark = Time.time;

GameObject go = this.gameObject;

MarchingCube.GetMesh(ref go, ref material, false);

/* vertex 8 (0-7)

E4---------F5 7654-3210

| IIGF-DCBA

| I

H7---------G6 |

| I | I |

| A0---------B1

| I

D3---------C2 */

vertices.Clear();

triangles.Clear();uv.Clear();  for (int z = 0; z < GridSize.z; z++)  {  for (int y = 0; y < GridSize.y; y++)  {  for (int x = 0; x < GridSize.x; x++)  {  cell.p[0] = p[x, y, z + 1]; // A0  cell.p[1] = p[x + 1, y, z + 1]; // B1  cell.p[2] = p[x + 1, y, z]; //C2  cell.p[3] = p[x, y, z]; //D3  cell.p[4] = p[x, y + 1, z + 1]; //E4  cell.p[5] = p[x + 1, y + 1, z + 1]; //F5  cell.p[6] = p[x + 1, y + 1, z]; //G6  cell.p[7] = p[x, y + 1, z]; //H7  MarchingCube.IsoFaces(ref cell, SurfaceLevel);  BuildCellMeshData(ref cell);  }  }  }  Vector3[] av = vertices.ToArray();  int[] at = triangles.ToArray();  Vector2[] au = uv.ToArray();  MarchingCube.SetMesh(ref go, ref av, ref at, ref au);  float timeTaken = mark - Time.time;  if (Math.Approximately(timeTaken, 0) == false)  {  Debug.Log(string.Format(\"mesh time = {0}\", timeTaken));  }  private void BuildCellMeshData(ref GridCell cell)  {  bool uvAlternate = false;  for (int i = 0; i < cell.numtriangles; i++)  {  vertices.Add(cell.triangle[i].p[0]);  vertices.Add(cell.triangle[i].p[1]);  vertices.Add(cell.triangle[i].p[2]);  triangles.Add(vertices.Count - 1);  triangles.Add(vertices.Count - 2);  triangles.Add(vertices.Count - 3);  if (uvAlternate == true)  {  uv.Add(UVCoord.A);  uv.Add(UVCoord.C);  uv.Add(UVCoord.D);  }  else  {  uv.Add(UVCoord.A);  uv.Add(UVCoord.B);  uv.Add(UVCoord.C);  }  uvAlternate = luvAlternate;

## References

* [1] [PERSON] Design and Construction of Virtual Welding Training System for the Shielded Metal Arc Welding (SMAW).