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

Moving the cup with iTween

parent a58dae6b
......@@ -13,8 +13,6 @@ public class SceneControllerEditor : Editor
{
private bool showLabels = false;
public SemanticBehaviour[] semanticBehaviours;
private JSONArray sceneJson;
private JSONArray instructionJson;
......@@ -27,32 +25,32 @@ public class SceneControllerEditor : Editor
public override void OnInspectorGUI()
{
SceneController sc = (SceneController) target;
base.DrawDefaultInspector();
if (sc.semanticBehaviours == null || GUILayout.Button("Refresh list of semantic labels"))
{
sc.semanticBehaviours = sc.FindSemanticLabels();
}
this.ImportInstruction(sc);
EditorGUILayout.Space();
base.DrawDefaultInspector();
ImportInstruction(sc);
EditorGUILayout.Space();
this.ExportContext(sc);
ExportContext(sc);
EditorGUILayout.Space();
this.ShowSemanticLabels(sc);
ShowSemanticLabels(sc);
}
private void ShowSemanticLabels(SceneController sc)
{
showLabels = EditorGUILayout.BeginFoldoutHeaderGroup(showLabels, "Semantic labels");
if (showLabels)
{
if (this.semanticBehaviours == null || GUILayout.Button("Refresh list of semantic labels"))
{
FindSemanticLabels();
}
foreach (SemanticBehaviour sb in this.semanticBehaviours)
foreach (SemanticBehaviour sb in sc.semanticBehaviours)
{
string label = sb.GetComponent<InstanceIdentifier>().name;
// Fill dict
if (sb.is_a.Count() > 0)
{
label += $" a {sb.is_a.Split('#')[1]}";
......@@ -69,7 +67,7 @@ public class SceneControllerEditor : Editor
string exportFile = EditorGUILayout.TextField("Export Context File", "Assets/DLU/Resources/context.json");
if (sceneJson == null)
{
sceneJson = this.GenerateContextJSON();
sceneJson = GenerateContextJSON(sc);
}
if (GUILayout.Button("Export to file"))
{
......@@ -87,22 +85,13 @@ public class SceneControllerEditor : Editor
EditorGUILayout.TextArea(sc.instruction == null ? "" : sc.instruction.ToString());
}
public void FindSemanticLabels()
{
this.semanticBehaviours = GameObject.FindObjectsOfType<SemanticBehaviour>();
}
public JSONArray GenerateContextJSON()
public JSONArray GenerateContextJSON(SceneController sc)
{
if (this.semanticBehaviours == null)
{
FindSemanticLabels();
}
Dictionary<string, JSONObject> sceneDict = new Dictionary<string, JSONObject>();
JSONArray sceneArray = new JSONArray();
foreach (SemanticBehaviour sb in this.semanticBehaviours)
foreach (SemanticBehaviour sb in sc.semanticBehaviours)
{
JSONObject jsonObject = null;
string name = sb.GetComponent<InstanceIdentifier>().name;
......
using UnityEngine;
using SimpleJSON;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace dlu
{
public class SceneController : MonoBehaviour
{
public string importInstructionFile = "Assets/DLU/Resources/instruction.json";
[HideInInspector]
public JSONArray instruction = null;
public string importInstructionFile = "Assets/DLU/Resources/instruction.json";
private SemanticBehaviour[] _semanticBehaviours;
private Dictionary<string, GameObject> sceneDict; // = new Dictionary<string, GameObject>();
[HideInInspector]
public SemanticBehaviour[] semanticBehaviours {
get
{
return this._semanticBehaviours;
}
set
{
sceneDict = new Dictionary<string, GameObject>();
foreach (SemanticBehaviour sb in value)
{
sceneDict[sb.GetComponent<InstanceIdentifier>().name] = sb.gameObject;
}
this._semanticBehaviours = value;
}
}
public void Start()
{
if (this.instruction == null)
if (instruction == null)
{
instruction = LoadInstruction(importInstructionFile);
}
if (semanticBehaviours == null)
{
this.instruction = LoadInstruction(this.importInstructionFile);
semanticBehaviours = FindSemanticLabels();
}
StartCoroutine(EvaluateInstruction());
}
public JSONArray LoadInstruction(string json)
{
return JSON.Parse(File.ReadAllText(json)) as JSONArray;
}
public SemanticBehaviour[] FindSemanticLabels()
{
return GameObject.FindObjectsOfType<SemanticBehaviour>();
}
public IEnumerator EvaluateInstruction()
{
Dictionary<string, JSONObject> taskDict = new Dictionary<string, JSONObject>();
JSONObject task = null;
// Populate quick access dict and search for task
foreach (JSONObject jo in instruction)
{
taskDict[jo["name"]] = jo;
if (task == null && jo.HasKey("classifies"))
{
task = jo;
Debug.Log($"Task identified: {task}");
}
}
// If no task is found, stop
if (task == null)
{
Debug.LogError("No task found!");
yield return null;
}
else // if task is found, execute actions
{
foreach (JSONNode action in task["classifies"])
{
yield return ExecuteAction(action, taskDict);
}
}
}
public IEnumerator ExecuteAction(string actionName, Dictionary<string, JSONObject> taskDict)
{
JSONObject action = taskDict[actionName];
Debug.Log($"Performing action {actionName}: {action}");
List<string> participants = new List<string>();
foreach (JSONNode participant in action["hasParticipant"])
{
Debug.Log($"Participant: {participant}");
foreach(JSONNode is_a in taskDict[participant]["is_a"])
{
if (is_a != "http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#PhysicalAgent")
{
participants.Add(participant);
}
}
}
foreach (string participant in participants)
{
GameObject targetGO = new GameObject($"Target of {participant}");
Vector3 position = taskDict[participant]["components"]["transform"]["position"];
Quaternion orientation = taskDict[participant]["components"]["transform"]["orientation"];
targetGO.transform.SetPositionAndRotation(position, orientation);
double speed = taskDict[participant]["components"].HasKey("speed") ? taskDict[participant]["components"]["speed"].AsDouble : 1.0;
Hashtable arguments = new Hashtable();
arguments["name"] = actionName;
arguments["position"] = targetGO.transform;
arguments["speed"] = speed;
iTween.MoveTo(sceneDict[participant], arguments);
}
yield return null;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 8c4549a83b3ae4236b2d999ec7eb0d71
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: ab52eab86b3cf4f71831ad90648ef72e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 87e6af88d13064ce38ef549bbdb90840
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 20f5496af0a1a4ac1bcc8850db15c00a
folderAsset: yes
timeCreated: 1516932782
licenseType: Store
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 70ae88ee4c1a745d0819de61ec68af19
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: -1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
- serializedVersion: 3
buildTarget: iPhone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 2d2cb0af9aa924b12bd57127320643a3
folderAsset: yes
timeCreated: 1504197499
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
iTween can be used with all scripting languages that Unity supports including JavaScript, C# and Boo. To install iTween create a folder named "Plugins" in your project's assets (if you are using C# the location of iTween does not matter as long as it is inside your assets folder).
For complete documentation, examples and information visit: http://itween.pixelplacement.com
\ No newline at end of file
fileFormatVersion: 2
guid: b68b11cac1ab04f95985e32ea67b8435
TextScriptImporter:
userData:
fileFormatVersion: 2
guid: 2b4957ecfb9d44cb59b99d2305c1848c
folderAsset: yes
DefaultImporter:
userData:
using UnityEngine;
using System.Collections;
public class MoveSample : MonoBehaviour
{
void Start(){
iTween.MoveBy(gameObject, iTween.Hash("x", 2, "easeType", "easeInOutExpo", "loopType", "pingPong", "delay", .1));
}
}
fileFormatVersion: 2
guid: 93cb45d44c16f45a4bbd5099fe096c20
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
using UnityEngine;
using System.Collections;
public class RotateSample : MonoBehaviour
{
void Start(){
iTween.RotateBy(gameObject, iTween.Hash("x", .25, "easeType", "easeInOutBack", "loopType", "pingPong", "delay", .4));
}
}
fileFormatVersion: 2
guid: d6bc01eb564f142a1ada6ced5215636a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 8
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
m_AmbientEquatorColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
m_AmbientGroundColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 3
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
--- !u!157 &4
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 9
m_Resolution: 1
m_BakeResolution: 50
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AO: 1
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 0
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 1
m_BakeBackend: 0
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringMode: 0
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 0
--- !u!196 &5
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666666
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &795364717
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 795364718}
- component: {fileID: 795364719}
- component: {fileID: 795364721}
- component: {fileID: 795364722}
- component: {fileID: 795364720}
- component: {fileID: 795364723}
m_Layer: 0
m_Name: Main Camera