diff --git a/Assets/PackageStagingArea/eu.netherlands3d.cameras/Runtime/Scripts/Cameras/FreeCamera.cs b/Assets/PackageStagingArea/eu.netherlands3d.cameras/Runtime/Scripts/Cameras/FreeCamera.cs index 10beda89..594e8015 100644 --- a/Assets/PackageStagingArea/eu.netherlands3d.cameras/Runtime/Scripts/Cameras/FreeCamera.cs +++ b/Assets/PackageStagingArea/eu.netherlands3d.cameras/Runtime/Scripts/Cameras/FreeCamera.cs @@ -1,5 +1,4 @@ using DG.Tweening; -using Netherlands3D.Coordinates; using Netherlands3D.Events; using Netherlands3D.Twin.PackageStagingArea.eu.netherlands3d.cameras.Runtime.Scripts.Cameras; using UnityEngine; @@ -99,9 +98,6 @@ public class FreeCamera : MonoBehaviour private Vector3 previousPosition; public OrthographicSwitcher orthographicSwitcher; - private Bounds areaBoundingBox; - private GameObject test; - void Awake() { cameraComponent = GetComponent(); @@ -109,9 +105,6 @@ void Awake() worldPlane = new Plane(Vector3.up, Vector3.zero); - areaBoundingBox = new Bounds(); - test = GameObject.CreatePrimitive(PrimitiveType.Cube); - horizontalInput.AddListenerStarted(MoveHorizontally); verticalInput.AddListenerStarted(MoveForwardBackwards); upDownInput.AddListenerStarted(MoveUpDown); @@ -320,16 +313,6 @@ void Update() { Clamp(); } - - //lon lat amstel 1 - Coordinate coord = new Coordinate(CoordinateSystem.WGS84, 52.36748063234993, 4.901222522254939, 0); - areaBoundingBox.center = coord.ToUnity(); - areaBoundingBox.size = Vector3.one * 10000; - test.transform.position = areaBoundingBox.center; - test.transform.transform.localScale = Vector3.one * 10000; - - if(!areaBoundingBox.Contains(transform.position)) - transform.position = areaBoundingBox.ClosestPoint(transform.position); } /// diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 04d28603..731b689a 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -387,6 +387,60 @@ GameObject: type: 3} m_PrefabInstance: {fileID: 7732943800119484192} m_PrefabAsset: {fileID: 0} +--- !u!1 &645481520 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 645481521} + - component: {fileID: 645481522} + m_Layer: 0 + m_Name: minimapbbox + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &645481521 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 645481520} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 0.5, y: 0.5, z: 0.5} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 2056814322} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: -476} + m_SizeDelta: {x: 100, y: 100} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &645481522 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 645481520} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b5202f52126f648418a30116a04878fc, type: 3} + m_Name: + m_EditorClassIdentifier: + BoundingBox: + m_Center: {x: 0, y: 0, z: 0} + m_Extent: {x: 0, y: 0, z: 0} + lineWidth: 2 + lineColor: {r: 1, g: 0, b: 0, a: 1} + boxSize: 20000 --- !u!1001 &675407186 PrefabInstance: m_ObjectHideFlags: 0 @@ -982,6 +1036,12 @@ GameObject: type: 3} m_PrefabInstance: {fileID: 7732943800119484192} m_PrefabAsset: {fileID: 0} +--- !u!224 &2056814322 stripped +RectTransform: + m_CorrespondingSourceObject: {fileID: 2773908478669454240, guid: 9963fec33e379324db2affcb3f83332f, + type: 3} + m_PrefabInstance: {fileID: 7732943800119484192} + m_PrefabAsset: {fileID: 0} --- !u!1001 &596812713273688386 PrefabInstance: m_ObjectHideFlags: 0 @@ -1829,22 +1889,22 @@ PrefabInstance: - target: {fileID: 3849934062868920522, guid: 5fbb7c7c8ec47e849afba1b658f3e07e, type: 3} propertyPath: m_LocalRotation.w - value: 0.21047351 + value: 0.20970187 objectReference: {fileID: 0} - target: {fileID: 3849934062868920522, guid: 5fbb7c7c8ec47e849afba1b658f3e07e, type: 3} propertyPath: m_LocalRotation.x - value: 0.088996775 + value: 0.08872657 objectReference: {fileID: 0} - target: {fileID: 3849934062868920522, guid: 5fbb7c7c8ec47e849afba1b658f3e07e, type: 3} propertyPath: m_LocalRotation.y - value: 0.89667463 + value: 0.89676464 objectReference: {fileID: 0} - target: {fileID: 3849934062868920522, guid: 5fbb7c7c8ec47e849afba1b658f3e07e, type: 3} propertyPath: m_LocalRotation.z - value: -0.37915057 + value: -0.37942845 objectReference: {fileID: 0} - target: {fileID: 3919916255551741050, guid: 5fbb7c7c8ec47e849afba1b658f3e07e, type: 3} @@ -9279,6 +9339,10 @@ PrefabInstance: - {fileID: 5460884897478157278, guid: 9963fec33e379324db2affcb3f83332f, type: 3} - {fileID: 3246588944541065497, guid: 9963fec33e379324db2affcb3f83332f, type: 3} m_AddedGameObjects: + - targetCorrespondingSourceObject: {fileID: 2773908478669454240, guid: 9963fec33e379324db2affcb3f83332f, + type: 3} + insertIndex: 0 + addedObject: {fileID: 645481521} - targetCorrespondingSourceObject: {fileID: 8632740765308209879, guid: 9963fec33e379324db2affcb3f83332f, type: 3} insertIndex: -1 diff --git a/Assets/Scripts/UI/MinimapBoundingBoxController.cs b/Assets/Scripts/UI/MinimapBoundingBoxController.cs new file mode 100644 index 00000000..ef315685 --- /dev/null +++ b/Assets/Scripts/UI/MinimapBoundingBoxController.cs @@ -0,0 +1,86 @@ +using Netherlands3D.Coordinates; +using Netherlands3D.Minimap; +using UnityEngine; + +namespace Netherlands3D.Twin +{ + public class MinimapBoundingBoxController : MonoBehaviour + { + private UIBoundingBox bbox; + private WMTSMap wmtsMap; + private RectTransform minimapTransform; + private RectTransform rTransform; + private FreeCamera freeCam; + private GameObject test; + public Bounds BoundingBox; + + public float lineWidth; + public Color lineColor; + public float boxSize = 20000; + + //lon lat amstel 1 + private Coordinate coord = new Coordinate(CoordinateSystem.WGS84, 52.36748063234993, 4.901222522254939, 0); + + private void Start() + { + freeCam = FindObjectOfType(); + MinimapUI map = FindObjectOfType(); + wmtsMap = map.GetComponentInChildren(); + minimapTransform = map.GetComponent(); + rTransform = GetComponent(); + transform.SetParent(wmtsMap.transform, false); + + GameObject bboxObject = new GameObject("boundingbox"); + bboxObject.transform.SetParent(map.transform, false); + bbox = bboxObject.AddComponent(); + BoundingBox = new Bounds(); + //test = GameObject.CreatePrimitive(PrimitiveType.Cube); + } + + private Vector3 GetLocalMapPositionForWorldPosition(Vector3 unityPosition) + { + Vector3RD rdPos = CoordinateConverter.UnitytoRD(unityPosition); + Vector3 mapPos = wmtsMap.DeterminePositionOnMap(rdPos); + rTransform.localPosition = mapPos; + Vector3 worldPosition = rTransform.position; + Vector3 localPositionInGrandparent = minimapTransform.InverseTransformPoint(worldPosition); + return localPositionInGrandparent - (Vector3)minimapTransform.sizeDelta * 0.5f; + } + + private void Update() + { + Vector3 target = coord.ToUnity(); + target.y = 0; + + wmtsMap.PositionObjectOnMap(rTransform, CoordinateConverter.UnitytoRD(target)); + BoundingBox.center = target; + BoundingBox.size = new Vector3(boxSize, Mathf.Max(boxSize, 100000000), boxSize); + //test.transform.position = BoundingBox.center; + //test.transform.transform.localScale = Vector3.one * boxSize; + + UpdateMap(); + + + if (!BoundingBox.Contains(freeCam.transform.position)) + freeCam.transform.position = BoundingBox.ClosestPoint(freeCam.transform.position); + } + + private void UpdateMap() + { + RectTransform rt = wmtsMap.GetComponent(); + float width = BoundingBox.size.x; + float depth = BoundingBox.size.z; + bbox.points = new Vector2[] + { + GetLocalMapPositionForWorldPosition(BoundingBox.center + new Vector3(-0.5f * width, 0, 0.5f * depth)), + GetLocalMapPositionForWorldPosition(BoundingBox.center + new Vector3(0.5f * width, 0, 0.5f * depth)), + GetLocalMapPositionForWorldPosition(BoundingBox.center + new Vector3(0.5f * width, 0, -0.5f * depth)), + GetLocalMapPositionForWorldPosition(BoundingBox.center + new Vector3(-0.5f * width, 0, -0.5f * depth)), + GetLocalMapPositionForWorldPosition(BoundingBox.center + new Vector3(-0.5f * width, 0, 0.5f * depth)) + }; + bbox.lineWidth = lineWidth; + bbox.color = lineColor; + bbox.SetVerticesDirty(); + } + } +} diff --git a/Assets/Scripts/UI/MinimapBoundingBoxController.cs.meta b/Assets/Scripts/UI/MinimapBoundingBoxController.cs.meta new file mode 100644 index 00000000..4dbe5680 --- /dev/null +++ b/Assets/Scripts/UI/MinimapBoundingBoxController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b5202f52126f648418a30116a04878fc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/UIBoundingBox.cs b/Assets/Scripts/UI/UIBoundingBox.cs new file mode 100644 index 00000000..65d85b55 --- /dev/null +++ b/Assets/Scripts/UI/UIBoundingBox.cs @@ -0,0 +1,54 @@ +using UnityEngine; +using UnityEngine.UI; + + +namespace Netherlands3D.Twin +{ + [RequireComponent(typeof(CanvasRenderer))] + public class UIBoundingBox : MaskableGraphic + { + public Vector2[] points; // Array of points to draw lines between + public float lineWidth = 2.0f; // Width of the line + + protected override void OnPopulateMesh(VertexHelper vh) + { + vh.Clear(); + if (points == null || points.Length < 2) return; + + // Loop through each pair of points to create line segments + for (int i = 0; i < points.Length - 1; i++) + { + Vector2 start = points[i]; + Vector2 end = points[i + 1]; + AddLineSegment(vh, start, end); + } + } + + void AddLineSegment(VertexHelper vh, Vector2 start, Vector2 end) + { + // Calculate the direction and perpendicular vector for line width + Vector2 direction = end - start; + direction.Normalize(); + Vector2 perpendicular = new Vector2(-direction.y, direction.x) * (lineWidth / 2); + + // Define the four corners of the quad + Vector2 p1 = start + perpendicular; // Top left + Vector2 p2 = start - perpendicular; // Bottom left + Vector2 p3 = end - perpendicular; // Bottom right + Vector2 p4 = end + perpendicular; // Top right + + // Add the vertices for the quad + vh.AddVert(p1, color, new Vector2(0, 0)); + vh.AddVert(p2, color, new Vector2(0, 1)); + vh.AddVert(p3, color, new Vector2(1, 1)); + vh.AddVert(p4, color, new Vector2(1, 0)); + + // Calculate the starting vertex index for this quad + int startIndex = vh.currentVertCount - 4; + + // Add the two triangles that make up the quad + vh.AddTriangle(startIndex, startIndex + 1, startIndex + 2); // First triangle + vh.AddTriangle(startIndex, startIndex + 2, startIndex + 3); // Second triangle + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/UI/UIBoundingBox.cs.meta b/Assets/Scripts/UI/UIBoundingBox.cs.meta new file mode 100644 index 00000000..a8c40dcd --- /dev/null +++ b/Assets/Scripts/UI/UIBoundingBox.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 26f10f3d23430db46b7a34f016c8b1df +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: