Verified Commit 608b57c6 authored by Sebastian Höffner's avatar Sebastian Höffner
Browse files

Expanding context export to include transform component.

parent 54300443
[{"is_a":["http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Steam"],"name":"steam_0","components":{"transform":{"position":{"":[-0.0840557441115379,0.912578999996185,2.47390842437744]},"orientation":[-0.000711875502020121,-2.74777412414551E-05,0.000304955523461103,0.999999821186066]}}},{"is_a":["http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Lamp","http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Lamp","http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Lamp","http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Lamp","http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Lamp"],"name":"lamp_1","components":{"transform":{"position":{"":[-1.64600002765656,2.24000000953674,3]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Wall","http://www.ease-crc.org/ont/EASE.owl#Wall","http://www.ease-crc.org/ont/EASE.owl#Wall","http://www.ease-crc.org/ont/EASE.owl#Wall","http://www.ease-crc.org/ont/EASE.owl#Wall"],"name":"wall_2","components":{"transform":{"position":{"":[3,0,1]},"orientation":[0,0.707106828689575,0,0.707106828689575]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Floor"],"name":"floor_0","components":{"transform":{"position":{"":[3.09999990463257,-0.100000001490116,-3.09999990463257]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#PhysicalPlace"],"name":"environment_0","components":{"transform":{"position":{"":[-15,-0.050000011920929,-15]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Ceiling"],"name":"ceiling_0","components":{"transform":{"position":{"":[3.09999990463257,2.57999992370605,-3.09999990463257]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Cupboard","http://www.ease-crc.org/ont/EASE.owl#Cupboard"],"name":"cupboard_2","components":{"transform":{"position":{"":[1.36000001430511,0,2.09999990463257]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE-OBJ.owl#Pot"],"name":"pot_0","components":{}},{"is_a":["http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Window","http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Window","http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Window","http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Window","http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Window"],"name":"window_1","components":{"transform":{"position":{"":[1.62541604042053,0.785416007041931,-3.00545001029968]},"orientation":[0,1,0,0]}}},{"is_a":["http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Chair"],"name":"chair_0","components":{"transform":{"position":{"":[1.07895708084106,0,-1.34624290466309]},"orientation":[0,0.0316231548786163,0,0.999499917030334]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Drawer","http://www.ease-crc.org/ont/EASE.owl#Drawer"],"name":"drawer_1","components":{"transform":{"position":{"":[1.30631196498871,0.555086016654968,2.1399998664856]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Door","http://www.ease-crc.org/ont/EASE.owl#Door","http://www.ease-crc.org/ont/EASE.owl#Door","http://www.ease-crc.org/ont/EASE.owl#Door","http://www.ease-crc.org/ont/EASE.owl#Door","http://www.ease-crc.org/ont/EASE.owl#Door","http://www.ease-crc.org/ont/EASE.owl#Door","http://www.ease-crc.org/ont/EASE.owl#Door","http://www.ease-crc.org/ont/EASE.owl#Door"],"name":"door_10","components":{"transform":{"position":{"":[-2.15999984741211,0.1701720058918,0.413687914609909]},"orientation":[0,-0.707106828689575,0,0.707106828689575]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Wall"],"name":"wall_1","components":{"transform":{"position":{"":[3,0,3]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#Entity"],"name":"sun_0","components":{"transform":{"position":{"":[0,3,0]},"orientation":[0.22958692908287,-0.251401782035828,0.0615176223218441,0.9382444024086]}}},{"is_a":["http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Sink","http://www.ease-crc.org/ont/EASE.owl#Cupboard"],"name":"sink_0","components":{"transform":{"position":{"":[-2.07999992370605,0,2.09999990463257]},"orientation":[0,0,0,1]}}},{"is_a":["http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Chair"],"name":"chair_2","components":{"transform":{"position":{"":[-0.00044173002243042,0,-1.84847187995911]},"orientation":[0,0.999981224536896,0,0.00614215806126595]}}},{"is_a":["http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Apple"],"name":"apple_0","components":{"transform":{"position":{"":[-1.01800000667572,0.840098917484283,2.6956000328064]},"orientation":[-6.12323426292584E-17,1,6.12323426292584E-17,-3.74939939305299E-33]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Wall"],"name":"wall_7","components":{"transform":{"position":{"":[-3,0,-1]},"orientation":[0,-0.707106828689575,0,0.707106828689575]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Rack"],"name":"rack_1","components":{"transform":{"position":{"":[-2.55999994277954,1.60000002384186,-0.0599999986588955]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Stove"],"name":"stove_0","components":{"transform":{"position":{"":[0.5,0,2.09999990463257]},"orientation":[0,0,0,1]}}},{"is_a":["http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Shelf","http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Shelf"],"name":"shelf_0","components":{"transform":{"position":{"":[-2.55999994277954,1.21099996566772,-0.0599999986588955]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Cupboard","http://www.ease-crc.org/ont/EASE.owl#Cupboard"],"name":"cupboard_8","components":{"transform":{"position":{"":[-2.55999994277954,1.60000002384186,1.22000002861023]},"orientation":[0,-0.707106828689575,0,0.707106828689575]}}},{"is_a":["http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Shelf","http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Shelf"],"name":"shelf_3","components":{"transform":{"position":{"":[-2.55999994277954,1.60000002384186,2.5]},"orientation":[0,-0.707106828689575,0,0.707106828689575]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Refrigerator"],"name":"refrigerator_0","components":{"transform":{"position":{"":[2.22000002861023,0,2.09999990463257]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Door"],"name":"door_7","components":{"transform":{"position":{"":[2.11932611465454,0.217418000102043,2.16999983787537]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Door"],"name":"door_6","components":{"transform":{"position":{"":[2.11932611465454,1.30259597301483,2.16999983787537]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Door"],"name":"door_3","components":{"transform":{"position":{"":[-1.16631197929382,1.65368807315826,2.59999990463257]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Door"],"name":"door_2","components":{"transform":{"position":{"":[-0.413688004016876,1.65368807315826,2.59999990463257]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Cupboard"],"name":"cupboard_7","components":{"transform":{"position":{"":[-0.360000014305115,1.60000002384186,2.57999992370605]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Rack"],"name":"rack_0","components":{"transform":{"position":{"":[-2.55999994277954,1.60000002384186,2.5]},"orientation":[0,-0.707106828689575,0,0.707106828689575]}}},{"is_a":["http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Cup","http://www.ease-crc.org/ont/EASE.owl#DesignedContainer"],"name":"cup_0","components":{"transform":{"position":{"":[-2.57680010795593,0.838436722755432,1.73479998111725]},"orientation":[-1.3969840395589E-08,-0.918447494506836,1.11758726717426E-08,-0.395542949438095]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Room"],"name":"kitchen_1","components":{"transform":{"position":{"":[0,0,0]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Countertop"],"name":"counter_0","components":{"transform":{"position":{"":[-2.07999992370605,0,2.07999992370605]},"orientation":[0,0,0,1]}}},{"is_a":["http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Chair"],"name":"chair_1","components":{"transform":{"position":{"":[0.412418007850647,0,-1.32948207855225]},"orientation":[0,-0.0111704673618078,0,0.999937653541565]}}},{"is_a":["http://www.ease-crc.org/ont/EASE-OBJ.owl#Lid"],"name":"lid_0","components":{"transform":{"position":{"":[-0.358455181121826,0.84524142742157,2.5877947807312]},"orientation":[-0.0100866016000509,0.382520109415054,0.0244066566228867,0.923569679260254]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Table"],"name":"table_0","components":{"transform":{"position":{"":[1.43400001525879,0,-2.04800009727478]},"orientation":[0,0,0,1]}}},{"is_a":["http://ease-ph.glpages.informatik.uni-bremen.de/dlu/dlu/EASE-DLUext.owl#Chair"],"name":"chair_3","components":{"transform":{"position":{"":[0.748000383377075,0,-1.85008120536804]},"orientation":[0,0.999948978424072,0,0.0101014049723744]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Cupboard","http://www.ease-crc.org/ont/EASE.owl#Cupboard"],"name":"cupboard_0","components":{"transform":{"position":{"":[-2.09999990463257,0,0.359999924898148]},"orientation":[0,-0.707106828689575,0,0.707106828689575]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Wall"],"name":"wall_4","components":{"transform":{"position":{"":[3,0,-1]},"orientation":[0,0.707106828689575,0,0.707106828689575]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Cupboard"],"name":"cupboard_5","components":{"transform":{"position":{"":[-2.55999994277954,1.60000002384186,2.07800006866455]},"orientation":[0,-0.707106828689575,0,0.707106828689575]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Countertop"],"name":"counter_1","components":{"transform":{"position":{"":[-2.09999990463257,0,-0.539999961853027]},"orientation":[0,0,0,1]}}},{"is_a":["http://www.ease-crc.org/ont/EASE.owl#Wall"],"name":"wall_6","components":{"transform":{"position":{"":[-3,0,3]},"orientation":[0,-0.707106828689575,0,0.707106828689575]}}}]
\ No newline at end of file
fileFormatVersion: 2
guid: 431449616a5bc4aee9001c37457c42ab
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -12,6 +12,7 @@ public class SceneControllerEditor : Editor
{
private bool showLabels;
private bool exportContext;
private JSONArray sceneJson;
public override void OnInspectorGUI()
{
......@@ -56,14 +57,16 @@ public class SceneControllerEditor : Editor
if (exportContext)
{
JSONArray sceneJson = sc.GenerateContextJSON();
if (sceneJson == null || GUILayout.Button("Refresh scene JSON"))
{
sceneJson = sc.GenerateContextJSON();
}
EditorGUILayout.TextArea(sceneJson.ToString());
string exportFile = EditorGUILayout.TextField("Export file", "Assets/DLU/Resources/context.json");
if (GUILayout.Button("Export to file"))
{
File.WriteAllText(exportFile, sceneJson.ToString());
}
}
EditorGUILayout.EndFoldoutHeaderGroup();
......
......@@ -3,7 +3,7 @@ using UnityEngine;
namespace dlu
{
public class InstanceIdentifier : SemanticBehaviour
public class InstanceIdentifier : MonoBehaviour
{
public new string name;
}
......
......@@ -12,6 +12,12 @@ public class SceneController : MonoBehaviour
[HideInInspector]
public SemanticBehaviour[] semanticBehaviours;
public SceneController()
{
JSONNode.VectorContainerType = JSONContainerType.Object;
JSONNode.QuaternionContainerType = JSONContainerType.Object;
}
public void Start()
{
if (semanticBehaviours == null)
......@@ -57,26 +63,34 @@ public class SceneController : MonoBehaviour
JSONObject jsonObject = null;
if (!sceneDict.ContainsKey(sb.name))
{
sceneDict[sb.name] = new JSONObject();
sceneDict[sb.name].Add("is_a", new JSONArray());
jsonObject = new JSONObject();
jsonObject.Add("is_a", new JSONArray());
jsonObject.Add("name", sb.GetComponent<InstanceIdentifier>().name);
jsonObject.Add("components", new JSONObject());
sceneDict[sb.name] = jsonObject;
sceneArray.Add(sceneDict[sb.name]);
}
jsonObject = sceneDict[sb.name];
jsonObject["is_a"].Add(sb.is_a);
switch (sb)
{
case InstanceIdentifier identifier: HandleInstanceIdentifier(jsonObject, identifier); break;
case Entity entity: Handle(jsonObject, entity); break;
default:
Debug.LogWarning("Trying to add SemanticBehaviour to JSON, but no case exists.", sb);
Debug.LogWarning($"No Handler for SemanticBehaviour \"{sb.GetType().Name}\"");
break;
}
}
return sceneArray;
}
private void HandleInstanceIdentifier(JSONObject jsonObject, InstanceIdentifier identifier)
private void Handle(JSONObject jsonObject, Entity entity)
{
jsonObject["name"] = identifier.name;
JSONObject transform = new JSONObject();
transform["position"] = entity.transform.position;
transform["orientation"] = entity.transform.rotation;
jsonObject["components"]["transform"] = transform;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment