diff --git a/Assets/Scripts/Layers/LayerTypes/GeoJSONLineLayer.cs b/Assets/Scripts/Layers/LayerTypes/GeoJSONLineLayer.cs index 33a8c8d2..fd16f7f7 100644 --- a/Assets/Scripts/Layers/LayerTypes/GeoJSONLineLayer.cs +++ b/Assets/Scripts/Layers/LayerTypes/GeoJSONLineLayer.cs @@ -18,6 +18,9 @@ public partial class GeoJSONLineLayer : LayerGameObject { public List SpawnedVisualisations = new(); + private bool randomizeColorPerFeature = false; + public bool RandomizeColorPerFeature { get => randomizeColorPerFeature; set => randomizeColorPerFeature = value; } + [SerializeField] private LineRenderer3D lineRenderer3D; public LineRenderer3D LineRenderer3D @@ -30,7 +33,7 @@ public LineRenderer3D LineRenderer3D // Destroy(lineRenderer3D.gameObject); lineRenderer3D = value; } - } + } public override void OnLayerActiveInHierarchyChanged(bool activeInHierarchy) { @@ -46,6 +49,9 @@ public void AddAndVisualizeFeature(Feature feature, CoordinateSystem original var newFeatureVisualisation = new FeatureLineVisualisations() { feature = feature }; + // Create visual with random color if enabled + UpdateMaterialInstance(); + if (feature.Geometry is MultiLineString multiLineString) { var newLines = GeoJSONGeometryVisualizerUtility.VisualizeMultiLineString(multiLineString, originalCoordinateSystem, lineRenderer3D); @@ -60,6 +66,22 @@ public void AddAndVisualizeFeature(Feature feature, CoordinateSystem original SpawnedVisualisations.Add(newFeatureVisualisation); } + private void UpdateMaterialInstance() + { + // Create material with random color if randomize per feature is enabled + if (RandomizeColorPerFeature) + { + var randomColor = UnityEngine.Random.ColorHSV(); + randomColor.a = LayerData.Color.a; + + lineRenderer3D.LineMaterial.color = randomColor; + return; + } + + // Default to material with layer color + lineRenderer3D.LineMaterial.color = LayerData.Color; + } + /// /// Checks the Bounds of the visualisations and checks them against the camera frustum /// to remove visualisations that are out of view diff --git a/Assets/Scripts/Layers/LayerTypes/GeoJSONPointLayer.cs b/Assets/Scripts/Layers/LayerTypes/GeoJSONPointLayer.cs index 55901d9b..51e3dad7 100644 --- a/Assets/Scripts/Layers/LayerTypes/GeoJSONPointLayer.cs +++ b/Assets/Scripts/Layers/LayerTypes/GeoJSONPointLayer.cs @@ -15,6 +15,9 @@ public partial class GeoJSONPointLayer : LayerGameObject { public List SpawnedVisualisations = new(); + private bool randomizeColorPerFeature = false; + public bool RandomizeColorPerFeature { get => randomizeColorPerFeature; set => randomizeColorPerFeature = value; } + [SerializeField] private BatchedMeshInstanceRenderer pointRenderer3D; public BatchedMeshInstanceRenderer PointRenderer3D @@ -28,7 +31,7 @@ public BatchedMeshInstanceRenderer PointRenderer3D pointRenderer3D = value; } } - + public override void OnLayerActiveInHierarchyChanged(bool activeInHierarchy) { pointRenderer3D.gameObject.SetActive(activeInHierarchy); @@ -42,7 +45,10 @@ public void AddAndVisualizeFeature(Feature feature, CoordinateSystem original return; var newFeatureVisualisation = new FeaturePointVisualisations() { feature = feature }; - + + // Create visual with random color if enabled + UpdateMaterialInstance(); + if (feature.Geometry is MultiPoint multiPoint) { var newPointCollection = GeoJSONGeometryVisualizerUtility.VisualizeMultiPoint(multiPoint, originalCoordinateSystem, PointRenderer3D); @@ -57,7 +63,23 @@ public void AddAndVisualizeFeature(Feature feature, CoordinateSystem original SpawnedVisualisations.Add(newFeatureVisualisation); } - /// + private void UpdateMaterialInstance() + { + // Create material with random color if randomize per feature is enabled + if (RandomizeColorPerFeature) + { + var randomColor = UnityEngine.Random.ColorHSV(); + randomColor.a = LayerData.Color.a; + + pointRenderer3D.Material.color = randomColor; + return; + } + + // Default to material with layer color + pointRenderer3D.Material.color = LayerData.Color; + } + + /// /// Checks the Bounds of the visualisations and checks them against the camera frustum /// to remove visualisations that are out of view /// diff --git a/Assets/Scripts/Layers/LayerTypes/GeoJsonLayerGameObject.cs b/Assets/Scripts/Layers/LayerTypes/GeoJsonLayerGameObject.cs index a420562e..3ff16182 100644 --- a/Assets/Scripts/Layers/LayerTypes/GeoJsonLayerGameObject.cs +++ b/Assets/Scripts/Layers/LayerTypes/GeoJsonLayerGameObject.cs @@ -287,7 +287,6 @@ private GeoJSONPointLayer CreateOrGetPointLayer() private void VisualizeFeature(Feature feature) { - LoadDefaultValues(); var originalCoordinateSystem = GetCoordinateSystem(); switch (feature.Geometry.Type) {