Empeld
Empeld plugin documentation.
essentials.Prefabs.Previewing.PrefabPreviewBuilder Class Reference

Class to build a mesh that is a rough drawing of a prefab Used for preview-rendering More...

Public Member Functions

 PrefabPreviewBuilder ()
 
Mesh BuildMesh (Prefab prefab)
 

Public Attributes

Rgba GridColor = Rgba.Blue
 
string TextureFile = null
 
bool Clip = true
 

Detailed Description

Class to build a mesh that is a rough drawing of a prefab Used for preview-rendering

Constructor & Destructor Documentation

◆ PrefabPreviewBuilder()

essentials.Prefabs.Previewing.PrefabPreviewBuilder.PrefabPreviewBuilder ( )
21  {
22  var resolver = this.GetDependency<IResourceResolver>();
23  this.TextureFile = resolver.Resolve("textures/prefabpreview.png");
24  }
string TextureFile
Definition: PrefabPreviewBuilder.cs:17

Member Function Documentation

◆ BuildMesh()

Mesh essentials.Prefabs.Previewing.PrefabPreviewBuilder.BuildMesh ( Prefab  prefab)

Attribute: x, y, z

;

Attribute: x,y,z+1

== 0)

Attribute: x,y,z-1

== 0)

Attribute: x-1,y,z

== 0)

Attribute: x+1,y,z

== 0)

Attribute: x,y-1,z

== 0)

Attribute: x,y+1,z

== 0)

27  {
28  var mesh = new Mesh();
29 
30  var material = new Material()
31  {
32  Color = this.GridColor,
33  TextureFile = this.TextureFile,
34  };
35 
36  for (int x=0; x<prefab.Width; ++x)
37  {
38  for (int y=0; y<prefab.Length; ++y)
39  {
40  for (int z=0; z<prefab.Height; ++z)
41  {
42  var block = prefab[x, y, z];
43  if (block != 0)
44  {
45  const float size = 1f;
46  var position = new Vector3i(x, y, z) - prefab.Center;
47 
48  //Top
49  if (!Clip || !prefab.InBounds(x,y,z+1) || prefab[x,y,z+1] == 0)
50  mesh.AddQuad(
51  new Vertex(new Vector3(size, size, size) + position, new Vector2(1f, 1f), Vector3.UnitZ),
52  new Vertex(new Vector3(size, 0, size) + position, new Vector2(1f, 0f), Vector3.UnitZ),
53  new Vertex(new Vector3(0, 0, size) + position, new Vector2(0f, 0f), Vector3.UnitZ),
54  new Vertex(new Vector3(0, size, size) + position, new Vector2(0f, 1f), Vector3.UnitZ),
55  material
56  );
57 
58  //Bottom
59  if (!Clip || !prefab.InBounds(x,y,z-1) || prefab[x,y,z-1] == 0)
60  mesh.AddQuad(
61  new Vertex(new Vector3(size, size, 0) + position, new Vector2(1f, 1f), -Vector3.UnitZ),
62  new Vertex(new Vector3(size, 0, 0) + position, new Vector2(1f, 0f), -Vector3.UnitZ),
63  new Vertex(new Vector3(0, 0, 0) + position, new Vector2(0f, 0f), -Vector3.UnitZ),
64  new Vertex(new Vector3(0, size, 0) + position, new Vector2(0f, 1f), -Vector3.UnitZ),
65  material
66  );
67 
68  //Left
69  if (!Clip || !prefab.InBounds(x-1,y,z) || prefab[x-1,y,z] == 0)
70  mesh.AddQuad(
71  new Vertex(new Vector3(0, size, size) + position, new Vector2(1f, 1f), -Vector3.UnitX),
72  new Vertex(new Vector3(0, 0, size) + position, new Vector2(0f, 1f), -Vector3.UnitX),
73  new Vertex(new Vector3(0, 0, 0) + position, new Vector2(0f, 0f), -Vector3.UnitX),
74  new Vertex(new Vector3(0, size, 0) + position, new Vector2(1f, 0f), -Vector3.UnitX),
75  material
76  );
77 
78  //right
79  if (!Clip || !prefab.InBounds(x+1,y,z) || prefab[x+1,y,z] == 0)
80  mesh.AddQuad(
81  new Vertex(new Vector3(size, size, size) + position, new Vector2(1f, 1f), Vector3.UnitX),
82  new Vertex(new Vector3(size, 0, size) + position, new Vector2(0f, 1f), Vector3.UnitX),
83  new Vertex(new Vector3(size, 0, 0) + position, new Vector2(0f, 0f), Vector3.UnitX),
84  new Vertex(new Vector3(size, size, 0) + position, new Vector2(1f, 0f), Vector3.UnitX),
85  material
86  );
87 
88  //Front
89  if (!Clip || !prefab.InBounds(x,y-1,z) || prefab[x,y-1,z] == 0)
90  mesh.AddQuad(
91  new Vertex(new Vector3(size, 0, size) + position, new Vector2(1f, 1f), -Vector3.UnitY),
92  new Vertex(new Vector3(size, 0, 0) + position, new Vector2(1f, 0f), -Vector3.UnitY),
93  new Vertex(new Vector3(0, 0, 0) + position, new Vector2(0f, 0f), -Vector3.UnitY),
94  new Vertex(new Vector3(0, 0, size) + position, new Vector2(0f, 1f), -Vector3.UnitY),
95  material
96  );
97 
98  //Back
99  if (!Clip || !prefab.InBounds(x,y+1,z) || prefab[x,y+1,z] == 0)
100  mesh.AddQuad(
101  new Vertex(new Vector3(size, size, size) + position, new Vector2(1f, 1f), Vector3.UnitY),
102  new Vertex(new Vector3(size, size, 0) + position, new Vector2(1f, 0f), Vector3.UnitY),
103  new Vertex(new Vector3(0, size, 0) + position, new Vector2(0f, 0f), Vector3.UnitY),
104  new Vertex(new Vector3(0, size, size) + position, new Vector2(0f, 1f), Vector3.UnitY),
105  material
106  );
107  }
108  }
109  }
110  }
111 
112  return mesh;
113  }
A raw, un-optimize, fully mutable, representation of a static mesh
Definition: Mesh.cs:13
static readonly Vector3i
All directions, including diagnols
Definition: Vector3i.cs:111
Rgba GridColor
Definition: PrefabPreviewBuilder.cs:16
Definition: Vertex.cs:7
Definition: Material.cs:6
bool Clip
Definition: PrefabPreviewBuilder.cs:18
string TextureFile
Definition: PrefabPreviewBuilder.cs:17

Member Data Documentation

◆ Clip

bool essentials.Prefabs.Previewing.PrefabPreviewBuilder.Clip = true

◆ GridColor

Rgba essentials.Prefabs.Previewing.PrefabPreviewBuilder.GridColor = Rgba.Blue

◆ TextureFile

string essentials.Prefabs.Previewing.PrefabPreviewBuilder.TextureFile = null

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