Commit 96573066 authored by Sylvain Renault's avatar Sylvain Renault
Browse files

Lot of new functions :-)

Group concept as KeyValue.
Visual for trackables, anchors and link via prefabs.
Edit link now run well (TODO: drag/select elements?).
Code optimization in WorldLink.
TMP Pro for UI.
parent ba624f78
Loading
Loading
Loading
Loading
+33 −10
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Last change: June 2022
// Last change: July 2022
//

#define USING_OPENAPI_GENERATOR // alt. is Swagger
@@ -25,6 +25,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using TMPro;
using ETSI.ARF.WorldStorage.REST;

#if USING_OPENAPI_GENERATOR
@@ -59,6 +60,7 @@ namespace ETSI.ARF.WorldStorage.UI
        Vector3 localCRS_pos;
        Vector3 localCRS_rot;
        byte[] trackablePayload = new byte[1] { 0 };

        [SerializeField] Dictionary<string, List<string>> keyValueTags = new Dictionary<string, List<string>>();
        string key1 = "";
        string value1 = "";
@@ -70,7 +72,7 @@ namespace ETSI.ARF.WorldStorage.UI

        public static void ShowWindow(WorldStorageServer ws, WorldStorageUser user, string UUID = "")
        {
            winSingleton = EditorWindow.GetWindow(typeof(TrackableWindow), false, WorldStorageWindow.winName) as TrackableWindow;
            winSingleton = EditorWindow.GetWindow(typeof(TrackableWindow), false, "ETSI ARF - Trackable") as TrackableWindow;
            winSingleton.worldStorageServer = ws;
            winSingleton.worldStorageUser = user;
            if (!string.IsNullOrEmpty(UUID))
@@ -80,6 +82,27 @@ namespace ETSI.ARF.WorldStorage.UI
            }
        }

        public static GameObject GenerateAndUpdateVisual(string UUID, string name, Vector3 pos, Vector3 rot)
        {
            ETSI.ARF.WorldStorage.UI.Prefabs.WorldStoragePrefabs prefabs;
            prefabs = (Prefabs.WorldStoragePrefabs)Resources.Load("ARFPrefabs");
            GameObject arf = GameObject.Find("ARF Visuals");
            GameObject visual = GameObject.Find(UUID);

            if (arf == null) arf = new GameObject("ARF Visuals");
            if (visual == null)
            {
                visual = SceneAsset.Instantiate<GameObject>(prefabs.trackablePrefab, pos, Quaternion.Euler(rot), arf.transform); // TODO rot
                visual.name = UUID;
            }
            else
            {
                visual.transform.SetPositionAndRotation(pos, Quaternion.Euler(rot));
            }
            visual.transform.Find("Canvas/Text").GetComponent<TextMeshProUGUI>().text = $"Name: { name }\nUUID: { UUID }";
            return visual;
        }

        public TrackableWindow()
        {
            // init somne stuffs
@@ -115,7 +138,7 @@ namespace ETSI.ARF.WorldStorage.UI
            EditorGUILayout.Space();

            //GUILayout.BeginHorizontal();
            customName = EditorGUILayout.TextField("Name of Trackable", customName);
            customName = EditorGUILayout.TextField("Name of Trackable:", customName);
#if isDEBUG
            GUILayout.Label("UUID: " + UUID, EditorStyles.miniLabel); // readonly
            GUILayout.Label("Creator UID: " + creatorUUID, EditorStyles.miniLabel); // readonly
@@ -171,6 +194,7 @@ namespace ETSI.ARF.WorldStorage.UI
                if (string.IsNullOrEmpty(UUID) || UUID == "0") UUID = System.Guid.Empty.ToString();
                Trackable obj = GenerateTrackable();
                UUID = TrackableRequest.AddTrackable(worldStorageServer, obj);
                UUID = UUID.Trim('"'); //Bugfix: remove " from server return value
                WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
                WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
            }
@@ -184,6 +208,7 @@ namespace ETSI.ARF.WorldStorage.UI
                {
                    Trackable obj = GenerateTrackable();
                    UUID = TrackableRequest.UpdateTrackable(worldStorageServer, obj);
                    UUID = UUID.Trim('"'); //Bugfix: remove " from server return value
                }
                WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
                WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
