Skip to content

Commit 566890c

Browse files
wjazd do magazynu
1 parent d22b665 commit 566890c

File tree

6 files changed

+327
-129
lines changed

6 files changed

+327
-129
lines changed

Assets/New Terrain 3.asset

544 KB
Binary file not shown.

Assets/New Terrain 3.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/New Terrain 4.asset

544 KB
Binary file not shown.

Assets/New Terrain 4.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/src/models/warehouse.cs

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEngine;
44
using Newtonsoft.Json;
55
using System;
6+
using Parabox.CSG;
67

78
[System.Serializable]
89

@@ -113,25 +114,17 @@ public void Add_MeshObject(GameObject InstanceML, float MLwidth, float MLlength,
113114

114115
//ok na parzyste
115116
//float offset_l = -((length_*MLlength + ((length_/2)-1)*(MLlength + 16f))/2);
117+
float offset_l = -((length_ * MLlength + (MLlength + 16f)) / 2);
116118

117-
//Debug.Log($"Magazyn {this.Destination}: Lenght:{length_}, Offset: {offset_l}");
119+
Debug.Log($"Magazyn {this.Destination}: Lenght:{length_}, Offset: {offset_l}");
118120

119121
// TODO: fix with Ceiling i Floor
120122
//float offset_l = -((float)(Math.Ceiling((float)(length_ /2)) + (float)(Math.Floor((float)(length_ / 2))) * (MLlength + 16f)) / 2);
121123
//int temp_offset_l = -((int)(Math.Ceiling(length_ / 2) + (int)(Math.Floor(length_ / 2)) * (MLlength + 16))) / 2;
122124
//float offset_l = temp_offset_l;
123-
float offset_w = 0f;
124-
float offset_l = 0f;
125125

126-
if (length_ % 2 == 0)
127-
{
128-
offset_l = -((length_ * MLlength + (MLlength + 16f)) / 2);
129-
//-(length_ * MLlength + (MLlength + 16f) / 2);
130-
}
131-
else
132-
{
133-
offset_l = -((length_ * MLlength + (MLlength + 16f)/2 + MLlength) / 2);
134-
}
126+
127+
float offset_w = 0f;
135128
int path_l = length_ / 2;
136129
for (int l_index = 0; l_index < length_; l_index++)
137130
{
@@ -186,31 +179,63 @@ public void Add_MeshObject(GameObject InstanceML, float MLwidth, float MLlength,
186179
int wall_width = (int)(Mathf.RoundToInt(max_offset_w / 13.05f) + 1);
187180

188181
//dluzsze sciany
189-
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
182+
GameObject front_wall = GameObject.CreatePrimitive(PrimitiveType.Cube);
190183
// x, y, z, gdzie y to wysokosc
191-
cube.transform.position = new Vector3(this.LocationX, 8f, this.LocationY + 6.75f);
192-
cube.transform.localScale = new Vector3(wall_length * 13.05f, 15f, 1f);
193-
cube.name = $"FrontWall";
194-
cube.transform.SetParent(instantiatedObject.transform);
195-
184+
front_wall.transform.position = new Vector3(this.LocationX, 8f, this.LocationY + 6.75f);
185+
front_wall.transform.localScale = new Vector3(wall_length * 13.05f, 15f, 1f);
186+
front_wall.name = $"FrontWall";
187+
front_wall.transform.SetParent(instantiatedObject.transform);
188+
189+
// Create a hole within the wall
190+
GameObject hole = GameObject.CreatePrimitive(PrimitiveType.Cube);
191+
float holeWidth = 5.0f;
192+
float holeHeight = 10.0f;
193+
hole.transform.position = new Vector3(this.LocationX, 8f, this.LocationY + 6.75f);
194+
hole.transform.localScale = new Vector3(holeWidth, holeHeight, 1f);
195+
hole.transform.SetParent(cube.transform);
196+
197+
Model result = CSG.Subtract(front_wall, hole);
198+
var composite = new GameObject();
199+
composite.AddComponent<MeshFilter>().sharedMesh = result.mesh;
200+
composite.AddComponent<MeshRenderer>().sharedMaterials = result.materials.ToArray();
201+
cube.transform.position = composite.transform.position;
202+
composite.transform.SetParent(instantiatedObject.transform);
203+
204+
Destroy(front_wall);
205+
Destroy(hole);
206+
207+
GameObject back_wall = GameObject.CreatePrimitive(PrimitiveType.Cube);
208+
back_wall.transform.position = new Vector3(this.LocationX, 8f, this.LocationY + wall_width * 13.05f);
209+
back_wall.transform.localScale = new Vector3(wall_length * 13.05f, 15f, 1f);
210+
back_wall.name = $"BackWall";
211+
back_wall.transform.SetParent(instantiatedObject.transform);
212+
213+
GameObject gate_hole = GameObject.CreatePrimitive(PrimitiveType.Cube);
214+
float gate_width = 10.0f;
215+
float gate_height = 10.0f;
216+
gate_hole.transform.position = new Vector3(this.LocationX, 8f, this.LocationY + 6.75f);
217+
gate_hole.transform.localScale = new Vector3(holeWidth, holeHeight, 1f);
218+
gate_hole.transform.SetParent(cube.transform);
219+
220+
Model result = CSG.Subtract(back_wall, gate_hole);
221+
var composite = new GameObject();
222+
composite.AddComponent<MeshFilter>().sharedMesh = result.mesh;
223+
composite.AddComponent<MeshRenderer>().sharedMaterials = result.materials.ToArray();
224+
cube.transform.position = composite.transform.position;
225+
composite.transform.SetParent(instantiatedObject.transform);
196226

197-
GameObject cube2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
198-
cube2.transform.position = new Vector3(this.LocationX, 8f, this.LocationY + wall_width * 13.05f);
199-
cube2.transform.localScale = new Vector3(wall_length * 13.05f, 15f, 1f);
200-
cube2.name = $"BackWall";
201-
cube2.transform.SetParent(instantiatedObject.transform);
202227
//krotsze
203-
GameObject cube3 = GameObject.CreatePrimitive(PrimitiveType.Cube);
204-
cube3.transform.position = new Vector3(this.LocationX + wall_length * 13.05f / 2, 8f, this.LocationY + wall_width * 13.05f / 2 + MLlength / 4);
205-
cube3.transform.localScale = new Vector3(1f, 15f, wall_width * 13.05f - MLlength / 2 + 1);
206-
cube3.name = $"LeftWall";
207-
cube3.transform.SetParent(instantiatedObject.transform);
208-
209-
GameObject cube4 = GameObject.CreatePrimitive(PrimitiveType.Cube);
210-
cube4.transform.position = new Vector3(this.LocationX - wall_length * 13.05f / 2, 8f, this.LocationY + wall_width * 13.05f / 2 + MLlength / 4);
211-
cube4.transform.localScale = new Vector3(1f, 15f, wall_width * 13.05f - MLlength / 2 + 1);
212-
cube4.name = $"RightWall";
213-
cube4.transform.SetParent(instantiatedObject.transform);
228+
GameObject left_wall = GameObject.CreatePrimitive(PrimitiveType.Cube);
229+
left_wall.transform.position = new Vector3(this.LocationX + wall_length * 13.05f / 2, 8f, this.LocationY + wall_width * 13.05f / 2 + MLlength / 4);
230+
left_wall.transform.localScale = new Vector3(1f, 15f, wall_width * 13.05f - MLlength / 2 + 1);
231+
left_wall.name = $"LeftWall";
232+
left_wall.transform.SetParent(instantiatedObject.transform);
233+
234+
GameObject right_wall = GameObject.CreatePrimitive(PrimitiveType.Cube);
235+
right_wall.transform.position = new Vector3(this.LocationX - wall_length * 13.05f / 2, 8f, this.LocationY + wall_width * 13.05f / 2 + MLlength / 4);
236+
right_wall.transform.localScale = new Vector3(1f, 15f, wall_width * 13.05f - MLlength / 2 + 1);
237+
right_wall.name = $"RightWall";
238+
right_wall.transform.SetParent(instantiatedObject.transform);
214239

215240
instantiatedObject.transform.rotation = Quaternion.Euler(new Vector3(0, this.rotation, 0));
216241

0 commit comments

Comments
 (0)