From 6e20d252782aac514129e2f9e2eb8d850be133be Mon Sep 17 00:00:00 2001 From: Simon Broggi Date: Fri, 21 Aug 2020 16:21:59 +0200 Subject: [PATCH 1/2] Incremental delaunai (#1) * allow reusing mesh when converting from other data structure to unity mesh * add DelaunayIncrementalController (Start with a quad. Works in play mode. Adds triangles to mesh when pressing space) * update to unity 2019.4 * refactor generation of voronoi from delaunay --- .../DelaunayIncrementalController.cs | 95 +++++ .../DelaunayIncrementalController.cs.meta | 11 + .../delaunayIncremental.unity | 397 ++++++++++++++++++ .../delaunayIncremental.unity.meta | 7 + .../5. Voronoi diagram/VoronoiController.cs | 51 +-- .../DelaunayToVoronoiAlgorithm.cs | 7 +- .../_TransformBetweenDataStructures.cs | 72 +++- Logs/Packages-Update.log | 25 ++ Packages/manifest.json | 21 +- Packages/packages-lock.json | 380 +++++++++++++++++ ProjectSettings/ProjectVersion.txt | 3 +- ProjectSettings/XRSettings.asset | 10 + 12 files changed, 1014 insertions(+), 65 deletions(-) create mode 100644 Assets/Test scenes/4. Triangulation/DelaunayIncrementalController.cs create mode 100644 Assets/Test scenes/4. Triangulation/DelaunayIncrementalController.cs.meta create mode 100644 Assets/Test scenes/4. Triangulation/delaunayIncremental.unity create mode 100644 Assets/Test scenes/4. Triangulation/delaunayIncremental.unity.meta create mode 100644 Packages/packages-lock.json create mode 100644 ProjectSettings/XRSettings.asset diff --git a/Assets/Test scenes/4. Triangulation/DelaunayIncrementalController.cs b/Assets/Test scenes/4. Triangulation/DelaunayIncrementalController.cs new file mode 100644 index 0000000..874190d --- /dev/null +++ b/Assets/Test scenes/4. Triangulation/DelaunayIncrementalController.cs @@ -0,0 +1,95 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Habrador_Computational_Geometry; + +public class DelaunayIncrementalController : MonoBehaviour +{ + Mesh triangulatedMesh; + MeshFilter meshFilter; + MeshRenderer meshRenderer; + public Rect bounds; + AABB2 normalizingBox; // Rect in Habrador? what's the difference to Rect?? + float dMax; + HalfEdgeData2 delaunayData_normalized; + + void Start() + { + InitializeMeshComponents(); + + normalizingBox = new AABB2(bounds.xMin, bounds.xMax, bounds.yMin, bounds.yMax); + dMax = HelpMethods.CalculateDMax(normalizingBox); + + // Triangle2 superTriangle = new Triangle2(new MyVector2(-10f, -10f), new MyVector2(10f, -10f), new MyVector2(0f, 10f)); + float rightNormalized = (normalizingBox.maxX - normalizingBox.minX) / dMax; + float topNormalized = (normalizingBox.maxY - normalizingBox.minY) / dMax; + Triangle2 quadTri1 = new Triangle2(new MyVector2(0f, 0f), new MyVector2(rightNormalized, 0f), new MyVector2(0f, topNormalized)); + Triangle2 quadTri2 = new Triangle2(new MyVector2(rightNormalized, 0f), new MyVector2(rightNormalized, topNormalized), new MyVector2(0f, topNormalized)); + + + //Create the triangulation data with a quad + HashSet triangles_normalized = new HashSet(); + triangles_normalized.Add(quadTri1); + triangles_normalized.Add(quadTri2); + + //Change to half-edge data structure + delaunayData_normalized = new HalfEdgeData2(); + _TransformBetweenDataStructures.Triangle2ToHalfEdge2(triangles_normalized, delaunayData_normalized); + } + + void InitializeMeshComponents() + { + meshFilter = GetComponent(); + if(meshFilter == null) + { + meshFilter = gameObject.AddComponent(); + } + if(meshFilter.mesh == null) + { + meshFilter.mesh = new Mesh(); + } + triangulatedMesh = meshFilter.mesh; + + meshRenderer = GetComponent(); + if(meshRenderer == null) + { + meshRenderer = gameObject.AddComponent(); + } + } + + [ContextMenu("Add random point")] + void AddRandomPoint() + { + //These are for display purposes only + int missedPoints = 0; + int flippedEdges = 0; + + // random value within bounds, normalized + float x = (normalizingBox.maxX - normalizingBox.minX) * Random.value / dMax; + float y = (normalizingBox.maxY - normalizingBox.minY) * Random.value / dMax; + DelaunayIncrementalSloan.InsertNewPointInTriangulation(new MyVector2(x, y), delaunayData_normalized, ref missedPoints, ref flippedEdges); + } + + private void Update() + { + if(Input.GetKey(KeyCode.Space)) + { + AddRandomPoint(); + } + + //From half-edge to triangle + HashSet triangles_2d_normalized = _TransformBetweenDataStructures.HalfEdge2ToTriangle2(delaunayData_normalized); + + //From 2d to 3d + HashSet triangles_3d = new HashSet(); + + foreach (Triangle2 t in triangles_2d_normalized) + { + //UnNormalize here + triangles_3d.Add(new Triangle3(HelpMethods.UnNormalize(t.p1, normalizingBox, dMax).ToMyVector3(), HelpMethods.UnNormalize(t.p2, normalizingBox, dMax).ToMyVector3(), HelpMethods.UnNormalize(t.p3, normalizingBox, dMax).ToMyVector3())); + } + + triangulatedMesh = _TransformBetweenDataStructures.Triangle3ToCompressedMesh(triangles_3d, triangulatedMesh); + } + +} diff --git a/Assets/Test scenes/4. Triangulation/DelaunayIncrementalController.cs.meta b/Assets/Test scenes/4. Triangulation/DelaunayIncrementalController.cs.meta new file mode 100644 index 0000000..fb496e7 --- /dev/null +++ b/Assets/Test scenes/4. Triangulation/DelaunayIncrementalController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 86180527360e4ef44aed7515c4910031 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Test scenes/4. Triangulation/delaunayIncremental.unity b/Assets/Test scenes/4. Triangulation/delaunayIncremental.unity new file mode 100644 index 0000000..c198458 --- /dev/null +++ b/Assets/Test scenes/4. Triangulation/delaunayIncremental.unity @@ -0,0 +1,397 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!29 &1 +OcclusionCullingSettings: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_OcclusionBakeSettings: + smallestOccluder: 5 + smallestHole: 0.25 + backfaceThreshold: 100 + m_SceneGUID: 00000000000000000000000000000000 + m_OcclusionCullingData: {fileID: 0} +--- !u!104 &2 +RenderSettings: + m_ObjectHideFlags: 0 + serializedVersion: 9 + m_Fog: 0 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} + m_FogMode: 3 + m_FogDensity: 0.01 + m_LinearFogStart: 0 + m_LinearFogEnd: 300 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} + m_AmbientIntensity: 1 + m_AmbientMode: 0 + m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} + m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} + m_HaloStrength: 0.5 + m_FlareStrength: 1 + m_FlareFadeSpeed: 3 + m_HaloTexture: {fileID: 0} + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} + m_DefaultReflectionMode: 0 + m_DefaultReflectionResolution: 128 + m_ReflectionBounces: 1 + m_ReflectionIntensity: 1 + m_CustomReflection: {fileID: 0} + m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1} + m_UseRadianceAmbientProbe: 0 +--- !u!157 &3 +LightmapSettings: + m_ObjectHideFlags: 0 + serializedVersion: 11 + m_GIWorkflowMode: 0 + m_GISettings: + serializedVersion: 2 + m_BounceScale: 1 + m_IndirectOutputScale: 1 + m_AlbedoBoost: 1 + m_EnvironmentLightingMode: 0 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 1 + m_LightmapEditorSettings: + serializedVersion: 12 + m_Resolution: 2 + m_BakeResolution: 40 + m_AtlasSize: 1024 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_ExtractAmbientOcclusion: 0 + m_Padding: 2 + m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 + m_TextureCompression: 1 + m_FinalGather: 0 + m_FinalGatherFiltering: 1 + m_FinalGatherRayCount: 256 + m_ReflectionCompression: 2 + m_MixedBakeMode: 2 + m_BakeBackend: 0 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 500 + m_PVRBounces: 2 + m_PVREnvironmentSampleCount: 500 + m_PVREnvironmentReferencePointCount: 2048 + m_PVRFilteringMode: 2 + m_PVRDenoiserTypeDirect: 0 + m_PVRDenoiserTypeIndirect: 0 + m_PVRDenoiserTypeAO: 0 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 + m_PVREnvironmentMIS: 0 + m_PVRCulling: 1 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 5 + m_PVRFilteringGaussRadiusAO: 2 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 + m_ExportTrainingData: 0 + m_TrainingDataDestination: TrainingData + m_LightProbeSampleCountMultiplier: 4 + m_LightingDataAsset: {fileID: 0} + m_UseShadowmask: 1 +--- !u!196 &4 +NavMeshSettings: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_BuildSettings: + serializedVersion: 2 + agentTypeID: 0 + agentRadius: 0.5 + agentHeight: 2 + agentSlope: 45 + agentClimb: 0.4 + ledgeDropHeight: 0 + maxJumpAcrossDistance: 0 + minRegionArea: 2 + manualCellSize: 0 + cellSize: 0.16666667 + manualTileSize: 0 + tileSize: 256 + accuratePlacement: 0 + debug: + m_Flags: 0 + m_NavMeshData: {fileID: 0} +--- !u!1 &739290443 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 739290445} + - component: {fileID: 739290444} + m_Layer: 0 + m_Name: Directional Light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!108 &739290444 +Light: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 739290443} + m_Enabled: 1 + serializedVersion: 10 + m_Type: 1 + m_Shape: 0 + m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} + m_Intensity: 1 + m_Range: 10 + m_SpotAngle: 30 + m_InnerSpotAngle: 21.80208 + m_CookieSize: 10 + m_Shadows: + m_Type: 2 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_CullingMatrixOverride: + e00: 1 + e01: 0 + e02: 0 + e03: 0 + e10: 0 + e11: 1 + e12: 0 + e13: 0 + e20: 0 + e21: 0 + e22: 1 + e23: 0 + e30: 0 + e31: 0 + e32: 0 + e33: 1 + m_UseCullingMatrixOverride: 0 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingLayerMask: 1 + m_Lightmapping: 4 + m_LightShadowCasterMode: 0 + m_AreaSize: {x: 1, y: 1} + m_BounceIntensity: 1 + m_ColorTemperature: 6570 + m_UseColorTemperature: 0 + m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} + m_UseBoundingSphereOverride: 0 + m_ShadowRadius: 0 + m_ShadowAngle: 0 +--- !u!4 &739290445 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 739290443} + m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} + m_LocalPosition: {x: -33, y: 500, z: -157} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} +--- !u!1 &888250122 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 888250125} + - component: {fileID: 888250124} + - component: {fileID: 888250123} + m_Layer: 0 + m_Name: Camera + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!81 &888250123 +AudioListener: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 888250122} + m_Enabled: 1 +--- !u!20 &888250124 +Camera: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 888250122} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 2 + m_BackGroundColor: {r: 0.6603774, g: 0.6603774, b: 0.6603774, a: 0} + m_projectionMatrixMode: 1 + m_GateFitMode: 2 + m_FOVAxisMode: 0 + m_SensorSize: {x: 36, y: 24} + m_LensShift: {x: 0, y: 0} + m_FocalLength: 50 + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 0 + orthographic size: 5 + m_Depth: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 1 + m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 +--- !u!4 &888250125 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 888250122} + m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} + m_LocalPosition: {x: 0, y: 3, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} +--- !u!1 &1171182120 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1171182122} + - component: {fileID: 1171182121} + - component: {fileID: 1171182124} + - component: {fileID: 1171182123} + m_Layer: 0 + m_Name: _DelaunayIncremental Controller + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1171182121 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1171182120} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 86180527360e4ef44aed7515c4910031, type: 3} + m_Name: + m_EditorClassIdentifier: + points: [] + bounds: + serializedVersion: 2 + x: -2 + y: -0.5 + width: 4 + height: 1 +--- !u!4 &1171182122 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1171182120} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!23 &1171182123 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1171182120} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10302, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &1171182124 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1171182120} + m_Mesh: {fileID: 0} diff --git a/Assets/Test scenes/4. Triangulation/delaunayIncremental.unity.meta b/Assets/Test scenes/4. Triangulation/delaunayIncremental.unity.meta new file mode 100644 index 0000000..1d794c9 --- /dev/null +++ b/Assets/Test scenes/4. Triangulation/delaunayIncremental.unity.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 337a7e4903fe0a94da7399cce747b876 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Test scenes/5. Voronoi diagram/VoronoiController.cs b/Assets/Test scenes/5. Voronoi diagram/VoronoiController.cs index 9ddcb4f..8829c4a 100644 --- a/Assets/Test scenes/5. Voronoi diagram/VoronoiController.cs +++ b/Assets/Test scenes/5. Voronoi diagram/VoronoiController.cs @@ -130,56 +130,7 @@ private void DisplayVoronoiCells(List cells) VoronoiCell2 cell = cells[i]; - //Debug.Log(cell.edges.Count); - - Vector3 p1 = cell.sitePos.ToVector3(); - - Gizmos.color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1f); - - List vertices = new List(); - - List triangles = new List(); - - vertices.Add(p1); - - for (int j = 0; j < cell.edges.Count; j++) - { - //if (j != 2) - //{ - // continue; - //} - - Vector3 p2 = cell.edges[j].p1.ToVector3(); - Vector3 p3 = cell.edges[j].p2.ToVector3(); - - //p3 before p2 to get correct orientation pr the triangle will be upside-down - vertices.Add(p3); - vertices.Add(p2); - - triangles.Add(0); - triangles.Add(vertices.Count - 2); - triangles.Add(vertices.Count - 1); - - //Gizmos.DrawLine(p2, p3); - //Gizmos.DrawLine(p1, p3); - //Gizmos.DrawLine(p1, p2); - - //Vector3 lineCenter = (p3 - p2) * 0.5f; - - //Vector3 lineDir = (p3 - p2).normalized; - - //Vector3 lineNormal = new Vector3(lineDir.z, lineDir.y, -lineDir.x); - - //Gizmos.DrawRay(lineCenter, lineNormal.normalized); - } - - Mesh triangleMesh = new Mesh(); - - triangleMesh.vertices = vertices.ToArray(); - - triangleMesh.triangles = triangles.ToArray(); - - triangleMesh.RecalculateNormals(); + Mesh triangleMesh = _TransformBetweenDataStructures.VoronoiCellToMesh(cell); Gizmos.DrawMesh(triangleMesh); } diff --git a/Assets/_Habrador Computational Geometry Library/5. Voronoi diagram/DelaunayToVoronoiAlgorithm.cs b/Assets/_Habrador Computational Geometry Library/5. Voronoi diagram/DelaunayToVoronoiAlgorithm.cs index 70116e0..bc73835 100644 --- a/Assets/_Habrador Computational Geometry Library/5. Voronoi diagram/DelaunayToVoronoiAlgorithm.cs +++ b/Assets/_Habrador Computational Geometry Library/5. Voronoi diagram/DelaunayToVoronoiAlgorithm.cs @@ -19,11 +19,16 @@ public static List GenerateVoronoiDiagram(HashSet sites //Generate the voronoi diagram + return GenerateVoronoiFromDelaunay(data); + } + + public static List GenerateVoronoiFromDelaunay(HalfEdgeData2 delaunayData) + { //Step 1. For every delaunay edge, compute a voronoi edge //The voronoi edge is the edge connecting the circumcenters of two neighboring delaunay triangles List voronoiEdges = new List(); - HashSet triangles = data.faces; + HashSet triangles = delaunayData.faces; foreach (HalfEdgeFace2 t in triangles) { diff --git a/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/_TransformBetweenDataStructures.cs b/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/_TransformBetweenDataStructures.cs index 51f80d6..27787e4 100644 --- a/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/_TransformBetweenDataStructures.cs +++ b/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/_TransformBetweenDataStructures.cs @@ -152,7 +152,7 @@ public static HashSet MeshToTriangle2(Vector2[] meshVertices, int[] m //Version 1. Check that each vertex exists only once in the final mesh //Make sure the triangles have the correct orientation - public static Mesh Triangle3ToCompressedMesh(HashSet triangles) + public static Mesh Triangle3ToCompressedMesh(HashSet triangles, Mesh mesh = null) { if (triangles == null) { @@ -212,7 +212,13 @@ public static Mesh Triangle3ToCompressedMesh(HashSet triangles) //Step4. Create the final mesh - Mesh mesh = new Mesh(); + if(mesh == null) + { + mesh = new Mesh(); + } + { + mesh.Clear(); + } //From MyVector3 to Vector3 Vector3[] meshVerticesArray = new Vector3[meshVertices.Count]; @@ -238,7 +244,7 @@ public static Mesh Triangle3ToCompressedMesh(HashSet triangles) //Version 2. Don't check for duplicate vertices, which can be good if we want a low-poly style mesh //Make sure the triangles have the correct orientation - public static Mesh Triangle3ToMesh(HashSet triangles) + public static Mesh Triangle3ToMesh(HashSet triangles, Mesh mesh = null) { //Create the list with all vertices and triangles List meshVertices = new List(); @@ -266,7 +272,14 @@ public static Mesh Triangle3ToMesh(HashSet triangles) } //Create the final mesh - Mesh mesh = new Mesh(); + if(mesh == null) + { + mesh = new Mesh(); + } + else + { + mesh.Clear(); + } //From MyVector3 to Vector3 Vector3[] meshVerticesArray = new Vector3[meshVertices.Count]; @@ -291,7 +304,7 @@ public static Mesh Triangle3ToMesh(HashSet triangles) // //meshHeight is the y coordinate in 3d space - public static Mesh Triangles2ToMesh(HashSet triangles, bool useCompressedMesh, float meshHeight = 0f) + public static Mesh Triangles2ToMesh(HashSet triangles, bool useCompressedMesh, float meshHeight = 0f, Mesh mesh = null) { //2d to 3d HashSet triangles_3d = new HashSet(); @@ -304,16 +317,61 @@ public static Mesh Triangles2ToMesh(HashSet triangles, bool useCompre //To mesh if (useCompressedMesh) { - Mesh mesh = _TransformBetweenDataStructures.Triangle3ToCompressedMesh(triangles_3d); + mesh = _TransformBetweenDataStructures.Triangle3ToCompressedMesh(triangles_3d, mesh); return mesh; } else { - Mesh mesh = _TransformBetweenDataStructures.Triangle3ToMesh(triangles_3d); + mesh = _TransformBetweenDataStructures.Triangle3ToMesh(triangles_3d, mesh); return mesh; } } + + public static Mesh VoronoiCellToMesh(VoronoiCell2 cell, Mesh mesh = null) + { + Vector3 p1 = cell.sitePos.ToVector3(); + + Gizmos.color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1f); + + List vertices = new List(); + + List triangles = new List(); + + vertices.Add(p1); + + for (int j = 0; j < cell.edges.Count; j++) + { + Vector3 p2 = cell.edges[j].p1.ToVector3(); + Vector3 p3 = cell.edges[j].p2.ToVector3(); + + //p3 before p2 to get correct orientation pr the triangle will be upside-down + vertices.Add(p3); + vertices.Add(p2); + + triangles.Add(0); + triangles.Add(vertices.Count - 2); + triangles.Add(vertices.Count - 1); + + } + + if(mesh == null) + { + mesh = new Mesh(); + } + else + { + mesh.Clear(); + } + + mesh.vertices = vertices.ToArray(); + + mesh.triangles = triangles.ToArray(); + + mesh.RecalculateNormals(); + + return mesh; + } } } diff --git a/Logs/Packages-Update.log b/Logs/Packages-Update.log index d650ece..2a5eec6 100644 --- a/Logs/Packages-Update.log +++ b/Logs/Packages-Update.log @@ -49,3 +49,28 @@ Update Mode: updateDependencies The following packages were updated: com.unity.package-manager-ui from version 2.0.7 to 2.0.8 + +=== Thu Aug 20 16:29:00 2020 + +Packages were changed. +Update Mode: updateDependencies + +The following packages were added: + com.unity.2d.sprite@1.0.0 + com.unity.2d.tilemap@1.0.0 + com.unity.ide.rider@1.1.4 + com.unity.ide.vscode@1.2.1 + com.unity.modules.androidjni@1.0.0 + com.unity.multiplayer-hlapi@1.0.6 + com.unity.test-framework@1.1.14 + com.unity.timeline@1.2.6 + com.unity.ugui@1.0.0 + com.unity.xr.legacyinputhelpers@2.1.4 +The following packages were updated: + com.unity.ads from version 2.0.8 to 3.4.7 + com.unity.analytics from version 3.2.2 to 3.3.5 + com.unity.collab-proxy from version 1.2.15 to 1.2.16 + com.unity.purchasing from version 2.0.3 to 2.0.6 + com.unity.textmeshpro from version 1.4.1 to 2.0.1 +The following packages were removed: + com.unity.package-manager-ui@2.0.8 diff --git a/Packages/manifest.json b/Packages/manifest.json index 07789d0..8dcc66c 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,13 +1,22 @@ { "dependencies": { - "com.unity.ads": "2.0.8", - "com.unity.analytics": "3.2.2", - "com.unity.collab-proxy": "1.2.15", - "com.unity.package-manager-ui": "2.0.8", - "com.unity.purchasing": "2.0.3", + "com.unity.2d.sprite": "1.0.0", + "com.unity.2d.tilemap": "1.0.0", + "com.unity.ads": "3.4.7", + "com.unity.analytics": "3.3.5", + "com.unity.collab-proxy": "1.2.16", + "com.unity.ide.rider": "1.1.4", + "com.unity.ide.vscode": "1.2.1", + "com.unity.multiplayer-hlapi": "1.0.6", + "com.unity.purchasing": "2.0.6", "com.unity.recorder": "2.1.0-preview.1", - "com.unity.textmeshpro": "1.4.1", + "com.unity.test-framework": "1.1.14", + "com.unity.textmeshpro": "2.0.1", + "com.unity.timeline": "1.2.6", + "com.unity.ugui": "1.0.0", + "com.unity.xr.legacyinputhelpers": "2.1.4", "com.unity.modules.ai": "1.0.0", + "com.unity.modules.androidjni": "1.0.0", "com.unity.modules.animation": "1.0.0", "com.unity.modules.assetbundle": "1.0.0", "com.unity.modules.audio": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json new file mode 100644 index 0000000..a7d64a5 --- /dev/null +++ b/Packages/packages-lock.json @@ -0,0 +1,380 @@ +{ + "dependencies": { + "com.unity.2d.sprite": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.2d.tilemap": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.ads": { + "version": "3.4.7", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.ugui": "1.0.0" + }, + "url": "https://packages.unity.com" + }, + "com.unity.analytics": { + "version": "3.3.5", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.ugui": "1.0.0" + }, + "url": "https://packages.unity.com" + }, + "com.unity.collab-proxy": { + "version": "1.2.16", + "depth": 0, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.ext.nunit": { + "version": "1.0.0", + "depth": 1, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.ide.rider": { + "version": "1.1.4", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.test-framework": "1.1.1" + }, + "url": "https://packages.unity.com" + }, + "com.unity.ide.vscode": { + "version": "1.2.1", + "depth": 0, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.multiplayer-hlapi": { + "version": "1.0.6", + "depth": 0, + "source": "registry", + "dependencies": { + "nuget.mono-cecil": "0.1.6-preview" + }, + "url": "https://packages.unity.com" + }, + "com.unity.purchasing": { + "version": "2.0.6", + "depth": 0, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.recorder": { + "version": "2.1.0-preview.1", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.timeline": "1.0.0" + }, + "url": "https://packages.unity.com" + }, + "com.unity.test-framework": { + "version": "1.1.14", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.ext.nunit": "1.0.0", + "com.unity.modules.imgui": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0" + }, + "url": "https://packages.unity.com" + }, + "com.unity.textmeshpro": { + "version": "2.0.1", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.ugui": "1.0.0" + }, + "url": "https://packages.unity.com" + }, + "com.unity.timeline": { + "version": "1.2.6", + "depth": 0, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.ugui": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.ui": "1.0.0" + } + }, + "com.unity.xr.legacyinputhelpers": { + "version": "2.1.4", + "depth": 0, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "nuget.mono-cecil": { + "version": "0.1.6-preview", + "depth": 1, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.modules.ai": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.androidjni": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.animation": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.assetbundle": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.audio": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.cloth": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0" + } + }, + "com.unity.modules.director": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.animation": "1.0.0" + } + }, + "com.unity.modules.imageconversion": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.imgui": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.jsonserialize": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.particlesystem": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.physics": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.physics2d": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.screencapture": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.imageconversion": "1.0.0" + } + }, + "com.unity.modules.subsystems": { + "version": "1.0.0", + "depth": 1, + "source": "builtin", + "dependencies": { + "com.unity.modules.jsonserialize": "1.0.0" + } + }, + "com.unity.modules.terrain": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.terrainphysics": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0", + "com.unity.modules.terrain": "1.0.0" + } + }, + "com.unity.modules.tilemap": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics2d": "1.0.0" + } + }, + "com.unity.modules.ui": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.uielements": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.imgui": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0" + } + }, + "com.unity.modules.umbra": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.unityanalytics": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0" + } + }, + "com.unity.modules.unitywebrequest": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.unitywebrequestassetbundle": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.assetbundle": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0" + } + }, + "com.unity.modules.unitywebrequestaudio": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.audio": "1.0.0" + } + }, + "com.unity.modules.unitywebrequesttexture": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.imageconversion": "1.0.0" + } + }, + "com.unity.modules.unitywebrequestwww": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.unitywebrequestassetbundle": "1.0.0", + "com.unity.modules.unitywebrequestaudio": "1.0.0", + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.assetbundle": "1.0.0", + "com.unity.modules.imageconversion": "1.0.0" + } + }, + "com.unity.modules.vehicles": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0" + } + }, + "com.unity.modules.video": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.ui": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0" + } + }, + "com.unity.modules.vr": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.physics": "1.0.0", + "com.unity.modules.xr": "1.0.0" + } + }, + "com.unity.modules.wind": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.xr": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.subsystems": "1.0.0" + } + } + } +} diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 4c21eea..9eeca0e 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1 +1,2 @@ -m_EditorVersion: 2018.4.14f1 +m_EditorVersion: 2019.4.7f1 +m_EditorVersionWithRevision: 2019.4.7f1 (e992b1a16e65) diff --git a/ProjectSettings/XRSettings.asset b/ProjectSettings/XRSettings.asset new file mode 100644 index 0000000..482590c --- /dev/null +++ b/ProjectSettings/XRSettings.asset @@ -0,0 +1,10 @@ +{ + "m_SettingKeys": [ + "VR Device Disabled", + "VR Device User Alert" + ], + "m_SettingValues": [ + "False", + "False" + ] +} \ No newline at end of file From 9b0fc6f933ab16463f824addc5b0de9225622369 Mon Sep 17 00:00:00 2001 From: Simon Broggi Date: Mon, 24 Aug 2020 11:44:12 +0200 Subject: [PATCH 2/2] Invremental voronoi (#2) * refactor * add vertex color to halfedge vert, triangle, and voronoi data structures --- .../DelaunayIncrementalController.cs | 50 +++++++++-- .../delaunayIncremental.unity | 9 +- .../5. Voronoi diagram/VoronoiController.cs | 2 +- Assets/Test scenes/_Materials/VertecColor.mat | 85 +++++++++++++++++++ .../_Materials/VertecColor.mat.meta | 8 ++ .../Delaunay/DelaunayIncrementalSloan.cs | 4 +- .../DelaunayToVoronoiAlgorithm.cs | 5 +- .../Half-edge/HalfEdgeDataStructure.cs | 11 ++- .../Half-edge/HalfEdgeHelpMethods.cs | 30 ++++--- .../Data structures/Triangle.cs | 42 ++++++++- .../Data structures/Voronoi.cs | 9 +- .../_TransformBetweenDataStructures.cs | 83 +++++++++++++----- .../_Utility scripts/HelpMethods.cs | 4 +- Packages/manifest.json | 2 +- Packages/packages-lock.json | 2 +- 15 files changed, 287 insertions(+), 59 deletions(-) create mode 100644 Assets/Test scenes/_Materials/VertecColor.mat create mode 100644 Assets/Test scenes/_Materials/VertecColor.mat.meta diff --git a/Assets/Test scenes/4. Triangulation/DelaunayIncrementalController.cs b/Assets/Test scenes/4. Triangulation/DelaunayIncrementalController.cs index 874190d..777907b 100644 --- a/Assets/Test scenes/4. Triangulation/DelaunayIncrementalController.cs +++ b/Assets/Test scenes/4. Triangulation/DelaunayIncrementalController.cs @@ -23,8 +23,8 @@ void Start() // Triangle2 superTriangle = new Triangle2(new MyVector2(-10f, -10f), new MyVector2(10f, -10f), new MyVector2(0f, 10f)); float rightNormalized = (normalizingBox.maxX - normalizingBox.minX) / dMax; float topNormalized = (normalizingBox.maxY - normalizingBox.minY) / dMax; - Triangle2 quadTri1 = new Triangle2(new MyVector2(0f, 0f), new MyVector2(rightNormalized, 0f), new MyVector2(0f, topNormalized)); - Triangle2 quadTri2 = new Triangle2(new MyVector2(rightNormalized, 0f), new MyVector2(rightNormalized, topNormalized), new MyVector2(0f, topNormalized)); + Triangle2 quadTri1 = new Triangle2(new MyVector2(0f, 0f), new MyVector2(rightNormalized, 0f), new MyVector2(0f, topNormalized), Color.cyan, Color.magenta, Color.yellow); + Triangle2 quadTri2 = new Triangle2(new MyVector2(rightNormalized, 0f), new MyVector2(rightNormalized, topNormalized), new MyVector2(0f, topNormalized), Color.magenta, Color.black, Color.yellow); //Create the triangulation data with a quad @@ -35,6 +35,9 @@ void Start() //Change to half-edge data structure delaunayData_normalized = new HalfEdgeData2(); _TransformBetweenDataStructures.Triangle2ToHalfEdge2(triangles_normalized, delaunayData_normalized); + + // Update mesh + triangulatedMesh = CreateUnnormalizedMesh(delaunayData_normalized, triangulatedMesh); } void InitializeMeshComponents() @@ -67,7 +70,10 @@ void AddRandomPoint() // random value within bounds, normalized float x = (normalizingBox.maxX - normalizingBox.minX) * Random.value / dMax; float y = (normalizingBox.maxY - normalizingBox.minY) * Random.value / dMax; - DelaunayIncrementalSloan.InsertNewPointInTriangulation(new MyVector2(x, y), delaunayData_normalized, ref missedPoints, ref flippedEdges); + Color color = Random.ColorHSV(); + DelaunayIncrementalSloan.InsertNewPointInTriangulation(new MyVector2(x, y), delaunayData_normalized, ref missedPoints, ref flippedEdges, color); + + delaunayMeshNeedsUpdate = true; } private void Update() @@ -77,8 +83,37 @@ private void Update() AddRandomPoint(); } + if(delaunayMeshNeedsUpdate) + { + triangulatedMesh = CreateUnnormalizedMesh(delaunayData_normalized, triangulatedMesh); + + //--Voronoi--// + /* + // create cells + List voronoiCells = DelaunayToVoronoiAlgorithm.GenerateVoronoiFromDelaunay(delaunayData_normalized); + + // unnormalize + voronoiCells = HelpMethods.UnNormalize(voronoiCells, normalizingBox, dMax); + + // if(voronoiCells.Count > 0) + // { + // triangulatedMesh.Clear(); + // triangulatedMesh = _TransformBetweenDataStructures.VoronoiCellToMesh(voronoiCells[voronoiCells.Count-1], triangulatedMesh); + // } + triangulatedMesh = _TransformBetweenDataStructures.VoronoiToMesh(voronoiCells, triangulatedMesh); + */ + //----// + + delaunayMeshNeedsUpdate = false; + } + } + + bool delaunayMeshNeedsUpdate = false; + + Mesh CreateUnnormalizedMesh(HalfEdgeData2 data_normalized, Mesh mesh) + { //From half-edge to triangle - HashSet triangles_2d_normalized = _TransformBetweenDataStructures.HalfEdge2ToTriangle2(delaunayData_normalized); + HashSet triangles_2d_normalized = _TransformBetweenDataStructures.HalfEdge2ToTriangle2(data_normalized); //From 2d to 3d HashSet triangles_3d = new HashSet(); @@ -86,10 +121,13 @@ private void Update() foreach (Triangle2 t in triangles_2d_normalized) { //UnNormalize here - triangles_3d.Add(new Triangle3(HelpMethods.UnNormalize(t.p1, normalizingBox, dMax).ToMyVector3(), HelpMethods.UnNormalize(t.p2, normalizingBox, dMax).ToMyVector3(), HelpMethods.UnNormalize(t.p3, normalizingBox, dMax).ToMyVector3())); + triangles_3d.Add(new Triangle3( HelpMethods.UnNormalize(t.p1, normalizingBox, dMax).ToMyVector3(), + HelpMethods.UnNormalize(t.p2, normalizingBox, dMax).ToMyVector3(), + HelpMethods.UnNormalize(t.p3, normalizingBox, dMax).ToMyVector3(), + t.c1, t.c2, t.c3)); } - triangulatedMesh = _TransformBetweenDataStructures.Triangle3ToCompressedMesh(triangles_3d, triangulatedMesh); + return _TransformBetweenDataStructures.Triangle3ToMesh(triangles_3d, mesh); } } diff --git a/Assets/Test scenes/4. Triangulation/delaunayIncremental.unity b/Assets/Test scenes/4. Triangulation/delaunayIncremental.unity index c198458..3c82485 100644 --- a/Assets/Test scenes/4. Triangulation/delaunayIncremental.unity +++ b/Assets/Test scenes/4. Triangulation/delaunayIncremental.unity @@ -264,7 +264,7 @@ Camera: height: 1 near clip plane: 0.3 far clip plane: 1000 - field of view: 60 + field of view: 41 orthographic: 0 orthographic size: 5 m_Depth: 0 @@ -327,13 +327,12 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 86180527360e4ef44aed7515c4910031, type: 3} m_Name: m_EditorClassIdentifier: - points: [] bounds: serializedVersion: 2 x: -2 - y: -0.5 + y: -1.125 width: 4 - height: 1 + height: 2.25 --- !u!4 &1171182122 Transform: m_ObjectHideFlags: 0 @@ -366,7 +365,7 @@ MeshRenderer: m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: - - {fileID: 10302, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 2100000, guid: 78152745138964de2aa3b0281a48e869, type: 2} m_StaticBatchInfo: firstSubMesh: 0 subMeshCount: 0 diff --git a/Assets/Test scenes/5. Voronoi diagram/VoronoiController.cs b/Assets/Test scenes/5. Voronoi diagram/VoronoiController.cs index 8829c4a..b8c5c62 100644 --- a/Assets/Test scenes/5. Voronoi diagram/VoronoiController.cs +++ b/Assets/Test scenes/5. Voronoi diagram/VoronoiController.cs @@ -131,7 +131,7 @@ private void DisplayVoronoiCells(List cells) VoronoiCell2 cell = cells[i]; Mesh triangleMesh = _TransformBetweenDataStructures.VoronoiCellToMesh(cell); - + Gizmos.color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1f); Gizmos.DrawMesh(triangleMesh); } } diff --git a/Assets/Test scenes/_Materials/VertecColor.mat b/Assets/Test scenes/_Materials/VertecColor.mat new file mode 100644 index 0000000..b26bce1 --- /dev/null +++ b/Assets/Test scenes/_Materials/VertecColor.mat @@ -0,0 +1,85 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: VertecColor + m_Shader: {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _AlphaTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - PixelSnap: 0 + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _EnableExternalAlpha: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _Flip: {r: 1, g: 1, b: 1, a: 1} + - _RendererColor: {r: 1, g: 1, b: 1, a: 1} diff --git a/Assets/Test scenes/_Materials/VertecColor.mat.meta b/Assets/Test scenes/_Materials/VertecColor.mat.meta new file mode 100644 index 0000000..e26bb5f --- /dev/null +++ b/Assets/Test scenes/_Materials/VertecColor.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 78152745138964de2aa3b0281a48e869 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Habrador Computational Geometry Library/4. Triangulation/Delaunay/DelaunayIncrementalSloan.cs b/Assets/_Habrador Computational Geometry Library/4. Triangulation/Delaunay/DelaunayIncrementalSloan.cs index b5d01a7..adc37c3 100644 --- a/Assets/_Habrador Computational Geometry Library/4. Triangulation/Delaunay/DelaunayIncrementalSloan.cs +++ b/Assets/_Habrador Computational Geometry Library/4. Triangulation/Delaunay/DelaunayIncrementalSloan.cs @@ -91,7 +91,7 @@ public static HalfEdgeData2 GenerateTriangulation(HashSet points, Hal //Insert a new point in the triangulation we already have, so we need at least one triangle - public static void InsertNewPointInTriangulation(MyVector2 p, HalfEdgeData2 triangulationData, ref int missedPoints, ref int flippedEdges) + public static void InsertNewPointInTriangulation(MyVector2 p, HalfEdgeData2 triangulationData, ref int missedPoints, ref int flippedEdges, Color? color=null) { //Step 5. Insert the new point in the triangulation //Find the existing triangle the point is in @@ -104,7 +104,7 @@ public static void InsertNewPointInTriangulation(MyVector2 p, HalfEdgeData2 tria } //Delete this triangle and form 3 new triangles by connecting p to each of the vertices in the old triangle - HalfEdgeHelpMethods.SplitTriangleFaceAtPoint(f, p, triangulationData); + HalfEdgeHelpMethods.SplitTriangleFaceAtPoint(f, p, triangulationData, color); //Step 6. Initialize stack. Place all triangles which are adjacent to the edges opposite p on a LIFO stack diff --git a/Assets/_Habrador Computational Geometry Library/5. Voronoi diagram/DelaunayToVoronoiAlgorithm.cs b/Assets/_Habrador Computational Geometry Library/5. Voronoi diagram/DelaunayToVoronoiAlgorithm.cs index bc73835..b447a6a 100644 --- a/Assets/_Habrador Computational Geometry Library/5. Voronoi diagram/DelaunayToVoronoiAlgorithm.cs +++ b/Assets/_Habrador Computational Geometry Library/5. Voronoi diagram/DelaunayToVoronoiAlgorithm.cs @@ -68,7 +68,8 @@ public static List GenerateVoronoiFromDelaunay(HalfEdgeData2 delau //No cell was found so we need to create a new cell if (cellPos == -1) { - VoronoiCell2 newCell = new VoronoiCell2(e.sitePos); + VoronoiCell2 newCell = new VoronoiCell2(e.sitePos, e.color); + //newCell.color = Color.green;// Random.ColorHSV(); // ToDo get color from halfedge vert voronoiCells.Add(newCell); @@ -122,7 +123,7 @@ private static void TryAddVoronoiEdgeFromTriangleEdge(HalfEdge2 e, MyVector2 vor MyVector2 voronoiVertexNeighbor = _Geometry.CalculateCircleCenter(v1, v2, v3); //Create a new vornoi edge between the voronoi vertices - VoronoiEdge2 edge = new VoronoiEdge2(voronoiVertex, voronoiVertexNeighbor, sitePos: e.prevEdge.v.position); + VoronoiEdge2 edge = new VoronoiEdge2(voronoiVertex, voronoiVertexNeighbor, e.prevEdge.v.position, e.prevEdge.v.color); allEdges.Add(edge); } diff --git a/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Half-edge/HalfEdgeDataStructure.cs b/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Half-edge/HalfEdgeDataStructure.cs index e0a8a3e..d631883 100644 --- a/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Half-edge/HalfEdgeDataStructure.cs +++ b/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Half-edge/HalfEdgeDataStructure.cs @@ -83,10 +83,19 @@ public class HalfEdgeVertex2 //Might seem strange because each halfEdge references a vertex the edge is going to? public HalfEdge2 edge; + public Color32 color; - public HalfEdgeVertex2(MyVector2 position) + public HalfEdgeVertex2(MyVector2 position, Color32? c = null) { + if(c == null) + { + this.color = Color.white; + } + else + { + this.color = c.Value; + } this.position = position; } } diff --git a/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Half-edge/HalfEdgeHelpMethods.cs b/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Half-edge/HalfEdgeHelpMethods.cs index 27ce9e1..4122f4b 100644 --- a/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Half-edge/HalfEdgeHelpMethods.cs +++ b/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Half-edge/HalfEdgeHelpMethods.cs @@ -22,10 +22,10 @@ public static void FlipTriangleEdge(HalfEdge2 e) HalfEdge2 e_5 = e_4.nextEdge; HalfEdge2 e_6 = e_4.prevEdge; //The 4 vertex positions - MyVector2 aPos = e_1.v.position; - MyVector2 bPos = e_2.v.position; - MyVector2 cPos = e_3.v.position; - MyVector2 dPos = e_5.v.position; + MyVector2 aPos = e_1.v.position; Color32 aCol = e_1.v.color; + MyVector2 bPos = e_2.v.position; Color32 bCol = e_2.v.color; + MyVector2 cPos = e_3.v.position; Color32 cCol = e_3.v.color; + MyVector2 dPos = e_5.v.position; Color32 dCol = e_5.v.color; //The 6 old vertices, we can use HalfEdgeVertex2 a_old = e_1.v; @@ -44,9 +44,9 @@ public static void FlipTriangleEdge(HalfEdge2 e) HalfEdgeVertex2 d = d_old; //Triangle 1: b-d-a HalfEdgeVertex2 b_opposite = a_opposite_old; - b_opposite.position = bPos; + b_opposite.position = bPos; b_opposite.color = bCol; HalfEdgeVertex2 d_opposite = c_opposite_old; - d_opposite.position = dPos; + d_opposite.position = dPos; d_opposite.color = dCol; HalfEdgeVertex2 a = a_old; @@ -125,7 +125,7 @@ public static void FlipTriangleEdge(HalfEdge2 e) // //Split a face (which we know is a triangle) at a point to create three new triangles while removing the old triangle //Could maybe make it more general so we can split a face, which consists of n edges - public static void SplitTriangleFaceAtPoint(HalfEdgeFace2 f, MyVector2 splitPosition, HalfEdgeData2 data) + public static void SplitTriangleFaceAtPoint(HalfEdgeFace2 f, MyVector2 splitPosition, HalfEdgeData2 data, Color? splitColor = null) { //The edges that belongs to this face HalfEdge2 e_1 = f.edge; @@ -135,9 +135,9 @@ public static void SplitTriangleFaceAtPoint(HalfEdgeFace2 f, MyVector2 splitPosi //A list with new edges so we can connect the new edges with an edge on the opposite side HashSet newEdges = new HashSet(); - CreateNewFace(e_1, splitPosition, data, newEdges); - CreateNewFace(e_2, splitPosition, data, newEdges); - CreateNewFace(e_3, splitPosition, data, newEdges); + CreateNewFace(e_1, splitPosition, data, newEdges, splitColor); + CreateNewFace(e_2, splitPosition, data, newEdges, splitColor); + CreateNewFace(e_3, splitPosition, data, newEdges, splitColor); //Debug.Log("New edges " + newEdges.Count); @@ -181,17 +181,19 @@ public static void SplitTriangleFaceAtPoint(HalfEdgeFace2 f, MyVector2 splitPosi //Create a new triangle face - private static void CreateNewFace(HalfEdge2 e_old, MyVector2 splitPosition, HalfEdgeData2 data, HashSet newEdges) + private static void CreateNewFace(HalfEdge2 e_old, MyVector2 splitPosition, HalfEdgeData2 data, HashSet newEdges, Color? splitColor = null) { //This triangle has the following positons MyVector2 p_split = splitPosition; MyVector2 p_next = e_old.prevEdge.v.position; + Color c_next = e_old.prevEdge.v.color; MyVector2 p_prev = e_old.v.position; + Color c_prev = e_old.v.color; //Create the new stuff - HalfEdgeVertex2 v_split = new HalfEdgeVertex2(p_split); - HalfEdgeVertex2 v_next = new HalfEdgeVertex2(p_next); - HalfEdgeVertex2 v_prev = new HalfEdgeVertex2(p_prev); + HalfEdgeVertex2 v_split = new HalfEdgeVertex2(p_split, splitColor); + HalfEdgeVertex2 v_next = new HalfEdgeVertex2(p_next, c_next); + HalfEdgeVertex2 v_prev = new HalfEdgeVertex2(p_prev, c_prev); //This is the edge that has the same position as the old edge HalfEdge2 e_1 = new HalfEdge2(v_prev); diff --git a/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Triangle.cs b/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Triangle.cs index 3567f83..6de5f9a 100644 --- a/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Triangle.cs +++ b/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Triangle.cs @@ -11,12 +11,23 @@ public struct Triangle3 public MyVector3 p1; public MyVector3 p2; public MyVector3 p3; + public Color32 c1, c2, c3; public Triangle3(MyVector3 p1, MyVector3 p2, MyVector3 p3) { this.p1 = p1; this.p2 = p2; this.p3 = p3; + c1 = c2 = c3 = Color.white; + } + public Triangle3(MyVector3 p1, MyVector3 p2, MyVector3 p3, Color32 c1, Color32 c2, Color32 c3) + { + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.c1 = c1; + this.c2 = c2; + this.c3 = c3; } //Change orientation of triangle from cw -> ccw or ccw -> cw @@ -33,15 +44,39 @@ public void ChangeOrientation() public struct Triangle2 { //Corners - public MyVector2 p1; - public MyVector2 p2; - public MyVector2 p3; + public MyVector2 p1 + { + get; + private set; + } + public MyVector2 p2 + { + get; + private set; + } + public MyVector2 p3 + { + get; + private set; + } + + public Color32 c1, c2, c3; public Triangle2(MyVector2 p1, MyVector2 p2, MyVector2 p3) { this.p1 = p1; this.p2 = p2; this.p3 = p3; + c1 = c2 = c3 = Color.white; + } + public Triangle2(MyVector2 p1, MyVector2 p2, MyVector2 p3, Color32 c1, Color32 c2, Color32 c3) + { + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.c1 = c1; + this.c2 = c2; + this.c3 = c3; } //Change orientation of triangle from cw -> ccw or ccw -> cw @@ -49,6 +84,7 @@ public void ChangeOrientation() { //Swap two vertices (p1, p2) = (p2, p1); + (c1, c2) = (c2, c1); } //Find the max and min coordinates, which is useful when doing AABB intersections diff --git a/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Voronoi.cs b/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Voronoi.cs index c3ed1cd..c79cd5f 100644 --- a/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Voronoi.cs +++ b/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/Voronoi.cs @@ -13,13 +13,15 @@ public class VoronoiEdge2 //All positions within a vornoi cell is closer to this position than any other position in the diagram public MyVector2 sitePos; + public Color32 color; - public VoronoiEdge2(MyVector2 p1, MyVector2 p2, MyVector2 sitePos) + public VoronoiEdge2(MyVector2 p1, MyVector2 p2, MyVector2 sitePos, Color32 color) { this.p1 = p1; this.p2 = p2; this.sitePos = sitePos; + this.color = color; } } @@ -33,9 +35,12 @@ public class VoronoiCell2 public List edges = new List(); - public VoronoiCell2(MyVector2 sitePos) + public Color32 color; + + public VoronoiCell2(MyVector2 sitePos, Color32 color) { this.sitePos = sitePos; + this.color = color; } } } diff --git a/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/_TransformBetweenDataStructures.cs b/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/_TransformBetweenDataStructures.cs index 27787e4..594da83 100644 --- a/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/_TransformBetweenDataStructures.cs +++ b/Assets/_Habrador Computational Geometry Library/_Utility scripts/Data structures/_TransformBetweenDataStructures.cs @@ -22,6 +22,9 @@ public static HalfEdgeData2 Triangle2ToHalfEdge2(HashSet triangles, H HalfEdgeVertex2 v1 = new HalfEdgeVertex2(t.p1); HalfEdgeVertex2 v2 = new HalfEdgeVertex2(t.p2); HalfEdgeVertex2 v3 = new HalfEdgeVertex2(t.p3); + v1.color = t.c1; + v2.color = t.c2; + v3.color = t.c3; //The vertices the edge points to HalfEdge2 he1 = new HalfEdge2(v1); @@ -112,7 +115,7 @@ public static HashSet HalfEdge2ToTriangle2(HalfEdgeData2 data) MyVector2 p2 = face.edge.nextEdge.v.position; MyVector2 p3 = face.edge.nextEdge.nextEdge.v.position; - Triangle2 t = new Triangle2(p1, p2, p3); + Triangle2 t = new Triangle2(p1, p2, p3, face.edge.v.color, face.edge.nextEdge.v.color, face.edge.nextEdge.nextEdge.v.color); triangles.Add(t); } @@ -252,6 +255,8 @@ public static Mesh Triangle3ToMesh(HashSet triangles, Mesh mesh = nul //Create the list with all triangles List meshTriangles = new List(); + List meshColors = new List(); + int arrayPos = 0; foreach (Triangle3 t in triangles) @@ -264,6 +269,10 @@ public static Mesh Triangle3ToMesh(HashSet triangles, Mesh mesh = nul meshVertices.Add(v2); meshVertices.Add(v3); + meshColors.Add(t.c1); + meshColors.Add(t.c2); + meshColors.Add(t.c3); + meshTriangles.Add(arrayPos + 0); meshTriangles.Add(arrayPos + 1); meshTriangles.Add(arrayPos + 2); @@ -292,6 +301,7 @@ public static Mesh Triangle3ToMesh(HashSet triangles, Mesh mesh = nul } mesh.vertices = meshVerticesArray; + mesh.colors32 = meshColors.ToArray(); mesh.triangles = meshTriangles.ToArray(); return mesh; @@ -329,17 +339,61 @@ public static Mesh Triangles2ToMesh(HashSet triangles, bool useCompre } } - public static Mesh VoronoiCellToMesh(VoronoiCell2 cell, Mesh mesh = null) + public static Mesh VoronoiToMesh(List voronoiCells, Mesh mesh = null) + { + if(mesh == null) + { + mesh = new Mesh(); + } + else + { + mesh.Clear(); + } + + for (int i = 0; i < voronoiCells.Count; i++) + { + VoronoiCell2 cell = voronoiCells[i]; + mesh = VoronoiCellToMesh(cell, mesh, true); + } + return mesh; + } + + public static Mesh VoronoiCellToMesh(VoronoiCell2 cell, Mesh mesh = null, bool appendToMesh = false) { Vector3 p1 = cell.sitePos.ToVector3(); - Gizmos.color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1f); + List vertices; + List triangles; + List colors; - List vertices = new List(); + Color32 cellColor = cell.color; - List triangles = new List(); + if(mesh == null) + { + mesh = new Mesh(); + vertices = new List(); + triangles = new List(); + colors = new List(); + } + else + { + if(appendToMesh) + { + vertices = new List(mesh.vertices); + triangles = new List(mesh.triangles); + colors = new List(mesh.colors32); + } + else + { + mesh.Clear(); + vertices = new List(); + triangles = new List(); + colors = new List(); + } + } - vertices.Add(p1); + int p1Index = vertices.Count; + vertices.Add(p1); colors.Add(cellColor); for (int j = 0; j < cell.edges.Count; j++) { @@ -347,27 +401,18 @@ public static Mesh VoronoiCellToMesh(VoronoiCell2 cell, Mesh mesh = null) Vector3 p3 = cell.edges[j].p2.ToVector3(); //p3 before p2 to get correct orientation pr the triangle will be upside-down - vertices.Add(p3); - vertices.Add(p2); + vertices.Add(p3); colors.Add(cellColor); + vertices.Add(p2); colors.Add(cellColor); - triangles.Add(0); + triangles.Add(p1Index); triangles.Add(vertices.Count - 2); triangles.Add(vertices.Count - 1); } - - if(mesh == null) - { - mesh = new Mesh(); - } - else - { - mesh.Clear(); - } mesh.vertices = vertices.ToArray(); - mesh.triangles = triangles.ToArray(); + mesh.colors32 = colors.ToArray(); mesh.RecalculateNormals(); diff --git a/Assets/_Habrador Computational Geometry Library/_Utility scripts/HelpMethods.cs b/Assets/_Habrador Computational Geometry Library/_Utility scripts/HelpMethods.cs index 6aa73d0..8272415 100644 --- a/Assets/_Habrador Computational Geometry Library/_Utility scripts/HelpMethods.cs +++ b/Assets/_Habrador Computational Geometry Library/_Utility scripts/HelpMethods.cs @@ -159,14 +159,14 @@ public static List UnNormalize(List data, AABB2 aabb { MyVector2 sitePosUnNormalized = HelpMethods.UnNormalize(cell.sitePos, aabb, dMax); - VoronoiCell2 cellUnNormalized = new VoronoiCell2(sitePosUnNormalized); + VoronoiCell2 cellUnNormalized = new VoronoiCell2(sitePosUnNormalized, cell.color); foreach (VoronoiEdge2 e in cell.edges) { MyVector2 p1UnNormalized = HelpMethods.UnNormalize(e.p1, aabb, dMax); MyVector2 p2UnNormalized = HelpMethods.UnNormalize(e.p2, aabb, dMax); - VoronoiEdge2 eUnNormalized = new VoronoiEdge2(p1UnNormalized, p2UnNormalized, sitePosUnNormalized); + VoronoiEdge2 eUnNormalized = new VoronoiEdge2(p1UnNormalized, p2UnNormalized, sitePosUnNormalized, cell.color); cellUnNormalized.edges.Add(eUnNormalized); } diff --git a/Packages/manifest.json b/Packages/manifest.json index 8dcc66c..671bea0 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -9,7 +9,7 @@ "com.unity.ide.vscode": "1.2.1", "com.unity.multiplayer-hlapi": "1.0.6", "com.unity.purchasing": "2.0.6", - "com.unity.recorder": "2.1.0-preview.1", + "com.unity.recorder": "2.2.0-preview.4", "com.unity.test-framework": "1.1.14", "com.unity.textmeshpro": "2.0.1", "com.unity.timeline": "1.2.6", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index a7d64a5..19aa805 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -77,7 +77,7 @@ "url": "https://packages.unity.com" }, "com.unity.recorder": { - "version": "2.1.0-preview.1", + "version": "2.2.0-preview.4", "depth": 0, "source": "registry", "dependencies": {