Skip to content

Conversation

@cx384
Copy link
Contributor

@cx384 cx384 commented Oct 4, 2025

Revision of #15979 (Can't reopen the old PR because of rebase force push.) Closes #4758

  • All issues from the previous version should be resolved.
  • There are now 4 different animation definitions such that the overlay animations can be changed independently.
    Item image can now be a table
  • Animations can be changed via metadata (Json serialized and properly cached). ✨
    Removed for this PR

Problems (currently not planned to be resolved with this PR):

  • The image of visual = "wielditem" and visual = "item" objects (dropped items) is not animated.
  • As discussed in the old PR, there is no function to push the TileAnimationParams back to Lua.

To do

Ready for Review.

How to test

Start devtest and use
testitems:inventory_image_animation
testitems:inventory_image_animation_overlay
testitems:wield_image_animation
testitems:wield_image_animation_overlay
testitems:inventory_image_animation_meta (new, for metadata)
Test compatibility with older versions, which only use the first frame.

@cx384 cx384 added @ Script API @ Client / Audiovisuals Feature ✨ PRs that add or enhance a feature Concept approved Approved by a core dev: PRs welcomed! labels Oct 4, 2025
@Zughy Zughy added Roadmap: supported by core dev PR not adhering to the roadmap, yet some core dev decided to take care of it and removed Concept approved Approved by a core dev: PRs welcomed! labels Oct 4, 2025
@sfan5 sfan5 added the Rebase needed The PR needs to be rebased by its author label Oct 7, 2025
@cx384 cx384 force-pushed the item_animation_api branch from f06fffe to ff95981 Compare October 9, 2025 09:23
@cx384
Copy link
Contributor Author

cx384 commented Oct 9, 2025

  • Rebased
  • Removed meta animation override
  • inventory_image can now be a table containing the animation "for the greater good"
    Similar to tiledef, but a different specification because e.g. texture can't depend on in world coordinates.
    Could be extended to support other things like mesh item images in the future.

@cx384 cx384 removed the Rebase needed The PR needs to be rebased by its author label Oct 9, 2025
@SmallJoker SmallJoker self-requested a review October 11, 2025 14:03
@cx384 cx384 force-pushed the item_animation_api branch from d75ed95 to 06a265a Compare October 12, 2025 06:13
@cx384
Copy link
Contributor Author

cx384 commented Oct 12, 2025

Another big rebase, next time I will squash the commits to reduce rebase work.

Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

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

I'd like to propose a few changes:
0001-Use-AnimationInfo-for-simplicity.patch.tar.gz

Excerpt from the commit message:

  1. Moved 'ItemVisuals' to the source file (internal for 'ItemVisualsManager')
  2. Re-used 'AnimationInfo' with one tile: This makes it possible to use
    one class/interface to contain as many textures as wanted. (generic)
  3. Replaced 'OwnedAnimationInfo' with 'AnimationInfo' + 'freeFrames()' to
    (hopefully) reduce complexity.

@cx384
Copy link
Contributor Author

cx384 commented Oct 18, 2025

Thanks for the improvements.
Using AnimationInfo for all item images, including non-animated ones, certainly reduces complexity, and it probably doesn't matter memory/performance-wise.
I don't know if the TODO. Change this to a shared pointer. for the frames vector is a good idea, though.

Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

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

LGTM aside from that. I find the animations very distracting, but it works.


// Note: Also update core.protocol_versions in builtin when bumping
const u16 LATEST_PROTOCOL_VERSION = 50;
const u16 LATEST_PROTOCOL_VERSION = 51;
Copy link
Member

Choose a reason for hiding this comment

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

Design question to the dev team: Should we bump already, or in the 5.15.0-rc build?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Typically people bump the protocol version because a network change requires it.
If this isn't the case here we could delay the bumping, but I don't see a strong reason to.

Copy link
Member

Choose a reason for hiding this comment

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

I am mainly asking this in case there would be a second PR for 5.15.0 that also increases the version. I guess it does not matter. We could bump it multiple times per version.

Only send first frame texture names to old clients

Replace image string by item image definition

Bump protocol version

1. Moved 'ItemVisuals' to the source file (internal for 'ItemVisualsManager')
2. Re-used 'AnimationInfo' with one tile: This makes it possible to use
   one class/interface to contain as many textures as wanted. (generic)
3. Replaced 'OwnedAnimationInfo' with 'AnimationInfo' + 'freeFrames()' to
   (hopefully) reduce complexity.

Co-authored-by: SmallJoker <[email protected]>
@cx384 cx384 force-pushed the item_animation_api branch from b2958d1 to 298a6c5 Compare October 24, 2025 08:20
@cx384
Copy link
Contributor Author

cx384 commented Oct 24, 2025

Rebased (and squashed beforehand).

@cx384 cx384 merged commit 93ccb4b into luanti-org:master Oct 26, 2025
20 checks passed

~ItemVisuals()
{
inventory_normal.freeFrames();
Copy link
Collaborator

Choose a reason for hiding this comment

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

wouldn't it be cleaner if ItemVisuals owned the frames ptr separately, so that AnimationInfo is always just a reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the case before at some point, but with Krocks's suggestions it changed "to (hopefully) reduce complexity".
Though, it probably would be best to directly store it in ItemVisuals instead of allocating additional heap memory.

-- 'chunksize' mapgen setting can be a vector, instead of a single number (5.15.0)
chunksize_vector = true,
-- Item definition fields `inventory_image`, `inventory_overlay`, `wield_image`
-- and `wield_overlay` accept a table containing animation definitions. (5.16.0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

5.15.0

if (image.name.empty()) {
// no-op
} else if (image.animation.type == TileAnimationType::TAT_NONE) {
frames->push_back({0, tsrc->getTexture(image.name)});
Copy link
Collaborator

Choose a reason for hiding this comment

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

couldn't createAnimationFrames just handle the one-frame case?

AnimationInfo *getInventoryOverlayAnimation(const ItemStack &item, Client *client) const;

// Get item mesh
// Once said to return nullptr if there is an inventory image, but this is wrong
Copy link
Collaborator

Choose a reason for hiding this comment

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

line should be removed.


std::vector<FrameSpec> createAnimationFrames(ITextureSource *tsrc,
const std::string &image_name, const TileAnimationParams &animation,
int &result_frame_length_ms)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would move this to another file, but not sure where

void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
void createItemMesh(Client *client, const ItemDefinition &def,
AnimationInfo &animation_normal,
AnimationInfo &animation_overlay,
Copy link
Collaborator

@sfan5 sfan5 Oct 27, 2025

Choose a reason for hiding this comment

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

const?

extractTexture(f.tiledef_special[0], l0, tsrc), nullptr
);
result->buffer_info.emplace_back(0, l0.has_color, l0.color);
mesh = getExtrudedMesh(l0.texture);
Copy link
Collaborator

Choose a reason for hiding this comment

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

no, the extractTexture call is important and was needed for preparation for array textures.
(in the future) l0.texture may be an array texture, which isn't usable for the item mesh.


// Modifies the texture name such that it only contains the first frame
// If the texture_size is know (client code), getTextureModifer should be used instead
void extractFirstFrame(std::string &name) const;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would put a disclaimer here that this function is only for compatibility purposes with old clients.

cx384 added a commit to cx384/minetest that referenced this pull request Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@ Client / Audiovisuals Feature ✨ PRs that add or enhance a feature One approval ✅ ◻️ Roadmap: supported by core dev PR not adhering to the roadmap, yet some core dev decided to take care of it @ Script API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Animated item textures in the inventory

4 participants