...
 
Commits (2)
fileFormatVersion: 2
guid: 374e76d5e0314e845a4b92bebd7922fe
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 98b7db83cd065e1409139224546cd45a
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 17a91259b1b03d84cb5b4f72145f8484
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using UnityEngine;
public abstract class GetMemberPosition : MonoBehaviour {
// Names of child objects to use for bounding-box computations
protected List<string> ListMember;
bool IncludePointsOutsideCamera = false;
// Id of the virtual human
public int ID { get; set; }
// Use this for initialization
void Start () {
void Start ()
{
InitList();
}
protected abstract void InitList();
void RecursiveFindPositionChild(Transform parent, string childName, List<double> Box)
void UpdateBoundingBoxRecursive(Transform transform, List<double> Box)
{
foreach (Transform child in parent)
if (ListMember.Contains(transform.name) && !IsPointBehindCamera(transform.position))
{
if (child.name == childName)
{
Camera Cam = Camera.main;
Vector3 PosW = child.gameObject.transform.position;
Vector3 PosC = Cam.WorldToScreenPoint(PosW);
if (CheckOutsideCamera(PosW, PosC))
{
Box[0] = Mathf.Min((float)Box[0], PosC.x);
Box[1] = Mathf.Min((float)Box[1], PosC.y);
Box[2] = Mathf.Max((float)Box[2], PosC.x);
Box[3] = Mathf.Max((float)Box[3], PosC.y);
}
}
else
Vector3 PosC = Camera.main.WorldToScreenPoint(transform.position);
if (IncludePointsOutsideCamera || IsPointInsideCamera(PosC))
{
RecursiveFindPositionChild(child, childName, Box);
Box[0] = Math.Min(Box[0], PosC.x);
Box[1] = Math.Min(Box[1], PosC.y);
Box[2] = Math.Max(Box[2], PosC.x);
Box[3] = Math.Max(Box[3], PosC.y);
}
}
foreach (Transform child in transform)
UpdateBoundingBoxRecursive(child, Box);
}
private bool IsPointBehindCamera(Vector3 posW)
{
return Vector3.Dot(Camera.main.transform.forward, posW - Camera.main.transform.position) < 0;
}
private bool CheckOutsideCamera(Vector3 PosW, Vector3 PosC)
private bool IsPointInsideCamera(Vector3 PosC)
{
Camera Cam = Camera.main;
// checking if worldPoint isn't behind the camera:
if (Vector3.Dot(Cam.transform.forward, PosW - Cam.transform.position) >= 0)
{
Rect screen = new Rect(0, 0, Cam.pixelWidth, Cam.pixelWidth);
// checking if screenPoint is inside the screen area:
if (screen.Contains(PosC)){
// screenPoint is a valid screen point
return true;
}
}
return false;
Rect screen = new Rect(0, 0, Cam.pixelWidth, Cam.pixelWidth);
return screen.Contains(PosC);
}
public List<double> GetBoundingBox()
{
List<double> res = new List<double> { Camera.main.pixelWidth, Camera.main.pixelHeight,0,0};
foreach (string member in ListMember)
RecursiveFindPositionChild(gameObject.transform, member,res);
// get the bounding box of all relevant points in screen coordinates
UpdateBoundingBoxRecursive(transform, res);
if (IncludePointsOutsideCamera)
{
// clamp the bounding box to the part that is actually on-screen
res[0] = Math.Max(res[0], 0);
res[1] = Math.Max(res[1], 0);
res[2] = Math.Min(res[2], Camera.main.pixelWidth);
res[3] = Math.Min(res[3], Camera.main.pixelHeight);
}
return res;
}
......
......@@ -21,7 +21,6 @@
*/
using UnityEngine;
using System.Collections;
using System.IO;
using System.Collections.Generic;
......@@ -49,7 +48,6 @@ public class LoadEnv : MonoBehaviour
float camShiftHold = 1.0f; // Control the effect of shift with holding time
#endregion
/// <summary>
/// Scene and agents initialization
/// </summary>
......@@ -104,9 +102,7 @@ public class LoadEnv : MonoBehaviour
// ---------------------
// CLEAR PREVIOUS AGENTS
foreach (GameObject a in avatars)
{
Destroy(a);
}
avatars.Clear();
// -------------
......@@ -116,29 +112,29 @@ public class LoadEnv : MonoBehaviour
if (info.Length == 0)
info = dir.GetFiles("*.txt");
FollowTrajectory tmpFollower;
var crowdParentObject = new GameObject("Crowd");
int i = 0;
foreach (FileInfo f in info)
{
// ------------------------------------------------------------
// IF NO ROCKETMAN (PROPRIETARY ASSETS), USE PLASTICMAN INSTEAD
var temp = RocketBox ? CreateAgent_RocketBox(i) : CreateAgent_PlasticMan(i);
avatars.Add(temp);
var character = RocketBox ? CreateAgent_RocketBox(i) : CreateAgent_PlasticMan(i);
character.transform.parent = crowdParentObject.transform;
avatars.Add(character);
// ---------------
// ---------------------
// SET NAME, TAG, AND ID
temp.name = gameObject.name + i.ToString("D4");
temp.tag = "Player";
var mPos = gameObject.GetComponent<GetMemberPosition>();
if (mPos != null)
mPos.ID = i; //add an id for each virtual human
character.name += i.ToString("D4");
character.tag = "Player";
character.GetComponent<GetMemberPosition>().ID = i;
// ----------------------------------
// FOLLOWTRAJECTORY SCRIPT MANAGEMENT
// Setup of the CSV filename and disable the start synchro
tmpFollower = temp.GetComponent<FollowTrajectory>();
tmpFollower.SetCsvFilename(f.FullName);
tmpFollower._SyncLaunchWithTrajectory = true; // start the character at the csv time
var follower = character.GetComponent<FollowTrajectory>();
follower.SetCsvFilename(f.FullName);
follower._SyncLaunchWithTrajectory = true; // start the character at the csv time
i++;
}
......@@ -243,7 +239,7 @@ public class LoadEnv : MonoBehaviour
// ESCAPE => EXIT APPS
if (Input.GetKeyDown(KeyCode.Escape) == true)
{
menuM.toogleMenu();
menuM.toggleMenu();
}
// -------------------------------
......
This diff is collapsed.
......@@ -101,32 +101,20 @@ public class CamRecorder : MonoBehaviour {
{
if (human.GetComponentInChildren<SkinnedMeshRenderer>().enabled)
{
List<double> Pos = null;
int Id = -1;
if (human.GetComponent<GetMemberPosition>() != null)
{
Pos = human.GetComponent<GetMemberPosition>().GetBoundingBox();
Id = human.GetComponent<GetMemberPosition>().ID;
}
else if (human.GetComponent<GetMemberPositionRocketBox>() != null)
var component = human.GetComponent<GetMemberPosition>();
if (component != null)
{
Pos = human.GetComponent<GetMemberPositionRocketBox>().GetBoundingBox();
Id = human.GetComponent<GetMemberPositionRocketBox>().ID;
}
var bbox = component.GetBoundingBox();
if (Pos != null)
{
// check bounding boxes
if (!(Pos[0] == Cam.pixelWidth) && !(Pos[0] == Cam.pixelHeight) && !(Pos[0] == 0) && !(Pos[0] == 0))
if (bbox[2] > bbox[0] && bbox[3] > bbox[1])
{
text += imageIncrement.ToString() + "," +
Id.ToString() + "," +
Pos[0].ToString().Replace(',', '.') + "," +
(Cam.pixelHeight - Pos[1]).ToString().Replace(',', '.') + "," +
Pos[2].ToString().Replace(',', '.') + "," +
(Cam.pixelHeight - Pos[3]).ToString().Replace(',', '.') + "," +
component.ID.ToString() + "," +
bbox[0].ToString().Replace(',', '.') + "," +
(Cam.pixelHeight - bbox[1]).ToString().Replace(',', '.') + "," +
bbox[2].ToString().Replace(',', '.') + "," +
(Cam.pixelHeight - bbox[3]).ToString().Replace(',', '.') + "," +
"-1,-1,-1,-1\n";
}
}
......
......@@ -15,12 +15,11 @@
** 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, Florian Berton
** Authors: Julien Bruneau, Florian Berton, Wouter van Toll
**
** Contact: crowd_group@inria.fr
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml;
......@@ -35,7 +34,7 @@ public class ObstaclesReader
XMLObstacles obst; // list of XML obstacle objects
GameObject defaultWall; // default wall used as template to create new one
GameObject defaultPillar; // default cylinder used as template to create new one
GameObject ground; // default ground used as template to create new one
GameObject defaultGround; // default ground used as template to create new one
List<GameObject> obstList; // list of created obstacles
......@@ -44,23 +43,12 @@ public class ObstaclesReader
/// </summary>
public ObstaclesReader()
{
defaultPillar = null;
defaultWall = null;
defaultPillar = Resources.Load<GameObject>("Pillar");
defaultWall = Resources.Load<GameObject>("Wall");
defaultGround = Resources.Load<GameObject>("Ground");
obst = new XMLObstacles();
obstList = new List<GameObject>();
GameObject[] obstGO = GameObject.FindGameObjectsWithTag("Obst");
foreach (GameObject g in obstGO)
{
if (g.name == "Wall")
defaultWall = g;
else if (g.name == "Pillar")
defaultPillar = g;
else if (g.name == "Ground")
ground = g;
g.SetActive(false);
}
}
/// <summary>
......@@ -92,7 +80,7 @@ public class ObstaclesReader
createCylinder(g);
}
// ----------
// LOAD STAGE (and remove the ground if a stage is loaded)
// LOAD STAGE
if (stageInfo.file != "" && stageInfo.stageName != "")
{
AssetBundle myLoadedAssetBundle = AssetBundle.LoadFromFile(stageInfo.file);
......@@ -102,18 +90,19 @@ public class ObstaclesReader
return;
}
GameObject prefab = myLoadedAssetBundle.LoadAsset<GameObject>(stageInfo.stageName);
GameObject stage = GameObject.Instantiate(prefab);
GameObject stage = Object.Instantiate(prefab);
stage.transform.position += stageInfo.position.vect;
stage.transform.Rotate(stageInfo.rotation.vect);
obstList.Add(stage);
ground.SetActive(false);
myLoadedAssetBundle.Unload(false);
}
else
{
ground.SetActive(true);
// add the ground
var ground = Object.Instantiate(defaultGround);
ground.name = "Ground";
}
}
......