Skip to content

Accessing Animation Data #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 1.20
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.figuramc.figura.lua.docs.LuaTypeDoc;
import org.figuramc.figura.model.FiguraModelPart;
import org.luaj.vm2.LuaError;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;

import java.util.*;
Expand Down Expand Up @@ -140,6 +141,25 @@ public void playCode(float minTime, float maxTime) {
// -- lua methods -- //


@LuaWhitelist
@LuaMethodDoc("animation.getChannels")
public LuaTable getChannels() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am guessing this is because it is called "channel" in BlockBench?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its because thats what figura refers to them as (AnimationChannel)

LuaTable ret = new LuaTable();
for (Map.Entry<FiguraModelPart, List<Animation.AnimationChannel>> entry : animationParts) {
FiguraModelPart part = entry.getKey();
List<Animation.AnimationChannel> value = new ArrayList<Animation.AnimationChannel>();
for (Animation.AnimationChannel channel : entry.getValue()) {
value.add(channel);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any need to iterate over all channels instead of initializing the list with the collection?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk


LuaValue lPart = (LuaValue) owner.luaRuntime.typeManager.javaToLua(part);
LuaValue lValue = (LuaValue) owner.luaRuntime.typeManager.javaToLua(value);
ret.set(lPart, lValue);
}
System.out.println();
return ret;
}

@LuaWhitelist
@LuaMethodDoc("animation.is_playing")
public boolean isPlaying() {
Expand Down Expand Up @@ -607,5 +627,17 @@ public enum LoopMode {
HOLD
}

public record AnimationChannel(TransformType type, Keyframe... keyframes) {}
@LuaWhitelist
@LuaTypeDoc(
name = "AnimationChannel",
value = "animation_channel"
)
public record AnimationChannel(TransformType type, Keyframe... keyframes) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, does @LuaWhitelist not work on record fields?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhhhh idk lol

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i jsut forgot to add it i think


@LuaWhitelist
@LuaMethodDoc("animation.get_keyframes")
public List<Keyframe> getKeyframes() {
return List.of(keyframes);
}
}
}
30 changes: 30 additions & 0 deletions common/src/main/java/org/figuramc/figura/animation/Keyframe.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
import com.mojang.datafixers.util.Pair;
import org.figuramc.figura.FiguraMod;
import org.figuramc.figura.avatar.Avatar;
import org.figuramc.figura.lua.LuaWhitelist;
import org.figuramc.figura.lua.docs.LuaMethodDoc;
import org.figuramc.figura.lua.docs.LuaTypeDoc;
import org.figuramc.figura.math.vector.FiguraVec3;
import org.luaj.vm2.LuaError;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;

