Search in sources :

Example 1 with SkeletalMeshComponent

use of org.terasology.rendering.logic.SkeletalMeshComponent in project Terasology by MovingBlocks.

the class AnimationScreen method initialise.

@Override
public void initialise() {
    spawnEntityIdButton = find("spawnEntityIdButton", UIButton.class);
    entityDropdown = find("entityDropdown", UIDropdownScrollable.class);
    logger.info("Number of available skeletal meshes: " + assetManager.getAvailableAssets(SkeletalMesh.class).size());
    ArrayList skeletalMesh = new ArrayList(assetManager.getAvailableAssets(SkeletalMesh.class));
    if (entityDropdown != null) {
        entityDropdown.setOptions(skeletalMesh);
    }
    animationSpeedSlider = find("entityAnimationSpeedSlider", UISlider.class);
    if (animationSpeedSlider != null) {
        animationSpeedSlider.setMinimum(-0.0f);
        animationSpeedSlider.setIncrement(0.1f);
        animationSpeedSlider.setRange(10.0f);
        animationSpeedSlider.setPrecision(1);
    }
    spawnEntityIdButton.subscribe(widget -> {
        Vector3f localPlayerPosition = localPlayer.getPosition();
        Quat4f localPlayerRotation = localPlayer.getRotation();
        Vector3f offset = localPlayer.getViewDirection();
        offset.scale(2.0f);
        offset.y = 0;
        localPlayerPosition.add(offset);
        Optional<Prefab> prefab = assetManager.getAsset(entityDropdown.getSelection(), Prefab.class);
        if (prefab.isPresent() && prefab.get().getComponent(LocationComponent.class) != null) {
            entityRef = entityManager.create(prefab.get(), localPlayerPosition, localPlayerRotation);
            SkeletalMeshComponent skeletalMeshComponent = entityRef.getComponent(SkeletalMeshComponent.class);
            skeletalMeshComponent.animationRate = animationSpeedSlider.getValue();
            entityRef.saveComponent(skeletalMeshComponent);
            CharacterMovementComponent movementComponent = entityRef.getComponent(CharacterMovementComponent.class);
            movementComponent.speedMultiplier = animationSpeedSlider.getValue();
            entityRef.saveComponent(movementComponent);
        }
    });
}
Also used : SkeletalMeshComponent(org.terasology.rendering.logic.SkeletalMeshComponent) UISlider(org.terasology.rendering.nui.widgets.UISlider) UIButton(org.terasology.rendering.nui.widgets.UIButton) UIDropdownScrollable(org.terasology.rendering.nui.widgets.UIDropdownScrollable) Vector3f(org.terasology.math.geom.Vector3f) ArrayList(java.util.ArrayList) CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) Prefab(org.terasology.entitySystem.prefab.Prefab) Quat4f(org.terasology.math.geom.Quat4f)

Aggregations

ArrayList (java.util.ArrayList)1 Prefab (org.terasology.entitySystem.prefab.Prefab)1 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)1 Quat4f (org.terasology.math.geom.Quat4f)1 Vector3f (org.terasology.math.geom.Vector3f)1 SkeletalMesh (org.terasology.rendering.assets.skeletalmesh.SkeletalMesh)1 SkeletalMeshComponent (org.terasology.rendering.logic.SkeletalMeshComponent)1 UIButton (org.terasology.rendering.nui.widgets.UIButton)1 UIDropdownScrollable (org.terasology.rendering.nui.widgets.UIDropdownScrollable)1 UISlider (org.terasology.rendering.nui.widgets.UISlider)1