@@ -206,8 +231,9 @@ namespace ETSI.ARF.WorldStorage.UI

            // ###########################################################
            GUI.backgroundColor = WorldStorageWindow.arfColors[5];
            if (GUILayout.Button("Generate GameObject Component"))
            if (GUILayout.Button("Generate/Update GameObject Visual"))
            {
                GenerateAndUpdateVisual(UUID, customName, localCRS_pos, localCRS_rot);
            }
            GUI.backgroundColor = ori;
        }
@@ -224,13 +250,10 @@ namespace ETSI.ARF.WorldStorage.UI
                trackableSize = new Vector3((float)obj.TrackableSize[0], (float)obj.TrackableSize[1], (float)obj.TrackableSize[2]);
            }
            else trackableSize = Vector3.zero;

            if (obj.LocalCRS.Count == 16)
            {
                Matrix4x4 localCRS = new Matrix4x4();
                localCRS.m00 = obj.LocalCRS[0]; localCRS.m01 = obj.LocalCRS[1]; localCRS.m02 = obj.LocalCRS[2]; localCRS.m03 = obj.LocalCRS[3];
                localCRS.m10 = obj.LocalCRS[4]; localCRS.m11 = obj.LocalCRS[5]; localCRS.m12 = obj.LocalCRS[6]; localCRS.m13 = obj.LocalCRS[7];
                localCRS.m20 = obj.LocalCRS[8]; localCRS.m21 = obj.LocalCRS[9]; localCRS.m22 = obj.LocalCRS[10]; localCRS.m23 = obj.LocalCRS[11];
                localCRS.m30 = obj.LocalCRS[12]; localCRS.m31 = obj.LocalCRS[13]; localCRS.m32 = obj.LocalCRS[14]; localCRS.m33 = obj.LocalCRS[15];
                Matrix4x4 localCRS = WorldStorageWindow.MatrixFromLocalCRS(obj.LocalCRS); 
                localCRS_pos = localCRS.GetPosition();
                localCRS_rot = localCRS.rotation.eulerAngles;
            }
@@ -245,7 +268,7 @@ namespace ETSI.ARF.WorldStorage.UI
            key1 = first.Item1;
            value1 = first.Item2;
           
            this.Repaint(); // TODO
            this.Repaint();
        }

        public Trackable GenerateTrackable()
+32 −9
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using TMPro;
using ETSI.ARF.WorldStorage.REST;

#if USING_OPENAPI_GENERATOR
@@ -56,6 +57,7 @@ namespace ETSI.ARF.WorldStorage.UI
        Vector3 worldAnchorSize;
        Vector3 localCRS_pos;
        Vector3 localCRS_rot;

        [SerializeField] Dictionary<string, List<string>> keyValueTags = new Dictionary<string, List<string>>();
        string key1 = "";
        string value1 = "";
@@ -67,7 +69,7 @@ namespace ETSI.ARF.WorldStorage.UI

        public static void ShowWindow(WorldStorageServer ws, WorldStorageUser user, string UUID = "")
        {
            winSingleton = EditorWindow.GetWindow(typeof(WorldAnchorWindow), false, WorldStorageWindow.winName) as WorldAnchorWindow;
            winSingleton = EditorWindow.GetWindow(typeof(WorldAnchorWindow), false, "ETSI ARF - World Anchor") as WorldAnchorWindow;
            winSingleton.worldStorageServer = ws;
            winSingleton.worldStorageUser = user;
            if (!string.IsNullOrEmpty(UUID))
@@ -77,6 +79,27 @@ namespace ETSI.ARF.WorldStorage.UI
            }
        }

        public static GameObject GenerateAndUpdateVisual(string UUID, string name, Vector3 pos, Vector3 rot)
        {
            ETSI.ARF.WorldStorage.UI.Prefabs.WorldStoragePrefabs prefabs;
            prefabs = (Prefabs.WorldStoragePrefabs)Resources.Load("ARFPrefabs");
            GameObject arf = GameObject.Find("ARF Visuals");
            GameObject visual = GameObject.Find(UUID);

            if (arf == null) arf = new GameObject("ARF Visuals");
            if (visual == null)
            {
                visual = SceneAsset.Instantiate<GameObject>(prefabs.worldAnchorPrefab, pos, Quaternion.Euler(rot), arf.transform); // TODO rot
                visual.name = UUID;
            }
            else
            {
                visual.transform.SetPositionAndRotation(pos, Quaternion.Euler(rot));
            }
            visual.transform.Find("Canvas/Text").GetComponent<TextMeshProUGUI>().text = $"Name: { name }\nUUID: { UUID }";
            return visual;
        }

        public WorldAnchorWindow()
        {
            // init somne stuffs
@@ -112,7 +135,7 @@ namespace ETSI.ARF.WorldStorage.UI
            EditorGUILayout.Space();

            //GUILayout.BeginHorizontal();
            customName = EditorGUILayout.TextField("Name of Anchor", customName);
            customName = EditorGUILayout.TextField("Name of Anchor:", customName);
#if isDEBUG
            GUILayout.Label("UUID: " + UUID, EditorStyles.miniLabel); // readonly
            GUILayout.Label("Creator UID: " + creatorUUID, EditorStyles.miniLabel); // readonly
@@ -156,6 +179,7 @@ namespace ETSI.ARF.WorldStorage.UI
                if (string.IsNullOrEmpty(UUID) || UUID == "0") UUID = System.Guid.Empty.ToString();
                WorldAnchor obj = GenerateWorldAnchor();
                UUID = WorldAnchorRequest.AddWorldAnchor(worldStorageServer, obj);
                UUID = UUID.Trim('"'); //Bugfix: remove " from server return value
                WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
                WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
            }