@LuaWhitelist
@LuaTypeDoc(
name = "Keyframe",
value = "keyframe"
)
public class Keyframe implements Comparable<Keyframe> {

private final Avatar owner;
Expand Down Expand Up @@ -36,14 +44,19 @@ public Keyframe(Avatar owner, Animation animation, float time, Interpolation int
this.bezierRightTime = bezierRightTime;
}

@LuaWhitelist
@LuaMethodDoc("keyframe.get_target_a")
public FiguraVec3 getTargetA(float delta) {
return targetA != null ? targetA.copy() : FiguraVec3.of(parseStringData(aCode[0], delta), parseStringData(aCode[1], delta), parseStringData(aCode[2], delta));
}

@LuaWhitelist
@LuaMethodDoc("keyframe.get_target_b")
public FiguraVec3 getTargetB(float delta) {
return targetB != null ? targetB.copy() : FiguraVec3.of(parseStringData(bCode[0], delta), parseStringData(bCode[1], delta), parseStringData(bCode[2], delta));
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an extra empty line?

private float parseStringData(String data, float delta) {
FiguraMod.pushProfiler(data);
try {
Expand Down Expand Up @@ -83,26 +96,43 @@ private float parseStringData(String data, float delta) {
return FiguraMod.popReturnProfiler(0f);
}

@LuaWhitelist
@LuaMethodDoc("keyframe.ph")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LuaMethodDoc is not required for a function to be accessible in Lua, but if you are adding docs, please do it properly or remove useless "docs".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what i can tell thats required to have it show up in the docs command, they're all pretty self explanatory, so documentation shouldnt really be necessary imo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"setPos" and "setRot" are also self-explanatory but still are documented, and it's better to have consistent documentation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh fine ill add docs

public float getTime() {
return time;
}


public Interpolation getInterpolation() {
return interpolation;
}

@LuaWhitelist
@LuaMethodDoc("keyframe.ph")
public String getInterpolate() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, forgot about this, but getInterpolation (verb noun) not getInterpolate (verb verb)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so uhhhh, that is different from the existing getInterpolation and idk how to get around that
waybe we should move to dev-chat

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having the same name is fine, maybe add a Void argument? or no, LuaValue arg? don't know which, but
i am physically unable to move to dev-chat

return interpolation.toString();
}

@LuaWhitelist
@LuaMethodDoc("keyframe.ph")
public FiguraVec3 getBezierLeft() {
return bezierLeft.copy();
}

@LuaWhitelist
@LuaMethodDoc("keyframe.ph")
public FiguraVec3 getBezierRight() {
return bezierRight.copy();
}

@LuaWhitelist
@LuaMethodDoc("keyframe.ph")
public FiguraVec3 getBezierLeftTime() {
return bezierLeftTime.copy();
}

@LuaWhitelist
@LuaMethodDoc("keyframe.ph")
public FiguraVec3 getBezierRightTime() {
return bezierRightTime.copy();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.figuramc.figura.lua;

import org.figuramc.figura.animation.Animation;
import org.figuramc.figura.animation.Keyframe;
import org.figuramc.figura.entries.FiguraAPI;
import org.figuramc.figura.lua.api.*;
import org.figuramc.figura.lua.api.action_wheel.Action;
Expand Down Expand Up @@ -123,6 +124,8 @@ public class FiguraAPIManager {

add(AnimationAPI.class);
add(Animation.class);
add(Animation.AnimationChannel.class);
add(Keyframe.class);

add(HostAPI.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.figuramc.figura.FiguraMod;
import org.figuramc.figura.animation.Animation;
import org.figuramc.figura.entries.FiguraAPI;
import org.figuramc.figura.animation.Keyframe;
import org.figuramc.figura.lua.api.*;
import org.figuramc.figura.lua.api.action_wheel.Action;
import org.figuramc.figura.lua.api.action_wheel.ActionWheelAPI;
Expand Down Expand Up @@ -119,7 +120,9 @@ public class FiguraDocsManager {

put("animations", List.of(
AnimationAPI.class,
Animation.class
Animation.class,
Animation.AnimationChannel.class,
Keyframe.class
));

put("nameplate", List.of(
Expand Down
6 changes: 6 additions & 0 deletions common/src/main/resources/assets/figura/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,13 @@
"figura.docs.animation.get_speed": "Gets the animation's speed",
"figura.docs.animation.set_speed": "Sets the animation's playback speed\nNegative numbers can be used for an inverted animation",
"figura.docs.animation.get_name": "Returns this animation's name",
"figura.docs.animation.get_channels": "Returns a table containing all the animation channels for this animation\nThis table is structured {ModelPart = {AnimationChannel, AnimationChannel}}",

"figura.docs.animation_channel.get_keyframes": "Returns a list of keyframes that are in this channel",

"figura.docs.keyframe.get_target_a": "Gets target 'A' of this keyframe\n I have no idea what 'A' means",
"figura.docs.keyframe.get_target_b": "Gets target 'B' of this keyframe\n I have no idea what 'B' means",
"figura.docs.keyframe.ph": "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:>


"figura.docs.avatar": "A global API containing functions to interact with your avatar's metadata, and also to get information about the current script environment",
"figura.docs.avatar.store": "Store the given key-value pair inside your current avatar's metadata\nSomeone else can get this information from a different script with the avatarVars() function in World\nThe key must be a string",
Expand Down