Beispiel #1
0
 public void OnAwake(Transform defaultTransform, DReConRewardStats orderToCopy = null)
 {
     _spawnableEnv          = GetComponentInParent <SpawnableEnv>();
     _articulationBodyParts = ObjectToTrack
                              .GetComponentsInChildren <ArticulationBody>()
                              .Distinct()
                              .ToList();
     _rigidbodyParts = ObjectToTrack
                       .GetComponentsInChildren <Rigidbody>()
                       .Distinct()
                       .ToList();
     if (_rigidbodyParts?.Count > 0)
     {
         _bodyParts = _rigidbodyParts.Select(x => x.gameObject).ToList();
     }
     else
     {
         _bodyParts = _articulationBodyParts.Select(x => x.gameObject).ToList();
     }
     _trackRotations = _bodyParts
                       .SelectMany(x => x.GetComponentsInChildren <Transform>())
                       .Select(x => x.gameObject)
                       .Distinct()
                       .Where(x => x.GetComponent <Rigidbody>() != null || x.GetComponent <ArticulationBody>() != null)
                       .ToList();
     _capsuleColliders = _bodyParts
                         .SelectMany(x => x.GetComponentsInChildren <CapsuleCollider>())
                         .Distinct()
                         .ToList();
     if (orderToCopy != null)
     {
         _bodyParts = orderToCopy._bodyParts
                      .Select(x => _bodyParts.First(y => y.name == x.name))
                      .ToList();
         _trackRotations = orderToCopy._trackRotations
                           .Select(x => _trackRotations.First(y => y.name == x.name))
                           .ToList();
         _capsuleColliders = orderToCopy._capsuleColliders
                             .Select(x => _capsuleColliders.First(y => y.name == x.name))
                             .ToList();
     }
     Points = Enumerable.Range(0, _capsuleColliders.Count * 6)
              .Select(x => Vector3.zero)
              .ToArray();
     _lastPoints = Enumerable.Range(0, _capsuleColliders.Count * 6)
                   .Select(x => Vector3.zero)
                   .ToArray();
     PointVelocity = Enumerable.Range(0, _capsuleColliders.Count * 6)
                     .Select(x => Vector3.zero)
                     .ToArray();
     Rotations = Enumerable.Range(0, _trackRotations.Count)
                 .Select(x => Quaternion.identity)
                 .ToList();
     if (_root == null)
     {
         _root = _bodyParts.First(x => x.name == "butt");
     }
     transform.position = defaultTransform.position;
     transform.rotation = defaultTransform.rotation;
 }
Beispiel #2
0
    public override void AgentReset()
    {
        if (!_hasLazyInitialized)
        {
            _bodyManager            = GetComponent <BodyManager002>();
            _bodyManager.BodyConfig = MarathonManAgent.BodyConfig;
            _bodyManager.OnInitializeAgent();
            _hasLazyInitialized = true;
        }

        if (_bodyManager == null)
        {
            _bodyManager = GetComponent <BodyManager002>();
        }
        _bodyManager.OnAgentReset();
        if (_terrainGenerator == null)
        {
            _terrainGenerator = GetComponent <TerrainGenerator>();
        }
        if (_spawnableEnv == null)
        {
            _spawnableEnv = GetComponentInParent <SpawnableEnv>();
        }
        _terrainGenerator.Reset();
        lastXPosInMeters = (int)
                           _bodyManager.GetBodyParts(BodyPartGroup.Foot)
                           .Average(x => x.Transform.position.x);
        _pain = 0f;
    }
Beispiel #3
0
    void Awake()
    {
        _spawnableEnv = GetComponentInParent <SpawnableEnv>();
        Assert.IsNotNull(_spawnableEnv);
        _mocap   = _spawnableEnv.GetComponentInChildren <MocapController>().gameObject;
        _ragDoll = _spawnableEnv.GetComponentInChildren <RagDollAgent>().gameObject;
        Assert.IsNotNull(_mocap);
        Assert.IsNotNull(_ragDoll);
        _inputController = _spawnableEnv.GetComponentInChildren <InputController>();
        // _mocapBodyParts = _mocap.GetComponentsInChildren<ArticulationBody>().ToList();
        // _ragDollBodyParts = _ragDoll.GetComponentsInChildren<ArticulationBody>().ToList();
        // Assert.AreEqual(_mocapBodyParts.Count, _ragDollBodyParts.Count);
        _mocapHead = _mocap
                     .GetComponentsInChildren <Transform>()
                     .First(x => x.name == "head");
        _ragDollHead = _ragDoll
                       .GetComponentsInChildren <Transform>()
                       .First(x => x.name == "head");
        _mocapBodyStats = new GameObject("MocapDReConRewardStats").AddComponent <DReConRewardStats>();
        var mocapController = _spawnableEnv.GetComponentInChildren <MocapController>();

        _mocapBodyStats.ObjectToTrack = mocapController;
        _mocapBodyStats.transform.SetParent(_spawnableEnv.transform);
        _mocapBodyStats.OnAwake(_mocapBodyStats.ObjectToTrack.transform);

        _ragDollBodyStats = new GameObject("RagDollDReConRewardStats").AddComponent <DReConRewardStats>();
        _ragDollBodyStats.ObjectToTrack = this;
        _ragDollBodyStats.transform.SetParent(_spawnableEnv.transform);
        _ragDollBodyStats.OnAwake(transform, _mocapBodyStats);

        _mocapBodyStats.AssertIsCompatible(_ragDollBodyStats);
    }