@@ -169,6 +193,7 @@ namespace ETSI.ARF.WorldStorage.UI
                {
                    WorldAnchor obj = GenerateWorldAnchor();
                    UUID = WorldAnchorRequest.UpdateWorldAnchor(worldStorageServer, obj);
                    UUID = UUID.Trim('"'); //Bugfix: remove " from server return value
                    WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
                    WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
                }
@@ -190,8 +215,9 @@ namespace ETSI.ARF.WorldStorage.UI

            // ###########################################################
            GUI.backgroundColor = WorldStorageWindow.arfColors[5];
            if (GUILayout.Button("Generate GameObject Component"))
            if (GUILayout.Button("Generate/Update GameObject Visual"))
            {
                GenerateAndUpdateVisual(UUID, customName, localCRS_pos, localCRS_rot);
            }
            GUI.backgroundColor = ori;
        }
@@ -207,13 +233,10 @@ namespace ETSI.ARF.WorldStorage.UI
                worldAnchorSize = new Vector3((float)obj.WorldAnchorSize[0], (float)obj.WorldAnchorSize[1], (float)obj.WorldAnchorSize[2]);
            }
            else worldAnchorSize = Vector3.zero;

            if (obj.LocalCRS.Count == 16)
            {
                Matrix4x4 localCRS = new Matrix4x4();
                localCRS.m00 = obj.LocalCRS[0]; localCRS.m01 = obj.LocalCRS[1]; localCRS.m02 = obj.LocalCRS[2]; localCRS.m03 = obj.LocalCRS[3];
                localCRS.m10 = obj.LocalCRS[4]; localCRS.m11 = obj.LocalCRS[5]; localCRS.m12 = obj.LocalCRS[6]; localCRS.m13 = obj.LocalCRS[7];
                localCRS.m20 = obj.LocalCRS[8]; localCRS.m21 = obj.LocalCRS[9]; localCRS.m22 = obj.LocalCRS[10]; localCRS.m23 = obj.LocalCRS[11];
                localCRS.m30 = obj.LocalCRS[12]; localCRS.m31 = obj.LocalCRS[13]; localCRS.m32 = obj.LocalCRS[14]; localCRS.m33 = obj.LocalCRS[15];
                Matrix4x4 localCRS = WorldStorageWindow.MatrixFromLocalCRS(obj.LocalCRS);
                localCRS_pos = localCRS.GetPosition();
                localCRS_rot = localCRS.rotation.eulerAngles;
            }
@@ -228,7 +251,7 @@ namespace ETSI.ARF.WorldStorage.UI
            key1 = first.Item1;
            value1 = first.Item2;

            this.Repaint(); // TODO
            this.Repaint();
        }

        public WorldAnchor GenerateWorldAnchor()
+160 −102

File changed.

Preview size limit exceeded, changes collapsed.

+57 −38
Original line number Diff line number Diff line
@@ -121,7 +121,7 @@ namespace ETSI.ARF.WorldStorage.UI
#endif

            GUI.backgroundColor = WorldStorageWindow.arfColors[4];
            if (GUILayout.Button("Open World Representation Graph Window..."))
            if (GUILayout.Button("Open World Graph Window..."))
            {
                GraphWindow.ShowWindow();
            }
