Skip to content

Commit

Permalink
integrated character animator and navigator into avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
DerKatsche committed Dec 21, 2023
1 parent d7eaf5d commit b8953d6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 386 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {
EventState,
KeyboardEventTypes,
KeyboardInfo,
LinesMesh,
MeshBuilder,
Nullable,
PointerEventTypes,
PointerInfo,
Expand All @@ -14,7 +12,6 @@ import bind from "bind-decorator";
import SCENE_TYPES, {
ScenePresenterFactory,
} from "~DependencyInjection/Scenes/SCENE_TYPES";
import { config } from "../../../../../config";
import CoreDIContainer from "../../../DependencyInjection/CoreDIContainer";
import CORE_TYPES from "../../../DependencyInjection/CoreTypes";
import INavigation from "../Navigation/INavigation";
Expand All @@ -31,7 +28,6 @@ export default class AvatarController implements IAvatarController {

private scenePresenter: IScenePresenter;
private navigation: INavigation;
private pathLine: LinesMesh;

private keyMovementTarget: Nullable<Vector3> = null;
private pointerMovementTarget: Nullable<Vector3> = null;
Expand All @@ -57,26 +53,18 @@ export default class AvatarController implements IAvatarController {
@bind
private applyInputs(): void {
if (this.keyMovementTarget !== null) {
this.navigation.Crowd.agentGoto(
this.viewModel.agentIndex,
this.keyMovementTarget
);
this.viewModel.movementTarget.Value = this.keyMovementTarget;

this.debug_drawPath(this.keyMovementTarget);
this.viewModel.characterNavigator.startMovement(this.keyMovementTarget);
} else if (this.pointerMovementTarget !== null) {
const movementDistance = this.pointerMovementTarget
.subtract(this.viewModel.parentNode.position)
.length();

if (movementDistance > this.viewModel.pointerMovementThreshold) {
this.navigation.Crowd.agentGoto(
this.viewModel.agentIndex,
this.viewModel.movementTarget.Value = this.pointerMovementTarget;
this.viewModel.characterNavigator.startMovement(
this.pointerMovementTarget
);
this.viewModel.movementTarget.Value = this.pointerMovementTarget;

this.debug_drawPath(this.pointerMovementTarget);
}
}
this.pointerMovementTarget = null;
Expand Down Expand Up @@ -152,18 +140,4 @@ export default class AvatarController implements IAvatarController {
this.lastFramePosition = this.viewModel.parentNode.position;
}
}

private debug_drawPath(target: Vector3): void {
if (config.isDebug === false) return;

let pathPoints = this.navigation.Plugin.computePath(
this.navigation.Crowd.getAgentPosition(this.viewModel.agentIndex),
target
);
this.pathLine = MeshBuilder.CreateDashedLines(
"navigation path",
{ points: pathPoints, updatable: true, instance: this.pathLine },
this.scenePresenter.Scene
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { injectable } from "inversify";
import AvatarViewModel, { AvatarAnimationAction } from "./AvatarViewModel";
import AvatarViewModel from "./AvatarViewModel";
import IAvatarPresenter from "./IAvatarPresenter";
import LearningElementTO from "src/Components/Core/Application/DataTransferObjects/LearningElementTO";
import CharacterAnimationActions from "../CharacterAnimator/CharacterAnimationActions";

/**
* @class AvatarPresenter
Expand All @@ -16,8 +17,8 @@ export default class AvatarPresenter implements IAvatarPresenter {
}

public onLearningElementLoaded(learningElementTO: LearningElementTO): void {
this.viewModel.animationStateMachine.applyAction(
AvatarAnimationAction.InteractionStarted
this.viewModel.characterAnimator.transition(
CharacterAnimationActions.InteractionStarted
);
}
}
Loading

0 comments on commit b8953d6

Please sign in to comment.