Skip to content

Commit d63a470

Browse files
committed
Support starting playback at a specified frame
1 parent 78ab2b7 commit d63a470

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

doc/lua_api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8662,8 +8662,9 @@ Track numbers start at 1.
86628662
* `play_animation(track, [animation])`
86638663
`.x` and `.b3d` models only have a single animation track.
86648664
* `animation` is an optional table with the following optional fields:
8665-
* `start_frame = 0.0`, `end_frame = math.huge`, animation range in frames (seconds);
8665+
* `min_frame = 0.0`, `max_frame = math.huge`, animation range in frames (seconds);
86668666
clamped on the client to first and last frame in the corresponding track.
8667+
* `frame`, where to start playing the animation, defaults to `min_frame` if `speed >= 0`, `max_frame` otherwise.
86678668
* `speed = 1.0`, animation speed in frames per second.
86688669
(Recall that glTF frames are typically just timetamps in seconds.)
86698670
A negative speed plays the animation backwards.

src/client/content_cao.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,14 +1673,10 @@ void GenericCAO::processMessage(const std::string &data)
16731673
v2f range = readV2F32(is);
16741674
anim.min_frame = std::min(range.X, range.Y);
16751675
anim.max_frame = std::max(range.X, range.Y);
1676-
16771676
anim.fps = readF32(is);
1678-
if (anim.fps >= 0) {
1679-
anim.cur_frame = anim.min_frame;
1680-
} else {
1681-
anim.cur_frame = anim.max_frame;
1682-
}
1677+
anim.cur_frame = anim.fps >= 0 ? anim.min_frame : anim.max_frame;
16831678
anim.blend = readF32(is);
1679+
16841680
// these are sent inverted so we get true when the server sends nothing
16851681
anim.loop = !readU8(is);
16861682

@@ -1691,6 +1687,7 @@ void GenericCAO::processMessage(const std::string &data)
16911687
}
16921688
if (!is.eof()) {
16931689
anim.priority = readS32(is);
1690+
anim.cur_frame = readF32(is);
16941691
}
16951692

16961693
// Apply animation

src/script/lua_api/l_object.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ static void readTrackAnimSpec(lua_State *L, int tidx,
491491
anim.max_frame = getfloatfield_default(L, tidx, "max_frame",
492492
std::numeric_limits<f32>::infinity());
493493
anim.fps = getfloatfield_default(L, tidx, "speed", 1.0f);
494+
anim.cur_frame = getfloatfield_default(L, tidx, "frame",
495+
anim.fps >= 0 ? anim.min_frame : anim.max_frame);
494496
anim.blend = getfloatfield_default(L, tidx, "blend", 0.0f);
495497
anim.loop = getboolfield_default(L, tidx, "loop", true);
496498
anim.priority = getintfield_default(L, tidx, "priority", 0);
@@ -502,6 +504,7 @@ static void pushTrackAnimSpec(lua_State *L,
502504
lua_newtable(L);
503505
setfloatfield(L, -1, "min_frame", anim.min_frame);
504506
setfloatfield(L, -1, "max_frame", anim.max_frame);
507+
setfloatfield(L, -1, "frame", anim.cur_frame);
505508
setfloatfield(L, -1, "speed", anim.fps);
506509
setfloatfield(L, -1, "blend", anim.blend);
507510
setboolfield(L, -1, "loop", anim.loop);

src/server/unit_sao.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,12 @@ std::string UnitSAO::generateUpdateAnimationCommand(const scene::TrackId &track)
392392
writeF32(os, anim.max_frame);
393393
writeF32(os, anim.fps);
394394
writeF32(os, anim.blend);
395-
// these are sent inverted so we get true when the server sends nothing
395+
// sent inverted so we get true when the server sends nothing
396396
writeU8(os, !anim.loop);
397397

398398
writeTrackIdentifier(os, track);
399399
writeS32(os, anim.priority);
400+
writeF32(os, anim.cur_frame);
400401

401402
return os.str();
402403
}

0 commit comments

Comments
 (0)