@@ -205,7 +205,7 @@ namespace ETSI.ARF.WorldStorage.UI
            // ###########################################################
            #region Filter
            EditorGUILayout.Space(10);
            filterByKeyValueTag = EditorGUILayout.TextField("Filter Value (Key = Group):", filterByKeyValueTag);
            filterByKeyValueTag = EditorGUILayout.TextField("Filter for KeyValue Group:", filterByKeyValueTag);
            #endregion

            // ###########################################################
@@ -229,6 +229,8 @@ namespace ETSI.ARF.WorldStorage.UI

            GUI.backgroundColor = WorldStorageWindow.arfColors[3];
            if (GUILayout.Button("Delete all Trackables (3 stay in!!!)"))
            {
                if (EditorUtility.DisplayDialog("Deleting elements", "Do you really want to delete all trackables?", "Yes", "No"))
                {
                    Debug.Log("Deleting all Trackable ");
                    int n = 0;
@@ -247,6 +249,7 @@ namespace ETSI.ARF.WorldStorage.UI
                    GetTrackables();
                    WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
                }
            }
            GUI.backgroundColor = ori;
           
            // Show list
@@ -304,6 +307,8 @@ namespace ETSI.ARF.WorldStorage.UI

            GUI.backgroundColor = WorldStorageWindow.arfColors[3];
            if (GUILayout.Button("Delete all World Anchors (3 stay in!!!)"))
            {
                if (EditorUtility.DisplayDialog("Deleting elements", "Do you really want to delete all anchors?", "Yes", "No"))
                {
                    Debug.Log("Deleting all World Anchors ");
                    int n = 0;
@@ -322,6 +327,7 @@ namespace ETSI.ARF.WorldStorage.UI
                    GetWorldAnchors();
                    WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
                }
            }
            GUI.backgroundColor = ori;

            // Show list
@@ -379,6 +385,8 @@ namespace ETSI.ARF.WorldStorage.UI

            GUI.backgroundColor = WorldStorageWindow.arfColors[3];
            if (GUILayout.Button("Delete all World Links (3 stay in!!!)"))
            {
                if (EditorUtility.DisplayDialog("Deleting elements", "Do you really want to delete all links?", "Yes", "No"))
                {
                    Debug.Log("Deleting all World Links");
                    int n = 0;
@@ -397,6 +405,7 @@ namespace ETSI.ARF.WorldStorage.UI
                    GetWorldLinks();
                    WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
                }
            }
            GUI.backgroundColor = ori;

            // Show list
@@ -482,6 +491,16 @@ namespace ETSI.ARF.WorldStorage.UI
            return ("", "");
        }

        static public Matrix4x4 MatrixFromLocalCRS(List<float> localCRS)
        {
            Matrix4x4 matrix = new Matrix4x4();
            matrix.m00 = localCRS[0]; matrix.m01 = localCRS[1]; matrix.m02 = localCRS[2]; matrix.m03 = localCRS[3];
            matrix.m10 = localCRS[4]; matrix.m11 = localCRS[5]; matrix.m12 = localCRS[6]; matrix.m13 = localCRS[7];
            matrix.m20 = localCRS[8]; matrix.m21 = localCRS[9]; matrix.m22 = localCRS[10]; matrix.m23 = localCRS[11];
            matrix.m30 = localCRS[12]; matrix.m31 = localCRS[13]; matrix.m32 = localCRS[14]; matrix.m33 = localCRS[15];
            return matrix;
        }

        public void GetTrackables()
        {
            // Get all objects
+36 −0
Original line number Diff line number Diff line
//
// ARF - Augmented Reality Framework (ETSI ISG ARF)
//
// Copyright 2022 ETSI
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Last change: July 2022
//

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace ETSI.ARF.WorldStorage.UI.Prefabs
{
    [System.Serializable]
    [CreateAssetMenu(fileName = "ARFPrefabs", menuName = "ARF World Storage/Setup for Visuals (prefabs)", order = 1)]
    public class WorldStoragePrefabs : ScriptableObject
    {
        [SerializeField] public GameObject trackablePrefab;
        [SerializeField] public GameObject worldAnchorPrefab;
        [SerializeField] public GameObject worldLinkPrefab;
    }
}
 No newline at end of file
Loading