summaryrefslogtreecommitdiff
path: root/Pathfinding Visualizer/Assets
diff options
context:
space:
mode:
authorSimon O'Shea <osheas1@wit.edu>2023-08-07 13:59:44 -0400
committerSimon O'Shea <osheas1@wit.edu>2023-08-07 13:59:44 -0400
commit7c3fd8d5630482d96dbbfbed2cd08c0d3530d5ad (patch)
tree470579942ac20179c0112ddb03d05657b217fbab /Pathfinding Visualizer/Assets
parent94b8f55509cfea3706299abb7a909c9cd413ba80 (diff)
cells now change color based on value!!!
colors are a bit weird though, need to figure that out
Diffstat (limited to 'Pathfinding Visualizer/Assets')
-rw-r--r--Pathfinding Visualizer/Assets/GridColorMaterials/MATERIAL.pngbin0 -> 1706 bytes
-rw-r--r--Pathfinding Visualizer/Assets/GridColorMaterials/MATERIAL.png.meta127
-rw-r--r--Pathfinding Visualizer/Assets/GridColorMaterials/cellMaterial.mat (renamed from Pathfinding Visualizer/Assets/GridColorMaterials/GridMaterial.mat)6
-rw-r--r--Pathfinding Visualizer/Assets/GridColorMaterials/cellMaterial.mat.meta (renamed from Pathfinding Visualizer/Assets/GridColorMaterials/GridMaterial.mat.meta)2
-rw-r--r--Pathfinding Visualizer/Assets/Scenes/MainScene.unity2
-rw-r--r--Pathfinding Visualizer/Assets/Scripts/CellMesh.cs154
-rw-r--r--Pathfinding Visualizer/Assets/Scripts/LogicGrid.cs17
-rw-r--r--Pathfinding Visualizer/Assets/Scripts/Main.cs6
-rw-r--r--Pathfinding Visualizer/Assets/Scripts/MeshUtils.cs161
-rw-r--r--Pathfinding Visualizer/Assets/Scripts/MeshUtils.cs.meta11
10 files changed, 366 insertions, 120 deletions
diff --git a/Pathfinding Visualizer/Assets/GridColorMaterials/MATERIAL.png b/Pathfinding Visualizer/Assets/GridColorMaterials/MATERIAL.png
new file mode 100644
index 0000000..b660f24
--- /dev/null
+++ b/Pathfinding Visualizer/Assets/GridColorMaterials/MATERIAL.png
Binary files differ
diff --git a/Pathfinding Visualizer/Assets/GridColorMaterials/MATERIAL.png.meta b/Pathfinding Visualizer/Assets/GridColorMaterials/MATERIAL.png.meta
new file mode 100644
index 0000000..6a8eed7
--- /dev/null
+++ b/Pathfinding Visualizer/Assets/GridColorMaterials/MATERIAL.png.meta
@@ -0,0 +1,127 @@
+fileFormatVersion: 2
+guid: 951cf69dd3ce5204ab23a45cb2cfb39c
+TextureImporter:
+ internalIDToNameTable: []
+ externalObjects: {}
+ serializedVersion: 12
+ mipmaps:
+ mipMapMode: 0
+ enableMipMap: 0
+ sRGBTexture: 1
+ linearTexture: 0
+ fadeOut: 0
+ borderMipMap: 0
+ mipMapsPreserveCoverage: 0
+ alphaTestReferenceValue: 0.5
+ mipMapFadeDistanceStart: 1
+ mipMapFadeDistanceEnd: 3
+ bumpmap:
+ convertToNormalMap: 0
+ externalNormalMap: 0
+ heightScale: 0.25
+ normalMapFilter: 0
+ flipGreenChannel: 0
+ isReadable: 0
+ streamingMipmaps: 0
+ streamingMipmapsPriority: 0
+ vTOnly: 0
+ ignoreMipmapLimit: 0
+ grayScaleToAlpha: 0
+ generateCubemap: 6
+ cubemapConvolution: 0
+ seamlessCubemap: 0
+ textureFormat: 1
+ maxTextureSize: 2048
+ textureSettings:
+ serializedVersion: 2
+ filterMode: 1
+ aniso: 1
+ mipBias: 0
+ wrapU: 1
+ wrapV: 1
+ wrapW: 1
+ nPOTScale: 0
+ lightmap: 0
+ compressionQuality: 50
+ spriteMode: 1
+ spriteExtrude: 1
+ spriteMeshType: 1
+ alignment: 0
+ spritePivot: {x: 0.5, y: 0.5}
+ spritePixelsToUnits: 100
+ spriteBorder: {x: 0, y: 0, z: 0, w: 0}
+ spriteGenerateFallbackPhysicsShape: 1
+ alphaUsage: 1
+ alphaIsTransparency: 1
+ spriteTessellationDetail: -1
+ textureType: 8
+ textureShape: 1
+ singleChannelComponent: 0
+ flipbookRows: 1
+ flipbookColumns: 1
+ maxTextureSizeSet: 0
+ compressionQualitySet: 0
+ textureFormatSet: 0
+ ignorePngGamma: 0
+ applyGammaDecoding: 0
+ swizzle: 50462976
+ cookieLightType: 0
+ platformSettings:
+ - serializedVersion: 3
+ buildTarget: DefaultTexturePlatform
+ maxTextureSize: 2048
+ resizeAlgorithm: 0
+ textureFormat: -1
+ textureCompression: 1
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ ignorePlatformSupport: 0
+ androidETC2FallbackOverride: 0
+ forceMaximumCompressionQuality_BC6H_BC7: 0
+ - serializedVersion: 3
+ buildTarget: Standalone
+ maxTextureSize: 2048
+ resizeAlgorithm: 0
+ textureFormat: -1
+ textureCompression: 1
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ ignorePlatformSupport: 0
+ androidETC2FallbackOverride: 0
+ forceMaximumCompressionQuality_BC6H_BC7: 0
+ - serializedVersion: 3
+ buildTarget: Server
+ maxTextureSize: 2048
+ resizeAlgorithm: 0
+ textureFormat: -1
+ textureCompression: 1
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ ignorePlatformSupport: 0
+ androidETC2FallbackOverride: 0
+ forceMaximumCompressionQuality_BC6H_BC7: 0
+ spriteSheet:
+ serializedVersion: 2
+ sprites: []
+ outline: []
+ physicsShape: []
+ bones: []
+ spriteID: 5e97eb03825dee720800000000000000
+ internalID: 0
+ vertices: []
+ indices:
+ edges: []
+ weights: []
+ secondaryTextures: []
+ nameFileIdTable: {}
+ mipmapLimitGroupName:
+ pSDRemoveMatte: 0
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Pathfinding Visualizer/Assets/GridColorMaterials/GridMaterial.mat b/Pathfinding Visualizer/Assets/GridColorMaterials/cellMaterial.mat
index c8fc4b2..44ae80f 100644
--- a/Pathfinding Visualizer/Assets/GridColorMaterials/GridMaterial.mat
+++ b/Pathfinding Visualizer/Assets/GridColorMaterials/cellMaterial.mat
@@ -7,8 +7,8 @@ Material:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
- m_Name: GridMaterial
- m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
+ m_Name: cellMaterial
+ m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
@@ -44,7 +44,7 @@ Material:
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
- m_Texture: {fileID: 0}
+ m_Texture: {fileID: 2800000, guid: 951cf69dd3ce5204ab23a45cb2cfb39c, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
diff --git a/Pathfinding Visualizer/Assets/GridColorMaterials/GridMaterial.mat.meta b/Pathfinding Visualizer/Assets/GridColorMaterials/cellMaterial.mat.meta
index bc768cd..1f5416f 100644
--- a/Pathfinding Visualizer/Assets/GridColorMaterials/GridMaterial.mat.meta
+++ b/Pathfinding Visualizer/Assets/GridColorMaterials/cellMaterial.mat.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 6ab99349792397f45a20efcb8c623941
+guid: 5c15fb7e68981214b8a7478ca8c22bf0
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
diff --git a/Pathfinding Visualizer/Assets/Scenes/MainScene.unity b/Pathfinding Visualizer/Assets/Scenes/MainScene.unity
index 15c0cb6..fa0a3ec 100644
--- a/Pathfinding Visualizer/Assets/Scenes/MainScene.unity
+++ b/Pathfinding Visualizer/Assets/Scenes/MainScene.unity
@@ -326,7 +326,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- - {fileID: 2100000, guid: 6ab99349792397f45a20efcb8c623941, type: 2}
+ - {fileID: 2100000, guid: 5c15fb7e68981214b8a7478ca8c22bf0, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
diff --git a/Pathfinding Visualizer/Assets/Scripts/CellMesh.cs b/Pathfinding Visualizer/Assets/Scripts/CellMesh.cs
index 4e3840e..5fc6bd8 100644
--- a/Pathfinding Visualizer/Assets/Scripts/CellMesh.cs
+++ b/Pathfinding Visualizer/Assets/Scripts/CellMesh.cs
@@ -4,9 +4,6 @@ using UnityEngine;
public class CellMesh : MonoBehaviour
{
-
- Material m_Material;
-
private LogicGrid grid;
private Mesh mesh;
@@ -20,11 +17,20 @@ public class CellMesh : MonoBehaviour
{
this.grid = grid;
UpdateCellVisual();
+
+ // Subscribe to event
+ grid.OnGridValueChanged += GridValueChanged;
+ }
+
+ private void GridValueChanged(object sender, LogicGrid.OnGridValueChangedEventArgs e)
+ {
+ Debug.Log("FIRE!!");
+ UpdateCellVisual();
}
private void UpdateCellVisual()
{
- CreateEmptyMeshArrays(grid.GetWidth() * grid.GetHeight(), out Vector3[] vertices, out Vector2[] uv, out int[] triangles);
+ MeshUtils.CreateEmptyMeshArrays(grid.GetWidth() * grid.GetHeight(), out Vector3[] vertices, out Vector2[] uv, out int[] triangles);
for(int x = 0; x < grid.GetWidth(); x++)
for(int y = 0; y < grid.GetHeight(); y++)
@@ -33,7 +39,12 @@ public class CellMesh : MonoBehaviour
Vector3 quadSize = new Vector3(1, 1) * grid.GetCellSize();
- AddQuad(vertices, uv, triangles, index, grid.GetWorldPosition(x, y), quadSize, Vector2.zero);
+ int gridValue = grid.GetValue(x, y);
+ float gridValueNormalized = gridValue / 4f;
+ Vector2 gridValueUV = new Vector2(gridValueNormalized, 0f);
+
+
+ MeshUtils.AddToMeshArrays(vertices, uv, triangles, index, grid.GetWorldPosition(x, y) + (quadSize * .5f), 0f, quadSize, gridValueUV, gridValueUV);
}
mesh.vertices = vertices;
@@ -43,55 +54,37 @@ public class CellMesh : MonoBehaviour
void Start()
{
- /**
- m_Material = GetComponent<Renderer>().material;
-
- Debug.Log("Mesh Testing");
-
- Mesh mesh = new Mesh();
-
-
- // Build required data-structures for square mesh
- Vector3[] vertices = new Vector3[4];
- Vector2[] uv = new Vector2[4];
- int[] triangles = new int[6];
-
- // Set vertices of polygon (2 triangles -> 1 quad)
- vertices[0] = new Vector3(0, 0);
- vertices[1] = new Vector3(0, 10);
- vertices[2] = new Vector3(10, 10);
- vertices[3] = new Vector3(10, 0);
-
- // UV index contains texture position that should match to vertex with same index
- uv[0] = new Vector2(0, 0);
- uv[1] = new Vector2(0, 1);
- uv[2] = new Vector2(1, 1);
- uv[3] = new Vector2(1, 0);
-
-
- // Set order of indexes of vertices to draw polygon (v1 -> v2 -> v3 -> v1)
- // Note: always set clockwise, otherwise mesh will be facing backwards
- triangles[0] = 0;
- triangles[1] = 1;
- triangles[2] = 2;
-
- triangles[3] = 0;
- triangles[4] = 2;
- triangles[5] = 3;
-
- mesh.vertices = vertices;
- mesh.uv = uv;
- mesh.triangles = triangles;
-
- GetComponent<MeshFilter>().mesh = mesh;
- */
+
}
-
+ /* MeshRenderer myRenderer = GetComponent<MeshRenderer>();
+ Material m_material;
+ if (myRenderer != null)
+ {
+ m_material = myRenderer.material;
+
+ if(gridValue == -1)
+ {
+ m_material.color = Color.black;
+ }
+ if (gridValue == 0)
+ {
+ m_material.color = Color.white;
+ }
+ if (gridValue == 1)
+ {
+ m_material.color = Color.green;
+ }
+ if (gridValue == 2)
+ {
+ m_material.color = Color.cyan;
+ }*//*
+ }
+*/
private void Update()
{
- if(Input.GetKeyDown("1"))
+/* if(Input.GetKeyDown("1"))
{
Debug.Log("1");
m_Material.color = Color.white;
@@ -110,67 +103,6 @@ public class CellMesh : MonoBehaviour
Debug.Log("3");
m_Material.color = Color.green;
//m_Material.SetColor("_Color", Color.white);
- }
- }
-
-
- // CREDIT FOR BELOW FUNCTIONS: CODEMONKEY
- // https://www.youtube.com/watch?v=mZzZXfySeFQ
- public static void CreateEmptyMeshArrays(int quadCount, out Vector3[] vertices, out Vector2[] uvs, out int[] triangles)
- {
- vertices = new Vector3[4 * quadCount];
- uvs = new Vector2[4 * quadCount];
- triangles = new int[6 * quadCount];
- }
-
-
- private void AddQuad(Vector3[] vertices, Vector2[] uvs, int[] triangles, int index, Vector3 GridPos, Vector3 QuadSize, Vector2 Uv)
- {
- vertices[index * 4] = new Vector3((-0.5f + GridPos.x) * QuadSize.x, (-0.5f + GridPos.y) * QuadSize.y);
- vertices[(index * 4) + 1] = new Vector3((-0.5f + GridPos.x) * QuadSize.x, (+0.5f + GridPos.y) * QuadSize.y);
- vertices[(index * 4) + 2] = new Vector3((+0.5f + GridPos.x) * QuadSize.x, (+0.5f + GridPos.y) * QuadSize.y);
- vertices[(index * 4) + 3] = new Vector3((+0.5f + GridPos.x) * QuadSize.x, (-0.5f + GridPos.y) * QuadSize.y);
-
- Debug.Log(vertices[0]);
- Debug.Log(vertices[1]);
- Debug.Log(vertices[2]);
- Debug.Log(vertices[3]);
-
- uvs[(index * 4)] = Uv;
- uvs[(index * 4) + 1] = Uv;
- uvs[(index * 4) + 2] = Uv;
- uvs[(index * 4) + 3] = Uv;
-
- triangles[(index * 6) + 0] = (index * 4) + 0;
- triangles[(index * 6) + 1] = (index * 4) + 1;
- triangles[(index * 6) + 2] = (index * 4) + 2;
- triangles[(index * 6) + 3] = (index * 4) + 2;
- triangles[(index * 6) + 4] = (index * 4) + 3;
- triangles[(index * 6) + 5] = (index * 4) + 0;
- }
-
- /* private void AddQuad(Vector3[] vertices, Vector2[] uvs, int[] triangles, int index, Vector3 GridPos, Vector3 QuadSize, Vector2 Uv)
- {
- vertices[index * 4] = new Vector3((-0.5f + GridPos.x) * QuadSize.x, (-0.5f + GridPos.y) * QuadSize.y);
- vertices[(index * 4) + 1] = new Vector3((-0.5f + GridPos.x) * QuadSize.x, (+0.5f + GridPos.y) * QuadSize.y);
- vertices[(index * 4) + 2] = new Vector3((+0.5f + GridPos.x) * QuadSize.x, (+0.5f + GridPos.y) * QuadSize.y);
- vertices[(index * 4) + 3] = new Vector3((+0.5f + GridPos.x) * QuadSize.x, (-0.5f + GridPos.y) * QuadSize.y);
-
- Debug.Log(vertices[0]);
- Debug.Log(vertices[1]);
- Debug.Log(vertices[2]);
- Debug.Log(vertices[3]);
-
- uvs[(index * 4)] = Uv;
- uvs[(index * 4) + 1] = Uv;
- uvs[(index * 4) + 2] = Uv;
- uvs[(index * 4) + 3] = Uv;
-
- triangles[(index * 6) + 0] = (index * 4) + 0;
- triangles[(index * 6) + 1] = (index * 4) + 1;
- triangles[(index * 6) + 2] = (index * 4) + 2;
- triangles[(index * 6) + 3] = (index * 4) + 2;
- triangles[(index * 6) + 4] = (index * 4) + 3;
- triangles[(index * 6) + 5] = (index * 4) + 0;
}*/
+ }
}
diff --git a/Pathfinding Visualizer/Assets/Scripts/LogicGrid.cs b/Pathfinding Visualizer/Assets/Scripts/LogicGrid.cs
index 873822a..2428594 100644
--- a/Pathfinding Visualizer/Assets/Scripts/LogicGrid.cs
+++ b/Pathfinding Visualizer/Assets/Scripts/LogicGrid.cs
@@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
+using System;
// INSPIRED BY "CODE MONKEY" ON YOUTUBE
@@ -14,10 +15,16 @@ public class LogicGrid
// Actual Grid Array
private int[,] gridArray;
-
// Debug Grid Array used for updating the text-objects
private TextMesh[,] debugTextArray;
+ public event EventHandler<OnGridValueChangedEventArgs> OnGridValueChanged;
+ public class OnGridValueChangedEventArgs : EventArgs
+ {
+ public int x;
+ public int y;
+ }
+
public LogicGrid(int width, int height, float cellSize, Vector3 originPosition)
@@ -83,6 +90,14 @@ public class LogicGrid
// Set the value in our debug mesh so that our Text on-screen gets updated
debugTextArray[x, y].text = gridArray[x, y].ToString();
+
+ if (OnGridValueChanged != null)
+ OnGridValueChanged(this, new OnGridValueChangedEventArgs
+ {
+ x = x,
+ y = y
+ });
+ ;
}
}
diff --git a/Pathfinding Visualizer/Assets/Scripts/Main.cs b/Pathfinding Visualizer/Assets/Scripts/Main.cs
index 30f2671..cdc64db 100644
--- a/Pathfinding Visualizer/Assets/Scripts/Main.cs
+++ b/Pathfinding Visualizer/Assets/Scripts/Main.cs
@@ -38,21 +38,21 @@ public class Main : MonoBehaviour
{
Debug.Log("Placing Mode: Agent");
placementMode = 'a';
- placementValue = 2;
+ placementValue = 3;
}
// Place Sample in grid
if(Input.GetKeyDown("s"))
{
Debug.Log("Placing Mode: Sample");
placementMode = 's';
- placementValue = 1;
+ placementValue = 2;
}
// Place Obstacle in grid
if(Input.GetKeyDown("o"))
{
Debug.Log("Placing Mode: Obstacle");
placementMode = 'o';
- placementValue = -1;
+ placementValue = 1;
}
diff --git a/Pathfinding Visualizer/Assets/Scripts/MeshUtils.cs b/Pathfinding Visualizer/Assets/Scripts/MeshUtils.cs
new file mode 100644
index 0000000..fa7842c
--- /dev/null
+++ b/Pathfinding Visualizer/Assets/Scripts/MeshUtils.cs
@@ -0,0 +1,161 @@
+/*
+ ------------------- Code Monkey -------------------
+
+ Thank you for downloading this package
+ I hope you find it useful in your projects
+ If you have any questions let me know
+ Cheers!
+
+ unitycodemonkey.com
+ --------------------------------------------------
+ */
+
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public static class MeshUtils {
+
+ private static readonly Vector3 Vector3zero = Vector3.zero;
+ private static readonly Vector3 Vector3one = Vector3.one;
+ private static readonly Vector3 Vector3yDown = new Vector3(0,-1);
+
+
+ private static Quaternion[] cachedQuaternionEulerArr;
+ private static void CacheQuaternionEuler() {
+ if (cachedQuaternionEulerArr != null) return;
+ cachedQuaternionEulerArr = new Quaternion[360];
+ for (int i=0; i<360; i++) {
+ cachedQuaternionEulerArr[i] = Quaternion.Euler(0,0,i);
+ }
+ }
+ private static Quaternion GetQuaternionEuler(float rotFloat) {
+ int rot = Mathf.RoundToInt(rotFloat);
+ rot = rot % 360;
+ if (rot < 0) rot += 360;
+ //if (rot >= 360) rot -= 360;
+ if (cachedQuaternionEulerArr == null) CacheQuaternionEuler();
+ return cachedQuaternionEulerArr[rot];
+ }
+
+
+ public static Mesh CreateEmptyMesh() {
+ Mesh mesh = new Mesh();
+ mesh.vertices = new Vector3[0];
+ mesh.uv = new Vector2[0];
+ mesh.triangles = new int[0];
+ return mesh;
+ }
+
+ public static void CreateEmptyMeshArrays(int quadCount, out Vector3[] vertices, out Vector2[] uvs, out int[] triangles) {
+ vertices = new Vector3[4 * quadCount];
+ uvs = new Vector2[4 * quadCount];
+ triangles = new int[6 * quadCount];
+ }
+
+ public static Mesh CreateMesh(Vector3 pos, float rot, Vector3 baseSize, Vector2 uv00, Vector2 uv11) {
+ return AddToMesh(null, pos, rot, baseSize, uv00, uv11);
+ }
+
+ public static Mesh AddToMesh(Mesh mesh, Vector3 pos, float rot, Vector3 baseSize, Vector2 uv00, Vector2 uv11) {
+ if (mesh == null) {
+ mesh = CreateEmptyMesh();
+ }
+ Vector3[] vertices = new Vector3[4 + mesh.vertices.Length];
+ Vector2[] uvs = new Vector2[4 + mesh.uv.Length];
+ int[] triangles = new int[6 + mesh.triangles.Length];
+
+ mesh.vertices.CopyTo(vertices, 0);
+ mesh.uv.CopyTo(uvs, 0);
+ mesh.triangles.CopyTo(triangles, 0);
+
+ int index = vertices.Length / 4 - 1;
+ //Relocate vertices
+ int vIndex = index*4;
+ int vIndex0 = vIndex;
+ int vIndex1 = vIndex+1;
+ int vIndex2 = vIndex+2;
+ int vIndex3 = vIndex+3;
+
+ baseSize *= .5f;
+
+ bool skewed = baseSize.x != baseSize.y;
+ if (skewed) {
+ vertices[vIndex0] = pos+GetQuaternionEuler(rot)*new Vector3(-baseSize.x, baseSize.y);
+ vertices[vIndex1] = pos+GetQuaternionEuler(rot)*new Vector3(-baseSize.x, -baseSize.y);
+ vertices[vIndex2] = pos+GetQuaternionEuler(rot)*new Vector3( baseSize.x, -baseSize.y);
+ vertices[vIndex3] = pos+GetQuaternionEuler(rot)*baseSize;
+ } else {
+ vertices[vIndex0] = pos+GetQuaternionEuler(rot-270)*baseSize;
+ vertices[vIndex1] = pos+GetQuaternionEuler(rot-180)*baseSize;
+ vertices[vIndex2] = pos+GetQuaternionEuler(rot- 90)*baseSize;
+ vertices[vIndex3] = pos+GetQuaternionEuler(rot- 0)*baseSize;
+ }
+
+ //Relocate UVs
+ uvs[vIndex0] = new Vector2(uv00.x, uv11.y);
+ uvs[vIndex1] = new Vector2(uv00.x, uv00.y);
+ uvs[vIndex2] = new Vector2(uv11.x, uv00.y);
+ uvs[vIndex3] = new Vector2(uv11.x, uv11.y);
+
+ //Create triangles
+ int tIndex = index*6;
+
+ triangles[tIndex+0] = vIndex0;
+ triangles[tIndex+1] = vIndex3;
+ triangles[tIndex+2] = vIndex1;
+
+ triangles[tIndex+3] = vIndex1;
+ triangles[tIndex+4] = vIndex3;
+ triangles[tIndex+5] = vIndex2;
+
+ mesh.vertices = vertices;
+ mesh.triangles = triangles;
+ mesh.uv = uvs;
+
+ //mesh.bounds = bounds;
+
+ return mesh;
+ }
+
+ public static void AddToMeshArrays(Vector3[] vertices, Vector2[] uvs, int[] triangles, int index, Vector3 pos, float rot, Vector3 baseSize, Vector2 uv00, Vector2 uv11) {
+ //Relocate vertices
+ int vIndex = index*4;
+ int vIndex0 = vIndex;
+ int vIndex1 = vIndex+1;
+ int vIndex2 = vIndex+2;
+ int vIndex3 = vIndex+3;
+
+ baseSize *= .5f;
+
+ bool skewed = baseSize.x != baseSize.y;
+ if (skewed) {
+ vertices[vIndex0] = pos+GetQuaternionEuler(rot)*new Vector3(-baseSize.x, baseSize.y);
+ vertices[vIndex1] = pos+GetQuaternionEuler(rot)*new Vector3(-baseSize.x, -baseSize.y);
+ vertices[vIndex2] = pos+GetQuaternionEuler(rot)*new Vector3( baseSize.x, -baseSize.y);
+ vertices[vIndex3] = pos+GetQuaternionEuler(rot)*baseSize;
+ } else {
+ vertices[vIndex0] = pos+GetQuaternionEuler(rot-270)*baseSize;
+ vertices[vIndex1] = pos+GetQuaternionEuler(rot-180)*baseSize;
+ vertices[vIndex2] = pos+GetQuaternionEuler(rot- 90)*baseSize;
+ vertices[vIndex3] = pos+GetQuaternionEuler(rot- 0)*baseSize;
+ }
+
+ //Relocate UVs
+ uvs[vIndex0] = new Vector2(uv00.x, uv11.y);
+ uvs[vIndex1] = new Vector2(uv00.x, uv00.y);
+ uvs[vIndex2] = new Vector2(uv11.x, uv00.y);
+ uvs[vIndex3] = new Vector2(uv11.x, uv11.y);
+
+ //Create triangles
+ int tIndex = index*6;
+
+ triangles[tIndex+0] = vIndex0;
+ triangles[tIndex+1] = vIndex3;
+ triangles[tIndex+2] = vIndex1;
+
+ triangles[tIndex+3] = vIndex1;
+ triangles[tIndex+4] = vIndex3;
+ triangles[tIndex+5] = vIndex2;
+ }
+}
diff --git a/Pathfinding Visualizer/Assets/Scripts/MeshUtils.cs.meta b/Pathfinding Visualizer/Assets/Scripts/MeshUtils.cs.meta
new file mode 100644
index 0000000..4e2dca8
--- /dev/null
+++ b/Pathfinding Visualizer/Assets/Scripts/MeshUtils.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 984c4cdb3d17696468650e34e19e16b8
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: