// Use this for initialization public override void Init(AnimationAnalyzer animAnalyzer, NeighbourAgents neighborhood, NeighbourObstacles obstacles) { analyzer = animAnalyzer; if (analyzer != null && !analyzer.initialized) { analyzer.Init(); } storedPlan = new List <FootstepPlanningAction>(); outputPlan = new Stack <DefaultAction>(); domainList = new List <PlanningDomainBase>(); domainList.Add(new FootstepPlanningDomain(analyzer, neighborhood, obstacles)); planner = new ADAstarPlanner(); planner.init(ref domainList, MaxNumberOfNodes); initialized = true; currentState = null; isPlanComputed = false; planChanged = false; goalMeshRenderer = goalStateTransform.gameObject.GetComponent("MeshRenderer") as MeshRenderer; currentGoal = goalStateTransform.position; }
//public void Init (AnimationAnalyzer animAnalyzer, AnimationEngine animEngine, FootstepPlanningTest planner, public void Init(AnimationAnalyzer animAnalyzer, AnimationEngine animEngine, Planner planner, NeighbourAgents agents, NeighbourObstacles obstacles, CollisionReaction colReact) { analyzer = animAnalyzer; if (analyzer != null && !analyzer.initialized) { analyzer.Init(); } planning = planner; if (planning != null && !planning.initialized) { planning.Init(analyzer, agents, obstacles); } engine = animEngine; if (engine != null && !engine.initialized) { engine.Init(analyzer, planning, agents, obstacles); } collision = colReact; if (collision != null && !collision.initialized) { collision.Init(analyzer, planning, engine, agents, obstacles); } if (debugText != null) { debugText.gameObject.active = false; } initialized = true; }
//public void Init(AnimationAnalyzer analyzer, FootstepPlanningTest planner, public void Init(AnimationAnalyzer analyzer, Planner planner, AnimationEngine animEngine, CollisionReaction collisionReact, NavMeshWayPoints navMeshWaypoints, SteeringManager steering, NeighbourAgents agents, NeighbourObstacles obstacles, PlaceFootSteps steps) { planning = planner; if (planning != null && !planning.initialized) { planning.Init(analyzer, agents, obstacles); } engine = animEngine; if (engine != null && !engine.initialized) { engine.Init(analyzer, planning, agents, obstacles); } collision = collisionReact; if (collision != null && !collision.initialized) { collision.Init(analyzer, planner, engine, agents, obstacles); } waypoints = navMeshWaypoints; //if (waypoints != null && !waypoints.initialized) // waypoints.Init(planning,steering,analyzer,agents,obstacles); neighborhood = agents; if (neighborhood != null && !neighborhood.initialized) { neighborhood.Init(); } footsteps = steps; if (footsteps != null && !footsteps.initiated) { footsteps.Init(analyzer, planner, engine, neighborhood, obstacles); } nObstacles = obstacles; if (nObstacles != null && !nObstacles.initialized) { nObstacles.Init(); } timeSinceLastPlan = 0; timeSinceLastWaypoints = 0; previousGoalPosition = planning.goalStateTransform.position; previousCurrentGoalPosition = planning.currentGoal; previousActionsSinceLastPlan = -1; newWaypoint = false; initialized = true; }
private void FillArray(ref float[] array, float value, int startIndex, int endIndex) { float length = (startIndex < endIndex) ? (endIndex - startIndex) : endIndex + (_sampleNumber - 1) - startIndex; for (var i = startIndex; i <= (startIndex + length); i++) { var index = (int)AnimationAnalyzer.Mod(i, _sampleNumber); array[index] = value; } }
public GridPlanningDomain(AnimationAnalyzer animAnalyzer) { analyzer = animAnalyzer; Vector3 dir1 = new Vector3(1, 0, 0); Vector3 dir2 = new Vector3(-1, 0, 0); Vector3 dir3 = new Vector3(0, 0, 1); Vector3 dir4 = new Vector3(0, 0, -1); Vector3 dir5 = new Vector3(-1, 0, -1); dir5.Normalize(); Vector3 dir6 = new Vector3(-1, 0, 1); dir6.Normalize(); Vector3 dir7 = new Vector3(1, 0, -1); dir7.Normalize(); Vector3 dir8 = new Vector3(1, 0, 1); dir8.Normalize(); movDirections = new List <Vector3>(); /* * if (analyzer != null) * { * movDirections.Add(dir1*analyzer.meanStepSize); * movDirections.Add(dir2*analyzer.meanStepSize); * movDirections.Add(dir3*analyzer.meanStepSize); * movDirections.Add(dir4*analyzer.meanStepSize); * * * movDirections.Add(dir5*analyzer.meanStepSize); * movDirections.Add(dir6*analyzer.meanStepSize); * movDirections.Add(dir7*analyzer.meanStepSize); * movDirections.Add(dir8*analyzer.meanStepSize); * } * else */ { float meanStepSize = 1.0f; movDirections.Add(dir1 * meanStepSize); movDirections.Add(dir2 * meanStepSize); movDirections.Add(dir3 * meanStepSize); movDirections.Add(dir4 * meanStepSize); movDirections.Add(dir5 * meanStepSize); movDirections.Add(dir6 * meanStepSize); movDirections.Add(dir7 * meanStepSize); movDirections.Add(dir8 * meanStepSize); } }
// Use this for initialization //public void Init (FootstepPlanningTest planner, SteeringManager steeringManager, AnimationAnalyzer analyzer, NeighbourAgents agents, NeighbourObstacles obstacles, RootMotionComputer computer) { public void Init(Planner planner, SteeringManager steeringManager, AnimationAnalyzer analyzer, NeighbourAgents agents, NeighbourObstacles obstacles) { steering = steeringManager; planning = planner; if (planning != null && !planning.initialized) planning.Init(analyzer, agents, obstacles); navMeshLayer = 1 << LayerMask.NameToLayer("StaticWorld"); initialized = true; }
// Use this for initialization public override void Init(AnimationAnalyzer animAnalyzer, NeighbourAgents neighborhood, NeighbourObstacles obstacles) { analyzer = animAnalyzer; if (analyzer != null && !analyzer.initialized) { analyzer.Init(); } storedPlan = new List <FootstepPlanningAction>(); outputPlan = new Stack <DefaultAction>(); domainList = new List <PlanningDomainBase>(); gpd = new GridPlanningDomain(analyzer); //gtd = new GridTimeDomain(analyzer, obstacles); gtd = new GridTimeDomain(obstacles, neighborhood); fpd = new FootstepPlanningDomain(analyzer, neighborhood, obstacles); if (useGridDomain) { domainList.Add(gpd); //domainList.Add(gpd); } if (useGridTimeDomain) { domainList.Add(gtd); //domainList.Add(gtd); } if (useFootstepDomain) { domainList.Add(fpd); //domainList.Add(fpd); } planner = new BestFirstSearchPlanner(); planner.init(ref domainList, MaxNumberOfNodes); initialized = true; currentState = null; isPlanComputed = false; planChanged = false; goalMeshRenderer = goalStateTransform.gameObject.GetComponent("MeshRenderer") as MeshRenderer; currentGoal = goalStateTransform.position; goalReached = false; }
//public void Init(AnimationAnalyzer animAnalyzer, FootstepPlanningTest planner, RootMotionComputer computer, NeighbourAgents agents, NeighbourObstacles obstacles){ public void Init(AnimationAnalyzer animAnalyzer, Planner planner, NeighbourAgents agents, NeighbourObstacles obstacles) { analyzer = animAnalyzer; if (analyzer != null && !analyzer.initialized) { analyzer.Init(); } planning = planner; if (planning != null && !planning.initialized) { planning.Init(analyzer, agents, obstacles); } foreach (AnimationState state in animation) { state.enabled = true; state.speed = 1.0f; state.wrapMode = WrapMode.Loop; state.weight = 0; } currentAnimation = null; action = null; animation.Stop(); initialized = true; actionNum = 0; changed = false; errorT = new Vector3(0, 0, 0); errorR = 0; currentBlendingTime = 0; currentActionTime = 0; previousBlendingTime = 0; currentActionEndTime = 0; actionsSinceLastPlan = 0; insertedAction = false; initGameObjectPos = transform.position; initGameObjectRotY = transform.eulerAngles.y; initLocalRootPos = root.localPosition; lastRootPos = root.position; lastRootRot = root.rotation; }
// Use this for initialization //public void Init (FootstepPlanningTest planner, SteeringManager steeringManager, AnimationAnalyzer analyzer, NeighbourAgents agents, NeighbourObstacles obstacles, RootMotionComputer computer) { public void Init(Planner planner, SteeringManager steeringManager, AnimationAnalyzer analyzer, NeighbourAgents agents, NeighbourObstacles obstacles) { steering = steeringManager; planning = planner; if (planning != null && !planning.initialized) { planning.Init(analyzer, agents, obstacles); } navMeshLayer = 1 << LayerMask.NameToLayer("StaticWorld"); initialized = true; }
public GridPlanningDomain(AnimationAnalyzer animAnalyzer) { analyzer = animAnalyzer; Vector3 dir1 = new Vector3(1,0,0); Vector3 dir2 = new Vector3(-1,0,0); Vector3 dir3 = new Vector3(0,0,1); Vector3 dir4 = new Vector3(0,0,-1); Vector3 dir5 = new Vector3(-1,0,-1); dir5.Normalize(); Vector3 dir6 = new Vector3(-1,0,1); dir6.Normalize(); Vector3 dir7 = new Vector3(1,0,-1); dir7.Normalize(); Vector3 dir8 = new Vector3(1,0,1); dir8.Normalize(); movDirections = new List<Vector3>(); /* if (analyzer != null) { movDirections.Add(dir1*analyzer.meanStepSize); movDirections.Add(dir2*analyzer.meanStepSize); movDirections.Add(dir3*analyzer.meanStepSize); movDirections.Add(dir4*analyzer.meanStepSize); movDirections.Add(dir5*analyzer.meanStepSize); movDirections.Add(dir6*analyzer.meanStepSize); movDirections.Add(dir7*analyzer.meanStepSize); movDirections.Add(dir8*analyzer.meanStepSize); } else */ { float meanStepSize = 1.0f; movDirections.Add(dir1*meanStepSize); movDirections.Add(dir2*meanStepSize); movDirections.Add(dir3*meanStepSize); movDirections.Add(dir4*meanStepSize); movDirections.Add(dir5*meanStepSize); movDirections.Add(dir6*meanStepSize); movDirections.Add(dir7*meanStepSize); movDirections.Add(dir8*meanStepSize); } }
public void ComputeRootMotion() { if (currentAnimation == null || action == null) { //Debug.Log("something is wrong at time " + Time.time ); return; } AnimationState anim = currentAnimation; Vector3 displacement = Vector3.zero; float rotY = 0; float currentTime = anim.normalizedTime; CompleteAnimationCurve animCurve = action.animInfo.RootCurve; displacement.x = animCurve.xPos.Evaluate(currentTime); displacement.y = animCurve.yPos.Evaluate(currentTime); displacement.z = animCurve.zPos.Evaluate(currentTime); rotY = animCurve.yRot.Evaluate(currentTime); transform.position = initGameObjectPos; transform.rotation = Quaternion.Euler(0, initGameObjectRotY, 0); displacement = transform.rotation * displacement; transform.Translate(displacement, Space.World); transform.Rotate(new Vector3(0, rotY, 0)); Vector3 forwardProj = new Vector3(-root.right.x, 0, -root.right.z); Vector3 zVector = new Vector3(0, 0, 1); float newRotY = AnimationAnalyzer.CalculateAngleOf2Vectors(zVector, forwardProj); root.RotateAround(transform.position, Vector3.up, -newRotY + initGameObjectRotY + rotY); root.localPosition = initLocalRootPos; /****/ xPos = animCurve.xPos; yPos = animCurve.yPos; zPos = animCurve.zPos; yRot = animCurve.yRot; /****/ }
void LateUpdate() { AnimationState anim = currentAnimState; Vector3 displacement = Vector3.zero; float rotY = 0; float currentTime = anim.normalizedTime; RootCurve animCurve = animationCurves[anim.name]; displacement.x = animCurve.xPos.Evaluate(currentTime); displacement.y = animCurve.yPos.Evaluate(currentTime); displacement.z = animCurve.zPos.Evaluate(currentTime); rotY = animCurve.yRot.Evaluate(currentTime); if (changed) { prevEndPos = transform.position; prevEndRot = transform.eulerAngles.y; } transform.position = prevEndPos; transform.rotation = Quaternion.Euler(0, prevEndRot, 0); displacement = transform.rotation * displacement; transform.Translate(displacement, Space.World); transform.Rotate(new Vector3(0, rotY, 0)); Vector3 forwardProj = new Vector3(-root.right.x, 0, -root.right.z); Vector3 zVector = new Vector3(0, 0, 1); float newRotY = AnimationAnalyzer.CalculateAngleOf2Vectors(zVector, forwardProj); root.RotateAround(transform.position, Vector3.up, -newRotY + prevEndRot + rotY); root.localPosition = initRootLocalPos; xPos = animCurve.xPos; yPos = animCurve.yPos; zPos = animCurve.zPos; yRot = animCurve.yRot; }
public void AnalyzeAnimations(int sampleNumber, float velocityTh, int smoothingTh) { LoadAnimationClips(); foreach (var clip in _clipList) { if (!clip.isHumanMotion) { errorList.Add(clip); continue; } var animationAnalyzer = new AnimationAnalyzer(clip, sampleNumber); animationAnalyzer.AnalyzeAnimation(velocityTh, smoothingTh); } }
// Use this for initialization void Start() { //AnimationAnalyzer analyzer = agent.GetComponent("AnimationAnalyzer") as AnimationAnalyzer; if (analyzer == null) { analyzer = agent.GetComponent("AnimationAnalyzer") as AnimationAnalyzer; if (analyzer != null) { analyzer.Init(); } animationNames = analyzer.animationNames; } currentAnimationIndex = 0; }
//public void Init(AnimationAnalyzer analyzer, FootstepPlanningTest planner, public void Init(AnimationAnalyzer analyzer, Planner planner, AnimationEngine animEngine, CollisionReaction collisionReact, NavMeshWayPoints navMeshWaypoints, SteeringManager steering, NeighbourAgents agents, NeighbourObstacles obstacles, PlaceFootSteps steps) { planning = planner; if (planning != null && !planning.initialized) planning.Init(analyzer,agents,obstacles); engine = animEngine; if (engine != null && !engine.initialized) engine.Init(analyzer,planning,agents,obstacles); collision = collisionReact; if (collision != null && !collision.initialized) collision.Init(analyzer,planner,engine,agents,obstacles); waypoints = navMeshWaypoints; //if (waypoints != null && !waypoints.initialized) // waypoints.Init(planning,steering,analyzer,agents,obstacles); neighborhood = agents; if (neighborhood != null && !neighborhood.initialized) neighborhood.Init(); footsteps = steps; if (footsteps != null && !footsteps.initiated) footsteps.Init(analyzer,planner,engine,neighborhood,obstacles); nObstacles = obstacles; if (nObstacles != null && !nObstacles.initialized) nObstacles.Init(); timeSinceLastPlan = 0; timeSinceLastWaypoints = 0; previousGoalPosition = planning.goalStateTransform.position; previousCurrentGoalPosition = planning.currentGoal; previousActionsSinceLastPlan = -1; newWaypoint = false; initialized = true; }
private int[] SmoothGroundTimes(int[] groundedTimes) { var correctedTimes = groundedTimes; for (int i = 0; i < groundedTimes.Length; i++) { var a = groundedTimes[i]; var b = groundedTimes[(int)AnimationAnalyzer.Mod((i - 1), _sampleNumber)]; var c = groundedTimes[(int)AnimationAnalyzer.Mod((i + 1), _sampleNumber)]; if (a != b && a != c) { correctedTimes[i] = c; } } return(correctedTimes); }
void Awake() { analyzer = null; animationNames = null; currentAnimationName = null; currentAnimationIndex = 0; currentAnimation = null; currentActionTime = 0; currentBlendingTime = 0; previousBlendingTime = 0; changed = false; stored = false; }
//public void Init (AnimationAnalyzer animAnalyzer, AnimationEngine animEngine, FootstepPlanningTest planner, public void Init(AnimationAnalyzer animAnalyzer, AnimationEngine animEngine, Planner planner, NeighbourAgents agents, NeighbourObstacles obstacles, CollisionReaction colReact) { analyzer = animAnalyzer; if (analyzer != null && !analyzer.initialized) analyzer.Init(); planning = planner; if (planning != null && !planning.initialized) planning.Init(analyzer, agents, obstacles); engine = animEngine; if (engine != null && !engine.initialized) engine.Init(analyzer,planning,agents,obstacles); collision = colReact; if (collision != null && !collision.initialized) collision.Init(analyzer,planning,engine,agents,obstacles); if (debugText != null) debugText.gameObject.active = false; initialized = true; }
//public void Init(AnimationAnalyzer animAnalyzer, FootstepPlanningTest planner, AnimationEngine animEngine, public void Init(AnimationAnalyzer animAnalyzer, Planner planner, AnimationEngine animEngine, NeighbourAgents agents, NeighbourObstacles obstacles) { analyzer = animAnalyzer; if (analyzer != null && !analyzer.initialized) { analyzer.Init(); } planning = planner; if (planning != null && !planning.initialized) { planning.Init(analyzer, agents, obstacles); } engine = animEngine; if (engine != null && !engine.initialized) { engine.Init(analyzer, planning, agents, obstacles); } if (rightFoot.position[1] < leftFoot.position[1]) { auxHeight = rightFoot.position[1]; } else { auxHeight = leftFoot.position[1]; } counter = 0; footSteps = new Object[numberOfFootSteps]; initiated = true; }
//public void Init(AnimationAnalyzer animAnalyzer, FootstepPlanningTest planner, AnimationEngine animEngine, NeighbourAgents agents, NeighbourObstacles obstacles) public void Init(AnimationAnalyzer animAnalyzer, Planner planner, AnimationEngine animEngine, NeighbourAgents agents, NeighbourObstacles obstacles) { analyzer = animAnalyzer; if (analyzer != null && !analyzer.initialized) { analyzer.Init(); } planning = planner; if (planning != null && !planning.initialized) { planning.Init(analyzer, agents, obstacles); } engine = animEngine; if (engine != null && !engine.initialized) { engine.Init(analyzer, planning, agents, obstacles); } reacting = false; initialized = true; }
//public void Init(AnimationAnalyzer animAnalyzer, FootstepPlanningTest planner, AnimationEngine animEngine, public void Init(AnimationAnalyzer animAnalyzer, Planner planner, AnimationEngine animEngine, NeighbourAgents agents, NeighbourObstacles obstacles) { analyzer = animAnalyzer; if (analyzer != null && !analyzer.initialized) analyzer.Init(); planning = planner; if (planning != null && !planning.initialized) planning.Init(analyzer, agents, obstacles); engine = animEngine; if (engine != null && !engine.initialized) engine.Init(analyzer,planning,agents,obstacles); if (rightFoot.position[1] < leftFoot.position[1]) auxHeight = rightFoot.position[1]; else auxHeight = leftFoot.position[1]; counter = 0; footSteps = new Object[numberOfFootSteps]; initiated = true; }
// Use this for initialization void Start() { //AnimationAnalyzer analyzer = agent.GetComponent("AnimationAnalyzer") as AnimationAnalyzer; if (analyzer == null) { analyzer = agent.GetComponent("AnimationAnalyzer") as AnimationAnalyzer; if (analyzer != null) analyzer.Init(); animationNames = analyzer.animationNames; } currentAnimationIndex = 0; }
// Use this for initialization void InitAgent(int i) { AnimationAnalyzer analyzer = null; // Initialize different components of the agents // ( Animation Engine, Planner, Neighbors, ...) //foreach (GameObject agent in agents) //for(int i = 0; i < agents.Length; i++) { GameObject agent = agents[i]; //agent.active = true; agent.transform.position = agentsPos[i]; //if (analyzer == null) { analyzer = agent.GetComponent("AnimationAnalyzer") as AnimationAnalyzer; if (analyzer != null) { analyzer.Init(); //analyzer.ReadAnalysisFromFile(animationsFileName); } } /* * else * { * Vector3 startPos = agent.transform.position; * Quaternion startRot = agent.transform.rotation; * analyzer.RemoveAnimations(agent.animation); * agent.transform.position = startPos; * agent.transform.rotation = startRot; * } */ NeighbourAgents neighbourAgents = agent.GetComponent("NeighbourAgents") as NeighbourAgents; //if (neighbourAgents != null) // neighbourAgents.Init(); NeighbourObstacles neighbourObstacles = agent.GetComponent("NeighbourObstacles") as NeighbourObstacles; //if (neighbourObstacles != null) // neighbourObstacles.Init(); Planner planning; if (ADAFootstepTest.ADA_PLANNER_IN_USE) { ADAFootstepTest ADAplanning = agent.GetComponent("ADAFootstepTest") as ADAFootstepTest; planning = ADAplanning as Planner; } else { FootstepPlanningTest FPTplanning = agent.GetComponent("FootstepPlanningTest") as FootstepPlanningTest; planning = FPTplanning as Planner; } if (planning != null) { planning.Init(analyzer, neighbourAgents, neighbourObstacles); } AnimationEngine engine = agent.GetComponent("AnimationEngine") as AnimationEngine; if (engine != null) { engine.Init(analyzer, planning, neighbourAgents, neighbourObstacles); } CollisionReaction collider = agent.GetComponent("CollisionReaction") as CollisionReaction; if (collider != null) { collider.Init(analyzer, planning, engine, neighbourAgents, neighbourObstacles); } NavMeshWayPoints waypoints = agent.GetComponent("NavMeshWayPoints") as NavMeshWayPoints; if (waypoints != null) { waypoints.Init(planning, steering, analyzer, neighbourAgents, neighbourObstacles); } PlaceFootSteps footsteps = agent.GetComponent("PlaceFootSteps") as PlaceFootSteps; if (footsteps != null) { footsteps.Init(analyzer, planning, engine, neighbourAgents, neighbourObstacles); } EventsMonitor events = agent.GetComponent("EventsMonitor") as EventsMonitor; if (events != null) { events.Init(analyzer, planning, engine, collider, waypoints, steering, neighbourAgents, neighbourObstacles, footsteps); events.enabled = false; } DebugScript debug = agent.GetComponent("DebugScript") as DebugScript; if (debug != null) { debug.Init(analyzer, engine, planning, neighbourAgents, neighbourObstacles, collider); } if (analyzer != null) { analyzer.RemoveAnimations(agent.animation); } } }
public FootstepPlanningDomain(AnimationAnalyzer animAnalyzer, NeighbourAgents n, NeighbourObstacles o) { analyzer = animAnalyzer; neighborhood = n; obstacles = o; }
//public void Init(AnimationAnalyzer animAnalyzer, FootstepPlanningTest planner, AnimationEngine animEngine, NeighbourAgents agents, NeighbourObstacles obstacles) public void Init(AnimationAnalyzer animAnalyzer, Planner planner, AnimationEngine animEngine,NeighbourAgents agents, NeighbourObstacles obstacles) { analyzer = animAnalyzer; if (analyzer != null && !analyzer.initialized) analyzer.Init(); planning = planner; if (planning != null && !planning.initialized) planning.Init(analyzer, agents, obstacles); engine = animEngine; if (engine != null && !engine.initialized) engine.Init(analyzer,planning, agents, obstacles); reacting = false; initialized = true; }
private (float[] f, float[] x, float[] z, float[] s) GenerateFlightTimes(int[] groundedTimes, Vector3[] inPlacePos, Vector3[] position) { var flightTimes = new float[_sampleNumber]; float[] x = new float[_sampleNumber]; float[] z = new float[_sampleNumber]; //TODO: refactor this method //stride test float[] s = new float[_sampleNumber]; //test List <int> strikeList = new List <int>(); List <float> flightList = new List <float>(); List <float> xList = new List <float>(); List <float> zList = new List <float>(); List <float> strideList = new List <float>(); var endTime = _clip.length; float flightTime; bool isIdle = true; for (var i = 1; i < groundedTimes.Length; i++) { if (groundedTimes[i] != groundedTimes[i - 1]) { isIdle = false; if (groundedTimes[i] == 0) { var liftTime = _timeSample[i]; int liftIndex = i; var j = i; while (groundedTimes[(int)AnimationAnalyzer.Mod(j, _sampleNumber)] == 0) { j++; } int strikeIndex = (int)AnimationAnalyzer.Mod(j + 1, _sampleNumber); var strikeTime = _timeSample[strikeIndex]; flightTime = (liftTime < strikeTime) ? (strikeTime - liftTime) : (strikeTime + endTime - liftTime); Vector3 startPos = position[liftIndex]; Vector3 endPos = position[strikeIndex]; Vector3 displacement = inPlacePos[strikeIndex]; //stridelength test float strideLength; if (strikeTime < liftTime) { Vector3 finalPos = position[_sampleNumber - 1]; Vector3 initialPos = position[0]; float d1 = Vector3.Distance(finalPos, startPos); float d2 = Vector3.Distance(initialPos, endPos); strideLength = d1 + d2; } else { strideLength = Vector3.Distance(endPos, startPos); } strikeList.Add(strikeIndex); flightList.Add(flightTime); xList.Add(displacement.x); zList.Add(displacement.z); strideList.Add(strideLength); if (_clip.name == "PIK_Walk") { Debug.Log(displacement.z); } } } } for (var i = 0; i < strikeList.Count; i++) { var currentFlight = flightList[i]; var prevStrike = strikeList[(int)AnimationAnalyzer.Mod((i - 1), strikeList.Count)]; var currentStrike = strikeList[i]; var currentX = xList[i]; var currentZ = zList[i]; var strideLength = strideList[i]; FillArray(ref x, currentX, prevStrike, currentStrike); FillArray(ref z, currentZ, prevStrike, currentStrike); FillArray(ref flightTimes, currentFlight, prevStrike, currentStrike); FillArray(ref s, strideLength, prevStrike, currentStrike); } if (isIdle) { Vector3 displacement = inPlacePos[0]; FillArray(ref x, displacement.x, 0, _sampleNumber - 1); FillArray(ref z, displacement.z, 0, _sampleNumber - 1); FillArray(ref s, 0, 0, _sampleNumber - 1); } return(flightTimes, x, z, s); }
//public void Init(AnimationAnalyzer animAnalyzer, FootstepPlanningTest planner, RootMotionComputer computer, NeighbourAgents agents, NeighbourObstacles obstacles){ public void Init(AnimationAnalyzer animAnalyzer, Planner planner, NeighbourAgents agents, NeighbourObstacles obstacles) { analyzer = animAnalyzer; if (analyzer != null && !analyzer.initialized) analyzer.Init(); planning = planner; if (planning != null && !planning.initialized) planning.Init(analyzer,agents,obstacles); foreach (AnimationState state in animation) { state.enabled = true; state.speed = 1.0f; state.wrapMode = WrapMode.Loop; state.weight = 0; } currentAnimation = null; action = null; animation.Stop(); initialized = true; actionNum = 0; changed = false; errorT = new Vector3(0,0,0); errorR = 0; currentBlendingTime = 0; currentActionTime = 0; previousBlendingTime = 0; currentActionEndTime = 0; actionsSinceLastPlan = 0; insertedAction = false; initGameObjectPos = transform.position; initGameObjectRotY = transform.eulerAngles.y; initLocalRootPos = root.localPosition; lastRootPos = root.position; lastRootRot = root.rotation; }
// Use this for initialization void Start() { animationCurves = new SerializableDictionary <string, RootCurve>(); Vector3 initPos = transform.position; Quaternion initRot = transform.rotation; initRootLocalPos = root.localPosition; Vector3 originalRootPos = root.position; Quaternion originalRootRot = root.rotation; Vector3 prevEndPos = transform.position; for (int i = 0; i < animationNames.Length; i++) { RootCurve animCurve; animCurve.xPos = new AnimationCurve(); animCurve.yPos = new AnimationCurve(); animCurve.zPos = new AnimationCurve(); animCurve.yRot = new AnimationCurve(); float initYRot = 0; transform.position = Vector3.zero; transform.rotation = Quaternion.identity; AnimationState anim = animation[animationNames[i]]; anim.enabled = true; anim.wrapMode = WrapMode.Loop; Vector3 initRootPos = root.position; // For every sample we want for (int s = 0; s < samples; s++) { // Sample the Animation until the end of our action anim.normalizedTime = s * time / (samples - 1); animation.Play(anim.name); animation.Sample(); if (s == 0) { initRootPos = root.position; Vector3 initForwardProj = new Vector3(-root.right.x, 0, -root.right.z); Vector3 initZVector = new Vector3(0, 0, 1); initYRot = AnimationAnalyzer.CalculateAngleOf2Vectors(initZVector, initForwardProj); } Vector3 rootDisplacement = root.position - initRootPos; animCurve.xPos.AddKey(s * time / (samples - 1), rootDisplacement.x); if (s == samples - 1) { animCurve.yPos.AddKey(s * time / (samples - 1), 0); } else { animCurve.yPos.AddKey(s * time / (samples - 1), rootDisplacement.y); } animCurve.zPos.AddKey(s * time / (samples - 1), rootDisplacement.z); Vector3 forwardProj = new Vector3(-root.right.x, 0, -root.right.z); Vector3 zVector = new Vector3(0, 0, 1); float yRot = AnimationAnalyzer.CalculateAngleOf2Vectors(zVector, forwardProj) - initYRot; animCurve.yRot.AddKey(s * time / (samples - 1), yRot); } animCurve.xPos.postWrapMode = WrapMode.Clamp; animCurve.xPos.preWrapMode = WrapMode.Clamp; animCurve.yPos.postWrapMode = WrapMode.Clamp; animCurve.yPos.preWrapMode = WrapMode.Clamp; animCurve.zPos.postWrapMode = WrapMode.Clamp; animCurve.zPos.preWrapMode = WrapMode.Clamp; animCurve.yRot.postWrapMode = WrapMode.Clamp; animCurve.yRot.preWrapMode = WrapMode.Clamp; animationCurves.Add(animationNames[i], animCurve); // We remove the animation anim.normalizedTime = 0.0f; anim.enabled = false; animation.Stop(); animation.Sample(); } root.rotation = originalRootRot; root.position = originalRootPos; transform.position = initPos; transform.rotation = initRot; currentAnimState = null; currentAnimIndex = -1; Vector3 position = transform.position; Quaternion rot = transform.rotation; for (int i = 0; i < animationNames.Length; i++) { Vector3 displacement = Vector3.zero; float rotY = 0; float currentTime = time; RootCurve animCurve = animationCurves[animationNames[i]]; displacement.x = animCurve.xPos.Evaluate(currentTime); displacement.y = animCurve.yPos.Evaluate(currentTime); displacement.z = animCurve.zPos.Evaluate(currentTime); rotY = animCurve.yRot.Evaluate(currentTime); position += rot * displacement; Quaternion rotation = Quaternion.Euler(0, rotY, 0); rot = rotation * rot; Instantiate(rootRepresentation, position, Quaternion.identity); } Destroy(rootRepresentation); changed = false; }
public virtual void Init(AnimationAnalyzer aa, NeighbourAgents na, NeighbourObstacles no) { }
// Use this for initialization public override void Init(AnimationAnalyzer animAnalyzer, NeighbourAgents neighborhood, NeighbourObstacles obstacles) { analyzer = animAnalyzer; if (analyzer != null && !analyzer.initialized) analyzer.Init(); storedPlan = new List<FootstepPlanningAction>(); outputPlan = new Stack<DefaultAction>(); domainList = new List<PlanningDomainBase>(); domainList.Add(new FootstepPlanningDomain(analyzer, neighborhood, obstacles)); planner = new ADAstarPlanner(); planner.init(ref domainList, MaxNumberOfNodes); initialized = true; currentState = null; isPlanComputed = false; planChanged = false; goalMeshRenderer = goalStateTransform.gameObject.GetComponent("MeshRenderer") as MeshRenderer; currentGoal = goalStateTransform.position; }
// Use this for initialization public override void Init(AnimationAnalyzer animAnalyzer, NeighbourAgents neighborhood, NeighbourObstacles obstacles) { analyzer = animAnalyzer; if (analyzer != null && !analyzer.initialized) analyzer.Init(); storedPlan = new List<FootstepPlanningAction>(); outputPlan = new Stack<DefaultAction>(); domainList = new List<PlanningDomainBase>(); gpd = new GridPlanningDomain(analyzer); //gtd = new GridTimeDomain(analyzer, obstacles); gtd = new GridTimeDomain(obstacles,neighborhood); fpd = new FootstepPlanningDomain(analyzer, neighborhood, obstacles); if (useGridDomain) { domainList.Add(gpd); //domainList.Add(gpd); } if (useGridTimeDomain) { domainList.Add(gtd); //domainList.Add(gtd); } if (useFootstepDomain) { domainList.Add(fpd); //domainList.Add(fpd); } planner = new BestFirstSearchPlanner(); planner.init(ref domainList, MaxNumberOfNodes); initialized = true; currentState = null; isPlanComputed = false; planChanged = false; goalMeshRenderer = goalStateTransform.gameObject.GetComponent("MeshRenderer") as MeshRenderer; currentGoal = goalStateTransform.position; goalReached = false; }