Beispiel #4
0
    // static ScoreHistogramData _scoreHistogramData;


    // void FixedUpdate()
    // {
    //  foreach (var muscle in Muscles)
    //  {
    //  //  var i = Muscles.IndexOf(muscle);
    //  //  muscle.UpdateObservations();
    //  //  if (!DebugShowWithOffset && !DebugDisableMotor)
    //  //      muscle.UpdateMotor();
    //  //  if (!muscle.Rigidbody.useGravity)
    //  //      continue; // skip sub joints
    //  // }
    // }



    // Start is called before the first frame update
    void Start()
    {
        _spawnableEnv     = GetComponentInParent <SpawnableEnv>();
        _terrainGenerator = GetComponentInParent <TerrainGenerator>();
        SetupBody();
        DistanceTraveled = float.MinValue;
    }
Beispiel #5
0
 public void OnInitializeAgent()
 {
     _spawnableEnv     = GetComponentInParent <SpawnableEnv>();
     _terrainGenerator = GetComponentInParent <TerrainGenerator>();
     SetupBody();
     DistanceTraveled = float.MinValue;
 }
Beispiel #6
0
    override public void Initialize()
    {
        // grab access to objects
        _spawnableEnv = GetComponentInParent <SpawnableEnv>();
        _gameBoard    = _spawnableEnv.GetComponentInChildren <GameBoard>();
        // _mocapController = _spawnableEnv.GetComponentInChildren<MocapController>();

        // to do, error check the behavior paramaters

        _gameBoard.InitializeBoard(Size);
    }
Beispiel #7
0
    void Awake()
    {
        _anim = GetComponent <Animator>();
        _characterController = GetComponent <CharacterController>();
        _spawnableEnv        = GetComponentInParent <SpawnableEnv>();
        _inputController     = _spawnableEnv.GetComponentInChildren <InputController>();
        _targetDirection     = Quaternion.Euler(0, 90, 0);
        var ragDoll = _spawnableEnv.GetComponentInChildren <RagDollAgent>();

        _layerMask  = 1 << ragDoll.gameObject.layer;
        _layerMask |= 1 << this.gameObject.layer;
        _layerMask  = ~(_layerMask);
    }
Beispiel #8
0
 public void OnAwake(List <string> bodyPartsToTrack, Transform defaultTransform)
 {
     _bodyPartsToTrack      = bodyPartsToTrack;
     _spawnableEnv          = GetComponentInParent <SpawnableEnv>();
     _inputController       = _spawnableEnv.GetComponentInChildren <InputController>();
     _rigidbodyParts        = ObjectToTrack.GetComponentsInChildren <Rigidbody>().ToList();
     _articulationBodyParts = ObjectToTrack.GetComponentsInChildren <ArticulationBody>().ToList();
     if (_rigidbodyParts?.Count > 0)
     {
         _bodyParts = _rigidbodyParts
                      .SelectMany(x => x.GetComponentsInChildren <Transform>())
                      .Distinct()
                      .ToList();
     }
     else
     {
         _bodyParts = _articulationBodyParts
                      .SelectMany(x => x.GetComponentsInChildren <Transform>())
                      .Distinct()
                      .ToList();
     }
     if (_bodyPartsToTrack?.Count > 0)
     {
         _bodyParts = _bodyPartsToTrack
                      .Where(x => _bodyPartsToTrack.Contains(x))
                      .Select(x => _bodyParts.First(y => y.name == x))
                      .ToList();
     }
     Stats = _bodyParts
             .Select(x => new Stat {
         Name = x.name
     })
             .ToList();
     if (_root == null)
     {
         _root = _bodyParts.First(x => x.name == "butt").gameObject;
     }
     transform.position = defaultTransform.position;
     transform.rotation = defaultTransform.rotation;
 }
