Commit 04aa7021 authored by BRUNEAU Julien's avatar BRUNEAU Julien
Browse files

Merge branch 'dev'

# Conflicts:
#	Assets/Scripts/Menu/MenuManager.cs
#	Scenarios/ExampleFollow.xml
parents 04b032b0 50d8e7ca
fileFormatVersion: 2
guid: 42390f8e53a82ec43b071178ef245c55
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}
serializedVersion: 7
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: 2
wrapV: 2
wrapW: 2
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: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 8955e68877c90c347a4a186db39f9713
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 8b98398441c2b0a498faa12d0dd8f8cf
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: e7b9e93325cae8a4e97a1d3af4a24d03
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -38,6 +38,7 @@ public class CustomEditor_LoadEnv : Editor
if (GUILayout.Button("Create Template Config Files"))
{
ConfigReader.CreateTemplate();
ObstaclesReader.CreateTemplate();
}
}
}
......
......@@ -321,16 +321,23 @@ public class FollowTrajectory : MonoBehaviour
if(!_IsLaunchable && _bIsDone)
return;
if(_SyncLaunchWithTrajectory && (CurrentTime<_Myreader.mSkeleton[0][0]))
if(_SyncLaunchWithTrajectory && CurrentTime < _Myreader.mSkeleton[0][0] && 0.2 < _Myreader.mSkeleton[0][0])
{
CurrentTime += Time.deltaTime;
_ObjectInterface.Hide();
return;
}
else if (fCurrentTime > _Myreader.mSkeleton[_Myreader.mSkeleton.Count-1][0])
{
GameObject.Destroy(this.gameObject);
return;
}
else
_ObjectInterface.Show();
if(!_ChangingParent && transform.parent != null)
if (!_ChangingParent && transform.parent != null)
{
if(_InitialPositionWhenChangingParent == Vector3.zero)
{
......
......@@ -25,11 +25,11 @@ using UnityEngine;
public class ObjectInterface
{
protected GameObject _MyObj;
protected MeshRenderer _MeshRenderer = null;
protected SkinnedMeshRenderer _MeshRenderer = null;
public void Init(GameObject obj)
{
_MyObj = obj;
_MeshRenderer = _MyObj.GetComponent<MeshRenderer>();
_MeshRenderer = _MyObj.GetComponentInChildren<SkinnedMeshRenderer>();
}
public virtual void Show()
{
......
......@@ -66,7 +66,7 @@ public class TrajectoryReader
{
// While there's lines left in the text file, do this:
int iCurrentIndex = 0;
line = theReader.ReadLine(); // skip the first line
//line = theReader.ReadLine(); // skip the first line
do
{
line = theReader.ReadLine();
......
......@@ -209,7 +209,7 @@ public class LoadEnv : MonoBehaviour
// Setup of the CSV filename and disable the start synchro
tmpFollower = temp.GetComponent<FollowTrajectory>();
tmpFollower.SetCsvFilename(f.FullName);
tmpFollower._SyncLaunchWithTrajectory = false; // start the character when the simulation start not at the csv time
tmpFollower._SyncLaunchWithTrajectory = true; // start the character at the csv time
i++;
}
......
/* Crowd Simulator Engine
** Copyright (C) 2018 - Inria Rennes - Rainbow - Julien Pettre
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
** Authors: Julien Bruneau
**
** Contact: crowd_group@inria.fr
*/
/* Crowd Simulator Engine
** Copyright (C) 2018 - Inria Rennes - Rainbow - Julien Pettre
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
** Authors: Julien Bruneau
**
** Contact: crowd_group@inria.fr
*/
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
......@@ -30,6 +30,7 @@ using UnityEngine.UI;
public class MenuManager : MonoBehaviour {
string configPath;
ObstaclesReader obstReader;
Camera cam;
InputField inputConfigPath;
......@@ -41,11 +42,11 @@ public class MenuManager : MonoBehaviour {
configPath = null;
cam = Camera.main;
menu=GameObject.FindGameObjectWithTag("Menu");
string dataPath = defaultScenarioPath();
menu=GameObject.FindGameObjectWithTag("Menu");
obstReader = new ObstaclesReader();
string dataPath = defaultScenarioPath();
inputConfigPath = menu.GetComponentInChildren<InputField>();
inputConfigPath.text = dataPath;
......@@ -56,54 +57,54 @@ public class MenuManager : MonoBehaviour {
}
public string defaultScenarioPath()
{
string pathPlayer = Application.dataPath;
int lastIndex = pathPlayer.LastIndexOf('/');
string dataPath = pathPlayer.Remove(lastIndex, pathPlayer.Length - lastIndex);
string scenarioPath = dataPath + "/Scenarios";
if (Directory.Exists(scenarioPath))
return scenarioPath;
return dataPath;
public string defaultScenarioPath()
{
string pathPlayer = Application.dataPath;
int lastIndex = pathPlayer.LastIndexOf('/');
string dataPath = pathPlayer.Remove(lastIndex, pathPlayer.Length - lastIndex);
string scenarioPath = dataPath + "/Scenarios";
if (Directory.Exists(scenarioPath))
return scenarioPath;
return dataPath;
}
public void updateConfigList(string NewPath)
{
if (configFilesMenu == null)
return;
DirectoryInfo dir;
if (Directory.Exists(inputConfigPath.text))
public void updateConfigList(string NewPath)
{
if (configFilesMenu == null)
return;
DirectoryInfo dir;
if (Directory.Exists(inputConfigPath.text))
dir = new DirectoryInfo(inputConfigPath.text);
else
{
string dataPath = defaultScenarioPath();
dir = new DirectoryInfo(dataPath);
else
{
string dataPath = defaultScenarioPath();
dir = new DirectoryInfo(dataPath);
}
FileInfo[] infos = dir.GetFiles("*.xml");
configFilesMenu.options.Clear();
configFilesMenu.options.Add(new Dropdown.OptionData("NONE"));
foreach (FileInfo i in infos)
{
configFilesMenu.options.Add(new Dropdown.OptionData(i.Name.Remove(i.Name.Length-4)));
}
configFilesMenu.value = 0;
configFilesMenu.RefreshShownValue();
configFilesMenu.options.Clear();
configFilesMenu.options.Add(new Dropdown.OptionData("NONE"));
foreach (FileInfo i in infos)
{
configFilesMenu.options.Add(new Dropdown.OptionData(i.Name.Remove(i.Name.Length-4)));
}
configFilesMenu.value = 0;
configFilesMenu.RefreshShownValue();
}
public void updateConfigFile(int i)
{
if (configFilesMenu == null || configFilesMenu.value == 0)
return;
configPath = inputConfigPath.text + '\\' + configFilesMenu.options[configFilesMenu.value].text + ".xml";
public void updateConfigFile(int i)
{
if (configFilesMenu == null || configFilesMenu.value == 0)
return;
configPath = inputConfigPath.text + '\\' + configFilesMenu.options[configFilesMenu.value].text + ".xml";
//cam.transform.position = ConfigReader.camPosition;
//cam.transform.rotation = Quaternion.Euler(ConfigReader.camRotation);
//cam.transform.rotation = Quaternion.Euler(ConfigReader.camRotation);
}
// Update is called once per frame
......@@ -116,7 +117,9 @@ public class MenuManager : MonoBehaviour {
if (configPath == null || configFilesMenu.value == 0)
return;
ConfigReader.loadConfig(configPath);
ConfigReader.LoadConfig(configPath);
obstReader.clear();
obstReader.createObstacles(ConfigReader.obstaclesFile, ConfigReader.stageInfos);
LoadEnv env =gameObject.GetComponent<LoadEnv>();
env.loadScenario(ConfigReader.trajectoriesDir);
......@@ -130,11 +133,11 @@ public class MenuManager : MonoBehaviour {
public void saveConfig()
{
ConfigReader.CreateXML(configPath);
ConfigReader.SaveConfig(configPath);
}
public void exit()
{
Application.Quit();
}
}
}
\ No newline at end of file
......@@ -37,7 +37,7 @@ public static class ConfigReader
static ConfigData data; // Config data loaded from xml file
#endregion
/// <summary>
/// <summary>
/// Manage configuration: Load XML file or create default one
/// </summary>
static ConfigReader()
......@@ -50,21 +50,22 @@ public static class ConfigReader
data = new ConfigData();
}
static public void loadConfig(string path)
static public void LoadConfig(string path)
{
configFileName = path;
if (File.Exists(path))
{
string _info = LoadXML();
if (_info.ToString() != "")
{
data = (ConfigData)DeserializeObject(_info);
}
data= XMLLoader.LoadXML<ConfigData>(path);
}
}
public static void SaveConfig(string path)
{
XMLLoader.CreateXML<ConfigData>(path, data);
}
/// <summary>
/// Create a template config with all possible parameters
/// </summary>
......@@ -74,106 +75,25 @@ public static class ConfigReader
int lastIndex = pathPlayer.LastIndexOf('/');
string dataPath = pathPlayer.Remove(lastIndex, pathPlayer.Length - lastIndex);
data = new ConfigData();
data.colorList = new List<ConfigAgentColor>();
data.colorList.Add(new ConfigAgentColor(0, 1, 191, 1, 0, 0));
data.colorList.Add(new ConfigAgentColor(192, 1, 383, 0, 1, 0));
CreateXML(dataPath + @" / ConfigTemplate.xml");
ConfigData template = new ConfigData();
template.colorList = new List<ConfigAgentColor>();
template.colorList.Add(new ConfigAgentColor(0, 1, 191, 1, 0, 0));
template.colorList.Add(new ConfigAgentColor(192, 1, 383, 0, 1, 0));
XMLLoader.CreateXML<ConfigData>(dataPath + @" / ConfigTemplate.xml", template);
}
#region XMLserialization
/// <summary>
/// Create the file config.XML
/// </summary>
static public void CreateXML()
{
CreateXML(configFileName);
}
/// <summary>
/// Create a config file
/// </summary>
/// <param name="filename">The name of the config</param>
static public void CreateXML(string filename)
{
StreamWriter writer;
FileInfo t = new FileInfo(filename);
if (!t.Exists)
{
writer = t.CreateText();
}
else
{
t.Delete();
writer = t.CreateText();
}
writer.Write(SerializeObject(data));
writer.Close();
}
/// <summary>
/// Read a file
/// </summary>
/// <returns>The complete string of the file</returns>
static string LoadXML()
{
StreamReader r = File.OpenText(configFileName);
string _info = r.ReadToEnd();
r.Close();
return _info;
}
/// <summary>
/// Serialize an object into an XML text
/// </summary>
/// <param name="pObject">Objct to serialze</param>
/// <returns>XML string representing the inout object</returns>
static string SerializeObject(object pObject)
{
string XmlizedString = null;
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xs = new XmlSerializer(typeof(ConfigData));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
xmlTextWriter.Formatting= Formatting.Indented;
xs.Serialize(xmlTextWriter, pObject);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
return XmlizedString;
}
/// <summary>
/// Parse and XML file to deserialize a c# object
/// </summary>
/// <param name="pXmlizedString">XML string to parse</param>
/// <returns>C# object deserialzed from the XML string</returns>
static object DeserializeObject(string pXmlizedString)
{
XmlSerializer xs = new XmlSerializer(typeof(ConfigData));
MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
return xs.Deserialize(memoryStream);
}
static string UTF8ByteArrayToString(byte[] characters)
#region get_set
static public string trajectoriesDir
{
UTF8Encoding encoding = new UTF8Encoding();
string constructedString = encoding.GetString(characters);
return (constructedString);
get { return data.env_filesPath; }
}
static byte[] StringToUTF8ByteArray(string pXmlString)
static public ConfigStage stageInfos
{
UTF8Encoding encoding = new UTF8Encoding();
byte[] byteArray = encoding.GetBytes(pXmlString);
return byteArray;
get { return data.env_stageInfos; }
}
#endregion
#region get_set
static public string trajectoriesDir
static public string obstaclesFile
{
get { return data.env_filesPath; }
get { return data.env_obstFile; }
}
static public Vector3 camPosition
{
......@@ -242,6 +162,8 @@ public class ConfigData
// Evironnement config
public string env_filesPath;
public string env_obstFile;
public ConfigStage env_stageInfos;
// Camera config
public ConfigCam cam;
......@@ -258,6 +180,8 @@ public class ConfigData
{
// Evironnement config
env_filesPath = ".\\TrajExample\\ExampleTwoColor\\";
env_obstFile = "";
env_stageInfos = new ConfigStage();
// Camera config
cam = new ConfigCam();
......@@ -274,6 +198,25 @@ public class ConfigData
}
/// <summary>
/// Parameters of a stage to load from an AssetBundle
/// </summary>
public class ConfigStage
{
[XmlAttribute]
public string stageName;
public string file;
public ConfigVect3 position;
public ConfigVect3 rotation;
public ConfigStage() {
stageName = "";
file = "";
position = new ConfigVect3();
rotation = new ConfigVect3();
}
}
/// <summary>
/// Camera configuraton to be serialize in XML config
/// </summary>
......
/* Crowd Simulator Engine
** Copyright (C) 2018 - Inria Rennes - Rainbow - Julien Pettre
**