Empeld
Empeld plugin documentation.
essentials.Prefabs.PrefabExtensions Class Reference

Public Types

enum  PrefabTransform {
  PrefabTransform.Undefined =0, PrefabTransform.FlipX, PrefabTransform.FlipY, PrefabTransform.FlipZ,
  PrefabTransform.RotateZ90, PrefabTransform.RotateZ180, PrefabTransform.RotateZ270
}
 

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)
 
static Prefab Transform (this Prefab prefab, Func< Vector3i, Vector3i > transform)
 
static Prefab Transform (this Prefab prefab, PrefabTransform transform)
 

Member Enumeration Documentation

◆ PrefabTransform

Enumerator
Undefined 
FlipX 
FlipY 
FlipZ 
RotateZ90 
RotateZ180 
RotateZ270 
88  {
89  Undefined=0,
90  FlipX,
91  FlipY,
92  FlipZ,
93  RotateZ90,
94  RotateZ180,
95  RotateZ270
96  }

Member Function Documentation

◆ Autocrop()

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  }
Definition: Size3i.cs:6
static readonly Vector3i
All directions, including diagnols
Definition: Vector3i.cs:111
static Prefab SubPrefab(this Prefab prefab, Vector3i offset, Size3i size, Vector3i? center=null)
Definition: PrefabExtensions.cs:8

◆ SubPrefab()

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:8
int Y
The Y coordinate
Definition: Vector3i.cs:23
int Width
Definition: Size3i.cs:8
int Length
Definition: Size3i.cs:8
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

◆ Transform() [1/2]

static Prefab essentials.Prefabs.PrefabExtensions.Transform ( this Prefab  prefab,
Func< Vector3i, Vector3i transform 
)
static

Attribute: transform(new Vector3i(x, y, z))] = prefab[x, y, z

;

66  {
67  var l0 = transform(new Vector3i(-1, -1, -1));
68  var l1 = transform((Vector3i)prefab.Size);
69  var size = (Size3i)Vector3i.ComponentMax(l0, l1);
70 
71  var ret = new Prefab(size, transform(prefab.Center));
72 
73  for (int x=0; x<prefab.Width; ++x)
74  {
75  for (int y=0; y<prefab.Length; ++y)
76  {
77  for (int z=0; z<prefab.Height; ++z)
78  {
79  ret[transform(new Vector3i(x, y, z))] = prefab[x, y, z];
80  }
81  }
82  }
83 
84  return ret;
85  }
Definition: Size3i.cs:6
static readonly Vector3i
All directions, including diagnols
Definition: Vector3i.cs:111
A class representing a 3D coordinate of integers
Definition: Vector3i.cs:13

◆ Transform() [2/2]

static Prefab essentials.Prefabs.PrefabExtensions.Transform ( this Prefab  prefab,
PrefabTransform  transform 
)
static
99  {
100  Func<Vector3i, Vector3i> transformer;
101  switch(transform)
102  {
103  case PrefabTransform.FlipX:
104  transformer = vec => new Vector3i(prefab.Width - vec.X - 1, vec.Y, vec.Z);
105  break;
106  case PrefabTransform.FlipY:
107  transformer = vec => new Vector3i(vec.X, prefab.Length - vec.Y - 1, vec.Z);
108  break;
109  case PrefabTransform.FlipZ:
110  transformer = vec => new Vector3i(vec.X, vec.Y, prefab.Height - vec.Z - 1);
111  break;
112  case PrefabTransform.RotateZ90:
113  transformer = vec => new Vector3i(vec.Y, vec.X, vec.Z);
114  break;
115  case PrefabTransform.RotateZ180:
116  transformer = vec => new Vector3i(prefab.Width - vec.X - 1, prefab.Length - vec.Y - 1, vec.Z);
117  break;
118  case PrefabTransform.RotateZ270:
119  transformer = vec => new Vector3i(prefab.Length - vec.Y - 1, prefab.Width - vec.X - 1, vec.Z);
120  break;
121  default:
122  throw new ArgumentException("Invalid transform", "transform");
123  }
124 
125  return Transform(prefab, transformer);
126  }
static readonly Vector3i
All directions, including diagnols
Definition: Vector3i.cs:111
PrefabTransform
Definition: PrefabExtensions.cs:87
static Prefab Transform(this Prefab prefab, Func< Vector3i, Vector3i > transform)
Definition: PrefabExtensions.cs:65

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