Skip to content

Commit

Permalink
added assignment to the renderers to update the color in visualize fe…
Browse files Browse the repository at this point in the history
…atures
  • Loading branch information
bozmir committed Sep 19, 2024
1 parent 62bc285 commit 2f7aabd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
24 changes: 23 additions & 1 deletion Assets/Scripts/Layers/LayerTypes/GeoJSONLineLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public partial class GeoJSONLineLayer : LayerGameObject
{
public List<FeatureLineVisualisations> SpawnedVisualisations = new();

private bool randomizeColorPerFeature = false;
public bool RandomizeColorPerFeature { get => randomizeColorPerFeature; set => randomizeColorPerFeature = value; }

[SerializeField] private LineRenderer3D lineRenderer3D;

public LineRenderer3D LineRenderer3D
Expand All @@ -30,7 +33,7 @@ public LineRenderer3D LineRenderer3D
// Destroy(lineRenderer3D.gameObject);
lineRenderer3D = value;
}
}
}

public override void OnLayerActiveInHierarchyChanged(bool activeInHierarchy)
{
Expand All @@ -46,6 +49,9 @@ public void AddAndVisualizeFeature<T>(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);
Expand All @@ -60,6 +66,22 @@ public void AddAndVisualizeFeature<T>(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;
}

/// <summary>
/// Checks the Bounds of the visualisations and checks them against the camera frustum
/// to remove visualisations that are out of view
Expand Down
28 changes: 25 additions & 3 deletions Assets/Scripts/Layers/LayerTypes/GeoJSONPointLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public partial class GeoJSONPointLayer : LayerGameObject
{
public List<FeaturePointVisualisations> SpawnedVisualisations = new();

private bool randomizeColorPerFeature = false;
public bool RandomizeColorPerFeature { get => randomizeColorPerFeature; set => randomizeColorPerFeature = value; }

[SerializeField] private BatchedMeshInstanceRenderer pointRenderer3D;

public BatchedMeshInstanceRenderer PointRenderer3D
Expand All @@ -28,7 +31,7 @@ public BatchedMeshInstanceRenderer PointRenderer3D
pointRenderer3D = value;
}
}

public override void OnLayerActiveInHierarchyChanged(bool activeInHierarchy)
{
pointRenderer3D.gameObject.SetActive(activeInHierarchy);
Expand All @@ -42,7 +45,10 @@ public void AddAndVisualizeFeature<T>(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);
Expand All @@ -57,7 +63,23 @@ public void AddAndVisualizeFeature<T>(Feature feature, CoordinateSystem original
SpawnedVisualisations.Add(newFeatureVisualisation);
}

/// <summary>
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;
}

/// <summary>
/// Checks the Bounds of the visualisations and checks them against the camera frustum
/// to remove visualisations that are out of view
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion Assets/Scripts/Layers/LayerTypes/GeoJsonLayerGameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ private GeoJSONPointLayer CreateOrGetPointLayer()

private void VisualizeFeature(Feature feature)
{
LoadDefaultValues();
var originalCoordinateSystem = GetCoordinateSystem();
switch (feature.Geometry.Type)
{
Expand Down

0 comments on commit 2f7aabd

Please sign in to comment.