Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
essentials.Prefabs.PrefabExtensions Class Reference

Static Public Member Functions

static Prefab SubPrefab (this Prefab prefab, Vector3i offset, Size3i size, Vector3i?center=null)
 
static Prefab Autocrop (this Prefab prefab, Vector3i?center=null)
 

Member Function Documentation

static Prefab essentials.Prefabs.PrefabExtensions.Autocrop ( this Prefab  prefab,
Vector3i center = null 
)
static

Attribute: x,y,z

!= 0)

34  {
35  int minX = int.MaxValue;
36  int minY = int.MaxValue;
37  int minZ = int.MaxValue;
38  int maxX = -int.MaxValue;
39  int maxY = -int.MaxValue;
40  int maxZ = -int.MaxValue;
41 
42  for (int x=0; x<prefab.Width; ++x)
43  {
44  for (int y=0; y<prefab.Length; ++y)
45  {
46  for (int z=0; z<prefab.Height; ++z)
47  {
48  if (prefab[x,y,z] != 0)
49  {
50  minX = Math.Min(minX, x);
51  minY = Math.Min(minY, y);
52  minZ = Math.Min(minZ, z);
53 
54  maxX = Math.Max(maxX, x);
55  maxY = Math.Max(maxY, y);
56  maxZ = Math.Max(maxZ, z);
57  }
58  }
59  }
60  }
61 
62  return SubPrefab(prefab, new Vector3i(minX, minY, minZ), new Size3i(maxX - minX, maxY - minY, maxZ - minZ), center);
63  }
static Prefab SubPrefab(this Prefab prefab, Vector3i offset, Size3i size, Vector3i?center=null)
Definition: PrefabExtensions.cs:8
Definition: Size3i.cs:5
static readonly Vector3i
All directions, including diagnols
Definition: Vector3i.cs:111
static Prefab essentials.Prefabs.PrefabExtensions.SubPrefab ( this Prefab  prefab,
Vector3i  offset,
Size3i  size,
Vector3i center = null 
)
static

Attribute: pt] = prefab[origPoint

;

9  {
10  Vector3i newCenter = center ?? prefab.Center - offset;
11  var cropped = new Prefab(size, newCenter);
12 
13  for (int x=0; x<size.Width; ++x)
14  {
15  for (int y=0; y<size.Length; ++y)
16  {
17  for (int z=0; z<size.Height; ++z)
18  {
19  Vector3i pt = new Vector3i(x, y, z);
20  Vector3i origPoint = pt + offset;
21  if (origPoint.X >= 0 && origPoint.Y >= 0 && origPoint.Z >= 0
22  && origPoint.X < prefab.Width && origPoint.Y < prefab.Length && origPoint.Z < prefab.Height)
23  {
24  cropped[pt] = prefab[origPoint];
25  }
26  }
27  }
28  }
29 
30  return cropped;
31  }
static readonly Vector3i
All directions, including diagnols
Definition: Vector3i.cs:111
int Height
Definition: Size3i.cs:7
int Y
The Y coordinate
Definition: Vector3i.cs:23
int Width
Definition: Size3i.cs:7
int Length
Definition: Size3i.cs:7
A class representing a 3D coordinate of integers
Definition: Vector3i.cs:13
int X
The X coordinate
Definition: Vector3i.cs:18
int Z
The Z coordinate
Definition: Vector3i.cs:28

The documentation for this class was generated from the following file: