scripts
This commit is contained in:
@@ -0,0 +1,306 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ProBuilder2.Common
|
||||
{
|
||||
// Token: 0x02000010 RID: 16
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("")]
|
||||
[Serializable]
|
||||
public class pb_ElementGraphics : pb_MonoBehaviourSingleton<pb_ElementGraphics>
|
||||
{
|
||||
// Token: 0x06000083 RID: 131 RVA: 0x0000EA04 File Offset: 0x0000CE04
|
||||
public override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
base.gameObject.hideFlags = HideFlags.HideAndDontSave;
|
||||
if (pb_MonoBehaviourSingleton<pb_MeshRenderer>.nullableInstance == null)
|
||||
{
|
||||
base.gameObject.AddComponent<pb_MeshRenderer>();
|
||||
}
|
||||
this.wireframeMaterial = this.CreateMaterial(Shader.Find("Hidden/ProBuilder/FaceHighlight"), "WIREFRAME_MATERIAL");
|
||||
this.wireframeMaterial.SetColor("_Color", this.wireframeColor);
|
||||
this.faceMaterial = this.CreateMaterial(Shader.Find("Hidden/ProBuilder/FaceHighlight"), "FACE_SELECTION_MATERIAL");
|
||||
this.faceMaterial.SetColor("_Color", this.faceSelectionColor);
|
||||
this.vertexMaterial = this.CreateMaterial(Shader.Find("Hidden/ProBuilder/pb_VertexShader"), "VERTEX_BILLBOARD_MATERIAL");
|
||||
this.vertexMaterial.SetColor("_Color", this.vertexDotColor);
|
||||
this.vertexMaterial.SetFloat("_Scale", pb_ElementGraphics.vertexHandleSize * 4f);
|
||||
}
|
||||
|
||||
// Token: 0x06000084 RID: 132 RVA: 0x0000EAEE File Offset: 0x0000CEEE
|
||||
private void OnDestroy()
|
||||
{
|
||||
global::UnityEngine.Object.DestroyImmediate(this.faceMaterial);
|
||||
global::UnityEngine.Object.DestroyImmediate(this.vertexMaterial);
|
||||
global::UnityEngine.Object.DestroyImmediate(this.wireframeMaterial);
|
||||
}
|
||||
|
||||
// Token: 0x06000085 RID: 133 RVA: 0x0000EB14 File Offset: 0x0000CF14
|
||||
public override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
this.pool = new pb_ObjectPool<pb_Renderable>(0, 8, new Func<pb_Renderable>(pb_Renderable.CreateInstance), new Action<pb_Renderable>(pb_Renderable.DestroyInstance));
|
||||
}
|
||||
|
||||
// Token: 0x06000086 RID: 134 RVA: 0x0000EB6E File Offset: 0x0000CF6E
|
||||
private void OnDisable()
|
||||
{
|
||||
this.pool.Empty();
|
||||
}
|
||||
|
||||
// Token: 0x06000087 RID: 135 RVA: 0x0000EB7C File Offset: 0x0000CF7C
|
||||
private Material CreateMaterial(Shader shader, string materialName)
|
||||
{
|
||||
return new Material(shader)
|
||||
{
|
||||
name = materialName,
|
||||
hideFlags = pb_ElementGraphics.PB_EDITOR_GRAPHIC_HIDE_FLAGS
|
||||
};
|
||||
}
|
||||
|
||||
// Token: 0x06000088 RID: 136 RVA: 0x0000EBA4 File Offset: 0x0000CFA4
|
||||
public void LoadPrefs(Color in_faceSelectionColor, Color in_edgeSelectionColor, Color in_vertSelectionColor, Color in_vertexDotColor, float in_vertexHandleSize)
|
||||
{
|
||||
this.faceSelectionColor = in_faceSelectionColor;
|
||||
this.edgeSelectionColor = in_edgeSelectionColor;
|
||||
this.vertSelectionColor = in_vertSelectionColor;
|
||||
this.vertexDotColor = in_vertexDotColor;
|
||||
pb_ElementGraphics.vertexHandleSize = in_vertexHandleSize;
|
||||
this.wireframeMaterial.SetColor("_Color", this.wireframeColor);
|
||||
this.faceMaterial.SetColor("_Color", this.faceSelectionColor);
|
||||
this.vertexMaterial.SetColor("_Color", this.vertexDotColor);
|
||||
this.vertexMaterial.SetFloat("_Scale", pb_ElementGraphics.vertexHandleSize * 4f);
|
||||
}
|
||||
|
||||
// Token: 0x06000089 RID: 137 RVA: 0x0000EC32 File Offset: 0x0000D032
|
||||
private void AddRenderable(pb_Renderable ren)
|
||||
{
|
||||
this.activeRenderables.Add(ren);
|
||||
pb_MeshRenderer.Add(ren);
|
||||
}
|
||||
|
||||
// Token: 0x0600008A RID: 138 RVA: 0x0000EC48 File Offset: 0x0000D048
|
||||
public void RebuildGraphics(pb_Object[] selection, pb_Edge[][] universalEdgesDistinct, EditLevel editLevel, SelectMode selectionMode)
|
||||
{
|
||||
if (this.pool == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (pb_Renderable pb_Renderable in this.activeRenderables)
|
||||
{
|
||||
this.pool.Put(pb_Renderable);
|
||||
pb_MeshRenderer.Remove(pb_Renderable);
|
||||
}
|
||||
this.wireframeMaterial.SetColor("_Color", (selectionMode != SelectMode.Edge || editLevel != EditLevel.Geometry) ? this.wireframeColor : this.edgeSelectionColor);
|
||||
for (int i = 0; i < selection.Length; i++)
|
||||
{
|
||||
this.AddRenderable(this.BuildEdgeMesh(selection[i], universalEdgesDistinct[i]));
|
||||
}
|
||||
if (editLevel == EditLevel.Geometry)
|
||||
{
|
||||
if (selectionMode != SelectMode.Face)
|
||||
{
|
||||
if (selectionMode == SelectMode.Vertex)
|
||||
{
|
||||
foreach (pb_Object pb_Object in selection)
|
||||
{
|
||||
this.AddRenderable(this.BuildVertexMesh(pb_Object));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (pb_Object pb_Object2 in selection)
|
||||
{
|
||||
this.AddRenderable(this.BuildFaceMesh(pb_Object2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600008B RID: 139 RVA: 0x0000ED9C File Offset: 0x0000D19C
|
||||
private pb_Renderable BuildFaceMesh(pb_Object pb)
|
||||
{
|
||||
pb_Renderable pb_Renderable = this.pool.Get();
|
||||
pb_Renderable.name = "Faces Renderable";
|
||||
pb_Renderable.transform = pb.transform;
|
||||
pb_Renderable.materials = new Material[] { this.faceMaterial };
|
||||
pb_Renderable.mesh.Clear();
|
||||
pb_Renderable.mesh.vertices = pb.vertices;
|
||||
pb_Renderable.mesh.triangles = pb_Face.AllTriangles(pb.SelectedFaces);
|
||||
return pb_Renderable;
|
||||
}
|
||||
|
||||
// Token: 0x0600008C RID: 140 RVA: 0x0000EE14 File Offset: 0x0000D214
|
||||
private pb_Renderable BuildVertexMesh(pb_Object pb)
|
||||
{
|
||||
ushort num = 16383;
|
||||
int num2 = pb.sharedIndices.Length;
|
||||
if (num2 > (int)num)
|
||||
{
|
||||
num2 = (int)num;
|
||||
}
|
||||
Vector3[] array = new Vector3[pb.sharedIndices.Length];
|
||||
HashSet<int> hashSet = new HashSet<int>(pb.sharedIndices.GetCommonIndices(pb.SelectedTriangles));
|
||||
for (int i = 0; i < num2; i++)
|
||||
{
|
||||
array[i] = pb.vertices[pb.sharedIndices[i][0]];
|
||||
}
|
||||
Vector3[] array2 = new Vector3[num2 * 4];
|
||||
Vector3[] array3 = new Vector3[num2 * 4];
|
||||
Vector2[] array4 = new Vector2[num2 * 4];
|
||||
Vector2[] array5 = new Vector2[num2 * 4];
|
||||
Color[] array6 = new Color[num2 * 4];
|
||||
int[] array7 = new int[num2 * 6];
|
||||
int num3 = 0;
|
||||
int num4 = 0;
|
||||
Vector3 up = Vector3.up;
|
||||
Vector3 right = Vector3.right;
|
||||
for (int j = 0; j < num2; j++)
|
||||
{
|
||||
array2[num4] = array[j];
|
||||
array2[num4 + 1] = array[j];
|
||||
array2[num4 + 2] = array[j];
|
||||
array2[num4 + 3] = array[j];
|
||||
array4[num4] = Vector3.zero;
|
||||
array4[num4 + 1] = Vector3.right;
|
||||
array4[num4 + 2] = Vector3.up;
|
||||
array4[num4 + 3] = Vector3.one;
|
||||
array5[num4] = -up - right;
|
||||
array5[num4 + 1] = -up + right;
|
||||
array5[num4 + 2] = up - right;
|
||||
array5[num4 + 3] = up + right;
|
||||
array3[num4] = Vector3.forward;
|
||||
array3[num4 + 1] = Vector3.forward;
|
||||
array3[num4 + 2] = Vector3.forward;
|
||||
array3[num4 + 3] = Vector3.forward;
|
||||
array7[num3] = num4;
|
||||
array7[num3 + 1] = num4 + 1;
|
||||
array7[num3 + 2] = num4 + 2;
|
||||
array7[num3 + 3] = num4 + 1;
|
||||
array7[num3 + 4] = num4 + 3;
|
||||
array7[num3 + 5] = num4 + 2;
|
||||
if (hashSet.Contains(j))
|
||||
{
|
||||
array6[num4] = this.vertSelectionColor;
|
||||
array6[num4 + 1] = this.vertSelectionColor;
|
||||
array6[num4 + 2] = this.vertSelectionColor;
|
||||
array6[num4 + 3] = this.vertSelectionColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
array6[num4] = this.vertexDotColor;
|
||||
array6[num4 + 1] = this.vertexDotColor;
|
||||
array6[num4 + 2] = this.vertexDotColor;
|
||||
array6[num4 + 3] = this.vertexDotColor;
|
||||
}
|
||||
num4 += 4;
|
||||
num3 += 6;
|
||||
}
|
||||
pb_Renderable pb_Renderable = this.pool.Get();
|
||||
pb_Renderable.name = "Vertex Renderable";
|
||||
pb_Renderable.transform = pb.transform;
|
||||
pb_Renderable.materials = new Material[] { this.vertexMaterial };
|
||||
pb_Renderable.mesh.Clear();
|
||||
pb_Renderable.mesh.vertices = array2;
|
||||
pb_Renderable.mesh.normals = array3;
|
||||
pb_Renderable.mesh.uv = array4;
|
||||
pb_Renderable.mesh.uv2 = array5;
|
||||
pb_Renderable.mesh.colors = array6;
|
||||
pb_Renderable.mesh.triangles = array7;
|
||||
return pb_Renderable;
|
||||
}
|
||||
|
||||
// Token: 0x0600008D RID: 141 RVA: 0x0000F258 File Offset: 0x0000D658
|
||||
private pb_Renderable BuildEdgeMesh(pb_Object pb, pb_Edge[] universalEdgesDistinct)
|
||||
{
|
||||
pb_IntArray[] sharedIndices = pb.sharedIndices;
|
||||
int num = universalEdgesDistinct.Length;
|
||||
int[] array = new int[num * 2];
|
||||
int num2 = 0;
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
array[num2++] = sharedIndices[universalEdgesDistinct[i].x][0];
|
||||
array[num2++] = sharedIndices[universalEdgesDistinct[i].y][0];
|
||||
}
|
||||
pb_Renderable pb_Renderable = this.pool.Get();
|
||||
pb_Renderable.name = "Wireframe Renderable";
|
||||
pb_Renderable.materials = new Material[] { this.wireframeMaterial };
|
||||
pb_Renderable.transform = pb.transform;
|
||||
pb_Renderable.mesh.name = "Wireframe Mesh";
|
||||
pb_Renderable.mesh.Clear();
|
||||
pb_Renderable.mesh.vertices = pb.vertices;
|
||||
pb_Renderable.mesh.normals = pb.vertices;
|
||||
pb_Renderable.mesh.uv = new Vector2[pb.vertexCount];
|
||||
pb_Renderable.mesh.subMeshCount = 1;
|
||||
pb_Renderable.mesh.SetIndices(array, MeshTopology.Lines, 0);
|
||||
return pb_Renderable;
|
||||
}
|
||||
|
||||
// Token: 0x04000088 RID: 136
|
||||
private const string FACE_SHADER = "Hidden/ProBuilder/FaceHighlight";
|
||||
|
||||
// Token: 0x04000089 RID: 137
|
||||
private const string EDGE_SHADER = "Hidden/ProBuilder/FaceHighlight";
|
||||
|
||||
// Token: 0x0400008A RID: 138
|
||||
private const string VERT_SHADER = "Hidden/ProBuilder/pb_VertexShader";
|
||||
|
||||
// Token: 0x0400008B RID: 139
|
||||
private const string PREVIEW_OBJECT_NAME = "ProBuilderSelectionGameObject";
|
||||
|
||||
// Token: 0x0400008C RID: 140
|
||||
private const string WIREFRAME_OBJECT_NAME = "ProBuilderWireframeGameObject";
|
||||
|
||||
// Token: 0x0400008D RID: 141
|
||||
private const string SELECTION_MESH_NAME = "ProBuilderEditorSelectionMesh";
|
||||
|
||||
// Token: 0x0400008E RID: 142
|
||||
private const string WIREFRAME_MESH_NAME = "ProBuilderEditorWireframeMesh";
|
||||
|
||||
// Token: 0x0400008F RID: 143
|
||||
private static float vertexHandleSize = 0.03f;
|
||||
|
||||
// Token: 0x04000090 RID: 144
|
||||
[SerializeField]
|
||||
private Material faceMaterial;
|
||||
|
||||
// Token: 0x04000091 RID: 145
|
||||
[SerializeField]
|
||||
private Material vertexMaterial;
|
||||
|
||||
// Token: 0x04000092 RID: 146
|
||||
[SerializeField]
|
||||
private Material wireframeMaterial;
|
||||
|
||||
// Token: 0x04000093 RID: 147
|
||||
[SerializeField]
|
||||
private Color faceSelectionColor = new Color(0f, 1f, 1f, 0.275f);
|
||||
|
||||
// Token: 0x04000094 RID: 148
|
||||
[SerializeField]
|
||||
private Color edgeSelectionColor = new Color(0f, 0.6f, 0.7f, 1f);
|
||||
|
||||
// Token: 0x04000095 RID: 149
|
||||
[SerializeField]
|
||||
private Color vertSelectionColor = new Color(1f, 0.2f, 0.2f, 1f);
|
||||
|
||||
// Token: 0x04000096 RID: 150
|
||||
[SerializeField]
|
||||
private Color wireframeColor = new Color(0.53f, 0.65f, 0.84f, 1f);
|
||||
|
||||
// Token: 0x04000097 RID: 151
|
||||
[SerializeField]
|
||||
private Color vertexDotColor = new Color(0.8f, 0.8f, 0.8f, 1f);
|
||||
|
||||
// Token: 0x04000098 RID: 152
|
||||
private static readonly HideFlags PB_EDITOR_GRAPHIC_HIDE_FLAGS = HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.DontSaveInEditor | HideFlags.NotEditable;
|
||||
|
||||
// Token: 0x04000099 RID: 153
|
||||
private pb_ObjectPool<pb_Renderable> pool;
|
||||
|
||||
// Token: 0x0400009A RID: 154
|
||||
private List<pb_Renderable> activeRenderables = new List<pb_Renderable>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user