Beispiel #9
0
    // Start is called before the first frame update
    void Awake()
    {
        _spawnableEnv           = GetComponentInParent <SpawnableEnv>();
        _inputController        = _spawnableEnv.GetComponentInChildren <InputController>();
        BodyPartDifferenceStats = BodyPartsToTrack
                                  .Select(x => new BodyPartDifferenceStats {
            Name = x
        })
                                  .ToList();

        _mocapBodyStats = new GameObject("MocapDReConObservationStats").AddComponent <DReConObservationStats>();
        var mocapController = _spawnableEnv.GetComponentInChildren <MocapController>();

        _mocapBodyStats.ObjectToTrack = mocapController;
        _mocapBodyStats.transform.SetParent(_spawnableEnv.transform);
        _mocapBodyStats.OnAwake(BodyPartsToTrack, _mocapBodyStats.ObjectToTrack.transform);

        _ragDollBodyStats = new GameObject("RagDollDReConObservationStats").AddComponent <DReConObservationStats>();
        _ragDollBodyStats.ObjectToTrack = this;
        _ragDollBodyStats.transform.SetParent(_spawnableEnv.transform);
        _ragDollBodyStats.OnAwake(BodyPartsToTrack, transform);
    }
Beispiel #10
0
 public override void AgentReset()
 {
     if (_bodyManager == null)
     {
         _bodyManager = GetComponent <BodyManager002>();
     }
     _bodyManager.OnAgentReset();
     if (_terrainGenerator == null)
     {
         _terrainGenerator = GetComponent <TerrainGenerator>();
     }
     if (_spawnableEnv == null)
     {
         _spawnableEnv = GetComponentInParent <SpawnableEnv>();
     }
     _terrainGenerator.Reset();
     lastXPosInMeters = (int)
                        _bodyManager.GetBodyParts(BodyPartGroup.Foot)
                        .Average(x => x.Transform.position.x);
     _pain        = 0f;
     _modeRecover = false;
 }
Beispiel #11
0
    public override void AgentReset()
    {
        if (!_hasLazyInitialized)
        {
            _decisionRequester  = GetComponent <DecisionRequester>();
            _debugController    = FindObjectOfType <MarathonTestBedController>();
            Time.fixedDeltaTime = FixedDeltaTime;
            _spawnableEnv       = GetComponentInParent <SpawnableEnv>();
            _mocapController    = _spawnableEnv.GetComponentInChildren <MocapController>();
            _mocapBodyParts     = _mocapController.GetComponentsInChildren <Rigidbody>().ToList();
            _bodyParts          = GetComponentsInChildren <ArticulationBody>().ToList();
            _dReConObservations = GetComponent <DReConObservations>();
            _dReConRewards      = GetComponent <DReConRewards>();
            var mocapController = _spawnableEnv.GetComponentInChildren <MocapController>();
            _trackBodyStatesInWorldSpace = mocapController.GetComponent <TrackBodyStatesInWorldSpace>();
            _ragDollSettings             = GetComponent <RagDoll003>();
            _inputController             = _spawnableEnv.GetComponentInChildren <InputController>();
            _sensorObservations          = GetComponent <SensorObservations>();

            foreach (var body in GetComponentsInChildren <ArticulationBody>())
            {
                body.solverIterations         = 255;
                body.solverVelocityIterations = 255;
            }

            _motors = GetComponentsInChildren <ArticulationBody>()
                      .Where(x => x.jointType == ArticulationJointType.SphericalJoint)
                      .Where(x => !x.isRoot)
                      .Distinct()
                      .ToList();
            var individualMotors = new List <float>();
            foreach (var m in _motors)
            {
                if (m.twistLock == ArticulationDofLock.LimitedMotion)
                {
                    individualMotors.Add(0f);
                }
                if (m.swingYLock == ArticulationDofLock.LimitedMotion)
                {
                    individualMotors.Add(0f);
                }
                if (m.swingZLock == ArticulationDofLock.LimitedMotion)
                {
                    individualMotors.Add(0f);
                }
            }
            _dReConObservations.PreviousActions = individualMotors.ToArray();
            _hasLazyInitialized = true;
        }
        _smoothedActions = null;
        debugCopyMocap   = false;
        _inputController.OnReset();
        _mocapController.GetComponentInChildren <MocapAnimatorController>().OnReset();
        var angle    = Vector3.SignedAngle(Vector3.forward, _inputController.HorizontalDirection, Vector3.up);
        var rotation = Quaternion.Euler(0f, angle, 0f);

        _mocapController.OnReset(rotation);
        _mocapController.CopyStatesTo(this.gameObject);
        // _trackBodyStatesInWorldSpace.CopyStatesTo(this.gameObject);
        float timeDelta = float.MinValue;

        _dReConObservations.OnReset();
        _dReConRewards.OnReset();
        _dReConObservations.OnStep(timeDelta);
        _dReConRewards.OnStep(timeDelta);
        _skipRewardAfterTeleport = false;
#if UNITY_EDITOR
        if (DebugPauseOnReset)
        {
            UnityEditor.EditorApplication.isPaused = true;
        }
#endif
    }